@caratlogic/design-system 0.1.43 → 0.1.45

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 (34) hide show
  1. package/dist/components/molecules/FloatingSlideOver/FloatingSlideOver.d.ts +11 -0
  2. package/dist/components/molecules/FloatingSlideOver/FloatingSlideOver.d.ts.map +1 -0
  3. package/dist/components/molecules/FloatingSlideOver/FloatingSlideOver.hooks.d.ts +23 -0
  4. package/dist/components/molecules/FloatingSlideOver/FloatingSlideOver.hooks.d.ts.map +1 -0
  5. package/dist/components/molecules/FloatingSlideOver/FloatingSlideOver.types.d.ts +19 -0
  6. package/dist/components/molecules/FloatingSlideOver/FloatingSlideOver.types.d.ts.map +1 -0
  7. package/dist/components/molecules/FloatingSlideOver/FloatingSlideOver.utils.d.ts +9 -0
  8. package/dist/components/molecules/FloatingSlideOver/FloatingSlideOver.utils.d.ts.map +1 -0
  9. package/dist/components/molecules/FloatingSlideOver/index.d.ts +3 -0
  10. package/dist/components/molecules/FloatingSlideOver/index.d.ts.map +1 -0
  11. package/dist/components/molecules/Sidebar/Sidebar.parts.d.ts.map +1 -1
  12. package/dist/components/molecules/SlideOut/SlideOut.parts.d.ts +2 -0
  13. package/dist/components/molecules/SlideOut/SlideOut.parts.d.ts.map +1 -1
  14. package/dist/components/organisms/Filters/FilterSurface/FilterSurface.accessibility.d.ts +4 -0
  15. package/dist/components/organisms/Filters/FilterSurface/FilterSurface.accessibility.d.ts.map +1 -1
  16. package/dist/components/organisms/Filters/FilterSurface/FilterSurface.d.ts +9 -4
  17. package/dist/components/organisms/Filters/FilterSurface/FilterSurface.d.ts.map +1 -1
  18. package/dist/components/organisms/Filters/FilterSurface/FilterSurface.hooks.d.ts +33 -2
  19. package/dist/components/organisms/Filters/FilterSurface/FilterSurface.hooks.d.ts.map +1 -1
  20. package/dist/components/organisms/Filters/FilterSurface/FilterSurface.parts.d.ts +12 -1
  21. package/dist/components/organisms/Filters/FilterSurface/FilterSurface.parts.d.ts.map +1 -1
  22. package/dist/components/organisms/Filters/FilterSurface/FilterSurface.types.d.ts +95 -2
  23. package/dist/components/organisms/Filters/FilterSurface/FilterSurface.types.d.ts.map +1 -1
  24. package/dist/components/organisms/Filters/FilterSurface/FilterSurface.utils.d.ts +32 -0
  25. package/dist/components/organisms/Filters/FilterSurface/FilterSurface.utils.d.ts.map +1 -1
  26. package/dist/components/organisms/Filters/FilterSurface/index.d.ts +2 -2
  27. package/dist/components/organisms/Filters/FilterSurface/index.d.ts.map +1 -1
  28. package/dist/index.cjs.js +1026 -49
  29. package/dist/index.cjs.js.map +1 -1
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.esm.js +1025 -50
  33. package/dist/index.esm.js.map +1 -1
  34. package/package.json +1 -1
package/dist/index.cjs.js CHANGED
@@ -22680,6 +22680,20 @@ function distanceBetween(p1, p2) {
22680
22680
  return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
22681
22681
  }
22682
22682
 
22683
+ function getRelativeTransformOrigin(event, rect) {
22684
+ const eventCoordinates = getEventCoordinates(event);
22685
+
22686
+ if (!eventCoordinates) {
22687
+ return '0 0';
22688
+ }
22689
+
22690
+ const transformOrigin = {
22691
+ x: (eventCoordinates.x - rect.left) / rect.width * 100,
22692
+ y: (eventCoordinates.y - rect.top) / rect.height * 100
22693
+ };
22694
+ return transformOrigin.x + "% " + transformOrigin.y + "%";
22695
+ }
22696
+
22683
22697
  /**
22684
22698
  * Sort collisions from smallest to greatest value
22685
22699
  */
@@ -25964,6 +25978,396 @@ function useDroppable(_ref) {
25964
25978
  };
25965
25979
  }
25966
25980
 
