@erxes/ui 4.0.0-v2.7 → 4.0.0-v2.8

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
@@ -27,6 +27,8 @@ Only what something uses:
27
27
  `useLiveSignal`, `RecordTimeline`, `getPluginAssetsUrl`, `addPluginStyles` and the `IUIConfig` types,
28
28
  - the design-system primitives in `src/components` (Accordion, Card, Slider …), even unused,
29
29
  because plugins build on them,
30
+ - the record views plugins build lists from: `RecordTable` and `RecordList` (rows grouped under
31
+ headers that fold away, such as tasks by status; the Operation plugin is the first consumer),
30
32
  - the pickers in `src/modules/pickers`: `EntityPicker`, and `SelectMember`, `MemberInline` and
31
33
  `useMembersById`, which take `memberQueries` from `@erxes/core-contract/client`. They read
32
34
  through TanStack query options, so erxes-ui imports nothing from core.
package/dist/index.d.ts CHANGED
@@ -90,6 +90,8 @@ import { MemberInline, SelectMember } from "./modules/pickers/SelectMember.js";
90
90
  import { NumberField } from "./modules/record-field/components/NumberField.js";
91
91
  import { TextField } from "./modules/record-field/components/TextField.js";
92
92
  import { PhoneInput } from "./modules/record-field/meta-inputs/components/PhoneInput.js";
93
+ import { RecordList } from "./modules/record-list/RecordList.js";
94
+ import { RecordListGroup } from "./modules/record-list/RecordListRoot.js";
93
95
  import { RecordTable } from "./modules/record-table/components/RecordTable.js";
94
96
  import { RecordTableColumnDef } from "./modules/record-table/components/RecordTableProvider.js";
95
97
  import { RecordTableInlineCell } from "./modules/record-table/components/RecordTableCellInline.js";
@@ -119,4 +121,4 @@ import { jsonOf } from "./utils/json.js";
119
121
  import { PluginLiveMessage, PluginRuntime, PluginSession, getPluginRuntime, pluginFetch, pluginJson, setPluginRuntime, useLiveSignal } from "./utils/plugin-runtime.js";
120
122
  import { addPluginStyles } from "./utils/plugin-styles.js";
121
123
  import { RecordTimeline, RecordTimelineProps, setRecordTimeline } from "./utils/record-timeline.js";
122
- 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, type CompanyContact, ContactLink, type ContactQueries, ContextMenu, CopyText, type CustomerContact, DateInput, DatePicker, Dialog, DisplayMenu, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, type FileStorageAdapter, Filter, Form, FullNameField, FullNameValue, HoverCard, type IUIConfig, IconComponent, IconPicker, IconTip, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, ListFilter, type Member, MemberInline, type MemberQueries, type MultiSelectOption, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PanelDescriptionEditor, PanelDescriptionField, PanelExpansionContext, PanelField, PanelFieldTrigger, PanelFormLayout, PanelFormRow, PanelLabel, PanelSection, PhoneDisplay, PhoneField, PhoneInput, type PluginLiveMessage, type PluginRuntime, type PluginSession, Popover, PopoverScoped, RadioGroup, RecordOpenerProvider, RecordPage, type RecordRef, 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 TContactContentType, type TDashboardWidgetPreview, type TListDisplay, type TListFilterField, type TListFilterProps, type TPanelRecordType, type TPropertyInputMeta, type TPropertyInputProps, type TRecordContacts, type TRecordDraftProps, type TRecordSection, type TRecordSectionProps, type TRecordSlotProps, type TRecordTab, type TRelationTab, type TRelationTabProps, TabButton, Table, Tabs, TextField, TextOverflowTooltip, Textarea, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, ViewBar, addPluginStyles, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatPhoneNumber, formatter, getPluginAssetsUrl, getPluginRuntime, isUndefinedOrNull, jsonOf, localTimeZone, memberName, pluginFetch, pluginJson, readImage, setFileStorage, setListFilter, setPluginRuntime, setRecordPage, setRecordTimeline, stored, storedFamily, themeState, toIsoDay, toast, useConfirm, useFilterContext, useFormat, useListDisplay, useListFilterParams, useLiveSignal, useMembersById, useOpenRecord, usePageHotkey, usePanelExpanded, usePreviousHotkeyScope, useScopedHotkeys, useToast, useUpload, zoneOffset };
124
+ 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, type CompanyContact, ContactLink, type ContactQueries, ContextMenu, CopyText, type CustomerContact, DateInput, DatePicker, Dialog, DisplayMenu, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, type FileStorageAdapter, Filter, Form, FullNameField, FullNameValue, HoverCard, type IUIConfig, IconComponent, IconPicker, IconTip, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, ListFilter, type Member, MemberInline, type MemberQueries, type MultiSelectOption, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PanelDescriptionEditor, PanelDescriptionField, PanelExpansionContext, PanelField, PanelFieldTrigger, PanelFormLayout, PanelFormRow, PanelLabel, PanelSection, PhoneDisplay, PhoneField, PhoneInput, type PluginLiveMessage, type PluginRuntime, type PluginSession, Popover, PopoverScoped, RadioGroup, RecordList, type RecordListGroup, RecordOpenerProvider, RecordPage, type RecordRef, 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 TContactContentType, type TDashboardWidgetPreview, type TListDisplay, type TListFilterField, type TListFilterProps, type TPanelRecordType, type TPropertyInputMeta, type TPropertyInputProps, type TRecordContacts, type TRecordDraftProps, type TRecordSection, type TRecordSectionProps, type TRecordSlotProps, type TRecordTab, type TRelationTab, type TRelationTabProps, TabButton, Table, Tabs, TextField, TextOverflowTooltip, Textarea, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, ViewBar, addPluginStyles, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatPhoneNumber, formatter, getPluginAssetsUrl, getPluginRuntime, isUndefinedOrNull, jsonOf, localTimeZone, memberName, pluginFetch, pluginJson, readImage, setFileStorage, setListFilter, setPluginRuntime, setRecordPage, setRecordTimeline, stored, storedFamily, themeState, toIsoDay, toast, useConfirm, useFilterContext, useFormat, useListDisplay, useListFilterParams, useLiveSignal, useMembersById, useOpenRecord, usePageHotkey, usePanelExpanded, usePreviousHotkeyScope, useScopedHotkeys, useToast, useUpload, zoneOffset };
package/dist/index.js CHANGED
@@ -88,6 +88,7 @@ import { MemberInline, SelectMember } from "./modules/pickers/SelectMember.js";
88
88
  import { NumberField } from "./modules/record-field/components/NumberField.js";
