powerpagestoolkit 2.3.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 CHANGED
@@ -1,317 +1,234 @@
1
1
  # PowerPages Tool Kit
2
2
 
3
- This package provides utilities for managing and interacting with the DOM and making AJAX requests to a DataVerse API. It includes the `API` module for handling CRUD operations and the `DOMNodeReference` class for seamless DOM manipulations.
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
- After installing
18
+ ```bash
19
+ npm install powerpagestoolkit
20
+ ```
21
+
22
+ ## Core Modules
8
23
 
9
- `npm install powerpagestoolkit`
24
+ ### DOMNodeReference
10
25
 
11
- You can then import into your JavaScript files as follows:
26
+ A powerful class for managing DOM elements with automatic value synchronization and event handling.
12
27
 
13
- ```javascript
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
- # Modules
36
+ // Create a single reference
37
+ const node = await createDOMNodeReference("#myElement");
22
38
 
23
- ### `DOMNodereference`
24
-
25
- The `DOMNodeReference` module simplifies DOM element management. It provides functionalities for creating and interacting with DOM elements:
26
-
27
- #### Usage
39
+ // Create multiple references
40
+ const nodes = await createMultipleDOMNodeReferences(".my-class");
41
+ ```
28
42
 
29
- - **`createDOMNodeReference(selector)`**: Creates a `DOMNodeReference` instance for a single DOM element specified by a CSS selector or HTMLElement. Returns a `DOMNodeReference` instance.
43
+ #### Properties
30
44
 
31
- - **`createMultipleDOMNodeReferences(selector)`**: Creates multiple `DOMNodeReference` instances for all elements matching the specified CSS selector. Returns an array of `DOMNodeReference` instances.
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
- `selector` uses standard ED6 `document.querySelector()` syntax. For more information, read [here](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector)
55
+ #### Key Methods
34
56
 
35
- ```javascript
36
- // single instance of DOMNodeReference
37
- const node = await createDOMNodeReference("#my-element");
57
+ ##### Event Handling
38
58
 
39
- node.onceLoaded(() => {
40
- console.log("Element is loaded: ", node.element);
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
- // to imitate 'querySelectorAll', and return an array of DOMNodeReferences
44
- const nodeArray = await createMultipleDOMNodeReferences('div[class="row"]');
45
-
46
- nodeArray.forEach((node) => {
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
- ##### Available Properties
54
-
55
- These properties are public and can be used in any custom logic/configurations
71
+ ##### Visibility Control
56
72
 
57
73
  ```typescript
58
- target: HTMLElement | string;
59
- element: HTMLElement;
60
- isLoaded: boolean;
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;
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
- ##### Methods
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
- ```javascript
195
- // OTHER METHODS
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
- // Sets the value of the associated HTML element.
198
- setValue(value: any)
104
+ ##### Element Manipulation
199
105
 
200
- // Sets the inner HTML content of the associated HTML element.
201
- setTextContent(text: string)
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
- // set any style attribute for 'this' with standard CSS style declaration
204
- setStyle(options: Partial<CSSStyleDeclaration>): void;
124
+ // State management
125
+ node.disable();
126
+ node.enable();
127
+ ```
205
128
 
206
- // Appends child elements to the associated HTML element.
207
- append(...elements: HTMLElement[])
129
+ ##### Label and Tooltip Management
208
130
 
209
- // Inserts elements after the associated HTML element.
210
- after(...elements: HTMLElement[])
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
- // Retrieves the label associated with the HTML element.
213
- getLabel(): HTMLElement | null
142
+ ### DataVerse API
214
143
 
215
- // Appends child elements to the label associated with the HTML element.
216
- appendToLabel(...elements: HTMLElement[])
144
+ Type-safe wrapper for DataVerse API operations.
217
145
 
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)
146
+ #### Create Record
221
147
 
222
- // Unchecks both yes and no radio buttons if they exist.
223
- uncheckRadios()
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
- // Adds a tooltip to the label associated with the HTML element.
226
- addLabelTooltip(text: string)
161
+ #### Get Records
227
162
 
228
- // Adds a tooltip with the specified text to the element
229
- addTooltip(text: string)
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
- // Executes a callback function once the element is fully loaded.
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
- ### `API`
187
+ ## Best Practices
237
188
 
238
- The `API` module provides functions for creating and retrieving records from a DataVerse. It includes the following methods:
189
+ 1. Always await DOMNodeReference creation:
239
190
 
240
- - **`createRecord(schema)`**: Creates a new record in the DataVerse using the provided schema instance. Returns a Promise that resolves with the record ID or rejects with an error.
241
- - **`getRecord(tableSetName, recordID, selectColumns)`**: Retrieves a specific record from the DataVerse. Returns a Promise that resolves with the retrieved record or rejects with an error.
191
+ ```typescript
192
+ const node = await createDOMNodeReference("#element");
193
+ ```
242
194
 
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.
195
+ 2. Include all referenced nodes in dependency arrays:
244
196
 
245
- #### Usage
197
+ ```typescript
198
+ node.configureConditionalRendering(
199
+ () => dependentNode.value === "test",
200
+ [dependentNode] // Required!
201
+ );
202
+ ```
246
203
 
247
- ###### 1. Creating a Record
204
+ 3. Use TypeScript for better type safety and IntelliSense support.
248
205
 
