@erxes/ui 4.0.0-v2.11 → 4.0.0-v2.13

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 (51) hide show
  1. package/CATALOG.md +9 -2
  2. package/dist/components/color-picker.js +2 -2
  3. package/dist/components/combobox.js +4 -1
  4. package/dist/components/command-bar.js +3 -0
  5. package/dist/components/dialog.d.ts +5 -2
  6. package/dist/components/dialog.js +19 -10
  7. package/dist/components/field-control.d.ts +16 -0
  8. package/dist/components/field-control.js +19 -0
  9. package/dist/components/form-layout.d.ts +19 -0
  10. package/dist/components/form-layout.js +56 -0
  11. package/dist/components/form.d.ts +9 -2
  12. package/dist/components/form.js +17 -7
  13. package/dist/components/input.d.ts +1 -1
  14. package/dist/components/input.js +9 -4
  15. package/dist/components/multiselect.js +4 -1
  16. package/dist/components/on-demand.d.ts +9 -2
  17. package/dist/components/on-demand.js +15 -1
  18. package/dist/components/popover.js +17 -13
  19. package/dist/components/select.js +16 -11
  20. package/dist/components/sheet.d.ts +5 -2
  21. package/dist/components/sheet.js +18 -9
  22. package/dist/components/textarea.js +4 -1
  23. package/dist/hooks/use-focus-first-field.d.ts +8 -0
  24. package/dist/hooks/use-focus-first-field.js +15 -0
  25. package/dist/hooks/use-page-hotkey.d.ts +2 -0
  26. package/dist/hooks/use-page-hotkey.js +4 -2
  27. package/dist/index.d.ts +4 -2
  28. package/dist/index.js +4 -2
  29. package/dist/lib/render-in-dom.d.ts +6 -0
  30. package/dist/lib/render-in-dom.js +26 -0
  31. package/dist/modules/conditions/PathPicker.js +7 -2
  32. package/dist/modules/conditions/conditions.d.ts +2 -0
  33. package/dist/modules/filter/components/FilterBar.js +3 -0
  34. package/dist/modules/list/ListFilter.d.ts +11 -3
  35. package/dist/modules/list/ListFilter.js +8 -2
  36. package/dist/modules/list/ViewBar.d.ts +36 -4
  37. package/dist/modules/list/ViewBar.js +33 -9
  38. package/dist/modules/list/filter/ListFilterBar.js +11 -4
  39. package/dist/modules/list/filter/RuleChips.js +1 -5
  40. package/dist/modules/record-field/components/TextField.js +1 -4
  41. package/dist/modules/record-panel/PanelForm.d.ts +4 -2
  42. package/dist/modules/record-panel/PanelForm.js +73 -7
  43. package/dist/node_modules/.pnpm/vitest@5.1.0_@opentelemetry_api@1.10.0_@types_node@26.6.6_@vitest_browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/chunks/display.BlTmubjj.js +181 -0
  44. package/dist/node_modules/.pnpm/vitest@5.1.0_@opentelemetry_api@1.10.0_@types_node@26.6.6_@vitest_browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/chunks/index.D0heQG4v.js +987 -0
  45. package/dist/node_modules/.pnpm/vitest@5.1.0_@opentelemetry_api@1.10.0_@types_node@26.6.6_@vitest_browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/chunks/pathe.M-eThtNZ.zq3TM4NT.js +176 -0
  46. package/dist/node_modules/.pnpm/vitest@5.1.0_@opentelemetry_api@1.10.0_@types_node@26.6.6_@vitest_browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/chunks/run.CjdgFZiW.js +1509 -0
  47. package/dist/node_modules/.pnpm/vitest@5.1.0_@opentelemetry_api@1.10.0_@types_node@26.6.6_@vitest_browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/chunks/source-map.DakdQc29.js +687 -0
  48. package/dist/node_modules/.pnpm/vitest@5.1.0_@opentelemetry_api@1.10.0_@types_node@26.6.6_@vitest_browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/chunks/tinyrainbow.Do8I1XRG.js +85 -0
  49. package/dist/node_modules/.pnpm/vitest@5.1.0_@opentelemetry_api@1.10.0_@types_node@26.6.6_@vitest_browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/task-utils.js +6 -0
  50. package/exports.txt +7 -0
  51. package/package.json +4 -1
