@basic-ui/core 0.0.51 → 0.0.53

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 (104) hide show
  1. package/build/cjs/index.js +19 -3
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/esm/Carousel/Carousel.d.ts +9 -0
  4. package/build/esm/Carousel/Carousel.js +38 -0
  5. package/build/esm/Carousel/Carousel.js.map +1 -0
  6. package/build/esm/Carousel/Fader.d.ts +14 -0
  7. package/build/esm/Carousel/Fader.js +76 -0
  8. package/build/esm/Carousel/Fader.js.map +1 -0
  9. package/build/esm/Carousel/FaderItem.d.ts +5 -0
  10. package/build/esm/Carousel/FaderItem.js +16 -0
  11. package/build/esm/Carousel/FaderItem.js.map +1 -0
  12. package/build/esm/Carousel/Preloader.d.ts +7 -0
  13. package/build/esm/Carousel/Preloader.js +70 -0
  14. package/build/esm/Carousel/Preloader.js.map +1 -0
  15. package/build/esm/Carousel/Slider.d.ts +14 -0
  16. package/build/esm/Carousel/Slider.js +212 -0
  17. package/build/esm/Carousel/Slider.js.map +1 -0
  18. package/build/esm/Carousel/SliderItem.d.ts +12 -0
  19. package/build/esm/Carousel/SliderItem.js +41 -0
  20. package/build/esm/Carousel/SliderItem.js.map +1 -0
  21. package/build/esm/Carousel/context.d.ts +10 -0
  22. package/build/esm/Carousel/context.js +8 -0
  23. package/build/esm/Carousel/context.js.map +1 -0
  24. package/build/esm/Carousel/getSliderParams.d.ts +9 -0
  25. package/build/esm/Carousel/getSliderParams.js +85 -0
  26. package/build/esm/Carousel/getSliderParams.js.map +1 -0
  27. package/build/esm/Carousel/index.d.ts +7 -0
  28. package/build/esm/Carousel/index.js +8 -0
  29. package/build/esm/Carousel/index.js.map +1 -0
  30. package/build/esm/Carousel/useCarouselGestures.d.ts +30 -0
  31. package/build/esm/Carousel/useCarouselGestures.js +33 -0
  32. package/build/esm/Carousel/useCarouselGestures.js.map +1 -0
  33. package/build/esm/DatePicker/DatePicker.d.ts +24 -0
  34. package/build/esm/DatePicker/DatePicker.js +101 -0
  35. package/build/esm/DatePicker/DatePicker.js.map +1 -0
  36. package/build/esm/DatePicker/DatePickerSelect.d.ts +8 -0
  37. package/build/esm/DatePicker/DatePickerSelect.js +201 -0
  38. package/build/esm/DatePicker/DatePickerSelect.js.map +1 -0
  39. package/build/esm/DatePicker/RangeDatePicker.d.ts +28 -0
  40. package/build/esm/DatePicker/RangeDatePicker.js +94 -0
  41. package/build/esm/DatePicker/RangeDatePicker.js.map +1 -0
  42. package/build/esm/DatePicker/adjustDates.d.ts +4 -0
  43. package/build/esm/DatePicker/adjustDates.js +18 -0
  44. package/build/esm/DatePicker/adjustDates.js.map +1 -0
  45. package/build/esm/DatePicker/contexts.d.ts +31 -0
  46. package/build/esm/DatePicker/contexts.js +15 -0
  47. package/build/esm/DatePicker/contexts.js.map +1 -0
  48. package/build/esm/DatePicker/dateTypes.d.ts +2 -0
  49. package/build/esm/DatePicker/dateTypes.js +2 -0
  50. package/build/esm/DatePicker/dateTypes.js.map +1 -0
  51. package/build/esm/DatePicker/hooks.d.ts +36 -0
  52. package/build/esm/DatePicker/hooks.js +98 -0
  53. package/build/esm/DatePicker/hooks.js.map +1 -0
  54. package/build/esm/DatePicker/index.d.ts +5 -0
  55. package/build/esm/DatePicker/index.js +6 -0
  56. package/build/esm/DatePicker/index.js.map +1 -0
  57. package/build/esm/Portal/Portal.d.ts +3 -2
  58. package/build/esm/Portal/Portal.js +6 -3
  59. package/build/esm/Portal/Portal.js.map +1 -1
  60. package/build/esm/Portal/PortalSelectorProvider.d.ts +8 -0
  61. package/build/esm/Portal/PortalSelectorProvider.js +13 -0
  62. package/build/esm/Portal/PortalSelectorProvider.js.map +1 -0
  63. package/build/esm/Portal/index.d.ts +1 -0
  64. package/build/esm/Portal/index.js +1 -0
  65. package/build/esm/Portal/index.js.map +1 -1
  66. package/build/esm/hooks/useControlledState.js +1 -1
  67. package/build/esm/hooks/useControlledState.js.map +1 -1
  68. package/build/esm/hooks/useId.d.ts +1 -0
  69. package/build/esm/hooks/useId.js +25 -0
  70. package/build/esm/hooks/useId.js.map +1 -0
  71. package/build/esm/utils/assignRef.d.ts +3 -0
  72. package/build/esm/utils/assignRef.js +25 -0
  73. package/build/esm/utils/assignRef.js.map +1 -0
  74. package/build/esm/utils/getCircularIndex.d.ts +1 -0
  75. package/build/esm/utils/getCircularIndex.js +8 -0
  76. package/build/esm/utils/getCircularIndex.js.map +1 -0
  77. package/build/esm/utils/rubberBandClamp.d.ts +2 -0
  78. package/build/esm/utils/rubberBandClamp.js +20 -0
  79. package/build/esm/utils/rubberBandClamp.js.map +1 -0
  80. package/build/esm/utils/wrapEvent.d.ts +3 -0
  81. package/build/esm/utils/wrapEvent.js +16 -0
  82. package/build/esm/utils/wrapEvent.js.map +1 -0
  83. package/build/tsconfig-build.tsbuildinfo +1 -1
  84. package/build/tsconfig.tsbuildinfo +7270 -0
  85. package/package.json +2 -2
  86. package/src/Portal/Portal.tsx +15 -4
  87. package/src/Portal/PortalSelectorProvider.tsx +24 -0
  88. package/src/Portal/index.ts +5 -0
  89. package/src/hooks/useControlledState.ts +3 -3
  90. package/build/esm/TimerField/clamp.d.ts +0 -1
  91. package/build/esm/TimerField/clamp.js +0 -2
  92. package/build/esm/TimerField/clamp.js.map +0 -1
  93. package/build/esm/TimerField/index.d.ts +0 -1
  94. package/build/esm/TimerField/index.js +0 -2
  95. package/build/esm/TimerField/index.js.map +0 -1
  96. package/build/esm/TimerField/useControlledState.d.ts +0 -1
  97. package/build/esm/TimerField/useControlledState.js +0 -2
  98. package/build/esm/TimerField/useControlledState.js.map +0 -1
  99. package/build/esm/TimerField/useTimerField.d.ts +0 -44
  100. package/build/esm/TimerField/useTimerField.js +0 -430
  101. package/build/esm/TimerField/useTimerField.js.map +0 -1
  102. package/build/esm/TimerField/wrapEvent.d.ts +0 -1
  103. package/build/esm/TimerField/wrapEvent.js +0 -2
  104. package/build/esm/TimerField/wrapEvent.js.map +0 -1
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { MonthNames, DayNames } from './dateTypes';
3
+ export declare type RangeDatePickerProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> & {
4
+ as?: React.ElementType<any>;
5
+ minDate?: Date;
6
+ maxDate?: Date;
7
+ dayNames: DayNames;
8
+ monthNames: MonthNames;
9
+ children?: React.ReactNode[];
10
+ onChange?: (from: Date | null, to: Date | null) => void;
11
+ from?: Date | null;
12
+ to?: Date | null;
13
+ defaultFrom?: Date | null;
14
+ defaultTo?: Date | null;
15
+ };
16
+ export declare const RangeDatePicker: React.ForwardRefExoticComponent<Pick<React.HTMLAttributes<HTMLDivElement>, "dir" | "slot" | "style" | "title" | "children" | "onFocus" | "onBlur" | "id" | "hidden" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "draggable" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocusCapture" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture"> & {
17
+ as?: "symbol" | "object" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "blockquote" | "body" | "br" | "button" | "canvas" | "caption" | "cite" | "code" | "col" | "colgroup" | "data" | "datalist" | "dd" | "del" | "details" | "dfn" | "dialog" | "div" | "dl" | "dt" | "em" | "embed" | "fieldset" | "figcaption" | "figure" | "footer" | "form" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "head" | "header" | "hgroup" | "hr" | "html" | "i" | "iframe" | "img" | "input" | "ins" | "kbd" | "label" | "legend" | "li" | "link" | "main" | "map" | "mark" | "menu" | "meta" | "meter" | "nav" | "noscript" | "ol" | "optgroup" | "option" | "output" | "p" | "param" | "picture" | "pre" | "progress" | "q" | "rp" | "rt" | "ruby" | "s" | "samp" | "script" | "section" | "select" | "slot" | "small" | "source" | "span" | "strong" | "style" | "sub" | "summary" | "sup" | "table" | "tbody" | "td" | "template" | "textarea" | "tfoot" | "th" | "thead" | "time" | "title" | "tr" | "track" | "u" | "ul" | "var" | "video" | "wbr" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "filter" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "stop" | "svg" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | "big" | "keygen" | "menuitem" | "noindex" | "webview" | "animate" | "animateMotion" | "animateTransform" | "feDropShadow" | "mpath" | React.ComponentClass<any, any> | React.FunctionComponent<any> | undefined;
18
+ minDate?: Date | undefined;
19
+ maxDate?: Date | undefined;
20
+ dayNames: DayNames;
21
+ monthNames: MonthNames;
22
+ children?: React.ReactNode[] | undefined;
23
+ onChange?: ((from: Date | null, to: Date | null) => void) | undefined;
24
+ from?: Date | null | undefined;
25
+ to?: Date | null | undefined;
26
+ defaultFrom?: Date | null | undefined;
27
+ defaultTo?: Date | null | undefined;
28
+ } & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,94 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
+ import React, { forwardRef, useRef, useState } from 'react';
5
+ import { assignMultipleRefs } from '../utils/assignRef';
6
+ import { adjustDates } from './adjustDates';
7
+ import { RangeDatePickerProvider } from './contexts';
8
+ export var RangeDatePicker = forwardRef(function RangeDatePicker(_ref, ref) {
9
+ var _ref$as = _ref.as,
10
+ Comp = _ref$as === void 0 ? 'div' : _ref$as,
11
+ _ref$minDate = _ref.minDate,
12
+ propMinDate = _ref$minDate === void 0 ? new Date(0) : _ref$minDate,
13
+ _ref$maxDate = _ref.maxDate,
14
+ propMaxDate = _ref$maxDate === void 0 ? new Date() : _ref$maxDate,
15
+ dayNames = _ref.dayNames,
16
+ monthNames = _ref.monthNames,
17
+ onChange = _ref.onChange,
18
+ controlledFrom = _ref.from,
19
+ controlledTo = _ref.to,
20
+ defaultFrom = _ref.defaultFrom,
21
+ defaultTo = _ref.defaultTo,
22
+ rest = _objectWithoutProperties(_ref, ["as", "minDate", "maxDate", "dayNames", "monthNames", "onChange", "from", "to", "defaultFrom", "defaultTo"]);
23
+
24
+ var isControlled = controlledFrom !== undefined && controlledTo !== undefined;
25
+ var minDate = propMinDate,
26
+ maxDate = propMaxDate;
27
+ var rangeDatePickerRef = useRef(null);
28
+
29
+ var _useState = useState({
30
+ from: defaultFrom || null,
31
+ to: defaultTo || null
32
+ }),
33
+ _useState2 = _slicedToArray(_useState, 2),
34
+ _useState2$ = _useState2[0],
35
+ stateFrom = _useState2$.from,
36
+ stateTo = _useState2$.to,
37
+ setDates = _useState2[1];
38
+
39
+ var _useState3 = useState(false),
40
+ _useState4 = _slicedToArray(_useState3, 2),
41
+ innerHasFocus = _useState4[0],
42
+ setInnerHasFocus = _useState4[1];
43
+
44
+ var onChangeFrom = function onChangeFrom(from) {
45
+ var to = stateTo;
46
+
47
+ var _adjustDates = adjustDates(from, to, 'from'),
48
+ nextFrom = _adjustDates.from,
49
+ nextTo = _adjustDates.to;
50
+
51
+ onChange && onChange(nextFrom, nextTo);
52
+ setDates({
53
+ from: nextFrom,
54
+ to: nextTo
55
+ });
56
+ };
57
+
58
+ var onChangeTo = function onChangeTo(to) {
59
+ var from = stateFrom;
60
+
61
+ var _adjustDates2 = adjustDates(from, to, 'to'),
62
+ nextFrom = _adjustDates2.from,
63
+ nextTo = _adjustDates2.to;
64
+
65
+ onChange && onChange(nextFrom, nextTo);
66
+ setDates({
67
+ from: nextFrom,
68
+ to: nextTo
69
+ });
70
+ };
71
+
72
+ var from = isControlled ? controlledFrom : stateFrom;
73
+ var to = isControlled ? controlledTo : stateTo;
74
+ var contextValue = {
75
+ rangeDatePickerRef: rangeDatePickerRef,
76
+ innerHasFocus: innerHasFocus,
77
+ setInnerHasFocus: setInnerHasFocus,
78
+ minDate: minDate,
79
+ maxDate: maxDate,
80
+ from: from,
81
+ to: to,
82
+ dayNames: dayNames,
83
+ monthNames: monthNames,
84
+ onChangeFrom: onChangeFrom,
85
+ onChangeTo: onChangeTo
86
+ };
87
+ return /*#__PURE__*/React.createElement(RangeDatePickerProvider, {
88
+ value: contextValue
89
+ }, /*#__PURE__*/React.createElement(Comp, _extends({
90
+ ref: assignMultipleRefs(ref, rangeDatePickerRef),
91
+ "data-has-focus": innerHasFocus ? '' : undefined
92
+ }, rest)));
93
+ });
94
+ //# sourceMappingURL=RangeDatePicker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/DatePicker/RangeDatePicker.tsx"],"names":["React","forwardRef","useRef","useState","assignMultipleRefs","adjustDates","RangeDatePickerProvider","RangeDatePicker","ref","as","Comp","minDate","propMinDate","Date","maxDate","propMaxDate","dayNames","monthNames","onChange","controlledFrom","from","controlledTo","to","defaultFrom","defaultTo","rest","isControlled","undefined","rangeDatePickerRef","stateFrom","stateTo","setDates","innerHasFocus","setInnerHasFocus","onChangeFrom","nextFrom","nextTo","onChangeTo","contextValue"],"mappings":"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","sourcesContent":["import React, { forwardRef, useRef, useState } from 'react';\nimport { MonthNames, DayNames } from './dateTypes';\nimport { assignMultipleRefs } from '../utils/assignRef';\nimport { adjustDates } from './adjustDates';\nimport {\n RangeDatePickerProvider,\n RangeDatePickerContextProps,\n} from './contexts';\n\nexport type RangeDatePickerProps = Omit<\n React.HTMLAttributes<HTMLDivElement>,\n 'onChange'\n> & {\n as?: React.ElementType<any>;\n minDate?: Date;\n maxDate?: Date;\n dayNames: DayNames;\n monthNames: MonthNames;\n children?: React.ReactNode[];\n onChange?: (from: Date | null, to: Date | null) => void;\n from?: Date | null;\n to?: Date | null;\n defaultFrom?: Date | null;\n defaultTo?: Date | null;\n};\n\nexport const RangeDatePicker = forwardRef<HTMLDivElement, RangeDatePickerProps>(\n function RangeDatePicker(\n {\n as: Comp = 'div',\n minDate: propMinDate = new Date(0),\n maxDate: propMaxDate = new Date(),\n dayNames,\n monthNames,\n onChange,\n from: controlledFrom,\n to: controlledTo,\n defaultFrom,\n defaultTo,\n ...rest\n },\n ref\n ) {\n const isControlled =\n controlledFrom !== undefined && controlledTo !== undefined;\n\n const minDate = propMinDate,\n maxDate = propMaxDate;\n\n const rangeDatePickerRef = useRef<HTMLDivElement | null>(null);\n const [{ from: stateFrom, to: stateTo }, setDates] = useState({\n from: (defaultFrom || null) as Date | null,\n to: (defaultTo || null) as Date | null,\n });\n const [innerHasFocus, setInnerHasFocus] = useState(false);\n\n const onChangeFrom = (from: Date | null) => {\n const to = stateTo;\n const { from: nextFrom, to: nextTo } = adjustDates(from, to, 'from');\n\n onChange && onChange(nextFrom, nextTo);\n setDates({ from: nextFrom, to: nextTo });\n };\n\n const onChangeTo = (to: Date | null) => {\n const from = stateFrom;\n const { from: nextFrom, to: nextTo } = adjustDates(from, to, 'to');\n\n onChange && onChange(nextFrom, nextTo);\n setDates({ from: nextFrom, to: nextTo });\n };\n\n const from = isControlled ? controlledFrom : stateFrom;\n const to = isControlled ? controlledTo : stateTo;\n\n const contextValue: RangeDatePickerContextProps = {\n rangeDatePickerRef,\n innerHasFocus,\n setInnerHasFocus,\n minDate,\n maxDate,\n from,\n to,\n dayNames,\n monthNames,\n onChangeFrom,\n onChangeTo,\n };\n\n return (\n <RangeDatePickerProvider value={contextValue}>\n <Comp\n ref={assignMultipleRefs(ref, rangeDatePickerRef)}\n data-has-focus={innerHasFocus ? '' : undefined}\n {...rest}\n />\n </RangeDatePickerProvider>\n );\n }\n);\n"],"file":"RangeDatePicker.js"}
@@ -0,0 +1,4 @@
1
+ export declare function adjustDates(from: Date | null, to: Date | null, frozenParam: 'from' | 'to'): {
2
+ from: Date | null;
3
+ to: Date | null;
4
+ };
@@ -0,0 +1,18 @@
1
+ import { addDays, isValid, differenceInDays } from 'date-fns';
2
+ export function adjustDates(from, to, frozenParam) {
3
+ if (to && isValid(to) && from && isValid(from)) {
4
+ if (differenceInDays(to, from) < 1) {
5
+ if (frozenParam === 'from') {
6
+ to = addDays(from, 1); // add one day
7
+ } else {
8
+ from = addDays(from, -1); // remove one day
9
+ }
10
+ }
11
+ }
12
+
13
+ return {
14
+ from: from,
15
+ to: to
16
+ };
17
+ }
18
+ //# sourceMappingURL=adjustDates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/DatePicker/adjustDates.ts"],"names":["addDays","isValid","differenceInDays","adjustDates","from","to","frozenParam"],"mappings":"AAAA,SAASA,OAAT,EAAkBC,OAAlB,EAA2BC,gBAA3B,QAAmD,UAAnD;AAEA,OAAO,SAASC,WAAT,CACLC,IADK,EAELC,EAFK,EAGLC,WAHK,EAIL;AACA,MAAID,EAAE,IAAIJ,OAAO,CAACI,EAAD,CAAb,IAAqBD,IAArB,IAA6BH,OAAO,CAACG,IAAD,CAAxC,EAAgD;AAC9C,QAAIF,gBAAgB,CAACG,EAAD,EAAKD,IAAL,CAAhB,GAA6B,CAAjC,EAAoC;AAClC,UAAIE,WAAW,KAAK,MAApB,EAA4B;AAC1BD,QAAAA,EAAE,GAAGL,OAAO,CAACI,IAAD,EAAO,CAAP,CAAZ,CAD0B,CACH;AACxB,OAFD,MAEO;AACLA,QAAAA,IAAI,GAAGJ,OAAO,CAACI,IAAD,EAAO,CAAC,CAAR,CAAd,CADK,CACqB;AAC3B;AACF;AACF;;AAED,SAAO;AAAEA,IAAAA,IAAI,EAAJA,IAAF;AAAQC,IAAAA,EAAE,EAAFA;AAAR,GAAP;AACD","sourcesContent":["import { addDays, isValid, differenceInDays } from 'date-fns';\n\nexport function adjustDates(\n from: Date | null,\n to: Date | null,\n frozenParam: 'from' | 'to'\n) {\n if (to && isValid(to) && from && isValid(from)) {\n if (differenceInDays(to, from) < 1) {\n if (frozenParam === 'from') {\n to = addDays(from, 1); // add one day\n } else {\n from = addDays(from, -1); // remove one day\n }\n }\n }\n\n return { from, to };\n}\n"],"file":"adjustDates.js"}
@@ -0,0 +1,31 @@
1
+ /// <reference types="react" />
2
+ import { MonthNames, DayNames } from './dateTypes';
3
+ import { ReducerState, ReducerActions } from './hooks';
4
+ export interface RangeDatePickerContextProps {
5
+ rangeDatePickerRef: React.MutableRefObject<HTMLDivElement | null>;
6
+ innerHasFocus: boolean;
7
+ setInnerHasFocus: (hasFocus: boolean) => void;
8
+ minDate: Date;
9
+ maxDate: Date;
10
+ from?: Date | null;
11
+ to?: Date | null;
12
+ onChangeFrom: (d: Date | null) => void;
13
+ onChangeTo: (d: Date | null) => void;
14
+ dayNames: DayNames;
15
+ monthNames: MonthNames;
16
+ }
17
+ export declare const RangeDatePickerProvider: import("react").Provider<RangeDatePickerContextProps | null>;
18
+ export declare const useRangeDatePickerContext: () => RangeDatePickerContextProps | null;
19
+ export interface DatePickerContextProps {
20
+ minDate: Date;
21
+ maxDate: Date;
22
+ dayNames: DayNames;
23
+ monthNames: MonthNames;
24
+ datePickerRef: React.MutableRefObject<HTMLDivElement | null>;
25
+ state: ReducerState;
26
+ dispatch: (value: ReducerActions) => void;
27
+ controlledValueRef: React.MutableRefObject<Date | null | undefined>;
28
+ onChangeRef: React.MutableRefObject<((from: Date | null) => void) | undefined>;
29
+ }
30
+ export declare const useDatePickerContext: () => DatePickerContextProps;
31
+ export declare const DatePickerProvider: import("react").Provider<DatePickerContextProps>;
@@ -0,0 +1,15 @@
1
+ import { createContext, useContext } from 'react';
2
+ var rangeContext = createContext(null);
3
+ var RangeDatePickerProvider = rangeContext.Provider;
4
+ export { RangeDatePickerProvider };
5
+ export var useRangeDatePickerContext = function useRangeDatePickerContext() {
6
+ return useContext(rangeContext);
7
+ }; // DatePicker
8
+
9
+ var datePickerContext = createContext(null);
10
+ export var useDatePickerContext = function useDatePickerContext() {
11
+ return useContext(datePickerContext);
12
+ };
13
+ var DatePickerProvider = datePickerContext.Provider;
14
+ export { DatePickerProvider };
15
+ //# sourceMappingURL=contexts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/DatePicker/contexts.ts"],"names":["createContext","useContext","rangeContext","RangeDatePickerProvider","Provider","useRangeDatePickerContext","datePickerContext","useDatePickerContext","DatePickerProvider"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,UAAxB,QAA0C,OAA1C;AAmBA,IAAMC,YAAY,GAAGF,aAAa,CAAqC,IAArC,CAAlC;IACyBG,uB,GAA4BD,Y,CAAtCE,Q;;AACf,OAAO,IAAMC,yBAAyB,GAAG,SAA5BA,yBAA4B;AAAA,SAAMJ,UAAU,CAACC,YAAD,CAAhB;AAAA,CAAlC,C,CAEP;;AAcA,IAAMI,iBAAiB,GAAGN,aAAa,CAAyB,IAAzB,CAAvC;AACA,OAAO,IAAMO,oBAAoB,GAAG,SAAvBA,oBAAuB;AAAA,SAAMN,UAAU,CAACK,iBAAD,CAAhB;AAAA,CAA7B;IACkBE,kB,GAAuBF,iB,CAAjCF,Q","sourcesContent":["import { createContext, useContext } from 'react';\nimport { MonthNames, DayNames } from './dateTypes';\nimport { ReducerState, ReducerActions } from './hooks';\n\n// RangeDatePicker\nexport interface RangeDatePickerContextProps {\n rangeDatePickerRef: React.MutableRefObject<HTMLDivElement | null>;\n innerHasFocus: boolean;\n setInnerHasFocus: (hasFocus: boolean) => void;\n minDate: Date;\n maxDate: Date;\n from?: Date | null;\n to?: Date | null;\n onChangeFrom: (d: Date | null) => void;\n onChangeTo: (d: Date | null) => void;\n dayNames: DayNames;\n monthNames: MonthNames;\n}\n\nconst rangeContext = createContext<RangeDatePickerContextProps | null>(null);\nexport const { Provider: RangeDatePickerProvider } = rangeContext;\nexport const useRangeDatePickerContext = () => useContext(rangeContext);\n\n// DatePicker\nexport interface DatePickerContextProps {\n minDate: Date;\n maxDate: Date;\n dayNames: DayNames;\n monthNames: MonthNames;\n datePickerRef: React.MutableRefObject<HTMLDivElement | null>;\n state: ReducerState;\n dispatch: (value: ReducerActions) => void;\n controlledValueRef: React.MutableRefObject<Date | null | undefined>;\n onChangeRef: React.MutableRefObject<\n ((from: Date | null) => void) | undefined\n >;\n}\nconst datePickerContext = createContext<DatePickerContextProps>(null as any);\nexport const useDatePickerContext = () => useContext(datePickerContext);\nexport const { Provider: DatePickerProvider } = datePickerContext;\n"],"file":"contexts.js"}
@@ -0,0 +1,2 @@
1
+ export declare type DayNames = [string, string, string, string, string, string, string];
2
+ export declare type MonthNames = [string, string, string, string, string, string, string, string, string, string, string, string];
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=dateTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"dateTypes.js"}
@@ -0,0 +1,36 @@
1
+ export declare const FOCUS = "FOCUS";
2
+ export declare const BLUR = "BLUR";
3
+ export declare const NAVIGATE = "NAVIGATE";
4
+ export declare const SET_DATE = "SET_DATE";
5
+ export declare type ActionTypes = typeof FOCUS | typeof BLUR | typeof NAVIGATE | typeof SET_DATE;
6
+ export interface ReducerState {
7
+ isFocused: boolean;
8
+ navigationYear: number;
9
+ navigationMonth: number;
10
+ navigationDay: number;
11
+ selectedDate: Date | null;
12
+ }
13
+ interface FocusAction {
14
+ type: typeof FOCUS;
15
+ }
16
+ interface NavigateAction {
17
+ type: typeof NAVIGATE;
18
+ year: number;
19
+ month: number;
20
+ day: number;
21
+ }
22
+ interface SetDateAction {
23
+ type: typeof SET_DATE;
24
+ selectedDate: Date | null;
25
+ }
26
+ interface BlurAction {
27
+ type: typeof BLUR;
28
+ selectedDate: Date | null;
29
+ }
30
+ export declare type ReducerActions = FocusAction | BlurAction | NavigateAction | SetDateAction;
31
+ export declare function reducer(currentState: Readonly<ReducerState>, action: ReducerActions): ReducerState;
32
+ export declare function useInnerFocus(): {
33
+ handleFocus: () => void;
34
+ handleBlur: () => void;
35
+ };
36
+ export {};
@@ -0,0 +1,98 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { useRangeDatePickerContext, useDatePickerContext } from './contexts'; ////////////////////////////////////////////////////////////////////////////////
3
+ // Actions
4
+
5
+ export var FOCUS = 'FOCUS';
6
+ export var BLUR = 'BLUR';
7
+ export var NAVIGATE = 'NAVIGATE';
8
+ export var SET_DATE = 'SET_DATE';
9
+ export function reducer(currentState, action) {
10
+ switch (action.type) {
11
+ case FOCUS:
12
+ return _extends(_extends({}, currentState), {}, {
13
+ isFocused: true
14
+ });
15
+
16
+ case BLUR:
17
+ return _extends(_extends({}, currentState), {}, {
18
+ navigationYear: -1,
19
+ navigationMonth: -1,
20
+ navigationDay: -1,
21
+ selectedDate: action.selectedDate,
22
+ isFocused: false
23
+ });
24
+
25
+ case NAVIGATE:
26
+ return _extends(_extends({}, currentState), {}, {
27
+ navigationYear: action.year,
28
+ navigationMonth: action.month,
29
+ navigationDay: action.day
30
+ });
31
+
32
+ case SET_DATE:
33
+ {
34
+ return _extends(_extends({}, currentState), {}, {
35
+ navigationYear: -1,
36
+ navigationMonth: -1,
37
+ navigationDay: -1,
38
+ selectedDate: action.selectedDate
39
+ });
40
+ }
41
+ }
42
+ } ////////////////////////////////////////////////////////////////////////////////
43
+ // Hooks
44
+
45
+ export function useInnerFocus() {
46
+ var _useDatePickerContext = useDatePickerContext(),
47
+ dispatch = _useDatePickerContext.dispatch,
48
+ onChangeRef = _useDatePickerContext.onChangeRef,
49
+ datePickerRef = _useDatePickerContext.datePickerRef,
50
+ _useDatePickerContext2 = _useDatePickerContext.state,
51
+ selectedDate = _useDatePickerContext2.selectedDate,
52
+ navigationMonth = _useDatePickerContext2.navigationMonth,
53
+ navigationYear = _useDatePickerContext2.navigationYear,
54
+ navigationDay = _useDatePickerContext2.navigationDay;
55
+
56
+ var rangeCtx = useRangeDatePickerContext();
57
+
58
+ var handleFocus = function handleFocus() {
59
+ dispatch({
60
+ type: FOCUS
61
+ });
62
+
63
+ if (rangeCtx) {
64
+ rangeCtx.setInnerHasFocus(true);
65
+ }
66
+ };
67
+
68
+ var handleBlur = function handleBlur() {
69
+ requestAnimationFrame(function () {
70
+ // we on want to close only if focus rests outside the datepicker
71
+ if (datePickerRef.current && !datePickerRef.current.contains(document.activeElement)) {
72
+ if (selectedDate && navigationYear >= 0 && navigationMonth >= 0 && navigationDay === -1) {
73
+ // user started picking a new day, but haven't finished :(
74
+ onChangeRef.current && onChangeRef.current(null);
75
+ dispatch({
76
+ type: BLUR,
77
+ selectedDate: null
78
+ });
79
+ } else {
80
+ dispatch({
81
+ type: BLUR,
82
+ selectedDate: selectedDate
83
+ });
84
+ }
85
+ }
86
+
87
+ if (rangeCtx && rangeCtx.rangeDatePickerRef.current && !rangeCtx.rangeDatePickerRef.current.contains(document.activeElement)) {
88
+ rangeCtx.setInnerHasFocus(false);
89
+ }
90
+ });
91
+ };
92
+
93
+ return {
94
+ handleFocus: handleFocus,
95
+ handleBlur: handleBlur
96
+ };
97
+ }
98
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/DatePicker/hooks.tsx"],"names":["useRangeDatePickerContext","useDatePickerContext","FOCUS","BLUR","NAVIGATE","SET_DATE","reducer","currentState","action","type","isFocused","navigationYear","navigationMonth","navigationDay","selectedDate","year","month","day","useInnerFocus","dispatch","onChangeRef","datePickerRef","state","rangeCtx","handleFocus","setInnerHasFocus","handleBlur","requestAnimationFrame","current","contains","document","activeElement","rangeDatePickerRef"],"mappings":"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","sourcesContent":["import { useRangeDatePickerContext, useDatePickerContext } from './contexts';\n\n////////////////////////////////////////////////////////////////////////////////\n// Actions\n\nexport const FOCUS = 'FOCUS';\n\nexport const BLUR = 'BLUR';\n\nexport const NAVIGATE = 'NAVIGATE';\n\nexport const SET_DATE = 'SET_DATE';\n\nexport type ActionTypes =\n | typeof FOCUS\n | typeof BLUR\n | typeof NAVIGATE\n | typeof SET_DATE;\n\n////////////////////////////////////////////////////////////////////////////////\n// Reducer\n\nexport interface ReducerState {\n isFocused: boolean;\n navigationYear: number;\n navigationMonth: number;\n navigationDay: number;\n selectedDate: Date | null;\n}\n\ninterface FocusAction {\n type: typeof FOCUS;\n}\n\ninterface NavigateAction {\n type: typeof NAVIGATE;\n year: number;\n month: number;\n day: number;\n}\ninterface SetDateAction {\n type: typeof SET_DATE;\n selectedDate: Date | null;\n}\n\ninterface BlurAction {\n type: typeof BLUR;\n selectedDate: Date | null;\n}\n\nexport type ReducerActions =\n | FocusAction\n | BlurAction\n | NavigateAction\n | SetDateAction;\n\nexport function reducer(\n currentState: Readonly<ReducerState>,\n action: ReducerActions\n): ReducerState {\n switch (action.type) {\n case FOCUS:\n return {\n ...currentState,\n isFocused: true,\n };\n case BLUR:\n return {\n ...currentState,\n navigationYear: -1,\n navigationMonth: -1,\n navigationDay: -1,\n selectedDate: action.selectedDate,\n isFocused: false,\n };\n case NAVIGATE:\n return {\n ...currentState,\n navigationYear: action.year,\n navigationMonth: action.month,\n navigationDay: action.day,\n };\n case SET_DATE: {\n return {\n ...currentState,\n navigationYear: -1,\n navigationMonth: -1,\n navigationDay: -1,\n selectedDate: action.selectedDate,\n };\n }\n }\n}\n\n////////////////////////////////////////////////////////////////////////////////\n// Hooks\n\nexport function useInnerFocus() {\n const {\n dispatch,\n onChangeRef,\n datePickerRef,\n state: { selectedDate, navigationMonth, navigationYear, navigationDay },\n } = useDatePickerContext();\n const rangeCtx = useRangeDatePickerContext();\n\n const handleFocus = () => {\n dispatch({ type: FOCUS });\n if (rangeCtx) {\n rangeCtx.setInnerHasFocus(true);\n }\n };\n\n const handleBlur = () => {\n requestAnimationFrame(() => {\n // we on want to close only if focus rests outside the datepicker\n if (\n datePickerRef.current &&\n !datePickerRef.current.contains(document.activeElement)\n ) {\n if (\n selectedDate &&\n navigationYear >= 0 &&\n navigationMonth >= 0 &&\n navigationDay === -1\n ) {\n // user started picking a new day, but haven't finished :(\n onChangeRef.current && onChangeRef.current(null);\n dispatch({ type: BLUR, selectedDate: null });\n } else {\n dispatch({ type: BLUR, selectedDate });\n }\n }\n\n if (\n rangeCtx &&\n rangeCtx.rangeDatePickerRef.current &&\n !rangeCtx.rangeDatePickerRef.current.contains(document.activeElement)\n ) {\n rangeCtx.setInnerHasFocus(false);\n }\n });\n };\n\n return { handleFocus, handleBlur };\n}\n"],"file":"hooks.js"}
@@ -0,0 +1,5 @@
1
+ export * from './DatePicker';
2
+ export * from './RangeDatePicker';
3
+ export * from './DatePickerSelect';
4
+ export * from './dateTypes';
5
+ export * from './contexts';
@@ -0,0 +1,6 @@
1
+ export * from './DatePicker';
2
+ export * from './RangeDatePicker';
3
+ export * from './DatePickerSelect';
4
+ export * from './dateTypes';
5
+ export * from './contexts';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/DatePicker/index.tsx"],"names":[],"mappings":"AAAA,cAAc,cAAd;AACA,cAAc,mBAAd;AACA,cAAc,oBAAd;AACA,cAAc,aAAd;AACA,cAAc,YAAd","sourcesContent":["export * from './DatePicker';\nexport * from './RangeDatePicker';\nexport * from './DatePickerSelect';\nexport * from './dateTypes';\nexport * from './contexts';\n"],"file":"index.js"}
@@ -1,6 +1,7 @@
1
- import type { FC, ReactNode } from 'react';
1
+ import { type FC, type ReactNode } from 'react';
2
+ import type { PortalSelectorFn } from './PortalSelectorProvider';
2
3
  export interface PortalProps {
3
4
  children?: ReactNode;
4
- selector?: string;
5
+ selector?: PortalSelectorFn;
5
6
  }
