@stemy/ngx-dynamic-form 10.2.23 → 10.2.26

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.
@@ -163,9 +163,37 @@
163
163
  return Promise.resolve(null);
164
164
  var phoneRegexp = /^(?:\d){10,12}$/;
165
165
  return phoneRegexp.test(value) ? null : { phone: true };
166
+ }
167
+ function validateItemsMinLength(minLength) {
168
+ return function (control) {
169
+ var value = control.value;
170
+ return (Array.isArray(value) && value.every(function (v) { return typeof v == "string" && v.length >= minLength; }))
171
+ ? null : { itemsMinLength: minLength };
172
+ };
173
+ }
174
+ function validateItemsMaxLength(maxLength) {
175
+ return function (control) {
176
+ var value = control.value;
177
+ return (Array.isArray(value) && value.every(function (v) { return typeof v == "string" && v.length <= maxLength; }))
178
+ ? null : { itemsMaxLength: maxLength };
179
+ };
180
+ }
181
+ function validateItemsMinValue(min) {
182
+ return function (control) {
183
+ var value = control.value;
184
+ return (Array.isArray(value) && value.every(function (v) { return typeof v == "number" && v >= min; }))
185
+ ? null : { itemsMinValue: min };
186
+ };
187
+ }
188
+ function validateItemsMaxValue(max) {
189
+ return function (control) {
190
+ var value = control.value;
191
+ return (Array.isArray(value) && value.every(function (v) { return typeof v == "number" && v <= max; }))
192
+ ? null : { itemsMaxValue: max };
193
+ };
166
194
  }
167
195
 
168
- /*! *****************************************************************************
196
+ /******************************************************************************
169
197
  Copyright (c) Microsoft Corporation.
170
198
 
171
199
  Permission to use, copy, modify, and/or distribute this software for any
@@ -189,6 +217,8 @@
189
217
  return extendStatics(d, b);
190
218
  };
191
219
  function __extends(d, b) {
220
+ if (typeof b !== "function" && b !== null)
221
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
192
222
  extendStatics(d, b);
193
223
  function __() { this.constructor = d; }
194
224
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -325,7 +355,11 @@
325
355
  var __createBinding = Object.create ? (function (o, m, k, k2) {
326
356
  if (k2 === undefined)
327
357
  k2 = k;
328
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
358
+ var desc = Object.getOwnPropertyDescriptor(m, k);
359
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
360
+ desc = { enumerable: true, get: function () { return m[k]; } };
361
+ }
362
+ Object.defineProperty(o, k2, desc);
329
363
  }) : (function (o, m, k, k2) {
330
364
  if (k2 === undefined)
331
365
  k2 = k;
@@ -374,11 +408,13 @@
374
408
  }
375
409
  return ar;
376
410
  }
411
+ /** @deprecated */
377
412
  function __spread() {
378
413
  for (var ar = [], i = 0; i < arguments.length; i++)
379
414
  ar = ar.concat(__read(arguments[i]));
380
415
  return ar;
381
416
  }
417
+ /** @deprecated */
382
418
  function __spreadArrays() {
383
419
  for (var s = 0, i = 0, il = arguments.length; i < il; i++)
384
420
  s += arguments[i].length;
@@ -387,7 +423,17 @@
387
423
  r[k] = a[j];
388
424
  return r;
389
425
  }
390
- ;
426
+ function __spreadArray(to, from, pack) {
427
+ if (pack || arguments.length === 2)
428
+ for (var i = 0, l = from.length, ar; i < l; i++) {
429
+ if (ar || !(i in from)) {
430
+ if (!ar)
431
+ ar = Array.prototype.slice.call(from, 0, i);
432
+ ar[i] = from[i];
433
+ }
434
+ }
435
+ return to.concat(ar || Array.prototype.slice.call(from));
436
+ }
391
437
  function __await(v) {
392
438
  return this instanceof __await ? (this.v = v, this) : new __await(v);
393
439
  }
@@ -452,18 +498,26 @@
452
498
  function __importDefault(mod) {
453
499
  return (mod && mod.__esModule) ? mod : { default: mod };
454
500
  }
