wangzhibo
2023-10-31 86070cd00485c47a2c5c3ffa4a9bae6648dd05c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
// node_modules/@felte/common/dist/esm/utils/isPlainObject.js
function _isPlainObject(value) {
  return Object.prototype.toString.call(value) === "[object Object]";
}
 
// node_modules/@felte/common/dist/esm/utils/cloneDeep.js
function _cloneDeep(obj) {
  return Object.keys(obj || {}).reduce((res, key) => Object.assign(Object.assign({}, res), { [key]: _isPlainObject(obj[key]) ? _cloneDeep(obj[key]) : Array.isArray(obj[key]) ? [...obj[key]] : obj[key] }), {});
}
 
// node_modules/@felte/common/dist/esm/utils/update.js
function _update(obj, path, updater) {
  if (obj)
    obj = _cloneDeep(obj);
  if (!_isPlainObject(obj))
    obj = {};
  const splitPath = !Array.isArray(path) ? path.match(/[^.[\]]+/g) || [] : path;
  const lastSection = splitPath[splitPath.length - 1];
  if (!lastSection)
    return obj;
  let property = obj;
  for (let i = 0; i < splitPath.length - 1; i++) {
    const section = splitPath[i];
    if (!property[section] || !_isPlainObject(property[section]) && !Array.isArray(property[section])) {
      const nextSection = splitPath[i + 1];
      if (isNaN(Number(nextSection))) {
        property[section] = {};
      } else {
        property[section] = [];
      }
    }
    property = property[section];
  }
  property[lastSection] = updater(property[lastSection]);
  return obj;
}
 
// node_modules/@felte/common/dist/esm/utils/some.js
function _some(obj, pred) {
  const keys = Object.keys(obj);
  return keys.some((key) => pred(obj[key]));
}
 
// node_modules/@felte/common/dist/esm/utils/mapValues.js
function _mapValues(obj, updater) {
  const keys = Object.keys(obj || {});
  return keys.reduce((acc, key) => Object.assign(Object.assign({}, acc), { [key]: updater(obj[key]) }), {});
}
 
// node_modules/@felte/common/dist/esm/external/.pnpm/@rollup_plugin-typescript@10.0.1_rollup@3.25.1_tslib@2.5.3_typescript@4.9.5/external/tslib/tslib.es6.js
function __rest(s, e) {
  var t = {};
  for (var p in s)
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
      t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
}
 
// node_modules/@felte/common/dist/esm/utils/deepSet.js
function handleArray(value) {
  return function(propVal) {
    if (_isPlainObject(propVal)) {
      const _a = deepSet(propVal, value), field = __rest(_a, ["key"]);
      return field;
    }
    return value;
  };
}
function deepSet(obj, value) {
  return _mapValues(obj, (prop) => _isPlainObject(prop) ? deepSet(prop, value) : Array.isArray(prop) ? prop.map(handleArray(value)) : value);
}
 
// node_modules/@felte/common/dist/esm/utils/mergeWith.js
function _mergeWith(...args) {
  const customizer = args.pop();
  const _obj = args.shift();
  if (typeof _obj === "string")
    return _obj;
  const obj = _cloneDeep(_obj);
  if (args.length === 0)
    return obj;
  for (const source of args) {
    if (!source)
      continue;
    if (typeof source === "string")
      return source;
    let rsValue = customizer(obj, source);
    if (typeof rsValue !== "undefined")
      return rsValue;
    const keys = Array.from(new Set(Object.keys(obj).concat(Object.keys(source))));
    for (const key of keys) {
      rsValue = customizer(obj[key], source[key]);
      if (typeof rsValue !== "undefined") {
        obj[key] = rsValue;
      } else if (_isPlainObject(source[key]) && _isPlainObject(obj[key])) {
        obj[key] = _mergeWith(obj[key], source[key], customizer);
      } else if (Array.isArray(source[key])) {
        obj[key] = source[key].map((val, i) => {
          if (!_isPlainObject(val))
            return val;
          const newObj = Array.isArray(obj[key]) ? obj[key][i] : obj[key];
          return _mergeWith(newObj, val, customizer);
        });
      } else if (_isPlainObject(source[key])) {
        const defaultObj = deepSet(_cloneDeep(source[key]), void 0);
        obj[key] = _mergeWith(defaultObj, source[key], customizer);
      } else if (typeof source[key] !== "undefined") {
        obj[key] = source[key];
      }
    }
  }
  return obj;
}
 
