@pk-design/react-tailwind 1.13.2 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -380,6 +380,86 @@ const useResponsiveValue = (value) => {
380
380
  return value.base;
381
381
  };
382
382
 
383
+ // history.back() lands later, so a drawer opening meanwhile (one replacing another,
384
+ // or React re-running effects under StrictMode) would have its new entry removed
385
+ // instead, and close at once. Removals are counted, and an opening drawer waits for them.
386
+ let pendingBacks = 0;
387
+ const afterBacks = [];
388
+ function settleBack() {
389
+ pendingBacks = Math.max(0, pendingBacks - 1);
390
+ if (pendingBacks === 0)
391
+ afterBacks.splice(0).forEach((run) => run());
392
+ }
393
+ function removeEntry() {
394
+ pendingBacks += 1;
395
+ let settled = false;
396
+ const settle = () => {
397
+ if (settled)
398
+ return;
399
+ settled = true;
400
+ window.removeEventListener('popstate', settle);
401
+ settleBack();
402
+ };
403
+ window.addEventListener('popstate', settle);
404
+ // A back that never reports (nothing to go back to) mustn't hold others up.
405
+ window.setTimeout(settle, 500);
406
+ window.history.back();
407
+ }
408
+ /**
409
+ * While `active`, the browser's back button (and Android's back gesture)
410
+ * closes the drawer instead of leaving the page: opening adds a history entry
411
+ * (keeping the current state, so routers see the same location), and back
412
+ * removes it. Closed any other way, the entry is removed too, but only if it's
413
+ * still the latest one, so a form that saves and then navigates isn't undone.
414
+ */
415
+ function useCloseOnBack(active, onClose) {
416
+ const onCloseRef = React__default.useRef(onClose);
417
+ React__default.useEffect(() => {
418
+ onCloseRef.current = onClose;
419
+ });
420
+ const token = React__default.useId();
421
+ React__default.useEffect(() => {
422
+ if (!active || typeof window === 'undefined')
423
+ return;
424
+ const pushEntry = () => { var _a; return window.history.pushState({ ...((_a = window.history.state) !== null && _a !== void 0 ? _a : {}), drawer: token }, ''); };
425
+ let entryPresent = false;
426
+ let disposed = false;
427
+ const handlePop = () => {
428
+ var _a;
429
+ if (((_a = window.history.state) === null || _a === void 0 ? void 0 : _a.drawer) === token)
430
+ return;
431
+ entryPresent = false;
432
+ onCloseRef.current();
433
+ // onClose may step back within the drawer instead of closing it; if it's
434
+ // still open afterwards, take back its entry so the next back works too.
435
+ window.setTimeout(() => {
436
+ if (disposed)
437
+ return;
438
+ pushEntry();
439
+ entryPresent = true;
440
+ }, 0);
441
+ };
442
+ const start = () => {
443
+ if (disposed)
444
+ return;
445
+ pushEntry();
446
+ entryPresent = true;
447
+ window.addEventListener('popstate', handlePop);
448
+ };
449
+ if (pendingBacks > 0)
450
+ afterBacks.push(start);
451
+ else
452
+ start();
453
+ return () => {
454
+ var _a;
455
+ disposed = true;
456
+ window.removeEventListener('popstate', handlePop);
457
+ if (entryPresent && ((_a = window.history.state) === null || _a === void 0 ? void 0 : _a.drawer) === token)
458
+ removeEntry();
459
+ };
460
+ }, [active, token]);
461
+ }
462
+
383
463
  const alignmentMap = {
384
464
  center: 'items-center justify-center h-full',
385
465
  start: 'justify-start h-full',
@@ -478,85 +558,6 @@ const Drawer = ({ isOpen, onClose = () => { }, closeOnOutsideClick = true, align
478
558
  : [panelAlignmentMap[align], panelSizeMap[size], panelClass])), "data-layout": fullscreen ? 'fullscreen' : undefined, children: [shouldShowDragHandle && (jsx("div", { className: "w-12 h-1.5 rounded-full bg-gray-300 dark:bg-gray-600 mx-auto my-2.5 shrink-0 cursor-grab", "data-testid": "drawer-drag-handle" })), fullscreen && (jsxs("div", { className: "sticky top-0 z-10 flex h-14 shrink-0 items-center gap-1 border-b border-[var(--ui-border)] bg-white pl-1 pr-3 pt-[env(safe-area-inset-top,0px)] box-content dark:bg-gray-800", children: [jsx(Button, { iconOnly: true, "aria-label": "Close", variant: "plain", theme: "secondary", onClick: onClose, className: "shrink-0", children: jsx(SvgX, { className: "size-5" }) }), title && (jsx(DialogTitle, { as: "h3", className: "min-w-0 flex-1 truncate text-base font-semibold text-gray-900 dark:text-white", children: title })), headerAction && jsx("div", { className: "ml-auto shrink-0", children: headerAction })] })), !fullscreen && showTitleSection && (jsxs("div", { className: buildClassName('space-y-1 py-3 px-4 md:px-6 flex flex-col border-b border-[var(--ui-border)] shrink-0', titleSticky && 'sticky top-0 bg-white dark:bg-gray-800 z-10'), children: [jsxs("div", { className: "flex items-center justify-between gap-3 min-w-0", children: [jsxs("div", { className: "flex items-center gap-2 min-w-0 flex-1", children: [showBackButton && (jsx(Button, { iconOnly: true, "aria-label": "Back", variant: "plain", theme: "secondary", size: "xs", onClick: onClose, children: jsx(SvgChevronLeft, { className: "size-4" }) })), title && (jsx(DialogTitle, { as: "h3", className: buildClassName('text-lg font-semibold text-gray-900 dark:text-white truncate tracking-tight min-w-0', titleClass), children: title }))] }), showCloseButton && (jsx(Button, { iconOnly: true, "aria-label": "Close drawer", variant: "plain", theme: "secondary", size: "xs", onClick: onClose, className: "rounded-full text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 shrink-0", children: jsx(SvgX, { className: "size-4" }) }))] }), description && (jsx("p", { className: buildClassName('text-sm text-gray-500 dark:text-gray-400 font-normal truncate', descriptionClass), children: description }))] })), jsxs("div", { className: buildClassName('flex-1 p-4 md:p-6 space-y-4 min-w-0', contentClass, fullscreen && 'pb-[calc(1rem+env(safe-area-inset-bottom,0px))]'), children: [fullscreen && description && (jsx("p", { className: buildClassName('text-sm text-gray-500 dark:text-gray-400', descriptionClass), children: description })), children] }), !fullscreen && footer && (jsx("div", { className: buildClassName('p-4 border-t border-[var(--ui-border-muted)] bg-white dark:bg-gray-800 shrink-0 min-w-0', footerSticky && 'sticky bottom-0 z-10'), children: footer }))] }) }) })] }));
