powerpagestoolkit 2.2.0 → 2.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 +173 -256
- package/dist/API.d.ts +3 -3
- package/dist/DOMNodeReference.d.ts +4 -5
- package/dist/bundle.css +35 -0
- package/dist/bundle.js +22 -20
- package/dist/index.d.ts +1 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -1,317 +1,234 @@
|
|
|
1
1
|
# PowerPages Tool Kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A TypeScript/JavaScript utility package for seamless DOM manipulation and DataVerse API interactions in PowerPages applications. This toolkit provides robust DOM element management and standardized DataVerse CRUD operations with full TypeScript support.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Powerful DOM element manipulation and reference management
|
|
8
|
+
- Type-safe DataVerse API operations
|
|
9
|
+
- Automatic value synchronization for form elements
|
|
10
|
+
- Advanced conditional rendering and validation
|
|
11
|
+
- Radio button and checkbox handling
|
|
12
|
+
- Event management with proper TypeScript typing
|
|
13
|
+
- Mutation observer integration for dynamic content
|
|
14
|
+
- Tooltip and label management utilities
|
|
4
15
|
|
|
5
16
|
## Installation
|
|
6
17
|
|
|
7
|
-
|
|
18
|
+
```bash
|
|
19
|
+
npm install powerpagestoolkit
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Core Modules
|
|
8
23
|
|
|
9
|
-
|
|
24
|
+
### DOMNodeReference
|
|
10
25
|
|
|
11
|
-
|
|
26
|
+
A powerful class for managing DOM elements with automatic value synchronization and event handling.
|
|
12
27
|
|
|
13
|
-
|
|
28
|
+
#### Basic Usage
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
14
31
|
import {
|
|
15
|
-
API,
|
|
16
32
|
createDOMNodeReference,
|
|
17
33
|
createMultipleDOMNodeReferences,
|
|
18
34
|
} from "powerpagestoolkit";
|
|
19
|
-
```
|
|
20
35
|
|
|
21
|
-
|
|
36
|
+
// Create a single reference
|
|
37
|
+
const node = await createDOMNodeReference("#myElement");
|
|
22
38
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
#### Usage
|
|
39
|
+
// Create multiple references
|
|
40
|
+
const nodes = await createMultipleDOMNodeReferences(".my-class");
|
|
41
|
+
```
|
|
28
42
|
|
|
29
|
-
|
|
43
|
+
#### Properties
|
|
30
44
|
|
|
31
|
-
|
|
45
|
+
| Property | Type | Description |
|
|
46
|
+
| -------- | ------------------------ | --------------------------------------------- |
|
|
47
|
+
| element | HTMLElement | The referenced DOM element |
|
|
48
|
+
| value | any | Current synchronized value of the element |
|
|
49
|
+
| isLoaded | boolean | Element load status |
|
|
50
|
+
| target | HTMLElement \| string | Original target selector or element |
|
|
51
|
+
| yesRadio | DOMNodeReference \| null | Reference to 'yes' radio (for boolean fields) |
|
|
52
|
+
| noRadio | DOMNodeReference \| null | Reference to 'no' radio (for boolean fields) |
|
|
53
|
+
| checked | boolean | Checkbox/radio checked state |
|
|
32
54
|
|
|
33
|
-
|
|
55
|
+
#### Key Methods
|
|
34
56
|
|
|
35
|
-
|
|
36
|
-
// single instance of DOMNodeReference
|
|
37
|
-
const node = await createDOMNodeReference("#my-element");
|
|
57
|
+
##### Event Handling
|
|
38
58
|
|
|
39
|
-
|
|
40
|
-
|
|
59
|
+
```typescript
|
|
60
|
+
// Add event listener with proper 'this' context
|
|
61
|
+
node.on("change", function (e) {
|
|
62
|
+
console.log("Current value:", this.value);
|
|
41
63
|
});
|
|
42
64
|
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
node.oneLoaded(() => {
|
|
48
|
-
console.log("Element loaded: ", node.element")
|
|
49
|
-
})
|
|
50
|
-
})
|
|
65
|
+
// Wait for element to be loaded
|
|
66
|
+
node.onceLoaded((instance) => {
|
|
67
|
+
console.log("Element ready:", instance.element);
|
|
68
|
+
});
|
|
51
69
|
```
|
|
52
70
|
|
|
53
|
-
#####
|
|
54
|
-
|
|
55
|
-
These properties are public and can be used in any custom logic/configurations
|
|
71
|
+
##### Visibility Control
|
|
56
72
|
|
|
57
73
|
```typescript
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// checked will represent wether the radio has been checked or not
|
|
70
|
-
checked: boolean;
|
|
74
|
+
// Basic visibility
|
|
75
|
+
node.hide();
|
|
76
|
+
node.show();
|
|
77
|
+
|
|
78
|
+
// Advanced conditional rendering
|
|
79
|
+
node.configureConditionalRendering(
|
|
80
|
+
function () {
|
|
81
|
+
return otherNode.value === "expected";
|
|
82
|
+
},
|
|
83
|
+
[otherNode] // Dependencies that trigger re-evaluation
|
|
84
|
+
);
|
|
71
85
|
```
|
|
72
86
|
|
|
73
|
-
#####
|
|
74
|
-
|
|
75
|
-
Here are the key methods you can use with a DOMNodeReference instance:
|
|
76
|
-
|
|
77
|
-
```javascript
|
|
78
|
-
|
|
79
|
-
/********/
|
|
80
|
-
// VISIBILITY / ACCESSIBILITY
|
|
81
|
-
|
|
82
|
-
// Hides the associated DOM element.
|
|
83
|
-
hide()
|
|
84
|
-
|
|
85
|
-
// Shows the associated DOM element.
|
|
86
|
-
show()
|
|
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
|
-
```
|
|
87
|
+
##### Validation and Requirements
|
|
193
88
|
|
|
194
|
-
```
|
|
195
|
-
|
|
89
|
+
```typescript
|
|
90
|
+
node.configureValidationAndRequirements(
|
|
91
|
+
// Required condition
|
|
92
|
+
function () {
|
|
93
|
+
return dependentNode.yesRadio?.checked ?? false;
|
|
94
|
+
},
|
|
95
|
+
// Validation condition
|
|
96
|
+
function () {
|
|
97
|
+
return this.value != null && this.value !== "";
|
|
98
|
+
},
|
|
99
|
+
"Field Display Name",
|
|
100
|
+
[dependentNode] // Dependencies
|
|
101
|
+
);
|
|
102
|
+
```
|
|
196
103
|
|
|
197
|
-
|
|
198
|
-
setValue(value: any)
|
|
104
|
+
##### Element Manipulation
|
|
199
105
|
|
|
200
|
-
|
|
201
|
-
|
|
106
|
+
```typescript
|
|
107
|
+
// Value management
|
|
108
|
+
node.setValue("new value");
|
|
109
|
+
node.updateValue(); // Sync with DOM
|
|
110
|
+
|
|
111
|
+
// Content manipulation
|
|
112
|
+
node.setInnerHTML("<span>New content</span>");
|
|
113
|
+
node.append(childElement);
|
|
114
|
+
node.prepend(headerElement);
|
|
115
|
+
node.after(siblingElement);
|
|
116
|
+
node.before(labelElement);
|
|
117
|
+
|
|
118
|
+
// Styling
|
|
119
|
+
node.setStyle({
|
|
120
|
+
display: "block",
|
|
121
|
+
color: "red",
|
|
122
|
+
});
|
|
202
123
|
|
|
203
|
-
//
|
|
204
|
-
|
|
124
|
+
// State management
|
|
125
|
+
node.disable();
|
|
126
|
+
node.enable();
|
|
127
|
+
```
|
|
205
128
|
|
|
206
|
-
|
|
207
|
-
append(...elements: HTMLElement[])
|
|
129
|
+
##### Label and Tooltip Management
|
|
208
130
|
|
|
209
|
-
|
|
210
|
-
|
|
131
|
+
```typescript
|
|
132
|
+
// Label operations
|
|
133
|
+
const label = node.getLabel();
|
|
134
|
+
node.appendToLabel(infoElement);
|
|
135
|
+
node.addLabelTooltip("Helper text");
|
|
136
|
+
node.addTooltip("Inline helper");
|
|
137
|
+
|
|
138
|
+
// Required state
|
|
139
|
+
node.setRequiredLevel(true);
|
|
140
|
+
```
|
|
211
141
|
|
|
212
|
-
|
|
213
|
-
getLabel(): HTMLElement | null
|
|
142
|
+
### DataVerse API
|
|
214
143
|
|
|
215
|
-
|
|
216
|
-
appendToLabel(...elements: HTMLElement[])
|
|
144
|
+
Type-safe wrapper for DataVerse API operations.
|
|
217
145
|
|
|
218
|
-
|
|
219
|
-
// in the event handler function
|
|
220
|
-
on(eventType: string, eventHandler: (this: DOMNodeReference) => void)
|
|
146
|
+
#### Create Record
|
|
221
147
|
|
|
222
|
-
|
|
223
|
-
|
|
148
|
+
```typescript
|
|
149
|
+
const recordId = await API.createRecord("accounts", {
|
|
150
|
+
name: "New Account",
|
|
151
|
+
type: "Customer",
|
|
152
|
+
})
|
|
153
|
+
.then(() => {
|
|
154
|
+
console.log("Created record:", recordId);
|
|
155
|
+
})
|
|
156
|
+
.catch(() => {
|
|
157
|
+
console.error("Creation failed:", error);
|
|
158
|
+
});
|
|
159
|
+
```
|
|
224
160
|
|
|
225
|
-
|
|
226
|
-
addLabelTooltip(text: string)
|
|
161
|
+
#### Get Records
|
|
227
162
|
|
|
228
|
-
|
|
229
|
-
|
|
163
|
+
```typescript
|
|
164
|
+
// Single record
|
|
165
|
+
const record = await API.getRecord(
|
|
166
|
+
"accounts",
|
|
167
|
+
"record-guid",
|
|
168
|
+
"select=name,accountnumber"
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// Multiple records
|
|
172
|
+
const records = await API.getMultiple(
|
|
173
|
+
"contacts",
|
|
174
|
+
'$filter=firstname eq "Jane"&$select=firstname,lastname'
|
|
175
|
+
);
|
|
176
|
+
```
|
|
230
177
|
|
|
231
|
-
|
|
232
|
-
onceLoaded(callback: (instance: DOMNodeReference) => void)
|
|
178
|
+
#### Update Record
|
|
233
179
|
|
|
180
|
+
```typescript
|
|
181
|
+
await API.updateRecord("contacts", "record-guid", {
|
|
182
|
+
name: "Jane Smith",
|
|
183
|
+
email: "jane@example.com",
|
|
184
|
+
});
|
|
234
185
|
```
|
|
235
186
|
|
|
236
|
-
|
|
187
|
+
## Best Practices
|
|
237
188
|
|
|
238
|
-
|
|
189
|
+
1. Always await DOMNodeReference creation:
|
|
239
190
|
|
|
240
|
-
|
|
241
|
-
|
|
191
|
+
```typescript
|
|
192
|
+
const node = await createDOMNodeReference("#element");
|
|
193
|
+
```
|
|
242
194
|
|
|
243
|
-
|
|
195
|
+
2. Include all referenced nodes in dependency arrays:
|
|
244
196
|
|
|
245
|
-
|
|
197
|
+
```typescript
|
|
198
|
+
node.configureConditionalRendering(
|
|
199
|
+
() => dependentNode.value === "test",
|
|
200
|
+
[dependentNode] // Required!
|
|
201
|
+
);
|
|
202
|
+
```
|
|
246
203
|
|
|
247
|
-
|
|
204
|
+
3. Use TypeScript for better type safety and IntelliSense support.
|
|
248
205
|
|
|
249
|
-
|
|
206
|
+
4. Handle loading states:
|
|
250
207
|
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
name: "Sample Record",
|
|
255
|
-
description: "This is a sample record for demonstration.",
|
|
208
|
+
```typescript
|
|
209
|
+
node.onceLoaded((instance) => {
|
|
210
|
+
// Safe to manipulate the element here
|
|
256
211
|
});
|
|
257
|
-
|
|
258
|
-
API.createRecord(schema)
|
|
259
|
-
.then((recordId) => {
|
|
260
|
-
console.log("Record created successfully with ID:", recordId);
|
|
261
|
-
})
|
|
262
|
-
.catch((error) => {
|
|
263
|
-
console.error("Error creating record:", error);
|
|
264
|
-
});
|
|
265
212
|
```
|
|
266
213
|
|
|
267
|
-
|
|
214
|
+
5. Use proper error handling with API operations:
|
|
268
215
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
API.getRecord(tableSetName, recordID)
|
|
276
|
-
.then((record) => {
|
|
277
|
-
console.log("Retrieved record:", record);
|
|
278
|
-
})
|
|
279
|
-
.catch((error) => {
|
|
280
|
-
console.error("Error retrieving record:", error);
|
|
281
|
-
});
|
|
216
|
+
```typescript
|
|
217
|
+
try {
|
|
218
|
+
await API.createRecord(/*...*/);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
// Handle error appropriately
|
|
221
|
+
}
|
|
282
222
|
```
|
|
283
223
|
|
|
284
|
-
|
|
224
|
+
## TypeScript Support
|
|
285
225
|
|
|
286
|
-
|
|
226
|
+
The package includes full TypeScript definitions and type safety. Use TypeScript for the best development experience and catch potential errors at compile time.
|
|
287
227
|
|
|
288
|
-
|
|
289
|
-
const tableSetName = "contacts"; // The DataVerse table set name
|
|
290
|
-
const queryParameters =
|
|
291
|
-
"$filter=firstName eq 'John'&$select=firstName,lastName"; // OData query parameters
|
|
228
|
+
## Contributing
|
|
292
229
|
|
|
293
|
-
|
|
294
|
-
.then((records) => {
|
|
295
|
-
console.log("Retrieved records:", records);
|
|
296
|
-
})
|
|
297
|
-
.catch((error) => {
|
|
298
|
-
console.error("Error retrieving records:", error);
|
|
299
|
-
});
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
##### Example Schema Class
|
|
230
|
+
Contributions are welcome, feel free to create a pull request with enhancements. Please include an explanation of the changes made. All pull requests will be reviewed by the project owner.
|
|
303
231
|
|
|
304
|
-
|
|
232
|
+
## License
|
|
305
233
|
|
|
306
|
-
|
|
307
|
-
class YourSchemaClass {
|
|
308
|
-
constructor(tableSetName, data) {
|
|
309
|
-
this.setName = tableSetName;
|
|
310
|
-
this.data = data;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
value() {
|
|
314
|
-
return JSON.stringify(this.data); // Convert data to JSON format for the API
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
```
|
|
234
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/dist/API.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
declare const API: {
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param
|
|
3
|
+
* @param tableSetName The dataverse set name for the table that you are updating a record in
|
|
4
|
+
* @param data The JSON of the fields and data that are to be updated on the targeted record
|
|
5
5
|
* @returns a Promise resolving the successful results *[record id]* of the POST request, or rejecting the failed results *[error]* of the POST request.
|
|
6
6
|
*/
|
|
7
|
-
createRecord(
|
|
7
|
+
createRecord(tableSetName: string, data: object): Promise<string>;
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
10
10
|
* @param tableSetName The DataVerse SET name of the table being queried
|
|
@@ -40,7 +40,6 @@ export declare const _init: unique symbol;
|
|
|
40
40
|
[_init](): Promise<void>;
|
|
41
41
|
private _initValueSync;
|
|
42
42
|
updateValue(): void;
|
|
43
|
-
private _observeValueChanges;
|
|
44
43
|
private _attachVisibilityController;
|
|
45
44
|
private _attachRadioButtons;
|
|
46
45
|
/**
|
|
@@ -71,12 +70,12 @@ export declare const _init: unique symbol;
|
|
|
71
70
|
toggleVisibility(shouldShow: Function | boolean): DOMNodeReference;
|
|
72
71
|
/**
|
|
73
72
|
* Sets the value of the HTML element.
|
|
74
|
-
* @param {() => any} value - The value to set for the HTML element.
|
|
73
|
+
* @param {(() => any) | any} value - The value to set for the HTML element.
|
|
75
74
|
* for parents of boolean radios, pass true or false as value, or
|
|
76
75
|
* an expression returning a boolean
|
|
77
76
|
* @returns - Instance of this
|
|
78
77
|
*/
|
|
79
|
-
setValue(value: any): DOMNodeReference;
|
|
78
|
+
setValue(value: (() => any) | any): DOMNodeReference;
|
|
80
79
|
/**
|
|
81
80
|
* Disables the element so that users cannot input any data
|
|
82
81
|
* @returns - Instance of this
|
|
@@ -182,11 +181,11 @@ export declare const _init: unique symbol;
|
|
|
182
181
|
/**
|
|
183
182
|
* Sets the required level for the field by adding or removing the "required-field" class on the label.
|
|
184
183
|
*
|
|
185
|
-
* @param {boolean} isRequired - Determines whether the field should be marked as required.
|
|
184
|
+
* @param {Function | boolean} isRequired - Determines whether the field should be marked as required.
|
|
186
185
|
* If true, the "required-field" class is added to the label; if false, it is removed.
|
|
187
186
|
* @returns - Instance of this
|
|
188
187
|
*/
|
|
189
|
-
setRequiredLevel(isRequired:
|
|
188
|
+
setRequiredLevel(isRequired: (() => boolean) | boolean): DOMNodeReference;
|
|
190
189
|
/**
|
|
191
190
|
* Executes a callback function once the element is fully loaded.
|
|
192
191
|
* If the element is already loaded, the callback is called immediately.
|
package/dist/bundle.css
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* src/style.css */
|
|
2
|
+
.info-icon {
|
|
3
|
+
position: relative;
|
|
4
|
+
display: inline-block;
|
|
5
|
+
}
|
|
6
|
+
.info-icon .fa-info-circle {
|
|
7
|
+
cursor: pointer;
|
|
8
|
+
}
|
|
9
|
+
.info-icon .flyout-content {
|
|
10
|
+
max-width: calc(100vw - 20px);
|
|
11
|
+
display: none;
|
|
12
|
+
position: absolute;
|
|
13
|
+
left: 50%;
|
|
14
|
+
transform: translateX(-50%);
|
|
15
|
+
background-color: #f9f9f9;
|
|
16
|
+
padding: 10px;
|
|
17
|
+
border: 1px solid #ddd;
|
|
18
|
+
z-index: 1;
|
|
19
|
+
min-width: 200px;
|
|
20
|
+
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
|
|
21
|
+
border-radius: 4px;
|
|
22
|
+
}
|
|
23
|
+
@media (max-width: 600px) {
|
|
24
|
+
.info-icon .flyout-content {
|
|
25
|
+
max-width: 95vw;
|
|
26
|
+
padding: 12px;
|
|
27
|
+
font-size: 0.9em;
|
|
28
|
+
display: block;
|
|
29
|
+
right: auto;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
.required-field::after {
|
|
33
|
+
content: " *" !important;
|
|
34
|
+
color: #f00 !important;
|
|
35
|
+
}
|
package/dist/bundle.js
CHANGED
|
@@ -23,16 +23,16 @@ function safeAjax(ajaxOptions) {
|
|
|
23
23
|
// src/API.ts
|
|
24
24
|
var API = {
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
* @param
|
|
26
|
+
* @param tableSetName The dataverse set name for the table that you are updating a record in
|
|
27
|
+
* @param data The JSON of the fields and data that are to be updated on the targeted record
|
|
28
28
|
* @returns a Promise resolving the successful results *[record id]* of the POST request, or rejecting the failed results *[error]* of the POST request.
|
|
29
29
|
*/
|
|
30
|
-
createRecord(
|
|
30
|
+
createRecord(tableSetName, data) {
|
|
31
31
|
return new Promise((resolve, reject) => {
|
|
32
32
|
safeAjax({
|
|
33
33
|
type: "POST",
|
|
34
|
-
url: `/_api/${
|
|
35
|
-
data:
|
|
34
|
+
url: `/_api/${tableSetName}`,
|
|
35
|
+
data: JSON.stringify(data),
|
|
36
36
|
contentType: "application/json",
|
|
37
37
|
success: function(response, status, xhr) {
|
|
38
38
|
resolve(xhr.getResponseHeader("entityid"));
|
|
@@ -270,6 +270,9 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
270
270
|
this.element.selectedOptions
|
|
271
271
|
).map((option) => option.value);
|
|
272
272
|
break;
|
|
273
|
+
case "select-one":
|
|
274
|
+
this.value = this.element.value;
|
|
275
|
+
break;
|
|
273
276
|
case "number":
|
|
274
277
|
this.value = this.element.value !== "" ? Number(this.element.value) : null;
|
|
275
278
|
break;
|
|
@@ -281,19 +284,8 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
281
284
|
this.yesRadio.updateValue();
|
|
282
285
|
this.noRadio.updateValue();
|
|
283
286
|
this.checked = this.yesRadio.checked;
|
|
284
|
-
this.value = this.yesRadio
|
|
287
|
+
this.value = this.yesRadio.checked;
|
|
285
288
|
}
|
|
286
|
-
this._observeValueChanges();
|
|
287
|
-
}
|
|
288
|
-
// Add a method to observe value changes using MutationObserver
|
|
289
|
-
_observeValueChanges() {
|
|
290
|
-
const observer = new MutationObserver(() => {
|
|
291
|
-
this.updateValue();
|
|
292
|
-
});
|
|
293
|
-
observer.observe(this.element, {
|
|
294
|
-
attributes: true,
|
|
295
|
-
attributeFilter: ["value"]
|
|
296
|
-
});
|
|
297
289
|
}
|
|
298
290
|
_attachVisibilityController() {
|
|
299
291
|
this.visibilityController = this.element;
|
|
@@ -366,12 +358,15 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
366
358
|
}
|
|
367
359
|
/**
|
|
368
360
|
* Sets the value of the HTML element.
|
|
369
|
-
* @param {() => any} value - The value to set for the HTML element.
|
|
361
|
+
* @param {(() => any) | any} value - The value to set for the HTML element.
|
|
370
362
|
* for parents of boolean radios, pass true or false as value, or
|
|
371
363
|
* an expression returning a boolean
|
|
372
364
|
* @returns - Instance of this
|
|
373
365
|
*/
|
|
374
366
|
setValue(value) {
|
|
367
|
+
if (value instanceof Function) {
|
|
368
|
+
value = value();
|
|
369
|
+
}
|
|
375
370
|
if (this.element.classList.contains("boolean-radio")) {
|
|
376
371
|
this.yesRadio.element.checked = value;
|
|
377
372
|
this.noRadio.element.checked = !value;
|
|
@@ -609,7 +604,7 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
609
604
|
/**
|
|
610
605
|
* Sets the required level for the field by adding or removing the "required-field" class on the label.
|
|
611
606
|
*
|
|
612
|
-
* @param {boolean} isRequired - Determines whether the field should be marked as required.
|
|
607
|
+
* @param {Function | boolean} isRequired - Determines whether the field should be marked as required.
|
|
613
608
|
* If true, the "required-field" class is added to the label; if false, it is removed.
|
|
614
609
|
* @returns - Instance of this
|
|
615
610
|
*/
|
|
@@ -697,4 +692,11 @@ export {
|
|
|
697
692
|
createDOMNodeReference,
|
|
698
693
|
createMultipleDOMNodeReferences
|
|
699
694
|
};
|
|
700
|
-
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
(function() {
|
|
698
|
+
const style = document.createElement('style');
|
|
699
|
+
style.textContent = "/* src/style.css */\n.info-icon {\n position: relative;\n display: inline-block;\n}\n.info-icon .fa-info-circle {\n cursor: pointer;\n}\n.info-icon .flyout-content {\n max-width: calc(100vw - 20px);\n display: none;\n position: absolute;\n left: 50%;\n transform: translateX(-50%);\n background-color: #f9f9f9;\n padding: 10px;\n border: 1px solid #ddd;\n z-index: 1;\n min-width: 200px;\n box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);\n border-radius: 4px;\n}\n@media (max-width: 600px) {\n .info-icon .flyout-content {\n max-width: 95vw;\n padding: 12px;\n font-size: 0.9em;\n display: block;\n right: auto;\n }\n}\n.required-field::after {\n content: \" *\" !important;\n color: #f00 !important;\n}\n";
|
|
700
|
+
document.head.appendChild(style);
|
|
701
|
+
})();
|
|
702
|
+
|
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "powerpagestoolkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.4",
|
|
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/bundle.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"typecheck": "tsc",
|
|
9
|
-
"build": "node build.js",
|
|
9
|
+
"node:build": "node build.js",
|
|
10
|
+
"clean": "rimraf dist",
|
|
10
11
|
"build:types": "tsc --emitDeclarationOnly --declaration",
|
|
11
|
-
"build
|
|
12
|
+
"build": "npm run clean && npm run typecheck && npm run node:build && npm run build:types",
|
|
12
13
|
"dev": "tsc --watch"
|
|
13
14
|
},
|
|
14
15
|
"devDependencies": {
|
|
@@ -19,6 +20,7 @@
|
|
|
19
20
|
"esbuild-css-modules-plugin": "^3.1.2",
|
|
20
21
|
"eslint": "^8.57.1",
|
|
21
22
|
"eslint-plugin-import": "^2.31.0",
|
|
23
|
+
"rimraf": "^6.0.1",
|
|
22
24
|
"ts-loader": "^9.5.1",
|
|
23
25
|
"typescript": "^5.6.3",
|
|
24
26
|
"typescript-eslint": "^8.12.2"
|
|
@@ -55,6 +57,7 @@
|
|
|
55
57
|
],
|
|
56
58
|
"files": [
|
|
57
59
|
"dist/bundle.js",
|
|
60
|
+
"dist/bundle.css",
|
|
58
61
|
"dist/**/*.d.ts"
|
|
59
62
|
],
|
|
60
63
|
"exports": {
|
|
@@ -65,6 +68,9 @@
|
|
|
65
68
|
"./createDOMNodeReference": {
|
|
66
69
|
"import": "./dist/createDOMNodeReference.js",
|
|
67
70
|
"types": "./dist/createDOMNodeReference.d.ts"
|
|
71
|
+
},
|
|
72
|
+
"./style.css": {
|
|
73
|
+
"import": "./dist/bundle.css"
|
|
68
74
|
}
|
|
69
75
|
}
|
|
70
76
|
}
|