@optionfactory/ful 0.91.0 → 0.93.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.
package/dist/ful.iife.js CHANGED
@@ -90,6 +90,38 @@ var ful = (function (exports) {
90
90
  }
91
91
  }
92
92
 
93
+ class MediaType {
94
+ #type;
95
+ #subtype;
96
+ constructor(type, subtype) {
97
+ this.#type = type;
98
+ this.#subtype = subtype;
99
+ }
100
+ get normalized(){
101
+ return `${this.#type}/${this.#subtype}`;
102
+ }
103
+ get type() {
104
+ return this.#type;
105
+ }
106
+ get subtype() {
107
+ return this.#subtype;
108
+ }
109
+ /**
110
+ *
111
+ * @param {string|null|undefined} v
112
+ * @returns
113
+ */
114
+ static parse(v) {
115
+ if (!v) {
116
+ return new MediaType("unknown", "unknown");
117
+ }
118
+ const [prefix, _] = v.split(";");
119
+ const [ptype, psubtype] = prefix.trim().split("/");
120
+ return new MediaType(ptype.toLowerCase(), psubtype?.toLowerCase());
121
+ }
122
+ }
123
+
124
+
93
125
  /**
94
126
  * @typedef {Int8Array| Uint8Array| Uint8ClampedArray| Int16Array| Uint16Array| Int32Array| Uint32Array| Float32Array| Float64Array| BigInt64Array| BigUint64Array} TypedArray
95
127
  */
