@luftborn/custom-elements 2.3.4 → 2.4.1

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.
Files changed (30) hide show
  1. package/demo/index.js +50 -61
  2. package/demo/index.min.js +49 -60
  3. package/demo/index.min.js.map +1 -1
  4. package/dist/elements/CustomRegularExpression/CustomRegularExpressionElement.js +3 -0
  5. package/dist/elements/CustomRegularExpression/CustomRegularExpressionElement.js.map +1 -1
  6. package/dist/elements/EmailField/EmailFieldElement.js +3 -0
  7. package/dist/elements/EmailField/EmailFieldElement.js.map +1 -1
  8. package/dist/elements/NumericField/NumericFieldElement.js +3 -0
  9. package/dist/elements/NumericField/NumericFieldElement.js.map +1 -1
  10. package/dist/elements/TextAreaElement/TextAreaElement.js +3 -0
  11. package/dist/elements/TextAreaElement/TextAreaElement.js.map +1 -1
  12. package/dist/elements/TextField/TextFieldElement.js +4 -1
  13. package/dist/elements/TextField/TextFieldElement.js.map +1 -1
  14. package/dist/elements/TypeAhead/TypeAheadElement.js +3 -0
  15. package/dist/elements/TypeAhead/TypeAheadElement.js.map +1 -1
  16. package/dist/framework/CustomInputElement.d.ts +1 -0
  17. package/dist/framework/CustomInputElement.js +1 -0
  18. package/dist/framework/CustomInputElement.js.map +1 -1
  19. package/dist/framework/Validation/Validators/SEPersonalNumber.d.ts +2 -2
  20. package/dist/framework/Validation/Validators/SEPersonalNumber.js +28 -58
  21. package/dist/framework/Validation/Validators/SEPersonalNumber.js.map +1 -1
  22. package/package.json +1 -1
  23. package/src/elements/CustomRegularExpression/CustomRegularExpressionElement.ts +3 -0
  24. package/src/elements/EmailField/EmailFieldElement.ts +3 -0
  25. package/src/elements/NumericField/NumericFieldElement.ts +3 -0
  26. package/src/elements/TextAreaElement/TextAreaElement.ts +3 -0
  27. package/src/elements/TextField/TextFieldElement.ts +4 -1
  28. package/src/elements/TypeAhead/TypeAheadElement.ts +3 -0
  29. package/src/framework/CustomInputElement.ts +2 -0
  30. package/src/framework/Validation/Validators/SEPersonalNumber.ts +32 -69
