@alfalab/core-components-date-input 4.4.20 → 5.0.0-snapshot-6a9d3fc

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.
Files changed (87) hide show
  1. package/Component.d.ts +4 -7
  2. package/Component.js +12 -13
  3. package/Component.js.map +1 -0
  4. package/cssm/Component.d.ts +4 -7
  5. package/cssm/Component.js +12 -11
  6. package/cssm/Component.js.map +1 -0
  7. package/cssm/index.d.ts +2 -2
  8. package/cssm/index.js +12 -11
  9. package/cssm/index.js.map +1 -0
  10. package/cssm/index.module.css +5 -24
  11. package/cssm/utils/format.d.ts +8 -9
  12. package/cssm/utils/format.js +1 -0
  13. package/cssm/utils/format.js.map +1 -0
  14. package/cssm/utils/index.d.ts +2 -2
  15. package/cssm/utils/index.js +12 -11
  16. package/cssm/utils/index.js.map +1 -0
  17. package/cssm/utils/native-supports.d.ts +1 -2
  18. package/cssm/utils/native-supports.js +1 -0
  19. package/cssm/utils/native-supports.js.map +1 -0
  20. package/esm/Component.d.ts +4 -7
  21. package/esm/Component.js +3 -4
  22. package/esm/Component.js.map +1 -0
  23. package/esm/index.css +7 -27
  24. package/esm/index.d.ts +2 -2
  25. package/esm/index.js +1 -0
  26. package/esm/index.js.map +1 -0
  27. package/esm/index.module.css.js +6 -0
  28. package/esm/index.module.css.js.map +1 -0
  29. package/esm/utils/format.d.ts +8 -9
  30. package/esm/utils/format.js +1 -0
  31. package/esm/utils/format.js.map +1 -0
  32. package/esm/utils/index.d.ts +2 -2
  33. package/esm/utils/index.js +1 -0
  34. package/esm/utils/index.js.map +1 -0
  35. package/esm/utils/native-supports.d.ts +1 -2
  36. package/esm/utils/native-supports.js +1 -0
  37. package/esm/utils/native-supports.js.map +1 -0
  38. package/index.css +7 -27
  39. package/index.d.ts +2 -2
  40. package/index.js +12 -11
  41. package/index.js.map +1 -0
  42. package/index.module.css.js +8 -0
  43. package/index.module.css.js.map +1 -0
  44. package/modern/Component.d.ts +4 -7
  45. package/modern/Component.js +3 -4
  46. package/modern/Component.js.map +1 -0
  47. package/modern/index.css +7 -27
  48. package/modern/index.d.ts +2 -2
  49. package/modern/index.js +1 -0
  50. package/modern/index.js.map +1 -0
  51. package/modern/index.module.css.js +6 -0
  52. package/modern/index.module.css.js.map +1 -0
  53. package/modern/utils/format.d.ts +8 -9
  54. package/modern/utils/format.js +1 -0
  55. package/modern/utils/format.js.map +1 -0
  56. package/modern/utils/index.d.ts +2 -2
  57. package/modern/utils/index.js +1 -0
  58. package/modern/utils/index.js.map +1 -0
  59. package/modern/utils/native-supports.d.ts +1 -2
  60. package/modern/utils/native-supports.js +1 -0
  61. package/modern/utils/native-supports.js.map +1 -0
  62. package/moderncssm/Component.d.ts +4 -7
  63. package/moderncssm/Component.js +2 -1
  64. package/moderncssm/Component.js.map +1 -0
  65. package/moderncssm/index.d.ts +2 -2
  66. package/moderncssm/index.js +1 -0
  67. package/moderncssm/index.js.map +1 -0
  68. package/moderncssm/index.module.css +3 -3
  69. package/moderncssm/utils/format.d.ts +8 -9
  70. package/moderncssm/utils/format.js +1 -0
  71. package/moderncssm/utils/format.js.map +1 -0
  72. package/moderncssm/utils/index.d.ts +2 -2
  73. package/moderncssm/utils/index.js +1 -0
  74. package/moderncssm/utils/index.js.map +1 -0
  75. package/moderncssm/utils/native-supports.d.ts +1 -2
  76. package/moderncssm/utils/native-supports.js +1 -0
  77. package/moderncssm/utils/native-supports.js.map +1 -0
  78. package/package.json +6 -5
  79. package/utils/format.d.ts +8 -9
  80. package/utils/format.js +1 -0
  81. package/utils/format.js.map +1 -0
  82. package/utils/index.d.ts +2 -2
  83. package/utils/index.js +12 -11
  84. package/utils/index.js.map +1 -0
  85. package/utils/native-supports.d.ts +1 -2
  86. package/utils/native-supports.js +1 -0
  87. package/utils/native-supports.js.map +1 -0
