@abgov/jsonforms-components 2.74.1 → 2.75.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.
package/index.esm.js CHANGED
@@ -4821,6 +4821,195 @@ const UTCToFullLocalTime = (fullTime, useUTC = false) => {
4821
4821
  }).replace('p.m.', 'PM').replace('a.m.', 'AM');
4822
4822
  };
4823
4823
 
4824
+ // Default formats keyed by type; the mask can be overridden per field via UI schema options.
4825
+ const DEFAULT_PATTERNS = {
4826
+ phone: {
4827
+ mask: '(###) ###-####',
4828
+ pattern: /^\(?\d{3}\)?[- ]?\d{3}[- ]?\d{4}$/,
4829
+ error: 'Must be a valid 10-digit phone number in format (000) 000-0000',
4830
+ allowedKeys: /[0-9]/
4831
+ },
4832
+ sin: {
4833
+ mask: '### ### ###',
4834
+ pattern: /^\d{3} \d{3} \d{3}$/,
4835
+ error: 'Must be three groups of three digits.',
4836
+ allowedKeys: /[0-9]/
4837
+ },
4838
+ postalCode: {
4839
+ mask: '### ###',
4840
+ pattern: /^[A-Za-z]\d[A-Za-z] \d[A-Za-z]\d$/,
4841
+ error: 'Must be in A0A 0A0 capital letters and numbers format',
4842
+ allowedKeys: /[A-Za-z0-9]/
4843
+ },
4844
+ driverId: {
4845
+ // Alberta driver's licence: six digits, a dash, then three digits.
4846
+ mask: '######-###',
4847
+ pattern: /^\d{6}-\d{3}$/,
4848
+ error: "Must be a valid driver's licence number in format 000000-000",
4849
+ allowedKeys: /[0-9]/
4850
+ },
4851
+ mvid: {
4852
+ // Motor vehicle ID: four digits, a dash, then five digits.
4853
+ mask: '####-#####',
4854
+ pattern: /^\d{4}-\d{5}$/,
4855
+ error: 'Must be a valid motor vehicle ID in format 0000-00000',
4856
+ allowedKeys: /[0-9]/
4857
+ }
4858
+ };
4859
+ // Mask placeholder characters; each consumes one input character. Any other mask character is treated as a literal.
4860
+ const MASK_PLACEHOLDERS = new Set(['#', '*', '_']);
4861
+ const isPlaceholder = char => MASK_PLACEHOLDERS.has(char);
4862
+ // Navigation/editing keys that keystroke filtering must always let through.
4863
+ const MASK_CONTROL_KEYS = new Set(['Backspace', 'Delete', 'Tab', 'Enter', 'Escape', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End']);
4864
+ // A single-character key should be blocked when the format restricts input and the key isn't allowed.
4865
+ const shouldBlockKey = (key, allowedKeys) => !!allowedKeys && key.length === 1 && !MASK_CONTROL_KEYS.has(key) && !allowedKeys.test(key);
4866
+ // Removes characters the format doesn't allow (e.g. letters from a digit-only field), for paste/programmatic input.
4867
+ const filterAllowedKeys = (value, allowedKeys) => allowedKeys ? [...(value != null ? value : '')].filter(char => allowedKeys.test(char)).join('') : value != null ? value : '';
4868
+ // A mask slot holds one content character (letter or digit); everything else in the value is a separator.
4869
+ const NON_CONTENT = /[^a-zA-Z0-9]/g;
4870
+ const IS_CONTENT = /[a-zA-Z0-9]/;
4871
+ // Number of fill slots in a mask (its placeholder characters).
4872
+ const maskDigitCount = mask => [...mask].filter(isPlaceholder).length;
4873
+ // Formats a value into a placeholder mask (e.g. '(###) ###-####'), filling only the content entered so far.
4874
+ // Placeholder characters consume one content character each; every other mask character is a literal.
4875
+ const formatWithPattern = (value, mask) => {
4876
+ const maxContent = maskDigitCount(mask);
4877
+ const content = (value != null ? value : '').replace(NON_CONTENT, '').slice(0, maxContent);
4878
+ let index = 0;
4879
+ let formatted = '';
4880
+ for (const maskChar of mask) {
4881
+ if (index >= content.length) {
4882
+ break;
4883
+ }
4884
+ formatted += isPlaceholder(maskChar) ? content[index++] : maskChar;
4885
+ }
4886
+ return formatted;
4887
+ };
4888
+ // Fills the mask with the value's content, leaving the placeholder character for positions not yet entered.
4889
+ const toMaskTemplate = (value, mask) => {
4890
+ const maxContent = maskDigitCount(mask);
4891
+ const content = (value != null ? value : '').replace(NON_CONTENT, '').slice(0, maxContent);
4892
+ let index = 0;
4893
+ let display = '';
4894
+ for (const maskChar of mask) {
4895
+ display += isPlaceholder(maskChar) ? index < content.length ? content[index++] : maskChar : maskChar;
4896
+ }
4897
+ return display;
4898
+ };
4899
+ // Caret position just after the Nth content character within a rendered mask, so in-place edits keep the cursor in place.
4900
+ const caretAfterDigits = (display, digitCount) => {
4901
+ if (digitCount <= 0) {
4902
+ return 0;
4903
+ }
4904
+ let seen = 0;
4905
+ for (let i = 0; i < display.length; i++) {
4906
+ if (IS_CONTENT.test(display[i])) {
4907
+ seen += 1;
4908
+ if (seen === digitCount) {
4909
+ return i + 1;
4910
+ }
4911
+ }
4912
+ }
4913
+ return display.length;
4914
+ };
4915
+ // Computes an in-place masked edit from the raw input and caret index: what to show, what to store, where to put the caret.
4916
+ const computeMaskEdit = (rawValue, caretIndex, mask) => {
4917
+ const digitsBeforeCaret = rawValue.slice(0, caretIndex).replace(NON_CONTENT, '').length;
4918
+ const display = toMaskTemplate(rawValue, mask);
4919
+ const stored = formatWithPattern(rawValue, mask);
4920
+ const caret = caretAfterDigits(display, Math.min(digitsBeforeCaret, maskDigitCount(mask)));
4921
+ return {
4922
+ display,
4923
+ stored,
4924
+ caret
4925
+ };
4926
+ };
4927
+ // True once the value has as many content characters as the mask has fill slots.
4928
+ const isMaskFilled = (value, mask) => value.replace(NON_CONTENT, '').length >= maskDigitCount(mask);
4929
+ // A human placeholder for a mask, e.g. '(###) ###-####' -> '(000) 000-0000'.
4930
+ const maskPlaceholder = mask => [...mask].map(char => isPlaceholder(char) ? '0' : char).join('');
4931
+ // GoA retargets composed events to the host, so prefer the inner native input from the composed path.
4932
+ const getMaskInputTarget = detail => {
4933
+ var _target$shadowRoot$qu, _target$shadowRoot;
4934
+ const event = detail.event;
4935
+ if (!event) {
4936
+ return undefined;
4937
+ }
4938
+ const path = typeof event.composedPath === 'function' ? event.composedPath() : [];
4939
+ const fromPath = path.find(node => node instanceof HTMLInputElement);
4940
+ if (fromPath) {
4941
+ return fromPath;
4942
+ }
4943
+ const target = event.target;
4944
+ if (target instanceof HTMLInputElement) {
4945
+ return target;
4946
+ }
4947
+ return (_target$shadowRoot$qu = target == null || (_target$shadowRoot = target.shadowRoot) == null ? void 0 : _target$shadowRoot.querySelector('input')) != null ? _target$shadowRoot$qu : undefined;
4948
+ };
4949
+ const applyMaskValue = (target, edit) => {
4950
+ target.value = edit.display;
4951
+ target.setSelectionRange == null || target.setSelectionRange(edit.caret, edit.caret);
4952
+ };
4953
+ // Applies an in-place edit to the inner input and re-applies after the web component paints.
4954
+ const applyInPlaceEdit = (target, edit) => {
4955
+ if (!target) {
4956
+ return;
4957
+ }
4958
+ applyMaskValue(target, edit);
4959
+ requestAnimationFrame(() => applyMaskValue(target, edit));
4960
+ };
4961
+ // When the template is already filled, extra content characters must be rejected rather than shifting the value.
4962
+ const overflowMaskEdit = (previousDisplay, rawValue, caretIndex, mask) => {
4963
+ if (!isMaskFilled(previousDisplay, mask)) {
4964
+ return undefined;
4965
+ }
4966
+ if ((rawValue != null ? rawValue : '').replace(NON_CONTENT, '').length <= maskDigitCount(mask)) {
4967
+ return undefined;
4968
+ }
4969
+ return {
4970
+ display: previousDisplay,
4971
+ stored: formatWithPattern(previousDisplay, mask),
4972
+ caret: Math.min(Math.max(caretIndex, 0), previousDisplay.length)
4973
+ };
4974
+ };
4975
+ /**
4976
+ * Applies a mask template to a value, e.g. mask "(###) ###-####" turns "7801234567" into "(780) 123-4567".
4977
+ * '#' consumes one content character from the input; every other character is a literal inserted into the output.
4978
+ * The mask's literal characters are stripped from the input first so an already formatted value re-formats cleanly.
4979
+ * Returns the original value unchanged when the mask is empty or no content characters remain.
4980
+ * @param value - The raw input value
4981
+ * @param mask - The mask template string
4982
+ * @returns The masked value
4983
+ */
4984
+ const applyFormatPattern = (value, mask) => {
4985
+ if (!mask || !value) {
4986
+ return value;
4987
+ }
4988
+ const literals = new Set(mask.split('').filter(char => !isPlaceholder(char)));
4989
+ const content = value.split('').filter(char => !literals.has(char));
4990
+ if (content.length === 0) {
4991
+ return value;
4992
+ }
4993
+ let contentIndex = 0;
4994
+ let result = '';
4995
+ for (const maskChar of mask) {
4996
+ if (contentIndex >= content.length) {
4997
+ break;
4998
+ }
4999
+ if (isPlaceholder(maskChar)) {
5000
+ result += content[contentIndex];
5001
+ contentIndex += 1;
5002
+ } else {
5003
+ result += maskChar;
5004
+ }
5005
+ }
5006
+ // Append any remaining content characters that did not fit the mask.
5007
+ if (contentIndex < content.length) {
5008
+ result += content.slice(contentIndex).join('');
5009
+ }
5010
+ return result;
5011
+ };
5012
+
4824
5013
  /**
4825
5014
  * Checks input controls data value to determine is required and has any data.
4826
5015
  * @param props - The JsonForm control props
@@ -9810,54 +9999,6 @@ if (DESCRIPTORS$1 && isCallable(NativeSymbol) && (!('description' in SymbolProto
9810
9999
  });
9811
10000
  }
9812
10001
 
9813
- var call$2 = functionCall;
9814
- var fixRegExpWellKnownSymbolLogic = fixRegexpWellKnownSymbolLogic;
9815
- var anObject = anObject$t;
9816
- var isNullOrUndefined = isNullOrUndefined$7;
9817
- var toLength$2 = toLength$7;
9818
- var toString$5 = toString$n;
9819
- var requireObjectCoercible$3 = requireObjectCoercible$e;
9820
- var getMethod = getMethod$7;
9821
- var advanceStringIndex = advanceStringIndex$3;
9822
- var regExpExec = regexpExecAbstract;
9823
-
9824
- // @@match logic
9825
- fixRegExpWellKnownSymbolLogic('match', function (MATCH, nativeMatch, maybeCallNative) {
9826
- return [
9827
- // `String.prototype.match` method
9828
- // https://tc39.es/ecma262/#sec-string.prototype.match
9829
- function match(regexp) {
9830
- var O = requireObjectCoercible$3(this);
9831
- var matcher = isNullOrUndefined(regexp) ? undefined : getMethod(regexp, MATCH);
9832
- return matcher ? call$2(matcher, regexp, O) : new RegExp(regexp)[MATCH](toString$5(O));
9833
- },
9834
- // `RegExp.prototype[@@match]` method
9835
- // https://tc39.es/ecma262/#sec-regexp.prototype-@@match
9836
- function (string) {
9837
- var rx = anObject(this);
9838
- var S = toString$5(string);
9839
- var res = maybeCallNative(nativeMatch, rx, S);
9840
-
9841
- if (res.done) return res.value;
9842
-
9843
- if (!rx.global) return regExpExec(rx, S);
9844
-
9845
- var fullUnicode = rx.unicode;
9846
- rx.lastIndex = 0;
9847
- var A = [];
9848
- var n = 0;
9849
- var result;
9850
- while ((result = regExpExec(rx, S)) !== null) {
9851
- var matchStr = toString$5(result[0]);
9852
- A[n] = matchStr;
9853
- if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength$2(rx.lastIndex), fullUnicode);
9854
- n++;
9855
- }
9856
- return n === 0 ? null : A;
9857
- }
9858
- ];
9859
- });
9860
-
9861
10002
  //type DebounceValueType = string | boolean | number | Record<string, unknown>;
9862
10003
  /**
9863
10004
  * A helper util to return a value at a certain delay. The delay is reset if the value arg changes
@@ -9888,23 +10029,6 @@ function fetchRegisterConfigFromOptions$1(options) {
9888
10029
  const config = Object.assign({}, options);
9889
10030
  return config;
9890
10031
  }
9891
- const formattedSinPattern = /^\d{3}-\d{3}-\d{3}$/;
9892
- const allowedSinInputPattern = /^[\d-]*$/;
9893
- const allowedSinKeyPattern = /^[\d-]$/;
9894
- const allowedSinControlKeys = new Set(['Backspace', 'Delete', 'Tab', 'Enter', 'Escape', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End']);
9895
- const formatSinForDisplay = value => value.replace(/ /g, '-');
9896
- const formatSinForSchema = value => value.replace(/-/g, ' ');
9897
- const formatSin = value => {
9898
- var _digits$match$join, _digits$match;
9899
- if (!allowedSinInputPattern.test(value)) {
9900
- return '';
9901
- }
9902
- if (formattedSinPattern.test(value)) {
9903
- return value;
9904
- }
9905
- const digits = value == null ? void 0 : value.replace(/\D/g, '').slice(0, 9);
9906
- return (_digits$match$join = digits == null || (_digits$match = digits.match(/.{1,3}/g)) == null ? void 0 : _digits$match.join('-')) != null ? _digits$match$join : '';
9907
- };
9908
10032
  const resetInputValue = (detail, value) => {
9909
10033
  var _detail$event;
9910
10034
  const target = (_detail$event = detail.event) == null ? void 0 : _detail$event.target;
@@ -9912,6 +10036,13 @@ const resetInputValue = (detail, value) => {
9912
10036
  target.value = value;
9913
10037
  }
9914
10038
  };
10039
+ // Resolve the mask format for a field: schema.format must match a DEFAULT_PATTERNS key.
10040
+ const resolveFormatConfig = schema => {
10041
+ if (schema.format && schema.format in DEFAULT_PATTERNS) {
10042
+ return DEFAULT_PATTERNS[schema.format];
10043
+ }
10044
+ return schema.title === sinTitle ? DEFAULT_PATTERNS.sin : undefined;
10045
+ };
9915
10046
  const GoAInputText = props => {
9916
10047
  return jsxs(JsonFormRegisterProvider, {
9917
10048
  defaultRegisters: undefined,
@@ -9919,7 +10050,7 @@ const GoAInputText = props => {
9919
10050
  });
9920
10051
  };
9921
10052
  const InnerGoAInputText = props => {
9922
- var _uischema$options$com, _uischema$options, _props$uischema, _uischema$options2, _uischema$options3, _uischema$options$pla, _uischema$options4, _props$uischema2, _uischema$options5, _uischema$options6, _uischema$options$com2, _uischema$options7, _uischema$options8, _uischema$options9;
10053
+ var _formatConfig$mask, _uischema$options, _uischema$options2, _uischema$options$com, _uischema$options3, _props$uischema, _uischema$options4, _uischema$options5, _uischema$options$pla, _uischema$options6, _props$uischema2, _uischema$options7, _uischema$options8, _uischema$options$com2, _uischema$options9, _uischema$options0, _uischema$options1, _uischema$options10;
9923
10054
  const {
9924
10055
  data,
9925
10056
  config,
@@ -9934,18 +10065,37 @@ const InnerGoAInputText = props => {
9934
10065
  isVisited,
9935
10066
  setIsVisited
9936
10067
  } = props;
9937
- const isSinField = schema.title === sinTitle;
9938
- const initialValue = isSinField && typeof data === 'string' ? formatSinForDisplay(data) : data;
10068
+ // Detect the mask format from the JSON schema `format` (with the SIN title kept for backward compatibility).
10069
+ const formatConfig = resolveFormatConfig(schema);
10070
+ const mask = (_formatConfig$mask = formatConfig == null ? void 0 : formatConfig.mask) != null ? _formatConfig$mask : uischema == null || (_uischema$options = uischema.options) == null ? void 0 : _uischema$options.mask;
10071
+ const allowedKeys = formatConfig == null ? void 0 : formatConfig.allowedKeys;
10072
+ // In-place shows the fill-in template and keeps the caret in place while editing.
10073
+ const inPlace = !!mask && (uischema == null || (_uischema$options2 = uischema.options) == null ? void 0 : _uischema$options2.inPlace) === true;
10074
+ const toDisplay = value => {
10075
+ if (!mask) {
10076
+ return value;
10077
+ }
10078
+ const str = typeof value === 'string' ? value : '';
10079
+ return inPlace ? toMaskTemplate(str, mask) : formatWithPattern(str, mask);
10080
+ };
9939
10081
  const [manualInput, setManualInput] = useState(false);
9940
- const [localValue, setLocalValue] = useState(initialValue);
10082
+ // In-place mounts empty then sets the template so the web component reflects it (a value change forces the paint).
10083
+ const [localValue, setLocalValue] = useState(inPlace ? '' : toDisplay(data));
10084
+ useEffect(() => {
10085
+ if (inPlace) {
10086
+ setLocalValue(toDisplay(data));
10087
+ }
10088
+ // eslint-disable-next-line react-hooks/exhaustive-deps
10089
+ }, []);
9941
10090
  const debouncedValue = useDebounce(localValue, 300);
9942
10091
  const hasDefault = Object.prototype.hasOwnProperty.call(schema, 'default');
9943
10092
  useEffect(() => {
9944
10093
  if (data === undefined || data === null) {
9945
10094
  return;
9946
10095
  }
9947
- setLocalValue(isSinField && typeof data === 'string' ? formatSinForDisplay(data) : data);
9948
- }, [data, isSinField]);
10096
+ setLocalValue(toDisplay(data));
10097
+ // eslint-disable-next-line react-hooks/exhaustive-deps
10098
+ }, [data, mask]);
9949
10099
  useEffect(() => {
9950
10100
  if (typeof handleChange === 'function' && hasDefault && data === undefined && !manualInput) {
9951
10101
  handleChange(props.path, schema.default);
@@ -9955,17 +10105,19 @@ const InnerGoAInputText = props => {
9955
10105
  }, [schema.default, data]);
9956
10106
  /* istanbul ignore next */
9957
10107
  useEffect(() => {
9958
- const dataForInput = isSinField && typeof data === 'string' ? formatSinForDisplay(data) : data;
10108
+ const dataForInput = toDisplay(data);
9959
10109
  if (debouncedValue === dataForInput) return;
9960
10110
  // Only sync if debouncedValue differs from data and is not initial empty state
9961
10111
  if (debouncedValue !== dataForInput && (debouncedValue !== '' || data !== undefined)) {
9962
10112
  onChangeForInputControl({
9963
- value: isSinField ? formatSinForSchema(debouncedValue) : debouncedValue,
10113
+ // Normalize to the clean value; for in-place this drops the unfilled template characters.
10114
+ value: mask ? formatWithPattern(debouncedValue, mask) : debouncedValue,
9964
10115
  controlProps: props
9965
10116
  });
9966
10117
  }
10118
+ // eslint-disable-next-line react-hooks/exhaustive-deps
9967
10119
  }, [debouncedValue]);
9968
- const width = (_uischema$options$com = uischema == null || (_uischema$options = uischema.options) == null || (_uischema$options = _uischema$options.componentProps) == null ? void 0 : _uischema$options.width) != null ? _uischema$options$com : '100%';
10120
+ const width = (_uischema$options$com = uischema == null || (_uischema$options3 = uischema.options) == null || (_uischema$options3 = _uischema$options3.componentProps) == null ? void 0 : _uischema$options3.width) != null ? _uischema$options$com : '100%';
9969
10121
  const registerCtx = useContext(JsonFormsRegisterContext);
9970
10122
  const registerConfig = fetchRegisterConfigFromOptions$1((_props$uischema = props.uischema) == null || (_props$uischema = _props$uischema.options) == null ? void 0 : _props$uischema.register);
9971
10123
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -9973,9 +10125,9 @@ const InnerGoAInputText = props => {
9973
10125
  if (registerConfig) {
9974
10126
  registerData = registerCtx == null ? void 0 : registerCtx.selectRegisterData(registerConfig);
9975
10127
  }
9976
- const labelPath = (uischema == null || (_uischema$options2 = uischema.options) == null ? void 0 : _uischema$options2.label) || 'label';
9977
- const valuePath = (uischema == null || (_uischema$options3 = uischema.options) == null ? void 0 : _uischema$options3.value) || 'value';
9978
- const dropDownPlaceholder = (_uischema$options$pla = uischema == null || (_uischema$options4 = uischema.options) == null ? void 0 : _uischema$options4.placeholder) != null ? _uischema$options$pla : 'Select an option';
10128
+ const labelPath = (uischema == null || (_uischema$options4 = uischema.options) == null ? void 0 : _uischema$options4.label) || 'label';
10129
+ const valuePath = (uischema == null || (_uischema$options5 = uischema.options) == null ? void 0 : _uischema$options5.value) || 'value';
10130
+ const dropDownPlaceholder = (_uischema$options$pla = uischema == null || (_uischema$options6 = uischema.options) == null ? void 0 : _uischema$options6.placeholder) != null ? _uischema$options$pla : 'Select an option';
9979
10131
  const autoCompletion = ((_props$uischema2 = props.uischema) == null || (_props$uischema2 = _props$uischema2.options) == null ? void 0 : _props$uischema2.autoComplete) === true;
9980
10132
  const mergedOptions = useMemo(() => {
9981
10133
  var _registerData;
@@ -10012,32 +10164,10 @@ const InnerGoAInputText = props => {
10012
10164
  }, [registerCtx, registerConfig]);
10013
10165
  const appliedUiSchemaOptions = Object.assign({}, config, uischema == null ? void 0 : uischema.options);
10014
10166
  const placeholder = (appliedUiSchemaOptions == null ? void 0 : appliedUiSchemaOptions.placeholder) || (schema == null ? void 0 : schema.description) || '';
10015
- const autoCapitalize = (uischema == null || (_uischema$options5 = uischema.options) == null || (_uischema$options5 = _uischema$options5.componentProps) == null ? void 0 : _uischema$options5.autoCapitalize) === true || (uischema == null || (_uischema$options6 = uischema.options) == null ? void 0 : _uischema$options6.autoCapitalize) === true;
10016
- const readOnly = (_uischema$options$com2 = uischema == null || (_uischema$options7 = uischema.options) == null || (_uischema$options7 = _uischema$options7.componentProps) == null ? void 0 : _uischema$options7.readOnly) != null ? _uischema$options$com2 : false;
10017
- const preventInvalidSinKey = event => {
10018
- if (!isSinField || allowedSinControlKeys.has(event.key) || event.metaKey || event.ctrlKey || event.altKey || allowedSinKeyPattern.test(event.key)) {
10019
- return;
10020
- }
10021
- event.preventDefault();
10022
- };
10023
- const preventInvalidSinBeforeInput = event => {
10024
- if (!isSinField) {
10025
- return;
10026
- }
10027
- const data = event.nativeEvent.data;
10028
- if (data && !allowedSinInputPattern.test(data)) {
10029
- event.preventDefault();
10030
- }
10031
- };
10032
- const preventInvalidSinPaste = event => {
10033
- if (isSinField && !allowedSinInputPattern.test(event.clipboardData.getData('text'))) {
10034
- event.preventDefault();
10035
- }
10036
- };
10167
+ const autoCapitalize = (uischema == null || (_uischema$options7 = uischema.options) == null || (_uischema$options7 = _uischema$options7.componentProps) == null ? void 0 : _uischema$options7.autoCapitalize) === true || (uischema == null || (_uischema$options8 = uischema.options) == null ? void 0 : _uischema$options8.autoCapitalize) === true;
10168
+ const readOnly = (_uischema$options$com2 = uischema == null || (_uischema$options9 = uischema.options) == null || (_uischema$options9 = _uischema$options9.componentProps) == null ? void 0 : _uischema$options9.readOnly) != null ? _uischema$options$com2 : false;
10169
+ const formatPattern = uischema == null || (_uischema$options0 = uischema.options) == null ? void 0 : _uischema$options0.formatPattern;
10037
10170
  return jsx("div", {
10038
- onKeyDownCapture: preventInvalidSinKey,
10039
- onBeforeInputCapture: preventInvalidSinBeforeInput,
10040
- onPasteCapture: preventInvalidSinPaste,
10041
10171
  children: mergedOptions.length > 1 ? jsx(GoabDropdown, {
10042
10172
  name: `jsonforms-${path}-dropdown`,
10043
10173
  value: data,
@@ -10058,22 +10188,34 @@ const InnerGoAInputText = props => {
10058
10188
  value: localValue,
10059
10189
  width: width,
10060
10190
  readonly: readOnly,
10061
- maxLength: isSinField ? 11 : undefined,
10062
- placeholder: placeholder,
10191
+ maxLength: inPlace ? undefined : mask ? mask.length : undefined,
10192
+ placeholder: inPlace ? undefined : mask ? maskPlaceholder(mask) : placeholder,
10063
10193
  name: (appliedUiSchemaOptions == null ? void 0 : appliedUiSchemaOptions.name) || `${id || label}-input`,
10064
10194
  ariaLabel: (appliedUiSchemaOptions == null ? void 0 : appliedUiSchemaOptions.name) || `${id || label}-input`,
10065
10195
  testId: (appliedUiSchemaOptions == null ? void 0 : appliedUiSchemaOptions.testId) || `${id}-input`
10066
- }, (_uischema$options8 = uischema.options) == null ? void 0 : _uischema$options8.componentProps, {
10196
+ }, (_uischema$options1 = uischema.options) == null ? void 0 : _uischema$options1.componentProps, {
10067
10197
  onChange: detail => {
10068
- let formattedValue = detail.value;
10069
- if (isSinField && !allowedSinInputPattern.test(detail.value)) {
10070
- resetInputValue(detail, localValue);
10071
- return;
10072
- }
10073
- if (isSinField && detail.value !== '') {
10074
- formattedValue = formatSin(detail.value);
10198
+ const cleaned = allowedKeys ? filterAllowedKeys(detail.value, allowedKeys) : detail.value;
10199
+ if (inPlace && mask) {
10200
+ var _target$selectionStar;
10201
+ const target = getMaskInputTarget(detail);
10202
+ const caretIndex = (_target$selectionStar = target == null ? void 0 : target.selectionStart) != null ? _target$selectionStar : cleaned.length;
10203
+ const overflow = overflowMaskEdit(localValue, cleaned, caretIndex, mask);
10204
+ if (overflow) {
10205
+ applyInPlaceEdit(target, overflow);
10206
+ return;
10207
+ }
10208
+ const edit = computeMaskEdit(cleaned, caretIndex, mask);
10209
+ applyInPlaceEdit(target, edit);
10210
+ setLocalValue(edit.display);
10211
+ } else {
10212
+ const formattedValue = mask && cleaned !== '' ? formatWithPattern(cleaned, mask) : cleaned;
10213
+ // If characters were rejected, force the input to show the cleaned value.
10214
+ if (allowedKeys && cleaned !== detail.value) {
10215
+ resetInputValue(detail, formattedValue);
10216
+ }
10217
+ setLocalValue(formattedValue);
10075
10218
  }
10076
- setLocalValue(formattedValue);
10077
10219
  setManualInput(true);
10078
10220
  if (isVisited === false && setIsVisited) {
10079
10221
  setIsVisited();
@@ -10083,19 +10225,39 @@ const InnerGoAInputText = props => {
10083
10225
  if (isVisited === false && setIsVisited) {
10084
10226
  setIsVisited();
10085
10227
  }
10228
+ const capitalizedValue = autoCapitalize ? detail.value.toUpperCase() : detail.value;
10229
+ if (formatPattern) {
10230
+ const formattedValue = applyFormatPattern(capitalizedValue, formatPattern);
10231
+ setLocalValue(formattedValue);
10232
+ handleChange(path, formattedValue);
10233
+ return;
10234
+ }
10086
10235
  onBlurForTextControl({
10087
10236
  name: detail.name,
10088
10237
  controlProps: props,
10089
- value: autoCapitalize ? detail.value.toUpperCase() : detail.value
10238
+ value: capitalizedValue
10090
10239
  });
10091
10240
  },
10092
10241
  onKeyPress: detail => {
10093
- if (isSinField && detail.key && !allowedSinKeyPattern.test(detail.key)) {
10094
- var _detail$event2;
10095
- (_detail$event2 = detail.event) == null || _detail$event2.preventDefault();
10242
+ const keyPressDetail = detail;
10243
+ const blockDisallowed = shouldBlockKey(detail.key, allowedKeys);
10244
+ // In-place has no maxLength, and GoA keyPress fires on keyup after the character is inserted.
10245
+ const blockOverflow = inPlace && !!mask && /^[A-Za-z0-9]$/.test(detail.key) && isMaskFilled(localValue, mask);
10246
+ if (blockDisallowed || blockOverflow) {
10247
+ var _keyPressDetail$event;
10248
+ (_keyPressDetail$event = keyPressDetail.event) == null || _keyPressDetail$event.preventDefault();
10249
+ }
10250
+ if (blockOverflow && mask) {
10251
+ var _ref, _target$value, _target$selectionStar2;
10252
+ const target = getMaskInputTarget(keyPressDetail);
10253
+ const rawValue = (_ref = (_target$value = target == null ? void 0 : target.value) != null ? _target$value : detail.value) != null ? _ref : localValue;
10254
+ const overflow = overflowMaskEdit(localValue, rawValue, (_target$selectionStar2 = target == null ? void 0 : target.selectionStart) != null ? _target$selectionStar2 : localValue.length, mask);
10255
+ if (overflow) {
10256
+ applyInPlaceEdit(target, overflow);
10257
+ }
10096
10258
  }
10097
10259
  }
10098
- }, uischema == null || (_uischema$options9 = uischema.options) == null ? void 0 : _uischema$options9.componentProps))
10260
+ }, uischema == null || (_uischema$options10 = uischema.options) == null ? void 0 : _uischema$options10.componentProps))
10099
10261
  });
10100
10262
  };
10101
10263
  const GoATextControl = props => jsx(GoAInputBaseControl, Object.assign({}, props, {
@@ -10254,15 +10416,15 @@ function _objectWithoutPropertiesLoose(r, e) {
10254
10416
  }
10255
10417
 
10256
10418
  var toIntegerOrInfinity$1 = toIntegerOrInfinity$9;
10257
- var toString$4 = toString$n;
10258
- var requireObjectCoercible$2 = requireObjectCoercible$e;
10419
+ var toString$5 = toString$n;
10420
+ var requireObjectCoercible$3 = requireObjectCoercible$e;
10259
10421
 
10260
10422
  var $RangeError$1 = RangeError;
10261
10423
 
10262
10424
  // `String.prototype.repeat` method implementation
10263
10425
  // https://tc39.es/ecma262/#sec-string.prototype.repeat
10264
10426
  var stringRepeat = function repeat(count) {
10265
- var str = toString$4(requireObjectCoercible$2(this));
10427
+ var str = toString$5(requireObjectCoercible$3(this));
10266
10428
  var result = '';
10267
10429
  var n = toIntegerOrInfinity$1(count);
10268
10430
  if (n < 0 || n === Infinity) throw new $RangeError$1('Wrong number of repetitions');
@@ -10272,10 +10434,10 @@ var stringRepeat = function repeat(count) {
10272
10434
 
10273
10435
  // https://github.com/tc39/proposal-string-pad-start-end
10274
10436
  var uncurryThis$4 = functionUncurryThis;
10275
- var toLength$1 = toLength$7;
10276
- var toString$3 = toString$n;
10437
+ var toLength$2 = toLength$7;
10438
+ var toString$4 = toString$n;
10277
10439
  var $repeat = stringRepeat;
10278
- var requireObjectCoercible$1 = requireObjectCoercible$e;
10440
+ var requireObjectCoercible$2 = requireObjectCoercible$e;
10279
10441
 
10280
10442
  var repeat = uncurryThis$4($repeat);
10281
10443
  var stringSlice$1 = uncurryThis$4(''.slice);
@@ -10284,10 +10446,10 @@ var ceil = Math.ceil;
10284
10446
  // `String.prototype.{ padStart, padEnd }` methods implementation
10285
10447
  var createMethod = function (IS_END) {
10286
10448
  return function ($this, maxLength, fillString) {
10287
- var S = toString$3(requireObjectCoercible$1($this));
10288
- var intMaxLength = toLength$1(maxLength);
10449
+ var S = toString$4(requireObjectCoercible$2($this));
10450
+ var intMaxLength = toLength$2(maxLength);
10289
10451
  var stringLength = S.length;
10290
- var fillStr = fillString === undefined ? ' ' : toString$3(fillString);
10452
+ var fillStr = fillString === undefined ? ' ' : toString$4(fillString);
10291
10453
  var fillLen, stringFiller;
10292
10454
  if (intMaxLength <= stringLength || fillStr === '') return S;
10293
10455
  fillLen = intMaxLength - stringLength;
@@ -11331,6 +11493,54 @@ const GoInputBaseReview = props => jsx(GoAInputBaseControl, Object.assign({}, pr
11331
11493
  }));
11332
11494
  const GoAInputBaseReviewControl = withJsonFormsControlProps(GoInputBaseReview);
11333
11495
 
11496
+ var call$2 = functionCall;
11497
+ var fixRegExpWellKnownSymbolLogic = fixRegexpWellKnownSymbolLogic;
11498
+ var anObject = anObject$t;
11499
+ var isNullOrUndefined = isNullOrUndefined$7;
11500
+ var toLength$1 = toLength$7;
11501
+ var toString$3 = toString$n;
11502
+ var requireObjectCoercible$1 = requireObjectCoercible$e;
11503
+ var getMethod = getMethod$7;
11504
+ var advanceStringIndex = advanceStringIndex$3;
11505
+ var regExpExec = regexpExecAbstract;
11506
+
11507
+ // @@match logic
11508
+ fixRegExpWellKnownSymbolLogic('match', function (MATCH, nativeMatch, maybeCallNative) {
11509
+ return [
11510
+ // `String.prototype.match` method
11511
+ // https://tc39.es/ecma262/#sec-string.prototype.match
11512
+ function match(regexp) {
11513
+ var O = requireObjectCoercible$1(this);
11514
+ var matcher = isNullOrUndefined(regexp) ? undefined : getMethod(regexp, MATCH);
11515
+ return matcher ? call$2(matcher, regexp, O) : new RegExp(regexp)[MATCH](toString$3(O));
11516
+ },
11517
+ // `RegExp.prototype[@@match]` method
11518
+ // https://tc39.es/ecma262/#sec-regexp.prototype-@@match
11519
+ function (string) {
11520
+ var rx = anObject(this);
11521
+ var S = toString$3(string);
11522
+ var res = maybeCallNative(nativeMatch, rx, S);
11523
+
11524
+ if (res.done) return res.value;
11525
+
11526
+ if (!rx.global) return regExpExec(rx, S);
11527
+
11528
+ var fullUnicode = rx.unicode;
11529
+ rx.lastIndex = 0;
11530
+ var A = [];
11531
+ var n = 0;
11532
+ var result;
11533
+ while ((result = regExpExec(rx, S)) !== null) {
11534
+ var matchStr = toString$3(result[0]);
11535
+ A[n] = matchStr;
11536
+ if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength$1(rx.lastIndex), fullUnicode);
11537
+ n++;
11538
+ }
11539
+ return n === 0 ? null : A;
11540
+ }
11541
+ ];
11542
+ });
11543
+
11334
11544
  var $$6 = _export;
11335
11545
  var toObject$2 = toObject$c;
11336
11546
  var lengthOfArrayLike$2 = lengthOfArrayLike$c;
@@ -13656,107 +13866,95 @@ const FullNameDobReviewControl = props => {
13656
13866
  };
13657
13867
  const GoAInputBaseFullNameDobControlReview = withJsonFormsAllOfProps(FullNameDobReviewControl);
13658
13868
 
13659
- let _$5 = t => t,
13660
- _t$6;
13661
- const PhoneGrid = styled.div(_t$6 || (_t$6 = _$5`
13662
- display: grid;
13663
- grid-template-columns: 1fr 2fr;
13664
- gap: 0.2rem;
13665
- align-items: start;
13666
- margin-bottom: var(--goa-space-l) !important;
13667
-
13668
- goa-form-item {
13669
- margin-right: 0 !important;
13670
- }
13671
- `));
13672
- const PHONE_REGEX = /^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/;
13673
- const normalizePhoneData = value => ({
13674
- type: (value == null ? void 0 : value.type) || '',
13675
- number: (value == null ? void 0 : value.number) || ''
13676
- });
13677
- const PhoneNumberWithTypeControl = props => {
13678
- const {
13679
- data,
13680
- path,
13681
- handleChange,
13682
- enabled,
13683
- visible,
13684
- required
13685
- } = props;
13686
- const [formData, setFormData] = useState(normalizePhoneData(data));
13687
- const [error, setError] = useState(undefined);
13869
+ // Encapsulates masked-input state for a GoA input: display value, mount reflection, and change/keypress handling.
13870
+ const useMaskedInput = ({
13871
+ mask,
13872
+ inPlace,
13873
+ data,
13874
+ onCommit
13875
+ }) => {
13876
+ const format = value => inPlace ? toMaskTemplate(value, mask) : formatWithPattern(value, mask);
13877
+ const initialDisplay = format(typeof data === 'string' ? data : '');
13878
+ // In-place mounts empty then sets the template so the web component reflects it (a value change forces the paint).
13879
+ const [value, setValue] = useState(inPlace ? '' : initialDisplay);
13688
13880
  useEffect(() => {
13689
- const nextData = normalizePhoneData(data);
13690
- setFormData(currentData => currentData.type === nextData.type && currentData.number === nextData.number ? currentData : nextData);
13691
- }, [data]);
13692
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
13693
- const updateFormData = updated => {
13694
- setFormData(updated);
13695
- if (updated.number && !PHONE_REGEX.test(updated.number)) {
13696
- setError('Enter a valid phone number (e.g., (780) 123-4567)');
13697
- } else {
13698
- setError(undefined);
13881
+ if (inPlace) {
13882
+ setValue(initialDisplay);
13699
13883
  }
13700
- handleChange(path, updated);
13884
+ // eslint-disable-next-line react-hooks/exhaustive-deps
13885
+ }, []);
13886
+ const handleChange = detail => {
13887
+ var _target$selectionStar;
13888
+ const rawValue = detail.value;
13889
+ if (!inPlace) {
13890
+ const stored = formatWithPattern(rawValue, mask);
13891
+ setValue(stored);
13892
+ onCommit(stored);
13893
+ return;
13894
+ }
13895
+ const target = getMaskInputTarget(detail);
13896
+ const caretIndex = (_target$selectionStar = target == null ? void 0 : target.selectionStart) != null ? _target$selectionStar : rawValue.length;
13897
+ const overflow = overflowMaskEdit(value, rawValue, caretIndex, mask);
13898
+ if (overflow) {
13899
+ applyInPlaceEdit(target, overflow);
13900
+ return;
13901
+ }
13902
+ const edit = computeMaskEdit(rawValue, caretIndex, mask);
13903
+ applyInPlaceEdit(target, edit);
13904
+ setValue(edit.display);
13905
+ onCommit(edit.stored);
13906
+ };
13907
+ // In-place has no maxLength (the template is already full length) and GoA keyPress is keyup, so restore on overflow.
13908
+ const handleKeyPress = detail => {
13909
+ var _detail$event, _target$value, _target$selectionStar2;
13910
+ if (!inPlace || !/^[A-Za-z0-9]$/.test(detail.key) || !isMaskFilled(value, mask)) {
13911
+ return;
13912
+ }
13913
+ (_detail$event = detail.event) == null || _detail$event.preventDefault();
13914
+ const target = getMaskInputTarget(detail);
13915
+ const rawValue = (_target$value = target == null ? void 0 : target.value) != null ? _target$value : value;
13916
+ const overflow = overflowMaskEdit(value, rawValue, (_target$selectionStar2 = target == null ? void 0 : target.selectionStart) != null ? _target$selectionStar2 : value.length, mask);
13917
+ if (overflow) {
13918
+ applyInPlaceEdit(target, overflow);
13919
+ }
13920
+ };
13921
+ return {
13922
+ value,
13923
+ handleChange,
13924
+ handleKeyPress
13701
13925
  };
13702
- return jsx(Visible, {
13703
- "$visible": visible,
13704
- children: jsxs(PhoneGrid, {
13705
- children: [jsx(GoabFormItem, {
13706
- label: "Phone type",
13707
- requirement: required ? 'required' : undefined,
13708
- children: jsxs(GoabDropdown, {
13709
- name: "type",
13710
- value: formData.type || '',
13711
- disabled: !enabled,
13712
- onChange: detail => updateFormData(Object.assign({}, formData, {
13713
- type: detail.value
13714
- })),
13715
- children: [jsx(GoabDropdownItem, {
13716
- value: "Mobile"
13717
- }), jsx(GoabDropdownItem, {
13718
- value: "Landline"
13719
- })]
13720
- })
13721
- }), jsx(GoabFormItem, {
13722
- label: "Phone number",
13723
- error: error,
13724
- requirement: required ? 'required' : undefined,
13725
- children: jsx(GoabInput, {
13726
- type: "tel",
13727
- name: "number",
13728
- placeholder: "(000) 000-0000",
13729
- value: formData.number || '',
13730
- disabled: !enabled,
13731
- onChange: detail => updateFormData(Object.assign({}, formData, {
13732
- number: detail.value
13733
- }))
13734
- })
13735
- })]
13736
- })
13737
- });
13738
13926
  };
13739
- const GoAPhoneNumberWithTypeControl = withJsonFormsControlProps(PhoneNumberWithTypeControl);
13740
13927
 
13741
13928
  const PhoneNumberControl = props => {
13929
+ var _uischema$options, _uischema$options2;
13742
13930
  const {
13743
13931
  data,
13744
13932
  path,
13745
13933
  schema,
13934
+ uischema,
13746
13935
  handleChange,
13747
13936
  enabled,
13748
13937
  visible,
13749
13938
  required
13750
13939
  } = props;
13940
+ // Default mask can be overridden per field via the UI schema options.
13941
+ const phoneMask = (uischema == null || (_uischema$options = uischema.options) == null ? void 0 : _uischema$options.phoneMask) || DEFAULT_PATTERNS.phone.mask;
13942
+ // When in-place, the field shows the fill-in template and edits keep the caret in place.
13943
+ const inPlace = (uischema == null || (_uischema$options2 = uischema.options) == null ? void 0 : _uischema$options2.inPlace) === true;
13751
13944
  const [error, setError] = useState('');
13752
- const handleInputChange = (name, value) => {
13753
- if (value && !PHONE_REGEX.test(value)) {
13754
- setError('Must be a valid 10-digit phone number in format (000) 000-0000');
13755
- } else {
13756
- setError('');
13945
+ const {
13946
+ value,
13947
+ handleChange: handleMaskChange,
13948
+ handleKeyPress
13949
+ } = useMaskedInput({
13950
+ mask: phoneMask,
13951
+ inPlace,
13952
+ data,
13953
+ onCommit: stored => {
13954
+ setError(stored && !DEFAULT_PATTERNS.phone.pattern.test(stored) ? DEFAULT_PATTERNS.phone.error : '');
13955
+ handleChange(path, stored);
13757
13956
  }
13758
- handleChange(path, value);
13759
- };
13957
+ });
13760
13958
  return jsx(Visible, {
13761
13959
  "$visible": visible,
13762
13960
  children: jsx(GoabFormItem, {
@@ -13770,9 +13968,11 @@ const PhoneNumberControl = props => {
13770
13968
  disabled: !enabled,
13771
13969
  "aria-label": "phone number input",
13772
13970
  testId: `phone-input-${path}`,
13773
- value: data || '',
13774
- onChange: detail => handleInputChange(detail.name, detail.value),
13775
- placeholder: "(000) 000-0000",
13971
+ value: value,
13972
+ maxLength: inPlace ? undefined : phoneMask.length,
13973
+ placeholder: inPlace ? undefined : maskPlaceholder(phoneMask),
13974
+ onChange: detail => handleMaskChange(detail),
13975
+ onKeyPress: inPlace ? detail => handleKeyPress(detail) : undefined,
13776
13976
  width: "100%"
13777
13977
  })
13778
13978
  })
@@ -13782,14 +13982,14 @@ const GoAPhoneNumberControl = withJsonFormsControlProps(PhoneNumberControl);
13782
13982
 
13783
13983
  const PhoneNumberTester = rankWith(4, and(isControl$1, schemaTypeIs('string'), formatIs('phone')));
13784
13984
 
13785
- let _$4 = t => t,
13786
- _t$5,
13985
+ let _$5 = t => t,
13986
+ _t$6,
13787
13987
  _t2$2,
13788
13988
  _t3$1,
13789
13989
  _t4$1,
13790
13990
  _t5,
13791
13991
  _t6;
13792
- const SearchBox = styled.div(_t$5 || (_t$5 = _$4`
13992
+ const SearchBox = styled.div(_t$6 || (_t$6 = _$5`
13793
13993
  position: relative;
13794
13994
 
13795
13995
  .suggestions {
@@ -13831,7 +14031,7 @@ const SearchBox = styled.div(_t$5 || (_t$5 = _$4`
13831
14031
  pointer-events: none; /* Prevent spinner from interfering with clicks */
13832
14032
  }
13833
14033
  `));
13834
- const AddressIndent = styled.div(_t2$2 || (_t2$2 = _$4`
14034
+ const AddressIndent = styled.div(_t2$2 || (_t2$2 = _$5`
13835
14035
  margin: 0 0 var(--goa-space-m) 0;
13836
14036
  text-wrap: wrap;
13837
14037
  word-break: break-word;
@@ -13839,15 +14039,15 @@ const AddressIndent = styled.div(_t2$2 || (_t2$2 = _$4`
13839
14039
  border-radius: var(--goa-border-radius-xl);
13840
14040
  padding: var(--goa-space-l);
13841
14041
  `));
13842
- const TextWrap = styled.p(_t3$1 || (_t3$1 = _$4`
14042
+ const TextWrap = styled.p(_t3$1 || (_t3$1 = _$5`
13843
14043
  text-wrap: auto;
13844
14044
  word-break: break-word;
13845
14045
  `));
13846
- const TextWrapDiv = styled.div(_t4$1 || (_t4$1 = _$4`
14046
+ const TextWrapDiv = styled.div(_t4$1 || (_t4$1 = _$5`
13847
14047
  text-wrap: auto;
13848
14048
  word-break: break-word;
13849
14049
  `));
13850
- const LabelDiv = styled.div(_t5 || (_t5 = _$4`
14050
+ const LabelDiv = styled.div(_t5 || (_t5 = _$5`
13851
14051
  color: var(--goa-color-text-default);
13852
14052
  font: var(--goa-typography-body-m);
13853
14053
  min-height: 2.625rem;
@@ -13857,7 +14057,7 @@ const LabelDiv = styled.div(_t5 || (_t5 = _$4`
13857
14057
  word-break: break-word;
13858
14058
  `));
13859
14059
  /* istanbul ignore next */
13860
- const ListItem = styled.li(_t6 || (_t6 = _$4`
14060
+ const ListItem = styled.li(_t6 || (_t6 = _$5`
13861
14061
  background-color: ${0};
13862
14062
  color: ${0};
13863
14063
  font-weight: ${0};
@@ -13894,6 +14094,88 @@ const PhoneNumberReviewControl = props => {
13894
14094
  };
13895
14095
  const GoabInputBasePhoneNumberReviewControl = withJsonFormsAllOfProps(PhoneNumberReviewControl);
13896
14096
 
14097
+ let _$4 = t => t,
14098
+ _t$5;
14099
+ const PhoneGrid = styled.div(_t$5 || (_t$5 = _$4`
14100
+ display: grid;
14101
+ grid-template-columns: 1fr 2fr;
14102
+ gap: 0.2rem;
14103
+ align-items: start;
14104
+ margin-bottom: var(--goa-space-l) !important;
14105
+
14106
+ goa-form-item {
14107
+ margin-right: 0 !important;
14108
+ }
14109
+ `));
14110
+ const PHONE_REGEX = /^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/;
14111
+ const normalizePhoneData = value => ({
14112
+ type: (value == null ? void 0 : value.type) || '',
14113
+ number: (value == null ? void 0 : value.number) || ''
14114
+ });
14115
+ const PhoneNumberWithTypeControl = props => {
14116
+ const {
14117
+ data,
14118
+ path,
14119
+ handleChange,
14120
+ enabled,
14121
+ visible,
14122
+ required
14123
+ } = props;
14124
+ const [formData, setFormData] = useState(normalizePhoneData(data));
14125
+ const [error, setError] = useState(undefined);
14126
+ useEffect(() => {
14127
+ const nextData = normalizePhoneData(data);
14128
+ setFormData(currentData => currentData.type === nextData.type && currentData.number === nextData.number ? currentData : nextData);
14129
+ }, [data]);
14130
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14131
+ const updateFormData = updated => {
14132
+ setFormData(updated);
14133
+ if (updated.number && !PHONE_REGEX.test(updated.number)) {
14134
+ setError('Enter a valid phone number (e.g., (780) 123-4567)');
14135
+ } else {
14136
+ setError(undefined);
14137
+ }
14138
+ handleChange(path, updated);
14139
+ };
14140
+ return jsx(Visible, {
14141
+ "$visible": visible,
14142
+ children: jsxs(PhoneGrid, {
14143
+ children: [jsx(GoabFormItem, {
14144
+ label: "Phone type",
14145
+ requirement: required ? 'required' : undefined,
14146
+ children: jsxs(GoabDropdown, {
14147
+ name: "type",
14148
+ value: formData.type || '',
14149
+ disabled: !enabled,
14150
+ onChange: detail => updateFormData(Object.assign({}, formData, {
14151
+ type: detail.value
14152
+ })),
14153
+ children: [jsx(GoabDropdownItem, {
14154
+ value: "Mobile"
14155
+ }), jsx(GoabDropdownItem, {
14156
+ value: "Landline"
14157
+ })]
14158
+ })
14159
+ }), jsx(GoabFormItem, {
14160
+ label: "Phone number",
14161
+ error: error,
14162
+ requirement: required ? 'required' : undefined,
14163
+ children: jsx(GoabInput, {
14164
+ type: "tel",
14165
+ name: "number",
14166
+ placeholder: "(000) 000-0000",
14167
+ value: formData.number || '',
14168
+ disabled: !enabled,
14169
+ onChange: detail => updateFormData(Object.assign({}, formData, {
14170
+ number: detail.value
14171
+ }))
14172
+ })
14173
+ })]
14174
+ })
14175
+ });
14176
+ };
14177
+ const GoAPhoneNumberWithTypeControl = withJsonFormsControlProps(PhoneNumberWithTypeControl);
14178
+
13897
14179
  const isPhoneNumberWithType = createSchemaMatchTester(['number', 'type'], true);
13898
14180
  const PhoneNumberWithTypeTester = rankWith(4, isPhoneNumberWithType);
13899
14181
 
@@ -20316,6 +20598,8 @@ const GoAErrorControlTester = rankWith(1000, (uischema, schema, context) => {
20316
20598
  });
20317
20599
  var GoAErrorControl = withJsonFormsControlProps(ErrorControl);
20318
20600
 
20601
+ // Allow empty values so incomplete fields are not treated as format errors.
20602
+ const optionalFormat = pattern => input => !input || pattern.test(input);
20319
20603
  const createDefaultAjv = (...schemas) => {
20320
20604
  const ajv = new Ajv({
20321
20605
  allErrors: true,
@@ -20329,6 +20613,9 @@ const createDefaultAjv = (...schemas) => {
20329
20613
  addErrors(ajv);
20330
20614
  addFormats(ajv);
20331
20615
  ajv.addFormat('time', /^([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/);
20616
+ Object.entries(DEFAULT_PATTERNS).forEach(([format, config]) => {
20617
+ ajv.addFormat(format, optionalFormat(config.pattern));
20618
+ });
20332
20619
  ajv.addFormat('phone', PHONE_REGEX);
20333
20620
  ajv.addFormat('computed', /^[a-zA-Z0-9._-]+$/);
20334
20621
  ajv.addFormat('file-urn', {
@@ -20680,4 +20967,4 @@ const GoARenderers = [...GoABaseRenderers, {
20680
20967
  }];
20681
20968
  const GoACells = [...InputCells];
20682
20969
 
20683
- export { ADD_DATALIST_ACTION, ADD_NO_ANONYMOUS_ACTION, ADD_REGISTER_DATA_ACTION, ADD_REGISTER_DATA_ERROR, ADD_USER_ACTION, AUTO_POPULATE_SOURCES, AddressLookUpControl, AddressLookUpControlReview, AddressLookUpTester, AddressLoopUpControlTableReview, ArrayControl, ArrayControlBase, ArrayControlReview, BooleanComponent, BooleanControl, BooleanRadioComponent, BooleanRadioControl, CategorizationPagesRendererTester, CategorizationStepperRendererTester, CheckboxGroup, ContactInformationTester, ContextProviderC, ContextProviderClass, ContextProviderFactory, ContractInfoControl, ContractInfoControlReview, EnumCheckboxControl, EnumRadioControl, EnumSelect, FileUploader, FileUploaderReview, FileUploaderTester, FormPageStepper, FormPagesView, FormStepper, FormStepperControl, FormStepperPagesControl, FormStepperReviewControl, FormStepperReviewer, FormStepperView, FullNameControl, FullNameControlReview, FullNameDobControl, FullNameDobReviewControl, FullNameDobTester, FullNameReviewControl, FullNameTester, GoAArrayControlRenderer, GoAArrayControlReviewRenderer, GoAArrayControlTester, GoABaseInputReviewComponent, GoABaseRenderers, GoABaseReviewRenderers, GoABaseTableReviewRenderers, GoABooleanControl, GoABooleanControlTester, GoABooleanRadioControl, GoABooleanRadioControlTester, GoACalculationControl, GoACalculationControlTester, GoACells, GoACheckoutGroupControlTester, GoAContractInfoControlReview, GoADateControl, GoADateControlTester, GoADateInput, GoADateTimeControl, GoADateTimeControlTester, GoADateTimeInput, GoAEmailControl, GoAEmailControlTester, GoAEmailInput, GoAEnumCheckboxGroupControl, GoAEnumControl, GoAEnumControlTester, GoAEnumRadioGroupControl, GoAInputBaseControl, GoAInputBaseFullNameControlReview, GoAInputBaseFullNameDobControlReview, GoAInputBaseReviewControl, GoAInputBaseTableReview, GoAInputBaseTableReviewControl, GoAInputDateControl, GoAInputDateTimeControl, GoAInputEmailControl, GoAInputIntegerControl, GoAInputNumberControl, GoAInputText, GoAInputTextControl, GoAInputTimeControl, GoAIntegerControl, GoAIntegerControlTester, GoAListWithDetailsControlRenderer, GoAListWithDetailsTester, GoANumberControl, GoANumberControlTester, GoANumberInput, GoAPhoneNumberControl, GoAPhoneNumberWithTypeControl, GoAPrimitiveArrayRenderer, GoAPrimitiveArrayTester, GoARadioGroupControlTester, GoARenderers, GoAReviewRenderers, GoATextControl, GoATextControlTester, GoATimeControl, GoATimeControlTester, GoATimeInput, GoInputBaseReview, GoabInputBasePhoneNumberReviewControl, GoabInputBasePhoneNumberWithTypeReviewControl, GoabInputInteger, InnerGoAInputText, JsonFormContext, JsonFormRegisterProvider, JsonFormsRegisterContext, ListWithDetailsControl, MultiLineText, MultiLineTextControl, MultiLineTextControlInput, MultiLineTextControlTester, NAVIGATION_PARAMS, OPTION_DEFINITIONS, PHONE_REGEX, PhoneGrid, PhoneNumberControl, PhoneNumberReviewControl, PhoneNumberTester, PhoneNumberWithTypeControl, PhoneNumberWithTypeReviewControl, PhoneNumberWithTypeTester, PrimitiveArrayControl, REVIEW_CHANGE_ACTION, RadioGroup, ReviewRenderContext, ReviewRenderProvider, USER_FIELD_DEFINITIONS, autoPopulatePropertiesMonaco, autoPopulateValue, categoriesAreValid, createAutoPopulateMiddleware, createDefaultAjv, enumControl, errMalformedDate, fetchRegisterConfigFromOptions$1 as fetchRegisterConfigFromOptions, formatSin, getAutoPopulateControls, getAutoPopulatedData, getByJsonPointer, getCategoryScopes, getExternalFormPath, getNavigationTargetFromParams, getNavigationTargets, hasDataInScopes, hasDataValue, isAddressLookup, isContactInformation, isFullName, isFullNameDoB, isPhoneNumberWithType, mergeAutoPopulatedData, predictiveOptionsMonaco, registerReducer, resolveRefs, toDateTimeLocalInputValue, tryResolveRefs, useRegisterUser, useReviewContext, useShowChangeButtons };
20970
+ export { ADD_DATALIST_ACTION, ADD_NO_ANONYMOUS_ACTION, ADD_REGISTER_DATA_ACTION, ADD_REGISTER_DATA_ERROR, ADD_USER_ACTION, AUTO_POPULATE_SOURCES, AddressLookUpControl, AddressLookUpControlReview, AddressLookUpTester, AddressLoopUpControlTableReview, ArrayControl, ArrayControlBase, ArrayControlReview, BooleanComponent, BooleanControl, BooleanRadioComponent, BooleanRadioControl, CategorizationPagesRendererTester, CategorizationStepperRendererTester, CheckboxGroup, ContactInformationTester, ContextProviderC, ContextProviderClass, ContextProviderFactory, ContractInfoControl, ContractInfoControlReview, EnumCheckboxControl, EnumRadioControl, EnumSelect, FileUploader, FileUploaderReview, FileUploaderTester, FormPageStepper, FormPagesView, FormStepper, FormStepperControl, FormStepperPagesControl, FormStepperReviewControl, FormStepperReviewer, FormStepperView, FullNameControl, FullNameControlReview, FullNameDobControl, FullNameDobReviewControl, FullNameDobTester, FullNameReviewControl, FullNameTester, GoAArrayControlRenderer, GoAArrayControlReviewRenderer, GoAArrayControlTester, GoABaseInputReviewComponent, GoABaseRenderers, GoABaseReviewRenderers, GoABaseTableReviewRenderers, GoABooleanControl, GoABooleanControlTester, GoABooleanRadioControl, GoABooleanRadioControlTester, GoACalculationControl, GoACalculationControlTester, GoACells, GoACheckoutGroupControlTester, GoAContractInfoControlReview, GoADateControl, GoADateControlTester, GoADateInput, GoADateTimeControl, GoADateTimeControlTester, GoADateTimeInput, GoAEmailControl, GoAEmailControlTester, GoAEmailInput, GoAEnumCheckboxGroupControl, GoAEnumControl, GoAEnumControlTester, GoAEnumRadioGroupControl, GoAInputBaseControl, GoAInputBaseFullNameControlReview, GoAInputBaseFullNameDobControlReview, GoAInputBaseReviewControl, GoAInputBaseTableReview, GoAInputBaseTableReviewControl, GoAInputDateControl, GoAInputDateTimeControl, GoAInputEmailControl, GoAInputIntegerControl, GoAInputNumberControl, GoAInputText, GoAInputTextControl, GoAInputTimeControl, GoAIntegerControl, GoAIntegerControlTester, GoAListWithDetailsControlRenderer, GoAListWithDetailsTester, GoANumberControl, GoANumberControlTester, GoANumberInput, GoAPhoneNumberControl, GoAPhoneNumberWithTypeControl, GoAPrimitiveArrayRenderer, GoAPrimitiveArrayTester, GoARadioGroupControlTester, GoARenderers, GoAReviewRenderers, GoATextControl, GoATextControlTester, GoATimeControl, GoATimeControlTester, GoATimeInput, GoInputBaseReview, GoabInputBasePhoneNumberReviewControl, GoabInputBasePhoneNumberWithTypeReviewControl, GoabInputInteger, InnerGoAInputText, JsonFormContext, JsonFormRegisterProvider, JsonFormsRegisterContext, ListWithDetailsControl, MultiLineText, MultiLineTextControl, MultiLineTextControlInput, MultiLineTextControlTester, NAVIGATION_PARAMS, OPTION_DEFINITIONS, PHONE_REGEX, PhoneGrid, PhoneNumberControl, PhoneNumberReviewControl, PhoneNumberTester, PhoneNumberWithTypeControl, PhoneNumberWithTypeReviewControl, PhoneNumberWithTypeTester, PrimitiveArrayControl, REVIEW_CHANGE_ACTION, RadioGroup, ReviewRenderContext, ReviewRenderProvider, USER_FIELD_DEFINITIONS, autoPopulatePropertiesMonaco, autoPopulateValue, categoriesAreValid, createAutoPopulateMiddleware, createDefaultAjv, enumControl, errMalformedDate, fetchRegisterConfigFromOptions$1 as fetchRegisterConfigFromOptions, getAutoPopulateControls, getAutoPopulatedData, getByJsonPointer, getCategoryScopes, getExternalFormPath, getNavigationTargetFromParams, getNavigationTargets, hasDataInScopes, hasDataValue, isAddressLookup, isContactInformation, isFullName, isFullNameDoB, isPhoneNumberWithType, mergeAutoPopulatedData, predictiveOptionsMonaco, registerReducer, resolveRefs, toDateTimeLocalInputValue, tryResolveRefs, useRegisterUser, useReviewContext, useShowChangeButtons };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "2.74.1",
3
+ "version": "2.75.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Government of Alberta - React renderers for JSON Forms based on the design system.",
6
6
  "repository": "https://github.com/GovAlta/adsp-monorepo",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": "1.0.0",
3
- "generatedAt": "2026-09-03T22:56:39.161Z",
4
- "sourceCommit": "169c6d54a69229f169a5ceae66539c141522e350",
3
+ "generatedAt": "2026-09-08T16:38:31.930Z",
4
+ "sourceCommit": "769e0871a07d4049577cd0a6f97d1dc56258481b",
5
5
  "sourcePath": "libs/jsonforms-components/src/index.ts",
6
6
  "rendererCount": 33,
7
7
  "renderers": [
@@ -4,7 +4,6 @@ import { WithInputProps } from './type';
4
4
  import { RegisterConfig } from '../../Context/register';
5
5
  export type GoAInputTextProps = CellProps & WithClassname & WithInputProps;
6
6
  export declare function fetchRegisterConfigFromOptions(options: Record<string, unknown> | undefined): RegisterConfig | undefined;
7
- export declare const formatSin: (value: string) => string;
8
7
  export declare const GoAInputText: (props: GoAInputTextProps) => JSX.Element;
9
8
  export declare const InnerGoAInputText: (props: GoAInputTextProps) => JSX.Element;
10
9
  export declare const GoATextControl: (props: ControlProps) => import("react/jsx-runtime").JSX.Element;
@@ -4,6 +4,17 @@ export interface WithInputProps {
4
4
  isVisited?: boolean;
5
5
  setIsVisited?: () => void;
6
6
  }
7
+ /**
8
+ * UI schema options recognized by the text input control.
9
+ */
10
+ export interface InputControlOptions {
11
+ /**
12
+ * Mask template applied to the value on blur, e.g. "(###) ###-####".
13
+ * '#' consumes one input character; every other character is inserted as a literal.
14
+ * Formatting only; validation is still driven by the JSON schema `pattern`.
15
+ */
16
+ formatPattern?: string;
17
+ }
7
18
  /**
8
19
  * Base event control props to handle event controls
9
20
  */
@@ -32,6 +32,10 @@ export declare const onKeyPressForTimeControl: (props: EventKeyPressControlProps
32
32
  * @param props - EventKeyPressControlProps
33
33
  */
34
34
  export declare const onKeyPressForDateControl: (props: EventKeyPressControlProps) => void;
35
+ /**
36
+ * Re-exported from ./patternForm to keep existing import paths stable.
37
+ */
38
+ export { applyFormatPattern } from './patternForm';
35
39
  /**
36
40
  * Helper function to process onBlur events for text controls.
37
41
  * @param props - EventBlurControlProps
@@ -0,0 +1,42 @@
1
+ export interface MaskPattern {
2
+ mask: string;
3
+ pattern: RegExp;
4
+ error: string;
5
+ allowedKeys?: RegExp;
6
+ }
7
+ export declare const DEFAULT_PATTERNS: Record<string, MaskPattern>;
8
+ export declare const MASK_PLACEHOLDERS: Set<string>;
9
+ export declare const MASK_CONTROL_KEYS: Set<string>;
10
+ export declare const shouldBlockKey: (key: string, allowedKeys?: RegExp) => boolean;
11
+ export declare const filterAllowedKeys: (value: string, allowedKeys?: RegExp) => string;
12
+ export declare const maskDigitCount: (mask: string) => number;
13
+ export declare const formatWithPattern: (value: string, mask: string) => string;
14
+ export declare const toMaskTemplate: (value: string, mask: string) => string;
15
+ export declare const caretAfterDigits: (display: string, digitCount: number) => number;
16
+ export interface MaskEdit {
17
+ display: string;
18
+ stored: string;
19
+ caret: number;
20
+ }
21
+ export declare const computeMaskEdit: (rawValue: string, caretIndex: number, mask: string) => MaskEdit;
22
+ export declare const isMaskFilled: (value: string, mask: string) => boolean;
23
+ export declare const maskPlaceholder: (mask: string) => string;
24
+ type MaskInputTarget = (HTMLInputElement & {
25
+ setSelectionRange?: (start: number, end: number) => void;
26
+ }) | undefined;
27
+ export declare const getMaskInputTarget: (detail: {
28
+ event?: Event;
29
+ }) => MaskInputTarget;
30
+ export declare const applyInPlaceEdit: (target: MaskInputTarget, edit: MaskEdit) => void;
31
+ export declare const overflowMaskEdit: (previousDisplay: string, rawValue: string, caretIndex: number, mask: string) => MaskEdit | undefined;
32
+ /**
33
+ * Applies a mask template to a value, e.g. mask "(###) ###-####" turns "7801234567" into "(780) 123-4567".
34
+ * '#' consumes one content character from the input; every other character is a literal inserted into the output.
35
+ * The mask's literal characters are stripped from the input first so an already formatted value re-formats cleanly.
36
+ * Returns the original value unchanged when the mask is empty or no content characters remain.
37
+ * @param value - The raw input value
38
+ * @param mask - The mask template string
39
+ * @returns The masked value
40
+ */
41
+ export declare const applyFormatPattern: (value: string, mask: string | undefined) => string;
42
+ export {};
@@ -0,0 +1,21 @@
1
+ interface MaskChangeDetail {
2
+ value: string;
3
+ event?: Event;
4
+ }
5
+ interface MaskKeyPressDetail {
6
+ key: string;
7
+ event?: Event;
8
+ }
9
+ interface UseMaskedInputOptions {
10
+ mask: string;
11
+ inPlace: boolean;
12
+ data: unknown;
13
+ onCommit: (stored: string) => void;
14
+ }
15
+ interface UseMaskedInputResult {
16
+ value: string;
17
+ handleChange: (detail: MaskChangeDetail) => void;
18
+ handleKeyPress: (detail: MaskKeyPressDetail) => void;
19
+ }
20
+ export declare const useMaskedInput: ({ mask, inPlace, data, onCommit }: UseMaskedInputOptions) => UseMaskedInputResult;
21
+ export {};