analytica-frontend-lib 1.1.72 → 1.1.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1815,7 +1815,7 @@ var Input = forwardRef9(
1815
1815
  var Input_default = Input;
1816
1816
 
1817
1817
  // src/components/Search/Search.tsx
1818
- import { CaretLeft, X as X3 } from "phosphor-react";
1818
+ import { X as X3, MagnifyingGlass } from "phosphor-react";
1819
1819
  import {
1820
1820
  forwardRef as forwardRef11,
1821
1821
  useState as useState7,
@@ -2333,20 +2333,19 @@ var DropdownMenu = ({
2333
2333
  };
2334
2334
  useEffect6(() => {
2335
2335
  if (open) {
2336
- document.addEventListener("mousedown", handleClickOutside);
2336
+ document.addEventListener("pointerdown", handleClickOutside);
2337
2337
  document.addEventListener("keydown", handleDownkey);
2338
2338
  }
2339
2339
  return () => {
2340
- document.removeEventListener("mousedown", handleClickOutside);
2340
+ document.removeEventListener("pointerdown", handleClickOutside);
2341
2341
  document.removeEventListener("keydown", handleDownkey);
2342
2342
  };
2343
2343
  }, [open]);
2344
2344
  useEffect6(() => {
2345
- setOpen(open);
2346
2345
  onOpenChange?.(open);
2347
2346
  }, [open, onOpenChange]);
2348
2347
  useEffect6(() => {
2349
- if (propOpen) {
2348
+ if (propOpen !== void 0) {
2350
2349
  setOpen(propOpen);
2351
2350
  }
2352
2351
  }, [propOpen]);
@@ -2473,6 +2472,7 @@ var DropdownMenuItem = forwardRef10(
2473
2472
  onClick,
2474
2473
  variant = "menu",
2475
2474
  store: externalStore,
2475
+ preventClose = false,
2476
2476
  ...props
2477
2477
  }, ref) => {
2478
2478
  const store = useDropdownStore(externalStore);
@@ -2484,8 +2484,17 @@ var DropdownMenuItem = forwardRef10(
2484
2484
  e.stopPropagation();
2485
2485
  return;
2486
2486
  }
2487
- onClick?.(e);
2488
- setOpen(false);
2487
+ if (e.type === "click") {
2488
+ onClick?.(e);
2489
+ } else if (e.type === "keydown") {
2490
+ if (e.key === "Enter" || e.key === " ") {
2491
+ onClick?.(e);
2492
+ }
2493
+ props.onKeyDown?.(e);
2494
+ }
2495
+ if (!preventClose) {
2496
+ setOpen(false);
2497
+ }
2489
2498
  };
2490
2499
  const getVariantClasses = () => {
2491
2500
  if (variant === "profile") {
@@ -2512,7 +2521,11 @@ var DropdownMenuItem = forwardRef10(
2512
2521
  `,
2513
2522
  onClick: handleClick,
2514
2523
  onKeyDown: (e) => {
2515
- if (e.key === "Enter" || e.key === " ") handleClick(e);
2524
+ if (e.key === "Enter" || e.key === " ") {
2525
+ e.preventDefault();
2526
+ e.stopPropagation();
2527
+ handleClick(e);
2528
+ }
2516
2529
  },
2517
2530
  tabIndex: disabled ? -1 : 0,
2518
2531
  ...props,
@@ -2578,10 +2591,17 @@ var ProfileMenuHeader = forwardRef10(({ className, name, email, store: _store, .
2578
2591
  );
2579
2592
  });
2580
2593
  ProfileMenuHeader.displayName = "ProfileMenuHeader";
2581
- var ProfileToggleTheme = ({ ...props }) => {
2594
+ var ProfileToggleTheme = ({
2595
+ store: externalStore,
2596
+ ...props
2597
+ }) => {
2582
2598
  const { themeMode, setTheme } = useTheme();
2583
2599
  const [modalThemeToggle, setModalThemeToggle] = useState6(false);
2584
2600
  const [selectedTheme, setSelectedTheme] = useState6(themeMode);
2601
+ const internalStoreRef = useRef3(null);
2602
+ internalStoreRef.current ??= createDropdownStore();
2603
+ const store = externalStore ?? internalStoreRef.current;
2604
+ const setOpen = useStore3(store, (s) => s.setOpen);
2585
2605
  const handleClick = (e) => {
2586
2606
  e.preventDefault();
2587
2607
  e.stopPropagation();
@@ -2590,12 +2610,20 @@ var ProfileToggleTheme = ({ ...props }) => {
2590
2610
  const handleSave = () => {
2591
2611
  setTheme(selectedTheme);
2592
2612
  setModalThemeToggle(false);
2613
+ setOpen(false);
2614
+ };
2615
+ const handleCancel = () => {
2616
+ setSelectedTheme(themeMode);
2617
+ setModalThemeToggle(false);
2618
+ setOpen(false);
2593
2619
  };
2594
2620
  return /* @__PURE__ */ jsxs13(Fragment2, { children: [
2595
2621
  /* @__PURE__ */ jsx20(
2596
2622
  DropdownMenuItem,
2597
2623
  {
2598
2624
  variant: "profile",
2625
+ preventClose: true,
2626
+ store,
2599
2627
  iconLeft: /* @__PURE__ */ jsx20(
2600
2628
  "svg",
2601
2629
  {
@@ -2630,19 +2658,12 @@ var ProfileToggleTheme = ({ ...props }) => {
2630
2658
  Modal_default,
2631
2659
  {
2632
2660
  isOpen: modalThemeToggle,
2633
- onClose: () => setModalThemeToggle(false),
2661
+ onClose: handleCancel,
2634
2662
  title: "Apar\xEAncia",
2635
2663
  size: "md",
2636
2664
  footer: /* @__PURE__ */ jsxs13("div", { className: "flex gap-3", children: [
2637
- /* @__PURE__ */ jsx20(
2638
- Button_default,
2639
- {
2640
- variant: "outline",
2641
- onClick: () => setModalThemeToggle(false),
2642
- children: "Cancelar"
2643
- }
2644
- ),
2645
- /* @__PURE__ */ jsx20(Button_default, { variant: "solid", onClick: () => handleSave(), children: "Salvar" })
2665
+ /* @__PURE__ */ jsx20(Button_default, { variant: "outline", onClick: handleCancel, children: "Cancelar" }),
2666
+ /* @__PURE__ */ jsx20(Button_default, { variant: "solid", onClick: handleSave, children: "Salvar" })
2646
2667
  ] }),
2647
2668
  children: /* @__PURE__ */ jsxs13("div", { className: "flex flex-col", children: [
2648
2669
  /* @__PURE__ */ jsx20("p", { className: "text-sm text-text-500", children: "Escolha o tema:" }),
@@ -2731,11 +2752,15 @@ var Search = forwardRef11(
2731
2752
  value,
2732
2753
  onChange,
2733
2754
  placeholder = "Buscar...",
2755
+ onKeyDown: userOnKeyDown,
2734
2756
  ...props
2735
2757
  }, ref) => {
2736
2758
  const [dropdownOpen, setDropdownOpen] = useState7(false);
2759
+ const [forceClose, setForceClose] = useState7(false);
2760
+ const justSelectedRef = useRef4(false);
2737
2761
  const dropdownStore = useRef4(createDropdownStore()).current;
2738
2762
  const dropdownRef = useRef4(null);
2763
+ const inputElRef = useRef4(null);
2739
2764
  const filteredOptions = useMemo2(() => {
2740
2765
  if (!options.length) {
2741
2766
  return [];
@@ -2743,24 +2768,35 @@ var Search = forwardRef11(
2743
2768
  const filtered = filterOptions(options, value || "");
2744
2769
  return filtered;
2745
2770
  }, [options, value]);
2746
- const showDropdown = controlledShowDropdown ?? (dropdownOpen && value && String(value).length > 0);
2771
+ const showDropdown = !forceClose && (controlledShowDropdown ?? (dropdownOpen && value && String(value).length > 0));
2772
+ const setOpenAndNotify = (open) => {
2773
+ setDropdownOpen(open);
2774
+ dropdownStore.setState({ open });
2775
+ onDropdownChange?.(open);
2776
+ };
2747
2777
  useEffect7(() => {
2778
+ if (justSelectedRef.current) {
2779
+ justSelectedRef.current = false;
2780
+ return;
2781
+ }
2782
+ if (forceClose) {
2783
+ setOpenAndNotify(false);
2784
+ return;
2785
+ }
2748
2786
  const shouldShow = Boolean(value && String(value).length > 0);
2749
- setDropdownOpen(shouldShow);
2750
- dropdownStore.setState({ open: shouldShow });
2751
- onDropdownChange?.(shouldShow);
2752
- }, [value, onDropdownChange, dropdownStore]);
2787
+ setOpenAndNotify(shouldShow);
2788
+ }, [value, forceClose, onDropdownChange, dropdownStore]);
2753
2789
  const handleSelectOption = (option) => {
2790
+ justSelectedRef.current = true;
2791
+ setForceClose(true);
2754
2792
  onSelect?.(option);
2755
- setDropdownOpen(false);
2756
- dropdownStore.setState({ open: false });
2793
+ setOpenAndNotify(false);
2757
2794
  updateInputValue(option, ref, onChange);
2758
2795
  };
2759
2796
  useEffect7(() => {
2760
2797
  const handleClickOutside = (event) => {
2761
2798
  if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
2762
- setDropdownOpen(false);
2763
- dropdownStore.setState({ open: false });
2799
+ setOpenAndNotify(false);
2764
2800
  }
2765
2801
  };
2766
2802
  if (showDropdown) {
@@ -2769,9 +2805,10 @@ var Search = forwardRef11(
2769
2805
  return () => {
2770
2806
  document.removeEventListener("mousedown", handleClickOutside);
2771
2807
  };
2772
- }, [showDropdown, dropdownStore]);
2808
+ }, [showDropdown, dropdownStore, onDropdownChange]);
2773
2809
  const generatedId = useId7();
2774
2810
  const inputId = id ?? `search-${generatedId}`;
2811
+ const dropdownId = `${inputId}-dropdown`;
2775
2812
  const handleClear = () => {
2776
2813
  if (onClear) {
2777
2814
  onClear();
@@ -2784,21 +2821,40 @@ var Search = forwardRef11(
2784
2821
  e.stopPropagation();
2785
2822
  handleClear();
2786
2823
  };
2787
- const handleLeftIconClick = () => {
2788
- if (ref && "current" in ref && ref.current) {
2789
- ref.current.blur();
2790
- }
2824
+ const handleSearchIconClick = (e) => {
2825
+ e.preventDefault();
2826
+ e.stopPropagation();
2827
+ setTimeout(() => {
2828
+ inputElRef.current?.focus();
2829
+ }, 0);
2791
2830
  };
2792
2831
  const handleInputChange = (e) => {
2832
+ setForceClose(false);
2793
2833
  onChange?.(e);
2794
2834
  onSearch?.(e.target.value);
2795
2835
  };
2836
+ const handleKeyDown = (e) => {
2837
+ userOnKeyDown?.(e);
2838
+ if (e.defaultPrevented) return;
2839
+ if (e.key === "Enter") {
2840
+ e.preventDefault();
2841
+ if (showDropdown && filteredOptions.length > 0) {
2842
+ handleSelectOption(filteredOptions[0]);
2843
+ } else if (value) {
2844
+ onSearch?.(String(value));
2845
+ setForceClose(true);
2846
+ setOpenAndNotify(false);
2847
+ }
2848
+ }
2849
+ };
2796
2850
  const getInputStateClasses = (disabled2, readOnly2) => {
2797
2851
  if (disabled2) return "cursor-not-allowed opacity-40";
2798
2852
  if (readOnly2) return "cursor-default focus:outline-none !text-text-900";
2799
2853
  return "hover:border-border-400";
2800
2854
  };
2801
- const showClearButton = value && !disabled && !readOnly;
2855
+ const hasValue = String(value ?? "").length > 0;
2856
+ const showClearButton = hasValue && !disabled && !readOnly;
2857
+ const showSearchIcon = !hasValue && !disabled && !readOnly;
2802
2858
  return /* @__PURE__ */ jsxs14(
2803
2859
  "div",
2804
2860
  {
@@ -2806,30 +2862,30 @@ var Search = forwardRef11(
2806
2862
  className: `w-full max-w-lg md:w-[488px] ${containerClassName}`,
2807
2863
  children: [
2808
2864
  /* @__PURE__ */ jsxs14("div", { className: "relative flex items-center", children: [
2809
- /* @__PURE__ */ jsx21("div", { className: "absolute left-3 top-1/2 transform -translate-y-1/2", children: /* @__PURE__ */ jsx21(
2810
- "button",
2811
- {
2812
- type: "button",
2813
- className: "w-6 h-6 text-text-800 flex items-center justify-center bg-transparent border-0 p-0 cursor-pointer hover:text-text-600 transition-colors",
2814
- onClick: handleLeftIconClick,
2815
- "aria-label": "Voltar",
2816
- children: /* @__PURE__ */ jsx21(CaretLeft, {})
2817
- }
2818
- ) }),
2819
2865
  /* @__PURE__ */ jsx21(
2820
2866
  "input",
2821
2867
  {
2822
- ref,
2868
+ ref: (node) => {
2869
+ if (ref) {
2870
+ if (typeof ref === "function") ref(node);
2871
+ else
2872
+ ref.current = node;
2873
+ }
2874
+ inputElRef.current = node;
2875
+ },
2823
2876
  id: inputId,
2824
2877
  type: "text",
2825
- className: `w-full py-0 px-4 pl-10 ${showClearButton ? "pr-10" : "pr-4"} font-normal text-text-900 focus:outline-primary-950 border rounded-full bg-background focus:bg-primary-50 border-border-300 focus:border-2 focus:border-primary-950 h-10 placeholder:text-text-600 ${getInputStateClasses(disabled, readOnly)} ${className}`,
2878
+ className: `w-full py-0 px-4 pr-10 font-normal text-text-900 focus:outline-primary-950 border rounded-full bg-background focus:bg-primary-50 border-border-300 focus:border-2 focus:border-primary-950 h-10 placeholder:text-text-600 ${getInputStateClasses(disabled, readOnly)} ${className}`,
2826
2879
  value,
2827
2880
  onChange: handleInputChange,
2881
+ onKeyDown: handleKeyDown,
2828
2882
  disabled,
2829
2883
  readOnly,
2830
2884
  placeholder,
2831
2885
  "aria-expanded": showDropdown ? "true" : void 0,
2832
2886
  "aria-haspopup": options.length > 0 ? "listbox" : void 0,
2887
+ "aria-controls": showDropdown ? dropdownId : void 0,
2888
+ "aria-autocomplete": "list",
2833
2889
  role: options.length > 0 ? "combobox" : void 0,
2834
2890
  ...props
2835
2891
  }
@@ -2843,11 +2899,22 @@ var Search = forwardRef11(
2843
2899
  "aria-label": "Limpar busca",
2844
2900
  children: /* @__PURE__ */ jsx21("span", { className: "w-6 h-6 text-text-800 flex items-center justify-center hover:text-text-600 transition-colors", children: /* @__PURE__ */ jsx21(X3, {}) })
2845
2901
  }
2902
+ ) }),
2903
+ showSearchIcon && /* @__PURE__ */ jsx21("div", { className: "absolute right-3 top-1/2 transform -translate-y-1/2", children: /* @__PURE__ */ jsx21(
2904
+ "button",
2905
+ {
2906
+ type: "button",
2907
+ className: "p-0 border-0 bg-transparent cursor-pointer",
2908
+ onMouseDown: handleSearchIconClick,
2909
+ "aria-label": "Buscar",
2910
+ children: /* @__PURE__ */ jsx21("span", { className: "w-6 h-6 text-text-800 flex items-center justify-center hover:text-text-600 transition-colors", children: /* @__PURE__ */ jsx21(MagnifyingGlass, {}) })
2911
+ }
2846
2912
  ) })
2847
2913
  ] }),
2848
2914
  showDropdown && /* @__PURE__ */ jsx21(DropdownMenu_default, { open: showDropdown, onOpenChange: setDropdownOpen, children: /* @__PURE__ */ jsx21(
2849
2915
  DropdownMenuContent,
2850
2916
  {
2917
+ id: dropdownId,
2851
2918
  className: "w-full mt-1",
2852
2919
  style: { maxHeight: dropdownMaxHeight },
2853
2920
  align: "start",
@@ -7046,7 +7113,7 @@ import {
7046
7113
  cloneElement as cloneElement6,
7047
7114
  useState as useState14
7048
7115
  } from "react";
7049
- import { CaretLeft as CaretLeft2, CaretRight as CaretRight4 } from "phosphor-react";
7116
+ import { CaretLeft, CaretRight as CaretRight4 } from "phosphor-react";
7050
7117
  import { jsx as jsx41, jsxs as jsxs29 } from "react/jsx-runtime";
7051
7118
  var createMenuStore = (onValueChange) => create7((set) => ({
7052
7119
  value: "",
@@ -7312,7 +7379,7 @@ var MenuOverflow = ({
7312
7379
  className: "absolute left-0 top-1/2 -translate-y-1/2 z-10 flex h-8 w-8 items-center justify-center rounded-full bg-white shadow-md cursor-pointer",
7313
7380
  "data-testid": "scroll-left-button",
7314
7381
  children: [
7315
- /* @__PURE__ */ jsx41(CaretLeft2, { size: 16 }),
7382
+ /* @__PURE__ */ jsx41(CaretLeft, { size: 16 }),
7316
7383
  /* @__PURE__ */ jsx41("span", { className: "sr-only", children: "Scroll left" })
7317
7384
  ]
7318
7385
  }
@@ -8795,7 +8862,7 @@ function useApiConfig(api) {
8795
8862
  // src/components/Quiz/Quiz.tsx
8796
8863
  import {
8797
8864
  BookOpen,
8798
- CaretLeft as CaretLeft3,
8865
+ CaretLeft as CaretLeft2,
8799
8866
  CaretRight as CaretRight5,
8800
8867
  Clock as Clock2,
8801
8868
  SquaresFour
@@ -10255,7 +10322,7 @@ var QuizTitle = forwardRef20(
10255
10322
  /* @__PURE__ */ jsx48(
10256
10323
  IconButton_default,
10257
10324
  {
10258
- icon: /* @__PURE__ */ jsx48(CaretLeft3, { size: 24 }),
10325
+ icon: /* @__PURE__ */ jsx48(CaretLeft2, { size: 24 }),
10259
10326
  size: "md",
10260
10327
  "aria-label": "Voltar",
10261
10328
  onClick: handleBackClick
@@ -10512,7 +10579,7 @@ var QuizFooter = forwardRef20(
10512
10579
  size: "medium",
10513
10580
  variant: "link",
10514
10581
  action: "primary",
10515
- iconLeft: /* @__PURE__ */ jsx48(CaretLeft3, { size: 18 }),
10582
+ iconLeft: /* @__PURE__ */ jsx48(CaretLeft2, { size: 18 }),
10516
10583
  onClick: () => {
10517
10584
  goToPreviousQuestion();
10518
10585
  },