89
89
  import { TextField } from "./modules/record-field/components/TextField.js";
90
90
  import { PhoneInput } from "./modules/record-field/meta-inputs/components/PhoneInput.js";
91
+ import { RecordList } from "./modules/record-list/RecordList.js";
91
92
  import { RecordTable } from "./modules/record-table/components/RecordTable.js";
92
93
  import { RecordTableInlineCell } from "./modules/record-table/components/RecordTableCellInline.js";
93
94
  import { EnumCursorDirection } from "./modules/record-table/types/RecordTableCursorTypes.js";
@@ -115,4 +116,4 @@ import { jsonOf } from "./utils/json.js";
115
116
  import { getPluginRuntime, pluginFetch, pluginJson, setPluginRuntime, useLiveSignal } from "./utils/plugin-runtime.js";
116
117
  import { addPluginStyles } from "./utils/plugin-styles.js";
117
118
  import { RecordTimeline, setRecordTimeline } from "./utils/record-timeline.js";
118
- export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, BackgroundGradientAnimation, Badge, Breadcrumb, Button, Calendar, Card, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, ContactLink, ContextMenu, CopyText, DateInput, DatePicker, Dialog, DisplayMenu, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, Filter, Form, FullNameField, FullNameValue, HoverCard, IconComponent, IconPicker, IconTip, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, ListFilter, MemberInline, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PanelDescriptionEditor, PanelDescriptionField, PanelExpansionContext, PanelField, PanelFieldTrigger, PanelFormLayout, PanelFormRow, PanelLabel, PanelSection, PhoneDisplay, PhoneField, PhoneInput, Popover, PopoverScoped, RadioGroup, RecordOpenerProvider, RecordPage, 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, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, ViewBar, addPluginStyles, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatPhoneNumber, formatter, getPluginAssetsUrl, getPluginRuntime, isUndefinedOrNull, jsonOf, localTimeZone, memberName, pluginFetch, pluginJson, readImage, setFileStorage, setListFilter, setPluginRuntime, setRecordPage, setRecordTimeline, stored, storedFamily, themeState, toIsoDay, toast, useConfirm, useFilterContext, useFormat, useListDisplay, useListFilterParams, useLiveSignal, useMembersById, useOpenRecord, usePageHotkey, usePanelExpanded, usePreviousHotkeyScope, useScopedHotkeys, useToast, useUpload, zoneOffset };
119
+ export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, BackgroundGradientAnimation, Badge, Breadcrumb, Button, Calendar, Card, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, ContactLink, ContextMenu, CopyText, DateInput, DatePicker, Dialog, DisplayMenu, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, Filter, Form, FullNameField, FullNameValue, HoverCard, IconComponent, IconPicker, IconTip, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, ListFilter, MemberInline, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PanelDescriptionEditor, PanelDescriptionField, PanelExpansionContext, PanelField, PanelFieldTrigger, PanelFormLayout, PanelFormRow, PanelLabel, PanelSection, PhoneDisplay, PhoneField, PhoneInput, Popover, PopoverScoped, RadioGroup, RecordList, RecordOpenerProvider, RecordPage, 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, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, ViewBar, addPluginStyles, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatPhoneNumber, formatter, getPluginAssetsUrl, getPluginRuntime, isUndefinedOrNull, jsonOf, localTimeZone, memberName, pluginFetch, pluginJson, readImage, setFileStorage, setListFilter, setPluginRuntime, setRecordPage, setRecordTimeline, stored, storedFamily, themeState, toIsoDay, toast, useConfirm, useFilterContext, useFormat, useListDisplay, useListFilterParams, useLiveSignal, useMembersById, useOpenRecord, usePageHotkey, usePanelExpanded, usePreviousHotkeyScope, useScopedHotkeys, useToast, useUpload, zoneOffset };
@@ -1,13 +1,20 @@
1
- declare const LIST_DISPLAYS: readonly ['table', 'board'];
2
- /** How a list shows its records: rows in a table, or cards on a board. */
1
+ declare const LIST_DISPLAYS: readonly ['list', 'table', 'board'];
2
+ /** How a list shows its records: grouped rows (`RecordList`), a table, or cards on a board. */
3
3
  export type TListDisplay = (typeof LIST_DISPLAYS)[number];
