powerpagestoolkit 2.5.4211 → 2.6.1
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 +23 -10
- package/assets/infoIconExample.gif +0 -0
- package/dist/DOMNodeReference.d.ts +4 -1
- package/dist/bundle.js +72 -9
- package/dist/createDOMNodeReferences.d.ts +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -99,23 +99,25 @@ Out of the box, Microsoft does not provide PowerPages developers the ability to
|
|
|
99
99
|
_Method signature:_
|
|
100
100
|
|
|
101
101
|
```typescript
|
|
102
|
-
|
|
102
|
+
configureConditionalRendering(
|
|
103
103
|
condition: () => boolean,
|
|
104
104
|
dependencies?: Array<DOMNodeReference>,
|
|
105
105
|
clearValuesOnHide: boolean = true
|
|
106
|
-
): DOMNodeReference
|
|
106
|
+
): DOMNodeReference /* Instance of this returned
|
|
107
|
+
for optional method chaining */
|
|
107
108
|
```
|
|
108
109
|
|
|
109
110
|
_Example implementation:_
|
|
110
111
|
|
|
111
112
|
```typescript
|
|
112
113
|
node.configureConditionalRendering(
|
|
113
|
-
// Function to evaluate wether this node should be visible or not
|
|
114
|
-
|
|
114
|
+
function () // Function to evaluate wether this node should be visible or not
|
|
115
|
+
{
|
|
115
116
|
return otherNode.value === "some value";
|
|
116
117
|
},
|
|
117
118
|
[otherNode] /* Dependency array | if the values or visibility of these
|
|
118
119
|
change, the function is re-evaluated */,
|
|
120
|
+
|
|
119
121
|
true /* should the values in the targeted elements (this.element)
|
|
120
122
|
be cleared if this node is hidden? Default = true */
|
|
121
123
|
);
|
|
@@ -128,12 +130,11 @@ This utility enhances PowerPages forms by adding dynamic field validation and co
|
|
|
128
130
|
_Method signature:_
|
|
129
131
|
|
|
130
132
|
```typescript
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
dependencies: DOMNodeReference[] // Fields that trigger validation checks
|
|
133
|
+
configureValidationAndRequirements(
|
|
134
|
+
isRequired: () => boolean,
|
|
135
|
+
isValid: () => boolean,
|
|
136
|
+
fieldDisplayName: string,
|
|
137
|
+
dependencies: DOMNodeReference[]
|
|
137
138
|
): DOMNodeReference; /* instance of this is returned for optional
|
|
138
139
|
method chaining */
|
|
139
140
|
```
|
|
@@ -218,6 +219,18 @@ node.addTooltip(
|
|
|
218
219
|
);
|
|
219
220
|
```
|
|
220
221
|
|
|
222
|
+
_Example:_
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
import { createRef } from "powerpagestoolkit";
|
|
226
|
+
|
|
227
|
+
const title = await createRef("#myTitle");
|
|
228
|
+
|
|
229
|
+
title.addTooltip("This is an Example of a tooltip!", { color: "red" });
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+