@@ -130,18 +162,32 @@ var ful = (function (exports) {
130
162
  * @returns an HttpClientError
131
163
  */
132
164
  static async fromResponse(response) {
133
- const text = await response.text();
134
- const message = `${response.status} ${response.statusText}: ${text}`;
135
- const fallback = [{
136
- type: "GENERIC_PROBLEM",
137
- context: null,
138
- reason: message,
139
- details: null
140
- }];
141
- try {
142
- return new HttpClientError(message, response.status, text ? JSON.parse(text) : fallback);
143
- } catch (e) {
144
- return new HttpClientError(message, response.status, fallback);
165
+ switch(MediaType.parse(response.headers.get("Content-Type")).normalized){
166
+ case 'application/failures+json': {
167
+ const data = await response.json();
168
+ const message = `${response.status} ${response.statusText}: ${data.length} failures`;
169
+ return new HttpClientError(message, response.status, data);
170
+ }
171
+ case 'application/problem+json': {
172
+ const data = await response.json();
173
+ const message = `${response.status} ${response.statusText}: ${data.title} ${data.detail}`;
174
+ return new HttpClientError(message, response.status, data.problems || [{
175
+ type: "GENERIC_PROBLEM",
176
+ context: null,
177
+ reason: message,
178
+ details: null
179
+ }]);
180
+ }
181
+ default: {
182
+ const text = await response.text();
183
+ const message = `${response.status} ${response.statusText}: ${text}`;
184
+ return new HttpClientError(message, response.status, [{
185
+ type: "GENERIC_PROBLEM",
186
+ context: null,
187
+ reason: message,
188
+ details: null
189
+ }]);
190
+ }
145
191
  }
146
192
  }
147
193
  }
@@ -154,9 +200,9 @@ var ful = (function (exports) {
154
200
  constructor() {
155
201
  this.#k = document.querySelector("meta[name='_csrf_header']")?.getAttribute("content");
156
202
  this.#v = document.querySelector("meta[name='_csrf']")?.getAttribute("content");
157
- }
203
+ }
158
204
  async intercept(request, chain) {
159
- if(this.#k && this.#v) {
205
+ if (this.#k && this.#v) {
160
206
  request.headers.set(this.#k, this.#v);
161
207
  }
162
208
  return await chain.proceed(request);
@@ -468,6 +514,7 @@ var ful = (function (exports) {
468
514
  const builder = new HttpMultipartRequestCustomizer(formData);
469
515
  callback(builder);
470
516
  this.#body = formData;
517
+ return this;
471
518
  }
472
519
  /**
473
520
  * Sets a fetch options for the request.
@@ -591,7 +638,7 @@ var ful = (function (exports) {
591
638
  *
592
639
  * @param {FormData} formData
593
640
  */
594
- constructor(formData){
641
+ constructor(formData) {
595
642
  this.#formData = formData;
596
643
  }
597
644
  /**
@@ -600,7 +647,7 @@ var ful = (function (exports) {
600
647
  * @param {*} value
601
648
  * @returns this builder
602
649
  */
603
- field(name, value){
650
+ field(name, value) {
604
651
  this.#formData.append(name, value);
605
652
  return this;
606
653
  }
@@ -614,10 +661,24 @@ var ful = (function (exports) {
614
661
  * @param {string|undefined} filename
615
662
  * @returns this builder
616
663
  */
617
- blob(name, value, filename){
664
+ blob(name, value, filename) {
618
665
  this.#formData.append(name, value, filename);
619
666
  return this;
620
667
  }
668
+ /**
669
+ * Appends multiple Blobs to the FormData with the same name.
670
+ * The default filename for Blob objects is "blob";
671
+ * The default filename for File objects is the file's filename.
672
+ * @param {string} name
673
+ * @param {Blob[]} values
674
+ * @returns this builder
675
+ */
676
+ blobs(name, values) {
677
+ for (let v of values) {
678
+ this.#formData.append(name, v);
679
+ }
680
+ return this;
681
+ }
621
682
  /**
622
683
  * Appends a JSON serialized blob to the FormData.
623
684
  * @param {string} name
@@ -625,8 +686,8 @@ var ful = (function (exports) {
625
686
  * @param {string|undefined} filename
626
687
  * @returns this builder
627
688
  */
628
- json(name, value, filename){
629
- const blob = new Blob([JSON.stringify(value)], {type: 'application/json'});
689
+ json(name, value, filename) {
690
+ const blob = new Blob([JSON.stringify(value)], { type: 'application/json' });
630
691
  this.#formData.append(name, blob, filename);
631
692
  return this;
632
693
  }
@@ -1401,6 +1462,7 @@ var ful = (function (exports) {
1401
1462
  static IGNORED_CHILDREN_SELECTOR = '.d-none, [hidden]';
1402
1463
  static SCROLL_OFFSET = 50;
1403
1464
  static INVALID_CLASS = 'is-invalid';
1465
+ submitter;
1404
1466
  render() {
1405
1467
  const form = document.createElement('form');
1406
1468
  form.replaceChildren(...this.childNodes);
@@ -1413,8 +1475,14 @@ var ful = (function (exports) {
1413
1475
  this.replaceChildren(form);
1414
1476
  }
1415
1477
  spinner(spin) {
1416
- this.querySelectorAll('ful-spinner').forEach(el => el.hidden = !spin);
1417
- this.querySelectorAll('[type=submit],[type=reset]').forEach(el => el.disabled = spin);
1478
+ this.querySelectorAll('ful-spinner').forEach(el => {
1479
+ const hel = /** @type HTMLElement} */ (el);
1480
+ hel.hidden = !spin;
1481
+ });
1482
+ this.querySelectorAll('[type=submit],[type=reset]').forEach(el => {
1483
+ const hel = /** @type HTMLButtonElement} */ (el);
1484
+ hel.disabled = spin;
1485
+ });
1418
1486
  }
1419
1487
  async remoting(fn) {
1420
1488
  try {
@@ -1449,7 +1517,7 @@ var ful = (function (exports) {
1449
1517
  }
1450
1518
  }
1451
1519
  get values() {
1452
- return Array.from(this.querySelectorAll('[name]'))
1520
+ return Array.from(/** @type {NodeListOf<HTMLElement>} */ (this.querySelectorAll('[name]')))
1453
1521
  .filter(el => {
1454
1522
  if (el.dataset['fulBindInclude'] === 'never') {
1455
1523
  return false;
@@ -1473,10 +1541,14 @@ var ful = (function (exports) {
1473
1541
  const validationTargetsSelector = `[name='${CSS.escape(name)}'] [ful-validation-target],[name='${CSS.escape(name)}']:not(:has([ful-validation-target]))`;
1474
1542
  this.querySelectorAll(validationTargetsSelector).forEach(input => input.classList.add(Form.INVALID_CLASS));
1475
1543
  const fieldErrorsSelector = `ful-field-error[field='${CSS.escape(name)}']`;
1476
- this.querySelectorAll(fieldErrorsSelector).forEach(el => el.innerText = e.reason);
1544
+ this.querySelectorAll(fieldErrorsSelector).forEach(el => {
1545
+ const hel = /** @type HTMLElement} */ (el);
1546
+ hel.innerText = e.reason;
1547
+ });
1477
1548
  });
1478
1549
  this.querySelectorAll("ful-errors").forEach(el => {
1479
- el.innerText = globalErrors.map(e => e.reason).join("\n");
1550
+ const hel = /** @type HTMLElement} */ (el);
1551
+ hel.innerText = globalErrors.map(e => e.reason).join("\n");
1480
1552
  if (globalErrors.length !== 0) {
1481
1553
  el.removeAttribute('hidden');
1482
1554
  }
@@ -1575,6 +1647,8 @@ var ful = (function (exports) {
1575
1647
  </div>
1576
1648
  `
1577
1649
  }) {
1650
+ shouldLoad;
1651
+ _unwrappedRemoteLoad;
1578
1652
  constructor(tsConfig) {
1579
1653
  super();
1580
1654
  this.tsConfig = tsConfig;
@@ -1626,6 +1700,7 @@ var ful = (function (exports) {
1626
1700
  }
1627
1701
  callback(data);
1628
1702
  };
1703
+ // @ts-ignore
1629
1704
  this.ts = new TomSelect(input, Object.assign(remote ? {
1630
1705
  preload: 'focus',
1631
1706
  load: this._unwrappedRemoteLoad,
@@ -1778,6 +1853,7 @@ var ful = (function (exports) {
1778
1853
  exports.Input = Input;
1779
1854
  exports.LightSlots = LightSlots;
1780
1855
  exports.LocalStorage = LocalStorage;
1856
+ exports.MediaType = MediaType;
1781
1857
  exports.Nodes = Nodes;
1782
1858
  exports.ParsedElement = ParsedElement;
1783
1859
  exports.RadioGroup = RadioGroup;