@ea-lab/reactive-json-docs 0.3.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/data-mapping.md +76 -0
- package/public/rjbuild/docs/advanced-concepts/data-mapping.yaml +140 -0
- package/public/rjbuild/docs/advanced-concepts/data-processors.md +373 -0
- package/public/rjbuild/docs/advanced-concepts/data-processors.yaml +309 -0
- package/public/rjbuild/docs/advanced-concepts/index.md +10 -0
- package/public/rjbuild/docs/advanced-concepts/index.yaml +16 -0
- package/public/rjbuild/docs/{extend → advanced-concepts/plugins}/component-development-guide-llm.md +2 -0
- package/public/rjbuild/docs/{extend → advanced-concepts/plugins}/component-development.md +1 -1
- package/public/rjbuild/docs/{extend → advanced-concepts/plugins}/component-development.yaml +1 -1
- package/public/rjbuild/docs/{extend → advanced-concepts/plugins}/plugin-system.md +2 -0
- package/public/rjbuild/docs/{extend → advanced-concepts/plugins}/plugin-system.yaml +2 -0
- 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/dataMapping/index.md +31 -0
- package/public/rjbuild/docs/core/dataMapping/index.yaml +24 -0
- package/public/rjbuild/docs/core/dataMapping/simpleMapping.md +131 -0
- package/public/rjbuild/docs/core/dataMapping/simpleMapping.yaml +376 -0
- 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/element/special/ReactiveJsonSubroot.md +4 -3
- package/public/rjbuild/docs/core/element/special/ReactiveJsonSubroot.yaml +114 -6
- 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.md → getting-started/index.md} +30 -6
- package/public/rjbuild/docs/{getting-started.yaml → getting-started/index.yaml} +22 -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 +358 -0
- package/public/rjbuild/docs/getting-started/rjbuild-structure.yaml +421 -0
- package/public/rjbuild/docs/{template.md → getting-started/template-contexts-data-binding.md} +16 -12
- package/public/rjbuild/docs/{template.yaml → getting-started/template-contexts-data-binding.yaml} +28 -14
- package/public/rjbuild/docs/install.yaml +682 -681
- /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
- /package/public/rjbuild/docs/{extend → advanced-concepts/plugins}/index.md +0 -0
- /package/public/rjbuild/docs/{extend → advanced-concepts/plugins}/index.yaml +0 -0
|
@@ -1,254 +1,26 @@
|
|
|
1
1
|
renderView:
|
|
2
2
|
- type: Markdown
|
|
3
3
|
content: |
|
|
4
|
-
#
|
|
4
|
+
# Reactions
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
> For an introduction to the reactions system and detailed examples, see [Getting Started: Reactions](../../getting-started/reactions).
|
|
7
7
|
|
|
8
|
-
Reactions
|
|
8
|
+
Reactions in Reactive-JSON allow you to respond to user events and perform operations like data updates, network requests, and browser interactions. They execute in response to user events to modify application state and trigger behaviors.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- type: RjBuildDescriber
|
|
13
|
-
title: "Basic Reaction Structure"
|
|
14
|
-
description:
|
|
15
|
-
- type: Markdown
|
|
16
|
-
content: |
|
|
17
|
-
This example demonstrates the fundamental structure of reactions in Reactive-JSON.
|
|
18
|
-
|
|
19
|
-
Reactions are defined as part of the `actions` array on any element and consist of:
|
|
20
|
-
- `what`: The name of the reaction to execute
|
|
21
|
-
- `on`: The event that triggers the reaction
|
|
22
|
-
- **Reaction-specific properties**: Vary depending on the reaction type
|
|
23
|
-
- **Optional conditions**: Same conditional system as actions
|
|
24
|
-
|
|
25
|
-
toDescribe:
|
|
26
|
-
renderView:
|
|
27
|
-
- type: TextField
|
|
28
|
-
label: "Enter some text:"
|
|
29
|
-
dataLocation: ~.user_input
|
|
30
|
-
placeholder: "Type something..."
|
|
31
|
-
|
|
32
|
-
- type: button
|
|
33
|
-
content: "Save Text"
|
|
34
|
-
actions:
|
|
35
|
-
- what: setData # Reaction type
|
|
36
|
-
on: click # Triggering event
|
|
37
|
-
path: ~.saved_text # Reaction-specific property
|
|
38
|
-
value: ~.user_input # Reaction-specific property
|
|
39
|
-
when: ~.user_input # Optional condition
|
|
40
|
-
isEmpty: "not" # Condition value
|
|
41
|
-
|
|
42
|
-
- type: div
|
|
43
|
-
content: ["Saved text: ", ~.saved_text]
|
|
44
|
-
actions:
|
|
45
|
-
- what: hide # Action (no 'on' property)
|
|
46
|
-
when: ~.saved_text # Condition
|
|
47
|
-
isEmpty: true
|
|
48
|
-
|
|
49
|
-
data:
|
|
50
|
-
user_input: ""
|
|
51
|
-
saved_text: ""
|
|
52
|
-
|
|
53
|
-
- type: Markdown
|
|
54
|
-
content: |
|
|
55
|
-
## Reaction Types
|
|
56
|
-
|
|
57
|
-
Reactive-JSON provides several built-in reactions:
|
|
10
|
+
## Available Reaction Components
|
|
58
11
|
|
|
59
12
|
### Data Management
|
|
60
|
-
- **[setData](setData)**: Sets data at the specified path
|
|
61
|
-
- **[addData](addData)**: Adds new data to the specified path
|
|
62
|
-
- **[removeData](removeData)**: Removes data from the specified path
|
|
63
|
-
- **[moveData](moveData)**: Moves data from one path to another
|
|
13
|
+
- **[setData](./setData)**: Sets data at the specified path
|
|
14
|
+
- **[addData](./addData)**: Adds new data to the specified path
|
|
15
|
+
- **[removeData](./removeData)**: Removes data from the specified path
|
|
16
|
+
- **[moveData](./moveData)**: Moves data from one path to another
|
|
64
17
|
|
|
65
18
|
### Network Operations
|
|
66
|
-
- **[fetchData](fetchData)**: Fetches data from a URL using GET requests
|
|
67
|
-
- **[submitData](submitData)**: Submits data to a server endpoint using POST/PUT/DELETE
|
|
19
|
+
- **[fetchData](./fetchData)**: Fetches data from a URL using GET requests
|
|
20
|
+
- **[submitData](./submitData)**: Submits data to a server endpoint using POST/PUT/DELETE
|
|
68
21
|
|
|
69
22
|
### Browser Operations
|
|
70
|
-
- **[setClipboardData](setClipboardData)**: Copies data to the clipboard
|
|
71
|
-
- **[redirectNow](redirectNow)**: Performs an immediate redirect
|
|
72
|
-
- **[triggerEvent](triggerEvent)**: Triggers a custom event
|
|
73
|
-
- **[postMessage](postMessage)**: Sends a message to another window/frame
|
|
74
|
-
|
|
75
|
-
For detailed documentation of each reaction, including properties and examples, see their respective documentation pages.
|
|
76
|
-
|
|
77
|
-
- type: RjBuildDescriber
|
|
78
|
-
title: "Event Types and Conditional Reactions"
|
|
79
|
-
description:
|
|
80
|
-
- type: Markdown
|
|
81
|
-
content: |
|
|
82
|
-
This example shows different event types and conditional reactions.
|
|
83
|
-
|
|
84
|
-
Common event types:
|
|
85
|
-
- `click`: Mouse click (works on any element)
|
|
86
|
-
- `change`: Form input change (works on form elements only)
|
|
87
|
-
- `submit`: Form submission (works on form elements only)
|
|
88
|
-
- `keydown`/`keyup`: Keyboard events (works on focusable elements)
|
|
89
|
-
|
|
90
|
-
toDescribe:
|
|
91
|
-
renderView:
|
|
92
|
-
- type: button
|
|
93
|
-
content: "Toggle Mode (Click)"
|
|
94
|
-
actions:
|
|
95
|
-
- what: setData
|
|
96
|
-
on: click
|
|
97
|
-
path: ~.mode
|
|
98
|
-
value: "editing"
|
|
99
|
-
when: ~.mode
|
|
100
|
-
isNot: "editing"
|
|
101
|
-
- what: setData
|
|
102
|
-
on: click
|
|
103
|
-
path: ~.mode
|
|
104
|
-
value: "viewing"
|
|
105
|
-
when: ~.mode
|
|
106
|
-
is: "editing"
|
|
107
|
-
|
|
108
|
-
- type: TextField
|
|
109
|
-
label: "Text field (onChange):"
|
|
110
|
-
dataLocation: ~.text_value
|
|
111
|
-
actions:
|
|
112
|
-
- what: setData
|
|
113
|
-
on: change
|
|
114
|
-
path: ~.last_change
|
|
115
|
-
value: ~.text_value
|
|
116
|
-
when: ~.mode
|
|
117
|
-
is: "editing"
|
|
118
|
-
|
|
119
|
-
- type: div
|
|
120
|
-
content: ["Current mode: ", ~.mode]
|
|
121
|
-
|
|
122
|
-
- type: div
|
|
123
|
-
content: ["Last change: ", ~.last_change]
|
|
124
|
-
actions:
|
|
125
|
-
- what: hide
|
|
126
|
-
when: ~.last_change
|
|
127
|
-
isEmpty: true
|
|
128
|
-
|
|
129
|
-
data:
|
|
130
|
-
mode: "viewing"
|
|
131
|
-
text_value: ""
|
|
132
|
-
last_change: ""
|
|
133
|
-
|
|
134
|
-
- type: RjBuildDescriber
|
|
135
|
-
title: "Data Management Example"
|
|
136
|
-
description:
|
|
137
|
-
- type: Markdown
|
|
138
|
-
content: |
|
|
139
|
-
This example demonstrates the core data management reactions: setData, addData, and removeData.
|
|
140
|
-
|
|
141
|
-
toDescribe:
|
|
142
|
-
renderView:
|
|
143
|
-
- type: TextField
|
|
144
|
-
label: "Add item:"
|
|
145
|
-
dataLocation: ~.new_item
|
|
146
|
-
placeholder: "Enter item name"
|
|
147
|
-
|
|
148
|
-
- type: button
|
|
149
|
-
content: "Add Item"
|
|
150
|
-
actions:
|
|
151
|
-
- what: addData
|
|
152
|
-
on: click
|
|
153
|
-
path: ~.items
|
|
154
|
-
value:
|
|
155
|
-
name: ~.new_item
|
|
156
|
-
when: ~.new_item
|
|
157
|
-
isEmpty: "not"
|
|
158
|
-
- what: setData
|
|
159
|
-
on: click
|
|
160
|
-
path: ~.new_item
|
|
161
|
-
value: ""
|
|
162
|
-
when: ~.new_item
|
|
163
|
-
isEmpty: "not"
|
|
164
|
-
|
|
165
|
-
- type: div
|
|
166
|
-
content: "Items:"
|
|
167
|
-
attributes:
|
|
168
|
-
style:
|
|
169
|
-
fontWeight: "bold"
|
|
170
|
-
margin: "10px 0 5px 0"
|
|
171
|
-
|
|
172
|
-
- type: Switch
|
|
173
|
-
content: ~.items
|
|
174
|
-
singleOption:
|
|
175
|
-
load: itemTemplate
|
|
176
|
-
|
|
177
|
-
templates:
|
|
178
|
-
itemTemplate:
|
|
179
|
-
type: div
|
|
180
|
-
content:
|
|
181
|
-
- "• "
|
|
182
|
-
- ~.name
|
|
183
|
-
- type: button
|
|
184
|
-
content: " [Remove]"
|
|
185
|
-
attributes:
|
|
186
|
-
style:
|
|
187
|
-
marginLeft: "10px"
|
|
188
|
-
background: "red"
|
|
189
|
-
color: "white"
|
|
190
|
-
border: "none"
|
|
191
|
-
padding: "2px 8px"
|
|
192
|
-
fontSize: "12px"
|
|
193
|
-
actions:
|
|
194
|
-
- what: removeData
|
|
195
|
-
on: click
|
|
196
|
-
target: currentTemplateData
|
|
197
|
-
parentLevel: 0
|
|
198
|
-
|
|
199
|
-
data:
|
|
200
|
-
new_item: ""
|
|
201
|
-
items:
|
|
202
|
-
- name: "Sample item 1"
|
|
203
|
-
- name: "Sample item 2"
|
|
204
|
-
|
|
205
|
-
- type: Markdown
|
|
206
|
-
content: |
|
|
207
|
-
## Advanced Features
|
|
208
|
-
|
|
209
|
-
### Conditional Logic
|
|
210
|
-
Reactions support the same conditional operators as actions:
|
|
211
|
-
- `when` + `is`/`isNot`: Value equality checks
|
|
212
|
-
- `when` + `isEmpty`: Empty value tests
|
|
213
|
-
- `when` + `contains`/`containsNot`: Content search
|
|
214
|
-
- `when` + `>`, `<`, `>=`, `<=`: Numeric/date comparisons
|
|
215
|
-
- `andConditions`/`orConditions`: Complex condition logic
|
|
216
|
-
|
|
217
|
-
### Event Control
|
|
218
|
-
Use `stopPropagation: true` to:
|
|
219
|
-
1. Prevent event bubbling to parent elements
|
|
220
|
-
2. Stop execution of subsequent actions for the same event
|
|
221
|
-
|
|
222
|
-
### Execution Order
|
|
223
|
-
- Multiple reactions on the same event execute in the order they are defined
|
|
224
|
-
- Reactions with unmet conditions are skipped
|
|
225
|
-
- Actions (without `on` property) are evaluated separately from reactions
|
|
226
|
-
|
|
227
|
-
- type: Markdown
|
|
228
|
-
content: |
|
|
229
|
-
## Technical Details
|
|
230
|
-
|
|
231
|
-
- Reactions are triggered by DOM events
|
|
232
|
-
- Multiple reactions can be defined for the same event
|
|
233
|
-
- Reactions are executed in the order they appear in the YAML
|
|
234
|
-
- Reactions can be chained together by modifying data that other reactions depend on
|
|
235
|
-
- Conditional reactions only execute when their conditions evaluate to true
|
|
236
|
-
- The `stopPropagation` property affects both event bubbling and subsequent action execution
|
|
237
|
-
|
|
238
|
-
## Limitations
|
|
239
|
-
|
|
240
|
-
- Event availability depends on the HTML element type (e.g., `change` only works on form elements)
|
|
241
|
-
- Network operations require proper CORS configuration
|
|
242
|
-
- Browser operations require appropriate permissions
|
|
243
|
-
- No built-in error handling beyond console logging for network operations
|
|
244
|
-
- Only one network request (fetch/submit) can be active at a time
|
|
245
|
-
- URLs in network operations must be static strings (dynamic URLs not supported)
|
|
246
|
-
|
|
247
|
-
## Best Practices
|
|
248
|
-
|
|
249
|
-
1. **Use descriptive conditions**: Make your conditional logic clear and readable
|
|
250
|
-
2. **Handle empty states**: Always consider what happens when data is empty or undefined
|
|
251
|
-
3. **Order matters**: Place more specific conditions before general ones
|
|
252
|
-
4. **Use stopPropagation wisely**: Only use it when you specifically need to prevent event bubbling or stop action execution
|
|
253
|
-
5. **Test network operations**: Ensure your API endpoints return the expected format
|
|
254
|
-
6. **Provide user feedback**: Use visual indicators during loading states (see individual reaction documentation for CSS examples)
|
|
23
|
+
- **[setClipboardData](./setClipboardData)**: Copies data to the clipboard
|
|
24
|
+
- **[redirectNow](./redirectNow)**: Performs an immediate redirect
|
|
25
|
+
- **[triggerEvent](./triggerEvent)**: Triggers a custom event
|
|
26
|
+
- **[postMessage](./postMessage)**: Sends a message to another window/frame
|
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
This section documents components that are specific to the reactive-json-docs package. These components are not part of the core Reactive-JSON library but are provided by the documentation system to enhance the presentation of examples and technical content.
|
|
6
6
|
|
|
7
|
-
**Important**: These components are only available when using reactive-json-docs and are not included in the core @ea-lab/reactive-json package.
|
|
8
|
-
|
|
9
7
|
## Available Components
|
|
10
8
|
|
|
11
9
|
The documentation system provides specialized components for:
|
|
@@ -7,8 +7,6 @@ renderView:
|
|
|
7
7
|
|
|
8
8
|
This section documents components that are specific to the reactive-json-docs package. These components are not part of the core Reactive-JSON library but are provided by the documentation system to enhance the presentation of examples and technical content.
|
|
9
9
|
|
|
10
|
-
**Important**: These components are only available when using reactive-json-docs and are not included in the core @ea-lab/reactive-json package.
|
|
11
|
-
|
|
12
10
|
## Available Components
|
|
13
11
|
|
|
14
12
|
The documentation system provides specialized components for:
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# Actions System
|
|
2
|
+
|
|
3
|
+
The Reactive-JSON actions system allows you to modify element behavior and appearance based on dynamic conditions - all through JSON configuration. Actions are applied to individual elements and can control visibility, display tooltips, redirect users, or trigger other behaviors based on the current data state.
|
|
4
|
+
|
|
5
|
+
Actions enable the UI to adapt automatically based on the application's state. They differ from [reactions](./reactions.md), which execute in response to user events; actions are evaluated continuously based on data conditions.
|
|
6
|
+
|
|
7
|
+
## Basic Syntax
|
|
8
|
+
|
|
9
|
+
Actions are defined as part of the `actions` array on any element. Each action has the following structure:
|
|
10
|
+
|
|
11
|
+
- `what`: The type of action to execute.
|
|
12
|
+
- `when` (optional): Data field reference to evaluate for the condition that determines when the action should execute. Supports various conditional operators: `is`, `isNot`, `isEmpty`, `contains`, `containsNot`, `containedBy`, `containedByNot`, numeric comparisons (`>`, `<`, `>=`, `<=`), and complex conditions (`andConditions`, `orConditions`). For detailed information about each condition type, see the [conditional operators reference](#conditional-operators) below.
|
|
13
|
+
|
|
14
|
+
In addition to these core properties, actions support action-specific properties that vary depending on the action type. For example, a `hide` action only requires the condition properties, while a `redirect` action needs a `to` property specifying the destination URL.
|
|
15
|
+
|
|
16
|
+
```yaml
|
|
17
|
+
renderView:
|
|
18
|
+
- type: CheckBoxField
|
|
19
|
+
dataLocation: ~.show_advanced
|
|
20
|
+
options:
|
|
21
|
+
- value: true
|
|
22
|
+
label: "Show advanced settings"
|
|
23
|
+
|
|
24
|
+
- type: div
|
|
25
|
+
content: "Advanced Settings Panel"
|
|
26
|
+
actions:
|
|
27
|
+
- what: hide # Action type
|
|
28
|
+
when: ~.show_advanced # Condition to evaluate
|
|
29
|
+
isNot: true # Expected value
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Basic Action Demonstration
|
|
33
|
+
|
|
34
|
+
This example demonstrates how actions adapt the UI based on application state.
|
|
35
|
+
|
|
36
|
+
When you check the checkbox, the "Advanced Settings Panel" becomes visible. The action continuously evaluates the condition and shows/hides content accordingly.
|
|
37
|
+
|
|
38
|
+
```yaml
|
|
39
|
+
renderView:
|
|
40
|
+
- type: CheckBoxField
|
|
41
|
+
dataLocation: ~.show_advanced
|
|
42
|
+
options:
|
|
43
|
+
- value: true
|
|
44
|
+
label: "Show advanced settings"
|
|
45
|
+
|
|
46
|
+
- type: div
|
|
47
|
+
content: "Basic Settings"
|
|
48
|
+
attributes:
|
|
49
|
+
style:
|
|
50
|
+
padding: "15px"
|
|
51
|
+
border: "2px solid var(--bs-border-color, #dee2e6)"
|
|
52
|
+
borderRadius: "8px"
|
|
53
|
+
margin: "10px 0"
|
|
54
|
+
|
|
55
|
+
- type: div
|
|
56
|
+
content: "Advanced Settings Panel"
|
|
57
|
+
attributes:
|
|
58
|
+
style:
|
|
59
|
+
padding: "15px"
|
|
60
|
+
border: "2px dashed var(--bs-border-color, #dee2e6)"
|
|
61
|
+
borderRadius: "8px"
|
|
62
|
+
margin: "10px 0"
|
|
63
|
+
fontStyle: "italic"
|
|
64
|
+
actions:
|
|
65
|
+
- what: hide # Action type
|
|
66
|
+
when: ~.show_advanced # Condition to evaluate
|
|
67
|
+
isNot: true # Expected value
|
|
68
|
+
|
|
69
|
+
data:
|
|
70
|
+
show_advanced: false
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Action Types
|
|
74
|
+
|
|
75
|
+
Reactive-JSON provides several built-in actions:
|
|
76
|
+
|
|
77
|
+
### Visibility Control
|
|
78
|
+
- **[hide](../core/action/Hide.md)**: Completely hides the element and its children
|
|
79
|
+
- **[visuallyHide](../core/action/VisuallyHide.md)**: Visually hides the element while keeping it accessible to screen readers
|
|
80
|
+
|
|
81
|
+
### User Interaction
|
|
82
|
+
- **[tooltip](../core/action/Tooltip.md)**: Displays a tooltip on hover
|
|
83
|
+
- **[popover](../core/action/Popover.md)**: Shows a more complex popover on click
|
|
84
|
+
|
|
85
|
+
### Navigation
|
|
86
|
+
- **[redirect](../core/action/Redirect.md)**: Redirects to a specified URL
|
|
87
|
+
|
|
88
|
+
For detailed documentation of each action, including properties and examples, see their respective documentation pages.
|
|
89
|
+
|
|
90
|
+
## Complete Examples
|
|
91
|
+
|
|
92
|
+
### Basic Conditional Actions Example
|
|
93
|
+
|
|
94
|
+
```yaml
|
|
95
|
+
renderView:
|
|
96
|
+
- type: div
|
|
97
|
+
content: "This shows only when status is 'active'"
|
|
98
|
+
attributes:
|
|
99
|
+
style:
|
|
100
|
+
padding: "10px"
|
|
101
|
+
border: "1px solid var(--bs-border-color, #dee2e6)"
|
|
102
|
+
margin: "5px 0"
|
|
103
|
+
actions:
|
|
104
|
+
- what: hide
|
|
105
|
+
when: ~.status
|
|
106
|
+
isNot: "active"
|
|
107
|
+
|
|
108
|
+
- type: div
|
|
109
|
+
content: "This shows only when text is not empty"
|
|
110
|
+
attributes:
|
|
111
|
+
style:
|
|
112
|
+
padding: "10px"
|
|
113
|
+
border: "1px solid var(--bs-border-color, #dee2e6)"
|
|
114
|
+
margin: "5px 0"
|
|
115
|
+
actions:
|
|
116
|
+
- what: hide
|
|
117
|
+
when: ~.text_input
|
|
118
|
+
isEmpty: true
|
|
119
|
+
|
|
120
|
+
- type: SelectField
|
|
121
|
+
label: "Status:"
|
|
122
|
+
dataLocation: ~.status
|
|
123
|
+
options:
|
|
124
|
+
- value: "inactive"
|
|
125
|
+
label: "Inactive"
|
|
126
|
+
- value: "active"
|
|
127
|
+
label: "Active"
|
|
128
|
+
|
|
129
|
+
- type: TextField
|
|
130
|
+
label: "Text:"
|
|
131
|
+
dataLocation: ~.text_input
|
|
132
|
+
placeholder: "Type something..."
|
|
133
|
+
|
|
134
|
+
data:
|
|
135
|
+
status: "inactive"
|
|
136
|
+
text_input: ""
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Tooltip Action Example
|
|
140
|
+
|
|
141
|
+
```yaml
|
|
142
|
+
renderView:
|
|
143
|
+
- type: button
|
|
144
|
+
content: "Hover for help (when enabled)"
|
|
145
|
+
actions:
|
|
146
|
+
- what: tooltip
|
|
147
|
+
content: "This is a helpful tooltip!"
|
|
148
|
+
placement: "top"
|
|
149
|
+
when: ~.show_tooltips
|
|
150
|
+
is: true
|
|
151
|
+
|
|
152
|
+
- type: CheckBoxField
|
|
153
|
+
label: "Enable tooltips"
|
|
154
|
+
dataLocation: ~.show_tooltips
|
|
155
|
+
options:
|
|
156
|
+
- value: true
|
|
157
|
+
label: ""
|
|
158
|
+
|
|
159
|
+
data:
|
|
160
|
+
show_tooltips: true
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Practical Form Example
|
|
164
|
+
|
|
165
|
+
```yaml
|
|
166
|
+
renderView:
|
|
167
|
+
- type: h4
|
|
168
|
+
content: "Simple Contact Form"
|
|
169
|
+
|
|
170
|
+
- type: TextField
|
|
171
|
+
label: "Name:"
|
|
172
|
+
dataLocation: ~.form.name
|
|
173
|
+
placeholder: "Enter your name"
|
|
174
|
+
|
|
175
|
+
- type: TextField
|
|
176
|
+
label: "Email:"
|
|
177
|
+
dataLocation: ~.form.email
|
|
178
|
+
inputType: "email"
|
|
179
|
+
placeholder: "Enter your email"
|
|
180
|
+
|
|
181
|
+
- type: div
|
|
182
|
+
content: "Please fill in both fields"
|
|
183
|
+
attributes:
|
|
184
|
+
style:
|
|
185
|
+
color: "var(--bs-danger, #dc3545)"
|
|
186
|
+
fontSize: "14px"
|
|
187
|
+
actions:
|
|
188
|
+
- what: hide
|
|
189
|
+
andConditions:
|
|
190
|
+
- when: ~.form.name
|
|
191
|
+
isNotEmpty:
|
|
192
|
+
- when: ~.form.email
|
|
193
|
+
isNotEmpty:
|
|
194
|
+
|
|
195
|
+
- type: button
|
|
196
|
+
content: "Submit"
|
|
197
|
+
attributes:
|
|
198
|
+
style:
|
|
199
|
+
border: "1px solid var(--bs-border-color, #dee2e6)"
|
|
200
|
+
padding: "8px 16px"
|
|
201
|
+
actions:
|
|
202
|
+
- what: hide
|
|
203
|
+
when: ~.form.name
|
|
204
|
+
isEmpty: true
|
|
205
|
+
- what: hide
|
|
206
|
+
when: ~.form.email
|
|
207
|
+
isEmpty: true
|
|
208
|
+
|
|
209
|
+
- type: div
|
|
210
|
+
content: "✅ Form submitted successfully!"
|
|
211
|
+
attributes:
|
|
212
|
+
style:
|
|
213
|
+
color: "var(--bs-success, #198754)"
|
|
214
|
+
marginTop: "10px"
|
|
215
|
+
fontWeight: "bold"
|
|
216
|
+
actions:
|
|
217
|
+
- what: hide
|
|
218
|
+
when: ~.submitted
|
|
219
|
+
isNot: true
|
|
220
|
+
|
|
221
|
+
data:
|
|
222
|
+
form:
|
|
223
|
+
name: ""
|
|
224
|
+
email: ""
|
|
225
|
+
submitted: false
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Conditional Operators {#conditional-operators}
|
|
229
|
+
|
|
230
|
+
Actions support the following conditional operators when using the `when` property:
|
|
231
|
+
|
|
232
|
+
- `is`: Value equals exactly the specified value.
|
|
233
|
+
- `isNot`: Value is different from the specified value.
|
|
234
|
+
- `isEmpty`: Value is empty (null, undefined, empty string, empty array, or empty object). The presence of the property is sufficient (value doesn't matter, can be `null` in JSON). Use `isEmpty:` to check if empty, or `isEmpty: "not"` to check if not empty (alternatively, use `isNotEmpty:`).
|
|
235
|
+
- `isNotEmpty`: Value is not empty (shorthand for `isEmpty: "not"`). The presence of the property is sufficient - the value doesn't matter and can be `null` in JSON.
|
|
236
|
+
- `contains`: Value contains the specified substring or array element.
|
|
237
|
+
- `containsNot`: Value does not contain the specified substring or array element.
|
|
238
|
+
- `containedBy`: Value is contained within the specified array or string.
|
|
239
|
+
- `containedByNot`: Value is not contained within the specified array or string.
|
|
240
|
+
- `>`: Value is greater than the specified number or date.
|
|
241
|
+
- `<`: Value is less than the specified number or date.
|
|
242
|
+
- `>=`: Value is greater than or equal to the specified number or date.
|
|
243
|
+
- `<=`: Value is less than or equal to the specified number or date.
|
|
244
|
+
- `andConditions` (array): All nested conditions must be true for the action to execute.
|
|
245
|
+
|
|
246
|
+
```yaml
|
|
247
|
+
# Example: Hide when both status is active AND user has admin role
|
|
248
|
+
andConditions:
|
|
249
|
+
- when: ~.status
|
|
250
|
+
is: "active"
|
|
251
|
+
- when: ~.user_role
|
|
252
|
+
is: "admin"
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
- `orConditions` (array): At least one nested condition must be true for the action to execute.
|
|
256
|
+
|
|
257
|
+
## Execution Order
|
|
258
|
+
- Actions are evaluated in the order they appear in the array.
|
|
259
|
+
- Conditions are evaluated before action execution.
|
|
260
|
+
- Some actions (like `hide`) prevent subsequent actions from executing.
|
|
261
|
+
|
|
262
|
+
### State-Driven Behavior
|
|
263
|
+
- Actions continuously evaluate their conditions based on current data.
|
|
264
|
+
- No explicit triggers needed - they respond automatically to data changes.
|
|
265
|
+
- Perfect for creating adaptive interfaces that respond to application state.
|
|
266
|
+
|
|
267
|
+
## Technical Limitations
|
|
268
|
+
|
|
269
|
+
1. **Execution order**: Actions are evaluated in definition order and cannot be reordered dynamically.
|
|
270
|
+
2. **Hide behavior**: Once an element is hidden with the `hide` action, no subsequent actions execute.
|
|
271
|
+
3. **Synchronous evaluation**: All conditions and actions are evaluated synchronously.
|
|
272
|
+
4. **Data scope**: Actions can only access data from the current template context and global context.
|
|
273
|
+
5. **No side effects**: Actions cannot directly modify global state or trigger reactions.
|
|
274
|
+
6. **External dependencies**: Some actions (tooltip, popover) require React Bootstrap components.
|
|
275
|
+
|
|
276
|
+
## Best Practices
|
|
277
|
+
|
|
278
|
+
1. **Keep conditions simple**: Avoid overly complex condition logic for better maintainability.
|
|
279
|
+
2. **Consider performance**: Minimize frequently-evaluated complex conditions.
|
|
280
|
+
3. **Use appropriate actions**: Choose `visuallyHide` over `hide` when content should remain accessible.
|
|
281
|
+
4. **Test thoroughly**: Verify action behavior with different data states.
|
|
282
|
+
5. **Document complex logic**: Add comments for non-obvious conditional logic.
|
|
283
|
+
6. **Order matters**: Place critical actions (like `hide`) early in the action array when appropriate.
|
|
284
|
+
|
|
285
|
+
## Next Steps
|
|
286
|
+
|
|
287
|
+
Now that you understand how actions work to adapt the UI based on application state, learn about **[Reactions](./reactions.md)** to handle user events and trigger behaviors in response to user interactions.
|
|
288
|
+
|
|
289
|
+
Actions and reactions work together to create fully interactive applications: actions provide state-driven UI adaptation, while reactions enable event-driven behavior.
|
|
290
|
+
|
|
291
|
+
## Related Documentation
|
|
292
|
+
|
|
293
|
+
- **[Reactions System](./reactions.md)**: Learn about handling user events and state changes.
|
|
294
|
+
- **[Template System](../getting-started/template-contexts-data-binding.md)**: Understand data binding and template expressions.
|