@dnb/eufemia 10.70.1 → 10.71.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/CHANGELOG.md +26 -0
- package/cjs/components/date-picker/DatePickerContext.d.ts +0 -1
- package/cjs/components/date-picker/DatePickerContext.js.map +1 -1
- package/cjs/components/date-picker/DatePickerFooter.d.ts +2 -2
- package/cjs/components/date-picker/DatePickerFooter.js.map +1 -1
- package/cjs/components/date-picker/DatePickerInput.js +25 -81
- package/cjs/components/date-picker/DatePickerInput.js.map +1 -1
- package/cjs/components/date-picker/DatePickerProvider.js +0 -2
- package/cjs/components/date-picker/DatePickerProvider.js.map +1 -1
- package/cjs/components/date-picker/hooks/useDates.d.ts +1 -12
- package/cjs/components/date-picker/hooks/useDates.js +1 -39
- package/cjs/components/date-picker/hooks/useDates.js.map +1 -1
- package/cjs/components/date-picker/hooks/useInputDates.d.ts +14 -0
- package/cjs/components/date-picker/hooks/useInputDates.js +80 -0
- package/cjs/components/date-picker/hooks/useInputDates.js.map +1 -0
- package/cjs/components/input-masked/InputMaskedHooks.js +11 -7
- package/cjs/components/input-masked/InputMaskedHooks.js.map +1 -1
- package/cjs/components/input-masked/InputMaskedUtils.d.ts +1 -1
- package/cjs/components/input-masked/InputMaskedUtils.js +2 -1
- package/cjs/components/input-masked/InputMaskedUtils.js.map +1 -1
- package/cjs/components/input-masked/text-mask/adjustCaretPosition.js +2 -2
- package/cjs/components/input-masked/text-mask/adjustCaretPosition.js.map +1 -1
- package/cjs/components/modal/ModalDocs.d.ts +2 -0
- package/cjs/components/modal/ModalDocs.js +11 -1
- package/cjs/components/modal/ModalDocs.js.map +1 -1
- package/cjs/components/tooltip/TooltipContainer.js +2 -1
- package/cjs/components/tooltip/TooltipContainer.js.map +1 -1
- package/cjs/components/upload/Upload.js +6 -3
- package/cjs/components/upload/Upload.js.map +1 -1
- package/cjs/components/upload/UploadDocs.d.ts +1 -0
- package/cjs/components/upload/UploadDocs.js +43 -1
- package/cjs/components/upload/UploadDocs.js.map +1 -1
- package/cjs/components/upload/UploadFileListCell.js +32 -12
- package/cjs/components/upload/UploadFileListCell.js.map +1 -1
- package/cjs/components/upload/types.d.ts +7 -0
- package/cjs/components/upload/types.js.map +1 -1
- package/cjs/extensions/forms/DataContext/Provider/ProviderDocs.js +1 -1
- package/cjs/extensions/forms/DataContext/Provider/ProviderDocs.js.map +1 -1
- package/cjs/extensions/forms/Field/Number/Number.js +3 -6
- package/cjs/extensions/forms/Field/Number/Number.js.map +1 -1
- package/cjs/extensions/forms/Field/PhoneNumber/PhoneNumber.d.ts +6 -4
- package/cjs/extensions/forms/Field/PhoneNumber/PhoneNumber.js +33 -25
- package/cjs/extensions/forms/Field/PhoneNumber/PhoneNumber.js.map +1 -1
- package/cjs/extensions/forms/Field/PhoneNumber/PhoneNumberDocs.d.ts +2 -2
- package/cjs/extensions/forms/Field/PhoneNumber/PhoneNumberDocs.js +8 -3
- package/cjs/extensions/forms/Field/PhoneNumber/PhoneNumberDocs.js.map +1 -1
- package/cjs/extensions/forms/Field/Provider/useFieldProvider.d.ts +3 -3
- package/cjs/extensions/forms/Field/Upload/Upload.d.ts +1 -1
- package/cjs/extensions/forms/Field/Upload/Upload.js +3 -1
- package/cjs/extensions/forms/Field/Upload/Upload.js.map +1 -1
- package/cjs/extensions/forms/FieldBlock/FieldBlock.js +11 -4
- package/cjs/extensions/forms/FieldBlock/FieldBlock.js.map +1 -1
- package/cjs/extensions/forms/FieldBlock/FieldBlockContext.d.ts +1 -1
- package/cjs/extensions/forms/FieldBlock/FieldBlockContext.js.map +1 -1
- package/cjs/extensions/forms/hooks/DataValueWritePropsDocs.js +1 -1
- package/cjs/extensions/forms/hooks/DataValueWritePropsDocs.js.map +1 -1
- package/cjs/extensions/forms/hooks/useFieldProps.js +50 -17
- package/cjs/extensions/forms/hooks/useFieldProps.js.map +1 -1
- package/cjs/extensions/forms/types.d.ts +8 -5
- package/cjs/extensions/forms/types.js.map +1 -1
- package/cjs/extensions/forms/utils/FormError.d.ts +20 -13
- package/cjs/extensions/forms/utils/FormError.js.map +1 -1
- package/cjs/shared/Eufemia.d.ts +1 -1
- package/cjs/shared/Eufemia.js +2 -2
- package/cjs/shared/Eufemia.js.map +1 -1
- package/cjs/shared/locales/en-GB.js +2 -2
- package/cjs/shared/locales/en-GB.js.map +1 -1
- package/cjs/style/core/scopes.scss +1 -1
- package/cjs/style/dnb-ui-basis.css +1 -1
- package/cjs/style/dnb-ui-basis.min.css +1 -1
- package/cjs/style/dnb-ui-body.css +1 -1
- package/cjs/style/dnb-ui-body.min.css +1 -1
- package/cjs/style/dnb-ui-core.css +1 -1
- package/cjs/style/dnb-ui-core.min.css +1 -1
- package/components/date-picker/DatePickerContext.d.ts +0 -1
- package/components/date-picker/DatePickerContext.js.map +1 -1
- package/components/date-picker/DatePickerFooter.d.ts +2 -2
- package/components/date-picker/DatePickerFooter.js.map +1 -1
- package/components/date-picker/DatePickerInput.js +25 -81
- package/components/date-picker/DatePickerInput.js.map +1 -1
- package/components/date-picker/DatePickerProvider.js +0 -2
- package/components/date-picker/DatePickerProvider.js.map +1 -1
- package/components/date-picker/hooks/useDates.d.ts +1 -12
- package/components/date-picker/hooks/useDates.js +2 -38
- package/components/date-picker/hooks/useDates.js.map +1 -1
- package/components/date-picker/hooks/useInputDates.d.ts +14 -0
- package/components/date-picker/hooks/useInputDates.js +72 -0
- package/components/date-picker/hooks/useInputDates.js.map +1 -0
- package/components/input-masked/InputMaskedHooks.js +11 -7
- package/components/input-masked/InputMaskedHooks.js.map +1 -1
- package/components/input-masked/InputMaskedUtils.d.ts +1 -1
- package/components/input-masked/InputMaskedUtils.js +2 -1
- package/components/input-masked/InputMaskedUtils.js.map +1 -1
- package/components/input-masked/text-mask/adjustCaretPosition.js +2 -2
- package/components/input-masked/text-mask/adjustCaretPosition.js.map +1 -1
- package/components/modal/ModalDocs.d.ts +2 -0
- package/components/modal/ModalDocs.js +10 -0
- package/components/modal/ModalDocs.js.map +1 -1
- package/components/tooltip/TooltipContainer.js +2 -1
- package/components/tooltip/TooltipContainer.js.map +1 -1
- package/components/upload/Upload.js +6 -3
- package/components/upload/Upload.js.map +1 -1
- package/components/upload/UploadDocs.d.ts +1 -0
- package/components/upload/UploadDocs.js +42 -0
- package/components/upload/UploadDocs.js.map +1 -1
- package/components/upload/UploadFileListCell.js +32 -12
- package/components/upload/UploadFileListCell.js.map +1 -1
- package/components/upload/types.d.ts +7 -0
- package/components/upload/types.js.map +1 -1
- package/es/components/date-picker/DatePickerContext.d.ts +0 -1
- package/es/components/date-picker/DatePickerContext.js.map +1 -1
- package/es/components/date-picker/DatePickerFooter.d.ts +2 -2
- package/es/components/date-picker/DatePickerFooter.js.map +1 -1
- package/es/components/date-picker/DatePickerInput.js +20 -75
- package/es/components/date-picker/DatePickerInput.js.map +1 -1
- package/es/components/date-picker/DatePickerProvider.js +0 -2
- package/es/components/date-picker/DatePickerProvider.js.map +1 -1
- package/es/components/date-picker/hooks/useDates.d.ts +1 -12
- package/es/components/date-picker/hooks/useDates.js +2 -38
- package/es/components/date-picker/hooks/useDates.js.map +1 -1
- package/es/components/date-picker/hooks/useInputDates.d.ts +14 -0
- package/es/components/date-picker/hooks/useInputDates.js +70 -0
- package/es/components/date-picker/hooks/useInputDates.js.map +1 -0
- package/es/components/input-masked/InputMaskedHooks.js +11 -7
- package/es/components/input-masked/InputMaskedHooks.js.map +1 -1
- package/es/components/input-masked/InputMaskedUtils.d.ts +1 -1
- package/es/components/input-masked/InputMaskedUtils.js +2 -1
- package/es/components/input-masked/InputMaskedUtils.js.map +1 -1
- package/es/components/input-masked/text-mask/adjustCaretPosition.js +2 -2
- package/es/components/input-masked/text-mask/adjustCaretPosition.js.map +1 -1
- package/es/components/modal/ModalDocs.d.ts +2 -0
- package/es/components/modal/ModalDocs.js +6 -0
- package/es/components/modal/ModalDocs.js.map +1 -1
- package/es/components/tooltip/TooltipContainer.js +2 -1
- package/es/components/tooltip/TooltipContainer.js.map +1 -1
- package/es/components/upload/Upload.js +6 -3
- package/es/components/upload/Upload.js.map +1 -1
- package/es/components/upload/UploadDocs.d.ts +1 -0
- package/es/components/upload/UploadDocs.js +42 -0
- package/es/components/upload/UploadDocs.js.map +1 -1
- package/es/components/upload/UploadFileListCell.js +32 -12
- package/es/components/upload/UploadFileListCell.js.map +1 -1
- package/es/components/upload/types.d.ts +7 -0
- package/es/components/upload/types.js.map +1 -1
- package/es/extensions/forms/DataContext/Provider/ProviderDocs.js +1 -1
- package/es/extensions/forms/DataContext/Provider/ProviderDocs.js.map +1 -1
- package/es/extensions/forms/Field/Number/Number.js +3 -6
- package/es/extensions/forms/Field/Number/Number.js.map +1 -1
- package/es/extensions/forms/Field/PhoneNumber/PhoneNumber.d.ts +6 -4
- package/es/extensions/forms/Field/PhoneNumber/PhoneNumber.js +24 -16
- package/es/extensions/forms/Field/PhoneNumber/PhoneNumber.js.map +1 -1
- package/es/extensions/forms/Field/PhoneNumber/PhoneNumberDocs.d.ts +2 -2
- package/es/extensions/forms/Field/PhoneNumber/PhoneNumberDocs.js +7 -2
- package/es/extensions/forms/Field/PhoneNumber/PhoneNumberDocs.js.map +1 -1
- package/es/extensions/forms/Field/Provider/useFieldProvider.d.ts +3 -3
- package/es/extensions/forms/Field/Upload/Upload.d.ts +1 -1
- package/es/extensions/forms/Field/Upload/Upload.js +3 -1
- package/es/extensions/forms/Field/Upload/Upload.js.map +1 -1
- package/es/extensions/forms/FieldBlock/FieldBlock.js +11 -4
- package/es/extensions/forms/FieldBlock/FieldBlock.js.map +1 -1
- package/es/extensions/forms/FieldBlock/FieldBlockContext.d.ts +1 -1
- package/es/extensions/forms/FieldBlock/FieldBlockContext.js.map +1 -1
- package/es/extensions/forms/hooks/DataValueWritePropsDocs.js +1 -1
- package/es/extensions/forms/hooks/DataValueWritePropsDocs.js.map +1 -1
- package/es/extensions/forms/hooks/useFieldProps.js +51 -18
- package/es/extensions/forms/hooks/useFieldProps.js.map +1 -1
- package/es/extensions/forms/types.d.ts +8 -5
- package/es/extensions/forms/types.js.map +1 -1
- package/es/extensions/forms/utils/FormError.d.ts +20 -13
- package/es/extensions/forms/utils/FormError.js +1 -0
- package/es/extensions/forms/utils/FormError.js.map +1 -1
- package/es/shared/Eufemia.d.ts +1 -1
- package/es/shared/Eufemia.js +2 -2
- package/es/shared/Eufemia.js.map +1 -1
- package/es/shared/locales/en-GB.js +2 -2
- package/es/shared/locales/en-GB.js.map +1 -1
- package/es/style/core/scopes.scss +1 -1
- package/es/style/dnb-ui-basis.css +1 -1
- package/es/style/dnb-ui-basis.min.css +1 -1
- package/es/style/dnb-ui-body.css +1 -1
- package/es/style/dnb-ui-body.min.css +1 -1
- package/es/style/dnb-ui-core.css +1 -1
- package/es/style/dnb-ui-core.min.css +1 -1
- package/esm/dnb-ui-basis.min.mjs +1 -1
- package/esm/dnb-ui-components.min.mjs +1 -1
- package/esm/dnb-ui-elements.min.mjs +1 -1
- package/esm/dnb-ui-extensions.min.mjs +1 -1
- package/esm/dnb-ui-lib.min.mjs +1 -1
- package/extensions/forms/DataContext/Provider/ProviderDocs.js +1 -1
- package/extensions/forms/DataContext/Provider/ProviderDocs.js.map +1 -1
- package/extensions/forms/Field/Number/Number.js +3 -6
- package/extensions/forms/Field/Number/Number.js.map +1 -1
- package/extensions/forms/Field/PhoneNumber/PhoneNumber.d.ts +6 -4
- package/extensions/forms/Field/PhoneNumber/PhoneNumber.js +33 -25
- package/extensions/forms/Field/PhoneNumber/PhoneNumber.js.map +1 -1
- package/extensions/forms/Field/PhoneNumber/PhoneNumberDocs.d.ts +2 -2
- package/extensions/forms/Field/PhoneNumber/PhoneNumberDocs.js +7 -2
- package/extensions/forms/Field/PhoneNumber/PhoneNumberDocs.js.map +1 -1
- package/extensions/forms/Field/Provider/useFieldProvider.d.ts +3 -3
- package/extensions/forms/Field/Upload/Upload.d.ts +1 -1
- package/extensions/forms/Field/Upload/Upload.js +3 -1
- package/extensions/forms/Field/Upload/Upload.js.map +1 -1
- package/extensions/forms/FieldBlock/FieldBlock.js +11 -4
- package/extensions/forms/FieldBlock/FieldBlock.js.map +1 -1
- package/extensions/forms/FieldBlock/FieldBlockContext.d.ts +1 -1
- package/extensions/forms/FieldBlock/FieldBlockContext.js.map +1 -1
- package/extensions/forms/hooks/DataValueWritePropsDocs.js +1 -1
- package/extensions/forms/hooks/DataValueWritePropsDocs.js.map +1 -1
- package/extensions/forms/hooks/useFieldProps.js +51 -18
- package/extensions/forms/hooks/useFieldProps.js.map +1 -1
- package/extensions/forms/types.d.ts +8 -5
- package/extensions/forms/types.js.map +1 -1
- package/extensions/forms/utils/FormError.d.ts +20 -13
- package/extensions/forms/utils/FormError.js.map +1 -1
- package/package.json +1 -1
- package/shared/Eufemia.d.ts +1 -1
- package/shared/Eufemia.js +2 -2
- package/shared/Eufemia.js.map +1 -1
- package/shared/locales/en-GB.js +2 -2
- package/shared/locales/en-GB.js.map +1 -1
- package/style/core/scopes.scss +1 -1
- package/style/dnb-ui-basis.css +1 -1
- package/style/dnb-ui-basis.min.css +1 -1
- package/style/dnb-ui-body.css +1 -1
- package/style/dnb-ui-body.min.css +1 -1
- package/style/dnb-ui-core.css +1 -1
- package/style/dnb-ui-core.min.css +1 -1
- package/umd/dnb-ui-basis.min.js +1 -1
- package/umd/dnb-ui-components.min.js +1 -1
- package/umd/dnb-ui-elements.min.js +1 -1
- package/umd/dnb-ui-extensions.min.js +1 -1
- package/umd/dnb-ui-lib.min.js +1 -1
- package/cjs/components/icon/lib/SvgComparison.d.ts +0 -2
- package/cjs/components/icon/lib/SvgComparison.js +0 -56
- package/cjs/components/icon/lib/SvgComparison.js.map +0 -1
- package/components/icon/lib/SvgComparison.d.ts +0 -2
- package/components/icon/lib/SvgComparison.js +0 -49
- package/components/icon/lib/SvgComparison.js.map +0 -1
- package/es/components/icon/lib/SvgComparison.d.ts +0 -2
- package/es/components/icon/lib/SvgComparison.js +0 -49
- package/es/components/icon/lib/SvgComparison.js.map +0 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
+
import { format, isValid } from 'date-fns';
|
|
7
|
+
import { useCallback, useState } from 'react';
|
|
8
|
+
export default function useInputDates({
|
|
9
|
+
startDate,
|
|
10
|
+
endDate
|
|
11
|
+
}) {
|
|
12
|
+
const [previousDates, setPreviousDates] = useState({
|
|
13
|
+
startDate,
|
|
14
|
+
endDate
|
|
15
|
+
});
|
|
16
|
+
const [inputDates, setInputDates] = useState({
|
|
17
|
+
startDay: formatInputDate('day', startDate),
|
|
18
|
+
startMonth: formatInputDate('month', startDate),
|
|
19
|
+
startYear: formatInputDate('year', startDate),
|
|
20
|
+
endDay: formatInputDate('day', endDate),
|
|
21
|
+
endMonth: formatInputDate('month', endDate),
|
|
22
|
+
endYear: formatInputDate('year', endDate)
|
|
23
|
+
});
|
|
24
|
+
const hasStartDateChange = startDate !== previousDates.startDate;
|
|
25
|
+
const hasEndDateChange = endDate !== previousDates.endDate;
|
|
26
|
+
if (hasStartDateChange || hasEndDateChange) {
|
|
27
|
+
setInputDates(currentInputDates => _objectSpread(_objectSpread(_objectSpread({}, currentInputDates), hasStartDateChange && getInputDates('start', startDate)), hasEndDateChange && getInputDates('end', endDate)));
|
|
28
|
+
setPreviousDates({
|
|
29
|
+
startDate,
|
|
30
|
+
endDate
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const updateInputDates = useCallback(dates => {
|
|
34
|
+
setInputDates(current => _objectSpread(_objectSpread({}, current), dates));
|
|
35
|
+
}, []);
|
|
36
|
+
return {
|
|
37
|
+
inputDates,
|
|
38
|
+
updateInputDates
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const inputDateFormatter = {
|
|
42
|
+
day: date => pad(format(date, 'dd'), 2),
|
|
43
|
+
month: date => pad(format(date, 'MM'), 2),
|
|
44
|
+
year: date => format(date, 'yyyy')
|
|
45
|
+
};
|
|
46
|
+
function formatInputDate(type, date) {
|
|
47
|
+
return isValid(date) ? inputDateFormatter[type](date) : null;
|
|
48
|
+
}
|
|
49
|
+
function getInputDates(type, date) {
|
|
50
|
+
if (isValid(date)) {
|
|
51
|
+
return {
|
|
52
|
+
[`${type}Day`]: formatInputDate('day', date),
|
|
53
|
+
[`${type}Month`]: formatInputDate('month', date),
|
|
54
|
+
[`${type}Year`]: formatInputDate('year', date)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (date === undefined) {
|
|
58
|
+
return {
|
|
59
|
+
[`${type}Day`]: null,
|
|
60
|
+
[`${type}Month`]: null,
|
|
61
|
+
[`${type}Year`]: null
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return {};
|
|
65
|
+
}
|
|
66
|
+
export function pad(date, size) {
|
|
67
|
+
const dateWithPadding = '000000000' + date;
|
|
68
|
+
return dateWithPadding.substring(dateWithPadding.length - size);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=useInputDates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInputDates.js","names":["format","isValid","useCallback","useState","useInputDates","startDate","endDate","previousDates","setPreviousDates","inputDates","setInputDates","startDay","formatInputDate","startMonth","startYear","endDay","endMonth","endYear","hasStartDateChange","hasEndDateChange","currentInputDates","_objectSpread","getInputDates","updateInputDates","dates","current","inputDateFormatter","day","date","pad","month","year","type","undefined","size","dateWithPadding","substring","length"],"sources":["../../../../../src/components/date-picker/hooks/useInputDates.ts"],"sourcesContent":["import { format, isValid } from 'date-fns'\nimport { DatePickerDates } from './useDates'\nimport { useCallback, useState } from 'react'\n\nexport type DatePickerInputDates = {\n startDay?: string\n startMonth?: string\n startYear?: string\n endDay?: string\n endMonth?: string\n endYear?: string\n}\n\nexport default function useInputDates({\n startDate,\n endDate,\n}: Pick<DatePickerDates, 'startDate' | 'endDate'>) {\n const [previousDates, setPreviousDates] = useState<\n Pick<DatePickerDates, 'startDate' | 'endDate'>\n >({ startDate, endDate })\n\n const [inputDates, setInputDates] = useState<DatePickerInputDates>({\n startDay: formatInputDate('day', startDate),\n startMonth: formatInputDate('month', startDate),\n startYear: formatInputDate('year', startDate),\n endDay: formatInputDate('day', endDate),\n endMonth: formatInputDate('month', endDate),\n endYear: formatInputDate('year', endDate),\n })\n\n const hasStartDateChange = startDate !== previousDates.startDate\n const hasEndDateChange = endDate !== previousDates.endDate\n\n // Update input dates if startDate or endDate changes\n if (hasStartDateChange || hasEndDateChange) {\n setInputDates((currentInputDates) => ({\n ...currentInputDates,\n ...(hasStartDateChange && getInputDates('start', startDate)),\n ...(hasEndDateChange && getInputDates('end', endDate)),\n }))\n\n setPreviousDates({ startDate, endDate })\n }\n\n const updateInputDates = useCallback((dates: DatePickerInputDates) => {\n setInputDates((current) => ({ ...current, ...dates }))\n }, [])\n\n return {\n inputDates,\n updateInputDates,\n }\n}\n\nconst inputDateFormatter = {\n day: (date: Date) => pad(format(date, 'dd'), 2),\n month: (date: Date) => pad(format(date, 'MM'), 2),\n year: (date: Date) => format(date, 'yyyy'),\n}\n\nfunction formatInputDate(type: 'day' | 'month' | 'year', date: Date) {\n return isValid(date) ? inputDateFormatter[type](date) : null\n}\n\nfunction getInputDates(type: 'start' | 'end', date: Date | undefined) {\n if (isValid(date)) {\n return {\n [`${type}Day`]: formatInputDate('day', date),\n [`${type}Month`]: formatInputDate('month', date),\n [`${type}Year`]: formatInputDate('year', date),\n }\n }\n\n if (date === undefined) {\n return {\n [`${type}Day`]: null,\n [`${type}Month`]: null,\n [`${type}Year`]: null,\n }\n }\n\n return {}\n}\n\nexport function pad(date: string, size: number) {\n const dateWithPadding = '000000000' + date\n\n return dateWithPadding.substring(dateWithPadding.length - size)\n}\n"],"mappings":";;;;;AAAA,SAASA,MAAM,EAAEC,OAAO,QAAQ,UAAU;AAE1C,SAASC,WAAW,EAAEC,QAAQ,QAAQ,OAAO;AAW7C,eAAe,SAASC,aAAaA,CAAC;EACpCC,SAAS;EACTC;AAC8C,CAAC,EAAE;EACjD,MAAM,CAACC,aAAa,EAAEC,gBAAgB,CAAC,GAAGL,QAAQ,CAEhD;IAAEE,SAAS;IAAEC;EAAQ,CAAC,CAAC;EAEzB,MAAM,CAACG,UAAU,EAAEC,aAAa,CAAC,GAAGP,QAAQ,CAAuB;IACjEQ,QAAQ,EAAEC,eAAe,CAAC,KAAK,EAAEP,SAAS,CAAC;IAC3CQ,UAAU,EAAED,eAAe,CAAC,OAAO,EAAEP,SAAS,CAAC;IAC/CS,SAAS,EAAEF,eAAe,CAAC,MAAM,EAAEP,SAAS,CAAC;IAC7CU,MAAM,EAAEH,eAAe,CAAC,KAAK,EAAEN,OAAO,CAAC;IACvCU,QAAQ,EAAEJ,eAAe,CAAC,OAAO,EAAEN,OAAO,CAAC;IAC3CW,OAAO,EAAEL,eAAe,CAAC,MAAM,EAAEN,OAAO;EAC1C,CAAC,CAAC;EAEF,MAAMY,kBAAkB,GAAGb,SAAS,KAAKE,aAAa,CAACF,SAAS;EAChE,MAAMc,gBAAgB,GAAGb,OAAO,KAAKC,aAAa,CAACD,OAAO;EAG1D,IAAIY,kBAAkB,IAAIC,gBAAgB,EAAE;IAC1CT,aAAa,CAAEU,iBAAiB,IAAAC,aAAA,CAAAA,aAAA,CAAAA,aAAA,KAC3BD,iBA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Ae,CAAC,MAAM,EAAEgB,IAAI;IAC/C,CAAC;EACH;EAEA,IAAIA,IAAI,KAAKK,SAAS,EAAE;IACtB,OAAO;MACL,CAAC,GAAGD,IAAI,KAAK,GAAG,IAAI;MACpB,CAAC,GAAGA,IAAI,OAAO,GAAG,IAAI;MACtB,CAAC,GAAGA,IAAI,MAAM,GAAG;IACnB,CAAC;EACH;EAEA,OAAO,CAAC,CAAC;AACX;AAEA,OAAO,SAASH,GAAGA,CAACD,IAAY,EAAEM,IAAY,EAAE;EAC9C,MAAMC,eAAe,GAAG,WAAW,GAAGP,IAAI;EAE1C,OAAOO,eAAe,CAACC,SAAS,CAACD,eAAe,CAACE,MAAM,GAAGH,IAAI,CAAC;AACjE","ignoreList":[]}
|
|
@@ -60,11 +60,13 @@ export const useLocalValue = () => {
|
|
|
60
60
|
} = React.useContext(InputMaskedContext);
|
|
61
61
|
const maskParams = useNumberMaskParams() || {};
|
|
62
62
|
const locale = useTranslation();
|
|
63
|
-
const [localValue, setLocalValue] = React.useState(() =>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
const [localValue, setLocalValue] = React.useState(() => {
|
|
64
|
+
return correctNumberValue({
|
|
65
|
+
locale,
|
|
66
|
+
props,
|
|
67
|
+
maskParams
|
|
68
|
+
});
|
|
69
|
+
});
|
|
68
70
|
React.useEffect(() => {
|
|
69
71
|
const value = correctNumberValue({
|
|
70
72
|
localValue,
|
|
@@ -202,10 +204,11 @@ export const useEventMapping = ({
|
|
|
202
204
|
const useCallEvent = ({
|
|
203
205
|
setLocalValue
|
|
204
206
|
}) => {
|
|
207
|
+
const maskParamsRef = React.useRef();
|
|
208
|
+
maskParamsRef.current = useMaskParams();
|
|
205
209
|
const {
|
|
206
210
|
props
|
|
207
211
|
} = React.useContext(InputMaskedContext);
|
|
208
|
-
const maskParams = useMaskParams();
|
|
209
212
|
const isNumberMask = useNumberMask();
|
|
210
213
|
const decimalSeparators = /[,.'·]/;
|
|
211
214
|
let isUnidentified = false;
|
|
@@ -213,6 +216,7 @@ const useCallEvent = ({
|
|
|
213
216
|
event,
|
|
214
217
|
value
|
|
215
218
|
}, name) => {
|
|
219
|
+
const maskParams = maskParamsRef.current;
|
|
216
220
|
value = value || event.target.value;
|
|
217
221
|
const selStart = event.target.selectionStart;
|
|
218
222
|
let keyCode = keycode(event);
|
|
@@ -278,7 +282,7 @@ const useCallEvent = ({
|
|
|
278
282
|
case 'on_key_down':
|
|
279
283
|
case 'on_mouse_down':
|
|
280
284
|
case 'on_mouse_up':
|
|
281
|
-
event.target.runCorrectCaretPosition = () => correctCaretPosition(event.target,
|
|
285
|
+
event.target.runCorrectCaretPosition = () => correctCaretPosition(event.target, maskParamsRef, props);
|
|
282
286
|
if (!event.target.__getCorrectCaretPosition) {
|
|
283
287
|
event.target.runCorrectCaretPosition();
|
|
284
288
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputMaskedHooks.js","names":["React","useCallback","classnames","cleanNumber","getCurrencySymbol","isTrue","dispatchCustomElementEvent","extendPropsWithContext","keycode","safeSetSelection","TextMask","createNumberMask","InputMaskedContext","isRequestingLocaleSupport","isRequestingNumberMask","correctNumberValue","handlePercentMask","handleCurrencyMask","handleNumberMask","correctCaretPosition","getSoftKeyboardAttributes","handleThousandsSeparator","handleDecimalSeparator","fromJSON","invisibleSpace","useLayoutEffect","window","useEffect","useFilteredProps","props","useContext","mask","number_mask","currency_mask","number_format","mask_options","as_currency","as_number","as_percent","locale","show_mask","show_guide","pipe","keep_char_positions","placeholder_char","attributes","_objectWithoutProperties","_excluded","htmlAttributes","Object","freeze","useTranslation","context","useLocalValue","maskParams","useNumberMaskParams","localValue","setLocalValue","useState","value","useNumberMask","useMask","numberMask","useMaskParams","placeholder","showMask","placeholderChar","showGuide","keepCharPositions","useInputElement","inner_ref","isFn","refHook","useRef","ref","current","inputElementRef","createElement","params","innerRef","_extends","inputRef","inputElement","guide","className","useEventMapping","callEvent","useCallEvent","onBeforeInput","event","onFocus","onBlur","onMouseUp","onMouseDown","onKeyDown","onSubmit","onChange","on_focus","undefined","on_blur","on_key_down","on_submit","on_change","isNumberMask","decimalSeparators","isUnidentified","name","target","selStart","selectionStart","keyCode","which","data","key","disallowLeadingZeroes","replace","test","testValue","slice","length","preventDefault","decimalSymbol","hasDecimalSymbol","includes","allowedDecimals","decimalLimit","allowDecimal","charAtSelection","index","indexOf","thousandsSeparatorSymbol","num","prefix","suffix","decimalSeparator","thousandsSeparator","numberValue","Number","cleanedValue","String","charAt","runCorrectCaretPosition","__getCorrectCaretPosition","result","_currency_mask","_objectSpread","currency","_currency_mask2","currencyDisplay"],"sources":["../../../../src/components/input-masked/InputMaskedHooks.js"],"sourcesContent":["/**\n * Web InputMasked Component\n *\n */\n\nimport React, { useCallback } from 'react'\nimport classnames from 'classnames'\nimport {\n cleanNumber,\n getCurrencySymbol,\n} from '../number-format/NumberUtils'\nimport {\n isTrue,\n dispatchCustomElementEvent,\n extendPropsWithContext,\n keycode,\n} from '../../shared/component-helper'\nimport { safeSetSelection } from './text-mask/createTextMaskInputElement'\n\nimport TextMask from './TextMask'\nimport createNumberMask from './addons/createNumberMask'\nimport InputMaskedContext from './InputMaskedContext'\n\nimport {\n isRequestingLocaleSupport,\n isRequestingNumberMask,\n correctNumberValue,\n handlePercentMask,\n handleCurrencyMask,\n handleNumberMask,\n correctCaretPosition,\n getSoftKeyboardAttributes,\n handleThousandsSeparator,\n handleDecimalSeparator,\n fromJSON,\n invisibleSpace,\n} from './InputMaskedUtils'\n\n// SSR warning fix: https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\nconst useLayoutEffect =\n typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect\n\n/**\n * Takes all component properties and filters out all internal used properties\n *\n * @returns object {props, htmlAttributes}\n */\nexport const useFilteredProps = () => {\n const { props } = React.useContext(InputMaskedContext)\n\n const {\n mask, // eslint-disable-line\n number_mask, // eslint-disable-line\n currency_mask, // eslint-disable-line\n number_format, // eslint-disable-line\n mask_options, // eslint-disable-line\n as_currency, // eslint-disable-line\n as_number, // eslint-disable-line\n as_percent, // eslint-disable-line\n locale, // eslint-disable-line\n show_mask, // eslint-disable-line\n show_guide, // eslint-disable-line\n pipe, // eslint-disable-line\n keep_char_positions, // eslint-disable-line\n placeholder_char, // eslint-disable-line\n\n // Get get rest of possible attributes\n ...attributes\n } = props\n\n return { props, htmlAttributes: Object.freeze(attributes) }\n}\n\n/**\n * Returns locale from either component or context\n *\n * @returns string\n */\nexport const useTranslation = () => {\n const { props, context } = React.useContext(InputMaskedContext)\n\n let { locale } = props\n if (!locale && context?.locale) {\n locale = context.locale\n }\n\n return locale\n}\n\n/**\n * Handle internal value state\n *\n * It handles both the value state given as a prop form outside,\n * along with the current written and internal value.\n *\n * @returns object with internal value state and state setter\n */\nexport const useLocalValue = () => {\n const { props, context } = React.useContext(InputMaskedContext)\n const maskParams = useNumberMaskParams() || {}\n const locale = useTranslation()\n\n const [localValue, setLocalValue] = React.useState(() =>\n correctNumberValue({\n locale,\n props,\n maskParams,\n })\n )\n\n /**\n * Use an effect here, just;\n * because when a property gets changed from outside\n */\n React.useEffect(() => {\n const value = correctNumberValue({\n localValue,\n locale,\n props,\n maskParams,\n })\n\n setLocalValue(value)\n\n // Do not set \"localValue\" and \"maskParams\" here\n }, [props, context, locale]) // eslint-disable-line\n\n return { localValue, setLocalValue }\n}\n\n/**\n * Create createNumberMask if number mask parameters exists\n *\n * @returns mask function\n */\nexport const useNumberMask = () => {\n const maskParams = useNumberMaskParams()\n const { props } = React.useContext(InputMaskedContext)\n\n if (!maskParams || !isRequestingNumberMask(props)) {\n return null\n }\n\n const mask = createNumberMask(maskParams)\n\n mask.maskParams = maskParams\n\n return mask\n}\n\n/**\n * Returns either internal mask or given property mask\n *\n * @returns mask function\n */\nexport const useMask = () => {\n const { props } = React.useContext(InputMaskedContext)\n\n const numberMask = useNumberMask()\n if (numberMask) {\n return numberMask\n }\n\n return props.mask\n}\n\n/**\n * Returns the final mask params\n *\n * @returns mask params\n */\nexport const useMaskParams = () => {\n const { props } = React.useContext(InputMaskedContext)\n\n const {\n keep_char_positions,\n show_guide,\n show_mask,\n placeholder_char,\n placeholder,\n } = props\n\n const mask = useMask()\n const maskParams = useNumberMaskParams() || {}\n\n maskParams.showMask = !placeholder && isTrue(show_mask)\n\n // Revalidated placeholder char to a zero width space\n maskParams.placeholderChar = placeholder_char\n if (typeof mask?.placeholderChar !== 'undefined') {\n maskParams.placeholderChar = mask.placeholderChar\n }\n if (maskParams.placeholderChar === null) {\n maskParams.placeholderChar = invisibleSpace\n }\n\n if (typeof mask?.showMask !== 'undefined') {\n maskParams.showMask = mask.showMask\n }\n\n maskParams.showGuide = isTrue(show_guide)\n maskParams.keepCharPositions = isTrue(keep_char_positions)\n\n return maskParams\n}\n\n/**\n * Handle the TextMask dependency\n *\n * @returns React Element\n */\nexport const useInputElement = () => {\n const { props } = React.useContext(InputMaskedContext)\n const { pipe, inner_ref } = props\n\n const mask = useMask()\n const { showMask, showGuide, placeholderChar, keepCharPositions } =\n useMaskParams()\n\n const isFn = typeof inner_ref === 'function'\n const refHook = React.useRef()\n const ref = (!isFn && inner_ref) || refHook\n\n useLayoutEffect(() => {\n if (isFn) {\n inner_ref?.(ref.current)\n }\n }, [inner_ref, isFn, ref])\n\n // Create the actual input element\n const inputElementRef = React.useRef(<input ref={ref} />)\n\n return useCallback(\n (params, innerRef) => {\n // Set ref for Eufemia input\n innerRef.current = ref.current\n\n return (\n <TextMask\n inputRef={ref}\n inputElement={inputElementRef.current}\n pipe={pipe}\n mask={mask || createNumberMask()}\n showMask={showMask}\n guide={showGuide}\n keepCharPositions={keepCharPositions}\n placeholderChar={placeholderChar}\n {...getSoftKeyboardAttributes(mask)}\n {...params}\n className={classnames(\n params.className,\n showMask &&\n showGuide &&\n placeholderChar &&\n placeholderChar !== invisibleSpace &&\n 'dnb-input-masked--guide' // will use --font-family-monospace\n )}\n />\n )\n },\n [\n keepCharPositions,\n mask,\n pipe,\n placeholderChar,\n ref,\n showGuide,\n showMask,\n ]\n )\n}\n\n/**\n * Will map some events we need to map during typing\n *\n * @param {object} param0\n * @property {function} setLocalValue setState handler\n * @returns object of events to handle\n */\nexport const useEventMapping = ({ setLocalValue }) => {\n const callEvent = useCallEvent({ setLocalValue })\n\n return {\n onBeforeInput: (event) => callEvent({ event }, 'on_before_input'),\n onFocus: (params) => callEvent(params, 'on_focus'),\n onBlur: (params) => callEvent(params, 'on_blur'),\n onMouseUp: (event) => callEvent({ event }, 'on_mouse_up'),\n onMouseDown: (event) => callEvent({ event }, 'on_mouse_down'),\n onKeyDown: (params) => callEvent(params, 'on_key_down'),\n onSubmit: (params) => callEvent(params, 'on_submit'),\n onChange: (params) => callEvent(params, 'on_change'),\n\n on_focus: undefined,\n on_blur: undefined,\n on_key_down: undefined,\n on_submit: undefined,\n on_change: undefined,\n }\n}\n\n/**\n * Will map some events we need to map during typing\n *\n * @param {object} param0\n * @property {function} setLocalValue setState handler\n * @returns event handler function\n */\nconst useCallEvent = ({ setLocalValue }) => {\n const { props } = React.useContext(InputMaskedContext)\n const maskParams = useMaskParams()\n const isNumberMask = useNumberMask()\n\n // Source: https://en.wikipedia.org/wiki/Decimal_separator\n const decimalSeparators = /[,.'·]/\n let isUnidentified = false\n\n const callEvent = ({ event, value }, name) => {\n value = value || event.target.value\n const selStart = event.target.selectionStart\n let keyCode = keycode(event)\n\n // Android issue: https://bugs.chromium.org/p/chromium/issues/detail?id=118639\n if (\n name === 'on_key_down' &&\n (event.which === 229 || keyCode === undefined)\n ) {\n isUnidentified = true\n }\n\n // Android issue: https://bugs.chromium.org/p/chromium/issues/detail?id=118639\n // so we use this solution instead\n if (\n isUnidentified &&\n name === 'on_before_input' &&\n typeof event?.data !== 'undefined'\n ) {\n name = 'on_key_down'\n keyCode = event.data\n isUnidentified = false\n }\n\n // Add support for \"await userEvent.type(input, '0...')\"\n if (isUnidentified && event.key === '0') {\n keyCode = '0'\n isUnidentified = false\n }\n\n // Prevent entering a leading zero\n if (\n name === 'on_key_down' &&\n !isUnidentified &&\n maskParams?.disallowLeadingZeroes &&\n (keyCode === '0' ||\n keyCode === 'numpad 0' ||\n (value.replace(/[^\\d]/g, '') === '' &&\n decimalSeparators.test(keyCode)))\n ) {\n const testValue = (\n value.slice(0, selStart) +\n '0' +\n value.slice(selStart + 1, value.length)\n ).replace(/[^\\d]/g, '')\n\n if (/^0/.test(testValue)) {\n event.preventDefault()\n }\n }\n\n if (\n name === 'on_key_down' &&\n isNumberMask &&\n !isUnidentified &&\n maskParams?.decimalSymbol\n ) {\n const hasDecimalSymbol = value.includes(maskParams.decimalSymbol)\n const allowedDecimals =\n maskParams.decimalLimit > 0 || maskParams.allowDecimal !== false\n\n if (!allowedDecimals && decimalSeparators.test(keyCode)) {\n event.preventDefault()\n }\n\n const charAtSelection = value.slice(selStart, selStart + 1)\n\n if (allowedDecimals) {\n // if we have already a decimal ...\n if (hasDecimalSymbol && decimalSeparators.test(keyCode)) {\n // ... we set the cursor on after the decimalSeparators\n if (decimalSeparators.test(charAtSelection)) {\n const index = value.indexOf(maskParams.decimalSymbol)\n if (index > -1) {\n safeSetSelection(event.target, index + 1)\n }\n }\n\n // ... we do not allow to type another\n event.preventDefault()\n }\n\n // replace other decimal\n else if (\n !hasDecimalSymbol &&\n keyCode !== maskParams.decimalSymbol &&\n decimalSeparators.test(keyCode)\n ) {\n value = value.slice(0, selStart)\n setLocalValue(value + maskParams.decimalSymbol)\n event.target.value = value + maskParams.decimalSymbol\n event.preventDefault()\n }\n }\n\n // move cursor to right if key is delete and char at selection is thousand separator\n if (\n keyCode === 'delete' &&\n charAtSelection === (maskParams.thousandsSeparatorSymbol || ' ')\n ) {\n safeSetSelection(event.target, selStart + 1)\n event.preventDefault()\n }\n }\n\n let num = cleanNumber(value, {\n prefix: maskParams.prefix,\n suffix: maskParams.suffix,\n decimalSeparator: maskParams.decimalSymbol || ',',\n thousandsSeparator: maskParams.thousandsSeparatorSymbol || ' ',\n })\n\n // We don't want to return NaN, so we set it to 0\n if (num === '-') {\n num = -0\n }\n\n const numberValue = Number(num)\n\n // Return '' (empty string) when the user has entered something invalid\n const cleanedValue =\n numberValue === 0 && String(num).charAt(0) !== '0' ? '' : num\n\n switch (name) {\n case 'on_focus':\n case 'on_key_down':\n case 'on_mouse_down':\n case 'on_mouse_up':\n event.target.runCorrectCaretPosition = () =>\n correctCaretPosition(event.target, maskParams, props)\n if (!event.target.__getCorrectCaretPosition) {\n event.target.runCorrectCaretPosition()\n }\n break\n }\n\n const result = dispatchCustomElementEvent(props, name, {\n event,\n value,\n numberValue,\n cleanedValue,\n })\n\n if (name === 'on_change') {\n setLocalValue(value)\n }\n\n return result\n }\n\n return callEvent\n}\n\n/**\n * Returns number mask parameters if requested by the component properties\n *\n * @returns object of number mask parameter\n */\nconst useNumberMaskParams = () => {\n const { props } = React.useContext(InputMaskedContext)\n const locale = useTranslation()\n\n if (!isRequestingNumberMask(props)) {\n return { ...fromJSON(props.mask_options) }\n }\n\n let { number_mask, currency_mask, mask_options } = props\n const { as_number, as_percent, as_currency, value } = props\n\n mask_options = fromJSON(mask_options)\n number_mask = isTrue(number_mask) ? {} : fromJSON(number_mask)\n currency_mask = isTrue(currency_mask)\n ? {}\n : fromJSON(currency_mask, {\n currency: currency_mask,\n })\n if (!currency_mask?.currency) {\n delete currency_mask.currency\n }\n\n if (isRequestingLocaleSupport(props)) {\n const thousandsSeparatorSymbol = handleThousandsSeparator(locale)\n const decimalSymbol = handleDecimalSeparator(locale)\n\n if (isTrue(as_number) || isTrue(as_percent)) {\n number_mask = extendPropsWithContext(number_mask, null, {\n decimalSymbol,\n thousandsSeparatorSymbol,\n })\n } else if (as_currency) {\n currency_mask = extendPropsWithContext(currency_mask, null, {\n decimalSymbol,\n thousandsSeparatorSymbol,\n currency: getCurrencySymbol(\n locale,\n typeof as_currency === 'string' ? as_currency : null,\n currency_mask?.currencyDisplay,\n value\n ),\n })\n }\n }\n\n let maskParams = null\n\n if (number_mask) {\n maskParams = handleNumberMask({\n mask_options,\n number_mask,\n })\n\n if (isTrue(as_percent)) {\n maskParams = handlePercentMask({ props, locale, maskParams })\n }\n } else if (currency_mask) {\n maskParams = handleCurrencyMask({\n mask_options,\n currency_mask,\n })\n }\n\n return maskParams\n}\n"],"mappings":";;;;;;AAKA,OAAOA,KAAK,IAAIC,WAAW,QAAQ,OAAO;AAC1C,OAAOC,UAAU,MAAM,YAAY;AACnC,SACEC,WAAW,EACXC,iBAAiB,QACZ,8BAA8B;AACrC,SACEC,MAAM,EACNC,0BAA0B,EAC1BC,sBAAsB,EACtBC,OAAO,QACF,+BAA+B;AACtC,SAASC,gBAAgB,QAAQ,wCAAwC;AAEzE,OAAOC,QAAQ,MAAM,YAAY;AACjC,OAAOC,gBAAgB,MAAM,2BAA2B;AACxD,OAAOC,kBAAkB,MAAM,sBAAsB;AAErD,SACEC,yBAAyB,EACzBC,sBAAsB,EACtBC,kBAAkB,EAClBC,iBAAiB,EACjBC,kBAAkB,EAClBC,gBAAgB,EAChBC,oBAAoB,EACpBC,yBAAyB,EACzBC,wBAAwB,EACxBC,sBAAsB,EACtBC,QAAQ,EACRC,cAAc,QACT,oBAAoB;AAG3B,MAAMC,eAAe,GACnB,OAAOC,MAAM,KAAK,WAAW,GAAG1B,KAAK,CAAC2B,SAAS,GAAG3B,KAAK,CAACyB,eAAe;AAOzE,OAAO,MAAMG,gBAAgB,GAAGA,CAAA,KAAM;EACpC,MAAM;IAAEC;EAAM,CAAC,GAAG7B,KAAK,CAAC8B,UAAU,CAAClB,kBAAkB,CAAC;EAEtD,MAAM;MACJmB,IAAI;MACJC,WAAW;MACXC,aAAa;MACbC,aAAa;MACbC,YAAY;MACZC,WAAW;MACXC,SAAS;MACTC,UAAU;MACVC,MAAM;MACNC,SAAS;MACTC,UAAU;MACVC,IAAI;MACJC,mBAAmB;MACnBC;IAIF,CAAC,GAAGf,KAAK;IADJgB,UAAU,GAAAC,wBAAA,CACXjB,KA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G,eAAA;MACtBlH,aAAa,GAAG1B,sBAAsB,CAAC0B,aAAa,EAAE,IAAI,EAAE;QAC1DwF,aAAa;QACbS,wBAAwB;QACxBgB,QAAQ,EAAE9I,iBAAiB,CACzBmC,MAAM,EACN,OAAOH,WAAW,KAAK,QAAQ,GAAGA,WAAW,GAAG,IAAI,GAAA+G,eAAA,GACpDlH,aAAa,cAAAkH,eAAA,uBAAbA,eAAA,CAAeC,eAAe,EAC9BzF,KACF;MACF,CAAC,CAAC;IACJ;EACF;EAEA,IAAIL,UAAU,GAAG,IAAI;EAErB,IAAItB,WAAW,EAAE;IACfsB,UAAU,GAAGpC,gBAAgB,CAAC;MAC5BiB,YAAY;MACZH;IACF,CAAC,CAAC;IAEF,IAAI3B,MAAM,CAACiC,UAAU,CAAC,EAAE;MACtBgB,UAAU,GAAGtC,iBAAiB,CAAC;QAAEa,KAAK;QAAEU,MAAM;QAAEe;MAAW,CAAC,CAAC;IAC/D;EACF,CAAC,MAAM,IAAIrB,aAAa,EAAE;IACxBqB,UAAU,GAAGrC,kBAAkB,CAAC;MAC9BkB,YAAY;MACZF;IACF,CAAC,CAAC;EACJ;EAEA,OAAOqB,UAAU;AACnB,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"InputMaskedHooks.js","names":["React","useCallback","classnames","cleanNumber","getCurrencySymbol","isTrue","dispatchCustomElementEvent","extendPropsWithContext","keycode","safeSetSelection","TextMask","createNumberMask","InputMaskedContext","isRequestingLocaleSupport","isRequestingNumberMask","correctNumberValue","handlePercentMask","handleCurrencyMask","handleNumberMask","correctCaretPosition","getSoftKeyboardAttributes","handleThousandsSeparator","handleDecimalSeparator","fromJSON","invisibleSpace","useLayoutEffect","window","useEffect","useFilteredProps","props","useContext","mask","number_mask","currency_mask","number_format","mask_options","as_currency","as_number","as_percent","locale","show_mask","show_guide","pipe","keep_char_positions","placeholder_char","attributes","_objectWithoutProperties","_excluded","htmlAttributes","Object","freeze","useTranslation","context","useLocalValue","maskParams","useNumberMaskParams","localValue","setLocalValue","useState","value","useNumberMask","useMask","numberMask","useMaskParams","placeholder","showMask","placeholderChar","showGuide","keepCharPositions","useInputElement","inner_ref","isFn","refHook","useRef","ref","current","inputElementRef","createElement","params","innerRef","_extends","inputRef","inputElement","guide","className","useEventMapping","callEvent","useCallEvent","onBeforeInput","event","onFocus","onBlur","onMouseUp","onMouseDown","onKeyDown","onSubmit","onChange","on_focus","undefined","on_blur","on_key_down","on_submit","on_change","maskParamsRef","isNumberMask","decimalSeparators","isUnidentified","name","target","selStart","selectionStart","keyCode","which","data","key","disallowLeadingZeroes","replace","test","testValue","slice","length","preventDefault","decimalSymbol","hasDecimalSymbol","includes","allowedDecimals","decimalLimit","allowDecimal","charAtSelection","index","indexOf","thousandsSeparatorSymbol","num","prefix","suffix","decimalSeparator","thousandsSeparator","numberValue","Number","cleanedValue","String","charAt","runCorrectCaretPosition","__getCorrectCaretPosition","result","_currency_mask","_objectSpread","currency","_currency_mask2","currencyDisplay"],"sources":["../../../../src/components/input-masked/InputMaskedHooks.js"],"sourcesContent":["/**\n * Web InputMasked Component\n *\n */\n\nimport React, { useCallback } from 'react'\nimport classnames from 'classnames'\nimport {\n cleanNumber,\n getCurrencySymbol,\n} from '../number-format/NumberUtils'\nimport {\n isTrue,\n dispatchCustomElementEvent,\n extendPropsWithContext,\n keycode,\n} from '../../shared/component-helper'\nimport { safeSetSelection } from './text-mask/createTextMaskInputElement'\n\nimport TextMask from './TextMask'\nimport createNumberMask from './addons/createNumberMask'\nimport InputMaskedContext from './InputMaskedContext'\n\nimport {\n isRequestingLocaleSupport,\n isRequestingNumberMask,\n correctNumberValue,\n handlePercentMask,\n handleCurrencyMask,\n handleNumberMask,\n correctCaretPosition,\n getSoftKeyboardAttributes,\n handleThousandsSeparator,\n handleDecimalSeparator,\n fromJSON,\n invisibleSpace,\n} from './InputMaskedUtils'\n\n// SSR warning fix: https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\nconst useLayoutEffect =\n typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect\n\n/**\n * Takes all component properties and filters out all internal used properties\n *\n * @returns object {props, htmlAttributes}\n */\nexport const useFilteredProps = () => {\n const { props } = React.useContext(InputMaskedContext)\n\n const {\n mask, // eslint-disable-line\n number_mask, // eslint-disable-line\n currency_mask, // eslint-disable-line\n number_format, // eslint-disable-line\n mask_options, // eslint-disable-line\n as_currency, // eslint-disable-line\n as_number, // eslint-disable-line\n as_percent, // eslint-disable-line\n locale, // eslint-disable-line\n show_mask, // eslint-disable-line\n show_guide, // eslint-disable-line\n pipe, // eslint-disable-line\n keep_char_positions, // eslint-disable-line\n placeholder_char, // eslint-disable-line\n\n // Get get rest of possible attributes\n ...attributes\n } = props\n\n return { props, htmlAttributes: Object.freeze(attributes) }\n}\n\n/**\n * Returns locale from either component or context\n *\n * @returns string\n */\nexport const useTranslation = () => {\n const { props, context } = React.useContext(InputMaskedContext)\n\n let { locale } = props\n if (!locale && context?.locale) {\n locale = context.locale\n }\n\n return locale\n}\n\n/**\n * Handle internal value state\n *\n * It handles both the value state given as a prop form outside,\n * along with the current written and internal value.\n *\n * @returns object with internal value state and state setter\n */\nexport const useLocalValue = () => {\n const { props, context } = React.useContext(InputMaskedContext)\n const maskParams = useNumberMaskParams() || {}\n const locale = useTranslation()\n\n const [localValue, setLocalValue] = React.useState(() => {\n return correctNumberValue({\n locale,\n props,\n maskParams,\n })\n })\n\n /**\n * Use an effect here, just;\n * because when a property gets changed from outside\n */\n React.useEffect(() => {\n const value = correctNumberValue({\n localValue,\n locale,\n props,\n maskParams,\n })\n\n setLocalValue(value)\n\n // Do not set \"localValue\" and \"maskParams\" here\n }, [props, context, locale]) // eslint-disable-line\n\n return { localValue, setLocalValue }\n}\n\n/**\n * Create createNumberMask if number mask parameters exists\n *\n * @returns mask function\n */\nexport const useNumberMask = () => {\n const maskParams = useNumberMaskParams()\n const { props } = React.useContext(InputMaskedContext)\n\n if (!maskParams || !isRequestingNumberMask(props)) {\n return null\n }\n\n const mask = createNumberMask(maskParams)\n\n mask.maskParams = maskParams\n\n return mask\n}\n\n/**\n * Returns either internal mask or given property mask\n *\n * @returns mask function\n */\nexport const useMask = () => {\n const { props } = React.useContext(InputMaskedContext)\n\n const numberMask = useNumberMask()\n if (numberMask) {\n return numberMask\n }\n\n return props.mask\n}\n\n/**\n * Returns the final mask params\n *\n * @returns mask params\n */\nexport const useMaskParams = () => {\n const { props } = React.useContext(InputMaskedContext)\n\n const {\n keep_char_positions,\n show_guide,\n show_mask,\n placeholder_char,\n placeholder,\n } = props\n\n const mask = useMask()\n const maskParams = useNumberMaskParams() || {}\n\n maskParams.showMask = !placeholder && isTrue(show_mask)\n\n // Revalidated placeholder char to a zero width space\n maskParams.placeholderChar = placeholder_char\n if (typeof mask?.placeholderChar !== 'undefined') {\n maskParams.placeholderChar = mask.placeholderChar\n }\n if (maskParams.placeholderChar === null) {\n maskParams.placeholderChar = invisibleSpace\n }\n\n if (typeof mask?.showMask !== 'undefined') {\n maskParams.showMask = mask.showMask\n }\n\n maskParams.showGuide = isTrue(show_guide)\n maskParams.keepCharPositions = isTrue(keep_char_positions)\n\n return maskParams\n}\n\n/**\n * Handle the TextMask dependency\n *\n * @returns React Element\n */\nexport const useInputElement = () => {\n const { props } = React.useContext(InputMaskedContext)\n const { pipe, inner_ref } = props\n\n const mask = useMask()\n const { showMask, showGuide, placeholderChar, keepCharPositions } =\n useMaskParams()\n\n const isFn = typeof inner_ref === 'function'\n const refHook = React.useRef()\n const ref = (!isFn && inner_ref) || refHook\n\n useLayoutEffect(() => {\n if (isFn) {\n inner_ref?.(ref.current)\n }\n }, [inner_ref, isFn, ref])\n\n // Create the actual input element\n const inputElementRef = React.useRef(<input ref={ref} />)\n\n return useCallback(\n (params, innerRef) => {\n // Set ref for Eufemia input\n innerRef.current = ref.current\n\n return (\n <TextMask\n inputRef={ref}\n inputElement={inputElementRef.current}\n pipe={pipe}\n mask={mask || createNumberMask()}\n showMask={showMask}\n guide={showGuide}\n keepCharPositions={keepCharPositions}\n placeholderChar={placeholderChar}\n {...getSoftKeyboardAttributes(mask)}\n {...params}\n className={classnames(\n params.className,\n showMask &&\n showGuide &&\n placeholderChar &&\n placeholderChar !== invisibleSpace &&\n 'dnb-input-masked--guide' // will use --font-family-monospace\n )}\n />\n )\n },\n [\n keepCharPositions,\n mask,\n pipe,\n placeholderChar,\n ref,\n showGuide,\n showMask,\n ]\n )\n}\n\n/**\n * Will map some events we need to map during typing\n *\n * @param {object} param0\n * @property {function} setLocalValue setState handler\n * @returns object of events to handle\n */\nexport const useEventMapping = ({ setLocalValue }) => {\n const callEvent = useCallEvent({ setLocalValue })\n\n return {\n onBeforeInput: (event) => callEvent({ event }, 'on_before_input'),\n onFocus: (params) => callEvent(params, 'on_focus'),\n onBlur: (params) => callEvent(params, 'on_blur'),\n onMouseUp: (event) => callEvent({ event }, 'on_mouse_up'),\n onMouseDown: (event) => callEvent({ event }, 'on_mouse_down'),\n onKeyDown: (params) => callEvent(params, 'on_key_down'),\n onSubmit: (params) => callEvent(params, 'on_submit'),\n onChange: (params) => callEvent(params, 'on_change'),\n\n on_focus: undefined,\n on_blur: undefined,\n on_key_down: undefined,\n on_submit: undefined,\n on_change: undefined,\n }\n}\n\n/**\n * Will map some events we need to map during typing\n *\n * @param {object} param0\n * @property {function} setLocalValue setState handler\n * @returns event handler function\n */\nconst useCallEvent = ({ setLocalValue }) => {\n const maskParamsRef = React.useRef()\n maskParamsRef.current = useMaskParams()\n\n const { props } = React.useContext(InputMaskedContext)\n const isNumberMask = useNumberMask()\n\n // Source: https://en.wikipedia.org/wiki/Decimal_separator\n const decimalSeparators = /[,.'·]/\n let isUnidentified = false\n\n const callEvent = ({ event, value }, name) => {\n const maskParams = maskParamsRef.current\n value = value || event.target.value\n const selStart = event.target.selectionStart\n let keyCode = keycode(event)\n\n // Android issue: https://bugs.chromium.org/p/chromium/issues/detail?id=118639\n if (\n name === 'on_key_down' &&\n (event.which === 229 || keyCode === undefined)\n ) {\n isUnidentified = true\n }\n\n // Android issue: https://bugs.chromium.org/p/chromium/issues/detail?id=118639\n // so we use this solution instead\n if (\n isUnidentified &&\n name === 'on_before_input' &&\n typeof event?.data !== 'undefined'\n ) {\n name = 'on_key_down'\n keyCode = event.data\n isUnidentified = false\n }\n\n // Add support for \"await userEvent.type(input, '0...')\"\n if (isUnidentified && event.key === '0') {\n keyCode = '0'\n isUnidentified = false\n }\n\n // Prevent entering a leading zero\n if (\n name === 'on_key_down' &&\n !isUnidentified &&\n maskParams?.disallowLeadingZeroes &&\n (keyCode === '0' ||\n keyCode === 'numpad 0' ||\n (value.replace(/[^\\d]/g, '') === '' &&\n decimalSeparators.test(keyCode)))\n ) {\n const testValue = (\n value.slice(0, selStart) +\n '0' +\n value.slice(selStart + 1, value.length)\n ).replace(/[^\\d]/g, '')\n\n if (/^0/.test(testValue)) {\n event.preventDefault()\n }\n }\n\n if (\n name === 'on_key_down' &&\n isNumberMask &&\n !isUnidentified &&\n maskParams?.decimalSymbol\n ) {\n const hasDecimalSymbol = value.includes(maskParams.decimalSymbol)\n const allowedDecimals =\n maskParams.decimalLimit > 0 || maskParams.allowDecimal !== false\n\n if (!allowedDecimals && decimalSeparators.test(keyCode)) {\n event.preventDefault()\n }\n\n const charAtSelection = value.slice(selStart, selStart + 1)\n\n if (allowedDecimals) {\n // if we have already a decimal ...\n if (hasDecimalSymbol && decimalSeparators.test(keyCode)) {\n // ... we set the cursor on after the decimalSeparators\n if (decimalSeparators.test(charAtSelection)) {\n const index = value.indexOf(maskParams.decimalSymbol)\n if (index > -1) {\n safeSetSelection(event.target, index + 1)\n }\n }\n\n // ... we do not allow to type another\n event.preventDefault()\n }\n\n // replace other decimal\n else if (\n !hasDecimalSymbol &&\n keyCode !== maskParams.decimalSymbol &&\n decimalSeparators.test(keyCode)\n ) {\n value = value.slice(0, selStart)\n setLocalValue(value + maskParams.decimalSymbol)\n event.target.value = value + maskParams.decimalSymbol\n event.preventDefault()\n }\n }\n\n // move cursor to right if key is delete and char at selection is thousand separator\n if (\n keyCode === 'delete' &&\n charAtSelection === (maskParams.thousandsSeparatorSymbol || ' ')\n ) {\n safeSetSelection(event.target, selStart + 1)\n event.preventDefault()\n }\n }\n\n let num = cleanNumber(value, {\n prefix: maskParams.prefix,\n suffix: maskParams.suffix,\n decimalSeparator: maskParams.decimalSymbol || ',',\n thousandsSeparator: maskParams.thousandsSeparatorSymbol || ' ',\n })\n\n // We don't want to return NaN, so we set it to 0\n if (num === '-') {\n num = -0\n }\n\n const numberValue = Number(num)\n\n // Return '' (empty string) when the user has entered something invalid\n const cleanedValue =\n numberValue === 0 && String(num).charAt(0) !== '0' ? '' : num\n\n switch (name) {\n case 'on_focus':\n case 'on_key_down':\n case 'on_mouse_down':\n case 'on_mouse_up':\n event.target.runCorrectCaretPosition = () =>\n correctCaretPosition(event.target, maskParamsRef, props)\n if (!event.target.__getCorrectCaretPosition) {\n event.target.runCorrectCaretPosition()\n }\n break\n }\n\n const result = dispatchCustomElementEvent(props, name, {\n event,\n value,\n numberValue,\n cleanedValue,\n })\n\n if (name === 'on_change') {\n setLocalValue(value)\n }\n\n return result\n }\n\n return callEvent\n}\n\n/**\n * Returns number mask parameters if requested by the component properties\n *\n * @returns object of number mask parameter\n */\nconst useNumberMaskParams = () => {\n const { props } = React.useContext(InputMaskedContext)\n const locale = useTranslation()\n\n if (!isRequestingNumberMask(props)) {\n return { ...fromJSON(props.mask_options) }\n }\n\n let { number_mask, currency_mask, mask_options } = props\n const { as_number, as_percent, as_currency, value } = props\n\n mask_options = fromJSON(mask_options)\n number_mask = isTrue(number_mask) ? {} : fromJSON(number_mask)\n currency_mask = isTrue(currency_mask)\n ? {}\n : fromJSON(currency_mask, {\n currency: currency_mask,\n })\n if (!currency_mask?.currency) {\n delete currency_mask.currency\n }\n\n if (isRequestingLocaleSupport(props)) {\n const thousandsSeparatorSymbol = handleThousandsSeparator(locale)\n const decimalSymbol = handleDecimalSeparator(locale)\n\n if (isTrue(as_number) || isTrue(as_percent)) {\n number_mask = extendPropsWithContext(number_mask, null, {\n decimalSymbol,\n thousandsSeparatorSymbol,\n })\n } else if (as_currency) {\n currency_mask = extendPropsWithContext(currency_mask, null, {\n decimalSymbol,\n thousandsSeparatorSymbol,\n currency: getCurrencySymbol(\n locale,\n typeof as_currency === 'string' ? as_currency : null,\n currency_mask?.currencyDisplay,\n value\n ),\n })\n }\n }\n\n let maskParams = null\n\n if (number_mask) {\n maskParams = handleNumberMask({\n mask_options,\n number_mask,\n })\n\n if (isTrue(as_percent)) {\n maskParams = handlePercentMask({ props, locale, maskParams })\n }\n } else if (currency_mask) {\n maskParams = handleCurrencyMask({\n mask_options,\n currency_mask,\n })\n }\n\n return maskParams\n}\n"],"mappings":";;;;;;AAKA,OAAOA,KAAK,IAAIC,WAAW,QAAQ,OAAO;AAC1C,OAAOC,UAAU,MAAM,YAAY;AACnC,SACEC,WAAW,EACXC,iBAAiB,QACZ,8BAA8B;AACrC,SACEC,MAAM,EACNC,0BAA0B,EAC1BC,sBAAsB,EACtBC,OAAO,QACF,+BAA+B;AACtC,SAASC,gBAAgB,QAAQ,wCAAwC;AAEzE,OAAOC,QAAQ,MAAM,YAAY;AACjC,OAAOC,gBAAgB,MAAM,2BAA2B;AACxD,OAAOC,kBAAkB,MAAM,sBAAsB;AAErD,SACEC,yBAAyB,EACzBC,sBAAsB,EACtBC,kBAAkB,EAClBC,iBAAiB,EACjBC,kBAAkB,EAClBC,gBAAgB,EAChBC,oBAAoB,EACpBC,yBAAyB,EACzBC,wBAAwB,EACxBC,sBAAsB,EACtBC,QAAQ,EACRC,cAAc,QACT,oBAAoB;AAG3B,MAAMC,eAAe,GACnB,OAAOC,MAAM,KAAK,WAAW,GAAG1B,KAAK,CAAC2B,SAAS,GAAG3B,KAAK,CAACyB,eAAe;AAOzE,OAAO,MAAMG,gBAAgB,GAAGA,CAAA,KAAM;EACpC,MAAM;IAAEC;EAAM,CAAC,GAAG7B,KAAK,CAAC8B,UAAU,CAAClB,kBAAk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,yBAAyB,CAACgB,KAAK,CAAC,EAAE;IACpC,MAAMsG,wBAAwB,GAAG9G,wBAAwB,CAACkB,MAAM,CAAC;IACjE,MAAMmF,aAAa,GAAGpG,sBAAsB,CAACiB,MAAM,CAAC;IAEpD,IAAIlC,MAAM,CAACgC,SAAS,CAAC,IAAIhC,MAAM,CAACiC,UAAU,CAAC,EAAE;MAC3CN,WAAW,GAAGzB,sBAAsB,CAACyB,WAAW,EAAE,IAAI,EAAE;QACtD0F,aAAa;QACbS;MACF,CAAC,CAAC;IACJ,CAAC,MAAM,IAAI/F,WAAW,EAAE;MAAA,IAAAgH,eAAA;MACtBnH,aAAa,GAAG1B,sBAAsB,CAAC0B,aAAa,EAAE,IAAI,EAAE;QAC1DyF,aAAa;QACbS,wBAAwB;QACxBgB,QAAQ,EAAE/I,iBAAiB,CACzBmC,MAAM,EACN,OAAOH,WAAW,KAAK,QAAQ,GAAGA,WAAW,GAAG,IAAI,GAAAgH,eAAA,GACpDnH,aAAa,cAAAmH,eAAA,uBAAbA,eAAA,CAAeC,eAAe,EAC9B1F,KACF;MACF,CAAC,CAAC;IACJ;EACF;EAEA,IAAIL,UAAU,GAAG,IAAI;EAErB,IAAItB,WAAW,EAAE;IACfsB,UAAU,GAAGpC,gBAAgB,CAAC;MAC5BiB,YAAY;MACZH;IACF,CAAC,CAAC;IAEF,IAAI3B,MAAM,CAACiC,UAAU,CAAC,EAAE;MACtBgB,UAAU,GAAGtC,iBAAiB,CAAC;QAAEa,KAAK;QAAEU,MAAM;QAAEe;MAAW,CAAC,CAAC;IAC/D;EACF,CAAC,MAAM,IAAIrB,aAAa,EAAE;IACxBqB,UAAU,GAAGrC,kBAAkB,CAAC;MAC9BkB,YAAY;MACZF;IACF,CAAC,CAAC;EACJ;EAEA,OAAOqB,UAAU;AACnB,CAAC","ignoreList":[]}
|
|
@@ -33,7 +33,7 @@ export const invisibleSpace: "";
|
|
|
33
33
|
export function isRequestingLocaleSupport(props: object): boolean;
|
|
34
34
|
export function isRequestingNumberMask(props: object): boolean;
|
|
35
35
|
export function correctNumberValue({ localValue, props, locale, maskParams, }: object): string;
|
|
36
|
-
export function correctCaretPosition(element: Element,
|
|
36
|
+
export function correctCaretPosition(element: Element, maskParamsRef: any, props: any): void;
|
|
37
37
|
export function handlePercentMask({ props, locale, maskParams }: object): any;
|
|
38
38
|
export function handleCurrencyMask({ mask_options, currency_mask }: object): any;
|
|
39
39
|
export function handleNumberMask({ mask_options, number_mask }: object): any;
|
|
@@ -76,9 +76,10 @@ export const correctNumberValue = ({
|
|
|
76
76
|
}
|
|
77
77
|
return value;
|
|
78
78
|
};
|
|
79
|
-
export const correctCaretPosition = (element,
|
|
79
|
+
export const correctCaretPosition = (element, maskParamsRef, props) => {
|
|
80
80
|
const correction = () => {
|
|
81
81
|
try {
|
|
82
|
+
const maskParams = maskParamsRef === null || maskParamsRef === void 0 ? void 0 : maskParamsRef.current;
|
|
82
83
|
const suffix = maskParams === null || maskParams === void 0 ? void 0 : maskParams.suffix;
|
|
83
84
|
const prefix = maskParams === null || maskParams === void 0 ? void 0 : maskParams.prefix;
|
|
84
85
|
const start = element.selectionStart;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputMaskedUtils.js","names":["format","getDecimalSeparator","getThousandsSeparator","warn","IS_IOS","safeSetSelection","enableLocaleSupportWhen","enableNumberMaskWhen","invisibleSpace","isRequestingLocaleSupport","props","Object","entries","some","k","v","includes","isRequestingNumberMask","correctNumberValue","localValue","locale","maskParams","value","undefined","String","isNaN","parseFloat","decimalPos","indexOf","integerLimit","limit","integers","split","isNegative","length","decimals","slice","shouldHaveDecimals","allowDecimal","decimalLimit","number_format","options","_objectSpread","decimalSymbol","replace","localNumberValue","numberValue","valueHasDecimal","endsWithDecimal","endsWith","endsWithZeroAndDecimal","startsWith","test","correctCaretPosition","element","correction","suffix","prefix","start","selectionStart","end","selectionEnd","suffixStart","suffixEnd","pos","placeholderChar","prefixStart","prefixEnd","char","mask","chars","l","i","RegExp","n","_mask$test","call","e","window","requestAnimationFrame","handlePercentMask","_String","_String$match","percent","match","handleCurrencyMask","mask_options","currency_mask","givenParams","paramsWithDefaults","showMask","currency","handleNumberMask","number_mask","getSoftKeyboardAttributes","instanceOf","allowNegative","inputMode","handleThousandsSeparator","handleDecimalSeparator","fromJSON","str","fallback","JSON","parse"],"sources":["../../../../src/components/input-masked/InputMaskedUtils.js"],"sourcesContent":["/**\n * Web InputMasked Component\n *\n */\n\nimport {\n format,\n getDecimalSeparator,\n getThousandsSeparator,\n} from '../number-format/NumberUtils'\nimport { warn } from '../../shared/component-helper'\nimport { IS_IOS } from '../../shared/helpers'\nimport { safeSetSelection } from './text-mask/createTextMaskInputElement'\n\nconst enableLocaleSupportWhen = ['as_number', 'as_percent', 'as_currency']\nconst enableNumberMaskWhen = [\n 'as_number',\n 'as_percent',\n 'as_currency',\n 'number_mask',\n 'currency_mask',\n]\n\nexport const invisibleSpace = '\\u200B'\n\n/**\n * Will return true if a prop needs Locale support\n *\n * @param {object} props object with given component props\n * @returns boolean\n */\nexport const isRequestingLocaleSupport = (props) => {\n return Object.entries(props).some(\n ([k, v]) => v && enableLocaleSupportWhen.includes(k)\n )\n}\n\n/**\n * Will return true if a prop will enable the internal NumberMask\n *\n * @param {object} props object with given component props\n * @returns boolean\n */\nexport const isRequestingNumberMask = (props) => {\n return Object.entries(props).some(\n ([k, v]) => v && enableNumberMaskWhen.includes(k)\n )\n}\n\n/**\n * Probably the most complex part of this component\n * It will modify a given value based on certain criteria's\n *\n * @param {object} param0 object with properties\n * @property {string} localValue optional – if given, it will uses its ending to determine of what to return\n * @property {number|string} value component property value\n * @property {object} context Eufemia Context\n * @property {string} locale Eufemia locale (either from component or context)\n * @property {object} maskParams predefined mask parameters\n * @returns string Value\n */\nexport const correctNumberValue = ({\n localValue = null,\n props,\n locale,\n maskParams,\n}) => {\n let value =\n props.value === null\n ? null\n : props.value === undefined\n ? undefined\n : String(props.value)\n\n if (isNaN(parseFloat(value))) {\n return value\n }\n\n const decimalPos = value.indexOf('.')\n\n if (\n maskParams.integerLimit &&\n typeof maskParams.integerLimit === 'number'\n ) {\n const limit = maskParams.integerLimit\n const integers = value.split('.')[0]\n const isNegative = parseFloat(integers) < 0\n if (integers.length - (isNegative ? 1 : 0) > limit) {\n const decimals = decimalPos > 0 ? value.slice(decimalPos) : ''\n value = integers.slice(0, limit + (isNegative ? 1 : 0)) + decimals\n }\n }\n\n const shouldHaveDecimals =\n maskParams.allowDecimal ||\n (maskParams.decimalLimit > 0 && maskParams.allowDecimal !== false)\n\n if (!shouldHaveDecimals) {\n if (decimalPos > -1) {\n value = value.slice(0, decimalPos)\n }\n }\n\n /**\n * This only runs IF \"number_format\" is set – we do not use it else\n */\n if (props.number_format) {\n const options = {\n locale,\n decimals: 0,\n ...props.number_format,\n }\n if (shouldHaveDecimals) {\n options.decimals = maskParams.decimalLimit\n }\n value = format(value, options)\n }\n\n const decimalSymbol = maskParams.decimalSymbol\n value = value.replace('.', decimalSymbol)\n\n if (localValue !== null) {\n const localNumberValue = localValue.replace(/[^\\d,.-]/g, '')\n const numberValue = value.replace(/[^\\d,.-]/g, '')\n const valueHasDecimal = numberValue.includes(decimalSymbol)\n\n if (!valueHasDecimal) {\n const endsWithDecimal = localNumberValue.endsWith(decimalSymbol)\n const endsWithZeroAndDecimal = localNumberValue.endsWith(\n `${decimalSymbol}0`\n )\n\n if (endsWithDecimal) {\n value = `${value}${decimalSymbol}`\n } else if (\n endsWithZeroAndDecimal &&\n !numberValue.endsWith(`${decimalSymbol}0`)\n ) {\n /**\n * When the users has 20,02, then hits \"backspace\",\n * the returned {numberValue} in the onChange event would then be \"20\",\n * but we want it to be 20,0\n */\n value = `${value}${decimalSymbol}0`\n }\n }\n\n /**\n * If the user removes a leading digit and we have left a leading zero.\n *\n * The users enters these steps:\n * Step 1. 1012\n * Step 2. 012 -> user removes 1, now use \"localValue\"\n * Step 3. 2012\n *\n * If a dev listens on_change and sends the number value back in,\n * for this, we also ensure that \"numberValue\" and \"localNumberValue\" is the same.\n */\n if (\n localNumberValue !== '0' &&\n localNumberValue.startsWith('0') &&\n parseFloat(numberValue.replace(decimalSymbol, '.')) ===\n parseFloat(localNumberValue.replace(decimalSymbol, '.'))\n ) {\n value = localValue\n }\n\n /**\n * While typing;\n * If the local value is - or -0 we use it.\n * Also, because of invisible whitespace we remove everything else\n */\n if (/^(-|-0)$/.test(localValue.replace(/[^\\d-0]/g, ''))) {\n value = localValue\n } else if (localNumberValue === '' && numberValue === '0') {\n value = ''\n }\n }\n\n return value\n}\n\n/**\n * This is a helper for setting the cursor position,\n * when it is on a not allowed position\n *\n * @param {Element} element Input Element\n * @param {Object} maskParams Mask parameters, containing eventually suffix or prefix\n */\nexport const correctCaretPosition = (element, maskParams, props) => {\n const correction = () => {\n try {\n const suffix = maskParams?.suffix\n const prefix = maskParams?.prefix\n\n const start = element.selectionStart\n const end = element.selectionEnd\n\n if (start !== end) {\n return // stop here\n }\n\n if (suffix || prefix) {\n const suffixStart = element.value.indexOf(suffix)\n const suffixEnd = suffixStart + suffix?.length\n let pos = undefined\n\n if (start >= suffixStart && start <= suffixEnd) {\n pos = suffixStart\n\n // If there is a placeholder,\n // and the user clicks after the suffix\n // we want the position to be \"before\" the placeholderChar\n if (\n maskParams.placeholderChar !== invisibleSpace &&\n element.value.length - 1 === String(suffix + prefix).length\n ) {\n pos = pos - 1\n }\n } else {\n const prefixStart = element.value.indexOf(prefix)\n const prefixEnd = prefixStart + prefix?.length || 0\n\n if (start >= prefixStart && start <= prefixEnd) {\n pos = prefixEnd\n }\n }\n\n const char = element.value.slice(pos - 1, pos)\n if (char === invisibleSpace) {\n pos = suffixStart - 1\n }\n\n if (!isNaN(parseFloat(pos))) {\n safeSetSelection(element, pos)\n }\n } else if (props?.mask && element.value.length === end) {\n const chars = element.value.split('')\n\n for (let l = chars.length, i = l - 1; i >= 0; i--) {\n const char = chars[i]\n const mask = props.mask[i]\n if (\n char &&\n char !== invisibleSpace &&\n mask instanceof RegExp &&\n mask.test(char)\n ) {\n for (let n = i + 1; n < l; n++) {\n const mask = props.mask[n]\n if (mask?.test?.(char)) {\n safeSetSelection(element, n)\n break\n }\n }\n\n break\n }\n }\n }\n } catch (e) {\n warn(e)\n }\n }\n\n if (typeof window !== 'undefined') {\n window.requestAnimationFrame(correction)\n }\n}\n\n/**\n * Manipulate needed mask for handle: percent\n *\n * @param {object} param0 object with properties\n * @property {object} props Component property\n * @property {string} locale Eufemia locale (either from component or context)\n * @property {object} maskParams predefined mask parameters\n * @returns object maskParams\n */\nexport const handlePercentMask = ({ props, locale, maskParams }) => {\n const value = format(props.value, { locale, percent: true })\n maskParams.suffix = String(value)?.match(/((\\s|)%)$/g, '$1')?.[0] || ' %'\n\n return maskParams\n}\n\n/**\n * Return needed mask for handle: currency\n *\n * @param {object} param0 object with properties\n * @property {object} context Eufemia context\n * @property {object} mask_options Component property for change the mask parameters\n * @property {object} currency_mask Component property for change the currency parameters\n * @returns object maskParams\n */\nexport const handleCurrencyMask = ({ mask_options, currency_mask }) => {\n const givenParams = {\n ...mask_options,\n ...currency_mask,\n }\n const paramsWithDefaults = {\n showMask: true,\n placeholderChar: null,\n allowDecimal: true,\n decimalLimit: 2,\n decimalSymbol: ',',\n ...givenParams,\n }\n\n const suffix =\n typeof currency_mask === 'string'\n ? currency_mask\n : typeof givenParams.currency === 'string'\n ? givenParams.currency\n : 'kr'\n paramsWithDefaults.suffix = ` ${suffix}`\n\n if (\n typeof givenParams?.allowDecimal === 'undefined' &&\n typeof givenParams?.decimalLimit === 'number'\n ) {\n paramsWithDefaults.allowDecimal = givenParams.decimalLimit > 0\n }\n\n return paramsWithDefaults\n}\n\n/**\n * Return needed mask for handle: number\n *\n * @param {object} param0 object with properties\n * @property {object} context Eufemia context\n * @property {object} mask_options Component property for change the mask parameters\n * @property {object} number_mask Component property for change the number parameters\n * @returns object maskParams\n */\nexport const handleNumberMask = ({ mask_options, number_mask }) => {\n const maskParams = {\n decimalSymbol: ',',\n ...mask_options,\n ...number_mask,\n }\n\n if (typeof maskParams.allowDecimal === 'undefined') {\n maskParams.allowDecimal = maskParams.decimalLimit > 0\n }\n\n return maskParams\n}\n\n/**\n * Returns the type of what inputMode or type attribute should be used\n *\n * @param {function} mask mask function\n * @returns undefined|decimal|numeric\n */\nexport function getSoftKeyboardAttributes(mask) {\n if (mask?.instanceOf !== 'createNumberMask') {\n return undefined\n }\n\n const maskParams = mask?.maskParams\n\n // because of the missing minus key, we still have to use text on iOS\n if (IS_IOS && maskParams?.allowNegative !== false) {\n return undefined\n }\n\n return {\n inputMode:\n maskParams.allowDecimal && maskParams.decimalLimit !== 0\n ? 'decimal'\n : 'numeric',\n }\n}\n\n/**\n * Returns the thousands separator character\n *\n * @param {string} locale Component or context locale\n * @returns string\n */\nexport function handleThousandsSeparator(locale) {\n return getThousandsSeparator(locale).replace(' ', ' ') // replace non-breaking space with a regular space\n}\n\n/**\n * Returns the decimal separator character\n *\n * @param {string} locale Component or context locale\n * @returns string\n */\nexport function handleDecimalSeparator(locale) {\n let decimalSymbol = getDecimalSeparator(locale)\n\n return decimalSymbol\n}\n\n/**\n * Will take a JSON and return it parsed\n *\n * @param {string} str\n * @param {*} fallback optional fallback\n * @returns parsed json\n */\nexport function fromJSON(str, fallback = null) {\n if (typeof str === 'string' && str[0] === '{') {\n return JSON.parse(str)\n }\n\n return str || fallback\n}\n"],"mappings":";;;AAKA,SACEA,MAAM,EACNC,mBAAmB,EACnBC,qBAAqB,QAChB,8BAA8B;AACrC,SAASC,IAAI,QAAQ,+BAA+B;AACpD,SAASC,MAAM,QAAQ,sBAAsB;AAC7C,SAASC,gBAAgB,QAAQ,wCAAwC;AAEzE,MAAMC,uBAAuB,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,aAAa,CAAC;AAC1E,MAAMC,oBAAoB,GAAG,CAC3B,WAAW,EACX,YAAY,EACZ,aAAa,EACb,aAAa,EACb,eAAe,CAChB;AAED,OAAO,MAAMC,cAAc,GAAG,QAAQ;A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CAACmB,MAAM,CAAC;EAE/C,OAAOuB,aAAa;AACtB;AASA,OAAO,SAASyD,QAAQA,CAACC,GAAG,EAAEC,QAAQ,GAAG,IAAI,EAAE;EAC7C,IAAI,OAAOD,GAAG,KAAK,QAAQ,IAAIA,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;IAC7C,OAAOE,IAAI,CAACC,KAAK,CAACH,GAAG,CAAC;EACxB;EAEA,OAAOA,GAAG,IAAIC,QAAQ;AACxB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"InputMaskedUtils.js","names":["format","getDecimalSeparator","getThousandsSeparator","warn","IS_IOS","safeSetSelection","enableLocaleSupportWhen","enableNumberMaskWhen","invisibleSpace","isRequestingLocaleSupport","props","Object","entries","some","k","v","includes","isRequestingNumberMask","correctNumberValue","localValue","locale","maskParams","value","undefined","String","isNaN","parseFloat","decimalPos","indexOf","integerLimit","limit","integers","split","isNegative","length","decimals","slice","shouldHaveDecimals","allowDecimal","decimalLimit","number_format","options","_objectSpread","decimalSymbol","replace","localNumberValue","numberValue","valueHasDecimal","endsWithDecimal","endsWith","endsWithZeroAndDecimal","startsWith","test","correctCaretPosition","element","maskParamsRef","correction","current","suffix","prefix","start","selectionStart","end","selectionEnd","suffixStart","suffixEnd","pos","placeholderChar","prefixStart","prefixEnd","char","mask","chars","l","i","RegExp","n","_mask$test","call","e","window","requestAnimationFrame","handlePercentMask","_String","_String$match","percent","match","handleCurrencyMask","mask_options","currency_mask","givenParams","paramsWithDefaults","showMask","currency","handleNumberMask","number_mask","getSoftKeyboardAttributes","instanceOf","allowNegative","inputMode","handleThousandsSeparator","handleDecimalSeparator","fromJSON","str","fallback","JSON","parse"],"sources":["../../../../src/components/input-masked/InputMaskedUtils.js"],"sourcesContent":["/**\n * Web InputMasked Component\n *\n */\n\nimport {\n format,\n getDecimalSeparator,\n getThousandsSeparator,\n} from '../number-format/NumberUtils'\nimport { warn } from '../../shared/component-helper'\nimport { IS_IOS } from '../../shared/helpers'\nimport { safeSetSelection } from './text-mask/createTextMaskInputElement'\n\nconst enableLocaleSupportWhen = ['as_number', 'as_percent', 'as_currency']\nconst enableNumberMaskWhen = [\n 'as_number',\n 'as_percent',\n 'as_currency',\n 'number_mask',\n 'currency_mask',\n]\n\nexport const invisibleSpace = '\\u200B'\n\n/**\n * Will return true if a prop needs Locale support\n *\n * @param {object} props object with given component props\n * @returns boolean\n */\nexport const isRequestingLocaleSupport = (props) => {\n return Object.entries(props).some(\n ([k, v]) => v && enableLocaleSupportWhen.includes(k)\n )\n}\n\n/**\n * Will return true if a prop will enable the internal NumberMask\n *\n * @param {object} props object with given component props\n * @returns boolean\n */\nexport const isRequestingNumberMask = (props) => {\n return Object.entries(props).some(\n ([k, v]) => v && enableNumberMaskWhen.includes(k)\n )\n}\n\n/**\n * Probably the most complex part of this component\n * It will modify a given value based on certain criteria's\n *\n * @param {object} param0 object with properties\n * @property {string} localValue optional – if given, it will uses its ending to determine of what to return\n * @property {number|string} value component property value\n * @property {object} context Eufemia Context\n * @property {string} locale Eufemia locale (either from component or context)\n * @property {object} maskParams predefined mask parameters\n * @returns string Value\n */\nexport const correctNumberValue = ({\n localValue = null,\n props,\n locale,\n maskParams,\n}) => {\n let value =\n props.value === null\n ? null\n : props.value === undefined\n ? undefined\n : String(props.value)\n\n if (isNaN(parseFloat(value))) {\n return value\n }\n\n const decimalPos = value.indexOf('.')\n\n if (\n maskParams.integerLimit &&\n typeof maskParams.integerLimit === 'number'\n ) {\n const limit = maskParams.integerLimit\n const integers = value.split('.')[0]\n const isNegative = parseFloat(integers) < 0\n if (integers.length - (isNegative ? 1 : 0) > limit) {\n const decimals = decimalPos > 0 ? value.slice(decimalPos) : ''\n value = integers.slice(0, limit + (isNegative ? 1 : 0)) + decimals\n }\n }\n\n const shouldHaveDecimals =\n maskParams.allowDecimal ||\n (maskParams.decimalLimit > 0 && maskParams.allowDecimal !== false)\n\n if (!shouldHaveDecimals) {\n if (decimalPos > -1) {\n value = value.slice(0, decimalPos)\n }\n }\n\n /**\n * This only runs IF \"number_format\" is set – we do not use it else\n */\n if (props.number_format) {\n const options = {\n locale,\n decimals: 0,\n ...props.number_format,\n }\n if (shouldHaveDecimals) {\n options.decimals = maskParams.decimalLimit\n }\n value = format(value, options)\n }\n\n const decimalSymbol = maskParams.decimalSymbol\n value = value.replace('.', decimalSymbol)\n\n if (localValue !== null) {\n const localNumberValue = localValue.replace(/[^\\d,.-]/g, '')\n const numberValue = value.replace(/[^\\d,.-]/g, '')\n const valueHasDecimal = numberValue.includes(decimalSymbol)\n\n if (!valueHasDecimal) {\n const endsWithDecimal = localNumberValue.endsWith(decimalSymbol)\n const endsWithZeroAndDecimal = localNumberValue.endsWith(\n `${decimalSymbol}0`\n )\n\n if (endsWithDecimal) {\n value = `${value}${decimalSymbol}`\n } else if (\n endsWithZeroAndDecimal &&\n !numberValue.endsWith(`${decimalSymbol}0`)\n ) {\n /**\n * When the users has 20,02, then hits \"backspace\",\n * the returned {numberValue} in the onChange event would then be \"20\",\n * but we want it to be 20,0\n */\n value = `${value}${decimalSymbol}0`\n }\n }\n\n /**\n * If the user removes a leading digit and we have left a leading zero.\n *\n * The users enters these steps:\n * Step 1. 1012\n * Step 2. 012 -> user removes 1, now use \"localValue\"\n * Step 3. 2012\n *\n * If a dev listens on_change and sends the number value back in,\n * for this, we also ensure that \"numberValue\" and \"localNumberValue\" is the same.\n */\n if (\n localNumberValue !== '0' &&\n localNumberValue.startsWith('0') &&\n parseFloat(numberValue.replace(decimalSymbol, '.')) ===\n parseFloat(localNumberValue.replace(decimalSymbol, '.'))\n ) {\n value = localValue\n }\n\n /**\n * While typing;\n * If the local value is - or -0 we use it.\n * Also, because of invisible whitespace we remove everything else\n */\n if (/^(-|-0)$/.test(localValue.replace(/[^\\d-0]/g, ''))) {\n value = localValue\n } else if (localNumberValue === '' && numberValue === '0') {\n value = ''\n }\n }\n\n return value\n}\n\n/**\n * This is a helper for setting the cursor position,\n * when it is on a not allowed position\n *\n * @param {Element} element Input Element\n * @param {Object} maskParams Mask parameters, containing eventually suffix or prefix\n */\nexport const correctCaretPosition = (element, maskParamsRef, props) => {\n const correction = () => {\n try {\n const maskParams = maskParamsRef?.current\n\n const suffix = maskParams?.suffix\n const prefix = maskParams?.prefix\n\n const start = element.selectionStart\n const end = element.selectionEnd\n\n if (start !== end) {\n return // stop here\n }\n\n if (suffix || prefix) {\n const suffixStart = element.value.indexOf(suffix)\n const suffixEnd = suffixStart + suffix?.length\n let pos = undefined\n\n if (start >= suffixStart && start <= suffixEnd) {\n pos = suffixStart\n\n // If there is a placeholder,\n // and the user clicks after the suffix\n // we want the position to be \"before\" the placeholderChar\n if (\n maskParams.placeholderChar !== invisibleSpace &&\n element.value.length - 1 === String(suffix + prefix).length\n ) {\n pos = pos - 1\n }\n } else {\n const prefixStart = element.value.indexOf(prefix)\n const prefixEnd = prefixStart + prefix?.length || 0\n\n if (start >= prefixStart && start <= prefixEnd) {\n pos = prefixEnd\n }\n }\n\n const char = element.value.slice(pos - 1, pos)\n if (char === invisibleSpace) {\n pos = suffixStart - 1\n }\n\n if (!isNaN(parseFloat(pos))) {\n safeSetSelection(element, pos)\n }\n } else if (props?.mask && element.value.length === end) {\n const chars = element.value.split('')\n\n for (let l = chars.length, i = l - 1; i >= 0; i--) {\n const char = chars[i]\n const mask = props.mask[i]\n if (\n char &&\n char !== invisibleSpace &&\n mask instanceof RegExp &&\n mask.test(char)\n ) {\n for (let n = i + 1; n < l; n++) {\n const mask = props.mask[n]\n if (mask?.test?.(char)) {\n safeSetSelection(element, n)\n break\n }\n }\n\n break\n }\n }\n }\n } catch (e) {\n warn(e)\n }\n }\n\n if (typeof window !== 'undefined') {\n window.requestAnimationFrame(correction)\n }\n}\n\n/**\n * Manipulate needed mask for handle: percent\n *\n * @param {object} param0 object with properties\n * @property {object} props Component property\n * @property {string} locale Eufemia locale (either from component or context)\n * @property {object} maskParams predefined mask parameters\n * @returns object maskParams\n */\nexport const handlePercentMask = ({ props, locale, maskParams }) => {\n const value = format(props.value, { locale, percent: true })\n maskParams.suffix = String(value)?.match(/((\\s|)%)$/g, '$1')?.[0] || ' %'\n\n return maskParams\n}\n\n/**\n * Return needed mask for handle: currency\n *\n * @param {object} param0 object with properties\n * @property {object} context Eufemia context\n * @property {object} mask_options Component property for change the mask parameters\n * @property {object} currency_mask Component property for change the currency parameters\n * @returns object maskParams\n */\nexport const handleCurrencyMask = ({ mask_options, currency_mask }) => {\n const givenParams = {\n ...mask_options,\n ...currency_mask,\n }\n const paramsWithDefaults = {\n showMask: true,\n placeholderChar: null,\n allowDecimal: true,\n decimalLimit: 2,\n decimalSymbol: ',',\n ...givenParams,\n }\n\n const suffix =\n typeof currency_mask === 'string'\n ? currency_mask\n : typeof givenParams.currency === 'string'\n ? givenParams.currency\n : 'kr'\n paramsWithDefaults.suffix = ` ${suffix}`\n\n if (\n typeof givenParams?.allowDecimal === 'undefined' &&\n typeof givenParams?.decimalLimit === 'number'\n ) {\n paramsWithDefaults.allowDecimal = givenParams.decimalLimit > 0\n }\n\n return paramsWithDefaults\n}\n\n/**\n * Return needed mask for handle: number\n *\n * @param {object} param0 object with properties\n * @property {object} context Eufemia context\n * @property {object} mask_options Component property for change the mask parameters\n * @property {object} number_mask Component property for change the number parameters\n * @returns object maskParams\n */\nexport const handleNumberMask = ({ mask_options, number_mask }) => {\n const maskParams = {\n decimalSymbol: ',',\n ...mask_options,\n ...number_mask,\n }\n\n if (typeof maskParams.allowDecimal === 'undefined') {\n maskParams.allowDecimal = maskParams.decimalLimit > 0\n }\n\n return maskParams\n}\n\n/**\n * Returns the type of what inputMode or type attribute should be used\n *\n * @param {function} mask mask function\n * @returns undefined|decimal|numeric\n */\nexport function getSoftKeyboardAttributes(mask) {\n if (mask?.instanceOf !== 'createNumberMask') {\n return undefined\n }\n\n const maskParams = mask?.maskParams\n\n // because of the missing minus key, we still have to use text on iOS\n if (IS_IOS && maskParams?.allowNegative !== false) {\n return undefined\n }\n\n return {\n inputMode:\n maskParams.allowDecimal && maskParams.decimalLimit !== 0\n ? 'decimal'\n : 'numeric',\n }\n}\n\n/**\n * Returns the thousands separator character\n *\n * @param {string} locale Component or context locale\n * @returns string\n */\nexport function handleThousandsSeparator(locale) {\n return getThousandsSeparator(locale).replace(' ', ' ') // replace non-breaking space with a regular space\n}\n\n/**\n * Returns the decimal separator character\n *\n * @param {string} locale Component or context locale\n * @returns string\n */\nexport function handleDecimalSeparator(locale) {\n let decimalSymbol = getDecimalSeparator(locale)\n\n return decimalSymbol\n}\n\n/**\n * Will take a JSON and return it parsed\n *\n * @param {string} str\n * @param {*} fallback optional fallback\n * @returns parsed json\n */\nexport function fromJSON(str, fallback = null) {\n if (typeof str === 'string' && str[0] === '{') {\n return JSON.parse(str)\n }\n\n return str || fallback\n}\n"],"mappings":";;;AAKA,SACEA,MAAM,EACNC,mBAAmB,EACnBC,qBAAqB,QAChB,8BAA8B;AACrC,SAASC,IAAI,QAAQ,+BAA+B;AACpD,SAASC,MAAM,QAAQ,sBAAsB;AAC7C,SAASC,gBAAgB,QAAQ,wCAAwC;AAEzE,MAAMC,uBAAuB,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,aAAa,CAAC;AAC1E,MAAMC,oBAAoB,GAAG,CAC3B,WAAW,EACX,YAAY,EACZ,aAAa,EACb,aAAa,EACb,eAAe,CAChB;AAED,OAAO,MAAMC,cAAc,GAAG,QAAQ;AAQtC,OAAO,MAAMC,yBAAyB,GAAIC,KAAK,IAAK;EAClD,OAAOC,MAAM,CAACC,OAAO,CAACF,KAAK,CAAC,CAACG,IAAI,CAC/B,CAAC,CAACC,CAAC,EAAEC,CAAC,CAAC,KAAKA,CAAC,IAAIT,uBAAuB,CAACU,QAAQ,CAACF,CAAC,CACrD,CAAC;AACH,CAAC;AAQD,OAAO,MAAMG,sBAAsB,GAAIP,KAAK,IAAK;EAC/C,OAAOC,MAAM,CAACC,OAAO,CAACF,KAAK,CAAC,CAACG,IAAI,CAC/B,CAAC,CAACC,CAAC,EAAEC,CAA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xB","ignoreList":[]}
|
|
@@ -40,9 +40,9 @@ export default function adjustCaretPosition({
|
|
|
40
40
|
targetChar = intersection[intersection.length - 1];
|
|
41
41
|
const previousLeftMaskChars = previousPlaceholder.substr(0, intersection.length).split(emptyString).filter(char => char !== placeholderChar).length;
|
|
42
42
|
const leftMaskChars = placeholder.substr(0, intersection.length).split(emptyString).filter(char => char !== placeholderChar).length;
|
|
43
|
-
const
|
|
43
|
+
const maskLengthChanged = leftMaskChars !== previousLeftMaskChars;
|
|
44
44
|
const targetIsMaskMovingLeft = previousPlaceholder[intersection.length - 1] !== undefined && placeholder[intersection.length - 2] !== undefined && previousPlaceholder[intersection.length - 1] !== placeholderChar && previousPlaceholder[intersection.length - 1] !== placeholder[intersection.length - 1] && previousPlaceholder[intersection.length - 1] === placeholder[intersection.length - 2];
|
|
45
|
-
if (!isAddition && (
|
|
45
|
+
if (!isAddition && (maskLengthChanged || targetIsMaskMovingLeft) && previousLeftMaskChars > 0 && placeholder.indexOf(targetChar) > -1 && rawValue[currentCaretPosition] !== undefined) {
|
|
46
46
|
trackRightCharacter = true;
|
|
47
47
|
targetChar = rawValue[currentCaretPosition];
|
|
48
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adjustCaretPosition.js","names":["defaultArray","emptyString","adjustCaretPosition","previousConformedValue","previousPlaceholder","currentCaretPosition","conformedValue","rawValue","placeholderChar","placeholder","indexesOfPipedChars","caretTrapIndexes","keepCharPositions","length","rawValueLength","previousConformedValueLength","placeholderLength","conformedValueLength","editLength","isAddition","isFirstRawValue","isPartialMultiCharEdit","possiblyHasRejectedChar","startingSearchIndex","trackRightCharacter","targetChar","normalizedConformedValue","toLowerCase","normalizedRawValue","leftHalfChars","substr","split","intersection","filter","char","indexOf","previousLeftMaskChars","leftMaskChars","masklengthChanged","targetIsMaskMovingLeft","undefined","pipedChars","map","index","countTargetCharInPipedChars","countTargetCharInIntersection","countTargetCharInPlaceholder","requiredNumberOfMatches","numberOfEncounteredMatches","i","conformedValueChar","lastPlaceholderChar"],"sources":["../../../../../src/components/input-masked/text-mask/adjustCaretPosition.js"],"sourcesContent":["const defaultArray = []\nconst emptyString = ''\n\nexport default function adjustCaretPosition({\n previousConformedValue = emptyString,\n previousPlaceholder = emptyString,\n currentCaretPosition = 0,\n conformedValue,\n rawValue,\n placeholderChar,\n placeholder,\n indexesOfPipedChars = defaultArray,\n caretTrapIndexes = defaultArray,\n keepCharPositions = false,\n}) {\n if (currentCaretPosition === 0 || !rawValue.length) {\n return 0\n }\n\n // Store lengths for faster performance?\n const rawValueLength = rawValue.length\n const previousConformedValueLength = previousConformedValue.length\n const placeholderLength = placeholder.length\n const conformedValueLength = conformedValue.length\n\n // This tells us how long the edit is. If user modified input from `(2__)` to `(243__)`,\n // we know the user in this instance pasted two characters\n const editLength = rawValueLength - previousConformedValueLength\n\n // If the edit length is positive, that means the user is adding characters, not deleting.\n const isAddition = editLength > 0\n\n // This is the first raw value the user entered that needs to be conformed to mask\n const isFirstRawValue = previousConformedValueLength === 0\n\n // A partial multi-character edit happens when the user makes a partial selection in their\n // input and edits that selection. That is going from `(123) 432-4348` to `() 432-4348` by\n // selecting the first 3 digits and pressing backspace.\n //\n // Such cases can also happen when the user presses the backspace while holding down the ALT\n // key.\n const isPartialMultiCharEdit =\n editLength > 1 && !isAddition && !isFirstRawValue\n\n // This algorithm doesn't support all cases of multi-character edits, so we just return\n // the current caret position.\n //\n // This works fine for most cases.\n if (isPartialMultiCharEdit) {\n return currentCaretPosition\n }\n\n // For a mask like (111), if the `previousConformedValue` is (1__) and user attempts to enter\n // `f` so the `rawValue` becomes (1f__), the new `conformedValue` would be (1__), which is the\n // same as the original `previousConformedValue`. We handle this case differently for caret\n // positioning.\n const possiblyHasRejectedChar =\n isAddition &&\n ((keepCharPositions !== false &&\n previousConformedValue === conformedValue) ||\n conformedValue === placeholder)\n\n let startingSearchIndex = 0\n let trackRightCharacter\n let targetChar\n\n if (possiblyHasRejectedChar) {\n startingSearchIndex = currentCaretPosition - editLength\n } else {\n // At this point in the algorithm, we want to know where the caret is right before the raw input\n // has been conformed, and then see if we can find that same spot in the conformed input.\n //\n // We do that by seeing what character lies immediately before the caret, and then look for that\n // same character in the conformed input and place the caret there.\n\n // First, we need to normalize the inputs so that letter capitalization between raw input and\n // conformed input wouldn't matter.\n const normalizedConformedValue = conformedValue.toLowerCase()\n const normalizedRawValue = rawValue.toLowerCase()\n\n // Then we take all characters that come before where the caret currently is.\n const leftHalfChars = normalizedRawValue\n .substr(0, currentCaretPosition)\n .split(emptyString)\n\n // Now we find all the characters in the left half that exist in the conformed input\n // This step ensures that we don't look for a character that was filtered out or rejected by `conformToMask`.\n const intersection = leftHalfChars.filter(\n (char) => normalizedConformedValue.indexOf(char) !== -1\n )\n\n // The last character in the intersection is the character we want to look for in the conformed\n // value and the one we want to adjust the caret close to\n targetChar = intersection[intersection.length - 1]\n\n // Calculate the number of mask characters in the previous placeholder\n // from the start of the string up to the place where the caret is\n const previousLeftMaskChars = previousPlaceholder\n .substr(0, intersection.length)\n .split(emptyString)\n .filter((char) => char !== placeholderChar).length\n\n // Calculate the number of mask characters in the current placeholder\n // from the start of the string up to the place where the caret is\n const leftMaskChars = placeholder\n .substr(0, intersection.length)\n .split(emptyString)\n .filter((char) => char !== placeholderChar).length\n\n // Has the number of mask characters up to the caret changed?\n const masklengthChanged = leftMaskChars !== previousLeftMaskChars\n\n // Detect if `targetChar` is a mask character and has moved to the left\n const targetIsMaskMovingLeft =\n previousPlaceholder[intersection.length - 1] !== undefined &&\n placeholder[intersection.length - 2] !== undefined &&\n previousPlaceholder[intersection.length - 1] !== placeholderChar &&\n previousPlaceholder[intersection.length - 1] !==\n placeholder[intersection.length - 1] &&\n previousPlaceholder[intersection.length - 1] ===\n placeholder[intersection.length - 2]\n\n // If deleting and the `targetChar` `is a mask character and `masklengthChanged` is true\n // or the mask is moving to the left, we can't use the selected `targetChar` any longer\n // if we are not at the end of the string.\n // In this case, change tracking strategy and track the character to the right of the caret.\n if (\n !isAddition &&\n (masklengthChanged || targetIsMaskMovingLeft) &&\n previousLeftMaskChars > 0 &&\n placeholder.indexOf(targetChar) > -1 &&\n rawValue[currentCaretPosition] !== undefined\n ) {\n trackRightCharacter = true\n targetChar = rawValue[currentCaretPosition]\n }\n\n // It is possible that `targetChar` will appear multiple times in the conformed value.\n // We need to know not to select a character that looks like our target character from the placeholder or\n // the piped characters, so we inspect the piped characters and the placeholder to see if they contain\n // characters that match our target character.\n\n // If the `conformedValue` got piped, we need to know which characters were piped in so that when we look for\n // our `targetChar`, we don't select a piped char by mistake\n const pipedChars = indexesOfPipedChars.map(\n (index) => normalizedConformedValue[index]\n )\n\n // We need to know how many times the `targetChar` occurs in the piped characters.\n const countTargetCharInPipedChars = pipedChars.filter(\n (char) => char === targetChar\n ).length\n\n // We need to know how many times it occurs in the intersection\n const countTargetCharInIntersection = intersection.filter(\n (char) => char === targetChar\n ).length\n\n // We need to know if the placeholder contains characters that look like\n // our `targetChar`, so we don't select one of those by mistake.\n const countTargetCharInPlaceholder = placeholder\n .substr(0, placeholder.indexOf(placeholderChar))\n .split(emptyString)\n .filter(\n (char, index) =>\n // Check if `char` is the same as our `targetChar`, so we account for it\n char === targetChar &&\n // but also make sure that both the `rawValue` and placeholder don't have the same character at the same\n // index because if they are equal, that means we are already counting those characters in\n // `countTargetCharInIntersection`\n rawValue[index] !== char\n ).length\n\n // The number of times we need to see occurrences of the `targetChar` before we know it is the one we're looking\n // for is:\n const requiredNumberOfMatches =\n countTargetCharInPlaceholder +\n countTargetCharInIntersection +\n countTargetCharInPipedChars +\n // The character to the right of the caret isn't included in `intersection`\n // so add one if we are tracking the character to the right\n (trackRightCharacter ? 1 : 0)\n\n // Now we start looking for the location of the `targetChar`.\n // We keep looping forward and store the index in every iteration. Once we have encountered\n // enough occurrences of the target character, we break out of the loop\n // If are searching for the second `1` in `1214`, `startingSearchIndex` will point at `4`.\n let numberOfEncounteredMatches = 0\n for (let i = 0; i < conformedValueLength; i++) {\n const conformedValueChar = normalizedConformedValue[i]\n\n startingSearchIndex = i + 1\n\n if (conformedValueChar === targetChar) {\n numberOfEncounteredMatches++\n }\n\n if (numberOfEncounteredMatches >= requiredNumberOfMatches) {\n break\n }\n }\n }\n\n // At this point, if we simply return `startingSearchIndex` as the adjusted caret position,\n // most cases would be handled. However, we want to fast forward or rewind the caret to the\n // closest placeholder character if it happens to be in a non-editable spot. That's what the next\n // logic is for.\n\n // In case of addition, we fast forward.\n if (isAddition) {\n // We want to remember the last placeholder character encountered so that if the mask\n // contains more characters after the last placeholder character, we don't forward the caret\n // that far to the right. Instead, we stop it at the last encountered placeholder character.\n let lastPlaceholderChar = startingSearchIndex\n\n for (let i = startingSearchIndex; i <= placeholderLength; i++) {\n if (placeholder[i] === placeholderChar) {\n lastPlaceholderChar = i\n }\n\n if (\n // If we're adding, we can position the caret at the next placeholder character.\n placeholder[i] === placeholderChar ||\n // If a caret trap was set by a mask function, we need to stop at the trap.\n caretTrapIndexes.indexOf(i) !== -1 ||\n // This is the end of the placeholder. We cannot move any further. Let's put the caret there.\n i === placeholderLength\n ) {\n return lastPlaceholderChar\n }\n }\n } else {\n // In case of deletion, we rewind.\n if (trackRightCharacter) {\n // Searching for the character that was to the right of the caret\n // We start at `startingSearchIndex` - 1 because it includes one character extra to the right\n for (let i = startingSearchIndex - 1; i >= 0; i--) {\n // If tracking the character to the right of the cursor, we move to the left until\n // we found the character and then place the caret right before it\n\n if (\n // `targetChar` should be in `conformedValue`, since it was in `rawValue`, just\n // to the right of the caret\n conformedValue[i] === targetChar ||\n // If a caret trap was set by a mask function, we need to stop at the trap.\n caretTrapIndexes.indexOf(i) !== -1 ||\n // This is the beginning of the placeholder. We cannot move any further.\n // Let's put the caret there.\n i === 0\n ) {\n return i\n }\n }\n } else {\n // Searching for the first placeholder or caret trap to the left\n\n for (let i = startingSearchIndex; i >= 0; i--) {\n // If we're deleting, we stop the caret right before the placeholder character.\n // For example, for mask `(111) 11`, current conformed input `(456) 86`. If user\n // modifies input to `(456 86`. That is, they deleted the `)`, we place the caret\n // right after the first `6`\n\n if (\n // If we're deleting, we can position the caret right before the placeholder character\n placeholder[i - 1] === placeholderChar ||\n // If a caret trap was set by a mask function, we need to stop at the trap.\n caretTrapIndexes.indexOf(i) !== -1 ||\n // This is the beginning of the placeholder. We cannot move any further.\n // Let's put the caret there.\n i === 0\n ) {\n return i\n }\n }\n }\n }\n}\n"],"mappings":"AAAA,MAAMA,YAAY,GAAG,EAAE;AACvB,MAAMC,WAAW,GAAG,EAAE;AAEtB,eAAe,SAASC,mBAAmBA,CAAC;EAC1CC,sBAAsB,GAAGF,WAAW;EACpCG,mBAAmB,GAAGH,WAAW;EACjCI,oBAAoB,GAAG,CAAC;EACxBC,cAAc;EACdC,QAAQ;EACRC,eAAe;EACfC,WAAW;EACXC,mBAAmB,GAAGV,YAAY;EAClCW,gBAAgB,GAAGX,YAAY;EAC/BY,iBAAiB,GAAG;AACtB,CAAC,EAAE;EACD,IAAIP,oBAAoB,KAAK,CAAC,IAAI,CAACE,QAAQ,CAACM,MAAM,EAAE;IAClD,OAAO,CAAC;EACV;EAGA,MAAMC,cAAc,GAAGP,QAAQ,CAACM,MAAM;EACtC,MAAME,4BAA4B,GAAGZ,sBAAsB,CAACU,MAAM;EAClE,MAAMG,iBAAiB,GAAGP,WAAW,CAACI,MAAM;EAC5C,MAAMI,oBAAoB,GAAGX,cAAc,CAACO,MAAM;EAIlD,MAAMK,UAAU,GAAGJ,cAAc,GAAGC,4BAA4B;EAGhE,MAAMI,UAAU,GAAGD,UAAU,GAAG,CAAC;EAGjC,MAAME,eAAe,GAAGL,4BAA4B,KAAK,CAAC;EAQ1D,MAAMM,sBAAsB,GAC1BH,UAAU,GAAG,CAAC,IAAI,CAACC,UAAU,IAAI,CAACC,eAAe;EAMnD,IAAIC,sBAAsB,EAAE;IAC1B,OAAOhB,oBAAoB;EAC7B;EAMA,MAAMiB,uBAAuB,GAC3BH,UAAU,KACRP,iBAAiB,KAAK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KAAKxB,UAAU,IAEhCd,gBAAgB,CAACwB,OAAO,CAACc,CAAC,CAAC,KAAK,CAAC,CAAC,IAGlCA,CAAC,KAAK,CAAC,EACP;UACA,OAAOA,CAAC;QACV;MACF;IACF,CAAC,MAAM;MAGL,KAAK,IAAIA,CAAC,GAAG1B,mBAAmB,EAAE0B,CAAC,IAAI,CAAC,EAAEA,CAAC,EAAE,EAAE;QAM7C,IAEExC,WAAW,CAACwC,CAAC,GAAG,CAAC,CAAC,KAAKzC,eAAe,IAEtCG,gBAAgB,CAACwB,OAAO,CAACc,CAAC,CAAC,KAAK,CAAC,CAAC,IAGlCA,CAAC,KAAK,CAAC,EACP;UACA,OAAOA,CAAC;QACV;MACF;IACF;EACF;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"adjustCaretPosition.js","names":["defaultArray","emptyString","adjustCaretPosition","previousConformedValue","previousPlaceholder","currentCaretPosition","conformedValue","rawValue","placeholderChar","placeholder","indexesOfPipedChars","caretTrapIndexes","keepCharPositions","length","rawValueLength","previousConformedValueLength","placeholderLength","conformedValueLength","editLength","isAddition","isFirstRawValue","isPartialMultiCharEdit","possiblyHasRejectedChar","startingSearchIndex","trackRightCharacter","targetChar","normalizedConformedValue","toLowerCase","normalizedRawValue","leftHalfChars","substr","split","intersection","filter","char","indexOf","previousLeftMaskChars","leftMaskChars","maskLengthChanged","targetIsMaskMovingLeft","undefined","pipedChars","map","index","countTargetCharInPipedChars","countTargetCharInIntersection","countTargetCharInPlaceholder","requiredNumberOfMatches","numberOfEncounteredMatches","i","conformedValueChar","lastPlaceholderChar"],"sources":["../../../../../src/components/input-masked/text-mask/adjustCaretPosition.js"],"sourcesContent":["const defaultArray = []\nconst emptyString = ''\n\nexport default function adjustCaretPosition({\n previousConformedValue = emptyString,\n previousPlaceholder = emptyString,\n currentCaretPosition = 0,\n conformedValue,\n rawValue,\n placeholderChar,\n placeholder,\n indexesOfPipedChars = defaultArray,\n caretTrapIndexes = defaultArray,\n keepCharPositions = false,\n}) {\n if (currentCaretPosition === 0 || !rawValue.length) {\n return 0\n }\n\n // Store lengths for faster performance?\n const rawValueLength = rawValue.length\n const previousConformedValueLength = previousConformedValue.length\n const placeholderLength = placeholder.length\n const conformedValueLength = conformedValue.length\n\n // This tells us how long the edit is. If user modified input from `(2__)` to `(243__)`,\n // we know the user in this instance pasted two characters\n const editLength = rawValueLength - previousConformedValueLength\n\n // If the edit length is positive, that means the user is adding characters, not deleting.\n const isAddition = editLength > 0\n\n // This is the first raw value the user entered that needs to be conformed to mask\n const isFirstRawValue = previousConformedValueLength === 0\n\n // A partial multi-character edit happens when the user makes a partial selection in their\n // input and edits that selection. That is going from `(123) 432-4348` to `() 432-4348` by\n // selecting the first 3 digits and pressing backspace.\n //\n // Such cases can also happen when the user presses the backspace while holding down the ALT\n // key.\n const isPartialMultiCharEdit =\n editLength > 1 && !isAddition && !isFirstRawValue\n\n // This algorithm doesn't support all cases of multi-character edits, so we just return\n // the current caret position.\n //\n // This works fine for most cases.\n if (isPartialMultiCharEdit) {\n return currentCaretPosition\n }\n\n // For a mask like (111), if the `previousConformedValue` is (1__) and user attempts to enter\n // `f` so the `rawValue` becomes (1f__), the new `conformedValue` would be (1__), which is the\n // same as the original `previousConformedValue`. We handle this case differently for caret\n // positioning.\n const possiblyHasRejectedChar =\n isAddition &&\n ((keepCharPositions !== false &&\n previousConformedValue === conformedValue) ||\n conformedValue === placeholder)\n\n let startingSearchIndex = 0\n let trackRightCharacter\n let targetChar\n\n if (possiblyHasRejectedChar) {\n startingSearchIndex = currentCaretPosition - editLength\n } else {\n // At this point in the algorithm, we want to know where the caret is right before the raw input\n // has been conformed, and then see if we can find that same spot in the conformed input.\n //\n // We do that by seeing what character lies immediately before the caret, and then look for that\n // same character in the conformed input and place the caret there.\n\n // First, we need to normalize the inputs so that letter capitalization between raw input and\n // conformed input wouldn't matter.\n const normalizedConformedValue = conformedValue.toLowerCase()\n const normalizedRawValue = rawValue.toLowerCase()\n\n // Then we take all characters that come before where the caret currently is.\n const leftHalfChars = normalizedRawValue\n .substr(0, currentCaretPosition)\n .split(emptyString)\n\n // Now we find all the characters in the left half that exist in the conformed input\n // This step ensures that we don't look for a character that was filtered out or rejected by `conformToMask`.\n const intersection = leftHalfChars.filter(\n (char) => normalizedConformedValue.indexOf(char) !== -1\n )\n\n // The last character in the intersection is the character we want to look for in the conformed\n // value and the one we want to adjust the caret close to\n targetChar = intersection[intersection.length - 1]\n\n // Calculate the number of mask characters in the previous placeholder\n // from the start of the string up to the place where the caret is\n const previousLeftMaskChars = previousPlaceholder\n .substr(0, intersection.length)\n .split(emptyString)\n .filter((char) => char !== placeholderChar).length\n\n // Calculate the number of mask characters in the current placeholder\n // from the start of the string up to the place where the caret is\n const leftMaskChars = placeholder\n .substr(0, intersection.length)\n .split(emptyString)\n .filter((char) => char !== placeholderChar).length\n\n // Has the number of mask characters up to the caret changed?\n const maskLengthChanged = leftMaskChars !== previousLeftMaskChars\n\n // Detect if `targetChar` is a mask character and has moved to the left\n const targetIsMaskMovingLeft =\n previousPlaceholder[intersection.length - 1] !== undefined &&\n placeholder[intersection.length - 2] !== undefined &&\n previousPlaceholder[intersection.length - 1] !== placeholderChar &&\n previousPlaceholder[intersection.length - 1] !==\n placeholder[intersection.length - 1] &&\n previousPlaceholder[intersection.length - 1] ===\n placeholder[intersection.length - 2]\n\n // If deleting and the `targetChar` `is a mask character and `maskLengthChanged` is true\n // or the mask is moving to the left, we can't use the selected `targetChar` any longer\n // if we are not at the end of the string.\n // In this case, change tracking strategy and track the character to the right of the caret.\n if (\n !isAddition &&\n (maskLengthChanged || targetIsMaskMovingLeft) &&\n previousLeftMaskChars > 0 &&\n placeholder.indexOf(targetChar) > -1 &&\n rawValue[currentCaretPosition] !== undefined\n ) {\n trackRightCharacter = true\n targetChar = rawValue[currentCaretPosition]\n }\n\n // It is possible that `targetChar` will appear multiple times in the conformed value.\n // We need to know not to select a character that looks like our target character from the placeholder or\n // the piped characters, so we inspect the piped characters and the placeholder to see if they contain\n // characters that match our target character.\n\n // If the `conformedValue` got piped, we need to know which characters were piped in so that when we look for\n // our `targetChar`, we don't select a piped char by mistake\n const pipedChars = indexesOfPipedChars.map(\n (index) => normalizedConformedValue[index]\n )\n\n // We need to know how many times the `targetChar` occurs in the piped characters.\n const countTargetCharInPipedChars = pipedChars.filter(\n (char) => char === targetChar\n ).length\n\n // We need to know how many times it occurs in the intersection\n const countTargetCharInIntersection = intersection.filter(\n (char) => char === targetChar\n ).length\n\n // We need to know if the placeholder contains characters that look like\n // our `targetChar`, so we don't select one of those by mistake.\n const countTargetCharInPlaceholder = placeholder\n .substr(0, placeholder.indexOf(placeholderChar))\n .split(emptyString)\n .filter(\n (char, index) =>\n // Check if `char` is the same as our `targetChar`, so we account for it\n char === targetChar &&\n // but also make sure that both the `rawValue` and placeholder don't have the same character at the same\n // index because if they are equal, that means we are already counting those characters in\n // `countTargetCharInIntersection`\n rawValue[index] !== char\n ).length\n\n // The number of times we need to see occurrences of the `targetChar` before we know it is the one we're looking\n // for is:\n const requiredNumberOfMatches =\n countTargetCharInPlaceholder +\n countTargetCharInIntersection +\n countTargetCharInPipedChars +\n // The character to the right of the caret isn't included in `intersection`\n // so add one if we are tracking the character to the right\n (trackRightCharacter ? 1 : 0)\n\n // Now we start looking for the location of the `targetChar`.\n // We keep looping forward and store the index in every iteration. Once we have encountered\n // enough occurrences of the target character, we break out of the loop\n // If are searching for the second `1` in `1214`, `startingSearchIndex` will point at `4`.\n let numberOfEncounteredMatches = 0\n for (let i = 0; i < conformedValueLength; i++) {\n const conformedValueChar = normalizedConformedValue[i]\n\n startingSearchIndex = i + 1\n\n if (conformedValueChar === targetChar) {\n numberOfEncounteredMatches++\n }\n\n if (numberOfEncounteredMatches >= requiredNumberOfMatches) {\n break\n }\n }\n }\n\n // At this point, if we simply return `startingSearchIndex` as the adjusted caret position,\n // most cases would be handled. However, we want to fast forward or rewind the caret to the\n // closest placeholder character if it happens to be in a non-editable spot. That's what the next\n // logic is for.\n\n // In case of addition, we fast forward.\n if (isAddition) {\n // We want to remember the last placeholder character encountered so that if the mask\n // contains more characters after the last placeholder character, we don't forward the caret\n // that far to the right. Instead, we stop it at the last encountered placeholder character.\n let lastPlaceholderChar = startingSearchIndex\n\n for (let i = startingSearchIndex; i <= placeholderLength; i++) {\n if (placeholder[i] === placeholderChar) {\n lastPlaceholderChar = i\n }\n\n if (\n // If we're adding, we can position the caret at the next placeholder character.\n placeholder[i] === placeholderChar ||\n // If a caret trap was set by a mask function, we need to stop at the trap.\n caretTrapIndexes.indexOf(i) !== -1 ||\n // This is the end of the placeholder. We cannot move any further. Let's put the caret there.\n i === placeholderLength\n ) {\n return lastPlaceholderChar\n }\n }\n } else {\n // In case of deletion, we rewind.\n if (trackRightCharacter) {\n // Searching for the character that was to the right of the caret\n // We start at `startingSearchIndex` - 1 because it includes one character extra to the right\n for (let i = startingSearchIndex - 1; i >= 0; i--) {\n // If tracking the character to the right of the cursor, we move to the left until\n // we found the character and then place the caret right before it\n\n if (\n // `targetChar` should be in `conformedValue`, since it was in `rawValue`, just\n // to the right of the caret\n conformedValue[i] === targetChar ||\n // If a caret trap was set by a mask function, we need to stop at the trap.\n caretTrapIndexes.indexOf(i) !== -1 ||\n // This is the beginning of the placeholder. We cannot move any further.\n // Let's put the caret there.\n i === 0\n ) {\n return i\n }\n }\n } else {\n // Searching for the first placeholder or caret trap to the left\n\n for (let i = startingSearchIndex; i >= 0; i--) {\n // If we're deleting, we stop the caret right before the placeholder character.\n // For example, for mask `(111) 11`, current conformed input `(456) 86`. If user\n // modifies input to `(456 86`. That is, they deleted the `)`, we place the caret\n // right after the first `6`\n\n if (\n // If we're deleting, we can position the caret right before the placeholder character\n placeholder[i - 1] === placeholderChar ||\n // If a caret trap was set by a mask function, we need to stop at the trap.\n caretTrapIndexes.indexOf(i) !== -1 ||\n // This is the beginning of the placeholder. We cannot move any further.\n // Let's put the caret there.\n i === 0\n ) {\n return i\n }\n }\n }\n }\n}\n"],"mappings":"AAAA,MA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AAC,GAAG,CAAC,CAAC,KAAKzC,eAAe,IAEtCG,gBAAgB,CAACwB,OAAO,CAACc,CAAC,CAAC,KAAK,CAAC,CAAC,IAGlCA,CAAC,KAAK,CAAC,EACP;UACA,OAAOA,CAAC;QACV;MACF;IACF;EACF;AACF","ignoreList":[]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { PropertiesTableProps } from '../../shared/types';
|
|
2
2
|
export declare const ModalProperties: PropertiesTableProps;
|
|
3
|
+
export declare const ModalPropertiesWithSnakeCase: PropertiesTableProps;
|
|
3
4
|
export declare const ModalEvents: PropertiesTableProps;
|
|
5
|
+
export declare const ModalEventsWithSnakeCase: PropertiesTableProps;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { toSnakeCase } from '../../shared/component-helper';
|
|
2
|
+
const transformPropertyNamesWithSnakeCase = properties => {
|
|
3
|
+
return Object.fromEntries(Object.entries(properties).map(([key, value]) => [key !== key.toLowerCase() ? `${key} / ${toSnakeCase(key)}` : key, value]));
|
|
4
|
+
};
|
|
1
5
|
export const ModalProperties = {
|
|
2
6
|
id: {
|
|
3
7
|
doc: 'The id used internal for the trigger button and Modal component.',
|
|
@@ -165,6 +169,7 @@ export const ModalProperties = {
|
|
|
165
169
|
status: 'optional'
|
|
166
170
|
}
|
|
167
171
|
};
|
|
172
|
+
export const ModalPropertiesWithSnakeCase = transformPropertyNamesWithSnakeCase(ModalProperties);
|
|
168
173
|
export const ModalEvents = {
|
|
169
174
|
onOpen: {
|
|
170
175
|
doc: 'This event gets triggered once the modal shows up. Returns the modal id: `{ id }`.',
|
|
@@ -182,4 +187,5 @@ export const ModalEvents = {
|
|
|
182
187
|
status: 'optional'
|
|
183
188
|
}
|
|
184
189
|
};
|
|
190
|
+
export const ModalEventsWithSnakeCase = transformPropertyNamesWithSnakeCase(ModalEvents);
|
|
185
191
|
//# sourceMappingURL=ModalDocs.js.map
|