@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.
Files changed (93) hide show
  1. package/README-npm.md +49 -0
  2. package/README.md +86 -0
  3. package/package.json +79 -0
  4. package/public/rjbuild/component-doc/chartjs/components.yaml +252 -0
  5. package/public/rjbuild/component-doc/chartjs/overview.yaml +51 -0
  6. package/public/rjbuild/component-doc/core/action/HashChangeListener.md +90 -0
  7. package/public/rjbuild/component-doc/core/action/HashChangeListener.yaml +124 -0
  8. package/public/rjbuild/component-doc/core/action/Hide.md +22 -0
  9. package/public/rjbuild/component-doc/core/action/Hide.yaml +60 -0
  10. package/public/rjbuild/component-doc/core/action/MessageListener.md +93 -0
  11. package/public/rjbuild/component-doc/core/action/MessageListener.yaml +153 -0
  12. package/public/rjbuild/component-doc/core/action/Popover.md +26 -0
  13. package/public/rjbuild/component-doc/core/action/Popover.yaml +100 -0
  14. package/public/rjbuild/component-doc/core/action/ReactOnEvent.md +81 -0
  15. package/public/rjbuild/component-doc/core/action/ReactOnEvent.yaml +133 -0
  16. package/public/rjbuild/component-doc/core/action/Redirect.md +20 -0
  17. package/public/rjbuild/component-doc/core/action/Redirect.yaml +68 -0
  18. package/public/rjbuild/component-doc/core/action/Tooltip.md +22 -0
  19. package/public/rjbuild/component-doc/core/action/Tooltip.yaml +90 -0
  20. package/public/rjbuild/component-doc/core/action/VisuallyHide.md +21 -0
  21. package/public/rjbuild/component-doc/core/action/VisuallyHide.yaml +62 -0
  22. package/public/rjbuild/component-doc/core/action/index.md +214 -0
  23. package/public/rjbuild/component-doc/core/action/index.yaml +278 -0
  24. package/public/rjbuild/component-doc/core/element/form/CheckBoxField.md +276 -0
  25. package/public/rjbuild/component-doc/core/element/form/CheckBoxField.yaml +338 -0
  26. package/public/rjbuild/component-doc/core/element/form/DateField.md +189 -0
  27. package/public/rjbuild/component-doc/core/element/form/DateField.yaml +264 -0
  28. package/public/rjbuild/component-doc/core/element/form/NumberField.md +136 -0
  29. package/public/rjbuild/component-doc/core/element/form/NumberField.yaml +103 -0
  30. package/public/rjbuild/component-doc/core/element/form/SelectField.md +304 -0
  31. package/public/rjbuild/component-doc/core/element/form/SelectField.yaml +360 -0
  32. package/public/rjbuild/component-doc/core/element/form/TextAreaField.md +134 -0
  33. package/public/rjbuild/component-doc/core/element/form/TextAreaField.yaml +146 -0
  34. package/public/rjbuild/component-doc/core/element/form/TextField.md +129 -0
  35. package/public/rjbuild/component-doc/core/element/form/TextField.yaml +147 -0
  36. package/public/rjbuild/component-doc/core/element/form/formElementsCommon.md +106 -0
  37. package/public/rjbuild/component-doc/core/element/form/index.md +50 -0
  38. package/public/rjbuild/component-doc/core/element/form/index.yaml +96 -0
  39. package/public/rjbuild/component-doc/core/element/html/AccordionItem.yaml +47 -0
  40. package/public/rjbuild/component-doc/core/element/html/FolderSortableTree.yaml +81 -0
  41. package/public/rjbuild/component-doc/core/element/html/FormatNumeral.yaml +58 -0
  42. package/public/rjbuild/component-doc/core/element/html/Html.yaml +67 -0
  43. package/public/rjbuild/component-doc/core/element/html/LabelFromValue.yaml +54 -0
  44. package/public/rjbuild/component-doc/core/element/html/Modal.yaml +93 -0
  45. package/public/rjbuild/component-doc/core/element/html/PreformattedMarkup.yaml +37 -0
  46. package/public/rjbuild/component-doc/core/element/html/SortableTreeItemCollapseButton.yaml +92 -0
  47. package/public/rjbuild/component-doc/core/element/html/Tabs.yaml +57 -0
  48. package/public/rjbuild/component-doc/core/element/special/BootstrapElement.md +17 -0
  49. package/public/rjbuild/component-doc/core/element/special/BootstrapElement.yaml +18 -0
  50. package/public/rjbuild/component-doc/core/element/special/Count.md +37 -0
  51. package/public/rjbuild/component-doc/core/element/special/Count.yaml +325 -0
  52. package/public/rjbuild/component-doc/core/element/special/DataFilter.md +149 -0
  53. package/public/rjbuild/component-doc/core/element/special/DataFilter.yaml +315 -0
  54. package/public/rjbuild/component-doc/core/element/special/DelayedActions.md +51 -0
  55. package/public/rjbuild/component-doc/core/element/special/DelayedActions.yaml +55 -0
  56. package/public/rjbuild/component-doc/core/element/special/PageControls.md +126 -0
  57. package/public/rjbuild/component-doc/core/element/special/PageControls.yaml +133 -0
  58. package/public/rjbuild/component-doc/core/element/special/Phantom.md +31 -0
  59. package/public/rjbuild/component-doc/core/element/special/Phantom.yaml +34 -0
  60. package/public/rjbuild/component-doc/core/element/special/ReactiveJsonSubroot.md +27 -0
  61. package/public/rjbuild/component-doc/core/element/special/ReactiveJsonSubroot.yaml +51 -0
  62. package/public/rjbuild/component-doc/core/element/special/Switch.md +262 -0
  63. package/public/rjbuild/component-doc/core/element/special/Switch.yaml +348 -0
  64. package/public/rjbuild/component-doc/core/example/accordion.md +96 -0
  65. package/public/rjbuild/component-doc/core/example/accordion.yaml +64 -0
  66. package/public/rjbuild/component-doc/core/example/dynamic-content.md +197 -0
  67. package/public/rjbuild/component-doc/core/example/dynamic-content.yaml +237 -0
  68. package/public/rjbuild/component-doc/core/example/html.md +66 -0
  69. package/public/rjbuild/component-doc/core/example/html.yaml +83 -0
  70. package/public/rjbuild/component-doc/core/example/website.yaml +1663 -0
  71. package/public/rjbuild/component-doc/core/reaction/addData.md +96 -0
  72. package/public/rjbuild/component-doc/core/reaction/addData.yaml +133 -0
  73. package/public/rjbuild/component-doc/core/reaction/fetchData.md +60 -0
  74. package/public/rjbuild/component-doc/core/reaction/fetchData.yaml +156 -0
  75. package/public/rjbuild/component-doc/core/reaction/index.md +236 -0
  76. package/public/rjbuild/component-doc/core/reaction/index.yaml +254 -0
  77. package/public/rjbuild/component-doc/core/reaction/moveData.md +68 -0
  78. package/public/rjbuild/component-doc/core/reaction/moveData.yaml +71 -0
  79. package/public/rjbuild/component-doc/core/reaction/postMessage.md +63 -0
  80. package/public/rjbuild/component-doc/core/reaction/postMessage.yaml +68 -0
  81. package/public/rjbuild/component-doc/core/reaction/redirectNow.md +37 -0
  82. package/public/rjbuild/component-doc/core/reaction/redirectNow.yaml +37 -0
  83. package/public/rjbuild/component-doc/core/reaction/removeData.md +78 -0
  84. package/public/rjbuild/component-doc/core/reaction/removeData.yaml +56 -0
  85. package/public/rjbuild/component-doc/core/reaction/setClipboardData.md +44 -0
  86. package/public/rjbuild/component-doc/core/reaction/setClipboardData.yaml +41 -0
  87. package/public/rjbuild/component-doc/core/reaction/setData.md +93 -0
  88. package/public/rjbuild/component-doc/core/reaction/setData.yaml +85 -0
  89. package/public/rjbuild/component-doc/core/reaction/submitData.md +138 -0
  90. package/public/rjbuild/component-doc/core/reaction/submitData.yaml +141 -0
  91. package/public/rjbuild/component-doc/core/reaction/triggerEvent.md +59 -0
  92. package/public/rjbuild/component-doc/core/reaction/triggerEvent.yaml +59 -0
  93. package/public/rjbuild/component-doc/index.yaml +13 -0