479
559
  };
480
560
  Drawer.displayName = 'Drawer';
481
- // history.back() lands later, so a drawer opening meanwhile (one replacing another,
482
- // or React re-running effects under StrictMode) would have its new entry removed
483
- // instead, and close at once. Removals are counted, and an opening drawer waits for them.
484
- let pendingBacks = 0;
485
- const afterBacks = [];
486
- function settleBack() {
487
- pendingBacks = Math.max(0, pendingBacks - 1);
488
- if (pendingBacks === 0)
489
- afterBacks.splice(0).forEach((run) => run());
490
- }
491
- function removeEntry() {
492
- pendingBacks += 1;
493
- let settled = false;
494
- const settle = () => {
495
- if (settled)
496
- return;
497
- settled = true;
498
- window.removeEventListener('popstate', settle);
499
- settleBack();
500
- };
501
- window.addEventListener('popstate', settle);
502
- // A back that never reports (nothing to go back to) mustn't hold others up.
503
- window.setTimeout(settle, 500);
504
- window.history.back();
505
- }
506
- /**
507
- * While `active`, the browser's back button (and Android's back gesture)
508
- * closes the drawer instead of leaving the page: opening adds a history entry
509
- * (keeping the current state, so routers see the same location), and back
510
- * removes it. Closed any other way, the entry is removed too, but only if it's
511
- * still the latest one, so a form that saves and then navigates isn't undone.
512
- */
513
- function useCloseOnBack(active, onClose) {
514
- const onCloseRef = React__default.useRef(onClose);
515
- React__default.useEffect(() => {
516
- onCloseRef.current = onClose;
517
- });
518
- const token = React__default.useId();
519
- React__default.useEffect(() => {
520
- if (!active || typeof window === 'undefined')
521
- return;
522
- const pushEntry = () => { var _a; return window.history.pushState({ ...((_a = window.history.state) !== null && _a !== void 0 ? _a : {}), drawer: token }, ''); };
523
- let entryPresent = false;
524
- let disposed = false;
525
- const handlePop = () => {
526
- var _a;
527
- if (((_a = window.history.state) === null || _a === void 0 ? void 0 : _a.drawer) === token)
528
- return;
529
- entryPresent = false;
530
- onCloseRef.current();
531
- // onClose may step back within the drawer instead of closing it; if it's
532
- // still open afterwards, take back its entry so the next back works too.
533
- window.setTimeout(() => {
534
- if (disposed)
535
- return;
536
- pushEntry();
537
- entryPresent = true;
538
- }, 0);
539
- };
540
- const start = () => {
541
- if (disposed)
542
- return;
543
- pushEntry();
544
- entryPresent = true;
545
- window.addEventListener('popstate', handlePop);
546
- };
547
- if (pendingBacks > 0)
548
- afterBacks.push(start);
549
- else
550
- start();
551
- return () => {
552
- var _a;
553
- disposed = true;
554
- window.removeEventListener('popstate', handlePop);
555
- if (entryPresent && ((_a = window.history.state) === null || _a === void 0 ? void 0 : _a.drawer) === token)
556
- removeEntry();
557
- };
558
- }, [active, token]);
559
- }
560
561
 
