@erxes/ui 4.0.0-v2.14 → 4.0.0-v2.16

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.
Files changed (38) hide show
  1. package/CATALOG.md +15 -6
  2. package/dist/components/form-layout.d.ts +3 -1
  3. package/dist/components/form-layout.js +4 -3
  4. package/dist/components/input-group.js +1 -1
  5. package/dist/index.d.ts +5 -5
  6. package/dist/index.js +3 -2
  7. package/dist/modules/blocks/components/Editor.d.ts +1 -1
  8. package/dist/modules/blocks/components/Editor.js +5 -2
  9. package/dist/modules/blocks/hooks/useBlockEditor.d.ts +3 -0
  10. package/dist/modules/blocks/hooks/useBlockEditor.js +21 -2
  11. package/dist/modules/blocks/types/TextEditor.d.ts +3 -1
  12. package/dist/modules/conditions/ValueEditor.js +9 -4
  13. package/dist/modules/conditions/conditions.d.ts +7 -3
  14. package/dist/modules/conditions/conditions.js +8 -1
  15. package/dist/modules/conditions/fieldIcons.js +3 -1
  16. package/dist/modules/conditions/fieldOptions.d.ts +7 -5
  17. package/dist/modules/conditions/fieldOptions.js +22 -10
  18. package/dist/modules/conditions/filterRule.js +3 -1
  19. package/dist/modules/list/ListFilter.d.ts +6 -5
  20. package/dist/modules/list/ListFilter.js +3 -3
  21. package/dist/modules/list/filter/ListFilterBar.js +8 -3
  22. package/dist/modules/pickers/LookupPicker.d.ts +6 -0
  23. package/dist/modules/pickers/LookupPicker.js +32 -1
  24. package/dist/modules/record-list/RecordList.d.ts +2 -1
  25. package/dist/modules/record-list/RecordList.js +2 -1
  26. package/dist/modules/record-list/RecordListRoot.d.ts +3 -1
  27. package/dist/modules/record-list/RecordListRoot.js +53 -37
  28. package/dist/modules/record-table/components/RecordTableHead.d.ts +7 -2
  29. package/dist/modules/record-table/components/RecordTableHead.js +73 -6
  30. package/dist/modules/record-table/components/RecordTableProvider.d.ts +22 -1
  31. package/dist/modules/record-table/components/RecordTableProvider.js +12 -1
  32. package/dist/modules/records/contacts.d.ts +18 -0
  33. package/dist/modules/records/openRecord.d.ts +46 -4
  34. package/dist/modules/records/openRecord.js +28 -5
  35. package/dist/types/UIConfig.d.ts +69 -101
  36. package/dist/types/UIConfig.js +14 -0
  37. package/exports.txt +12 -3
  38. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  import { Combobox } from "../../components/combobox.js";
2
2
  import { Popover } from "../../components/popover.js";
3
3
  import { EntityPicker } from "./EntityPicker.js";
4
+ import { companyTitle, customerTitle } from "../records/contacts.js";
4
5
  import { memberName } from "./members.js";
5
6
  import { jsx, jsxs } from "react/jsx-runtime";
6
7
  import { useMemo, useState } from "react";
@@ -44,6 +45,36 @@ const useMemberOptions = (members, enabled = true, picked = []) => {
44
45
  options: [...team.options, ...others.options]
45
46
  };
46
47
  };
48
+ const customerOption = (customer) => ({
49
+ value: customer.id,
50
+ label: customerTitle(customer) || customer.id
51
+ });
52
+ const companyOption = (company) => ({
53
+ value: company.id,
54
+ label: companyTitle(company) || company.id
55
+ });
56
+ /**
57
+ * Customers or companies matching `search` as picker options, the `picked` ones first so their
58
+ * names show whatever is searched; none without `contacts` or a `type`.
59
+ */
60
+ const useContactOptions = (contacts, type, picked = [], search = "") => {
61
+ const ids = [...new Set(picked)].toSorted((a, b) => a.localeCompare(b));
62
+ const input = { search: search.trim() || void 0 };
63
+ const customers = type === "customer" ? contacts?.customers : void 0;
64
+ const companies = type === "company" ? contacts?.companies : void 0;
65
+ const byIds = ids.length > 0;
66
+ const lookups = [
67
+ useLookup(customers && byIds ? customers({ ids }) : void 0, byIds, customerOption),
68
+ useLookup(companies && byIds ? companies({ ids }) : void 0, byIds, companyOption),
69
+ useLookup(customers?.(input), true, customerOption),
70
+ useLookup(companies?.(input), true, companyOption)
71
+ ];
72
+ return {
73
+ options: [...new Map(lookups.flatMap((lookup) => lookup.options).map((row) => [row.value, row])).values()],
74
+ loading: lookups.some((lookup) => lookup.loading),
75
+ error: lookups.find((lookup) => lookup.error)?.error ?? null
76
+ };
77
+ };
47
78
  /** A record type's tags as picker options; none without `tags`. */
