@optionfactory/ful 1.0.8 → 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.iife.js CHANGED
@@ -88,6 +88,16 @@ var ful = (function (exports, ftl) {
88
88
  this.name = 'Failure';
89
89
  this.problems = problems;
90
90
  }
91
+ dropping(prefix){
92
+ return new Failure(this.message, Failure.dropProblemsContext(this.problems, prefix), this);
93
+ }
94
+ static dropProblemsContext(problems, prefix){
95
+ return problems.map(({type, context, reason, details}) => {
96
+ const nctx = context?.startsWith(prefix) ? context.substring(prefix.length) : context;
97
+ return {type, context: nctx, reason, details};
98
+ })
99
+ }
100
+
91
101
  }
92
102
 
93
103
  class MediaType {
@@ -141,6 +151,9 @@ var ful = (function (exports, ftl) {
141
151
  this.name = 'HttpClientError';
142
152
  this.status = status;
143
153
  }
154
+ dropping(prefix){
155
+ return new HttpClientError(this.message, this.status, Failure.dropProblemsContext(this.problems, prefix), this);
156
+ }
144
157
  /**
145
158
  *
146
159
  * @param {string} type
@@ -1130,15 +1143,16 @@ var ful = (function (exports, ftl) {
1130
1143
  /**
1131
1144
  * @param {{ [x: string]: any; }} obj
1132
1145
  * @param {string} prefix
1146
+ * @param {Set<String>} stops
1133
1147
  * @return {{ [x: string]: any; }}
1134
1148
  */
1135
- static flatten(obj, prefix) {
1149
+ static flatten(obj, prefix, stops) {
1136
1150
  return Object.keys(obj).reduce((acc, k) => {
1137
- const pre = prefix.length ? prefix + '.' : '';
1138
- if (typeof obj[k] === 'object' && obj[k] !== null) {
1139
- Object.assign(acc, Bindings.flatten(obj[k], pre + k));
1151
+ const pre = prefix.length ? prefix + '.' + k : k;
1152
+ if (!stops.has(prefix) && typeof obj[k] === 'object' && obj[k] !== null) {
1153
+ Object.assign(acc, Bindings.flatten(obj[k], pre, stops));
1140
1154
  } else {
1141
- acc[pre + k] = obj[k];
1155
+ acc[pre] = obj[k];
1142
1156
  }
1143
1157
  return acc;
1144
1158
  }, {});
@@ -1233,7 +1247,10 @@ var ful = (function (exports, ftl) {
1233
1247
  }
1234
1248
 
1235
1249
  static mutateIn(form, values){
1236
- for (const [flattenedKey, value] of Object.entries(Bindings.flatten(values, ''))) {
1250
+ const names = Array.from(form.form.elements)
1251
+ .map(el => el.getAttribute("name"))
1252
+ .filter(n => n);
1253
+ for (const [flattenedKey, value] of Object.entries(Bindings.flatten(values, '', new Set(names)))) {
1237
1254
  for(const el of form.querySelectorAll(`[name='${CSS.escape(flattenedKey)}']`)){
1238
1255
  Bindings.mutate(el, value);
1239
1256
  }
@@ -1435,10 +1452,10 @@ var ful = (function (exports, ftl) {
1435
1452
  this.replaceChildren(fragment);
1436
1453
  }
1437
1454
  get value() {
1438
- return this.#input.value;
1455
+ return this.#input.value === '' ? null : this.#input.value;
1439
1456
  }
1440
1457
  set value(value) {
1441
- this.#input.value = value;
1458
+ this.#input.value = value === '' ? null : value;
1442
1459
  }
1443
1460
  get readonly(){
1444
1461
  return this.#input.readOnly;