@erxes/ui 4.0.0-v2.1 → 4.0.0-v2.2

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/README.md CHANGED
@@ -24,9 +24,12 @@ Only what something uses:
24
24
  - what web imports,
25
25
  - what plugin UIs import (the HR plugin is the first consumer),
26
26
  - the plugin API in the plugin skills: `getPluginRuntime`, `pluginFetch`, `pluginJson`,
27
- `useLiveSignal`, `RecordTimeline`, `getPluginAssetsUrl` and the `IUIConfig` types,
27
+ `useLiveSignal`, `RecordTimeline`, `getPluginAssetsUrl`, `addPluginStyles` and the `IUIConfig` types,
28
28
  - the design-system primitives in `src/components` (Accordion, Card, Slider …), even unused,
29
- because plugins build on them.
29
+ because plugins build on them,
30
+ - the pickers in `src/modules/pickers`: `EntityPicker`, and `SelectMember`, `MemberInline` and
31
+ `useMembersById`, which take `memberQueries` from `@erxes/core-contract/client`. They read
32
+ through TanStack query options, so erxes-ui imports nothing from core.
30
33
 
31
34
  Anything else is removed, not kept "in case". Before you remove an export, check the HR plugin
32
35
  UI and `.agents/skills/plugin-contract/SKILL.md`.