48
79
  const useTagOptions = (tags, enabled = true) => useLookup(tags, enabled, tagOption);
49
80
  /** A button that picks members or tags, one or several with `multiple`. */
@@ -81,4 +112,4 @@ const LookupPicker = ({ lookup: { options, loading, error }, value, onValueChang
81
112
  }) })]
82
113
  });
83
114
  };
84
- export { LookupPicker, useMemberOptions, useTagOptions };
115
+ export { LookupPicker, useContactOptions, useMemberOptions, useTagOptions };
@@ -6,7 +6,8 @@ declare const RecordListSkeleton: ({ rows }: {
6
6
  }) => import("react").JSX.Element;
7
7
  /**
8
8
  * Rows grouped under headers that fold away, such as tasks by status.
9
- * Each group's sticky header picks all its rows, and folded groups are kept in this browser.
9
+ * Each group's sticky header picks all its rows (unless `selectable={false}`), and folded groups
10
+ * are kept in this browser.
10
11
  * Wrap it in `RecordList.Provider`, which holds the selection `RecordList.useSelection` reads
11
12
  * for a bulk command bar.
12
13
  */
@@ -11,7 +11,8 @@ const RecordListSkeleton = ({ rows = 8 }) => /* @__PURE__ */ jsx("div", {
11
11
  });
12
12
  /**
13
13
  * Rows grouped under headers that fold away, such as tasks by status.
14
- * Each group's sticky header picks all its rows, and folded groups are kept in this browser.
14
+ * Each group's sticky header picks all its rows (unless `selectable={false}`), and folded groups
15
+ * are kept in this browser.
15
16
  * Wrap it in `RecordList.Provider`, which holds the selection `RecordList.useSelection` reads
16
17
  * for a bulk command bar.
17
18
  */
@@ -17,6 +17,8 @@ interface RecordListProps<TRow> {
17
17
  renderRow: (row: TRow) => ReactNode;
18
18
  /** False: one list with no headers, such as rows sorted by date. */
19
19
  grouped?: boolean;
20
+ /** False: rows without checkboxes, for a list with no bulk actions. */
21
+ selectable?: boolean;
20
22
  className?: string;
21
23
  }
22
24
  /**
@@ -24,5 +26,5 @@ interface RecordListProps<TRow> {
24
26
  * folded groups are kept in this browser. Shift-click picks every row between two clicks, as
25
27
  * shown. Inside `RecordList.Provider`, which holds the selection a command bar reads.
26
28
  */
27
- export declare const RecordListRoot: <TRow>({ groups, rowId, rowLabel, renderRow, grouped, className }: RecordListProps<TRow>) => import("react").JSX.Element;
29
+ export declare const RecordListRoot: <TRow>({ groups, rowId, rowLabel, renderRow, grouped, selectable, className }: RecordListProps<TRow>) => import("react").JSX.Element;
28
30
  export {};
@@ -15,45 +15,57 @@ import { useAtom } from "jotai";
15
15
  */
16
16
  const revealed = "opacity-0 group-hover/list-row:opacity-100 group-focus-within/list-row:opacity-100";
17
17
  const useHover = () => useMediaQuery("(hover: hover) and (not (any-pointer: coarse))");