25981
+ function AnimationManager(_ref) {
25982
+ let {
25983
+ animation,
25984
+ children
25985
+ } = _ref;
25986
+ const [clonedChildren, setClonedChildren] = React.useState(null);
25987
+ const [element, setElement] = React.useState(null);
25988
+ const previousChildren = usePrevious(children);
25989
+
25990
+ if (!children && !clonedChildren && previousChildren) {
25991
+ setClonedChildren(previousChildren);
25992
+ }
25993
+
25994
+ useIsomorphicLayoutEffect$1(() => {
25995
+ if (!element) {
25996
+ return;
25997
+ }
25998
+
25999
+ const key = clonedChildren == null ? void 0 : clonedChildren.key;
26000
+ const id = clonedChildren == null ? void 0 : clonedChildren.props.id;
26001
+
26002
+ if (key == null || id == null) {
26003
+ setClonedChildren(null);
26004
+ return;
26005
+ }
26006
+
26007
+ Promise.resolve(animation(id, element)).then(() => {
26008
+ setClonedChildren(null);
26009
+ });
26010
+ }, [animation, clonedChildren, element]);
26011
+ return React.createElement(React.Fragment, null, children, clonedChildren ? React.cloneElement(clonedChildren, {
26012
+ ref: setElement
26013
+ }) : null);
26014
+ }
26015
+
26016
+ const defaultTransform = {
26017
+ x: 0,
26018
+ y: 0,
26019
+ scaleX: 1,
26020
+ scaleY: 1
26021
+ };
26022
+ function NullifiedContextProvider(_ref) {
26023
+ let {
26024
+ children
26025
+ } = _ref;
26026
+ return React.createElement(InternalContext.Provider, {
26027
+ value: defaultInternalContext
26028
+ }, React.createElement(ActiveDraggableContext.Provider, {
26029
+ value: defaultTransform
26030
+ }, children));
26031
+ }
26032
+
26033
+ const baseStyles = {
26034
+ position: 'fixed',
26035
+ touchAction: 'none'
26036
+ };
26037
+
26038
+ const defaultTransition$1 = activatorEvent => {
26039
+ const isKeyboardActivator = isKeyboardEvent(activatorEvent);
26040
+ return isKeyboardActivator ? 'transform 250ms ease' : undefined;
26041
+ };
26042
+
26043
+ const PositionedOverlay = /*#__PURE__*/React.forwardRef((_ref, ref) => {
26044
+ let {
26045
+ as,
26046
+ activatorEvent,
26047
+ adjustScale,
26048
+ children,
26049
+ className,
26050
+ rect,
26051
+ style,
26052
+ transform,
26053
+ transition = defaultTransition$1
26054
+ } = _ref;
26055
+
26056
+ if (!rect) {
26057
+ return null;
26058
+ }
26059
+
26060
+ const scaleAdjustedTransform = adjustScale ? transform : { ...transform,
26061
+ scaleX: 1,
26062
+ scaleY: 1
26063
+ };
26064
+ const styles = { ...baseStyles,
26065
+ width: rect.width,
26066
+ height: rect.height,
26067
+ top: rect.top,
26068
+ left: rect.left,
26069
+ transform: CSS$1.Transform.toString(scaleAdjustedTransform),
26070
+ transformOrigin: adjustScale && activatorEvent ? getRelativeTransformOrigin(activatorEvent, rect) : undefined,
26071
+ transition: typeof transition === 'function' ? transition(activatorEvent) : transition,
26072
+ ...style
26073
+ };
26074
+ return React.createElement(as, {
26075
+ className,
26076
+ style: styles,
26077
+ ref
26078
+ }, children);
26079
+ });
26080
+
26081
+ const defaultDropAnimationSideEffects = options => _ref => {
26082
+ let {
26083
+ active,
26084
+ dragOverlay
26085
+ } = _ref;
26086
+ const originalStyles = {};
26087
+ const {
26088
+ styles,
26089
+ className
26090
+ } = options;
26091
+
26092
+ if (styles != null && styles.active) {
26093
+ for (const [key, value] of Object.entries(styles.active)) {
26094
+ if (value === undefined) {
26095
+ continue;
26096
+ }
26097
+
26098
+ originalStyles[key] = active.node.style.getPropertyValue(key);
26099
+ active.node.style.setProperty(key, value);
26100
+ }
26101
+ }
26102
+
26103
+ if (styles != null && styles.dragOverlay) {
26104
+ for (const [key, value] of Object.entries(styles.dragOverlay)) {
26105
+ if (value === undefined) {
26106
+ continue;
26107
+ }
26108
+
26109
+ dragOverlay.node.style.setProperty(key, value);
26110
+ }
26111
+ }
26112
+
26113
+ if (className != null && className.active) {
26114
+ active.node.classList.add(className.active);
26115
+ }
26116
+
26117
+ if (className != null && className.dragOverlay) {
26118
+ dragOverlay.node.classList.add(className.dragOverlay);
26119
+ }
26120
+
26121
+ return function cleanup() {
26122
+ for (const [key, value] of Object.entries(originalStyles)) {
26123
+ active.node.style.setProperty(key, value);
26124
+ }
26125
+
26126
+ if (className != null && className.active) {
26127
+ active.node.classList.remove(className.active);
26128
+ }
26129
+ };
26130
+ };
26131
+
26132
+ const defaultKeyframeResolver = _ref2 => {
26133
+ let {
26134
+ transform: {
26135
+ initial,
26136
+ final
26137
+ }
26138
+ } = _ref2;
26139
+ return [{
26140
+ transform: CSS$1.Transform.toString(initial)
26141
+ }, {
26142
+ transform: CSS$1.Transform.toString(final)
26143
+ }];
26144
+ };
26145
+
26146
+ const defaultDropAnimationConfiguration = {
26147
+ duration: 250,
26148
+ easing: 'ease',
26149
+ keyframes: defaultKeyframeResolver,
26150
+ sideEffects: /*#__PURE__*/defaultDropAnimationSideEffects({
26151
+ styles: {
26152
+ active: {
26153
+ opacity: '0'
26154
+ }
26155
+ }
26156
+ })
26157
+ };
26158
+ function useDropAnimation(_ref3) {
26159
+ let {
26160
+ config,
26161
+ draggableNodes,
26162
+ droppableContainers,
26163
+ measuringConfiguration
26164
+ } = _ref3;
26165
+ return useEvent((id, node) => {
26166
+ if (config === null) {
26167
+ return;
26168
+ }
26169
+
26170
+ const activeDraggable = draggableNodes.get(id);
26171
+
26172
+ if (!activeDraggable) {
26173
+ return;
26174
+ }
26175
+
26176
+ const activeNode = activeDraggable.node.current;
26177
+
26178
+ if (!activeNode) {
26179
+ return;
26180
+ }
26181
+
26182
+ const measurableNode = getMeasurableNode(node);
26183
+
26184
+ if (!measurableNode) {
26185
+ return;
26186
+ }
26187
+
26188
+ const {
26189
+ transform
26190
+ } = getWindow$1(node).getComputedStyle(node);
26191
+ const parsedTransform = parseTransform(transform);
26192
+
26193
+ if (!parsedTransform) {
26194
+ return;
26195
+ }
26196
+
26197
+ const animation = typeof config === 'function' ? config : createDefaultDropAnimation(config);
26198
+ scrollIntoViewIfNeeded(activeNode, measuringConfiguration.draggable.measure);
26199
+ return animation({
26200
+ active: {
26201
+ id,
26202
+ data: activeDraggable.data,
26203
+ node: activeNode,
26204
+ rect: measuringConfiguration.draggable.measure(activeNode)
26205
+ },
26206
+ draggableNodes,
26207
+ dragOverlay: {
26208
+ node,
26209
+ rect: measuringConfiguration.dragOverlay.measure(measurableNode)
26210
+ },
26211
+ droppableContainers,
26212
+ measuringConfiguration,
26213
+ transform: parsedTransform
26214
+ });
26215
+ });
26216
+ }
26217
+
26218
+ function createDefaultDropAnimation(options) {
26219
+ const {
26220
+ duration,
26221
+ easing,
26222
+ sideEffects,
26223
+ keyframes
26224
+ } = { ...defaultDropAnimationConfiguration,
26225
+ ...options
26226
+ };
26227
+ return _ref4 => {
26228
+ let {
26229
+ active,
26230
+ dragOverlay,
26231
+ transform,
26232
+ ...rest
26233
+ } = _ref4;
26234
+
26235
+ if (!duration) {
26236
+ // Do not animate if animation duration is zero.
26237
+ return;
26238
+ }
26239
+
26240
+ const delta = {
26241
+ x: dragOverlay.rect.left - active.rect.left,
26242
+ y: dragOverlay.rect.top - active.rect.top
26243
+ };
26244
+ const scale = {
26245
+ scaleX: transform.scaleX !== 1 ? active.rect.width * transform.scaleX / dragOverlay.rect.width : 1,
26246
+ scaleY: transform.scaleY !== 1 ? active.rect.height * transform.scaleY / dragOverlay.rect.height : 1
26247
+ };
26248
+ const finalTransform = {
26249
+ x: transform.x - delta.x,
26250
+ y: transform.y - delta.y,
26251
+ ...scale
26252
+ };
26253
+ const animationKeyframes = keyframes({ ...rest,
26254
+ active,
26255
+ dragOverlay,
26256
+ transform: {
26257
+ initial: transform,
26258
+ final: finalTransform
26259
+ }
26260
+ });
26261
+ const [firstKeyframe] = animationKeyframes;
26262
+ const lastKeyframe = animationKeyframes[animationKeyframes.length - 1];
26263
+
26264
+ if (JSON.stringify(firstKeyframe) === JSON.stringify(lastKeyframe)) {
26265
+ // The start and end keyframes are the same, infer that there is no animation needed.
26266
+ return;
26267
+ }
26268
+
26269
+ const cleanup = sideEffects == null ? void 0 : sideEffects({
26270
+ active,
26271
+ dragOverlay,
26272
+ ...rest
26273
+ });
26274
+ const animation = dragOverlay.node.animate(animationKeyframes, {
26275
+ duration,
26276
+ easing,
26277
+ fill: 'forwards'
26278
+ });
26279
+ return new Promise(resolve => {
26280
+ animation.onfinish = () => {
26281
+ cleanup == null ? void 0 : cleanup();
26282
+ resolve();
26283
+ };
26284
+ });
26285
+ };
26286
+ }
26287
+
26288
+ let key = 0;
26289
+ function useKey(id) {
26290
+ return React.useMemo(() => {
26291
+ if (id == null) {
26292
+ return;
26293
+ }
26294
+
26295
+ key++;
26296
+ return key;
26297
+ }, [id]);
26298
+ }
26299
+
26300
+ const DragOverlay = /*#__PURE__*/React.memo(_ref => {
26301
+ let {
26302
+ adjustScale = false,
26303
+ children,
26304
+ dropAnimation: dropAnimationConfig,
26305
+ style,
26306
+ transition,
26307
+ modifiers,
26308
+ wrapperElement = 'div',
26309
+ className,
26310
+ zIndex = 999
26311
+ } = _ref;
26312
+ const {
26313
+ activatorEvent,
26314
+ active,
26315
+ activeNodeRect,
26316
+ containerNodeRect,
26317
+ draggableNodes,
26318
+ droppableContainers,
26319
+ dragOverlay,
26320
+ over,
26321
+ measuringConfiguration,
26322
+ scrollableAncestors,
26323
+ scrollableAncestorRects,
26324
+ windowRect
26325
+ } = useDndContext();
26326
+ const transform = React.useContext(ActiveDraggableContext);
26327
+ const key = useKey(active == null ? void 0 : active.id);
26328
+ const modifiedTransform = applyModifiers(modifiers, {
26329
+ activatorEvent,
26330
+ active,
26331
+ activeNodeRect,
26332
+ containerNodeRect,
26333
+ draggingNodeRect: dragOverlay.rect,
26334
+ over,
26335
+ overlayNodeRect: dragOverlay.rect,
26336
+ scrollableAncestors,
26337
+ scrollableAncestorRects,
26338
+ transform,
26339
+ windowRect
26340
+ });
26341
+ const initialRect = useInitialValue(activeNodeRect);
26342
+ const dropAnimation = useDropAnimation({
26343
+ config: dropAnimationConfig,
26344
+ draggableNodes,
26345
+ droppableContainers,
26346
+ measuringConfiguration
26347
+ }); // We need to wait for the active node to be measured before connecting the drag overlay ref
26348
+ // otherwise collisions can be computed against a mispositioned drag overlay
26349
+
26350
+ const ref = initialRect ? dragOverlay.setRef : undefined;
26351
+ return React.createElement(NullifiedContextProvider, null, React.createElement(AnimationManager, {
26352
+ animation: dropAnimation
26353
+ }, active && key ? React.createElement(PositionedOverlay, {
26354
+ key: key,
26355
+ id: active.id,
26356
+ ref: ref,
26357
+ as: wrapperElement,
26358
+ activatorEvent: activatorEvent,
26359
+ adjustScale: adjustScale,
26360
+ className: className,
26361
+ transition: transition,
26362
+ rect: initialRect,
26363
+ style: {
26364
+ zIndex,
26365
+ ...style
26366
+ },
26367
+ transform: modifiedTransform
26368
+ }, children) : null));
26369
+ });
26370
+
25967
26371
  const PERMISSIONS = {
25968
26372
  NONE: 0, // no access
25969
26373
  READ: 2, // can only read
@@ -43428,6 +43832,154 @@ function TriStateFilter({ value, onChange, ariaLabel, compact = false, }) {
43428
43832
  }) }));
43429
43833
  }
43430
43834
 