455
- function __classPrivateFieldGet(receiver, privateMap) {
456
- if (!privateMap.has(receiver)) {
457
- throw new TypeError("attempted to get private field on non-instance");
458
- }
459
- return privateMap.get(receiver);
501
+ function __classPrivateFieldGet(receiver, state, kind, f) {
502
+ if (kind === "a" && !f)
503
+ throw new TypeError("Private accessor was defined without a getter");
504
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
505
+ throw new TypeError("Cannot read private member from an object whose class did not declare it");
506
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
460
507
  }
461
- function __classPrivateFieldSet(receiver, privateMap, value) {
462
- if (!privateMap.has(receiver)) {
463
- throw new TypeError("attempted to set private field on non-instance");
464
- }
465
- privateMap.set(receiver, value);
466
- return value;
508
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
509
+ if (kind === "m")
510
+ throw new TypeError("Private method is not writable");
511
+ if (kind === "a" && !f)
512
+ throw new TypeError("Private accessor was defined without a setter");
513
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
514
+ throw new TypeError("Cannot write private member to an object whose class did not declare it");
515
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
516
+ }
517
+ function __classPrivateFieldIn(state, receiver) {
518
+ if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
519
+ throw new TypeError("Cannot use 'in' operator on non-object");
520
+ return typeof state === "function" ? receiver === state : state.has(receiver);
467
521
  }
468
522
 
469
523
  var FormSubject = /** @class */ (function (_super) {
@@ -473,28 +527,55 @@
473
527
  _this.notifyCallback = notifyCallback;
474
528
  return _this;
475
529
  }
530
+ FormSubject.prototype.handleNotifiedValue = function (controlModel, control, val) {
531
+ var _this = this;
532
+ val.then(function (v) { return _this.next(v); });
533
+ };
476
534
  FormSubject.prototype.notify = function (controlModel, control) {
477
- return __awaiter(this, void 0, void 0, function () {
478
- var value;
479
- return __generator(this, function (_a) {
480
- switch (_a.label) {
481
- case 0:
482
- value = this.notifyCallback(controlModel, control);
483
- if (!(value instanceof Promise)) return [3 /*break*/, 2];
484
- return [4 /*yield*/, value];
485
- case 1:
486
- value = _a.sent();
487
- _a.label = 2;
488
- case 2:
489
- this.next(value);
490
- return [2 /*return*/];
491
- }
492
- });
493
- });
535
+ var path = controlModel;
536
+ while (path && isNaN(path.index)) {
537
+ path = path.parent;
538
+ }
539
+ var value = this.notifyCallback(controlModel, control, path === null || path === void 0 ? void 0 : path.index);
540
+ if (!(value instanceof Promise)) {
541
+ value = Promise.resolve(value);
542
+ }
543
+ this.handleNotifiedValue(controlModel, control, value);
494
544
  };
495
545
  return FormSubject;
496
546
  }(rxjs.Subject));
497
547
 
