@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
|
@@ -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>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/modules/record-list/selection.ts
|
|
2
|
+
/**
|
|
3
|
+
* The rows a click on `id` picks. With `anchor` (the row clicked before), every row from it to
|
|
4
|
+
* `id` in `order`, the rows as shown; without, or when either left the list, `id` alone.
|
|
5
|
+
*/
|
|
6
|
+
const rowsBetween = (order, anchor, id) => {
|
|
7
|
+
const from = anchor === null ? -1 : order.indexOf(anchor);
|
|
8
|
+
const to = order.indexOf(id);
|
|
9
|
+
if (from === -1 || to === -1) return [id];
|
|
10
|
+
return order.slice(Math.min(from, to), Math.max(from, to) + 1);
|
|
11
|
+
};
|
|
12
|
+
/** `picked` with `ids` added (`on`) or taken out. */
|
|
13
|
+
const withRows = (picked, ids, on) => {
|
|
14
|
+
const next = new Set(picked);
|
|
15
|
+
for (const id of ids) if (on) next.add(id);
|
|
16
|
+
else next.delete(id);
|
|
17
|
+
return next;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* One list's picked rows, outside React: each row subscribes to its own state, so a click
|
|
21
|
+
* renders only the rows it changes. Every change starts from the current state, so changes
|
|
22
|
+
* made before a render all count.
|
|
23
|
+
*/
|
|
24
|
+
const createSelection = () => {
|
|
25
|
+
let picked = /* @__PURE__ */ new Set();
|
|
26
|
+
let anchor = null;
|
|
27
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
28
|
+
const set = (next) => {
|
|
29
|
+
picked = next;
|
|
30
|
+
for (const listener of listeners) listener();
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
subscribe: (listener) => {
|
|
34
|
+
listeners.add(listener);
|
|
35
|
+
return () => {
|
|
36
|
+
listeners.delete(listener);
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
picked: () => picked,
|
|
40
|
+
/** With `order` (the rows as shown), a shift-click: every row since the last click. */
|
|
41
|
+
toggle: (id, order) => {
|
|
42
|
+
const rows = order ? rowsBetween(order, anchor, id) : [id];
|
|
43
|
+
anchor = id;
|
|
44
|
+
set(withRows(picked, rows, !picked.has(id)));
|
|
45
|
+
},
|
|
46
|
+
/** Picks all of `ids`, or clears them when all are picked. */
|
|
47
|
+
toggleAll: (ids) => set(withRows(picked, ids, !ids.every((id) => picked.has(id)))),
|
|
48
|
+
clear: () => {
|
|
49
|
+
anchor = null;
|
|
50
|
+
set(/* @__PURE__ */ new Set());
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export { createSelection, rowsBetween, withRows };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** A record's description as a full-size tab, saved when the editor loses focus. */
|
|
2
|
+
export declare const PanelDescriptionEditor: ({ value, scope, readonly, isHTML, onSave }: {
|
|
3
|
+
value: string;
|
|
4
|
+
scope: string;
|
|
5
|
+
readonly?: boolean;
|
|
6
|
+
/** Stores HTML instead of the editor's blocks. */
|
|
7
|
+
isHTML?: boolean;
|
|
8
|
+
onSave: (description: string) => void;
|
|
9
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { usePageHotkey } from "../../hooks/use-page-hotkey.js";
|
|
2
|
+
import { Editor } from "../blocks/components/LazyEditor.js";
|
|
3
|
+
import { useSaveOnLeave } from "./useSaveOnLeave.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/modules/record-panel/PanelDescriptionEditor.tsx
|
|
6
|
+
/** The editor inside `container`, when it is shown (an inactive tab's panel is `hidden`). */
|
|
7
|
+
const visibleEditor = (container) => {
|
|
8
|
+
const editor = container?.querySelector("[contenteditable=\"true\"]");
|
|
9
|
+
if (!editor?.getClientRects().length) return null;
|
|
10
|
+
return editor.closest("[hidden], [inert]") ? null : editor;
|
|
11
|
+
};
|
|
12
|
+
/** `/` focuses the description editor, unless it is read-only or not shown (another panel's may be). */
|
|
13
|
+
const useSlashFocus = (containerRef, readonly) => usePageHotkey("/", () => visibleEditor(containerRef.current)?.focus(), {
|
|
14
|
+
useKey: true,
|
|
15
|
+
when: () => !readonly && visibleEditor(containerRef.current) !== null
|
|
16
|
+
});
|
|
17
|
+
/** A record's description as a full-size tab, saved when the editor loses focus. */
|
|
18
|
+
const PanelDescriptionEditor = ({ value, scope, readonly, isHTML, onSave }) => {
|
|
19
|
+
const { containerRef, onChange } = useSaveOnLeave({
|
|
20
|
+
value,
|
|
21
|
+
readonly,
|
|
22
|
+
onSave
|
|
23
|
+
});
|
|
24
|
+
useSlashFocus(containerRef, readonly);
|
|
25
|
+
return /* @__PURE__ */ jsx("div", {
|
|
26
|
+
ref: containerRef,
|
|
27
|
+
className: "flex min-h-0 flex-1 flex-col p-3",
|
|
28
|
+
children: /* @__PURE__ */ jsx(Editor, {
|
|
29
|
+
initialContent: value,
|
|
30
|
+
onChange,
|
|
31
|
+
scope,
|
|
32
|
+
readonly,
|
|
33
|
+
isHTML,
|
|
34
|
+
variant: "default",
|
|
35
|
+
className: "h-full min-h-0 flex-1 [&_.bn-container]:h-full [&_.bn-editor]:min-h-full"
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
export { PanelDescriptionEditor };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const PanelDescriptionField: ({ label, value, scope, readonly, isHTML, onSave }: {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
scope: string;
|
|
5
|
+
readonly?: boolean;
|
|
6
|
+
/** Stores HTML instead of the editor's blocks. */
|
|
7
|
+
isHTML?: boolean;
|
|
8
|
+
onSave: (value: string) => void;
|
|
9
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Editor } from "../blocks/components/LazyEditor.js";
|
|
2
|
+
import { useSaveOnLeave } from "./useSaveOnLeave.js";
|
|
3
|
+
import { IconAlignLeft } from "@tabler/icons-react";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/modules/record-panel/PanelDescriptionField.tsx
|
|
6
|
+
const PanelDescriptionField = ({ label, value, scope, readonly, isHTML, onSave }) => {
|
|
7
|
+
const { containerRef, onChange } = useSaveOnLeave({
|
|
8
|
+
value,
|
|
9
|
+
readonly,
|
|
10
|
+
onSave
|
|
11
|
+
});
|
|
12
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
13
|
+
className: "flex flex-col gap-1.5 pt-2",
|
|
14
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
15
|
+
className: "flex items-center gap-1.5 text-xs font-medium text-accent-foreground",
|
|
16
|
+
children: [/* @__PURE__ */ jsx(IconAlignLeft, {
|
|
17
|
+
className: "size-3.5 shrink-0",
|
|
18
|
+
"aria-hidden": "true"
|
|
19
|
+
}), label]
|
|
20
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
21
|
+
ref: containerRef,
|
|
22
|
+
children: /* @__PURE__ */ jsx(Editor, {
|
|
23
|
+
initialContent: value,
|
|
24
|
+
onChange,
|
|
25
|
+
scope,
|
|
26
|
+
label,
|
|
27
|
+
readonly,
|
|
28
|
+
isHTML,
|
|
29
|
+
variant: "ghost",
|
|
30
|
+
className: "h-auto min-h-20"
|
|
31
|
+
})
|
|
32
|
+
})]
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export { PanelDescriptionField };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RecordTableInlineCell } from "../record-table/components/RecordTableCellInline.js";
|
|
2
|
+
import { Icon } from "@tabler/icons-react";
|
|
3
|
+
export declare const PanelField: ({ label, icon: Icon, children, placeholder, htmlFor, cell }: {
|
|
4
|
+
label: React.ReactNode;
|
|
5
|
+
icon?: Icon;
|
|
6
|
+
placeholder?: React.ReactNode;
|
|
7
|
+
htmlFor?: string;
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
cell?: boolean;
|
|
10
|
+
}) => import("react").JSX.Element;
|
|
11
|
+
export declare const PanelFieldTrigger: (props: React.ComponentProps<typeof RecordTableInlineCell.Trigger>) => import("react").JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Label } from "../../components/label.js";
|
|
2
|
+
import { cn } from "../../lib/utils.js";
|
|
3
|
+
import { RecordTableInlineCell } from "../record-table/components/RecordTableCellInline.js";
|
|
4
|
+
import { PanelLabel } from "./PanelLabel.js";
|
|
5
|
+
import { IconForms } from "@tabler/icons-react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { useId } from "react";
|
|
8
|
+
// src/modules/record-panel/PanelField.tsx
|
|
9
|
+
const PanelField = ({ label, icon: Icon = IconForms, children, placeholder, htmlFor, cell = true }) => {
|
|
10
|
+
const labelId = useId();
|
|
11
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
12
|
+
className: "grid grid-cols-field items-center gap-x-2 min-h-7",
|
|
13
|
+
children: [/* @__PURE__ */ jsxs(Label, {
|
|
14
|
+
id: labelId,
|
|
15
|
+
htmlFor,
|
|
16
|
+
variant: "muted",
|
|
17
|
+
className: "flex min-w-0 items-center",
|
|
18
|
+
children: [Icon && /* @__PURE__ */ jsx(Icon, {
|
|
19
|
+
className: "size-3.5 shrink-0",
|
|
20
|
+
"aria-hidden": "true"
|
|
21
|
+
}), /* @__PURE__ */ jsx(PanelLabel, { children: label })]
|
|
22
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
23
|
+
className: cn("relative min-w-0", cell && "text-xs [&_button:not([role=switch],[data-panel-inline])]:h-7 [&_button:not([role=switch])]:text-xs [&_input]:text-xs"),
|
|
24
|
+
children: [/* @__PURE__ */ jsx(RecordTableInlineCell.LabelledBy, {
|
|
25
|
+
value: labelId,
|
|
26
|
+
children
|
|
27
|
+
}), placeholder && /* @__PURE__ */ jsxs("span", {
|
|
28
|
+
className: "pointer-events-none absolute inset-y-0 left-2 flex items-center gap-1.5 text-xs text-muted-foreground",
|
|
29
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
30
|
+
className: "size-3.5 shrink-0",
|
|
31
|
+
"aria-hidden": "true"
|
|
32
|
+
}), placeholder]
|
|
33
|
+
})]
|
|
34
|
+
})]
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const PanelFieldTrigger = (props) => /* @__PURE__ */ jsx(RecordTableInlineCell.Trigger, {
|
|
38
|
+
variant: "field",
|
|
39
|
+
...props
|
|
40
|
+
});
|
|
41
|
+
export { PanelField, PanelFieldTrigger };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Icon } from "@tabler/icons-react";
|
|
2
|
+
/**
|
|
3
|
+
* One field of a record not created yet, laid out like `PanelField`: its
|
|
4
|
+
* label, then the input, with the field's error under it.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PanelFormRow: ({ label, icon: Icon, required, error, children }: {
|
|
7
|
+
label: React.ReactNode;
|
|
8
|
+
icon?: Icon;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
error?: string;
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
}) => import("react").JSX.Element;
|
|
13
|
+
/**
|
|
14
|
+
* The body and footer of a new record's form in the side panel: its rows,
|
|
15
|
+
* then Cancel and Save. Nothing is saved until Save.
|
|
16
|
+
*/
|
|
17
|
+
export declare const PanelFormLayout: ({ children, onCancel, saving, saveLabel }: {
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
onCancel: () => void;
|
|
20
|
+
saving?: boolean;
|
|
21
|
+
saveLabel?: string;
|
|
22
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Button } from "../../components/button.js";
|
|
2
|
+
import { Spinner } from "../../components/spinner.js";
|
|
3
|
+
import { RecordTableInlineCell } from "../record-table/components/RecordTableCellInline.js";
|
|
4
|
+
import { PanelLabel } from "./PanelLabel.js";
|
|
5
|
+
import { IconForms } from "@tabler/icons-react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { useId } from "react";
|
|
8
|
+
import { useTranslation } from "react-i18next";
|
|
9
|
+
// src/modules/record-panel/PanelForm.tsx
|
|
10
|
+
/**
|
|
11
|
+
* One field of a record not created yet, laid out like `PanelField`: its
|
|
12
|
+
* label, then the input, with the field's error under it.
|
|
13
|
+
*/
|
|
14
|
+
const PanelFormRow = ({ label, icon: Icon = IconForms, required, error, children }) => {
|
|
15
|
+
const labelId = useId();
|
|
16
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
17
|
+
className: "grid grid-cols-field items-center gap-x-2 gap-y-0.5 min-h-7",
|
|
18
|
+
children: [
|
|
19
|
+
/* @__PURE__ */ jsxs("span", {
|
|
20
|
+
id: labelId,
|
|
21
|
+
className: "flex min-w-0 items-center gap-1.5 text-xs font-medium text-accent-foreground",
|
|
22
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
23
|
+
className: "size-3.5 shrink-0",
|
|
24
|
+
"aria-hidden": "true"
|
|
25
|
+
}), /* @__PURE__ */ jsxs(PanelLabel, {
|
|
26
|
+
tooltip: label,
|
|
27
|
+
children: [label, required && /* @__PURE__ */ jsx("span", {
|
|
28
|
+
className: "text-destructive",
|
|
29
|
+
children: " *"
|
|
30
|
+
})]
|
|
31
|
+
})]
|
|
32
|
+
}),
|
|
33
|
+
/* @__PURE__ */ jsxs("div", {
|
|
34
|
+
className: "group/panel-value relative min-w-0 text-xs [&_button:not([role=switch])]:text-xs [&_input:placeholder-shown]:pl-7",
|
|
35
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
36
|
+
className: "pointer-events-none absolute left-2 top-1/2 z-1 hidden size-3.5 -translate-y-1/2 text-muted-foreground group-has-[input:placeholder-shown]/panel-value:block",
|
|
37
|
+
"aria-hidden": "true"
|
|
38
|
+
}), /* @__PURE__ */ jsx(RecordTableInlineCell.LabelledBy, {
|
|
39
|
+
value: labelId,
|
|
40
|
+
children
|
|
41
|
+
})]
|
|
42
|
+
}),
|
|
43
|
+
error && /* @__PURE__ */ jsx("span", {
|
|
44
|
+
className: "col-start-2 text-xs text-destructive",
|
|
45
|
+
children: error
|
|
46
|
+
})
|
|
47
|
+
]
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The body and footer of a new record's form in the side panel: its rows,
|
|
52
|
+
* then Cancel and Save. Nothing is saved until Save.
|
|
53
|
+
*/
|
|
54
|
+
const PanelFormLayout = ({ children, onCancel, saving, saveLabel }) => {
|
|
55
|
+
const { t } = useTranslation("common", { keyPrefix: "side-panel" });
|
|
56
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
57
|
+
className: "flex flex-1 min-h-0 flex-col",
|
|
58
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
59
|
+
className: "flex-1 min-h-0 overflow-y-auto",
|
|
60
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
61
|
+
className: "flex flex-col gap-1 p-3",
|
|
62
|
+
children
|
|
63
|
+
})
|
|
64
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
65
|
+
className: "flex shrink-0 justify-end gap-1 border-t bg-background p-2",
|
|
66
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
67
|
+
type: "button",
|
|
68
|
+
variant: "ghost",
|
|
69
|
+
size: "sm",
|
|
70
|
+
onClick: onCancel,
|
|
71
|
+
children: t("cancel", "Cancel")
|
|
72
|
+
}), /* @__PURE__ */ jsxs(Button, {
|
|
73
|
+
type: "submit",
|
|
74
|
+
size: "sm",
|
|
75
|
+
disabled: saving,
|
|
76
|
+
children: [saving && /* @__PURE__ */ jsx(Spinner, { size: "sm" }), saveLabel || t("save", "Save")]
|
|
77
|
+
})]
|
|
78
|
+
})]
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
export { PanelFormLayout, PanelFormRow };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Tooltip } from "../../components/tooltip.js";
|
|
2
|
+
import { cn } from "../../lib/utils.js";
|
|
3
|
+
import { usePanelExpanded } from "./panelExpansion.js";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
|
+
// src/modules/record-panel/PanelLabel.tsx
|
|
7
|
+
/** Whether the label is cut off; the observers see the clamp come and go with the panel width. */
|
|
8
|
+
const useIsClamped = () => {
|
|
9
|
+
const ref = useRef(null);
|
|
10
|
+
const [isClamped, setIsClamped] = useState(false);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const element = ref.current;
|
|
13
|
+
if (!element) return;
|
|
14
|
+
const check = () => setIsClamped(element.scrollHeight > element.clientHeight + 1);
|
|
15
|
+
const resizeObserver = new ResizeObserver(check);
|
|
16
|
+
const contentObserver = new MutationObserver(check);
|
|
17
|
+
check();
|
|
18
|
+
resizeObserver.observe(element);
|
|
19
|
+
contentObserver.observe(element, {
|
|
20
|
+
childList: true,
|
|
21
|
+
subtree: true,
|
|
22
|
+
characterData: true
|
|
23
|
+
});
|
|
24
|
+
return () => {
|
|
25
|
+
resizeObserver.disconnect();
|
|
26
|
+
contentObserver.disconnect();
|
|
27
|
+
};
|
|
28
|
+
}, []);
|
|
29
|
+
return {
|
|
30
|
+
ref,
|
|
31
|
+
isClamped
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const PanelLabel = ({ children, tooltip, className }) => {
|
|
35
|
+
const expanded = usePanelExpanded();
|
|
36
|
+
const { ref, isClamped } = useIsClamped();
|
|
37
|
+
const showTooltip = isClamped && !expanded;
|
|
38
|
+
return /* @__PURE__ */ jsx(Tooltip.Provider, {
|
|
39
|
+
delay: 100,
|
|
40
|
+
children: /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(Tooltip.Trigger, {
|
|
41
|
+
render: /* @__PURE__ */ jsx("span", { className: cn("my-1 block min-w-0 wrap-break-word", className) }),
|
|
42
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
43
|
+
ref,
|
|
44
|
+
className: cn("block", !expanded && "line-clamp-2"),
|
|
45
|
+
children
|
|
46
|
+
})
|
|
47
|
+
}), showTooltip && /* @__PURE__ */ jsx(Tooltip.Content, { children: tooltip ?? children })] })
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
export { PanelLabel };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ElementType, ReactNode } from "react";
|
|
2
|
+
/** Separates a record's fields, tags and linked records with plain headings. */
|
|
3
|
+
export declare const PanelSection: ({ title, icon: Icon, children, nested }: {
|
|
4
|
+
title: string;
|
|
5
|
+
/** Beside the title, as a plugin's section has it. */
|
|
6
|
+
icon?: ElementType;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
nested?: boolean;
|
|
9
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { cn } from "../../lib/utils.js";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
// src/modules/record-panel/PanelSection.tsx
|
|
4
|
+
/** Separates a record's fields, tags and linked records with plain headings. */
|
|
5
|
+
const PanelSection = ({ title, icon: Icon, children, nested = false }) => /* @__PURE__ */ jsxs("section", {
|
|
6
|
+
className: cn("pt-1", !nested && "border-b last:border-b-0"),
|
|
7
|
+
children: [/* @__PURE__ */ jsxs("h3", {
|
|
8
|
+
className: cn("flex items-center gap-1.5 text-xs", nested ? "h-7 px-1 font-normal text-muted-foreground" : "h-10 px-3 font-medium"),
|
|
9
|
+
children: [Icon && /* @__PURE__ */ jsx(Icon, {
|
|
10
|
+
className: "size-3.5 flex-none text-muted-foreground",
|
|
11
|
+
"aria-hidden": "true"
|
|
12
|
+
}), title]
|
|
13
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
14
|
+
className: cn("min-w-0", nested ? "pb-1" : "px-3 pb-2"),
|
|
15
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
16
|
+
className: "flex min-w-0 flex-col gap-1",
|
|
17
|
+
children
|
|
18
|
+
})
|
|
19
|
+
})]
|
|
20
|
+
});
|
|
21
|
+
export { PanelSection };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Whether the nearest record panel fills a page, and how to switch it. */
|
|
2
|
+
type PanelExpansion = {
|
|
3
|
+
expanded: boolean;
|
|
4
|
+
toggle?: () => void;
|
|
5
|
+
} | null;
|
|
6
|
+
/** Provided by the host's record panel; erxes-ui's panel parts read it. */
|
|
7
|
+
export declare const PanelExpansionContext: import("react").Context<PanelExpansion>;
|
|
8
|
+
/** Whether the record is shown at full size, on its own page: a slot can lay out wider. */
|
|
9
|
+
export declare const usePanelExpanded: () => boolean;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
// src/modules/record-panel/panelExpansion.ts
|
|
3
|
+
/** Provided by the host's record panel; erxes-ui's panel parts read it. */
|
|
4
|
+
const PanelExpansionContext = createContext(null);
|
|
5
|
+
/** Whether the record is shown at full size, on its own page: a slot can lay out wider. */
|
|
6
|
+
const usePanelExpanded = () => useContext(PanelExpansionContext)?.expanded ?? false;
|
|
7
|
+
export { PanelExpansionContext, usePanelExpanded };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Saves a description editor when you click or tab anywhere outside it, never while
|
|
3
|
+
* typing. Focus can't be trusted to leave the editor first: closing the image preview
|
|
4
|
+
* or a toolbar menu drops it on the page. An edit that arrives while focus is already
|
|
5
|
+
* outside, such as an upload that finishes after you moved on, saves right away.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useSaveOnLeave: ({ value, readonly, onSave }: {
|
|
8
|
+
value: string;
|
|
9
|
+
readonly?: boolean;
|
|
10
|
+
onSave: (value: string) => void;
|
|
11
|
+
}) => {
|
|
12
|
+
containerRef: import("react").RefObject<HTMLDivElement | null>;
|
|
13
|
+
onChange: (next: string) => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
// src/modules/record-panel/useSaveOnLeave.ts
|
|
3
|
+
/**
|
|
4
|
+
* Saves a description editor when you click or tab anywhere outside it, never while
|
|
5
|
+
* typing. Focus can't be trusted to leave the editor first: closing the image preview
|
|
6
|
+
* or a toolbar menu drops it on the page. An edit that arrives while focus is already
|
|
7
|
+
* outside, such as an upload that finishes after you moved on, saves right away.
|
|
8
|
+
*/
|
|
9
|
+
const useSaveOnLeave = ({ value, readonly, onSave }) => {
|
|
10
|
+
const containerRef = useRef(null);
|
|
11
|
+
const latest = useRef(value);
|
|
12
|
+
const saved = useRef(value);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
latest.current = value;
|
|
15
|
+
saved.current = value;
|
|
16
|
+
}, [value]);
|
|
17
|
+
const save = () => {
|
|
18
|
+
if (readonly || latest.current === saved.current) return;
|
|
19
|
+
saved.current = latest.current;
|
|
20
|
+
onSave(latest.current);
|
|
21
|
+
};
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const leave = (event) => {
|
|
24
|
+
if (event.target instanceof Node && containerRef.current?.contains(event.target)) return;
|
|
25
|
+
save();
|
|
26
|
+
};
|
|
27
|
+
document.addEventListener("pointerdown", leave, true);
|
|
28
|
+
document.addEventListener("focusin", leave);
|
|
29
|
+
return () => {
|
|
30
|
+
document.removeEventListener("pointerdown", leave, true);
|
|
31
|
+
document.removeEventListener("focusin", leave);
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
containerRef,
|
|
36
|
+
onChange: (next) => {
|
|
37
|
+
latest.current = next;
|
|
38
|
+
if (!containerRef.current?.contains(document.activeElement)) save();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export { useSaveOnLeave };
|