@erxes/ui 4.0.0-v2.12 → 4.0.0-v2.14

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.
Files changed (70) hide show
  1. package/CATALOG.md +3 -2
  2. package/README.md +1 -1
  3. package/dist/components/color-picker.js +2 -2
  4. package/dist/components/command-bar.js +3 -0
  5. package/dist/components/input.d.ts +1 -1
  6. package/dist/components/input.js +2 -2
  7. package/dist/components/on-demand.d.ts +9 -2
  8. package/dist/components/on-demand.js +15 -1
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.js +2 -2
  11. package/dist/modules/conditions/ConditionsEditor.d.ts +5 -3
  12. package/dist/modules/conditions/ConditionsEditor.js +139 -177
  13. package/dist/modules/conditions/DateEditors.d.ts +8 -0
  14. package/dist/modules/conditions/DateEditors.js +188 -0
  15. package/dist/modules/conditions/FieldPicker.d.ts +17 -0
  16. package/dist/modules/conditions/FieldPicker.js +99 -0
  17. package/dist/modules/conditions/RuleParts.d.ts +30 -0
  18. package/dist/modules/conditions/RuleParts.js +78 -0
  19. package/dist/modules/conditions/RuleRow.d.ts +27 -0
  20. package/dist/modules/conditions/RuleRow.js +156 -0
  21. package/dist/modules/conditions/TypedInput.d.ts +13 -0
  22. package/dist/modules/conditions/TypedInput.js +36 -0
  23. package/dist/modules/conditions/ValueEditor.d.ts +18 -0
  24. package/dist/modules/conditions/ValueEditor.js +164 -0
  25. package/dist/modules/conditions/conditions.d.ts +15 -8
  26. package/dist/modules/conditions/conditions.js +1 -75
  27. package/dist/modules/conditions/fieldIcons.d.ts +6 -0
  28. package/dist/modules/conditions/fieldIcons.js +19 -0
  29. package/dist/modules/conditions/fieldOptions.d.ts +13 -0
  30. package/dist/modules/conditions/fieldOptions.js +26 -0
  31. package/dist/modules/conditions/filterRule.d.ts +45 -0
  32. package/dist/modules/conditions/filterRule.js +169 -0
  33. package/dist/modules/conditions/filterText.d.ts +16 -0
  34. package/dist/modules/conditions/filterText.js +156 -0
  35. package/dist/modules/filter/components/Filter.d.ts +1 -1
  36. package/dist/modules/filter/components/Filter.js +1 -1
  37. package/dist/modules/filter/components/FilterBar.js +3 -0
  38. package/dist/modules/list/ListFilter.d.ts +20 -7
  39. package/dist/modules/list/ListFilter.js +50 -17
  40. package/dist/modules/list/ViewBar.d.ts +2 -0
  41. package/dist/modules/list/ViewBar.js +21 -10
  42. package/dist/modules/list/filter/AddFilter.d.ts +10 -0
  43. package/dist/modules/list/filter/AddFilter.js +140 -0
  44. package/dist/modules/list/filter/AdvancedPopover.d.ts +8 -0
  45. package/dist/modules/list/filter/AdvancedPopover.js +103 -0
  46. package/dist/modules/list/filter/ListFilterBar.d.ts +3 -3
  47. package/dist/modules/list/filter/ListFilterBar.js +104 -198
  48. package/dist/modules/list/filter/RuleChips.d.ts +12 -2
  49. package/dist/modules/list/filter/RuleChips.js +132 -138
  50. package/dist/modules/list/filter/SearchChip.d.ts +6 -0
  51. package/dist/modules/list/filter/SearchChip.js +69 -0
  52. package/dist/modules/list/filter/filterRules.d.ts +15 -40
  53. package/dist/modules/list/filter/filterRules.js +27 -156
  54. package/dist/modules/list/filter/listFilterContext.d.ts +25 -18
  55. package/dist/modules/list/filter/listFilterContext.js +8 -24
  56. package/dist/modules/list/filter/listFilterQuery.d.ts +4 -0
  57. package/dist/modules/list/filter/listFilterQuery.js +10 -2
  58. package/dist/theme.css +3 -2
  59. package/exports.txt +1 -0
  60. package/package.json +1 -1
  61. package/dist/modules/conditions/ConditionValueInput.d.ts +0 -10
  62. package/dist/modules/conditions/ConditionValueInput.js +0 -166
  63. package/dist/modules/conditions/PathPicker.d.ts +0 -8
  64. package/dist/modules/conditions/PathPicker.js +0 -51
  65. package/dist/modules/list/filter/AdvancedFilterDialog.d.ts +0 -5
  66. package/dist/modules/list/filter/AdvancedFilterDialog.js +0 -52
  67. package/dist/modules/list/filter/FieldMenus.d.ts +0 -5
  68. package/dist/modules/list/filter/FieldMenus.js +0 -184
  69. package/dist/modules/list/filter/fieldIcons.d.ts +0 -7
  70. package/dist/modules/list/filter/fieldIcons.js +0 -16