43835
+ const SlideOut = ({ open, onOpenChange, ...props }) => {
43836
+ const scheduleLockRelease = useOverlayBodyLockRelease(open);
43837
+ return (jsxRuntime.jsx(DialogPrimitive__namespace.Root, { ...props, open: open, onOpenChange: (next) => {
43838
+ onOpenChange?.(next);
43839
+ if (!next)
43840
+ scheduleLockRelease();
43841
+ } }));
43842
+ };
43843
+ const SlideOutTrigger = DialogPrimitive__namespace.Trigger;
43844
+ const SlideOutClose = DialogPrimitive__namespace.Close;
43845
+ const SlideOutPortal = DialogPrimitive__namespace.Portal;
43846
+ // Overlay
43847
+ const SLIDE_OUT_OVERLAY_CLASS_NAME = 'fixed inset-0 z-40 bg-black/50';
43848
+ const SLIDE_OUT_OVERLAY_BLUR_CLASS_NAME = 'backdrop-blur-sm';
43849
+ /** The slide-outs' backdrop, dimmed and slightly blurred; other panels over the page reuse it to match. */
43850
+ const SLIDE_OUT_BACKDROP_CLASS_NAME = cn(SLIDE_OUT_OVERLAY_CLASS_NAME, SLIDE_OUT_OVERLAY_BLUR_CLASS_NAME);
43851
+ const SlideOutOverlay = React__namespace.forwardRef(({ className, ...props }, ref) => (jsxRuntime.jsx(DialogPrimitive__namespace.Overlay, { ref: ref, className: cn(SLIDE_OUT_OVERLAY_CLASS_NAME, className), ...props })));
43852
+ SlideOutOverlay.displayName = DialogPrimitive__namespace.Overlay.displayName;
43853
+ // Positional classes per edge. `right` is the historical default and its
43854
+ // value is byte-for-byte what SlideOutContent always rendered.
43855
+ const slideOutSideClasses = {
43856
+ right: 'right-0 top-0 h-full w-[488px] max-w-full border-l slide-in-from-right',
43857
+ left: 'left-0 top-0 h-full w-[488px] max-w-full border-r slide-in-from-left',
43858
+ top: 'inset-x-0 top-0 h-1/3 w-full border-b slide-in-from-top',
43859
+ bottom: 'inset-x-0 bottom-0 h-1/3 w-full border-t slide-in-from-bottom',
43860
+ };
43861
+ // Content — slide-out panel. Defaults to a right-anchored 488px drawer;
43862
+ // pass `side` to anchor to any edge (absorbs the old sheet/drawer use cases).
43863
+ const SlideOutContent = React__namespace.forwardRef(({ className, children, overlayClassName, side = 'right', ...props }, ref) => (jsxRuntime.jsxs(SlideOutPortal, { children: [jsxRuntime.jsx(SlideOutOverlay, { className: overlayClassName ?? SLIDE_OUT_OVERLAY_BLUR_CLASS_NAME }), jsxRuntime.jsx(DialogPrimitive__namespace.Content, { ref: ref, className: cn('fixed z-50 border-border bg-card text-card-foreground shadow-xl animate-in', slideOutSideClasses[side], className), ...props, children: children })] })));
43864
+ SlideOutContent.displayName = DialogPrimitive__namespace.Content.displayName;
43865
+ // Header — owns the standard 16px padding and bottom border.
43866
+ const SlideOutHeader = ({ className, ...props }) => (jsxRuntime.jsx("div", { className: cn('flex flex-col space-y-1.5 border-b border-border px-4 py-4 text-xs', className), ...props }));
43867
+ SlideOutHeader.displayName = 'SlideOutHeader';
43868
+ // Title
43869
+ const SlideOutTitle = React__namespace.forwardRef(({ className, ...props }, ref) => (jsxRuntime.jsx(DialogPrimitive__namespace.Title, { ref: ref, className: cn('text-lg font-semibold', className), ...props })));
43870
+ SlideOutTitle.displayName = DialogPrimitive__namespace.Title.displayName;
43871
+ // Description
43872
+ const SlideOutDescription = React__namespace.forwardRef(({ className, ...props }, ref) => (jsxRuntime.jsx(DialogPrimitive__namespace.Description, { ref: ref, className: cn('text-sm text-muted-foreground', className), ...props })));
43873
+ SlideOutDescription.displayName = DialogPrimitive__namespace.Description.displayName;
43874
+
43875
+ /** The app's content area, right of the sidebar; the panel starts at its left edge. */
43876
+ const SIDEBAR_INSET_SELECTOR = '[data-slot="sidebar-inset"]';
43877
+ /** Dropdowns, menus and listboxes, portaled outside the panel; an outside click first closes them. */
43878
+ const OPEN_LAYER_SELECTOR = '[data-slot="popover-content"], [role="menu"], [role="listbox"]';
43879
+ /** How long the panel takes to slide out; it stays mounted until then. */
43880
+ const SLIDE_OUT_MS = 200;
43881
+ /** The top-level element under `<body>` that holds `node`: the app root, for a node in the page. */
43882
+ function getBodyChild(node) {
43883
+ let current = node;
43884
+ while (current && current.parentElement !== node.ownerDocument.body)
43885
+ current = current.parentElement;
43886
+ return current;
43887
+ }
43888
+
43889
+ /**
43890
+ * Backdrop handlers that call `onClose` on a click outside the panel, unless a dropdown or menu was open
43891
+ * when the press began: that click only closes the dropdown.
43892
+ */
43893
+ function useBackdropClose(onClose) {
43894
+ const layerOpenRef = React.useRef(false);
43895
+ return {
43896
+ onPointerDown: () => {
43897
+ layerOpenRef.current = !!document.querySelector(OPEN_LAYER_SELECTOR);
43898
+ },
43899
+ onClick: () => {
43900
+ if (!layerOpenRef.current)
43901
+ onClose?.();
43902
+ layerOpenRef.current = false;
43903
+ },
43904
+ };
43905
+ }
43906
+ /** Keeps the panel mounted while it slides out; `closing` is true for that time. */
43907
+ function useSlideOverPresence(open) {
43908
+ const [mounted, setMounted] = React.useState(open);
43909
+ React.useEffect(() => {
43910
+ if (open) {
43911
+ setMounted(true);
43912
+ return;
43913
+ }
43914
+ const timer = window.setTimeout(() => setMounted(false), SLIDE_OUT_MS);
43915
+ return () => window.clearTimeout(timer);
43916
+ }, [open]);
43917
+ return { mounted: mounted || open, closing: mounted && !open };
43918
+ }
43919
+ /** Where the content area right of the sidebar starts, in px from the viewport's left; 0 without a sidebar. */
43920
+ function useSidebarInsetLeft(active) {
43921
+ const [left, setLeft] = React.useState(0);
43922
+ React.useLayoutEffect(() => {
43923
+ if (!active)
43924
+ return;
43925
+ const inset = document.querySelector(SIDEBAR_INSET_SELECTOR);
43926
+ if (!inset)
43927
+ return;
43928
+ const measure = () => setLeft(Math.max(0, inset.getBoundingClientRect().left));
43929
+ measure();
43930
+ // The inset narrows or widens with the window and the sidebar.
43931
+ const observer = new ResizeObserver(measure);
43932
+ observer.observe(inset);
43933
+ window.addEventListener('resize', measure);
43934
+ return () => {
43935
+ observer.disconnect();
43936
+ window.removeEventListener('resize', measure);
43937
+ };
43938
+ }, [active]);
43939
+ return left;
43940
+ }
43941
+ /**
43942
+ * While `active`, makes the app behind the panel inert (no clicks, focus or screen reader) and moves focus
43943
+ * into `panel`; on close, focus goes back where it was. Popovers and menus portal outside the app root, so
43944
+ * they stay usable.
43945
+ */
43946
+ function useModalPanel(anchor, panel, active) {
43947
+ React.useEffect(() => {
43948
+ const root = anchor.current && getBodyChild(anchor.current);
43949
+ if (!active || !(root instanceof HTMLElement))
43950
+ return;
43951
+ const previousFocus = document.activeElement;
43952
+ const wasInert = root.inert;
43953
+ root.inert = true;
43954
+ panel.current?.focus({ preventScroll: true });
43955
+ return () => {
43956
+ root.inert = wasInert;
43957
+ if (previousFocus instanceof HTMLElement)
43958
+ previousFocus.focus({ preventScroll: true });
43959
+ };
43960
+ }, [anchor, panel, active]);
43961
+ }
43962
+
43963
+ /**
43964
+ * A large panel that slides in from the right over the page and covers everything right of the sidebar,
43965
+ * floating with a small gap on every side and rounded corners, on the slide-outs' dimmed, slightly blurred
43966
+ * backdrop. The page behind, sidebar included, can't be used until it closes. A click outside calls
43967
+ * `onClose`; the content closes it otherwise (a close button, Escape).
43968
+ */
43969
+ function FloatingSlideOver({ open, title, onClose, className, children, }) {
43970
+ const anchorRef = React.useRef(null);
43971
+ const panelRef = React.useRef(null);
43972
+ const { mounted, closing } = useSlideOverPresence(open);
43973
+ const left = useSidebarInsetLeft(mounted);
43974
+ useModalPanel(anchorRef, panelRef, mounted);
43975
+ const backdrop = useBackdropClose(onClose);
43976
+ const state = closing ? 'closed' : 'open';
43977
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("span", { ref: anchorRef, hidden: true }), mounted &&
43978
+ ReactDOM.createPortal(jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { "aria-hidden": "true", "data-state": state, className: SLIDE_OUT_BACKDROP_CLASS_NAME, onPointerDown: backdrop.onPointerDown, onClick: backdrop.onClick }), jsxRuntime.jsx("div", { ref: panelRef, role: "dialog", "aria-modal": "true", "aria-label": title, tabIndex: -1, "data-state": state,
43979
+ // The same gap from the sidebar's edge as on the other sides.
43980
+ style: { left: `calc(${left}px + 0.5rem)` }, className: cn('fixed inset-y-2 right-2 z-50 flex flex-col overflow-hidden rounded-xl border border-border bg-background shadow-xl outline-none', 'data-[state=open]:animate-in data-[state=open]:slide-in-from-right data-[state=open]:duration-300 data-[state=open]:ease-out', 'data-[state=closed]:animate-out data-[state=closed]:slide-out-to-right data-[state=closed]:duration-200 data-[state=closed]:ease-in', 'motion-reduce:animate-none', className), children: children })] }), document.body)] }));
43981
+ }
43982
+
43431
43983
  /** Read-only filter summaries of a saved search, as pills; optionally one line ending in "+N more". */