@@ -1,8 +1,6 @@
1
- /// <reference types="react" />
2
- import React from 'react';
3
- import { ChangeEvent } from "react";
4
- import { InputProps } from "@alfalab/core-components-input";
5
- type DateInputProps = Omit<InputProps, 'onChange'> & {
1
+ import React, { ChangeEvent } from 'react';
2
+ import { InputProps } from '@alfalab/core-components-input';
3
+ export declare type DateInputProps = Omit<InputProps, 'onChange'> & {
6
4
  /**
7
5
  * Управление нативным режимом на мобильных устройствах
8
6
  */
@@ -26,7 +24,7 @@ type DateInputProps = Omit<InputProps, 'onChange'> & {
26
24
  * @deprecated
27
25
  * use UniversalDateInput instead
28
26
  */
29
- declare const DateInput: React.ForwardRefExoticComponent<Omit<InputProps, "onChange"> & {
27
+ export declare const DateInput: React.ForwardRefExoticComponent<Omit<InputProps, "onChange"> & {
30
28
  /**
31
29
  * Управление нативным режимом на мобильных устройствах
32
30
  */
@@ -46,4 +44,3 @@ declare const DateInput: React.ForwardRefExoticComponent<Omit<InputProps, "onCha
46
44
  value: string;
47
45
  }) => void) | undefined;
48
46
  } & React.RefAttributes<HTMLInputElement>>;
49
- export { DateInputProps, DateInput };
@@ -1,7 +1,7 @@
1
1
  import React, { forwardRef, useRef, useState, useEffect } from 'react';
2
2
  import mergeRefs from 'react-merge-refs';
3
3
  import { Input } from '@alfalab/core-components-input/moderncssm';
4
- import { format, parseDateString, isCompleteDateInput, isValid, NATIVE_DATE_FORMAT, formatDate } from './utils/format.js';
4
+ import { format, parseDateString, isCompleteDateInput, isValid, formatDate, NATIVE_DATE_FORMAT } from './utils/format.js';
5
5
  import { isInputDateSupported } from './utils/native-supports.js';
6
6
  import styles from './index.module.css';
7
7
 
@@ -91,3 +91,4 @@ function getDotsCount(value) {
91
91
  }
92
92
 
93
93
  export { DateInput };
94
+ //# sourceMappingURL=Component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Component.js","sources":["../src/Component.tsx"],"sourcesContent":["import React, { ChangeEvent, FocusEvent, forwardRef, useEffect, useRef, useState } from 'react';\nimport mergeRefs from 'react-merge-refs';\n\nimport { Input, InputProps } from '@alfalab/core-components-input';\n\nimport {\n format,\n formatDate,\n isCompleteDateInput,\n isInputDateSupported,\n isValid,\n NATIVE_DATE_FORMAT,\n parseDateString,\n} from './utils';\n\nimport styles from './index.module.css';\n\nexport type DateInputProps = Omit<InputProps, 'onChange'> & {\n /**\n * Управление нативным режимом на мобильных устройствах\n */\n mobileMode?: 'input' | 'native';\n\n /**\n * Обработчик изменения значения\n */\n onChange?: (\n event: ChangeEvent<HTMLInputElement>,\n payload: { date: Date; value: string },\n ) => void;\n\n /**\n * Обработчик окончания ввода\n */\n onComplete?: (\n event: ChangeEvent<HTMLInputElement>,\n payload: { date: Date; value: string },\n ) => void;\n};\n\n/**\n * @deprecated\n * use UniversalDateInput instead\n */\nexport const DateInput = forwardRef<HTMLInputElement, DateInputProps>(\n (\n {\n mobileMode = 'input',\n defaultValue = '',\n rightAddons,\n error,\n value: propValue,\n onBlur,\n onChange,\n onComplete,\n ...restProps\n },\n ref,\n ) => {\n const inputRef = useRef<HTMLInputElement>(null);\n\n const [shouldRenderNative, setShouldRenderNative] = useState(false);\n\n const [value, setValue] = useState(propValue || defaultValue);\n\n const moveCaretTo = (pos: number) => {\n requestAnimationFrame(() => {\n inputRef.current?.setSelectionRange(pos, pos);\n });\n };\n\n const handleChange = (event: ChangeEvent<HTMLInputElement>) => {\n const { value: newValue } = event.target;\n const caretPos = event.target.selectionStart || 0;\n\n // Позволяем вводить только цифры и точки\n if (/[^\\d.]/.test(newValue)) {\n moveCaretTo(caretPos - 1);\n\n return;\n }\n\n // Не даем вводить больше, чем 2 точки\n if (getDotsCount(newValue) > 2) {\n moveCaretTo(caretPos - 1);\n\n return;\n }\n\n // Форматируем введенное значение (добавляем точки)\n const formattedValue = format(newValue);\n const date = parseDateString(formattedValue);\n\n // Управляем кареткой, если она находится не в конце инпута\n if (caretPos !== newValue.length) {\n if (formattedValue === value) {\n moveCaretTo(caretPos);\n } else if (newValue.length - formattedValue.length === 1) {\n moveCaretTo(caretPos);\n } else if (\n formattedValue.length - newValue.length === 1 &&\n getDotsCount(formattedValue) > getDotsCount(newValue)\n ) {\n moveCaretTo(caretPos);\n }\n }\n\n setValue(formattedValue);\n\n if (onChange) onChange(event, { date, value: formattedValue });\n\n if (isCompleteDateInput(formattedValue)) {\n const valid = formattedValue.length > 0 && isValid(formattedValue);\n\n if (!valid) return;\n\n if (onComplete) onComplete(event, { date, value: formattedValue });\n }\n };\n\n const handleNativeInputChange = (event: ChangeEvent<HTMLInputElement>) => {\n const newDate = parseDateString(event.target.value, NATIVE_DATE_FORMAT);\n const newValue = event.target.value === '' ? '' : formatDate(newDate);\n\n setValue(newValue);\n\n if (onComplete) onComplete(event, { date: newDate, value: newValue });\n if (onChange) onChange(event, { date: newDate, value: newValue });\n };\n\n const handleBlur = (event: FocusEvent<HTMLInputElement>) => {\n if (onBlur) onBlur(event);\n };\n\n useEffect(() => {\n if (mobileMode === 'native' && isInputDateSupported()) {\n setShouldRenderNative(true);\n }\n }, [mobileMode]);\n\n useEffect(() => {\n if (typeof propValue !== 'undefined') {\n setValue(propValue);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [propValue]);\n\n return (\n <Input\n {...restProps}\n ref={mergeRefs([ref, inputRef])}\n value={value}\n inputMode='decimal'\n pattern='[0-9\\.]*'\n onChange={handleChange}\n onBlur={handleBlur}\n placeholder='ДД.ММ.ГГГГ'\n error={error}\n rightAddons={\n <React.Fragment>\n {rightAddons}\n\n {shouldRenderNative && (\n <input\n type='date'\n ref={ref}\n defaultValue={defaultValue}\n onChange={handleNativeInputChange}\n className={styles.nativeInput}\n />\n )}\n </React.Fragment>\n }\n />\n );\n },\n);\n\nfunction getDotsCount(value: string) {\n return (value.match(/\\./g) || []).length;\n}\n"],"names":[],"mappings":";;;;;;;AAwCA;;;AAGG;AACU,MAAA,SAAS,GAAG,UAAU,CAC/B,CACI,EACI,UAAU,GAAG,OAAO,EACpB,YAAY,GAAG,EAAE,EACjB,WAAW,EACX,KAAK,EACL,KAAK,EAAE,SAAS,EAChB,MAAM,EACN,QAAQ,EACR,UAAU,EACV,GAAG,SAAS,EACf,EACD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,CAAC;AAC7B,KAAC;IAED,SAAS,CAAC,MAAK;AACX,QAAA,IAAI,UAAU,KAAK,QAAQ,IAAI,oBAAoB,EAAE,EAAE;YACnD,qBAAqB,CAAC,IAAI,CAAC;AAC9B;AACL,KAAC,EAAE,CAAC,UAAU,CAAC,CAAC;IAEhB,SAAS,CAAC,MAAK;AACX,QAAA,IAAI,OAAO,SAAS,KAAK,WAAW,EAAE;YAClC,QAAQ,CAAC,SAAS,CAAC;AACtB;;AAEL,KAAC,EAAE,CAAC,SAAS,CAAC,CAAC;IAEf,QACI,oBAAC,KAAK,EAAA,EAAA,GACE,SAAS,EACb,GAAG,EAAE,SAAS,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,EAC/B,KAAK,EAAE,KAAK,EACZ,SAAS,EAAC,SAAS,EACnB,OAAO,EAAC,WAAU,EAClB,QAAQ,EAAE,YAAY,EACtB,MAAM,EAAE,UAAU,EAClB,WAAW,EAAC,oDAAY,EACxB,KAAK,EAAE,KAAK,EACZ,WAAW,EACP,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,QAAQ,EAAA,IAAA;YACV,WAAW;AAEX,YAAA,kBAAkB,KACf,KACI,CAAA,aAAA,CAAA,OAAA,EAAA,EAAA,IAAI,EAAC,MAAM,EACX,GAAG,EAAE,GAAG,EACR,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,uBAAuB,EACjC,SAAS,EAAE,MAAM,CAAC,WAAW,EAC/B,CAAA,CACL,CACY,EAAA,CAEvB;AAEV,CAAC;AAGL,SAAS,YAAY,CAAC,KAAa,EAAA;AAC/B,IAAA,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,MAAM;AAC5C;;;;"}
@@ -1,2 +1,2 @@
1
- export * from "./Component";
2
- export * from "./utils/index";
1
+ export * from './Component';
2
+ export * from './utils';
@@ -1,3 +1,4 @@
1
1
  export { DateInput } from './Component.js';
2
2
  export { DATE_FORMAT, DATE_MASK, NATIVE_DATE_FORMAT, format, formatDate, isCompleteDateInput, isValid, parseDateString } from './utils/format.js';
3
3
  export { isInputDateSupported } from './utils/native-supports.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -1,5 +1,3 @@
1
- /* */
2
-
3
1
  .nativeInput {
4
2
  opacity: 0;
5
3
  position: absolute;
@@ -7,7 +5,9 @@
7
5
  left: var(--gap-0);
8
6
  width: 100%;
9
7
  height: 100%;
10
- appearance: none;
8
+ -webkit-appearance: none;
9
+ -moz-appearance: none;
10
+ appearance: none;
11
11
  z-index: 1
12
12
  }
13
13
 
@@ -1,9 +1,8 @@
1
- declare const DATE_FORMAT = "dd.MM.yyyy";
2
- declare const NATIVE_DATE_FORMAT = "yyyy-MM-dd";
3
- declare const DATE_MASK: (string | RegExp)[];
4
- declare const isCompleteDateInput: (input: string) => boolean;
5
- declare const formatDate: (date: Date | number, dateFormat?: string) => string;
6
- declare const parseDateString: (value: string, dateFormat?: string) => Date;
7
- declare const isValid: (inputValue?: string) => boolean;
8
- declare const format: (value: string) => string;
9
- export { DATE_FORMAT, NATIVE_DATE_FORMAT, DATE_MASK, isCompleteDateInput, formatDate, parseDateString, isValid, format };
1
+ export declare const DATE_FORMAT = "dd.MM.yyyy";
2
+ export declare const NATIVE_DATE_FORMAT = "yyyy-MM-dd";
3
+ export declare const DATE_MASK: (string | RegExp)[];
4
+ export declare const isCompleteDateInput: (input: string) => boolean;
5
+ export declare const formatDate: (date: Date | number, dateFormat?: string) => string;
6
+ export declare const parseDateString: (value: string, dateFormat?: string) => Date;
7
+ export declare const isValid: (inputValue?: string) => boolean;
8
+ export declare const format: (value: string) => string;
@@ -28,3 +28,4 @@ const format = (value) => value
28
28
  .replace(/^()\.(\d)\.(\d\d\d\d)([0-9]*)/, '$1.$2.$3'); // .2.2005123123 => .2.2005
29
29
 
30
30
  export { DATE_FORMAT, DATE_MASK, NATIVE_DATE_FORMAT, format, formatDate, isCompleteDateInput, isValid, parseDateString };
31
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sources":["../../src/utils/format.ts"],"sourcesContent":["import dateFnsFormat from 'date-fns/format';\nimport dateFnsIsValid from 'date-fns/isValid';\nimport parse from 'date-fns/parse';\n\nexport const DATE_FORMAT = 'dd.MM.yyyy';\nexport const NATIVE_DATE_FORMAT = 'yyyy-MM-dd';\nexport const DATE_MASK = [/\\d/, /\\d/, '.', /\\d/, /\\d/, '.', /\\d/, /\\d/, /\\d/, /\\d/];\n\nexport const isCompleteDateInput = (input: string) => input.length === DATE_MASK.length;\n\nexport const formatDate = (date: Date | number, dateFormat = DATE_FORMAT) =>\n dateFnsFormat(date, dateFormat);\n\nexport const parseDateString = (value: string, dateFormat = DATE_FORMAT) =>\n parse(value, dateFormat, new Date());\n\nexport const isValid = (inputValue?: string) =>\n !inputValue || (isCompleteDateInput(inputValue) && dateFnsIsValid(parseDateString(inputValue)));\n\nexport const format = (value: string): string =>\n value\n .replace(/^(\\d\\d)(\\d)$/, '$1.$2') // 121 => 12.1\n .replace(/^(\\d\\d)\\.(\\d\\d)(\\d)$/, '$1.$2.$3') // 12.122 => 12.12.2\n .replace(/^(\\d\\d)\\d\\.(.*)/, '$1.$2') // 123.12.2005 => 12.12.2005\n .replace(/^(\\d\\d\\.\\d\\d)\\d\\.(.*)/, '$1.$2') // 12.123.2005 => 12.12.2005\n .replace(/^(\\d\\d\\.\\d\\d\\.\\d\\d\\d\\d).*/, '$1') // 12.12.20056 => 12.12.2005\n .replace(/\\.$/, '') // 12. => 12\n .replace(/^(\\d\\d\\.\\d\\d)(\\d\\d\\d\\d)/, '$1.$2') // 12.122005 => 12.12.2005\n .replace(/^(\\d\\d)(\\d\\d\\.\\d\\d\\d\\d)/, '$1.$2') // 1212.2005 => 12.12.2005\n .replace(/^(\\d\\.\\d\\d\\.\\d\\d\\d\\d)([0-9]*)/, '$1') // 1.12.2005123123 => 01.12.2005\n .replace(/^(\\d\\d\\.\\d\\.\\d\\d\\d\\d)([0-9]*)/, '$1') // 01.2.20055125125 => 01.2.2005\n .replace(/^(\\d\\.\\d\\.\\d\\d\\d\\d)([0-9]*)/, '$1') // 1.2.20055125125 => 1.2.2005\n .replace(/^(\\d)\\.(\\d\\d)([0-9]*)\\.(\\d\\d\\d\\d)/, '$1.$2.$4') // 1.123123.2005 => 1.12.2005\n .replace(/^(\\d\\d)\\.()\\.(\\d\\d\\d\\d)([0-9]*)/, '$1.$2.$3') // 01..2005123123 => 01..2005\n .replace(/^(\\d)\\.()\\.(\\d\\d\\d\\d)([0-9]*)/, '$1.$2.$3') // 1..2005123123 => 1..2005\n .replace(/^()\\.()\\.(\\d\\d\\d\\d)([0-9]*)/, '$1.$2.$3') // ..2005123123 => ..2005\n .replace(/^()\\.(\\d)\\.(\\d\\d\\d\\d)([0-9]*)/, '$1.$2.$3'); // .2.2005123123 => .2.2005\n"],"names":[],"mappings":";;;;AAIO,MAAM,WAAW,GAAG;AACpB,MAAM,kBAAkB,GAAG;AACrB,MAAA,SAAS,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;AAErE,MAAA,mBAAmB,GAAG,CAAC,KAAa,KAAK,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC;AAEpE,MAAA,UAAU,GAAG,CAAC,IAAmB,EAAE,UAAU,GAAG,WAAW,KACpE,aAAa,CAAC,IAAI,EAAE,UAAU;MAErB,eAAe,GAAG,CAAC,KAAa,EAAE,UAAU,GAAG,WAAW,KACnE,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,IAAI,EAAE;AAE1B,MAAA,OAAO,GAAG,CAAC,UAAmB,KACvC,CAAC,UAAU,KAAK,mBAAmB,CAAC,UAAU,CAAC,IAAI,cAAc,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;MAErF,MAAM,GAAG,CAAC,KAAa,KAChC;AACK,KAAA,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC;AAChC,KAAA,OAAO,CAAC,sBAAsB,EAAE,UAAU,CAAC;AAC3C,KAAA,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC;AACnC,KAAA,OAAO,CAAC,uBAAuB,EAAE,OAAO,CAAC;AACzC,KAAA,OAAO,CAAC,2BAA2B,EAAE,IAAI,CAAC;AAC1C,KAAA,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;AAClB,KAAA,OAAO,CAAC,yBAAyB,EAAE,OAAO,CAAC;AAC3C,KAAA,OAAO,CAAC,yBAAyB,EAAE,OAAO,CAAC;AAC3C,KAAA,OAAO,CAAC,+BAA+B,EAAE,IAAI,CAAC;AAC9C,KAAA,OAAO,CAAC,+BAA+B,EAAE,IAAI,CAAC;AAC9C,KAAA,OAAO,CAAC,6BAA6B,EAAE,IAAI,CAAC;AAC5C,KAAA,OAAO,CAAC,mCAAmC,EAAE,UAAU,CAAC;AACxD,KAAA,OAAO,CAAC,iCAAiC,EAAE,UAAU,CAAC;AACtD,KAAA,OAAO,CAAC,+BAA+B,EAAE,UAAU,CAAC;AACpD,KAAA,OAAO,CAAC,6BAA6B,EAAE,UAAU,CAAC;AAClD,KAAA,OAAO,CAAC,+BAA+B,EAAE,UAAU,EAAE;;;;"}
@@ -1,2 +1,2 @@
1
- export * from "./format";
2
- export * from "./native-supports";
1
+ export * from './format';
2
+ export * from './native-supports';
@@ -1,2 +1,3 @@
1
1
  export { DATE_FORMAT, DATE_MASK, NATIVE_DATE_FORMAT, format, formatDate, isCompleteDateInput, isValid, parseDateString } from './format.js';
2
2
  export { isInputDateSupported } from './native-supports.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,5 +1,4 @@
1
1
  /**
2
2
  * Возвращает `true`, если поддерживается `input[type="date"]`
3
3
  */
4
- declare function isInputDateSupported(): boolean;
5
- export { isInputDateSupported };
4
+ export declare function isInputDateSupported(): boolean;
@@ -10,3 +10,4 @@ function isInputDateSupported() {
10
10
  }
11
11
 
12
12
  export { isInputDateSupported };
13
+ //# sourceMappingURL=native-supports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-supports.js","sources":["../../src/utils/native-supports.ts"],"sourcesContent":["/**\n * Возвращает `true`, если поддерживается `input[type=\"date\"]`\n */\nexport function isInputDateSupported() {\n const input = document.createElement('input');\n const value = 'a';\n\n input.setAttribute('type', 'date');\n input.setAttribute('value', value);\n\n return input.value !== value;\n}\n"],"names":[],"mappings":"AAAA;;AAEG;SACa,oBAAoB,GAAA;IAChC,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC;IAC7C,MAAM,KAAK,GAAG,GAAG;AAEjB,IAAA,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC;AAClC,IAAA,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC;AAElC,IAAA,OAAO,KAAK,CAAC,KAAK,KAAK,KAAK;AAChC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfalab/core-components-date-input",
3
- "version": "4.4.20",
3
+ "version": "5.0.0-snapshot-6a9d3fc",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -12,14 +12,15 @@
12
12
  },
