@ea-lab/reactive-json-docs 0.4.0 → 0.6.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 +5 -2
- package/public/rjbuild/docs/advanced-concepts/index.md +1 -0
- package/public/rjbuild/docs/advanced-concepts/index.yaml +1 -0
- package/public/rjbuild/docs/advanced-concepts/plugins/component-development.md +1 -1
- package/public/rjbuild/docs/advanced-concepts/plugins/component-development.yaml +1 -1
- package/public/rjbuild/docs/core/action/Attribute/SetAttributeValue.md +93 -0
- package/public/rjbuild/docs/core/action/Attribute/SetAttributeValue.yaml +141 -0
- package/public/rjbuild/docs/core/action/Attribute/ToggleAttributeValue.md +267 -0
- package/public/rjbuild/docs/core/action/Attribute/ToggleAttributeValue.yaml +244 -0
- package/public/rjbuild/docs/core/action/Attribute/UnsetAttribute.md +108 -0
- package/public/rjbuild/docs/core/action/Attribute/UnsetAttribute.yaml +135 -0
- package/public/rjbuild/docs/core/action/Attribute/UnsetAttributeValue.md +135 -0
- package/public/rjbuild/docs/core/action/Attribute/UnsetAttributeValue.yaml +185 -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 +24 -203
- package/public/rjbuild/docs/core/action/index.yaml +24 -263
- package/public/rjbuild/docs/core/element/form/DateField.md +1 -1
- package/public/rjbuild/docs/core/element/form/DateField.yaml +4 -4
- package/public/rjbuild/docs/core/element/form/SelectField.yaml +2 -2
- package/public/rjbuild/docs/core/example/website.yaml +10 -10
- package/public/rjbuild/docs/core/reaction/index.md +17 -229
- package/public/rjbuild/docs/core/reaction/index.yaml +14 -242
- package/public/rjbuild/docs/core/reaction/setData.md +1 -1
- package/public/rjbuild/docs/core/reaction/setData.yaml +1 -1
- package/public/rjbuild/docs/docs-components/index.md +0 -2
- package/public/rjbuild/docs/docs-components/index.yaml +0 -2
- package/public/rjbuild/docs/getting-started/actions.md +294 -0
- package/public/rjbuild/docs/getting-started/actions.yaml +403 -0
- package/public/rjbuild/docs/getting-started/index.md +30 -6
- package/public/rjbuild/docs/getting-started/index.yaml +20 -6
- package/public/rjbuild/docs/getting-started/reactions.md +301 -0
- package/public/rjbuild/docs/getting-started/reactions.yaml +300 -0
- package/public/rjbuild/docs/getting-started/rjbuild-structure.md +10 -4
- package/public/rjbuild/docs/getting-started/rjbuild-structure.yaml +10 -4
- package/public/rjbuild/docs/getting-started/{template.md → template-contexts-data-binding.md} +16 -12
- package/public/rjbuild/docs/getting-started/{template.yaml → template-contexts-data-binding.yaml} +28 -14
- /package/public/rjbuild/docs/{core/reaction → advanced-concepts}/forward-update.md +0 -0
- /package/public/rjbuild/docs/{core/reaction → advanced-concepts}/forward-update.yaml +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ea-lab/reactive-json-docs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Complete documentation for Reactive-JSON - Components, examples and LLM-parsable guides",
|
|
5
5
|
"main": "public/rjbuild/docs/index.yaml",
|
|
6
6
|
"files": [
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"private": false,
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@craco/craco": "^7.1.0",
|
|
29
|
-
"@ea-lab/reactive-json": "^0.
|
|
29
|
+
"@ea-lab/reactive-json": "^0.5.0",
|
|
30
30
|
"@ea-lab/reactive-json-chartjs": "^0.0.23",
|
|
31
31
|
"@npmcli/fs": "^4.0.0",
|
|
32
32
|
"@reduxjs/toolkit": "^2.6.1",
|
|
@@ -75,5 +75,8 @@
|
|
|
75
75
|
"last 1 firefox version",
|
|
76
76
|
"last 1 safari version"
|
|
77
77
|
]
|
|
78
|
+
},
|
|
79
|
+
"dependencies": {
|
|
80
|
+
"remark-gfm": "^4.0.1"
|
|
78
81
|
}
|
|
79
82
|
}
|
|
@@ -6,4 +6,5 @@ This section covers advanced features and concepts in Reactive-JSON that enable
|
|
|
6
6
|
|
|
7
7
|
- **[Data Mapping](data-mapping.md)**: Learn how to selectively dispatch and transform response data using the Data Mapping system
|
|
8
8
|
- **[Data Processors](data-processors.md)**: Learn how to intercept and modify data from HTTP requests using the DataProcessor system
|
|
9
|
+
- **[Forward Update](forward-update.md)**: Implementation details about the retrieval of event values.
|
|
9
10
|
- **[Plugins](plugins/index.md)**: Learn how to extend Reactive-JSON with custom components and plugins.
|
|
@@ -9,6 +9,7 @@ renderView:
|
|
|
9
9
|
|
|
10
10
|
- **[Data Mapping](data-mapping)**: Learn how to selectively dispatch and transform response data using the Data Mapping system.
|
|
11
11
|
- **[Data Processors](data-processors)**: Learn how to intercept and modify data from HTTP requests using the DataProcessor system.
|
|
12
|
+
- **[Forward Update](forward-update)**: Implementation details about the retrieval of event values.
|
|
12
13
|
- **[Plugins](plugins/index)**: Learn how to extend Reactive-JSON with custom components and plugins.
|
|
13
14
|
|
|
14
15
|
data:
|
|
@@ -19,7 +19,7 @@ All components have access to these React contexts:
|
|
|
19
19
|
- **TemplateContext**: Contains current template data for evaluation
|
|
20
20
|
|
|
21
21
|
Other specialized contexts are available.
|
|
22
|
-
- **EventDispatcherContext**: Centralized event handling system, mostly used by the [reaction system](/docs/
|
|
22
|
+
- **EventDispatcherContext**: Centralized event handling system, mostly used by the [reaction system](/docs/getting-started/reactions).
|
|
23
23
|
- **PaginationContext**: Used by components that integrate pagination, such as [Switch](/docs/core/element/special/Switch).
|
|
24
24
|
|
|
25
25
|
## Basic Element Component
|
|
@@ -22,7 +22,7 @@ renderView:
|
|
|
22
22
|
- **TemplateContext**: Contains current template data for evaluation
|
|
23
23
|
|
|
24
24
|
Other specialized contexts are available.
|
|
25
|
-
- **EventDispatcherContext**: Centralized event handling system, mostly used by the [reaction system](/docs/
|
|
25
|
+
- **EventDispatcherContext**: Centralized event handling system, mostly used by the [reaction system](/docs/getting-started/reactions).
|
|
26
26
|
- **PaginationContext**: Used by components that integrate pagination, such as [Switch](/docs/core/element/special/Switch).
|
|
27
27
|
|
|
28
28
|
## Basic Element Component
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# SetAttributeValue
|
|
2
|
+
|
|
3
|
+
Dynamically sets or modifies the value of an HTML attribute on an element.
|
|
4
|
+
|
|
5
|
+
## Basic Syntax
|
|
6
|
+
|
|
7
|
+
```yaml
|
|
8
|
+
actions:
|
|
9
|
+
# Add CSS class
|
|
10
|
+
- what: setAttributeValue
|
|
11
|
+
name: "class"
|
|
12
|
+
value: "active"
|
|
13
|
+
|
|
14
|
+
# Replace attribute value
|
|
15
|
+
- what: setAttributeValue
|
|
16
|
+
name: "data-status"
|
|
17
|
+
mode: "replace"
|
|
18
|
+
value: ~.currentStatus
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Properties
|
|
22
|
+
|
|
23
|
+
- **name** *(string, required)*: The name of the attribute to modify.
|
|
24
|
+
- **mode** *(string, optional)*: The modification mode. Default: `"append"`.
|
|
25
|
+
- `"append"`: Adds the value to the existing attribute value (space-separated).
|
|
26
|
+
- `"replace"`: Completely replaces the existing attribute value.
|
|
27
|
+
- **value** *(string, required)*: The value to set or append. Supports template evaluation (e.g., `~.dynamicValue`, `~~.globalValue`). Automatically converted to string if not already. Special characters are handled safely.
|
|
28
|
+
- **preventDuplicateValues** *(boolean, optional)*: When `true` (default), prevents duplicate values when using append mode.
|
|
29
|
+
- **separator** *(string, optional)*: The separator used between values. Default: `" "` (space).
|
|
30
|
+
|
|
31
|
+
## Behavior
|
|
32
|
+
|
|
33
|
+
- **Append mode**: Adds the new value to the existing attribute, separated by the specified separator.
|
|
34
|
+
- **Replace mode**: Completely overwrites the existing attribute value.
|
|
35
|
+
- **Duplicate prevention**: In append mode, prevents adding duplicate values when enabled.
|
|
36
|
+
|
|
37
|
+
## Common Use Cases
|
|
38
|
+
|
|
39
|
+
- **Dynamic CSS classes**: Adding/removing CSS classes based on state.
|
|
40
|
+
- **Data attributes**: Setting data-* attributes for JavaScript integration.
|
|
41
|
+
- **ARIA attributes**: Dynamically updating accessibility attributes.
|
|
42
|
+
- **Style attributes**: Modifying inline styles conditionally.
|
|
43
|
+
|
|
44
|
+
## Example
|
|
45
|
+
|
|
46
|
+
```yaml
|
|
47
|
+
renderView:
|
|
48
|
+
- type: input
|
|
49
|
+
attributes:
|
|
50
|
+
type: "text"
|
|
51
|
+
placeholder: "Start typing to see the highlighting..."
|
|
52
|
+
class: "sav-demo-input"
|
|
53
|
+
value: ~.input_data
|
|
54
|
+
style:
|
|
55
|
+
padding: "10px"
|
|
56
|
+
border: "2px solid #007bff"
|
|
57
|
+
borderRadius: "4px"
|
|
58
|
+
fontSize: "16px"
|
|
59
|
+
margin: "10px 0"
|
|
60
|
+
width: "300px"
|
|
61
|
+
display: "block"
|
|
62
|
+
actions:
|
|
63
|
+
- what: setData
|
|
64
|
+
on: change
|
|
65
|
+
path: ~.input_data
|
|
66
|
+
value: <reactive-json:event-new-value>
|
|
67
|
+
- what: setAttributeValue
|
|
68
|
+
name: "class"
|
|
69
|
+
value: "sav-highlighted"
|
|
70
|
+
when: ~.input_data
|
|
71
|
+
isNotEmpty:
|
|
72
|
+
|
|
73
|
+
- type: div
|
|
74
|
+
content: ~.input_data
|
|
75
|
+
|
|
76
|
+
- type: style
|
|
77
|
+
content: |
|
|
78
|
+
.sav-highlighted {
|
|
79
|
+
border-color: #28a745 !important;
|
|
80
|
+
outline: 2px solid #28a745 !important;
|
|
81
|
+
outline-offset: 2px !important;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
data:
|
|
85
|
+
input_data: ""
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Notes
|
|
89
|
+
|
|
90
|
+
- The action respects existing attribute values when using append mode.
|
|
91
|
+
- Use replace mode when you need complete control over the attribute value.
|
|
92
|
+
- Duplicate prevention only applies to append mode.
|
|
93
|
+
- The value property supports full template evaluation including `~.localData`, `~~.globalData`, `~>nearestKey`, and `~~>globalKey` patterns.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
renderView:
|
|
2
|
+
- type: Markdown
|
|
3
|
+
content: |
|
|
4
|
+
# SetAttributeValue
|
|
5
|
+
|
|
6
|
+
Dynamically sets or modifies the value of an HTML attribute on an element.
|
|
7
|
+
|
|
8
|
+
## Basic Syntax
|
|
9
|
+
|
|
10
|
+
- type: TabbedSerializer
|
|
11
|
+
yamlSerializedContent: |
|
|
12
|
+
actions:
|
|
13
|
+
# Add CSS class
|
|
14
|
+
- what: setAttributeValue
|
|
15
|
+
name: "class"
|
|
16
|
+
value: "active"
|
|
17
|
+
|
|
18
|
+
# Replace attribute value
|
|
19
|
+
- what: setAttributeValue
|
|
20
|
+
name: "data-status"
|
|
21
|
+
mode: "replace"
|
|
22
|
+
value: ~.currentStatus
|
|
23
|
+
|
|
24
|
+
- type: Markdown
|
|
25
|
+
content: |
|
|
26
|
+
## Properties
|
|
27
|
+
|
|
28
|
+
- type: DefinitionList
|
|
29
|
+
content:
|
|
30
|
+
- term:
|
|
31
|
+
code: name
|
|
32
|
+
after: "(string, required)"
|
|
33
|
+
details: The name of the attribute to modify.
|
|
34
|
+
- term:
|
|
35
|
+
code: mode
|
|
36
|
+
after: "(string, optional)"
|
|
37
|
+
details:
|
|
38
|
+
type: Markdown
|
|
39
|
+
content: |
|
|
40
|
+
The modification mode. Default: `"append"`
|
|
41
|
+
- `"append"`: Adds the value to the existing attribute value (space-separated)
|
|
42
|
+
- `"replace"`: Completely replaces the existing attribute value
|
|
43
|
+
- term:
|
|
44
|
+
code: value
|
|
45
|
+
after: "(string, required)"
|
|
46
|
+
details: The value to set or append. Supports template evaluation (e.g., `~.dynamicValue`, `~~.globalValue`). Automatically converted to string if not already. Special characters are handled safely.
|
|
47
|
+
- term:
|
|
48
|
+
code: preventDuplicateValues
|
|
49
|
+
after: "(boolean, optional)"
|
|
50
|
+
details:
|
|
51
|
+
type: Markdown
|
|
52
|
+
content: When `true` (default), prevents duplicate values when using append mode.
|
|
53
|
+
- term:
|
|
54
|
+
code: separator
|
|
55
|
+
after: "(string, optional)"
|
|
56
|
+
details:
|
|
57
|
+
type: Markdown
|
|
58
|
+
content: |
|
|
59
|
+
The separator used between values. Default: `" "` (space).
|
|
60
|
+
|
|
61
|
+
- type: Markdown
|
|
62
|
+
content: |
|
|
63
|
+
|
|
64
|
+
## Behavior
|
|
65
|
+
|
|
66
|
+
- **Append mode**: Adds the new value to the existing attribute, separated by the specified separator.
|
|
67
|
+
- **Replace mode**: Completely overwrites the existing attribute value.
|
|
68
|
+
- **Duplicate prevention**: In append mode, prevents adding duplicate values when enabled.
|
|
69
|
+
|
|
70
|
+
## Common Use Cases
|
|
71
|
+
|
|
72
|
+
- **Dynamic CSS classes**: Adding/removing CSS classes based on state.
|
|
73
|
+
- **Data attributes**: Setting data-* attributes for JavaScript integration.
|
|
74
|
+
- **ARIA attributes**: Dynamically updating accessibility attributes.
|
|
75
|
+
- **Style attributes**: Modifying inline styles conditionally.
|
|
76
|
+
|
|
77
|
+
- type: RjBuildDescriber
|
|
78
|
+
title: "SetAttributeValue Action Examples"
|
|
79
|
+
description:
|
|
80
|
+
- type: Markdown
|
|
81
|
+
content: |
|
|
82
|
+
This example demonstrates how to use the `SetAttributeValue` action to dynamically add CSS classes based on input content.
|
|
83
|
+
|
|
84
|
+
**Expected behavior:**
|
|
85
|
+
- Initially, the input field has normal appearance (base styling)
|
|
86
|
+
- Start typing in the input field
|
|
87
|
+
- When the field is not empty, the 'sav-highlighted' class is automatically added (visual highlighting)
|
|
88
|
+
- Clear the field to remove the highlighting
|
|
89
|
+
- The action uses append mode and responds to the `isNotEmpty` condition
|
|
90
|
+
|
|
91
|
+
Try typing and clearing the input to see how the class attribute changes automatically.
|
|
92
|
+
|
|
93
|
+
toDescribe:
|
|
94
|
+
renderView:
|
|
95
|
+
- type: input
|
|
96
|
+
attributes:
|
|
97
|
+
type: "text"
|
|
98
|
+
placeholder: "Start typing to see the highlighting..."
|
|
99
|
+
class: "sav-demo-input"
|
|
100
|
+
value: ~.input_data
|
|
101
|
+
style:
|
|
102
|
+
padding: "10px"
|
|
103
|
+
border: "2px solid #007bff"
|
|
104
|
+
borderRadius: "4px"
|
|
105
|
+
fontSize: "16px"
|
|
106
|
+
margin: "10px 0"
|
|
107
|
+
width: "300px"
|
|
108
|
+
display: "block"
|
|
109
|
+
actions:
|
|
110
|
+
- what: setData
|
|
111
|
+
on: change
|
|
112
|
+
path: ~.input_data
|
|
113
|
+
value: <reactive-json:event-new-value>
|
|
114
|
+
- what: setAttributeValue
|
|
115
|
+
name: "class"
|
|
116
|
+
value: "sav-highlighted"
|
|
117
|
+
when: ~.input_data
|
|
118
|
+
isNotEmpty:
|
|
119
|
+
|
|
120
|
+
- type: div
|
|
121
|
+
content: ~.input_data
|
|
122
|
+
|
|
123
|
+
- type: style
|
|
124
|
+
content: |
|
|
125
|
+
.sav-highlighted {
|
|
126
|
+
border-color: #28a745 !important;
|
|
127
|
+
outline: 2px solid #28a745 !important;
|
|
128
|
+
outline-offset: 2px !important;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
data:
|
|
132
|
+
input_data: ""
|
|
133
|
+
|
|
134
|
+
- type: Markdown
|
|
135
|
+
content: |
|
|
136
|
+
## Notes
|
|
137
|
+
|
|
138
|
+
- The action respects existing attribute values when using append mode.
|
|
139
|
+
- Use replace mode when you need complete control over the attribute value.
|
|
140
|
+
- Duplicate prevention only applies to append mode.
|
|
141
|
+
- The value property supports full template evaluation including `~.localData`, `~~.globalData`, `~>nearestKey`, and `~~>globalKey` patterns.
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# ToggleAttributeValue
|
|
2
|
+
|
|
3
|
+
Toggles the presence of a specific value in an HTML attribute. Supports both simple on-off toggles and cyclic toggling through multiple values.
|
|
4
|
+
|
|
5
|
+
## Important Notes
|
|
6
|
+
|
|
7
|
+
### Action-Based Behavior
|
|
8
|
+
`ToggleAttributeValue` is an **action component** that operates based on data state changes, not direct event triggers. It requires a state variable in your data to activate the toggle behavior. This means you cannot directly use `on: click` with `ToggleAttributeValue` - instead, you must use `setData` with `on: click` to change a state variable, then use `when/is` conditions on the toggle action to respond to that state change.
|
|
9
|
+
|
|
10
|
+
### Base Attribute Detection
|
|
11
|
+
`ToggleAttributeValue` determines what to toggle by examining the **original attributes** defined in your component's props, not the current DOM state. This means:
|
|
12
|
+
|
|
13
|
+
- ✅ **Stable behavior**: The toggle always works relative to the initial attribute values
|
|
14
|
+
- ✅ **No infinite loops**: Changes don't trigger recursive re-evaluation
|
|
15
|
+
- ⚠️ **Limitation**: The toggle cannot detect or work with values that were dynamically added by other attribute actions (`SetAttributeValue`, `UnsetAttributeValue`)
|
|
16
|
+
|
|
17
|
+
**Example**: If your component initially has `class="base"` and another action adds `"dynamic"`, the toggle will only work with `"base"` and won't see `"dynamic"`.
|
|
18
|
+
|
|
19
|
+
## Basic Syntax
|
|
20
|
+
|
|
21
|
+
```yaml
|
|
22
|
+
actions:
|
|
23
|
+
# Toggle CSS class.
|
|
24
|
+
- what: toggleAttributeValue
|
|
25
|
+
name: "class"
|
|
26
|
+
value: "active"
|
|
27
|
+
|
|
28
|
+
# Cyclic toggle with array.
|
|
29
|
+
- what: toggleAttributeValue
|
|
30
|
+
name: "class"
|
|
31
|
+
value: ["theme-light", "theme-dark", "theme-auto", ""]
|
|
32
|
+
|
|
33
|
+
# Keep attribute when empty.
|
|
34
|
+
- what: toggleAttributeValue
|
|
35
|
+
name: "data-optional"
|
|
36
|
+
value: "enabled"
|
|
37
|
+
keepAttributeWhenEmpty: true
|
|
38
|
+
|
|
39
|
+
# Conditional toggle.
|
|
40
|
+
- what: toggleAttributeValue
|
|
41
|
+
name: "data-features"
|
|
42
|
+
value: ~.featureName
|
|
43
|
+
when: ~.shouldToggle
|
|
44
|
+
is: true
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Properties
|
|
48
|
+
|
|
49
|
+
- **keepAttributeWhenEmpty** *(boolean, optional)*: Whether to keep the attribute when it becomes empty. If `false`, the attribute is removed when no values remain. Default: `false`.
|
|
50
|
+
- **name** *(string, required)*: The name of the attribute to modify.
|
|
51
|
+
- **separator** *(string, optional)*: The separator used between values. Default: `" "` (space).
|
|
52
|
+
- **value** *(string|array, required)*: The value(s) to toggle in the attribute. Can be a single string or an array of strings for cyclic toggling. Supports template evaluation (e.g., `~.dynamicValue`, `~~.globalValue`). Automatically converted to string if not already.
|
|
53
|
+
|
|
54
|
+
## Behavior
|
|
55
|
+
|
|
56
|
+
### Simple Toggle (string value)
|
|
57
|
+
- **Smart toggle**: Automatically adds the value if missing, removes it if present.
|
|
58
|
+
- **Preservation**: Other values in the attribute remain intact.
|
|
59
|
+
- **Empty handling**: By default, removes the entire attribute if no values remain. Set `keepAttributeWhenEmpty` to `true` to preserve empty attributes.
|
|
60
|
+
|
|
61
|
+
#### Common Examples
|
|
62
|
+
```yaml
|
|
63
|
+
# Toggle CSS class.
|
|
64
|
+
- what: toggleAttributeValue
|
|
65
|
+
name: "class"
|
|
66
|
+
value: "active"
|
|
67
|
+
|
|
68
|
+
# Toggle readonly attribute.
|
|
69
|
+
- what: toggleAttributeValue
|
|
70
|
+
name: "readonly"
|
|
71
|
+
value: "readonly"
|
|
72
|
+
|
|
73
|
+
# Toggle checked attribute.
|
|
74
|
+
- what: toggleAttributeValue
|
|
75
|
+
name: "checked"
|
|
76
|
+
value: "checked"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Cyclic Toggle (array value)
|
|
80
|
+
- **Cyclic behavior**: When `value` is an array, the action cycles through the values in order.
|
|
81
|
+
- **Sequential rotation**: Each toggle moves to the next value in the array.
|
|
82
|
+
- **Empty values handling**: Empty strings (`""`) in the array represent the absence of the value.
|
|
83
|
+
- **Clean detection**: Values are split by separator and empty values (from double separators) are filtered out during detection.
|
|
84
|
+
- **First match priority**: If multiple array values are already present, only the first detected value is replaced.
|
|
85
|
+
- **Default fallback**: If no array values are present, the first array value is applied.
|
|
86
|
+
- **Empty value filtering**: Attributes with empty values from double separators (e.g., `"val1,,val2,"`) are cleaned during detection, treating them as `"val1 val2"`.
|
|
87
|
+
- **Single value arrays**: Arrays with one value behave identically to string values (toggle between value and empty).
|
|
88
|
+
- **Empty string inclusion**: Including `""` in arrays explicitly defines an "empty state" in the cycle.
|
|
89
|
+
|
|
90
|
+
#### Array Behavior Examples
|
|
91
|
+
|
|
92
|
+
##### Four-step cycle with empty state
|
|
93
|
+
```yaml
|
|
94
|
+
# Starting with class="theme-light"
|
|
95
|
+
# Clicks will progress: theme-light → theme-dark → theme-auto → "" → theme-light → ...
|
|
96
|
+
value: ["theme-light", "theme-dark", "theme-auto", ""]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
##### Simple alternation
|
|
100
|
+
```yaml
|
|
101
|
+
# Starting with class="size-small"
|
|
102
|
+
# Clicks will alternate: size-small → size-large → size-small → ...
|
|
103
|
+
value: ["size-small", "size-large"]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
##### Single value array (equivalent to string)
|
|
107
|
+
```yaml
|
|
108
|
+
# Equivalent to value: "highlight"
|
|
109
|
+
# Toggles: highlight → "" → highlight → ...
|
|
110
|
+
value: ["highlight"]
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Common Use Cases
|
|
114
|
+
|
|
115
|
+
- **CSS class toggling**: Adding/removing CSS classes based on state changes.
|
|
116
|
+
- **Data attribute management**: Toggling specific values in space-separated data attributes.
|
|
117
|
+
- **Interactive styling**: Toggle styling classes for user interactions.
|
|
118
|
+
- **Feature flags**: Toggle feature-related classes or data attributes.
|
|
119
|
+
- **State cycling**: Cycle through multiple states (e.g., theme variants, size options).
|
|
120
|
+
- **Multi-step processes**: Progress through sequential steps with visual indicators.
|
|
121
|
+
|
|
122
|
+
## Examples
|
|
123
|
+
|
|
124
|
+
### Simple Toggle (string value)
|
|
125
|
+
```yaml
|
|
126
|
+
renderView:
|
|
127
|
+
- type: button
|
|
128
|
+
content: "Toggle 'active' class"
|
|
129
|
+
actions:
|
|
130
|
+
- what: setData
|
|
131
|
+
on: click
|
|
132
|
+
path: ~.toggleActive
|
|
133
|
+
value: "yes"
|
|
134
|
+
when: ~.toggleActive
|
|
135
|
+
is: "no"
|
|
136
|
+
- what: setData
|
|
137
|
+
on: click
|
|
138
|
+
path: ~.toggleActive
|
|
139
|
+
value: "no"
|
|
140
|
+
when: ~.toggleActive
|
|
141
|
+
is: "yes"
|
|
142
|
+
|
|
143
|
+
- type: div
|
|
144
|
+
content: "Element that toggles classes based on state"
|
|
145
|
+
attributes:
|
|
146
|
+
class: "base-class"
|
|
147
|
+
style:
|
|
148
|
+
padding: "10px"
|
|
149
|
+
border: "1px solid #ccc"
|
|
150
|
+
margin: "10px 0"
|
|
151
|
+
actions:
|
|
152
|
+
- what: toggleAttributeValue
|
|
153
|
+
name: "class"
|
|
154
|
+
value: "active"
|
|
155
|
+
when: ~.toggleActive
|
|
156
|
+
is: "yes"
|
|
157
|
+
|
|
158
|
+
data:
|
|
159
|
+
toggleActive: "no"
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Keep Attribute When Empty
|
|
163
|
+
```yaml
|
|
164
|
+
renderView:
|
|
165
|
+
- type: button
|
|
166
|
+
content: "Toggle data attribute (keeps when empty)"
|
|
167
|
+
actions:
|
|
168
|
+
- what: setData
|
|
169
|
+
on: click
|
|
170
|
+
path: ~.toggleFeature
|
|
171
|
+
value: "yes"
|
|
172
|
+
when: ~.toggleFeature
|
|
173
|
+
is: "no"
|
|
174
|
+
- what: setData
|
|
175
|
+
on: click
|
|
176
|
+
path: ~.toggleFeature
|
|
177
|
+
value: "no"
|
|
178
|
+
when: ~.toggleFeature
|
|
179
|
+
is: "yes"
|
|
180
|
+
|
|
181
|
+
- type: div
|
|
182
|
+
content: "Element with preserved attribute"
|
|
183
|
+
attributes:
|
|
184
|
+
data-feature: "enabled"
|
|
185
|
+
style:
|
|
186
|
+
padding: "10px"
|
|
187
|
+
border: "1px solid #999"
|
|
188
|
+
margin: "10px 0"
|
|
189
|
+
actions:
|
|
190
|
+
- what: toggleAttributeValue
|
|
191
|
+
name: "data-feature"
|
|
192
|
+
value: "enabled"
|
|
193
|
+
keepAttributeWhenEmpty: true
|
|
194
|
+
when: ~.toggleFeature
|
|
195
|
+
is: "yes"
|
|
196
|
+
|
|
197
|
+
data:
|
|
198
|
+
toggleFeature: "no"
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Cyclic Toggle (array value)
|
|
202
|
+
```yaml
|
|
203
|
+
renderView:
|
|
204
|
+
- type: button
|
|
205
|
+
content: "Cycle through themes"
|
|
206
|
+
actions:
|
|
207
|
+
- what: setData
|
|
208
|
+
on: click
|
|
209
|
+
path: ~.cycleThemes
|
|
210
|
+
value: "yes"
|
|
211
|
+
when: ~.cycleThemes
|
|
212
|
+
is: "no"
|
|
213
|
+
- what: setData
|
|
214
|
+
on: click
|
|
215
|
+
path: ~.cycleThemes
|
|
216
|
+
value: "no"
|
|
217
|
+
when: ~.cycleThemes
|
|
218
|
+
is: "yes"
|
|
219
|
+
|
|
220
|
+
- type: div
|
|
221
|
+
content: "Element that cycles through theme classes"
|
|
222
|
+
attributes:
|
|
223
|
+
class: "theme-light"
|
|
224
|
+
actions:
|
|
225
|
+
- what: toggleAttributeValue
|
|
226
|
+
name: "class"
|
|
227
|
+
value: ["theme-light", "theme-dark", "theme-auto", ""]
|
|
228
|
+
when: ~.cycleThemes
|
|
229
|
+
is: "yes"
|
|
230
|
+
|
|
231
|
+
- type: button
|
|
232
|
+
content: "Alternate between sizes"
|
|
233
|
+
actions:
|
|
234
|
+
- what: setData
|
|
235
|
+
on: click
|
|
236
|
+
path: ~.alternateSizes
|
|
237
|
+
value: "yes"
|
|
238
|
+
when: ~.alternateSizes
|
|
239
|
+
is: "no"
|
|
240
|
+
- what: setData
|
|
241
|
+
on: click
|
|
242
|
+
path: ~.alternateSizes
|
|
243
|
+
value: "no"
|
|
244
|
+
when: ~.alternateSizes
|
|
245
|
+
is: "yes"
|
|
246
|
+
|
|
247
|
+
- type: div
|
|
248
|
+
content: "Element that alternates between size classes"
|
|
249
|
+
attributes:
|
|
250
|
+
class: "size-small"
|
|
251
|
+
actions:
|
|
252
|
+
- what: toggleAttributeValue
|
|
253
|
+
name: "class"
|
|
254
|
+
value: ["size-small", "size-large"]
|
|
255
|
+
when: ~.alternateSizes
|
|
256
|
+
is: "yes"
|
|
257
|
+
|
|
258
|
+
data:
|
|
259
|
+
cycleThemes: "no"
|
|
260
|
+
alternateSizes: "no"
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Notes
|
|
264
|
+
|
|
265
|
+
- The `value` property supports full template evaluation including `~.localData`, `~~.globalData`, `~>nearestKey`, and `~~>globalKey` patterns.
|
|
266
|
+
- More efficient than separate SetAttributeValue/UnsetAttributeValue actions for toggle scenarios.
|
|
267
|
+
- Works with any space-separated attribute values (class, data attributes, etc.).
|