@opengeoweb/time-slider 19.5.1 → 19.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js
CHANGED
|
@@ -2059,6 +2059,7 @@ var TimeSliderMenu = function TimeSliderMenu(_ref) {
|
|
|
2059
2059
|
icon = _ref.icon,
|
|
2060
2060
|
_ref$onChangeSliderVa = _ref.onChangeSliderValue,
|
|
2061
2061
|
onChangeSliderValue = _ref$onChangeSliderVa === void 0 ? function () {} : _ref$onChangeSliderVa,
|
|
2062
|
+
onSelectSliderValue = _ref.onSelectSliderValue,
|
|
2062
2063
|
displayCurrentLength = _ref.displayCurrentLength,
|
|
2063
2064
|
_ref$disbleUserSetDur = _ref.disbleUserSetDuration,
|
|
2064
2065
|
disbleUserSetDuration = _ref$disbleUserSetDur === void 0 ? true : _ref$disbleUserSetDur,
|
|
@@ -2188,6 +2189,7 @@ var TimeSliderMenu = function TimeSliderMenu(_ref) {
|
|
|
2188
2189
|
if (!isSelected) {
|
|
2189
2190
|
onChangeSliderValue(mark.value);
|
|
2190
2191
|
}
|
|
2192
|
+
onSelectSliderValue == null || onSelectSliderValue(mark.value);
|
|
2191
2193
|
setOpen(false);
|
|
2192
2194
|
},
|
|
2193
2195
|
selected: !!isSelected && !displayLengthInputField,
|
|
@@ -2715,6 +2717,16 @@ var getTimeStepShortcutDirection = function getTimeStepShortcutDirection(event)
|
|
|
2715
2717
|
}
|
|
2716
2718
|
return null;
|
|
2717
2719
|
};
|
|
2720
|
+
var focusAdjacentMenuItem = function focusAdjacentMenuItem(target, direction) {
|
|
2721
|
+
var _target$parentElement, _target$parentElement2, _menuItems$nextIndex;
|
|
2722
|
+
if (!(target instanceof HTMLElement) || target.getAttribute('role') !== 'menuitem') {
|
|
2723
|
+
return;
|
|
2724
|
+
}
|
|
2725
|
+
var menuItems = Array.from((_target$parentElement = (_target$parentElement2 = target.parentElement) == null ? void 0 : _target$parentElement2.querySelectorAll('[role="menuitem"]:not([aria-disabled="true"])')) != null ? _target$parentElement : []);
|
|
2726
|
+
var currentIndex = menuItems.indexOf(target);
|
|
2727
|
+
var nextIndex = currentIndex + (direction === 'up' ? -1 : 1);
|
|
2728
|
+
(_menuItems$nextIndex = menuItems[nextIndex]) == null || _menuItems$nextIndex.focus();
|
|
2729
|
+
};
|
|
2718
2730
|
var TimeStepShortcutContext = /*#__PURE__*/React.createContext(null);
|
|
2719
2731
|
// Listens for the time-step keyboard shortcut on document (capture phase, so it
|
|
2720
2732
|
// runs before any element-level handlers that may stopPropagation). Ignores
|
|
@@ -2738,7 +2750,9 @@ var useTimeStepShortcutListener = function useTimeStepShortcutListener(enabled,
|
|
|
2738
2750
|
return;
|
|
2739
2751
|
}
|
|
2740
2752
|
event.preventDefault();
|
|
2753
|
+
event.stopPropagation();
|
|
2741
2754
|
onShortcutRef.current(direction);
|
|
2755
|
+
focusAdjacentMenuItem(target, direction);
|
|
2742
2756
|
};
|
|
2743
2757
|
document.addEventListener('keydown', handleKeyDown, {
|
|
2744
2758
|
capture: true
|
|
@@ -2880,30 +2894,14 @@ var _TimeStepButton = function TimeStepButton(_ref) {
|
|
|
2880
2894
|
var _useState = useState(isOpenByDefault),
|
|
2881
2895
|
open = _useState[0],
|
|
2882
2896
|
setOpen = _useState[1];
|
|
2883
|
-
var stepToAdjacentMark = useCallback(function (direction) {
|
|
2884
|
-
var _marks$nextIndex;
|
|
2885
|
-
var currentIndex = marks.findIndex(function (mark) {
|
|
2886
|
-
return mark.value === timeStep;
|
|
2887
|
-
});
|
|
2888
|
-
if (currentIndex === -1) {
|
|
2889
|
-
return;
|
|
2890
|
-
}
|
|
2891
|
-
var indexDelta = direction === 'up' ? -1 : 1;
|
|
2892
|
-
var nextIndex = Math.min(Math.max(currentIndex + indexDelta, 0), marks.length - 1);
|
|
2893
|
-
var nextValue = (_marks$nextIndex = marks[nextIndex]) == null ? void 0 : _marks$nextIndex.value;
|
|
2894
|
-
if (nextValue !== undefined && nextValue !== timeStep) {
|
|
2895
|
-
onMenuItemClick(nextValue);
|
|
2896
|
-
}
|
|
2897
|
-
}, [timeStep, onMenuItemClick]);
|
|
2898
2897
|
var shortcutContext = useContext(TimeStepShortcutContext);
|
|
2899
2898
|
useEffect(function () {
|
|
2900
2899
|
if (!(shortcutContext != null && shortcutContext.pendingDirection)) {
|
|
2901
2900
|
return;
|
|
2902
2901
|
}
|
|
2903
2902
|
setOpen(true);
|
|
2904
|
-
stepToAdjacentMark(shortcutContext.pendingDirection);
|
|
2905
2903
|
shortcutContext.consume();
|
|
2906
|
-
}, [shortcutContext
|
|
2904
|
+
}, [shortcutContext]);
|
|
2907
2905
|
return jsx(TimeSliderMenu, {
|
|
2908
2906
|
allOptionsDisabled: disabled,
|
|
2909
2907
|
displayCurrentLength: true,
|
|
@@ -2915,6 +2913,7 @@ var _TimeStepButton = function TimeStepButton(_ref) {
|
|
|
2915
2913
|
isAutoSelected: isTimestepAuto,
|
|
2916
2914
|
marks: translatedMarks,
|
|
2917
2915
|
onChangeSliderValue: onMenuItemClick,
|
|
2916
|
+
onSelectSliderValue: shortcutContext == null ? void 0 : shortcutContext.closeOptionsMenu,
|
|
2918
2917
|
open: open,
|
|
2919
2918
|
setOpen: setOpen,
|
|
2920
2919
|
title: t('timeslider-time-step'),
|
|
@@ -2986,6 +2985,7 @@ var OptionsMenuButton = function OptionsMenuButton(_ref) {
|
|
|
2986
2985
|
var _useState3 = useState(null),
|
|
2987
2986
|
pendingDirection = _useState3[0],
|
|
2988
2987
|
setPendingDirection = _useState3[1];
|
|
2988
|
+
var openedByShortcutRef = useRef(false);
|
|
2989
2989
|
var _useTimesliderTransla = useTimesliderTranslation(),
|
|
2990
2990
|
t = _useTimesliderTransla.t;
|
|
2991
2991
|
useEffect(function () {
|
|
@@ -2994,12 +2994,24 @@ var OptionsMenuButton = function OptionsMenuButton(_ref) {
|
|
|
2994
2994
|
}
|
|
2995
2995
|
}, [anchorEl, isOpenByDefault]);
|
|
2996
2996
|
useTimeStepShortcutListener(enableKeyboardShortcut, function (direction) {
|
|
2997
|
-
setOpen(
|
|
2997
|
+
setOpen(function (wasOpen) {
|
|
2998
|
+
if (!wasOpen) {
|
|
2999
|
+
openedByShortcutRef.current = true;
|
|
3000
|
+
}
|
|
3001
|
+
return true;
|
|
3002
|
+
});
|
|
2998
3003
|
setPendingDirection(direction);
|
|
2999
3004
|
});
|
|
3000
3005
|
var shortcutContextValue = useMemo(function () {
|
|
3001
3006
|
return {
|
|
3002
3007
|
pendingDirection: pendingDirection,
|
|
3008
|
+
closeOptionsMenu: function closeOptionsMenu() {
|
|
3009
|
+
if (openedByShortcutRef.current) {
|
|
3010
|
+
setOpen(false);
|
|
3011
|
+
}
|
|
3012
|
+
openedByShortcutRef.current = false;
|
|
3013
|
+
setPendingDirection(null);
|
|
3014
|
+
},
|
|
3003
3015
|
consume: function consume() {
|
|
3004
3016
|
return setPendingDirection(null);
|
|
3005
3017
|
}
|
|
@@ -3011,6 +3023,7 @@ var OptionsMenuButton = function OptionsMenuButton(_ref) {
|
|
|
3011
3023
|
"data-testid": "optionsMenuButton",
|
|
3012
3024
|
isSelected: open,
|
|
3013
3025
|
onClick: function onClick() {
|
|
3026
|
+
openedByShortcutRef.current = false;
|
|
3014
3027
|
setOpen(!open);
|
|
3015
3028
|
},
|
|
3016
3029
|
ref: function ref(_ref2) {
|
package/dist/src/lib/components/TimeSliderButtons/OptionsMenuButton/optionsMenuShortcut.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type TimeStepDirection = 'up' | 'down';
|
|
|
3
3
|
export declare const getTimeStepShortcutDirection: (event: KeyboardEvent | React.KeyboardEvent) => TimeStepDirection | null;
|
|
4
4
|
export interface TimeStepShortcutContextValue {
|
|
5
5
|
pendingDirection: TimeStepDirection | null;
|
|
6
|
+
closeOptionsMenu: () => void;
|
|
6
7
|
consume: () => void;
|
|
7
8
|
}
|
|
8
9
|
export declare const TimeStepShortcutContext: React.Context<TimeStepShortcutContextValue | null>;
|
|
@@ -14,6 +14,7 @@ export interface TimeSliderMenuProps {
|
|
|
14
14
|
handleAutoClick?: () => void;
|
|
15
15
|
isAutoSelected?: boolean;
|
|
16
16
|
onChangeSliderValue?: (markValue: number) => void;
|
|
17
|
+
onSelectSliderValue?: (markValue: number) => void;
|
|
17
18
|
setOpen: (display: boolean) => void;
|
|
18
19
|
open: boolean;
|
|
19
20
|
displayCurrentLength?: boolean;
|
|
@@ -21,4 +22,4 @@ export interface TimeSliderMenuProps {
|
|
|
21
22
|
customLengthSelector?: React.ReactNode;
|
|
22
23
|
customFieldHeader?: string;
|
|
23
24
|
}
|
|
24
|
-
export declare const TimeSliderMenu: ({ marks, value, allOptionsDisabled, isAutoDisabled, handleAutoClick, isAutoSelected, title, icon, onChangeSliderValue, displayCurrentLength, disbleUserSetDuration, customLengthSelector, setOpen, customFieldHeader, open, }: TimeSliderMenuProps) => React.ReactElement;
|
|
25
|
+
export declare const TimeSliderMenu: ({ marks, value, allOptionsDisabled, isAutoDisabled, handleAutoClick, isAutoSelected, title, icon, onChangeSliderValue, onSelectSliderValue, displayCurrentLength, disbleUserSetDuration, customLengthSelector, setOpen, customFieldHeader, open, }: TimeSliderMenuProps) => React.ReactElement;
|