package/demo/index.min.js CHANGED
@@ -3032,6 +3032,9 @@ var CustomRegularExpressionElement = /** @class */ (function (_super) {
3032
3032
  if (this.customValue) {
3033
3033
  this.text.setAttribute('pattern', this.customValue);
3034
3034
  }
3035
+ if (this.placeholder) {
3036
+ this.text.setAttribute('placeholder', this.placeholder);
3037
+ }
3035
3038
  };
3036
3039
  // events
3037
3040
  CustomRegularExpressionElement.prototype.change = function ($event) {
@@ -3342,6 +3345,9 @@ var EmailFieldElement = /** @class */ (function (_super) {
3342
3345
  if (this.required) {
3343
3346
  this.email.setAttribute('required', '');
3344
3347
  }
3348
+ if (this.placeholder) {
3349
+ this.email.setAttribute('placeholder', this.placeholder);
3350
+ }
3345
3351
  };
3346
3352
  // events
3347
3353
  EmailFieldElement.prototype.change = function ($event) {
@@ -3780,6 +3786,9 @@ var NumericFieldElement = /** @class */ (function (_super) {
3780
3786
  if (this.step) {
3781
3787
  this.number.setAttribute('step', this.step);
3782
3788
  }
3789
+ if (this.placeholder) {
3790
+ this.number.setAttribute('placeholder', this.placeholder);
3791
+ }
3783
3792
  };
3784
3793
  // events
3785
3794
  NumericFieldElement.prototype.change = function ($event) {
@@ -4130,6 +4139,9 @@ var TextAreaElement = /** @class */ (function (_super) {
4130
4139
  if (this.required) {
4131
4140
  this.text.setAttribute('required', '');
4132
4141
  }
4142
+ if (this.placeholder) {
4143
+ this.text.setAttribute('placeholder', this.placeholder);
4144
+ }
4133
4145
  };
4134
4146
  // events
4135
4147
  TextAreaElement.prototype.change = function ($event) {
@@ -4211,6 +4223,9 @@ var TextFieldElement = /** @class */ (function (_super) {
4211
4223
  if (this.required) {
4212
4224
  this.text.setAttribute('required', '');
4213
4225
  }
4226
+ if (this.placeholder) {
4227
+ this.text.setAttribute('placeholder', this.placeholder);
4228
+ }
4214
4229
  };
4215
4230
  // events
4216
4231
  TextFieldElement.prototype.change = function ($event) {
@@ -4224,7 +4239,7 @@ var TextFieldElement = /** @class */ (function (_super) {
4224
4239
  TextFieldElement = __decorate([
4225
4240
  (0, custom_element_decorator_1.default)({
4226
4241
  selector: 'text-element',
4227
- template: "\n\t\t\t<div class=\"wrapper\">\n\t\t\t\t<input type=\"text\" id='text-field'/>\n\t\t\t</div>",
4242
+ template: "\n\t\t\t<div class=\"wrapper\">\n\t\t\t\t<input type=\"text\" id='text-field' />\n\t\t\t</div>",
4228
4243
  style: "\n\t:host{\n\t\t\twidth:100%;\n\t}\n\t.wrapper{\n\t\t\tdisplay:flex;\n\t}\n\tinput{\n\t\t\tbox-sizing: border-box;\n\t\t\twidth: 100% !important;\n\t\t\tborder: none;\n\t\t\tbackground-color: #f1f4ff;\n\t\t\tmargin: 2px;\n\t\t\tresize: none;\n\t}\n\t\t",
4229
4244
  useShadow: true,
4230
4245
  })
@@ -4322,6 +4337,9 @@ var TypeAheadElement = /** @class */ (function (_super) {
4322
4337
  if (this.required) {
4323
4338
  this.textInputElement.setAttribute('required', '');
4324
4339
  }
4340
+ if (this.placeholder) {
4341
+ this.textInputElement.setAttribute('placeholder', this.placeholder);
4342
+ }
4325
4343
  this.textInputElement.addEventListener('change', this.change.bind(this));
4326
4344
  this.textInputElement.addEventListener('input', function () {
4327
4345
  _this.inputEventHandler();
@@ -4579,6 +4597,7 @@ var CustomInputElement = /** @class */ (function (_super) {
4579
4597
  this.dependencies = data.dependencies;
4580
4598
  this.required = data.required;
4581
4599
  this.name = data.name;
4600
+ this.placeholder = data.placeholder;
4582
4601
  this.allDependenciesMustBeMet = data.allDependenciesMustBeMet;
4583
4602
  this.multi = data.multi;
4584
4603
  this.max = data.max;
@@ -6237,68 +6256,38 @@ exports.default = SECompanyRegistrationValidator;
6237
6256
  Object.defineProperty(exports, "__esModule", { value: true });
6238
6257
  var SEPersonalNumberValidator = /** @class */ (function () {
6239
6258
  function SEPersonalNumberValidator() {
6240
- this.regex = new RegExp(/^(\d{2}){0,1}(\d{2})(\d{2})(\d{2})([\+\-]?)((?!000)\d{3})(\d)$/);
6241
6259
  }
6242
6260
  SEPersonalNumberValidator.prototype.isSatisfiedBy = function (input, allowEmpty) {
6243
6261
  if (allowEmpty === void 0) { allowEmpty = true; }
6244
- if (allowEmpty && !input) {
6245
- return true;
6246
- }
6247
- var matches = this.regex.exec(input);
6248
- if (!matches || matches.length < 7) {
6249
- return false;
6250
- }
6251
- var groups = matches;
6252
- var decade = groups[2];
6253
- var century;
6254
- if (groups[1]) {
6255
- century = groups[1];
6256
- }
6257
- else {
6258
- var born = new Date().getFullYear() - parseInt(decade, 10);
6259
- if (groups[5] && groups[5] === '+') {
6260
- born -= 100;
6261
- }
6262
- century = born.toString().substring(0, 2);
6263
- }
6264
- // Create date time object.
6265
- var day = parseInt(groups[4], 10);
6266
- var isCoordinationNumber = day > 60;
6267
- day = isCoordinationNumber ? day - 60 : day;
6268
- var realDay = day;
6269
- var year = decade;
6270
- var fullYear = century + decade;
6271
- var month = groups[3];
6272
- var numbers = groups[6] + groups[7];
6273
- var controlNumber = groups[7];
6274
- // Try parse date-time to make sure it's actually a real date.
6275
- if (!Date.parse(fullYear + "-" + month + "-" + realDay)) {
6276
- return false;
6277
- }
6278
- if (this.luhn("" + year + month + day + groups[6]) !== parseInt(controlNumber, 10)) {
6279
- return false;
6280
- }
6281
- return true;
6282
- };
6283
- SEPersonalNumberValidator.prototype.luhn = function (value) {
6284
- // Luhm algorithm doubles every other number in the value.
6285
- // To get the correct checksum digit we aught to append a 0 on the sequence.
6286
- // If the result becomes a two digit number, subtract 9 from the value.
6287
- // If the total sum is not a 0, the last checksum value should be subtracted from 10.
6288
- // The resulting value is the check value that we use as control number.
6289
- // The value passed is a string, so we aught to get the actual integer value from each char (i.e., subtract '0' which is 48).
6290
- var t = value.split('').map(function (d) { return parseInt(d, 10); });
6291
- var sum = 0;
6292
- var temp;
6293
- for (var i = 0; i < t.length; i++) {
6294
- temp = t[i];
6295
- temp *= 2 - (i % 2);
6296
- if (temp > 9) {
6297
- temp -= 9;
6298
- }
6299
- sum += temp;
6300
- }
6301
- return Math.ceil(sum / 10.0) * 10 - sum;
6262
+ // Format: 10 or 12 digits [YY]YYMMDD[-/+]NNNN and pass checksum validation
6263
+ var match = input
6264
+ .replace(/[ +-]/g, '')
6265
+ .match(/^(\d{2}|\d{4})(\d{2})(\d{2})(\d{4})$/i);
6266
+ if (!match)
6267
+ return false; // not matching regex
6268
+ var _a = match.slice(1).map(Number), month = _a[1], day = _a[2];
6269
+ return ((!allowEmpty ? !!input : true) &&
6270
+ this.validateDayAndMonth(month, day) &&
6271
+ this.validateChecksum(input));
6272
+ };
6273
+ SEPersonalNumberValidator.prototype.validateDayAndMonth = function (month, day) {
6274
+ var maxDaysInMonth = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
6275
+ return (!(month < 1 || month > 12) && !(day < 1 || day > maxDaysInMonth[month]));
6276
+ };
6277
+ SEPersonalNumberValidator.prototype.validateChecksum = function (persNo) {
6278
+ var digits = persNo
6279
+ .replace(/[ +-]/g, '')
6280
+ .slice(-10)
6281
+ .split('')
6282
+ .map(Number);
6283
+ var luhnWeights = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1];
6284
+ var luhnF = function (n) { return (n < 10 ? n : n - 9); };
6285
+ var luhnSum = luhnWeights
6286
+ .map(function (value, index) { return value * digits[index]; })
6287
+ .map(luhnF)
6288
+ .reduce(function (a, b) { return a + b; });
6289
+ var controlSum = 10 - (+luhnSum % 10);
6290
+ return controlSum % 10 == 0;
6302
6291
  };
6303
6292
  return SEPersonalNumberValidator;
6304
6293
  }());