@@ -0,0 +1,254 @@
1
+ renderView:
2
+ - type: Markdown
3
+ content: |
4
+ # Reactive-JSON Reactions System Documentation
5
+
6
+ ## Introduction
7
+
8
+ 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.
9
+
10
+ Reactions enable you to create interactive interfaces that respond to user input, modify application state, communicate with servers, and control browser behavior - all through JSON configuration.
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:
58
+
59
+ ### 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
64
+
65
+ ### 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
68
+
69
+ ### 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)
@@ -0,0 +1,68 @@
1
+ # Reaction: moveData
2
+
3
+ ## Introduction
4
+
5
+ The `moveData` reaction changes the position of an element within an array in the global data context. This is particularly useful for reordering items in a list, for example, moving an item up or down. Like `removeData`, it can operate in `path` mode or `target` mode.
6
+
7
+ ## Properties
8
+
9
+ - `what` (string, required): The name of the reaction, which must be `moveData`.
10
+ - `on` (string, required): The name of the event that triggers the reaction.
11
+ - `path` (string, optional): The path to the array element to move. Required if `target` is not used.
12
+ - `target` (string, optional): If set to `currentTemplateData`, the reaction will target the data associated with the current template item.
13
+ - `parentLevel` (number, optional): Used with `target: 'currentTemplateData'`. Specifies how many levels to go up from the current data path to find the element to move.
14
+ - `increment` (integer, required): The number of positions to move the element. A positive integer moves it down (towards the end of the array), and a negative integer moves it up (towards the beginning).
15
+
16
+ ## Behavior
17
+
18
+ - When triggered, `moveData` repositions an element within an array.
19
+ - **Path Mode**: Identifies the element to move using its full `path`.
20
+ - **Target Mode**: Identifies the element using `target: 'currentTemplateData'`, typically within a `Switch`.
21
+ - The `increment` value determines the direction and magnitude of the move. For example, `increment: 1` moves the item one position down, and `increment: -1` moves it one position up.
22
+ - The reaction has no effect if the target is not an array or if the move is out of bounds.
23
+
24
+ ## Example
25
+
26
+ ### Moving an item in a list
27
+
28
+ This example demonstrates how to move items up and down in a to-do list. Each item has "Up" and "Down" buttons that trigger the `moveData` reaction.
29
+
30
+ ```yaml
31
+ renderView:
32
+ - type: Switch
33
+ content: ~.todos
34
+ singleOption:
35
+ load: todo_item
36
+ templates:
37
+ todo_item:
38
+ type: div
39
+ content:
40
+ - ~.text
41
+ - type: button
42
+ content: "Up"
43
+ attributes: { style: "margin-left: 10px;" }
44
+ actions:
45
+ - what: moveData
46
+ on: click
47
+ target: currentTemplateData
48
+ increment: -1
49
+ - type: button
50
+ content: "Down"
51
+ attributes: { style: "margin-left: 5px;" }
52
+ actions:
53
+ - what: moveData
54
+ on: click
55
+ target: currentTemplateData
56
+ increment: 1
57
+ data:
58
+ todos:
59
+ - text: "Buy milk"
60
+ - text: "Learn Reactive-JSON"
61
+ - text: "Build an app"
62
+ ```
63
+
64
+ ## Limitations
65
+
66
+ - The target data must be an element within an array. The reaction will not work on objects.
67
+ - An `increment` must be provided.
68
+ - Moving an element past the beginning or end of the array has no effect (e.g., moving the first item up).
@@ -0,0 +1,71 @@
1
+ renderView:
2
+ - type: Markdown
3
+ content: |
4
+ # Reaction: moveData
5
+
6
+ The `moveData` reaction changes the position of an element within an array in the global data context.
7
+
8
+ ## Properties
9
+
10
+ - `what` (string, required): The name of the reaction, which must be `moveData`.
11
+ - `on` (string, required): The name of the event that triggers the reaction.
12
+ - `path` (string, optional): The path to the array element to move. Required if `target` is not used.
13
+ - `target` (string, optional): If set to `currentTemplateData`, the reaction will target the data associated with the current template item.
14
+ - `parentLevel` (number, optional): Used with `target: 'currentTemplateData'`. Specifies how many levels to go up from the current data path to find the element to move.
15
+ - `increment` (integer, required): The number of positions to move the element. A positive integer moves it down (towards the end of the array), and a negative integer moves it up (towards the beginning).
16
+
17
+ ## Behavior
18
+
19
+ - When triggered, `moveData` repositions an element within an array.
20
+ - **Path Mode**: Identifies the element to move using its full `path`.
21
+ - **Target Mode**: Identifies the element using `target: 'currentTemplateData'`, typically within a `Switch`.
22
+ - The `increment` value determines the direction and magnitude of the move. For example, `increment: 1` moves the item one position down, and `increment: -1` moves it one position up.
23
+ - The reaction has no effect if the target is not an array or if the move is out of bounds.
24
+
25
+ ## Limitations
26
+
27
+ - The target data must be an element within an array. The reaction will not work on objects.
28
+ - An `increment` must be provided.
29
+ - Moving an element past the beginning or end of the array has no effect (e.g., moving the first item up).
30
+
31
+ - type: RjBuildDescriber
32
+ title: "Moving an item in a list"
33
+ description: |
34
+ This example demonstrates how to move items up and down in a to-do list.
35
+ Each item has "Up" and "Down" buttons that trigger the `moveData` reaction with an `increment` of -1 or 1.
36
+ toDescribe:
37
+ renderView:
38
+ - type: Switch
39
+ content: ~.todos
40
+ singleOption:
41
+ load: todo_item
42
+ templates:
43
+ todo_item:
44
+ type: div
45
+ content:
46
+ - ~.text
47
+ - type: button
48
+ content: "Up"
49
+ attributes:
50
+ style:
51
+ marginLeft: 10px
52
+ actions:
53
+ - what: moveData
54
+ on: click
55
+ target: currentTemplateData
56
+ increment: -1
57
+ - type: button
58
+ content: "Down"
59
+ attributes:
60
+ style:
61
+ marginLeft: 5px
62
+ actions:
63
+ - what: moveData
64
+ on: click
65
+ target: currentTemplateData
66
+ increment: 1
67
+ data:
68
+ todos:
69
+ - text: "Buy milk"
70
+ - text: "Learn Reactive-JSON"
71
+ - text: "Build an app"
@@ -0,0 +1,63 @@
1
+ # Reaction: postMessage
2
+
3
+ ## Introduction
4
+
5
+ The `postMessage` reaction sends a message to another window or frame using the standard `window.postMessage` Web API. This is useful for communication between your Reactive-JSON application and a parent window (if embedded in an iframe) or for other cross-origin communication scenarios.
6
+
7
+ ## Properties
8
+
9
+ - `what` (string, required): The name of the reaction, must be `postMessage`.
10
+ - `on` (string, required): The event that triggers the reaction (e.g., `click`, `change`).
11
+ - `message` (any, required): The data to send as the message. This value is evaluated and can be any serializable type (string, number, object, array).
12
+ - `messageTarget` (string, optional): The target window for the message. Can be `'parent'` (the default) or `'self'`.
13
+ - `targetOrigin` (string, optional): Specifies the origin of the target window for security. Defaults to the current window's origin (`window.location.origin`). Use `"*"` for any origin, but be aware of the security implications.
14
+ - `includeChangedValue` (boolean, optional): If the trigger event is `change` on an input element, setting this to `true` will add the input's new value to the message payload under the key `changedValue`. Currently, this is only supported for checkboxes.
15
+
16
+ ## Behavior
17
+
18
+ - When triggered, the reaction evaluates the `message` content.
19
+ - It identifies the target window based on `messageTarget` and the target origin from `targetOrigin`.
20
+ - It sends the evaluated message to the target window using `postMessage`.
21
+ - If `includeChangedValue` is true and the event is a `change` on a supported input, the input's value is added to the message.
22
+
23
+ ## Testing Messages
24
+
25
+ To verify that messages are being sent correctly, you can add a message event listener in the browser's console:
26
+
27
+ ```javascript
28
+ window.addEventListener("message", (evt) => {
29
+ console.log("Event data:", JSON.stringify(evt.data));
30
+ });
31
+ ```
32
+
33
+ This will log all received messages to the console, making it easy to debug and verify the message content.
34
+
35
+ ## Example
36
+
37
+ ### Sending a message to a parent window
38
+
39
+ This example shows how to send a message to a parent frame when a button is clicked. A parent window would need to set up a `message` event listener to receive this data.
40
+
41
+ ```yaml
42
+ renderView:
43
+ - type: button
44
+ content: "Send Data to Parent"
45
+ actions:
46
+ - what: postMessage
47
+ on: click
48
+ message:
49
+ type: "userAction"
50
+ payload:
51
+ user: ~.user.name
52
+ action: "confirm"
53
+ # targetOrigin: "https://parent.example.com" # Should be set for security
54
+ data:
55
+ user:
56
+ name: "Alice"
57
+ ```
58
+
59
+ ## Limitations
60
+
61
+ - The receiving window must implement an event listener for the `"message"` event to handle the incoming data.
62
+ - For security, you should always specify a precise `targetOrigin` rather than using `*` when possible.
63
+ - `includeChangedValue` currently only supports checkboxes. Other input types are not yet implemented.
@@ -0,0 +1,68 @@
1
+ renderView:
2
+ - type: Markdown
3
+ content: |
4
+ # Reaction: postMessage
5
+
6
+ The `postMessage` reaction sends a message to another window or frame using the standard `window.postMessage` Web API.
7
+
8
+ - type: BsAlert
9
+ attributes:
10
+ variant: warning
11
+ content:
12
+ - type: Markdown
13
+ content: |
14
+ **Security warning:**
15
+ The `postMessage` API requires special attention to security. Always set a precise `targetOrigin` and validate the origin and content of received messages. See the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#security_concerns) for best practices.
16
+
17
+ - type: Markdown
18
+ content: |
19
+ ## Properties
20
+ - `what` (string, required): The name of the reaction, must be `postMessage`.
21
+ - `on` (string, required): The event that triggers the reaction (e.g., `click`, `change`).
22
+ - `message` (any, required): The data to send as the message. This value is evaluated and can be any serializable type (string, number, object, array).
23
+ - `messageTarget` (string, optional): The target window for the message. Can be `'parent'` (the default) or `'self'`.
24
+ - `targetOrigin` (string, optional): Specifies the origin of the target window for security. Defaults to the current window's origin (`window.location.origin`). Use `"*"` for any origin, but be aware of the security implications.
25
+ - `includeChangedValue` (boolean, optional): If the trigger event is `change` on an input element, setting this to `true` will add the input's new value to the message payload under the key `changedValue`. Currently, this is only supported for checkboxes.
26
+
27
+ ## Behavior
28
+ - When triggered, the reaction evaluates the `message` content.
29
+ - It identifies the target window based on `messageTarget` and the target origin from `targetOrigin`.
30
+ - It sends the evaluated message to the target window using `postMessage`.
31
+ - If `includeChangedValue` is true and the event is a `change` on a supported input, the input's value is added to the message.
32
+
33
+ ## Limitations
34
+ - The receiving window must implement an event listener for the `"message"` event to handle the incoming data.
35
+ - For security, you should always specify a precise `targetOrigin` rather than using `*` when possible.
36
+ - `includeChangedValue` currently only supports checkboxes. Other input types are not yet implemented.
37
+
38
+ - type: RjBuildDescriber
39
+ title: "Sending a message to the same window"
40
+ description:
41
+ - type: Markdown
42
+ content: |
43
+ This example shows how to send a message to the same window when a button is clicked.
44
+ The current window would need to set up a `message` event listener to receive this data.
45
+
46
+ To verify that messages are being sent correctly, you can open your browser's console and paste this code:
47
+ ```javascript
48
+ window.addEventListener("message", (evt) => {
49
+ console.log("Event data:", JSON.stringify(evt.data));
50
+ });
51
+ ```
52
+ Then try the example below and watch the console for messages.
53
+
54
+ toDescribe:
55
+ renderView:
56
+ - type: button
57
+ content: "Send Data"
58
+ actions:
59
+ - what: postMessage
60
+ on: click
61
+ message:
62
+ type: "userAction"
63
+ payload:
64
+ user: "Alice"
65
+ action: "confirm"
66
+ # targetOrigin: "https://parent.example.com" # Should be set for security
67
+ messageTarget: self # For demo purposes, we target self
68
+
@@ -0,0 +1,37 @@
1
+ # Reaction: redirectNow
2
+
3
+ ## Introduction
4
+
5
+ The `redirectNow` reaction performs an immediate browser redirection to a specified URL. It is useful for navigating to a new page after an action is completed, such as after submitting a form or clicking a link.
6
+
7
+ ## Properties
8
+
9
+ - `what` (string, required): The name of the reaction, which must be `redirectNow`.
10
+ - `on` (string, required): The name of the event that triggers the reaction (e.g., `click`).
11
+ - `to` (string, required): The URL to redirect to. This value is evaluated, so it can be a static URL or dynamically constructed from data.
12
+
13
+ ## Behavior
14
+
15
+ - When triggered, the reaction evaluates the `to` property to get the target URL.
16
+ - It then sets `window.location.href` to the resulting URL, causing the browser to navigate to the new page.
17
+
18
+ ## Example
19
+
20
+ ### Redirecting to a URL
21
+
22
+ This example shows a button that redirects the user to the Reactive-JSON GitHub page when clicked.
23
+
24
+ ```yaml
25
+ renderView:
26
+ - type: button
27
+ content: "Visit GitHub"
28
+ actions:
29
+ - what: redirectNow
30
+ on: click
31
+ to: "https://github.com/reactive-json/reactive-json"
32
+ ```
33
+
34
+ ## Limitations
35
+
36
+ - The `to` property must resolve to a valid URL string for the redirection to work.
37
+ - This action causes a full page reload, which will reset the entire application state.
@@ -0,0 +1,37 @@
1
+ renderView:
2
+ - type: Markdown
3
+ content: |
4
+ # Reaction: redirectNow
5
+
6
+ The `redirectNow` reaction performs an immediate browser redirection to a specified URL.
7
+
8
+ ## Properties
9
+
10
+ - `what` (string, required): The name of the reaction, which must be `redirectNow`.
11
+ - `on` (string, required): The name of the event that triggers the reaction (e.g., `click`).
12
+ - `to` (string, required): The URL to redirect to. This value is evaluated, so it can be a static URL or dynamically constructed from data.
13
+
14
+ ## Behavior
15
+
16
+ - When triggered, the reaction evaluates the `to` property to get the target URL.
17
+ - It then sets `window.location.href` to the resulting URL, causing the browser to navigate to the new page.
18
+
19
+ ## Limitations
20
+
21
+ - The `to` property must resolve to a valid URL string for the redirection to work.
22
+ - This action causes a full page reload, which will reset the entire application state.
23
+
24
+ **Note**: Since this example performs a real redirection, clicking the button will navigate you away from this page.
25
+
26
+ - type: RjBuildDescriber
27
+ title: "Redirecting to a URL"
28
+ description: "This example shows a button that redirects the user to the Reactive-JSON GitHub page when clicked."
29
+ toDescribe:
30
+ renderView:
31
+ - type: button
32
+ content: "Visit GitHub"
33
+ actions:
34
+ - what: redirectNow
35
+ on: click
36
+ to: "https://github.com/reactive-json/reactive-json"
37
+
@@ -0,0 +1,78 @@
1
+ # Reaction: removeData
2
+
3
+ ## Introduction
4
+
5
+ The `removeData` reaction deletes data from a specific location in the global data context. It is essential for dynamically managing lists, removing items, or clearing parts of the application state. It can operate in two modes: `path` mode (to target a specific data location) or `target` mode (to target the current template's data).
6
+
7
+ ## Properties
8
+
9
+ - `what` (string, required): The name of the reaction, which must be `removeData`.
10
+ - `on` (string, required): The name of the event that triggers the reaction (e.g., `click`).
11
+ - `path` (string, optional): The target location in the data context to delete. Required if `target` is not used.
12
+ - `target` (string, optional): If set to `currentTemplateData`, the reaction will remove the data associated with the current template item.
13
+ - `parentLevel` (number, optional): Used with `target: 'currentTemplateData'`. Specifies how many levels to go up from the current data path before removing. `0` means the current level.
14
+
15
+ ## Behavior
16
+
17
+ - When triggered, `removeData` deletes the data at the specified location.
18
+ - **Path Mode**: If `path` is provided, the data at that exact location is removed.
19
+ - **Target Mode**:
20
+ - If `target` is `'currentTemplateData'`, the reaction targets the data of the component triggering the action.
21
+ - `parentLevel` can be used to traverse up the data hierarchy. For example, in a list of items, `parentLevel: 0` would target the item itself, allowing for its deletion from the parent list/object.
22
+
23
+ ## Examples
24
+
25
+ ### 1. Using `path` to remove a specific key
26
+
27
+ This example shows how to delete a specific user profile field by clicking a button.
28
+
29
+ ```yaml
30
+ renderView:
31
+ - type: div
32
+ content: "User email: ~.user.email"
33
+ - type: button
34
+ content: "Remove Email"
35
+ actions:
36
+ - what: removeData
37
+ on: click
38
+ path: ~.user.email
39
+ data:
40
+ user:
41
+ name: "John Doe"
42
+ email: "john.doe@example.com"
43
+ ```
44
+
45
+ ### 2. Using `target` to remove an item from a list
46
+
47
+ This example shows a list of users where each user can be removed by clicking a "Remove" button next to their name. The reaction targets the current item in the iteration.
48
+
49
+ ```yaml
50
+ renderView:
51
+ - type: Switch
52
+ content: ~.users
53
+ singleOption:
54
+ load: user_item
55
+ templates:
56
+ user_item:
57
+ type: div
58
+ content:
59
+ - ~.name
60
+ - type: button
61
+ content: "Remove"
62
+ attributes: { style: "margin-left: 10px;" }
63
+ actions:
64
+ - what: removeData
65
+ on: click
66
+ target: currentTemplateData
67
+ parentLevel: 0
68
+ data:
69
+ users:
70
+ - name: "Alice"
71
+ - name: "Bob"
72
+ - name: "Charlie"
73
+ ```
74
+
75
+ ## Limitations
76
+
77
+ - Either `path` or `target` must be provided for the reaction to work.
78
+ - In `target` mode, if `parentLevel` goes beyond the root of the data, the reaction will do nothing.