@erxes/ui 4.0.0-v2.1 → 4.0.0-v2.11
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/AGENTS.md +58 -0
- package/CATALOG.md +251 -0
- package/README.md +25 -2
- package/dist/components/accordion.d.ts +1 -0
- package/dist/components/accordion.js +1 -0
- package/dist/components/alert-dialog.d.ts +4 -0
- package/dist/components/alert-dialog.js +4 -0
- package/dist/components/alert.d.ts +1 -0
- package/dist/components/alert.js +1 -0
- package/dist/components/avatar.d.ts +2 -0
- package/dist/components/avatar.js +1 -0
- package/dist/components/background-gradient-animation.d.ts +4 -1
- package/dist/components/background-gradient-animation.js +4 -1
- package/dist/components/badge.d.ts +3 -0
- package/dist/components/badge.js +2 -0
- package/dist/components/breadcrumb.d.ts +1 -0
- package/dist/components/breadcrumb.js +1 -0
- package/dist/components/button.d.ts +6 -1
- package/dist/components/button.js +5 -1
- package/dist/components/calendar.d.ts +5 -0
- package/dist/components/calendar.js +4 -0
- package/dist/components/card.d.ts +1 -0
- package/dist/components/card.js +1 -0
- package/dist/components/chart-config.d.ts +4 -1
- package/dist/components/charts.d.ts +6 -0
- package/dist/components/charts.js +12 -3
- package/dist/components/checkbox.d.ts +1 -0
- package/dist/components/checkbox.js +1 -0
- package/dist/components/choicebox-group.d.ts +1 -0
- package/dist/components/choicebox-group.js +1 -0
- package/dist/components/collapsible.d.ts +1 -0
- package/dist/components/collapsible.js +1 -0
- package/dist/components/color-picker.d.ts +1 -0
- package/dist/components/color-picker.js +13 -6
- package/dist/components/combobox.d.ts +6 -1
- package/dist/components/combobox.js +9 -1
- package/dist/components/command-bar.d.ts +4 -0
- package/dist/components/command-bar.js +4 -0
- package/dist/components/command.d.ts +4 -0
- package/dist/components/command.js +4 -0
- package/dist/components/context-menu.d.ts +1 -0
- package/dist/components/context-menu.js +1 -0
- package/dist/components/copy-text.d.ts +1 -0
- package/dist/components/copy-text.js +1 -0
- package/dist/components/date-picker-value.d.ts +5 -9
- package/dist/components/date-picker-value.js +15 -34
- package/dist/components/date-picker.d.ts +4 -4
- package/dist/components/date-picker.js +9 -7
- package/dist/components/date-text-input.d.ts +2 -4
- package/dist/components/date-text-input.js +11 -9
- package/dist/components/dialog.d.ts +4 -0
- package/dist/components/dialog.js +5 -1
- package/dist/components/drag-handle.d.ts +1 -0
- package/dist/components/drag-handle.js +1 -0
- package/dist/components/dropdown-menu.d.ts +1 -0
- package/dist/components/dropdown-menu.js +1 -0
- package/dist/components/empty.d.ts +6 -1
- package/dist/components/empty.js +25 -2
- package/dist/components/form.d.ts +6 -2
- package/dist/components/form.js +8 -2
- package/dist/components/hover-card.d.ts +1 -0
- package/dist/components/hover-card.js +1 -0
- package/dist/components/icon-tip.d.ts +7 -0
- package/dist/components/icon-tip.js +16 -0
- package/dist/components/info-card.d.ts +4 -0
- package/dist/components/info-card.js +4 -0
- package/dist/components/input-group.d.ts +5 -4
- package/dist/components/input-group.js +5 -4
- package/dist/components/input.d.ts +1 -0
- package/dist/components/input.js +1 -0
- package/dist/components/kbd.d.ts +2 -1
- package/dist/components/kbd.js +2 -1
- package/dist/components/label.d.ts +1 -1
- package/dist/components/label.js +1 -1
- package/dist/components/multiselect.d.ts +1 -0
- package/dist/components/multiselect.js +3 -2
- package/dist/components/on-demand.d.ts +6 -0
- package/dist/components/on-demand.js +6 -0
- package/dist/components/popover.d.ts +4 -0
- package/dist/components/popover.js +4 -0
- package/dist/components/radio-group.d.ts +1 -0
- package/dist/components/radio-group.js +1 -0
- package/dist/components/scroll-area.d.ts +1 -0
- package/dist/components/scroll-area.js +1 -0
- package/dist/components/select.d.ts +5 -1
- package/dist/components/select.js +7 -1
- package/dist/components/separator.d.ts +4 -0
- package/dist/components/separator.js +4 -0
- package/dist/components/sheet.d.ts +4 -0
- package/dist/components/sheet.js +8 -4
- package/dist/components/sidebar/panel.js +29 -7
- package/dist/components/sidebar.d.ts +1 -0
- package/dist/components/sidebar.js +1 -0
- package/dist/components/skeleton.d.ts +1 -0
- package/dist/components/skeleton.js +1 -0
- package/dist/components/spinner.d.ts +1 -0
- package/dist/components/spinner.js +1 -0
- package/dist/components/string-array.js +1 -0
- package/dist/components/switch.d.ts +1 -0
- package/dist/components/switch.js +1 -0
- package/dist/components/table.d.ts +4 -0
- package/dist/components/table.js +4 -0
- package/dist/components/tabs.d.ts +8 -1
- package/dist/components/tabs.js +8 -1
- package/dist/components/text-overflow.d.ts +4 -1
- package/dist/components/text-overflow.js +4 -1
- package/dist/components/textarea.d.ts +1 -0
- package/dist/components/textarea.js +1 -0
- package/dist/components/toaster.d.ts +4 -1
- package/dist/components/toaster.js +5 -2
- package/dist/components/toggle-group.d.ts +5 -0
- package/dist/components/toggle-group.js +19 -11
- package/dist/components/toggle.d.ts +1 -0
- package/dist/components/toggle.js +1 -0
- package/dist/components/tooltip.d.ts +4 -0
- package/dist/components/tooltip.js +4 -0
- package/dist/components/upload.d.ts +4 -0
- package/dist/components/upload.js +20 -11
- package/dist/federation.d.ts +8 -1
- package/dist/federation.js +12 -2
- package/dist/hooks/use-item-keys.d.ts +11 -0
- package/dist/hooks/use-item-keys.js +24 -0
- package/dist/hooks/use-page-hotkey.d.ts +12 -0
- package/dist/hooks/use-page-hotkey.js +22 -0
- package/dist/hooks/use-toast.d.ts +5 -0
- package/dist/hooks/use-toast.js +5 -0
- package/dist/index.d.ts +33 -6
- package/dist/index.js +31 -4
- package/dist/lib/format.d.ts +60 -0
- package/dist/lib/format.js +86 -0
- package/dist/lib/money.d.ts +13 -0
- package/dist/lib/money.js +21 -0
- package/dist/lib/stored.d.ts +13 -0
- package/dist/lib/stored.js +41 -0
- package/dist/lib/text.d.ts +11 -0
- package/dist/lib/text.js +18 -0
- package/dist/modules/attachments/use-carousel.js +5 -10
- package/dist/modules/blocks/hooks/useBarcodeSizeForm.d.ts +1 -1
- package/dist/modules/blocks/utils/parseBlocks.d.ts +1 -1
- package/dist/modules/blocks/utils/parseBlocks.js +1 -1
- package/dist/modules/conditions/ConditionValueInput.d.ts +10 -0
- package/dist/modules/conditions/ConditionValueInput.js +166 -0
- package/dist/modules/conditions/ConditionsEditor.d.ts +11 -0
- package/dist/modules/conditions/ConditionsEditor.js +209 -0
- package/dist/modules/conditions/LazyConditionsEditor.d.ts +10 -0
- package/dist/modules/conditions/LazyConditionsEditor.js +11 -0
- package/dist/modules/conditions/PathPicker.d.ts +8 -0
- package/dist/modules/conditions/PathPicker.js +51 -0
- package/dist/modules/conditions/conditions.d.ts +66 -0
- package/dist/modules/conditions/conditions.js +136 -0
- package/dist/modules/display/components/EmailDisplay.d.ts +4 -0
- package/dist/modules/display/components/EmailDisplay.js +6 -3
- package/dist/modules/display/components/PhoneDisplay.d.ts +4 -0
- package/dist/modules/display/components/PhoneDisplay.js +4 -0
- package/dist/modules/display/components/RelativeDateDisplay.d.ts +7 -5
- package/dist/modules/display/components/RelativeDateDisplay.js +10 -8
- package/dist/modules/display/components/SexDisplay.d.ts +1 -0
- package/dist/modules/display/components/SexDisplay.js +1 -0
- package/dist/modules/filter/components/Filter.d.ts +4 -0
- package/dist/modules/filter/components/Filter.js +4 -0
- package/dist/modules/filter/components/FilterBar.js +5 -7
- package/dist/modules/filter/components/FilterDialog.js +4 -5
- package/dist/modules/filter/components/FilterPopover.js +1 -1
- package/dist/modules/filter/components/FilterProvider.d.ts +1 -2
- package/dist/modules/filter/components/FilterProvider.js +22 -16
- package/dist/modules/filter/hooks/useFilterContext.d.ts +1 -0
- package/dist/modules/filter/hooks/useFilterContext.js +1 -0
- package/dist/modules/filter/types/filter.d.ts +0 -1
- package/dist/modules/hotkey/components/PopoverScoped.d.ts +5 -0
- package/dist/modules/hotkey/components/PopoverScoped.js +5 -0
- package/dist/modules/hotkey/hooks/usePreviousHotkeyScope.d.ts +1 -0
- package/dist/modules/hotkey/hooks/usePreviousHotkeyScope.js +1 -0
- package/dist/modules/hotkey/hooks/useScopedHotkeys.d.ts +5 -1
- package/dist/modules/hotkey/hooks/useScopedHotkeys.js +5 -1
- package/dist/modules/icons/components/IconComponent.d.ts +4 -0
- package/dist/modules/icons/components/IconComponent.js +4 -0
- package/dist/modules/icons/components/IconPicker.d.ts +4 -0
- package/dist/modules/icons/components/IconPicker.js +7 -5
- package/dist/modules/icons/providers/IconsProvider.d.ts +1 -0
- package/dist/modules/icons/providers/IconsProvider.js +1 -0
- package/dist/modules/inputs/components/EmailField.d.ts +4 -1
- package/dist/modules/inputs/components/EmailField.js +4 -1
- package/dist/modules/inputs/components/FullNameField.d.ts +6 -0
- package/dist/modules/inputs/components/FullNameField.js +20 -8
- package/dist/modules/inputs/components/PhoneField.d.ts +4 -1
- package/dist/modules/inputs/components/PhoneField.js +4 -1
- package/dist/modules/inputs/components/SexField.d.ts +1 -0
- package/dist/modules/inputs/components/SexField.js +1 -0
- package/dist/modules/layout/components/AppLayout.d.ts +6 -6
- package/dist/modules/layout/components/AppLayout.js +12 -13
- package/dist/modules/layout/components/AppLayoutResizeHandle.d.ts +5 -12
- package/dist/modules/layout/components/AppLayoutResizeHandle.js +15 -18
- package/dist/modules/layout/components/Page.d.ts +5 -0
- package/dist/modules/layout/components/Page.js +5 -0
- package/dist/modules/layout/components/PageHeader.d.ts +4 -1
- package/dist/modules/layout/components/PageHeader.js +9 -3
- package/dist/modules/list/DisplayMenu.d.ts +24 -0
- package/dist/modules/list/DisplayMenu.js +87 -0
- package/dist/modules/list/ListFilter.d.ts +63 -0
- package/dist/modules/list/ListFilter.js +44 -0
- package/dist/modules/list/ViewBar.d.ts +13 -0
- package/dist/modules/list/ViewBar.js +30 -0
- package/dist/modules/list/filter/AdvancedFilterDialog.d.ts +5 -0
- package/dist/modules/list/filter/AdvancedFilterDialog.js +52 -0
- package/dist/modules/list/filter/FieldMenus.d.ts +5 -0
- package/dist/modules/list/filter/FieldMenus.js +184 -0
- package/dist/modules/list/filter/ListFilterBar.d.ts +6 -0
- package/dist/modules/list/filter/ListFilterBar.js +246 -0
- package/dist/modules/list/filter/RecordCount.d.ts +7 -0
- package/dist/modules/list/filter/RecordCount.js +22 -0
- package/dist/modules/list/filter/RuleChips.d.ts +2 -0
- package/dist/modules/list/filter/RuleChips.js +157 -0
- package/dist/modules/list/filter/fieldIcons.d.ts +7 -0
- package/dist/modules/list/filter/fieldIcons.js +16 -0
- package/dist/modules/list/filter/filterRules.d.ts +46 -0
- package/dist/modules/list/filter/filterRules.js +166 -0
- package/dist/modules/list/filter/listFilterContext.d.ts +29 -0
- package/dist/modules/list/filter/listFilterContext.js +34 -0
- package/dist/modules/list/filter/listFilterQuery.d.ts +16 -0
- package/dist/modules/list/filter/listFilterQuery.js +22 -0
- package/dist/modules/navigation-menu/components/NavigationMenu.d.ts +4 -3
- package/dist/modules/navigation-menu/components/NavigationMenu.js +7 -7
- package/dist/modules/pickers/EntityPicker.d.ts +37 -0
- package/dist/modules/pickers/EntityPicker.js +67 -0
- package/dist/modules/pickers/LookupPicker.d.ts +51 -0
- package/dist/modules/pickers/LookupPicker.js +84 -0
- package/dist/modules/pickers/SelectMember.d.ts +41 -0
- package/dist/modules/pickers/SelectMember.js +122 -0
- package/dist/modules/pickers/members.d.ts +30 -0
- package/dist/modules/pickers/members.js +18 -0
- package/dist/modules/record-field/components/NumberField.d.ts +5 -0
- package/dist/modules/record-field/components/NumberField.js +14 -7
- package/dist/modules/record-field/components/TextField.d.ts +4 -0
- package/dist/modules/record-field/components/TextField.js +14 -3
- package/dist/modules/record-field/meta-inputs/components/PhoneInput.d.ts +5 -0
- package/dist/modules/record-field/meta-inputs/components/PhoneInput.js +5 -0
- package/dist/modules/record-list/RecordList.d.ts +18 -0
- package/dist/modules/record-list/RecordList.js +23 -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 +13 -0
- package/dist/modules/record-panel/PanelDescriptionField.js +39 -0
- package/dist/modules/record-panel/PanelField.d.ts +17 -0
- package/dist/modules/record-panel/PanelField.js +47 -0
- package/dist/modules/record-panel/PanelForm.d.ts +28 -0
- package/dist/modules/record-panel/PanelForm.js +88 -0
- package/dist/modules/record-panel/PanelLabel.d.ts +10 -0
- package/dist/modules/record-panel/PanelLabel.js +55 -0
- package/dist/modules/record-panel/PanelSection.d.ts +12 -0
- package/dist/modules/record-panel/PanelSection.js +24 -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/record-table/components/RecordTable.d.ts +6 -0
- package/dist/modules/record-table/components/RecordTable.js +6 -0
- package/dist/modules/record-table/components/RecordTableCell.d.ts +9 -0
- package/dist/modules/record-table/components/RecordTableCell.js +16 -2
- package/dist/modules/record-table/components/RecordTableCellInline.d.ts +5 -0
- package/dist/modules/record-table/components/RecordTableCellInline.js +8 -7
- package/dist/modules/record-table/components/RecordTableCursor.js +30 -28
- package/dist/modules/record-table/components/RecordTableProvider.js +12 -7
- package/dist/modules/record-table/hooks/useTablePreferences.d.ts +1 -1
- package/dist/modules/record-table/hooks/useTablePreferences.js +18 -31
- package/dist/modules/record-table/states/RecordTableCursorState.d.ts +21 -1
- package/dist/modules/record-table/states/RecordTableCursorState.js +21 -3
- package/dist/modules/record-table/types/RecordTableCursorTypes.d.ts +1 -0
- package/dist/modules/record-table/types/RecordTableCursorTypes.js +1 -0
- package/dist/modules/records/ContactLink.d.ts +13 -0
- package/dist/modules/records/ContactLink.js +77 -0
- package/dist/modules/records/contacts.d.ts +35 -0
- package/dist/modules/records/contacts.js +10 -0
- package/dist/modules/records/openRecord.d.ts +44 -0
- package/dist/modules/records/openRecord.js +48 -0
- package/dist/state/sidebarPanelState.d.ts +5 -1
- package/dist/state/sidebarPanelState.js +11 -3
- package/dist/state/themeState.d.ts +13 -2
- package/dist/state/themeState.js +18 -4
- package/dist/theme.css +5 -2
- package/dist/types/SexCode.d.ts +1 -0
- package/dist/types/SexCode.js +1 -0
- package/dist/types/UIConfig.d.ts +131 -3
- package/dist/utils/IsUndefinedOrNull.d.ts +1 -0
- package/dist/utils/IsUndefinedOrNull.js +1 -0
- package/dist/utils/file-storage.d.ts +1 -0
- package/dist/utils/file-storage.js +1 -0
- package/dist/utils/format/formatPhoneNumber.d.ts +4 -0
- package/dist/utils/format/formatPhoneNumber.js +4 -0
- package/dist/utils/getPluginAssetsUrl.d.ts +5 -0
- package/dist/utils/getPluginAssetsUrl.js +5 -0
- package/dist/utils/host-component.d.ts +10 -0
- package/dist/utils/host-component.js +34 -0
- package/dist/utils/json.d.ts +3 -2
- package/dist/utils/json.js +3 -2
- package/dist/utils/plugin-runtime.d.ts +21 -17
- package/dist/utils/plugin-runtime.js +59 -12
- package/dist/utils/plugin-styles.d.ts +7 -0
- package/dist/utils/plugin-styles.js +54 -0
- package/dist/utils/record-timeline.d.ts +10 -9
- package/dist/utils/record-timeline.js +12 -17
- package/exports.txt +226 -0
- package/package.json +13 -3
- package/dist/constants/IntlLanguages.d.ts +0 -74
- package/dist/constants/IntlLanguages.js +0 -76
- package/dist/hooks/use-query-state.d.ts +0 -16
- package/dist/hooks/use-query-state.js +0 -122
- package/dist/modules/filter/hooks/useFilterQueryState.d.ts +0 -4
- package/dist/modules/filter/hooks/useFilterQueryState.js +0 -14
- package/dist/types/Theme.d.ts +0 -1
- package/dist/types/Theme.js +0 -0
- package/dist/utils/localization/formatDateISOStringToRelativeDate.d.ts +0 -2
- package/dist/utils/localization/formatDateISOStringToRelativeDate.js +0 -16
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Avatar } from "../../components/avatar.js";
|
|
2
|
+
import { Badge } from "../../components/badge.js";
|
|
3
|
+
import { Combobox } from "../../components/combobox.js";
|
|
4
|
+
import { Popover } from "../../components/popover.js";
|
|
5
|
+
import { cn } from "../../lib/utils.js";
|
|
6
|
+
import { readImage } from "../../utils/core.js";
|
|
7
|
+
import { PopoverScoped } from "../hotkey/components/PopoverScoped.js";
|
|
8
|
+
import { RecordTableInlineCell } from "../record-table/components/RecordTableCellInline.js";
|
|
9
|
+
import { EntityPicker } from "./EntityPicker.js";
|
|
10
|
+
import { memberName, useMembersById } from "./members.js";
|
|
11
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { useState } from "react";
|
|
13
|
+
import { useQuery } from "@tanstack/react-query";
|
|
14
|
+
// src/modules/pickers/SelectMember.tsx
|
|
15
|
+
/** A member's name, with an "Inactive" badge for disabled ones. */
|
|
16
|
+
const MemberLabel = ({ member }) => member.status === "active" ? /* @__PURE__ */ jsx(Fragment, { children: memberName(member) }) : /* @__PURE__ */ jsxs("span", {
|
|
17
|
+
className: "inline-flex items-center gap-1",
|
|
18
|
+
children: [/* @__PURE__ */ jsx("span", { children: memberName(member) }), /* @__PURE__ */ jsx(Badge, {
|
|
19
|
+
variant: "destructive",
|
|
20
|
+
size: "sm",
|
|
21
|
+
className: "h-5 shrink-0",
|
|
22
|
+
children: "Inactive"
|
|
23
|
+
})]
|
|
24
|
+
});
|
|
25
|
+
/** A member's avatar and name by id, or a placeholder without one. */
|
|
26
|
+
const MemberInline = ({ memberId, members, placeholder, size = "lg", className }) => {
|
|
27
|
+
const member = useMembersById([memberId], members).get(memberId ?? "");
|
|
28
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [member && /* @__PURE__ */ jsxs(Avatar, {
|
|
29
|
+
size,
|
|
30
|
+
children: [/* @__PURE__ */ jsx(Avatar.Image, { src: readImage(member.avatarUrl) }), /* @__PURE__ */ jsx(Avatar.Fallback, { children: memberName(member).charAt(0) })]
|
|
31
|
+
}), /* @__PURE__ */ jsx(Combobox.Value, {
|
|
32
|
+
value: member && /* @__PURE__ */ jsx(MemberLabel, { member }),
|
|
33
|
+
loading: Boolean(memberId) && !member,
|
|
34
|
+
placeholder: placeholder ?? "Select a member",
|
|
35
|
+
className
|
|
36
|
+
})] });
|
|
37
|
+
};
|
|
38
|
+
/** Active members, searched on their name and email; picking one reports its id. */
|
|
39
|
+
const MemberList = ({ value, members, noneLabel, onPick }) => {
|
|
40
|
+
const team = useQuery(members.team);
|
|
41
|
+
return /* @__PURE__ */ jsx(EntityPicker, {
|
|
42
|
+
items: team.data?.data ?? [],
|
|
43
|
+
itemKey: (member) => ({
|
|
44
|
+
id: member.id,
|
|
45
|
+
label: `${memberName(member)} ${member.email}`
|
|
46
|
+
}),
|
|
47
|
+
renderItem: (member) => /* @__PURE__ */ jsx(MemberInline, {
|
|
48
|
+
memberId: member.id,
|
|
49
|
+
members,
|
|
50
|
+
placeholder: "Unnamed user"
|
|
51
|
+
}),
|
|
52
|
+
value: value ? [value] : [],
|
|
53
|
+
onValueChange: ([id]) => onPick(id ?? null),
|
|
54
|
+
noneLabel,
|
|
55
|
+
loading: team.isPending,
|
|
56
|
+
error: team.error
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
/** The member as a record table cell; click to pick another. */
|
|
60
|
+
const SelectMemberInlineCell = ({ ref, value, onValueChange, members, noneLabel, scope, placeholder, size = "lg", className, variant, id, "aria-label": ariaLabel }) => {
|
|
61
|
+
const [open, setOpen] = useState(false);
|
|
62
|
+
return /* @__PURE__ */ jsxs(PopoverScoped, {
|
|
63
|
+
scope,
|
|
64
|
+
open,
|
|
65
|
+
onOpenChange: setOpen,
|
|
66
|
+
children: [/* @__PURE__ */ jsx(RecordTableInlineCell.Trigger, {
|
|
67
|
+
ref,
|
|
68
|
+
id,
|
|
69
|
+
"aria-label": ariaLabel,
|
|
70
|
+
variant,
|
|
71
|
+
className,
|
|
72
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
73
|
+
className: "contents text-xs",
|
|
74
|
+
children: /* @__PURE__ */ jsx(MemberInline, {
|
|
75
|
+
memberId: value,
|
|
76
|
+
members,
|
|
77
|
+
placeholder: placeholder ?? "",
|
|
78
|
+
size
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
}), /* @__PURE__ */ jsx(RecordTableInlineCell.Content, { children: /* @__PURE__ */ jsx(MemberList, {
|
|
82
|
+
value,
|
|
83
|
+
members,
|
|
84
|
+
noneLabel,
|
|
85
|
+
onPick: (next) => {
|
|
86
|
+
onValueChange(next);
|
|
87
|
+
setOpen(false);
|
|
88
|
+
}
|
|
89
|
+
}) })]
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
/** A member picker button; its other props (an id, `Form.Control`'s aria wiring) go to the button. */
|
|
93
|
+
const SelectMemberField = ({ value, onValueChange, members, noneLabel, placeholder, className, ...trigger }) => {
|
|
94
|
+
const [open, setOpen] = useState(false);
|
|
95
|
+
return /* @__PURE__ */ jsxs(Popover, {
|
|
96
|
+
open,
|
|
97
|
+
onOpenChange: setOpen,
|
|
98
|
+
children: [/* @__PURE__ */ jsx(Combobox.Trigger, {
|
|
99
|
+
...trigger,
|
|
100
|
+
className: cn("w-full", className),
|
|
101
|
+
children: /* @__PURE__ */ jsx(MemberInline, {
|
|
102
|
+
memberId: value,
|
|
103
|
+
members,
|
|
104
|
+
placeholder
|
|
105
|
+
})
|
|
106
|
+
}), /* @__PURE__ */ jsx(Combobox.Content, { children: /* @__PURE__ */ jsx(MemberList, {
|
|
107
|
+
value,
|
|
108
|
+
members,
|
|
109
|
+
noneLabel,
|
|
110
|
+
onPick: (next) => {
|
|
111
|
+
onValueChange(next);
|
|
112
|
+
setOpen(false);
|
|
113
|
+
}
|
|
114
|
+
}) })]
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
/** The member picker as a table cell and as a field. */
|
|
118
|
+
const SelectMember = {
|
|
119
|
+
InlineCell: SelectMemberInlineCell,
|
|
120
|
+
Field: SelectMemberField
|
|
121
|
+
};
|
|
122
|
+
export { MemberInline, SelectMember };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { UseQueryOptions } from "@tanstack/react-query";
|
|
2
|
+
/** A team member as the pickers show one. Core's `User` has these fields and more. */
|
|
3
|
+
export interface Member {
|
|
4
|
+
id: string;
|
|
5
|
+
email: string;
|
|
6
|
+
fullName: string | null;
|
|
7
|
+
username: string | null;
|
|
8
|
+
avatarUrl: string | null;
|
|
9
|
+
status: string;
|
|
10
|
+
}
|
|
11
|
+
type MemberQuery = UseQueryOptions<{
|
|
12
|
+
data: Member[];
|
|
13
|
+
}, Error, {
|
|
14
|
+
data: Member[];
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Where members come from, as TanStack query options. erxes-ui knows nothing of core: web and
|
|
18
|
+
* plugin UIs pass `memberQueries` from `@erxes/core-contract/client`.
|
|
19
|
+
*/
|
|
20
|
+
export interface MemberQueries {
|
|
21
|
+
/** The active team: every picker's list, and the names most screens show. */
|
|
22
|
+
team: MemberQuery;
|
|
23
|
+
/** Members by id, for those outside the active team (disabled ones). */
|
|
24
|
+
byIds: (ids: string[]) => MemberQuery;
|
|
25
|
+
}
|
|
26
|
+
/** How a member reads: the display name, else the username, else the email. */
|
|
27
|
+
export declare const memberName: (member: Pick<Member, 'fullName' | 'username' | 'email'>) => string;
|
|
28
|
+
/** Members by id, any status. The active team answers most; only the rest are fetched. */
|
|
29
|
+
export declare const useMembersById: (ids: (string | null | undefined)[], members: MemberQueries) => Map<string, Member>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { keepPreviousData, useQuery } from "@tanstack/react-query";
|
|
3
|
+
// src/modules/pickers/members.ts
|
|
4
|
+
/** How a member reads: the display name, else the username, else the email. */
|
|
5
|
+
const memberName = (member) => member.fullName || member.username || member.email;
|
|
6
|
+
/** Members by id, any status. The active team answers most; only the rest are fetched. */
|
|
7
|
+
const useMembersById = (ids, members) => {
|
|
8
|
+
const team = useQuery(members.team);
|
|
9
|
+
const known = useMemo(() => new Set((team.data?.data ?? []).map((user) => user.id)), [team.data]);
|
|
10
|
+
const wanted = useMemo(() => [...new Set(ids.filter((id) => Boolean(id) && !known.has(id ?? "")))].toSorted((a, b) => a.localeCompare(b)), [ids, known]);
|
|
11
|
+
const others = useQuery({
|
|
12
|
+
...members.byIds(wanted),
|
|
13
|
+
enabled: team.isFetched && wanted.length > 0,
|
|
14
|
+
placeholderData: keepPreviousData
|
|
15
|
+
});
|
|
16
|
+
return useMemo(() => new Map([...team.data?.data ?? [], ...others.data?.data ?? []].map((user) => [user.id, user])), [team.data, others.data]);
|
|
17
|
+
};
|
|
18
|
+
export { memberName, useMembersById };
|
|
@@ -8,5 +8,10 @@ type NumberFieldProps = React.ComponentProps<typeof RecordTableInlineCell.Trigge
|
|
|
8
8
|
onSave?: (value: number) => void;
|
|
9
9
|
formatValue?: (value: number) => string;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* A number in a table cell or panel row that edits in a popover.
|
|
13
|
+
* Enter, or closing it after typing, calls `onSave`; Escape drops the edit. `formatValue` shows
|
|
14
|
+
* the number another way, such as money.
|
|
15
|
+
*/
|
|
11
16
|
export declare const NumberField: ({ placeholder, value, scope, onSave, onValueChange, formatValue, children, ...props }: NumberFieldProps) => React.JSX.Element;
|
|
12
17
|
export {};
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { Input } from "../../../components/input.js";
|
|
2
|
+
import { useFormat } from "../../../lib/format.js";
|
|
2
3
|
import { TextOverflowTooltip } from "../../../components/text-overflow.js";
|
|
3
4
|
import { PopoverScoped } from "../../hotkey/components/PopoverScoped.js";
|
|
4
5
|
import { RecordTableInlineCell } from "../../record-table/components/RecordTableCellInline.js";
|
|
5
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { useState } from "react";
|
|
7
|
+
import { useRef, useState } from "react";
|
|
7
8
|
// src/modules/record-field/components/NumberField.tsx
|
|
9
|
+
/**
|
|
10
|
+
* A number in a table cell or panel row that edits in a popover.
|
|
11
|
+
* Enter, or closing it after typing, calls `onSave`; Escape drops the edit. `formatValue` shows
|
|
12
|
+
* the number another way, such as money.
|
|
13
|
+
*/
|
|
8
14
|
const NumberField = ({ placeholder, value, scope, onSave, onValueChange, formatValue, children, ...props }) => {
|
|
15
|
+
const fmt = useFormat();
|
|
9
16
|
const [isOpen, setIsOpen] = useState(false);
|
|
10
17
|
const [editingValue, setEditingValue] = useState(String(value));
|
|
11
|
-
const
|
|
12
|
-
const shown = isOpen ? editingValue : formatValue ? formatValue(value) :
|
|
18
|
+
const edited = useRef(false);
|
|
19
|
+
const shown = isOpen ? editingValue : formatValue ? formatValue(value) : fmt.number(value);
|
|
13
20
|
const resetEditing = () => {
|
|
14
21
|
setEditingValue(String(value));
|
|
15
|
-
|
|
22
|
+
edited.current = false;
|
|
16
23
|
};
|
|
17
24
|
const handleAction = (e) => {
|
|
18
25
|
e?.preventDefault();
|
|
@@ -33,7 +40,7 @@ const NumberField = ({ placeholder, value, scope, onSave, onValueChange, formatV
|
|
|
33
40
|
onOpenChange: (open) => {
|
|
34
41
|
setIsOpen(open);
|
|
35
42
|
if (open) resetEditing();
|
|
36
|
-
else if (
|
|
43
|
+
else if (edited.current) handleAction();
|
|
37
44
|
},
|
|
38
45
|
children: [/* @__PURE__ */ jsxs(RecordTableInlineCell.Trigger, {
|
|
39
46
|
...props,
|
|
@@ -42,12 +49,12 @@ const NumberField = ({ placeholder, value, scope, onSave, onValueChange, formatV
|
|
|
42
49
|
render: /* @__PURE__ */ jsx("form", { onSubmit: handleAction }),
|
|
43
50
|
children: [/* @__PURE__ */ jsx(Input, {
|
|
44
51
|
type: "text",
|
|
45
|
-
value: editingValue
|
|
52
|
+
value: editingValue,
|
|
46
53
|
onChange: (e) => {
|
|
47
54
|
const rawValue = e.target.value.replace(/,/g, "");
|
|
48
55
|
if (/^-?\d*\.?\d*$/.test(rawValue)) {
|
|
49
56
|
setEditingValue(rawValue);
|
|
50
|
-
|
|
57
|
+
edited.current = true;
|
|
51
58
|
const numValue = Number(rawValue);
|
|
52
59
|
if (!isNaN(numValue)) onValueChange?.(numValue);
|
|
53
60
|
}
|
|
@@ -8,5 +8,9 @@ type TextFieldProps = React.ComponentProps<typeof RecordTableInlineCell.Trigger>
|
|
|
8
8
|
onSave?: (value: string) => void;
|
|
9
9
|
defaultOpen?: boolean;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* A text value in a table cell or panel row that edits in a popover.
|
|
13
|
+
* Enter or leaving it saves a change through `onSave`; Escape drops it.
|
|
14
|
+
*/
|
|
11
15
|
export declare const TextField: ({ ref, placeholder, value, scope, onSave, onValueChange, defaultOpen, variant, children, ...props }: TextFieldProps) => React.JSX.Element;
|
|
12
16
|
export {};
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { Input } from "../../../components/input.js";
|
|
2
2
|
import { TextOverflowTooltip } from "../../../components/text-overflow.js";
|
|
3
3
|
import { PopoverScoped } from "../../hotkey/components/PopoverScoped.js";
|
|
4
|
+
import { CellColumnHead } from "../../record-table/components/RecordTableCell.js";
|
|
4
5
|
import { RecordTableInlineCell } from "../../record-table/components/RecordTableCellInline.js";
|
|
5
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { useState } from "react";
|
|
7
|
+
import { use, useState } from "react";
|
|
7
8
|
// src/modules/record-field/components/TextField.tsx
|
|
9
|
+
/**
|
|
10
|
+
* A text value in a table cell or panel row that edits in a popover.
|
|
11
|
+
* Enter or leaving it saves a change through `onSave`; Escape drops it.
|
|
12
|
+
*/
|
|
8
13
|
const TextField = ({ ref, placeholder, value, scope, onSave, onValueChange, defaultOpen = false, variant = "input", children, ...props }) => {
|
|
9
14
|
const [isOpen, setIsOpen] = useState(defaultOpen);
|
|
10
15
|
const [editingValue, setEditingValue] = useState(value);
|
|
16
|
+
const shown = isOpen ? editingValue : value;
|
|
17
|
+
const labelled = use(CellColumnHead) !== void 0;
|
|
11
18
|
/** Saves a changed text value and closes the inline editor. */
|
|
12
19
|
const handleAction = (e) => {
|
|
13
20
|
e?.preventDefault();
|
|
@@ -16,7 +23,7 @@ const TextField = ({ ref, placeholder, value, scope, onSave, onValueChange, defa
|
|
|
16
23
|
};
|
|
17
24
|
/** Submits on Enter; Escape is handled by the popover before dismissal. */
|
|
18
25
|
const handleKeyDown = (e) => {
|
|
19
|
-
if (e.key === "Enter") {
|
|
26
|
+
if (e.key === "Enter" && !e.nativeEvent.isComposing) {
|
|
20
27
|
e.preventDefault();
|
|
21
28
|
handleAction();
|
|
22
29
|
}
|
|
@@ -40,7 +47,11 @@ const TextField = ({ ref, placeholder, value, scope, onSave, onValueChange, defa
|
|
|
40
47
|
empty: !value,
|
|
41
48
|
...props,
|
|
42
49
|
ref,
|
|
43
|
-
children: [children, /* @__PURE__ */ jsx(TextOverflowTooltip, { value:
|
|
50
|
+
children: [children, shown ? /* @__PURE__ */ jsx(TextOverflowTooltip, { value: shown }) : /* @__PURE__ */ jsx("span", {
|
|
51
|
+
"aria-hidden": labelled,
|
|
52
|
+
className: "truncate",
|
|
53
|
+
children: placeholder
|
|
54
|
+
})]
|
|
44
55
|
}), /* @__PURE__ */ jsxs(RecordTableInlineCell.Content, {
|
|
45
56
|
render: /* @__PURE__ */ jsx("form", { onSubmit: handleAction }),
|
|
46
57
|
children: [/* @__PURE__ */ jsx(Input, {
|
|
@@ -12,5 +12,10 @@ interface PhoneInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElemen
|
|
|
12
12
|
onEnter?: (phone: string) => void;
|
|
13
13
|
onValidationChange?: (isValid: boolean, error?: string) => void;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* A phone input with a country flag picker that formats as you type.
|
|
17
|
+
* It validates on change and blur and reports through `onValidationChange`; `onChange` gets
|
|
18
|
+
* the number and its country code.
|
|
19
|
+
*/
|
|
15
20
|
export declare const PhoneInput: ({ ref, value, onChange, className, defaultCountry, placeholder, onEnter, onValidationChange, onKeyDown, onBlur, variant, ...props }: PhoneInputProps & React.RefAttributes<HTMLInputElement>) => React.JSX.Element;
|
|
16
21
|
export {};
|
|
@@ -89,6 +89,11 @@ const usePhoneValidation = (onValidationChange) => {
|
|
|
89
89
|
validate
|
|
90
90
|
};
|
|
91
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* A phone input with a country flag picker that formats as you type.
|
|
94
|
+
* It validates on change and blur and reports through `onValidationChange`; `onChange` gets
|
|
95
|
+
* the number and its country code.
|
|
96
|
+
*/
|
|
92
97
|
const PhoneInput = ({ ref, value, onChange, className, defaultCountry, placeholder, onEnter, onValidationChange, onKeyDown, onBlur, variant, ...props }) => {
|
|
93
98
|
const [initial] = useState(() => parseInitialPhone(value, defaultCountry));
|
|
94
99
|
const [selectedCountry, setSelectedCountry] = useState(initial.country);
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* Rows grouped under headers that fold away, such as tasks by status.
|
|
9
|
+
* Each group's sticky header picks all its rows, and folded groups are kept in this browser.
|
|
10
|
+
* Wrap it in `RecordList.Provider`, which holds the selection `RecordList.useSelection` reads
|
|
11
|
+
* for a bulk command bar.
|
|
12
|
+
*/
|
|
13
|
+
export declare const RecordList: typeof RecordListRoot & {
|
|
14
|
+
Provider: typeof RecordListProvider;
|
|
15
|
+
Skeleton: typeof RecordListSkeleton;
|
|
16
|
+
useSelection: typeof useRecordListSelection;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
/**
|
|
13
|
+
* Rows grouped under headers that fold away, such as tasks by status.
|
|
14
|
+
* Each group's sticky header picks all its rows, and folded groups are kept in this browser.
|
|
15
|
+
* Wrap it in `RecordList.Provider`, which holds the selection `RecordList.useSelection` reads
|
|
16
|
+
* for a bulk command bar.
|
|
17
|
+
*/
|
|
18
|
+
const RecordList = Object.assign(RecordListRoot, {
|
|
19
|
+
Provider: RecordListProvider,
|
|
20
|
+
Skeleton: RecordListSkeleton,
|
|
21
|
+
useSelection: useRecordListSelection
|
|
22
|
+
});
|
|
23
|
+
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 {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Button } from "../../components/button.js";
|
|
2
|
+
import { Checkbox } from "../../components/checkbox.js";
|
|
3
|
+
import { useMediaQuery } from "../../hooks/use-media-query.js";
|
|
4
|
+
import { cn } from "../../lib/utils.js";
|
|
5
|
+
import { collapsedGroups, useRecordListContext, useSelectionState } from "./RecordListProvider.js";
|
|
6
|
+
import { IconChevronDown, IconChevronRight } from "@tabler/icons-react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { useId } from "react";
|
|
9
|
+
import { useAtom } from "jotai";
|
|
10
|
+
// src/modules/record-list/RecordListRoot.tsx
|
|
11
|
+
/**
|
|
12
|
+
* A row's control that shows on hover or focus. A row's own controls (an empty date, say) can
|
|
13
|
+
* use the same classes. Where a finger may be the pointer (a phone, a touch laptop), nothing
|
|
14
|
+
* hovers first, so there they always show.
|
|
15
|
+
*/
|
|
16
|
+
const revealed = "opacity-0 group-hover/list-row:opacity-100 group-focus-within/list-row:opacity-100";
|
|
17
|
+
const useHover = () => useMediaQuery("(hover: hover) and (not (any-pointer: coarse))");
|
|
18
|
+
const GroupHeader = ({ group, ids, panelId, collapsed, onCollapse }) => {
|
|
19
|
+
const { selection } = useRecordListContext();
|
|
20
|
+
const hover = useHover();
|
|
21
|
+
const picked = useSelectionState((current) => ids.filter((id) => current.has(id)).length);
|
|
22
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
23
|
+
className: "group/list-row sticky top-0 z-10 flex h-9 items-center gap-1 border-b bg-muted px-2 text-xs font-medium",
|
|
24
|
+
children: [
|
|
25
|
+
/* @__PURE__ */ jsx("span", {
|
|
26
|
+
className: cn("flex h-9 w-8 shrink-0 items-center justify-center", hover && !picked && revealed),
|
|
27
|
+
children: /* @__PURE__ */ jsx(Checkbox, {
|
|
28
|
+
checked: picked > 0 && picked === ids.length,
|
|
29
|
+
indeterminate: picked > 0 && picked < ids.length,
|
|
30
|
+
"aria-label": `Select all in ${group.label}`,
|
|
31
|
+
onCheckedChange: () => selection.toggleAll(ids)
|
|
32
|
+
})
|
|
33
|
+
}),
|
|
34
|
+
/* @__PURE__ */ jsxs(Button, {
|
|
35
|
+
variant: "ghost",
|
|
36
|
+
size: "sm",
|
|
37
|
+
"aria-expanded": !collapsed,
|
|
38
|
+
"aria-controls": collapsed ? void 0 : panelId,
|
|
39
|
+
onClick: () => onCollapse(!collapsed),
|
|
40
|
+
children: [
|
|
41
|
+
collapsed ? /* @__PURE__ */ jsx(IconChevronRight, { "aria-hidden": true }) : /* @__PURE__ */ jsx(IconChevronDown, { "aria-hidden": true }),
|
|
42
|
+
group.icon,
|
|
43
|
+
group.label,
|
|
44
|
+
/* @__PURE__ */ jsx("span", {
|
|
45
|
+
className: "text-muted-foreground tabular-nums",
|
|
46
|
+
children: ids.length
|
|
47
|
+
})
|
|
48
|
+
]
|
|
49
|
+
}),
|
|
50
|
+
group.action && /* @__PURE__ */ jsx("span", {
|
|
51
|
+
className: "ml-auto flex items-center",
|
|
52
|
+
children: group.action
|
|
53
|
+
})
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
const Row = ({ id, label, order, children }) => {
|
|
58
|
+
const { selection } = useRecordListContext();
|
|
59
|
+
const hover = useHover();
|
|
60
|
+
const checked = useSelectionState((current) => current.has(id));
|
|
61
|
+
const selecting = useSelectionState((current) => current.size > 0);
|
|
62
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
63
|
+
"data-record-row": id,
|
|
64
|
+
"data-selected": checked || void 0,
|
|
65
|
+
className: "group/list-row flex h-11 items-center gap-1 border-b px-2 text-sm hover:bg-muted data-selected:bg-primary/10",
|
|
66
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
67
|
+
className: cn("flex h-11 w-8 shrink-0 items-center justify-center", hover && !selecting && revealed),
|
|
68
|
+
children: /* @__PURE__ */ jsx(Checkbox, {
|
|
69
|
+
className: "relative after:absolute after:-inset-x-2 after:-inset-y-3.5",
|
|
70
|
+
checked,
|
|
71
|
+
"aria-label": `Select ${label}`,
|
|
72
|
+
onCheckedChange: (_checked, { event }) => {
|
|
73
|
+
const range = event instanceof MouseEvent && event.shiftKey;
|
|
74
|
+
if (range) window.getSelection()?.removeAllRanges();
|
|
75
|
+
selection.toggle(id, range ? order : void 0);
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
}), children]
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Rows in groups, each under a sticky header that folds it away and picks all its rows; the
|
|
83
|
+
* folded groups are kept in this browser. Shift-click picks every row between two clicks, as
|
|
84
|
+
* shown. Inside `RecordList.Provider`, which holds the selection a command bar reads.
|
|
85
|
+
*/
|
|
86
|
+
const RecordListRoot = ({ groups, rowId, rowLabel, renderRow, grouped = true, className }) => {
|
|
87
|
+
const { listId } = useRecordListContext();
|
|
88
|
+
const [collapsed, setCollapsed] = useAtom(collapsedGroups(listId));
|
|
89
|
+
const prefix = useId();
|
|
90
|
+
const folded = (group) => grouped && collapsed.includes(group.id);
|
|
91
|
+
const order = groups.filter((group) => !folded(group)).flatMap((group) => group.rows.map(rowId));
|
|
92
|
+
const rows = (list) => list.map((row) => /* @__PURE__ */ jsx(Row, {
|
|
93
|
+
id: rowId(row),
|
|
94
|
+
label: rowLabel(row),
|
|
95
|
+
order,
|
|
96
|
+
children: renderRow(row)
|
|
97
|
+
}, rowId(row)));
|
|
98
|
+
if (!grouped) return /* @__PURE__ */ jsx("div", {
|
|
99
|
+
"data-record-list": listId,
|
|
100
|
+
className,
|
|
101
|
+
children: /* @__PURE__ */ jsx("ul", { children: rows(groups.flatMap((group) => group.rows)) })
|
|
102
|
+
});
|
|
103
|
+
return /* @__PURE__ */ jsx("div", {
|
|
104
|
+
"data-record-list": listId,
|
|
105
|
+
className,
|
|
106
|
+
children: groups.map((group) => {
|
|
107
|
+
const panelId = `${prefix}-${group.id}`;
|
|
108
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
109
|
+
"aria-label": group.label,
|
|
110
|
+
children: [/* @__PURE__ */ jsx(GroupHeader, {
|
|
111
|
+
group,
|
|
112
|
+
ids: group.rows.map(rowId),
|
|
113
|
+
panelId,
|
|
114
|
+
collapsed: folded(group),
|
|
115
|
+
onCollapse: (fold) => setCollapsed((current) => fold ? [...current, group.id] : current.filter((id) => id !== group.id))
|
|
116
|
+
}), !folded(group) && /* @__PURE__ */ jsx("ul", {
|
|
117
|
+
id: panelId,
|
|
118
|
+
children: rows(group.rows)
|
|
119
|
+
})]
|
|
120
|
+
}, group.id);
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
export { RecordListRoot };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rows a click on `id` picks. With `anchor` (the row clicked before), every row from it to
|
|
3
|
+
* `id` in `order`, the rows as shown; without, or when either left the list, `id` alone.
|
|
4
|
+
*/
|
|
5
|
+
export declare const rowsBetween: (order: readonly string[], anchor: string | null, id: string) => string[];
|
|
6
|
+
/** `picked` with `ids` added (`on`) or taken out. */
|
|
7
|
+
export declare const withRows: (picked: ReadonlySet<string>, ids: readonly string[], on: boolean) => Set<string>;
|
|
8
|
+
/**
|
|
9
|
+
* One list's picked rows, outside React: each row subscribes to its own state, so a click
|
|
10
|
+
* renders only the rows it changes. Every change starts from the current state, so changes
|
|
11
|
+
* made before a render all count.
|
|
12
|
+
*/
|
|
13
|
+
export declare const createSelection: () => {
|
|
14
|
+
subscribe: (listener: () => void) => () => void;
|
|
15
|
+
picked: () => ReadonlySet<string>;
|
|
16
|
+
/** With `order` (the rows as shown), a shift-click: every row since the last click. */
|
|
17
|
+
toggle: (id: string, order?: readonly string[]) => void;
|
|
18
|
+
/** Picks all of `ids`, or clears them when all are picked. */
|
|
19
|
+
toggleAll: (ids: readonly string[]) => void;
|
|
20
|
+
clear: () => void;
|
|
21
|
+
};
|
|
22
|
+
export type Selection = ReturnType<typeof createSelection>;
|