@erxes/ui 4.0.0-v2.18 → 4.0.0-v2.19

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/CATALOG.md CHANGED
@@ -64,6 +64,7 @@ core's, in the erxes repo on branch `postgre`. The `ui-patterns` skill has the r
64
64
  - `companyTitle(company)` A company's name, else its email or phone.
65
65
  - `<ContactLink contentType contentId contacts placeholder>` A customer or company as a chip: its avatar and name.
66
66
  - `type ContactQueries { customer, company }` Where customers and companies come from, as TanStack query options.
67
+ - `<ContactRelationInput {...RelationProps}>` A record's customers or companies in a side panel field.
67
68
  - `type ContactSearch { search, ids }` What a contact search asks for: matches, or the contacts with these ids.
68
69
  - `type ContactSearchQueries { customers, companies }` Where a filter's `customer` and `company` fields search contacts.
69
70
  - `type CustomerContact { id, firstName, middleName, lastName, primaryEmail, … }` What a customer reads as: core's `Customer` has these fields and more.
@@ -87,9 +88,11 @@ core's, in the erxes repo on branch `postgre`. The `ui-patterns` skill has the r
87
88
  - `type RecordRef { contentType, contentId }` A record the host can open, by `contentType` and `contentId`.
88
89
  - `RecordTimeline` Core's timeline of notes, calls and events for a plugin's record.
89
90
  - `type RecordTimelineProps { type, id }` Which record `RecordTimeline` shows: its timeline type and id.
91
+ - `<SelectContactContent kind value onValueChange contacts multiple>` A picker's searchable list of customers or companies, the picked first.
90
92
  - `setRecordPage` Web registers how a record draws on its own page.
91
93
  - `setRecordTimeline` Registers core's timeline; web calls it at startup and plugins don't.
92
94
  - `type TContactContentType` The customer or company types `ContactLink` shows.
95
+ - `type TContactKind` Which contacts a picker lists: core's customers or its companies.
93
96
  - `useOpenRecord()` Opens a record, or a new draft, in core's side panel.
94
97
  - `usePanelExpanded()` Whether the record shows at full size on its own page.
95
98
  - `useRecordPanel()` The record a slot is in, and what the slot can do to it.
package/dist/index.d.ts CHANGED
@@ -116,6 +116,7 @@ import { PanelLabel } from "./modules/record-panel/PanelLabel.js";
116
116
  import { PanelSection } from "./modules/record-panel/PanelSection.js";
117
117
  import { PanelExpansionContext, usePanelExpanded } from "./modules/record-panel/panelExpansion.js";
118
118
  import { ContactLink } from "./modules/records/ContactLink.js";
119
+ import { ContactRelationInput, SelectContactContent, TContactKind } from "./modules/records/ContactPicker.js";
119
120
  import { MEMBER_CONTENT_TYPE, MemberLink } from "./modules/records/MemberLink.js";
120
121
  import { CompanyContact, ContactQueries, ContactSearch, ContactSearchQueries, CustomerContact, TContactContentType, companyTitle, customerTitle } from "./modules/records/contacts.js";
121
122
  import { RecordOpenerProvider, RecordPage, RecordPageProps, RecordPanelControls, RecordPanelProvider, RecordRef, setRecordPage, useOpenRecord, useRecordPanel } from "./modules/records/openRecord.js";
@@ -131,4 +132,4 @@ import { jsonOf } from "./utils/json.js";
131
132
  import { PluginLiveMessage, PluginRuntime, PluginSession, getPluginRuntime, pluginFetch, pluginJson, setPluginRuntime, useLiveSignal } from "./utils/plugin-runtime.js";
132
133
  import { addPluginStyles } from "./utils/plugin-styles.js";
133
134
  import { RecordTimeline, RecordTimelineProps, setRecordTimeline } from "./utils/record-timeline.js";
