@vuu-ui/vuu-ui-controls 2.1.19-beta.1 → 2.1.19-beta.2

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 (180) hide show
  1. package/package.json +12 -13
  2. package/src/calendar/Calendar.css.js +10 -0
  3. package/src/calendar/Calendar.js +70 -0
  4. package/src/calendar/index.js +4 -0
  5. package/src/calendar/internal/CalendarCarousel.css.js +19 -0
  6. package/src/calendar/internal/CalendarCarousel.js +73 -0
  7. package/src/calendar/internal/CalendarContext.js +9 -0
  8. package/src/calendar/internal/CalendarDay.css.js +116 -0
  9. package/src/calendar/internal/CalendarDay.js +64 -0
  10. package/src/calendar/internal/CalendarMonth.css.js +13 -0
  11. package/src/calendar/internal/CalendarMonth.js +43 -0
  12. package/src/calendar/internal/CalendarNavigation.css.js +24 -0
  13. package/src/calendar/internal/CalendarNavigation.js +185 -0
  14. package/src/calendar/internal/CalendarWeekHeader.css.js +23 -0
  15. package/src/calendar/internal/CalendarWeekHeader.js +31 -0
  16. package/src/calendar/internal/useFocusManagement.js +66 -0
  17. package/src/calendar/internal/utils.js +57 -0
  18. package/src/calendar/useCalendar.js +116 -0
  19. package/src/calendar/useCalendarDay.js +74 -0
  20. package/src/calendar/useSelection.js +202 -0
  21. package/src/column-picker/ColumnPicker.css.js +8 -0
  22. package/src/column-picker/ColumnPicker.js +108 -0
  23. package/src/column-picker/ColumnSearch.css.js +61 -0
  24. package/src/column-picker/ColumnSearch.js +66 -0
  25. package/src/column-picker/index.js +2 -0
  26. package/src/column-picker/moving-window.js +49 -0
  27. package/src/common-hooks/index.js +3 -0
  28. package/src/common-hooks/selectionTypes.js +8 -0
  29. package/src/common-hooks/use-resize-observer.js +122 -0
  30. package/src/common-hooks/useControlled.js +45 -0
  31. package/src/context-panel-provider/ContextPanelProvider.js +80 -0
  32. package/src/cycle-state-button/CycleStateButton.js +30 -0
  33. package/src/cycle-state-button/index.js +1 -0
  34. package/src/date-input/DateInput.css.js +195 -0
  35. package/src/date-input/DateInput.js +210 -0
  36. package/src/date-input/index.js +1 -0
  37. package/src/date-picker/DatePicker.js +137 -0
  38. package/src/date-picker/DatePickerContext.js +20 -0
  39. package/src/date-picker/DatePickerPanel.css.js +25 -0
  40. package/src/date-picker/DatePickerPanel.js +124 -0
  41. package/src/date-picker/index.js +1 -0
  42. package/src/drag-drop/DragDropProvider.js +123 -0
  43. package/src/drag-drop/DragDropState.js +25 -0
  44. package/src/drag-drop/Draggable.css.js +57 -0
  45. package/src/drag-drop/Draggable.js +77 -0
  46. package/src/drag-drop/DropIndicator.css.js +11 -0
  47. package/src/drag-drop/DropIndicator.js +28 -0
  48. package/src/drag-drop/dragDropTypes.js +3 -0
  49. package/src/drag-drop/drop-target-utils.js +199 -0
  50. package/src/drag-drop/index.js +6 -0
  51. package/src/drag-drop/useAutoScroll.js +53 -0
  52. package/src/drag-drop/useDragDisplacers.js +126 -0
  53. package/src/drag-drop/useDragDrop.js +435 -0
  54. package/src/drag-drop/useDragDropCopy.js +22 -0
  55. package/src/drag-drop/useDragDropIndicator.js +182 -0
  56. package/src/drag-drop/useDragDropNaturalMovement.js +205 -0
  57. package/src/drag-drop/useDropIndicator.js +21 -0
  58. package/src/drag-drop/useGlobalDragDrop.js +67 -0
  59. package/src/drag-drop/useTransition.js +11 -0
  60. package/src/editable/index.js +1 -0
  61. package/src/editable/useEditableText.js +199 -0
  62. package/src/editable-label/EditableLabel.css.js +81 -0
  63. package/src/editable-label/EditableLabel.js +125 -0
  64. package/src/editable-label/index.js +1 -0
  65. package/src/expando-input/ExpandoInput.css.js +67 -0
  66. package/src/expando-input/ExpandoInput.js +40 -0
  67. package/src/expando-input/index.js +1 -0
  68. package/src/highlighter/Highlighter.css.js +8 -0
  69. package/src/highlighter/Highlighter.js +27 -0
  70. package/src/highlighter/index.js +1 -0
  71. package/src/hover-overlay/HoverOverlay.js +92 -0
  72. package/src/icon-button/Icon.css.js +8 -0
  73. package/src/icon-button/Icon.js +26 -0
  74. package/src/icon-button/IconButton.css.js +10 -0
  75. package/src/icon-button/IconButton.js +28 -0
  76. package/src/icon-button/ToggleIconButton.css.js +47 -0
  77. package/src/icon-button/ToggleIconButton.js +26 -0
  78. package/src/icon-button/index.js +3 -0
  79. package/src/index.js +31 -0
  80. package/src/instrument-picker/SearchCell.css.js +17 -0
  81. package/src/instrument-picker/SearchCell.js +29 -0
  82. package/src/instrument-picker/TablePicker.css.js +23 -0
  83. package/src/instrument-picker/TablePicker.js +89 -0
  84. package/src/instrument-picker/index.js +1 -0
  85. package/src/instrument-picker/moving-window.js +49 -0
  86. package/src/instrument-picker/useDataSource.js +38 -0
  87. package/src/instrument-picker/useTablePicker.js +136 -0
  88. package/src/measured-container/MeasuredContainer.css.js +11 -0
  89. package/src/measured-container/MeasuredContainer.js +50 -0
  90. package/src/measured-container/index.js +2 -0
  91. package/src/measured-container/useMeasuredContainer.js +156 -0
  92. package/src/modal-provider/ModalProvider.js +147 -0
  93. package/src/overflow-container/OverflowContainer.css.js +135 -0
  94. package/src/overflow-container/OverflowContainer.js +87 -0
  95. package/src/overflow-container/index.js +2 -0
  96. package/src/overflow-container/overflow-utils.js +211 -0
  97. package/src/overflow-container/useOverflowContainer.js +108 -0
  98. package/src/price-ticker/PriceTicker.css.js +32 -0
  99. package/src/price-ticker/PriceTicker.js +51 -0
  100. package/src/price-ticker/index.js +1 -0
  101. package/src/prompt/Prompt.css.js +48 -0
  102. package/src/prompt/Prompt.js +112 -0
  103. package/src/sortable-list/SortableList.js +39 -0
  104. package/src/split-button/SplitButton.css.js +117 -0
  105. package/src/split-button/SplitButton.js +60 -0
  106. package/src/split-button/SplitStateButton.css.js +66 -0
  107. package/src/split-button/SplitStateButton.js +23 -0
  108. package/src/split-button/index.js +2 -0
  109. package/src/split-button/useSplitButton.js +61 -0
  110. package/src/table-search/SearchCell.css.js +20 -0
  111. package/src/table-search/SearchCell.js +26 -0
  112. package/src/table-search/TableSearch.css.js +27 -0
  113. package/src/table-search/TableSearch.js +81 -0
  114. package/src/table-search/index.js +1 -0
  115. package/src/table-search/moving-window.js +49 -0
  116. package/src/table-search/useTableSearch.js +30 -0
  117. package/src/tabs-next/TabBar.css.js +26 -0
  118. package/src/tabs-next/TabBar.js +27 -0
  119. package/src/tabs-next/TabListNext.css.js +36 -0
  120. package/src/tabs-next/TabListNext.js +94 -0
  121. package/src/tabs-next/TabNext.css.js +76 -0
  122. package/src/tabs-next/TabNext.js +91 -0
  123. package/src/tabs-next/TabNextAction.js +26 -0
  124. package/src/tabs-next/TabNextContext.js +14 -0
  125. package/src/tabs-next/TabNextPanel.css.js +17 -0
  126. package/src/tabs-next/TabNextPanel.js +69 -0
  127. package/src/tabs-next/TabNextTrigger.css.js +22 -0
  128. package/src/tabs-next/TabNextTrigger.js +66 -0
  129. package/src/tabs-next/TabOverflowList.css.js +77 -0
  130. package/src/tabs-next/TabOverflowList.js +115 -0
  131. package/src/tabs-next/TabsNext.js +149 -0
  132. package/src/tabs-next/TabsNextContext.js +28 -0
  133. package/src/tabs-next/hooks/useCollection.js +80 -0
  134. package/src/tabs-next/hooks/useFocusOutside.js +23 -0
  135. package/src/tabs-next/hooks/useOverflow.js +118 -0
  136. package/src/tabs-next/index.js +7 -0
  137. package/src/tabstrip/Tab.css.js +148 -0
  138. package/src/tabstrip/Tab.js +107 -0
  139. package/src/tabstrip/TabMenu.css.js +8 -0
  140. package/src/tabstrip/TabMenu.js +48 -0
  141. package/src/tabstrip/TabMenuOptions.js +14 -0
  142. package/src/tabstrip/TabsTypes.js +0 -0
  143. package/src/tabstrip/Tabstrip.css.js +121 -0
  144. package/src/tabstrip/Tabstrip.js +106 -0
  145. package/src/tabstrip/ThemeTabstrip.css.js +20 -0
  146. package/src/tabstrip/index.js +4 -0
  147. package/src/tabstrip/tabstrip-dom-utils.js +11 -0
  148. package/src/tabstrip/useAnimatedSelectionThumb.js +68 -0
  149. package/src/tabstrip/useKeyboardNavigation.js +191 -0
  150. package/src/tabstrip/useSelection.js +50 -0
  151. package/src/tabstrip/useTabstrip.js +181 -0
  152. package/src/time-input/MaskedInput.js +285 -0
  153. package/src/time-input/TimeInput.css.js +39 -0
  154. package/src/time-input/TimeInput.js +37 -0
  155. package/src/time-input/useTimeInput.js +82 -0
  156. package/src/toolbar/Toolbar.css.js +46 -0
  157. package/src/toolbar/Toolbar.js +62 -0
  158. package/src/toolbar/index.js +1 -0
  159. package/src/toolbar/toolbar-dom-utils.js +11 -0
  160. package/src/toolbar/useKeyboardNavigation.js +240 -0
  161. package/src/toolbar/useSelection.js +82 -0
  162. package/src/toolbar/useToolbar.js +73 -0
  163. package/src/utils/deprecated-types.js +0 -0
  164. package/src/utils/escapeRegExp.js +5 -0
  165. package/src/utils/forwardCallbackProps.js +15 -0
  166. package/src/utils/index.js +5 -0
  167. package/src/utils/isOverflowElement.js +2 -0
  168. package/src/utils/isPlainObject.js +2 -0
  169. package/src/vuu-date-picker/VuuDatePicker.js +92 -0
  170. package/src/vuu-date-picker/index.js +1 -0
  171. package/src/vuu-input/VuuInput.css.js +13 -0
  172. package/src/vuu-input/VuuInput.js +85 -0
  173. package/src/vuu-input/index.js +1 -0
  174. package/src/vuu-time-picker/TimeRangePicker.js +0 -0
  175. package/src/vuu-time-picker/VuuTimePicker.css.js +14 -0
  176. package/src/vuu-time-picker/VuuTimePicker.js +26 -0
  177. package/src/vuu-typeahead-input/VuuTypeaheadInput.css.js +49 -0
  178. package/src/vuu-typeahead-input/VuuTypeaheadInput.js +46 -0
  179. package/src/vuu-typeahead-input/index.js +1 -0
  180. package/src/vuu-typeahead-input/useVuuTypeaheadInput.js +140 -0