@@ -1,53 +1,73 @@
1
1
  import { Button } from "../../components/button.js";
2
+ import { FieldControlContext } from "../../components/field-control.js";
2
3
  import { Spinner } from "../../components/spinner.js";
4
+ import { useConfirm } from "../../hooks/use-confirm.js";
5
+ import { useFocusFirstField } from "../../hooks/use-focus-first-field.js";
6
+ import { isOverlayShown } from "../../hooks/use-page-hotkey.js";
3
7
  import { RecordTableInlineCell } from "../record-table/components/RecordTableCellInline.js";
4
8
  import { PanelLabel } from "./PanelLabel.js";
5
9
  import { IconForms } from "@tabler/icons-react";
6
10
  import { jsx, jsxs } from "react/jsx-runtime";
7
- import { useId } from "react";
11
+ import { useEffect, useId, useRef } from "react";
8
12
  import { useTranslation } from "react-i18next";
13
+ import { useHotkeys } from "react-hotkeys-hook";
9
14
  // src/modules/record-panel/PanelForm.tsx
10
15
  /**
11
16
  * One field of a form in the side panel, laid out like `PanelField`.
12
17
  * Icon and label, then the control, with its error, or else its hint, under it. A long label wraps to two lines (the
13
18
  * full text on hover) instead of being cut. `htmlFor` names the control by its id, so a click
14
- * on the label focuses it and a switch toggles.
19
+ * on the label focuses it and a switch toggles. The input, select or picker in the row is named
20
+ * by the label and described by the error or hint, and marked invalid and required with it.
15
21
  */