4
+ /** The displays a list offers, in the menu's order; the first shows until one is chosen. */
5
+ type ListDisplays = readonly [TListDisplay, ...TListDisplay[]];
4
6
  /**
5
- * `const [display] = useListDisplay('sales-deals')`: the table or board a list shows, chosen
6
- * under its Display menu and remembered in this browser, one choice per list.
7
+ * `const [display] = useListDisplay('sales-deals')`: the display a list shows, chosen under its
8
+ * Display menu and remembered in this browser, one choice per list. Give it the same `displays`
9
+ * as the list's `DisplayMenu`.
7
10
  */
8
- export declare const useListDisplay: (list: string) => ["board" | "table", (args_0: "board" | "table" | typeof import("jotai/utils").RESET | ((prev: "board" | "table") => "board" | "table" | typeof import("jotai/utils").RESET)) => void];
9
- /** "Display" in a list's filter bar: table or board (`useListDisplay(list)` reads the choice). */
10
- export declare const DisplayMenu: ({ list }: {
11
+ export declare const useListDisplay: (list: string, displays?: ListDisplays) => readonly ["board" | "list" | "table", (args_0: "board" | "list" | "table" | typeof import("jotai/utils").RESET | ((prev: "board" | "list" | "table" | null) => "board" | "list" | "table" | typeof import("jotai/utils").RESET | null) | null) => void];
12
+ /**
13
+ * "Display" in a list's filter bar: table or board, or the `displays` the list offers, such as
14
+ * `['list', 'board', 'table']` (`useListDisplay(list, displays)` reads the choice).
15
+ */
16
+ export declare const DisplayMenu: ({ list, displays }: {
11
17
  list: string;
18
+ displays?: ListDisplays;
12
19
  }) => import("react").JSX.Element;
13
20
  export {};
@@ -3,36 +3,53 @@ import { IconTip } from "../../components/icon-tip.js";
3
3
  import { Popover } from "../../components/popover.js";
4
4
  import { storedFamily } from "../../lib/stored.js";
5
5
  import { cn } from "../../lib/utils.js";
6
- import { IconAdjustmentsHorizontal, IconLayoutKanban, IconTable } from "@tabler/icons-react";
6
+ import { IconAdjustmentsHorizontal, IconLayoutKanban, IconList, IconTable } from "@tabler/icons-react";
7
7
  import { jsx, jsxs } from "react/jsx-runtime";
8
8
  import { useAtom } from "jotai";
9
9
  import { z } from "zod";
10
10
  import { useTranslation } from "react-i18next";
11
11
  // src/modules/list/DisplayMenu.tsx
12
+ const LIST_DISPLAYS = [
13
+ "list",
14
+ "table",
15
+ "board"
16
+ ];
17
+ const TABLE_AND_BOARD = ["table", "board"];
18
+ /** Null until the member picks one. */
12
19
  const listDisplayFamily = storedFamily({
13
20
  key: "erxes:list-display",
14
- schema: z.enum(["table", "board"]),
15
- initial: "table"
21
+ schema: z.enum(LIST_DISPLAYS).nullable(),
22
+ initial: null
16
23
  });
17
24
  /**
18
- * `const [display] = useListDisplay('sales-deals')`: the table or board a list shows, chosen
19
- * under its Display menu and remembered in this browser, one choice per list.
25
+ * `const [display] = useListDisplay('sales-deals')`: the display a list shows, chosen under its
26
+ * Display menu and remembered in this browser, one choice per list. Give it the same `displays`
27
+ * as the list's `DisplayMenu`.
20
28
  */
21
- const useListDisplay = (list) => useAtom(listDisplayFamily(list));
22
- const DISPLAYS = [{
23
- value: "table",
24
- label: "table",
25
- fallback: "Table",
26
- icon: IconTable
27
- }, {
28
- value: "board",
29
- label: "board",
30
- fallback: "Board",
31
- icon: IconLayoutKanban
32
- }];
33
- /** "Display" in a list's filter bar: table or board (`useListDisplay(list)` reads the choice). */
34
- const DisplayMenu = ({ list }) => {
35
- const [current, setDisplay] = useListDisplay(list);
29
+ const useListDisplay = (list, displays = TABLE_AND_BOARD) => {
30
+ const [chosen, setDisplay] = useAtom(listDisplayFamily(list));
31
+ return [chosen && displays.includes(chosen) ? chosen : displays[0], setDisplay];
32
+ };
33
+ const DISPLAYS = {
34
+ list: {
35
+ fallback: "List",
36
+ icon: IconList
37
+ },
38
+ table: {
39
+ fallback: "Table",
40
+ icon: IconTable
41
+ },
42
+ board: {
43
+ fallback: "Board",
44
+ icon: IconLayoutKanban
45
+ }
46
+ };
47
+ /**
48
+ * "Display" in a list's filter bar: table or board, or the `displays` the list offers, such as
49
+ * `['list', 'board', 'table']` (`useListDisplay(list, displays)` reads the choice).
50
+ */
51
+ const DisplayMenu = ({ list, displays = TABLE_AND_BOARD }) => {
52
+ const [current, setDisplay] = useListDisplay(list, displays);
36
53
  const { t } = useTranslation("views", { keyPrefix: "display" });
37
54
  return /* @__PURE__ */ jsxs(Popover, { children: [/* @__PURE__ */ jsx(IconTip, {
38
55
  label: t("label", "Display"),
@@ -52,14 +69,17 @@ const DisplayMenu = ({ list }) => {
52
69
  className: "mb-2 text-xs font-medium text-muted-foreground",
53
70
  children: t("view", "View")
54
71
  }), /* @__PURE__ */ jsx("div", {
55
- className: "grid grid-cols-2 gap-2",
56
- children: DISPLAYS.map(({ value, label, fallback, icon: Icon }) => /* @__PURE__ */ jsxs("button", {
57
- type: "button",
58
- "aria-pressed": current === value,
59
- onClick: () => setDisplay(value),
60
- className: cn("flex flex-col items-center gap-1.5 rounded-lg border p-3 text-sm text-muted-foreground transition-colors hover:bg-accent", current === value && "border-primary bg-primary/5 font-medium text-foreground"),
61
- children: [/* @__PURE__ */ jsx(Icon, { className: "size-5" }), t(label, fallback)]
62
- }, value))
72
+ className: cn("grid gap-2", displays.length > 2 ? "grid-cols-3" : "grid-cols-2"),
73
+ children: displays.map((value) => {
74
+ const { fallback, icon: Icon } = DISPLAYS[value];
75
+ return /* @__PURE__ */ jsxs("button", {
76
+ type: "button",
77
+ "aria-pressed": current === value,
78
+ onClick: () => setDisplay(value),
79
+ className: cn("flex flex-col items-center gap-1.5 rounded-lg border p-3 text-sm text-muted-foreground transition-colors hover:bg-accent", current === value && "border-primary bg-primary/5 font-medium text-foreground"),
80
+ children: [/* @__PURE__ */ jsx(Icon, { className: "size-5" }), t(value, fallback)]
81
+ }, value);
82
+ })
63
83
  })]
64
84
  })] });
65
85
  };
@@ -0,0 +1,12 @@
1
+ import { RecordListProvider, useRecordListSelection } from "./RecordListProvider.js";
2
+ import { RecordListRoot } from "./RecordListRoot.js";
3
+ /** Stands in for the rows while they load. */
4
+ declare const RecordListSkeleton: ({ rows }: {
5
+ rows?: number;
6
+ }) => import("react").JSX.Element;
7
+ export declare const RecordList: typeof RecordListRoot & {
8
+ Provider: typeof RecordListProvider;
9
+ Skeleton: typeof RecordListSkeleton;
10
+ useSelection: typeof useRecordListSelection;
11
+ };
12
+ export {};
@@ -0,0 +1,17 @@
1
+ import { Skeleton } from "../../components/skeleton.js";
2
+ import { RecordListProvider, useRecordListSelection } from "./RecordListProvider.js";
3
+ import { RecordListRoot } from "./RecordListRoot.js";
4
+ import { jsx } from "react/jsx-runtime";
5
+ // src/modules/record-list/RecordList.tsx
6
+ /** Stands in for the rows while they load. */
7
+ const RecordListSkeleton = ({ rows = 8 }) => /* @__PURE__ */ jsx("div", {
8
+ className: "flex flex-col gap-2 p-3",
9
+ "aria-busy": true,
10
+ children: Array.from({ length: rows }, (_, index) => /* @__PURE__ */ jsx(Skeleton, { className: "h-8" }, `row-${String(index)}`))
11
+ });
12
+ const RecordList = Object.assign(RecordListRoot, {
13
+ Provider: RecordListProvider,
14
+ Skeleton: RecordListSkeleton,
15
+ useSelection: useRecordListSelection
16
+ });
17
+ export { RecordList };
@@ -0,0 +1,30 @@
1
+ import { Selection } from "./selection.js";
2
+ import { PropsWithChildren } from "react";
3
+ /** The groups folded away, per list, kept in this browser. */
4
+ export declare const collapsedGroups: import("jotai-family").AtomFamily<string, import("jotai").WritableAtom<string[], [typeof import("jotai/utils").RESET | string[] | ((prev: string[]) => typeof import("jotai/utils").RESET | string[])], void>>;
5
+ interface RecordListContextValue {
6
+ listId: string;
7
+ selection: Selection;
8
+ }
9
+ export declare const useRecordListContext: () => RecordListContextValue;
10
+ /** Renders again only when `read` of the selection changes, such as one row's own state. */
11
+ export declare const useSelectionState: <T>(read: (picked: ReadonlySet<string>) => T) => T;
12
+ /**
13
+ * The selection a record list and its command bar share. Rows that leave the list stay
14
+ * picked until `clear`, so read the selection through the rows the page shows.
15
+ */
16
+ export declare const useRecordListSelection: () => {
17
+ ids: string[];
18
+ has: (id: string) => boolean;
19
+ toggle: (id: string) => void;
20
+ toggleAll: (ids: readonly string[]) => void;
21
+ clear: () => void;
22
+ };
23
+ /**
24
+ * `listId` names the list in this browser, where its folded groups are kept. Another
25
+ * `listId` is another list: its selection starts empty.
26
+ */
27
+ export declare const RecordListProvider: ({ listId, children }: PropsWithChildren<{
28
+ listId: string;
29
+ }>) => import("react").JSX.Element;
30
+ export {};
@@ -0,0 +1,57 @@
1
+ import { storedFamily } from "../../lib/stored.js";
2
+ import { createSelection } from "./selection.js";
3
+ import { jsx } from "react/jsx-runtime";
4
+ import { createContext, useContext, useState, useSyncExternalStore } from "react";
5
+ import { z } from "zod";
6
+ // src/modules/record-list/RecordListProvider.tsx
7
+ /** The groups folded away, per list, kept in this browser. */
8
+ const collapsedGroups = storedFamily({
9
+ key: "erxes:record-list:collapsed",
10
+ schema: z.array(z.string().max(200)).max(500),
11
+ initial: []
12
+ });
13
+ const RecordListContext = createContext(null);
14
+ const useRecordListContext = () => {
15
+ const context = useContext(RecordListContext);
16
+ if (!context) throw new Error("A record list must be used within RecordList.Provider.");
17
+ return context;
18
+ };
19
+ /** Renders again only when `read` of the selection changes, such as one row's own state. */
20
+ const useSelectionState = (read) => {
21
+ const { selection } = useRecordListContext();
22
+ return useSyncExternalStore(selection.subscribe, () => read(selection.picked()));
23
+ };
24
+ /**
25
+ * The selection a record list and its command bar share. Rows that leave the list stay
26
+ * picked until `clear`, so read the selection through the rows the page shows.
27
+ */
28
+ const useRecordListSelection = () => {
29
+ const { selection } = useRecordListContext();
30
+ const picked = useSelectionState((current) => current);
31
+ return {
32
+ ids: [...picked],
33
+ has: (id) => picked.has(id),
34
+ toggle: (id) => selection.toggle(id),
35
+ toggleAll: selection.toggleAll,
36
+ clear: selection.clear
37
+ };
38
+ };
39
+ const SelectionScope = ({ listId, children }) => {
40
+ const [context] = useState(() => ({
41
+ listId,
42
+ selection: createSelection()
43
+ }));
44
+ return /* @__PURE__ */ jsx(RecordListContext.Provider, {
45
+ value: context,
46
+ children
47
+ });
48
+ };
49
+ /**
50
+ * `listId` names the list in this browser, where its folded groups are kept. Another
51
+ * `listId` is another list: its selection starts empty.
52
+ */
53
+ const RecordListProvider = ({ listId, children }) => /* @__PURE__ */ jsx(SelectionScope, {
54
+ listId,
55
+ children
56
+ }, listId);
57
+ export { RecordListProvider, collapsedGroups, useRecordListContext, useRecordListSelection, useSelectionState };
@@ -0,0 +1,28 @@
1
+ import { ReactNode } from "react";
2
+ /** A run of rows under one header, such as the tasks in one status. */
3
+ export interface RecordListGroup<TRow> {
4
+ id: string;
5
+ label: string;
6
+ icon?: ReactNode;
7
+ rows: TRow[];
8
+ /** The header's controls on the right, such as a "+" that adds a row to this group. */
9
+ action?: ReactNode;
10
+ }
11
+ interface RecordListProps<TRow> {
12
+ groups: RecordListGroup<TRow>[];
13
+ rowId: (row: TRow) => string;
14
+ /** The row's name, for its checkbox's label. */
15
+ rowLabel: (row: TRow) => string;
16
+ /** The row's content, after its checkbox. */
17
+ renderRow: (row: TRow) => ReactNode;
18
+ /** False: one list with no headers, such as rows sorted by date. */
19
+ grouped?: boolean;
20
+ className?: string;
21
+ }
22
+ /**
23
+ * Rows in groups, each under a sticky header that folds it away and picks all its rows; the
24
+ * folded groups are kept in this browser. Shift-click picks every row between two clicks, as
25
+ * shown. Inside `RecordList.Provider`, which holds the selection a command bar reads.
26
+ */
27
+ export declare const RecordListRoot: <TRow>({ groups, rowId, rowLabel, renderRow, grouped, className }: RecordListProps<TRow>) => import("react").JSX.Element;
28
+ export {};
@@ -0,0 +1,124 @@
1
+ import { Button } from "../../components/button.js";
2
+ import { Checkbox } from "../../components/checkbox.js";
3
+ import { useMediaQuery } from "../../hooks/use-media-query.js";
4
+ import { cn } from "../../lib/utils.js";
5
+ import { collapsedGroups, useRecordListContext, useSelectionState } from "./RecordListProvider.js";
6
+ import { IconChevronDown, IconChevronRight } from "@tabler/icons-react";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ import { useId } from "react";
9
+ import { useAtom } from "jotai";
10
+ // src/modules/record-list/RecordListRoot.tsx
11
+ /**
12
+ * A row's control that shows on hover or focus. A row's own controls (an empty date, say) can
13
+ * use the same classes. Where a finger may be the pointer (a phone, a touch laptop), nothing
14
+ * hovers first, so there they always show.
15
+ */
16
+ const revealed = "opacity-0 group-hover/list-row:opacity-100 group-focus-within/list-row:opacity-100";
17
+ const useHover = () => useMediaQuery("(hover: hover) and (not (any-pointer: coarse))");
18
+ const GroupHeader = ({ group, ids, panelId, collapsed, onCollapse }) => {
19
+ const { selection } = useRecordListContext();
20
+ const hover = useHover();
21
+ const picked = useSelectionState((current) => ids.filter((id) => current.has(id)).length);
22
+ return /* @__PURE__ */ jsxs("div", {
23
+ className: "group/list-row sticky top-0 z-10 flex h-9 items-center gap-1 border-b bg-muted px-2 text-xs font-medium",
24
+ children: [
25
+ /* @__PURE__ */ jsx("span", {
26
+ className: cn("flex h-9 w-8 shrink-0 items-center justify-center", hover && !picked && revealed),
27
+ children: /* @__PURE__ */ jsx(Checkbox, {
28
+ checked: picked > 0 && picked === ids.length,
29
+ indeterminate: picked > 0 && picked < ids.length,
30
+ "aria-label": `Select all in ${group.label}`,
31
+ onCheckedChange: () => selection.toggleAll(ids)
32
+ })
33
+ }),
34
+ /* @__PURE__ */ jsxs(Button, {
35
+ variant: "ghost",
36
+ size: "sm",
37
+ "aria-expanded": !collapsed,
38
+ "aria-controls": collapsed ? void 0 : panelId,
39
+ onClick: () => onCollapse(!collapsed),
40
+ children: [
41
+ collapsed ? /* @__PURE__ */ jsx(IconChevronRight, { "aria-hidden": true }) : /* @__PURE__ */ jsx(IconChevronDown, { "aria-hidden": true }),
42
+ group.icon,
43
+ group.label,
44
+ /* @__PURE__ */ jsx("span", {
45
+ className: "text-muted-foreground tabular-nums",
46
+ children: ids.length
47
+ })
48
+ ]
49
+ }),
50
+ group.action && /* @__PURE__ */ jsx("span", {
51
+ className: "ml-auto flex items-center",
52
+ children: group.action
53
+ })
54
+ ]
55
+ });
56
+ };
57
+ const Row = ({ id, label, order, children }) => {
58
+ const { selection } = useRecordListContext();
59
+ const hover = useHover();
60
+ const checked = useSelectionState((current) => current.has(id));
61
+ const selecting = useSelectionState((current) => current.size > 0);
62
+ return /* @__PURE__ */ jsxs("li", {
63
+ "data-record-row": id,
64
+ "data-selected": checked || void 0,
65
+ className: "group/list-row flex h-11 items-center gap-1 border-b px-2 text-sm hover:bg-muted data-selected:bg-primary/10",
66
+ children: [/* @__PURE__ */ jsx("span", {
67
+ className: cn("flex h-11 w-8 shrink-0 items-center justify-center", hover && !selecting && revealed),
68
+ children: /* @__PURE__ */ jsx(Checkbox, {
69
+ className: "relative after:absolute after:-inset-x-2 after:-inset-y-3.5",
70
+ checked,
71
+ "aria-label": `Select ${label}`,
72
+ onCheckedChange: (_checked, { event }) => {
73
+ const range = event instanceof MouseEvent && event.shiftKey;
74
+ if (range) window.getSelection()?.removeAllRanges();
75
+ selection.toggle(id, range ? order : void 0);
76
+ }
77
+ })
78
+ }), children]
79
+ });
80
+ };
81
+ /**
82
+ * Rows in groups, each under a sticky header that folds it away and picks all its rows; the
83
+ * folded groups are kept in this browser. Shift-click picks every row between two clicks, as
84
+ * shown. Inside `RecordList.Provider`, which holds the selection a command bar reads.
85
+ */
86
+ const RecordListRoot = ({ groups, rowId, rowLabel, renderRow, grouped = true, className }) => {
87
+ const { listId } = useRecordListContext();
88
+ const [collapsed, setCollapsed] = useAtom(collapsedGroups(listId));
89
+ const prefix = useId();
90
+ const folded = (group) => grouped && collapsed.includes(group.id);
91
+ const order = groups.filter((group) => !folded(group)).flatMap((group) => group.rows.map(rowId));
92
+ const rows = (list) => list.map((row) => /* @__PURE__ */ jsx(Row, {
93
+ id: rowId(row),
94
+ label: rowLabel(row),
95
+ order,
96
+ children: renderRow(row)
97
+ }, rowId(row)));
98
+ if (!grouped) return /* @__PURE__ */ jsx("div", {
99
+ "data-record-list": listId,
100
+ className,
101
+ children: /* @__PURE__ */ jsx("ul", { children: rows(groups.flatMap((group) => group.rows)) })
102
+ });
103
+ return /* @__PURE__ */ jsx("div", {
104
+ "data-record-list": listId,
105
+ className,
106
+ children: groups.map((group) => {
107
+ const panelId = `${prefix}-${group.id}`;
108
+ return /* @__PURE__ */ jsxs("section", {
109
+ "aria-label": group.label,
110
+ children: [/* @__PURE__ */ jsx(GroupHeader, {
111
+ group,
112
+ ids: group.rows.map(rowId),
113
+ panelId,
114
+ collapsed: folded(group),
115
+ onCollapse: (fold) => setCollapsed((current) => fold ? [...current, group.id] : current.filter((id) => id !== group.id))
116
+ }), !folded(group) && /* @__PURE__ */ jsx("ul", {
117
+ id: panelId,
118
+ children: rows(group.rows)
119
+ })]
120
+ }, group.id);
121
+ })
122
+ });
123
+ };
124
+ export { RecordListRoot };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The rows a click on `id` picks. With `anchor` (the row clicked before), every row from it to
3
+ * `id` in `order`, the rows as shown; without, or when either left the list, `id` alone.
4
+ */
5
+ export declare const rowsBetween: (order: readonly string[], anchor: string | null, id: string) => string[];
6
+ /** `picked` with `ids` added (`on`) or taken out. */
7
+ export declare const withRows: (picked: ReadonlySet<string>, ids: readonly string[], on: boolean) => Set<string>;
8
+ /**
9
+ * One list's picked rows, outside React: each row subscribes to its own state, so a click
10
+ * renders only the rows it changes. Every change starts from the current state, so changes
11
+ * made before a render all count.
12
+ */
13
+ export declare const createSelection: () => {
14
+ subscribe: (listener: () => void) => () => void;
15
+ picked: () => ReadonlySet<string>;
16
+ /** With `order` (the rows as shown), a shift-click: every row since the last click. */
17
+ toggle: (id: string, order?: readonly string[]) => void;
18
+ /** Picks all of `ids`, or clears them when all are picked. */
19
+ toggleAll: (ids: readonly string[]) => void;
20
+ clear: () => void;
21
+ };
22
+ export type Selection = ReturnType<typeof createSelection>;
@@ -0,0 +1,54 @@
1
+ // src/modules/record-list/selection.ts
2
+ /**
3
+ * The rows a click on `id` picks. With `anchor` (the row clicked before), every row from it to
4
+ * `id` in `order`, the rows as shown; without, or when either left the list, `id` alone.
5
+ */
6
+ const rowsBetween = (order, anchor, id) => {
7
+ const from = anchor === null ? -1 : order.indexOf(anchor);
8
+ const to = order.indexOf(id);
9
+ if (from === -1 || to === -1) return [id];
10
+ return order.slice(Math.min(from, to), Math.max(from, to) + 1);
11
+ };
12
+ /** `picked` with `ids` added (`on`) or taken out. */
13
+ const withRows = (picked, ids, on) => {
14
+ const next = new Set(picked);
15
+ for (const id of ids) if (on) next.add(id);
16
+ else next.delete(id);
17
+ return next;
18
+ };
19
+ /**
20
+ * One list's picked rows, outside React: each row subscribes to its own state, so a click
21
+ * renders only the rows it changes. Every change starts from the current state, so changes
22
+ * made before a render all count.
23
+ */
24
+ const createSelection = () => {
25
+ let picked = /* @__PURE__ */ new Set();
26
+ let anchor = null;
27
+ const listeners = /* @__PURE__ */ new Set();
28
+ const set = (next) => {
29
+ picked = next;
30
+ for (const listener of listeners) listener();
31
+ };
32
+ return {
33
+ subscribe: (listener) => {
34
+ listeners.add(listener);
35
+ return () => {
36
+ listeners.delete(listener);
37
+ };
38
+ },
39
+ picked: () => picked,
40
+ /** With `order` (the rows as shown), a shift-click: every row since the last click. */
41
+ toggle: (id, order) => {
42
+ const rows = order ? rowsBetween(order, anchor, id) : [id];
43
+ anchor = id;
44
+ set(withRows(picked, rows, !picked.has(id)));
45
+ },
46
+ /** Picks all of `ids`, or clears them when all are picked. */
47
+ toggleAll: (ids) => set(withRows(picked, ids, !ids.every((id) => picked.has(id)))),
48
+ clear: () => {
49
+ anchor = null;
50
+ set(/* @__PURE__ */ new Set());
51
+ }
52
+ };
53
+ };
54
+ export { createSelection, rowsBetween, withRows };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erxes/ui",
3
- "version": "4.0.0-v2.7",
3
+ "version": "4.0.0-v2.8",
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",