13
13
  "sideEffects": false,
14
14
  "peerDependencies": {
15
- "react": "^16.9.0 || ^17.0.1 || ^18.0.0"
15
+ "react": "^16.9.0 || ^17.0.1 || ^18.0.0",
16
+ "react-dom": "^16.9.0 || ^17.0.1 || ^18.0.0"
16
17
  },
17
18
  "dependencies": {
18
- "@alfalab/core-components-input": "^15.6.2",
19
+ "@alfalab/core-components-input": "16.0.0-snapshot-6a9d3fc",
19
20
  "date-fns": "^2.16.1",
20
21
  "react-merge-refs": "^1.1.0",
21
22
  "tslib": "^2.4.0"
22
23
  },
23
- "themesVersion": "13.7.4",
24
- "varsVersion": "9.20.1"
24
+ "themesVersion": "14.0.0-snapshot-6a9d3fc",
25
+ "varsVersion": "10.0.0-snapshot-6a9d3fc"
25
26
  }
package/utils/format.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- declare const DATE_FORMAT = "dd.MM.yyyy";
2
- declare const NATIVE_DATE_FORMAT = "yyyy-MM-dd";
3
- declare const DATE_MASK: (string | RegExp)[];
4
- declare const isCompleteDateInput: (input: string) => boolean;
5
- declare const formatDate: (date: Date | number, dateFormat?: string) => string;
6
- declare const parseDateString: (value: string, dateFormat?: string) => Date;
7
- declare const isValid: (inputValue?: string) => boolean;
8
- declare const format: (value: string) => string;
9
- export { DATE_FORMAT, NATIVE_DATE_FORMAT, DATE_MASK, isCompleteDateInput, formatDate, parseDateString, isValid, format };
1
+ export declare const DATE_FORMAT = "dd.MM.yyyy";
2
+ export declare const NATIVE_DATE_FORMAT = "yyyy-MM-dd";
3
+ export declare const DATE_MASK: (string | RegExp)[];
4
+ export declare const isCompleteDateInput: (input: string) => boolean;
5
+ export declare const formatDate: (date: Date | number, dateFormat?: string) => string;
6
+ export declare const parseDateString: (value: string, dateFormat?: string) => Date;
7
+ export declare const isValid: (inputValue?: string) => boolean;
8
+ export declare const format: (value: string) => string;
package/utils/format.js CHANGED
@@ -55,3 +55,4 @@ exports.formatDate = formatDate;
55
55
  exports.isCompleteDateInput = isCompleteDateInput;