// node_modules/@felte/common/dist/esm/utils/defaultsDeep.js
function defaultsCustomizer(objValue, srcValue) {
  if (_isPlainObject(objValue) && _isPlainObject(srcValue))
    return;
  if (Array.isArray(srcValue)) {
    if (srcValue.some(_isPlainObject))
      return;
    const objArray = Array.isArray(objValue) ? objValue : [];
    return srcValue.map((value, index) => {
      var _a;
      return (_a = objArray[index]) !== null && _a !== void 0 ? _a : value;
    });
  }
  if (typeof objValue !== "undefined")
    return objValue;
}
function _defaultsDeep(...args) {
  return _mergeWith(...args, defaultsCustomizer);
}
 
// node_modules/@felte/common/dist/esm/utils/merge.js
function _merge(...args) {
  return _mergeWith(...args, () => void 0);
}
 
// node_modules/@felte/common/dist/esm/utils/get.js
function _get(obj, path, defaultValue) {
  const travel = (regexp) => String.prototype.split.call(path, regexp).filter(Boolean).reduce((res, key) => res !== null && res !== void 0 ? res[key] : res, obj);
  const result = travel(/[,[\]]+?/) || travel(/[,[\].]+?/);
  return result === void 0 || result === obj ? defaultValue : result;
}
 
// node_modules/@felte/common/dist/esm/utils/set.js
function _set(obj, path, value) {
  return _update(obj, path, () => value);
}
 
// node_modules/@felte/common/dist/esm/utils/unset.js
function _unset(obj, path) {
  if (!obj || Object(obj) !== obj)
    return;
  else if (typeof obj !== "undefined")
    obj = _cloneDeep(obj);
  const newPath = !Array.isArray(path) ? path.toString().match(/[^.[\]]+/g) || [] : path;
  const foundProp = newPath.length === 1 ? obj : _get(obj, newPath.slice(0, -1).join("."));
  if (Array.isArray(foundProp)) {
    foundProp.splice(Number(newPath[newPath.length - 1]), 1);
  } else {
    foundProp === null || foundProp === void 0 ? true : delete foundProp[newPath[newPath.length - 1]];
  }
  return obj;
}
 
// node_modules/@felte/common/dist/esm/utils/deepSome.js
function deepSome(obj, pred) {
  return _some(obj, (value) => _isPlainObject(value) ? deepSome(value, pred) : Array.isArray(value) ? value.length === 0 || value.every((v) => typeof v === "string") ? pred(value) : value.some((v) => _isPlainObject(v) ? deepSome(v, pred) : pred(v)) : pred(value));
}
 
// node_modules/@felte/common/dist/esm/utils/typeGuards.js
function isInputElement(el) {
  return (el === null || el === void 0 ? void 0 : el.nodeName) === "INPUT";
}
function isTextAreaElement(el) {
  return (el === null || el === void 0 ? void 0 : el.nodeName) === "TEXTAREA";
}
function isSelectElement(el) {
  return (el === null || el === void 0 ? void 0 : el.nodeName) === "SELECT";
}
function isFieldSetElement(el) {
  return (el === null || el === void 0 ? void 0 : el.nodeName) === "FIELDSET";
}
function isFormControl(el) {
  return isInputElement(el) || isTextAreaElement(el) || isSelectElement(el);
}
function isElement(el) {
  return el.nodeType === Node.ELEMENT_NODE;
}
 
// node_modules/@felte/common/dist/esm/utils/getPath.js
function getPath(el, name) {
  return name !== null && name !== void 0 ? name : isFormControl(el) ? el.name : "";
}
 
// node_modules/@felte/common/dist/esm/utils/shouldIgnore.js
function shouldIgnore(el) {
  let parent = el;
  while (parent && parent.nodeName !== "FORM") {
    if (parent.hasAttribute("data-felte-ignore"))
      return true;
    parent = parent.parentElement;
  }
  return false;
}
 
// node_modules/@felte/common/dist/esm/utils/getValue.js
function getValue(storeValue, selectorOrPath) {
  if (!_isPlainObject(storeValue) || !selectorOrPath)
    return storeValue;
  if (typeof selectorOrPath === "string") {
    return _get(storeValue, selectorOrPath);
  }
  return selectorOrPath(storeValue);
}
 