43432
43984
  function SavedSearchChipList({ chips, emptyText = 'No filters', collapsible = false, className, }) {
43433
43985
  const { listRef, expanded, toggle, visibleChips, hiddenCount } = useChipOverflow(chips, collapsible);
@@ -73075,7 +73627,7 @@ const SidebarRail = React__namespace.forwardRef(({ className, ...props }, ref) =
73075
73627
  return (jsxRuntime.jsx("button", { ref: ref, "data-sidebar": "rail", "aria-label": "Toggle Sidebar", tabIndex: -1, onClick: toggleSidebar, title: "Toggle Sidebar", className: cn('absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex', '[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize', '[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize', 'group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar', 'group-data-[side=left][data-collapsible=offcanvas]:-right-2', 'group-data-[side=right][data-collapsible=offcanvas]:-left-2', className), ...props }));
73076
73628
  });
73077
73629
  SidebarRail.displayName = 'SidebarRail';
73078
- const SidebarInset = React__namespace.forwardRef(({ className, ...props }, ref) => (jsxRuntime.jsx("main", { ref: ref, className: cn('relative flex min-h-screen flex-1 flex-col bg-background', 'peer-data-[variant=inset]:min-h-[calc(100svh-1rem)] md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow', className), ...props })));
73630
+ const SidebarInset = React__namespace.forwardRef(({ className, ...props }, ref) => (jsxRuntime.jsx("main", { ref: ref, "data-slot": "sidebar-inset", className: cn('relative flex min-h-screen flex-1 flex-col bg-background', 'peer-data-[variant=inset]:min-h-[calc(100svh-1rem)] md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow', className), ...props })));
73079
73631
  SidebarInset.displayName = 'SidebarInset';
73080
73632
  const SidebarInput = React__namespace.forwardRef(({ className, ...props }, ref) => (jsxRuntime.jsx("input", { ref: ref, "data-sidebar": "input", className: cn('h-8 w-full bg-background text-sm shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring', className), ...props })));
73081
73633
  SidebarInput.displayName = 'SidebarInput';
@@ -73213,42 +73765,6 @@ const AppSidebar = ({ brand, navGroups = [], footer, className, }) => {
73213
73765
  return (jsxRuntime.jsxs(Sidebar, { collapsible: "icon", className: className, children: [brand && (jsxRuntime.jsx(SidebarHeader, { children: jsxRuntime.jsx(BrandHeader$1, { brand: brand }) })), jsxRuntime.jsx(SidebarContent, { children: navGroups.map((group) => (jsxRuntime.jsx(NavGroupSection, { group: group }, group.label ?? 'nav-group'))) }), footer && jsxRuntime.jsx(SidebarFooter, { children: footer }), jsxRuntime.jsx(SidebarRail, {})] }));
73214
73766
  };
73215
73767
 