18
- const GroupHeader = ({ group, ids, panelId, collapsed, onCollapse }) => {
18
+ const GroupHeader = ({ group, ids, panelId, collapsed, onCollapse, selectable }) => /* @__PURE__ */ jsxs("div", {
19
+ 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",
20
+ children: [
21
+ selectable && /* @__PURE__ */ jsx(GroupCheckbox, {
22
+ label: group.label,
23
+ ids
24
+ }),
25
+ /* @__PURE__ */ jsxs(Button, {
26
+ variant: "ghost",
27
+ size: "sm",
28
+ "aria-expanded": !collapsed,
29
+ "aria-controls": collapsed ? void 0 : panelId,
30
+ onClick: () => onCollapse(!collapsed),
31
+ children: [
32
+ collapsed ? /* @__PURE__ */ jsx(IconChevronRight, { "aria-hidden": true }) : /* @__PURE__ */ jsx(IconChevronDown, { "aria-hidden": true }),
33
+ group.icon,
34
+ group.label,
35
+ /* @__PURE__ */ jsx("span", {
36
+ className: "text-muted-foreground tabular-nums",
37
+ children: ids.length
38
+ })
39
+ ]
40
+ }),
41
+ group.action && /* @__PURE__ */ jsx("span", {
42
+ className: "ml-auto flex items-center",
43
+ children: group.action
44
+ })
45
+ ]
46
+ });
47
+ /** Picks or drops every row of a group. */
48
+ const GroupCheckbox = ({ label, ids }) => {
19
49
  const { selection } = useRecordListContext();
20
50
  const hover = useHover();
21
51
  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
- ]
52
+ return /* @__PURE__ */ jsx("span", {
53
+ className: cn("flex h-9 w-8 shrink-0 items-center justify-center", hover && !picked && revealed),
54
+ children: /* @__PURE__ */ jsx(Checkbox, {
55
+ checked: picked > 0 && picked === ids.length,
56
+ indeterminate: picked > 0 && picked < ids.length,
57
+ "aria-label": `Select all in ${label}`,
58
+ onCheckedChange: () => selection.toggleAll(ids)
59
+ })
55
60
  });
56
61
  };