// node_modules/@felte/common/dist/esm/utils/executeValidation.js
function executeCustomizer(objValue, srcValue) {
  if (_isPlainObject(objValue) || _isPlainObject(srcValue))
    return;
  if (objValue === null || objValue === "")
    return srcValue;
  if (srcValue === null || srcValue === "")
    return objValue;
  if (!srcValue)
    return objValue;
  if (!objValue || !srcValue)
    return;
  if (Array.isArray(objValue)) {
    if (!Array.isArray(srcValue))
      return [...objValue, srcValue];
    const newErrors = [];
    const errLength = Math.max(srcValue.length, objValue.length);
    for (let i = 0; i < errLength; i++) {
      let obj = objValue[i];
      let src = srcValue[i];
      if (!_isPlainObject(obj) && !_isPlainObject(src)) {
        if (!Array.isArray(obj))
          obj = [obj];
        if (!Array.isArray(src))
          src = [src];
        newErrors.push(...obj, ...src);
      } else {
        newErrors.push(mergeErrors([obj !== null && obj !== void 0 ? obj : {}, src !== null && src !== void 0 ? src : {}]));
      }
    }
    return newErrors.filter(Boolean);
  }
  if (!Array.isArray(srcValue))
    srcValue = [srcValue];
  return [objValue, ...srcValue].reduce((acc, value) => acc.concat(value), []).filter(Boolean);
}
function mergeErrors(errors) {
  const merged = _mergeWith(...errors, executeCustomizer);
  return merged;
}
function runValidations(values, validationOrValidations) {
  if (!validationOrValidations)
    return [];
  const validations = Array.isArray(validationOrValidations) ? validationOrValidations : [validationOrValidations];
  return validations.map((v) => v(values));
}
 
// node_modules/@felte/common/dist/esm/utils/executeTransforms.js
function executeTransforms(values, transforms) {
  if (!transforms)
    return values;
  if (!Array.isArray(transforms))
    return transforms(values);
  return transforms.reduce((res, t) => t(res), values);
}
 
// node_modules/@felte/common/dist/esm/utils/createId.js
function createId(length = 8) {
  const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  let str = "";
  for (let i = 0; i < length; i++) {
    str += chars.charAt(Math.floor(Math.random() * chars.length));
  }
  return str;
}
 
// node_modules/@felte/common/dist/esm/utils/isEqual.js
function isEqual(val1, val2) {
  if (val1 === val2)
    return true;
  if (Array.isArray(val1) && Array.isArray(val2)) {
    if (val1.length !== val2.length)
      return false;
    return val1.every((v, i) => isEqual(v, val2[i]));
  }
  if (_isPlainObject(val1) && _isPlainObject(val2)) {
    const keys1 = Object.keys(val1);
    const keys2 = Object.keys(val2);
    if (keys1.length !== keys2.length)
      return false;
    return keys1.every((k) => isEqual(val1[k], val2[k]));
  }
  return false;
}
 
// node_modules/@felte/common/dist/esm/utils/debounce.js
function debounce(func, timeout, { onInit, onEnd } = {}) {
  let timer;
  return (...args) => {
    if (!timer)
      onInit === null || onInit === void 0 ? void 0 : onInit();
    if (timer)
      clearTimeout(timer);
    timer = setTimeout(() => {
      func.apply(this, args);
      timer = void 0;
      onEnd === null || onEnd === void 0 ? void 0 : onEnd();
    }, timeout);
  };
}
 