@@ -0,0 +1,181 @@
1
+ import { useCallback, useRef, useState } from "react";
2
+ import { useDragDrop } from "../drag-drop/index.js";
3
+ import { isTabMenuOptions } from "./TabMenuOptions.js";
4
+ import { getIndexOfSelectedTab } from "./tabstrip-dom-utils.js";
5
+ import { useAnimatedSelectionThumb } from "./useAnimatedSelectionThumb.js";
6
+ import { useKeyboardNavigation } from "./useKeyboardNavigation.js";
7
+ import { useSelection } from "./useSelection.js";
8
+ const editKeys = new Set([
9
+ "Enter",
10
+ " "
11
+ ]);
12
+ const isEditKey = (key)=>editKeys.has(key);
13
+ const useTabstrip = ({ activeTabIndex: activeTabIndexProp, allowDragDrop, animateSelectionThumb, containerRef, onActiveChange, onAddTab, onCloseTab, onExitEditMode, onMoveTab, orientation, keyBoardActivation })=>{
14
+ const lastSelection = useRef(activeTabIndexProp);
15
+ const [interactedTabState, setInteractedTabState] = useState();
16
+ const { focusTab: keyboardHookFocusTab, highlightedIdx, onClick: keyboardHookHandleClick, onKeyDown: keyboardHookHandleKeyDown, setHighlightedIdx: keyboardHookSetHighlightedIndex, ...keyboardHook } = useKeyboardNavigation({
17
+ containerRef,
18
+ keyBoardActivation,
19
+ orientation,
20
+ selectedIndex: lastSelection.current
21
+ });
22
+ const { activateTab: selectionHookActivateTab, onClick: selectionHookHandleClick, onKeyDown: selectionHookHandleKeyDown, selected: selectionHookSelected } = useSelection({
23
+ highlightedIdx,
24
+ onSelectionChange: onActiveChange,
25
+ selected: activeTabIndexProp
26
+ });
27
+ lastSelection.current = selectionHookSelected;
28
+ const { containerStyle, resumeAnimation, suspendAnimation } = useAnimatedSelectionThumb(containerRef, animateSelectionThumb ? selectionHookSelected : -1, orientation);
29
+ const handleDrop = useCallback(({ fromIndex, toIndex })=>{
30
+ const { current: selected } = lastSelection;
31
+ console.log(`useTabstrip handleDrop ${fromIndex} - ${toIndex} ${selected}`);
32
+ onMoveTab?.(fromIndex, toIndex);
33
+ let nextSelectedTab = -1;
34
+ if (-1 !== toIndex) {
35
+ if (selected === fromIndex) nextSelectedTab = toIndex;
36
+ else if (fromIndex > selected && toIndex <= selected) nextSelectedTab = selected + 1;
37
+ else if (fromIndex < selected && toIndex >= selected) nextSelectedTab = selected - 1;
38
+ if (-1 !== nextSelectedTab) {
39
+ suspendAnimation();
40
+ selectionHookActivateTab(nextSelectedTab);
41
+ requestAnimationFrame(resumeAnimation);
42
+ }
43
+ keyboardHookFocusTab(toIndex, false, false, 350);
44
+ }
45
+ }, [
46
+ keyboardHookFocusTab,
47
+ onMoveTab,
48
+ resumeAnimation,
49
+ selectionHookActivateTab,
50
+ suspendAnimation
51
+ ]);
52
+ const { onMouseDown: dragDropHookHandleMouseDown, ...dragDropHook } = useDragDrop({
53
+ allowDragDrop,
54
+ containerRef,
55
+ draggableClassName: `tabstrip-${orientation}`,
56
+ onDrop: handleDrop,
57
+ orientation: "horizontal",
58
+ itemQuery: ".vuuOverflowContainer-item"
59
+ });
60
+ const handleExitEditMode = useCallback((originalValue, editedValue, allowDeactivation, tabIndex)=>{
61
+ setInteractedTabState(void 0);
62
+ onExitEditMode?.(originalValue, editedValue, allowDeactivation, tabIndex);
63
+ if (!allowDeactivation) keyboardHookFocusTab(tabIndex, false, true);
64
+ }, [
65
+ keyboardHookFocusTab,
66
+ onExitEditMode
67
+ ]);
68
+ const handleClick = useCallback((evt, tabIndex)=>{
69
+ keyboardHookHandleClick(evt, tabIndex);
70
+ selectionHookHandleClick(evt, tabIndex);
71
+ }, [
72
+ keyboardHookHandleClick,
73
+ selectionHookHandleClick
74
+ ]);
75
+ const editTab = useCallback((tabIndex = highlightedIdx)=>{
76
+ console.log(`set interacted tab state ${tabIndex}`);
77
+ setInteractedTabState({
78
+ index: tabIndex,
79
+ state: "rename"
80
+ });
81
+ }, [
82
+ highlightedIdx
83
+ ]);
84
+ const handleKeyDown = useCallback((evt)=>{
85
+ keyboardHookHandleKeyDown(evt);
86
+ if (!evt.defaultPrevented) selectionHookHandleKeyDown(evt);
87
+ if (!evt.defaultPrevented && isEditKey(evt.key)) editTab();
88
+ }, [
89
+ editTab,
90
+ keyboardHookHandleKeyDown,
91
+ selectionHookHandleKeyDown
92
+ ]);
93
+ const handleCloseTabFromMenu = useCallback((tabIndex)=>{
94
+ const selectedTabIndex = getIndexOfSelectedTab(containerRef.current);
95
+ const newActiveTabIndex = selectedTabIndex > tabIndex ? selectedTabIndex - 1 : selectedTabIndex === tabIndex ? 0 : selectedTabIndex;
96
+ suspendAnimation();
97
+ onCloseTab?.(tabIndex, newActiveTabIndex);
98
+ setTimeout(()=>{
99
+ resumeAnimation();
100
+ }, 200);
101
+ return true;
102
+ }, [
103
+ containerRef,
104
+ onCloseTab,
105
+ resumeAnimation,
106
+ suspendAnimation
107
+ ]);
108
+ const handleRenameTabFromMenu = useCallback((tabIndex)=>{
109
+ editTab(tabIndex);
110
+ return true;
111
+ }, [
112
+ editTab
113
+ ]);
114
+ const handleTabMenuAction = useCallback((menuItemId, options)=>{
115
+ if (isTabMenuOptions(options)) switch(menuItemId){
116
+ case "close-tab":
117
+ return handleCloseTabFromMenu(options.tabIndex);
118
+ case "rename-tab":
119
+ return handleRenameTabFromMenu(options.tabIndex);
120
+ default:
121
+ console.log(`tab menu action ${menuItemId}`);
122
+ }
123
+ return false;
124
+ }, [
125
+ handleCloseTabFromMenu,
126
+ handleRenameTabFromMenu
127
+ ]);
128
+ const handleTabMenuClose = useCallback(()=>{
129
+ if (interactedTabState?.index === highlightedIdx) keyboardHookSetHighlightedIndex(highlightedIdx);
130
+ else keyboardHookFocusTab(highlightedIdx);
131
+ }, [
132
+ highlightedIdx,
133
+ interactedTabState?.index,
134
+ keyboardHookFocusTab,
135
+ keyboardHookSetHighlightedIndex
136
+ ]);
137
+ const onSwitchWrappedItemIntoView = useCallback((item)=>{
138
+ const index = parseInt(item.index);
139
+ if (!isNaN(index)) selectionHookActivateTab(index);
140
+ }, [
141
+ selectionHookActivateTab
142
+ ]);
143
+ const navigationProps = {
144
+ onFocus: keyboardHook.onFocus,
145
+ onKeyDown: handleKeyDown
146
+ };
147
+ const handleAddTabClick = useCallback(()=>{
148
+ onAddTab?.();
149
+ requestAnimationFrame(()=>{
150
+ const selectedTabIndex = getIndexOfSelectedTab(containerRef.current);
151
+ if (-1 !== selectedTabIndex) keyboardHookFocusTab(selectedTabIndex);
152
+ });
153
+ }, [
154
+ containerRef,
155
+ keyboardHookFocusTab,
156
+ onAddTab
157
+ ]);
158
+ const tabProps = {
159
+ onClick: handleClick,
160
+ onKeyDown: handleKeyDown,
161
+ onExitEditMode: handleExitEditMode,
162
+ onMenuAction: handleTabMenuAction,
163
+ onMenuClose: handleTabMenuClose,
164
+ onMouseDown: dragDropHookHandleMouseDown
165
+ };
166
+ return {
167
+ activeTabIndex: selectionHookSelected,
168
+ containerProps: {
169
+ ...keyboardHook.containerProps,
170
+ onSwitchWrappedItemIntoView
171
+ },
172
+ containerStyle,
173
+ focusVisible: keyboardHook.focusVisible,
174
+ interactedTabState,
175
+ navigationProps,
176
+ onClickAddTab: handleAddTabClick,
177
+ tabProps,
178
+ ...dragDropHook
179
+ };
180
+ };
181
+ export { useTabstrip };
@@ -0,0 +1,285 @@
1
+ import { EventEmitter, createSyntheticEvent, decrementTimeUnitValue, incrementTimeUnitValue, isValidTimeString, updateTimeString, zeroTime, zeroTimeUnit } from "@vuu-ui/vuu-utils";
2
+ const NullSelection = {
3
+ end: null,
4
+ start: null
5
+ };
6
+ const FullSelection = {
7
+ end: 0,
8
+ start: 8
9
+ };
10
+ const CursorAtEnd = {
11
+ end: 8,
12
+ start: 8
13
+ };
14
+ class MaskedInput extends EventEmitter {
15
+ #controlled = false;
16
+ #input = null;
17
+ #isFocused = false;
18
+ #isIncrementalChange = false;
19
+ #selectionStart = -1;
20
+ #selectionEnd = -1;
21
+ #value;
22
+ #unitSelected;
23
+ #halfUnitSelected;
24
+ constructor(defaultValue, inputEl = null){
25
+ super();
26
+ if (inputEl) this.input = inputEl;
27
+ this.#value = defaultValue ?? zeroTime;
28
+ }
29
+ set input(el) {
30
+ if (this.#input) throw Error("MaskedInput cannot be reused, create a new instance for a new input");
31
+ this.#input = el;
32
+ el.addEventListener("change", this.emitSyntheticChangeEvent);
33
+ }
34
+ emitSyntheticChangeEvent = (e)=>{
35
+ const syntheticEvent = createSyntheticEvent(e);
36
+ this.emit("change", syntheticEvent);
37
+ };
38
+ get cursorPos() {
39
+ return this.selectionStart;
40
+ }
41
+ set cursorPos(value) {
42
+ this.selectionStart = value;
43
+ this.selectionEnd = value;
44
+ if (this.#input) this.#input.setSelectionRange(value, value);
45
+ }
46
+ get isFocused() {
47
+ return this.#isFocused;
48
+ }
49
+ get selectionStart() {
50
+ return this.#selectionStart;
51
+ }
52
+ set selectionStart(value) {
53
+ this.#selectionStart = value;
54
+ }
55
+ get selectionEnd() {
56
+ return this.#selectionEnd;
57
+ }
58
+ set selectionEnd(value) {
59
+ this.#selectionEnd = value;
60
+ }
61
+ setValue(value) {
62
+ if (!this.#controlled) {
63
+ this.#isIncrementalChange = false;
64
+ this.#value = value;
65
+ }
66
+ if (this.#input) {
67
+ this.#input.value = value;
68
+ this.#input.dispatchEvent(new Event("change", {
69
+ bubbles: true,
70
+ composed: true
71
+ }));
72
+ }
73
+ }
74
+ setUnitValue(unit, value) {
75
+ const newTimeString = updateTimeString(this.#value, unit, value);
76
+ this.setValue(newTimeString);
77
+ }
78
+ getUnitValue(unit) {
79
+ switch(unit){
80
+ case "hours":
81
+ return this.#value.slice(0, 2);
82
+ case "minutes":
83
+ return this.#value.slice(3, 5);
84
+ case "seconds":
85
+ return this.#value.slice(6, 8);
86
+ default:
87
+ throw Error(`[MaskedInout] invalue unit ${unit}`);
88
+ }
89
+ }
90
+ get value() {
91
+ return this.#value;
92
+ }
93
+ set value(value) {
94
+ this.#controlled = true;
95
+ this.#value = value;
96
+ if (this.isFocused) {
97
+ const isIncremental = this.#isIncrementalChange;
98
+ this.#isIncrementalChange = false;
99
+ requestAnimationFrame(()=>{
100
+ if (isIncremental) this.restoreSelection();
101
+ else this.advanceSelection();
102
+ });
103
+ }
104
+ }
105
+ clear(unit) {
106
+ if (this.#input) {
107
+ let newValue = this.#value;
108
+ if ("hours" === unit) newValue = zeroTimeUnit.concat(this.#value.slice(2));
109
+ else if ("minutes" === unit) newValue = this.#value.slice(0, 3).concat(zeroTimeUnit).concat(this.#value.slice(5));
110
+ else if ("seconds" === unit) newValue = this.#value.slice(0, 6).concat(zeroTimeUnit);
111
+ if (newValue !== this.#value) this.setValue(newValue);
112
+ }
113
+ }
114
+ select(unit, halfUnit = false) {
115
+ if (this.#input) {
116
+ const offset = halfUnit ? 1 : 0;
117
+ if ("hours" === unit) {
118
+ this.selectionStart = this.#input.selectionStart = 0 + offset;
119
+ this.selectionEnd = this.#input.selectionEnd = 2;
120
+ } else if ("minutes" === unit) {
121
+ this.selectionStart = this.#input.selectionStart = 3 + offset;
122
+ this.selectionEnd = this.#input.selectionEnd = 5;
123
+ } else if ("seconds" === unit) {
124
+ this.selectionStart = this.#input.selectionStart = 6 + offset;
125
+ this.selectionEnd = this.#input.selectionEnd = 8;
126
+ }
127
+ this.#input.setSelectionRange(this.selectionStart, this.selectionEnd);
128
+ if (halfUnit) {
129
+ this.#halfUnitSelected = unit;
130
+ this.#unitSelected = void 0;
131
+ } else {
132
+ this.#halfUnitSelected = void 0;
133
+ this.#unitSelected = unit;
134
+ }
135
+ }
136
+ }
137
+ removeSelection() {
138
+ this.#selectionStart = this.selectionEnd = 8;
139
+ this.#unitSelected = void 0;
140
+ this.#halfUnitSelected = void 0;
141
+ }
142
+ restoreSelection() {
143
+ if (this.#unitSelected) this.select(this.#unitSelected);
144
+ }
145
+ advanceSelection() {
146
+ if (this.#unitSelected) this.select(this.#unitSelected, true);
147
+ else if ("hours" === this.#halfUnitSelected) this.select("minutes");
148
+ else if ("minutes" === this.#halfUnitSelected) this.select("seconds");
149
+ else if ("seconds" === this.#halfUnitSelected) this.select("seconds");
150
+ else throw Error("unreachable code, in theory");
151
+ }
152
+ moveFocus(direction) {
153
+ if ("right" === direction) {
154
+ if ("hours" === this.#unitSelected || "hours" === this.#halfUnitSelected) this.select("minutes");
155
+ else if ("minutes" === this.#unitSelected || "minutes" === this.#halfUnitSelected) this.select("seconds");
156
+ else if ("seconds" === this.#unitSelected || "seconds" === this.#halfUnitSelected) this.select("seconds");
157
+ } else if ("seconds" === this.#unitSelected || "seconds" === this.#halfUnitSelected) this.select("minutes");
158
+ else if ("minutes" === this.#unitSelected || "minutes" === this.#halfUnitSelected) this.select("hours");
159
+ else if ("hours" === this.#unitSelected || "hours" === this.#halfUnitSelected) this.select("hours");
160
+ else {
161
+ const selection = this.getSelection();
162
+ if (selection === CursorAtEnd) this.select("seconds");
163
+ }
164
+ }
165
+ pasteValue(value) {
166
+ this.#halfUnitSelected = void 0;
167
+ this.#unitSelected = void 0;
168
+ this.#value = value;
169
+ }
170
+ getUnitAtCursorPos(cursorPos = this.cursorPos) {
171
+ if (cursorPos >= 0 && cursorPos < 3) return "hours";
172
+ if (cursorPos < 6) return "minutes";
173
+ if (cursorPos <= 8) return "seconds";
174
+ throw Error(`[MaskedInput] getUnitAtCursorPos invalid cursor position ${cursorPos}`);
175
+ }
176
+ incrementValue() {
177
+ if (this.#input) {
178
+ this.#isIncrementalChange = true;
179
+ const unit = this.getUnitAtCursorPos();
180
+ const unitValue = this.getUnitValue(unit);
181
+ const newUnitValue = incrementTimeUnitValue(unit, unitValue);
182
+ this.setUnitValue(unit, newUnitValue);
183
+ this.select(unit);
184
+ }
185
+ }
186
+ decrementValue() {
187
+ if (this.#input) {
188
+ this.#isIncrementalChange = true;
189
+ const unit = this.getUnitAtCursorPos();
190
+ const unitValue = this.getUnitValue(unit);
191
+ const newUnitValue = decrementTimeUnitValue(unit, unitValue);
192
+ this.setUnitValue(unit, newUnitValue);
193
+ this.select(unit);
194
+ }
195
+ }
196
+ backspace() {
197
+ if (this.#input) {
198
+ const { cursorPos } = this;
199
+ if ("seconds" === this.#unitSelected) {
200
+ this.clear("seconds");
201
+ this.select("minutes");
202
+ } else if ("minutes" === this.#unitSelected) {
203
+ this.clear("minutes");
204
+ this.select("hours");
205
+ } else if ("hours" === this.#unitSelected) {
206
+ this.clear("hours");
207
+ this.select("hours");
208
+ } else if (cursorPos > 0) {
209
+ const offset = 6 === this.selectionStart || 3 === this.selectionStart ? 2 : 1;
210
+ const newValue = this.#value.slice(0, cursorPos - offset).concat(zeroTime.slice(cursorPos - offset, cursorPos)).concat(this.#value.slice(cursorPos));
211
+ this.selectionStart -= offset;
212
+ this.selectionEnd -= offset;
213
+ this.setValue(newValue);
214
+ requestAnimationFrame(()=>{
215
+ this.#input?.setSelectionRange(this.#selectionStart, this.selectionEnd);
216
+ });
217
+ }
218
+ }
219
+ }
220
+ update(key) {
221
+ if (this.#input) {
222
+ const { cursorPos } = this;
223
+ if (cursorPos < 8) {
224
+ const originalValue = this.#value;
225
+ const newValue = this.#value.split("").toSpliced(cursorPos, 1, key).join("");
226
+ this.setValue(newValue);
227
+ if (isValidTimeString(newValue)) {
228
+ this.#input.classList.remove("invalid");
229
+ if (this.#controlled && newValue === originalValue) this.advanceSelection();
230
+ else if (!this.#controlled) this.advanceSelection();
231
+ } else if (this.#unitSelected) {
232
+ this.select(this.#unitSelected);
233
+ this.#input.classList.add("invalid");
234
+ }
235
+ }
236
+ }
237
+ }
238
+ getSelection() {
239
+ if (this.#input) {
240
+ const { selectionEnd, selectionStart } = this.#input;
241
+ if (null === selectionEnd || null === selectionStart) return NullSelection;
242
+ if (0 === selectionStart && 8 === selectionEnd) return FullSelection;
243
+ if (8 === selectionStart && 8 === selectionEnd) return CursorAtEnd;
244
+ else return {
245
+ end: selectionEnd,
246
+ start: selectionStart
247
+ };
248
+ }
249
+ throw Error("[MasketInput] selection referenced, but no input");
250
+ }
251
+ click() {
252
+ if (this.#input) {
253
+ this.#isFocused = true;
254
+ const selection = this.getSelection();
255
+ if (selection === NullSelection) this.select("hours");
256
+ else if (selection === FullSelection) ;
257
+ else {
258
+ const cursorPos = this.#input.selectionStart ?? 0;
259
+ this.select(this.getUnitAtCursorPos(cursorPos));
260
+ }
261
+ }
262
+ }
263
+ doubleClick() {
264
+ if (this.#input) {
265
+ const { selectionStart, selectionEnd } = this.#input;
266
+ if (null === selectionStart || null === selectionEnd) ;
267
+ else if (selectionStart < 3) this.select("hours");
268
+ else if (selectionStart < 6) this.select("minutes");
269
+ else if (selectionStart <= 8) this.select("seconds");
270
+ }
271
+ }
272
+ focus = ()=>{
273
+ if (this.#input) {
274
+ this.#isFocused = true;
275
+ requestAnimationFrame(()=>{
276
+ this.select("hours");
277
+ });
278
+ }
279
+ };
280
+ blur = ()=>{
281
+ this.removeSelection();
282
+ this.#isFocused = false;
283
+ };
284
+ }
285
+ export { MaskedInput };
@@ -0,0 +1,39 @@
1
+ const css = `
2
+ .salt-density-high .vuuTimeInput {
3
+ --time-input-width: 60px;
4
+ }
5
+
6
+ .salt-density-medium .vuuTimeInput {
7
+ --time-input-width: 70px;
8
+ }
9
+
10
+ .salt-density-low .vuuTimeInput {
11
+ --time-input-width: 80px;
12
+ }
13
+
14
+ .salt-density-touch .vuuTimeInput {
15
+ --time-input-width: 90px;
16
+ }
17
+
18
+ .vuuTimeInput {
19
+ background: var(--vuuTimeInput-background, inherit);
20
+ font-family: var(--salt-typography-fontFamily);
21
+ width: var(--vuuTimeInput-width, var(--time-input-width));
22
+ border-width: 1px;
23
+
24
+ &:focus::-webkit-input-placeholder {
25
+ color: #0000;
26
+ }
27
+
28
+ &:focus {
29
+ outline: var(--vuuTimeInput-outline, var(--salt-focused-outline));
30
+ }
31
+ }
32
+
33
+ .invalid {
34
+ border-color: red;
35
+ }
36
+
37
+
38
+ `;
39
+ export default css;
@@ -0,0 +1,37 @@
1
+ import { createElement, forwardRef } from "react";
2
+ import { useForkRef } from "@salt-ds/core";
3
+ import { useComponentCssInjection } from "@salt-ds/styles";
4
+ import { useWindow } from "@salt-ds/window";
5
+ import clsx from "clsx";
6
+ import { useTimeInput } from "./useTimeInput.js";
7
+ import TimeInput_0 from "./TimeInput.css";
8
+ const classBase = "vuuTimeInput";
9
+ const TimeInput_TimeInput = /*#__PURE__*/ forwardRef(function({ className, date, defaultValue, onChange, onCommit, placeholder = "hh:mm:ss", value, ...htmlAttributes }, ref) {
10
+ const targetWindow = useWindow();
11
+ useComponentCssInjection({
12
+ testId: "vuu-time-input",
13
+ css: TimeInput_0,
14
+ window: targetWindow
15
+ });
16
+ const { inputRef, eventHandlers } = useTimeInput({
17
+ date,
18
+ defaultValue,
19
+ onChange,
20
+ onCommit,
21
+ value
22
+ });
23
+ return /*#__PURE__*/ createElement("input", {
24
+ ...htmlAttributes,
25
+ ...eventHandlers,
26
+ "aria-placeholder": placeholder,
27
+ className: clsx(classBase, className),
28
+ defaultValue: defaultValue,
29
+ key: defaultValue,
30
+ placeholder: placeholder,
31
+ readOnly: true,
32
+ ref: useForkRef(ref, inputRef),
33
+ spellCheck: "false",
34
+ value: value
35
+ });
36
+ });
37
+ export { TimeInput_TimeInput as TimeInput };
@@ -0,0 +1,82 @@
1
+ import { isValidTimeString } from "@vuu-ui/vuu-utils";
2
+ import { useCallback, useMemo, useRef } from "react";
3
+ import { MaskedInput } from "./MaskedInput.js";
4
+ const isDigit = (char)=>1 === char.length && /[0-9]/.test(char);
5
+ const useTimeInput = ({ defaultValue, onChange, onCommit, value })=>{
6
+ const mousedDownRef = useRef(false);
7
+ const maskedInputRef = useRef(void 0);
8
+ useMemo(()=>{
9
+ if (void 0 === maskedInputRef.current) {
10
+ maskedInputRef.current = new MaskedInput(defaultValue, null);
11
+ maskedInputRef.current.on("change", (e)=>{
12
+ onChange?.(e);
13
+ });
14
+ }
15
+ if (value && value !== maskedInputRef.current.value) maskedInputRef.current.value = value;
16
+ }, [
17
+ defaultValue,
18
+ onChange,
19
+ value
20
+ ]);
21
+ const setInputEl = useCallback((el)=>{
22
+ if (el && maskedInputRef.current) maskedInputRef.current.input = el;
23
+ }, []);
24
+ const back = useRef(false);
25
+ const commitValue = useCallback((evt, value)=>{
26
+ if (isValidTimeString(value)) onCommit(evt, value, "text-input");
27
+ else if ("hh:mm:ss" === value) console.log("no value set");
28
+ else console.log("value is not valid");
29
+ }, [
30
+ onCommit
31
+ ]);
32
+ const handleKeyDown = useCallback((e)=>{
33
+ const { current: maskedInput } = maskedInputRef;
34
+ if (maskedInput) {
35
+ if ("Backspace" === e.key) {
36
+ maskedInput.backspace();
37
+ back.current = true;
38
+ } else if (isDigit(e.key)) maskedInput.update(e.key);
39
+ else if ("ArrowLeft" === e.key) maskedInput.moveFocus("left");
40
+ else if ("ArrowRight" === e.key) maskedInput.moveFocus("right");
41
+ else if ("ArrowUp" === e.key) maskedInput.incrementValue();
42
+ else if ("ArrowDown" === e.key) maskedInput.decrementValue();
43
+ else if ("v" === e.key && e.metaKey) return;
44
+ else if ("Tab" === e.key) return;
45
+ else if ("Enter" === e.key) commitValue(e, maskedInput.value);
46
+ }
47
+ e.preventDefault();
48
+ }, [
49
+ commitValue
50
+ ]);
51
+ const handleDoubleClick = useCallback(()=>{
52
+ maskedInputRef.current?.doubleClick();
53
+ }, []);
54
+ const handlePaste = useCallback((e)=>{
55
+ const value = e.clipboardData.getData("text");
56
+ if (isValidTimeString(value)) maskedInputRef.current?.pasteValue(value);
57
+ }, []);
58
+ const handleFocus = useCallback(()=>{
59
+ if (mousedDownRef.current) mousedDownRef.current = false;
60
+ else maskedInputRef.current?.focus();
61
+ }, []);
62
+ const handleMouseDown = useCallback(()=>{
63
+ mousedDownRef.current = true;
64
+ }, []);
65
+ const handleMouseUp = useCallback((e)=>{
66
+ e.preventDefault();
67
+ maskedInputRef.current?.click();
68
+ }, []);
69
+ return {
70
+ inputRef: setInputEl,
71
+ eventHandlers: {
72
+ onBlur: maskedInputRef.current?.blur,
73
+ onDoubleClick: handleDoubleClick,
74
+ onFocus: handleFocus,
75
+ onKeyDown: handleKeyDown,
76
+ onMouseDown: handleMouseDown,
77
+ onMouseUp: handleMouseUp,
78
+ onPaste: handlePaste
79
+ }
80
+ };
81
+ };
82
+ export { useTimeInput };
@@ -0,0 +1,46 @@
1
+ const css = `
2
+ .vuuToolbar {
3
+ --toolbar-height: var(--vuuToolbar-height, 36px);
4
+ --toolbar-item-height: var(--vuuToolbarItem-height, 100%);
5
+ --vuuOverflowContainer-background: var(--vuuToolbar-background);
6
+ --vuuOverflowContainer-borderColor: var(--vuuToolbar-borderColor);
7
+ --vuuOverflowContainer-borderStyle: var(--vuuToolbar-borderStyle);
8
+ --vuuOverflowContainer-borderWidth: var(--vuuToolbar-borderWidth);
9
+ height: var(--toolbar-height);
10
+ }
11
+
12
+ .vuuToolbar-alignCenter {
13
+ --vuuOverflowContainer-justifyContent: center;
14
+ }
15
+
16
+ .vuuToolbar-alignEnd {
17
+ --vuuOverflowContainer-justifyContent: flex-end;
18
+ }
19
+
20
+ .vuuToolbar-withSeparators .vuuOverflowContainer-item:not(:first-child):before {
21
+ content: "";
22
+ left: calc(-1 * var(--overflow-item-gap));
23
+ width: 1px;
24
+ height: var(--toolbar-item-height);
25
+ background-color: var(--salt-separable-primary-borderColor);
26
+ position: absolute;
27
+ top: 0;
28
+ }
29
+
30
+ .vuuToolbarItem.vuuFocusVisible {
31
+ outline-color: var(--vuuToolbarItem-outlineColor, var(--salt-focused-outlineColor));
32
+ outline-offset: 0px;
33
+ outline-width: 1px;
34
+ outline-style: dashed;
35
+ }
36
+
37
+ .vuuToolbarItem:focus, .vuuToolbarItem:focus-visible {
38
+ outline-color: var(--vuuToolbarItem-outlineColor, var(--vuu-color-purple-10));
39
+ outline-offset: 0px;
40
+ outline-width: 1px;
41
+ outline-style: dashed;
42
+ }
43
+
44
+
45
+ `;
46
+ export default css;