@erxes/ui 4.0.0-v2.4 → 4.0.0-v2.5

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.
@@ -2,7 +2,7 @@ import { useFormat } from "../lib/format.js";
2
2
  import { cn } from "../lib/utils.js";
3
3
  import { ChartContext, configFor, fillOf, keyOf, useChart } from "./chart-config.js";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
- import "react";
5
+ import React from "react";
6
6
  import * as RechartsPrimitive from "recharts";
7
7
  // src/components/charts.tsx
8
8
  /** The series colours as `--color-<key>` variables. */
@@ -13,8 +13,9 @@ const colorVariables = (config) => {
13
13
  };
14
14
  const ChartContainer = ({ ref, className, children, config, style, ...props }) => {
15
15
  const cssVariables = colorVariables(config);
16
+ const chart = React.useMemo(() => ({ config }), [config]);
16
17
  return /* @__PURE__ */ jsx(ChartContext.Provider, {
17
- value: { config },
18
+ value: chart,
18
19
  children: /* @__PURE__ */ jsx("div", {
19
20
  ref,
20
21
  style: {
@@ -5,7 +5,7 @@ import { cn } from "../lib/utils.js";
5
5
  import { PopoverScoped } from "../modules/hotkey/components/PopoverScoped.js";
6
6
  import { IconCheck, IconChevronDown } from "@tabler/icons-react";
7
7
  import { jsx, jsxs } from "react/jsx-runtime";
8
- import { createContext, useContext, useState } from "react";
8
+ import { createContext, useContext, useMemo, useState } from "react";
9
9
  import { IMaskInput } from "react-imask";
10
10
  // src/components/color-picker.tsx
11
11
  const DEFAULT_COLORS = {
@@ -33,12 +33,17 @@ const useColorPickerContext = () => {
33
33
  return context;
34
34
  };
35
35
  const ColorPickerProvider = ({ children, value, onValueChange, colors = DEFAULT_COLORS, open, onOpenChange, scope }) => {
36
+ const picker = useMemo(() => ({
37
+ value,
38
+ onValueChange,
39
+ colors
40
+ }), [
41
+ value,
42
+ onValueChange,
43
+ colors
44
+ ]);
36
45
  return /* @__PURE__ */ jsx(ColorPickerContext.Provider, {
37
- value: {
38
- value,
39
- onValueChange,
40
- colors
41
- },
46
+ value: picker,
42
47
  children: /* @__PURE__ */ jsx(PopoverScoped, {
43
48
  scope,
44
49
  open,
@@ -83,6 +88,7 @@ const ColorPickerContent = ({ setOpen }) => {
83
88
  style: { "--swatch": value },
84
89
  children: [/* @__PURE__ */ jsx("input", {
85
90
  type: "color",
91
+ "aria-label": "Custom color",
86
92
  value: value || "#000000",
87
93
  className: "absolute inset-0 w-full h-full opacity-0 cursor-pointer",
88
94
  onChange: (e) => onValueChange?.(e.target.value)
@@ -8,8 +8,9 @@ import { useRender } from "@base-ui/react/use-render";
8
8
  // src/components/form.tsx
9
9
  const FormFieldContext = React.createContext(null);
10
10
  const FormField = ({ ...props }) => {
11
+ const field = React.useMemo(() => ({ name: props.name }), [props.name]);
11
12
  return /* @__PURE__ */ jsx(FormFieldContext.Provider, {
12
- value: { name: props.name },
13
+ value: field,
13
14
  children: /* @__PURE__ */ jsx(Controller, { ...props })
14
15
  });
15
16
  };
@@ -39,8 +40,9 @@ const formItemVariants = cva("", {
39
40
  });
40
41
  const FormItem = ({ ref, className, orientation, ...props }) => {
41
42
  const id = React.useId();
43
+ const item = React.useMemo(() => ({ id }), [id]);
42
44
  return /* @__PURE__ */ jsx(FormItemContext.Provider, {
43
- value: { id },
45
+ value: item,
44
46
  children: /* @__PURE__ */ jsx("div", {
45
47
  ref,
46
48
  className: cn(formItemVariants({ orientation }), className),
@@ -14,7 +14,7 @@ const SelectorField = ({ fieldRef, value, placeholder, hidePlaceholderWhenSelect
14
14
  className: "flex flex-wrap gap-1 w-full",
15
15
  children: [
16
16
  value.map((option) => /* @__PURE__ */ jsxs(Combobox.Chip, {
17
- className: "relative inline-flex h-7 cursor-default items-center rounded-md border border-solid bg-background pe-7 pl-2 ps-2 text-xs font-medium text-secondary-foreground transition-all hover:bg-background data-disabled:cursor-not-allowed data-disabled:opacity-50",
17
+ className: "relative inline-flex h-7 cursor-default items-center rounded-md border border-solid bg-background pe-7 pl-2 ps-2 text-xs font-medium text-secondary-foreground transition-colors hover:bg-background data-disabled:cursor-not-allowed data-disabled:opacity-50",
18
18
  children: [option.label, /* @__PURE__ */ jsx(Combobox.ChipRemove, {
19
19
  "aria-label": "Remove",
20
20
  className: "absolute -inset-y-px -end-px flex size-7 items-center justify-center rounded-e-lg border border-transparent p-0 text-muted-foreground/80 outline-0 transition-colors hover:text-foreground focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-ring/70",
@@ -68,8 +68,9 @@ const SelectorPopup = ({ fieldRef, emptyIndicator }) => /* @__PURE__ */ jsx(Comb
68
68
  })
69
69
  }) });
70
70
  const has = (list, key) => list.some((item) => item.value === key);
71
+ const NONE = [];
71
72
  /** Picks several options from a list, shown as removable badges; picked options leave the list. */
72
- const MultipleSelector = ({ value = [], onChange, options = [], placeholder = "Search", creatable, emptyIndicator, disabled, ...fieldProps }) => {
73
+ const MultipleSelector = ({ value = NONE, onChange, options = NONE, placeholder = "Search", creatable, emptyIndicator, disabled, ...fieldProps }) => {
73
74
  const fieldRef = useRef(null);
74
75
  const [query, setQuery] = useState("");
75
76
  const typed = query.trim();
@@ -14,6 +14,7 @@ function StringArrayInput({ value, onValueChange, placeholder = "Add a tag" }) {
14
14
  setDraft("");
15
15
  };
16
16
  const onKeyDown = (event) => {
17
+ if (event.nativeEvent.isComposing) return;
17
18
  if (event.key === "Enter" || event.key === ",") {
18
19
  event.preventDefault();
19
20
  add([draft]);
@@ -13,7 +13,7 @@ const ToastList = () => {
13
13
  return toasts.map((item) => /* @__PURE__ */ jsxs(Toast.Root, {
14
14
  toast: item,
15
15
  swipeDirection: "right",
16
- className: "group pointer-events-auto relative flex w-full items-center space-x-2 overflow-hidden rounded-md p-4 pr-6 shadow-lg transition-all bg-background text-foreground translate-x-(--toast-swipe-movement-x) animate-in slide-in-from-top-full sm:slide-in-from-bottom-full data-limited:hidden data-swiping:transition-none data-ending-style:animate-out data-ending-style:fade-out-80 data-ending-style:slide-out-to-right-full",
16
+ className: "group pointer-events-auto relative flex w-full items-center space-x-2 overflow-hidden rounded-md p-4 pr-6 shadow-lg transition-transform bg-background text-foreground translate-x-(--toast-swipe-movement-x) animate-in slide-in-from-top-full sm:slide-in-from-bottom-full data-limited:hidden data-swiping:transition-none data-ending-style:animate-out data-ending-style:fade-out-80 data-ending-style:slide-out-to-right-full",
17
17
  children: [
18
18
  /* @__PURE__ */ jsx("div", {
19
19
  className: "[&>svg]:size-4.5 mt-0.5 flex-none mb-auto",
@@ -10,17 +10,20 @@ const ToggleGroupContext = React.createContext({
10
10
  variant: "default"
11
11
  });
12
12
  /** The value is an array: one item for a single choice, empty when nothing is pressed. */
13
- const ToggleGroupRoot = ({ className, variant, size, children, ...props }) => /* @__PURE__ */ jsx(ToggleGroup$1, {
14
- className: cn("flex items-center justify-center gap-1 isolate", variant === "outline" && "gap-0 bg-muted rounded", className),
15
- ...props,
16
- children: /* @__PURE__ */ jsx(ToggleGroupContext, {
17
- value: {
18
- variant,
19
- size
20
- },
21
- children
22
- })
23
- });
13
+ const ToggleGroupRoot = ({ className, variant, size, children, ...props }) => {
14
+ const look = React.useMemo(() => ({
15
+ variant,
16
+ size
17
+ }), [variant, size]);
18
+ return /* @__PURE__ */ jsx(ToggleGroup$1, {
19
+ className: cn("flex items-center justify-center gap-1 isolate", variant === "outline" && "gap-0 bg-muted rounded", className),
20
+ ...props,
21
+ children: /* @__PURE__ */ jsx(ToggleGroupContext, {
22
+ value: look,
23
+ children
24
+ })
25
+ });
26
+ };
24
27
  const ToggleGroupItem = ({ className, variant, size, ...props }) => {
25
28
  const context = React.use(ToggleGroupContext);
26
29
  return /* @__PURE__ */ jsx(Toggle, {
@@ -7,7 +7,7 @@ import { cn } from "../lib/utils.js";
7
7
  import { readImage } from "../utils/core.js";
8
8
  import { IconTrash, IconUpload, IconUserCircle } from "@tabler/icons-react";
9
9
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
- import { createContext, useContext, useRef, useState } from "react";
10
+ import { createContext, useContext, useMemo, useRef, useState } from "react";
11
11
  import { cva } from "class-variance-authority";
12
12
  import { useTranslation } from "react-i18next";
13
13
  // src/components/upload.tsx
@@ -23,17 +23,22 @@ const UploadRoot = ({ ref, className, value, onChange, multiple, ...rest }) => {
23
23
  const [previewUrl, setPreviewUrl] = useState();
24
24
  const [isImageFocused, setIsImageFocused] = useState(false);
25
25
  const url = previewUrl ?? value;
26
+ const upload = useMemo(() => ({
27
+ url,
28
+ multiple,
29
+ onChange,
30
+ fileInputRef,
31
+ previewRef,
32
+ setPreviewUrl,
33
+ chooseFile: () => fileInputRef.current?.click(),
34
+ setIsImageFocused
35
+ }), [
36
+ url,
37
+ multiple,
38
+ onChange
39
+ ]);
26
40
  return /* @__PURE__ */ jsxs(UploadContext.Provider, {
27
- value: {
28
- url,
29
- multiple,
30
- onChange,
31
- fileInputRef,
32
- previewRef,
33
- setPreviewUrl,
34
- chooseFile: () => fileInputRef.current?.click(),
35
- setIsImageFocused
36
- },
41
+ value: upload,
37
42
  children: [/* @__PURE__ */ jsx(Dialog, {
38
43
  open: isImageFocused,
39
44
  onOpenChange: setIsImageFocused,
@@ -16,13 +16,12 @@ const EmailChip = ({ item, email, onEmailClick, onEmailDoubleClick, onEmailKeyAc
16
16
  className: "min-w-0",
17
17
  children: /* @__PURE__ */ jsx(EmailText, { ...item })
18
18
  });
19
- return /* @__PURE__ */ jsx("span", {
19
+ return /* @__PURE__ */ jsx("button", {
20
+ type: "button",
20
21
  className: cn(buttonVariants({
21
22
  size: "sm",
22
23
  variant: "secondary"
23
24
  }), "min-w-0 max-w-full h-6 w-fit rounded-sm border gap-1 cursor-pointer hover:bg-primary/10 hover:text-primary-text focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring"),
24
- role: "button",
25
- tabIndex: 0,
26
25
  onClick: (event) => {
27
26
  event.stopPropagation();
28
27
  onEmailClick(email);
@@ -1,6 +1,7 @@
1
1
  import { FilterContext } from "../context/FilterContext.js";
2
2
  import { filterDialogViewState, filterPopoverViewState, openDialogState, openPopoverState } from "../states/filterStates.js";
3
3
  import { jsx } from "react/jsx-runtime";
4
+ import { useMemo } from "react";
4
5
  import { useSetAtom } from "jotai";
5
6
  // src/modules/filter/components/FilterProvider.tsx
6
7
  const FilterProvider = ({ children, id }) => {
@@ -8,21 +9,27 @@ const FilterProvider = ({ children, id }) => {
8
9
  const setView = useSetAtom(filterPopoverViewState(id));
9
10
  const setDialogView = useSetAtom(filterDialogViewState(id));
10
11
  const setOpenDialog = useSetAtom(openDialogState(id));
11
- const resetFilterState = () => {
12
- setOpen(false);
13
- setView("root");
14
- setDialogView("root");
15
- setOpenDialog(false);
16
- };
17
- return /* @__PURE__ */ jsx(FilterContext.Provider, {
18
- value: {
19
- id,
20
- resetFilterState,
21
- setOpen,
22
- setView,
23
- setDialogView,
24
- setOpenDialog
12
+ const filter = useMemo(() => ({
13
+ id,
14
+ resetFilterState: () => {
15
+ setOpen(false);
16
+ setView("root");
17
+ setDialogView("root");
18
+ setOpenDialog(false);
25
19
  },
20
+ setOpen,
21
+ setView,
22
+ setDialogView,
23
+ setOpenDialog
24
+ }), [
25
+ id,
26
+ setOpen,
27
+ setView,
28
+ setDialogView,
29
+ setOpenDialog
30
+ ]);
31
+ return /* @__PURE__ */ jsx(FilterContext.Provider, {
32
+ value: filter,
26
33
  children
27
34
  });
28
35
  };
@@ -1,4 +1,5 @@
1
1
  import { Combobox } from "../../../components/combobox.js";
2
+ /** Controlled: shows `value`, and reports a pick through `onValueChange`. */
2
3
  export declare const IconPicker: ({ ref, value, onValueChange, ...props }: React.ComponentProps<typeof Combobox.TriggerBase> & {
3
4
  value?: string;
4
5
  onValueChange?: (value: string | null) => void;
@@ -6,12 +6,12 @@ import { IconComponent } from "./IconComponent.js";
6
6
  import { jsx, jsxs } from "react/jsx-runtime";
7
7
  import { useState } from "react";
8
8
  // src/modules/icons/components/IconPicker.tsx
9
+ /** Controlled: shows `value`, and reports a pick through `onValueChange`. */
9
10
  const IconPicker = ({ ref, value, onValueChange, ...props }) => {
10
11
  const { getIcons } = useIcons();
11
- const [_value, setValue] = useState(value);
12
12
  const [open, setOpen] = useState(false);
13
13
  const icons = Object.entries(getIcons());
14
- const selectedFirst = [...icons.filter(([key]) => key === _value), ...icons.filter(([key]) => key !== _value)];
14
+ const selectedFirst = [...icons.filter(([key]) => key === value), ...icons.filter(([key]) => key !== value)];
15
15
  return /* @__PURE__ */ jsxs(Popover, {
16
16
  open,
17
17
  onOpenChange: setOpen,
@@ -20,7 +20,7 @@ const IconPicker = ({ ref, value, onValueChange, ...props }) => {
20
20
  size: "icon",
21
21
  ref,
22
22
  ...props,
23
- children: /* @__PURE__ */ jsx(IconComponent, { name: _value })
23
+ children: /* @__PURE__ */ jsx(IconComponent, { name: value })
24
24
  }), /* @__PURE__ */ jsx(Combobox.Content, {
25
25
  className: "w-60 min-w-60",
26
26
  children: /* @__PURE__ */ jsxs(Command, { children: [/* @__PURE__ */ jsx(Command.Input, { placeholder: "Search icon..." }), /* @__PURE__ */ jsx(Command.List, {
@@ -29,12 +29,11 @@ const IconPicker = ({ ref, value, onValueChange, ...props }) => {
29
29
  className: "flex flex-wrap gap-2",
30
30
  children: selectedFirst.map(([key, Icon]) => /* @__PURE__ */ jsx(Command.Item, {
31
31
  onSelect: () => {
32
- setValue(key);
33
32
  onValueChange?.(key);
34
33
  setOpen(false);
35
34
  },
36
35
  value: key,
37
- checked: _value === key,
36
+ checked: value === key,
38
37
  children: /* @__PURE__ */ jsx(Icon, {})
39
38
  }, key))
40
39
  })
@@ -4,17 +4,23 @@ import { useFullNameField } from "../hooks/useFullNameField.js";
4
4
  import { PopoverScoped } from "../../hotkey/components/PopoverScoped.js";
5
5
  import { RecordTableInlineCell } from "../../record-table/components/RecordTableCellInline.js";
6
6
  import { jsx, jsxs } from "react/jsx-runtime";
7
- import { useState } from "react";
7
+ import { useMemo, useState } from "react";
8
8
  // src/modules/inputs/components/FullNameField.tsx
9
9
  const FullNameFieldProvider = ({ children, firstName, lastName, setFirstName, setLastName }) => {
10
+ const name = useMemo(() => ({
11
+ firstName,
12
+ lastName,
13
+ setFirstName,
14
+ setLastName,
15
+ fullName: `${firstName || ""}${firstName ? " " : ""}${lastName || ""}`
16
+ }), [
17
+ firstName,
18
+ lastName,
19
+ setFirstName,
20
+ setLastName
21
+ ]);
10
22
  return /* @__PURE__ */ jsx(FullNameFieldContext.Provider, {
11
- value: {
12
- firstName,
13
- lastName,
14
- setFirstName,
15
- setLastName,
16
- fullName: `${firstName || ""}${firstName ? " " : ""}${lastName || ""}`
17
- },
23
+ value: name,
18
24
  children
19
25
  });
20
26
  };
@@ -4,17 +4,17 @@ import { TextOverflowTooltip } from "../../../components/text-overflow.js";
4
4
  import { PopoverScoped } from "../../hotkey/components/PopoverScoped.js";
5
5
  import { RecordTableInlineCell } from "../../record-table/components/RecordTableCellInline.js";
6
6
  import { jsx, jsxs } from "react/jsx-runtime";
7
- import { useState } from "react";
7
+ import { useRef, useState } from "react";
8
8
  // src/modules/record-field/components/NumberField.tsx
9
9
  const NumberField = ({ placeholder, value, scope, onSave, onValueChange, formatValue, children, ...props }) => {
10
10
  const fmt = useFormat();
11
11
  const [isOpen, setIsOpen] = useState(false);
12
12
  const [editingValue, setEditingValue] = useState(String(value));
13
- const [isEdited, setIsEdited] = useState(false);
13
+ const edited = useRef(false);
14
14
  const shown = isOpen ? editingValue : formatValue ? formatValue(value) : fmt.number(value);
15
15
  const resetEditing = () => {
16
16
  setEditingValue(String(value));
17
- setIsEdited(false);
17
+ edited.current = false;
18
18
  };
19
19
  const handleAction = (e) => {
20
20
  e?.preventDefault();
@@ -35,7 +35,7 @@ const NumberField = ({ placeholder, value, scope, onSave, onValueChange, formatV
35
35
  onOpenChange: (open) => {
36
36
  setIsOpen(open);
37
37
  if (open) resetEditing();
38
- else if (isEdited) handleAction();
38
+ else if (edited.current) handleAction();
39
39
  },
40
40
  children: [/* @__PURE__ */ jsxs(RecordTableInlineCell.Trigger, {
41
41
  ...props,
@@ -49,7 +49,7 @@ const NumberField = ({ placeholder, value, scope, onSave, onValueChange, formatV
49
49
  const rawValue = e.target.value.replace(/,/g, "");
50
50
  if (/^-?\d*\.?\d*$/.test(rawValue)) {
51
51
  setEditingValue(rawValue);
52
- setIsEdited(true);
52
+ edited.current = true;
53
53
  const numValue = Number(rawValue);
54
54
  if (!isNaN(numValue)) onValueChange?.(numValue);
55
55
  }
@@ -19,7 +19,7 @@ const TextField = ({ ref, placeholder, value, scope, onSave, onValueChange, defa
19
19
  };
20
20
  /** Submits on Enter; Escape is handled by the popover before dismissal. */
21
21
  const handleKeyDown = (e) => {
22
- if (e.key === "Enter") {
22
+ if (e.key === "Enter" && !e.nativeEvent.isComposing) {
23
23
  e.preventDefault();
24
24
  handleAction();
25
25
  }
@@ -5,7 +5,7 @@ import { tablePositionState } from "../states/RecordTableCursorState.js";
5
5
  import "../types/RecordTableCursorTypes.js";
6
6
  import { RecordTableRowSkeleton } from "./RecordTableRowSkeleton.js";
7
7
  import { jsx, jsxs } from "react/jsx-runtime";
8
- import { createContext, useContext, useEffect, useState } from "react";
8
+ import { createContext, useContext, useEffect, useMemo, useState } from "react";
9
9
  import { useStore } from "jotai";
10
10
  import { useDebouncedCallback } from "use-debounce";
11
11
  // src/modules/record-table/components/RecordTableCursor.tsx
@@ -52,14 +52,21 @@ const RecordTableCursorProvider = ({ children, hasPreviousPage, loading, dataLen
52
52
  sessionKey,
53
53
  store
54
54
  ]);
55
+ const cursor = useMemo(() => ({
56
+ viewport,
57
+ startBackwardFetch,
58
+ hasNextPage,
59
+ hasPreviousPage,
60
+ loading
61
+ }), [
62
+ viewport,
63
+ startBackwardFetch,
64
+ hasNextPage,
65
+ hasPreviousPage,
66
+ loading
67
+ ]);
55
68
  return /* @__PURE__ */ jsx(RecordTableCursorContext.Provider, {
56
- value: {
57
- viewport,
58
- startBackwardFetch,
59
- hasNextPage,
60
- hasPreviousPage,
61
- loading
62
- },
69
+ value: cursor,
63
70
  children: /* @__PURE__ */ jsxs(ScrollArea.Root, {
64
71
  className: "h-full w-full pb-2 pr-2 relative",
65
72
  children: [
@@ -3,7 +3,7 @@ import { readRow } from "../utils/rowFields.js";
3
3
  import { RecordTableContainer } from "./RecordTableContainer.js";
4
4
  import { RecordTableDnDProvider } from "./RecordTableDnDProvider.js";
5
5
  import { jsx } from "react/jsx-runtime";
6
- import { createContext, useContext, useId, useState } from "react";
6
+ import { createContext, useContext, useId, useMemo, useState } from "react";
7
7
  import { shallow, useSelector } from "@tanstack/react-store";
8
8
  import { columnOrderingFeature, columnPinningFeature, columnResizingFeature, columnSizingFeature, columnVisibilityFeature, rowSelectionFeature, tableFeatures, useTable } from "@tanstack/react-table";
9
9
  // src/modules/record-table/components/RecordTableProvider.tsx
@@ -53,13 +53,18 @@ const RecordTableProvider = ({ children, columns, data, stickyColumns, tableId,
53
53
  getRowId
54
54
  }, () => null);
55
55
  const headPrefix = useId();
56
+ const context = useMemo(() => ({
57
+ table: shared,
58
+ columnSelectorOpen,
59
+ setColumnSelectorOpen,
60
+ headId: (columnId) => `${headPrefix}-head-${columnId}`
61
+ }), [
62
+ shared,
63
+ columnSelectorOpen,
64
+ headPrefix
65
+ ]);
56
66
  return /* @__PURE__ */ jsx(RecordTableContext.Provider, {
57
- value: {
58
- table: shared,
59
- columnSelectorOpen,
60
- setColumnSelectorOpen,
61
- headId: (columnId) => `${headPrefix}-head-${columnId}`
62
- },
67
+ value: context,
63
68
  children: /* @__PURE__ */ jsx(RecordTableDnDProvider, {
64
69
  setColumnOrder,
65
70
  children: /* @__PURE__ */ jsx(RecordTableContainer, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erxes/ui",
3
- "version": "4.0.0-v2.4",
3
+ "version": "4.0.0-v2.5",
4
4
  "private": false,
5
5
  "description": "erxes design system: UI primitives, layout, hooks and shared frontend state",
6
6
  "license": "AGPL-3.0-only",