@stemy/ngx-dynamic-form 10.2.24 → 10.2.27

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) {
@@ -740,7 +821,8 @@
740
821
  };
741
822
  DynamicFormService.prototype.getFormControlModel = function (property, schema) {
742
823
  var _a, _b;
743
- 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)) {
744
826
  return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
745
827
  }
746
828
  switch (property.type) {
@@ -752,15 +834,10 @@
752
834
  return new core.DynamicTextAreaModel(this.getFormTextareaConfig(property, schema));
753
835
  case "boolean":
754
836
  return new core.DynamicCheckboxModel(this.getFormCheckboxConfig(property, schema));
755
- case "list":
756
- return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
757
837
  case "array":
758
- 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) {
759
839
  return new DynamicFormArrayModel(this.getFormArrayConfig(property, schema));
760
840
  }
761
- else if (((_b = property.items) === null || _b === void 0 ? void 0 : _b.enum) || property.enum) {
762
- return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
763
- }
764
841
  else {
765
842
  return new core.DynamicInputModel(this.getFormInputConfig(property, schema));
766
843
  }
@@ -814,6 +891,7 @@
814
891
  inputType = "number";
815
892
  break;
816
893
  }
894
+ var sub = property.type == "array" ? property.items || property : property;
817
895
  return Object.assign(this.getFormControlConfig(property, schema), {
818
896
  inputType: inputType,
819
897
  autoComplete: property.autoComplete || "off",
@@ -821,9 +899,11 @@
821
899
  accept: ngxUtils.ObjectUtils.isString(property.accept) ? property.accept : null,
822
900
  mask: ngxUtils.ObjectUtils.isString(property.mask) ? property.mask : null,
823
901
  pattern: ngxUtils.ObjectUtils.isString(property.pattern) ? property.pattern : null,
824
- step: isNaN(property.step) ? 1 : property.step,
825
- min: isNaN(property.min) ? Number.MIN_SAFE_INTEGER : property.min,
826
- 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) ? Number.MIN_SAFE_INTEGER : sub.minimum,
904
+ max: isNaN(sub.maximum) ? Number.MAX_SAFE_INTEGER : sub.maximum,
905
+ minLength: isNaN(sub.minLength) ? Number.MIN_SAFE_INTEGER : sub.minLength,
906
+ maxLength: isNaN(sub.maxLength) ? Number.MAX_SAFE_INTEGER : sub.maxLength,
827
907
  });
828
908
  };
