wj-elements 0.1.96 → 0.1.98

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.
@@ -16,6 +16,115 @@ class Checkbox extends WJElement {
16
16
  * The class name.
17
17
  */
18
18
  __publicField(this, "className", "Checkbox");
19
+ this.internals = this.attachInternals();
20
+ }
21
+ /**
22
+ * Setter for the value attribute.
23
+ * @param {string} value - The value to set.
24
+ */
25
+ set value(value) {
26
+ debugger;
27
+ this.internals.setFormValue(value);
28
+ if (this.input)
29
+ this.input.value = value;
30
+ }
31
+ /**
32
+ * Getter for the value attribute.
33
+ * @returns {string} The value of the attribute.
34
+ */
35
+ get value() {
36
+ var _a;
37
+ debugger;
38
+ return ((_a = this.input) == null ? void 0 : _a.value) || "";
39
+ }
40
+ /**
41
+ * Getter for the customErrorDisplay attribute.
42
+ * @returns {boolean} Whether the attribute is present.
43
+ */
44
+ get customErrorDisplay() {
45
+ return this.hasAttribute("custom-error-display");
46
+ }
47
+ /**
48
+ * Getter for the validateOnChange attribute.
49
+ * @returns {boolean} Whether the attribute is present.
50
+ */
51
+ get validateOnChange() {
52
+ return this.hasAttribute("validate-on-change");
53
+ }
54
+ /**
55
+ * Getter for the invalid attribute.
56
+ * @returns {boolean} Whether the attribute is present.
57
+ */
58
+ get invalid() {
59
+ return this.hasAttribute("invalid");
60
+ }
61
+ /**
62
+ * Setter for the invalid attribute.
63
+ * @param {boolean} isInvalid - Whether the input is invalid.
64
+ */
65
+ set invalid(isInvalid) {
66
+ isInvalid ? this.setAttribute("invalid", "") : this.removeAttribute("invalid");
67
+ }
68
+ /**
69
+ * Getter for the form attribute.
70
+ * @returns {HTMLFormElement} The form the input is associated with.
71
+ */
72
+ get form() {
73
+ return this.internals.form;
74
+ }
75
+ /**
76
+ * Getter for the name attribute.
77
+ * @returns {string} The name of the input.
78
+ */
79
+ get name() {
80
+ return this.getAttribute("name");
81
+ }
82
+ /**
83
+ * Getter for the type attribute.
84
+ * @returns {string} The type of the input.
85
+ */
86
+ get type() {
87
+ return this.localName;
88
+ }
89
+ /**
90
+ * Getter for the validity attribute.
91
+ * @returns {ValidityState} The validity state of the input.
92
+ */
93
+ get validity() {
94
+ return this.internals.validity;
95
+ }
96
+ /**
97
+ * Getter for the validationMessage attribute.
98
+ * @returns {string} The validation message of the input.
99
+ */
100
+ get validationMessage() {
101
+ return this.internals.validationMessage;
102
+ }
103
+ /**
104
+ * Getter for the willValidate attribute.
105
+ * @returns {boolean} Whether the input will be validated.
106
+ */
107
+ get willValidate() {
108
+ return this.internals.willValidate;
109
+ }
110
+ /**
111
+ * @summary Getter for the defaultValue attribute.
112
+ * This method retrieves the 'value' attribute of the custom input element.
113
+ * The 'value' attribute represents the default value of the input element.
114
+ * If the 'value' attribute is not set, it returns an empty string.
115
+ * @returns {string} The default value of the input element.
116
+ */
117
+ get defaultValue() {
118
+ return this.getAttribute("value") ?? "";
119
+ }
120
+ /**
121
+ * @summary Setter for the defaultValue attribute.
122
+ * This method sets the 'value' attribute of the custom input element to the provided value.
123
+ * The 'value' attribute represents the default value of the input element.
124
+ * @param {string} value - The value to set as the default value.
125
+ */
126
+ set defaultValue(value) {
127
+ this.setAttribute("value", value);
19
128
  }
