@erxes/ui 4.0.0-v2.5 → 4.0.0-v2.7
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 +13 -0
- package/dist/components/icon-tip.d.ts +7 -0
- package/dist/components/icon-tip.js +16 -0
- package/dist/hooks/use-page-hotkey.d.ts +11 -0
- package/dist/hooks/use-page-hotkey.js +21 -0
- package/dist/index.d.ts +17 -2
- package/dist/index.js +16 -1
- package/dist/modules/list/DisplayMenu.d.ts +13 -0
- package/dist/modules/list/DisplayMenu.js +66 -0
- package/dist/modules/list/ListFilter.d.ts +44 -0
- package/dist/modules/list/ListFilter.js +39 -0
- package/dist/modules/list/ViewBar.d.ts +13 -0
- package/dist/modules/list/ViewBar.js +30 -0
- package/dist/modules/record-panel/PanelDescriptionEditor.d.ts +9 -0
- package/dist/modules/record-panel/PanelDescriptionEditor.js +39 -0
- package/dist/modules/record-panel/PanelDescriptionField.d.ts +9 -0
- package/dist/modules/record-panel/PanelDescriptionField.js +35 -0
- package/dist/modules/record-panel/PanelField.d.ts +11 -0
- package/dist/modules/record-panel/PanelField.js +41 -0
- package/dist/modules/record-panel/PanelForm.d.ts +22 -0
- package/dist/modules/record-panel/PanelForm.js +81 -0
- package/dist/modules/record-panel/PanelLabel.d.ts +5 -0
- package/dist/modules/record-panel/PanelLabel.js +50 -0
- package/dist/modules/record-panel/PanelSection.d.ts +9 -0
- package/dist/modules/record-panel/PanelSection.js +21 -0
- package/dist/modules/record-panel/panelExpansion.d.ts +10 -0
- package/dist/modules/record-panel/panelExpansion.js +7 -0
- package/dist/modules/record-panel/useSaveOnLeave.d.ts +14 -0
- package/dist/modules/record-panel/useSaveOnLeave.js +42 -0
- package/dist/modules/records/ContactLink.d.ts +13 -0
- package/dist/modules/records/ContactLink.js +77 -0
- package/dist/modules/records/contacts.d.ts +35 -0
- package/dist/modules/records/contacts.js +10 -0
- package/dist/modules/records/openRecord.d.ts +39 -0
- package/dist/modules/records/openRecord.js +46 -0
- package/dist/types/UIConfig.d.ts +101 -0
- package/dist/utils/host-component.d.ts +10 -0
- package/dist/utils/host-component.js +34 -0
- package/dist/utils/plugin-runtime.d.ts +3 -1
- package/dist/utils/plugin-runtime.js +51 -9
- package/dist/utils/record-timeline.d.ts +2 -4
- package/dist/utils/record-timeline.js +4 -17
- package/package.json +2 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Button } from "../../components/button.js";
|
|
2
|
+
import { Spinner } from "../../components/spinner.js";
|
|
3
|
+
import { RecordTableInlineCell } from "../record-table/components/RecordTableCellInline.js";
|
|
4
|
+
import { PanelLabel } from "./PanelLabel.js";
|
|
5
|
+
import { IconForms } from "@tabler/icons-react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { useId } from "react";
|
|
8
|
+
import { useTranslation } from "react-i18next";
|
|
9
|
+
// src/modules/record-panel/PanelForm.tsx
|
|
10
|
+
/**
|
|
11
|
+
* One field of a record not created yet, laid out like `PanelField`: its
|
|
12
|
+
* label, then the input, with the field's error under it.
|
|
13
|
+
*/
|
|
14
|
+
const PanelFormRow = ({ label, icon: Icon = IconForms, required, error, children }) => {
|
|
15
|
+
const labelId = useId();
|
|
16
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
17
|
+
className: "grid grid-cols-field items-center gap-x-2 gap-y-0.5 min-h-7",
|
|
18
|
+
children: [
|
|
19
|
+
/* @__PURE__ */ jsxs("span", {
|
|
20
|
+
id: labelId,
|
|
21
|
+
className: "flex min-w-0 items-center gap-1.5 text-xs font-medium text-accent-foreground",
|
|
22
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
23
|
+
className: "size-3.5 shrink-0",
|
|
24
|
+
"aria-hidden": "true"
|
|
25
|
+
}), /* @__PURE__ */ jsxs(PanelLabel, {
|
|
26
|
+
tooltip: label,
|
|
27
|
+
children: [label, required && /* @__PURE__ */ jsx("span", {
|
|
28
|
+
className: "text-destructive",
|
|
29
|
+
children: " *"
|
|
30
|
+
})]
|
|
31
|
+
})]
|
|
32
|
+
}),
|
|
33
|
+
/* @__PURE__ */ jsxs("div", {
|
|
34
|
+
className: "group/panel-value relative min-w-0 text-xs [&_button:not([role=switch])]:text-xs [&_input:placeholder-shown]:pl-7",
|
|
35
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
36
|
+
className: "pointer-events-none absolute left-2 top-1/2 z-1 hidden size-3.5 -translate-y-1/2 text-muted-foreground group-has-[input:placeholder-shown]/panel-value:block",
|
|
37
|
+
"aria-hidden": "true"
|
|
38
|
+
}), /* @__PURE__ */ jsx(RecordTableInlineCell.LabelledBy, {
|
|
39
|
+
value: labelId,
|
|
40
|
+
children
|
|
41
|
+
})]
|
|
42
|
+
}),
|
|
43
|
+
error && /* @__PURE__ */ jsx("span", {
|
|
44
|
+
className: "col-start-2 text-xs text-destructive",
|
|
45
|
+
children: error
|
|
46
|
+
})
|
|
47
|
+
]
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The body and footer of a new record's form in the side panel: its rows,
|
|
52
|
+
* then Cancel and Save. Nothing is saved until Save.
|
|
53
|
+
*/
|
|
54
|
+
const PanelFormLayout = ({ children, onCancel, saving, saveLabel }) => {
|
|
55
|
+
const { t } = useTranslation("common", { keyPrefix: "side-panel" });
|
|
56
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
57
|
+
className: "flex flex-1 min-h-0 flex-col",
|
|
58
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
59
|
+
className: "flex-1 min-h-0 overflow-y-auto",
|
|
60
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
61
|
+
className: "flex flex-col gap-1 p-3",
|
|
62
|
+
children
|
|
63
|
+
})
|
|
64
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
65
|
+
className: "flex shrink-0 justify-end gap-1 border-t bg-background p-2",
|
|
66
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
67
|
+
type: "button",
|
|
68
|
+
variant: "ghost",
|
|
69
|
+
size: "sm",
|
|
70
|
+
onClick: onCancel,
|
|
71
|
+
children: t("cancel", "Cancel")
|
|
72
|
+
}), /* @__PURE__ */ jsxs(Button, {
|
|
73
|
+
type: "submit",
|
|
74
|
+
size: "sm",
|
|
75
|
+
disabled: saving,
|
|
76
|
+
children: [saving && /* @__PURE__ */ jsx(Spinner, { size: "sm" }), saveLabel || t("save", "Save")]
|
|
77
|
+
})]
|
|
78
|
+
})]
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
export { PanelFormLayout, PanelFormRow };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Tooltip } from "../../components/tooltip.js";
|
|
2
|
+
import { cn } from "../../lib/utils.js";
|
|
3
|
+
import { usePanelExpanded } from "./panelExpansion.js";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
|
+
// src/modules/record-panel/PanelLabel.tsx
|
|
7
|
+
/** Whether the label is cut off; the observers see the clamp come and go with the panel width. */
|
|
8
|
+
const useIsClamped = () => {
|
|
9
|
+
const ref = useRef(null);
|
|
10
|
+
const [isClamped, setIsClamped] = useState(false);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const element = ref.current;
|
|
13
|
+
if (!element) return;
|
|
14
|
+
const check = () => setIsClamped(element.scrollHeight > element.clientHeight + 1);
|
|
15
|
+
const resizeObserver = new ResizeObserver(check);
|
|
16
|
+
const contentObserver = new MutationObserver(check);
|
|
17
|
+
check();
|
|
18
|
+
resizeObserver.observe(element);
|
|
19
|
+
contentObserver.observe(element, {
|
|
20
|
+
childList: true,
|
|
21
|
+
subtree: true,
|
|
22
|
+
characterData: true
|
|
23
|
+
});
|
|
24
|
+
return () => {
|
|
25
|
+
resizeObserver.disconnect();
|
|
26
|
+
contentObserver.disconnect();
|
|
27
|
+
};
|
|
28
|
+
}, []);
|
|
29
|
+
return {
|
|
30
|
+
ref,
|
|
31
|
+
isClamped
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const PanelLabel = ({ children, tooltip, className }) => {
|
|
35
|
+
const expanded = usePanelExpanded();
|
|
36
|
+
const { ref, isClamped } = useIsClamped();
|
|
37
|
+
const showTooltip = isClamped && !expanded;
|
|
38
|
+
return /* @__PURE__ */ jsx(Tooltip.Provider, {
|
|
39
|
+
delay: 100,
|
|
40
|
+
children: /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(Tooltip.Trigger, {
|
|
41
|
+
render: /* @__PURE__ */ jsx("span", { className: cn("my-1 block min-w-0 wrap-break-word", className) }),
|
|
42
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
43
|
+
ref,
|
|
44
|
+
className: cn("block", !expanded && "line-clamp-2"),
|
|
45
|
+
children
|
|
46
|
+
})
|
|
47
|
+
}), showTooltip && /* @__PURE__ */ jsx(Tooltip.Content, { children: tooltip ?? children })] })
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
export { PanelLabel };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ElementType, ReactNode } from "react";
|
|
2
|
+
/** Separates a record's fields, tags and linked records with plain headings. */
|
|
3
|
+
export declare const PanelSection: ({ title, icon: Icon, children, nested }: {
|
|
4
|
+
title: string;
|
|
5
|
+
/** Beside the title, as a plugin's section has it. */
|
|
6
|
+
icon?: ElementType;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
nested?: boolean;
|
|
9
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { cn } from "../../lib/utils.js";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
// src/modules/record-panel/PanelSection.tsx
|
|
4
|
+
/** Separates a record's fields, tags and linked records with plain headings. */
|
|
5
|
+
const PanelSection = ({ title, icon: Icon, children, nested = false }) => /* @__PURE__ */ jsxs("section", {
|
|
6
|
+
className: cn("pt-1", !nested && "border-b last:border-b-0"),
|
|
7
|
+
children: [/* @__PURE__ */ jsxs("h3", {
|
|
8
|
+
className: cn("flex items-center gap-1.5 text-xs", nested ? "h-7 px-1 font-normal text-muted-foreground" : "h-10 px-3 font-medium"),
|
|
9
|
+
children: [Icon && /* @__PURE__ */ jsx(Icon, {
|
|
10
|
+
className: "size-3.5 flex-none text-muted-foreground",
|
|
11
|
+
"aria-hidden": "true"
|
|
12
|
+
}), title]
|
|
13
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
14
|
+
className: cn("min-w-0", nested ? "pb-1" : "px-3 pb-2"),
|
|
15
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
16
|
+
className: "flex min-w-0 flex-col gap-1",
|
|
17
|
+
children
|
|
18
|
+
})
|
|
19
|
+
})]
|
|
20
|
+
});
|
|
21
|
+
export { PanelSection };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Whether the nearest record panel fills a page, and how to switch it. */
|
|
2
|
+
type PanelExpansion = {
|
|
3
|
+
expanded: boolean;
|
|
4
|
+
toggle?: () => void;
|
|
5
|
+
} | null;
|
|
6
|
+
/** Provided by the host's record panel; erxes-ui's panel parts read it. */
|
|
7
|
+
export declare const PanelExpansionContext: import("react").Context<PanelExpansion>;
|
|
8
|
+
/** Whether the record is shown at full size, on its own page: a slot can lay out wider. */
|
|
9
|
+
export declare const usePanelExpanded: () => boolean;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
// src/modules/record-panel/panelExpansion.ts
|
|
3
|
+
/** Provided by the host's record panel; erxes-ui's panel parts read it. */
|
|
4
|
+
const PanelExpansionContext = createContext(null);
|
|
5
|
+
/** Whether the record is shown at full size, on its own page: a slot can lay out wider. */
|
|
6
|
+
const usePanelExpanded = () => useContext(PanelExpansionContext)?.expanded ?? false;
|
|
7
|
+
export { PanelExpansionContext, usePanelExpanded };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Saves a description editor when you click or tab anywhere outside it, never while
|
|
3
|
+
* typing. Focus can't be trusted to leave the editor first: closing the image preview
|
|
4
|
+
* or a toolbar menu drops it on the page. An edit that arrives while focus is already
|
|
5
|
+
* outside, such as an upload that finishes after you moved on, saves right away.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useSaveOnLeave: ({ value, readonly, onSave }: {
|
|
8
|
+
value: string;
|
|
9
|
+
readonly?: boolean;
|
|
10
|
+
onSave: (value: string) => void;
|
|
11
|
+
}) => {
|
|
12
|
+
containerRef: import("react").RefObject<HTMLDivElement | null>;
|
|
13
|
+
onChange: (next: string) => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
// src/modules/record-panel/useSaveOnLeave.ts
|
|
3
|
+
/**
|
|
4
|
+
* Saves a description editor when you click or tab anywhere outside it, never while
|
|
5
|
+
* typing. Focus can't be trusted to leave the editor first: closing the image preview
|
|
6
|
+
* or a toolbar menu drops it on the page. An edit that arrives while focus is already
|
|
7
|
+
* outside, such as an upload that finishes after you moved on, saves right away.
|
|
8
|
+
*/
|
|
9
|
+
const useSaveOnLeave = ({ value, readonly, onSave }) => {
|
|
10
|
+
const containerRef = useRef(null);
|
|
11
|
+
const latest = useRef(value);
|
|
12
|
+
const saved = useRef(value);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
latest.current = value;
|
|
15
|
+
saved.current = value;
|
|
16
|
+
}, [value]);
|
|
17
|
+
const save = () => {
|
|
18
|
+
if (readonly || latest.current === saved.current) return;
|
|
19
|
+
saved.current = latest.current;
|
|
20
|
+
onSave(latest.current);
|
|
21
|
+
};
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const leave = (event) => {
|
|
24
|
+
if (event.target instanceof Node && containerRef.current?.contains(event.target)) return;
|
|
25
|
+
save();
|
|
26
|
+
};
|
|
27
|
+
document.addEventListener("pointerdown", leave, true);
|
|
28
|
+
document.addEventListener("focusin", leave);
|
|
29
|
+
return () => {
|
|
30
|
+
document.removeEventListener("pointerdown", leave, true);
|
|
31
|
+
document.removeEventListener("focusin", leave);
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
containerRef,
|
|
36
|
+
onChange: (next) => {
|
|
37
|
+
latest.current = next;
|
|
38
|
+
if (!containerRef.current?.contains(document.activeElement)) save();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export { useSaveOnLeave };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ContactQueries, TContactContentType } from "./contacts.js";
|
|
2
|
+
/**
|
|
3
|
+
* A customer or company as a chip: its avatar and name. Inside erxes, clicking it opens the
|
|
4
|
+
* record in core's side panel beside the page; elsewhere it is only the name.
|
|
5
|
+
* `contacts` is `contactQueries` from `@erxes/core-contract/client`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ContactLink: ({ contentType, contentId, contacts, placeholder }: {
|
|
8
|
+
contentType: TContactContentType;
|
|
9
|
+
contentId: string;
|
|
10
|
+
contacts: ContactQueries;
|
|
11
|
+
/** Shown when the record has no name, email or phone. */
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Avatar } from "../../components/avatar.js";
|
|
2
|
+
import { Skeleton } from "../../components/skeleton.js";
|
|
3
|
+
import { cn } from "../../lib/utils.js";
|
|
4
|
+
import { readImage } from "../../utils/core.js";
|
|
5
|
+
import { companyTitle, customerTitle } from "./contacts.js";
|
|
6
|
+
import { useOpenRecord } from "./openRecord.js";
|
|
7
|
+
import { IconArrowUpRight } from "@tabler/icons-react";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { useQuery } from "@tanstack/react-query";
|
|
10
|
+
// src/modules/records/ContactLink.tsx
|
|
11
|
+
/** The customer's or company's title and avatar. */
|
|
12
|
+
const useContact = (contentType, contentId, contacts) => {
|
|
13
|
+
const isCustomer = contentType === "core:customer";
|
|
14
|
+
const customer = useQuery({
|
|
15
|
+
...contacts.customer(contentId),
|
|
16
|
+
enabled: isCustomer
|
|
17
|
+
});
|
|
18
|
+
const company = useQuery({
|
|
19
|
+
...contacts.company(contentId),
|
|
20
|
+
enabled: !isCustomer
|
|
21
|
+
});
|
|
22
|
+
if (isCustomer) return {
|
|
23
|
+
title: customer.data ? customerTitle(customer.data) : "",
|
|
24
|
+
avatarUrl: customer.data?.avatarUrl,
|
|
25
|
+
isPending: customer.isPending,
|
|
26
|
+
error: customer.error
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
title: company.data ? companyTitle(company.data) : "",
|
|
30
|
+
avatarUrl: company.data?.avatarUrl,
|
|
31
|
+
isPending: company.isPending,
|
|
32
|
+
error: company.error
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const CHIP = "group/chip inline-flex h-6 max-w-full items-center gap-1 rounded-sm bg-muted px-1.5 text-xs font-medium";
|
|
36
|
+
/**
|
|
37
|
+
* A customer or company as a chip: its avatar and name. Inside erxes, clicking it opens the
|
|
38
|
+
* record in core's side panel beside the page; elsewhere it is only the name.
|
|
39
|
+
* `contacts` is `contactQueries` from `@erxes/core-contract/client`.
|
|
40
|
+
*/
|
|
41
|
+
const ContactLink = ({ contentType, contentId, contacts, placeholder }) => {
|
|
42
|
+
const { open, canOpen } = useOpenRecord();
|
|
43
|
+
const contact = useContact(contentType, contentId, contacts);
|
|
44
|
+
if (contact.isPending) return /* @__PURE__ */ jsx(Skeleton, {
|
|
45
|
+
radius: "sm",
|
|
46
|
+
className: "h-5 w-20"
|
|
47
|
+
});
|
|
48
|
+
const name = contact.error?.message || contact.title || placeholder || (contentType === "core:customer" ? "Unnamed customer" : "Unnamed company");
|
|
49
|
+
const face = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Avatar, {
|
|
50
|
+
size: "sm",
|
|
51
|
+
className: "size-4 flex-none",
|
|
52
|
+
children: [/* @__PURE__ */ jsx(Avatar.Image, { src: readImage(contact.avatarUrl ?? void 0) }), /* @__PURE__ */ jsx(Avatar.Fallback, { children: name.charAt(0) })]
|
|
53
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
54
|
+
className: cn("truncate", contact.error && "text-destructive"),
|
|
55
|
+
children: name
|
|
56
|
+
})] });
|
|
57
|
+
if (!canOpen) return /* @__PURE__ */ jsx("span", {
|
|
58
|
+
title: name,
|
|
59
|
+
className: CHIP,
|
|
60
|
+
children: face
|
|
61
|
+
});
|
|
62
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
63
|
+
type: "button",
|
|
64
|
+
onClick: () => open({
|
|
65
|
+
contentType,
|
|
66
|
+
contentId
|
|
67
|
+
}),
|
|
68
|
+
title: name,
|
|
69
|
+
"data-panel-inline": "",
|
|
70
|
+
className: cn(CHIP, "hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"),
|
|
71
|
+
children: [face, /* @__PURE__ */ jsx(IconArrowUpRight, {
|
|
72
|
+
className: "size-3 flex-none text-muted-foreground opacity-0 transition-opacity group-hover/chip:opacity-100 group-focus-visible/chip:opacity-100",
|
|
73
|
+
"aria-hidden": "true"
|
|
74
|
+
})]
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export { ContactLink };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { UseQueryOptions } from "@tanstack/react-query";
|
|
2
|
+
/** What a customer reads as: core's `Customer` has these fields and more. */
|
|
3
|
+
export interface CustomerContact {
|
|
4
|
+
id: string;
|
|
5
|
+
firstName: string | null;
|
|
6
|
+
middleName: string | null;
|
|
7
|
+
lastName: string | null;
|
|
8
|
+
primaryEmail: string | null;
|
|
9
|
+
primaryPhone: string | null;
|
|
10
|
+
avatarUrl: string | null;
|
|
11
|
+
}
|
|
12
|
+
/** What a company reads as: core's `Company` has these fields and more. */
|
|
13
|
+
export interface CompanyContact {
|
|
14
|
+
id: string;
|
|
15
|
+
primaryName: string | null;
|
|
16
|
+
primaryEmail: string | null;
|
|
17
|
+
primaryPhone: string | null;
|
|
18
|
+
avatarUrl: string | null;
|
|
19
|
+
}
|
|
20
|
+
type ContactQuery<T> = UseQueryOptions<T, Error, T>;
|
|
21
|
+
/**
|
|
22
|
+
* Where customers and companies come from, as TanStack query options. erxes-ui knows nothing
|
|
23
|
+
* of core: web and plugin UIs pass `contactQueries` from `@erxes/core-contract/client`.
|
|
24
|
+
*/
|
|
25
|
+
export interface ContactQueries {
|
|
26
|
+
customer: (id: string) => ContactQuery<CustomerContact>;
|
|
27
|
+
company: (id: string) => ContactQuery<CompanyContact>;
|
|
28
|
+
}
|
|
29
|
+
/** The customer or company types `ContactLink` shows. */
|
|
30
|
+
export type TContactContentType = 'core:customer' | 'core:company';
|
|
31
|
+
/** A customer's name, else its email or phone. */
|
|
32
|
+
export declare const customerTitle: (customer: Pick<CustomerContact, 'firstName' | 'middleName' | 'lastName' | 'primaryEmail' | 'primaryPhone'>) => string;
|
|
33
|
+
/** A company's name, else its email or phone. */
|
|
34
|
+
export declare const companyTitle: (company: Pick<CompanyContact, 'primaryName' | 'primaryEmail' | 'primaryPhone'>) => string;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/modules/records/contacts.ts
|
|
2
|
+
/** A customer's name, else its email or phone. */
|
|
3
|
+
const customerTitle = (customer) => [
|
|
4
|
+
customer.firstName,
|
|
5
|
+
customer.middleName,
|
|
6
|
+
customer.lastName
|
|
7
|
+
].filter(Boolean).join(" ") || customer.primaryEmail || customer.primaryPhone || "";
|
|
8
|
+
/** A company's name, else its email or phone. */
|
|
9
|
+
const companyTitle = (company) => company.primaryName || company.primaryEmail || company.primaryPhone || "";
|
|
10
|
+
export { companyTitle, customerTitle };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
/** A record the host can open: `core:customer`, `core:company`, or a plugin's own type. */
|
|
3
|
+
export interface RecordRef {
|
|
4
|
+
contentType: string;
|
|
5
|
+
contentId: string;
|
|
6
|
+
}
|
|
7
|
+
type OpenRecord = (record: RecordRef) => void;
|
|
8
|
+
/** Opens a draft of a record type, starting with `defaults` (e.g. the stage it was added in). */
|
|
9
|
+
type OpenNewRecord = (contentType: string, defaults?: Record<string, unknown>) => void;
|
|
10
|
+
/**
|
|
11
|
+
* How records open, provided by the host app (web): beside the page in its side panel, or,
|
|
12
|
+
* inside a record, on top of that record so Back returns to it. erxes-ui is a Module
|
|
13
|
+
* Federation singleton, so every plugin reads the host's.
|
|
14
|
+
*/
|
|
15
|
+
export declare const RecordOpenerProvider: ({ open, openNew, children }: PropsWithChildren<{
|
|
16
|
+
open: OpenRecord;
|
|
17
|
+
openNew?: OpenNewRecord;
|
|
18
|
+
}>) => import("react").JSX.Element;
|
|
19
|
+
/**
|
|
20
|
+
* `const { open, openNew } = useOpenRecord()`: `open({ contentType: 'sales:deal', contentId })`
|
|
21
|
+
* opens a record in core's side panel, the page staying under it, and
|
|
22
|
+
* `openNew('sales:deal', { stageId })` opens a draft that becomes the record on Save. Any
|
|
23
|
+
* type core or an installed plugin registers opens (`IUIConfig.recordTypes`). `canOpen` is
|
|
24
|
+
* false outside erxes (a plugin page rendered on its own), where both do nothing.
|
|
25
|
+
*/
|
|
26
|
+
export declare const useOpenRecord: () => {
|
|
27
|
+
open: OpenRecord;
|
|
28
|
+
openNew: OpenNewRecord;
|
|
29
|
+
canOpen: boolean;
|
|
30
|
+
};
|
|
31
|
+
/** Web registers how a record draws on its own page. */
|
|
32
|
+
export declare const setRecordPage: (component: import("react").ComponentType<RecordRef> | null) => void;
|
|
33
|
+
/**
|
|
34
|
+
* A record on its own page, as core draws it for `core:customer`: the record's View at full
|
|
35
|
+
* size, under the page header, with Back to its list. A plugin routes its record type's
|
|
36
|
+
* `listPath/:id` to `<RecordPage contentType="sales:deal" contentId={id} />`.
|
|
37
|
+
*/
|
|
38
|
+
export declare const RecordPage: (props: RecordRef) => import("react").JSX.Element | null;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { hostComponent } from "../../utils/host-component.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, use, useMemo } from "react";
|
|
4
|
+
// src/modules/records/openRecord.tsx
|
|
5
|
+
const RecordOpenerContext = createContext(null);
|
|
6
|
+
const ignore = () => void 0;
|
|
7
|
+
/**
|
|
8
|
+
* How records open, provided by the host app (web): beside the page in its side panel, or,
|
|
9
|
+
* inside a record, on top of that record so Back returns to it. erxes-ui is a Module
|
|
10
|
+
* Federation singleton, so every plugin reads the host's.
|
|
11
|
+
*/
|
|
12
|
+
const RecordOpenerProvider = ({ open, openNew = ignore, children }) => {
|
|
13
|
+
const opener = useMemo(() => ({
|
|
14
|
+
open,
|
|
15
|
+
openNew
|
|
16
|
+
}), [open, openNew]);
|
|
17
|
+
return /* @__PURE__ */ jsx(RecordOpenerContext, {
|
|
18
|
+
value: opener,
|
|
19
|
+
children
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* `const { open, openNew } = useOpenRecord()`: `open({ contentType: 'sales:deal', contentId })`
|
|
24
|
+
* opens a record in core's side panel, the page staying under it, and
|
|
25
|
+
* `openNew('sales:deal', { stageId })` opens a draft that becomes the record on Save. Any
|
|
26
|
+
* type core or an installed plugin registers opens (`IUIConfig.recordTypes`). `canOpen` is
|
|
27
|
+
* false outside erxes (a plugin page rendered on its own), where both do nothing.
|
|
28
|
+
*/
|
|
29
|
+
const useOpenRecord = () => {
|
|
30
|
+
const opener = use(RecordOpenerContext);
|
|
31
|
+
return {
|
|
32
|
+
open: opener?.open ?? ignore,
|
|
33
|
+
openNew: opener?.openNew ?? ignore,
|
|
34
|
+
canOpen: opener !== null
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const page = hostComponent();
|
|
38
|
+
/** Web registers how a record draws on its own page. */
|
|
39
|
+
const setRecordPage = page.set;
|
|
40
|
+
/**
|
|
41
|
+
* A record on its own page, as core draws it for `core:customer`: the record's View at full
|
|
42
|
+
* size, under the page header, with Back to its list. A plugin routes its record type's
|
|
43
|
+
* `listPath/:id` to `<RecordPage contentType="sales:deal" contentId={id} />`.
|
|
44
|
+
*/
|
|
45
|
+
const RecordPage = page.Host;
|
|
46
|
+
export { RecordOpenerProvider, RecordPage, setRecordPage, useOpenRecord };
|
package/dist/types/UIConfig.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { TContactContentType } from "../modules/records/contacts.js";
|
|
2
|
+
import { RecordRef } from "../modules/records/openRecord.js";
|
|
1
3
|
import { Icon } from "@tabler/icons-react";
|
|
4
|
+
import { UseQueryOptions } from "@tanstack/react-query";
|
|
2
5
|
/** A property input's own settings, stored with the custom field; each input defines its keys. */
|
|
3
6
|
export type TPropertyInputMeta = Record<string, unknown>;
|
|
4
7
|
export type TActivityRowProps = {
|
|
@@ -19,10 +22,108 @@ export type TPropertyInputProps = {
|
|
|
19
22
|
disabled?: boolean;
|
|
20
23
|
};
|
|
21
24
|
export type TDashboardWidgetPreview = 'bar' | 'line' | 'area' | 'pie' | 'table' | 'list' | 'kpi' | 'heatmap' | 'progress';
|
|
25
|
+
/** What a record section is given: the customer or company it shows on. */
|
|
26
|
+
export type TRecordSectionProps = {
|
|
27
|
+
contentType: TContactContentType;
|
|
28
|
+
contentId: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A section a plugin adds to a customer's or company's detail in core's panel, under core's
|
|
32
|
+
* own sections: e.g. the customer's deals. One that crashes shows its error, not the panel's.
|
|
33
|
+
*/
|
|
34
|
+
export type TRecordSection = {
|
|
35
|
+
contentType: TContactContentType;
|
|
36
|
+
/** The section's heading. */
|
|
37
|
+
title: string;
|
|
38
|
+
icon: React.ElementType;
|
|
39
|
+
component: React.ComponentType<TRecordSectionProps>;
|
|
40
|
+
};
|
|
41
|
+
/** What each slot of a plugin record is given: the record. */
|
|
42
|
+
export type TRecordSlotProps = RecordRef;
|
|
43
|
+
/** The customers and companies a record is about: what its relation tabs list records of. */
|
|
44
|
+
export type TRecordContacts = {
|
|
45
|
+
customerIds: string[];
|
|
46
|
+
companyIds: string[];
|
|
47
|
+
};
|
|
48
|
+
/** A record's own tab, placed after core's Detail tab or after its Activity tab. */
|
|
49
|
+
export type TRecordTab = {
|
|
50
|
+
value: string;
|
|
51
|
+
label: string;
|
|
52
|
+
icon: Icon;
|
|
53
|
+
after?: 'detail' | 'activity';
|
|
54
|
+
component: React.ComponentType<TRecordSlotProps>;
|
|
55
|
+
};
|
|
56
|
+
/** What a plugin record's draft is given: its form, saved as the record on Save. */
|
|
57
|
+
export type TRecordDraftProps = {
|
|
58
|
+
/** What its opener passed (`useOpenRecord().openNew(type, defaults)`), e.g. a stage. */
|
|
59
|
+
defaults: Record<string, unknown>;
|
|
60
|
+
/** Call with the saved record's id: the record takes the draft's place in the panel. */
|
|
61
|
+
onCreated: (id: string) => void;
|
|
62
|
+
/** Leaves the draft: back to the record it came from, else closes the panel. */
|
|
63
|
+
onCancel: () => void;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* A record type a plugin shows in core's side panel. Core draws the panel as it draws a
|
|
67
|
+
* customer's: header with Back, expand and close, the tabs (Detail, the type's own `tabs`,
|
|
68
|
+
* every allowed plugin's relation tabs for it, Activity), resizing, the address
|
|
69
|
+
* `?panel=/detail/<contentType>/<id>`, drafts. The plugin fills the slots. Open one with
|
|
70
|
+
* `useOpenRecord().open({ contentType, contentId })`, a draft with `openNew(contentType)`.
|
|
71
|
+
*/
|
|
72
|
+
export type TPanelRecordType = {
|
|
73
|
+
/** `<plugin name>:<thing>`, e.g. `sales:deal`; it must start with the plugin's `name`. */
|
|
74
|
+
contentType: string;
|
|
75
|
+
/** What one is called, e.g. "Deal": a draft's header reads "New deal". */
|
|
76
|
+
title: string;
|
|
77
|
+
icon: React.ElementType;
|
|
78
|
+
/**
|
|
79
|
+
* The record's own page, where the panel's expand button leads: a route of the plugin's,
|
|
80
|
+
* under its `path`, that renders `<RecordPage contentType contentId />`.
|
|
81
|
+
*/
|
|
82
|
+
detailPath: (contentId: string) => string;
|
|
83
|
+
/** The header's title: the record's name, editable in place if the plugin wants. */
|
|
84
|
+
Title: React.ComponentType<TRecordSlotProps>;
|
|
85
|
+
/** The header's own actions (a "more" menu), before expand and close. */
|
|
86
|
+
Actions?: React.ComponentType<TRecordSlotProps>;
|
|
87
|
+
/** The Detail tab: `PanelSection`s of `PanelField` rows. */
|
|
88
|
+
Detail: React.ComponentType<TRecordSlotProps>;
|
|
89
|
+
tabs?: TRecordTab[];
|
|
90
|
+
/** A record not created yet; without it, the type has no drafts. */
|
|
91
|
+
New?: React.ComponentType<TRecordDraftProps>;
|
|
92
|
+
/**
|
|
93
|
+
* The record's customers and companies, as query options (often the record's own query with
|
|
94
|
+
* `select`). Without it, plugins' relation tabs don't show on this type.
|
|
95
|
+
*/
|
|
96
|
+
contacts?: (contentId: string) => UseQueryOptions<TRecordContacts, Error, TRecordContacts>;
|
|
97
|
+
/** A timeline type of the plugin's manifest (`timelines`): core's Activity tab shows it. */
|
|
98
|
+
activity?: string;
|
|
99
|
+
};
|
|
100
|
+
/** What a relation tab is given: the record it shows on, and that record's contacts. */
|
|
101
|
+
export type TRelationTabProps = TRecordSlotProps & TRecordContacts;
|
|
102
|
+
/**
|
|
103
|
+
* A tab a plugin adds to other records' panels, listing its own records of the same customers
|
|
104
|
+
* and companies: a customer's deals, a task's deals. Shown on core's customers and companies
|
|
105
|
+
* (their contacts are themselves) and on plugin record types that give `contacts`. A record
|
|
106
|
+
* clicked in it opens on top in the same panel (`useOpenRecord().open`), and Back returns.
|
|
107
|
+
*/
|
|
108
|
+
export type TRelationTab = {
|
|
109
|
+
/** Unique within the plugin, e.g. `deals`. */
|
|
110
|
+
name: string;
|
|
111
|
+
title: string;
|
|
112
|
+
icon: Icon;
|
|
113
|
+
/** The content types it shows on (`core:customer`, `tasks:task`); every one when omitted. */
|
|
114
|
+
hosts?: string[];
|
|
115
|
+
component: React.ComponentType<TRelationTabProps>;
|
|
116
|
+
};
|
|
22
117
|
export type IUIConfig = {
|
|
23
118
|
name: string;
|
|
24
119
|
path: string;
|
|
25
120
|
icon?: React.ElementType;
|
|
121
|
+
/** Sections on core's customer and company detail, shown to members who may use the plugin. */
|
|
122
|
+
recordSections?: TRecordSection[];
|
|
123
|
+
/** The plugin's records core's side panel opens, for members who may use the plugin. */
|
|
124
|
+
recordTypes?: TPanelRecordType[];
|
|
125
|
+
/** Tabs on other records' panels listing the plugin's records of their contacts. */
|
|
126
|
+
relationTabs?: TRelationTab[];
|
|
26
127
|
i18n?: boolean;
|
|
27
128
|
i18nNamespace?: string;
|
|
28
129
|
hasFloatingWidget?: boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ComponentType } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A component the host app (web) provides at startup and plugin UIs render: core's timeline,
|
|
4
|
+
* a record's own page, a list's filter. erxes-ui is a Module Federation singleton, so every
|
|
5
|
+
* plugin gets the host's. Outside erxes nothing is registered and it renders nothing.
|
|
6
|
+
*/
|
|
7
|
+
export declare const hostComponent: <P extends object>() => {
|
|
8
|
+
set: (component: ComponentType<P> | null) => void;
|
|
9
|
+
Host: (props: P) => import("react").JSX.Element | null;
|
|
10
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Suspense, useSyncExternalStore } from "react";
|
|
3
|
+
// src/utils/host-component.tsx
|
|
4
|
+
/**
|
|
5
|
+
* A component the host app (web) provides at startup and plugin UIs render: core's timeline,
|
|
6
|
+
* a record's own page, a list's filter. erxes-ui is a Module Federation singleton, so every
|
|
7
|
+
* plugin gets the host's. Outside erxes nothing is registered and it renders nothing.
|
|
8
|
+
*/
|
|
9
|
+
const hostComponent = () => {
|
|
10
|
+
let registered = null;
|
|
11
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
12
|
+
const subscribe = (listener) => {
|
|
13
|
+
listeners.add(listener);
|
|
14
|
+
return () => listeners.delete(listener);
|
|
15
|
+
};
|
|
16
|
+
const read = () => registered;
|
|
17
|
+
const set = (component) => {
|
|
18
|
+
registered = component;
|
|
19
|
+
listeners.forEach((listener) => listener());
|
|
20
|
+
};
|
|
21
|
+
const Host = (props) => {
|
|
22
|
+
const Component = useSyncExternalStore(subscribe, read, read);
|
|
23
|
+
if (!Component) return null;
|
|
24
|
+
return /* @__PURE__ */ jsx(Suspense, {
|
|
25
|
+
fallback: null,
|
|
26
|
+
children: /* @__PURE__ */ jsx(Component, { ...props })
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
set,
|
|
31
|
+
Host
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export { hostComponent };
|
|
@@ -33,7 +33,9 @@ export declare const setPluginRuntime: (next: PluginRuntime | null) => void;
|
|
|
33
33
|
export declare const getPluginRuntime: () => PluginRuntime | null;
|
|
34
34
|
/**
|
|
35
35
|
* `fetch` against a plugin's API as the signed-in member. Relative paths are
|
|
36
|
-
* resolved against the plugin's API address; a 401 renews the token once
|
|
36
|
+
* resolved against the plugin's API address; a 401 renews the token once and
|
|
37
|
+
* sends the call again, so `init.body` must be one that can be sent twice
|
|
38
|
+
* (text, an ArrayBuffer, a Blob or FormData, not a stream).
|
|
37
39
|
*/
|
|
38
40
|
export declare const pluginFetch: (plugin: string, path: string, init?: RequestInit) => Promise<Response>;
|
|
39
41
|
/**
|