73216
- const SlideOut = ({ open, onOpenChange, ...props }) => {
73217
- const scheduleLockRelease = useOverlayBodyLockRelease(open);
73218
- return (jsxRuntime.jsx(DialogPrimitive__namespace.Root, { ...props, open: open, onOpenChange: (next) => {
73219
- onOpenChange?.(next);
73220
- if (!next)
73221
- scheduleLockRelease();
73222
- } }));
73223
- };
73224
- const SlideOutTrigger = DialogPrimitive__namespace.Trigger;
73225
- const SlideOutClose = DialogPrimitive__namespace.Close;
73226
- const SlideOutPortal = DialogPrimitive__namespace.Portal;
73227
- // Overlay
73228
- const SlideOutOverlay = React__namespace.forwardRef(({ className, ...props }, ref) => (jsxRuntime.jsx(DialogPrimitive__namespace.Overlay, { ref: ref, className: cn('fixed inset-0 z-40 bg-black/50', className), ...props })));
73229
- SlideOutOverlay.displayName = DialogPrimitive__namespace.Overlay.displayName;
73230
- // Positional classes per edge. `right` is the historical default and its
73231
- // value is byte-for-byte what SlideOutContent always rendered.
73232
- const slideOutSideClasses = {
73233
- right: 'right-0 top-0 h-full w-[488px] max-w-full border-l slide-in-from-right',
73234
- left: 'left-0 top-0 h-full w-[488px] max-w-full border-r slide-in-from-left',
73235
- top: 'inset-x-0 top-0 h-1/3 w-full border-b slide-in-from-top',
73236
- bottom: 'inset-x-0 bottom-0 h-1/3 w-full border-t slide-in-from-bottom',
73237
- };
73238
- // Content — slide-out panel. Defaults to a right-anchored 488px drawer;
73239
- // pass `side` to anchor to any edge (absorbs the old sheet/drawer use cases).
73240
- const SlideOutContent = React__namespace.forwardRef(({ className, children, overlayClassName, side = 'right', ...props }, ref) => (jsxRuntime.jsxs(SlideOutPortal, { children: [jsxRuntime.jsx(SlideOutOverlay, { className: overlayClassName ?? 'backdrop-blur-sm' }), jsxRuntime.jsx(DialogPrimitive__namespace.Content, { ref: ref, className: cn('fixed z-50 border-border bg-card text-card-foreground shadow-xl animate-in', slideOutSideClasses[side], className), ...props, children: children })] })));
73241
- SlideOutContent.displayName = DialogPrimitive__namespace.Content.displayName;
73242
- // Header — owns the standard 16px padding and bottom border.
73243
- const SlideOutHeader = ({ className, ...props }) => (jsxRuntime.jsx("div", { className: cn('flex flex-col space-y-1.5 border-b border-border px-4 py-4 text-xs', className), ...props }));
73244
- SlideOutHeader.displayName = 'SlideOutHeader';
73245
- // Title
73246
- const SlideOutTitle = React__namespace.forwardRef(({ className, ...props }, ref) => (jsxRuntime.jsx(DialogPrimitive__namespace.Title, { ref: ref, className: cn('text-lg font-semibold', className), ...props })));
73247
- SlideOutTitle.displayName = DialogPrimitive__namespace.Title.displayName;
73248
- // Description
73249
- const SlideOutDescription = React__namespace.forwardRef(({ className, ...props }, ref) => (jsxRuntime.jsx(DialogPrimitive__namespace.Description, { ref: ref, className: cn('text-sm text-muted-foreground', className), ...props })));
73250
- SlideOutDescription.displayName = DialogPrimitive__namespace.Description.displayName;
73251
-
73252
73768
  const SpecList = ({ rows, zebra = true, className, }) => {
73253
73769
  const visible = rows.filter((r) => !r.hidden);
73254
73770
  if (visible.length === 0)
@@ -77482,11 +77998,30 @@ function FilterField(props) {
77482
77998
 
77483
77999
  /** Leaves without applying; the draft is discarded. */
77484
78000
  const BACK_LABEL = 'Back without applying';
78001
+ const CLOSE_LABEL = 'Close without applying';
77485
78002
  const LOADING_LABEL = 'Loading filters';
77486
78003
  const ERROR_TITLE = "Couldn't load filters";
77487
78004
  const DEFAULT_ERROR_MESSAGE = 'Something went wrong while loading the filters. Check your connection and try again.';
77488
78005
  const RETRY_LABEL = 'Try again';
78006
+ const CARD_REORDER_HINT = 'Drag to rearrange';
78007
+ const getCardGripLabel = (card) => `Move ${card}`;
78008
+ const EMPTY_GROUP_LABEL = 'Drag filter cards here';
77489
78009
 
78010
+ /** Popovers, dialogs, menus and listboxes opened on top of the surface. */
78011
+ const NESTED_LAYER_SELECTOR = '[data-slot="popover-content"], [role="dialog"], [role="menu"], [role="listbox"]';
78012
+ /**
78013
+ * Closes the open popover or menu (not one that holds `from`) as Escape would. Radix closes a popover on
78014
+ * the click after an outside press, which a card drag never makes, so a grab would leave it open.
78015
+ */
78016
+ function dismissOpenLayer(from) {
78017
+ const layer = Array.from(from.ownerDocument.querySelectorAll(NESTED_LAYER_SELECTOR)).find((node) => !node.contains(from));
78018
+ // Sent from inside the layer, so the surface's own Escape handler leaves it alone.
78019
+ layer?.dispatchEvent(new KeyboardEvent('keydown', {
78020
+ key: 'Escape',
78021
+ bubbles: true,
78022
+ cancelable: true,
78023
+ }));
78024
+ }
77490
78025
  /** Placeholder cards while the filters load; roughly the first rows of a card grid. */
77491
78026
  const SKELETON_CARD_COUNT = 8;
77492
78027
  const SKELETON_GRID_CLASS_NAME = 'grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4';
@@ -77496,8 +78031,82 @@ const MASONRY_ROW_PX = 4;
77496
78031
  const getMasonrySpan = (height) => height > 0 ? Math.ceil(height / MASONRY_ROW_PX) : 0;
77497
78032
  /** Dense 4px rows; the vertical gap comes from each item's bottom padding. */
77498
78033
  const MASONRY_GRID_CLASS_NAME = 'grid-flow-row-dense auto-rows-[4px] gap-x-3';
78034
+ // Card drag: the DOM marks each card, group grid and "More filters" toggle, so a pointer hit is found by attribute.
78035
+ const CARD_ID_ATTR = 'data-filter-card-id';
78036
+ const GROUP_ID_ATTR = 'data-filter-group-id';
78037
+ const MORE_TOGGLE_ATTR = 'data-filter-more-toggle';
78038
+ const CARD_BODY_ATTR = 'data-filter-card-body';
78039
+ /** The group holding `id`, if any. */
78040
+ function findCardGroup(layout, id) {
78041
+ return Object.keys(layout).find((group) => layout[group].includes(id));
78042
+ }
78043
+ /** `layout` with `id` taken out of its group and put into `target.group`, beside `target.key` or at the end. */
78044
+ function moveCard(layout, id, target) {
78045
+ const rest = (layout[target.group] ?? []).filter((key) => key !== id);
78046
+ let at = rest.length;
78047
+ if (target.key !== undefined) {
78048
+ const index = rest.indexOf(target.key);
78049
+ if (index === -1)
78050
+ return layout;
78051
+ at = index + (target.side === 'after' ? 1 : 0);
78052
+ }
78053
+ const next = Object.fromEntries(Object.entries(layout).map(([group, ids]) => [
78054
+ group,
78055
+ ids.filter((key) => key !== id),
78056
+ ]));
78057
+ next[target.group] = [...rest.slice(0, at), id, ...rest.slice(at)];
78058
+ return next;
78059
+ }
78060
+ function isSameLayout(a, b) {
78061
+ const groups = Object.keys(a);
78062
+ return (groups.length === Object.keys(b).length &&
78063
+ groups.every((group) => b[group]?.length === a[group].length &&
78064
+ a[group].every((id, index) => b[group][index] === id)));
78065
+ }
78066
+ /**
78067
+ * Where a card lands when dropped on `hit` at height `y`. In its own group it takes the hit card's place
78068
+ * (after it when moving forward), the way a sortable list swaps; from another group the pointer's half
78069
+ * of the hit card decides.
78070
+ */
78071
+ function getCardDropTarget(layout, activeId, hit, y) {
78072
+ const ids = layout[hit.group] ?? [];
78073
+ const from = ids.indexOf(activeId);
78074
+ const side = from === -1
78075
+ ? y > hit.rect.top + hit.rect.height / 2
78076
+ ? 'after'
78077
+ : 'before'
78078
+ : from < ids.indexOf(hit.id)
78079
+ ? 'after'
78080
+ : 'before';
78081
+ return { group: hit.group, key: hit.id, side };
78082
+ }
78083
+ /** The card, group or "More filters" toggle at a viewport point. */
78084
+ function getDropHit(x, y) {
78085
+ const element = document.elementFromPoint(x, y);
78086
+ if (!element)
78087
+ return null;
78088
+ const group = element.closest(`[${GROUP_ID_ATTR}]`);
78089
+ const groupId = group?.getAttribute(GROUP_ID_ATTR);
78090
+ const card = element.closest(`[${CARD_ID_ATTR}]`);
78091
+ const cardId = card?.getAttribute(CARD_ID_ATTR);
78092
+ if (card && cardId && groupId)
78093
+ return {
78094
+ kind: 'card',
78095
+ id: cardId,
78096
+ group: groupId,
78097
+ rect: card.getBoundingClientRect(),
78098
+ };
78099
+ if (groupId)
78100
+ return { kind: 'group', group: groupId };
78101
+ const toggle = element.closest(`[${MORE_TOGGLE_ATTR}]`);
78102
+ return toggle ? { kind: 'more', toggle } : null;
78103
+ }
78104
+ /** The dropped card's copy settles into its slot at the speed the other cards slide. */
78105
+ const CARD_DROP_ANIMATION = {
78106
+ duration: 200,
78107
+ easing: 'ease',
78108
+ };
77499
78109
 
77500
- const NESTED_LAYER_SELECTOR = '[data-slot="popover-content"], [role="dialog"], [role="menu"], [role="listbox"]';
77501
78110
  function useCloseOnEscape(onClose) {
77502
78111
  React.useEffect(() => {
77503
78112
  const handleKeyDown = (event) => {
@@ -77515,12 +78124,27 @@ function useCloseOnEscape(onClose) {
77515
78124
  }
77516
78125
  function useFilterSurfaceMore(defaultExpanded = false) {
77517
78126
  const [expanded, setExpanded] = React.useState(defaultExpanded);
77518
- return { expanded, toggle: () => setExpanded((current) => !current) };
78127
+ const [toggleNode, setToggleNode] = React.useState(null);
78128
+ const registerExpander = React.useContext(FilterSurfaceSortableContext)?.registerExpander;
78129
+ // Inside a sortable surface, a dragged card resting on the toggle opens the section.
78130
+ React.useEffect(() => {
78131
+ if (!toggleNode || !registerExpander)
78132
+ return;
78133
+ return registerExpander(toggleNode, () => setExpanded(true));
78134
+ }, [toggleNode, registerExpander]);
78135
+ return {
78136
+ expanded,
78137
+ toggle: () => setExpanded((current) => !current),
78138
+ toggleRef: setToggleNode,
78139
+ };
77519
78140
  }
77520
- /** Measures a masonry card and keeps its row span in step with its height (content opening, wrapping…). */
77521
- function useMasonrySpan() {
78141
+ /**
78142
+ * Measures a masonry card and keeps its row span in step with its height (content opening, wrapping…).
78143
+ * `initialSpan` lets a remounted card take its known height on the first render.
78144
+ */
78145
+ function useMasonrySpan(initialSpan = 0) {
77522
78146
  const [node, setNode] = React.useState(null);
77523
- const [span, setSpan] = React.useState(0);
78147
+ const [span, setSpan] = React.useState(initialSpan);
77524
78148
  React.useEffect(() => {
77525
78149
  if (!node)
77526
78150
  return;
@@ -77535,6 +78159,308 @@ function useMasonrySpan() {
77535
78159
  }, [node]);
77536
78160
  return { ref: React.useCallback((next) => setNode(next), []), span };
77537
78161
  }
78162
+ const FilterSurfaceSortableContext = React.createContext(null);
78163
+ /** The surrounding `FilterSurfaceSortable`, or null outside one. */
78164
+ function useFilterSurfaceSortable() {
78165
+ return React.useContext(FilterSurfaceSortableContext);
78166
+ }
78167
+ /** A sortable card's drag wiring, masonry span and registration for the slide animation. */
78168
+ function useSortableFilterCard(id) {
78169
+ const sortable = React.useContext(FilterSurfaceSortableContext);
78170
+ if (!sortable)
78171
+ throw new Error('SortableFilterCard must be inside FilterSurfaceSortable');
78172
+ const { spans, registerCard, unregisterCard } = sortable;
78173
+ const { setNodeRef, setActivatorNodeRef, listeners } = useDraggable({ id });
78174
+ const { ref: spanRef, span } = useMasonrySpan(spans.get(id));
78175
+ const nodeRef = React.useRef(null);
78176
+ React.useEffect(() => {
78177
+ if (span > 0)
78178
+ spans.set(id, span);
78179
+ }, [spans, id, span]);
78180
+ const cardRef = React.useCallback((node) => {
78181
+ setNodeRef(node);
78182
+ if (node)
78183
+ registerCard(id, node);
78184
+ else
78185
+ unregisterCard(id, nodeRef.current);
78186
+ nodeRef.current = node;
78187
+ }, [id, setNodeRef, registerCard, unregisterCard]);
78188
+ return {
78189
+ ref: { card: cardRef, span: spanRef },
78190
+ span,
78191
+ isActive: sortable.activeId === id,
78192
+ dragging: sortable.activeId !== null,
78193
+ label: sortable.cardLabel(id),
78194
+ setActivatorNodeRef,
78195
+ listeners,
78196
+ };
78197
+ }
78198
+ const FLIP_MS = 200;
78199
+ const FLIP_TRANSITION = `transform ${FLIP_MS}ms ease`;
78200
+ // After a move the cards repack and a different card can end up under a still pointer; the pointer must
78201
+ // travel this far before the next move, so cards never rock back and forth on their own.
78202
+ const MOVE_TRAVEL_PX = 32;
78203
+ // Long enough that sweeping past "More filters" doesn't open it.
78204
+ const EXPAND_DELAY_MS = 400;
78205
+ function prefersReducedMotion() {
78206
+ return window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
78207
+ }
78208
+ /** Slides each card from where it was (`from`) to where the new layout put it. */
78209
+ function playFlip(nodes, from) {
78210
+ nodes.forEach((node, id) => {
78211
+ const before = from.get(id);
78212
+ if (!before)
78213
+ return;
78214
+ const after = node.getBoundingClientRect();
78215
+ const dx = before.left - after.left;
78216
+ const dy = before.top - after.top;
78217
+ if (!dx && !dy)
78218
+ return;
78219
+ node.style.transition = 'none';
78220
+ node.style.transform = `translate(${dx}px, ${dy}px)`;
78221
+ // Commit the offset before transitioning it away.
78222
+ void node.offsetWidth;
78223
+ node.style.transition = FLIP_TRANSITION;
78224
+ node.style.transform = '';
78225
+ node.addEventListener('transitionend', () => {
78226
+ node.style.transition = '';
78227
+ }, { once: true });
78228
+ });
78229
+ }
78230
+ /** A copy of the card for the drag overlay, without ids that would clash with the original. */
78231
+ function cloneCardBody(card) {
78232
+ const body = card?.querySelector(`[${CARD_BODY_ATTR}]`);
78233
+ if (!body)
78234
+ return null;
78235
+ const clone = body.cloneNode(true);
78236
+ if (!(clone instanceof HTMLElement))
78237
+ return null;
78238
+ clone.removeAttribute(CARD_BODY_ATTR);
78239
+ clone.querySelectorAll('[id]').forEach((el) => el.removeAttribute('id'));
78240
+ return clone;
78241
+ }
78242
+ /**
78243
+ * Card drag-to-reorder across a surface's groups. The live order is a draft: cards reflow as the pointer
78244
+ * crosses them and slide (FLIP) from their old spots, and the draft is handed over on drop. The pointer is
78245
+ * hit-tested against what is on screen, so masonry cards of any height land where they look.
78246
+ */
78247
+ function useFilterCardReorder({ layout, onLayoutChange, }) {
78248
+ const [draft, setDraft] = React.useState(null);
78249
+ const [activeId, setActiveId] = React.useState(null);
78250
+ const [overlay, setOverlay] = React.useState(null);
78251
+ const shown = draft ?? layout;
78252
+ const shownRef = React.useRef(shown);
78253
+ const activeRef = React.useRef(null);
78254
+ const nodesRef = React.useRef(new Map());
78255
+ const spansRef = React.useRef(new Map());
78256
+ const flipFromRef = React.useRef(null);
78257
+ const expandersRef = React.useRef(new Map());
78258
+ React.useLayoutEffect(() => {
78259
+ shownRef.current = shown;
78260
+ }, [shown]);
78261
+ // A new layout from the consumer (usually the one just dropped) replaces the draft.
78262
+ React.useEffect(() => {
78263
+ if (activeRef.current === null)
78264
+ setDraft(null);
78265
+ }, [layout]);
78266
+ const applyDraft = React.useCallback((next) => {
78267
+ if (!prefersReducedMotion()) {
78268
+ const rects = new Map();
78269
+ nodesRef.current.forEach((node, id) => rects.set(id, node.getBoundingClientRect()));
78270
+ flipFromRef.current = rects;
78271
+ }
78272
+ setDraft(next);
78273
+ }, []);
78274
+ React.useLayoutEffect(() => {
78275
+ const from = flipFromRef.current;
78276
+ if (!from)
78277
+ return;
78278
+ flipFromRef.current = null;
78279
+ playFlip(nodesRef.current, from);
78280
+ }, [draft]);
78281
+ useCardDragTracking(activeId, shownRef, applyDraft, expandersRef.current);
78282
+ const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 4 } }));
78283
+ const registerCard = React.useCallback((id, node) => {
78284
+ nodesRef.current.set(id, node);
78285
+ }, []);
78286
+ // A card moving between groups remounts; only forget it if the new node hasn't registered already.
78287
+ const unregisterCard = React.useCallback((id, node) => {
78288
+ if (nodesRef.current.get(id) === node)
78289
+ nodesRef.current.delete(id);
78290
+ }, []);
78291
+ const registerExpander = React.useCallback((toggle, expand) => {
78292
+ const expanders = expandersRef.current;
78293
+ expanders.set(toggle, expand);
78294
+ return () => {
78295
+ expanders.delete(toggle);
78296
+ };
78297
+ }, []);
78298
+ const onDragStart = React.useCallback((event) => {
78299
+ const id = String(event.active.id);
78300
+ activeRef.current = id;
78301
+ setOverlay(cloneCardBody(nodesRef.current.get(id)));
78302
+ setActiveId(id);
78303
+ }, []);
78304
+ const finish = React.useCallback((commit) => {
78305
+ activeRef.current = null;
78306
+ setActiveId(null);
78307
+ setOverlay(null);
78308
+ const next = shownRef.current;
78309
+ if (commit && !isSameLayout(next, layout)) {
78310
+ // The draft stays on screen until the consumer passes the saved layout back.
78311
+ onLayoutChange(next);
78312
+ return;
78313
+ }
78314
+ applyDraft(null);
78315
+ }, [layout, onLayoutChange, applyDraft]);
78316
+ const onDragEnd = React.useCallback(() => finish(true), [finish]);
78317
+ const onDragCancel = React.useCallback(() => finish(false), [finish]);
78318
+ return {
78319
+ layout: shown,
78320
+ activeId,
78321
+ overlay,
78322
+ sensors,
78323
+ spans: spansRef.current,
78324
+ registerCard,
78325
+ unregisterCard,
78326
+ registerExpander,
78327
+ onDragStart,
78328
+ onDragEnd,
78329
+ onDragCancel,
78330
+ };
78331
+ }
78332
+ /**
78333
+ * While a card drags: follows the pointer, moves the card in the draft as it crosses other cards or an
78334
+ * empty group, and opens a collapsed "More filters" the pointer rests on.
78335
+ */
78336
+ function useCardDragTracking(activeId, shownRef, applyDraft, expanders) {
78337
+ React.useEffect(() => {
78338
+ if (activeId === null)
78339
+ return;
78340
+ let point = null;
78341
+ let frame = null;
78342
+ // Cards are mid-slide until then; hit-testing them would chase a moving target.
78343
+ let settledAt = 0;
78344
+ let settleTimer;
78345
+ // The card last moved beside: staying over it does nothing, or two cards of different heights would swap forever.
78346
+ let lastOver = null;
78347
+ // Where the pointer was at the last move.
78348
+ let movedAt = null;
78349
+ const hasTravelled = (x, y) => !movedAt || Math.hypot(x - movedAt.x, y - movedAt.y) >= MOVE_TRAVEL_PX;
78350
+ let expandTimer;
78351
+ let expandToggle = null;
78352
+ const stopExpand = () => {
78353
+ window.clearTimeout(expandTimer);
78354
+ expandToggle = null;
78355
+ };
78356
+ const handleHit = (hit, x, y) => {
78357
+ if (hit?.kind !== 'more')
78358
+ stopExpand();
78359
+ if (!hit)
78360
+ return;
78361
+ const layout = shownRef.current;
78362
+ if (hit.kind === 'more') {
78363
+ if (hit.toggle === expandToggle)
78364
+ return;
78365
+ stopExpand();
78366
+ const expand = expanders.get(hit.toggle);
78367
+ if (!expand || hit.toggle.getAttribute('aria-expanded') !== 'false')
78368
+ return;
78369
+ expandToggle = hit.toggle;
78370
+ // Not a click: the drag swallows clicks until the drop.
78371
+ expandTimer = window.setTimeout(expand, EXPAND_DELAY_MS);
78372
+ return;
78373
+ }
78374
+ if (!hasTravelled(x, y))
78375
+ return;
78376
+ let next;
78377
+ if (hit.kind === 'group') {
78378
+ // Only an empty group takes a drop here; between cards of a full one the pointer is in a gap.
78379
+ if ((layout[hit.group] ?? []).some((id) => id !== activeId))
78380
+ return;
78381
+ if (findCardGroup(layout, activeId) === hit.group)
78382
+ return;
78383
+ next = moveCard(layout, activeId, { group: hit.group });
78384
+ }
78385
+ else {
78386
+ if (hit.id === activeId) {
78387
+ lastOver = null;
78388
+ return;
78389
+ }
78390
+ if (hit.id === lastOver)
78391
+ return;
78392
+ lastOver = hit.id;
78393
+ next = moveCard(layout, activeId, getCardDropTarget(layout, activeId, hit, y));
78394
+ }
78395
+ if (isSameLayout(next, layout))
78396
+ return;
78397
+ settledAt = performance.now() + FLIP_MS;
78398
+ movedAt = { x, y };
78399
+ applyDraft(next);
78400
+ };
78401
+ const check = () => {
78402
+ frame = null;
78403
+ if (!point)
78404
+ return;
78405
+ const wait = settledAt - performance.now();
78406
+ if (wait > 0) {
78407
+ window.clearTimeout(settleTimer);
78408
+ settleTimer = window.setTimeout(schedule, wait);
78409
+ return;
78410
+ }
78411
+ handleHit(getDropHit(point.x, point.y), point.x, point.y);
78412
+ };
78413
+ const schedule = () => {
78414
+ if (frame === null)
78415
+ frame = requestAnimationFrame(check);
78416
+ };
78417
+ const onPointerMove = (event) => {
78418
+ point = { x: event.clientX, y: event.clientY };
78419
+ schedule();
78420
+ };
78421
+ // Escape cancels the drag; marked handled so the surface doesn't also close.
78422
+ const onKeyDown = (event) => {
78423
+ if (event.key === 'Escape')
78424
+ event.preventDefault();
78425
+ };
78426
+ window.addEventListener('pointermove', onPointerMove);
78427
+ // Auto-scroll moves the cards under a still pointer.
78428
+ window.addEventListener('scroll', schedule, true);
78429
+ window.addEventListener('keydown', onKeyDown, true);
78430
+ return () => {
78431
+ window.removeEventListener('pointermove', onPointerMove);
78432
+ window.removeEventListener('scroll', schedule, true);
78433
+ window.removeEventListener('keydown', onKeyDown, true);
78434
+ if (frame !== null)
78435
+ cancelAnimationFrame(frame);
78436
+ window.clearTimeout(settleTimer);
78437
+ stopExpand();
78438
+ };
78439
+ }, [activeId, shownRef, applyDraft, expanders]);
78440
+ }
78441
+ /** The context the sortable groups and cards read. */
78442
+ function useSortableContextValue(reorder, renderCard, cardLabel) {
78443
+ const { layout, activeId, spans, registerCard, unregisterCard, registerExpander, } = reorder;
78444
+ return React.useMemo(() => ({
78445
+ layout,
78446
+ activeId,
78447
+ spans,
78448
+ renderCard,
78449
+ cardLabel: cardLabel ?? ((id) => id),
78450
+ registerCard,
78451
+ unregisterCard,
78452
+ registerExpander,
78453
+ }), [
78454
+ layout,
78455
+ activeId,
78456
+ spans,
78457
+ renderCard,
78458
+ cardLabel,
78459
+ registerCard,
78460
+ unregisterCard,
78461
+ registerExpander,
78462
+ ]);
78463
+ }
77538
78464
 
77539
78465
  const DEFAULT_SKELETON_CARDS = Array.from({ length: SKELETON_CARD_COUNT }, (_, index) => `card-${index}`);
77540
78466
  /** Loading placeholder: the page's own skeleton, or generic list cards. */
@@ -77550,23 +78476,72 @@ function MasonryItem({ children }) {
77550
78476
  const { ref, span } = useMasonrySpan();
77551
78477
  return (jsxRuntime.jsx("div", { style: span > 0 ? { gridRowEnd: `span ${span}` } : undefined, children: jsxRuntime.jsx("div", { ref: ref, className: "pb-3", children: children }) }));
77552
78478
  }
78479
+ /**
78480
+ * A grab tab on the middle of the card's top edge, always visible so the cards read as movable, and clear
78481
+ * of the header's title and actions. It lights up with its card on hover. The only place a card drag starts.
78482
+ */
78483
+ function CardReorderGrip({ label, dragging, setActivatorNodeRef, listeners, }) {
78484
+ return (jsxRuntime.jsx(TooltipProvider, { delayDuration: 500, children: jsxRuntime.jsxs(Tooltip, { open: dragging ? false : undefined, children: [jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: jsxRuntime.jsx("button", { ref: setActivatorNodeRef, type: "button",
78485
+ // Mouse and touch only, like column reorder.
78486
+ tabIndex: -1, "aria-label": getCardGripLabel(label), className: cn(
78487
+ // The ::before pads the tab's hit area beyond what it shows.
78488
+ 'absolute left-1/2 top-0 z-10 flex h-4 w-10 -translate-x-1/2 -translate-y-1/2 cursor-grab touch-none select-none items-center justify-center rounded-full border border-border bg-card text-foreground/50 shadow-sm transition-colors before:absolute before:-inset-2 before:content-[""] active:cursor-grabbing', dragging
78489
+ ? 'pointer-events-none'
78490
+ : 'group-hover/card:border-primary/50 group-hover/card:text-primary group-hover/card:hover:border-primary group-hover/card:hover:bg-primary group-hover/card:hover:text-primary-foreground'), onClick: (event) => event.stopPropagation(), ...listeners,
78491
+ // A grab closes any open dropdown first, so it doesn't stay open over the drag.
78492
+ onPointerDown: (event) => {
78493
+ dismissOpenLayer(event.currentTarget);
78494
+ listeners?.onPointerDown?.(event);
78495
+ }, children: jsxRuntime.jsx(GripHorizontal, { "aria-hidden": "true", className: "size-3.5", strokeWidth: 2.5 }) }) }), jsxRuntime.jsx(TooltipContent, { side: "top", children: CARD_REORDER_HINT })] }) }));
78496
+ }
78497
+ /** A card in a sortable group: draggable from its grip, and a dashed slot where it will land while it drags. */
78498
+ function SortableFilterCard({ id, masonry, children, }) {
78499
+ const { ref, span, isActive, dragging, label, setActivatorNodeRef, listeners, } = useSortableFilterCard(id);
78500
+ return (jsxRuntime.jsx("div", { ref: ref.card, "data-filter-card-id": id, className: "group/card", style: masonry && span > 0 ? { gridRowEnd: `span ${span}` } : undefined, children: jsxRuntime.jsx("div", { ref: masonry ? ref.span : undefined, className: cn(masonry && 'pb-3'), children: jsxRuntime.jsxs("div", { className: cn('relative rounded-xl transition-shadow', !dragging &&
78501
+ 'group-hover/card:ring-2 group-hover/card:ring-primary/20'), children: [jsxRuntime.jsx("div", { "data-filter-card-body": "", className: cn(isActive && 'invisible'), children: children }), isActive ? (jsxRuntime.jsx("div", { className: "absolute inset-0 rounded-xl border-2 border-dashed border-primary/40 bg-primary/5" })) : (jsxRuntime.jsx(CardReorderGrip, { label: label, dragging: dragging, setActivatorNodeRef: setActivatorNodeRef, listeners: listeners }))] }) }) }));
78502
+ }
78503
+ /** Where a group with no cards takes a drop. */
78504
+ function EmptyGroupDropZone({ groupId, }) {
78505
+ return (jsxRuntime.jsx("div", { "data-filter-group-id": groupId, className: "flex min-h-24 items-center justify-center rounded-xl border-2 border-dashed border-border text-sm text-muted-foreground", children: EMPTY_GROUP_LABEL }));
78506
+ }
78507
+ /** The copy of the dragged card under the pointer. */
78508
+ function FilterCardOverlay({ node, }) {
78509
+ return (jsxRuntime.jsxs("div", { "aria-hidden": "true", className: "relative cursor-grabbing rounded-xl shadow-lg ring-2 ring-primary/20", children: [jsxRuntime.jsx("div", { ref: (element) => {
78510
+ element?.replaceChildren(node);
78511
+ } }), jsxRuntime.jsx("span", { className: "absolute left-1/2 top-0 flex h-4 w-10 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full border border-primary bg-primary text-primary-foreground shadow-sm", children: jsxRuntime.jsx(GripHorizontal, { "aria-hidden": "true", className: "size-3.5", strokeWidth: 2.5 }) })] }));
78512
+ }
77553
78513
 
77554
78514
  /** Full-page filter screen (e.g. an advanced search): one sticky header with every action, then the scrolling card grid. */
77555
- function FilterSurface({ title, headerActions, primaryActions, chips, onClose, status = 'ready', errorMessage, onRetry, skeleton, children, }) {
78515
+ function FilterSurface({ title, headerActions, primaryActions, chips, onClose, closeButton = 'back', status = 'ready', errorMessage, onRetry, skeleton, children, }) {
77556
78516
  useCloseOnEscape(onClose);
77557
78517
  const ready = status === 'ready';
77558
78518
  const actions = ready ? primaryActions : undefined;
77559
- return (jsxRuntime.jsxs("div", { role: "region", "aria-label": title, className: "flex h-full min-h-0 flex-col bg-background", children: [jsxRuntime.jsxs("header", { className: "sticky top-0 z-20 flex shrink-0 flex-wrap items-center gap-x-3 gap-y-2 bg-background px-3 py-2.5", children: [jsxRuntime.jsx(IconButton, { appearance: "ghost", size: "sm", "aria-label": BACK_LABEL, title: BACK_LABEL, onClick: onClose, children: jsxRuntime.jsx(ArrowLeft, {}) }), jsxRuntime.jsx("h1", { className: "sr-only", children: title }), jsxRuntime.jsx("div", { className: "min-w-0 flex-1", children: ready && chips }), jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [headerActions, actions] })] }), jsxRuntime.jsx("div", { className: "min-h-0 flex-1 overflow-y-auto px-3 pb-3", children: status === 'loading' ? (jsxRuntime.jsx(FilterSurfaceSkeleton, { children: skeleton })) : status === 'error' ? (jsxRuntime.jsx(FilterSurfaceError, { message: errorMessage ?? DEFAULT_ERROR_MESSAGE, onRetry: onRetry })) : (jsxRuntime.jsx("div", { className: "flex flex-col gap-3", children: children })) })] }));
78519
+ return (jsxRuntime.jsxs("div", { role: "region", "aria-label": title, className: "flex h-full min-h-0 flex-col bg-background", children: [jsxRuntime.jsxs("header", { className: "sticky top-0 z-20 flex shrink-0 flex-wrap items-center gap-x-3 gap-y-2 bg-background px-3 py-2.5", children: [closeButton === 'back' && (jsxRuntime.jsx(IconButton, { appearance: "ghost", size: "sm", "aria-label": BACK_LABEL, title: BACK_LABEL, onClick: onClose, children: jsxRuntime.jsx(ArrowLeft, {}) })), jsxRuntime.jsx("h1", { className: "sr-only", children: title }), jsxRuntime.jsx("div", { className: "min-w-0 flex-1", children: ready && chips }), jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [headerActions, actions, closeButton === 'close' && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("span", { "aria-hidden": "true", className: "mx-1 h-6 w-px bg-border" }), jsxRuntime.jsx(IconButton, { appearance: "ghost", size: "sm", "aria-label": CLOSE_LABEL, title: CLOSE_LABEL, onClick: onClose, children: jsxRuntime.jsx(X$2, {}) })] }))] })] }), jsxRuntime.jsx("div", { className: "min-h-0 flex-1 overflow-y-auto px-3 pb-3", children: status === 'loading' ? (jsxRuntime.jsx(FilterSurfaceSkeleton, { children: skeleton })) : status === 'error' ? (jsxRuntime.jsx(FilterSurfaceError, { message: errorMessage ?? DEFAULT_ERROR_MESSAGE, onRetry: onRetry })) : (jsxRuntime.jsx("div", { className: "flex flex-col gap-3", children: children })) })] }));
78520
+ }
78521
+ /**
78522
+ * Lets the user drag the cards of its `FilterSurfaceGroup`s (those with a `sortableId`) into any order and
78523
+ * between groups, from a grip on each card. A collapsed `FilterSurfaceMore` opens when a card rests on it.
78524
+ */
78525
+ function FilterSurfaceSortable({ layout, onLayoutChange, renderCard, cardLabel, children, }) {
78526
+ const reorder = useFilterCardReorder({ layout, onLayoutChange });
78527
+ const context = useSortableContextValue(reorder, renderCard, cardLabel);
78528
+ return (jsxRuntime.jsxs(DndContext, { sensors: reorder.sensors, onDragStart: reorder.onDragStart, onDragEnd: reorder.onDragEnd, onDragCancel: reorder.onDragCancel, children: [jsxRuntime.jsx(FilterSurfaceSortableContext.Provider, { value: context, children: children }), jsxRuntime.jsx(DragOverlay, { className: "pointer-events-none", dropAnimation: CARD_DROP_ANIMATION, children: reorder.overlay && jsxRuntime.jsx(FilterCardOverlay, { node: reorder.overlay }) })] }));
77560
78529
  }