|
|
233
|
+
|
|
221
234
|
### DataVerse API
|
|
222
235
|
|
|
223
236
|
Perform secure API calls to DataVerse from your PowerPages site. This method implements the shell deferred token to send requests with `__RequestVerificationToken`
|
|
Binary file
|
|
@@ -3,6 +3,8 @@ export default class DOMNodeReference {
|
|
|
3
3
|
target: HTMLElement | string;
|
|
4
4
|
private isLoaded;
|
|
5
5
|
private defaultDisplay;
|
|
6
|
+
private observers;
|
|
7
|
+
private boundEventListeners;
|
|
6
8
|
/**
|
|
7
9
|
* The value of the element that this node represents
|
|
8
10
|
* stays in syncs with the live DOM elements?.,m via event handler
|
|
@@ -55,6 +57,7 @@ export default class DOMNodeReference {
|
|
|
55
57
|
private _attachVisibilityController;
|
|
56
58
|
private _attachRadioButtons;
|
|
57
59
|
private _bindMethods;
|
|
60
|
+
private _destroy;
|
|
58
61
|
/**
|
|
59
62
|
* Updates the value and checked state based on element type
|
|
60
63
|
* @public
|
|
@@ -68,7 +71,7 @@ export default class DOMNodeReference {
|
|
|
68
71
|
* specified event occurs.
|
|
69
72
|
* @returns - Instance of this [provides option to method chain]
|
|
70
73
|
*/
|
|
71
|
-
on(eventType:
|
|
74
|
+
on(eventType: keyof HTMLElementEventMap, eventHandler: (e: Event) => void): DOMNodeReference;
|
|
72
75
|
/**
|
|
73
76
|
* Hides the element by setting its display style to "none".
|
|
74
77
|
* @returns - Instance of this [provides option to method chain]
|
package/dist/bundle.js
CHANGED
|
@@ -234,6 +234,8 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
234
234
|
target;
|
|
235
235
|
isLoaded;
|
|
236
236
|
defaultDisplay;
|
|
237
|
+
observers;
|
|
238
|
+
boundEventListeners;
|
|
237
239
|
/**
|
|
238
240
|
* The value of the element that this node represents
|
|
239
241
|
* stays in syncs with the live DOM elements?.,m via event handler
|
|
@@ -250,6 +252,8 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
250
252
|
this.isLoaded = false;
|
|
251
253
|
this.defaultDisplay = "";
|
|
252
254
|
this.value = null;
|
|
255
|
+
this.observers = [];
|
|
256
|
+
this.boundEventListeners = [];
|
|
253
257
|
this._bindMethods();
|
|
254
258
|
}
|
|
255
259
|
async [_init]() {
|
|
@@ -265,6 +269,19 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
265
269
|
this._initValueSync();
|
|
266
270
|
this._attachVisibilityController();
|
|
267
271
|
this.defaultDisplay = this.visibilityController.style.display;
|
|
272
|
+
const observer = new MutationObserver((mutations) => {
|
|
273
|
+
for (const mutation of mutations) {
|
|
274
|
+
if (Array.from(mutation.removedNodes).includes(this.element)) {
|
|
275
|
+
this._destroy();
|
|
276
|
+
observer.disconnect();
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
observer.observe(document.body, {
|
|
282
|
+
childList: true,
|
|
283
|
+
subtree: true
|
|
284
|
+
});
|
|
268
285
|
this.isLoaded = true;
|
|
269
286
|
} catch (error) {
|
|
270
287
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -298,6 +315,13 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
298
315
|
eventType = "input";
|
|
299
316
|
}
|
|
300
317
|
this.element.addEventListener(eventType, this.updateValue);
|
|
318
|
+
const _element = this.element;
|
|
319
|
+
const _updateValue = this.updateValue;
|
|
320
|
+
this.boundEventListeners.push({
|
|
321
|
+
element: _element,
|
|
322
|
+
handler: _updateValue,
|
|
323
|
+
event: eventType
|
|
324
|
+
});
|
|
301
325
|
if (this.element instanceof HTMLInputElement && this.element.dataset.type === "date") {
|
|
302
326
|
await this._initDateSync(this.element);
|
|
303
327
|
}
|
|
@@ -315,6 +339,12 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
315
339
|
}
|
|
316
340
|
const dateNode = await waitFor("[data-date-format]", parentElement);
|
|
317
341
|
dateNode.addEventListener("select", this.updateValue);
|
|
342
|
+
const _handler = this.updateValue;
|
|
343
|
+
this.boundEventListeners.push({
|
|
344
|
+
element: dateNode,
|
|
345
|
+
handler: _handler,
|
|
346
|
+
event: "select"
|
|
347
|
+
});
|
|
318
348
|
}
|
|
319
349
|
/**
|
|
320
350
|
* Gets the current value of the element based on its type
|
|
@@ -398,6 +428,24 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
398
428
|
}
|
|
399
429
|
}
|
|
400
430
|
}
|
|
431
|
+
_destroy() {
|
|
432
|
+
if (this.boundEventListeners.length > 0) {
|
|
433
|
+
this.boundEventListeners.forEach((binding) => {
|
|
434
|
+
binding.element?.removeEventListener(binding.event, binding.handler);
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
if (this.observers.length > 0) {
|
|
438
|
+
this.observers.forEach((observer) => {
|
|
439
|
+
observer.disconnect();
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
this.yesRadio?._destroy();
|
|
443
|
+
this.noRadio?._destroy();
|
|
444
|
+
this.yesRadio = null;
|
|
445
|
+
this.noRadio = null;
|
|
446
|
+
this.isLoaded = false;
|
|
447
|
+
this.value = null;
|
|
448
|
+
}
|
|
401
449
|
/**
|
|
402
450
|
* Updates the value and checked state based on element type
|
|
403
451
|
* @public
|
|
@@ -419,17 +467,19 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
419
467
|
* @returns - Instance of this [provides option to method chain]
|
|
420
468
|
*/
|
|
421
469
|
on(eventType, eventHandler) {
|
|
422
|
-
if (typeof eventType !== "string") {
|
|
423
|
-
throw new Error(
|
|
424
|
-
`Argument "eventType" must be of type "string". Received: ${typeof eventType}`
|
|
425
|
-
);
|
|
426
|
-
}
|
|
427
470
|
if (typeof eventHandler !== "function") {
|
|
428
471
|
throw new Error(
|
|
429
472
|
`Argument "eventHandler" must be a Function. Received: ${typeof eventHandler}`
|
|
430
473
|
);
|
|
431
474
|
}
|
|
432
475
|
this.element.addEventListener(eventType, eventHandler.bind(this));
|
|
476
|
+
const _element = this.element;
|
|
477
|
+
const _handler = eventHandler;
|
|
478
|
+
this.boundEventListeners.push({
|
|
479
|
+
element: _element,
|
|
480
|
+
handler: _handler,
|
|
481
|
+
event: eventType
|
|
482
|
+
});
|
|
433
483
|
return this;
|
|
434
484
|
}
|
|
435
485
|
/**
|
|
@@ -845,6 +895,7 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
845
895
|
attributeFilter: ["style"],
|
|
846
896
|
subtree: false
|
|
847
897
|
});
|
|
898
|
+
this.observers.push(observer);
|
|
848
899
|
}
|
|
849
900
|
if (trackRadioButtons && (dep.yesRadio || dep.noRadio)) {
|
|
850
901
|
[dep.yesRadio, dep.noRadio].forEach((radio) => {
|
|
@@ -896,6 +947,7 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
896
947
|
subtree: true,
|
|
897
948
|
childList: true
|
|
898
949
|
});
|
|
950
|
+
this.observers.push(observer);
|
|
899
951
|
}
|
|
900
952
|
};
|
|
901
953
|
|
|
@@ -944,10 +996,21 @@ function createProxyHandler() {
|
|
|
944
996
|
};
|
|
945
997
|
}
|
|
946
998
|
function enhanceArray(array) {
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
999
|
+
Object.defineProperties(array, {
|
|
1000
|
+
hideAll: {
|
|
1001
|
+
value: function() {
|
|
1002
|
+
this.forEach((instance) => instance.hide());
|
|
1003
|
+
return this;
|
|
1004
|
+
}
|
|
1005
|
+
},
|
|
1006
|
+
showAll: {
|
|
1007
|
+
value: function() {
|
|
1008
|
+
this.forEach((instance) => instance.show());
|
|
1009
|
+
return this;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
});
|
|
1013
|
+
return array;
|
|
951
1014
|
}
|
|
952
1015
|
export {
|
|
953
1016
|
API_default as API,
|
|
@@ -6,4 +6,4 @@ import DOMNodeReference from "./DOMNodeReference.js";
|
|
|
6
6
|
* @param multiple Should this call return an array of instantiated references, or just a single? Defaults to false, returning a single instance
|
|
7
7
|
* @returns A promise that resolves to a Proxy of the initialized DOMNodeReference instance.
|
|
8
8
|
*/
|
|
9
|
-
export default function createDOMNodeReference(target: HTMLElement | string, multiple?: (() => boolean) | boolean): Promise<DOMNodeReference |
|
|
9
|
+
export default function createDOMNodeReference(target: HTMLElement | string, multiple?: (() => boolean) | boolean): Promise<DOMNodeReference | DOMNodeReference[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "powerpagestoolkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.01",
|
|
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",
|
|
@@ -58,7 +58,8 @@
|
|
|
58
58
|
"files": [
|
|
59
59
|
"dist/bundle.js",
|
|
60
60
|
"dist/bundle.css",
|
|
61
|
-
"dist/**/*.d.ts"
|
|
61
|
+
"dist/**/*.d.ts",
|
|
62
|
+
"assets/**"
|
|
62
63
|
],
|
|
63
64
|
"exports": {
|
|
64
65
|
".": {
|