@@ -1,6 +1,6 @@
1
1
  import { TListFilterProps } from "../ListFilter.js";
2
2
  /**
3
- * Inside `<Filter>`: its chips, the list's status and the count, then the list's controls
4
- * and the menu (`F`).
3
+ * In the view bar: the count, the list's own controls and the filter button (`F`). Under it,
4
+ * while the list is filtered, the filter row: in the view bar's slot, else right after the bar.
5
5
  */
6
- export declare const ListFilterBar: ({ id, fields, loading, error, status, totalCount, totalCapped, children, members, tags }: TListFilterProps) => import("react").JSX.Element;
6
+ export declare const ListFilterBar: (props: TListFilterProps) => import("react").JSX.Element;
@@ -1,210 +1,140 @@
1
1
  import { Button } from "../../../components/button.js";
2
- import { Combobox } from "../../../components/combobox.js";
3
- import { Command } from "../../../components/command.js";
4
2
  import { IconTip } from "../../../components/icon-tip.js";
5
- import { Popover } from "../../../components/popover.js";
6
3
  import { usePageHotkey } from "../../../hooks/use-page-hotkey.js";
7
- import { isRule } from "../../conditions/conditions.js";
8
- import { Filter } from "../../filter/components/Filter.js";
9
- import { useFilterContext } from "../../filter/hooks/useFilterContext.js";
10
- import { AdvancedFilterDialog } from "./AdvancedFilterDialog.js";
11
- import { FieldMenu } from "./FieldMenus.js";
12
- import { FIELD_ICONS } from "./fieldIcons.js";
13
- import { groupOf, inMenu, partsOf, withPart } from "./filterRules.js";
14
- import { ListFilterContext, useListFilter } from "./listFilterContext.js";
4
+ import { ruleCount } from "../../conditions/filterRule.js";
5
+ import { useFilterRowSlot } from "../ViewBar.js";
6
+ import { AddFilter } from "./AddFilter.js";
7
+ import { AdvancedPopover } from "./AdvancedPopover.js";
8
+ import { chipsOf, groupOf, partsOf, withPart } from "./filterRules.js";
9
+ import { ListFilterContext } from "./listFilterContext.js";
15
10
  import { useListConditions } from "./listFilterQuery.js";
16
11
  import { RecordCount } from "./RecordCount.js";
17
12
  import { RuleChips } from "./RuleChips.js";
18
- import { IconAdjustmentsHorizontal, IconFilter2, IconSearch } from "@tabler/icons-react";
13
+ import { SearchChip } from "./SearchChip.js";
14
+ import { IconFilter2, IconPlus } from "@tabler/icons-react";
19
15
  import { jsx, jsxs } from "react/jsx-runtime";