134
- export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, type AvatarProps, BackgroundGradientAnimation, Badge, type BadgeProps, Breadcrumb, Button, type ButtonProps, Calendar, type CalendarProps, Card, type ChartConfig, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, type CompanyContact, ConditionsEditor, ContactLink, type ContactQueries, type ContactSearch, type ContactSearchQueries, ContextMenu, CopyText, type CustomerContact, DASHBOARD_WIDGET_PREVIEWS, DateInput, DatePicker, Dialog, DisplayMenu, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, type FileStorageAdapter, Filter, Form, FullNameField, FullNameValue, HoverCard, type IUIConfig, IconComponent, IconPicker, IconTip, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, ListFilter, ListFilterEmpty, ListViewsProvider, LookupPicker, MEMBER_CONTENT_TYPE, type Member, MemberInline, MemberLink, type MemberQueries, type MultiSelectOption, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PanelDescriptionEditor, PanelDescriptionField, PanelExpansionContext, PanelField, PanelFieldTrigger, PanelFormLayout, PanelFormRow, PanelLabel, PanelSection, PhoneDisplay, PhoneField, PhoneInput, type PluginLiveMessage, type PluginRuntime, type PluginSession, Popover, PopoverScoped, RadioGroup, RecordList, type RecordListGroup, RecordOpenerProvider, RecordPage, type RecordPageProps, type RecordPanelControls, RecordPanelProvider, type RecordRef, RecordTable, type RecordTableColumnDef, RecordTableInlineCell, RecordTimeline, type RecordTimelineProps, RelativeDateDisplay, Resizable, ScrollArea, Select, SelectMember, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, type TConditionField, type TConditionGroup, type TConditionLookups, type TConditionRule, type TContactContentType, type TDashboardWidget, type TDashboardWidgetPreview, type TListDisplay, type TListDisplayOption, type TListFilterField, type TListFilterProps, type TListViews, type TPanelRecordType, type TPluginListType, type TPluginSettingsPage, type TPropertyValue, type TRecordContacts, type TRecordDraftProps, type TRecordProperties, type TRecordSection, type TRecordSectionProps, type TRecordSlotProps, type TRecordTab, type TRecordTableSort, type TRelationTab, type TRelationTabProps, type TViewTabsProps, TabButton, Table, Tabs, type Tag, type TagsQuery, TextField, TextOverflowTooltip, Textarea, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, ViewBar, addPluginStyles, amountStep, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatMoney, formatPhoneNumber, formatter, fromAmountInput, getPluginAssetsUrl, getPluginRuntime, isRule, isUndefinedOrNull, jsonOf, listFilterQuery, localTimeZone, memberName, oneOf, pluginFetch, pluginJson, readImage, setFileStorage, setPluginRuntime, setRecordPage, setRecordTimeline, stored, storedFamily, textOf, themeState, toAmountInput, toIsoDay, toast, useConfirm, useFieldControl, useFilterContext, useFocusFirstField, useFormat, useItemKeys, useListDisplay, useListFilterParams, useListViews, useLiveSignal, useMemberOptions, useMembersById, useMoney, useOpenRecord, usePageHotkey, usePanelExpanded, usePreviousHotkeyScope, useRecordPanel, useScopedHotkeys, useTagOptions, useToast, useUpload, zoneOffset };
135
+ export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, type AvatarProps, BackgroundGradientAnimation, Badge, type BadgeProps, Breadcrumb, Button, type ButtonProps, Calendar, type CalendarProps, Card, type ChartConfig, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, type CompanyContact, ConditionsEditor, ContactLink, type ContactQueries, ContactRelationInput, type ContactSearch, type ContactSearchQueries, ContextMenu, CopyText, type CustomerContact, DASHBOARD_WIDGET_PREVIEWS, DateInput, DatePicker, Dialog, DisplayMenu, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, type FileStorageAdapter, Filter, Form, FullNameField, FullNameValue, HoverCard, type IUIConfig, IconComponent, IconPicker, IconTip, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, ListFilter, ListFilterEmpty, ListViewsProvider, LookupPicker, MEMBER_CONTENT_TYPE, type Member, MemberInline, MemberLink, type MemberQueries, type MultiSelectOption, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PanelDescriptionEditor, PanelDescriptionField, PanelExpansionContext, PanelField, PanelFieldTrigger, PanelFormLayout, PanelFormRow, PanelLabel, PanelSection, PhoneDisplay, PhoneField, PhoneInput, type PluginLiveMessage, type PluginRuntime, type PluginSession, Popover, PopoverScoped, RadioGroup, RecordList, type RecordListGroup, RecordOpenerProvider, RecordPage, type RecordPageProps, type RecordPanelControls, RecordPanelProvider, type RecordRef, RecordTable, type RecordTableColumnDef, RecordTableInlineCell, RecordTimeline, type RecordTimelineProps, RelativeDateDisplay, Resizable, ScrollArea, Select, SelectContactContent, SelectMember, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, type TConditionField, type TConditionGroup, type TConditionLookups, type TConditionRule, type TContactContentType, type TContactKind, type TDashboardWidget, type TDashboardWidgetPreview, type TListDisplay, type TListDisplayOption, type TListFilterField, type TListFilterProps, type TListViews, type TPanelRecordType, type TPluginListType, type TPluginSettingsPage, type TPropertyValue, type TRecordContacts, type TRecordDraftProps, type TRecordProperties, type TRecordSection, type TRecordSectionProps, type TRecordSlotProps, type TRecordTab, type TRecordTableSort, type TRelationTab, type TRelationTabProps, type TViewTabsProps, TabButton, Table, Tabs, type Tag, type TagsQuery, TextField, TextOverflowTooltip, Textarea, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, ViewBar, addPluginStyles, amountStep, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatMoney, formatPhoneNumber, formatter, fromAmountInput, getPluginAssetsUrl, getPluginRuntime, isRule, isUndefinedOrNull, jsonOf, listFilterQuery, localTimeZone, memberName, oneOf, pluginFetch, pluginJson, readImage, setFileStorage, setPluginRuntime, setRecordPage, setRecordTimeline, stored, storedFamily, textOf, themeState, toAmountInput, toIsoDay, toast, useConfirm, useFieldControl, useFilterContext, useFocusFirstField, useFormat, useItemKeys, useListDisplay, useListFilterParams, useListViews, useLiveSignal, useMemberOptions, useMembersById, useMoney, useOpenRecord, usePageHotkey, usePanelExpanded, usePreviousHotkeyScope, useRecordPanel, useScopedHotkeys, useTagOptions, useToast, useUpload, zoneOffset };
package/dist/index.js CHANGED
@@ -112,6 +112,7 @@ import { PanelLabel } from "./modules/record-panel/PanelLabel.js";
112
112
  import { PanelSection } from "./modules/record-panel/PanelSection.js";
