powerpagestoolkit 1.3.201 → 1.3.203
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.md +61 -33
- package/index.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,8 +59,15 @@ target: HTMLElement | string;
|
|
|
59
59
|
element: HTMLElement;
|
|
60
60
|
isLoaded: boolean;
|
|
61
61
|
value: any;
|
|
62
|
+
/**
|
|
63
|
+
* If the element targeted is the main input for a yes/no radio control,
|
|
64
|
+
* yesRadio and noRadio will be available as properties of 'this'
|
|
65
|
+
*/
|
|
62
66
|
yesRadio: DOMNodeReference;
|
|
63
67
|
noRadio: DOMNodeReference;
|
|
68
|
+
// and if 'this' is the instance of a yesRadio or noRadio
|
|
69
|
+
// checked will represent wether the radio has been checked or not
|
|
70
|
+
checked: boolean
|
|
64
71
|
```
|
|
65
72
|
|
|
66
73
|
##### Methods
|
|
@@ -85,19 +92,22 @@ show()
|
|
|
85
92
|
toggleVisibility(shouldShow: boolean | () => boolean)
|
|
86
93
|
|
|
87
94
|
/**
|
|
88
|
-
* Configures conditional rendering for the target element
|
|
89
|
-
* and the visibility of one or more trigger elements.
|
|
95
|
+
* Configures conditional rendering for the target element
|
|
96
|
+
* based on a condition and the visibility of one or more trigger elements.
|
|
90
97
|
*
|
|
91
|
-
* @param {(this: DOMNodeReference) => boolean} condition -
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
98
|
+
* @param {(this: DOMNodeReference) => boolean} condition -
|
|
99
|
+
* A function that returns a boolean to determine the visibility
|
|
100
|
+
* of the target element. If `condition()` returns true, the
|
|
101
|
+
* element is shown; otherwise, it is hidden.
|
|
102
|
+
* @param {Array<DOMNodeReference>} dependencies - An array
|
|
103
|
+
* of `DOMNodeReference` instances. Event listeners are
|
|
104
|
+
* registered on each to toggle the visibility of the
|
|
105
|
+
* target element based on the `condition` and the
|
|
106
|
+
* visibility of the target node.
|
|
97
107
|
*/
|
|
98
108
|
configureConditionalRendering(
|
|
99
109
|
condition: (this: DOMNodeReference) => boolean,
|
|
100
|
-
|
|
110
|
+
dependencies: DOMNodeReference[]
|
|
101
111
|
)
|
|
102
112
|
|
|
103
113
|
|
|
@@ -106,22 +116,36 @@ configureConditionalRendering(
|
|
|
106
116
|
const other_node = await createDOMNodeReference(".element_class")
|
|
107
117
|
|
|
108
118
|
your_node.configureConditionalRendering(() =>
|
|
109
|
-
other_node.value == "3",
|
|
110
|
-
|
|
119
|
+
other_node.value == "3",
|
|
120
|
+
/* your_node will only be
|
|
121
|
+
visible when the value of other_node is "3"
|
|
122
|
+
*/
|
|
123
|
+
[other_node]
|
|
124
|
+
/* and we have to include any DOMNodeReferences used
|
|
125
|
+
in the evaluation logic, so that changes to them can
|
|
126
|
+
be watched and the condition evaluated again
|
|
127
|
+
*/
|
|
111
128
|
);
|
|
112
129
|
|
|
113
130
|
|
|
114
131
|
/**
|
|
115
|
-
* Sets up validation and requirement rules for the field.
|
|
132
|
+
* Sets up validation and requirement rules for the field.
|
|
133
|
+
* This function dynamically updates the field's required status
|
|
134
|
+
* and validates its input based on the specified conditions.
|
|
116
135
|
*
|
|
117
|
-
* @param {function(this: DOMNodeReference): boolean} isRequired
|
|
118
|
-
* whether the field should be required.
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
136
|
+
* @param {function(this: DOMNodeReference): boolean} isRequired
|
|
137
|
+
* A function that determines whether the field should be required.
|
|
138
|
+
* Return `true` if required, `false` to not be required.
|
|
139
|
+
* @param {function(this: DOMNodeReference): boolean} isValid
|
|
140
|
+
* A function that checks if the field's input is valid.
|
|
141
|
+
* Return `true` if validation satisfied, `false` if not.
|
|
142
|
+
* @param {string} fieldDisplayName - The name of the field, used
|
|
143
|
+
* in error messages if validation fails.
|
|
144
|
+
* @param {Array<DOMNodeReference>} [dependencies]
|
|
145
|
+
* Other fields that this field’s requirement depends on. When
|
|
146
|
+
* these Nodes or their values change, the required status
|
|
147
|
+
* of this field is re-evaluated. Make sure any DOMNodeReference
|
|
148
|
+
* used in `isRequired` or `isValid` is included in this array.
|
|
125
149
|
*/
|
|
126
150
|
configureValidationAndRequirements(
|
|
127
151
|
isRequired: (this: this) => boolean,
|
|
@@ -135,20 +159,27 @@ configureValidationAndRequirements(
|
|
|
135
159
|
const other_node = await createDOMNodeReference(".element_class")
|
|
136
160
|
|
|
137
161
|
your_node.configureValidationAndRequirements(
|
|
138
|
-
() => other_node.yesRadio.checked,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
162
|
+
() => other_node.yesRadio.checked,
|
|
163
|
+
/* if 'yes' is checked for this other node,
|
|
164
|
+
this function will evaluate to true,
|
|
165
|
+
meaning that 'your_node' will be required */
|
|
166
|
+
|
|
167
|
+
function () {
|
|
168
|
+
/* important to use standard 'function' declaration,
|
|
169
|
+
instead of arrow function when needing to
|
|
170
|
+
access 'this' (the instance of 'your_node') */
|
|
171
|
+
|
|
172
|
+
if (other_node.yesRadio.checked) {
|
|
173
|
+
// when other_node radio is checked 'yes'
|
|
145
174
|
return this.value; // this is only 'valid' if it has a value
|
|
146
175
|
} else return true;
|
|
147
176
|
},
|
|
148
177
|
"Your Field Name",
|
|
149
|
-
[other_node]
|
|
150
|
-
|
|
151
|
-
|
|
178
|
+
[other_node]
|
|
179
|
+
/* since our conditions depend on
|
|
180
|
+
'other_node' it must be included in the dependency
|
|
181
|
+
array so that the requirement conditions can be
|
|
182
|
+
re-evaluated when the value of 'other_node' changes */
|
|
152
183
|
);
|
|
153
184
|
|
|
154
185
|
|
|
@@ -188,9 +219,6 @@ on(eventType: string, eventHandler: (this: DOMNodeReference) => void)
|
|
|
188
219
|
// Unchecks both yes and no radio buttons if they exist.
|
|
189
220
|
uncheckRadios()
|
|
190
221
|
|
|
191
|
-
//Creates a validation instance for the field.
|
|
192
|
-
createValidation(evaluationFunction: () => boolean, fieldDisplayName: string)
|
|
193
|
-
|
|
194
222
|
// Adds a tooltip to the label associated with the HTML element.
|
|
195
223
|
addLabelTooltip(text: string)
|
|
196
224
|
|
package/index.d.ts
CHANGED
|
@@ -181,13 +181,13 @@ class DOMNodeReference {
|
|
|
181
181
|
* @param {(this: DOMNodeReference) => boolean} condition - A function that returns a boolean to determine
|
|
182
182
|
* the visibility of the target element. If `condition()` returns true, the element is shown;
|
|
183
183
|
* otherwise, it is hidden.
|
|
184
|
-
* @param {DOMNodeReference
|
|
184
|
+
* @param {Array<DOMNodeReference>} dependencies - An array of `DOMNodeReference` instances. Event listeners are
|
|
185
185
|
* registered on each to toggle the visibility of the target element based on the `condition` and the visibility of
|
|
186
186
|
* the target node.
|
|
187
187
|
*/
|
|
188
188
|
configureConditionalRendering(
|
|
189
189
|
condition: (this: DOMNodeReference) => boolean,
|
|
190
|
-
|
|
190
|
+
dependencies: DOMNodeReference[]
|
|
191
191
|
): void;
|
|
192
192
|
|
|
193
193
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "powerpagestoolkit",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.203",
|
|
4
4
|
"description": "Reference, manipulate, and engage with Power Pages sites through the nodes in the DOM; use a variety of custom methods that allow customizing your power pages site quicker and easier. ",
|
|
5
5
|
"main": "./dist/index.bundle.js",
|
|
6
6
|
"types": "index.d.ts",
|