16
22
  const PanelFormRow = ({ label, icon: Icon = IconForms, required, error, hint, htmlFor, children }) => {
17
23
  const labelId = useId();
24
+ const messageId = useId();
25
+ const LabelTag = htmlFor ? "label" : "span";
26
+ const field = {
27
+ "aria-labelledby": labelId,
28
+ "aria-describedby": error || hint ? messageId : void 0,
29
+ "aria-invalid": error ? true : void 0,
30
+ "aria-required": required ? true : void 0
31
+ };
18
32
  return /* @__PURE__ */ jsxs("div", {
19
33
  className: "grid grid-cols-field items-start gap-x-2 gap-y-0.5",
20
34
  children: [
21
- /* @__PURE__ */ jsxs(htmlFor ? "label" : "span", {
35
+ /* @__PURE__ */ jsxs(LabelTag, {
22
36
  id: labelId,
23
37
  htmlFor,
24
38
  className: "flex min-h-7 min-w-0 items-center gap-1.5 text-xs font-medium text-accent-foreground",
25
39
  children: [/* @__PURE__ */ jsx(Icon, {
26
- className: "size-3.5 shrink-0",
40
+ className: "mt-1.75 size-3.5 shrink-0 self-start",
27
41
  "aria-hidden": "true"
28
42
  }), /* @__PURE__ */ jsxs(PanelLabel, {
29
43
  tooltip: label,
30
44
  children: [label, required && /* @__PURE__ */ jsx("span", {
45
+ "aria-hidden": "true",
31
46
  className: "text-destructive",
32
47
  children: " *"
33
48
  })]
34
49
  })]
35
50
  }),
36
51
  /* @__PURE__ */ jsxs("div", {
37
- className: "group/panel-value relative flex min-h-7 min-w-0 flex-col justify-center text-xs [&_button:not([role=switch])]:text-xs [&_input:placeholder-shown]:pl-7",
52
+ className: "group/panel-value relative flex min-h-7 min-w-0 flex-col justify-center text-xs [&_button:not([role=switch])]:text-xs [&_input]:text-xs [&_input:placeholder-shown]:pl-7",
38
53
  children: [/* @__PURE__ */ jsx(Icon, {
39
54
  className: "pointer-events-none absolute left-2 top-1/2 z-1 hidden size-3.5 -translate-y-1/2 text-muted-foreground group-has-[input:placeholder-shown]/panel-value:block",
40
55
  "aria-hidden": "true"
41
56
  }), /* @__PURE__ */ jsx(RecordTableInlineCell.LabelledBy, {
42
57
  value: labelId,
43
- children
58
+ children: /* @__PURE__ */ jsx(FieldControlContext, {
59
+ value: field,
60
+ children
61
+ })
44
62
  })]
45
63
  }),
46
64
  error ? /* @__PURE__ */ jsx("span", {
65
+ id: messageId,
47
66
  role: "alert",
48
67
  className: "col-start-2 text-xs text-destructive",
49
68
  children: error
50
69
  }) : hint && /* @__PURE__ */ jsx("span", {
70
+ id: messageId,
51
71
  className: "col-start-2 text-xs text-muted-foreground",
52
72
  children: hint
53
73
  })
@@ -55,14 +75,59 @@ const PanelFormRow = ({ label, icon: Icon = IconForms, required, error, hint, ht
55
75
  });
56
76
  };
57
77
  /**
78
+ * Escape while focus is in the form leaves it, once the member agrees to drop what they typed.
79
+ * Returns the ref for the form's root; `bodyRef` holds its fields. A picker, menu or dialog keeps
80
+ * its own Escape: focus is in its popup then, outside the form.
81
+ */
82
+ const useEscapeToCancel = (bodyRef, onCancel, saving) => {
83
+ const { t } = useTranslation("common", { keyPrefix: "form" });
84
+ const { confirm } = useConfirm();
85
+ const touched = useRef(false);
86
+ useEffect(() => {
87
+ const body = bodyRef.current;
88
+ const onInput = () => {
89
+ touched.current = true;
90
+ };
91
+ body?.addEventListener("input", onInput);
92
+ return () => body?.removeEventListener("input", onInput);
93
+ }, [bodyRef]);
94
+ return useHotkeys("esc", () => {
95
+ if (!touched.current) {
96
+ onCancel();
97
+ return;
98
+ }
99
+ confirm({
100
+ message: t("discard-title", "Discard this draft?"),
101
+ options: {
102
+ description: t("discard-description", "What you typed here is not saved."),
103
+ okLabel: t("discard", "Discard"),
104
+ cancelLabel: t("keep-editing", "Keep editing"),
105
+ variants: { ok: "destructive" }
106
+ }
107
+ }).then(onCancel);
108
+ }, {
109
+ enableOnFormTags: true,
110
+ enableOnContentEditable: true,
111
+ preventDefault: true,
112
+ ignoreEventWhen: (event) => Boolean(saving) || event.defaultPrevented || isOverlayShown(bodyRef.current)
113
+ });
114
+ };
115
+ /**
58
116
  * A new record's form in the side panel: its rows, then Cancel and Save.
59
- * Nothing is saved until Save.
117
+ * Nothing is saved until Save. The first field takes focus when it opens; Enter in a field
118
+ * saves, and Escape cancels (asking first once something was typed).
60
119
  */
61
120
  const PanelFormLayout = ({ children, onCancel, saving, saveLabel }) => {
62
121
  const { t } = useTranslation("common", { keyPrefix: "side-panel" });
122
+ const bodyRef = useRef(null);
123
+ const rootRef = useEscapeToCancel(bodyRef, onCancel, saving);
124
+ useFocusFirstField(bodyRef);
63
125
  return /* @__PURE__ */ jsxs("div", {
126
+ ref: rootRef,
64
127
  className: "flex flex-1 min-h-0 flex-col",
128
+ "aria-busy": saving ? true : void 0,
65
129
  children: [/* @__PURE__ */ jsx("div", {
130
+ ref: bodyRef,
66
131
  className: "flex-1 min-h-0 overflow-y-auto",
67
132
  children: /* @__PURE__ */ jsx("div", {
68
133
  className: "flex flex-col gap-1 p-3",
@@ -74,6 +139,7 @@ const PanelFormLayout = ({ children, onCancel, saving, saveLabel }) => {
74
139
  type: "button",
75
140
  variant: "ghost",
76
141
  size: "sm",
142
+ disabled: saving,
77
143
  onClick: onCancel,
78
144
  children: t("cancel", "Cancel")
79
145
  }), /* @__PURE__ */ jsxs(Button, {
@@ -0,0 +1,181 @@
1
+ import { c as createDOMElementFilter, f as format$1, p as plugins } from "./index.D0heQG4v.js";
2
+ // ../../node_modules/.pnpm/vitest@5.1.0_@opentelemetry+api@1.10.0_@types+node@26.6.6_@vitest+browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/chunks/display.BlTmubjj.js
3
+ const { AsymmetricMatcher, DOMCollection, DOMElement, Immutable, ReactElement, ReactTestComponent } = plugins;
4
+ const PLUGINS = [
5
+ ReactTestComponent,
6
+ ReactElement,
7
+ DOMElement,
8
+ DOMCollection,
9
+ Immutable,
10
+ AsymmetricMatcher
11
+ ];
12
+ function stringify(object, maxDepth = 10, { maxLength, filterNode, ...options } = {}) {
13
+ const MAX_LENGTH = maxLength ?? 1e4;
14
+ let result;
15
+ const filterFn = typeof filterNode === "string" ? createNodeFilterFromSelector(filterNode) : filterNode;
16
+ const plugins = filterFn ? [
17
+ ReactTestComponent,
18
+ ReactElement,
19
+ createDOMElementFilter(filterFn),
20
+ DOMCollection,
21
+ Immutable,
22
+ AsymmetricMatcher
23
+ ] : PLUGINS;
24
+ try {
25
+ result = format$1(object, {
26
+ maxDepth,
27
+ escapeString: false,
28
+ plugins,
29
+ ...options
30
+ });
31
+ } catch {
32
+ result = format$1(object, {
33
+ callToJSON: false,
34
+ maxDepth,
35
+ escapeString: false,
36
+ plugins,
37
+ ...options
38
+ });
39
+ }
40
+ return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(Math.min(maxDepth, Number.MAX_SAFE_INTEGER) / 2), {
41
+ maxLength,
42
+ filterNode,
43
+ ...options
44
+ }) : result;
45
+ }
46
+ function createNodeFilterFromSelector(selector) {
47
+ const ELEMENT_NODE = 1;
48
+ const COMMENT_NODE = 8;
49
+ return (node) => {
50
+ if (node.nodeType === COMMENT_NODE) return false;
51
+ if (node.nodeType === ELEMENT_NODE && node.matches) try {
52
+ return !node.matches(selector);
53
+ } catch {
54
+ return true;
55
+ }
56
+ return true;
57
+ };
58
+ }
59
+ const formatRegExp = /%[sdjifoOc%]/g;
60
+ function format(args, options = {}) {
61
+ const formatArg = (item) => inspect(item, options);
62
+ if (typeof args[0] !== "string") {
63
+ const objects = [];
64
+ for (let i = 0; i < args.length; i++) objects.push(formatArg(args[i]));
65
+ return objects.join(" ");
66
+ }
67
+ const len = args.length;
68
+ let i = 1;
69
+ const template = args[0];
70
+ let str = String(template).replace(formatRegExp, (x) => {
71
+ if (x === "%%") return "%";
72
+ if (i >= len) return x;
73
+ switch (x) {
74
+ case "%s": {
75
+ const value = args[i++];
76
+ if (typeof value === "bigint") return `${value.toString()}n`;
77
+ if (typeof value === "number" && value === 0 && 1 / value < 0) return "-0";
78
+ if (typeof value === "object" && value !== null) {
79
+ if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) return value.toString();
80
+ return formatArg(value);
81
+ }
82
+ return String(value);
83
+ }
84
+ case "%d": {
85
+ const value = args[i++];
86
+ if (typeof value === "bigint") return `${value.toString()}n`;
87
+ if (typeof value === "symbol") return "NaN";
88
+ return Number(value).toString();
89
+ }
90
+ case "%i": {
91
+ const value = args[i++];
92
+ if (typeof value === "bigint") return `${value.toString()}n`;
93
+ return Number.parseInt(String(value)).toString();
94
+ }
95
+ case "%f": return Number.parseFloat(String(args[i++])).toString();
96
+ case "%o":
97
+ case "%O": return formatArg(args[i++]);
98
+ case "%c":
99
+ i++;
100
+ return "";
101
+ case "%j": try {
102
+ return JSON.stringify(args[i++]);
103
+ } catch (err) {
104
+ const m = err.message;
105
+ if (m.includes("circular structure") || m.includes("cyclic structures") || m.includes("cyclic object")) return "[Circular]";
106
+ throw err;
107
+ }
108
+ default: return x;
109
+ }
110
+ });
111
+ for (let x = args[i]; i < len; x = args[++i]) if (x === null || typeof x !== "object") str += ` ${typeof x === "symbol" ? x.toString() : x}`;
112
+ else str += ` ${formatArg(x)}`;
113
+ return str;
114
+ }
115
+ function inspect(obj, options) {
116
+ const { truncate, multiline, ...stringifyOptions } = options ?? {};
117
+ const prettyFormatOptions = {
118
+ singleQuote: true,
119
+ quoteKeys: false,
120
+ min: true,
121
+ spacingInner: " ",
122
+ spacingOuter: " ",
123
+ printBasicPrototype: false,
124
+ compareKeys: null,
125
+ ...multiline ? {
126
+ min: false,
127
+ spacingInner: void 0,
128
+ spacingOuter: void 0
129
+ } : {}
130
+ };
131
+ const threshold = truncate ?? 0;
132
+ const formatted = stringify(obj, void 0, {
133
+ ...prettyFormatOptions,
134
+ ...stringifyOptions,
135
+ maxLength: threshold || void 0
136
+ });
137
+ if (threshold === 0 || formatted.length <= threshold) return formatted;
138
+ const type = Object.prototype.toString.call(obj);
139
+ if (typeof obj === "string") {
140
+ let end = threshold - 1;
141
+ if (end > 0 && isHighSurrogate(formatted[end - 1])) end = end - 1;
142
+ return `'${formatted.slice(1, end)}…'`;
143
+ }
144
+ if (type === "[object Array]" || type === "[object Object]" || type === "[object Set]" || type === "[object Map]") return stringifyByMaxWidth(obj, threshold, {
145
+ ...prettyFormatOptions,
146
+ ...stringifyOptions,
147
+ maxDepth: 1
148
+ });
149
+ return stringify(obj, void 0, {
150
+ ...prettyFormatOptions,
151
+ ...stringifyOptions,
152
+ maxDepth: 0
153
+ });
154
+ }
155
+ function truncateString(string, maxLength) {
156
+ if (string.length <= maxLength) return string;
157
+ let end = maxLength - 1;
158
+ if (isHighSurrogate(string[end - 1])) end = end - 1;
159
+ return `${string.slice(0, end)}…`;
160
+ }
161
+ function stringifyByMaxWidth(object, threshold, options) {
162
+ function evaluate(x) {
163
+ return stringify(object, void 0, {
164
+ ...options,
165
+ maxWidth: x
166
+ });
167
+ }
168
+ return evaluate(binarySearch(0, threshold, (x) => evaluate(x).length <= threshold));
169
+ }
170
+ function binarySearch(x0, x1, f) {
171
+ while (x0 + 1 < x1) {
172
+ const x = Math.floor((x0 + x1) / 2);
173
+ if (f(x)) x0 = x;
174
+ else x1 = x;
175
+ }
176
+ return x0;
177
+ }
178
+ function isHighSurrogate(char) {
179
+ return char >= "\ud800" && char <= "\udbff";
180
+ }
181
+ export { formatRegExp as a, format as f, inspect as i, stringify as s, truncateString as t };