56
56
  exports.isValid = isValid;
57
57
  exports.parseDateString = parseDateString;
58
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sources":["../src/utils/format.ts"],"sourcesContent":["import dateFnsFormat from 'date-fns/format';\nimport dateFnsIsValid from 'date-fns/isValid';\nimport parse from 'date-fns/parse';\n\nexport const DATE_FORMAT = 'dd.MM.yyyy';\nexport const NATIVE_DATE_FORMAT = 'yyyy-MM-dd';\nexport const DATE_MASK = [/\\d/, /\\d/, '.', /\\d/, /\\d/, '.', /\\d/, /\\d/, /\\d/, /\\d/];\n\nexport const isCompleteDateInput = (input: string) => input.length === DATE_MASK.length;\n\nexport const formatDate = (date: Date | number, dateFormat = DATE_FORMAT) =>\n dateFnsFormat(date, dateFormat);\n\nexport const parseDateString = (value: string, dateFormat = DATE_FORMAT) =>\n parse(value, dateFormat, new Date());\n\nexport const isValid = (inputValue?: string) =>\n !inputValue || (isCompleteDateInput(inputValue) && dateFnsIsValid(parseDateString(inputValue)));\n\nexport const format = (value: string): string =>\n value\n .replace(/^(\\d\\d)(\\d)$/, '$1.$2') // 121 => 12.1\n .replace(/^(\\d\\d)\\.(\\d\\d)(\\d)$/, '$1.$2.$3') // 12.122 => 12.12.2\n .replace(/^(\\d\\d)\\d\\.(.*)/, '$1.$2') // 123.12.2005 => 12.12.2005\n .replace(/^(\\d\\d\\.\\d\\d)\\d\\.(.*)/, '$1.$2') // 12.123.2005 => 12.12.2005\n .replace(/^(\\d\\d\\.\\d\\d\\.\\d\\d\\d\\d).*/, '$1') // 12.12.20056 => 12.12.2005\n .replace(/\\.$/, '') // 12. => 12\n .replace(/^(\\d\\d\\.\\d\\d)(\\d\\d\\d\\d)/, '$1.$2') // 12.122005 => 12.12.2005\n .replace(/^(\\d\\d)(\\d\\d\\.\\d\\d\\d\\d)/, '$1.$2') // 1212.2005 => 12.12.2005\n .replace(/^(\\d\\.\\d\\d\\.\\d\\d\\d\\d)([0-9]*)/, '$1') // 1.12.2005123123 => 01.12.2005\n .replace(/^(\\d\\d\\.\\d\\.\\d\\d\\d\\d)([0-9]*)/, '$1') // 01.2.20055125125 => 01.2.2005\n .replace(/^(\\d\\.\\d\\.\\d\\d\\d\\d)([0-9]*)/, '$1') // 1.2.20055125125 => 1.2.2005\n .replace(/^(\\d)\\.(\\d\\d)([0-9]*)\\.(\\d\\d\\d\\d)/, '$1.$2.$4') // 1.123123.2005 => 1.12.2005\n .replace(/^(\\d\\d)\\.()\\.(\\d\\d\\d\\d)([0-9]*)/, '$1.$2.$3') // 01..2005123123 => 01..2005\n .replace(/^(\\d)\\.()\\.(\\d\\d\\d\\d)([0-9]*)/, '$1.$2.$3') // 1..2005123123 => 1..2005\n .replace(/^()\\.()\\.(\\d\\d\\d\\d)([0-9]*)/, '$1.$2.$3') // ..2005123123 => ..2005\n .replace(/^()\\.(\\d)\\.(\\d\\d\\d\\d)([0-9]*)/, '$1.$2.$3'); // .2.2005123123 => .2.2005\n"],"names":["dateFnsFormat","parse","dateFnsIsValid"],"mappings":";;;;;;;;;;;;;;AAIO,IAAM,WAAW,GAAG;AACpB,IAAM,kBAAkB,GAAG;AACrB,IAAA,SAAS,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;AAErE,IAAA,mBAAmB,GAAG,UAAC,KAAa,EAAK,EAAA,OAAA,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM,CAAA;AAE1E,IAAA,UAAU,GAAG,UAAC,IAAmB,EAAE,UAAwB,EAAA;AAAxB,IAAA,IAAA,UAAA,KAAA,MAAA,EAAA,EAAA,UAAwB,GAAA,WAAA,CAAA;AACpE,IAAA,OAAAA,8BAAa,CAAC,IAAI,EAAE,UAAU,CAAC;AAA/B;AAES,IAAA,eAAe,GAAG,UAAC,KAAa,EAAE,UAAwB,EAAA;AAAxB,IAAA,IAAA,UAAA,KAAA,MAAA,EAAA,EAAA,UAAwB,GAAA,WAAA,CAAA;IACnE,OAAAC,sBAAK,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC;AAApC;AAEG,IAAM,OAAO,GAAG,UAAC,UAAmB,EAAA;AACvC,IAAA,OAAA,CAAC,UAAU,KAAK,mBAAmB,CAAC,UAAU,CAAC,IAAIC,+BAAc,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC;AAA/F;AAEG,IAAM,MAAM,GAAG,UAAC,KAAa,EAAA;AAChC,IAAA,OAAA;AACK,SAAA,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC;AAChC,SAAA,OAAO,CAAC,sBAAsB,EAAE,UAAU,CAAC;AAC3C,SAAA,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC;AACnC,SAAA,OAAO,CAAC,uBAAuB,EAAE,OAAO,CAAC;AACzC,SAAA,OAAO,CAAC,2BAA2B,EAAE,IAAI,CAAC;AAC1C,SAAA,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;AAClB,SAAA,OAAO,CAAC,yBAAyB,EAAE,OAAO,CAAC;AAC3C,SAAA,OAAO,CAAC,yBAAyB,EAAE,OAAO,CAAC;AAC3C,SAAA,OAAO,CAAC,+BAA+B,EAAE,IAAI,CAAC;AAC9C,SAAA,OAAO,CAAC,+BAA+B,EAAE,IAAI,CAAC;AAC9C,SAAA,OAAO,CAAC,6BAA6B,EAAE,IAAI,CAAC;AAC5C,SAAA,OAAO,CAAC,mCAAmC,EAAE,UAAU,CAAC;AACxD,SAAA,OAAO,CAAC,iCAAiC,EAAE,UAAU,CAAC;AACtD,SAAA,OAAO,CAAC,+BAA+B,EAAE,UAAU,CAAC;AACpD,SAAA,OAAO,CAAC,6BAA6B,EAAE,UAAU,CAAC;AAClD,SAAA,OAAO,CAAC,+BAA+B,EAAE,UAAU,CAAC;AAhBzD,EAgB0D;;;;;;;;;;;"}
package/utils/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./format";
2
- export * from "./native-supports";
1
+ export * from './format';
2
+ export * from './native-supports';
package/utils/index.js CHANGED
@@ -2,17 +2,18 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var utils_format = require('./format.js');
6
- var utils_nativeSupports = require('./native-supports.js');
5
+ var format = require('./format.js');
6
+ var nativeSupports = require('./native-supports.js');
7
7
 