829
909
  DynamicFormService.prototype.getFormTextareaConfig = function (property, schema) {
@@ -891,8 +971,17 @@
891
971
  var _this = this;
892
972
  var _a;
893
973
  var $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
894
- if (property.optionsPath) {
895
- return new FormSubject(function (formModel, control) {
974
+ if (Array.isArray($enum)) {
975
+ return new FormSelectSubject(function () {
976
+ var options = $enum.map(function (value) {
977
+ var label = property.translatable ? property.id + "." + value : value;
978
+ return { value: value, label: label };
979
+ });
980
+ return _this.translateOptions(options);
981
+ });
982
+ }
983
+ if (isStringWithVal(property.optionsPath)) {
984
+ return new FormSelectSubject(function (formModel, control, index) {
896
985
  var path = property.optionsPath;
897
986
  var target = control;
898
987
  if (path.startsWith("$root")) {
@@ -907,21 +996,12 @@
907
996
  target = target.parent;
908
997
  }
909
998
  }
910
- var value = ngxUtils.ObjectUtils.getValue(target.value, path);
999
+ var value = ngxUtils.ObjectUtils.getValue(target.value, path.replace(/\$ix/gi, index));
911
1000
  var options = (!ngxUtils.ObjectUtils.isArray(value) ? [] : value).map(function (value) { return ({ value: value, label: value }); });
912
1001
  return _this.translateOptions(options);
913
1002
  });
914
1003
  }
915
- if (ngxUtils.ObjectUtils.isArray($enum)) {
916
- return new FormSubject(function () {
917
- var options = $enum.map(function (value) {
918
- var label = property.translatable ? property.id + "." + value : value;
919
- return { value: value, label: label };
920
- });
921
- return _this.translateOptions(options);
922
- });
923
- }
924
- return new FormSubject(function () { return __awaiter(_this, void 0, void 0, function () {
1004
+ return new FormSelectSubject(function () { return __awaiter(_this, void 0, void 0, function () {
925
1005
  var options;
926
1006
  return __generator(this, function (_c) {
927
1007
  switch (_c.label) {
@@ -957,24 +1037,46 @@
957
1037
  if (ngxUtils.ObjectUtils.isArray(schema.required) && schema.required.indexOf(property.id) >= 0) {
958
1038
  validators.required = null;
959
1039
  }
960
- if (property.minLength) {
1040
+ this.addPropertyValidators(validators, property);
1041
+ this.addItemsValidators(validators, property.items);
1042
+ return validators;
1043
+ };
1044
+ DynamicFormService.prototype.addPropertyValidators = function (validators, property) {
1045
+ if (!property)
1046
+ return;
1047
+ if (!isNaN(property.minLength)) {
961
1048
  validators.minLength = property.minLength;
962
1049
  }
963
- if (property.maxLength) {
1050
+ if (!isNaN(property.maxLength)) {
964
1051
  validators.maxLength = property.maxLength;
965
1052
  }
966
- if (property.min) {
967
- validators.min = property.min;
1053
+ if (!isNaN(property.minimum)) {
1054
+ validators.min = property.minimum;
968
1055
  }
969
- if (property.max) {
970
- validators.max = property.max;
1056
+ if (!isNaN(property.maximum)) {
1057
+ validators.max = property.maximum;
971
1058
  }
972
1059
  switch (property.format) {
973
1060
  case "email":
974
1061
  validators.email = null;
975
1062
  break;
976
1063
  }
977
- return validators;
1064
+ };
1065
+ DynamicFormService.prototype.addItemsValidators = function (validators, items) {
1066
+ if (!items)
1067
+ return;
1068
+ if (!isNaN(items.minLength)) {
1069
+ validators.itemsMinLength = items.minLength;
1070
+ }
1071
+ if (!isNaN(items.maxLength)) {
1072
+ validators.itemsMaxLength = items.maxLength;
1073
+ }
1074
+ if (!isNaN(items.minimum)) {
1075
+ validators.itemsMinValue = items.minimum;
1076
+ }
1077
+ if (!isNaN(items.maximum)) {
1078
+ validators.itemsMaxValue = items.maximum;
1079
+ }
978
1080
  };
979
1081
  return DynamicFormService;
980
1082
  }(core.DynamicFormService));
@@ -1369,10 +1471,14 @@
1369
1471
  ];
1370
1472
  // --- Pipes ---
1371
1473
  var pipes = [];
1372
- var ɵ0$1 = validateJSON, ɵ1 = validateRequiredTranslation, ɵ2 = validatePhone, ɵ3 = new Map([
1373
- ["validateJSON", validateJSON],
1374
- ["validateRequiredTranslation", validateRequiredTranslation],
1375
- ["validatePhone", validatePhone],
1474
+ var ɵ0$1 = validateJSON, ɵ1 = validateRequiredTranslation, ɵ2 = validateItemsMinLength, ɵ3 = validateItemsMaxLength, ɵ4 = validateItemsMinValue, ɵ5 = validateItemsMaxValue, ɵ6 = new Map([
1475
+ ["json", validateJSON],
1476
+ ["requiredTranslation", validateRequiredTranslation],
1477
+ ["phone", validatePhone],
1478
+ ["itemsMinLength", validateItemsMinLength],
1479
+ ["itemsMaxLength", validateItemsMaxLength],
1480
+ ["itemsMinValue", validateItemsMinValue],
1481
+ ["itemsMaxValue", validateItemsMaxValue],
1376
1482
  ]);
1377
1483
  var NgxDynamicFormModule = /** @class */ (function () {
1378
1484
  function NgxDynamicFormModule() {
@@ -1415,9 +1521,12 @@
1415
1521
  { provide: forms.NG_VALIDATORS, useValue: ɵ0$1, multi: true },
1416
1522
  { provide: forms.NG_VALIDATORS, useValue: ɵ1, multi: true },
1417
1523
  { provide: forms.NG_VALIDATORS, useValue: ɵ2, multi: true },
1524
+ { provide: forms.NG_VALIDATORS, useValue: ɵ3, multi: true },
1525
+ { provide: forms.NG_VALIDATORS, useValue: ɵ4, multi: true },
1526
+ { provide: forms.NG_VALIDATORS, useValue: ɵ5, multi: true },
1418
1527
  {
1419
1528
  provide: core.DYNAMIC_VALIDATORS,
1420
- useValue: ɵ3
1529
+ useValue: ɵ6
1421
1530
  }
1422
1531
  ])
1423
1532
  },] }
@@ -1436,6 +1545,7 @@
1436
1545
  exports.FormInput = FormInput;
1437
1546
  exports.FormModel = FormModel;
1438
1547
  exports.FormSelect = FormSelect;
1548
+ exports.FormSelectSubject = FormSelectSubject;
1439
1549
  exports.FormSerializable = FormSerializable;
1440
1550
  exports.FormStatic = FormStatic;
1441
1551
  exports.FormSubject = FormSubject;
@@ -1450,6 +1560,10 @@
1450
1560
  exports.getFormControl = getFormControl;
1451
1561
  exports.getFormFieldSets = getFormFieldSets;
1452
1562
  exports.getFormSerializer = getFormSerializer;
1563
+ exports.validateItemsMaxLength = validateItemsMaxLength;
1564
+ exports.validateItemsMaxValue = validateItemsMaxValue;
1565
+ exports.validateItemsMinLength = validateItemsMinLength;
1566
+ exports.validateItemsMinValue = validateItemsMinValue;
1453
1567
  exports.validateJSON = validateJSON;
1454
1568
  exports.validatePhone = validatePhone;
1455
1569
  exports.validateRequiredTranslation = validateRequiredTranslation;