113
113
  import { PanelExpansionContext, usePanelExpanded } from "./modules/record-panel/panelExpansion.js";
114
114
  import { ContactLink } from "./modules/records/ContactLink.js";
115
+ import { ContactRelationInput, SelectContactContent } from "./modules/records/ContactPicker.js";
115
116
  import { MEMBER_CONTENT_TYPE, MemberLink } from "./modules/records/MemberLink.js";
116
117
  import { companyTitle, customerTitle } from "./modules/records/contacts.js";
117
118
  import { RecordOpenerProvider, RecordPage, RecordPanelProvider, setRecordPage, useOpenRecord, useRecordPanel } from "./modules/records/openRecord.js";
@@ -127,4 +128,4 @@ import { jsonOf } from "./utils/json.js";
127
128
  import { getPluginRuntime, pluginFetch, pluginJson, setPluginRuntime, useLiveSignal } from "./utils/plugin-runtime.js";
128
129
  import { addPluginStyles } from "./utils/plugin-styles.js";
129
130
  import { RecordTimeline, setRecordTimeline } from "./utils/record-timeline.js";
130
- export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, BackgroundGradientAnimation, Badge, Breadcrumb, Button, Calendar, Card, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, ConditionsEditor, ContactLink, ContextMenu, CopyText, DASHBOARD_WIDGET_PREVIEWS, DateInput, DatePicker, Dialog, DisplayMenu, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, Filter, Form, FullNameField, FullNameValue, HoverCard, IconComponent, IconPicker, IconTip, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, ListFilter, ListFilterEmpty, ListViewsProvider, LookupPicker, MEMBER_CONTENT_TYPE, MemberInline, MemberLink, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PanelDescriptionEditor, PanelDescriptionField, PanelExpansionContext, PanelField, PanelFieldTrigger, PanelFormLayout, PanelFormRow, PanelLabel, PanelSection, PhoneDisplay, PhoneField, PhoneInput, Popover, PopoverScoped, RadioGroup, RecordList, RecordOpenerProvider, RecordPage, RecordPanelProvider, RecordTable, RecordTableInlineCell, RecordTimeline, RelativeDateDisplay, Resizable, ScrollArea, Select, SelectMember, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, TabButton, Table, Tabs, TextField, TextOverflowTooltip, Textarea, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, ViewBar, addPluginStyles, amountStep, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatMoney, formatPhoneNumber, formatter, fromAmountInput, getPluginAssetsUrl, getPluginRuntime, isRule, isUndefinedOrNull, jsonOf, listFilterQuery, localTimeZone, memberName, oneOf, pluginFetch, pluginJson, readImage, setFileStorage, setPluginRuntime, setRecordPage, setRecordTimeline, stored, storedFamily, textOf, themeState, toAmountInput, toIsoDay, toast, useConfirm, useFieldControl, useFilterContext, useFocusFirstField, useFormat, useItemKeys, useListDisplay, useListFilterParams, useListViews, useLiveSignal, useMemberOptions, useMembersById, useMoney, useOpenRecord, usePageHotkey, usePanelExpanded, usePreviousHotkeyScope, useRecordPanel, useScopedHotkeys, useTagOptions, useToast, useUpload, zoneOffset };
131
+ export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, BackgroundGradientAnimation, Badge, Breadcrumb, Button, Calendar, Card, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, ConditionsEditor, ContactLink, ContactRelationInput, ContextMenu, CopyText, DASHBOARD_WIDGET_PREVIEWS, DateInput, DatePicker, Dialog, DisplayMenu, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, Filter, Form, FullNameField, FullNameValue, HoverCard, IconComponent, IconPicker, IconTip, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, ListFilter, ListFilterEmpty, ListViewsProvider, LookupPicker, MEMBER_CONTENT_TYPE, MemberInline, MemberLink, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PanelDescriptionEditor, PanelDescriptionField, PanelExpansionContext, PanelField, PanelFieldTrigger, PanelFormLayout, PanelFormRow, PanelLabel, PanelSection, PhoneDisplay, PhoneField, PhoneInput, Popover, PopoverScoped, RadioGroup, RecordList, RecordOpenerProvider, RecordPage, RecordPanelProvider, RecordTable, RecordTableInlineCell, RecordTimeline, RelativeDateDisplay, Resizable, ScrollArea, Select, SelectContactContent, SelectMember, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, TabButton, Table, Tabs, TextField, TextOverflowTooltip, Textarea, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, ViewBar, addPluginStyles, amountStep, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatMoney, formatPhoneNumber, formatter, fromAmountInput, getPluginAssetsUrl, getPluginRuntime, isRule, isUndefinedOrNull, jsonOf, listFilterQuery, localTimeZone, memberName, oneOf, pluginFetch, pluginJson, readImage, setFileStorage, setPluginRuntime, setRecordPage, setRecordTimeline, stored, storedFamily, textOf, themeState, toAmountInput, toIsoDay, toast, useConfirm, useFieldControl, useFilterContext, useFocusFirstField, useFormat, useItemKeys, useListDisplay, useListFilterParams, useListViews, useLiveSignal, useMemberOptions, useMembersById, useMoney, useOpenRecord, usePageHotkey, usePanelExpanded, usePreviousHotkeyScope, useRecordPanel, useScopedHotkeys, useTagOptions, useToast, useUpload, zoneOffset };
@@ -17,8 +17,8 @@ import { BlockNoteView } from "@blocknote/shadcn";
17
17
  const blockEditorVariants = cva("erxes-blocknote transition", {
18
18
  variants: { variant: {
19
19
  default: "",
20
- outline: "rounded-md pt-1 styled-scroll shadow-xs data-focused:shadow-focus",
21
- ghost: "rounded-sm pt-1 styled-scroll hover:bg-accent focus-within:bg-background focus-within:shadow-focus"
20
+ outline: "rounded-md pt-1 text-sm styled-scroll shadow-xs data-focused:shadow-focus",
21
+ ghost: "rounded-sm pt-1 text-sm styled-scroll hover:bg-accent focus-within:bg-background focus-within:shadow-focus"
22
22
  } },
23
23
  defaultVariants: { variant: "default" }
24
24
  });
