powerpagestoolkit 1.2.2 → 1.3.0

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.
Files changed (4) hide show
  1. package/README.md +203 -1
  2. package/dist/index.bundle.js +206 -194032
  3. package/index.d.ts +205 -181
  4. package/package.json +5 -7
package/README.md CHANGED
@@ -1 +1,203 @@
1
- # PowerPagesToolKit
1
+ # PowerPages Tool Kit
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.
4
+
5
+ ## Installation
6
+
7
+ After installing
8
+
9
+ `npm install powerpagestoolkit`
10
+
11
+ You can then import into your JavaScript files as follows:
12
+
13
+ ```javascript
14
+ import {
15
+ API,
16
+ createDOMNodeReference,
17
+ createMultipleDOMNodeReferences,
18
+ } from "powerpagestoolkit";
19
+ ```
20
+
21
+ # Modules
22
+
23
+ ## `DOMNodereference`
24
+
25
+ The `DOMNodeReference` module simplifies DOM element management. It provides functionalities for creating and interacting with DOM elements:
26
+
27
+ ### Usage
28
+
29
+ - **`createDOMNodeReference(selector)`**: Creates a `DOMNodeReference` instance for a single DOM element specified by a CSS selector or HTMLElement. Returns a `DOMNodeReference` instance.
30
+
31
+ - **`createMultipleDOMNodeReferences(selector)`**: Creates multiple `DOMNodeReference` instances for all elements matching the specified CSS selector. Returns an array of `DOMNodeReference` instances.
32
+
33
+ ```javascript
34
+ // single instance of DOMNodeReference
35
+ const node = await createDOMNodeReference("#my-element");
36
+
37
+ node.onceLoaded(() => {
38
+ console.log("Element is loaded: ", node.element);
39
+ });
40
+
41
+ // to imitate 'querySelectorAll', and return an array of DOMNodeReferences
42
+ const nodeArray = await createMultipleDOMNodeReferences('div[class="row"]');
43
+
44
+ nodeArray.forEach((node) => {
45
+ node.oneLoaded(() => {
46
+ console.log("Element loaded: ", node.element")
47
+ })
48
+ })
49
+ ```
50
+
51
+ ##### Properties
52
+
53
+ ```typescript
54
+ target: string;
55
+ element: HTMLElement | null;
56
+ isLoaded: boolean;
57
+ visibilityController: HTMLElement | null;
58
+ defaultDisplay: string;
59
+ value: string | null;
60
+ ```
61
+
62
+ ##### Methods
63
+
64
+ Here are the key methods you can use with a DOMNodeReference instance:
65
+
66
+ ```typescript
67
+
68
+ // Hides the associated DOM element.
69
+ hide()
70
+
71
+ // Shows the associated DOM element.
72
+ show()
73
+
74
+ // Sets the value of the associated HTML element.
75
+ setValue(value: string)
76
+
77
+ // Appends child elements to the associated HTML element.
78
+ append(...elements: HTMLElement[])
79
+
80
+ // Inserts elements after the associated HTML element.
81
+ after(...elements: HTMLElement[])
82
+
83
+ // Retrieves the label associated with the HTML element.
84
+ getLabel(): HTMLElement | null
85
+
86
+ // Appends child elements to the label associated with the HTML element.
87
+ appendToLabel(...elements: HTMLElement[])
88
+
89
+ // Adds a click event listener to the associated HTML element.
90
+ addClickListener(eventHandler: () => void)
91
+
92
+ // Adds a change event listener to the associated HTML element.
93
+ addChangeListener(eventHandler: () => void)
94
+
95
+ // Unchecks both yes and no radio buttons if they exist.
96
+ uncheckRadios()
97
+
98
+ //Creates a validation instance for the field.
99
+ createValidation(evaluationFunction: () => boolean, fieldDisplayName: string)
100
+
101
+ // Adds a tooltip to the label associated with the HTML element.
102
+ addLabelTooltip(text: string)
103
+
104
+ // Adds a tooltip to the associated HTML element.
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)
116
+
117
+ // Executes a callback function once the element is fully loaded.
118
+ onceLoaded(callback: (instance: DOMNodeReference) => void)
119
+
120
+ ```
121
+
122
+ ## `API`
123
+
124
+ The `API` module provides functions for creating and retrieving records from a DataVerse. It includes the following methods:
125
+
126
+ - **`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.
127
+ - **`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.
128
+
129
+ - **`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
+
131
+ ### Usage
132
+
133
+ ###### 1. Creating a Record
134
+
135
+ 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.
136
+
137
+ ```javascript
138
+ // Assuming you have a schema class defined
139
+ const schema = new YourSchemaClass({
140
+ name: "Sample Record",
141
+ description: "This is a sample record for demonstration.",
142
+ });
143
+
144
+ API.createRecord(schema)
145
+ .then((recordId) => {
146
+ console.log("Record created successfully with ID:", recordId);
147
+ })
148
+ .catch((error) => {
149
+ console.error("Error creating record:", error);
150
+ });
151
+ ```
152
+
153
+ ###### 2. Getting a Single Record
154
+
155
+ To retrieve a specific record from the DataVerse, use the `getRecord` method. You need to provide the table set name and the record ID.
156
+
157
+ ```javascript
158
+ const tableSetName = "accounts"; // The DataVerse table set name
159
+ const recordID = "your-record-id"; // The GUID of the record to retrieve
160
+
161
+ API.getRecord(tableSetName, recordID)
162
+ .then((record) => {
163
+ console.log("Retrieved record:", record);
164
+ })
165
+ .catch((error) => {
166
+ console.error("Error retrieving record:", error);
167
+ });
168
+ ```
169
+
170
+ ###### 3. Getting Multiple Records
171
+
172
+ 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.
173
+
174
+ ```javascript
175
+ const tableSetName = "contacts"; // The DataVerse table set name
176
+ const queryParameters =
177
+ "$filter=firstName eq 'John'&$select=firstName,lastName"; // OData query parameters
178
+
179
+ API.getMultiple(tableSetName, queryParameters)
180
+ .then((records) => {
181
+ console.log("Retrieved records:", records);
182
+ })
183
+ .catch((error) => {
184
+ console.error("Error retrieving records:", error);
185
+ });
186
+ ```
187
+
188
+ ##### Example Schema Class
189
+
190
+ Here's a simple example of a schema class that you might use with the createRecord method:
191
+
192
+ ```javascript
193
+ class YourSchemaClass {
194
+ constructor(tableSetName, data) {
195
+ this.setName = tableSetName;
196
+ this.data = data;
197
+ }
198
+
199
+ value() {
200
+ return JSON.stringify(this.data); // Convert data to JSON format for the API
201
+ }
202
+ }
203
+ ```