6
7
  export declare const Portal: FC<PortalProps>;
@@ -1,15 +1,18 @@
1
+ import { useContext } from 'react';
1
2
  import { createPortal } from 'react-dom';
3
+ import { PortalSelectorContext } from './PortalSelectorProvider';
2
4
  import { jsx as _jsx } from "react/jsx-runtime";
3
5
  export var Portal = function Portal(_ref) {
4
6
  var children = _ref.children,
5
- _ref$selector = _ref.selector,
6
- selector = _ref$selector === void 0 ? 'body' : _ref$selector;
7
+ selectorProp = _ref.selector;
8
+ var selectorCtx = useContext(PortalSelectorContext);
7
9
 
8
10
  if (typeof window === 'undefined') {
9
11
  return null;
10
12
  }
11
13
 
12
- var dom = document.querySelector(selector);
14
+ var selector = selectorProp || selectorCtx || 'body';
15
+ var dom = typeof selector === 'string' ? document.querySelector(selector) : selector();
13
16
 
14
17
  if (dom) {
15
18
  return /*#__PURE__*/createPortal( /*#__PURE__*/_jsx("div", {
@@ -1 +1 @@
1
- {"version":3,"file":"Portal.js","names":["createPortal","Portal","children","selector","window","dom","document","querySelector"],"sources":["../../../src/Portal/Portal.tsx"],"sourcesContent":["import type { FC, ReactNode } from 'react';\nimport { createPortal } from 'react-dom';\n\nexport interface PortalProps {\n children?: ReactNode;\n selector?: string;\n}\n\nexport const Portal: FC<PortalProps> = ({ children, selector = 'body' }) => {\n if (typeof window === 'undefined') {\n return null;\n }\n\n const dom = document.querySelector(selector);\n if (dom) {\n return createPortal(<div data-portal=\"\">{children}</div>, dom);\n }\n\n return null;\n};\n"],"mappings":"AACA,SAASA,YAAT,QAA6B,WAA7B;;AAOA,OAAO,IAAMC,MAAuB,GAAG,SAA1BA,MAA0B,OAAqC;EAAA,IAAlCC,QAAkC,QAAlCA,QAAkC;EAAA,yBAAxBC,QAAwB;EAAA,IAAxBA,QAAwB,8BAAb,MAAa;;EAC1E,IAAI,OAAOC,MAAP,KAAkB,WAAtB,EAAmC;IACjC,OAAO,IAAP;EACD;;EAED,IAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAT,CAAuBJ,QAAvB,CAAZ;;EACA,IAAIE,GAAJ,EAAS;IACP,oBAAOL,YAAY,eAAC;MAAK,eAAY,EAAjB;MAAA,UAAqBE;IAArB,EAAD,EAAuCG,GAAvC,CAAnB;EACD;;EAED,OAAO,IAAP;AACD,CAXM"}
1
+ {"version":3,"file":"Portal.js","names":["useContext","createPortal","PortalSelectorContext","Portal","children","selectorProp","selector","selectorCtx","window","dom","document","querySelector"],"sources":["../../../src/Portal/Portal.tsx"],"sourcesContent":["import { useContext, type FC, type ReactNode } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport type { PortalSelectorFn } from './PortalSelectorProvider';\nimport { PortalSelectorContext } from './PortalSelectorProvider';\n\nexport interface PortalProps {\n children?: ReactNode;\n selector?: PortalSelectorFn;\n}\n\nexport const Portal: FC<PortalProps> = ({\n children,\n selector: selectorProp,\n}) => {\n const selectorCtx = useContext(PortalSelectorContext);\n if (typeof window === 'undefined') {\n return null;\n }\n\n const selector = selectorProp || selectorCtx || 'body';\n const dom =\n typeof selector === 'string'\n ? document.querySelector(selector)\n : selector();\n if (dom) {\n return createPortal(<div data-portal=\"\">{children}</div>, dom);\n }\n\n return null;\n};\n"],"mappings":"AAAA,SAASA,UAAT,QAAoD,OAApD;AACA,SAASC,YAAT,QAA6B,WAA7B;AAGA,SAASC,qBAAT,QAAsC,0BAAtC;;AAOA,OAAO,IAAMC,MAAuB,GAAG,SAA1BA,MAA0B,OAGjC;EAAA,IAFJC,QAEI,QAFJA,QAEI;EAAA,IADMC,YACN,QADJC,QACI;EACJ,IAAMC,WAAW,GAAGP,UAAU,CAACE,qBAAD,CAA9B;;EACA,IAAI,OAAOM,MAAP,KAAkB,WAAtB,EAAmC;IACjC,OAAO,IAAP;EACD;;EAED,IAAMF,QAAQ,GAAGD,YAAY,IAAIE,WAAhB,IAA+B,MAAhD;EACA,IAAME,GAAG,GACP,OAAOH,QAAP,KAAoB,QAApB,GACII,QAAQ,CAACC,aAAT,CAAuBL,QAAvB,CADJ,GAEIA,QAAQ,EAHd;;EAIA,IAAIG,GAAJ,EAAS;IACP,oBAAOR,YAAY,eAAC;MAAK,eAAY,EAAjB;MAAA,UAAqBG;IAArB,EAAD,EAAuCK,GAAvC,CAAnB;EACD;;EAED,OAAO,IAAP;AACD,CAnBM"}
@@ -0,0 +1,8 @@
1
+ import type { ReactNode } from 'react';
2
+ export declare type PortalSelectorFn = string | (() => Element | null);
3
+ export declare const PortalSelectorContext: import("react").Context<PortalSelectorFn | null>;
4
+ export declare type PortalSelectorProviderProps = {
5
+ selector: PortalSelectorFn;
6
+ children?: ReactNode | ReactNode[];
7
+ };
8
+ export declare const PortalSelectorProvider: ({ selector, children, }: PortalSelectorProviderProps) => JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { createContext } from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export var PortalSelectorContext = /*#__PURE__*/createContext(null);
4
+ PortalSelectorContext.displayName = 'PortalSelectorContext';
5
+ export var PortalSelectorProvider = function PortalSelectorProvider(_ref) {
6
+ var selector = _ref.selector,
7
+ children = _ref.children;
8
+ return /*#__PURE__*/_jsx(PortalSelectorContext.Provider, {
9
+ value: selector,
10
+ children: children
11
+ });
12
+ };
13
+ //# sourceMappingURL=PortalSelectorProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PortalSelectorProvider.js","names":["createContext","PortalSelectorContext","displayName","PortalSelectorProvider","selector","children"],"sources":["../../../src/Portal/PortalSelectorProvider.tsx"],"sourcesContent":["import { createContext } from 'react';\nimport type { ReactNode } from 'react';\n\nexport type PortalSelectorFn = string | (() => Element | null);\nexport const PortalSelectorContext = createContext<PortalSelectorFn | null>(\n null\n);\nPortalSelectorContext.displayName = 'PortalSelectorContext';\n\nexport type PortalSelectorProviderProps = {\n selector: PortalSelectorFn;\n children?: ReactNode | ReactNode[];\n};\n\nexport const PortalSelectorProvider = ({\n selector,\n children,\n}: PortalSelectorProviderProps) => {\n return (\n <PortalSelectorContext.Provider value={selector}>\n {children}\n </PortalSelectorContext.Provider>\n );\n};\n"],"mappings":"AAAA,SAASA,aAAT,QAA8B,OAA9B;;AAIA,OAAO,IAAMC,qBAAqB,gBAAGD,aAAa,CAChD,IADgD,CAA3C;AAGPC,qBAAqB,CAACC,WAAtB,GAAoC,uBAApC;AAOA,OAAO,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAyB,OAGH;EAAA,IAFjCC,QAEiC,QAFjCA,QAEiC;EAAA,IADjCC,QACiC,QADjCA,QACiC;EACjC,oBACE,KAAC,qBAAD,CAAuB,QAAvB;IAAgC,KAAK,EAAED,QAAvC;IAAA,UACGC;EADH,EADF;AAKD,CATM"}
@@ -1 +1,2 @@
1
1
  export * from './Portal';
2
+ export { PortalSelectorProvider, type PortalSelectorProviderProps, type PortalSelectorFn, } from './PortalSelectorProvider';
@@ -1,2 +1,3 @@
1
1
  export * from './Portal';
2
+ export { PortalSelectorProvider } from './PortalSelectorProvider';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/Portal/index.ts"],"sourcesContent":["export * from './Portal';\n"],"mappings":"AAAA,cAAc,UAAd"}
1
+ {"version":3,"file":"index.js","names":["PortalSelectorProvider"],"sources":["../../../src/Portal/index.ts"],"sourcesContent":["export * from './Portal';\nexport {\n PortalSelectorProvider,\n type PortalSelectorProviderProps,\n type PortalSelectorFn,\n} from './PortalSelectorProvider';\n"],"mappings":"AAAA,cAAc,UAAd;AACA,SACEA,sBADF,QAIO,0BAJP"}
@@ -12,7 +12,7 @@ export function useControlledState(valueProp, onChangeProp, defaultValue, defaul
12
12
  setValueState = _useState2[1];
13
13
 
14
14
  if (isControlled) {
15
- if (wasControlled.current && process.env.NODE_ENV !== 'production' && !hasWarned.current) {
15
+ if (!wasControlled.current && !hasWarned.current && process.env.NODE_ENV !== 'production') {
16
16
  console.warn('Trying to change from controlled to uncontrolled.');
17
17
  hasWarned.current = true;
18
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useControlledState.js","names":["useRef","useState","wrapEvent","useControlledState","valueProp","onChangeProp","defaultValue","defaultOnChange","isControlled","undefined","wasControlled","hasWarned","valueState","setValueState","current","process","env","NODE_ENV","console","warn"],"sources":["../../../src/hooks/useControlledState.ts"],"sourcesContent":["import type { Dispatch, SetStateAction, SyntheticEvent } from 'react';\nimport { useRef, useState } from 'react';\n\nimport type { CustomEventHandler } from '../utils';\nimport { wrapEvent } from '../utils';\n\nexport function useControlledState<\n V,\n E extends SyntheticEvent<any> | Event,\n H extends unknown[]\n>(\n valueProp: V | undefined,\n onChangeProp: CustomEventHandler<E, H> | undefined,\n defaultValue: V | (() => V),\n defaultOnChange: (\n setValue: Dispatch<SetStateAction<V>>\n ) => CustomEventHandler<E, H>\n): [V, CustomEventHandler<E, H>] {\n const isControlled = valueProp !== undefined;\n const wasControlled = useRef(isControlled);\n const hasWarned = useRef(false);\n const [valueState, setValueState] = useState<V>(defaultValue);\n\n if (isControlled) {\n if (\n wasControlled.current &&\n process.env.NODE_ENV !== 'production' &&\n !hasWarned.current\n ) {\n console.warn('Trying to change from controlled to uncontrolled.');\n hasWarned.current = true;\n }\n return [\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n valueProp!,\n wrapEvent(onChangeProp, defaultOnChange(setValueState)),\n ];\n }\n\n return [\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n valueState!,\n wrapEvent(onChangeProp, defaultOnChange(setValueState)),\n ];\n}\n"],"mappings":";AACA,SAASA,MAAT,EAAiBC,QAAjB,QAAiC,OAAjC;AAGA,SAASC,SAAT,QAA0B,UAA1B;AAEA,OAAO,SAASC,kBAAT,CAKLC,SALK,EAMLC,YANK,EAOLC,YAPK,EAQLC,eARK,EAW0B;EAC/B,IAAMC,YAAY,GAAGJ,SAAS,KAAKK,SAAnC;EACA,IAAMC,aAAa,GAAGV,MAAM,CAACQ,YAAD,CAA5B;EACA,IAAMG,SAAS,GAAGX,MAAM,CAAC,KAAD,CAAxB;;EACA,gBAAoCC,QAAQ,CAAIK,YAAJ,CAA5C;EAAA;EAAA,IAAOM,UAAP;EAAA,IAAmBC,aAAnB;;EAEA,IAAIL,YAAJ,EAAkB;IAChB,IACEE,aAAa,CAACI,OAAd,IACAC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YADzB,IAEA,CAACN,SAAS,CAACG,OAHb,EAIE;MACAI,OAAO,CAACC,IAAR,CAAa,mDAAb;MACAR,SAAS,CAACG,OAAV,GAAoB,IAApB;IACD;;IACD,OAAO,CACL;IACAV,SAFK,EAGLF,SAAS,CAACG,YAAD,EAAeE,eAAe,CAACM,aAAD,CAA9B,CAHJ,CAAP;EAKD;;EAED,OAAO,CACL;EACAD,UAFK,EAGLV,SAAS,CAACG,YAAD,EAAeE,eAAe,CAACM,aAAD,CAA9B,CAHJ,CAAP;AAKD"}
1
+ {"version":3,"file":"useControlledState.js","names":["useRef","useState","wrapEvent","useControlledState","valueProp","onChangeProp","defaultValue","defaultOnChange","isControlled","undefined","wasControlled","hasWarned","valueState","setValueState","current","process","env","NODE_ENV","console","warn"],"sources":["../../../src/hooks/useControlledState.ts"],"sourcesContent":["import type { Dispatch, SetStateAction, SyntheticEvent } from 'react';\nimport { useRef, useState } from 'react';\n\nimport type { CustomEventHandler } from '../utils';\nimport { wrapEvent } from '../utils';\n\nexport function useControlledState<\n V,\n E extends SyntheticEvent<any> | Event,\n H extends unknown[]\n>(\n valueProp: V | undefined,\n onChangeProp: CustomEventHandler<E, H> | undefined,\n defaultValue: V | (() => V),\n defaultOnChange: (\n setValue: Dispatch<SetStateAction<V>>\n ) => CustomEventHandler<E, H>\n): [V, CustomEventHandler<E, H>] {\n const isControlled = valueProp !== undefined;\n const wasControlled = useRef(isControlled);\n const hasWarned = useRef(false);\n const [valueState, setValueState] = useState<V>(defaultValue);\n\n if (isControlled) {\n if (\n !wasControlled.current &&\n !hasWarned.current &&\n process.env.NODE_ENV !== 'production'\n ) {\n console.warn('Trying to change from controlled to uncontrolled.');\n hasWarned.current = true;\n }\n return [\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n valueProp!,\n wrapEvent(onChangeProp, defaultOnChange(setValueState)),\n ];\n }\n\n return [\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n valueState!,\n wrapEvent(onChangeProp, defaultOnChange(setValueState)),\n ];\n}\n"],"mappings":";AACA,SAASA,MAAT,EAAiBC,QAAjB,QAAiC,OAAjC;AAGA,SAASC,SAAT,QAA0B,UAA1B;AAEA,OAAO,SAASC,kBAAT,CAKLC,SALK,EAMLC,YANK,EAOLC,YAPK,EAQLC,eARK,EAW0B;EAC/B,IAAMC,YAAY,GAAGJ,SAAS,KAAKK,SAAnC;EACA,IAAMC,aAAa,GAAGV,MAAM,CAACQ,YAAD,CAA5B;EACA,IAAMG,SAAS,GAAGX,MAAM,CAAC,KAAD,CAAxB;;EACA,gBAAoCC,QAAQ,CAAIK,YAAJ,CAA5C;EAAA;EAAA,IAAOM,UAAP;EAAA,IAAmBC,aAAnB;;EAEA,IAAIL,YAAJ,EAAkB;IAChB,IACE,CAACE,aAAa,CAACI,OAAf,IACA,CAACH,SAAS,CAACG,OADX,IAEAC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAH3B,EAIE;MACAC,OAAO,CAACC,IAAR,CAAa,mDAAb;MACAR,SAAS,CAACG,OAAV,GAAoB,IAApB;IACD;;IACD,OAAO,CACL;IACAV,SAFK,EAGLF,SAAS,CAACG,YAAD,EAAeE,eAAe,CAACM,aAAD,CAA9B,CAHJ,CAAP;EAKD;;EAED,OAAO,CACL;EACAD,UAFK,EAGLV,SAAS,CAACG,YAAD,EAAeE,eAAe,CAACM,aAAD,CAA9B,CAHJ,CAAP;AAKD"}
@@ -0,0 +1 @@
1
+ export declare const useId: (preferredId?: string | undefined) => string | undefined;
@@ -0,0 +1,25 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { useEffect, useState } from 'react'; // Could use UUID but if we hit 9,007,199,254,740,991 unique components over
3
+ // the lifetime of the app before it gets reloaded, I mean ... come on.
4
+ // I don't even know what xillion that is.
5
+ // /me googles
6
+ // Oh duh, quadrillion. Nine quadrillion components. I think we're okay.
7
+
8
+ var id = 0;
9
+
10
+ var genId = function genId() {
11
+ return "".concat(++id);
12
+ };
13
+
14
+ export var useId = function useId(preferredId) {
15
+ var _useState = useState(preferredId),
16
+ _useState2 = _slicedToArray(_useState, 2),
17
+ id = _useState2[0],
18
+ setId = _useState2[1];
19
+
20
+ useEffect(function () {
21
+ return setId(genId());
22
+ }, []);
23
+ return id;
24
+ };
25
+ //# sourceMappingURL=useId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/hooks/useId.ts"],"names":["useEffect","useState","id","genId","useId","preferredId","setId"],"mappings":";AAAA,SAASA,SAAT,EAAoBC,QAApB,QAAoC,OAApC,C,CAEA;AACA;AACA;AACA;AACA;;AACA,IAAIC,EAAE,GAAG,CAAT;;AACA,IAAMC,KAAK,GAAG,SAARA,KAAQ;AAAA,mBAAS,EAAED,EAAX;AAAA,CAAd;;AACA,OAAO,IAAME,KAAK,GAAG,SAARA,KAAQ,CAACC,WAAD,EAA0B;AAAA,kBACzBJ,QAAQ,CAAqBI,WAArB,CADiB;AAAA;AAAA,MACtCH,EADsC;AAAA,MAClCI,KADkC;;AAE7CN,EAAAA,SAAS,CAAC;AAAA,WAAMM,KAAK,CAACH,KAAK,EAAN,CAAX;AAAA,GAAD,EAAuB,EAAvB,CAAT;AACA,SAAOD,EAAP;AACD,CAJM","sourcesContent":["import { useEffect, useState } from 'react';\n\n// Could use UUID but if we hit 9,007,199,254,740,991 unique components over\n// the lifetime of the app before it gets reloaded, I mean ... come on.\n// I don't even know what xillion that is.\n// /me googles\n// Oh duh, quadrillion. Nine quadrillion components. I think we're okay.\nlet id = 0;\nconst genId = () => `${++id}`;\nexport const useId = (preferredId?: string) => {\n const [id, setId] = useState<string | undefined>(preferredId);\n useEffect(() => setId(genId()), []);\n return id;\n};\n"],"file":"useId.js"}
@@ -0,0 +1,3 @@
1
+ import { LegacyRef, MutableRefObject, Ref } from 'react';
2
+ export declare function assignRef<T>(ref: LegacyRef<T> | MutableRefObject<T> | Ref<T>, value: T): void;
3
+ export declare function assignMultipleRefs<T>(...refs: (LegacyRef<T> | MutableRefObject<T> | Ref<T>)[]): (node: T | null) => void;
@@ -0,0 +1,25 @@
1
+ export function assignRef(ref, value) {
2
+ if (ref == null) return;
3
+
4
+ if (typeof ref === 'function') {
5
+ ref(value);
6
+ } else {
7
+ try {
8
+ ref.current = value;
9
+ } catch (error) {
10
+ throw new Error("Cannot assign value \"".concat(value, "\" to ref \"").concat(ref, "\""));
11
+ }
12
+ }
13
+ }
14
+ export function assignMultipleRefs() {
15
+ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
16
+ refs[_key] = arguments[_key];
17
+ }
18
+
19
+ return function (node) {
20
+ refs.forEach(function (ref) {
21
+ assignRef(ref, node);
22
+ });
23
+ };
24
+ }
25
+ //# sourceMappingURL=assignRef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/assignRef.ts"],"names":["assignRef","ref","value","current","error","Error","assignMultipleRefs","refs","node","forEach"],"mappings":"AAEA,OAAO,SAASA,SAAT,CACLC,GADK,EAELC,KAFK,EAGL;AACA,MAAID,GAAG,IAAI,IAAX,EAAiB;;AACjB,MAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;AAC7BA,IAAAA,GAAG,CAACC,KAAD,CAAH;AACD,GAFD,MAEO;AACL,QAAI;AACDD,MAAAA,GAAD,CAA6BE,OAA7B,GAAuCD,KAAvC;AACD,KAFD,CAEE,OAAOE,KAAP,EAAc;AACd,YAAM,IAAIC,KAAJ,iCAAkCH,KAAlC,yBAAoDD,GAApD,QAAN;AACD;AACF;AACF;AAED,OAAO,SAASK,kBAAT,GAEL;AAAA,oCADGC,IACH;AADGA,IAAAA,IACH;AAAA;;AACA,SAAO,UAACC,IAAD,EAAoB;AACzBD,IAAAA,IAAI,CAACE,OAAL,CAAa,UAACR,GAAD,EAAS;AACpBD,MAAAA,SAAS,CAACC,GAAD,EAAMO,IAAN,CAAT;AACD,KAFD;AAGD,GAJD;AAKD","sourcesContent":["import { LegacyRef, MutableRefObject, Ref } from 'react';\n\nexport function assignRef<T>(\n ref: LegacyRef<T> | MutableRefObject<T> | Ref<T>,\n value: T\n) {\n if (ref == null) return;\n if (typeof ref === 'function') {\n ref(value);\n } else {\n try {\n (ref as MutableRefObject<T>).current = value;\n } catch (error) {\n throw new Error(`Cannot assign value \"${value}\" to ref \"${ref}\"`);\n }\n }\n}\n\nexport function assignMultipleRefs<T>(\n ...refs: (LegacyRef<T> | MutableRefObject<T> | Ref<T>)[]\n) {\n return (node: T | null) => {\n refs.forEach((ref) => {\n assignRef(ref, node);\n });\n };\n}\n"],"file":"assignRef.js"}
@@ -0,0 +1 @@
1
+ export declare function getCircularIndex(index: number, maxLength: number): number | null;