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

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 (30) hide show
  1. package/CATALOG.md +12 -6
  2. package/dist/index.d.ts +5 -5
  3. package/dist/index.js +3 -2
  4. package/dist/modules/conditions/ValueEditor.js +9 -4
  5. package/dist/modules/conditions/conditions.d.ts +7 -3
  6. package/dist/modules/conditions/conditions.js +8 -1
  7. package/dist/modules/conditions/fieldIcons.js +3 -1
  8. package/dist/modules/conditions/fieldOptions.d.ts +7 -5
  9. package/dist/modules/conditions/fieldOptions.js +22 -10
  10. package/dist/modules/conditions/filterRule.js +3 -1
  11. package/dist/modules/list/ListFilter.d.ts +6 -5
  12. package/dist/modules/list/ListFilter.js +3 -3
  13. package/dist/modules/list/filter/ListFilterBar.js +8 -3
  14. package/dist/modules/pickers/LookupPicker.d.ts +6 -0
  15. package/dist/modules/pickers/LookupPicker.js +32 -1
  16. package/dist/modules/record-list/RecordList.d.ts +2 -1
  17. package/dist/modules/record-list/RecordList.js +2 -1
  18. package/dist/modules/record-list/RecordListRoot.d.ts +3 -1
  19. package/dist/modules/record-list/RecordListRoot.js +53 -37
  20. package/dist/modules/record-table/components/RecordTableHead.d.ts +7 -2
  21. package/dist/modules/record-table/components/RecordTableHead.js +73 -6
  22. package/dist/modules/record-table/components/RecordTableProvider.d.ts +22 -1
  23. package/dist/modules/record-table/components/RecordTableProvider.js +12 -1
  24. package/dist/modules/records/contacts.d.ts +18 -0
  25. package/dist/modules/records/openRecord.d.ts +35 -1
  26. package/dist/modules/records/openRecord.js +27 -4
  27. package/dist/types/UIConfig.d.ts +47 -100
  28. package/dist/types/UIConfig.js +14 -0
  29. package/exports.txt +9 -3
  30. package/package.json +1 -1
@@ -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,12 +29,44 @@ 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;
36
70
  /** Web registers how a record draws on its own page. */
37
71
  export declare const setRecordPage: (component: import("react").ComponentType<RecordRef> | null) => void;
38
72
  /**
@@ -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,15 +34,31 @@ 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;
@@ -45,4 +68,4 @@ const setRecordPage = page.set;
45
68
  * routes its record type's `listPath/:id` to `<RecordPage contentType="sales:deal" contentId={id} />`.
46
69
  */
47
70
  const RecordPage = page.Host;
48
- export { RecordOpenerProvider, RecordPage, setRecordPage, useOpenRecord };
71
+ export { RecordOpenerProvider, RecordPage, RecordPanelProvider, setRecordPage, useOpenRecord, useRecordPanel };
@@ -2,39 +2,34 @@ import { TContactContentType } from "../modules/records/contacts.js";
2
2
  import { RecordRef } from "../modules/records/openRecord.js";
3
3
  import { Icon } from "@tabler/icons-react";
4
4
  import { UseQueryOptions } from "@tanstack/react-query";
5
+ /** Every schematic the widget catalog can draw for a dashboard widget. */
6
+ export declare const DASHBOARD_WIDGET_PREVIEWS: readonly ['bar', 'line', 'area', 'pie', 'table', 'list', 'kpi', 'heatmap', 'progress'];
7
+ /** The schematic a dashboard widget shows in the widget catalog. */
8
+ export type TDashboardWidgetPreview = (typeof DASHBOARD_WIDGET_PREVIEWS)[number];
5
9
  /**
6
- * A property input's own settings, stored with the custom field.
7
- * Each input defines its keys.
8
- */
9
- export type TPropertyInputMeta = Record<string, unknown>;
10
- /**
11
- * Props of a plugin's activity row component in `widgets.activityRows`.
12
- * The shape comes from erxes 3.x; web doesn't read `widgets` from a plugin's config.
10
+ * A plugin's tile for core's home dashboard.
11
+ * It shows in the widget catalog, under the plugin's name, to members who may use the plugin.
12
+ * A member places it at most once.
13
13
  */
