@dnb/eufemia 10.71.0 → 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 +8 -0
- 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 +18 -22
- package/cjs/components/date-picker/DatePickerInput.js.map +1 -1
- package/cjs/components/date-picker/hooks/useDates.d.ts +1 -10
- package/cjs/components/date-picker/hooks/useDates.js +2 -40
- 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/text-mask/adjustCaretPosition.js +2 -2
- package/cjs/components/input-masked/text-mask/adjustCaretPosition.js.map +1 -1
- package/cjs/components/tooltip/TooltipContainer.js +2 -1
- package/cjs/components/tooltip/TooltipContainer.js.map +1 -1
- package/cjs/extensions/forms/utils/FormError.d.ts +3 -0
- 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/DatePickerFooter.d.ts +2 -2
- package/components/date-picker/DatePickerFooter.js.map +1 -1
- package/components/date-picker/DatePickerInput.js +18 -22
- package/components/date-picker/DatePickerInput.js.map +1 -1
- package/components/date-picker/hooks/useDates.d.ts +1 -10
- package/components/date-picker/hooks/useDates.js +2 -36
- 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/text-mask/adjustCaretPosition.js +2 -2
- package/components/input-masked/text-mask/adjustCaretPosition.js.map +1 -1
- package/components/tooltip/TooltipContainer.js +2 -1
- package/components/tooltip/TooltipContainer.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 +18 -22
- package/es/components/date-picker/DatePickerInput.js.map +1 -1
- package/es/components/date-picker/hooks/useDates.d.ts +1 -10
- package/es/components/date-picker/hooks/useDates.js +2 -36
- 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/text-mask/adjustCaretPosition.js +2 -2
- package/es/components/input-masked/text-mask/adjustCaretPosition.js.map +1 -1
- package/es/components/tooltip/TooltipContainer.js +2 -1
- package/es/components/tooltip/TooltipContainer.js.map +1 -1
- package/es/extensions/forms/utils/FormError.d.ts +3 -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/utils/FormError.d.ts +3 -0
- 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
|
@@ -5,22 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = useDates;
|
|
8
|
-
exports.pad = pad;
|
|
9
8
|
require("core-js/modules/web.dom-collections.iterator.js");
|
|
10
|
-
var _react =
|
|
9
|
+
var _react = require("react");
|
|
11
10
|
var _DatePickerCalc = require("../DatePickerCalc");
|
|
12
|
-
var _isValid = _interopRequireDefault(require("date-fns/isValid"));
|
|
13
|
-
var _format = _interopRequireDefault(require("date-fns/format"));
|
|
14
11
|
var _dateFns = require("date-fns");
|
|
15
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
12
|
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; }
|
|
19
13
|
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; }
|
|
20
14
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
21
15
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
22
16
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23
|
-
const useLayoutEffect = typeof window === 'undefined' ? _react.default.useEffect : _react.default.useLayoutEffect;
|
|
24
17
|
function useDates(dateProps, _ref) {
|
|
25
18
|
let {
|
|
26
19
|
dateFormat,
|
|
@@ -76,30 +69,12 @@ function useDates(dateProps, _ref) {
|
|
|
76
69
|
});
|
|
77
70
|
callback === null || callback === void 0 ? void 0 : callback(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, dates), newDates), months), correctedDates));
|
|
78
71
|
}, [dates, shouldCorrectDate, isRange]);
|
|
79
|
-
useLayoutEffect(() => {
|
|
80
|
-
const startDates = updateInputDates('start', dates.startDate);
|
|
81
|
-
const endDates = updateInputDates('end', dates.endDate);
|
|
82
|
-
setDates(currentDates => _objectSpread(_objectSpread(_objectSpread({}, currentDates), startDates), endDates));
|
|
83
|
-
}, [dates.startDate, dates.endDate]);
|
|
84
72
|
return {
|
|
85
73
|
dates,
|
|
86
74
|
updateDates,
|
|
87
75
|
previousDateProps
|
|
88
76
|
};
|
|
89
77
|
}
|
|
90
|
-
function updateInputDates(type, date) {
|
|
91
|
-
const updatedDates = {};
|
|
92
|
-
if ((0, _isValid.default)(date)) {
|
|
93
|
-
updatedDates[`__${type}Day`] = pad((0, _format.default)(date, 'dd'), 2);
|
|
94
|
-
updatedDates[`__${type}Month`] = pad((0, _format.default)(date, 'MM'), 2);
|
|
95
|
-
updatedDates[`__${type}Year`] = (0, _format.default)(date, 'yyyy');
|
|
96
|
-
} else if (date === undefined) {
|
|
97
|
-
updatedDates[`__${type}Day`] = null;
|
|
98
|
-
updatedDates[`__${type}Month`] = null;
|
|
99
|
-
updatedDates[`__${type}Year`] = null;
|
|
100
|
-
}
|
|
101
|
-
return updatedDates;
|
|
102
|
-
}
|
|
103
78
|
function mapDates(dateProps, _ref2) {
|
|
104
79
|
var _ref3, _convertStringToDate, _convertStringToDate2;
|
|
105
80
|
let {
|
|
@@ -140,16 +115,7 @@ function mapDates(dateProps, _ref2) {
|
|
|
140
115
|
minDate,
|
|
141
116
|
maxDate
|
|
142
117
|
}, correctedDates);
|
|
143
|
-
|
|
144
|
-
const hasValidEndDate = (0, _isValid.default)(dates.endDate);
|
|
145
|
-
return _objectSpread(_objectSpread({}, dates), {}, {
|
|
146
|
-
__startDay: hasValidStartDate ? pad((0, _format.default)(dates.startDate, 'dd'), 2) : null,
|
|
147
|
-
__startMonth: hasValidStartDate ? pad((0, _format.default)(dates.startDate, 'MM'), 2) : null,
|
|
148
|
-
__startYear: hasValidStartDate ? (0, _format.default)(dates.startDate, 'yyyy') : null,
|
|
149
|
-
__endDay: hasValidEndDate ? pad((0, _format.default)(dates.endDate, 'dd'), 2) : null,
|
|
150
|
-
__endMonth: hasValidEndDate ? pad((0, _format.default)(dates.endDate, 'MM'), 2) : null,
|
|
151
|
-
__endYear: hasValidEndDate ? (0, _format.default)(dates.endDate, 'yyyy') : null
|
|
152
|
-
});
|
|
118
|
+
return _objectSpread({}, dates);
|
|
153
119
|
}
|
|
154
120
|
function deriveDatesFromProps(_ref4) {
|
|
155
121
|
let {
|
|
@@ -247,8 +213,4 @@ function getStartDate(dateProps, previousDateProps) {
|
|
|
247
213
|
}
|
|
248
214
|
return undefined;
|
|
249
215
|
}
|
|
250
|
-
function pad(date, size) {
|
|
251
|
-
const dateWithPadding = '000000000' + date;
|
|
252
|
-
return dateWithPadding.substring(dateWithPadding.length - size);
|
|
253
|
-
}
|
|
254
216
|
//# sourceMappingURL=useDates.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDates.js","names":["_react","_interopRequireWildcard","require","_DatePickerCalc","_isValid","_interopRequireDefault","_format","_dateFns","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","ownKeys","keys","getOwnPropertySymbols","o","filter","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","_toPropertyKey","value","configurable","writable","_toPrimitive","Symbol","toPrimitive","TypeError","String","Number","useLayoutEffect","window","React","useEffect","useDates","dateProps","_ref","dateFormat","isRange","shouldCorrectDate","previousDateProps","setPreviousDateProps","useState","dates","setDates","mapDates","hasDatePropChanges","useMemo","some","date","dateProp","previousDate","convertedDateProp","convertStringToDate","convertedPreviousDate","Date","isSameDay","derivedDates","deriveDatesFromProps","currentDates","updateDates","useCallback","newDates","callback","_newDates$startDate","_newDates$endDate","correctedDates","correctDates","startDate","endDate","minDate","maxDate","months","updateMonths","startDates","updateInputDates","endDates","type","updatedDates","isValid","pad","format","undefined","_ref2","_ref3","_convertStringToDate","_convertStringToDate2","getDate","startMonth","endMonth","addMonths","hasValidStartDate","hasValidEndDate","__startDay","__startMonth","__startYear","__endDay","__endMonth","__endYear","_ref4","getStartDate","_ref5","isDisabled","_ref6","_ref7","_newDates$startMonth","_ref8","_newDates$endMonth","size","dateWithPadding","substring"],"sources":["../../../../../src/components/date-picker/hooks/useDates.ts"],"sourcesContent":["import React, { useCallback, useMemo, useState } from 'react'\nimport { convertStringToDate, isDisabled } from '../DatePickerCalc'\nimport isValid from 'date-fns/isValid'\nimport format from 'date-fns/format'\nimport { addMonths, isSameDay } from 'date-fns'\nimport { DateType } from '../DatePickerContext'\n\n// SSR warning fix: https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\nconst useLayoutEffect =\n typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect\n\nexport type DatePickerDateProps = {\n date?: DateType\n startDate?: DateType\n endDate?: DateType\n startMonth?: DateType\n endMonth?: DateType\n minDate?: DateType\n maxDate?: DateType\n hoverDate?: DateType | null\n}\n\ntype UseDatesOptions = {\n dateFormat: string\n isRange: boolean\n shouldCorrectDate: boolean\n}\n// TODO: Move to DatePickerInput\nexport type DatePickerInputDates = {\n __startDay?: string\n __startMonth?: string\n __startYear?: string\n __endDay?: string\n __endMonth?: string\n __endYear?: string\n}\n\nexport type DatePickerDates = {\n date?: DateType\n startDate?: Date\n endDate?: Date\n minDate?: Date\n maxDate?: Date\n startMonth?: Date\n endMonth?: Date\n hoverDate?: Date\n} & DatePickerInputDates\n\nexport default function useDates(\n dateProps: DatePickerDateProps,\n {\n dateFormat,\n isRange = false,\n shouldCorrectDate = false,\n }: UseDatesOptions\n) {\n const [previousDateProps, setPreviousDateProps] = useState(dateProps)\n const [dates, setDates] = useState<DatePickerDates>({\n ...mapDates(dateProps, {\n dateFormat,\n isRange,\n shouldCorrectDate,\n }),\n })\n\n const hasDatePropChanges = useMemo(\n () =>\n Object.keys(dateProps).some((date) => {\n const dateProp = dateProps[date]\n const previousDate = previousDateProps[date]\n\n const convertedDateProp = convertStringToDate(dateProp, {\n dateFormat,\n })\n const convertedPreviousDate = convertStringToDate(previousDate, {\n dateFormat,\n })\n // Make sure that same dates does not trigger a change\n // i.e. 2021-01-01 and new Date('2021-01-01')\n if (\n convertedDateProp instanceof Date &&\n convertedPreviousDate instanceof Date\n ) {\n return !isSameDay(convertedDateProp, convertedPreviousDate)\n }\n\n return dateProp !== previousDate\n }),\n [dateProps, previousDateProps, dateFormat]\n )\n\n // Update dates on prop change\n if (hasDatePropChanges) {\n const derivedDates = deriveDatesFromProps({\n dates,\n dateProps,\n previousDateProps,\n dateFormat,\n isRange,\n })\n\n setDates((currentDates) => ({ ...currentDates, ...derivedDates }))\n setPreviousDateProps(dateProps)\n }\n\n const updateDates = useCallback(\n (\n newDates: DatePickerDates,\n callback?: (dates: DatePickerDates) => void\n ) => {\n // Correct dates based on min and max date\n const correctedDates = shouldCorrectDate\n ? correctDates({\n startDate: newDates.startDate ?? dates.startDate,\n endDate: newDates.endDate ?? dates.endDate,\n minDate: dates.minDate,\n maxDate: dates.maxDate,\n isRange,\n })\n : {}\n\n // Update months based on month or start/end date changes\n const months = updateMonths({\n newDates,\n currentDates: dates,\n })\n\n setDates((currentDates) => {\n return {\n ...currentDates,\n ...newDates,\n ...months,\n ...correctedDates,\n }\n })\n\n callback?.({\n ...dates,\n ...newDates,\n ...months,\n ...correctedDates,\n })\n },\n [dates, shouldCorrectDate, isRange]\n )\n\n // Updated input dates based on start and end dates, move to DatePickerInput\n // TODO: Move to DatePickerInput\n useLayoutEffect(() => {\n const startDates = updateInputDates('start', dates.startDate)\n const endDates = updateInputDates('end', dates.endDate)\n\n setDates((currentDates) => ({\n ...currentDates,\n ...startDates,\n ...endDates,\n }))\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [dates.startDate, dates.endDate])\n\n return {\n dates,\n updateDates,\n previousDateProps,\n } as const\n}\n\n// TODO: Move to DatePickerInput\nfunction updateInputDates(type: 'start' | 'end', date: Date | undefined) {\n const updatedDates = {}\n\n if (isValid(date)) {\n updatedDates[`__${type}Day`] = pad(format(date, 'dd'), 2)\n updatedDates[`__${type}Month`] = pad(format(date, 'MM'), 2)\n updatedDates[`__${type}Year`] = format(date, 'yyyy')\n } else if (date === undefined) {\n updatedDates[`__${type}Day`] = null\n updatedDates[`__${type}Month`] = null\n updatedDates[`__${type}Year`] = null\n }\n\n return updatedDates\n}\n\nfunction mapDates(\n dateProps: DatePickerDateProps,\n {\n dateFormat,\n isRange,\n shouldCorrectDate,\n }: Omit<UseDatesOptions, 'isLinked'>\n) {\n const date = dateProps.date\n\n const startDate =\n typeof dateProps?.startDate !== 'undefined'\n ? getDate(dateProps.startDate, dateFormat)\n : typeof date !== 'undefined'\n ? getDate(date, dateFormat)\n : undefined\n\n const endDate = !isRange\n ? startDate\n : convertStringToDate(dateProps?.endDate, {\n dateFormat,\n }) || undefined\n\n // Ensure that the calendar view displays the correct start and end months, and to prevent date flickering bug\n const startMonth =\n convertStringToDate(dateProps.startMonth, {\n dateFormat,\n }) ??\n startDate ??\n new Date()\n\n const endMonth =\n convertStringToDate(dateProps.endMonth, {\n dateFormat: dateFormat,\n }) ?? (isRange ? endDate ?? addMonths(startMonth, 1) : startMonth)\n\n const minDate = convertStringToDate(dateProps.minDate, {\n dateFormat,\n })\n\n const maxDate = convertStringToDate(dateProps.maxDate, {\n dateFormat,\n })\n\n const correctedDates = shouldCorrectDate\n ? correctDates({ startDate, endDate, minDate, maxDate, isRange })\n : {}\n\n const dates = {\n date,\n startDate,\n endDate,\n startMonth,\n endMonth,\n minDate,\n maxDate,\n ...correctedDates,\n }\n\n const hasValidStartDate = isValid(dates.startDate)\n const hasValidEndDate = isValid(dates.endDate)\n\n return {\n ...dates,\n __startDay: hasValidStartDate\n ? pad(format(dates.startDate, 'dd'), 2)\n : null,\n __startMonth: hasValidStartDate\n ? pad(format(dates.startDate, 'MM'), 2)\n : null,\n __startYear: hasValidStartDate\n ? format(dates.startDate, 'yyyy')\n : null,\n __endDay: hasValidEndDate ? pad(format(dates.endDate, 'dd'), 2) : null,\n __endMonth: hasValidEndDate\n ? pad(format(dates.endDate, 'MM'), 2)\n : null,\n __endYear: hasValidEndDate ? format(dates.endDate, 'yyyy') : null,\n }\n}\n\nfunction deriveDatesFromProps({\n dates,\n dateProps,\n previousDateProps,\n dateFormat,\n isRange,\n}: {\n dates: DatePickerDates\n dateProps: DatePickerDateProps\n previousDateProps: DatePickerDateProps\n dateFormat: UseDatesOptions['dateFormat']\n isRange: UseDatesOptions['isRange']\n}) {\n const derivedDates: DatePickerDates = {}\n\n const startDate = getStartDate(dateProps, previousDateProps)\n\n // Handle updates related to date and startDate changes when not in range mode\n if (typeof startDate !== 'undefined' && startDate !== dates.startDate) {\n derivedDates.startDate =\n convertStringToDate(startDate, {\n dateFormat,\n }) || undefined\n\n // Set endDate and startMonth to startDate if not in range mode\n if (!isRange) {\n derivedDates.startMonth =\n convertStringToDate(startDate, {\n dateFormat,\n }) || undefined\n\n derivedDates.endDate = derivedDates.startDate\n }\n }\n\n // update endDate based on endDate prop if in range mode\n if (\n isRange &&\n typeof dateProps.endDate !== 'undefined' &&\n dateProps.endDate !== dates.endDate\n ) {\n derivedDates.endDate =\n convertStringToDate(dateProps.endDate, {\n dateFormat,\n }) || undefined\n }\n\n // Handle startMonth/endMonth\n if (\n typeof dateProps.startMonth !== 'undefined' &&\n dateProps.startMonth !== previousDateProps.startMonth\n ) {\n derivedDates.startMonth = convertStringToDate(dateProps.startMonth, {\n dateFormat,\n })\n }\n if (\n typeof dateProps.endMonth !== 'undefined' &&\n dateProps.endMonth !== previousDateProps.endMonth\n ) {\n derivedDates.endMonth = convertStringToDate(dateProps.endMonth, {\n dateFormat,\n })\n }\n\n // Handle minDate/maxDate\n if (\n typeof dateProps.minDate !== 'undefined' &&\n dateProps.minDate !== previousDateProps.minDate\n ) {\n derivedDates.minDate = convertStringToDate(dateProps.minDate, {\n dateFormat,\n })\n }\n if (\n typeof dateProps.maxDate !== 'undefined' &&\n dateProps.maxDate !== previousDateProps.maxDate\n ) {\n derivedDates.maxDate = convertStringToDate(dateProps.maxDate, {\n dateFormat,\n })\n }\n\n return derivedDates\n}\n\nfunction correctDates({\n startDate,\n endDate,\n minDate,\n maxDate,\n isRange,\n}: {\n startDate: Date\n endDate: Date\n minDate: Date\n maxDate: Date\n isRange: boolean\n}) {\n const correctedDates = {}\n\n if (isDisabled(startDate, minDate, maxDate)) {\n correctedDates['startDate'] = minDate\n }\n if (isDisabled(endDate, minDate, maxDate)) {\n // state.endDate is only used by the input if range is set to true.\n // this is done to make maxDate correction work if the input is not a range and only maxDate is defined.\n if (!isRange && !minDate) {\n correctedDates['startDate'] = maxDate\n } else {\n correctedDates['endDate'] = maxDate\n }\n }\n\n return correctedDates\n}\n\nfunction updateMonths({\n newDates,\n currentDates,\n}: {\n newDates: DatePickerDates\n currentDates: DatePickerDates\n}) {\n const startMonth =\n newDates.startMonth ?? newDates.startDate ?? currentDates.startMonth\n const endMonth =\n newDates.endMonth ?? newDates.endDate ?? currentDates.endMonth\n\n return {\n startMonth,\n endMonth,\n }\n}\n\nfunction getDate(date: DateType, dateFormat: string) {\n return date instanceof Date\n ? date\n : convertStringToDate(date ?? '', {\n dateFormat,\n })\n}\n\nfunction getStartDate(\n dateProps: DatePickerDateProps,\n previousDateProps: DatePickerDateProps\n) {\n // prioritize startDate over date if provided\n if (\n typeof dateProps.startDate !== 'undefined' &&\n dateProps.startDate !== previousDateProps.startDate\n ) {\n return dateProps.startDate\n }\n\n if (\n typeof dateProps.date !== 'undefined' &&\n dateProps.date !== previousDateProps.date\n ) {\n return dateProps.date\n }\n\n return undefined\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,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AAA+C,SAAAG,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,yBAAAH,CAAA,6BAAAI,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAD,wBAAA,YAAAA,CAAAH,CAAA,WAAAA,CAAA,GAAAM,CAAA,GAAAD,CAAA,KAAAL,CAAA;AAAA,SAAAP,wBAAAO,CAAA,EAAAK,CAAA,SAAAA,CAAA,IAAAL,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAE,OAAA,EAAAF,CAAA,QAAAM,CAAA,GA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AACc,IAAI;EACvB;EAEA,OAAOiC,SAAS;AAClB;AAEO,SAASF,GAAGA,CAAC/B,IAAY,EAAE2D,IAAY,EAAE;EAC9C,MAAMC,eAAe,GAAG,WAAW,GAAG5D,IAAI;EAE1C,OAAO4D,eAAe,CAACC,SAAS,CAACD,eAAe,CAAC9F,MAAM,GAAG6F,IAAI,CAAC;AACjE","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useDates.js","names":["_react","require","_DatePickerCalc","_dateFns","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","useDates","dateProps","_ref","dateFormat","isRange","shouldCorrectDate","previousDateProps","setPreviousDateProps","useState","dates","setDates","mapDates","hasDatePropChanges","useMemo","some","date","dateProp","previousDate","convertedDateProp","convertStringToDate","convertedPreviousDate","Date","isSameDay","derivedDates","deriveDatesFromProps","currentDates","updateDates","useCallback","newDates","callback","_newDates$startDate","_newDates$endDate","correctedDates","correctDates","startDate","endDate","minDate","maxDate","months","updateMonths","_ref2","_ref3","_convertStringToDate","_convertStringToDate2","getDate","undefined","startMonth","endMonth","addMonths","_ref4","getStartDate","_ref5","isDisabled","_ref6","_ref7","_newDates$startMonth","_ref8","_newDates$endMonth"],"sources":["../../../../../src/components/date-picker/hooks/useDates.ts"],"sourcesContent":["import { useCallback, useMemo, useState } from 'react'\nimport { convertStringToDate, isDisabled } from '../DatePickerCalc'\nimport { addMonths, isSameDay } from 'date-fns'\nimport { DateType } from '../DatePickerContext'\n\nexport type DatePickerDateProps = {\n date?: DateType\n startDate?: DateType\n endDate?: DateType\n startMonth?: DateType\n endMonth?: DateType\n minDate?: DateType\n maxDate?: DateType\n hoverDate?: DateType | null\n}\n\ntype UseDatesOptions = {\n dateFormat: string\n isRange: boolean\n shouldCorrectDate: boolean\n}\n\nexport type DatePickerDates = {\n date?: DateType\n startDate?: Date\n endDate?: Date\n minDate?: Date\n maxDate?: Date\n startMonth?: Date\n endMonth?: Date\n hoverDate?: Date\n}\n\nexport default function useDates(\n dateProps: DatePickerDateProps,\n {\n dateFormat,\n isRange = false,\n shouldCorrectDate = false,\n }: UseDatesOptions\n) {\n const [previousDateProps, setPreviousDateProps] = useState(dateProps)\n const [dates, setDates] = useState<DatePickerDates>({\n ...mapDates(dateProps, {\n dateFormat,\n isRange,\n shouldCorrectDate,\n }),\n })\n\n const hasDatePropChanges = useMemo(\n () =>\n Object.keys(dateProps).some((date) => {\n const dateProp = dateProps[date]\n const previousDate = previousDateProps[date]\n\n const convertedDateProp = convertStringToDate(dateProp, {\n dateFormat,\n })\n const convertedPreviousDate = convertStringToDate(previousDate, {\n dateFormat,\n })\n // Make sure that same dates does not trigger a change\n // i.e. 2021-01-01 and new Date('2021-01-01')\n if (\n convertedDateProp instanceof Date &&\n convertedPreviousDate instanceof Date\n ) {\n return !isSameDay(convertedDateProp, convertedPreviousDate)\n }\n\n return dateProp !== previousDate\n }),\n [dateProps, previousDateProps, dateFormat]\n )\n\n // Update dates on prop change\n if (hasDatePropChanges) {\n const derivedDates = deriveDatesFromProps({\n dates,\n dateProps,\n previousDateProps,\n dateFormat,\n isRange,\n })\n\n setDates((currentDates) => ({ ...currentDates, ...derivedDates }))\n setPreviousDateProps(dateProps)\n }\n\n const updateDates = useCallback(\n (\n newDates: DatePickerDates,\n callback?: (dates: DatePickerDates) => void\n ) => {\n // Correct dates based on min and max date\n const correctedDates = shouldCorrectDate\n ? correctDates({\n startDate: newDates.startDate ?? dates.startDate,\n endDate: newDates.endDate ?? dates.endDate,\n minDate: dates.minDate,\n maxDate: dates.maxDate,\n isRange,\n })\n : {}\n\n // Update months based on month or start/end date changes\n const months = updateMonths({\n newDates,\n currentDates: dates,\n })\n\n setDates((currentDates) => {\n return {\n ...currentDates,\n ...newDates,\n ...months,\n ...correctedDates,\n }\n })\n\n callback?.({\n ...dates,\n ...newDates,\n ...months,\n ...correctedDates,\n })\n },\n [dates, shouldCorrectDate, isRange]\n )\n\n return {\n dates,\n updateDates,\n previousDateProps,\n } as const\n}\n\nfunction mapDates(\n dateProps: DatePickerDateProps,\n {\n dateFormat,\n isRange,\n shouldCorrectDate,\n }: Omit<UseDatesOptions, 'isLinked'>\n) {\n const date = dateProps.date\n\n const startDate =\n typeof dateProps?.startDate !== 'undefined'\n ? getDate(dateProps.startDate, dateFormat)\n : typeof date !== 'undefined'\n ? getDate(date, dateFormat)\n : undefined\n\n const endDate = !isRange\n ? startDate\n : convertStringToDate(dateProps?.endDate, {\n dateFormat,\n }) || undefined\n\n // Ensure that the calendar view displays the correct start and end months, and to prevent date flickering bug\n const startMonth =\n convertStringToDate(dateProps.startMonth, {\n dateFormat,\n }) ??\n startDate ??\n new Date()\n\n const endMonth =\n convertStringToDate(dateProps.endMonth, {\n dateFormat: dateFormat,\n }) ?? (isRange ? endDate ?? addMonths(startMonth, 1) : startMonth)\n\n const minDate = convertStringToDate(dateProps.minDate, {\n dateFormat,\n })\n\n const maxDate = convertStringToDate(dateProps.maxDate, {\n dateFormat,\n })\n\n const correctedDates = shouldCorrectDate\n ? correctDates({ startDate, endDate, minDate, maxDate, isRange })\n : {}\n\n const dates = {\n date,\n startDate,\n endDate,\n startMonth,\n endMonth,\n minDate,\n maxDate,\n ...correctedDates,\n }\n\n return {\n ...dates,\n }\n}\n\nfunction deriveDatesFromProps({\n dates,\n dateProps,\n previousDateProps,\n dateFormat,\n isRange,\n}: {\n dates: DatePickerDates\n dateProps: DatePickerDateProps\n previousDateProps: DatePickerDateProps\n dateFormat: UseDatesOptions['dateFormat']\n isRange: UseDatesOptions['isRange']\n}) {\n const derivedDates: DatePickerDates = {}\n\n const startDate = getStartDate(dateProps, previousDateProps)\n\n // Handle updates related to date and startDate changes when not in range mode\n if (typeof startDate !== 'undefined' && startDate !== dates.startDate) {\n derivedDates.startDate =\n convertStringToDate(startDate, {\n dateFormat,\n }) || undefined\n\n // Set endDate and startMonth to startDate if not in range mode\n if (!isRange) {\n derivedDates.startMonth =\n convertStringToDate(startDate, {\n dateFormat,\n }) || undefined\n\n derivedDates.endDate = derivedDates.startDate\n }\n }\n\n // update endDate based on endDate prop if in range mode\n if (\n isRange &&\n typeof dateProps.endDate !== 'undefined' &&\n dateProps.endDate !== dates.endDate\n ) {\n derivedDates.endDate =\n convertStringToDate(dateProps.endDate, {\n dateFormat,\n }) || undefined\n }\n\n // Handle startMonth/endMonth\n if (\n typeof dateProps.startMonth !== 'undefined' &&\n dateProps.startMonth !== previousDateProps.startMonth\n ) {\n derivedDates.startMonth = convertStringToDate(dateProps.startMonth, {\n dateFormat,\n })\n }\n if (\n typeof dateProps.endMonth !== 'undefined' &&\n dateProps.endMonth !== previousDateProps.endMonth\n ) {\n derivedDates.endMonth = convertStringToDate(dateProps.endMonth, {\n dateFormat,\n })\n }\n\n // Handle minDate/maxDate\n if (\n typeof dateProps.minDate !== 'undefined' &&\n dateProps.minDate !== previousDateProps.minDate\n ) {\n derivedDates.minDate = convertStringToDate(dateProps.minDate, {\n dateFormat,\n })\n }\n if (\n typeof dateProps.maxDate !== 'undefined' &&\n dateProps.maxDate !== previousDateProps.maxDate\n ) {\n derivedDates.maxDate = convertStringToDate(dateProps.maxDate, {\n dateFormat,\n })\n }\n\n return derivedDates\n}\n\nfunction correctDates({\n startDate,\n endDate,\n minDate,\n maxDate,\n isRange,\n}: {\n startDate: Date\n endDate: Date\n minDate: Date\n maxDate: Date\n isRange: boolean\n}) {\n const correctedDates = {}\n\n if (isDisabled(startDate, minDate, maxDate)) {\n correctedDates['startDate'] = minDate\n }\n if (isDisabled(endDate, minDate, maxDate)) {\n // state.endDate is only used by the input if range is set to true.\n // this is done to make maxDate correction work if the input is not a range and only maxDate is defined.\n if (!isRange && !minDate) {\n correctedDates['startDate'] = maxDate\n } else {\n correctedDates['endDate'] = maxDate\n }\n }\n\n return correctedDates\n}\n\nfunction updateMonths({\n newDates,\n currentDates,\n}: {\n newDates: DatePickerDates\n currentDates: DatePickerDates\n}) {\n const startMonth =\n newDates.startMonth ?? newDates.startDate ?? currentDates.startMonth\n const endMonth =\n newDates.endMonth ?? newDates.endDate ?? currentDates.endMonth\n\n return {\n startMonth,\n endMonth,\n }\n}\n\nfunction getDate(date: DateType, dateFormat: string) {\n return date instanceof Date\n ? date\n : convertStringToDate(date ?? '', {\n dateFormat,\n })\n}\n\nfunction getStartDate(\n dateProps: DatePickerDateProps,\n previousDateProps: DatePickerDateProps\n) {\n // prioritize startDate over date if provided\n if (\n typeof dateProps.startDate !== 'undefined' &&\n dateProps.startDate !== previousDateProps.startDate\n ) {\n return dateProps.startDate\n }\n\n if (\n typeof dateProps.date !== 'undefined' &&\n dateProps.date !== previousDateProps.date\n ) {\n return dateProps.date\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAA+C,SAAAG,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAZ,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EAAAb,CAAA,UAAAC,CAAA,WAAAW,SAAA,CAAAZ,CAAA,IAAAY,SAAA,CAAAZ,CAAA,QAAAA,CAAA,OAAAF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AACiC,SAAS,KAAK5B,iBAAiB,CAAC4B,SAAS,EACnD;IACA,OAAOjC,SAAS,CAACiC,SAAS;EAC5B;EAEA,IACE,OAAOjC,SAAS,CAACc,IAAI,KAAK,WAAW,IACrCd,SAAS,CAACc,IAAI,KAAKT,iBAAiB,CAACS,IAAI,EACzC;IACA,OAAOd,SAAS,CAACc,IAAI;EACvB;EAEA,OAAO8B,SAAS;AAClB","ignoreList":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DatePickerDates } from './useDates';
|
|
2
|
+
export type DatePickerInputDates = {
|
|
3
|
+
startDay?: string;
|
|
4
|
+
startMonth?: string;
|
|
5
|
+
startYear?: string;
|
|
6
|
+
endDay?: string;
|
|
7
|
+
endMonth?: string;
|
|
8
|
+
endYear?: string;
|
|
9
|
+
};
|
|
10
|
+
export default function useInputDates({ startDate, endDate, }: Pick<DatePickerDates, 'startDate' | 'endDate'>): {
|
|
11
|
+
inputDates: DatePickerInputDates;
|
|
12
|
+
updateInputDates: (dates: DatePickerInputDates) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare function pad(date: string, size: number): string;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = useInputDates;
|
|
8
|
+
exports.pad = pad;
|
|
9
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
10
|
+
var _dateFns = require("date-fns");
|
|
11
|
+
var _react = require("react");
|
|
12
|
+
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; }
|
|
13
|
+
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; }
|
|
14
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
16
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
17
|
+
function useInputDates(_ref) {
|
|
18
|
+
let {
|
|
19
|
+
startDate,
|
|
20
|
+
endDate
|
|
21
|
+
} = _ref;
|
|
22
|
+
const [previousDates, setPreviousDates] = (0, _react.useState)({
|
|
23
|
+
startDate,
|
|
24
|
+
endDate
|
|
25
|
+
});
|
|
26
|
+
const [inputDates, setInputDates] = (0, _react.useState)({
|
|
27
|
+
startDay: formatInputDate('day', startDate),
|
|
28
|
+
startMonth: formatInputDate('month', startDate),
|
|
29
|
+
startYear: formatInputDate('year', startDate),
|
|
30
|
+
endDay: formatInputDate('day', endDate),
|
|
31
|
+
endMonth: formatInputDate('month', endDate),
|
|
32
|
+
endYear: formatInputDate('year', endDate)
|
|
33
|
+
});
|
|
34
|
+
const hasStartDateChange = startDate !== previousDates.startDate;
|
|
35
|
+
const hasEndDateChange = endDate !== previousDates.endDate;
|
|
36
|
+
if (hasStartDateChange || hasEndDateChange) {
|
|
37
|
+
setInputDates(currentInputDates => _objectSpread(_objectSpread(_objectSpread({}, currentInputDates), hasStartDateChange && getInputDates('start', startDate)), hasEndDateChange && getInputDates('end', endDate)));
|
|
38
|
+
setPreviousDates({
|
|
39
|
+
startDate,
|
|
40
|
+
endDate
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const updateInputDates = (0, _react.useCallback)(dates => {
|
|
44
|
+
setInputDates(current => _objectSpread(_objectSpread({}, current), dates));
|
|
45
|
+
}, []);
|
|
46
|
+
return {
|
|
47
|
+
inputDates,
|
|
48
|
+
updateInputDates
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const inputDateFormatter = {
|
|
52
|
+
day: date => pad((0, _dateFns.format)(date, 'dd'), 2),
|
|
53
|
+
month: date => pad((0, _dateFns.format)(date, 'MM'), 2),
|
|
54
|
+
year: date => (0, _dateFns.format)(date, 'yyyy')
|
|
55
|
+
};
|
|
56
|
+
function formatInputDate(type, date) {
|
|
57
|
+
return (0, _dateFns.isValid)(date) ? inputDateFormatter[type](date) : null;
|
|
58
|
+
}
|
|
59
|
+
function getInputDates(type, date) {
|
|
60
|
+
if ((0, _dateFns.isValid)(date)) {
|
|
61
|
+
return {
|
|
62
|
+
[`${type}Day`]: formatInputDate('day', date),
|
|
63
|
+
[`${type}Month`]: formatInputDate('month', date),
|
|
64
|
+
[`${type}Year`]: formatInputDate('year', date)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (date === undefined) {
|
|
68
|
+
return {
|
|
69
|
+
[`${type}Day`]: null,
|
|
70
|
+
[`${type}Month`]: null,
|
|
71
|
+
[`${type}Year`]: null
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {};
|
|
75
|
+
}
|
|
76
|
+
function pad(date, size) {
|
|
77
|
+
const dateWithPadding = '000000000' + date;
|
|
78
|
+
return dateWithPadding.substring(dateWithPadding.length - size);
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=useInputDates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInputDates.js","names":["_dateFns","require","_react","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","useInputDates","_ref","startDate","endDate","previousDates","setPreviousDates","useState","inputDates","setInputDates","startDay","formatInputDate","startMonth","startYear","endDay","endMonth","endYear","hasStartDateChange","hasEndDateChange","currentInputDates","getInputDates","updateInputDates","useCallback","dates","current","inputDateFormatter","day","date","pad","format","month","year","type","isValid","undefined","size","dateWithPadding","substring"],"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,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAA6C,SAAAE,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAZ,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EAAAb,CAAA,UAAAC,CAAA,WAAAW,SAAA,CAAAZ,CAAA,IAAAY,SAAA,CAAAZ,CAAA,QAAAA,CAAA,OAAAF,OAAA,CAAAI,MAAA,CAAAD,CA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M,GAAGoD,IAAI,CAAC;AACjE","ignoreList":[]}
|
|
@@ -47,9 +47,9 @@ function adjustCaretPosition(_ref) {
|
|
|
47
47
|
targetChar = intersection[intersection.length - 1];
|
|
48
48
|
const previousLeftMaskChars = previousPlaceholder.substr(0, intersection.length).split(emptyString).filter(char => char !== placeholderChar).length;
|
|
49
49
|
const leftMaskChars = placeholder.substr(0, intersection.length).split(emptyString).filter(char => char !== placeholderChar).length;
|
|
50
|
-
const
|
|
50
|
+
const maskLengthChanged = leftMaskChars !== previousLeftMaskChars;
|
|
51
51
|
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];
|
|
52
|
-
if (!isAddition && (
|
|
52
|
+
if (!isAddition && (maskLengthChanged || targetIsMaskMovingLeft) && previousLeftMaskChars > 0 && placeholder.indexOf(targetChar) > -1 && rawValue[currentCaretPosition] !== undefined) {
|
|
53
53
|
trackRightCharacter = true;
|
|
54
54
|
targetChar = rawValue[currentCaretPosition];
|
|
55
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adjustCaretPosition.js","names":["defaultArray","emptyString","adjustCaretPosition","_ref","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;AAEP,SAASC,mBAAmBA,CAAAC,IAAA,EAWxC;EAAA,IAXyC;IAC1CC,sBAAsB,GAAGH,WAAW;IACpCI,mBAAmB,GAAGJ,WAAW;IACjCK,oBAAoB,GAAG,CAAC;IACxBC,cAAc;IACdC,QAAQ;IACRC,eAAe;IACfC,WAAW;IACXC,mBAAmB,GAAGX,YAAY;IAClCY,gBAAgB,GAAGZ,YAAY;IAC/Ba,iBAAiB,GAAG;EACtB,CAAC,GAAAV,IAAA;EACC,IAAIG,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,o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AC,EAAEA,CAAC,EAAE,EAAE;QAIjD,IAGE3C,cAAc,CAAC2C,CAAC,CAAC,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","_ref","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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K,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":[]}
|
|
@@ -159,7 +159,8 @@ function TooltipContainer(props) {
|
|
|
159
159
|
};
|
|
160
160
|
if (stylesFromPosition[position]) {
|
|
161
161
|
stylesFromPosition[position]();
|
|
162
|
-
}
|
|
162
|
+
}
|
|
163
|
+
if (stylesFromArrow[arrow]) {
|
|
163
164
|
stylesFromArrow[arrow]();
|
|
164
165
|
}
|
|
165
166
|
const rightOffset = parseFloat(String(style.left)) + elementWidth - window.innerWidth;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TooltipContainer.js","names":["_react","_interopRequireDefault","require","_componentHelper","_helpers","_classnames","e","__esModule","default","_extends","Object","assign","bind","n","arguments","length","t","r","hasOwnProperty","call","apply","ownKeys","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","_objectSpread","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","TypeError","String","Number","TooltipContainer","props","internalId","active","attributes","arrow","position","align","hideDelay","fixedPosition","noAnimation","skipPortal","useHover","children","targetElement","target","style","setStyle","React","useState","hover","setHover","isActive","isTrue","wasActive","makeActive","renewStyles","forceRerender","getBodySize","elementRef","useRef","offset","debounceTimeout","resizeObserver","document","width","height","body","getBoundingClientRect","clearTimers","clearTimeout","current","useLayoutEffect","addPositionObserver","ResizeObserver","setTimeout","observe","removePositionObserver","_resizeObserver$curre","disconnect","offsetLeft","offsetTop","element","window","alignOffset","elementWidth","offsetWidth","elementHeight","offsetHeight","rect","targetBodySize","getOffsetLeft","getOffsetTop","scrollY","undefined","pageYOffset","scrollX","pageXOffset","top","useMouseWhen","mousePos","left","widthBased","topHorizontal","leftVertical","stylesFromPosition","right","bottom","stylesFromArrow","rightOffset","parseFloat","innerWidth","handleMouseEnter","handleMouseLeave","handlePropagation","stopPropagation","createElement","role","ref","onMouseEnter","onMouseLeave","onMouseMove","onMouseDown","onTouchStart","className","classnames","id"],"sources":["../../../../src/components/tooltip/TooltipContainer.tsx"],"sourcesContent":["/**\n * Web Tooltip Component\n *\n */\n\nimport React from 'react'\nimport { isTrue } from '../../shared/component-helper'\nimport { getOffsetLeft, getOffsetTop } from '../../shared/helpers'\nimport classnames from 'classnames'\nimport { TooltipProps } from './types'\n\ntype TooltipContainerProps = {\n targetElement: HTMLElement\n style?: React.CSSProperties\n useHover?: boolean\n internalId?: string\n attributes?: Record<string, unknown> & { style: React.CSSProperties }\n}\n\nexport default function TooltipContainer(\n props: TooltipProps & TooltipContainerProps\n) {\n const {\n internalId,\n active,\n attributes,\n arrow,\n position,\n align,\n hideDelay,\n fixedPosition,\n noAnimation,\n skipPortal,\n useHover,\n children,\n targetElement: target,\n } = props\n\n const [style, setStyle] = React.useState(null)\n const [hover, setHover] = React.useState(false)\n const isActive = isTrue(active) || hover\n const [wasActive, makeActive] = React.useState(false)\n const [renewStyles, forceRerender] = React.useState(getBodySize)\n\n const elementRef = React.useRef<HTMLSpanElement>(null)\n const offset = React.useRef(16)\n const debounceTimeout = React.useRef<NodeJS.Timeout>()\n const resizeObserver = React.useRef<ResizeObserver>(null)\n\n function getBodySize() {\n if (!isActive || typeof document === 'undefined') {\n return 0 // stop here\n }\n\n const { width, height } = document.body.getBoundingClientRect()\n\n return width + height\n }\n\n const clearTimers = () => {\n clearTimeout(debounceTimeout.current)\n }\n\n React.useLayoutEffect(() => {\n const addPositionObserver = () => {\n if (resizeObserver.current || typeof document === 'undefined') {\n return // stop here\n }\n\n try {\n resizeObserver.current = new ResizeObserver(() => {\n clearTimers()\n debounceTimeout.current = setTimeout(\n () => forceRerender(getBodySize()),\n 100\n )\n })\n\n resizeObserver.current.observe(document.body)\n } catch (e) {\n //\n }\n }\n const removePositionObserver = () => {\n clearTimers()\n resizeObserver.current?.disconnect()\n }\n\n if (isActive) {\n makeActive(true)\n addPositionObserver()\n } else {\n removePositionObserver()\n }\n\n return removePositionObserver\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isActive])\n\n const offsetLeft = React.useRef(0)\n const offsetTop = React.useRef(0)\n\n React.useLayoutEffect(() => {\n if (!isActive) {\n /**\n * This \"resets\" the position between elements,\n * when not active. Else it will always first show on the older position.\n */\n if (wasActive) {\n clearTimeout(debounceTimeout.current)\n debounceTimeout.current = setTimeout(\n () => setStyle(null),\n hideDelay\n )\n }\n return // stop here\n }\n\n const element = elementRef?.current\n\n if (\n typeof window === 'undefined' ||\n !element ||\n !target?.getBoundingClientRect\n ) {\n return // stop here\n }\n\n let alignOffset = 0\n\n const elementWidth = element.offsetWidth\n const elementHeight = element.offsetHeight\n const rect = target.getBoundingClientRect()\n const targetBodySize = {\n width: target.offsetWidth,\n height: target.offsetHeight,\n }\n\n // fix for svg\n if (!target.offsetHeight) {\n targetBodySize.width = rect.width\n targetBodySize.height = rect.height\n }\n\n if (skipPortal && (!offsetLeft.current || !offsetTop.current)) {\n offsetLeft.current = getOffsetLeft(element) - offset.current\n offsetTop.current = getOffsetTop(element) - offset.current\n }\n\n const scrollY =\n window.scrollY !== undefined ? window.scrollY : window.pageYOffset\n const scrollX =\n window.scrollX !== undefined ? window.scrollX : window.pageXOffset\n const top =\n (isTrue(fixedPosition) ? 0 : scrollY) + rect.top - offsetTop.current\n\n // Use Mouse position when target is too wide\n const useMouseWhen = targetBodySize.width > 400\n const mousePos =\n getOffsetLeft(target) +\n rect.left / 2 +\n (element ? element.offsetWidth : 0)\n const widthBased = scrollX + rect.left\n const left =\n (useMouseWhen && mousePos < targetBodySize.width\n ? mousePos\n : widthBased) - offsetLeft.current\n\n const style = { ...props.style }\n\n if (align === 'left') {\n alignOffset = -targetBodySize.width / 2\n } else if (align === 'right') {\n alignOffset = targetBodySize.width / 2\n }\n\n const topHorizontal =\n top + targetBodySize.height / 2 - elementHeight / 2\n const leftVertical =\n left - elementWidth / 2 + targetBodySize.width / 2 + alignOffset\n\n const stylesFromPosition = {\n left: () => {\n style.top = topHorizontal\n style.left = left - elementWidth - offset.current\n },\n right: () => {\n style.top = topHorizontal\n style.left = left + targetBodySize.width + offset.current\n },\n top: () => {\n style.left = leftVertical\n style.top = top - elementHeight - offset.current\n },\n bottom: () => {\n style.left = leftVertical\n style.top = top + targetBodySize.height + offset.current\n },\n }\n\n const stylesFromArrow = {\n left: () => {\n style.left =\n left + targetBodySize.width / 2 - offset.current + alignOffset\n },\n right: () => {\n style.left =\n left -\n elementWidth +\n targetBodySize.width / 2 +\n offset.current +\n alignOffset\n },\n top: () => {\n style.top = top + targetBodySize.height / 2 - offset.current\n },\n bottom: () => {\n style.top =\n top + targetBodySize.height / 2 - elementHeight + offset.current\n },\n }\n\n if (stylesFromPosition[position]) {\n stylesFromPosition[position]()\n } else if (stylesFromArrow[arrow]) {\n stylesFromArrow[arrow]()\n }\n\n const rightOffset =\n parseFloat(String(style.left)) + elementWidth - window.innerWidth\n if (rightOffset > 0) {\n style.left = window.innerWidth - elementWidth\n }\n\n if (parseFloat(String(style.left)) < 0) {\n style.left = 0\n }\n if (parseFloat(String(style.top)) < 0) {\n style.top = 0\n }\n\n setStyle(style)\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [active, arrow, position, children, renewStyles])\n\n const handleMouseEnter = () => {\n if (isTrue(active) && useHover !== false) {\n setHover(true)\n }\n }\n\n const handleMouseLeave = () => {\n if (useHover !== false) {\n setHover(false)\n }\n }\n\n /**\n * By stopping propagation, we allow the user to select text when Tooltip is used in the Slider component\n */\n const handlePropagation = (e: React.SyntheticEvent) =>\n e.stopPropagation()\n\n return (\n <span\n role=\"tooltip\"\n aria-hidden={target ? true : undefined} // make sure SR does not find it in the DOM, because we use \"aria-describedby\" for that\n ref={elementRef}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onMouseMove={handlePropagation}\n onMouseDown={handlePropagation}\n onTouchStart={handlePropagation}\n {...attributes}\n className={classnames(\n attributes?.className,\n isTrue(noAnimation) && 'dnb-tooltip--no-animation',\n isTrue(fixedPosition) && 'dnb-tooltip--fixed',\n isActive && 'dnb-tooltip--active',\n !isActive && wasActive && 'dnb-tooltip--hide'\n )}\n style={{ ...style, ...attributes.style }}\n >\n {arrow && (\n <span\n className={classnames(\n 'dnb-tooltip__arrow',\n `dnb-tooltip__arrow__arrow--${arrow}`,\n `dnb-tooltip__arrow__position--${position}`\n )}\n />\n )}\n\n <span id={internalId} className=\"dnb-tooltip__content\">\n {children}\n </span>\n </span>\n )\n}\n"],"mappings":";;;;;;;AAKA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAAmC,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,SAAA,WAAAA,QAAA,GAAAC,MAAA,CAAAC,MAAA,GAAAD,MAAA,CAAAC,MAAA,CAAAC,IAAA,eAAAC,CAAA,aAAAP,CAAA,MAAAA,CAAA,GAAAQ,SAAA,CAAAC,MAAA,EAAAT,CAAA,UAAAU,CAAA,GAAAF,SAAA,CAAAR,CAAA,YAAAW,CAAA,IAAAD,CAAA,OAAAE,cAAA,CAAAC,IAAA,CAAAH,CAAA,EAAAC,CAAA,MAAAJ,CAAA,CAAAI,CAAA,IAAAD,CAAA,CAAAC,CAAA,aAAAJ,CAAA,KAAAJ,QAAA,CAAAW,KAAA,OA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JnD,MAAA,CAAAQ,OAAA,CAAA4H,aAAA;IACEQ,SAAS,mDAEuBzF,KAAK,kCACFC,QAAQ;EACzC,CACH,CACF,EAEDpD,MAAA,CAAAQ,OAAA,CAAA4H,aAAA;IAAMU,EAAE,EAAE9F,UAAW;IAAC4F,SAAS,EAAC;EAAsB,GACnDjF,QACG,CACF,CAAC;AAEX","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"TooltipContainer.js","names":["_react","_interopRequireDefault","require","_componentHelper","_helpers","_classnames","e","__esModule","default","_extends","Object","assign","bind","n","arguments","length","t","r","hasOwnProperty","call","apply","ownKeys","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","_objectSpread","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","TypeError","String","Number","TooltipContainer","props","internalId","active","attributes","arrow","position","align","hideDelay","fixedPosition","noAnimation","skipPortal","useHover","children","targetElement","target","style","setStyle","React","useState","hover","setHover","isActive","isTrue","wasActive","makeActive","renewStyles","forceRerender","getBodySize","elementRef","useRef","offset","debounceTimeout","resizeObserver","document","width","height","body","getBoundingClientRect","clearTimers","clearTimeout","current","useLayoutEffect","addPositionObserver","ResizeObserver","setTimeout","observe","removePositionObserver","_resizeObserver$curre","disconnect","offsetLeft","offsetTop","element","window","alignOffset","elementWidth","offsetWidth","elementHeight","offsetHeight","rect","targetBodySize","getOffsetLeft","getOffsetTop","scrollY","undefined","pageYOffset","scrollX","pageXOffset","top","useMouseWhen","mousePos","left","widthBased","topHorizontal","leftVertical","stylesFromPosition","right","bottom","stylesFromArrow","rightOffset","parseFloat","innerWidth","handleMouseEnter","handleMouseLeave","handlePropagation","stopPropagation","createElement","role","ref","onMouseEnter","onMouseLeave","onMouseMove","onMouseDown","onTouchStart","className","classnames","id"],"sources":["../../../../src/components/tooltip/TooltipContainer.tsx"],"sourcesContent":["/**\n * Web Tooltip Component\n *\n */\n\nimport React from 'react'\nimport { isTrue } from '../../shared/component-helper'\nimport { getOffsetLeft, getOffsetTop } from '../../shared/helpers'\nimport classnames from 'classnames'\nimport { TooltipProps } from './types'\n\ntype TooltipContainerProps = {\n targetElement: HTMLElement\n style?: React.CSSProperties\n useHover?: boolean\n internalId?: string\n attributes?: Record<string, unknown> & { style: React.CSSProperties }\n}\n\nexport default function TooltipContainer(\n props: TooltipProps & TooltipContainerProps\n) {\n const {\n internalId,\n active,\n attributes,\n arrow,\n position,\n align,\n hideDelay,\n fixedPosition,\n noAnimation,\n skipPortal,\n useHover,\n children,\n targetElement: target,\n } = props\n\n const [style, setStyle] = React.useState(null)\n const [hover, setHover] = React.useState(false)\n const isActive = isTrue(active) || hover\n const [wasActive, makeActive] = React.useState(false)\n const [renewStyles, forceRerender] = React.useState(getBodySize)\n\n const elementRef = React.useRef<HTMLSpanElement>(null)\n const offset = React.useRef(16)\n const debounceTimeout = React.useRef<NodeJS.Timeout>()\n const resizeObserver = React.useRef<ResizeObserver>(null)\n\n function getBodySize() {\n if (!isActive || typeof document === 'undefined') {\n return 0 // stop here\n }\n\n const { width, height } = document.body.getBoundingClientRect()\n\n return width + height\n }\n\n const clearTimers = () => {\n clearTimeout(debounceTimeout.current)\n }\n\n React.useLayoutEffect(() => {\n const addPositionObserver = () => {\n if (resizeObserver.current || typeof document === 'undefined') {\n return // stop here\n }\n\n try {\n resizeObserver.current = new ResizeObserver(() => {\n clearTimers()\n debounceTimeout.current = setTimeout(\n () => forceRerender(getBodySize()),\n 100\n )\n })\n\n resizeObserver.current.observe(document.body)\n } catch (e) {\n //\n }\n }\n const removePositionObserver = () => {\n clearTimers()\n resizeObserver.current?.disconnect()\n }\n\n if (isActive) {\n makeActive(true)\n addPositionObserver()\n } else {\n removePositionObserver()\n }\n\n return removePositionObserver\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isActive])\n\n const offsetLeft = React.useRef(0)\n const offsetTop = React.useRef(0)\n\n React.useLayoutEffect(() => {\n if (!isActive) {\n /**\n * This \"resets\" the position between elements,\n * when not active. Else it will always first show on the older position.\n */\n if (wasActive) {\n clearTimeout(debounceTimeout.current)\n debounceTimeout.current = setTimeout(\n () => setStyle(null),\n hideDelay\n )\n }\n return // stop here\n }\n\n const element = elementRef?.current\n\n if (\n typeof window === 'undefined' ||\n !element ||\n !target?.getBoundingClientRect\n ) {\n return // stop here\n }\n\n let alignOffset = 0\n\n const elementWidth = element.offsetWidth\n const elementHeight = element.offsetHeight\n const rect = target.getBoundingClientRect()\n const targetBodySize = {\n width: target.offsetWidth,\n height: target.offsetHeight,\n }\n\n // fix for svg\n if (!target.offsetHeight) {\n targetBodySize.width = rect.width\n targetBodySize.height = rect.height\n }\n\n if (skipPortal && (!offsetLeft.current || !offsetTop.current)) {\n offsetLeft.current = getOffsetLeft(element) - offset.current\n offsetTop.current = getOffsetTop(element) - offset.current\n }\n\n const scrollY =\n window.scrollY !== undefined ? window.scrollY : window.pageYOffset\n const scrollX =\n window.scrollX !== undefined ? window.scrollX : window.pageXOffset\n const top =\n (isTrue(fixedPosition) ? 0 : scrollY) + rect.top - offsetTop.current\n\n // Use Mouse position when target is too wide\n const useMouseWhen = targetBodySize.width > 400\n const mousePos =\n getOffsetLeft(target) +\n rect.left / 2 +\n (element ? element.offsetWidth : 0)\n const widthBased = scrollX + rect.left\n const left =\n (useMouseWhen && mousePos < targetBodySize.width\n ? mousePos\n : widthBased) - offsetLeft.current\n\n const style = { ...props.style }\n\n if (align === 'left') {\n alignOffset = -targetBodySize.width / 2\n } else if (align === 'right') {\n alignOffset = targetBodySize.width / 2\n }\n\n const topHorizontal =\n top + targetBodySize.height / 2 - elementHeight / 2\n const leftVertical =\n left - elementWidth / 2 + targetBodySize.width / 2 + alignOffset\n\n const stylesFromPosition = {\n left: () => {\n style.top = topHorizontal\n style.left = left - elementWidth - offset.current\n },\n right: () => {\n style.top = topHorizontal\n style.left = left + targetBodySize.width + offset.current\n },\n top: () => {\n style.left = leftVertical\n style.top = top - elementHeight - offset.current\n },\n bottom: () => {\n style.left = leftVertical\n style.top = top + targetBodySize.height + offset.current\n },\n }\n\n const stylesFromArrow = {\n left: () => {\n style.left =\n left + targetBodySize.width / 2 - offset.current + alignOffset\n },\n right: () => {\n style.left =\n left -\n elementWidth +\n targetBodySize.width / 2 +\n offset.current +\n alignOffset\n },\n top: () => {\n style.top = top + targetBodySize.height / 2 - offset.current\n },\n bottom: () => {\n style.top =\n top + targetBodySize.height / 2 - elementHeight + offset.current\n },\n }\n\n if (stylesFromPosition[position]) {\n stylesFromPosition[position]()\n }\n if (stylesFromArrow[arrow]) {\n stylesFromArrow[arrow]()\n }\n\n const rightOffset =\n parseFloat(String(style.left)) + elementWidth - window.innerWidth\n if (rightOffset > 0) {\n style.left = window.innerWidth - elementWidth\n }\n\n if (parseFloat(String(style.left)) < 0) {\n style.left = 0\n }\n if (parseFloat(String(style.top)) < 0) {\n style.top = 0\n }\n\n setStyle(style)\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [active, arrow, position, children, renewStyles])\n\n const handleMouseEnter = () => {\n if (isTrue(active) && useHover !== false) {\n setHover(true)\n }\n }\n\n const handleMouseLeave = () => {\n if (useHover !== false) {\n setHover(false)\n }\n }\n\n /**\n * By stopping propagation, we allow the user to select text when Tooltip is used in the Slider component\n */\n const handlePropagation = (e: React.SyntheticEvent) =>\n e.stopPropagation()\n\n return (\n <span\n role=\"tooltip\"\n aria-hidden={target ? true : undefined} // make sure SR does not find it in the DOM, because we use \"aria-describedby\" for that\n ref={elementRef}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onMouseMove={handlePropagation}\n onMouseDown={handlePropagation}\n onTouchStart={handlePropagation}\n {...attributes}\n className={classnames(\n attributes?.className,\n isTrue(noAnimation) && 'dnb-tooltip--no-animation',\n isTrue(fixedPosition) && 'dnb-tooltip--fixed',\n isActive && 'dnb-tooltip--active',\n !isActive && wasActive && 'dnb-tooltip--hide'\n )}\n style={{ ...style, ...attributes.style }}\n >\n {arrow && (\n <span\n className={classnames(\n 'dnb-tooltip__arrow',\n `dnb-tooltip__arrow__arrow--${arrow}`,\n `dnb-tooltip__arrow__position--${position}`\n )}\n />\n )}\n\n <span id={internalId} className=\"dnb-tooltip__content\">\n {children}\n </span>\n </span>\n )\n}\n"],"mappings":";;;;;;;AAKA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAAmC,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,SAAA,WAAAA,QAAA,GAAAC,MAAA,CAAAC,MAAA,GAAAD,MAAA,CAAAC,MAAA,CAAAC,IAAA,eAAAC,CAAA,aAAAP,CAAA,MAAAA,CAAA,GAAAQ,SAAA,CAAAC,MAAA,EAAAT,CAAA,UAAAU,CAAA,GAAAF,SAAA,CAAAR,CAAA,YAAAW,CAAA,IAAAD,CAAA,OAAAE,cAAA,CAAAC,IAAA,CAAAH,CAAA,EAAAC,CAAA,MAAAJ,CAAA,CAAAI,CAAA,IAAAD,CAAA,CAAAC,CAAA,aAAAJ,CAAA,KAAAJ,QAAA,CAAAW,KAAA,OAAAN,SAAA;AAAA,SAAAO,QAAAf,CAAA,EAAAW,CAAA,QAAAD,CAAA,GAAAN,MAAA,CAAAY,IAAA,CAAAhB,CAAA,OAAAI,MAAA,CAAAa,qBAAA,QAAAC,CAAA,GAAAd,MAAA,CAAAa,qBAAA,CAAAjB,CAAA,GAAAW,CAAA,KAAAO,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAR,CAAA,WAAAP,MAAA,CAAAgB,wBAAA,CAAApB,CAAA,EAAAW,CAAA,EAAAU,UAAA,OAAAX,CAAA,CAAAY,IAAA,CAAAR,KAA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AAM;IAC7B,IAAIvE,QAAQ,KAAK,KAAK,EAAE;MACtBS,QAAQ,CAAC,KAAK,CAAC;IACjB;EACF,CAAC;EAKD,MAAM+D,iBAAiB,GAAI5H,CAAuB,IAChDA,CAAC,CAAC6H,eAAe,CAAC,CAAC;EAErB,OACEnI,MAAA,CAAAQ,OAAA,CAAA4H,aAAA,SAAA3H,QAAA;IACE4H,IAAI,EAAC,SAAS;IACd,eAAaxE,MAAM,GAAG,IAAI,GAAGiD,SAAU;IACvCwB,GAAG,EAAE3D,UAAW;IAChB4D,YAAY,EAAEP,gBAAiB;IAC/BQ,YAAY,EAAEP,gBAAiB;IAC/BQ,WAAW,EAAEP,iBAAkB;IAC/BQ,WAAW,EAAER,iBAAkB;IAC/BS,YAAY,EAAET;EAAkB,GAC5BhF,UAAU;IACd0F,SAAS,EAAE,IAAAC,mBAAU,EACnB3F,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAE0F,SAAS,EAGrBxE,QAAQ,GAAI,qBAAqB,GACpBE,SAAS,IAAI,mBAAmB,EAH7C,IAAAD,uBAAM,EAACb,WAAW,CAAC,IAAI,2BAA2B,EAClD,IAAAa,uBAAM,EAACd,aAAa,CAAC,IAAI,oBAG3B,CAAE;IACFO,KAAK,EAAAjC,aAAA,CAAAA,aAAA,KAAOiC,KAAK,GAAKZ,UAAU,CAACY,KAAK;EAAG,IAExCX,KAAK,IACJnD,MAAA,CAAAQ,OAAA,CAAA4H,aAAA;IACEQ,SAAS,mDAEuBzF,KAAK,kCACFC,QAAQ;EACzC,CACH,CACF,EAEDpD,MAAA,CAAAQ,OAAA,CAAA4H,aAAA;IAAMU,EAAE,EAAE9F,UAAW;IAAC4F,SAAS,EAAC;EAAsB,GACnDjF,QACG,CACF,CAAC;AAEX","ignoreList":[]}
|
|
@@ -39,6 +39,9 @@ type FormErrorOptions = {
|
|
|
39
39
|
* Standard error object for Eufemia Forms, extending the built-in error with additional information for data handling
|
|
40
40
|
*/
|
|
41
41
|
export declare class FormError extends Error {
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated – can be removed in v11
|
|
44
|
+
*/
|
|
42
45
|
validationRule?: FormErrorOptions['validationRule'];
|
|
43
46
|
messageValues?: FormErrorOptions['messageValues'];
|
|
44
47
|
ajvKeyword?: FormErrorOptions['ajvKeyword'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormError.js","names":["FormError","Error","constructor","message","options","key","exports"],"sources":["../../../../../src/extensions/forms/utils/FormError.ts"],"sourcesContent":["import { ErrorObject } from 'ajv/dist/2020'\nimport { FormsTranslationFlat } from '../hooks/useTranslation'\n\ntype ValidationRule =\n | string\n | 'type'\n /**\n * @deprecated Use translation keys as the message instead of this parameter (e.g. Field.errorRequired)\n */\n | 'pattern'\n /**\n * @deprecated Use translation keys as the message instead of this parameter (e.g. Field.errorRequired)\n */\n | 'required'\n\ntype FormErrorOptions = {\n /**\n * What validation rule did the error occur based on? (i.e: minLength, required or maximum).\n * @deprecated Use translation keys as the message instead of this parameter (e.g. Field.errorRequired)\n */\n validationRule?: ValidationRule\n\n /**\n * Replacement values relevant for this error.\n * @example { minLength: 3 } to be able to replace values in a message like \"Minimum {minLength} characters\"\n */\n messageValues?: Record<string, string>\n\n /**\n * The AJV keyword that caused the error.\n */\n ajvKeyword?: ErrorObject['keyword']\n\n /**\n * An array of errors that should be rendered in the same error message.\n */\n errors?: Array<Error | FormError>\n\n /**\n * For internal use only.\n * A formatted (JSX) message to be used internally later on.\n */\n formattedMessage?: string | React.ReactElement\n}\n\n/**\n * Standard error object for Eufemia Forms, extending the built-in error with additional information for data handling\n */\nexport class FormError extends Error {\n
|
|
1
|
+
{"version":3,"file":"FormError.js","names":["FormError","Error","constructor","message","options","key","exports"],"sources":["../../../../../src/extensions/forms/utils/FormError.ts"],"sourcesContent":["import { ErrorObject } from 'ajv/dist/2020'\nimport { FormsTranslationFlat } from '../hooks/useTranslation'\n\ntype ValidationRule =\n | string\n | 'type'\n /**\n * @deprecated Use translation keys as the message instead of this parameter (e.g. Field.errorRequired)\n */\n | 'pattern'\n /**\n * @deprecated Use translation keys as the message instead of this parameter (e.g. Field.errorRequired)\n */\n | 'required'\n\ntype FormErrorOptions = {\n /**\n * What validation rule did the error occur based on? (i.e: minLength, required or maximum).\n * @deprecated Use translation keys as the message instead of this parameter (e.g. Field.errorRequired)\n */\n validationRule?: ValidationRule\n\n /**\n * Replacement values relevant for this error.\n * @example { minLength: 3 } to be able to replace values in a message like \"Minimum {minLength} characters\"\n */\n messageValues?: Record<string, string>\n\n /**\n * The AJV keyword that caused the error.\n */\n ajvKeyword?: ErrorObject['keyword']\n\n /**\n * An array of errors that should be rendered in the same error message.\n */\n errors?: Array<Error | FormError>\n\n /**\n * For internal use only.\n * A formatted (JSX) message to be used internally later on.\n */\n formattedMessage?: string | React.ReactElement\n}\n\n/**\n * Standard error object for Eufemia Forms, extending the built-in error with additional information for data handling\n */\nexport class FormError extends Error {\n /**\n * @deprecated – can be removed in v11\n */\n validationRule?: FormErrorOptions['validationRule']\n\n messageValues?: FormErrorOptions['messageValues']\n ajvKeyword?: FormErrorOptions['ajvKeyword']\n errors?: FormErrorOptions['errors']\n formattedMessage?: FormErrorOptions['formattedMessage']\n\n constructor(\n message: FormsTranslationFlat | string | React.ReactElement,\n options?: FormErrorOptions\n ) {\n super(message as string)\n\n if (options) {\n for (const key in options) {\n this[key] = options[key]\n }\n }\n }\n}\n"],"mappings":";;;;;;AAgDO,MAAMA,SAAS,SAASC,KAAK,CAAC;EAWnCC,WAAWA,CACTC,OAA2D,EAC3DC,OAA0B,EAC1B;IACA,KAAK,CAACD,OAAiB,CAAC;IAExB,IAAIC,OAAO,EAAE;MACX,KAAK,MAAMC,GAAG,IAAID,OAAO,EAAE;QACzB,IAAI,CAACC,GAAG,CAAC,GAAGD,OAAO,CAACC,GAAG,CAAC;MAC1B;IACF;EACF;AACF;AAACC,OAAA,CAAAN,SAAA,GAAAA,SAAA","ignoreList":[]}
|
package/cjs/shared/Eufemia.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "10.71.
|
|
1
|
+
export declare const version = "10.71.1";
|
|
2
2
|
export declare function init(): void;
|
package/cjs/shared/Eufemia.js
CHANGED
|
@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.init = init;
|
|
7
7
|
exports.version = void 0;
|
|
8
|
-
const version = exports.version = '10.71.
|
|
8
|
+
const version = exports.version = '10.71.1';
|
|
9
9
|
function init() {
|
|
10
10
|
if (typeof window !== 'undefined') {
|
|
11
11
|
class Eufemia {
|
|
12
12
|
get version() {
|
|
13
|
-
return '10.71.
|
|
13
|
+
return '10.71.1';
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
window.Eufemia = new Eufemia();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Eufemia.js","names":["version","exports","init","window","Eufemia"],"sources":["../../../src/shared/Eufemia.ts"],"sourcesContent":["export const version = '10.71.
|
|
1
|
+
{"version":3,"file":"Eufemia.js","names":["version","exports","init","window","Eufemia"],"sources":["../../../src/shared/Eufemia.ts"],"sourcesContent":["export const version = '10.71.1'\n\nexport function init() {\n if (typeof window !== 'undefined') {\n class Eufemia {\n get version() {\n return '10.71.1'\n }\n }\n\n window.Eufemia = new Eufemia()\n }\n}\n"],"mappings":";;;;;;;AAAO,MAAMA,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAG,SAAS;AAEzB,SAASE,IAAIA,CAAA,EAAG;EACrB,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IACjC,MAAMC,OAAO,CAAC;MACZ,IAAIJ,OAAOA,CAAA,EAAG;QACZ,OAAO,SAAS;MAClB;IACF;IAEAG,MAAM,CAACC,OAAO,GAAG,IAAIA,OAAO,CAAC,CAAC;EAChC;AACF","ignoreList":[]}
|
|
@@ -153,9 +153,9 @@ var _default = exports.default = {
|
|
|
153
153
|
title: 'Upload documents',
|
|
154
154
|
text: 'Drag & drop your files or choose files to upload.',
|
|
155
155
|
textSingular: 'Drag & drop your file or choose which file to upload.',
|
|
156
|
-
fileTypeTableCaption: 'Allowed formats and max.
|
|
156
|
+
fileTypeTableCaption: 'Allowed formats and max. file size',
|
|
157
157
|
fileTypeDescription: 'Allowed formats:',
|
|
158
|
-
fileSizeDescription: 'Max.
|
|
158
|
+
fileSizeDescription: 'Max. file size:',
|
|
159
159
|
fileAmountDescription: 'Max. number of files:',
|
|
160
160
|
fileSizeContent: '%size MB',
|
|
161
161
|
buttonText: 'Choose files',
|