548
+ var FormSelectSubject = /** @class */ (function (_super) {
549
+ __extends(FormSelectSubject, _super);
550
+ function FormSelectSubject() {
551
+ return _super !== null && _super.apply(this, arguments) || this;
552
+ }
553
+ FormSelectSubject.prototype.handleNotifiedValue = function (controlModel, control, val) {
554
+ var _this = this;
555
+ val.then(function (options) {
556
+ var _a, _b;
557
+ _this.next(options);
558
+ var currentVal = control.value;
559
+ if (controlModel.multiple) {
560
+ var correctVal = (currentVal || []).filter(function (t) { return options.findIndex(function (o) { return o.value == t; }) >= 0; });
561
+ if (correctVal.length !== (currentVal === null || currentVal === void 0 ? void 0 : currentVal.length)) {
562
+ control.setValue(correctVal, { onlySelf: true, emitEvent: false });
563
+ }
564
+ return;
565
+ }
566
+ var option = options.find(function (t) { return t.value == currentVal; });
567
+ if (!option) {
568
+ control.setValue((_b = (_a = options[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null, { onlySelf: true, emitEvent: false });
569
+ }
570
+ });
571
+ };
572
+ return FormSelectSubject;
573
+ }(FormSubject));
574
+
575
+ function isStringWithVal(val) {
576
+ return typeof val == "string" && val.length > 0;
577
+ }
578
+
498
579
  var DynamicFormArrayModel = /** @class */ (function (_super) {
499
580
  __extends(DynamicFormArrayModel, _super);
500
581
  function DynamicFormArrayModel(config, layout) {
@@ -599,7 +680,7 @@
599
680
  });
600
681
  };
601
682
  DynamicFormService.prototype.serializeRecursive = function (formModel, formGroup) {
602
- var _a;
683
+ var _a, _b;
603
684
  return __awaiter(this, void 0, void 0, function () {
604
685
  var result, _c, _d, _i, i, subModel, subControl, serializer, _e, _f, length, subArray, resArray, i_1, itemModel, _g, _h, _j, _k;
605
686
  return __generator(this, function (_l) {
@@ -658,8 +739,7 @@
658
739
  case 10:
659
740
  if (subModel instanceof core.DynamicInputModel && !ngxUtils.ObjectUtils.isNullOrUndefined(subControl.value)) {
660
741
  result[subModel.id] = subModel.inputType == "number"
661
- ? parseFloat(("" + subControl.value || "0").replace(/,/gi, ".")) || null
662
- : subControl.value;
742
+ ? (_b = parseFloat(("" + subControl.value || "0").replace(/,/gi, "."))) !== null && _b !== void 0 ? _b : null : subControl.value;
663
743
  return [3 /*break*/, 11];
664
744
  }
665
745
  result[subModel.id] = subControl.value;
@@ -741,7 +821,8 @@
741
821
  };
742
822
  DynamicFormService.prototype.getFormControlModel = function (property, schema) {
743
823
  var _a, _b;
744
- if (Array.isArray(property.enum) || ngxUtils.ObjectUtils.isString(property.optionsPath)) {
824
+ var $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
825
+ if (Array.isArray($enum) || isStringWithVal(property.optionsPath) || isStringWithVal(property.endpoint)) {
745
826
  return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
746
827
  }
747
828
  switch (property.type) {
@@ -753,15 +834,10 @@
753
834
  return new core.DynamicTextAreaModel(this.getFormTextareaConfig(property, schema));
754
835
  case "boolean":
755
836
  return new core.DynamicCheckboxModel(this.getFormCheckboxConfig(property, schema));
756
- case "list":
757
- return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
758
837
  case "array":
759
- if (((_a = property.items) === null || _a === void 0 ? void 0 : _a.$ref) || property.$ref) {
838
+ if (((_b = property.items) === null || _b === void 0 ? void 0 : _b.$ref) || property.$ref) {
760
839
  return new DynamicFormArrayModel(this.getFormArrayConfig(property, schema));
761
840
  }
762
- else if (((_b = property.items) === null || _b === void 0 ? void 0 : _b.enum) || property.enum) {
763
- return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
764
- }
765
841
  else {
766
842
  return new core.DynamicInputModel(this.getFormInputConfig(property, schema));
767
843
  }
@@ -815,6 +891,7 @@
815
891
  inputType = "number";
816
892
  break;
817
893
  }
894
+ var sub = property.type == "array" ? property.items || property : property;
818
895
  return Object.assign(this.getFormControlConfig(property, schema), {
819
896
  inputType: inputType,
820
897
  autoComplete: property.autoComplete || "off",
@@ -822,9 +899,9 @@
822
899
  accept: ngxUtils.ObjectUtils.isString(property.accept) ? property.accept : null,
823
900
  mask: ngxUtils.ObjectUtils.isString(property.mask) ? property.mask : null,
824
901
  pattern: ngxUtils.ObjectUtils.isString(property.pattern) ? property.pattern : null,
825
- step: isNaN(property.step) ? 1 : property.step,
826
- min: isNaN(property.min) ? Number.MIN_SAFE_INTEGER : property.min,
827
- max: isNaN(property.max) ? Number.MAX_SAFE_INTEGER : property.max,
902
+ step: isNaN(sub.step) ? (isNaN(property.step) ? 1 : property.step) : sub.step,
903
+ min: isNaN(sub.minimum) ? (isNaN(sub.minLength) ? Number.MIN_SAFE_INTEGER : sub.minLength) : sub.minimum,
904
+ max: isNaN(sub.maximum) ? (isNaN(sub.maxLength) ? Number.MAX_SAFE_INTEGER : sub.maxLength) : sub.maximum
828
905
  });
829
906
  };
830
907
  DynamicFormService.prototype.getFormTextareaConfig = function (property, schema) {
@@ -892,8 +969,17 @@
892
969
  var _this = this;
893
970
  var _a;
894
971
  var $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
895
- if (property.optionsPath) {
896
- return new FormSubject(function (formModel, control) {
972
+ if (Array.isArray($enum)) {
973
+ return new FormSelectSubject(function () {
974
+ var options = $enum.map(function (value) {
975
+ var label = property.translatable ? property.id + "." + value : value;
976
+ return { value: value, label: label };
977
+ });
978
+ return _this.translateOptions(options);
979
+ });
980
+ }
981
+ if (isStringWithVal(property.optionsPath)) {
982
+ return new FormSelectSubject(function (formModel, control, index) {
897
983
  var path = property.optionsPath;
898
984
  var target = control;
899
985
  if (path.startsWith("$root")) {
@@ -908,21 +994,12 @@
908
994
  target = target.parent;
909
995
  }
910
996
  }
911
- var value = ngxUtils.ObjectUtils.getValue(target.value, path);
997
+ var value = ngxUtils.ObjectUtils.getValue(target.value, path.replace(/\$ix/gi, index));
912
998
  var options = (!ngxUtils.ObjectUtils.isArray(value) ? [] : value).map(function (value) { return ({ value: value, label: value }); });
913
999
  return _this.translateOptions(options);
914
1000
  });
915
1001
  }
916
- if (ngxUtils.ObjectUtils.isArray($enum)) {
917
- return new FormSubject(function () {
918
- var options = $enum.map(function (value) {
919
- var label = property.translatable ? property.id + "." + value : value;
920
- return { value: value, label: label };
921
- });
922
- return _this.translateOptions(options);
923
- });
924
- }
925
- return new FormSubject(function () { return __awaiter(_this, void 0, void 0, function () {
1002
+ return new FormSelectSubject(function () { return __awaiter(_this, void 0, void 0, function () {
926
1003
  var options;
927
1004
  return __generator(this, function (_c) {
928
1005
  switch (_c.label) {
@@ -958,24 +1035,46 @@
958
1035
  if (ngxUtils.ObjectUtils.isArray(schema.required) && schema.required.indexOf(property.id) >= 0) {
959
1036
  validators.required = null;
960
1037
  }
961
- if (property.minLength) {
1038
+ this.addPropertyValidators(validators, property);
1039
+ this.addItemsValidators(validators, property.items);
1040
+ return validators;
1041
+ };
1042
+ DynamicFormService.prototype.addPropertyValidators = function (validators, property) {
1043
+ if (!property)
1044
+ return;
1045
+ if (!isNaN(property.minLength)) {
962
1046
  validators.minLength = property.minLength;
963
1047
  }
964
- if (property.maxLength) {
1048
+ if (!isNaN(property.maxLength)) {
965
1049
  validators.maxLength = property.maxLength;
966
1050
  }
967
- if (property.min) {
968
- validators.min = property.min;
1051
+ if (!isNaN(property.minimum)) {
1052
+ validators.min = property.minimum;
969
1053
  }
970
- if (property.max) {
971
- validators.max = property.max;
1054
+ if (!isNaN(property.maximum)) {
1055
+ validators.max = property.maximum;
972
1056
  }
973
1057
  switch (property.format) {
974
1058
  case "email":
975
1059
  validators.email = null;
976
1060
  break;
977
1061
  }
978
- return validators;
1062
+ };
1063
+ DynamicFormService.prototype.addItemsValidators = function (validators, items) {
1064
+ if (!items)
1065
+ return;
1066
+ if (!isNaN(items.minLength)) {
1067
+ validators.itemsMinLength = items.minLength;
1068
+ }
1069
+ if (!isNaN(items.maxLength)) {
1070
+ validators.itemsMaxLength = items.maxLength;
1071
+ }
1072
+ if (!isNaN(items.minimum)) {
1073
+ validators.itemsMinValue = items.minimum;
1074
+ }
1075
+ if (!isNaN(items.maximum)) {
1076
+ validators.itemsMaxValue = items.maximum;
1077
+ }
979
1078
  };
980
1079
  return DynamicFormService;
981
1080
  }(core.DynamicFormService));
@@ -1370,10 +1469,14 @@
1370
1469
  ];
1371
1470
  // --- Pipes ---
1372
1471
  var pipes = [];
1373
- var ɵ0$1 = validateJSON, ɵ1 = validateRequiredTranslation, ɵ2 = validatePhone, ɵ3 = new Map([
1374
- ["validateJSON", validateJSON],
1375
- ["validateRequiredTranslation", validateRequiredTranslation],
1376
- ["validatePhone", validatePhone],
1472
+ var ɵ0$1 = validateJSON, ɵ1 = validateRequiredTranslation, ɵ2 = validateItemsMinLength, ɵ3 = validateItemsMaxLength, ɵ4 = validateItemsMinValue, ɵ5 = validateItemsMaxValue, ɵ6 = new Map([
1473
+ ["json", validateJSON],
1474
+ ["requiredTranslation", validateRequiredTranslation],
1475
+ ["phone", validatePhone],
1476
+ ["itemsMinLength", validateItemsMinLength],
1477
+ ["itemsMaxLength", validateItemsMaxLength],
1478
+ ["itemsMinValue", validateItemsMinValue],
1479
+ ["itemsMaxValue", validateItemsMaxValue],
1377
1480
  ]);
1378
1481
  var NgxDynamicFormModule = /** @class */ (function () {
1379
1482
  function NgxDynamicFormModule() {
@@ -1416,9 +1519,12 @@
1416
1519
  { provide: forms.NG_VALIDATORS, useValue: ɵ0$1, multi: true },
1417
1520
  { provide: forms.NG_VALIDATORS, useValue: ɵ1, multi: true },
1418
1521
  { provide: forms.NG_VALIDATORS, useValue: ɵ2, multi: true },
1522
+ { provide: forms.NG_VALIDATORS, useValue: ɵ3, multi: true },
1523
+ { provide: forms.NG_VALIDATORS, useValue: ɵ4, multi: true },
1524
+ { provide: forms.NG_VALIDATORS, useValue: ɵ5, multi: true },
1419
1525
  {
1420
1526
  provide: core.DYNAMIC_VALIDATORS,
1421
- useValue: ɵ3
1527
+ useValue: ɵ6
1422
1528
  }
1423
1529
  ])
1424
1530
  },] }
@@ -1437,6 +1543,7 @@
1437
1543
  exports.FormInput = FormInput;
1438
1544
  exports.FormModel = FormModel;
1439
1545
  exports.FormSelect = FormSelect;
1546
+ exports.FormSelectSubject = FormSelectSubject;
1440
1547
  exports.FormSerializable = FormSerializable;
1441
1548
  exports.FormStatic = FormStatic;
1442
1549
  exports.FormSubject = FormSubject;
@@ -1451,6 +1558,10 @@
1451
1558
  exports.getFormControl = getFormControl;
1452
1559
  exports.getFormFieldSets = getFormFieldSets;
1453
1560
  exports.getFormSerializer = getFormSerializer;
1561
+ exports.validateItemsMaxLength = validateItemsMaxLength;
1562
+ exports.validateItemsMaxValue = validateItemsMaxValue;
1563
+ exports.validateItemsMinLength = validateItemsMinLength;
1564
+ exports.validateItemsMinValue = validateItemsMinValue;
1454
1565
  exports.validateJSON = validateJSON;
1455
1566
  exports.validatePhone = validatePhone;
1456
1567
  exports.validateRequiredTranslation = validateRequiredTranslation;