77561
- function FilterSurfaceGroup({ title, masonry = false, className, children, }) {
77562
- return (jsxRuntime.jsxs("section", { className: "flex flex-col gap-3", children: [title && (jsxRuntime.jsx("h2", { className: "text-xs font-semibold uppercase tracking-wide text-label", children: title })), jsxRuntime.jsx("div", { className: cn('grid grid-cols-1 items-start lg:grid-cols-6', masonry ? MASONRY_GRID_CLASS_NAME : 'gap-3', className), children: masonry
78530
+ function FilterSurfaceGroup({ title, masonry = false, sortableId, className, children, }) {
78531
+ const sortable = useFilterSurfaceSortable();
78532
+ const ids = sortable && sortableId ? (sortable.layout[sortableId] ?? []) : null;
78533
+ // Cards keep their own height (no stretching to the row's tallest), so short cards carry no empty space.
78534
+ const gridClassName = cn('grid grid-cols-1 items-start lg:grid-cols-6', masonry ? MASONRY_GRID_CLASS_NAME : 'gap-3', className);
78535
+ return (jsxRuntime.jsxs("section", { className: "flex flex-col gap-3", children: [title && (jsxRuntime.jsx("h2", { className: "text-xs font-semibold uppercase tracking-wide text-label", children: title })), sortable && sortableId && ids ? (ids.length === 0 ? (jsxRuntime.jsx(EmptyGroupDropZone, { groupId: sortableId })) : (
78536
+ // Top room for the first row's grab tabs, which sit on the cards' top edge.
78537
+ jsxRuntime.jsx("div", { className: cn(gridClassName, 'pt-2'), "data-filter-group-id": sortableId, children: ids.map((id) => (jsxRuntime.jsx(SortableFilterCard, { id: id, masonry: masonry, children: sortable.renderCard(id) }, id))) }))) : (jsxRuntime.jsx("div", { className: gridClassName, children: masonry
77563
78538
  ? React.Children.map(children, (child) => child ? jsxRuntime.jsx(MasonryItem, { children: child }) : null)
77564
- : children })] }));
78539
+ : children }))] }));
77565
78540
  }
77566
78541
  /** Collapsed "More filters" divider that reveals extra cards. */
77567
78542
  function FilterSurfaceMore({ label, defaultExpanded, children, }) {
77568
- const { expanded, toggle } = useFilterSurfaceMore(defaultExpanded);
77569
- return (jsxRuntime.jsxs("section", { className: "flex flex-col gap-3", children: [jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [jsxRuntime.jsx("span", { className: "h-px flex-1 bg-border" }), jsxRuntime.jsxs("button", { type: "button", "aria-expanded": expanded, onClick: toggle, className: "inline-flex cursor-pointer items-center gap-1.5 rounded-full border border-border bg-card px-3.5 py-1.5 text-xs font-medium text-primary outline-none hover:bg-muted/50 focus-visible:ring-2 focus-visible:ring-primary/30", children: [label, jsxRuntime.jsx(ChevronDown, { "aria-hidden": "true", className: cn('size-3.5 transition-transform', expanded && 'rotate-180') })] }), jsxRuntime.jsx("span", { className: "h-px flex-1 bg-border" })] }), expanded && children] }));
78543
+ const { expanded, toggle, toggleRef } = useFilterSurfaceMore(defaultExpanded);
78544
+ return (jsxRuntime.jsxs("section", { className: "flex flex-col gap-3", children: [jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [jsxRuntime.jsx("span", { className: "h-px flex-1 bg-border" }), jsxRuntime.jsxs("button", { ref: toggleRef, type: "button", "aria-expanded": expanded, onClick: toggle, "data-filter-more-toggle": "", className: "inline-flex cursor-pointer items-center gap-1.5 rounded-full border border-border bg-card px-3.5 py-1.5 text-xs font-medium text-primary outline-none hover:bg-muted/50 focus-visible:ring-2 focus-visible:ring-primary/30", children: [label, jsxRuntime.jsx(ChevronDown, { "aria-hidden": "true", className: cn('size-3.5 transition-transform', expanded && 'rotate-180') })] }), jsxRuntime.jsx("span", { className: "h-px flex-1 bg-border" })] }), expanded && children] }));
77570
78545
  }
77571
78546
 
77572
78547
  /** Falls back to counting the current page when the caller has no total. */
@@ -80231,6 +81206,8 @@ exports.FilterSelect = FilterSelect;
80231
81206
  exports.FilterSurface = FilterSurface;
80232
81207
  exports.FilterSurfaceGroup = FilterSurfaceGroup;
80233
81208
  exports.FilterSurfaceMore = FilterSurfaceMore;
81209
+ exports.FilterSurfaceSortable = FilterSurfaceSortable;
81210
+ exports.FloatingSlideOver = FloatingSlideOver;
80234
81211
  exports.FormSectionCard = FormSectionCard;
80235
81212
  exports.FormSectionCardSkeleton = FormSectionCardSkeleton;
80236
81213
  exports.GEM_AUDIT_CONFIG = GEM_AUDIT_CONFIG;