8
8
 
9
9
 
10
- exports.DATE_FORMAT = utils_format.DATE_FORMAT;
11
- exports.DATE_MASK = utils_format.DATE_MASK;
12
- exports.NATIVE_DATE_FORMAT = utils_format.NATIVE_DATE_FORMAT;
13
- exports.format = utils_format.format;
14
- exports.formatDate = utils_format.formatDate;
15
- exports.isCompleteDateInput = utils_format.isCompleteDateInput;
16
- exports.isValid = utils_format.isValid;
17
- exports.parseDateString = utils_format.parseDateString;
18
- exports.isInputDateSupported = utils_nativeSupports.isInputDateSupported;
10
+ exports.DATE_FORMAT = format.DATE_FORMAT;
11
+ exports.DATE_MASK = format.DATE_MASK;
12
+ exports.NATIVE_DATE_FORMAT = format.NATIVE_DATE_FORMAT;
13
+ exports.format = format.format;
14
+ exports.formatDate = format.formatDate;
15
+ exports.isCompleteDateInput = format.isCompleteDateInput;
16
+ exports.isValid = format.isValid;
17
+ exports.parseDateString = format.parseDateString;
18
+ exports.isInputDateSupported = nativeSupports.isInputDateSupported;
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,4 @@
1
1
  /**
2
2
  * Возвращает `true`, если поддерживается `input[type="date"]`
3
3
  */
4
- declare function isInputDateSupported(): boolean;
5
- export { isInputDateSupported };
4
+ export declare function isInputDateSupported(): boolean;
@@ -14,3 +14,4 @@ function isInputDateSupported() {
14
14
  }
15
15
 
16
16
  exports.isInputDateSupported = isInputDateSupported;
17
+ //# sourceMappingURL=native-supports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-supports.js","sources":["../src/utils/native-supports.ts"],"sourcesContent":["/**\n * Возвращает `true`, если поддерживается `input[type=\"date\"]`\n */\nexport function isInputDateSupported() {\n const input = document.createElement('input');\n const value = 'a';\n\n input.setAttribute('type', 'date');\n input.setAttribute('value', value);\n\n return input.value !== value;\n}\n"],"names":[],"mappings":";;;;AAAA;;AAEG;SACa,oBAAoB,GAAA;IAChC,IAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC;IAC7C,IAAM,KAAK,GAAG,GAAG;AAEjB,IAAA,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC;AAClC,IAAA,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC;AAElC,IAAA,OAAO,KAAK,CAAC,KAAK,KAAK,KAAK;AAChC;;;;"}