@@ -80,7 +80,7 @@ const SheetHeader = ({ className, children, ...props }) => {
80
80
  const items = React.Children.toArray(children);
81
81
  const close = actions ? items.find((child) => React.isValidElement(child) && child.type === SheetClose) : void 0;
82
82
  return /* @__PURE__ */ jsx("div", {
83
- className: cn("flex px-5 h-10 items-center bg-background border-b flex-none", className),
83
+ className: cn("flex flex-wrap items-center gap-x-2 gap-y-1 px-5 py-2 min-h-10 bg-background border-b flex-none", className),
84
84
  ...props,
85
85
  children: actions ? /* @__PURE__ */ jsxs(Fragment, { children: [items.filter((child) => child !== close), /* @__PURE__ */ jsxs("div", {
86
86
  className: "ml-auto flex shrink-0 items-center gap-1 [&>button]:ml-0",
@@ -97,11 +97,11 @@ const SheetFooter = ({ className, ...props }) => /* @__PURE__ */ jsx("div", {
97
97
  ...props
98
98
  });
99
99
  const SheetTitle = ({ className, ...props }) => /* @__PURE__ */ jsx(Dialog.Title, {
100
- className: cn("text-lg font-semibold text-foreground leading-none", className),
100
+ className: cn("min-w-0 flex-1 text-lg font-semibold text-foreground leading-tight", className),
101
101
  ...props
102
102
  });
103
103
  const SheetDescription = ({ className, ...props }) => /* @__PURE__ */ jsx(Dialog.Description, {
104
- className: cn("text-sm leading-none text-muted-foreground mt-2", className),
104
+ className: cn("order-last basis-full text-sm leading-snug text-muted-foreground", className),
105
105
  ...props
106
106
  });
107
107
  const Sheet = Object.assign(SheetRoot, {
@@ -1,13 +1,15 @@
1
1
  import { Button } from "../button.js";
2
2
  import { Separator } from "../separator.js";
3
+ import { useIsMobile } from "../../hooks/use-mobile.js";
3
4
  import { cn, mergeRefs } from "../../lib/utils.js";
4
- import { sidebarPanelOpenState } from "../../state/sidebarPanelState.js";
5
+ import { sidebarPanelOpenState, sidebarPanelOpenedAtState } from "../../state/sidebarPanelState.js";
5
6
  import { IconLayoutSidebarLeftCollapse, IconLayoutSidebarLeftExpand } from "@tabler/icons-react";
6
7
  import { jsx, jsxs } from "react/jsx-runtime";
7
8
  import React from "react";
8
9
  import { useTranslation } from "react-i18next";
9
- import { useAtom, useAtomValue } from "jotai";
10
+ import { useAtom } from "jotai";
10
11
  import { createPortal } from "react-dom";
12
+ import { useLocation } from "react-router-dom";
11
13
  // src/components/sidebar/panel.tsx
12
14
  const SIDEBAR_PANEL_SLOT = "[data-sidebar-panel-slot]";
13
15
  const findSidebarPanelSlot = (panel) => {
@@ -20,6 +22,26 @@ const findSidebarPanelSlot = (panel) => {
20
22
  return null;
21
23
  };
22
24
  const SidebarPanelInnerTriggerHiddenContext = React.createContext(false);
25
+ /**
26
+ * Whether the panel is open. On a desktop it stays as the member left it. On a phone it covers
27
+ * the page, so it starts closed and closes once you pick a page in it.
28
+ */
29
+ const useSidebarPanelOpen = () => {
30
+ const isMobile = useIsMobile();
31
+ const { pathname } = useLocation();
32
+ const [desktopOpen, setDesktopOpen] = useAtom(sidebarPanelOpenState);
33
+ const [openedAt, setOpenedAt] = useAtom(sidebarPanelOpenedAtState);
34
+ if (!isMobile) return {
35
+ isMobile,
36
+ open: desktopOpen,
37
+ setOpen: setDesktopOpen
38
+ };
39
+ return {
40
+ isMobile,
41
+ open: openedAt === pathname,
42
+ setOpen: (open) => setOpenedAt(open ? pathname : null)
43
+ };
44
+ };
23
45
  const isSlotAbovePanel = (slot, panel) => Boolean(panel && slot.compareDocumentPosition(panel) & Node.DOCUMENT_POSITION_FOLLOWING);
24
46
  const useSidebarPanelSlot = (panelRef, open) => {
25
47
  const [slot, setSlot] = React.useState(null);
@@ -46,7 +68,7 @@ const useSidebarPanelSlot = (panelRef, open) => {
46
68
  };
47
69
  const SidebarPanelTrigger = ({ ref, className, onClick, ...props }) => {
48
70
  const hidden = React.useContext(SidebarPanelInnerTriggerHiddenContext);
49
- const [open, setOpen] = useAtom(sidebarPanelOpenState);
71
+ const { open, setOpen } = useSidebarPanelOpen();
50
72
  const { t } = useTranslation("common", { keyPrefix: "navigation" });
51
73
  const toggleLabel = open ? t("collapse-sidebar", "Collapse sidebar") : t("expand-sidebar", "Expand sidebar");
52
74
  if (hidden) return null;
@@ -67,7 +89,7 @@ const SidebarPanelTrigger = ({ ref, className, onClick, ...props }) => {
67
89
  });
68
90
  };
69
91
  const SidebarPanel = ({ ref, className, children, label, actions, ...props }) => {
70
- const open = useAtomValue(sidebarPanelOpenState);
92
+ const { isMobile, open } = useSidebarPanelOpen();
71
93
  const panelRef = React.useRef(null);
72
94
  const { slot, claimed } = useSidebarPanelSlot(panelRef, open);
73
95
  const triggerInSlot = Boolean(slot && claimed);
@@ -75,7 +97,7 @@ const SidebarPanel = ({ ref, className, children, label, actions, ...props }) =>
75
97
  ref: mergeRefs(panelRef, ref),
76
98
  "data-sidebar": "panel",
77
99
  "data-state": open ? "expanded" : "collapsed",
78
- className: cn("relative flex h-full w-60 flex-col overflow-hidden border-r bg-sidebar text-foreground transition-layout duration-300 ease-out-quint motion-reduce:transition-none", className, !open && "w-0! overflow-visible border-0!"),
100
+ className: cn("relative flex h-full w-60 flex-col overflow-hidden border-r bg-sidebar text-foreground transition-layout duration-300 ease-out-quint motion-reduce:transition-none", className, isMobile && "absolute inset-y-0 left-0 z-20 shadow-lg", !open && "w-0! overflow-visible border-0! shadow-none"),
79
101
  ...props,
80
102
  children: [
81
103
  slot && claimed && createPortal(/* @__PURE__ */ jsxs("span", {
@@ -83,13 +105,13 @@ const SidebarPanel = ({ ref, className, children, label, actions, ...props }) =>
83
105
  children: [/* @__PURE__ */ jsx(SidebarPanelTrigger, { className: "size-7" }), /* @__PURE__ */ jsx(Separator.Inline, {})]
84
106
  }), slot),
85
107
  !open && !slot && /* @__PURE__ */ jsx("div", {
86
- className: "absolute top-2.5 left-2 z-20",
108
+ className: "absolute top-2.5 left-2 z-20 navigation-collapsed:left-12",
87
109
  children: /* @__PURE__ */ jsx(SidebarPanelTrigger, { className: "size-7 border bg-background shadow-xs" })
88
110
  }),
89
111
  /* @__PURE__ */ jsxs(SidebarPanelInnerTriggerHiddenContext.Provider, {
90
112
  value: triggerInSlot,
91
113
  children: [open && label && /* @__PURE__ */ jsxs("div", {
92
- className: "flex h-10 shrink-0 items-center gap-1 px-2",
114
+ className: "flex h-10 shrink-0 items-center gap-1 px-2 navigation-collapsed:pl-12",
93
115
  children: [
94
116
  /* @__PURE__ */ jsx("span", {
95
117
  className: "min-w-0 flex-1 truncate px-2 text-sm font-medium",
@@ -5,6 +5,9 @@
5
5
  * it never bundles a second React, router, query client or erxes-ui. A shared
6
6
  * name matches only that exact import, so React's entry points are listed one
7
7
  * by one: a remote that bundles its own `react/jsx-runtime` breaks as soon as
8
- * its React differs from the host's.
8
+ * its React differs from the host's. `@tanstack/query-core` is listed with
9
+ * `@tanstack/react-query` because `@orpc/tanstack-query` imports it directly: a
10
+ * plugin's own copy would hold a different `skipToken`, so `input: skipToken`
11
+ * (from the host's `@tanstack/react-query`) would run the query, not disable it.
9
12
  */
10
13
  export declare const SHARED: string[];
@@ -6,7 +6,10 @@
6
6
  * it never bundles a second React, router, query client or erxes-ui. A shared
7
7
  * name matches only that exact import, so React's entry points are listed one
8
8
  * by one: a remote that bundles its own `react/jsx-runtime` breaks as soon as
9
- * its React differs from the host's.
9
+ * its React differs from the host's. `@tanstack/query-core` is listed with
10
+ * `@tanstack/react-query` because `@orpc/tanstack-query` imports it directly: a
11
+ * plugin's own copy would hold a different `skipToken`, so `input: skipToken`
12
+ * (from the host's `@tanstack/react-query`) would run the query, not disable it.
10
13
  */
11
14
  const SHARED = [
12
15
  "react",
@@ -19,6 +22,7 @@ const SHARED = [
19
22
  "erxes-ui",
20
23
  "jotai",
21
24
  "react-i18next",
22
- "@tanstack/react-query"
25
+ "@tanstack/react-query",
26
+ "@tanstack/query-core"
23
27
  ];
24
28
  export { SHARED };
package/dist/index.d.ts CHANGED
@@ -82,6 +82,9 @@ import { AppLayout, AppLayoutFooterLink } from "./modules/layout/components/AppL
82
82
  import { PageContainer, PageSubHeader } from "./modules/layout/components/Page.js";
83
83
  import { PageHeader } from "./modules/layout/components/PageHeader.js";
84
84
  import { NavigationMenuLinkItem } from "./modules/navigation-menu/components/NavigationMenu.js";
85
+ import { EntityPicker } from "./modules/pickers/EntityPicker.js";
86
+ import { Member, MemberQueries, memberName, useMembersById } from "./modules/pickers/members.js";
87
+ import { MemberInline, SelectMember } from "./modules/pickers/SelectMember.js";
85
88
  import { NumberField } from "./modules/record-field/components/NumberField.js";
86
89
  import { TextField } from "./modules/record-field/components/TextField.js";
87
90
  import { PhoneInput } from "./modules/record-field/meta-inputs/components/PhoneInput.js";
@@ -100,5 +103,6 @@ import { formatPhoneNumber } from "./utils/format/formatPhoneNumber.js";
100
103
  import { getPluginAssetsUrl } from "./utils/getPluginAssetsUrl.js";
101
104
  import { jsonOf } from "./utils/json.js";
102
105
  import { PluginLiveMessage, PluginRuntime, PluginSession, getPluginRuntime, pluginFetch, pluginJson, setPluginRuntime, useLiveSignal } from "./utils/plugin-runtime.js";
106
+ import { addPluginStyles } from "./utils/plugin-styles.js";
103
107
  import { RecordTimeline, RecordTimelineProps, setRecordTimeline } from "./utils/record-timeline.js";
104
- export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, type AvatarProps, BackgroundGradientAnimation, Badge, type BadgeProps, Breadcrumb, Button, type ButtonProps, Calendar, type CalendarProps, Card, type ChartConfig, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, ContextMenu, CopyText, DateInput, DatePicker, Dialog, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EnumCursorDirection, type FileStorageAdapter, Filter, Form, FullNameField, FullNameValue, HoverCard, type IUIConfig, IconComponent, IconPicker, IconsProvider, InfoCard, Input, InputGroup, Kbd, Label, type MultiSelectOption, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PhoneDisplay, PhoneField, PhoneInput, type PluginLiveMessage, type PluginRuntime, type PluginSession, Popover, PopoverScoped, RadioGroup, RecordTable, type RecordTableColumnDef, RecordTableInlineCell, RecordTimeline, type RecordTimelineProps, RelativeDateDisplay, Resizable, ScrollArea, Select, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, type TActivityRowProps, type TDashboardWidgetPreview, type TPropertyInputMeta, type TPropertyInputProps, TabButton, Table, Tabs, TextField, TextOverflowTooltip, Textarea, type ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, badgeVariants, buttonVariants, cn, editorText, formatPhoneNumber, getPluginAssetsUrl, getPluginRuntime, isUndefinedOrNull, jsonOf, pluginFetch, pluginJson, readImage, setFileStorage, setPluginRuntime, setRecordTimeline, themeState, toast, useConfirm, useFilterContext, useFilterQueryState, useLiveSignal, useMultiQueryState, usePreviousHotkeyScope, useQueryState, useScopedHotkeys, useToast, useUpload };
108
+ export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, type AvatarProps, BackgroundGradientAnimation, Badge, type BadgeProps, Breadcrumb, Button, type ButtonProps, Calendar, type CalendarProps, Card, type ChartConfig, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, ContextMenu, CopyText, DateInput, DatePicker, Dialog, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, type FileStorageAdapter, Filter, Form, FullNameField, FullNameValue, HoverCard, type IUIConfig, IconComponent, IconPicker, IconsProvider, InfoCard, Input, InputGroup, Kbd, Label, type Member, MemberInline, type MemberQueries, type MultiSelectOption, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PhoneDisplay, PhoneField, PhoneInput, type PluginLiveMessage, type PluginRuntime, type PluginSession, Popover, PopoverScoped, RadioGroup, RecordTable, type RecordTableColumnDef, RecordTableInlineCell, RecordTimeline, type RecordTimelineProps, RelativeDateDisplay, Resizable, ScrollArea, Select, SelectMember, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, type TActivityRowProps, type TDashboardWidgetPreview, type TPropertyInputMeta, type TPropertyInputProps, TabButton, Table, Tabs, TextField, TextOverflowTooltip, Textarea, type ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, addPluginStyles, badgeVariants, buttonVariants, cn, editorText, formatPhoneNumber, getPluginAssetsUrl, getPluginRuntime, isUndefinedOrNull, jsonOf, memberName, pluginFetch, pluginJson, readImage, setFileStorage, setPluginRuntime, setRecordTimeline, themeState, toast, useConfirm, useFilterContext, useFilterQueryState, useLiveSignal, useMembersById, useMultiQueryState, usePreviousHotkeyScope, useQueryState, useScopedHotkeys, useToast, useUpload };
package/dist/index.js CHANGED
@@ -80,6 +80,9 @@ import { AppLayout, AppLayoutFooterLink } from "./modules/layout/components/AppL
80
80
  import { PageContainer, PageSubHeader } from "./modules/layout/components/Page.js";
81
81
  import { PageHeader } from "./modules/layout/components/PageHeader.js";
82
82
  import { NavigationMenuLinkItem } from "./modules/navigation-menu/components/NavigationMenu.js";
83
+ import { EntityPicker } from "./modules/pickers/EntityPicker.js";
84
+ import { memberName, useMembersById } from "./modules/pickers/members.js";
85
+ import { MemberInline, SelectMember } from "./modules/pickers/SelectMember.js";
83
86
  import { NumberField } from "./modules/record-field/components/NumberField.js";
84
87
  import { TextField } from "./modules/record-field/components/TextField.js";
85
88
  import { PhoneInput } from "./modules/record-field/meta-inputs/components/PhoneInput.js";
@@ -95,5 +98,6 @@ import { formatPhoneNumber } from "./utils/format/formatPhoneNumber.js";
95
98
  import { getPluginAssetsUrl } from "./utils/getPluginAssetsUrl.js";
96
99
  import { jsonOf } from "./utils/json.js";
97
100
  import { getPluginRuntime, pluginFetch, pluginJson, setPluginRuntime, useLiveSignal } from "./utils/plugin-runtime.js";
101
+ import { addPluginStyles } from "./utils/plugin-styles.js";
98
102
  import { RecordTimeline, setRecordTimeline } from "./utils/record-timeline.js";
99
- export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, BackgroundGradientAnimation, Badge, Breadcrumb, Button, Calendar, Card, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, ContextMenu, CopyText, DateInput, DatePicker, Dialog, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EnumCursorDirection, Filter, Form, FullNameField, FullNameValue, HoverCard, IconComponent, IconPicker, IconsProvider, InfoCard, Input, InputGroup, Kbd, Label, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PhoneDisplay, PhoneField, PhoneInput, Popover, PopoverScoped, RadioGroup, RecordTable, RecordTableInlineCell, RecordTimeline, RelativeDateDisplay, Resizable, ScrollArea, Select, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, TabButton, Table, Tabs, TextField, TextOverflowTooltip, Textarea, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, badgeVariants, buttonVariants, cn, editorText, formatPhoneNumber, getPluginAssetsUrl, getPluginRuntime, isUndefinedOrNull, jsonOf, pluginFetch, pluginJson, readImage, setFileStorage, setPluginRuntime, setRecordTimeline, themeState, toast, useConfirm, useFilterContext, useFilterQueryState, useLiveSignal, useMultiQueryState, usePreviousHotkeyScope, useQueryState, useScopedHotkeys, useToast, useUpload };
103
+ export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, BackgroundGradientAnimation, Badge, Breadcrumb, Button, Calendar, Card, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, ContextMenu, CopyText, DateInput, DatePicker, Dialog, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, Filter, Form, FullNameField, FullNameValue, HoverCard, IconComponent, IconPicker, IconsProvider, InfoCard, Input, InputGroup, Kbd, Label, MemberInline, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PhoneDisplay, PhoneField, PhoneInput, Popover, PopoverScoped, RadioGroup, RecordTable, RecordTableInlineCell, RecordTimeline, RelativeDateDisplay, Resizable, ScrollArea, Select, SelectMember, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, TabButton, Table, Tabs, TextField, TextOverflowTooltip, Textarea, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, addPluginStyles, badgeVariants, buttonVariants, cn, editorText, formatPhoneNumber, getPluginAssetsUrl, getPluginRuntime, isUndefinedOrNull, jsonOf, memberName, pluginFetch, pluginJson, readImage, setFileStorage, setPluginRuntime, setRecordTimeline, themeState, toast, useConfirm, useFilterContext, useFilterQueryState, useLiveSignal, useMembersById, useMultiQueryState, usePreviousHotkeyScope, useQueryState, useScopedHotkeys, useToast, useUpload };
@@ -25,11 +25,14 @@ const pageHeaderStartVariants = cva("flex flex-none items-center gap-2", {
25
25
  } },
26
26
  defaultVariants: { variant: "default" }
27
27
  });
28
- const PageHeaderStart = ({ ref, children, className, variant, ...props }) => /* @__PURE__ */ jsx("div", {
28
+ const PageHeaderStart = ({ ref, children, className, variant, ...props }) => /* @__PURE__ */ jsxs("div", {
29
29
  ref,
30
30
  className: cn(pageHeaderStartVariants({ variant }), className),
31
31
  ...props,
32
- children
32
+ children: [/* @__PURE__ */ jsx("span", {
33
+ "data-sidebar-panel-slot": "",
34
+ className: "contents"
35
+ }), children]
33
36
  });
34
37
  const PageHeaderEnd = ({ ref, children, className, ...props }) => /* @__PURE__ */ jsx("div", {
35
38
  ref,
@@ -0,0 +1,30 @@
1
+ import { ReactNode } from "react";
2
+ interface EntityPickerProps<T, K extends string> {
3
+ items: T[];
4
+ /** The id and the text a search matches. */
5
+ itemKey: (item: T) => {
6
+ id: K;
7
+ label: string;
8
+ };
9
+ /** How an item reads in the list; its label by default. */
10
+ renderItem?: (item: T) => ReactNode;
11
+ value: K[];
12
+ /** The picked ids. One pick replaces the value unless `multiple`, where it toggles. */
13
+ onValueChange: (ids: K[]) => void;
14
+ multiple?: boolean;
15
+ /** Items keep their order (a tree reads top down); otherwise the picked ones come first. */
16
+ keepOrder?: boolean;
17
+ loading?: boolean;
18
+ error?: Error | null;
19
+ /** Searching on the server: `items` are already the matches, so they are not filtered here. */
20
+ onSearchChange?: (search: string) => void;
21
+ searchPlaceholder?: string;
22
+ /** A first row that picks nothing. */
23
+ noneLabel?: string;
24
+ /** Above the list, e.g. the picked tags as badges. */
25
+ header?: ReactNode;
26
+ /** A row for what was searched, e.g. "Add tag: VIP"; `clear` empties the search. */
27
+ renderCreate?: (search: string, clear: () => void) => ReactNode;
28
+ }
29
+ export declare const EntityPicker: <T, K extends string = string>({ items, itemKey, renderItem, value, onValueChange, multiple, keepOrder, loading, error, onSearchChange, searchPlaceholder, noneLabel, header, renderCreate }: EntityPickerProps<T, K>) => import("react").JSX.Element;
30
+ export {};
@@ -0,0 +1,60 @@
1
+ import { Combobox } from "../../components/combobox.js";
2
+ import { Command } from "../../components/command.js";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { useState } from "react";
5
+ // src/modules/pickers/EntityPicker.tsx
6
+ const EntityPicker = ({ items, itemKey, renderItem, value, onValueChange, multiple, keepOrder, loading, error, onSearchChange, searchPlaceholder, noneLabel, header, renderCreate }) => {
7
+ const [search, setSearch] = useState("");
8
+ const [pickedAtOpen] = useState(value);
9
+ const term = search.trim().toLowerCase();
10
+ const matches = items.map((item) => ({
11
+ item,
12
+ ...itemKey(item)
13
+ })).filter((row) => onSearchChange !== void 0 || row.label.toLowerCase().includes(term));
14
+ const rows = keepOrder ? matches : matches.toSorted((a, b) => Number(pickedAtOpen.includes(b.id)) - Number(pickedAtOpen.includes(a.id)));
15
+ const pick = (id) => onValueChange(!multiple ? [id] : value.includes(id) ? value.filter((item) => item !== id) : [...value, id]);
16
+ const changeSearch = (next) => {
17
+ setSearch(next);
18
+ onSearchChange?.(next);
19
+ };
20
+ return /* @__PURE__ */ jsxs(Command, {
21
+ shouldFilter: false,
22
+ children: [
23
+ /* @__PURE__ */ jsx(Command.Input, {
24
+ value: search,
25
+ onValueChange: changeSearch,
26
+ placeholder: searchPlaceholder,
27
+ variant: "secondary",
28
+ wrapperClassName: "flex-auto",
29
+ focusOnMount: true
30
+ }),
31
+ header,
32
+ error && /* @__PURE__ */ jsx("p", {
33
+ role: "alert",
34
+ className: "text-destructive px-3 py-2 text-sm",
35
+ children: error.message
36
+ }),
37
+ /* @__PURE__ */ jsxs(Command.List, {
38
+ className: "max-h-75 overflow-y-auto",
39
+ children: [
40
+ noneLabel && !term && /* @__PURE__ */ jsxs(Command.Item, {
41
+ value: "__none__",
42
+ onSelect: () => onValueChange([]),
43
+ children: [/* @__PURE__ */ jsx("span", {
44
+ className: "text-muted-foreground",
45
+ children: noneLabel
46
+ }), /* @__PURE__ */ jsx(Combobox.Check, { checked: value.length === 0 })]
47
+ }),
48
+ renderCreate?.(search.trim(), () => changeSearch("")),
49
+ !error && /* @__PURE__ */ jsx(Combobox.Empty, { loading }),
50
+ rows.map(({ item, id, label }) => /* @__PURE__ */ jsxs(Command.Item, {
51
+ value: id,
52
+ onSelect: () => pick(id),
53
+ children: [renderItem ? renderItem(item) : label, /* @__PURE__ */ jsx(Combobox.Check, { checked: value.includes(id) })]
54
+ }, id))
55
+ ]
56
+ })
57
+ ]
58
+ });
59
+ };
60
+ export { EntityPicker };
@@ -0,0 +1,41 @@
1
+ import { AvatarProps } from "../../components/avatar.js";
2
+ import { Combobox } from "../../components/combobox.js";
3
+ import { RecordTableInlineCell } from "../record-table/components/RecordTableCellInline.js";
4
+ import { MemberQueries } from "./members.js";
5
+ import { ComponentProps, ComponentRef, RefAttributes } from "react";
6
+ /** One member by id: avatar and name, or the placeholder when there is none. */
7
+ export declare const MemberInline: ({ memberId, members, placeholder, size, className }: {
8
+ memberId: string | null | undefined;
9
+ members: MemberQueries;
10
+ placeholder?: string;
11
+ size?: AvatarProps['size'];
12
+ className?: string;
13
+ }) => import("react").JSX.Element;
14
+ interface SelectMemberProps {
15
+ value: string | null | undefined;
16
+ onValueChange: (id: string | null) => void;
17
+ /** Where the members come from: `memberQueries` from `@erxes/core-contract/client`. */
18
+ members: MemberQueries;
19
+ placeholder?: string;
20
+ /** A first row that picks no member, e.g. "Anyone" on a filter. */
21
+ noneLabel?: string;
22
+ }
23
+ /** The member as a record table cell; click to pick another. */
24
+ declare const SelectMemberInlineCell: ({ ref, value, onValueChange, members, noneLabel, scope, placeholder, size, className, variant, id, 'aria-label': ariaLabel }: SelectMemberProps & {
25
+ scope?: string;
26
+ size?: AvatarProps['size'];
27
+ className?: string;
28
+ /** `field` beside its label in a side panel; a table cell by default. */
29
+ variant?: ComponentProps<typeof RecordTableInlineCell.Trigger>['variant'];
30
+ id?: string;
31
+ /** Names the picker while it shows no member. */
32
+ 'aria-label'?: string;
33
+ } & RefAttributes<ComponentRef<typeof RecordTableInlineCell.Trigger>>) => import("react").JSX.Element;
34
+ /** A member picker button; its other props (an id, `Form.Control`'s aria wiring) go to the button. */
35
+ declare const SelectMemberField: ({ value, onValueChange, members, noneLabel, placeholder, className, ...trigger }: SelectMemberProps & Omit<ComponentProps<typeof Combobox.Trigger>, 'value' | 'children' | 'placeholder'>) => import("react").JSX.Element;
36
+ /** The member picker as a table cell and as a field. */
37
+ export declare const SelectMember: {
38
+ InlineCell: typeof SelectMemberInlineCell;
39
+ Field: typeof SelectMemberField;
40
+ };
41
+ export {};
@@ -0,0 +1,122 @@
1
+ import { Avatar } from "../../components/avatar.js";
2
+ import { Badge } from "../../components/badge.js";
3
+ import { Combobox } from "../../components/combobox.js";
4
+ import { Popover } from "../../components/popover.js";
5
+ import { cn } from "../../lib/utils.js";
6
+ import { readImage } from "../../utils/core.js";
7
+ import { PopoverScoped } from "../hotkey/components/PopoverScoped.js";
8
+ import { RecordTableInlineCell } from "../record-table/components/RecordTableCellInline.js";
9
+ import { EntityPicker } from "./EntityPicker.js";
10
+ import { memberName, useMembersById } from "./members.js";
11
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
+ import { useState } from "react";
13
+ import { useQuery } from "@tanstack/react-query";
14
+ // src/modules/pickers/SelectMember.tsx
15
+ /** A member's name, with an "Inactive" badge for disabled ones. */
16
+ const MemberLabel = ({ member }) => member.status === "active" ? /* @__PURE__ */ jsx(Fragment, { children: memberName(member) }) : /* @__PURE__ */ jsxs("span", {
17
+ className: "inline-flex items-center gap-1",
18
+ children: [/* @__PURE__ */ jsx("span", { children: memberName(member) }), /* @__PURE__ */ jsx(Badge, {
19
+ variant: "destructive",
20
+ size: "sm",
21
+ className: "h-5 shrink-0",
22
+ children: "Inactive"
23
+ })]
24
+ });
25
+ /** One member by id: avatar and name, or the placeholder when there is none. */
26
+ const MemberInline = ({ memberId, members, placeholder, size = "lg", className }) => {
27
+ const member = useMembersById([memberId], members).get(memberId ?? "");
28
+ return /* @__PURE__ */ jsxs(Fragment, { children: [member && /* @__PURE__ */ jsxs(Avatar, {
29
+ size,
30
+ children: [/* @__PURE__ */ jsx(Avatar.Image, { src: readImage(member.avatarUrl) }), /* @__PURE__ */ jsx(Avatar.Fallback, { children: memberName(member).charAt(0) })]
31
+ }), /* @__PURE__ */ jsx(Combobox.Value, {
32
+ value: member && /* @__PURE__ */ jsx(MemberLabel, { member }),
33
+ loading: Boolean(memberId) && !member,
34
+ placeholder: placeholder ?? "Select a member",
35
+ className
36
+ })] });
37
+ };
38
+ /** Active members, searched on their name and email; picking one reports its id. */
39
+ const MemberList = ({ value, members, noneLabel, onPick }) => {
40
+ const team = useQuery(members.team);
41
+ return /* @__PURE__ */ jsx(EntityPicker, {
42
+ items: team.data?.data ?? [],
43
+ itemKey: (member) => ({
44
+ id: member.id,
45
+ label: `${memberName(member)} ${member.email}`
46
+ }),
47
+ renderItem: (member) => /* @__PURE__ */ jsx(MemberInline, {
48
+ memberId: member.id,
49
+ members,
50
+ placeholder: "Unnamed user"
51
+ }),
52
+ value: value ? [value] : [],
53
+ onValueChange: ([id]) => onPick(id ?? null),
54
+ noneLabel,
55
+ loading: team.isPending,
56
+ error: team.error
57
+ });
58
+ };
59
+ /** The member as a record table cell; click to pick another. */
60
+ const SelectMemberInlineCell = ({ ref, value, onValueChange, members, noneLabel, scope, placeholder, size = "lg", className, variant, id, "aria-label": ariaLabel }) => {
61
+ const [open, setOpen] = useState(false);
62
+ return /* @__PURE__ */ jsxs(PopoverScoped, {
63
+ scope,
64
+ open,
65
+ onOpenChange: setOpen,
66
+ children: [/* @__PURE__ */ jsx(RecordTableInlineCell.Trigger, {
67
+ ref,
68
+ id,
69
+ "aria-label": ariaLabel,
70
+ variant,
71
+ className,
72
+ children: /* @__PURE__ */ jsx("span", {
73
+ className: "contents text-xs",
74
+ children: /* @__PURE__ */ jsx(MemberInline, {
75
+ memberId: value,
76
+ members,
77
+ placeholder: placeholder ?? "",
78
+ size
79
+ })
80
+ })
81
+ }), /* @__PURE__ */ jsx(RecordTableInlineCell.Content, { children: /* @__PURE__ */ jsx(MemberList, {
82
+ value,
83
+ members,
84
+ noneLabel,
85
+ onPick: (next) => {
86
+ onValueChange(next);
87
+ setOpen(false);
88
+ }
89
+ }) })]
90
+ });
91
+ };
92
+ /** A member picker button; its other props (an id, `Form.Control`'s aria wiring) go to the button. */
93
+ const SelectMemberField = ({ value, onValueChange, members, noneLabel, placeholder, className, ...trigger }) => {
94
+ const [open, setOpen] = useState(false);
95
+ return /* @__PURE__ */ jsxs(Popover, {
96
+ open,
97
+ onOpenChange: setOpen,
98
+ children: [/* @__PURE__ */ jsx(Combobox.Trigger, {
99
+ ...trigger,
100
+ className: cn("w-full", className),
101
+ children: /* @__PURE__ */ jsx(MemberInline, {
102
+ memberId: value,
103
+ members,
104
+ placeholder
105
+ })
106
+ }), /* @__PURE__ */ jsx(Combobox.Content, { children: /* @__PURE__ */ jsx(MemberList, {
107
+ value,
108
+ members,
109
+ noneLabel,
110
+ onPick: (next) => {
111
+ onValueChange(next);
112
+ setOpen(false);
113
+ }
114
+ }) })]
115
+ });
116
+ };
117
+ /** The member picker as a table cell and as a field. */
118
+ const SelectMember = {
119
+ InlineCell: SelectMemberInlineCell,
120
+ Field: SelectMemberField
121
+ };
122
+ export { MemberInline, SelectMember };
@@ -0,0 +1,30 @@
1
+ import { UseQueryOptions } from "@tanstack/react-query";
2
+ /** A team member as the pickers show one: core's `User` has these fields and more. */
3
+ export interface Member {
4
+ id: string;
5
+ email: string;
6
+ fullName: string | null;
7
+ username: string | null;
8
+ avatarUrl: string | null;
9
+ status: string;
10
+ }
11
+ type MemberQuery = UseQueryOptions<{
12
+ data: Member[];
13
+ }, Error, {
14
+ data: Member[];
15
+ }>;
16
+ /**
17
+ * Where members come from, as TanStack query options. erxes-ui knows nothing of core: web and
18
+ * plugin UIs pass `memberQueries` from `@erxes/core-contract/client`.
19
+ */
20
+ export interface MemberQueries {
21
+ /** The active team: every picker's list, and the names most screens show. */
22
+ team: MemberQuery;
23
+ /** Members by id, for those outside the active team (disabled ones). */
24
+ byIds: (ids: string[]) => MemberQuery;
25
+ }
26
+ /** How a member reads: the display name, else the username, else the email. */
27
+ export declare const memberName: (member: Pick<Member, 'fullName' | 'username' | 'email'>) => string;
28
+ /** Members by id, any status. The active team answers most; only the rest are fetched. */
29
+ export declare const useMembersById: (ids: (string | null | undefined)[], members: MemberQueries) => Map<string, Member>;
30
+ export {};
@@ -0,0 +1,18 @@
1
+ import { useMemo } from "react";
2
+ import { keepPreviousData, useQuery } from "@tanstack/react-query";
3
+ // src/modules/pickers/members.ts
4
+ /** How a member reads: the display name, else the username, else the email. */
5
+ const memberName = (member) => member.fullName || member.username || member.email;
6
+ /** Members by id, any status. The active team answers most; only the rest are fetched. */
7
+ const useMembersById = (ids, members) => {
8
+ const team = useQuery(members.team);
9
+ const known = useMemo(() => new Set((team.data?.data ?? []).map((user) => user.id)), [team.data]);
10
+ const wanted = useMemo(() => [...new Set(ids.filter((id) => Boolean(id) && !known.has(id ?? "")))].toSorted((a, b) => a.localeCompare(b)), [ids, known]);
11
+ const others = useQuery({
12
+ ...members.byIds(wanted),
13
+ enabled: team.isFetched && wanted.length > 0,
14
+ placeholderData: keepPreviousData
15
+ });
16
+ return useMemo(() => new Map([...team.data?.data ?? [], ...others.data?.data ?? []].map((user) => [user.id, user])), [team.data, others.data]);
17
+ };
18
+ export { memberName, useMembersById };
@@ -1 +1,5 @@
1
- export declare const sidebarPanelOpenState: import("jotai").WritableAtom<boolean, [boolean | typeof import("jotai/utils").RESET | ((prev: boolean) => boolean | typeof import("jotai/utils").RESET)], void>;
1
+ export declare const sidebarPanelOpenState: import("jotai").WritableAtom<boolean, [boolean | typeof import("jotai/utils").RESET | ((prev: boolean) => boolean | typeof import("jotai/utils").RESET)], void>;
2
+ /** On a phone, the path the panel was opened on: it covers the page, so it closes when you leave. */
3
+ export declare const sidebarPanelOpenedAtState: import("jotai").PrimitiveAtom<string | null> & {
4
+ init: string | null;
5
+ };
@@ -1,4 +1,7 @@
1
1
  import { atomWithStorage } from "jotai/utils";
2
+ import { atom } from "jotai";
2
3
  // src/state/sidebarPanelState.ts
3
4
  const sidebarPanelOpenState = atomWithStorage("sidebar:panel-open", true, void 0, { getOnInit: true });
4
- export { sidebarPanelOpenState };
5
+ /** On a phone, the path the panel was opened on: it covers the page, so it closes when you leave. */
6
+ const sidebarPanelOpenedAtState = atom(null);
7
+ export { sidebarPanelOpenState, sidebarPanelOpenedAtState };
package/dist/theme.css CHANGED
@@ -3,8 +3,9 @@
3
3
 
4
4
  Maps utilities to design tokens. Token values live on the host's :root and
5
5
  .dark (base.css, imported once by the host page), so this file must not
6
- declare them. A plugin imports it next to its own prefixed Tailwind
7
- utilities; see web/src/styles.css for the host.
6
+ declare them. A plugin UI imports it with theme(inline) to build its own
7
+ utilities (create-erxes's ui/src/styles.css), and addPluginStyles adds the
8
+ ones web lacks; see apps/web/src/styles.css for the host.
8
9
  */
9
10
  @custom-variant dark (&:is(.dark *));
10
11
  /* Inside an app layout whose navigation panel is closed, where its toggle button floats at the
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Adds `css`, the plugin's compiled Tailwind (`import css from './styles.css?inline'`), to the
3
+ * page: its utilities layer without the classes the page already has, and its `@property` and
4
+ * `@keyframes` rules. Calling it again for the same plugin replaces its sheet.
5
+ */
6
+ export declare const addPluginStyles: (plugin: string, css: string) => void;
@@ -0,0 +1,53 @@
1
+ // src/utils/plugin-styles.ts
2
+ const sheets = /* @__PURE__ */ new Map();
3
+ /** The class a rule is for: `md\:flex` in `.md\:flex`, `space-y-2` in `:where(.space-y-2 > …)`. */
4
+ const CLASS = /\.((?:\\[\da-f]{1,6} ?|\\.|[\w-])+)/i;
5
+ const classOf = (rule) => rule instanceof CSSStyleRule ? CLASS.exec(rule.selectorText)?.[1] : void 0;
6
+ const collectClasses = (rules, into) => {
7
+ for (const rule of rules) {
8
+ const name = classOf(rule);
9
+ if (name) into.add(name);
10
+ else if (rule instanceof CSSGroupingRule) collectClasses(rule.cssRules, into);
11
+ }
12
+ };
13
+ /** Another origin's sheet can't be read; web's own and inline ones can. */
14
+ const sameOrigin = (sheet) => !sheet.href || new URL(sheet.href).origin === window.location.origin;
15
+ /** Every class the page's other style sheets style. */
16
+ const pageClasses = (except) => {
17
+ const classes = /* @__PURE__ */ new Set();
18
+ for (const sheet of [...document.styleSheets, ...document.adoptedStyleSheets]) if (sheet !== except && sameOrigin(sheet)) collectClasses(sheet.cssRules, classes);
19
+ return classes;
20
+ };
21
+ /** Deletes the rules for classes the page has, and the groups that leave empty. */
22
+ const dropKnown = (group, known) => {
23
+ for (let index = group.cssRules.length - 1; index >= 0; index--) {
24
+ const rule = group.cssRules[index];
25
+ const name = rule && classOf(rule);
26
+ if (name !== void 0 && known.has(name)) group.deleteRule(index);
27
+ else if (rule instanceof CSSGroupingRule && !(rule instanceof CSSStyleRule)) {
28
+ dropKnown(rule, known);
29
+ if (rule.cssRules.length === 0) group.deleteRule(index);
30
+ }
31
+ }
32
+ };
33
+ /** What a plugin sheet keeps besides its utilities: the custom properties and keyframes they use. */
34
+ const isSupport = (rule) => rule instanceof CSSPropertyRule || rule instanceof CSSKeyframesRule || rule instanceof CSSLayerStatementRule || rule instanceof CSSLayerBlockRule && rule.name === "properties";
35
+ /**
36
+ * Adds `css`, the plugin's compiled Tailwind (`import css from './styles.css?inline'`), to the
37
+ * page: its utilities layer without the classes the page already has, and its `@property` and
38
+ * `@keyframes` rules. Calling it again for the same plugin replaces its sheet.
39
+ */
40
+ const addPluginStyles = (plugin, css) => {
41
+ const previous = sheets.get(plugin);
42
+ const sheet = new CSSStyleSheet();
43
+ sheet.replaceSync(css);
44
+ for (let index = sheet.cssRules.length - 1; index >= 0; index--) {
45
+ const rule = sheet.cssRules[index];
46
+ const utilities = rule instanceof CSSLayerBlockRule && rule.name === "utilities";
47
+ if (rule && !utilities && !isSupport(rule)) sheet.deleteRule(index);
48
+ }
49
+ dropKnown(sheet, pageClasses(previous));
50
+ sheets.set(plugin, sheet);
51
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets.filter((adopted) => adopted !== previous), sheet];
52
+ };
53
+ export { addPluginStyles };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erxes/ui",
3
- "version": "4.0.0-v2.1",
3
+ "version": "4.0.0-v2.2",
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",
@@ -70,6 +70,7 @@
70
70
  "zod": "4.6.7"
71
71
  },
72
72
  "devDependencies": {
73
+ "@tanstack/react-query": "^5.107.1",
73
74
  "@types/node": "^26.6.6",
74
75
  "@types/react": "19.3.0",
75
76
  "@types/react-dom": "19.3.0",
@@ -79,6 +80,7 @@
79
80
  "react-i18next": "^18.0.1"
80
81
  },
81
82
  "peerDependencies": {
83
+ "@tanstack/react-query": "^5.107.1",
82
84
  "jotai": "^3.0.2",
83
85
  "react": "^19.3.1",
84
86
  "react-dom": "^19.3.1",