20
129
  /**
21
130
  * @summary Set checked attribute
@@ -59,7 +168,7 @@ class Checkbox extends WJElement {
59
168
  return styles;
60
169
  }
61
170
  static get observedAttributes() {
62
- return ["checked", "disabled"];
171
+ return ["checked", "disabled", "value"];
63
172
  }
64
173
  /**
65
174
  * Sets up the attributes for the checkbox.
@@ -101,10 +210,12 @@ class Checkbox extends WJElement {
101
210
  afterDraw() {
102
211
  if (!this.disabled) {
103
212
  this.input.addEventListener("input", (e) => {
213
+ this.value = e.target.checked;
104
214
  this.checked = e.target.checked;
105
215
  event.dispatchCustomEvent(this, "wje-toggle:input");
106
216
  });
107
217
  this.input.addEventListener("change", (e) => {
218
+ this.value = e.target.checked;
108
219
  this.checked = e.target.checked;
109
220
  event.dispatchCustomEvent(this, "wje-toggle:change");
110
221
  });
@@ -116,7 +227,68 @@ class Checkbox extends WJElement {
116
227
  disconnectedCallback() {
117
228
  event.removeElement(this.input);
118
229
  }
230
+ /**
231
+ * @summary Callback function that is called when the custom element is associated with a form.
232
+ * This function adds an event listener to the form's submit event, which validates the input and propagates the validation.
233
+ * @param {HTMLFormElement} form - The form the custom element is associated with.
234
+ */
235
+ formAssociatedCallback(form) {
236
+ form.addEventListener("submit", () => {
237
+ });
238
+ }
239
+ /**
240
+ * The formResetCallback method is a built-in lifecycle callback that gets called when a form gets reset.
241
+ * This method is responsible for resetting the value of the custom input element to its default value.
242
+ * It also resets the form value and validity state in the form internals.
243
+ *
244
+ * @method
245
+ */
246
+ formResetCallback() {
247
+ this.value = this.defaultValue;
248
+ this.internals.setFormValue(this.defaultValue);
249
+ this.internals.setValidity({});
250
+ }
251
+ /**
252
+ * The formStateRestoreCallback method is a built-in lifecycle callback that gets called when the state of a form-associated custom element is restored.
253
+ * This method is responsible for restoring the value of the custom input element to its saved state.
254
+ * It also restores the form value and validity state in the form internals to their saved states.
255
+ *
256
+ * @param {Object} state - The saved state of the custom input element.
257
+ * @method
258
+ */
259
+ formStateRestoreCallback(state) {
260
+ this.value = state.value;
261
+ this.internals.setFormValue(state.value);
262
+ this.internals.setValidity({});
263
+ }
264
+ /**
265
+ * The formStateSaveCallback method is a built-in lifecycle callback that gets called when the state of a form-associated custom element is saved.
266
+ * This method is responsible for saving the value of the custom input element.
267
+ *
268
+ * @returns {Object} The saved state of the custom input element.
269
+ * @method
270
+ */
271
+ formStateSaveCallback() {
272
+ return {
273
+ value: this.value
274
+ };
275
+ }
276
+ /**
277
+ * The formDisabledCallback method is a built-in lifecycle callback that gets called when the disabled state of a form-associated custom element changes.
278
+ * This method is not implemented yet.
279
+ *
280
+ * @param {boolean} disabled - The new disabled state of the custom input element.
281
+ * @method
282
+ */
283
+ formDisabledCallback(disabled) {
284
+ console.warn("formDisabledCallback not implemented yet");
285
+ }
119
286
  }
287
+ /**
288
+ * Whether the input is associated with a form.
289
+ * @type {boolean}
290
+ */
291
+ __publicField(Checkbox, "formAssociated", true);
120
292
  WJElement.define("wje-checkbox", Checkbox);