// node_modules/@felte/common/dist/esm/utils/domUtils.js
function getFormControls(el) {
  if (isFormControl(el))
    return [el];
  if (el.childElementCount === 0)
    return [];
  const foundControls = /* @__PURE__ */ new Set();
  for (const child of el.children) {
    if (isFormControl(child))
      foundControls.add(child);
    if (isFieldSetElement(child)) {
      for (const fieldsetChild of child.elements) {
        if (isFormControl(fieldsetChild))
          foundControls.add(fieldsetChild);
      }
    }
    if (child.childElementCount > 0)
      getFormControls(child).forEach((value) => foundControls.add(value));
  }
  return Array.from(foundControls);
}
function addAttrsFromFieldset(fieldSet) {
  for (const element of fieldSet.elements) {
    if (!isFormControl(element) && !isFieldSetElement(element))
      continue;
    if (fieldSet.hasAttribute("data-felte-keep-on-remove") && !element.hasAttribute("data-felte-keep-on-remove")) {
      element.dataset.felteKeepOnRemove = fieldSet.dataset.felteKeepOnRemove;
    }
  }
}
function getInputTextOrNumber(el) {
  if (el.type.match(/^(number|range)$/)) {
    return !el.value ? null : +el.value;
  } else {
    return el.value;
  }
}
function getFormDefaultValues(node) {
  var _a;
  let defaultData = {};
  let defaultTouched = {};
  for (const el of node.elements) {
    if (isFieldSetElement(el))
      addAttrsFromFieldset(el);
    if (!isFormControl(el) || !el.name)
      continue;
    const elName = getPath(el);
    if (isInputElement(el)) {
      if (el.type === "checkbox") {
        if (typeof _get(defaultData, elName) === "undefined") {
          const checkboxes = Array.from(node.querySelectorAll(`[name="${el.name}"]`)).filter((checkbox) => {
            if (!isFormControl(checkbox))
              return false;
            return elName === getPath(checkbox);
          });
          if (checkboxes.length === 1) {
            defaultData = _set(defaultData, elName, el.checked);
            defaultTouched = _set(defaultTouched, elName, false);
            continue;
          }
          defaultData = _set(defaultData, elName, el.checked ? [el.value] : []);
          defaultTouched = _set(defaultTouched, elName, false);
          continue;
        }
        if (Array.isArray(_get(defaultData, elName)) && el.checked) {
          defaultData = _update(defaultData, elName, (value) => [
            ...value,
            el.value
          ]);
        }
        continue;
      }
      if (el.type === "radio") {
        if (_get(defaultData, elName))
          continue;
        defaultData = _set(defaultData, elName, el.checked ? el.value : void 0);
        defaultTouched = _set(defaultTouched, elName, false);
        continue;
      }
      if (el.type === "file") {
        defaultData = _set(defaultData, elName, el.multiple ? Array.from(el.files || []) : (_a = el.files) === null || _a === void 0 ? void 0 : _a[0]);
        defaultTouched = _set(defaultTouched, elName, false);
        continue;
      }
    } else if (isSelectElement(el)) {
      const multiple = el.multiple;
      if (!multiple) {
        defaultData = _set(defaultData, elName, el.value);
      } else {
        const selectedOptions = Array.from(el.selectedOptions).map((opt) => opt.value);
        defaultData = _set(defaultData, elName, selectedOptions);
      }
      defaultTouched = _set(defaultTouched, elName, false);
      continue;
    }
    const inputValue = getInputTextOrNumber(el);
    defaultData = _set(defaultData, elName, inputValue);
    defaultTouched = _set(defaultTouched, elName, false);
  }
  return { defaultData, defaultTouched };
}
function setControlValue(el, value) {
  var _a;
  if (!isFormControl(el))
    return;
  const fieldValue = value;
  if (isInputElement(el)) {
    if (el.type === "checkbox") {
      const checkboxesDefaultData = fieldValue;
      if (typeof checkboxesDefaultData === "undefined" || typeof checkboxesDefaultData === "boolean") {
        el.checked = !!checkboxesDefaultData;
        return;
      }
      if (Array.isArray(checkboxesDefaultData)) {
        if (checkboxesDefaultData.includes(el.value)) {
          el.checked = true;
        } else {
          el.checked = false;
        }
      }
      return;
    }
    if (el.type === "radio") {
      const radioValue = fieldValue;
      if (el.value === radioValue)
        el.checked = true;
      else
        el.checked = false;
      return;
    }
    if (el.type === "file") {
      if (value instanceof FileList) {
        el.files = value;
      } else if (value instanceof File && typeof DataTransfer !== "undefined") {
        const dataTransfer = new DataTransfer();
        dataTransfer.items.add(value);
        el.files = dataTransfer.files;
      } else if (typeof DataTransfer !== "undefined" && Array.isArray(value) && value.some((v) => v instanceof File)) {
        const dataTransfer = new DataTransfer();
        for (const file of value) {
          file instanceof File && dataTransfer.items.add(file);
        }
        el.files = dataTransfer.files;
      } else if (!value || Array.isArray(value) && !value.length) {
        el.files = null;
        el.value = "";
      }
      return;
    }
  } else if (isSelectElement(el)) {
    const multiple = el.multiple;
    if (!multiple) {
      el.value = String(fieldValue !== null && fieldValue !== void 0 ? fieldValue : "");
      for (const option of el.options) {
        if (option.value === String(fieldValue)) {
          option.selected = true;
        } else {
          option.selected = false;
        }
      }
    } else if (Array.isArray(fieldValue)) {
      el.value = String((_a = fieldValue[0]) !== null && _a !== void 0 ? _a : "");
      const stringValues = fieldValue.map((v) => String(v));
      for (const option of el.options) {
        if (stringValues.includes(option.value)) {
          option.selected = true;
        } else {
          option.selected = false;
        }
      }
    }
    return;
  }
  el.value = String(fieldValue !== null && fieldValue !== void 0 ? fieldValue : "");
}
function setForm(node, data) {
  for (const el of node.elements) {
    if (isFieldSetElement(el))
      addAttrsFromFieldset(el);
    if (!isFormControl(el) || !el.name)
      continue;
    const elName = getPath(el);
    setControlValue(el, _get(data, elName));
  }
}
 
export {
  _mapValues,
  _isPlainObject,
  _cloneDeep,
  deepSet,
  _mergeWith,
  _defaultsDeep,
  _merge,
  _get,
  _update,
  _set,
  _unset,
  deepSome,
  isInputElement,
  isSelectElement,
  isFormControl,
  isElement,
  getPath,
  shouldIgnore,
  getValue,
  mergeErrors,
  runValidations,
  executeTransforms,
  createId,
  isEqual,
  debounce,
  getFormControls,
  getInputTextOrNumber,
  getFormDefaultValues,
  setControlValue,
  setForm
};
//# sourceMappingURL=chunk-TSIAW2HS.js.map