561
562
  function ActionSheet({ isOpen, onClose, title, description, actions, showCancelButton = true, cancelLabel = 'Cancel', onCancel, closeOnBackdropClick = true, dragHandle = true, panelClass = '', containerClass = '', }) {
562
563
  const handleItemClick = (action) => {
@@ -5247,5 +5248,5 @@ const useIsTabletOrMobile = () => {
5247
5248
  return isMobile || isTablet;
5248
5249
  };
5249
5250
 
5250
- export { Accordion, ActionSheet, Alert, BREAKPOINT_QUERIES, Badge, Banner, BodyText, BottomNavigation, Breadcrumb, Button, ButtonGroup, Card, CardContent, CardDescription, CardFooter, CardHeader, CardMedia, CardTitle, Checkbox, CheckboxGroup, DOTS, DataList, DataTable, DetailedInformation, Dot, Drawer, Dropdown, EmptyState, EmptyTableRow, Flex, FlexItem, FloatingActionButton, Grid, GridCol, HeadingText, Input, Label, Loader, MobileHeader, MobilePicker, MobileStepper, PASSWORD_PLACEHOLDER, PASSWORD_TYPE, Pagination, PasswordInput, PinInput, PullToRefresh, QuantityStepper, Radio, RadioGroup, RadioSwitch, RangeInput, RangeSlider, SegmentedControl, SelectBox, Skeleton, SortIconMap, StatusPill, StickyActionBar, SwipeableRow, SwipeableTabs, Table, TableBody, TableCell, TableFoot, TableHead, TableHeaderCell, TableRow, Tabs, TextContent, Textarea, Toast, ToastProvider, VirtualizedDataTable, WheelPicker, buildClassName, buildInputClass, evaluatePasswordStrength, get, getSortIcon, isArray, isEmpty, nextSortDirection, updateSortQuery, useBreakpoint, useDebounce, useDebounceFn, useIsMobile, useIsTablet, useIsTabletOrMobile, useMediaQuery, usePagination, useResponsiveValue, useRowSelection, useToast };
5251
+ export { Accordion, ActionSheet, Alert, BREAKPOINT_QUERIES, Badge, Banner, BodyText, BottomNavigation, Breadcrumb, Button, ButtonGroup, Card, CardContent, CardDescription, CardFooter, CardHeader, CardMedia, CardTitle, Checkbox, CheckboxGroup, DOTS, DataList, DataTable, DetailedInformation, Dot, Drawer, Dropdown, EmptyState, EmptyTableRow, Flex, FlexItem, FloatingActionButton, Grid, GridCol, HeadingText, Input, Label, Loader, MobileHeader, MobilePicker, MobileStepper, PASSWORD_PLACEHOLDER, PASSWORD_TYPE, Pagination, PasswordInput, PinInput, PullToRefresh, QuantityStepper, Radio, RadioGroup, RadioSwitch, RangeInput, RangeSlider, SegmentedControl, SelectBox, Skeleton, SortIconMap, StatusPill, StickyActionBar, SwipeableRow, SwipeableTabs, Table, TableBody, TableCell, TableFoot, TableHead, TableHeaderCell, TableRow, Tabs, TextContent, Textarea, Toast, ToastProvider, VirtualizedDataTable, WheelPicker, buildClassName, buildInputClass, evaluatePasswordStrength, get, getSortIcon, isArray, isEmpty, nextSortDirection, updateSortQuery, useBreakpoint, useCloseOnBack, useDebounce, useDebounceFn, useIsMobile, useIsTablet, useIsTabletOrMobile, useMediaQuery, usePagination, useResponsiveValue, useRowSelection, useToast };
5251
5252
  //# sourceMappingURL=react-tailwind.es.js.map