@optionfactory/ful 1.0.7 → 1.0.9

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.mjs CHANGED
@@ -87,6 +87,16 @@ class Failure extends Error {
87
87
  this.name = 'Failure';
88
88
  this.problems = problems;
89
89
  }
90
+ dropping(prefix){
91
+ return new Failure(this.message, Failure.dropProblemsContext(this.problems, prefix), this);
92
+ }
93
+ static dropProblemsContext(problems, prefix){
94
+ return problems.map(({type, context, reason, details}) => {
95
+ const nctx = context?.startsWith(prefix) ? context.substring(prefix.length) : context;
96
+ return {type, context: nctx, reason, details};
97
+ })
98
+ }
99
+
90
100
  }
91
101
 
92
102
  class MediaType {
@@ -140,6 +150,9 @@ class HttpClientError extends Failure {
140
150
  this.name = 'HttpClientError';
141
151
  this.status = status;
142
152
  }
153
+ dropping(prefix){
154
+ return new HttpClientError(this.message, this.status, Failure.dropProblemsContext(this.problems, prefix), this);
155
+ }
143
156
  /**
144
157
  *
145
158
  * @param {string} type
@@ -1129,15 +1142,16 @@ class Bindings {
1129
1142
  /**
1130
1143
  * @param {{ [x: string]: any; }} obj
1131
1144
  * @param {string} prefix
1145
+ * @param {Set<String>} stops
1132
1146
  * @return {{ [x: string]: any; }}
1133
1147
  */
1134
- static flatten(obj, prefix) {
1148
+ static flatten(obj, prefix, stops) {
1135
1149
  return Object.keys(obj).reduce((acc, k) => {
1136
- const pre = prefix.length ? prefix + '.' : '';
1137
- if (typeof obj[k] === 'object' && obj[k] !== null) {
1138
- Object.assign(acc, Bindings.flatten(obj[k], pre + k));
1150
+ const pre = prefix.length ? prefix + '.' + k : k;
1151
+ if (!stops.has(prefix) && typeof obj[k] === 'object' && obj[k] !== null) {
1152
+ Object.assign(acc, Bindings.flatten(obj[k], pre, stops));
1139
1153
  } else {
1140
- acc[pre + k] = obj[k];
1154
+ acc[pre] = obj[k];
1141
1155
  }
1142
1156
  return acc;
1143
1157
  }, {});
@@ -1232,7 +1246,10 @@ class Bindings {
1232
1246
  }
1233
1247
 
1234
1248
  static mutateIn(form, values){
1235
- for (const [flattenedKey, value] of Object.entries(Bindings.flatten(values, ''))) {
1249
+ const names = Array.from(form.form.elements)
1250
+ .map(el => el.getAttribute("name"))
1251
+ .filter(n => n);
1252
+ for (const [flattenedKey, value] of Object.entries(Bindings.flatten(values, '', new Set(names)))) {
1236
1253
  for(const el of form.querySelectorAll(`[name='${CSS.escape(flattenedKey)}']`)){
1237
1254
  Bindings.mutate(el, value);
1238
1255
  }
@@ -1392,7 +1409,7 @@ class Form extends ParsedElement {
1392
1409
  }
1393
1410
 
1394
1411
  class Input extends ParsedElement {
1395
- static observed = ['value'];
1412
+ static observed = ['value', 'readonly:presence'];
1396
1413
  static slots = true;
1397
1414
  static template = `
1398
1415
  <label data-tpl-for="id" class="form-label">{{{{ slots.default }}}}</label>
@@ -1434,11 +1451,17 @@ class Input extends ParsedElement {
1434
1451
  this.replaceChildren(fragment);
1435
1452
  }
1436
1453
  get value() {
1437
- return this.#input.value;
1454
+ return this.#input.value === '' ? null : this.#input.value;
1438
1455
  }
1439
1456
  set value(value) {
1440
- this.#input.value = value;
1457
+ this.#input.value = value === '' ? null : value;
1458
+ }
1459
+ get readonly(){
1460
+ return this.#input.readOnly;
1441
1461
  }
1462
+ set readonly(v) {
1463
+ this.#input.readOnly = v;
1464
+ }
1442
1465
  focus(options) {
1443
1466
  this.#input.focus(options);
1444
1467
  }