121
293
  export {
122
294
  Checkbox as default
@@ -49,9 +49,9 @@ class Dialog extends WJElement {
49
49
  setupAttributes() {
50
50
  this.isShadowRoot = "open";
51
51
  }
52
- draw(context, store, params2) {
52
+ draw(context, store, params) {
53
53
  let fragment = document.createDocumentFragment();
54
- this.classList.add("fade", this.placement, params2.size);
54
+ this.classList.add("fade", this.placement, params.size);
55
55
  let slot = document.createElement("slot");
56
56
  let dialog = document.createElement("dialog");
57
57
  dialog.classList.add("modal-dialog");
@@ -96,14 +96,15 @@ class Dialog extends WJElement {
96
96
  close() {
97
97
  this.onClose();
98
98
  }
99
- afterDraw(context, store, params2) {
100
- if (params2.trigger) {
101
- event.addListener(document, params2.trigger, null, this.onOpen);
99
+ afterDraw(context, store, params) {
100
+ if (params.trigger) {
101
+ event.addListener(document, params.trigger, null, this.onOpen);
102
102
  }
103
103
  }
104
104
  beforeDisconnect() {
105
- if (params.trigger) {
106
- event.removeListener(document, params.trigger, null, this.onOpen);
105
+ var _a, _b;
106
+ if ((_a = this.params) == null ? void 0 : _a.trigger) {
107
+ event.removeListener(document, (_b = this.params) == null ? void 0 : _b.trigger, null, this.onOpen);
107
108
  }
108
109
  }
109
110
  beforeOpen() {
@@ -1526,7 +1526,10 @@ class Routerx extends WJElement {
1526
1526
  const attributeName = attributes[i].name;
1527
1527
  const attributeValue = attributes[i].value;
1528
1528
  if (attributeName === "component" && attributeValue.indexOf(".js") > -1) {
1529
- obj.component = () => import(attributeValue);
1529
+ obj.component = () => import(
1530
+ /*vite-ignore*/
1531
+ attributeValue
1532
+ );
1530
1533
  } else {
1531
1534
  if (attributeName !== "shadow") {
1532
1535
  const camelCase = attributeName.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
@@ -66,6 +66,110 @@ class Select extends WJElement {
66
66
  });
67
67
  this._selected = [];
68
68
  this.counterEl = null;
69
+ this.internals = this.attachInternals();
70
+ }
71
+ /**
72
+ * Setter for the value attribute.
73
+ * @param {string} value - The value to set.
74
+ */
75
+ set value(value) {
76
+ this.internals.setFormValue(JSON.stringify(value));
77
+ }
78
+ /**
79
+ * Getter for the value attribute.
80
+ * @returns {string} The value of the attribute.
81
+ */
82
+ get value() {
83
+ return this.selected;
84
+ }
85
+ /**
86
+ * Getter for the customErrorDisplay attribute.
87
+ * @returns {boolean} Whether the attribute is present.
88
+ */
89
+ get customErrorDisplay() {
90
+ return this.hasAttribute("custom-error-display");
91
+ }
92
+ /**
93
+ * Getter for the validateOnChange attribute.
94
+ * @returns {boolean} Whether the attribute is present.
95
+ */
96
+ get validateOnChange() {
97
+ return this.hasAttribute("validate-on-change");
98
+ }
99
+ /**
100
+ * Getter for the invalid attribute.
101
+ * @returns {boolean} Whether the attribute is present.
102
+ */
103
+ get invalid() {
104
+ return this.hasAttribute("invalid");
105
+ }
106
+ /**
107
+ * Setter for the invalid attribute.
108
+ * @param {boolean} isInvalid - Whether the input is invalid.
109
+ */
110
+ set invalid(isInvalid) {
111
+ isInvalid ? this.setAttribute("invalid", "") : this.removeAttribute("invalid");
112
+ }
113
+ /**
114
+ * Getter for the form attribute.
115
+ * @returns {HTMLFormElement} The form the input is associated with.
116
+ */
117
+ get form() {
118
+ return this.internals.form;
119
+ }
120
+ /**
121
+ * Getter for the name attribute.
122
+ * @returns {string} The name of the input.
123
+ */
124
+ get name() {
125
+ return this.getAttribute("name");
126
+ }
127
+ /**
128
+ * Getter for the type attribute.
129
+ * @returns {string} The type of the input.
130
+ */
131
+ get type() {
132
+ return this.localName;
133
+ }
134
+ /**
135
+ * Getter for the validity attribute.
136
+ * @returns {ValidityState} The validity state of the input.
137
+ */
138
+ get validity() {
139
+ return this.internals.validity;
140
+ }
141
+ /**
142
+ * Getter for the validationMessage attribute.
143
+ * @returns {string} The validation message of the input.
144
+ */
145
+ get validationMessage() {
146
+ return this.internals.validationMessage;
147
+ }
148
+ /**
149
+ * Getter for the willValidate attribute.
150
+ * @returns {boolean} Whether the input will be validated.
151
+ */
152
+ get willValidate() {
153
+ return this.internals.willValidate;
154
+ }
155
+ /**
156
+ * @summary Getter for the defaultValue attribute.
157
+ * This method retrieves the 'value' attribute of the custom input element.
158
+ * The 'value' attribute represents the default value of the input element.
159
+ * If the 'value' attribute is not set, it returns an empty string.
160
+ * @returns {string} The default value of the input element.
161
+ */
162
+ get defaultValue() {
163
+ return this.getAttribute("value") ?? "";
164
+ }
165
+ /**
166
+ * @summary Setter for the defaultValue attribute.
167
+ * This method sets the 'value' attribute of the custom input element to the provided value.
168
+ * The 'value' attribute represents the default value of the input element.
169
+ * @param {string} value - The value to set as the default value.
170
+ */
171
+ set defaultValue(value) {
172
+ this.setAttribute("value", value);
69
173
  }
70
174
  /**
71
175
  * Sets the selected value.
@@ -306,7 +410,7 @@ class Select extends WJElement {
306
410
  */
307
411
  selectionChanged(option = null, length = 0) {
308
412
  if (this.hasAttribute("multiple")) {
309
- this.value = this.selectedOptions.map((el) => el).reverse();
413
+ this.value = this.selectedOptions.map((el) => el.value).reverse();
310
414
  if (this.placeholder && length === 0) {
311
415
  this.chips.innerHTML = this.placeholder;
312
416
  this.input.value = "";
@@ -386,7 +490,68 @@ class Select extends WJElement {
386
490
  chip.appendChild(label);
387
491
  return chip;
388
492
  }
493
+ /**
494
+ * @summary Callback function that is called when the custom element is associated with a form.
495
+ * This function adds an event listener to the form's submit event, which validates the input and propagates the validation.
496
+ * @param {HTMLFormElement} form - The form the custom element is associated with.
497
+ */
498
+ formAssociatedCallback(form) {
499
+ form.addEventListener("submit", () => {
500
+ });
501
+ }
502
+ /**
503
+ * The formResetCallback method is a built-in lifecycle callback that gets called when a form gets reset.
504
+ * This method is responsible for resetting the value of the custom input element to its default value.
505
+ * It also resets the form value and validity state in the form internals.
506
+ *
507
+ * @method
508
+ */
509
+ formResetCallback() {
510
+ this.value = this.defaultValue;
511
+ this.internals.setFormValue(this.defaultValue);
512
+ this.internals.setValidity({});
513
+ }
514
+ /**
515
+ * The formStateRestoreCallback method is a built-in lifecycle callback that gets called when the state of a form-associated custom element is restored.
516
+ * This method is responsible for restoring the value of the custom input element to its saved state.
517
+ * It also restores the form value and validity state in the form internals to their saved states.
518
+ *
519
+ * @param {Object} state - The saved state of the custom input element.
520
+ * @method
521
+ */
522
+ formStateRestoreCallback(state) {
523
+ this.value = state.value;
524
+ this.internals.setFormValue(state.value);
525
+ this.internals.setValidity({});
526
+ }
527
+ /**
528
+ * The formStateSaveCallback method is a built-in lifecycle callback that gets called when the state of a form-associated custom element is saved.
529
+ * This method is responsible for saving the value of the custom input element.
530
+ *
531
+ * @returns {Object} The saved state of the custom input element.
532
+ * @method
533
+ */
534
+ formStateSaveCallback() {
535
+ return {
536
+ value: this.value
537
+ };
538
+ }
539
+ /**
540
+ * The formDisabledCallback method is a built-in lifecycle callback that gets called when the disabled state of a form-associated custom element changes.
541
+ * This method is not implemented yet.
542
+ *
543
+ * @param {boolean} disabled - The new disabled state of the custom input element.
544
+ * @method
545
+ */
546
+ formDisabledCallback(disabled) {
547
+ console.warn("formDisabledCallback not implemented yet");
548
+ }
389
549
  }
550
+ /**
551
+ * Whether the input is associated with a form.
552
+ * @type {boolean}
553
+ */
554
+ __publicField(Select, "formAssociated", true);
390
555
  Select.define("wje-select", Select);
391
556
  export {
392
557
  Select as default
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wj-elements",
3
3
  "description": "WebJET Elements is a modern set of user interface tools harnessing the power of web components designed to simplify web application development.",
4
- "version": "0.1.96",
4
+ "version": "0.1.98",
5
5
  "homepage": "https://github.com/lencys/wj-elements",
6
6
  "author": "Lukáš Ondrejček <lukas.ondrejcek@gmail.com>",
7
7
  "license": "MIT",