@gravity-ui/date-components 3.2.2 → 3.2.3

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.
@@ -200,24 +200,37 @@ function useBaseDateFieldState(props) {
200
200
  return;
201
201
  }
202
202
  const section = this.sections[sectionIndex];
203
+ const isLastSection = section.nextEditableSection === sectionIndex;
203
204
  let newValue = enteredKeys.current + key;
204
205
  const onInputNumber = (numberValue) => {
205
- var _a, _b, _c;
206
+ var _a;
206
207
  let sectionValue = section.type === 'month' ? numberValue - 1 : numberValue;
208
+ const sectionMaxValue = (_a = section.maxValue) !== null && _a !== void 0 ? _a : 0;
207
209
  const allowsZero = section.minValue === 0;
208
- if (section.type === 'hour' &&
209
- (section.minValue === 12 || section.maxValue === 11)) {
210
- if (numberValue > 12) {
210
+ let shouldResetUserInput;
211
+ if (
212
+ // 12-hour clock format with AM/PM
213
+ section.type === 'hour' &&
214
+ (sectionMaxValue === 11 || section.minValue === 12)) {
215
+ if (sectionValue > 12) {
211
216
  sectionValue = Number(key);
217
+ newValue = key;
218
+ }
219
+ if (sectionValue === 0) {
220
+ sectionValue = -Infinity;
212
221
  }
213
- if (section.minValue === 12 && sectionValue > 1) {
222
+ if (sectionValue === 12) {
223
+ sectionValue = 0;
224
+ }
225
+ if (section.minValue === 12) {
214
226
  sectionValue += 12;
215
227
  }
228
+ shouldResetUserInput = Number(newValue + '0') > 12;
216
229
  }
217
- else if (sectionValue > ((_a = section.maxValue) !== null && _a !== void 0 ? _a : 0)) {
230
+ else if (sectionValue > sectionMaxValue) {
218
231
  sectionValue = Number(key) - (section.type === 'month' ? 1 : 0);
219
232
  newValue = key;
220
- if (sectionValue > ((_b = section.maxValue) !== null && _b !== void 0 ? _b : 0)) {
233
+ if (sectionValue > sectionMaxValue) {
221
234
  enteredKeys.current = '';
222
235
  return;
223
236
  }
@@ -226,15 +239,21 @@ function useBaseDateFieldState(props) {
226
239
  if (shouldSetValue) {
227
240
  setSection(sectionIndex, sectionValue);
228
241
  }
229
- if (Number(numberValue + '0') > ((_c = section.maxValue) !== null && _c !== void 0 ? _c : 0) ||
230
- newValue.length >= String(section.maxValue).length) {
242
+ if (shouldResetUserInput === undefined) {
243
+ shouldResetUserInput = Number(newValue + '0') > sectionMaxValue;
244
+ }
245
+ const isMaxLength = newValue.length >= String(sectionMaxValue).length;
246
+ if (shouldResetUserInput) {
231
247
  enteredKeys.current = '';
232
248
  if (shouldSetValue) {
233
249
  this.focusNextSection();
234
250
  }
235
251
  }
252
+ else if (isMaxLength && shouldSetValue && !isLastSection) {
253
+ this.focusNextSection();
254
+ }
236
255
  else {
237
- enteredKeys.current = newValue === '0' && !allowsZero ? '' : newValue;
256
+ enteredKeys.current = newValue;
238
257
  }
239
258
  };
240
259
  const onInputString = (stringValue) => {
@@ -1 +1 @@
1
- {"version":3,"file":"useBaseDateFieldState.js","sourceRoot":"../../../../../src","sources":["components/DateField/hooks/useBaseDateFieldState.ts"],"names":[],"mappings":";;AA8HA,sDA0UC;;AAxcD,0DAA0B;AAK1B,gDAAyD;AAEzD,uCAKkB;AAElB,MAAM,SAAS,GAAkD;IAC7D,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IACV,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;CACb,CAAC;AAuGF,SAAgB,qBAAqB,CACjC,KAAmC;IAEnC,MAAM,EACF,KAAK,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,sBAAsB,EACtB,gBAAgB,EAChB,OAAO,EACP,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,QAAQ,EACR,OAAO,EACP,aAAa,EACb,UAAU,EACV,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,kBAAkB,GACrB,GAAG,KAAK,CAAC;IAEV,MAAM,WAAW,GAAG,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Q,CAAC,CAAC;wBACrC,aAAa,CAAC,WAAW,CAAC,CAAC;oBAC/B,CAAC;yBAAM,CAAC;wBACJ,aAAa,CAAC,QAAQ,CAAC,CAAC;oBAC5B,CAAC;oBACD,MAAM;gBACV,CAAC;YACL,CAAC;QACL,CAAC;QACD,kBAAkB,CAAC,GAAW;YAC1B,WAAW,CAAC,OAAO,GAAG,EAAE,CAAC;YACzB,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;KACJ,CAAC;AACN,CAAC","sourcesContent":["import React from 'react';\n\nimport type {DateTime} from '@gravity-ui/date-utils';\n\nimport type {ValidationState} from '../../types';\nimport {createPlaceholderValue} from '../../utils/dates';\nimport type {DateFieldSection, DateFieldSectionType, FormatInfo} from '../types';\nimport {\n EDITABLE_SEGMENTS,\n formatSections,\n getCurrentEditableSectionIndex,\n getDurationUnitFromSectionType,\n} from '../utils';\n\nconst PAGE_STEP: Partial<Record<DateFieldSectionType, number>> = {\n year: 5,\n quarter: 2,\n month: 2,\n weekday: 3,\n day: 7,\n hour: 2,\n minute: 15,\n second: 15,\n};\n\nexport type BaseDateFieldStateOptions<T = DateTime> = {\n value: T | null;\n displayValue: T;\n placeholderValue?: DateTime;\n timeZone: string;\n validationState?: ValidationState;\n editableSections: DateFieldSection[];\n formatInfo: FormatInfo;\n readOnly?: boolean;\n disabled?: boolean;\n selectedSectionIndexes: {startIndex: number; endIndex: number} | null;\n selectedSections: number | 'all';\n isEmpty: boolean;\n flushAllValidSections: () => void;\n flushValidSection: (sectionIndex: number) => void;\n setSelectedSections: (position: number | 'all') => void;\n setValue: (value: T) => void;\n setDate: (value: T | null) => void;\n adjustSection: (sectionIndex: number, amount: number) => void;\n setSection: (sectionIndex: number, amount: number) => void;\n getSectionValue: (sectionIndex: number) => DateTime;\n setSectionValue: (sectionIndex: number, currentValue: DateTime) => void;\n createPlaceholder: () => T;\n setValueFromString: (str: string) => boolean;\n};\n\nexport type DateFieldState<T = DateTime> = {\n /** The current field value. */\n value: T | null;\n /** Is no part of value is filled. */\n isEmpty: boolean;\n /** The current used value. value or placeholderValue */\n displayValue: T;\n /** Sets the field's value. */\n setValue: (value: T) => void;\n /** Sets the date value. */\n setDate: (value: T | null) => void;\n /** Formatted value */\n text: string;\n /** Whether the field is read only. */\n readOnly?: boolean;\n /** Whether the field is disabled. */\n disabled?: boolean;\n /** A list of segments for the current value. */\n sections: DateFieldSection[];\n /** Some info about available sections */\n formatInfo: FormatInfo;\n /**\n * @deprecated use formatInfo.hasDate instead.\n * Whether the the format is containing date parts\n */\n hasDate: boolean;\n /**\n * @deprecated use formatInfo.hasTime instead.\n * Whether the the format is containing time parts\n */\n hasTime: boolean;\n /** Selected sections */\n selectedSectionIndexes: {startIndex: number; endIndex: number} | null;\n /** The current validation state of the date field, based on the `validationState`, `minValue`, and `maxValue` props. */\n validationState?: ValidationState;\n /** Sets selection for segment in position. */\n setSelectedSections: (position: number | 'all') => void;\n /** Focuses segment in position */\n focusSectionInPosition: (position: number) => void;\n /** Focuses the next segment if present */\n focusNextSection: () => void;\n /** Focuses the previous segment if present */\n focusPreviousSection: () => void;\n /** Focuses the first segment */\n focusFirstSection: () => void;\n /** Focuses the last segment */\n focusLastSection: () => void;\n /** Increments the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */\n increment: () => void;\n /** Decrements the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */\n decrement: () => void;\n /**\n * Increments the currently selected segment by a larger amount, rounding it to the nearest increment.\n * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.\n * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.\n */\n incrementPage: () => void;\n /**\n * Decrements the currently selected segment by a larger amount, rounding it to the nearest decrement.\n * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.\n * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.\n */\n decrementPage: () => void;\n incrementToMax: () => void;\n decrementToMin: () => void;\n /** Clears the value of the currently selected segment, reverting it to the placeholder. */\n clearSection: () => void;\n /** Clears all segments, reverting them to the placeholder. */\n clearAll: () => void;\n /** Handles input key in the currently selected segment */\n onInput: (key: string) => void;\n //** Tries to set value from str. Supports date in input format or ISO */\n setValueFromString: (str: string) => boolean;\n};\n\nexport function useBaseDateFieldState<T = DateTime>(\n props: BaseDateFieldStateOptions<T>,\n): DateFieldState<T> {\n const {\n value,\n validationState,\n displayValue,\n editableSections,\n formatInfo,\n selectedSectionIndexes,\n selectedSections,\n isEmpty,\n flushAllValidSections,\n flushValidSection,\n setSelectedSections,\n setValue,\n setDate,\n adjustSection,\n setSection,\n getSectionValue,\n setSectionValue,\n createPlaceholder,\n setValueFromString,\n } = props;\n\n const enteredKeys = React.useRef('');\n\n return {\n value,\n isEmpty,\n displayValue,\n setValue,\n setDate,\n text: formatSections(editableSections),\n readOnly: props.readOnly,\n disabled: props.disabled,\n sections: editableSections,\n formatInfo,\n hasDate: formatInfo.hasDate,\n hasTime: formatInfo.hasTime,\n selectedSectionIndexes,\n validationState,\n setSelectedSections(position) {\n enteredKeys.current = '';\n setSelectedSections(position);\n },\n focusSectionInPosition(position) {\n const nextSectionIndex = this.sections.findIndex((s) => s.end >= position);\n const index = nextSectionIndex === -1 ? 0 : nextSectionIndex;\n const nextSection = this.sections[index];\n if (nextSection) {\n this.setSelectedSections(\n EDITABLE_SEGMENTS[nextSection.type] ? index : nextSection.nextEditableSection,\n );\n }\n },\n focusNextSection() {\n const currentIndex = selectedSections === 'all' ? 0 : selectedSections;\n const newIndex = this.sections[currentIndex]?.nextEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n focusPreviousSection() {\n const currentIndex = selectedSections === 'all' ? 0 : selectedSections;\n const newIndex = this.sections[currentIndex]?.previousEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n focusFirstSection() {\n const newIndex = this.sections[0]?.previousEditableSection ?? -1;\n if (newIndex !== -1) {\n setSelectedSections(newIndex);\n }\n },\n focusLastSection() {\n const newIndex = this.sections[this.sections.length - 1]?.nextEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n increment() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, 1);\n }\n },\n decrement() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, -1);\n }\n },\n incrementPage() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, PAGE_STEP[this.sections[sectionIndex].type] || 1);\n }\n },\n decrementPage() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, -(PAGE_STEP[this.sections[sectionIndex].type] || 1));\n }\n },\n incrementToMax() {\n if (this.readOnly || this.disabled) {\n return;\n }\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n const section = this.sections[sectionIndex];\n if (typeof section.maxValue === 'number') {\n setSection(sectionIndex, section.maxValue);\n }\n }\n },\n decrementToMin() {\n if (this.readOnly || this.disabled) {\n return;\n }\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n const section = this.sections[sectionIndex];\n if (typeof section.minValue === 'number') {\n setSection(sectionIndex, section.minValue);\n }\n }\n },\n clearSection() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n if (selectedSections === 'all') {\n this.clearAll();\n return;\n }\n\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex === -1) {\n return;\n }\n\n flushValidSection(sectionIndex);\n\n const section = this.sections[sectionIndex];\n\n const placeholder = createPlaceholderValue({\n placeholderValue: props.placeholderValue,\n timeZone: props.timeZone,\n }).timeZone(props.timeZone);\n\n const displayPortion = getSectionValue(sectionIndex);\n let currentValue = displayPortion;\n\n // Reset day period to default without changing the hour.\n if (section.type === 'dayPeriod') {\n const isPM = displayPortion.hour() >= 12;\n const shouldBePM = placeholder.hour() >= 12;\n if (isPM && !shouldBePM) {\n currentValue = displayPortion.set('hour', displayPortion.hour() - 12);\n } else if (!isPM && shouldBePM) {\n currentValue = displayPortion.set('hour', displayPortion.hour() + 12);\n }\n } else {\n const type = getDurationUnitFromSectionType(section.type);\n currentValue = displayPortion.set(type, placeholder[type]());\n }\n\n setSectionValue(sectionIndex, currentValue);\n },\n clearAll() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n flushAllValidSections();\n if (value !== null) {\n setDate(null);\n }\n\n const date = createPlaceholder();\n\n setValue(date);\n },\n onInput(key: string) {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex === -1) {\n return;\n }\n\n const section = this.sections[sectionIndex];\n let newValue = enteredKeys.current + key;\n\n const onInputNumber = (numberValue: number) => {\n let sectionValue = section.type === 'month' ? numberValue - 1 : numberValue;\n const allowsZero = section.minValue === 0;\n if (\n section.type === 'hour' &&\n (section.minValue === 12 || section.maxValue === 11)\n ) {\n if (numberValue > 12) {\n sectionValue = Number(key);\n }\n if (section.minValue === 12 && sectionValue > 1) {\n sectionValue += 12;\n }\n } else if (sectionValue > (section.maxValue ?? 0)) {\n sectionValue = Number(key) - (section.type === 'month' ? 1 : 0);\n newValue = key;\n if (sectionValue > (section.maxValue ?? 0)) {\n enteredKeys.current = '';\n return;\n }\n }\n\n const shouldSetValue = sectionValue > 0 || (sectionValue === 0 && allowsZero);\n if (shouldSetValue) {\n setSection(sectionIndex, sectionValue);\n }\n\n if (\n Number(numberValue + '0') > (section.maxValue ?? 0) ||\n newValue.length >= String(section.maxValue).length\n ) {\n enteredKeys.current = '';\n if (shouldSetValue) {\n this.focusNextSection();\n }\n } else {\n enteredKeys.current = newValue === '0' && !allowsZero ? '' : newValue;\n }\n };\n\n const onInputString = (stringValue: string) => {\n const options = section.options ?? [];\n let sectionValue = stringValue.toLocaleUpperCase();\n let foundOptions = options.filter((v) => v.startsWith(sectionValue));\n if (foundOptions.length === 0) {\n if (stringValue !== key) {\n sectionValue = key.toLocaleUpperCase();\n foundOptions = options.filter((v) => v.startsWith(sectionValue));\n }\n if (foundOptions.length === 0) {\n enteredKeys.current = '';\n return;\n }\n }\n const foundValue = foundOptions[0];\n const index = options.indexOf(foundValue);\n\n if (section.type === 'dayPeriod') {\n setSection(sectionIndex, index === 1 ? 12 : 0);\n } else {\n setSection(sectionIndex, index);\n }\n\n if (foundOptions.length > 1) {\n enteredKeys.current = newValue;\n } else {\n enteredKeys.current = '';\n this.focusNextSection();\n }\n };\n\n switch (section.type) {\n case 'day':\n case 'hour':\n case 'minute':\n case 'second':\n case 'quarter':\n case 'year': {\n if (!Number.isInteger(Number(newValue))) {\n return;\n }\n const numberValue = Number(newValue);\n onInputNumber(numberValue);\n break;\n }\n case 'dayPeriod': {\n onInputString(newValue);\n break;\n }\n case 'weekday':\n case 'month': {\n if (Number.isInteger(Number(newValue))) {\n const numberValue = Number(newValue);\n onInputNumber(numberValue);\n } else {\n onInputString(newValue);\n }\n break;\n }\n }\n },\n setValueFromString(str: string) {\n enteredKeys.current = '';\n return setValueFromString(str);\n },\n };\n}\n"]}
1
+ {"version":3,"file":"useBaseDateFieldState.js","sourceRoot":"../../../../../src","sources":["components/DateField/hooks/useBaseDateFieldState.ts"],"names":[],"mappings":";;AA8HA,sDAyVC;;AA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,CAAC,GAAW;YAC1B,WAAW,CAAC,OAAO,GAAG,EAAE,CAAC;YACzB,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;KACJ,CAAC;AACN,CAAC","sourcesContent":["import React from 'react';\n\nimport type {DateTime} from '@gravity-ui/date-utils';\n\nimport type {ValidationState} from '../../types';\nimport {createPlaceholderValue} from '../../utils/dates';\nimport type {DateFieldSection, DateFieldSectionType, FormatInfo} from '../types';\nimport {\n EDITABLE_SEGMENTS,\n formatSections,\n getCurrentEditableSectionIndex,\n getDurationUnitFromSectionType,\n} from '../utils';\n\nconst PAGE_STEP: Partial<Record<DateFieldSectionType, number>> = {\n year: 5,\n quarter: 2,\n month: 2,\n weekday: 3,\n day: 7,\n hour: 2,\n minute: 15,\n second: 15,\n};\n\nexport type BaseDateFieldStateOptions<T = DateTime> = {\n value: T | null;\n displayValue: T;\n placeholderValue?: DateTime;\n timeZone: string;\n validationState?: ValidationState;\n editableSections: DateFieldSection[];\n formatInfo: FormatInfo;\n readOnly?: boolean;\n disabled?: boolean;\n selectedSectionIndexes: {startIndex: number; endIndex: number} | null;\n selectedSections: number | 'all';\n isEmpty: boolean;\n flushAllValidSections: () => void;\n flushValidSection: (sectionIndex: number) => void;\n setSelectedSections: (position: number | 'all') => void;\n setValue: (value: T) => void;\n setDate: (value: T | null) => void;\n adjustSection: (sectionIndex: number, amount: number) => void;\n setSection: (sectionIndex: number, amount: number) => void;\n getSectionValue: (sectionIndex: number) => DateTime;\n setSectionValue: (sectionIndex: number, currentValue: DateTime) => void;\n createPlaceholder: () => T;\n setValueFromString: (str: string) => boolean;\n};\n\nexport type DateFieldState<T = DateTime> = {\n /** The current field value. */\n value: T | null;\n /** Is no part of value is filled. */\n isEmpty: boolean;\n /** The current used value. value or placeholderValue */\n displayValue: T;\n /** Sets the field's value. */\n setValue: (value: T) => void;\n /** Sets the date value. */\n setDate: (value: T | null) => void;\n /** Formatted value */\n text: string;\n /** Whether the field is read only. */\n readOnly?: boolean;\n /** Whether the field is disabled. */\n disabled?: boolean;\n /** A list of segments for the current value. */\n sections: DateFieldSection[];\n /** Some info about available sections */\n formatInfo: FormatInfo;\n /**\n * @deprecated use formatInfo.hasDate instead.\n * Whether the the format is containing date parts\n */\n hasDate: boolean;\n /**\n * @deprecated use formatInfo.hasTime instead.\n * Whether the the format is containing time parts\n */\n hasTime: boolean;\n /** Selected sections */\n selectedSectionIndexes: {startIndex: number; endIndex: number} | null;\n /** The current validation state of the date field, based on the `validationState`, `minValue`, and `maxValue` props. */\n validationState?: ValidationState;\n /** Sets selection for segment in position. */\n setSelectedSections: (position: number | 'all') => void;\n /** Focuses segment in position */\n focusSectionInPosition: (position: number) => void;\n /** Focuses the next segment if present */\n focusNextSection: () => void;\n /** Focuses the previous segment if present */\n focusPreviousSection: () => void;\n /** Focuses the first segment */\n focusFirstSection: () => void;\n /** Focuses the last segment */\n focusLastSection: () => void;\n /** Increments the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */\n increment: () => void;\n /** Decrements the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */\n decrement: () => void;\n /**\n * Increments the currently selected segment by a larger amount, rounding it to the nearest increment.\n * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.\n * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.\n */\n incrementPage: () => void;\n /**\n * Decrements the currently selected segment by a larger amount, rounding it to the nearest decrement.\n * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.\n * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.\n */\n decrementPage: () => void;\n incrementToMax: () => void;\n decrementToMin: () => void;\n /** Clears the value of the currently selected segment, reverting it to the placeholder. */\n clearSection: () => void;\n /** Clears all segments, reverting them to the placeholder. */\n clearAll: () => void;\n /** Handles input key in the currently selected segment */\n onInput: (key: string) => void;\n //** Tries to set value from str. Supports date in input format or ISO */\n setValueFromString: (str: string) => boolean;\n};\n\nexport function useBaseDateFieldState<T = DateTime>(\n props: BaseDateFieldStateOptions<T>,\n): DateFieldState<T> {\n const {\n value,\n validationState,\n displayValue,\n editableSections,\n formatInfo,\n selectedSectionIndexes,\n selectedSections,\n isEmpty,\n flushAllValidSections,\n flushValidSection,\n setSelectedSections,\n setValue,\n setDate,\n adjustSection,\n setSection,\n getSectionValue,\n setSectionValue,\n createPlaceholder,\n setValueFromString,\n } = props;\n\n const enteredKeys = React.useRef('');\n\n return {\n value,\n isEmpty,\n displayValue,\n setValue,\n setDate,\n text: formatSections(editableSections),\n readOnly: props.readOnly,\n disabled: props.disabled,\n sections: editableSections,\n formatInfo,\n hasDate: formatInfo.hasDate,\n hasTime: formatInfo.hasTime,\n selectedSectionIndexes,\n validationState,\n setSelectedSections(position) {\n enteredKeys.current = '';\n setSelectedSections(position);\n },\n focusSectionInPosition(position) {\n const nextSectionIndex = this.sections.findIndex((s) => s.end >= position);\n const index = nextSectionIndex === -1 ? 0 : nextSectionIndex;\n const nextSection = this.sections[index];\n if (nextSection) {\n this.setSelectedSections(\n EDITABLE_SEGMENTS[nextSection.type] ? index : nextSection.nextEditableSection,\n );\n }\n },\n focusNextSection() {\n const currentIndex = selectedSections === 'all' ? 0 : selectedSections;\n const newIndex = this.sections[currentIndex]?.nextEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n focusPreviousSection() {\n const currentIndex = selectedSections === 'all' ? 0 : selectedSections;\n const newIndex = this.sections[currentIndex]?.previousEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n focusFirstSection() {\n const newIndex = this.sections[0]?.previousEditableSection ?? -1;\n if (newIndex !== -1) {\n setSelectedSections(newIndex);\n }\n },\n focusLastSection() {\n const newIndex = this.sections[this.sections.length - 1]?.nextEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n increment() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, 1);\n }\n },\n decrement() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, -1);\n }\n },\n incrementPage() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, PAGE_STEP[this.sections[sectionIndex].type] || 1);\n }\n },\n decrementPage() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, -(PAGE_STEP[this.sections[sectionIndex].type] || 1));\n }\n },\n incrementToMax() {\n if (this.readOnly || this.disabled) {\n return;\n }\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n const section = this.sections[sectionIndex];\n if (typeof section.maxValue === 'number') {\n setSection(sectionIndex, section.maxValue);\n }\n }\n },\n decrementToMin() {\n if (this.readOnly || this.disabled) {\n return;\n }\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n const section = this.sections[sectionIndex];\n if (typeof section.minValue === 'number') {\n setSection(sectionIndex, section.minValue);\n }\n }\n },\n clearSection() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n if (selectedSections === 'all') {\n this.clearAll();\n return;\n }\n\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex === -1) {\n return;\n }\n\n flushValidSection(sectionIndex);\n\n const section = this.sections[sectionIndex];\n\n const placeholder = createPlaceholderValue({\n placeholderValue: props.placeholderValue,\n timeZone: props.timeZone,\n }).timeZone(props.timeZone);\n\n const displayPortion = getSectionValue(sectionIndex);\n let currentValue = displayPortion;\n\n // Reset day period to default without changing the hour.\n if (section.type === 'dayPeriod') {\n const isPM = displayPortion.hour() >= 12;\n const shouldBePM = placeholder.hour() >= 12;\n if (isPM && !shouldBePM) {\n currentValue = displayPortion.set('hour', displayPortion.hour() - 12);\n } else if (!isPM && shouldBePM) {\n currentValue = displayPortion.set('hour', displayPortion.hour() + 12);\n }\n } else {\n const type = getDurationUnitFromSectionType(section.type);\n currentValue = displayPortion.set(type, placeholder[type]());\n }\n\n setSectionValue(sectionIndex, currentValue);\n },\n clearAll() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n flushAllValidSections();\n if (value !== null) {\n setDate(null);\n }\n\n const date = createPlaceholder();\n\n setValue(date);\n },\n onInput(key: string) {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex === -1) {\n return;\n }\n\n const section = this.sections[sectionIndex];\n const isLastSection = section.nextEditableSection === sectionIndex;\n let newValue = enteredKeys.current + key;\n\n const onInputNumber = (numberValue: number) => {\n let sectionValue = section.type === 'month' ? numberValue - 1 : numberValue;\n const sectionMaxValue = section.maxValue ?? 0;\n const allowsZero = section.minValue === 0;\n let shouldResetUserInput;\n if (\n // 12-hour clock format with AM/PM\n section.type === 'hour' &&\n (sectionMaxValue === 11 || section.minValue === 12)\n ) {\n if (sectionValue > 12) {\n sectionValue = Number(key);\n newValue = key;\n }\n if (sectionValue === 0) {\n sectionValue = -Infinity;\n }\n if (sectionValue === 12) {\n sectionValue = 0;\n }\n if (section.minValue === 12) {\n sectionValue += 12;\n }\n shouldResetUserInput = Number(newValue + '0') > 12;\n } else if (sectionValue > sectionMaxValue) {\n sectionValue = Number(key) - (section.type === 'month' ? 1 : 0);\n newValue = key;\n if (sectionValue > sectionMaxValue) {\n enteredKeys.current = '';\n return;\n }\n }\n\n const shouldSetValue = sectionValue > 0 || (sectionValue === 0 && allowsZero);\n if (shouldSetValue) {\n setSection(sectionIndex, sectionValue);\n }\n\n if (shouldResetUserInput === undefined) {\n shouldResetUserInput = Number(newValue + '0') > sectionMaxValue;\n }\n const isMaxLength = newValue.length >= String(sectionMaxValue).length;\n if (shouldResetUserInput) {\n enteredKeys.current = '';\n if (shouldSetValue) {\n this.focusNextSection();\n }\n } else if (isMaxLength && shouldSetValue && !isLastSection) {\n this.focusNextSection();\n } else {\n enteredKeys.current = newValue;\n }\n };\n\n const onInputString = (stringValue: string) => {\n const options = section.options ?? [];\n let sectionValue = stringValue.toLocaleUpperCase();\n let foundOptions = options.filter((v) => v.startsWith(sectionValue));\n if (foundOptions.length === 0) {\n if (stringValue !== key) {\n sectionValue = key.toLocaleUpperCase();\n foundOptions = options.filter((v) => v.startsWith(sectionValue));\n }\n if (foundOptions.length === 0) {\n enteredKeys.current = '';\n return;\n }\n }\n const foundValue = foundOptions[0];\n const index = options.indexOf(foundValue);\n\n if (section.type === 'dayPeriod') {\n setSection(sectionIndex, index === 1 ? 12 : 0);\n } else {\n setSection(sectionIndex, index);\n }\n\n if (foundOptions.length > 1) {\n enteredKeys.current = newValue;\n } else {\n enteredKeys.current = '';\n this.focusNextSection();\n }\n };\n\n switch (section.type) {\n case 'day':\n case 'hour':\n case 'minute':\n case 'second':\n case 'quarter':\n case 'year': {\n if (!Number.isInteger(Number(newValue))) {\n return;\n }\n const numberValue = Number(newValue);\n onInputNumber(numberValue);\n break;\n }\n case 'dayPeriod': {\n onInputString(newValue);\n break;\n }\n case 'weekday':\n case 'month': {\n if (Number.isInteger(Number(newValue))) {\n const numberValue = Number(newValue);\n onInputNumber(numberValue);\n } else {\n onInputString(newValue);\n }\n break;\n }\n }\n },\n setValueFromString(str: string) {\n enteredKeys.current = '';\n return setValueFromString(str);\n },\n };\n}\n"]}
@@ -196,24 +196,37 @@ export function useBaseDateFieldState(props) {
196
196
  return;
197
197
  }
198
198
  const section = this.sections[sectionIndex];
199
+ const isLastSection = section.nextEditableSection === sectionIndex;
199
200
  let newValue = enteredKeys.current + key;
200
201
  const onInputNumber = (numberValue) => {
201
- var _a, _b, _c;
202
+ var _a;
202
203
  let sectionValue = section.type === 'month' ? numberValue - 1 : numberValue;
204
+ const sectionMaxValue = (_a = section.maxValue) !== null && _a !== void 0 ? _a : 0;
203
205
  const allowsZero = section.minValue === 0;
204
- if (section.type === 'hour' &&
205
- (section.minValue === 12 || section.maxValue === 11)) {
206
- if (numberValue > 12) {
206
+ let shouldResetUserInput;
207
+ if (
208
+ // 12-hour clock format with AM/PM
209
+ section.type === 'hour' &&
210
+ (sectionMaxValue === 11 || section.minValue === 12)) {
211
+ if (sectionValue > 12) {
207
212
  sectionValue = Number(key);
213
+ newValue = key;
214
+ }
215
+ if (sectionValue === 0) {
216
+ sectionValue = -Infinity;
208
217
  }
209
- if (section.minValue === 12 && sectionValue > 1) {
218
+ if (sectionValue === 12) {
219
+ sectionValue = 0;
220
+ }
221
+ if (section.minValue === 12) {
210
222
  sectionValue += 12;
211
223
  }
224
+ shouldResetUserInput = Number(newValue + '0') > 12;
212
225
  }
213
- else if (sectionValue > ((_a = section.maxValue) !== null && _a !== void 0 ? _a : 0)) {
226
+ else if (sectionValue > sectionMaxValue) {
214
227
  sectionValue = Number(key) - (section.type === 'month' ? 1 : 0);
215
228
  newValue = key;
216
- if (sectionValue > ((_b = section.maxValue) !== null && _b !== void 0 ? _b : 0)) {
229
+ if (sectionValue > sectionMaxValue) {
217
230
  enteredKeys.current = '';
218
231
  return;
219
232
  }
@@ -222,15 +235,21 @@ export function useBaseDateFieldState(props) {
222
235
  if (shouldSetValue) {
223
236
  setSection(sectionIndex, sectionValue);
224
237
  }
225
- if (Number(numberValue + '0') > ((_c = section.maxValue) !== null && _c !== void 0 ? _c : 0) ||
226
- newValue.length >= String(section.maxValue).length) {
238
+ if (shouldResetUserInput === undefined) {
239
+ shouldResetUserInput = Number(newValue + '0') > sectionMaxValue;
240
+ }
241
+ const isMaxLength = newValue.length >= String(sectionMaxValue).length;
242
+ if (shouldResetUserInput) {
227
243
  enteredKeys.current = '';
228
244
  if (shouldSetValue) {
229
245
  this.focusNextSection();
230
246
  }
231
247
  }
248
+ else if (isMaxLength && shouldSetValue && !isLastSection) {
249
+ this.focusNextSection();
250
+ }
232
251
  else {
233
- enteredKeys.current = newValue === '0' && !allowsZero ? '' : newValue;
252
+ enteredKeys.current = newValue;
234
253
  }
235
254
  };
236
255
  const onInputString = (stringValue) => {
@@ -1 +1 @@
1
- {"version":3,"file":"useBaseDateFieldState.js","sourceRoot":"../../../../../src","sources":["components/DateField/hooks/useBaseDateFieldState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,EAAC,sBAAsB,EAAC,6BAA0B;AAEzD,OAAO,EACH,iBAAiB,EACjB,cAAc,EACd,8BAA8B,EAC9B,8BAA8B,GACjC,oBAAiB;AAElB,MAAM,SAAS,GAAkD;IAC7D,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IACV,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;CACb,CAAC;AAuGF,MAAM,UAAU,qBAAqB,CACjC,KAAmC;IAEnC,MAAM,EACF,KAAK,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,sBAAsB,EACtB,gBAAgB,EAChB,OAAO,EACP,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,QAAQ,EACR,OAAO,EACP,aAAa,EACb,UAAU,EACV,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,kBAAkB,GACrB,GAAG,KAAK,CAAC;IAEV,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAErC,OAAO;QACH,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,CAAC;oBACD,MAAM;gBACV,CAAC;YACL,CAAC;QACL,CAAC;QACD,kBAAkB,CAAC,GAAW;YAC1B,WAAW,CAAC,OAAO,GAAG,EAAE,CAAC;YACzB,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;KACJ,CAAC;AACN,CAAC","sourcesContent":["import React from 'react';\n\nimport type {DateTime} from '@gravity-ui/date-utils';\n\nimport type {ValidationState} from '../../types';\nimport {createPlaceholderValue} from '../../utils/dates';\nimport type {DateFieldSection, DateFieldSectionType, FormatInfo} from '../types';\nimport {\n EDITABLE_SEGMENTS,\n formatSections,\n getCurrentEditableSectionIndex,\n getDurationUnitFromSectionType,\n} from '../utils';\n\nconst PAGE_STEP: Partial<Record<DateFieldSectionType, number>> = {\n year: 5,\n quarter: 2,\n month: 2,\n weekday: 3,\n day: 7,\n hour: 2,\n minute: 15,\n second: 15,\n};\n\nexport type BaseDateFieldStateOptions<T = DateTime> = {\n value: T | null;\n displayValue: T;\n placeholderValue?: DateTime;\n timeZone: string;\n validationState?: ValidationState;\n editableSections: DateFieldSection[];\n formatInfo: FormatInfo;\n readOnly?: boolean;\n disabled?: boolean;\n selectedSectionIndexes: {startIndex: number; endIndex: number} | null;\n selectedSections: number | 'all';\n isEmpty: boolean;\n flushAllValidSections: () => void;\n flushValidSection: (sectionIndex: number) => void;\n setSelectedSections: (position: number | 'all') => void;\n setValue: (value: T) => void;\n setDate: (value: T | null) => void;\n adjustSection: (sectionIndex: number, amount: number) => void;\n setSection: (sectionIndex: number, amount: number) => void;\n getSectionValue: (sectionIndex: number) => DateTime;\n setSectionValue: (sectionIndex: number, currentValue: DateTime) => void;\n createPlaceholder: () => T;\n setValueFromString: (str: string) => boolean;\n};\n\nexport type DateFieldState<T = DateTime> = {\n /** The current field value. */\n value: T | null;\n /** Is no part of value is filled. */\n isEmpty: boolean;\n /** The current used value. value or placeholderValue */\n displayValue: T;\n /** Sets the field's value. */\n setValue: (value: T) => void;\n /** Sets the date value. */\n setDate: (value: T | null) => void;\n /** Formatted value */\n text: string;\n /** Whether the field is read only. */\n readOnly?: boolean;\n /** Whether the field is disabled. */\n disabled?: boolean;\n /** A list of segments for the current value. */\n sections: DateFieldSection[];\n /** Some info about available sections */\n formatInfo: FormatInfo;\n /**\n * @deprecated use formatInfo.hasDate instead.\n * Whether the the format is containing date parts\n */\n hasDate: boolean;\n /**\n * @deprecated use formatInfo.hasTime instead.\n * Whether the the format is containing time parts\n */\n hasTime: boolean;\n /** Selected sections */\n selectedSectionIndexes: {startIndex: number; endIndex: number} | null;\n /** The current validation state of the date field, based on the `validationState`, `minValue`, and `maxValue` props. */\n validationState?: ValidationState;\n /** Sets selection for segment in position. */\n setSelectedSections: (position: number | 'all') => void;\n /** Focuses segment in position */\n focusSectionInPosition: (position: number) => void;\n /** Focuses the next segment if present */\n focusNextSection: () => void;\n /** Focuses the previous segment if present */\n focusPreviousSection: () => void;\n /** Focuses the first segment */\n focusFirstSection: () => void;\n /** Focuses the last segment */\n focusLastSection: () => void;\n /** Increments the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */\n increment: () => void;\n /** Decrements the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */\n decrement: () => void;\n /**\n * Increments the currently selected segment by a larger amount, rounding it to the nearest increment.\n * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.\n * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.\n */\n incrementPage: () => void;\n /**\n * Decrements the currently selected segment by a larger amount, rounding it to the nearest decrement.\n * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.\n * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.\n */\n decrementPage: () => void;\n incrementToMax: () => void;\n decrementToMin: () => void;\n /** Clears the value of the currently selected segment, reverting it to the placeholder. */\n clearSection: () => void;\n /** Clears all segments, reverting them to the placeholder. */\n clearAll: () => void;\n /** Handles input key in the currently selected segment */\n onInput: (key: string) => void;\n //** Tries to set value from str. Supports date in input format or ISO */\n setValueFromString: (str: string) => boolean;\n};\n\nexport function useBaseDateFieldState<T = DateTime>(\n props: BaseDateFieldStateOptions<T>,\n): DateFieldState<T> {\n const {\n value,\n validationState,\n displayValue,\n editableSections,\n formatInfo,\n selectedSectionIndexes,\n selectedSections,\n isEmpty,\n flushAllValidSections,\n flushValidSection,\n setSelectedSections,\n setValue,\n setDate,\n adjustSection,\n setSection,\n getSectionValue,\n setSectionValue,\n createPlaceholder,\n setValueFromString,\n } = props;\n\n const enteredKeys = React.useRef('');\n\n return {\n value,\n isEmpty,\n displayValue,\n setValue,\n setDate,\n text: formatSections(editableSections),\n readOnly: props.readOnly,\n disabled: props.disabled,\n sections: editableSections,\n formatInfo,\n hasDate: formatInfo.hasDate,\n hasTime: formatInfo.hasTime,\n selectedSectionIndexes,\n validationState,\n setSelectedSections(position) {\n enteredKeys.current = '';\n setSelectedSections(position);\n },\n focusSectionInPosition(position) {\n const nextSectionIndex = this.sections.findIndex((s) => s.end >= position);\n const index = nextSectionIndex === -1 ? 0 : nextSectionIndex;\n const nextSection = this.sections[index];\n if (nextSection) {\n this.setSelectedSections(\n EDITABLE_SEGMENTS[nextSection.type] ? index : nextSection.nextEditableSection,\n );\n }\n },\n focusNextSection() {\n const currentIndex = selectedSections === 'all' ? 0 : selectedSections;\n const newIndex = this.sections[currentIndex]?.nextEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n focusPreviousSection() {\n const currentIndex = selectedSections === 'all' ? 0 : selectedSections;\n const newIndex = this.sections[currentIndex]?.previousEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n focusFirstSection() {\n const newIndex = this.sections[0]?.previousEditableSection ?? -1;\n if (newIndex !== -1) {\n setSelectedSections(newIndex);\n }\n },\n focusLastSection() {\n const newIndex = this.sections[this.sections.length - 1]?.nextEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n increment() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, 1);\n }\n },\n decrement() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, -1);\n }\n },\n incrementPage() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, PAGE_STEP[this.sections[sectionIndex].type] || 1);\n }\n },\n decrementPage() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, -(PAGE_STEP[this.sections[sectionIndex].type] || 1));\n }\n },\n incrementToMax() {\n if (this.readOnly || this.disabled) {\n return;\n }\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n const section = this.sections[sectionIndex];\n if (typeof section.maxValue === 'number') {\n setSection(sectionIndex, section.maxValue);\n }\n }\n },\n decrementToMin() {\n if (this.readOnly || this.disabled) {\n return;\n }\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n const section = this.sections[sectionIndex];\n if (typeof section.minValue === 'number') {\n setSection(sectionIndex, section.minValue);\n }\n }\n },\n clearSection() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n if (selectedSections === 'all') {\n this.clearAll();\n return;\n }\n\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex === -1) {\n return;\n }\n\n flushValidSection(sectionIndex);\n\n const section = this.sections[sectionIndex];\n\n const placeholder = createPlaceholderValue({\n placeholderValue: props.placeholderValue,\n timeZone: props.timeZone,\n }).timeZone(props.timeZone);\n\n const displayPortion = getSectionValue(sectionIndex);\n let currentValue = displayPortion;\n\n // Reset day period to default without changing the hour.\n if (section.type === 'dayPeriod') {\n const isPM = displayPortion.hour() >= 12;\n const shouldBePM = placeholder.hour() >= 12;\n if (isPM && !shouldBePM) {\n currentValue = displayPortion.set('hour', displayPortion.hour() - 12);\n } else if (!isPM && shouldBePM) {\n currentValue = displayPortion.set('hour', displayPortion.hour() + 12);\n }\n } else {\n const type = getDurationUnitFromSectionType(section.type);\n currentValue = displayPortion.set(type, placeholder[type]());\n }\n\n setSectionValue(sectionIndex, currentValue);\n },\n clearAll() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n flushAllValidSections();\n if (value !== null) {\n setDate(null);\n }\n\n const date = createPlaceholder();\n\n setValue(date);\n },\n onInput(key: string) {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex === -1) {\n return;\n }\n\n const section = this.sections[sectionIndex];\n let newValue = enteredKeys.current + key;\n\n const onInputNumber = (numberValue: number) => {\n let sectionValue = section.type === 'month' ? numberValue - 1 : numberValue;\n const allowsZero = section.minValue === 0;\n if (\n section.type === 'hour' &&\n (section.minValue === 12 || section.maxValue === 11)\n ) {\n if (numberValue > 12) {\n sectionValue = Number(key);\n }\n if (section.minValue === 12 && sectionValue > 1) {\n sectionValue += 12;\n }\n } else if (sectionValue > (section.maxValue ?? 0)) {\n sectionValue = Number(key) - (section.type === 'month' ? 1 : 0);\n newValue = key;\n if (sectionValue > (section.maxValue ?? 0)) {\n enteredKeys.current = '';\n return;\n }\n }\n\n const shouldSetValue = sectionValue > 0 || (sectionValue === 0 && allowsZero);\n if (shouldSetValue) {\n setSection(sectionIndex, sectionValue);\n }\n\n if (\n Number(numberValue + '0') > (section.maxValue ?? 0) ||\n newValue.length >= String(section.maxValue).length\n ) {\n enteredKeys.current = '';\n if (shouldSetValue) {\n this.focusNextSection();\n }\n } else {\n enteredKeys.current = newValue === '0' && !allowsZero ? '' : newValue;\n }\n };\n\n const onInputString = (stringValue: string) => {\n const options = section.options ?? [];\n let sectionValue = stringValue.toLocaleUpperCase();\n let foundOptions = options.filter((v) => v.startsWith(sectionValue));\n if (foundOptions.length === 0) {\n if (stringValue !== key) {\n sectionValue = key.toLocaleUpperCase();\n foundOptions = options.filter((v) => v.startsWith(sectionValue));\n }\n if (foundOptions.length === 0) {\n enteredKeys.current = '';\n return;\n }\n }\n const foundValue = foundOptions[0];\n const index = options.indexOf(foundValue);\n\n if (section.type === 'dayPeriod') {\n setSection(sectionIndex, index === 1 ? 12 : 0);\n } else {\n setSection(sectionIndex, index);\n }\n\n if (foundOptions.length > 1) {\n enteredKeys.current = newValue;\n } else {\n enteredKeys.current = '';\n this.focusNextSection();\n }\n };\n\n switch (section.type) {\n case 'day':\n case 'hour':\n case 'minute':\n case 'second':\n case 'quarter':\n case 'year': {\n if (!Number.isInteger(Number(newValue))) {\n return;\n }\n const numberValue = Number(newValue);\n onInputNumber(numberValue);\n break;\n }\n case 'dayPeriod': {\n onInputString(newValue);\n break;\n }\n case 'weekday':\n case 'month': {\n if (Number.isInteger(Number(newValue))) {\n const numberValue = Number(newValue);\n onInputNumber(numberValue);\n } else {\n onInputString(newValue);\n }\n break;\n }\n }\n },\n setValueFromString(str: string) {\n enteredKeys.current = '';\n return setValueFromString(str);\n },\n };\n}\n"]}
1
+ {"version":3,"file":"useBaseDateFieldState.js","sourceRoot":"../../../../../src","sources":["components/DateField/hooks/useBaseDateFieldState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,EAAC,sBAAsB,EAAC,6BAA0B;AAEzD,OAAO,EACH,iBAAiB,EACjB,cAAc,EACd,8BAA8B,EAC9B,8BAA8B,G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,CAAC;QACnC,CAAC;KACJ,CAAC;AACN,CAAC","sourcesContent":["import React from 'react';\n\nimport type {DateTime} from '@gravity-ui/date-utils';\n\nimport type {ValidationState} from '../../types';\nimport {createPlaceholderValue} from '../../utils/dates';\nimport type {DateFieldSection, DateFieldSectionType, FormatInfo} from '../types';\nimport {\n EDITABLE_SEGMENTS,\n formatSections,\n getCurrentEditableSectionIndex,\n getDurationUnitFromSectionType,\n} from '../utils';\n\nconst PAGE_STEP: Partial<Record<DateFieldSectionType, number>> = {\n year: 5,\n quarter: 2,\n month: 2,\n weekday: 3,\n day: 7,\n hour: 2,\n minute: 15,\n second: 15,\n};\n\nexport type BaseDateFieldStateOptions<T = DateTime> = {\n value: T | null;\n displayValue: T;\n placeholderValue?: DateTime;\n timeZone: string;\n validationState?: ValidationState;\n editableSections: DateFieldSection[];\n formatInfo: FormatInfo;\n readOnly?: boolean;\n disabled?: boolean;\n selectedSectionIndexes: {startIndex: number; endIndex: number} | null;\n selectedSections: number | 'all';\n isEmpty: boolean;\n flushAllValidSections: () => void;\n flushValidSection: (sectionIndex: number) => void;\n setSelectedSections: (position: number | 'all') => void;\n setValue: (value: T) => void;\n setDate: (value: T | null) => void;\n adjustSection: (sectionIndex: number, amount: number) => void;\n setSection: (sectionIndex: number, amount: number) => void;\n getSectionValue: (sectionIndex: number) => DateTime;\n setSectionValue: (sectionIndex: number, currentValue: DateTime) => void;\n createPlaceholder: () => T;\n setValueFromString: (str: string) => boolean;\n};\n\nexport type DateFieldState<T = DateTime> = {\n /** The current field value. */\n value: T | null;\n /** Is no part of value is filled. */\n isEmpty: boolean;\n /** The current used value. value or placeholderValue */\n displayValue: T;\n /** Sets the field's value. */\n setValue: (value: T) => void;\n /** Sets the date value. */\n setDate: (value: T | null) => void;\n /** Formatted value */\n text: string;\n /** Whether the field is read only. */\n readOnly?: boolean;\n /** Whether the field is disabled. */\n disabled?: boolean;\n /** A list of segments for the current value. */\n sections: DateFieldSection[];\n /** Some info about available sections */\n formatInfo: FormatInfo;\n /**\n * @deprecated use formatInfo.hasDate instead.\n * Whether the the format is containing date parts\n */\n hasDate: boolean;\n /**\n * @deprecated use formatInfo.hasTime instead.\n * Whether the the format is containing time parts\n */\n hasTime: boolean;\n /** Selected sections */\n selectedSectionIndexes: {startIndex: number; endIndex: number} | null;\n /** The current validation state of the date field, based on the `validationState`, `minValue`, and `maxValue` props. */\n validationState?: ValidationState;\n /** Sets selection for segment in position. */\n setSelectedSections: (position: number | 'all') => void;\n /** Focuses segment in position */\n focusSectionInPosition: (position: number) => void;\n /** Focuses the next segment if present */\n focusNextSection: () => void;\n /** Focuses the previous segment if present */\n focusPreviousSection: () => void;\n /** Focuses the first segment */\n focusFirstSection: () => void;\n /** Focuses the last segment */\n focusLastSection: () => void;\n /** Increments the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */\n increment: () => void;\n /** Decrements the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */\n decrement: () => void;\n /**\n * Increments the currently selected segment by a larger amount, rounding it to the nearest increment.\n * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.\n * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.\n */\n incrementPage: () => void;\n /**\n * Decrements the currently selected segment by a larger amount, rounding it to the nearest decrement.\n * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.\n * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.\n */\n decrementPage: () => void;\n incrementToMax: () => void;\n decrementToMin: () => void;\n /** Clears the value of the currently selected segment, reverting it to the placeholder. */\n clearSection: () => void;\n /** Clears all segments, reverting them to the placeholder. */\n clearAll: () => void;\n /** Handles input key in the currently selected segment */\n onInput: (key: string) => void;\n //** Tries to set value from str. Supports date in input format or ISO */\n setValueFromString: (str: string) => boolean;\n};\n\nexport function useBaseDateFieldState<T = DateTime>(\n props: BaseDateFieldStateOptions<T>,\n): DateFieldState<T> {\n const {\n value,\n validationState,\n displayValue,\n editableSections,\n formatInfo,\n selectedSectionIndexes,\n selectedSections,\n isEmpty,\n flushAllValidSections,\n flushValidSection,\n setSelectedSections,\n setValue,\n setDate,\n adjustSection,\n setSection,\n getSectionValue,\n setSectionValue,\n createPlaceholder,\n setValueFromString,\n } = props;\n\n const enteredKeys = React.useRef('');\n\n return {\n value,\n isEmpty,\n displayValue,\n setValue,\n setDate,\n text: formatSections(editableSections),\n readOnly: props.readOnly,\n disabled: props.disabled,\n sections: editableSections,\n formatInfo,\n hasDate: formatInfo.hasDate,\n hasTime: formatInfo.hasTime,\n selectedSectionIndexes,\n validationState,\n setSelectedSections(position) {\n enteredKeys.current = '';\n setSelectedSections(position);\n },\n focusSectionInPosition(position) {\n const nextSectionIndex = this.sections.findIndex((s) => s.end >= position);\n const index = nextSectionIndex === -1 ? 0 : nextSectionIndex;\n const nextSection = this.sections[index];\n if (nextSection) {\n this.setSelectedSections(\n EDITABLE_SEGMENTS[nextSection.type] ? index : nextSection.nextEditableSection,\n );\n }\n },\n focusNextSection() {\n const currentIndex = selectedSections === 'all' ? 0 : selectedSections;\n const newIndex = this.sections[currentIndex]?.nextEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n focusPreviousSection() {\n const currentIndex = selectedSections === 'all' ? 0 : selectedSections;\n const newIndex = this.sections[currentIndex]?.previousEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n focusFirstSection() {\n const newIndex = this.sections[0]?.previousEditableSection ?? -1;\n if (newIndex !== -1) {\n setSelectedSections(newIndex);\n }\n },\n focusLastSection() {\n const newIndex = this.sections[this.sections.length - 1]?.nextEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n increment() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, 1);\n }\n },\n decrement() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, -1);\n }\n },\n incrementPage() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, PAGE_STEP[this.sections[sectionIndex].type] || 1);\n }\n },\n decrementPage() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, -(PAGE_STEP[this.sections[sectionIndex].type] || 1));\n }\n },\n incrementToMax() {\n if (this.readOnly || this.disabled) {\n return;\n }\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n const section = this.sections[sectionIndex];\n if (typeof section.maxValue === 'number') {\n setSection(sectionIndex, section.maxValue);\n }\n }\n },\n decrementToMin() {\n if (this.readOnly || this.disabled) {\n return;\n }\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n const section = this.sections[sectionIndex];\n if (typeof section.minValue === 'number') {\n setSection(sectionIndex, section.minValue);\n }\n }\n },\n clearSection() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n if (selectedSections === 'all') {\n this.clearAll();\n return;\n }\n\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex === -1) {\n return;\n }\n\n flushValidSection(sectionIndex);\n\n const section = this.sections[sectionIndex];\n\n const placeholder = createPlaceholderValue({\n placeholderValue: props.placeholderValue,\n timeZone: props.timeZone,\n }).timeZone(props.timeZone);\n\n const displayPortion = getSectionValue(sectionIndex);\n let currentValue = displayPortion;\n\n // Reset day period to default without changing the hour.\n if (section.type === 'dayPeriod') {\n const isPM = displayPortion.hour() >= 12;\n const shouldBePM = placeholder.hour() >= 12;\n if (isPM && !shouldBePM) {\n currentValue = displayPortion.set('hour', displayPortion.hour() - 12);\n } else if (!isPM && shouldBePM) {\n currentValue = displayPortion.set('hour', displayPortion.hour() + 12);\n }\n } else {\n const type = getDurationUnitFromSectionType(section.type);\n currentValue = displayPortion.set(type, placeholder[type]());\n }\n\n setSectionValue(sectionIndex, currentValue);\n },\n clearAll() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n flushAllValidSections();\n if (value !== null) {\n setDate(null);\n }\n\n const date = createPlaceholder();\n\n setValue(date);\n },\n onInput(key: string) {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex === -1) {\n return;\n }\n\n const section = this.sections[sectionIndex];\n const isLastSection = section.nextEditableSection === sectionIndex;\n let newValue = enteredKeys.current + key;\n\n const onInputNumber = (numberValue: number) => {\n let sectionValue = section.type === 'month' ? numberValue - 1 : numberValue;\n const sectionMaxValue = section.maxValue ?? 0;\n const allowsZero = section.minValue === 0;\n let shouldResetUserInput;\n if (\n // 12-hour clock format with AM/PM\n section.type === 'hour' &&\n (sectionMaxValue === 11 || section.minValue === 12)\n ) {\n if (sectionValue > 12) {\n sectionValue = Number(key);\n newValue = key;\n }\n if (sectionValue === 0) {\n sectionValue = -Infinity;\n }\n if (sectionValue === 12) {\n sectionValue = 0;\n }\n if (section.minValue === 12) {\n sectionValue += 12;\n }\n shouldResetUserInput = Number(newValue + '0') > 12;\n } else if (sectionValue > sectionMaxValue) {\n sectionValue = Number(key) - (section.type === 'month' ? 1 : 0);\n newValue = key;\n if (sectionValue > sectionMaxValue) {\n enteredKeys.current = '';\n return;\n }\n }\n\n const shouldSetValue = sectionValue > 0 || (sectionValue === 0 && allowsZero);\n if (shouldSetValue) {\n setSection(sectionIndex, sectionValue);\n }\n\n if (shouldResetUserInput === undefined) {\n shouldResetUserInput = Number(newValue + '0') > sectionMaxValue;\n }\n const isMaxLength = newValue.length >= String(sectionMaxValue).length;\n if (shouldResetUserInput) {\n enteredKeys.current = '';\n if (shouldSetValue) {\n this.focusNextSection();\n }\n } else if (isMaxLength && shouldSetValue && !isLastSection) {\n this.focusNextSection();\n } else {\n enteredKeys.current = newValue;\n }\n };\n\n const onInputString = (stringValue: string) => {\n const options = section.options ?? [];\n let sectionValue = stringValue.toLocaleUpperCase();\n let foundOptions = options.filter((v) => v.startsWith(sectionValue));\n if (foundOptions.length === 0) {\n if (stringValue !== key) {\n sectionValue = key.toLocaleUpperCase();\n foundOptions = options.filter((v) => v.startsWith(sectionValue));\n }\n if (foundOptions.length === 0) {\n enteredKeys.current = '';\n return;\n }\n }\n const foundValue = foundOptions[0];\n const index = options.indexOf(foundValue);\n\n if (section.type === 'dayPeriod') {\n setSection(sectionIndex, index === 1 ? 12 : 0);\n } else {\n setSection(sectionIndex, index);\n }\n\n if (foundOptions.length > 1) {\n enteredKeys.current = newValue;\n } else {\n enteredKeys.current = '';\n this.focusNextSection();\n }\n };\n\n switch (section.type) {\n case 'day':\n case 'hour':\n case 'minute':\n case 'second':\n case 'quarter':\n case 'year': {\n if (!Number.isInteger(Number(newValue))) {\n return;\n }\n const numberValue = Number(newValue);\n onInputNumber(numberValue);\n break;\n }\n case 'dayPeriod': {\n onInputString(newValue);\n break;\n }\n case 'weekday':\n case 'month': {\n if (Number.isInteger(Number(newValue))) {\n const numberValue = Number(newValue);\n onInputNumber(numberValue);\n } else {\n onInputString(newValue);\n }\n break;\n }\n }\n },\n setValueFromString(str: string) {\n enteredKeys.current = '';\n return setValueFromString(str);\n },\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/date-components",
3
- "version": "3.2.2",
3
+ "version": "3.2.3",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",