20
- import { useCallback, useMemo, useState } from "react";
16
+ import { useMemo, useRef, useState } from "react";
21
17
  import { useTranslation } from "react-i18next";
22
- import { useQueryState } from "nuqs";
18
+ import { createPortal } from "react-dom";
23
19
  import { useAutoAnimate } from "@formkit/auto-animate/react";
24
20
  // src/modules/list/filter/ListFilterBar.tsx
25
- /** Built-in fields first, the record's properties last; each with its heading's English. */
26
- const GROUPS = [
27
- {
28
- group: "fields",
29
- label: "Fields"
30
- },
31
- {
32
- group: "lead",
33
- label: "Lead"
34
- },
35
- {
36
- group: "company",
37
- label: "Company"
38
- },
39
- {
40
- group: "activity",
41
- label: "Activity"
42
- },
43
- {
44
- group: "custom",
45
- label: "Properties"
46
- }
47
- ];
48
- /** Every field, grouped; each opens its submenu. The search box filters them by name. */
49
- const FieldItems = () => {
50
- const { t } = useTranslation("views", { keyPrefix: "filter" });
51
- const { fields } = useListFilter();
52
- return GROUPS.map(({ group, label }) => {
53
- const inGroup = fields.filter((field) => (field.group ?? "fields") === group);
54
- if (!inGroup.length) return null;
55
- return /* @__PURE__ */ jsx(Command.Group, {
56
- heading: t(`group.${group}`, label),
57
- children: inGroup.map((field) => {
58
- const Icon = field.icon ?? FIELD_ICONS[field.type];
59
- return /* @__PURE__ */ jsxs(Filter.Item, {
60
- value: field.path,
61
- keywords: [field.label],
62
- children: [/* @__PURE__ */ jsx(Icon, {}), /* @__PURE__ */ jsx("span", {
63
- className: "truncate",
64
- children: field.label
65
- })]
66
- }, field.path);
67
- })
68
- }, group);
69
- });
70
- };
71
- /** The menu's first page: "Add filter…", search, the advanced filter, then the fields. */
72
- const RootMenu = ({ loading, error }) => {
73
- const { t } = useTranslation("views", { keyPrefix: "filter" });
74
- const { openAdvanced } = useListFilter();
75
- const search = t("search", "Search");
76
- const advanced = t("advanced", "Advanced filter");
77
- return /* @__PURE__ */ jsxs(Command, { children: [/* @__PURE__ */ jsx(Filter.CommandInput, {
78
- placeholder: t("add", "Add filter…"),
79
- variant: "secondary",
80
- focusOnMount: true
81
- }), /* @__PURE__ */ jsxs(Command.List, {
82
- className: "max-h-popup",
83
- children: [
84
- /* @__PURE__ */ jsx(Command.Empty, { children: t("no-match", "No field matches") }),
85
- /* @__PURE__ */ jsxs(Filter.Item, {
86
- value: "searchValue",
87
- keywords: [search],
88
- inDialog: true,
89
- children: [/* @__PURE__ */ jsx(IconSearch, {}), search]
90
- }),
91
- /* @__PURE__ */ jsxs(Filter.CommandItem, {
92
- value: "advanced",
93
- keywords: [advanced],
94
- onSelect: openAdvanced,
95
- children: [/* @__PURE__ */ jsx(IconAdjustmentsHorizontal, {}), advanced]
96
- }),
97
- loading && /* @__PURE__ */ jsx("p", {
98
- className: "px-2 py-1.5 text-xs text-muted-foreground",
99
- children: t("loading", "Loading fields…")
100
- }),
101
- error && /* @__PURE__ */ jsx("p", {
102
- role: "alert",
103
- className: "px-2 py-1.5 text-xs text-destructive",
104
- children: error.message
105
- }),
106
- /* @__PURE__ */ jsx(FieldItems, {})
107
- ]
108
- })] });
109
- };
110
- /** The search, as a chip (it opens the search box). */
111
- const SearchChip = () => {
112
- const { t } = useTranslation("views", { keyPrefix: "filter" });
113
- const [searchValue] = useQueryState("searchValue");
114
- return /* @__PURE__ */ jsxs(Filter.BarItem, {
115
- queryKey: "searchValue",
116
- children: [/* @__PURE__ */ jsxs(Filter.BarName, { children: [/* @__PURE__ */ jsx(IconSearch, {}), t("search", "Search")] }), /* @__PURE__ */ jsx(Filter.BarButton, {
117
- filterKey: "searchValue",
118
- inDialog: true,
119
- children: searchValue
120
- })]
121
- });
122
- };
123
- /** Opens the filter menu; it shows how many conditions apply. */
124
- const FilterButton = ({ count, onClick }) => {
21
+ /** The view bar's filter button: it opens the field picker and shows how many conditions apply. */
22
+ const FilterButton = ({ count }) => {
125
23
  const { t } = useTranslation("views", { keyPrefix: "filter" });
126
24
  const label = t("label", "Filter");
127
25
  return /* @__PURE__ */ jsx(IconTip, {
128
26
  label,
129
27
  hotkey: "F",
130
- children: /* @__PURE__ */ jsxs(Popover.Trigger, {
131
- render: /* @__PURE__ */ jsx(Button, {
28
+ children: /* @__PURE__ */ jsx(AddFilter, {
29
+ from: "bar",
30
+ trigger: /* @__PURE__ */ jsxs(Button, {
132
31
  size: "sm",
133
- "aria-label": label,
32
+ "aria-label": count > 0 ? `${label} ${count}` : label,
134
33
  "aria-keyshortcuts": "F",
135
34
  variant: count > 0 ? "secondary" : "ghost",
136
35
  tone: count > 0 ? "default" : "muted",
137
36
  className: "h-7 min-w-7",
138
- onClick
139
- }),
140
- children: [/* @__PURE__ */ jsx(IconFilter2, { className: "size-4" }), count > 0 && /* @__PURE__ */ jsx("span", {
141
- className: "text-xs tabular-nums",
142
- children: count
143
- })]
37
+ children: [/* @__PURE__ */ jsx(IconFilter2, { className: "size-4" }), count > 0 && /* @__PURE__ */ jsx("span", {
38
+ className: "text-xs tabular-nums",
39
+ children: count
40
+ })]
41
+ })
144
42
  })
145
43
  });
146
44
  };
147
- /** The bar's context: the list's conditions as parts, and the one the menu is editing. */
148
- const useListFilterState = (fields, lookups) => {
45
+ /**
46
+ * Under the view bar while the list is filtered: the conditions as chips that wrap, "+ Filter",
47
+ * Clear, and what the open view changed. The advanced filter opens anchored to it.
48
+ */
49
+ const FilterRow = ({ status }) => {
50
+ const { t } = useTranslation("views", { keyPrefix: "filter" });
51
+ const { clear } = useListConditions();
52
+ const [chipsRef] = useAutoAnimate({ duration: 150 });
53
+ const rowRef = useRef(null);
54
+ return /* @__PURE__ */ jsxs("div", {
55
+ ref: rowRef,
56
+ role: "toolbar",
57
+ "aria-label": t("row", "Filters"),
58
+ className: "flex min-h-10 shrink-0 items-start gap-2 border-b bg-background px-3 py-1.5",
59
+ children: [
60
+ /* @__PURE__ */ jsxs("div", {
61
+ ref: chipsRef,
62
+ className: "flex min-w-0 flex-1 flex-wrap items-center gap-1.5",
63
+ children: [
64
+ /* @__PURE__ */ jsx(SearchChip, {}),
65
+ /* @__PURE__ */ jsx(RuleChips, {}),
66
+ /* @__PURE__ */ jsx(AddFilter, {
67
+ from: "row",
68
+ trigger: /* @__PURE__ */ jsxs(Button, {
69
+ size: "sm",
70
+ variant: "ghost",
71
+ tone: "muted",
72
+ className: "h-7",
73
+ children: [/* @__PURE__ */ jsx(IconPlus, {}), t("label", "Filter")]
74
+ })
75
+ })
76
+ ]
77
+ }),
78
+ /* @__PURE__ */ jsxs("div", {
79
+ className: "flex h-7 shrink-0 items-center gap-1",
80
+ children: [/* @__PURE__ */ jsx(Button, {
81
+ size: "sm",
82
+ variant: "ghost",
83
+ tone: "muted",
84
+ className: "h-7",
85
+ onClick: clear,
86
+ children: t("clear", "Clear")
87
+ }), status]
88
+ }),
89
+ /* @__PURE__ */ jsx(AdvancedPopover, { anchor: rowRef })
90
+ ]
91
+ });
92
+ };
93
+ /** The filter's shared state: the conditions from the address, the open pickers. */
94
+ const useListFilterState = ({ fields, members, tags, totalCount, totalCapped, loading, error }) => {
149
95
  const { advanced, setAdvanced } = useListConditions();
150
- const { setOpen, setView } = useFilterContext();
151
- const [editing, setEditing] = useState(null);
96
+ const [adding, setAdding] = useState(null);
152
97
  const [advancedOpen, setAdvancedOpen] = useState(false);
98
+ const lookups = useMemo(() => ({
99
+ members,
100
+ tags
101
+ }), [members, tags]);
153
102
  const parts = useMemo(() => partsOf(advanced), [advanced]);
154
- const openMenu = useCallback((view, part) => {
155
- setEditing(part);
156
- setView(view);
157
- setOpen(true);
158
- }, [setOpen, setView]);
159
- usePageHotkey("f", () => openMenu("root", null));
160
103
  return {
161
- state: useMemo(() => ({
162
- fields,
163
- lookups,
164
- parts,
165
- editing,
166
- setPart: (index, next) => setAdvanced(groupOf(withPart(parts, index, next))),
167
- edit: (index) => {
168
- const part = parts[index];
169
- const field = part && isRule(part) && fields.find((one) => one.path === part.path);
170
- if (part && isRule(part) && field && inMenu(part, field)) openMenu(field.path, index);
171
- else setAdvancedOpen(true);
172
- },
173
- openAdvanced: () => setAdvancedOpen(true)
174
- }), [
175
- fields,
176
- lookups,
177
- parts,
178
- editing,
179
- setAdvanced,
180
- openMenu
181
- ]),
182
- setEditing,
104
+ fields,
105
+ lookups,
106
+ advanced,
107
+ chips: chipsOf(advanced),
108
+ parts,
109
+ setPart: (index, next) => setAdvanced(groupOf(withPart(parts, index, next))),
110
+ setAdvanced,
111
+ adding,
112
+ setAdding,
183
113
  advancedOpen,
184
- setAdvancedOpen
114
+ setAdvancedOpen,
115
+ totalCount,
116
+ totalCapped,
117
+ loading,
118
+ error
185
119
  };
186
120
  };
187
121
  /**
188
- * Inside `<Filter>`: its chips, the list's status and the count, then the list's controls
189
- * and the menu (`F`).
122
+ * In the view bar: the count, the list's own controls and the filter button (`F`). Under it,
123
+ * while the list is filtered, the filter row: in the view bar's slot, else right after the bar.
190
124
  */
191
- const ListFilterBar = ({ id, fields, loading, error, status, totalCount, totalCapped, children, members, tags }) => {
192
- const [chipsRef] = useAutoAnimate({ duration: 150 });
193
- const { search } = useListConditions();
194
- const lookups = useMemo(() => ({
195
- members,
196
- tags
197
- }), [members, tags]);
198
- const { state, setEditing, advancedOpen, setAdvancedOpen } = useListFilterState(fields, lookups);
125
+ const ListFilterBar = (props) => {
126
+ const { status, totalCount, totalCapped, children } = props;
127
+ const state = useListFilterState(props);
128
+ const { advanced, search, active } = useListConditions();
129
+ const slot = useFilterRowSlot();
130
+ const count = (advanced ? ruleCount(advanced) : 0) + (search ? 1 : 0);
131
+ const rowShown = active || state.advancedOpen;
132
+ usePageHotkey("f", () => state.setAdding(rowShown ? "row" : "bar"));
133
+ const row = rowShown && /* @__PURE__ */ jsx(FilterRow, { status });
199
134
  return /* @__PURE__ */ jsxs(ListFilterContext.Provider, {
200
135
  value: state,
201
136
  children: [
202
- /* @__PURE__ */ jsxs("div", {
203
- ref: chipsRef,
204
- className: "flex min-w-0 items-center gap-1 overflow-x-auto py-1 hide-scroll",
205
- children: [/* @__PURE__ */ jsx(SearchChip, {}), /* @__PURE__ */ jsx(RuleChips, {})]
206
- }),
207
- status,
137
+ !rowShown && status,
208
138
  /* @__PURE__ */ jsx(RecordCount, {
209
139
  totalCount,
210
140
  totalCapped
@@ -214,32 +144,8 @@ const ListFilterBar = ({ id, fields, loading, error, status, totalCount, totalCa
214
144
  className: "mx-1 h-4 w-px shrink-0 bg-border"
215
145
  }),
216
146
  children,
217
- /* @__PURE__ */ jsxs(Filter.Popover, {
218
- scope: `${id}-list`,
219
- children: [/* @__PURE__ */ jsx(FilterButton, {
220
- count: state.parts.length + (search ? 1 : 0),
221
- onClick: () => setEditing(null)
222
- }), /* @__PURE__ */ jsxs(Combobox.Content, {
223
- align: "end",
224
- className: "w-80",
225
- children: [/* @__PURE__ */ jsx(Filter.View, { children: /* @__PURE__ */ jsx(RootMenu, {
226
- loading,
227
- error
228
- }) }), fields.map((field) => /* @__PURE__ */ jsx(Filter.View, {
229
- filterKey: field.path,
230
- children: /* @__PURE__ */ jsx(FieldMenu, { field }, `${state.editing}`)
231
- }, field.path))]
232
- })]
233
- }),
234
- /* @__PURE__ */ jsx(Filter.Dialog, { children: /* @__PURE__ */ jsx(Filter.View, {
235
- filterKey: "searchValue",
236
- inDialog: true,
237
- children: /* @__PURE__ */ jsx(Filter.DialogStringView, { filterKey: "searchValue" })
238
- }) }),
239
- /* @__PURE__ */ jsx(AdvancedFilterDialog, {
240
- open: advancedOpen,
241
- onOpenChange: setAdvancedOpen
242
- })
147
+ /* @__PURE__ */ jsx(FilterButton, { count }),
148
+ row && (slot ? createPortal(row, slot) : row)
243
149
  ]
244
150
  });
245
151
  };
@@ -1,2 +1,12 @@
1
- /** Each part of the list's filter as a chip (parts are distinct, so a part is its own key). */
2
- export declare const RuleChips: () => import("react").JSX.Element[];
1
+ import { ReactNode } from "react";
2
+ /** A chip: joined segments on a muted ground, the last one a remove button. */
3
+ export declare const Chip: ({ children, removeLabel, onRemove }: {
4
+ children: ReactNode;
5
+ removeLabel: string;
6
+ onRemove: () => void;
7
+ }) => import("react").JSX.Element;
8
+ /**
9
+ * The list's conditions as chips, one per rule (keyed by place, so an open editor stays open as
10
+ * its rule changes), or the advanced filter's chip.
11
+ */
12
+ export declare const RuleChips: () => import("react").JSX.Element[] | import("react").JSX.Element;