62
+ const rowClass = "group/list-row flex h-11 items-center gap-1 border-b px-2 text-sm hover:bg-muted data-selected:bg-primary/10";
63
+ /** A row with no checkbox, in a list without selection. */
64
+ const PlainRow = ({ id, children }) => /* @__PURE__ */ jsx("li", {
65
+ "data-record-row": id,
66
+ className: rowClass,
67
+ children
68
+ });
57
69
  const Row = ({ id, label, order, children }) => {
58
70
  const { selection } = useRecordListContext();
59
71
  const hover = useHover();
@@ -62,7 +74,7 @@ const Row = ({ id, label, order, children }) => {
62
74
  return /* @__PURE__ */ jsxs("li", {
63
75
  "data-record-row": id,
64
76
  "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",
77
+ className: rowClass,
66
78
  children: [/* @__PURE__ */ jsx("span", {
67
79
  className: cn("flex h-11 w-8 shrink-0 items-center justify-center", hover && !selecting && revealed),
68
80
  children: /* @__PURE__ */ jsx(Checkbox, {
@@ -83,17 +95,20 @@ const Row = ({ id, label, order, children }) => {
83
95
  * folded groups are kept in this browser. Shift-click picks every row between two clicks, as
84
96
  * shown. Inside `RecordList.Provider`, which holds the selection a command bar reads.
85
97
  */
86
- const RecordListRoot = ({ groups, rowId, rowLabel, renderRow, grouped = true, className }) => {
98
+ const RecordListRoot = ({ groups, rowId, rowLabel, renderRow, grouped = true, selectable = true, className }) => {
87
99
  const { listId } = useRecordListContext();
88
100
  const [collapsed, setCollapsed] = useAtom(collapsedGroups(listId));
89
101
  const prefix = useId();
90
102
  const folded = (group) => grouped && collapsed.includes(group.id);
91
103
  const order = groups.filter((group) => !folded(group)).flatMap((group) => group.rows.map(rowId));
92
- const rows = (list) => list.map((row) => /* @__PURE__ */ jsx(Row, {
104
+ const rows = (list) => list.map((row) => selectable ? /* @__PURE__ */ jsx(Row, {
93
105
  id: rowId(row),
94
106
  label: rowLabel(row),
95
107
  order,
96
108
  children: renderRow(row)
109
+ }, rowId(row)) : /* @__PURE__ */ jsx(PlainRow, {
110
+ id: rowId(row),
111
+ children: renderRow(row)
97
112
  }, rowId(row)));
98
113
  if (!grouped) return /* @__PURE__ */ jsx("div", {
99
114
  "data-record-list": listId,
@@ -112,6 +127,7 @@ const RecordListRoot = ({ groups, rowId, rowLabel, renderRow, grouped = true, cl
112
127
  ids: group.rows.map(rowId),
113
128
  panelId,
114
129
  collapsed: folded(group),
130
+ selectable,
115
131
  onCollapse: (fold) => setCollapsed((current) => fold ? [...current, group.id] : current.filter((id) => id !== group.id))
116
132
  }), !folded(group) && /* @__PURE__ */ jsx("ul", {
117
133
  id: panelId,
@@ -1,8 +1,13 @@
1
- import { RecordTableFeatures } from "./RecordTableProvider.js";
1
+ import { RecordTableFeatures, TRecordTableSort } from "./RecordTableProvider.js";
2
2
  import React from "react";
3
3
  import { Header, RowData } from "@tanstack/react-table";
4
4
  type RecordTableHeader = Header<RecordTableFeatures, RowData>;
5
- /** A header cell: drag it to reorder its column, drag its right edge to resize it. */
5
+ /** Off → ascending → descending → off. */
6
+ export declare const nextSort: (sort: TRecordTableSort | null, by: string) => TRecordTableSort | null;
7
+ /**
8
+ * A header cell: drag it to reorder its column, drag its right edge to resize it, click it to
9
+ * sort by it when the table sorts (`RecordTable.Provider`'s `sortable`).
10
+ */
6
11
  export declare const RecordTableHead: ({ header, pinned, children, className, ...props }: React.ComponentProps<'th'> & {
7
12
  header: RecordTableHeader;
8
13
  pinned: boolean;
@@ -2,8 +2,9 @@ import { Table } from "../../../components/table.js";
2
2
  import { cn } from "../../../lib/utils.js";
3
3
  import { isStructuralColumn } from "../utils/columnUtils.js";
4
4
  import { useRecordTable, useRecordTableState } from "./RecordTableProvider.js";
5
+ import { IconArrowDown, IconArrowUp, IconArrowsSort } from "@tabler/icons-react";
5
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
- import "react";
7
+ import { useRef } from "react";
7
8
  import { cva } from "class-variance-authority";
8
9
  import { useDndContext } from "@dnd-kit/core";
9
10
  import { useSortable } from "@dnd-kit/sortable";
@@ -13,10 +14,65 @@ const recordTableHeadVariants = cva("sticky z-2 top-0 w-(--head-width) transitio
13
14
  isDragging: { true: "z-3" },
14
15
  pinned: { true: "z-3 left-(--head-start)" }
15
16
  } });
16
- /** A header cell: drag it to reorder its column, drag its right edge to resize it. */
17
+ const SORT_BUTTON = {
18
+ none: {
19
+ Icon: IconArrowsSort,
20
+ label: "Sort ascending"
21
+ },
22
+ asc: {
23
+ Icon: IconArrowUp,
24
+ label: "Sort descending"
25
+ },
26
+ desc: {
27
+ Icon: IconArrowDown,
28
+ label: "Clear sort"
29
+ }
30
+ };
31
+ const ARIA_SORT = {
32
+ asc: "ascending",
33
+ desc: "descending",
34
+ none: "none"
35
+ };
36
+ const CLICK_MS = 300;
37
+ /** Off → ascending → descending → off. */
38
+ const nextSort = (sort, by) => {
39
+ if (sort?.by !== by) return {
40
+ by,
41
+ direction: "asc"
42
+ };
43
+ return sort.direction === "asc" ? {
44
+ by,
45
+ direction: "desc"
46
+ } : null;
47
+ };
48
+ /** The header's sort control: the order shown, and a button for the keyboard. */
49
+ const SortButton = ({ direction, onSort }) => {
50
+ const { Icon, label } = SORT_BUTTON[direction ?? "none"];
51
+ return /* @__PURE__ */ jsx("button", {
52
+ type: "button",
53
+ "aria-label": label,
54
+ className: cn("relative z-1 ml-1 inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:bg-muted focus-visible:opacity-100 focus-visible:outline-2 focus-visible:outline-ring", !direction && "opacity-0 group-hover/head:opacity-100"),
55
+ onClick: (event) => {
56
+ event.stopPropagation();
57
+ onSort();
58
+ },
59
+ children: /* @__PURE__ */ jsx(Icon, {
60
+ className: "size-3.5",
61
+ "aria-hidden": true
62
+ })
63
+ });
64
+ };
65
+ /**
66
+ * A header cell: drag it to reorder its column, drag its right edge to resize it, click it to
67
+ * sort by it when the table sorts (`RecordTable.Provider`'s `sortable`).
68
+ */
17
69
  const RecordTableHead = ({ header, pinned, children, className, ...props }) => {
18
70
  const { id } = header.column;
19
- const { headId } = useRecordTable();
71
+ const { headId, sorting } = useRecordTable();
72
+ const pressedAt = useRef(0);
73
+ const sortable = Boolean(sorting?.columns.includes(id));
74
+ const direction = sorting?.sort?.by === id ? sorting.sort.direction : void 0;
75
+ const sort = () => sorting?.onChange(nextSort(sorting.sort, id));
20
76
  const { isDragging, listeners, setNodeRef, transform } = useSortable({
21
77
  id,
22
78
  disabled: pinned
@@ -27,13 +83,24 @@ const RecordTableHead = ({ header, pinned, children, className, ...props }) => {
27
83
  className: cn(recordTableHeadVariants({
28
84
  isDragging,
29
85
  pinned
30
- }), className),
86
+ }), sortable && "group/head cursor-pointer", className),
31
87
  style: {
32
88
  "--head-width": `var(--header-${header.id}-width)`,
33
89
  "--head-start": pinned ? `var(--col-${id}-start)` : void 0
34
90
  },
91
+ "aria-sort": sortable ? ARIA_SORT[direction ?? "none"] : void 0,
92
+ onPointerDown: sortable ? () => pressedAt.current = Date.now() : void 0,
93
+ onClick: sortable ? () => {
94
+ if (Date.now() - pressedAt.current < CLICK_MS) sort();
95
+ } : void 0,
35
96
  ...props,
36
- children: [children, !isStructuralColumn(id) && /* @__PURE__ */ jsxs(Fragment, { children: [
97
+ children: [sortable ? /* @__PURE__ */ jsxs("div", {
98
+ className: "flex items-center",
99
+ children: [children, /* @__PURE__ */ jsx(SortButton, {
100
+ direction,
101
+ onSort: sort
102
+ })]
103
+ }) : children, !isStructuralColumn(id) && /* @__PURE__ */ jsxs(Fragment, { children: [
37
104
  /* @__PURE__ */ jsx("span", {
38
105
  ...listeners,
39
106
  "aria-hidden": true,
@@ -75,4 +142,4 @@ const RecordTableHeadSize = ({ header }) => {
75
142
  onTouchStart: startResize
76
143
  });
77
144
  };
78
- export { RecordTableHead };
145
+ export { RecordTableHead, nextSort };
@@ -16,8 +16,21 @@ export type RecordTableFeatures = typeof recordTableFeatures;
16
16
  export type RecordTableColumnDef<TData extends RowData> = ColumnDef<RecordTableFeatures, TData>;
17
17
  /** Rows are typed `RowData` here: every table shares this context, whatever its data. */
18
18
  export type RecordTableInstance = Table<RecordTableFeatures, RowData>;
19
+ /** The order a list's rows come in: by a column, either way. The page sorts (usually its query). */
20
+ export interface TRecordTableSort {
21
+ by: string;
22
+ direction: 'asc' | 'desc';
23
+ }
24
+ interface IRecordTableSorting {
25
+ sort: TRecordTableSort | null;
26
+ /** The columns a click on their header sorts by. */
27
+ columns: readonly string[];
28
+ onChange: (sort: TRecordTableSort | null) => void;
29
+ }
19
30
  interface IRecordTableContext {
20
31
  table: RecordTableInstance;
32
+ /** Null: the table doesn't sort from its headers. */
33
+ sorting: IRecordTableSorting | null;
21
34
  columnSelectorOpen: boolean;
22
35
  setColumnSelectorOpen: (open: boolean) => void;
23
36
  /** The id of a column's header cell, unique per table: cells are named by their column. */
@@ -37,6 +50,14 @@ export interface RecordTableProviderProps<TData extends RowData> extends HTMLAtt
37
50
  data: TData[];
38
51
  stickyColumns?: string[];
39
52
  tableId?: string;
53
+ /**
54
+ * Sorting by a click on a column's header: off, then ascending, then descending, then off.
55
+ * `sortable` lists the columns that sort; the page orders the rows by `sort` (its query does)
56
+ * and keeps it, e.g. in the URL. Without `onSortChange` no header sorts.
57
+ */
58
+ sort?: TRecordTableSort | null;
59
+ sortable?: readonly string[];
60
+ onSortChange?: (sort: TRecordTableSort | null) => void;
40
61
  }
41
- export declare const RecordTableProvider: <TData extends RowData>({ children, columns, data, stickyColumns, tableId, ...containerProps }: RecordTableProviderProps<TData>) => import("react").JSX.Element;
62
+ export declare const RecordTableProvider: <TData extends RowData>({ children, columns, data, stickyColumns, tableId, sort, sortable, onSortChange, ...containerProps }: RecordTableProviderProps<TData>) => import("react").JSX.Element;
42
63
  export {};
@@ -34,7 +34,7 @@ const useRecordTableState = (select) => {
34
34
  };
35
35
  /** A row's `_id` or `id`, else tanstack's default (its index under its parent). */
36
36
  const getRowId = (row, index, parent) => readRow(row).id ?? (parent ? `${parent.id}.${index}` : String(index));
37
- const RecordTableProvider = ({ children, columns, data, stickyColumns, tableId, ...containerProps }) => {
37
+ const RecordTableProvider = ({ children, columns, data, stickyColumns, tableId, sort = null, sortable, onSortChange, ...containerProps }) => {
38
38
  const [columnSelectorOpen, setColumnSelectorOpen] = useState(false);
39
39
  const { state, setColumnOrder, ...layoutHandlers } = useColumnLayout({
40
40
  columnIds: columns.map((column) => column.id ?? ""),
@@ -53,13 +53,24 @@ const RecordTableProvider = ({ children, columns, data, stickyColumns, tableId,
53
53
  getRowId
54
54
  }, () => null);
55
55
  const headPrefix = useId();
56
+ const sorting = useMemo(() => onSortChange ? {
57
+ sort,
58
+ columns: sortable ?? [],
59
+ onChange: onSortChange
60
+ } : null, [
61
+ sort,
62
+ sortable,
63
+ onSortChange
64
+ ]);
56
65
  const context = useMemo(() => ({
57
66
  table: shared,
67
+ sorting,
58
68
  columnSelectorOpen,
59
69
  setColumnSelectorOpen,
60
70
  headId: (columnId) => `${headPrefix}-head-${columnId}`
61
71
  }), [
62
72
  shared,
73
+ sorting,
63
74
  columnSelectorOpen,
64
75
  headPrefix
65
76
  ]);
@@ -26,6 +26,24 @@ export interface ContactQueries {
26
26
  customer: (id: string) => ContactQuery<CustomerContact>;
27
27
  company: (id: string) => ContactQuery<CompanyContact>;
28
28
  }
29
+ type ContactRows<T> = UseQueryOptions<{
30
+ data: T[];
31
+ }, Error, {
32
+ data: T[];
33
+ }>;
34
+ /** What a contact search asks for: matches, or the contacts with these ids. */
35
+ export interface ContactSearch {
36
+ search?: string;
37
+ ids?: string[];
38
+ }
39
+ /**
40
+ * Where a filter's `customer` and `company` fields search contacts.
41
+ * TanStack query options; in erxes, `contactSearchQueries` from `@erxes/core-contract/client`.
42
+ */
43
+ export interface ContactSearchQueries {
44
+ customers: (input: ContactSearch) => ContactRows<CustomerContact>;
45
+ companies: (input: ContactSearch) => ContactRows<CompanyContact>;
46
+ }
29
47
  /** The customer or company types `ContactLink` shows. */
30
48
  export type TContactContentType = 'core:customer' | 'core:company';
31
49
  /** A customer's name, else its email or phone. */
@@ -16,9 +16,11 @@ type OpenNewRecord = (contentType: string, defaults?: Record<string, unknown>) =
16
16
  * record so Back returns to it. erxes-ui is a Module Federation singleton, so every plugin
17
17
  * reads the host's.
18
18
  */
19
- export declare const RecordOpenerProvider: ({ open, openNew, children }: PropsWithChildren<{
19
+ export declare const RecordOpenerProvider: ({ open, openNew, current, dismiss, children }: PropsWithChildren<{
20
20
  open: OpenRecord;
21
21
  openNew?: OpenNewRecord;
22
+ current?: RecordRef | null;
23
+ dismiss?: OpenRecord;
22
24
  }>) => import("react").JSX.Element;
23
25
  /**
24
26
  * Opens a record, or a new draft, in core's side panel.
@@ -27,18 +29,58 @@ export declare const RecordOpenerProvider: ({ open, openNew, children }: PropsWi
27
29
  * `openNew('sales:deal', { stageId })` opens a draft that becomes the record on Save. Any
28
30
  * type core or an installed plugin registers opens (`IUIConfig.recordTypes`). `canOpen` is
29
31
  * false outside erxes (a plugin page rendered on its own), where both do nothing.
32
+ *
33
+ * `current` is the record the panel shows now (null when it shows none or a draft), for a list
34
+ * that marks it or steps to the next (j/k). `dismiss(record)` takes a record out of the panel,
35
+ * shown or behind Back, e.g. one the list just deleted. Inside a record, `useRecordPanel`.
30
36
  */
31
37
  export declare const useOpenRecord: () => {
32
38
  open: OpenRecord;
33
39
  openNew: OpenNewRecord;
40
+ current: RecordRef | null;
41
+ dismiss: OpenRecord;
34
42
  canOpen: boolean;
35
43
  };
44
+ /**
45
+ * What a record shown in core's panel, or on its own page, can do to it. Core's own tabs are
46
+ * `detail` and `activity`; a type's `tabs` use their `value`.
47
+ */
48
+ export interface RecordPanelControls {
49
+ record: RecordRef;
50
+ /** The tab shown; empty is the record's default. */
51
+ tab: string;
52
+ /** Shows a tab: an Actions menu item whose form opens on Detail picks `detail` first. */
53
+ setTab: (tab: string) => void;
54
+ /** Closes the panel; on a record's own page, goes back to its list. */
55
+ close: () => void;
56
+ /** Takes this record out, e.g. after deleting it: back to the record under it, else closed. */
57
+ dismiss: () => void;
58
+ /** Puts another record in this one's place, Back unchanged: a request accepted as a task. */
59
+ replace: (next: RecordRef) => void;
60
+ }
61
+ /** Web gives each record it shows its controls. */
62
+ export declare const RecordPanelProvider: import("react").Context<RecordPanelControls | null>;
63
+ /**
64
+ * The record a slot is in, and what the slot can do to it.
65
+ * Any slot (`Title`, `Actions`, `Detail`, a tab, a relation tab): `const panel = useRecordPanel()`, then `panel?.dismiss()` after a delete,
66
+ * `panel?.replace({ contentType: 'tasks:task', contentId })`, `panel?.setTab('detail')`.
67
+ * Null outside a record (a plugin page on its own).
68
+ */
69
+ export declare const useRecordPanel: () => RecordPanelControls | null;
70
+ /** A `RecordPage`'s record, and the list it goes back to. */
71
+ export interface RecordPageProps extends RecordRef {
72
+ /**
73
+ * The list closing or deleting the record goes back to, e.g. its team's tasks; without it, the
74
+ * plugin's first page. Pass it once the record is known.
75
+ */
76
+ listPath?: string;
77
+ }
36
78
  /** Web registers how a record draws on its own page. */
37
- export declare const setRecordPage: (component: import("react").ComponentType<RecordRef> | null) => void;
79
+ export declare const setRecordPage: (component: import("react").ComponentType<RecordPageProps> | null) => void;
38
80
  /**
39
81
  * A record on its own page, as core draws a customer's.
40
82
  * The record's View at full size, under the page header, with Back to its list. A plugin
41
- * routes its record type's `listPath/:id` to `<RecordPage contentType="sales:deal" contentId={id} />`.
83
+ * routes its record type's `detailPath` to `<RecordPage contentType="sales:deal" contentId={id} listPath="/sales/deals" />`.
42
84
  */
43
- export declare const RecordPage: (props: RecordRef) => import("react").JSX.Element | null;
85
+ export declare const RecordPage: (props: RecordPageProps) => import("react").JSX.Element | null;
44
86
  export {};
@@ -10,11 +10,18 @@ const ignore = () => void 0;
10
10
  * record so Back returns to it. erxes-ui is a Module Federation singleton, so every plugin
11
11
  * reads the host's.
12
12
  */
13
- const RecordOpenerProvider = ({ open, openNew = ignore, children }) => {
13
+ const RecordOpenerProvider = ({ open, openNew = ignore, current = null, dismiss = ignore, children }) => {
14
14
  const opener = useMemo(() => ({
15
15
  open,
16
- openNew
17
- }), [open, openNew]);
16
+ openNew,
17
+ current,
18
+ dismiss
19
+ }), [
20
+ open,
21
+ openNew,
22
+ current,
23
+ dismiss
24
+ ]);
18
25
  return /* @__PURE__ */ jsx(RecordOpenerContext, {
19
26
  value: opener,
20
27
  children
@@ -27,22 +34,38 @@ const RecordOpenerProvider = ({ open, openNew = ignore, children }) => {
27
34
  * `openNew('sales:deal', { stageId })` opens a draft that becomes the record on Save. Any
28
35
  * type core or an installed plugin registers opens (`IUIConfig.recordTypes`). `canOpen` is
29
36
  * false outside erxes (a plugin page rendered on its own), where both do nothing.
37
+ *
38
+ * `current` is the record the panel shows now (null when it shows none or a draft), for a list
39
+ * that marks it or steps to the next (j/k). `dismiss(record)` takes a record out of the panel,
40
+ * shown or behind Back, e.g. one the list just deleted. Inside a record, `useRecordPanel`.
30
41
  */
31
42
  const useOpenRecord = () => {
32
43
  const opener = use(RecordOpenerContext);
33
44
  return {
34
45
  open: opener?.open ?? ignore,
35
46
  openNew: opener?.openNew ?? ignore,
47
+ current: opener?.current ?? null,
48
+ dismiss: opener?.dismiss ?? ignore,
36
49
  canOpen: opener !== null
37
50
  };
38
51
  };
52
+ const RecordPanelContext = createContext(null);
53
+ /** Web gives each record it shows its controls. */
54
+ const RecordPanelProvider = RecordPanelContext;
55
+ /**
56
+ * The record a slot is in, and what the slot can do to it.
57
+ * Any slot (`Title`, `Actions`, `Detail`, a tab, a relation tab): `const panel = useRecordPanel()`, then `panel?.dismiss()` after a delete,
58
+ * `panel?.replace({ contentType: 'tasks:task', contentId })`, `panel?.setTab('detail')`.
59
+ * Null outside a record (a plugin page on its own).
60
+ */
61
+ const useRecordPanel = () => use(RecordPanelContext);
39
62
  const page = hostComponent();
40
63
  /** Web registers how a record draws on its own page. */
41
64
  const setRecordPage = page.set;
42
65
  /**
43
66
  * A record on its own page, as core draws a customer's.
44
67
  * The record's View at full size, under the page header, with Back to its list. A plugin
45
- * routes its record type's `listPath/:id` to `<RecordPage contentType="sales:deal" contentId={id} />`.
68
+ * routes its record type's `detailPath` to `<RecordPage contentType="sales:deal" contentId={id} listPath="/sales/deals" />`.
46
69
  */
47
70
  const RecordPage = page.Host;
48
- export { RecordOpenerProvider, RecordPage, setRecordPage, useOpenRecord };
71
+ export { RecordOpenerProvider, RecordPage, RecordPanelProvider, setRecordPage, useOpenRecord, useRecordPanel };