14
- export type TActivityRowProps = {
15
- activity: {
16
- _id: string;
17
- activityType: string;
18
- sourcePlugin?: string;
19
- createdAt: string | Date;
20
- /** The plugin's own payload for the row. */
21
- metadata?: Record<string, unknown>;
14
+ export type TDashboardWidget = {
15
+ /** Unique within the plugin, e.g. `open-tickets`: a saved tile names it. */
16
+ name: string;
17
+ title: string;
18
+ description?: string;
19
+ icon: React.ElementType;
20
+ /** The schematic the catalog draws; the icon when left out. */
21
+ preview?: TDashboardWidgetPreview;
22
+ /** Grid units on a 12-column grid when placed; 6 × 6 when left out. */
23
+ size?: {
24
+ w: number;
25
+ h: number;
22
26
  };
27
+ /**
28
+ * The tile's body, under core's header with the title; it scrolls when taller than the tile.
29
+ * A `lazy` one loads when the tile first shows.
30
+ */
31
+ component: React.ComponentType;
23
32
  };
24
- /**
25
- * Props of a custom property input in `widgets.propertyInputs`.
26
- * It edits the field's value as text and its own settings as `meta`. The shape comes from
27
- * erxes 3.x; web doesn't read `widgets` from a plugin's config.
28
- */
29
- export type TPropertyInputProps = {
30
- value: string;
31
- onValueChange: (value: string) => void;
32
- meta?: TPropertyInputMeta;
33
- onMetaChange: (meta: TPropertyInputMeta) => void;
34
- disabled?: boolean;
35
- };
36
- /** The schematic a dashboard widget shows in the widget catalog. */
37
- export type TDashboardWidgetPreview = 'bar' | 'line' | 'area' | 'pie' | 'table' | 'list' | 'kpi' | 'heatmap' | 'progress';
38
33
  /** What a record section is given: the customer or company it shows on. */
39
34
  export type TRecordSectionProps = {
40
35
  contentType: TContactContentType;
@@ -135,25 +130,44 @@ export type TRelationTab = {
135
130
  hosts?: string[];
136
131
  component: React.ComponentType<TRelationTabProps>;
137
132
  };
133
+ /**
134
+ * A plugin's settings page, linked from core's settings sidebar.
135
+ * The page is a route of the plugin's own, under its `path`, e.g. `/frontline/settings/tags`.
136
+ */
137
+ export type TPluginSettingsPage = {
138
+ /** The page's address, under the plugin's `path`. */
139
+ path: string;
140
+ label: string;
141
+ icon?: React.ElementType;
142
+ };
138
143
  /**
139
144
  * A plugin UI's `CONFIG`, exported from its `./config` remote.
140
- * web reads `name`, `path`, `icon`, `modules`, `checkAccess`, `recordSections`, `recordTypes`
141
- * and `relationTabs`; its first module renders under `/<path>/*`. The other fields come from
142
- * erxes 3.x and web ignores them.
145
+ * web reads `name`, `path`, `icon`, `modules`, `checkAccess`, `recordSections`, `recordTypes`,
146
+ * `relationTabs`, `settings`, `dashboardWidgets` and `floatingWidget`; its first module renders
147
+ * under `/<path>/*`. The other fields come from erxes 3.x and web ignores them.
143
148
  */
144
149
  export type IUIConfig = {
145
150
  name: string;
146
151
  path: string;
147
152
  icon?: React.ElementType;
153
+ /** The plugin's settings pages, in core's settings sidebar for members who may use the plugin. */
154
+ settings?: TPluginSettingsPage[];
148
155
  /** Sections on core's customer and company detail, shown to members who may use the plugin. */
149
156
  recordSections?: TRecordSection[];
150
157
  /** The plugin's records core's side panel opens, for members who may use the plugin. */
151
158
  recordTypes?: TPanelRecordType[];
152
159
  /** Tabs on other records' panels listing the plugin's records of their contacts. */
153
160
  relationTabs?: TRelationTab[];
161
+ /** Tiles in core's home dashboard catalog, for members who may use the plugin. */
162
+ dashboardWidgets?: TDashboardWidget[];
163
+ /**
164
+ * One component web mounts once beside the app shell, on every page, for members who may use
165
+ * the plugin, and keeps mounted across navigation (a softphone). It sits in the bottom-right
166
+ * corner above the page.
167
+ */
168
+ floatingWidget?: React.ComponentType;
154
169
  i18n?: boolean;
155
170
  i18nNamespace?: string;
156
- hasFloatingWidget?: boolean;
157
171
  /**
158
172
  * erxes platform versions this plugin is built for, as a semver range
159
173
  * (e.g. `'~3.2'`, `'>=3.2.25 <3.4'`). Core warns, and still loads the
@@ -175,79 +189,12 @@ export type IUIConfig = {
175
189
  */
176
190
  subGroup?: () => React.ReactNode;
177
191
  };
178
- widgets?: {
179
- relationWidgets?: {
180
- name: string;
181
- icon?: React.ElementType;
182
- label?: string;
183
- contentTypes?: string[];
184
- }[];
185
- relationSettingsWidgets?: {
186
- name: string;
187
- icon?: React.ElementType;
188
- label?: string;
189
- }[];
190
- recordPickerWidgets?: {
191
- name: string;
192
- contentType: string;
193
- }[];
194
- recordPanels?: {
195
- contentType: string;
196
- properties?: boolean;
197
- draftTitle?: boolean;
198
- tabs?: {
199
- value: string;
200
- label: string;
201
- labelKey?: string;
202
- icon?: Icon;
203
- after?: 'detail' | 'properties' | 'activity';
204
- }[];
205
- detailPath?: (recordId: string, pathname: string) => string;
206
- }[];
207
- contactWidgets?: {
208
- name: string;
209
- label?: string;
210
- icon?: React.ElementType;
211
- }[];
212
- customerDetailWidgets?: {
213
- name: string;
214
- }[];
215
- dashboardWidgets?: {
216
- name: string;
217
- label: string;
218
- description?: string;
219
- icon?: React.ElementType;
220
- defaultSize: {
221
- w: number;
222
- h: number;
223
- };
224
- minSize?: {
225
- w: number;
226
- h: number;
227
- };
228
- maxSize?: {
229
- w: number;
230
- h: number;
231
- };
232
- configurable?: boolean;
233
- singleton?: boolean;
234
- preview?: TDashboardWidgetPreview;
235
- }[];
236
- formWidgets?: {
237
- name: string;
238
- contentType: string;
239
- icon?: React.ElementType;
240
- }[];
241
- propertyInputs?: Record<string, React.ComponentType<TPropertyInputProps>>;
242
- activityRows?: Record<string, React.ComponentType<TActivityRowProps>>;
243
- };
244
192
  modules?: {
245
193
  name: string;
246
194
  icon?: React.ElementType;
247
195
  path: string;
248
196
  hasAutomation?: boolean;
249
197
  hasRelationWidget?: boolean;
250
- hasFloatingWidget?: boolean;
251
198
  hasSegmentConfigWidget?: boolean;
252
199
  }[];
253
200
  };