powerpagestoolkit 1.3.0 → 1.3.4
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 +146 -32
- package/dist/index.bundle.js +467 -354
- package/index.d.ts +140 -42
- package/package.json +61 -38
package/README.md
CHANGED
|
@@ -20,16 +20,18 @@ import {
|
|
|
20
20
|
|
|
21
21
|
# Modules
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
### `DOMNodereference`
|
|
24
24
|
|
|
25
25
|
The `DOMNodeReference` module simplifies DOM element management. It provides functionalities for creating and interacting with DOM elements:
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
#### Usage
|
|
28
28
|
|
|
29
29
|
- **`createDOMNodeReference(selector)`**: Creates a `DOMNodeReference` instance for a single DOM element specified by a CSS selector or HTMLElement. Returns a `DOMNodeReference` instance.
|
|
30
30
|
|
|
31
31
|
- **`createMultipleDOMNodeReferences(selector)`**: Creates multiple `DOMNodeReference` instances for all elements matching the specified CSS selector. Returns an array of `DOMNodeReference` instances.
|
|
32
32
|
|
|
33
|
+
`selector` uses standard ED6 `document.querySelector()` syntax. For more information, read [here](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector)
|
|
34
|
+
|
|
33
35
|
```javascript
|
|
34
36
|
// single instance of DOMNodeReference
|
|
35
37
|
const node = await createDOMNodeReference("#my-element");
|
|
@@ -48,22 +50,34 @@ nodeArray.forEach((node) => {
|
|
|
48
50
|
})
|
|
49
51
|
```
|
|
50
52
|
|
|
51
|
-
##### Properties
|
|
53
|
+
##### Available Properties
|
|
54
|
+
|
|
55
|
+
These properties are public and can be used in any custom logic/configurations
|
|
52
56
|
|
|
53
57
|
```typescript
|
|
54
|
-
target: string;
|
|
55
|
-
element: HTMLElement
|
|
58
|
+
target: HTMLElement | string;
|
|
59
|
+
element: HTMLElement;
|
|
56
60
|
isLoaded: boolean;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
*/
|
|
66
|
+
yesRadio: DOMNodeReference;
|
|
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;
|
|
60
71
|
```
|
|
61
72
|
|
|
62
73
|
##### Methods
|
|
63
74
|
|
|
64
75
|
Here are the key methods you can use with a DOMNodeReference instance:
|
|
65
76
|
|
|
66
|
-
```
|
|
77
|
+
```javascript
|
|
78
|
+
|
|
79
|
+
/********/
|
|
80
|
+
// VISIBILITY / ACCESSIBILITY
|
|
67
81
|
|
|
68
82
|
// Hides the associated DOM element.
|
|
69
83
|
hide()
|
|
@@ -71,8 +85,123 @@ hide()
|
|
|
71
85
|
// Shows the associated DOM element.
|
|
72
86
|
show()
|
|
73
87
|
|
|
88
|
+
/**
|
|
89
|
+
* advanced visibility control in the case you need to apply
|
|
90
|
+
* custom logic to the visibility of an element
|
|
91
|
+
*/
|
|
92
|
+
toggleVisibility(shouldShow: boolean | () => boolean)
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Configures conditional rendering for the target element
|
|
96
|
+
* based on a condition and the visibility of one or more trigger elements.
|
|
97
|
+
*
|
|
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.
|
|
107
|
+
*/
|
|
108
|
+
configureConditionalRendering(
|
|
109
|
+
condition: (this: DOMNodeReference) => boolean,
|
|
110
|
+
dependencies: Array<DOMNodeReference>
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
// EXAMPLE:
|
|
115
|
+
const your_node = await createDOMNodeReference("#element_id")
|
|
116
|
+
const other_node = await createDOMNodeReference(".element_class")
|
|
117
|
+
|
|
118
|
+
your_node.configureConditionalRendering(() =>
|
|
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
|
+
*/
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
/**
|
|
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.
|
|
135
|
+
*
|
|
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.
|
|
149
|
+
*/
|
|
150
|
+
configureValidationAndRequirements(
|
|
151
|
+
isRequired: (this: this) => boolean,
|
|
152
|
+
isValid: (this: this) => boolean,
|
|
153
|
+
fieldDisplayName: string,
|
|
154
|
+
dependencies: Array<DOMNodeReference>
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
// EXAMPLE:
|
|
158
|
+
const your_node = await createDOMNodeReference("#element_id")
|
|
159
|
+
const other_node = await createDOMNodeReference(".element_class")
|
|
160
|
+
|
|
161
|
+
your_node.configureValidationAndRequirements(
|
|
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'
|
|
174
|
+
return this.value; // this is only 'valid' if it has a value
|
|
175
|
+
} else return true;
|
|
176
|
+
},
|
|
177
|
+
"Your Field Name",
|
|
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 */
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
/* sets the elements 'disabled' to true - useful for inputs
|
|
187
|
+
that need to be enabled/disabled conditionally */
|
|
188
|
+
disable()
|
|
189
|
+
|
|
190
|
+
// Sets the element 'disabled' to false
|
|
191
|
+
enable()
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
// OTHER METHODS
|
|
196
|
+
|
|
74
197
|
// Sets the value of the associated HTML element.
|
|
75
|
-
setValue(value:
|
|
198
|
+
setValue(value: any)
|
|
199
|
+
|
|
200
|
+
// Sets the inner HTML content of the associated HTML element.
|
|
201
|
+
setTextContent(text: string)
|
|
202
|
+
|
|
203
|
+
// set any style attribute for 'this' with standard CSS style declaration
|
|
204
|
+
setStyle(options: Partial<CSSStyleDeclaration>): void;
|
|
76
205
|
|
|
77
206
|
// Appends child elements to the associated HTML element.
|
|
78
207
|
append(...elements: HTMLElement[])
|
|
@@ -86,40 +215,25 @@ getLabel(): HTMLElement | null
|
|
|
86
215
|
// Appends child elements to the label associated with the HTML element.
|
|
87
216
|
appendToLabel(...elements: HTMLElement[])
|
|
88
217
|
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// Adds a change event listener to the associated HTML element.
|
|
93
|
-
addChangeListener(eventHandler: () => void)
|
|
218
|
+
// Create an event listener on the target element. Provide access to 'this'
|
|
219
|
+
// in the event handler function
|
|
220
|
+
on(eventType: string, eventHandler: (this: DOMNodeReference) => void)
|
|
94
221
|
|
|
95
222
|
// Unchecks both yes and no radio buttons if they exist.
|
|
96
223
|
uncheckRadios()
|
|
97
224
|
|
|
98
|
-
//Creates a validation instance for the field.
|
|
99
|
-
createValidation(evaluationFunction: () => boolean, fieldDisplayName: string)
|
|
100
|
-
|
|
101
225
|
// Adds a tooltip to the label associated with the HTML element.
|
|
102
226
|
addLabelTooltip(text: string)
|
|
103
227
|
|
|
104
|
-
// Adds a tooltip
|
|
105
|
-
|
|
106
|
-
addToolTip(text: string)
|
|
107
|
-
|
|
108
|
-
// Sets the inner HTML content of the associated HTML element.
|
|
109
|
-
setTextContent(text: string)
|
|
110
|
-
|
|
111
|
-
// Toggles visibility based on the provided boolean value.
|
|
112
|
-
toggleVisibility(shouldShow: boolean)
|
|
113
|
-
|
|
114
|
-
// Sets the visibility of the element based on a condition and binds it to another DOMNodeReference.
|
|
115
|
-
configureConditionalRendering(condition: () => boolean, triggerNode?: DOMNodeReference)
|
|
228
|
+
// Adds a tooltip with the specified text to the element
|
|
229
|
+
addTooltip(text: string)
|
|
116
230
|
|
|
117
231
|
// Executes a callback function once the element is fully loaded.
|
|
118
232
|
onceLoaded(callback: (instance: DOMNodeReference) => void)
|
|
119
233
|
|
|
120
234
|
```
|
|
121
235
|
|
|
122
|
-
|
|
236
|
+
### `API`
|
|
123
237
|
|
|
124
238
|
The `API` module provides functions for creating and retrieving records from a DataVerse. It includes the following methods:
|
|
125
239
|
|
|
@@ -128,7 +242,7 @@ The `API` module provides functions for creating and retrieving records from a D
|
|
|
128
242
|
|
|
129
243
|
- **`getMultiple(tableSetName, queryParameters)`**: Retrieves multiple records from the DataVerse based on specified query parameters. Returns a Promise that resolves with the list of retrieved records or rejects with an error.
|
|
130
244
|
|
|
131
|
-
|
|
245
|
+
#### Usage
|
|
132
246
|
|
|
133
247
|
###### 1. Creating a Record
|
|
134
248
|
|