@@ -0,0 +1,36 @@
1
+ import { ContactQueries, ContactSearchQueries } from "./contacts.js";
2
+ /** Which contacts a picker lists: core's customers or its companies. */
3
+ export type TContactKind = 'customer' | 'company';
4
+ /**
5
+ * A picker's searchable list of customers or companies, the picked first.
6
+ * Searched on the server; `contacts` is `contactSearchQueries` from
7
+ * `@erxes/core-contract/client`.
8
+ */
9
+ export declare const SelectContactContent: ({ kind, value, onValueChange, contacts, multiple, noneLabel }: {
10
+ kind: TContactKind;
11
+ value: string[];
12
+ onValueChange: (ids: string[]) => void;
13
+ contacts: ContactSearchQueries;
14
+ multiple?: boolean;
15
+ noneLabel?: string;
16
+ }) => import("react").JSX.Element;
17
+ type RelationProps = {
18
+ kind: TContactKind;
19
+ value: string[];
20
+ /** Picks several unless `multiple` is false; then a pick replaces the one linked. */
21
+ onValueChange?: (ids: string[]) => void;
22
+ /** `contactQueries` and `contactSearchQueries` from `@erxes/core-contract/client`. */
23
+ contacts: ContactQueries;
24
+ contactSearch: ContactSearchQueries;
25
+ multiple?: boolean;
26
+ scope: string;
27
+ disabled?: boolean;
28
+ };
29
+ /**
30
+ * A record's customers or companies in a side panel field.
31
+ * Put it in a `cell={false}` field. The first shows as a chip, then a muted button adds, changes, or shows the rest
32
+ * (`+N`). Without `onValueChange` it only shows them. Core's panels and plugin
33
+ * records draw contacts with it.
34
+ */
35
+ export declare const ContactRelationInput: (props: RelationProps) => import("react").JSX.Element;
36
+ export {};
@@ -0,0 +1,173 @@
1
+ import { Avatar } from "../../components/avatar.js";
2
+ import { Button } from "../../components/button.js";
3
+ import { Combobox } from "../../components/combobox.js";
4
+ import { Popover } from "../../components/popover.js";
5
+ import { Spinner } from "../../components/spinner.js";
6
+ import { cn } from "../../lib/utils.js";
7
+ import { readImage } from "../../utils/core.js";
8
+ import { PopoverScoped } from "../hotkey/components/PopoverScoped.js";
9
+ import { EntityPicker } from "../pickers/EntityPicker.js";
10
+ import { ContactLink } from "./ContactLink.js";
11
+ import { companyTitle, customerTitle } from "./contacts.js";
12
+ import { IconPlus } from "@tabler/icons-react";
13
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
14
+ import { useState } from "react";
15
+ import { useTranslation } from "react-i18next";
16
+ import { useQuery } from "@tanstack/react-query";
17
+ import { useDebounce } from "use-debounce";
18
+ // src/modules/records/ContactPicker.tsx
19
+ /** Up to 20 customers or companies: those matching `search`, or the ones with `ids`. */
20
+ const useContactRows = (contacts, kind, { search, ids }) => {
21
+ const input = {
22
+ search: search || void 0,
23
+ ids
24
+ };
25
+ const enabled = !ids || ids.length > 0;
26
+ const customers = useQuery({
27
+ ...contacts.customers(input),
28
+ enabled: enabled && kind === "customer",
29
+ placeholderData: (previous) => previous
30
+ });
31
+ const companies = useQuery({
32
+ ...contacts.companies(input),
33
+ enabled: enabled && kind === "company",
34
+ placeholderData: (previous) => previous
35
+ });
36
+ if (kind === "customer") return {
37
+ data: customers.data?.data.map((customer) => ({
38
+ id: customer.id,
39
+ name: customerTitle(customer),
40
+ avatarUrl: customer.avatarUrl
41
+ })),
42
+ isPending: customers.isPending,
43
+ error: customers.error
44
+ };
45
+ return {
46
+ data: companies.data?.data.map((company) => ({
47
+ id: company.id,
48
+ name: companyTitle(company),
49
+ avatarUrl: company.avatarUrl
50
+ })),
51
+ isPending: companies.isPending,
52
+ error: companies.error
53
+ };
54
+ };
55
+ /**
56
+ * A picker's searchable list of customers or companies, the picked first.
57
+ * Searched on the server; `contacts` is `contactSearchQueries` from
58
+ * `@erxes/core-contract/client`.
59
+ */
60
+ const SelectContactContent = ({ kind, value, onValueChange, contacts, multiple = true, noneLabel }) => {
61
+ const [search, setSearch] = useState("");
62
+ const [debounced] = useDebounce(search.trim(), 500);
63
+ const placeholder = kind === "customer" ? "Unnamed customer" : "Unnamed company";
64
+ const selected = useContactRows(contacts, kind, { ids: value });
65
+ const matches = useContactRows(contacts, kind, { search: debounced });
66
+ const found = matches.data ?? [];
67
+ const items = [...(selected.data ?? []).filter((option) => value.includes(option.id) && !found.some((match) => match.id === option.id)), ...found];
68
+ return /* @__PURE__ */ jsx(EntityPicker, {
69
+ multiple,
70
+ noneLabel,
71
+ items,
72
+ itemKey: (option) => ({
73
+ id: option.id,
74
+ label: option.name
75
+ }),
76
+ renderItem: (option) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Avatar, { children: [/* @__PURE__ */ jsx(Avatar.Image, { src: readImage(option.avatarUrl ?? void 0) }), /* @__PURE__ */ jsx(Avatar.Fallback, { children: option.name.charAt(0) })] }), /* @__PURE__ */ jsx(Combobox.Value, {
77
+ value: option.name,
78
+ placeholder
79
+ })] }),
80
+ value,
81
+ onValueChange,
82
+ onSearchChange: setSearch,
83
+ loading: matches.isPending,
84
+ error: matches.error ?? selected.error
85
+ });
86
+ };
87
+ const ContactRelationTriggerLabel = ({ saving, moreCount, hasLinks, addLabel }) => {
88
+ if (saving) return /* @__PURE__ */ jsx(Spinner, { size: "sm" });
89
+ if (moreCount > 0) return /* @__PURE__ */ jsxs("span", {
90
+ className: "font-normal",
91
+ children: ["+", moreCount]
92
+ });
93
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(IconPlus, { "aria-hidden": "true" }), !hasLinks && /* @__PURE__ */ jsx("span", {
94
+ className: "font-normal",
95
+ children: addLabel
96
+ })] });
97
+ };
98
+ /** The button after the first chip: `+N` more, or add, opening the picker. */
99
+ const ContactRelationPopover = ({ kind, value, contacts, contactSearch, multiple = true, scope, disabled = false, onValueChange }) => {
100
+ const { t } = useTranslation("common", { keyPrefix: "side-panel" });
101
+ const [open, setOpen] = useState(false);
102
+ const hasLinks = value.length > 0;
103
+ const moreCount = Math.max(0, value.length - 1);
104
+ const addLabel = kind === "company" ? t("add-company", "Add company") : t("add-customer", "Add customer");
105
+ const editLabel = kind === "company" ? t("edit-companies", "Edit companies") : t("edit-customers", "Edit customers");
106
+ return /* @__PURE__ */ jsxs(PopoverScoped, {
107
+ scope,
108
+ open,
109
+ onOpenChange: setOpen,
110
+ children: [/* @__PURE__ */ jsx(Popover.Trigger, {
111
+ render: /* @__PURE__ */ jsx(Button, {
112
+ variant: moreCount > 0 ? "secondary" : "ghost",
113
+ size: "xs",
114
+ tone: "muted",
115
+ "data-panel-inline": "",
116
+ disabled,
117
+ "aria-label": hasLinks ? editLabel : addLabel,
118
+ className: cn("shrink-0 [&>svg]:size-3.5", hasLinks && !moreCount && "opacity-0 group-hover/relations:opacity-100 focus-visible:opacity-100 data-popup-open:opacity-100")
119
+ }),
120
+ children: /* @__PURE__ */ jsx(ContactRelationTriggerLabel, {
121
+ saving: disabled,
122
+ moreCount,
123
+ hasLinks,
124
+ addLabel
125
+ })
126
+ }), /* @__PURE__ */ jsx(Combobox.Content, { children: onValueChange ? /* @__PURE__ */ jsx(SelectContactContent, {
127
+ kind,
128
+ value,
129
+ contacts: contactSearch,
130
+ multiple,
131
+ onValueChange: (ids) => {
132
+ if (disabled) return;
133
+ onValueChange(ids);
134
+ if (!multiple) setOpen(false);
135
+ }
136
+ }) : /* @__PURE__ */ jsx("div", {
137
+ className: "flex flex-col items-start gap-1 p-2",
138
+ children: value.map((id) => /* @__PURE__ */ jsx(ContactLink, {
139
+ contentType: kind === "company" ? "core:company" : "core:customer",
140
+ contentId: id,
141
+ contacts
142
+ }, id))
143
+ }) })]
144
+ });
145
+ };
146
+ /**
147
+ * A record's customers or companies in a side panel field.
148
+ * Put it in a `cell={false}` field. The first shows as a chip, then a muted button adds, changes, or shows the rest
149
+ * (`+N`). Without `onValueChange` it only shows them. Core's panels and plugin
150
+ * records draw contacts with it.
151
+ */
152
+ const ContactRelationInput = (props) => {
153
+ const { kind, value, contacts, onValueChange } = props;
154
+ const { t } = useTranslation("common", { keyPrefix: "side-panel" });
155
+ let control = null;
156
+ if (onValueChange || value.length > 1) control = /* @__PURE__ */ jsx(ContactRelationPopover, { ...props });
157
+ else if (!value.length) control = /* @__PURE__ */ jsx("span", {
158
+ className: "px-1 text-xs text-muted-foreground",
159
+ children: t("not-specified", "Not specified")
160
+ });
161
+ return /* @__PURE__ */ jsxs("div", {
162
+ className: "group/relations flex min-h-7 min-w-0 items-center gap-1 px-1",
163
+ children: [value.slice(0, 1).map((id) => /* @__PURE__ */ jsx("div", {
164
+ className: "flex min-w-0 overflow-hidden",
165
+ children: /* @__PURE__ */ jsx(ContactLink, {
166
+ contentType: kind === "company" ? "core:company" : "core:customer",
167
+ contentId: id,
168
+ contacts
169
+ })
170
+ }, id)), control]
171
+ });
172
+ };
173
+ export { ContactRelationInput, SelectContactContent };
package/exports.txt CHANGED
@@ -43,6 +43,7 @@ type TConditionGroup
43
43
  type TConditionLookups
44
44
  type TConditionRule
45
45
  type TContactContentType
46
+ type TContactKind
46
47
  type TDashboardWidget
47
48
  type TDashboardWidgetPreview
48
49
  type TListDisplay
@@ -91,6 +92,7 @@ value Command
91
92
  value CommandBar
92
93
  value ConditionsEditor
93
94
  value ContactLink
95
+ value ContactRelationInput
94
96
  value ContextMenu
95
97
  value CopyText
96
98
  value DASHBOARD_WIDGET_PREVIEWS
@@ -160,6 +162,7 @@ value RelativeDateDisplay
160
162
  value Resizable
161
163
  value ScrollArea
162
164
  value Select
165
+ value SelectContactContent
163
166
  value SelectMember
164
167
  value Separator
165
168
  value SexCode
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erxes/ui",
3
- "version": "4.0.0-v2.18",
3
+ "version": "4.0.0-v2.19",
4
4
  "private": false,
5
5
  "description": "erxes design system: UI primitives, layout, hooks and shared frontend state",
6
6
  "license": "AGPL-3.0-only",