@erxes/ui 4.0.0-v2.6 → 4.0.0-v2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -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 +17 -3
- package/dist/index.js +15 -2
- package/dist/modules/list/DisplayMenu.d.ts +20 -0
- package/dist/modules/list/DisplayMenu.js +86 -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-list/RecordList.d.ts +12 -0
- package/dist/modules/record-list/RecordList.js +17 -0
- package/dist/modules/record-list/RecordListProvider.d.ts +30 -0
- package/dist/modules/record-list/RecordListProvider.js +57 -0
- package/dist/modules/record-list/RecordListRoot.d.ts +28 -0
- package/dist/modules/record-list/RecordListRoot.js +124 -0
- package/dist/modules/record-list/selection.d.ts +22 -0
- package/dist/modules/record-list/selection.js +54 -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
|
@@ -27,12 +27,24 @@ Only what something uses:
|
|
|
27
27
|
`useLiveSignal`, `RecordTimeline`, `getPluginAssetsUrl`, `addPluginStyles` and the `IUIConfig` types,
|
|
28
28
|
- the design-system primitives in `src/components` (Accordion, Card, Slider …), even unused,
|
|
29
29
|
because plugins build on them,
|
|
30
|
+
- the record views plugins build lists from: `RecordTable` and `RecordList` (rows grouped under
|
|
31
|
+
headers that fold away, such as tasks by status; the Operation plugin is the first consumer),
|
|
30
32
|
- the pickers in `src/modules/pickers`: `EntityPicker`, and `SelectMember`, `MemberInline` and
|
|
31
33
|
`useMembersById`, which take `memberQueries` from `@erxes/core-contract/client`. They read
|
|
32
34
|
through TanStack query options, so erxes-ui imports nothing from core.
|
|
33
35
|
- core's records in `src/modules/records`: `ContactLink` (a customer or company by id, read
|
|
34
36
|
through `contactQueries` from `@erxes/core-contract/client`) and `useOpenRecord`, which open a
|
|
35
|
-
record in web's side panel through the `RecordOpenerProvider` web mounts
|
|
37
|
+
record or a draft in web's side panel through the `RecordOpenerProvider` web mounts, and
|
|
38
|
+
`RecordPage`, a record on its own page.
|
|
39
|
+
- the record panel's rows in `src/modules/record-panel`, which web's side panel and the slots
|
|
40
|
+
of a plugin's record types (`IUIConfig.recordTypes`) both fill it with: `PanelSection`,
|
|
41
|
+
`PanelField`, `PanelFormRow`, `PanelFormLayout`, `PanelLabel`, the description field and
|
|
42
|
+
editor, and `usePanelExpanded`. The panel itself (header, tabs, resize) is web's.
|
|
43
|
+
- a list's bar in `src/modules/list`: `ViewBar`, `DisplayMenu` with `useListDisplay`, and
|
|
44
|
+
`ListFilter` with `useListFilterParams`.
|
|
45
|
+
- what the host app provides at startup, rendered through `hostComponent`
|
|
46
|
+
(`src/utils/host-component.tsx`): `setRecordTimeline`, `setRecordPage` and `setListFilter`.
|
|
47
|
+
Outside erxes they render nothing.
|
|
36
48
|
|
|
37
49
|
Anything else is removed, not kept "in case". Before you remove an export, check the HR plugin
|
|
38
50
|
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";
|
|
@@ -88,16 +90,28 @@ import { MemberInline, SelectMember } from "./modules/pickers/SelectMember.js";
|
|
|
88
90
|
import { NumberField } from "./modules/record-field/components/NumberField.js";
|
|
89
91
|
import { TextField } from "./modules/record-field/components/TextField.js";
|
|
90
92
|
import { PhoneInput } from "./modules/record-field/meta-inputs/components/PhoneInput.js";
|
|
93
|
+
import { RecordList } from "./modules/record-list/RecordList.js";
|
|
94
|
+
import { RecordListGroup } from "./modules/record-list/RecordListRoot.js";
|
|
91
95
|
import { RecordTable } from "./modules/record-table/components/RecordTable.js";
|
|
92
96
|
import { RecordTableColumnDef } from "./modules/record-table/components/RecordTableProvider.js";
|
|
93
97
|
import { RecordTableInlineCell } from "./modules/record-table/components/RecordTableCellInline.js";
|
|
94
98
|
import { EnumCursorDirection } from "./modules/record-table/types/RecordTableCursorTypes.js";
|
|
99
|
+
import { DisplayMenu, TListDisplay, useListDisplay } from "./modules/list/DisplayMenu.js";
|
|
100
|
+
import { ListFilter, TListFilterField, TListFilterProps, setListFilter, useListFilterParams } from "./modules/list/ListFilter.js";
|
|
101
|
+
import { ViewBar } from "./modules/list/ViewBar.js";
|
|
102
|
+
import { PanelDescriptionEditor } from "./modules/record-panel/PanelDescriptionEditor.js";
|
|
103
|
+
import { PanelDescriptionField } from "./modules/record-panel/PanelDescriptionField.js";
|
|
104
|
+
import { PanelField, PanelFieldTrigger } from "./modules/record-panel/PanelField.js";
|
|
105
|
+
import { PanelFormLayout, PanelFormRow } from "./modules/record-panel/PanelForm.js";
|
|
106
|
+
import { PanelLabel } from "./modules/record-panel/PanelLabel.js";
|
|
107
|
+
import { PanelSection } from "./modules/record-panel/PanelSection.js";
|
|
108
|
+
import { PanelExpansionContext, usePanelExpanded } from "./modules/record-panel/panelExpansion.js";
|
|
95
109
|
import { ContactLink } from "./modules/records/ContactLink.js";
|
|
96
110
|
import { CompanyContact, ContactQueries, CustomerContact, TContactContentType, companyTitle, customerTitle } from "./modules/records/contacts.js";
|
|
97
|
-
import { RecordOpenerProvider, RecordRef, useOpenRecord } from "./modules/records/openRecord.js";
|
|
111
|
+
import { RecordOpenerProvider, RecordPage, RecordRef, setRecordPage, useOpenRecord } from "./modules/records/openRecord.js";
|
|
98
112
|
import { ThemeOption, themeState } from "./state/themeState.js";
|
|
99
113
|
import { SexCode } from "./types/SexCode.js";
|
|
100
|
-
import { IUIConfig, TActivityRowProps, TDashboardWidgetPreview, TPropertyInputMeta, TPropertyInputProps, TRecordSection, TRecordSectionProps } from "./types/UIConfig.js";
|
|
114
|
+
import { IUIConfig, TActivityRowProps, TDashboardWidgetPreview, TPanelRecordType, TPropertyInputMeta, TPropertyInputProps, TRecordContacts, TRecordDraftProps, TRecordSection, TRecordSectionProps, TRecordSlotProps, TRecordTab, TRelationTab, TRelationTabProps } from "./types/UIConfig.js";
|
|
101
115
|
import { isUndefinedOrNull } from "./utils/IsUndefinedOrNull.js";
|
|
102
116
|
import { readImage } from "./utils/core.js";
|
|
103
117
|
import { FileStorageAdapter, setFileStorage } from "./utils/file-storage.js";
|
|
@@ -107,4 +121,4 @@ import { jsonOf } from "./utils/json.js";
|
|
|
107
121
|
import { PluginLiveMessage, PluginRuntime, PluginSession, getPluginRuntime, pluginFetch, pluginJson, setPluginRuntime, useLiveSignal } from "./utils/plugin-runtime.js";
|
|
108
122
|
import { addPluginStyles } from "./utils/plugin-styles.js";
|
|
109
123
|
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 };
|
|
124
|
+
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, RecordList, type RecordListGroup, 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";
|
|
@@ -86,12 +88,23 @@ import { MemberInline, SelectMember } from "./modules/pickers/SelectMember.js";
|
|
|
86
88
|
import { NumberField } from "./modules/record-field/components/NumberField.js";
|
|
87
89
|
import { TextField } from "./modules/record-field/components/TextField.js";
|
|
88
90
|
import { PhoneInput } from "./modules/record-field/meta-inputs/components/PhoneInput.js";
|
|
91
|
+
import { RecordList } from "./modules/record-list/RecordList.js";
|
|
89
92
|
import { RecordTable } from "./modules/record-table/components/RecordTable.js";
|
|
90
93
|
import { RecordTableInlineCell } from "./modules/record-table/components/RecordTableCellInline.js";
|
|
91
94
|
import { EnumCursorDirection } from "./modules/record-table/types/RecordTableCursorTypes.js";
|
|
95
|
+
import { DisplayMenu, useListDisplay } from "./modules/list/DisplayMenu.js";
|
|
96
|
+
import { ListFilter, setListFilter, useListFilterParams } from "./modules/list/ListFilter.js";
|
|
97
|
+
import { ViewBar } from "./modules/list/ViewBar.js";
|
|
98
|
+
import { PanelDescriptionEditor } from "./modules/record-panel/PanelDescriptionEditor.js";
|
|
99
|
+
import { PanelDescriptionField } from "./modules/record-panel/PanelDescriptionField.js";
|
|
100
|
+
import { PanelField, PanelFieldTrigger } from "./modules/record-panel/PanelField.js";
|
|
101
|
+
import { PanelFormLayout, PanelFormRow } from "./modules/record-panel/PanelForm.js";
|
|
102
|
+
import { PanelLabel } from "./modules/record-panel/PanelLabel.js";
|
|
103
|
+
import { PanelSection } from "./modules/record-panel/PanelSection.js";
|
|
104
|
+
import { PanelExpansionContext, usePanelExpanded } from "./modules/record-panel/panelExpansion.js";
|
|
92
105
|
import { ContactLink } from "./modules/records/ContactLink.js";
|
|
93
106
|
import { companyTitle, customerTitle } from "./modules/records/contacts.js";
|
|
94
|
-
import { RecordOpenerProvider, useOpenRecord } from "./modules/records/openRecord.js";
|
|
107
|
+
import { RecordOpenerProvider, RecordPage, setRecordPage, useOpenRecord } from "./modules/records/openRecord.js";
|
|
95
108
|
import { ThemeOption, themeState } from "./state/themeState.js";
|
|
96
109
|
import { SexCode } from "./types/SexCode.js";
|
|
97
110
|
import { isUndefinedOrNull } from "./utils/IsUndefinedOrNull.js";
|
|
@@ -103,4 +116,4 @@ import { jsonOf } from "./utils/json.js";
|
|
|
103
116
|
import { getPluginRuntime, pluginFetch, pluginJson, setPluginRuntime, useLiveSignal } from "./utils/plugin-runtime.js";
|
|
104
117
|
import { addPluginStyles } from "./utils/plugin-styles.js";
|
|
105
118
|
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 };
|
|
119
|
+
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, RecordList, 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,20 @@
|
|
|
1
|
+
declare const LIST_DISPLAYS: readonly ['list', 'table', 'board'];
|
|
2
|
+
/** How a list shows its records: grouped rows (`RecordList`), a table, or cards on a board. */
|
|
3
|
+
export type TListDisplay = (typeof LIST_DISPLAYS)[number];
|
|
4
|
+
/** The displays a list offers, in the menu's order; the first shows until one is chosen. */
|
|
5
|
+
type ListDisplays = readonly [TListDisplay, ...TListDisplay[]];
|
|
6
|
+
/**
|
|
7
|
+
* `const [display] = useListDisplay('sales-deals')`: the display a list shows, chosen under its
|
|
8
|
+
* Display menu and remembered in this browser, one choice per list. Give it the same `displays`
|
|
9
|
+
* as the list's `DisplayMenu`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const useListDisplay: (list: string, displays?: ListDisplays) => readonly ["board" | "list" | "table", (args_0: "board" | "list" | "table" | typeof import("jotai/utils").RESET | ((prev: "board" | "list" | "table" | null) => "board" | "list" | "table" | typeof import("jotai/utils").RESET | null) | null) => void];
|
|
12
|
+
/**
|
|
13
|
+
* "Display" in a list's filter bar: table or board, or the `displays` the list offers, such as
|
|
14
|
+
* `['list', 'board', 'table']` (`useListDisplay(list, displays)` reads the choice).
|
|
15
|
+
*/
|
|
16
|
+
export declare const DisplayMenu: ({ list, displays }: {
|
|
17
|
+
list: string;
|
|
18
|
+
displays?: ListDisplays;
|
|
19
|
+
}) => import("react").JSX.Element;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
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, IconList, 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 LIST_DISPLAYS = [
|
|
13
|
+
"list",
|
|
14
|
+
"table",
|
|
15
|
+
"board"
|
|
16
|
+
];
|
|
17
|
+
const TABLE_AND_BOARD = ["table", "board"];
|
|
18
|
+
/** Null until the member picks one. */
|
|
19
|
+
const listDisplayFamily = storedFamily({
|
|
20
|
+
key: "erxes:list-display",
|
|
21
|
+
schema: z.enum(LIST_DISPLAYS).nullable(),
|
|
22
|
+
initial: null
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* `const [display] = useListDisplay('sales-deals')`: the display a list shows, chosen under its
|
|
26
|
+
* Display menu and remembered in this browser, one choice per list. Give it the same `displays`
|
|
27
|
+
* as the list's `DisplayMenu`.
|
|
28
|
+
*/
|
|
29
|
+
const useListDisplay = (list, displays = TABLE_AND_BOARD) => {
|
|
30
|
+
const [chosen, setDisplay] = useAtom(listDisplayFamily(list));
|
|
31
|
+
return [chosen && displays.includes(chosen) ? chosen : displays[0], setDisplay];
|
|
32
|
+
};
|
|
33
|
+
const DISPLAYS = {
|
|
34
|
+
list: {
|
|
35
|
+
fallback: "List",
|
|
36
|
+
icon: IconList
|
|
37
|
+
},
|
|
38
|
+
table: {
|
|
39
|
+
fallback: "Table",
|
|
40
|
+
icon: IconTable
|
|
41
|
+
},
|
|
42
|
+
board: {
|
|
43
|
+
fallback: "Board",
|
|
44
|
+
icon: IconLayoutKanban
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* "Display" in a list's filter bar: table or board, or the `displays` the list offers, such as
|
|
49
|
+
* `['list', 'board', 'table']` (`useListDisplay(list, displays)` reads the choice).
|
|
50
|
+
*/
|
|
51
|
+
const DisplayMenu = ({ list, displays = TABLE_AND_BOARD }) => {
|
|
52
|
+
const [current, setDisplay] = useListDisplay(list, displays);
|
|
53
|
+
const { t } = useTranslation("views", { keyPrefix: "display" });
|
|
54
|
+
return /* @__PURE__ */ jsxs(Popover, { children: [/* @__PURE__ */ jsx(IconTip, {
|
|
55
|
+
label: t("label", "Display"),
|
|
56
|
+
children: /* @__PURE__ */ jsx(Popover.Trigger, {
|
|
57
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
58
|
+
variant: "ghost",
|
|
59
|
+
size: "icon",
|
|
60
|
+
"aria-label": t("label", "Display"),
|
|
61
|
+
tone: "muted"
|
|
62
|
+
}),
|
|
63
|
+
children: /* @__PURE__ */ jsx(IconAdjustmentsHorizontal, { className: "size-4" })
|
|
64
|
+
})
|
|
65
|
+
}), /* @__PURE__ */ jsxs(Popover.Content, {
|
|
66
|
+
align: "end",
|
|
67
|
+
className: "w-64",
|
|
68
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
69
|
+
className: "mb-2 text-xs font-medium text-muted-foreground",
|
|
70
|
+
children: t("view", "View")
|
|
71
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
72
|
+
className: cn("grid gap-2", displays.length > 2 ? "grid-cols-3" : "grid-cols-2"),
|
|
73
|
+
children: displays.map((value) => {
|
|
74
|
+
const { fallback, icon: Icon } = DISPLAYS[value];
|
|
75
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
76
|
+
type: "button",
|
|
77
|
+
"aria-pressed": current === value,
|
|
78
|
+
onClick: () => setDisplay(value),
|
|
79
|
+
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"),
|
|
80
|
+
children: [/* @__PURE__ */ jsx(Icon, { className: "size-5" }), t(value, fallback)]
|
|
81
|
+
}, value);
|
|
82
|
+
})
|
|
83
|
+
})]
|
|
84
|
+
})] });
|
|
85
|
+
};
|
|
86
|
+
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,12 @@
|
|
|
1
|
+
import { RecordListProvider, useRecordListSelection } from "./RecordListProvider.js";
|
|
2
|
+
import { RecordListRoot } from "./RecordListRoot.js";
|
|
3
|
+
/** Stands in for the rows while they load. */
|
|
4
|
+
declare const RecordListSkeleton: ({ rows }: {
|
|
5
|
+
rows?: number;
|
|
6
|
+
}) => import("react").JSX.Element;
|
|
7
|
+
export declare const RecordList: typeof RecordListRoot & {
|
|
8
|
+
Provider: typeof RecordListProvider;
|
|
9
|
+
Skeleton: typeof RecordListSkeleton;
|
|
10
|
+
useSelection: typeof useRecordListSelection;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Skeleton } from "../../components/skeleton.js";
|
|
2
|
+
import { RecordListProvider, useRecordListSelection } from "./RecordListProvider.js";
|
|
3
|
+
import { RecordListRoot } from "./RecordListRoot.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/modules/record-list/RecordList.tsx
|
|
6
|
+
/** Stands in for the rows while they load. */
|
|
7
|
+
const RecordListSkeleton = ({ rows = 8 }) => /* @__PURE__ */ jsx("div", {
|
|
8
|
+
className: "flex flex-col gap-2 p-3",
|
|
9
|
+
"aria-busy": true,
|
|
10
|
+
children: Array.from({ length: rows }, (_, index) => /* @__PURE__ */ jsx(Skeleton, { className: "h-8" }, `row-${String(index)}`))
|
|
11
|
+
});
|
|
12
|
+
const RecordList = Object.assign(RecordListRoot, {
|
|
13
|
+
Provider: RecordListProvider,
|
|
14
|
+
Skeleton: RecordListSkeleton,
|
|
15
|
+
useSelection: useRecordListSelection
|
|
16
|
+
});
|
|
17
|
+
export { RecordList };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Selection } from "./selection.js";
|
|
2
|
+
import { PropsWithChildren } from "react";
|
|
3
|
+
/** The groups folded away, per list, kept in this browser. */
|
|
4
|
+
export declare const collapsedGroups: import("jotai-family").AtomFamily<string, import("jotai").WritableAtom<string[], [typeof import("jotai/utils").RESET | string[] | ((prev: string[]) => typeof import("jotai/utils").RESET | string[])], void>>;
|
|
5
|
+
interface RecordListContextValue {
|
|
6
|
+
listId: string;
|
|
7
|
+
selection: Selection;
|
|
8
|
+
}
|
|
9
|
+
export declare const useRecordListContext: () => RecordListContextValue;
|
|
10
|
+
/** Renders again only when `read` of the selection changes, such as one row's own state. */
|
|
11
|
+
export declare const useSelectionState: <T>(read: (picked: ReadonlySet<string>) => T) => T;
|
|
12
|
+
/**
|
|
13
|
+
* The selection a record list and its command bar share. Rows that leave the list stay
|
|
14
|
+
* picked until `clear`, so read the selection through the rows the page shows.
|
|
15
|
+
*/
|
|
16
|
+
export declare const useRecordListSelection: () => {
|
|
17
|
+
ids: string[];
|
|
18
|
+
has: (id: string) => boolean;
|
|
19
|
+
toggle: (id: string) => void;
|
|
20
|
+
toggleAll: (ids: readonly string[]) => void;
|
|
21
|
+
clear: () => void;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* `listId` names the list in this browser, where its folded groups are kept. Another
|
|
25
|
+
* `listId` is another list: its selection starts empty.
|
|
26
|
+
*/
|
|
27
|
+
export declare const RecordListProvider: ({ listId, children }: PropsWithChildren<{
|
|
28
|
+
listId: string;
|
|
29
|
+
}>) => import("react").JSX.Element;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { storedFamily } from "../../lib/stored.js";
|
|
2
|
+
import { createSelection } from "./selection.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { createContext, useContext, useState, useSyncExternalStore } from "react";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
// src/modules/record-list/RecordListProvider.tsx
|
|
7
|
+
/** The groups folded away, per list, kept in this browser. */
|
|
8
|
+
const collapsedGroups = storedFamily({
|
|
9
|
+
key: "erxes:record-list:collapsed",
|
|
10
|
+
schema: z.array(z.string().max(200)).max(500),
|
|
11
|
+
initial: []
|
|
12
|
+
});
|
|
13
|
+
const RecordListContext = createContext(null);
|
|
14
|
+
const useRecordListContext = () => {
|
|
15
|
+
const context = useContext(RecordListContext);
|
|
16
|
+
if (!context) throw new Error("A record list must be used within RecordList.Provider.");
|
|
17
|
+
return context;
|
|
18
|
+
};
|
|
19
|
+
/** Renders again only when `read` of the selection changes, such as one row's own state. */
|
|
20
|
+
const useSelectionState = (read) => {
|
|
21
|
+
const { selection } = useRecordListContext();
|
|
22
|
+
return useSyncExternalStore(selection.subscribe, () => read(selection.picked()));
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The selection a record list and its command bar share. Rows that leave the list stay
|
|
26
|
+
* picked until `clear`, so read the selection through the rows the page shows.
|
|
27
|
+
*/
|
|
28
|
+
const useRecordListSelection = () => {
|
|
29
|
+
const { selection } = useRecordListContext();
|
|
30
|
+
const picked = useSelectionState((current) => current);
|
|
31
|
+
return {
|
|
32
|
+
ids: [...picked],
|
|
33
|
+
has: (id) => picked.has(id),
|
|
34
|
+
toggle: (id) => selection.toggle(id),
|
|
35
|
+
toggleAll: selection.toggleAll,
|
|
36
|
+
clear: selection.clear
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const SelectionScope = ({ listId, children }) => {
|
|
40
|
+
const [context] = useState(() => ({
|
|
41
|
+
listId,
|
|
42
|
+
selection: createSelection()
|
|
43
|
+
}));
|
|
44
|
+
return /* @__PURE__ */ jsx(RecordListContext.Provider, {
|
|
45
|
+
value: context,
|
|
46
|
+
children
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* `listId` names the list in this browser, where its folded groups are kept. Another
|
|
51
|
+
* `listId` is another list: its selection starts empty.
|
|
52
|
+
*/
|
|
53
|
+
const RecordListProvider = ({ listId, children }) => /* @__PURE__ */ jsx(SelectionScope, {
|
|
54
|
+
listId,
|
|
55
|
+
children
|
|
56
|
+
}, listId);
|
|
57
|
+
export { RecordListProvider, collapsedGroups, useRecordListContext, useRecordListSelection, useSelectionState };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
/** A run of rows under one header, such as the tasks in one status. */
|
|
3
|
+
export interface RecordListGroup<TRow> {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
rows: TRow[];
|
|
8
|
+
/** The header's controls on the right, such as a "+" that adds a row to this group. */
|
|
9
|
+
action?: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
interface RecordListProps<TRow> {
|
|
12
|
+
groups: RecordListGroup<TRow>[];
|
|
13
|
+
rowId: (row: TRow) => string;
|
|
14
|
+
/** The row's name, for its checkbox's label. */
|
|
15
|
+
rowLabel: (row: TRow) => string;
|
|
16
|
+
/** The row's content, after its checkbox. */
|
|
17
|
+
renderRow: (row: TRow) => ReactNode;
|
|
18
|
+
/** False: one list with no headers, such as rows sorted by date. */
|
|
19
|
+
grouped?: boolean;
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Rows in groups, each under a sticky header that folds it away and picks all its rows; the
|
|
24
|
+
* folded groups are kept in this browser. Shift-click picks every row between two clicks, as
|
|
25
|
+
* shown. Inside `RecordList.Provider`, which holds the selection a command bar reads.
|
|
26
|
+
*/
|
|
27
|
+
export declare const RecordListRoot: <TRow>({ groups, rowId, rowLabel, renderRow, grouped, className }: RecordListProps<TRow>) => import("react").JSX.Element;
|
|
28
|
+
export {};
|