@erxes/ui 4.0.0-v2.6 → 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 +11 -1
- 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 +15 -3
- package/dist/index.js +14 -2
- 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/openRecord.d.ts +18 -4
- package/dist/modules/records/openRecord.js +32 -13
- package/dist/types/UIConfig.d.ts +82 -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 +1 -1
package/README.md
CHANGED
|
@@ -32,7 +32,17 @@ Only what something uses:
|
|
|
32
32
|
through TanStack query options, so erxes-ui imports nothing from core.
|
|
33
33
|
- core's records in `src/modules/records`: `ContactLink` (a customer or company by id, read
|
|
34
34
|
through `contactQueries` from `@erxes/core-contract/client`) and `useOpenRecord`, which open a
|
|
35
|
-
record in web's side panel through the `RecordOpenerProvider` web mounts
|
|
35
|
+
record or a draft in web's side panel through the `RecordOpenerProvider` web mounts, and
|
|
36
|
+
`RecordPage`, a record on its own page.
|
|
37
|
+
- the record panel's rows in `src/modules/record-panel`, which web's side panel and the slots
|
|
38
|
+
of a plugin's record types (`IUIConfig.recordTypes`) both fill it with: `PanelSection`,
|
|
39
|
+
`PanelField`, `PanelFormRow`, `PanelFormLayout`, `PanelLabel`, the description field and
|
|
40
|
+
editor, and `usePanelExpanded`. The panel itself (header, tabs, resize) is web's.
|
|
41
|
+
- a list's bar in `src/modules/list`: `ViewBar`, `DisplayMenu` with `useListDisplay`, and
|
|
42
|
+
`ListFilter` with `useListFilterParams`.
|
|
43
|
+
- what the host app provides at startup, rendered through `hostComponent`
|
|
44
|
+
(`src/utils/host-component.tsx`): `setRecordTimeline`, `setRecordPage` and `setListFilter`.
|
|
45
|
+
Outside erxes they render nothing.
|
|
36
46
|
|
|
37
47
|
Anything else is removed, not kept "in case". Before you remove an export, check the HR plugin
|
|
38
48
|
UI and `.agents/skills/plugin-contract/SKILL.md`.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
/** The hover label of an icon-only button, with its shortcut when it has one. */
|
|
3
|
+
export declare const IconTip: ({ label, hotkey, children }: {
|
|
4
|
+
label: string;
|
|
5
|
+
hotkey?: string;
|
|
6
|
+
children: ReactElement;
|
|
7
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Kbd } from "./kbd.js";
|
|
2
|
+
import { Tooltip } from "./tooltip.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
// src/components/icon-tip.tsx
|
|
5
|
+
/** The hover label of an icon-only button, with its shortcut when it has one. */
|
|
6
|
+
const IconTip = ({ label, hotkey, children }) => /* @__PURE__ */ jsx(Tooltip.Provider, {
|
|
7
|
+
delay: 300,
|
|
8
|
+
children: /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(Tooltip.Trigger, { render: children }), /* @__PURE__ */ jsx(Tooltip.Content, {
|
|
9
|
+
side: "bottom",
|
|
10
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
11
|
+
className: "flex items-center gap-1.5",
|
|
12
|
+
children: [label, hotkey && /* @__PURE__ */ jsx(Kbd, { children: hotkey })]
|
|
13
|
+
})
|
|
14
|
+
})] })
|
|
15
|
+
});
|
|
16
|
+
export { IconTip };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Keys } from "react-hotkeys-hook";
|
|
2
|
+
/**
|
|
3
|
+
* A page shortcut (`c` adds, `f` filters, `/` focuses the description, `mod+shift+enter`
|
|
4
|
+
* expands the panel): runs `action` unless someone is typing or a dialog or menu is open.
|
|
5
|
+
* `when` decides per key press whether this hook takes it at all, so another one may.
|
|
6
|
+
* `useKey` matches the character typed instead of the key's position (`/` on any layout).
|
|
7
|
+
*/
|
|
8
|
+
export declare const usePageHotkey: (keys: Keys, action: () => void, { when, useKey }?: {
|
|
9
|
+
when?: () => boolean;
|
|
10
|
+
useKey?: boolean;
|
|
11
|
+
}) => import("react").RefCallback<HTMLElement | null>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useHotkeys } from "react-hotkeys-hook";
|
|
2
|
+
// src/hooks/use-page-hotkey.ts
|
|
3
|
+
const OVERLAY = "[role=\"dialog\"], [role=\"alertdialog\"], [role=\"menu\"], [role=\"listbox\"]";
|
|
4
|
+
/**
|
|
5
|
+
* Keys meant for something else: a repeat, an IME composition, a key a handler already took,
|
|
6
|
+
* one typed into a text box, or any key while an overlay is shown. react-hotkeys-hook already
|
|
7
|
+
* skips inputs, textareas, selects and contenteditable editors.
|
|
8
|
+
*/
|
|
9
|
+
const meantElsewhere = (event) => event.repeat || event.isComposing || event.defaultPrevented || event.target instanceof Element && event.target.closest("[role=\"textbox\"]") !== null || Array.from(document.querySelectorAll(OVERLAY)).some((overlay) => overlay.getClientRects().length > 0);
|
|
10
|
+
/**
|
|
11
|
+
* A page shortcut (`c` adds, `f` filters, `/` focuses the description, `mod+shift+enter`
|
|
12
|
+
* expands the panel): runs `action` unless someone is typing or a dialog or menu is open.
|
|
13
|
+
* `when` decides per key press whether this hook takes it at all, so another one may.
|
|
14
|
+
* `useKey` matches the character typed instead of the key's position (`/` on any layout).
|
|
15
|
+
*/
|
|
16
|
+
const usePageHotkey = (keys, action, { when, useKey } = {}) => useHotkeys(keys, action, {
|
|
17
|
+
useKey,
|
|
18
|
+
preventDefault: true,
|
|
19
|
+
ignoreEventWhen: (event) => meantElsewhere(event) || when?.() === false
|
|
20
|
+
});
|
|
21
|
+
export { usePageHotkey };
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { DropdownMenu } from "./components/dropdown-menu.js";
|
|
|
27
27
|
import { Empty } from "./components/empty.js";
|
|
28
28
|
import { Form } from "./components/form.js";
|
|
29
29
|
import { HoverCard } from "./components/hover-card.js";
|
|
30
|
+
import { IconTip } from "./components/icon-tip.js";
|
|
30
31
|
import { InfoCard } from "./components/info-card.js";
|
|
31
32
|
import { Input } from "./components/input.js";
|
|
32
33
|
import { InputGroup } from "./components/input-group.js";
|
|
@@ -55,6 +56,7 @@ import { Toggle } from "./components/toggle.js";
|
|
|
55
56
|
import { Tooltip } from "./components/tooltip.js";
|
|
56
57
|
import { Upload } from "./components/upload.js";
|
|
57
58
|
import { useConfirm } from "./hooks/use-confirm.js";
|
|
59
|
+
import { usePageHotkey } from "./hooks/use-page-hotkey.js";
|
|
58
60
|
import { toast, useToast } from "./hooks/use-toast.js";
|
|
59
61
|
import { useUpload } from "./hooks/use-upload.js";
|
|
60
62
|
import { cn } from "./lib/utils.js";
|
|
@@ -92,12 +94,22 @@ import { RecordTable } from "./modules/record-table/components/RecordTable.js";
|
|
|
92
94
|
import { RecordTableColumnDef } from "./modules/record-table/components/RecordTableProvider.js";
|
|
93
95
|
import { RecordTableInlineCell } from "./modules/record-table/components/RecordTableCellInline.js";
|
|
94
96
|
import { EnumCursorDirection } from "./modules/record-table/types/RecordTableCursorTypes.js";
|
|
97
|
+
import { DisplayMenu, TListDisplay, useListDisplay } from "./modules/list/DisplayMenu.js";
|
|
98
|
+
import { ListFilter, TListFilterField, TListFilterProps, setListFilter, useListFilterParams } from "./modules/list/ListFilter.js";
|
|
99
|
+
import { ViewBar } from "./modules/list/ViewBar.js";
|
|
100
|
+
import { PanelDescriptionEditor } from "./modules/record-panel/PanelDescriptionEditor.js";
|
|
101
|
+
import { PanelDescriptionField } from "./modules/record-panel/PanelDescriptionField.js";
|
|
102
|
+
import { PanelField, PanelFieldTrigger } from "./modules/record-panel/PanelField.js";
|
|
103
|
+
import { PanelFormLayout, PanelFormRow } from "./modules/record-panel/PanelForm.js";
|
|
104
|
+
import { PanelLabel } from "./modules/record-panel/PanelLabel.js";
|
|
105
|
+
import { PanelSection } from "./modules/record-panel/PanelSection.js";
|
|
106
|
+
import { PanelExpansionContext, usePanelExpanded } from "./modules/record-panel/panelExpansion.js";
|
|
95
107
|
import { ContactLink } from "./modules/records/ContactLink.js";
|
|
96
108
|
import { CompanyContact, ContactQueries, CustomerContact, TContactContentType, companyTitle, customerTitle } from "./modules/records/contacts.js";
|
|
97
|
-
import { RecordOpenerProvider, RecordRef, useOpenRecord } from "./modules/records/openRecord.js";
|
|
109
|
+
import { RecordOpenerProvider, RecordPage, RecordRef, setRecordPage, useOpenRecord } from "./modules/records/openRecord.js";
|
|
98
110
|
import { ThemeOption, themeState } from "./state/themeState.js";
|
|
99
111
|
import { SexCode } from "./types/SexCode.js";
|
|
100
|
-
import { IUIConfig, TActivityRowProps, TDashboardWidgetPreview, TPropertyInputMeta, TPropertyInputProps, TRecordSection, TRecordSectionProps } from "./types/UIConfig.js";
|
|
112
|
+
import { IUIConfig, TActivityRowProps, TDashboardWidgetPreview, TPanelRecordType, TPropertyInputMeta, TPropertyInputProps, TRecordContacts, TRecordDraftProps, TRecordSection, TRecordSectionProps, TRecordSlotProps, TRecordTab, TRelationTab, TRelationTabProps } from "./types/UIConfig.js";
|
|
101
113
|
import { isUndefinedOrNull } from "./utils/IsUndefinedOrNull.js";
|
|
102
114
|
import { readImage } from "./utils/core.js";
|
|
103
115
|
import { FileStorageAdapter, setFileStorage } from "./utils/file-storage.js";
|
|
@@ -107,4 +119,4 @@ import { jsonOf } from "./utils/json.js";
|
|
|
107
119
|
import { PluginLiveMessage, PluginRuntime, PluginSession, getPluginRuntime, pluginFetch, pluginJson, setPluginRuntime, useLiveSignal } from "./utils/plugin-runtime.js";
|
|
108
120
|
import { addPluginStyles } from "./utils/plugin-styles.js";
|
|
109
121
|
import { RecordTimeline, RecordTimelineProps, setRecordTimeline } from "./utils/record-timeline.js";
|
|
110
|
-
export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, type AvatarProps, BackgroundGradientAnimation, Badge, type BadgeProps, Breadcrumb, Button, type ButtonProps, Calendar, type CalendarProps, Card, type ChartConfig, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, type CompanyContact, ContactLink, type ContactQueries, ContextMenu, CopyText, type CustomerContact, DateInput, DatePicker, Dialog, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, type FileStorageAdapter, Filter, Form, FullNameField, FullNameValue, HoverCard, type IUIConfig, IconComponent, IconPicker, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, type Member, MemberInline, type MemberQueries, type MultiSelectOption, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PhoneDisplay, PhoneField, PhoneInput, type PluginLiveMessage, type PluginRuntime, type PluginSession, Popover, PopoverScoped, RadioGroup, RecordOpenerProvider, type RecordRef, RecordTable, type RecordTableColumnDef, RecordTableInlineCell, RecordTimeline, type RecordTimelineProps, RelativeDateDisplay, Resizable, ScrollArea, Select, SelectMember, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, type TActivityRowProps, type TContactContentType, type TDashboardWidgetPreview, type TPropertyInputMeta, type TPropertyInputProps, type TRecordSection, type TRecordSectionProps, TabButton, Table, Tabs, TextField, TextOverflowTooltip, Textarea, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, addPluginStyles, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatPhoneNumber, formatter, getPluginAssetsUrl, getPluginRuntime, isUndefinedOrNull, jsonOf, localTimeZone, memberName, pluginFetch, pluginJson, readImage, setFileStorage, setPluginRuntime, setRecordTimeline, stored, storedFamily, themeState, toIsoDay, toast, useConfirm, useFilterContext, useFormat, useLiveSignal, useMembersById, useOpenRecord, usePreviousHotkeyScope, useScopedHotkeys, useToast, useUpload, zoneOffset };
|
|
122
|
+
export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, type AvatarProps, BackgroundGradientAnimation, Badge, type BadgeProps, Breadcrumb, Button, type ButtonProps, Calendar, type CalendarProps, Card, type ChartConfig, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, type CompanyContact, ContactLink, type ContactQueries, ContextMenu, CopyText, type CustomerContact, DateInput, DatePicker, Dialog, DisplayMenu, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, type FileStorageAdapter, Filter, Form, FullNameField, FullNameValue, HoverCard, type IUIConfig, IconComponent, IconPicker, IconTip, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, ListFilter, type Member, MemberInline, type MemberQueries, type MultiSelectOption, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PanelDescriptionEditor, PanelDescriptionField, PanelExpansionContext, PanelField, PanelFieldTrigger, PanelFormLayout, PanelFormRow, PanelLabel, PanelSection, PhoneDisplay, PhoneField, PhoneInput, type PluginLiveMessage, type PluginRuntime, type PluginSession, Popover, PopoverScoped, RadioGroup, RecordOpenerProvider, RecordPage, type RecordRef, RecordTable, type RecordTableColumnDef, RecordTableInlineCell, RecordTimeline, type RecordTimelineProps, RelativeDateDisplay, Resizable, ScrollArea, Select, SelectMember, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, type TActivityRowProps, type TContactContentType, type TDashboardWidgetPreview, type TListDisplay, type TListFilterField, type TListFilterProps, type TPanelRecordType, type TPropertyInputMeta, type TPropertyInputProps, type TRecordContacts, type TRecordDraftProps, type TRecordSection, type TRecordSectionProps, type TRecordSlotProps, type TRecordTab, type TRelationTab, type TRelationTabProps, TabButton, Table, Tabs, TextField, TextOverflowTooltip, Textarea, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, ViewBar, addPluginStyles, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatPhoneNumber, formatter, getPluginAssetsUrl, getPluginRuntime, isUndefinedOrNull, jsonOf, localTimeZone, memberName, pluginFetch, pluginJson, readImage, setFileStorage, setListFilter, setPluginRuntime, setRecordPage, setRecordTimeline, stored, storedFamily, themeState, toIsoDay, toast, useConfirm, useFilterContext, useFormat, useListDisplay, useListFilterParams, useLiveSignal, useMembersById, useOpenRecord, usePageHotkey, usePanelExpanded, usePreviousHotkeyScope, useScopedHotkeys, useToast, useUpload, zoneOffset };
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import { DropdownMenu } from "./components/dropdown-menu.js";
|
|
|
26
26
|
import { Empty } from "./components/empty.js";
|
|
27
27
|
import { Form } from "./components/form.js";
|
|
28
28
|
import { HoverCard } from "./components/hover-card.js";
|
|
29
|
+
import { IconTip } from "./components/icon-tip.js";
|
|
29
30
|
import { InfoCard } from "./components/info-card.js";
|
|
30
31
|
import { Input } from "./components/input.js";
|
|
31
32
|
import { InputGroup } from "./components/input-group.js";
|
|
@@ -53,6 +54,7 @@ import { Toggle } from "./components/toggle.js";
|
|
|
53
54
|
import { Tooltip } from "./components/tooltip.js";
|
|
54
55
|
import { Upload } from "./components/upload.js";
|
|
55
56
|
import { useConfirm } from "./hooks/use-confirm.js";
|
|
57
|
+
import { usePageHotkey } from "./hooks/use-page-hotkey.js";
|
|
56
58
|
import { toast, useToast } from "./hooks/use-toast.js";
|
|
57
59
|
import { useUpload } from "./hooks/use-upload.js";
|
|
58
60
|
import { cn } from "./lib/utils.js";
|
|
@@ -89,9 +91,19 @@ import { PhoneInput } from "./modules/record-field/meta-inputs/components/PhoneI
|
|
|
89
91
|
import { RecordTable } from "./modules/record-table/components/RecordTable.js";
|
|
90
92
|
import { RecordTableInlineCell } from "./modules/record-table/components/RecordTableCellInline.js";
|
|
91
93
|
import { EnumCursorDirection } from "./modules/record-table/types/RecordTableCursorTypes.js";
|
|
94
|
+
import { DisplayMenu, useListDisplay } from "./modules/list/DisplayMenu.js";
|
|
95
|
+
import { ListFilter, setListFilter, useListFilterParams } from "./modules/list/ListFilter.js";
|
|
96
|
+
import { ViewBar } from "./modules/list/ViewBar.js";
|
|
97
|
+
import { PanelDescriptionEditor } from "./modules/record-panel/PanelDescriptionEditor.js";
|
|
98
|
+
import { PanelDescriptionField } from "./modules/record-panel/PanelDescriptionField.js";
|
|
99
|
+
import { PanelField, PanelFieldTrigger } from "./modules/record-panel/PanelField.js";
|
|
100
|
+
import { PanelFormLayout, PanelFormRow } from "./modules/record-panel/PanelForm.js";
|
|
101
|
+
import { PanelLabel } from "./modules/record-panel/PanelLabel.js";
|
|
102
|
+
import { PanelSection } from "./modules/record-panel/PanelSection.js";
|
|
103
|
+
import { PanelExpansionContext, usePanelExpanded } from "./modules/record-panel/panelExpansion.js";
|
|
92
104
|
import { ContactLink } from "./modules/records/ContactLink.js";
|
|
93
105
|
import { companyTitle, customerTitle } from "./modules/records/contacts.js";
|
|
94
|
-
import { RecordOpenerProvider, useOpenRecord } from "./modules/records/openRecord.js";
|
|
106
|
+
import { RecordOpenerProvider, RecordPage, setRecordPage, useOpenRecord } from "./modules/records/openRecord.js";
|
|
95
107
|
import { ThemeOption, themeState } from "./state/themeState.js";
|
|
96
108
|
import { SexCode } from "./types/SexCode.js";
|
|
97
109
|
import { isUndefinedOrNull } from "./utils/IsUndefinedOrNull.js";
|
|
@@ -103,4 +115,4 @@ import { jsonOf } from "./utils/json.js";
|
|
|
103
115
|
import { getPluginRuntime, pluginFetch, pluginJson, setPluginRuntime, useLiveSignal } from "./utils/plugin-runtime.js";
|
|
104
116
|
import { addPluginStyles } from "./utils/plugin-styles.js";
|
|
105
117
|
import { RecordTimeline, setRecordTimeline } from "./utils/record-timeline.js";
|
|
106
|
-
export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, BackgroundGradientAnimation, Badge, Breadcrumb, Button, Calendar, Card, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, ContactLink, ContextMenu, CopyText, DateInput, DatePicker, Dialog, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, Filter, Form, FullNameField, FullNameValue, HoverCard, IconComponent, IconPicker, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, MemberInline, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PhoneDisplay, PhoneField, PhoneInput, Popover, PopoverScoped, RadioGroup, RecordOpenerProvider, 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, addPluginStyles, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatPhoneNumber, formatter, getPluginAssetsUrl, getPluginRuntime, isUndefinedOrNull, jsonOf, localTimeZone, memberName, pluginFetch, pluginJson, readImage, setFileStorage, setPluginRuntime, setRecordTimeline, stored, storedFamily, themeState, toIsoDay, toast, useConfirm, useFilterContext, useFormat, useLiveSignal, useMembersById, useOpenRecord, usePreviousHotkeyScope, useScopedHotkeys, useToast, useUpload, zoneOffset };
|
|
118
|
+
export { Accordion, Alert, AlertDialog, AppLayout, AppLayoutFooterLink, Avatar, BackgroundGradientAnimation, Badge, Breadcrumb, Button, Calendar, Card, ChartContainer, ChartLegendContent, ChartTooltipContent, Checkbox, ChoiceboxGroup, Collapsible, ColorPicker, Combobox, Command, CommandBar, ContactLink, ContextMenu, CopyText, DateInput, DatePicker, Dialog, DisplayMenu, DragHandle, DropdownMenu, Editor, EmailDisplay, EmailListField, Empty, EntityPicker, EnumCursorDirection, Filter, Form, FullNameField, FullNameValue, HoverCard, IconComponent, IconPicker, IconTip, IconsProvider, InfoCard, Input, InputGroup, Kbd, LANGUAGES, Label, ListFilter, MemberInline, MultipleSelector, NavigationMenuLinkItem, NumberField, PageContainer, PageHeader, PageSubHeader, PanelDescriptionEditor, PanelDescriptionField, PanelExpansionContext, PanelField, PanelFieldTrigger, PanelFormLayout, PanelFormRow, PanelLabel, PanelSection, PhoneDisplay, PhoneField, PhoneInput, Popover, PopoverScoped, RadioGroup, RecordOpenerProvider, RecordPage, RecordTable, RecordTableInlineCell, RecordTimeline, RelativeDateDisplay, Resizable, ScrollArea, Select, SelectMember, Separator, SexCode, SexDisplay, SexField, Sheet, Sidebar, Skeleton, Slider, Spinner, StringArrayInput, Switch, TabButton, Table, Tabs, TextField, TextOverflowTooltip, Textarea, ThemeOption, TimeField, Toaster, Toggle, ToggleGroup, Tooltip, Upload, ViewBar, addPluginStyles, badgeVariants, buttonVariants, cn, companyTitle, customerTitle, editorText, formatPhoneNumber, formatter, getPluginAssetsUrl, getPluginRuntime, isUndefinedOrNull, jsonOf, localTimeZone, memberName, pluginFetch, pluginJson, readImage, setFileStorage, setListFilter, setPluginRuntime, setRecordPage, setRecordTimeline, stored, storedFamily, themeState, toIsoDay, toast, useConfirm, useFilterContext, useFormat, useListDisplay, useListFilterParams, useLiveSignal, useMembersById, useOpenRecord, usePageHotkey, usePanelExpanded, usePreviousHotkeyScope, useScopedHotkeys, useToast, useUpload, zoneOffset };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const LIST_DISPLAYS: readonly ['table', 'board'];
|
|
2
|
+
/** How a list shows its records: rows in a table, or cards on a board. */
|
|
3
|
+
export type TListDisplay = (typeof LIST_DISPLAYS)[number];
|
|
4
|
+
/**
|
|
5
|
+
* `const [display] = useListDisplay('sales-deals')`: the table or board a list shows, chosen
|
|
6
|
+
* under its Display menu and remembered in this browser, one choice per list.
|
|
7
|
+
*/
|
|
8
|
+
export declare const useListDisplay: (list: string) => ["board" | "table", (args_0: "board" | "table" | typeof import("jotai/utils").RESET | ((prev: "board" | "table") => "board" | "table" | typeof import("jotai/utils").RESET)) => void];
|
|
9
|
+
/** "Display" in a list's filter bar: table or board (`useListDisplay(list)` reads the choice). */
|
|
10
|
+
export declare const DisplayMenu: ({ list }: {
|
|
11
|
+
list: string;
|
|
12
|
+
}) => import("react").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Button } from "../../components/button.js";
|
|
2
|
+
import { IconTip } from "../../components/icon-tip.js";
|
|
3
|
+
import { Popover } from "../../components/popover.js";
|
|
4
|
+
import { storedFamily } from "../../lib/stored.js";
|
|
5
|
+
import { cn } from "../../lib/utils.js";
|
|
6
|
+
import { IconAdjustmentsHorizontal, IconLayoutKanban, IconTable } from "@tabler/icons-react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { useAtom } from "jotai";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { useTranslation } from "react-i18next";
|
|
11
|
+
// src/modules/list/DisplayMenu.tsx
|
|
12
|
+
const listDisplayFamily = storedFamily({
|
|
13
|
+
key: "erxes:list-display",
|
|
14
|
+
schema: z.enum(["table", "board"]),
|
|
15
|
+
initial: "table"
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* `const [display] = useListDisplay('sales-deals')`: the table or board a list shows, chosen
|
|
19
|
+
* under its Display menu and remembered in this browser, one choice per list.
|
|
20
|
+
*/
|
|
21
|
+
const useListDisplay = (list) => useAtom(listDisplayFamily(list));
|
|
22
|
+
const DISPLAYS = [{
|
|
23
|
+
value: "table",
|
|
24
|
+
label: "table",
|
|
25
|
+
fallback: "Table",
|
|
26
|
+
icon: IconTable
|
|
27
|
+
}, {
|
|
28
|
+
value: "board",
|
|
29
|
+
label: "board",
|
|
30
|
+
fallback: "Board",
|
|
31
|
+
icon: IconLayoutKanban
|
|
32
|
+
}];
|
|
33
|
+
/** "Display" in a list's filter bar: table or board (`useListDisplay(list)` reads the choice). */
|
|
34
|
+
const DisplayMenu = ({ list }) => {
|
|
35
|
+
const [current, setDisplay] = useListDisplay(list);
|
|
36
|
+
const { t } = useTranslation("views", { keyPrefix: "display" });
|
|
37
|
+
return /* @__PURE__ */ jsxs(Popover, { children: [/* @__PURE__ */ jsx(IconTip, {
|
|
38
|
+
label: t("label", "Display"),
|
|
39
|
+
children: /* @__PURE__ */ jsx(Popover.Trigger, {
|
|
40
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
41
|
+
variant: "ghost",
|
|
42
|
+
size: "icon",
|
|
43
|
+
"aria-label": t("label", "Display"),
|
|
44
|
+
tone: "muted"
|
|
45
|
+
}),
|
|
46
|
+
children: /* @__PURE__ */ jsx(IconAdjustmentsHorizontal, { className: "size-4" })
|
|
47
|
+
})
|
|
48
|
+
}), /* @__PURE__ */ jsxs(Popover.Content, {
|
|
49
|
+
align: "end",
|
|
50
|
+
className: "w-64",
|
|
51
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
52
|
+
className: "mb-2 text-xs font-medium text-muted-foreground",
|
|
53
|
+
children: t("view", "View")
|
|
54
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
55
|
+
className: "grid grid-cols-2 gap-2",
|
|
56
|
+
children: DISPLAYS.map(({ value, label, fallback, icon: Icon }) => /* @__PURE__ */ jsxs("button", {
|
|
57
|
+
type: "button",
|
|
58
|
+
"aria-pressed": current === value,
|
|
59
|
+
onClick: () => setDisplay(value),
|
|
60
|
+
className: cn("flex flex-col items-center gap-1.5 rounded-lg border p-3 text-sm text-muted-foreground transition-colors hover:bg-accent", current === value && "border-primary bg-primary/5 font-medium text-foreground"),
|
|
61
|
+
children: [/* @__PURE__ */ jsx(Icon, { className: "size-5" }), t(label, fallback)]
|
|
62
|
+
}, value))
|
|
63
|
+
})]
|
|
64
|
+
})] });
|
|
65
|
+
};
|
|
66
|
+
export { DisplayMenu, useListDisplay };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ElementType, ReactNode } from "react";
|
|
2
|
+
/** A field a plugin's list filters by, as its menu, chip and the advanced filter show it. */
|
|
3
|
+
export type TListFilterField = {
|
|
4
|
+
/** The rules' `path` in the filter the list's API gets: `subject.<column>`, e.g. `subject.stageId`. */
|
|
5
|
+
path: `subject.${string}`;
|
|
6
|
+
label: string;
|
|
7
|
+
/** How it compares: contains (text), ranges (number), relative dates, yes/no, a pick. */
|
|
8
|
+
type: 'text' | 'number' | 'date' | 'boolean' | 'select' | 'member';
|
|
9
|
+
/** A `select`'s choices. */
|
|
10
|
+
options?: {
|
|
11
|
+
value: string;
|
|
12
|
+
label: string;
|
|
13
|
+
}[];
|
|
14
|
+
/** Instead of the type's icon. */
|
|
15
|
+
icon?: ElementType;
|
|
16
|
+
};
|
|
17
|
+
export type TListFilterProps = {
|
|
18
|
+
/** Unique per list, e.g. `sales-deals`: its menu's hotkey scope. */
|
|
19
|
+
id: string;
|
|
20
|
+
fields: TListFilterField[];
|
|
21
|
+
/** How many records match, shown after the chips; undefined while it loads. */
|
|
22
|
+
totalCount?: number | null;
|
|
23
|
+
/** The count stopped at its cap ("1,000+"). */
|
|
24
|
+
totalCapped?: boolean;
|
|
25
|
+
/** The list's own controls, before the menu: `DisplayMenu`, an Archived toggle. */
|
|
26
|
+
children?: ReactNode;
|
|
27
|
+
};
|
|
28
|
+
/** Web registers core's filter bar. */
|
|
29
|
+
export declare const setListFilter: (component: import("react").ComponentType<TListFilterProps> | null) => void;
|
|
30
|
+
/**
|
|
31
|
+
* A plugin list's filter bar, core's own: the menu of `fields` (`F`), search, the advanced
|
|
32
|
+
* filter, and each condition as a chip. The conditions and search live in the address (shared
|
|
33
|
+
* links and reloads keep them); `useListFilterParams()` reads them for the list's query.
|
|
34
|
+
*/
|
|
35
|
+
export declare const ListFilter: (props: TListFilterProps) => import("react").JSX.Element | null;
|
|
36
|
+
/**
|
|
37
|
+
* What `ListFilter` holds, for the list's API: `filter`, core's condition group
|
|
38
|
+
* (`ConditionGroup` from `@erxes/core-contract`) as JSON, its rules on the fields' paths,
|
|
39
|
+
* and `search`. Both are undefined when unset.
|
|
40
|
+
*/
|
|
41
|
+
export declare const useListFilterParams: () => {
|
|
42
|
+
filter: string | undefined;
|
|
43
|
+
search: string | undefined;
|
|
44
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { hostComponent } from "../../utils/host-component.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { parseAsString, useQueryStates } from "nuqs";
|
|
4
|
+
// src/modules/list/ListFilter.tsx
|
|
5
|
+
const listFilter = hostComponent();
|
|
6
|
+
/** Web registers core's filter bar. */
|
|
7
|
+
const setListFilter = listFilter.set;
|
|
8
|
+
/**
|
|
9
|
+
* A plugin list's filter bar, core's own: the menu of `fields` (`F`), search, the advanced
|
|
10
|
+
* filter, and each condition as a chip. The conditions and search live in the address (shared
|
|
11
|
+
* links and reloads keep them); `useListFilterParams()` reads them for the list's query.
|
|
12
|
+
*/
|
|
13
|
+
const ListFilter = listFilter.Host;
|
|
14
|
+
const FilterGroup = z.looseObject({ rules: z.array(z.unknown()).min(1) });
|
|
15
|
+
/** The filter as JSON text when it has a condition; anything else in the address reads as none. */
|
|
16
|
+
const filterText = (text) => {
|
|
17
|
+
if (!text) return void 0;
|
|
18
|
+
try {
|
|
19
|
+
return FilterGroup.safeParse(JSON.parse(text)).success ? text : void 0;
|
|
20
|
+
} catch {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* What `ListFilter` holds, for the list's API: `filter`, core's condition group
|
|
26
|
+
* (`ConditionGroup` from `@erxes/core-contract`) as JSON, its rules on the fields' paths,
|
|
27
|
+
* and `search`. Both are undefined when unset.
|
|
28
|
+
*/
|
|
29
|
+
const useListFilterParams = () => {
|
|
30
|
+
const [{ advanced, searchValue }] = useQueryStates({
|
|
31
|
+
advanced: parseAsString,
|
|
32
|
+
searchValue: parseAsString
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
filter: filterText(advanced),
|
|
36
|
+
search: searchValue || void 0
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export { ListFilter, setListFilter, useListFilterParams };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A list's one bar, under its page header: its views on the left, its filter on the right
|
|
4
|
+
* (`ListFilter`, with `DisplayMenu` inside it). The first tab's icon lines up with the page
|
|
5
|
+
* header's first crumb. Without `tabs` the list has one view, "All …" (`allLabel`).
|
|
6
|
+
*/
|
|
7
|
+
export declare const ViewBar: ({ allLabel, tabs, children }: {
|
|
8
|
+
allLabel: string;
|
|
9
|
+
/** Saved views as tabs; core's own lists pass theirs. */
|
|
10
|
+
tabs?: ReactNode;
|
|
11
|
+
/** The list's filter. */
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TabButton } from "../../components/tabs.js";
|
|
2
|
+
import { IconLayoutList } from "@tabler/icons-react";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useAutoAnimate } from "@formkit/auto-animate/react";
|
|
5
|
+
// src/modules/list/ViewBar.tsx
|
|
6
|
+
/**
|
|
7
|
+
* A list's one bar, under its page header: its views on the left, its filter on the right
|
|
8
|
+
* (`ListFilter`, with `DisplayMenu` inside it). The first tab's icon lines up with the page
|
|
9
|
+
* header's first crumb. Without `tabs` the list has one view, "All …" (`allLabel`).
|
|
10
|
+
*/
|
|
11
|
+
const ViewBar = ({ allLabel, tabs, children }) => {
|
|
12
|
+
const [tabsRef] = useAutoAnimate({ duration: 150 });
|
|
13
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
14
|
+
className: "flex h-10 shrink-0 items-center gap-3 border-b bg-background pr-3",
|
|
15
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
16
|
+
ref: tabsRef,
|
|
17
|
+
className: "flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto p-1 hide-scroll",
|
|
18
|
+
children: tabs ?? /* @__PURE__ */ jsxs(TabButton, {
|
|
19
|
+
type: "button",
|
|
20
|
+
"aria-current": "page",
|
|
21
|
+
active: true,
|
|
22
|
+
children: [/* @__PURE__ */ jsx(IconLayoutList, {}), allLabel]
|
|
23
|
+
})
|
|
24
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
25
|
+
className: "flex min-w-0 max-w-13/20 shrink-0 items-center justify-end",
|
|
26
|
+
children
|
|
27
|
+
})]
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
export { ViewBar };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** A record's description as a full-size tab, saved when the editor loses focus. */
|
|
2
|
+
export declare const PanelDescriptionEditor: ({ value, scope, readonly, isHTML, onSave }: {
|
|
3
|
+
value: string;
|
|
4
|
+
scope: string;
|
|
5
|
+
readonly?: boolean;
|
|
6
|
+
/** Stores HTML instead of the editor's blocks. */
|
|
7
|
+
isHTML?: boolean;
|
|
8
|
+
onSave: (description: string) => void;
|
|
9
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { usePageHotkey } from "../../hooks/use-page-hotkey.js";
|
|
2
|
+
import { Editor } from "../blocks/components/LazyEditor.js";
|
|
3
|
+
import { useSaveOnLeave } from "./useSaveOnLeave.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/modules/record-panel/PanelDescriptionEditor.tsx
|
|
6
|
+
/** The editor inside `container`, when it is shown (an inactive tab's panel is `hidden`). */
|
|
7
|
+
const visibleEditor = (container) => {
|
|
8
|
+
const editor = container?.querySelector("[contenteditable=\"true\"]");
|
|
9
|
+
if (!editor?.getClientRects().length) return null;
|
|
10
|
+
return editor.closest("[hidden], [inert]") ? null : editor;
|
|
11
|
+
};
|
|
12
|
+
/** `/` focuses the description editor, unless it is read-only or not shown (another panel's may be). */
|
|
13
|
+
const useSlashFocus = (containerRef, readonly) => usePageHotkey("/", () => visibleEditor(containerRef.current)?.focus(), {
|
|
14
|
+
useKey: true,
|
|
15
|
+
when: () => !readonly && visibleEditor(containerRef.current) !== null
|
|
16
|
+
});
|
|
17
|
+
/** A record's description as a full-size tab, saved when the editor loses focus. */
|
|
18
|
+
const PanelDescriptionEditor = ({ value, scope, readonly, isHTML, onSave }) => {
|
|
19
|
+
const { containerRef, onChange } = useSaveOnLeave({
|
|
20
|
+
value,
|
|
21
|
+
readonly,
|
|
22
|
+
onSave
|
|
23
|
+
});
|
|
24
|
+
useSlashFocus(containerRef, readonly);
|
|
25
|
+
return /* @__PURE__ */ jsx("div", {
|
|
26
|
+
ref: containerRef,
|
|
27
|
+
className: "flex min-h-0 flex-1 flex-col p-3",
|
|
28
|
+
children: /* @__PURE__ */ jsx(Editor, {
|
|
29
|
+
initialContent: value,
|
|
30
|
+
onChange,
|
|
31
|
+
scope,
|
|
32
|
+
readonly,
|
|
33
|
+
isHTML,
|
|
34
|
+
variant: "default",
|
|
35
|
+
className: "h-full min-h-0 flex-1 [&_.bn-container]:h-full [&_.bn-editor]:min-h-full"
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
export { PanelDescriptionEditor };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const PanelDescriptionField: ({ label, value, scope, readonly, isHTML, onSave }: {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
scope: string;
|
|
5
|
+
readonly?: boolean;
|
|
6
|
+
/** Stores HTML instead of the editor's blocks. */
|
|
7
|
+
isHTML?: boolean;
|
|
8
|
+
onSave: (value: string) => void;
|
|
9
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Editor } from "../blocks/components/LazyEditor.js";
|
|
2
|
+
import { useSaveOnLeave } from "./useSaveOnLeave.js";
|
|
3
|
+
import { IconAlignLeft } from "@tabler/icons-react";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/modules/record-panel/PanelDescriptionField.tsx
|
|
6
|
+
const PanelDescriptionField = ({ label, value, scope, readonly, isHTML, onSave }) => {
|
|
7
|
+
const { containerRef, onChange } = useSaveOnLeave({
|
|
8
|
+
value,
|
|
9
|
+
readonly,
|
|
10
|
+
onSave
|
|
11
|
+
});
|
|
12
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
13
|
+
className: "flex flex-col gap-1.5 pt-2",
|
|
14
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
15
|
+
className: "flex items-center gap-1.5 text-xs font-medium text-accent-foreground",
|
|
16
|
+
children: [/* @__PURE__ */ jsx(IconAlignLeft, {
|
|
17
|
+
className: "size-3.5 shrink-0",
|
|
18
|
+
"aria-hidden": "true"
|
|
19
|
+
}), label]
|
|
20
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
21
|
+
ref: containerRef,
|
|
22
|
+
children: /* @__PURE__ */ jsx(Editor, {
|
|
23
|
+
initialContent: value,
|
|
24
|
+
onChange,
|
|
25
|
+
scope,
|
|
26
|
+
label,
|
|
27
|
+
readonly,
|
|
28
|
+
isHTML,
|
|
29
|
+
variant: "ghost",
|
|
30
|
+
className: "h-auto min-h-20"
|
|
31
|
+
})
|
|
32
|
+
})]
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export { PanelDescriptionField };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RecordTableInlineCell } from "../record-table/components/RecordTableCellInline.js";
|
|
2
|
+
import { Icon } from "@tabler/icons-react";
|
|
3
|
+
export declare const PanelField: ({ label, icon: Icon, children, placeholder, htmlFor, cell }: {
|
|
4
|
+
label: React.ReactNode;
|
|
5
|
+
icon?: Icon;
|
|
6
|
+
placeholder?: React.ReactNode;
|
|
7
|
+
htmlFor?: string;
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
cell?: boolean;
|
|
10
|
+
}) => import("react").JSX.Element;
|
|
11
|
+
export declare const PanelFieldTrigger: (props: React.ComponentProps<typeof RecordTableInlineCell.Trigger>) => import("react").JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Label } from "../../components/label.js";
|
|
2
|
+
import { cn } from "../../lib/utils.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
|
+
// src/modules/record-panel/PanelField.tsx
|
|
9
|
+
const PanelField = ({ label, icon: Icon = IconForms, children, placeholder, htmlFor, cell = true }) => {
|
|
10
|
+
const labelId = useId();
|
|
11
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
12
|
+
className: "grid grid-cols-field items-center gap-x-2 min-h-7",
|
|
13
|
+
children: [/* @__PURE__ */ jsxs(Label, {
|
|
14
|
+
id: labelId,
|
|
15
|
+
htmlFor,
|
|
16
|
+
variant: "muted",
|
|
17
|
+
className: "flex min-w-0 items-center",
|
|
18
|
+
children: [Icon && /* @__PURE__ */ jsx(Icon, {
|
|
19
|
+
className: "size-3.5 shrink-0",
|
|
20
|
+
"aria-hidden": "true"
|
|
21
|
+
}), /* @__PURE__ */ jsx(PanelLabel, { children: label })]
|
|
22
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
23
|
+
className: cn("relative min-w-0", cell && "text-xs [&_button:not([role=switch],[data-panel-inline])]:h-7 [&_button:not([role=switch])]:text-xs [&_input]:text-xs"),
|
|
24
|
+
children: [/* @__PURE__ */ jsx(RecordTableInlineCell.LabelledBy, {
|
|
25
|
+
value: labelId,
|
|
26
|
+
children
|
|
27
|
+
}), placeholder && /* @__PURE__ */ jsxs("span", {
|
|
28
|
+
className: "pointer-events-none absolute inset-y-0 left-2 flex items-center gap-1.5 text-xs text-muted-foreground",
|
|
29
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
30
|
+
className: "size-3.5 shrink-0",
|
|
31
|
+
"aria-hidden": "true"
|
|
32
|
+
}), placeholder]
|
|
33
|
+
})]
|
|
34
|
+
})]
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const PanelFieldTrigger = (props) => /* @__PURE__ */ jsx(RecordTableInlineCell.Trigger, {
|
|
38
|
+
variant: "field",
|
|
39
|
+
...props
|
|
40
|
+
});
|
|
41
|
+
export { PanelField, PanelFieldTrigger };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Icon } from "@tabler/icons-react";
|
|
2
|
+
/**
|
|
3
|
+
* One field of a record not created yet, laid out like `PanelField`: its
|
|
4
|
+
* label, then the input, with the field's error under it.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PanelFormRow: ({ label, icon: Icon, required, error, children }: {
|
|
7
|
+
label: React.ReactNode;
|
|
8
|
+
icon?: Icon;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
error?: string;
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
}) => import("react").JSX.Element;
|
|
13
|
+
/**
|
|
14
|
+
* The body and footer of a new record's form in the side panel: its rows,
|
|
15
|
+
* then Cancel and Save. Nothing is saved until Save.
|
|
16
|
+
*/
|
|
17
|
+
export declare const PanelFormLayout: ({ children, onCancel, saving, saveLabel }: {
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
onCancel: () => void;
|
|
20
|
+
saving?: boolean;
|
|
21
|
+
saveLabel?: string;
|
|
22
|
+
}) => import("react").JSX.Element;
|
|
@@ -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 };
|
|
@@ -5,21 +5,35 @@ export interface RecordRef {
|
|
|
5
5
|
contentId: string;
|
|
6
6
|
}
|
|
7
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;
|
|
8
10
|
/**
|
|
9
11
|
* How records open, provided by the host app (web): beside the page in its side panel, or,
|
|
10
12
|
* inside a record, on top of that record so Back returns to it. erxes-ui is a Module
|
|
11
13
|
* Federation singleton, so every plugin reads the host's.
|
|
12
14
|
*/
|
|
13
|
-
export declare const RecordOpenerProvider: ({ open, children }: PropsWithChildren<{
|
|
15
|
+
export declare const RecordOpenerProvider: ({ open, openNew, children }: PropsWithChildren<{
|
|
14
16
|
open: OpenRecord;
|
|
17
|
+
openNew?: OpenNewRecord;
|
|
15
18
|
}>) => import("react").JSX.Element;
|
|
16
19
|
/**
|
|
17
|
-
* `const { open } = useOpenRecord()
|
|
18
|
-
*
|
|
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.
|
|
20
25
|
*/
|
|
21
26
|
export declare const useOpenRecord: () => {
|
|
22
27
|
open: OpenRecord;
|
|
28
|
+
openNew: OpenNewRecord;
|
|
23
29
|
canOpen: boolean;
|
|
24
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;
|
|
25
39
|
export {};
|
|
@@ -1,27 +1,46 @@
|
|
|
1
|
+
import { hostComponent } from "../../utils/host-component.js";
|
|
1
2
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, use } from "react";
|
|
3
|
+
import { createContext, use, useMemo } from "react";
|
|
3
4
|
// src/modules/records/openRecord.tsx
|
|
4
5
|
const RecordOpenerContext = createContext(null);
|
|
6
|
+
const ignore = () => void 0;
|
|
5
7
|
/**
|
|
6
8
|
* How records open, provided by the host app (web): beside the page in its side panel, or,
|
|
7
9
|
* inside a record, on top of that record so Back returns to it. erxes-ui is a Module
|
|
8
10
|
* Federation singleton, so every plugin reads the host's.
|
|
9
11
|
*/
|
|
10
|
-
const RecordOpenerProvider = ({ open, children }) =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
};
|
|
15
22
|
/**
|
|
16
|
-
* `const { open } = useOpenRecord()
|
|
17
|
-
*
|
|
18
|
-
*
|
|
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.
|
|
19
28
|
*/
|
|
20
29
|
const useOpenRecord = () => {
|
|
21
|
-
const
|
|
30
|
+
const opener = use(RecordOpenerContext);
|
|
22
31
|
return {
|
|
23
|
-
open: open ?? ignore,
|
|
24
|
-
|
|
32
|
+
open: opener?.open ?? ignore,
|
|
33
|
+
openNew: opener?.openNew ?? ignore,
|
|
34
|
+
canOpen: opener !== null
|
|
25
35
|
};
|
|
26
36
|
};
|
|
27
|
-
|
|
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,5 +1,7 @@
|
|
|
1
1
|
import { TContactContentType } from "../modules/records/contacts.js";
|
|
2
|
+
import { RecordRef } from "../modules/records/openRecord.js";
|
|
2
3
|
import { Icon } from "@tabler/icons-react";
|
|
4
|
+
import { UseQueryOptions } from "@tanstack/react-query";
|
|
3
5
|
/** A property input's own settings, stored with the custom field; each input defines its keys. */
|
|
4
6
|
export type TPropertyInputMeta = Record<string, unknown>;
|
|
5
7
|
export type TActivityRowProps = {
|
|
@@ -36,12 +38,92 @@ export type TRecordSection = {
|
|
|
36
38
|
icon: React.ElementType;
|
|
37
39
|
component: React.ComponentType<TRecordSectionProps>;
|
|
38
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
|
+
};
|
|
39
117
|
export type IUIConfig = {
|
|
40
118
|
name: string;
|
|
41
119
|
path: string;
|
|
42
120
|
icon?: React.ElementType;
|
|
43
121
|
/** Sections on core's customer and company detail, shown to members who may use the plugin. */
|
|
44
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[];
|
|
45
127
|
i18n?: boolean;
|
|
46
128
|
i18nNamespace?: string;
|
|
47
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
|
/**
|
|
@@ -4,6 +4,8 @@ import { z } from "zod";
|
|
|
4
4
|
// src/utils/plugin-runtime.ts
|
|
5
5
|
let runtime = null;
|
|
6
6
|
const sessions = /* @__PURE__ */ new Map();
|
|
7
|
+
/** A token is replaced this long before it ends, so no call carries one about to expire. */
|
|
8
|
+
const RENEW_BEFORE_MS = 3e4;
|
|
7
9
|
const setPluginRuntime = (next) => {
|
|
8
10
|
runtime = next;
|
|
9
11
|
sessions.clear();
|
|
@@ -13,19 +15,58 @@ const need = () => {
|
|
|
13
15
|
if (!runtime) throw new Error("erxes plugin runtime is not available (open the plugin inside erxes)");
|
|
14
16
|
return runtime;
|
|
15
17
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const Lifetime = jsonOf(z.object({
|
|
19
|
+
iat: z.number(),
|
|
20
|
+
exp: z.number()
|
|
21
|
+
}));
|
|
22
|
+
/** A JWT's claims as text; '' for a token that isn't one (its lifetime then comes from `expiresAt`). */
|
|
23
|
+
const claimsText = (token) => {
|
|
24
|
+
try {
|
|
25
|
+
return atob((token.split(".")[1] ?? "").replaceAll("-", "+").replaceAll("_", "/"));
|
|
26
|
+
} catch {
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* How long a token lasts, from its own claims (both core's clock), so a
|
|
32
|
+
* browser whose clock is set wrong still renews on time.
|
|
33
|
+
*/
|
|
34
|
+
const lifetimeMs = (session) => {
|
|
35
|
+
const claims = Lifetime.safeParse(claimsText(session.token));
|
|
36
|
+
return claims.success ? (claims.data.exp - claims.data.iat) * 1e3 : new Date(session.expiresAt).getTime() - Date.now();
|
|
37
|
+
};
|
|
38
|
+
const renew = (plugin) => {
|
|
39
|
+
const request = need().session(plugin).then((session) => ({
|
|
40
|
+
session,
|
|
41
|
+
endsAt: Date.now() + lifetimeMs(session)
|
|
42
|
+
}));
|
|
21
43
|
sessions.set(plugin, request);
|
|
22
|
-
request.catch(() =>
|
|
44
|
+
request.catch(() => {
|
|
45
|
+
if (sessions.get(plugin) === request) sessions.delete(plugin);
|
|
46
|
+
});
|
|
23
47
|
return request;
|
|
24
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* This member's session for `plugin`, renewed 30 seconds before it ends.
|
|
51
|
+
* `refused` is a token the plugin just turned down: it is replaced once, for
|
|
52
|
+
* every call that failed with it at the same time.
|
|
53
|
+
*/
|
|
54
|
+
const sessionOf = async (plugin, refused) => {
|
|
55
|
+
const cached = sessions.get(plugin);
|
|
56
|
+
if (cached) {
|
|
57
|
+
const held = await cached.catch(() => null);
|
|
58
|
+
if (held && held.session.token !== refused && held.endsAt - Date.now() > RENEW_BEFORE_MS) return held.session;
|
|
59
|
+
const renewing = sessions.get(plugin);
|
|
60
|
+
if (renewing && renewing !== cached) return (await renewing).session;
|
|
61
|
+
}
|
|
62
|
+
return (await renew(plugin)).session;
|
|
63
|
+
};
|
|
25
64
|
const join = (base, path) => `${base.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`;
|
|
26
65
|
/**
|
|
27
66
|
* `fetch` against a plugin's API as the signed-in member. Relative paths are
|
|
28
|
-
* resolved against the plugin's API address; a 401 renews the token once
|
|
67
|
+
* resolved against the plugin's API address; a 401 renews the token once and
|
|
68
|
+
* sends the call again, so `init.body` must be one that can be sent twice
|
|
69
|
+
* (text, an ArrayBuffer, a Blob or FormData, not a stream).
|
|
29
70
|
*/
|
|
30
71
|
const pluginFetch = async (plugin, path, init = {}) => {
|
|
31
72
|
const send = async (session) => {
|
|
@@ -38,8 +79,9 @@ const pluginFetch = async (plugin, path, init = {}) => {
|
|
|
38
79
|
credentials: "omit"
|
|
39
80
|
});
|
|
40
81
|
};
|
|
41
|
-
const
|
|
42
|
-
|
|
82
|
+
const session = await sessionOf(plugin);
|
|
83
|
+
const response = await send(session);
|
|
84
|
+
return response.status === 401 ? send(await sessionOf(plugin, session.token)) : response;
|
|
43
85
|
};
|
|
44
86
|
const errorBody = z.object({ message: z.string() });
|
|
45
87
|
/**
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { ComponentType } from "react";
|
|
2
1
|
/**
|
|
3
2
|
* Core's timeline, for plugin UIs: `<RecordTimeline type="hr.employee" id={employee.id} />`
|
|
4
3
|
* shows notes, mentions, pins, reactions, logged calls and the plugin's own
|
|
5
4
|
* entries for one of its records (the type must be in the plugin's manifest
|
|
6
|
-
* `timelines`). The host app (web) registers the component
|
|
7
|
-
* Module Federation singleton, so every plugin gets the host's.
|
|
5
|
+
* `timelines`). The host app (web) registers the component.
|
|
8
6
|
*/
|
|
9
7
|
export type RecordTimelineProps = {
|
|
10
8
|
type: string;
|
|
11
9
|
id: string;
|
|
12
10
|
};
|
|
13
|
-
export declare const setRecordTimeline: (component: ComponentType<RecordTimelineProps> | null) => void;
|
|
11
|
+
export declare const setRecordTimeline: (component: import("react").ComponentType<RecordTimelineProps> | null) => void;
|
|
14
12
|
export declare const RecordTimeline: (props: RecordTimelineProps) => import("react").JSX.Element | null;
|
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useSyncExternalStore } from "react";
|
|
1
|
+
import { hostComponent } from "./host-component.js";
|
|
3
2
|
// src/utils/record-timeline.tsx
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
registered = component;
|
|
8
|
-
listeners.forEach((listener) => listener());
|
|
9
|
-
};
|
|
10
|
-
const subscribe = (listener) => {
|
|
11
|
-
listeners.add(listener);
|
|
12
|
-
return () => listeners.delete(listener);
|
|
13
|
-
};
|
|
14
|
-
const RecordTimeline = (props) => {
|
|
15
|
-
const Component = useSyncExternalStore(subscribe, () => registered, () => registered);
|
|
16
|
-
if (!Component) return null;
|
|
17
|
-
return /* @__PURE__ */ jsx(Component, { ...props });
|
|
18
|
-
};
|
|
3
|
+
const timeline = hostComponent();
|
|
4
|
+
const setRecordTimeline = timeline.set;
|
|
5
|
+
const RecordTimeline = timeline.Host;
|
|
19
6
|
export { RecordTimeline, setRecordTimeline };
|