@rokoyfa/calendar 1.0.0 → 1.1.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-lib/npm/index.js
CHANGED
|
@@ -9037,20 +9037,46 @@ function DangerSection({ calendar, members, currentUserId, onOwnershipTransferre
|
|
|
9037
9037
|
}
|
|
9038
9038
|
|
|
9039
9039
|
// src/hooks/useArrowKeyNavigation.ts
|
|
9040
|
+
var lastUsedRoot = null;
|
|
9041
|
+
var wasUsed = false;
|
|
9042
|
+
var precedes = (a, b) => a.getRootNode().host.compareDocumentPosition(b.getRootNode().host) & Node.DOCUMENT_POSITION_FOLLOWING;
|
|
9040
9043
|
var isEditableTarget = (target) => target instanceof HTMLElement && (target.isContentEditable || target.closest("input, textarea, select, [role=\"dialog\"], dialog") !== null);
|
|
9044
|
+
var isNothingFocused = (target) => target === null || target === document.body || target === document.documentElement || target === document;
|
|
9045
|
+
var isVisible = (element) => {
|
|
9046
|
+
const { top, bottom, width, height } = element.getBoundingClientRect();
|
|
9047
|
+
return width > 0 && height > 0 && bottom > 0 && top < window.innerHeight;
|
|
9048
|
+
};
|
|
9049
|
+
var getInnerTarget = (event) => event.composedPath()[0] ?? null;
|
|
9041
9050
|
function useArrowKeyNavigation({ onPrevious, onNext }) {
|
|
9042
9051
|
const root = useRootElement();
|
|
9052
|
+
useEffect(() => {
|
|
9053
|
+
if (!lastUsedRoot || !wasUsed && precedes(root, lastUsedRoot)) lastUsedRoot = root;
|
|
9054
|
+
const markUsed = () => {
|
|
9055
|
+
lastUsedRoot = root;
|
|
9056
|
+
wasUsed = true;
|
|
9057
|
+
};
|
|
9058
|
+
root.addEventListener("pointerdown", markUsed);
|
|
9059
|
+
root.addEventListener("focusin", markUsed);
|
|
9060
|
+
return () => {
|
|
9061
|
+
root.removeEventListener("pointerdown", markUsed);
|
|
9062
|
+
root.removeEventListener("focusin", markUsed);
|
|
9063
|
+
if (lastUsedRoot === root) lastUsedRoot = null;
|
|
9064
|
+
};
|
|
9065
|
+
}, [root]);
|
|
9043
9066
|
useEffect(() => {
|
|
9044
9067
|
const handleKeyDown = (event) => {
|
|
9045
9068
|
if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
9046
|
-
if (isEditableTarget(event.target)) return;
|
|
9047
9069
|
const action = event.key === "ArrowLeft" ? onPrevious : event.key === "ArrowRight" ? onNext : null;
|
|
9048
9070
|
if (!action) return;
|
|
9071
|
+
const target = getInnerTarget(event);
|
|
9072
|
+
if (event.composedPath().includes(root)) {
|
|
9073
|
+
if (isEditableTarget(target)) return;
|
|
9074
|
+
} else if (!isNothingFocused(target) || lastUsedRoot !== root || !isVisible(root)) return;
|
|
9049
9075
|
event.preventDefault();
|
|
9050
9076
|
action();
|
|
9051
9077
|
};
|
|
9052
|
-
|
|
9053
|
-
return () =>
|
|
9078
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
9079
|
+
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
9054
9080
|
}, [
|
|
9055
9081
|
root,
|
|
9056
9082
|
onPrevious,
|
|
@@ -13148,7 +13174,7 @@ function CalendarWidget({ dataSource: providedDataSource, tenant, getUserToken,
|
|
|
13148
13174
|
}
|
|
13149
13175
|
|
|
13150
13176
|
// src/lib/version.ts
|
|
13151
|
-
var VERSION = "1.
|
|
13177
|
+
var VERSION = "1.1.0";
|
|
13152
13178
|
|
|
13153
13179
|
// src/lib/element.tsx
|
|
13154
13180
|
var DEFAULT_ELEMENT_NAME = "calendar-widget";
|