@player-ui/common-types-plugin 0.4.0-next.7 → 0.4.0-next.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/index.esm.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { TypesProviderPlugin } from '@player-ui/types-provider-plugin';
2
+ import { resolveDataRefs } from '@player-ui/player';
2
3
 
3
4
  const EMAIL_REGEX = /^((([a-z]|\d|[!#$%&'*+\-/=?^_`{|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#$%&'*+-/=?^_`{|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
4
5
  const PHONE_REGEX = /^\+?[1]?[- ]?\(?\d{3}[)\- ]?\s?\d{3}[ -]?\d{4}$/;
@@ -76,8 +77,9 @@ const regex = skipNullish((context, value, options) => {
76
77
  if (value === void 0 || value === null || value === "" || typeof (options == null ? void 0 : options.regex) !== "string") {
77
78
  return;
78
79
  }
79
- const patternMatch = options.regex.match(/^\/(.*)\/(\w)*$/);
80
- const regexp = patternMatch ? new RegExp(patternMatch[1], patternMatch[2]) : new RegExp(options.regex);
80
+ const resolvedRegex = resolveDataRefs(options.regex, context);
81
+ const patternMatch = resolvedRegex.match(/^\/(.*)\/(\w)*$/);
82
+ const regexp = patternMatch ? new RegExp(patternMatch[1], patternMatch[2]) : new RegExp(resolvedRegex);
81
83
  if (!regexp.test(value)) {
82
84
  const message = context.constants.getConstants("validation.regex", "constants", "Invalid entry");
83
85
  return { message };
@@ -338,9 +340,22 @@ var dataTypes = /*#__PURE__*/Object.freeze({
338
340
 
339
341
  const PLACEHOLDER = "#";
340
342
  const removeFormatCharactersFromMaskedString = (value, mask, reserved = [PLACEHOLDER]) => {
343
+ const reservedMatchesLength = mask.split("").filter((val) => reserved.includes(val)).length;
344
+ let replacements = 0;
341
345
  return value.split("").reduce((newString, nextChar, nextIndex) => {
342
346
  const maskedVal = mask[nextIndex];
347
+ if (maskedVal === void 0) {
348
+ return newString;
349
+ }
350
+ if (reservedMatchesLength === replacements) {
351
+ return newString;
352
+ }
343
353
  if (reserved.includes(maskedVal)) {
354
+ replacements++;
355
+ return newString + nextChar;
356
+ }
357
+ if (maskedVal !== nextChar) {
358
+ replacements++;
344
359
  return newString + nextChar;
345
360
  }
346
361
  return newString;
@@ -419,7 +434,7 @@ const createMaskedNumericFormatter = (name, mask) => {
419
434
  return usingExceptions;
420
435
  }
421
436
  }
422
- return removeFormatCharactersFromMaskedString(value, mask);
437
+ return formatAsMasked(value, /\d/g, mask.replace(/[^#]/g, ""));
423
438
  }
424
439
  };
425
440
  };
@@ -1,5 +1,5 @@
1
1
  {
2
- "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2654/execroot/player/plugins/common-types/core/src/data-types/types.ts",
2
+ "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2395/execroot/player/plugins/common-types/core/src/data-types/types.ts",
3
3
  "name": "BooleanType",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2654/execroot/player/plugins/common-types/core/src/data-types/types.ts",
2
+ "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2395/execroot/player/plugins/common-types/core/src/data-types/types.ts",
3
3
  "name": "CollectionType",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2654/execroot/player/plugins/common-types/core/src/data-types/types.ts",
2
+ "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2395/execroot/player/plugins/common-types/core/src/data-types/types.ts",
3
3
  "name": "DateType",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2654/execroot/player/plugins/common-types/core/src/data-types/types.ts",
2
+ "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2395/execroot/player/plugins/common-types/core/src/data-types/types.ts",
3
3
  "name": "IntegerNNType",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2654/execroot/player/plugins/common-types/core/src/data-types/types.ts",
2
+ "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2395/execroot/player/plugins/common-types/core/src/data-types/types.ts",
3
3
  "name": "IntegerPosType",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2654/execroot/player/plugins/common-types/core/src/data-types/types.ts",
2
+ "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2395/execroot/player/plugins/common-types/core/src/data-types/types.ts",
3
3
  "name": "IntegerType",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2654/execroot/player/plugins/common-types/core/src/data-types/types.ts",
2
+ "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2395/execroot/player/plugins/common-types/core/src/data-types/types.ts",
3
3
  "name": "PhoneType",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2654/execroot/player/plugins/common-types/core/src/data-types/types.ts",
2
+ "source": "/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2395/execroot/player/plugins/common-types/core/src/data-types/types.ts",
3
3
  "name": "StringType",
4
4
  "type": "object",
5
5
  "properties": {
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@player-ui/common-types-plugin",
3
- "version": "0.4.0-next.7",
3
+ "version": "0.4.0-next.9",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org"
7
7
  },
8
8
  "peerDependencies": {
9
- "@player-ui/player": "0.4.0-next.7"
9
+ "@player-ui/player": "0.4.0-next.9"
10
10
  },
11
11
  "dependencies": {
12
- "@player-ui/types-provider-plugin": "0.4.0-next.7",
12
+ "@player-ui/types-provider-plugin": "0.4.0-next.9",
13
13
  "@babel/runtime": "7.15.4"
14
14
  },
15
15
  "main": "dist/index.cjs.js",
@@ -53,6 +53,14 @@
53
53
  {
54
54
  "name": "Kelly Harrop",
55
55
  "url": "https://github.com/kharrop"
56
+ },
57
+ {
58
+ "name": "Alejandro Fimbres",
59
+ "url": "https://github.com/lexfm"
60
+ },
61
+ {
62
+ "name": "Rafael Campos",
63
+ "url": "https://github.com/rafbcampos"
56
64
  }
57
65
  ],
58
66
  "bundle": "./dist/common-types-plugin.prod.js"
@@ -17,10 +17,34 @@ export const removeFormatCharactersFromMaskedString = (
17
17
  mask: string,
18
18
  reserved: string[] = [PLACEHOLDER]
19
19
  ): string => {
20
+ const reservedMatchesLength = mask
21
+ .split('')
22
+ .filter((val) => reserved.includes(val)).length;
23
+ let replacements = 0;
24
+
20
25
  return value.split('').reduce((newString, nextChar, nextIndex) => {
21
26
  const maskedVal = mask[nextIndex];
22
27
 
28
+ if (maskedVal === undefined) {
29
+ return newString;
30
+ }
31
+
32
+ if (reservedMatchesLength === replacements) {
33
+ return newString;
34
+ }
35
+
23
36
  if (reserved.includes(maskedVal)) {
37
+ replacements++;
38
+ return newString + nextChar;
39
+ }
40
+
41
+ /**
42
+ * Characters will match when the incoming value is formatted, but in cases
43
+ * where it's being pulled from the model and deformatted again, ensure we
44
+ * don't skip over characters.
45
+ */
46
+ if (maskedVal !== nextChar) {
47
+ replacements++;
24
48
  return newString + nextChar;
25
49
  }
26
50
 
@@ -186,7 +210,7 @@ export const createMaskedNumericFormatter = (
186
210
  }
187
211
  }
188
212
 
189
- return removeFormatCharactersFromMaskedString(value, mask);
213
+ return formatAsMasked(value, /\d/g, mask.replace(/[^#]/g, ''));
190
214
  },
191
215
  };
192
216
  };
@@ -1,4 +1,5 @@
1
1
  import type { Expression } from '@player-ui/types';
2
+ import { resolveDataRefs } from '@player-ui/player';
2
3
  import type { ValidatorFunction } from '@player-ui/player';
3
4
 
4
5
  // Shamelessly lifted from Scott Gonzalez via the Bassistance Validation plugin http://projects.scottsplayground.com/email_address_validation/
@@ -177,12 +178,13 @@ export const regex: ValidatorFunction<{
177
178
  return;
178
179
  }
179
180
 
181
+ const resolvedRegex = resolveDataRefs(options.regex, context);
180
182
  // Split up /pattern/flags into [pattern, flags]
181
- const patternMatch = options.regex.match(/^\/(.*)\/(\w)*$/);
183
+ const patternMatch = resolvedRegex.match(/^\/(.*)\/(\w)*$/);
182
184
 
183
185
  const regexp = patternMatch
184
186
  ? new RegExp(patternMatch[1], patternMatch[2])
185
- : new RegExp(options.regex);
187
+ : new RegExp(resolvedRegex);
186
188
 
187
189
  if (!regexp.test(value)) {
188
190
  const message = context.constants.getConstants(