249
- To create a new record in the DataVerse, you can use the `createRecord` method. This method takes an instance of a schema class containing the data for the record.
206
+ 4. Handle loading states:
250
207
 
251
- ```javascript
252
- // Assuming you have a schema class defined
253
- const schema = new YourSchemaClass({
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
- ###### 2. Getting a Single Record
214
+ 5. Use proper error handling with API operations:
268
215
 
269
- To retrieve a specific record from the DataVerse, use the `getRecord` method. You need to provide the table set name and the record ID.
270
-
271
- ```javascript
272
- const tableSetName = "accounts"; // The DataVerse table set name
273
- const recordID = "your-record-id"; // The GUID of the record to retrieve
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
- ###### 3. Getting Multiple Records
224
+ ## TypeScript Support
285
225
 
286
- If you need to retrieve multiple records with specific query parameters, you can use the `getMultiple` method. This method accepts the table set name and optional query parameters for filtering.
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
- ```javascript
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
- API.getMultiple(tableSetName, queryParameters)
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
- Here's a simple example of a schema class that you might use with the createRecord method:
232
+ ## License
305
233
 
306
- ```javascript
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 {Schema} schema an instance of a schema class, containing the desired information for the POST request
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(schema: Schema): Promise<string>;
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: Function | boolean): DOMNodeReference;
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.
@@ -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 {Schema} schema an instance of a schema class, containing the desired information for the POST request
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(schema) {
30
+ createRecord(tableSetName, data) {
31
31
  return new Promise((resolve, reject) => {
32
32
  safeAjax({
33
33
  type: "POST",
34
- url: `/_api/${schema.logicalName()}`,
35
- data: schema.value(),
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"));
@@ -257,14 +257,10 @@ var DOMNodeReference = class _DOMNodeReference {
257
257
  } else {
258
258
  this.element.addEventListener("input", this.updateValue.bind(this));
259
259
  }
260
- this._observeValueChanges();
261
260
  }
262
261
  updateValue() {
263
262
  switch (this.element.type) {
264
263
  case "checkbox":
265
- this.value = +this.element.checked;
266
- this.checked = this.element.checked;
267
- break;
268
264
  case "radio":
269
265
  this.value = this.element.checked;
270
266
  this.checked = this.element.checked;
@@ -276,6 +272,7 @@ var DOMNodeReference = class _DOMNodeReference {
276
272
  break;
277
273
  case "select-one":
278
274
  this.value = this.element.value;
275
+ break;
279
276
  case "number":
280
277
  this.value = this.element.value !== "" ? Number(this.element.value) : null;
281
278
  break;
@@ -287,19 +284,9 @@ var DOMNodeReference = class _DOMNodeReference {
287
284
  this.yesRadio.updateValue();
288
285
  this.noRadio.updateValue();
289
286
  this.checked = this.yesRadio.checked;
290
- this.value = +this.yesRadio.checked;
287
+ this.value = this.yesRadio.checked;
291
288
  }
292
289
  }
293
- // Add a method to observe value changes using MutationObserver
294
- _observeValueChanges() {
295
- const observer = new MutationObserver(() => {
296
- this.updateValue();
297
- });
298
- observer.observe(this.element, {
299
- attributes: true,
300
- attributeFilter: ["value"]
301
- });
302
- }
303
290
  _attachVisibilityController() {
304
291
  this.visibilityController = this.element;
305
292
  if (this.element.tagName === "TABLE") {
@@ -371,12 +358,15 @@ var DOMNodeReference = class _DOMNodeReference {
371
358
  }
372
359
  /**
373
360
  * Sets the value of the HTML element.
374
- * @param {() => any} value - The value to set for the HTML element.
361
+ * @param {(() => any) | any} value - The value to set for the HTML element.
375
362
  * for parents of boolean radios, pass true or false as value, or
376
363
  * an expression returning a boolean
377
364
  * @returns - Instance of this
378
365
  */
379
366
  setValue(value) {
367
+ if (value instanceof Function) {
368
+ value = value();
369
+ }
380
370
  if (this.element.classList.contains("boolean-radio")) {
381
371
  this.yesRadio.element.checked = value;
382
372
  this.noRadio.element.checked = !value;
@@ -614,7 +604,7 @@ var DOMNodeReference = class _DOMNodeReference {
614
604
  /**
615
605
  * Sets the required level for the field by adding or removing the "required-field" class on the label.
616
606
  *
617
- * @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.
618
608
  * If true, the "required-field" class is added to the label; if false, it is removed.
619
609
  * @returns - Instance of this
620
610
  */
@@ -702,4 +692,11 @@ export {
702
692
  createDOMNodeReference,
703
693
  createMultipleDOMNodeReferences
704
694
  };
705
- //# sourceMappingURL=bundle.js.map
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
@@ -1,4 +1,4 @@
1
+ import './style.css';
1
2
  import API from "./API.js";
2
3
  import { createDOMNodeReference, createMultipleDOMNodeReferences } from "./createDOMNodeReferences.js";
3
- import "./style.css";
4
4
  export { API, createDOMNodeReference, createMultipleDOMNodeReferences };
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "powerpagestoolkit",
3
- "version": "2.3.0",
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:all": "npm run typecheck && npm run build && npm run build:types",
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
  }