@trackunit/react-components 8.0.7 → 8.0.8
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/index.cjs.js +133 -19
- package/index.esm.js +134 -20
- package/migrations/assets/react-router-components/package.json +3 -3
- package/migrations/entry.js.map +1 -0
- package/migrations/utils/jsx-utils.js.map +1 -0
- package/migrations/utils/move-named-imports.js.map +1 -0
- package/migrations/utils/package-json-utils.js.map +1 -0
- package/migrations/v2-0-0/breadcrumb-remove-deprecated-props.js.map +1 -0
- package/migrations/v2-0-0/cardheader-onclickclose-to-actions.js.map +1 -0
- package/migrations/v2-0-0/iconbutton-add-required-name.js.map +1 -0
- package/migrations/v2-0-0/kpi-tooltiplabel-to-wrapper.js.map +1 -0
- package/migrations/v2-0-0/notice-tooltiplabel-to-wrapper.js.map +1 -0
- package/migrations/v2-0-0/pagination-add-required-titles.js.map +1 -0
- package/migrations/v2-0-0/tag-add-removetaglabel.js.map +1 -0
- package/migrations/v2-0-0/togglegroup-remove-item-style.js.map +1 -0
- package/migrations/v2-6-0/menulist-rename-to-menucontent.js.map +1 -0
- package/migrations/v3-0-0/copyabletext-to-text-copybutton.js.map +1 -0
- package/migrations/v4-0-0/move-to-router-components.js.map +1 -0
- package/migrations/v8-0-0/collapse-native-details.js.map +1 -0
- package/package.json +1 -1
- package/src/components/Popover/PopoverContent.d.ts +10 -1
- package/src/components/Popover/PopoverTypes.d.ts +10 -2
- package/src/components/Popover/usePopover.d.ts +1 -1
- package/src/components/Popover/utils/keyboardFocus/keyboardFocus.d.ts +13 -0
- package/src/components/Tooltip/Tooltip.d.ts +1 -1
- package/src/components/Tooltip/Tooltip.variants.d.ts +12 -6
- package/translation.cjs.js +1 -1
- package/translation.esm.js +1 -1
- package/translation11.cjs.js +1 -1
- package/translation11.esm.js +1 -1
- package/translation12.cjs.js +1 -1
- package/translation12.esm.js +1 -1
- package/translation6.cjs.js +1 -1
- package/translation6.esm.js +1 -1
package/index.cjs.js
CHANGED
|
@@ -765,7 +765,83 @@ const useHoverScrollGuard = ({ enabled, hoverEnabled, openSiblingPinned, isOpen,
|
|
|
765
765
|
return enabled && isHoverScrollSuppressed;
|
|
766
766
|
};
|
|
767
767
|
|
|
768
|
-
|
|
768
|
+
/**
|
|
769
|
+
* `useFocus` treats `:focus-visible` as keyboard focus. jsdom reports that for every focus, and a
|
|
770
|
+
* programmatic `focus()` would otherwise open the popover and consume the next Escape. A key press
|
|
771
|
+
* is the signal we keep.
|
|
772
|
+
*
|
|
773
|
+
* One shared listener pair for every popover that opts into focus activation. A per-instance
|
|
774
|
+
* listener would add a capture-phase `keydown` and `pointerdown` handler, plus a timer, for every
|
|
775
|
+
* tooltip on the page.
|
|
776
|
+
*/
|
|
777
|
+
let keyboardFocus = false;
|
|
778
|
+
let subscribers = 0;
|
|
779
|
+
let outerFrame = 0;
|
|
780
|
+
let innerFrame = 0;
|
|
781
|
+
const cancelClear = () => {
|
|
782
|
+
if (outerFrame !== 0) {
|
|
783
|
+
cancelAnimationFrame(outerFrame);
|
|
784
|
+
outerFrame = 0;
|
|
785
|
+
}
|
|
786
|
+
if (innerFrame !== 0) {
|
|
787
|
+
cancelAnimationFrame(innerFrame);
|
|
788
|
+
innerFrame = 0;
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
const clearKeyboardFocus = () => {
|
|
792
|
+
keyboardFocus = false;
|
|
793
|
+
cancelClear();
|
|
794
|
+
};
|
|
795
|
+
const markKeyboardFocus = (event) => {
|
|
796
|
+
// Escape closes a menu or dialog, which hands focus back to its trigger. That return is not
|
|
797
|
+
// navigation, so it must not open the trigger's tooltip.
|
|
798
|
+
if (event.key === "Escape") {
|
|
799
|
+
clearKeyboardFocus();
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
keyboardFocus = true;
|
|
803
|
+
cancelClear();
|
|
804
|
+
// Tab moves focus in this key's default action, before either frame below. Menu navigation
|
|
805
|
+
// focuses the next item from Floating UI's requestAnimationFrame, which is later than a 0ms
|
|
806
|
+
// timeout, so the flag has to survive that frame. The frame after clears it: a programmatic
|
|
807
|
+
// focus() that was not caused by this key must not open a tooltip or take the next Escape.
|
|
808
|
+
outerFrame = requestAnimationFrame(() => {
|
|
809
|
+
outerFrame = 0;
|
|
810
|
+
innerFrame = requestAnimationFrame(() => {
|
|
811
|
+
keyboardFocus = false;
|
|
812
|
+
innerFrame = 0;
|
|
813
|
+
});
|
|
814
|
+
});
|
|
815
|
+
};
|
|
816
|
+
/**
|
|
817
|
+
* Installs the shared listeners on the first subscriber and removes them when the last one leaves.
|
|
818
|
+
*
|
|
819
|
+
* @returns {() => void} Unsubscribes this caller.
|
|
820
|
+
*/
|
|
821
|
+
const subscribeToKeyboardFocus = () => {
|
|
822
|
+
if (subscribers === 0) {
|
|
823
|
+
window.addEventListener("keydown", markKeyboardFocus, true);
|
|
824
|
+
window.addEventListener("pointerdown", clearKeyboardFocus, true);
|
|
825
|
+
}
|
|
826
|
+
subscribers += 1;
|
|
827
|
+
return () => {
|
|
828
|
+
subscribers -= 1;
|
|
829
|
+
if (subscribers === 0) {
|
|
830
|
+
window.removeEventListener("keydown", markKeyboardFocus, true);
|
|
831
|
+
window.removeEventListener("pointerdown", clearKeyboardFocus, true);
|
|
832
|
+
clearKeyboardFocus();
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
};
|
|
836
|
+
/**
|
|
837
|
+
* Whether the most recent input was a key press that should count as keyboard focus.
|
|
838
|
+
*
|
|
839
|
+
* @returns {boolean} True until the key's focus change has been handled, including one scheduled for the
|
|
840
|
+
* next frame, or a pointer press or Escape clears it.
|
|
841
|
+
*/
|
|
842
|
+
const isKeyboardFocus = () => keyboardFocus;
|
|
843
|
+
|
|
844
|
+
const DEFAULT_ACTIVATION = { click: true, hover: false, keyboardHandlers: true, focus: false };
|
|
769
845
|
const DEFAULT_DISMISSAL = {
|
|
770
846
|
enabled: true,
|
|
771
847
|
outsidePress: true,
|
|
@@ -838,7 +914,7 @@ const getNestedVerticalAlignmentAxis = ({ rects }) => {
|
|
|
838
914
|
* @param {PopoverProps} options The options for the popover
|
|
839
915
|
* @returns {UsePopoverType} The data for the popover
|
|
840
916
|
*/
|
|
841
|
-
const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = DEFAULT_ACTIVATION, dismissal = DEFAULT_DISMISSAL, sizing = DEFAULT_SIZING, onOpenStateChange, role = "dialog", id, className, "data-testid": dataTestId, }) => {
|
|
917
|
+
const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = DEFAULT_ACTIVATION, dismissal = DEFAULT_DISMISSAL, sizing = DEFAULT_SIZING, onOpenStateChange, role = "dialog", roleEnabled = true, id, className, "data-testid": dataTestId, }) => {
|
|
842
918
|
const [uncontrolledIsOpen, setUncontrolledIsOpen] = react.useState(initialOpen);
|
|
843
919
|
const [labelId, setLabelId] = react.useState();
|
|
844
920
|
const [descriptionId, setDescriptionId] = react.useState();
|
|
@@ -949,6 +1025,9 @@ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen
|
|
|
949
1025
|
placement,
|
|
950
1026
|
open: isOpen,
|
|
951
1027
|
onOpenChange: (open, _event, reason) => {
|
|
1028
|
+
if (open && reason === "focus" && !isKeyboardFocus()) {
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
952
1031
|
setUncontrolledIsOpen(open);
|
|
953
1032
|
onOpenStateChange?.(open);
|
|
954
1033
|
// Reset to `undefined` on close (regardless of *how* it closed) rather than keeping the close
|
|
@@ -979,8 +1058,15 @@ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen
|
|
|
979
1058
|
}, [isOpen, popoverData.update]);
|
|
980
1059
|
const popoverContext = popoverData.context;
|
|
981
1060
|
const resolvedActivation = typeof activation === "function" ? activation(DEFAULT_ACTIVATION) : activation;
|
|
1061
|
+
const focusEnabled = resolvedActivation.focus === true;
|
|
1062
|
+
react.useEffect(() => {
|
|
1063
|
+
if (!focusEnabled) {
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
return subscribeToKeyboardFocus();
|
|
1067
|
+
}, [focusEnabled]);
|
|
982
1068
|
const resolvedDismissal = typeof dismissal === "function" ? dismissal(DEFAULT_DISMISSAL) : dismissal;
|
|
983
|
-
const { outsidePress: configuredOutsidePress, ...restDismissal } = resolvedDismissal;
|
|
1069
|
+
const { outsidePress: configuredOutsidePress, bubbles: configuredBubbles, ...restDismissal } = resolvedDismissal;
|
|
984
1070
|
const clickInteraction = react$1.useClick(popoverContext, {
|
|
985
1071
|
enabled: resolvedActivation.click,
|
|
986
1072
|
keyboardHandlers: resolvedActivation.keyboardHandlers,
|
|
@@ -1012,10 +1098,21 @@ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen
|
|
|
1012
1098
|
}
|
|
1013
1099
|
return true;
|
|
1014
1100
|
},
|
|
1015
|
-
// Nested in a MenuTree: Escape closes one level at a time
|
|
1016
|
-
//
|
|
1017
|
-
//
|
|
1018
|
-
|
|
1101
|
+
// Nested in a MenuTree: Escape closes one level at a time unless the caller opts out.
|
|
1102
|
+
// Tooltips do: a hint must not swallow the Escape that dismisses the menu. Outside-press
|
|
1103
|
+
// bubbles only when the press is genuinely outside the tree; sibling-row presses are filtered
|
|
1104
|
+
// above so they don't collapse the root menu.
|
|
1105
|
+
// Other popovers keep Floating UI's default (Escape does not bubble) unless the caller asks
|
|
1106
|
+
// otherwise.
|
|
1107
|
+
bubbles: isInsideMenuTree
|
|
1108
|
+
? {
|
|
1109
|
+
escapeKey: false,
|
|
1110
|
+
outsidePress: true,
|
|
1111
|
+
...(typeof configuredBubbles === "boolean"
|
|
1112
|
+
? { escapeKey: configuredBubbles, outsidePress: configuredBubbles }
|
|
1113
|
+
: configuredBubbles),
|
|
1114
|
+
}
|
|
1115
|
+
: configuredBubbles,
|
|
1019
1116
|
});
|
|
1020
1117
|
const hoverOptions = typeof resolvedActivation.hover === "object" ? resolvedActivation.hover : undefined;
|
|
1021
1118
|
const hoverEnabled = hoverOptions ? (hoverOptions.active ?? true) : resolvedActivation.hover === true;
|
|
@@ -1091,6 +1188,12 @@ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen
|
|
|
1091
1188
|
popoverContext,
|
|
1092
1189
|
referenceRef: popoverData.refs.reference,
|
|
1093
1190
|
});
|
|
1191
|
+
const focusInteraction = react$1.useFocus(popoverContext, {
|
|
1192
|
+
// `visibleOnly` keeps pointer focus from opening the popover. Keyboard focus still matches
|
|
1193
|
+
// `:focus-visible`.
|
|
1194
|
+
enabled: focusEnabled,
|
|
1195
|
+
visibleOnly: true,
|
|
1196
|
+
});
|
|
1094
1197
|
const hoverInteraction = react$1.useHover(popoverContext, {
|
|
1095
1198
|
enabled: hoverEnabled && !openSiblingPinned && !isHoverScrollSuppressed,
|
|
1096
1199
|
delay: isHoverDelayed && !hasOpenSibling ? { open: 400 } : undefined,
|
|
@@ -1121,9 +1224,7 @@ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen
|
|
|
1121
1224
|
? react$1.safePolygon({ blockPointerEvents: isInsideMenuTree })
|
|
1122
1225
|
: undefined,
|
|
1123
1226
|
});
|
|
1124
|
-
const
|
|
1125
|
-
const focusInteraction = react$1.useFocus(popoverContext, { enabled: focusEnabled });
|
|
1126
|
-
const roleInteraction = react$1.useRole(popoverContext, { role });
|
|
1227
|
+
const roleInteraction = react$1.useRole(popoverContext, { enabled: roleEnabled, role });
|
|
1127
1228
|
// Distinguishes a genuine open -> close transition from this node simply mounting closed (the
|
|
1128
1229
|
// common case: every unrelated sibling elsewhere in the tree mounts with `isOpen === false`).
|
|
1129
1230
|
// Without this, that initial "closed" render would emit `MENU_TREE_CLOSE_EVENT` regardless, and
|
|
@@ -1381,14 +1482,14 @@ const withVisibilityCheck = (sourceRef) => ({
|
|
|
1381
1482
|
* @param {PopoverContentProps} props - The props for the PopoverContent component
|
|
1382
1483
|
* @returns {ReactElement} The popover content element
|
|
1383
1484
|
*/
|
|
1384
|
-
const PopoverContent = function PopoverContent({ className, "data-testid": dataTestId, children, portalId, initialFocus, returnFocus = true, ref: propRef, ...props }) {
|
|
1485
|
+
const PopoverContent = function PopoverContent({ className, "data-testid": dataTestId, children, portalId, initialFocus, returnFocus = true, guards = true, ref: propRef, ...props }) {
|
|
1385
1486
|
const { context: floatingContext, customProps, ...context } = usePopoverContext();
|
|
1386
1487
|
const ref = react$1.useMergeRefs([context.refs.setFloating, propRef]);
|
|
1387
1488
|
// Only a ref-based `returnFocus` has a concrete target to check -- the `boolean` case defers to
|
|
1388
1489
|
// Floating UI's own app-wide "previously focused element" tracking, which isn't exposed here to
|
|
1389
1490
|
// check against.
|
|
1390
1491
|
const resolvedReturnFocus = typeof returnFocus === "boolean" ? returnFocus : withVisibilityCheck(returnFocus);
|
|
1391
|
-
return (jsxRuntime.jsx(react$1.FloatingPortal, { id: portalId, root: document.body, children: context.isOpen === true ? (jsxRuntime.jsx(react$1.FloatingFocusManager, { closeOnFocusOut: context.closeOnFocusOut, context: floatingContext, guards:
|
|
1492
|
+
return (jsxRuntime.jsx(react$1.FloatingPortal, { id: portalId, preserveTabOrder: guards, root: document.body, children: context.isOpen === true ? (jsxRuntime.jsx(react$1.FloatingFocusManager, { closeOnFocusOut: context.closeOnFocusOut, context: floatingContext, guards: guards, initialFocus: initialFocus, modal: context.isModal, order: ["reference", "content"], returnFocus: resolvedReturnFocus, children: jsxRuntime.jsx("div", { "aria-describedby": context.descriptionId, "aria-labelledby": context.labelId, className: cvaPopoverContainer({ className: className ?? customProps.className }), "data-testid": dataTestId ?? customProps["data-testid"] ?? "popover-content", ref: ref, style: {
|
|
1392
1493
|
position: context.strategy,
|
|
1393
1494
|
top: context.y,
|
|
1394
1495
|
left: context.x,
|
|
@@ -2102,12 +2203,21 @@ const Text = ({ children, type = "p", size = "medium", align = "left", weight =
|
|
|
2102
2203
|
};
|
|
2103
2204
|
Text.displayName = "Text";
|
|
2104
2205
|
|
|
2206
|
+
const cvaTooltipTrigger = cssClassVarianceUtilities.cva({
|
|
2207
|
+
base: ["group", "inline-flex", "cursor-pointer", "border-0", "bg-transparent", "p-0"],
|
|
2208
|
+
});
|
|
2105
2209
|
const cvaTooltipIcon = cssClassVarianceUtilities.cva({
|
|
2106
|
-
base: [
|
|
2210
|
+
base: [
|
|
2211
|
+
"text-neutral-300",
|
|
2212
|
+
"transition",
|
|
2213
|
+
"hover:cursor-pointer",
|
|
2214
|
+
"hover:text-neutral-400",
|
|
2215
|
+
"group-focus-visible:text-neutral-400",
|
|
2216
|
+
],
|
|
2107
2217
|
variants: {
|
|
2108
2218
|
color: {
|
|
2109
|
-
light: "hover:text-white",
|
|
2110
|
-
dark: "hover:text-neutral-400",
|
|
2219
|
+
light: ["hover:text-white", "group-focus-visible:text-white"],
|
|
2220
|
+
dark: ["hover:text-neutral-400", "group-focus-visible:text-neutral-400"],
|
|
2111
2221
|
},
|
|
2112
2222
|
defaultVariants: {
|
|
2113
2223
|
color: "dark",
|
|
@@ -2165,7 +2275,7 @@ const FloatingArrowContainer = ({ arrowRef, mode = "dark", }) => {
|
|
|
2165
2275
|
return (jsxRuntime.jsx(react$1.FloatingArrow, { className: cvaTooltipPopoverTail({ mode, placement: floatingContext.placement }), context: floatingContext, ref: arrowRef }));
|
|
2166
2276
|
};
|
|
2167
2277
|
/**
|
|
2168
|
-
* Tooltips display additional information upon hover
|
|
2278
|
+
* Tooltips display additional information upon hover, and on keyboard focus with `openOnFocus`. The information included should be contextual, helpful, and nonessential while providing that extra ability to communicate and give clarity to a user.
|
|
2169
2279
|
*
|
|
2170
2280
|
* Tooltips should be used sparingly and contain succinct, supplementary information, and they should contain read-only text. **❗️Do not include interactive elements in tooltips ** (no links, buttons, etc). Interactive elements in tooltips are inaccessible since tooltips do not receive focus.
|
|
2171
2281
|
*
|
|
@@ -2222,8 +2332,11 @@ const Tooltip = ({ children, "data-testid": dataTestId, disabled = false, label,
|
|
|
2222
2332
|
setIsOpen(false);
|
|
2223
2333
|
}
|
|
2224
2334
|
// A label that repeats the trigger's accessible name would be read twice as its description.
|
|
2225
|
-
|
|
2226
|
-
|
|
2335
|
+
// The default icon trigger is always named with the label.
|
|
2336
|
+
const labelIsTriggerName = children === undefined ||
|
|
2337
|
+
(react.isValidElement(children) &&
|
|
2338
|
+
(children.props.ariaLabel === label || children.props["aria-label"] === label));
|
|
2339
|
+
const { className: iconClassName, ...restIconProps } = iconProps ?? {};
|
|
2227
2340
|
const arrowRef = react.useRef(null);
|
|
2228
2341
|
const { refs, floatingStyles, context } = react$1.useFloating({
|
|
2229
2342
|
placement: placement === "auto" ? "bottom" : placement,
|
|
@@ -2246,7 +2359,8 @@ const Tooltip = ({ children, "data-testid": dataTestId, disabled = false, label,
|
|
|
2246
2359
|
const wrappedChildren = react.useMemo(() => {
|
|
2247
2360
|
return jsxRuntime.jsx(reactSlot.Slot, { children: children });
|
|
2248
2361
|
}, [children]);
|
|
2249
|
-
|
|
2362
|
+
// Escape closes the hint and continues upward, so a menu or the assistant panel still hears it.
|
|
2363
|
+
return (jsxRuntime.jsxs(Popover, { activation: { click: false, hover: { delayed, interactable }, focus: openOnFocus && !tooltipSuppressed }, className: cvaTooltipPopover(), "data-testid": dataTestId, dismissal: { bubbles: { escapeKey: true } }, id: id, isOpen: tooltipSuppressed ? false : isOpen, onOpenStateChange: setIsOpen, placement: placement === "auto" ? "bottom" : placement, role: openOnFocus ? (labelIsTriggerName ? "label" : "tooltip") : undefined, roleEnabled: !tooltipSuppressed, children: [jsxRuntime.jsx(PopoverTrigger, { ...rest, "data-testid": dataTestId ? `${dataTestId}-trigger` : null, ref: mergedRef, style: style, children: children !== undefined ? (wrappedChildren) : openOnFocus ? (jsxRuntime.jsxs("button", { "aria-label": typeof label === "string" ? label : undefined, className: cvaTooltipTrigger(), disabled: disabled, type: "button", children: [typeof label === "string" ? null : jsxRuntime.jsx("span", { className: "sr-only", children: label }), jsxRuntime.jsx(Icon, { "data-testid": dataTestId ? `${dataTestId}-icon` : undefined, name: "QuestionMarkCircle", size: "small", ...restIconProps, ariaHidden: true, className: cvaTooltipIcon({ className: iconClassName, color: mode }) })] })) : (jsxRuntime.jsx(Icon, { className: cvaTooltipIcon({ color: mode }), "data-testid": dataTestId ? `${dataTestId}-icon` : undefined, name: "QuestionMarkCircle", size: "small", ...iconProps })) }), tooltipSuppressed || !isMounted ? null : (jsxRuntime.jsx("div", { ref: refs.setFloating, style: floatingStyles, children: jsxRuntime.jsx(PopoverContent, { guards: !openOnFocus, initialFocus: -1, returnFocus: false, children: jsxRuntime.jsxs("div", { "aria-label": typeof label === "string" ? label : undefined, className: cvaTooltipPopoverContent({ color: mode }), "data-testid": dataTestId ? `${dataTestId}-content` : undefined, onClick: e => e.stopPropagation(), onDoubleClick: e => e.stopPropagation(), onMouseDown: e => e.stopPropagation(), onPointerDown: e => e.stopPropagation(), children: [jsxRuntime.jsx(Text, { "data-testid": dataTestId ? `${dataTestId}-text` : undefined, inverted: mode === "dark", size: "small", type: typeof label === "string" ? "p" : "span", children: label }), placement !== "auto" && jsxRuntime.jsx(FloatingArrowContainer, { arrowRef: arrowRef, mode: mode })] }) }) }))] }));
|
|
2250
2364
|
};
|
|
2251
2365
|
|
|
2252
2366
|
/**
|
package/index.esm.js
CHANGED
|
@@ -12,7 +12,7 @@ import IconSpriteOutline from '@trackunit/ui-icons/icons-sprite-outline.svg';
|
|
|
12
12
|
import IconSpriteSolid from '@trackunit/ui-icons/icons-sprite-solid.svg';
|
|
13
13
|
import { snakeCase, titleCase } from 'string-ts';
|
|
14
14
|
import { cva } from '@trackunit/css-class-variance-utilities';
|
|
15
|
-
import { FloatingTree, useFloatingNodeId, useFloatingParentNodeId, useFloatingTree, offset, flip, shift, size, useFloating, autoUpdate, useClick, useDismiss, useHover as useHover$1, safePolygon,
|
|
15
|
+
import { FloatingTree, useFloatingNodeId, useFloatingParentNodeId, useFloatingTree, offset, flip, shift, size, useFloating, autoUpdate, useClick, useDismiss, useFocus, useHover as useHover$1, safePolygon, useRole, useInteractions, FloatingNode, useMergeRefs as useMergeRefs$1, FloatingPortal, FloatingFocusManager, arrow, useTransitionStatus, FloatingArrow, useListNavigation, useTypeahead, FloatingList, useListItem } from '@floating-ui/react';
|
|
16
16
|
import { Slot, Slottable } from '@radix-ui/react-slot';
|
|
17
17
|
import { omit, isEqual } from 'es-toolkit';
|
|
18
18
|
import { Link, useBlocker } from '@tanstack/react-router';
|
|
@@ -764,7 +764,83 @@ const useHoverScrollGuard = ({ enabled, hoverEnabled, openSiblingPinned, isOpen,
|
|
|
764
764
|
return enabled && isHoverScrollSuppressed;
|
|
765
765
|
};
|
|
766
766
|
|
|
767
|
-
|
|
767
|
+
/**
|
|
768
|
+
* `useFocus` treats `:focus-visible` as keyboard focus. jsdom reports that for every focus, and a
|
|
769
|
+
* programmatic `focus()` would otherwise open the popover and consume the next Escape. A key press
|
|
770
|
+
* is the signal we keep.
|
|
771
|
+
*
|
|
772
|
+
* One shared listener pair for every popover that opts into focus activation. A per-instance
|
|
773
|
+
* listener would add a capture-phase `keydown` and `pointerdown` handler, plus a timer, for every
|
|
774
|
+
* tooltip on the page.
|
|
775
|
+
*/
|
|
776
|
+
let keyboardFocus = false;
|
|
777
|
+
let subscribers = 0;
|
|
778
|
+
let outerFrame = 0;
|
|
779
|
+
let innerFrame = 0;
|
|
780
|
+
const cancelClear = () => {
|
|
781
|
+
if (outerFrame !== 0) {
|
|
782
|
+
cancelAnimationFrame(outerFrame);
|
|
783
|
+
outerFrame = 0;
|
|
784
|
+
}
|
|
785
|
+
if (innerFrame !== 0) {
|
|
786
|
+
cancelAnimationFrame(innerFrame);
|
|
787
|
+
innerFrame = 0;
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
const clearKeyboardFocus = () => {
|
|
791
|
+
keyboardFocus = false;
|
|
792
|
+
cancelClear();
|
|
793
|
+
};
|
|
794
|
+
const markKeyboardFocus = (event) => {
|
|
795
|
+
// Escape closes a menu or dialog, which hands focus back to its trigger. That return is not
|
|
796
|
+
// navigation, so it must not open the trigger's tooltip.
|
|
797
|
+
if (event.key === "Escape") {
|
|
798
|
+
clearKeyboardFocus();
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
keyboardFocus = true;
|
|
802
|
+
cancelClear();
|
|
803
|
+
// Tab moves focus in this key's default action, before either frame below. Menu navigation
|
|
804
|
+
// focuses the next item from Floating UI's requestAnimationFrame, which is later than a 0ms
|
|
805
|
+
// timeout, so the flag has to survive that frame. The frame after clears it: a programmatic
|
|
806
|
+
// focus() that was not caused by this key must not open a tooltip or take the next Escape.
|
|
807
|
+
outerFrame = requestAnimationFrame(() => {
|
|
808
|
+
outerFrame = 0;
|
|
809
|
+
innerFrame = requestAnimationFrame(() => {
|
|
810
|
+
keyboardFocus = false;
|
|
811
|
+
innerFrame = 0;
|
|
812
|
+
});
|
|
813
|
+
});
|
|
814
|
+
};
|
|
815
|
+
/**
|
|
816
|
+
* Installs the shared listeners on the first subscriber and removes them when the last one leaves.
|
|
817
|
+
*
|
|
818
|
+
* @returns {() => void} Unsubscribes this caller.
|
|
819
|
+
*/
|
|
820
|
+
const subscribeToKeyboardFocus = () => {
|
|
821
|
+
if (subscribers === 0) {
|
|
822
|
+
window.addEventListener("keydown", markKeyboardFocus, true);
|
|
823
|
+
window.addEventListener("pointerdown", clearKeyboardFocus, true);
|
|
824
|
+
}
|
|
825
|
+
subscribers += 1;
|
|
826
|
+
return () => {
|
|
827
|
+
subscribers -= 1;
|
|
828
|
+
if (subscribers === 0) {
|
|
829
|
+
window.removeEventListener("keydown", markKeyboardFocus, true);
|
|
830
|
+
window.removeEventListener("pointerdown", clearKeyboardFocus, true);
|
|
831
|
+
clearKeyboardFocus();
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
};
|
|
835
|
+
/**
|
|
836
|
+
* Whether the most recent input was a key press that should count as keyboard focus.
|
|
837
|
+
*
|
|
838
|
+
* @returns {boolean} True until the key's focus change has been handled, including one scheduled for the
|
|
839
|
+
* next frame, or a pointer press or Escape clears it.
|
|
840
|
+
*/
|
|
841
|
+
const isKeyboardFocus = () => keyboardFocus;
|
|
842
|
+
|
|
843
|
+
const DEFAULT_ACTIVATION = { click: true, hover: false, keyboardHandlers: true, focus: false };
|
|
768
844
|
const DEFAULT_DISMISSAL = {
|
|
769
845
|
enabled: true,
|
|
770
846
|
outsidePress: true,
|
|
@@ -837,7 +913,7 @@ const getNestedVerticalAlignmentAxis = ({ rects }) => {
|
|
|
837
913
|
* @param {PopoverProps} options The options for the popover
|
|
838
914
|
* @returns {UsePopoverType} The data for the popover
|
|
839
915
|
*/
|
|
840
|
-
const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = DEFAULT_ACTIVATION, dismissal = DEFAULT_DISMISSAL, sizing = DEFAULT_SIZING, onOpenStateChange, role = "dialog", id, className, "data-testid": dataTestId, }) => {
|
|
916
|
+
const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = DEFAULT_ACTIVATION, dismissal = DEFAULT_DISMISSAL, sizing = DEFAULT_SIZING, onOpenStateChange, role = "dialog", roleEnabled = true, id, className, "data-testid": dataTestId, }) => {
|
|
841
917
|
const [uncontrolledIsOpen, setUncontrolledIsOpen] = useState(initialOpen);
|
|
842
918
|
const [labelId, setLabelId] = useState();
|
|
843
919
|
const [descriptionId, setDescriptionId] = useState();
|
|
@@ -948,6 +1024,9 @@ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen
|
|
|
948
1024
|
placement,
|
|
949
1025
|
open: isOpen,
|
|
950
1026
|
onOpenChange: (open, _event, reason) => {
|
|
1027
|
+
if (open && reason === "focus" && !isKeyboardFocus()) {
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
951
1030
|
setUncontrolledIsOpen(open);
|
|
952
1031
|
onOpenStateChange?.(open);
|
|
953
1032
|
// Reset to `undefined` on close (regardless of *how* it closed) rather than keeping the close
|
|
@@ -978,8 +1057,15 @@ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen
|
|
|
978
1057
|
}, [isOpen, popoverData.update]);
|
|
979
1058
|
const popoverContext = popoverData.context;
|
|
980
1059
|
const resolvedActivation = typeof activation === "function" ? activation(DEFAULT_ACTIVATION) : activation;
|
|
1060
|
+
const focusEnabled = resolvedActivation.focus === true;
|
|
1061
|
+
useEffect(() => {
|
|
1062
|
+
if (!focusEnabled) {
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
return subscribeToKeyboardFocus();
|
|
1066
|
+
}, [focusEnabled]);
|
|
981
1067
|
const resolvedDismissal = typeof dismissal === "function" ? dismissal(DEFAULT_DISMISSAL) : dismissal;
|
|
982
|
-
const { outsidePress: configuredOutsidePress, ...restDismissal } = resolvedDismissal;
|
|
1068
|
+
const { outsidePress: configuredOutsidePress, bubbles: configuredBubbles, ...restDismissal } = resolvedDismissal;
|
|
983
1069
|
const clickInteraction = useClick(popoverContext, {
|
|
984
1070
|
enabled: resolvedActivation.click,
|
|
985
1071
|
keyboardHandlers: resolvedActivation.keyboardHandlers,
|
|
@@ -1011,10 +1097,21 @@ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen
|
|
|
1011
1097
|
}
|
|
1012
1098
|
return true;
|
|
1013
1099
|
},
|
|
1014
|
-
// Nested in a MenuTree: Escape closes one level at a time
|
|
1015
|
-
//
|
|
1016
|
-
//
|
|
1017
|
-
|
|
1100
|
+
// Nested in a MenuTree: Escape closes one level at a time unless the caller opts out.
|
|
1101
|
+
// Tooltips do: a hint must not swallow the Escape that dismisses the menu. Outside-press
|
|
1102
|
+
// bubbles only when the press is genuinely outside the tree; sibling-row presses are filtered
|
|
1103
|
+
// above so they don't collapse the root menu.
|
|
1104
|
+
// Other popovers keep Floating UI's default (Escape does not bubble) unless the caller asks
|
|
1105
|
+
// otherwise.
|
|
1106
|
+
bubbles: isInsideMenuTree
|
|
1107
|
+
? {
|
|
1108
|
+
escapeKey: false,
|
|
1109
|
+
outsidePress: true,
|
|
1110
|
+
...(typeof configuredBubbles === "boolean"
|
|
1111
|
+
? { escapeKey: configuredBubbles, outsidePress: configuredBubbles }
|
|
1112
|
+
: configuredBubbles),
|
|
1113
|
+
}
|
|
1114
|
+
: configuredBubbles,
|
|
1018
1115
|
});
|
|
1019
1116
|
const hoverOptions = typeof resolvedActivation.hover === "object" ? resolvedActivation.hover : undefined;
|
|
1020
1117
|
const hoverEnabled = hoverOptions ? (hoverOptions.active ?? true) : resolvedActivation.hover === true;
|
|
@@ -1090,6 +1187,12 @@ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen
|
|
|
1090
1187
|
popoverContext,
|
|
1091
1188
|
referenceRef: popoverData.refs.reference,
|
|
1092
1189
|
});
|
|
1190
|
+
const focusInteraction = useFocus(popoverContext, {
|
|
1191
|
+
// `visibleOnly` keeps pointer focus from opening the popover. Keyboard focus still matches
|
|
1192
|
+
// `:focus-visible`.
|
|
1193
|
+
enabled: focusEnabled,
|
|
1194
|
+
visibleOnly: true,
|
|
1195
|
+
});
|
|
1093
1196
|
const hoverInteraction = useHover$1(popoverContext, {
|
|
1094
1197
|
enabled: hoverEnabled && !openSiblingPinned && !isHoverScrollSuppressed,
|
|
1095
1198
|
delay: isHoverDelayed && !hasOpenSibling ? { open: 400 } : undefined,
|
|
@@ -1120,9 +1223,7 @@ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen
|
|
|
1120
1223
|
? safePolygon({ blockPointerEvents: isInsideMenuTree })
|
|
1121
1224
|
: undefined,
|
|
1122
1225
|
});
|
|
1123
|
-
const
|
|
1124
|
-
const focusInteraction = useFocus(popoverContext, { enabled: focusEnabled });
|
|
1125
|
-
const roleInteraction = useRole(popoverContext, { role });
|
|
1226
|
+
const roleInteraction = useRole(popoverContext, { enabled: roleEnabled, role });
|
|
1126
1227
|
// Distinguishes a genuine open -> close transition from this node simply mounting closed (the
|
|
1127
1228
|
// common case: every unrelated sibling elsewhere in the tree mounts with `isOpen === false`).
|
|
1128
1229
|
// Without this, that initial "closed" render would emit `MENU_TREE_CLOSE_EVENT` regardless, and
|
|
@@ -1380,14 +1481,14 @@ const withVisibilityCheck = (sourceRef) => ({
|
|
|
1380
1481
|
* @param {PopoverContentProps} props - The props for the PopoverContent component
|
|
1381
1482
|
* @returns {ReactElement} The popover content element
|
|
1382
1483
|
*/
|
|
1383
|
-
const PopoverContent = function PopoverContent({ className, "data-testid": dataTestId, children, portalId, initialFocus, returnFocus = true, ref: propRef, ...props }) {
|
|
1484
|
+
const PopoverContent = function PopoverContent({ className, "data-testid": dataTestId, children, portalId, initialFocus, returnFocus = true, guards = true, ref: propRef, ...props }) {
|
|
1384
1485
|
const { context: floatingContext, customProps, ...context } = usePopoverContext();
|
|
1385
1486
|
const ref = useMergeRefs$1([context.refs.setFloating, propRef]);
|
|
1386
1487
|
// Only a ref-based `returnFocus` has a concrete target to check -- the `boolean` case defers to
|
|
1387
1488
|
// Floating UI's own app-wide "previously focused element" tracking, which isn't exposed here to
|
|
1388
1489
|
// check against.
|
|
1389
1490
|
const resolvedReturnFocus = typeof returnFocus === "boolean" ? returnFocus : withVisibilityCheck(returnFocus);
|
|
1390
|
-
return (jsx(FloatingPortal, { id: portalId, root: document.body, children: context.isOpen === true ? (jsx(FloatingFocusManager, { closeOnFocusOut: context.closeOnFocusOut, context: floatingContext, guards:
|
|
1491
|
+
return (jsx(FloatingPortal, { id: portalId, preserveTabOrder: guards, root: document.body, children: context.isOpen === true ? (jsx(FloatingFocusManager, { closeOnFocusOut: context.closeOnFocusOut, context: floatingContext, guards: guards, initialFocus: initialFocus, modal: context.isModal, order: ["reference", "content"], returnFocus: resolvedReturnFocus, children: jsx("div", { "aria-describedby": context.descriptionId, "aria-labelledby": context.labelId, className: cvaPopoverContainer({ className: className ?? customProps.className }), "data-testid": dataTestId ?? customProps["data-testid"] ?? "popover-content", ref: ref, style: {
|
|
1391
1492
|
position: context.strategy,
|
|
1392
1493
|
top: context.y,
|
|
1393
1494
|
left: context.x,
|
|
@@ -2101,12 +2202,21 @@ const Text = ({ children, type = "p", size = "medium", align = "left", weight =
|
|
|
2101
2202
|
};
|
|
2102
2203
|
Text.displayName = "Text";
|
|
2103
2204
|
|
|
2205
|
+
const cvaTooltipTrigger = cva({
|
|
2206
|
+
base: ["group", "inline-flex", "cursor-pointer", "border-0", "bg-transparent", "p-0"],
|
|
2207
|
+
});
|
|
2104
2208
|
const cvaTooltipIcon = cva({
|
|
2105
|
-
base: [
|
|
2209
|
+
base: [
|
|
2210
|
+
"text-neutral-300",
|
|
2211
|
+
"transition",
|
|
2212
|
+
"hover:cursor-pointer",
|
|
2213
|
+
"hover:text-neutral-400",
|
|
2214
|
+
"group-focus-visible:text-neutral-400",
|
|
2215
|
+
],
|
|
2106
2216
|
variants: {
|
|
2107
2217
|
color: {
|
|
2108
|
-
light: "hover:text-white",
|
|
2109
|
-
dark: "hover:text-neutral-400",
|
|
2218
|
+
light: ["hover:text-white", "group-focus-visible:text-white"],
|
|
2219
|
+
dark: ["hover:text-neutral-400", "group-focus-visible:text-neutral-400"],
|
|
2110
2220
|
},
|
|
2111
2221
|
defaultVariants: {
|
|
2112
2222
|
color: "dark",
|
|
@@ -2164,7 +2274,7 @@ const FloatingArrowContainer = ({ arrowRef, mode = "dark", }) => {
|
|
|
2164
2274
|
return (jsx(FloatingArrow, { className: cvaTooltipPopoverTail({ mode, placement: floatingContext.placement }), context: floatingContext, ref: arrowRef }));
|
|
2165
2275
|
};
|
|
2166
2276
|
/**
|
|
2167
|
-
* Tooltips display additional information upon hover
|
|
2277
|
+
* Tooltips display additional information upon hover, and on keyboard focus with `openOnFocus`. The information included should be contextual, helpful, and nonessential while providing that extra ability to communicate and give clarity to a user.
|
|
2168
2278
|
*
|
|
2169
2279
|
* Tooltips should be used sparingly and contain succinct, supplementary information, and they should contain read-only text. **❗️Do not include interactive elements in tooltips ** (no links, buttons, etc). Interactive elements in tooltips are inaccessible since tooltips do not receive focus.
|
|
2170
2280
|
*
|
|
@@ -2221,8 +2331,11 @@ const Tooltip = ({ children, "data-testid": dataTestId, disabled = false, label,
|
|
|
2221
2331
|
setIsOpen(false);
|
|
2222
2332
|
}
|
|
2223
2333
|
// A label that repeats the trigger's accessible name would be read twice as its description.
|
|
2224
|
-
|
|
2225
|
-
|
|
2334
|
+
// The default icon trigger is always named with the label.
|
|
2335
|
+
const labelIsTriggerName = children === undefined ||
|
|
2336
|
+
(isValidElement(children) &&
|
|
2337
|
+
(children.props.ariaLabel === label || children.props["aria-label"] === label));
|
|
2338
|
+
const { className: iconClassName, ...restIconProps } = iconProps ?? {};
|
|
2226
2339
|
const arrowRef = useRef(null);
|
|
2227
2340
|
const { refs, floatingStyles, context } = useFloating({
|
|
2228
2341
|
placement: placement === "auto" ? "bottom" : placement,
|
|
@@ -2245,7 +2358,8 @@ const Tooltip = ({ children, "data-testid": dataTestId, disabled = false, label,
|
|
|
2245
2358
|
const wrappedChildren = useMemo(() => {
|
|
2246
2359
|
return jsx(Slot, { children: children });
|
|
2247
2360
|
}, [children]);
|
|
2248
|
-
|
|
2361
|
+
// Escape closes the hint and continues upward, so a menu or the assistant panel still hears it.
|
|
2362
|
+
return (jsxs(Popover, { activation: { click: false, hover: { delayed, interactable }, focus: openOnFocus && !tooltipSuppressed }, className: cvaTooltipPopover(), "data-testid": dataTestId, dismissal: { bubbles: { escapeKey: true } }, id: id, isOpen: tooltipSuppressed ? false : isOpen, onOpenStateChange: setIsOpen, placement: placement === "auto" ? "bottom" : placement, role: openOnFocus ? (labelIsTriggerName ? "label" : "tooltip") : undefined, roleEnabled: !tooltipSuppressed, children: [jsx(PopoverTrigger, { ...rest, "data-testid": dataTestId ? `${dataTestId}-trigger` : null, ref: mergedRef, style: style, children: children !== undefined ? (wrappedChildren) : openOnFocus ? (jsxs("button", { "aria-label": typeof label === "string" ? label : undefined, className: cvaTooltipTrigger(), disabled: disabled, type: "button", children: [typeof label === "string" ? null : jsx("span", { className: "sr-only", children: label }), jsx(Icon, { "data-testid": dataTestId ? `${dataTestId}-icon` : undefined, name: "QuestionMarkCircle", size: "small", ...restIconProps, ariaHidden: true, className: cvaTooltipIcon({ className: iconClassName, color: mode }) })] })) : (jsx(Icon, { className: cvaTooltipIcon({ color: mode }), "data-testid": dataTestId ? `${dataTestId}-icon` : undefined, name: "QuestionMarkCircle", size: "small", ...iconProps })) }), tooltipSuppressed || !isMounted ? null : (jsx("div", { ref: refs.setFloating, style: floatingStyles, children: jsx(PopoverContent, { guards: !openOnFocus, initialFocus: -1, returnFocus: false, children: jsxs("div", { "aria-label": typeof label === "string" ? label : undefined, className: cvaTooltipPopoverContent({ color: mode }), "data-testid": dataTestId ? `${dataTestId}-content` : undefined, onClick: e => e.stopPropagation(), onDoubleClick: e => e.stopPropagation(), onMouseDown: e => e.stopPropagation(), onPointerDown: e => e.stopPropagation(), children: [jsx(Text, { "data-testid": dataTestId ? `${dataTestId}-text` : undefined, inverted: mode === "dark", size: "small", type: typeof label === "string" ? "p" : "span", children: label }), placement !== "auto" && jsx(FloatingArrowContainer, { arrowRef: arrowRef, mode: mode })] }) }) }))] }));
|
|
2249
2363
|
};
|
|
2250
2364
|
|
|
2251
2365
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-router-components",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.20",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@trackunit/css-class-variance-utilities": "^2.6.62",
|
|
11
11
|
"@trackunit/i18n-library-translation": "^2.14.59",
|
|
12
|
-
"@trackunit/react-components": "^8.0.
|
|
13
|
-
"@trackunit/react-drawer": "^3.0.
|
|
12
|
+
"@trackunit/react-components": "^8.0.8",
|
|
13
|
+
"@trackunit/react-drawer": "^3.0.20",
|
|
14
14
|
"@trackunit/shared-utils": "^1.22.62",
|
|
15
15
|
"dequal": "^2.0.3",
|
|
16
16
|
"zod": "^3.25.76"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../../../../libs/react/components/migrations/entry.ts"],"names":[],"mappings":"","sourcesContent":["// Migration entry point for @nx/js:tsc build target.\n// Migrations are registered in ../migrations.json and resolved by NX at runtime.\nexport {};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-utils.js","sourceRoot":"","sources":["../../../../../../libs/react/components/migrations/utils/jsx-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAqE;AACrE,+CAAiC;AAEjC,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,CAAU,CAAC;AACjD,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAEvD,MAAM,SAAS,GAAG,CAAC,QAAgB,EAAW,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;AACpG,MAAM,QAAQ,GAAG,CAAC,QAAgB,EAAW,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;AAElG,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAW,EAAE,CACvD,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;AAE9E,MAAM,WAAW,GAAG,CAAC,QAAgB,EAAW,EAAE,CAChD,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC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AAO,CAAC;IACvC,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IACnC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,IAAI,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;AACtF,CAAC,CAAC;AARW,QAAA,6BAA6B,iCAQxC","sourcesContent":["import { logger, type Tree, visitNotIgnoredFiles } from \"@nx/devkit\";\nimport * as ts from \"typescript\";\n\nconst TSX_EXTENSIONS = [\".tsx\", \".jsx\"] as const;\nconst TS_EXTENSIONS = [\".ts\", \".tsx\", \".jsx\"] as const;\n\nconst isTsxFile = (filePath: string): boolean => TSX_EXTENSIONS.some(ext => filePath.endsWith(ext));\nconst isTsFile = (filePath: string): boolean => TS_EXTENSIONS.some(ext => filePath.endsWith(ext));\n\nconst isUnderNodeModules = (filePath: string): boolean =>\n filePath.includes(\"/node_modules/\") || filePath.startsWith(\"node_modules/\");\n\nconst isUnderDist = (filePath: string): boolean =>\n filePath.includes(\"/dist/\") || filePath.startsWith(\"dist/\") || filePath.includes(\"/.nx/\");\n\n/**\n * Whether a path is a `.ts`/`.tsx`/`.jsx` file that migrations look at: not under `node_modules`, `dist` or `.nx`.\n * Use it when a codemod walks the tree itself instead of going through {@link visitTsFiles}.\n */\nexport const isWorkspaceSourceFile = (filePath: string): boolean =>\n isTsFile(filePath) && !isUnderNodeModules(filePath) && !isUnderDist(filePath);\n\n/**\n * Visits every `.tsx`/`.jsx` file under the workspace root and invokes the\n * callback with the file path and its current contents. Files that don't\n * include the marker substring are skipped, which makes large workspaces\n * cheap to scan.\n */\nexport const visitTsxFiles = (\n tree: Tree,\n marker: string,\n callback: (filePath: string, content: string) => string | null | undefined\n): number => {\n let touched = 0;\n visitNotIgnoredFiles(tree, \"/\", filePath => {\n if (!isTsxFile(filePath)) return;\n if (isUnderNodeModules(filePath) || isUnderDist(filePath)) return;\n const content = tree.read(filePath, \"utf-8\");\n if (content === null) return;\n if (!content.includes(marker)) return;\n const updated = callback(filePath, content);\n if (updated !== null && updated !== undefined && updated !== content) {\n tree.write(filePath, updated);\n touched += 1;\n }\n });\n return touched;\n};\n\n/**\n * Same as {@link visitTsxFiles} but also includes plain `.ts` files. Use this\n * when the codemod also rewrites non-JSX files such as helpers or hooks.\n */\nexport const visitTsFiles = (\n tree: Tree,\n marker: string,\n callback: (filePath: string, content: string) => string | null | undefined\n): number => {\n let touched = 0;\n visitNotIgnoredFiles(tree, \"/\", filePath => {\n if (!isTsFile(filePath)) return;\n if (isUnderNodeModules(filePath) || isUnderDist(filePath)) return;\n const content = tree.read(filePath, \"utf-8\");\n if (content === null) return;\n if (!content.includes(marker)) return;\n const updated = callback(filePath, content);\n if (updated !== null && updated !== undefined && updated !== content) {\n tree.write(filePath, updated);\n touched += 1;\n }\n });\n return touched;\n};\n\n/**\n * Mapping of imported component aliases to their original names for a given\n * package. For `import { IconButton as Btn } from \"@trackunit/react-components\"`\n * this returns `{ Btn: \"IconButton\" }`.\n *\n * Returns `null` when the file imports nothing from the package, which lets\n * callers short-circuit before parsing JSX.\n */\nexport const getImportedAliases = (sourceFile: ts.SourceFile, packageName: string): Record<string, string> | null => {\n const result: Record<string, string> = {};\n let found = false;\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) continue;\n const moduleSpecifier = stmt.moduleSpecifier;\n if (!ts.isStringLiteral(moduleSpecifier)) continue;\n if (moduleSpecifier.text !== packageName) continue;\n\n const namedBindings = stmt.importClause?.namedBindings;\n if (namedBindings === undefined || !ts.isNamedImports(namedBindings)) continue;\n\n for (const element of namedBindings.elements) {\n const localName = element.name.text;\n const importedName = element.propertyName?.text ?? localName;\n result[localName] = importedName;\n found = true;\n }\n }\n\n return found ? result : null;\n};\n\n/**\n * Returns the local alias used in this file for `originalName` when imported\n * from `packageName`, or `null` if the component is not imported.\n */\nexport const getLocalAliasFor = (\n sourceFile: ts.SourceFile,\n packageName: string,\n originalName: string\n): string | null => {\n const aliases = getImportedAliases(sourceFile, packageName);\n if (aliases === null) return null;\n for (const [local, original] of Object.entries(aliases)) {\n if (original === originalName) return local;\n }\n return null;\n};\n\nexport type JsxElementMatch = {\n /** The opening JSX element (the one carrying the attributes). */\n openingElement: ts.JsxOpeningElement | ts.JsxSelfClosingElement;\n /** The full element including children, or the self-closing element. */\n element: ts.JsxElement | ts.JsxSelfClosingElement;\n};\n\n/**\n * Finds every JSX element whose tag name resolves to one of `tagNames`\n * (typically the local aliases returned by {@link getImportedAliases}).\n *\n * The result intentionally includes both opening and full elements so callers\n * can manipulate attributes (via `openingElement`) or wrap/replace the whole\n * element (via `element`).\n */\nexport const findJsxElements = (\n sourceFile: ts.SourceFile,\n tagNames: ReadonlyArray<string>\n): ReadonlyArray<JsxElementMatch> => {\n const matches: Array<JsxElementMatch> = [];\n const tagSet = new Set(tagNames);\n\n const visit = (node: ts.Node): void => {\n if (ts.isJsxSelfClosingElement(node)) {\n if (ts.isIdentifier(node.tagName) && tagSet.has(node.tagName.text)) {\n matches.push({ openingElement: node, element: node });\n }\n } else if (ts.isJsxElement(node)) {\n const opening = node.openingElement;\n if (ts.isIdentifier(opening.tagName) && tagSet.has(opening.tagName.text)) {\n matches.push({ openingElement: opening, element: node });\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n return matches;\n};\n\n/**\n * Looks up a named JSX attribute on the opening element. Returns `null` when\n * the attribute is missing or part of a spread attribute (which we cannot\n * statically inspect).\n */\nexport const findJsxAttribute = (\n openingElement: ts.JsxOpeningElement | ts.JsxSelfClosingElement,\n attributeName: string\n): ts.JsxAttribute | null => {\n for (const attr of openingElement.attributes.properties) {\n if (!ts.isJsxAttribute(attr)) continue;\n if (!ts.isIdentifier(attr.name)) continue;\n if (attr.name.text === attributeName) return attr;\n }\n return null;\n};\n\n/**\n * `true` when the element forwards a spread expression such as `{...rest}`,\n * which means we can't be sure which attributes are actually set.\n */\nexport const hasSpreadAttribute = (openingElement: ts.JsxOpeningElement | ts.JsxSelfClosingElement): boolean => {\n return openingElement.attributes.properties.some(prop => ts.isJsxSpreadAttribute(prop));\n};\n\n/**\n * Parses the file as TSX so JSX is recognised. We do not need a full program\n * here; tsquery's `ast` helper produces a script-kind source file which loses\n * JSX context, so we go through `createSourceFile` directly.\n */\nexport const parseTsx = (content: string, fileName = \"file.tsx\"): ts.SourceFile =>\n ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);\n\n/**\n * Helper for codemods to log a one-line summary at the end of a run. Migration\n * runners aggregate logs per migration, so this keeps output focused.\n */\nexport const logSummary = (migrationName: string, touched: number, manualReviewNeeded?: number): void => {\n if (touched === 0) {\n logger.info(` ${migrationName}: no files changed`);\n return;\n }\n const reviewSuffix =\n manualReviewNeeded !== undefined && manualReviewNeeded > 0\n ? ` (${manualReviewNeeded} location(s) need manual review)`\n : \"\";\n logger.info(` ${migrationName}: updated ${touched} file(s)${reviewSuffix}`);\n};\n\n/**\n * Inserts an attribute string immediately after the tag name (so the new\n * attribute appears first). Returns the resulting source content.\n *\n * The added attribute is rendered verbatim, so callers are responsible for\n * including the leading space (e.g. ` title=\"Close\"`).\n */\nexport const insertAttributeIntoOpeningTag = (\n content: string,\n openingElement: ts.JsxOpeningElement | ts.JsxSelfClosingElement,\n attributeText: string\n): string => {\n const tagName = openingElement.tagName;\n const insertPos = tagName.getEnd();\n return `${content.slice(0, insertPos)} ${attributeText}${content.slice(insertPos)}`;\n};\n"]}
|