@cfast/joy 0.1.0 → 0.2.0
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/dist/index.d.ts +32 -3
- package/dist/index.js +572 -104
- package/llms.txt +1 -0
- package/package.json +37 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode, ReactElement } from 'react';
|
|
2
|
-
import { ButtonProps } from
|
|
2
|
+
import { ButtonProps } from "@mui/joy";
|
|
3
3
|
import { ActionHookResult } from '@cfast/actions/client';
|
|
4
|
-
import { WhenForbidden, ConfirmOptions, ConfirmDialogSlotProps, FormStatusProps, EmptyStateProps, BreadcrumbItem, TabItem, AppShellProps, NavigationItem, UserMenuProps, DataTableProps, FilterBarProps, BulkAction, DropZoneProps, ImagePreviewProps, FileListProps, ListViewProps, DetailViewProps, AvatarWithInitialsProps, RoleBadgeProps, ImpersonationBannerProps } from '@cfast/ui';
|
|
4
|
+
import { WhenForbidden, ConfirmOptions, ConfirmDialogSlotProps, FormStatusProps, EmptyStateProps, BreadcrumbItem, TabItem, AppShellProps, NavigationItem, UserMenuProps, DataTableProps, FilterBarProps, BulkAction, DropZoneProps, ImagePreviewProps, FileListProps, UploadFieldProps, ListViewProps, DetailViewProps, AvatarWithInitialsProps, RoleBadgeProps, ImpersonationBannerProps } from '@cfast/ui';
|
|
5
5
|
export { PermissionGate } from '@cfast/ui';
|
|
6
6
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
7
7
|
|
|
@@ -124,6 +124,35 @@ declare function ImagePreview({ fileKey, src, getUrl, width, height, fallback, a
|
|
|
124
124
|
*/
|
|
125
125
|
declare function FileList({ files, onDownload, }: FileListProps): ReactElement;
|
|
126
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Joy UI styled drop zone + multi-file upload field.
|
|
129
|
+
*
|
|
130
|
+
* Same controlled API as the headless `@cfast/ui` `UploadField`: it accepts
|
|
131
|
+
* a `value` array of R2 keys and emits the new array via `onChange` whenever
|
|
132
|
+
* an upload completes or a file is removed. The visual layer uses Joy's
|
|
133
|
+
* `<Box>` (soft variant + dashed border), `<LinearProgress>` per file, and
|
|
134
|
+
* `<IconButton>` for removals.
|
|
135
|
+
*
|
|
136
|
+
* Re-exports the same {@link UploadFieldProps} type from `@cfast/ui` so
|
|
137
|
+
* consumers can swap implementations without changing prop usage.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```tsx
|
|
141
|
+
* import { UploadField } from "@cfast/joy";
|
|
142
|
+
*
|
|
143
|
+
* <UploadField
|
|
144
|
+
* filetype="productImages"
|
|
145
|
+
* basePath="/uploads"
|
|
146
|
+
* multiple
|
|
147
|
+
* maxFiles={10}
|
|
148
|
+
* accept="image/*"
|
|
149
|
+
* value={imageKeys}
|
|
150
|
+
* onChange={setImageKeys}
|
|
151
|
+
* />
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
declare function UploadField({ label, className, filetype, basePath, multiple, maxFiles, accept, maxSize, value, onChange, onError, disabled, uploader, }: UploadFieldProps): ReactElement;
|
|
155
|
+
|
|
127
156
|
/**
|
|
128
157
|
* Joy UI styled ListView — full page list with filters, table, and pagination.
|
|
129
158
|
*/
|
|
@@ -196,4 +225,4 @@ declare const joyLoginComponents: {
|
|
|
196
225
|
ErrorMessage: typeof ErrorMessage;
|
|
197
226
|
};
|
|
198
227
|
|
|
199
|
-
export { ActionButton, AppShell, AppShellHeader, AppShellSidebar, AvatarWithInitials, BulkActionBar, ConfirmDialog, DataTable, DetailView, DropZone, EmptyState, FileList, FilterBar, FormStatus, ImagePreview, ImpersonationBanner, ListView, NavigationProgress, PageContainer, RoleBadge, ToastProvider, UserMenu, joyLoginComponents };
|
|
228
|
+
export { ActionButton, AppShell, AppShellHeader, AppShellSidebar, AvatarWithInitials, BulkActionBar, ConfirmDialog, DataTable, DetailView, DropZone, EmptyState, FileList, FilterBar, FormStatus, ImagePreview, ImpersonationBanner, ListView, NavigationProgress, PageContainer, RoleBadge, ToastProvider, UploadField, UserMenu, joyLoginComponents };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/action-button.tsx
|
|
2
2
|
import "react";
|
|
3
|
-
import JoyButton from "@mui/joy
|
|
4
|
-
import JoyTooltip from "@mui/joy
|
|
3
|
+
import { Button as JoyButton } from "@mui/joy";
|
|
4
|
+
import { Tooltip as JoyTooltip } from "@mui/joy";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
function ActionButton({
|
|
7
7
|
action,
|
|
@@ -42,11 +42,11 @@ function ActionButton({
|
|
|
42
42
|
|
|
43
43
|
// src/confirm-dialog.tsx
|
|
44
44
|
import "react";
|
|
45
|
-
import Modal from "@mui/joy
|
|
46
|
-
import ModalDialog from "@mui/joy
|
|
47
|
-
import Typography from "@mui/joy
|
|
48
|
-
import Button from "@mui/joy
|
|
49
|
-
import Stack from "@mui/joy
|
|
45
|
+
import { Modal } from "@mui/joy";
|
|
46
|
+
import { ModalDialog } from "@mui/joy";
|
|
47
|
+
import { Typography } from "@mui/joy";
|
|
48
|
+
import { Button } from "@mui/joy";
|
|
49
|
+
import { Stack } from "@mui/joy";
|
|
50
50
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
51
51
|
function ConfirmDialog({
|
|
52
52
|
open,
|
|
@@ -108,8 +108,8 @@ function ToastProvider({ children }) {
|
|
|
108
108
|
|
|
109
109
|
// src/form-status.tsx
|
|
110
110
|
import "react";
|
|
111
|
-
import Alert from "@mui/joy
|
|
112
|
-
import Stack2 from "@mui/joy
|
|
111
|
+
import { Alert } from "@mui/joy";
|
|
112
|
+
import { Stack as Stack2 } from "@mui/joy";
|
|
113
113
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
114
114
|
function FormStatus({ data }) {
|
|
115
115
|
if (!data) return null;
|
|
@@ -140,9 +140,9 @@ function FormStatus({ data }) {
|
|
|
140
140
|
|
|
141
141
|
// src/empty-state.tsx
|
|
142
142
|
import "react";
|
|
143
|
-
import Typography2 from "@mui/joy
|
|
144
|
-
import Button2 from "@mui/joy
|
|
145
|
-
import Stack3 from "@mui/joy
|
|
143
|
+
import { Typography as Typography2 } from "@mui/joy";
|
|
144
|
+
import { Button as Button2 } from "@mui/joy";
|
|
145
|
+
import { Stack as Stack3 } from "@mui/joy";
|
|
146
146
|
import { useActionStatus } from "@cfast/ui";
|
|
147
147
|
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
148
148
|
function EmptyState({
|
|
@@ -191,7 +191,7 @@ function EmptyStateWithAction({
|
|
|
191
191
|
|
|
192
192
|
// src/navigation-progress.tsx
|
|
193
193
|
import "react";
|
|
194
|
-
import LinearProgress from "@mui/joy
|
|
194
|
+
import { LinearProgress } from "@mui/joy";
|
|
195
195
|
import { useNavigation } from "react-router";
|
|
196
196
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
197
197
|
function NavigationProgress() {
|
|
@@ -218,10 +218,10 @@ function NavigationProgress() {
|
|
|
218
218
|
|
|
219
219
|
// src/page-container.tsx
|
|
220
220
|
import "react";
|
|
221
|
-
import Typography3 from "@mui/joy
|
|
222
|
-
import Breadcrumbs from "@mui/joy
|
|
221
|
+
import { Typography as Typography3 } from "@mui/joy";
|
|
222
|
+
import { Breadcrumbs } from "@mui/joy";
|
|
223
223
|
import { Link } from "react-router";
|
|
224
|
-
import Stack4 from "@mui/joy
|
|
224
|
+
import { Stack as Stack4 } from "@mui/joy";
|
|
225
225
|
import { Fragment, jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
226
226
|
function PageContainer({
|
|
227
227
|
title,
|
|
@@ -244,10 +244,10 @@ function PageContainer({
|
|
|
244
244
|
|
|
245
245
|
// src/app-shell.tsx
|
|
246
246
|
import "react";
|
|
247
|
-
import Sheet from "@mui/joy
|
|
248
|
-
import List from "@mui/joy
|
|
249
|
-
import ListItem from "@mui/joy
|
|
250
|
-
import ListItemButton from "@mui/joy
|
|
247
|
+
import { Sheet } from "@mui/joy";
|
|
248
|
+
import { List } from "@mui/joy";
|
|
249
|
+
import { ListItem } from "@mui/joy";
|
|
250
|
+
import { ListItemButton } from "@mui/joy";
|
|
251
251
|
import { Link as Link2 } from "react-router";
|
|
252
252
|
import { useActionStatus as useActionStatus2 } from "@cfast/ui";
|
|
253
253
|
import { Fragment as Fragment2, jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
@@ -322,19 +322,19 @@ AppShell.Header = AppShellHeader;
|
|
|
322
322
|
|
|
323
323
|
// src/user-menu.tsx
|
|
324
324
|
import "react";
|
|
325
|
-
import Avatar from "@mui/joy
|
|
326
|
-
import Dropdown from "@mui/joy
|
|
327
|
-
import Menu from "@mui/joy
|
|
328
|
-
import MenuItem from "@mui/joy
|
|
329
|
-
import MenuButton from "@mui/joy
|
|
330
|
-
import IconButton from "@mui/joy
|
|
325
|
+
import { Avatar } from "@mui/joy";
|
|
326
|
+
import { Dropdown } from "@mui/joy";
|
|
327
|
+
import { Menu } from "@mui/joy";
|
|
328
|
+
import { MenuItem } from "@mui/joy";
|
|
329
|
+
import { MenuButton } from "@mui/joy";
|
|
330
|
+
import { IconButton } from "@mui/joy";
|
|
331
331
|
import { Link as Link3 } from "react-router";
|
|
332
332
|
import { useCurrentUser } from "@cfast/auth/client";
|
|
333
333
|
import { getInitials, useActionStatus as useActionStatus3 } from "@cfast/ui";
|
|
334
334
|
|
|
335
335
|
// src/role-badge.tsx
|
|
336
336
|
import "react";
|
|
337
|
-
import Chip from "@mui/joy
|
|
337
|
+
import { Chip } from "@mui/joy";
|
|
338
338
|
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
339
339
|
var VALID_COLORS = /* @__PURE__ */ new Set(["primary", "neutral", "danger", "success", "warning"]);
|
|
340
340
|
var defaultColors = {
|
|
@@ -389,9 +389,9 @@ function PermissionFilteredLink({ link }) {
|
|
|
389
389
|
|
|
390
390
|
// src/data-table.tsx
|
|
391
391
|
import { useState, useCallback as useCallback2 } from "react";
|
|
392
|
-
import JoyTable from "@mui/joy
|
|
393
|
-
import JoySheet from "@mui/joy
|
|
394
|
-
import JoyCheckbox from "@mui/joy
|
|
392
|
+
import { Table as JoyTable } from "@mui/joy";
|
|
393
|
+
import { Sheet as JoySheet } from "@mui/joy";
|
|
394
|
+
import { Checkbox as JoyCheckbox } from "@mui/joy";
|
|
395
395
|
import { getField, getRecordId } from "@cfast/ui";
|
|
396
396
|
import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
397
397
|
function normalizeColumns(columns) {
|
|
@@ -508,10 +508,10 @@ function defaultGetId(row) {
|
|
|
508
508
|
// src/filter-bar.tsx
|
|
509
509
|
import { useCallback as useCallback3 } from "react";
|
|
510
510
|
import { useSearchParams, useNavigate, useLocation } from "react-router";
|
|
511
|
-
import JoyInput from "@mui/joy
|
|
512
|
-
import JoySelect from "@mui/joy
|
|
513
|
-
import JoyOption from "@mui/joy
|
|
514
|
-
import JoyStack from "@mui/joy
|
|
511
|
+
import { Input as JoyInput } from "@mui/joy";
|
|
512
|
+
import { Select as JoySelect } from "@mui/joy";
|
|
513
|
+
import { Option as JoyOption } from "@mui/joy";
|
|
514
|
+
import { Stack as JoyStack } from "@mui/joy";
|
|
515
515
|
import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
516
516
|
function FilterBar({
|
|
517
517
|
filters,
|
|
@@ -595,10 +595,10 @@ function JoyFilterInput({
|
|
|
595
595
|
|
|
596
596
|
// src/bulk-action-bar.tsx
|
|
597
597
|
import "react";
|
|
598
|
-
import JoySheet2 from "@mui/joy
|
|
599
|
-
import JoyStack2 from "@mui/joy
|
|
600
|
-
import JoyButton2 from "@mui/joy
|
|
601
|
-
import JoyTypography from "@mui/joy
|
|
598
|
+
import { Sheet as JoySheet2 } from "@mui/joy";
|
|
599
|
+
import { Stack as JoyStack2 } from "@mui/joy";
|
|
600
|
+
import { Button as JoyButton2 } from "@mui/joy";
|
|
601
|
+
import { Typography as JoyTypography } from "@mui/joy";
|
|
602
602
|
import { jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
603
603
|
function BulkActionBar({
|
|
604
604
|
selectedCount,
|
|
@@ -656,9 +656,9 @@ function BulkActionBar({
|
|
|
656
656
|
|
|
657
657
|
// src/drop-zone.tsx
|
|
658
658
|
import { useState as useState2, useCallback as useCallback4, useRef } from "react";
|
|
659
|
-
import JoySheet3 from "@mui/joy
|
|
660
|
-
import JoyTypography2 from "@mui/joy
|
|
661
|
-
import JoyLinearProgress from "@mui/joy
|
|
659
|
+
import { Sheet as JoySheet3 } from "@mui/joy";
|
|
660
|
+
import { Typography as JoyTypography2 } from "@mui/joy";
|
|
661
|
+
import { LinearProgress as JoyLinearProgress } from "@mui/joy";
|
|
662
662
|
import { jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
663
663
|
function DropZone({
|
|
664
664
|
upload,
|
|
@@ -748,8 +748,8 @@ function DropZone({
|
|
|
748
748
|
|
|
749
749
|
// src/image-preview.tsx
|
|
750
750
|
import "react";
|
|
751
|
-
import JoyAspectRatio from "@mui/joy
|
|
752
|
-
import JoyTypography3 from "@mui/joy
|
|
751
|
+
import { AspectRatio as JoyAspectRatio } from "@mui/joy";
|
|
752
|
+
import { Typography as JoyTypography3 } from "@mui/joy";
|
|
753
753
|
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
754
754
|
function ImagePreview({
|
|
755
755
|
fileKey,
|
|
@@ -790,11 +790,11 @@ function ImagePreview({
|
|
|
790
790
|
|
|
791
791
|
// src/file-list.tsx
|
|
792
792
|
import "react";
|
|
793
|
-
import JoyList from "@mui/joy
|
|
794
|
-
import JoyListItem from "@mui/joy
|
|
795
|
-
import JoyListItemContent from "@mui/joy
|
|
796
|
-
import JoyTypography4 from "@mui/joy
|
|
797
|
-
import JoyButton3 from "@mui/joy
|
|
793
|
+
import { List as JoyList } from "@mui/joy";
|
|
794
|
+
import { ListItem as JoyListItem } from "@mui/joy";
|
|
795
|
+
import { ListItemContent as JoyListItemContent } from "@mui/joy";
|
|
796
|
+
import { Typography as JoyTypography4 } from "@mui/joy";
|
|
797
|
+
import { Button as JoyButton3 } from "@mui/joy";
|
|
798
798
|
import { jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
799
799
|
function formatBytes(bytes) {
|
|
800
800
|
if (bytes < 1024) return `${bytes} B`;
|
|
@@ -825,13 +825,480 @@ function FileList({
|
|
|
825
825
|
] }, file.key)) });
|
|
826
826
|
}
|
|
827
827
|
|
|
828
|
+
// src/upload-field.tsx
|
|
829
|
+
import { useCallback as useCallback5, useId, useRef as useRef2, useState as useState3 } from "react";
|
|
830
|
+
import { Box as JoyBox } from "@mui/joy";
|
|
831
|
+
import { Typography as JoyTypography5 } from "@mui/joy";
|
|
832
|
+
import { LinearProgress as JoyLinearProgress2 } from "@mui/joy";
|
|
833
|
+
import { IconButton as JoyIconButton } from "@mui/joy";
|
|
834
|
+
import { Stack as JoyStack3 } from "@mui/joy";
|
|
835
|
+
import { FormLabel as JoyFormLabel } from "@mui/joy";
|
|
836
|
+
import { jsx as jsx17, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
837
|
+
function defaultUploader(file, options) {
|
|
838
|
+
return new Promise((resolve, reject) => {
|
|
839
|
+
const xhr = new XMLHttpRequest();
|
|
840
|
+
xhr.open("POST", options.url);
|
|
841
|
+
xhr.upload.addEventListener("progress", (event) => {
|
|
842
|
+
if (event.lengthComputable) {
|
|
843
|
+
options.onProgress(Math.round(event.loaded / event.total * 100));
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
xhr.addEventListener("load", () => {
|
|
847
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
848
|
+
try {
|
|
849
|
+
const parsed = JSON.parse(xhr.responseText);
|
|
850
|
+
if (typeof parsed.key === "string" && typeof parsed.size === "number" && typeof parsed.type === "string") {
|
|
851
|
+
resolve({
|
|
852
|
+
key: parsed.key,
|
|
853
|
+
size: parsed.size,
|
|
854
|
+
type: parsed.type,
|
|
855
|
+
url: typeof parsed.url === "string" ? parsed.url : void 0
|
|
856
|
+
});
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
reject(new Error("Invalid response from server"));
|
|
860
|
+
} catch {
|
|
861
|
+
reject(new Error("Invalid response from server"));
|
|
862
|
+
}
|
|
863
|
+
} else {
|
|
864
|
+
try {
|
|
865
|
+
const parsed = JSON.parse(xhr.responseText);
|
|
866
|
+
const detail = typeof parsed.detail === "string" ? parsed.detail : typeof parsed.message === "string" ? parsed.message : `Upload failed (${xhr.status})`;
|
|
867
|
+
reject(new Error(detail));
|
|
868
|
+
} catch {
|
|
869
|
+
reject(new Error(`Upload failed (${xhr.status})`));
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
xhr.addEventListener("error", () => {
|
|
874
|
+
reject(new Error("Network error during upload"));
|
|
875
|
+
});
|
|
876
|
+
if (options.signal) {
|
|
877
|
+
options.signal.addEventListener("abort", () => {
|
|
878
|
+
xhr.abort();
|
|
879
|
+
reject(new Error("Upload cancelled"));
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
const formData = new FormData();
|
|
883
|
+
formData.append("file", file);
|
|
884
|
+
xhr.send(formData);
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
function matchesAccept(file, accept) {
|
|
888
|
+
if (!accept) return true;
|
|
889
|
+
const tokens = accept.split(",").map((t) => t.trim().toLowerCase()).filter(Boolean);
|
|
890
|
+
if (tokens.length === 0) return true;
|
|
891
|
+
const fileType = (file.type || "").toLowerCase();
|
|
892
|
+
const fileName = file.name.toLowerCase();
|
|
893
|
+
for (const token of tokens) {
|
|
894
|
+
if (token.startsWith(".")) {
|
|
895
|
+
if (fileName.endsWith(token)) return true;
|
|
896
|
+
} else if (token.endsWith("/*")) {
|
|
897
|
+
const prefix = token.slice(0, -1);
|
|
898
|
+
if (fileType.startsWith(prefix)) return true;
|
|
899
|
+
} else if (token === fileType) {
|
|
900
|
+
return true;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
return false;
|
|
904
|
+
}
|
|
905
|
+
function formatBytes2(bytes) {
|
|
906
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
907
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
908
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
909
|
+
}
|
|
910
|
+
function looksLikeImageKey(key) {
|
|
911
|
+
return /\.(png|jpe?g|webp|gif|avif|svg)(\?|$)/i.test(key);
|
|
912
|
+
}
|
|
913
|
+
function UploadField({
|
|
914
|
+
label,
|
|
915
|
+
className,
|
|
916
|
+
filetype,
|
|
917
|
+
basePath = "/uploads",
|
|
918
|
+
multiple = false,
|
|
919
|
+
maxFiles,
|
|
920
|
+
accept,
|
|
921
|
+
maxSize,
|
|
922
|
+
value,
|
|
923
|
+
onChange,
|
|
924
|
+
onError,
|
|
925
|
+
disabled = false,
|
|
926
|
+
uploader = defaultUploader
|
|
927
|
+
}) {
|
|
928
|
+
const [files, setFiles] = useState3([]);
|
|
929
|
+
const [isDragOver, setIsDragOver] = useState3(false);
|
|
930
|
+
const [globalError, setGlobalError] = useState3(null);
|
|
931
|
+
const inputRef = useRef2(null);
|
|
932
|
+
const reactId = useId();
|
|
933
|
+
const normalizedBase = `/${basePath.replace(/^\/+|\/+$/g, "")}`;
|
|
934
|
+
const uploadUrl = `${normalizedBase}/${filetype}`;
|
|
935
|
+
const effectiveMax = maxFiles ?? (multiple ? Number.POSITIVE_INFINITY : 1);
|
|
936
|
+
const currentValue = value ?? [];
|
|
937
|
+
const appendKey = useCallback5(
|
|
938
|
+
(key) => {
|
|
939
|
+
const next = [...currentValue, key];
|
|
940
|
+
onChange?.(next);
|
|
941
|
+
},
|
|
942
|
+
[currentValue, onChange]
|
|
943
|
+
);
|
|
944
|
+
const removeKey = useCallback5(
|
|
945
|
+
(key) => {
|
|
946
|
+
const next = currentValue.filter((k) => k !== key);
|
|
947
|
+
onChange?.(next);
|
|
948
|
+
},
|
|
949
|
+
[currentValue, onChange]
|
|
950
|
+
);
|
|
951
|
+
const removeTrackerEntry = useCallback5((id) => {
|
|
952
|
+
setFiles((prev) => prev.filter((f) => f.id !== id));
|
|
953
|
+
}, []);
|
|
954
|
+
const handleFiles = useCallback5(
|
|
955
|
+
async (incoming) => {
|
|
956
|
+
if (disabled) return;
|
|
957
|
+
setGlobalError(null);
|
|
958
|
+
const list = Array.from(incoming);
|
|
959
|
+
if (list.length === 0) return;
|
|
960
|
+
const inFlight = files.filter((f) => f.status !== "error").length;
|
|
961
|
+
const remainingSlots = effectiveMax - currentValue.length - inFlight;
|
|
962
|
+
if (remainingSlots <= 0) {
|
|
963
|
+
setGlobalError(
|
|
964
|
+
`Maximum of ${effectiveMax} file${effectiveMax === 1 ? "" : "s"} reached`
|
|
965
|
+
);
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
if (list.length > remainingSlots) {
|
|
969
|
+
setGlobalError(
|
|
970
|
+
`Only ${remainingSlots} more file${remainingSlots === 1 ? "" : "s"} allowed`
|
|
971
|
+
);
|
|
972
|
+
list.length = remainingSlots;
|
|
973
|
+
}
|
|
974
|
+
const accepted = [];
|
|
975
|
+
for (const file of list) {
|
|
976
|
+
const id = `${reactId}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
977
|
+
if (!matchesAccept(file, accept)) {
|
|
978
|
+
const errEntry = {
|
|
979
|
+
id,
|
|
980
|
+
name: file.name,
|
|
981
|
+
size: file.size,
|
|
982
|
+
type: file.type,
|
|
983
|
+
progress: 0,
|
|
984
|
+
status: "error",
|
|
985
|
+
error: `${file.type || "file"} is not an accepted type`
|
|
986
|
+
};
|
|
987
|
+
accepted.push({ entry: errEntry, file });
|
|
988
|
+
onError?.(errEntry);
|
|
989
|
+
continue;
|
|
990
|
+
}
|
|
991
|
+
if (maxSize != null && file.size > maxSize) {
|
|
992
|
+
const errEntry = {
|
|
993
|
+
id,
|
|
994
|
+
name: file.name,
|
|
995
|
+
size: file.size,
|
|
996
|
+
type: file.type,
|
|
997
|
+
progress: 0,
|
|
998
|
+
status: "error",
|
|
999
|
+
error: `File is ${formatBytes2(file.size)} but max is ${formatBytes2(maxSize)}`
|
|
1000
|
+
};
|
|
1001
|
+
accepted.push({ entry: errEntry, file });
|
|
1002
|
+
onError?.(errEntry);
|
|
1003
|
+
continue;
|
|
1004
|
+
}
|
|
1005
|
+
accepted.push({
|
|
1006
|
+
entry: {
|
|
1007
|
+
id,
|
|
1008
|
+
name: file.name,
|
|
1009
|
+
size: file.size,
|
|
1010
|
+
type: file.type,
|
|
1011
|
+
progress: 0,
|
|
1012
|
+
status: "pending"
|
|
1013
|
+
},
|
|
1014
|
+
file
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
setFiles((prev) => [...prev, ...accepted.map((a) => a.entry)]);
|
|
1018
|
+
for (const { entry, file } of accepted) {
|
|
1019
|
+
if (entry.status === "error") continue;
|
|
1020
|
+
setFiles(
|
|
1021
|
+
(prev) => prev.map(
|
|
1022
|
+
(f) => f.id === entry.id ? { ...f, status: "uploading" } : f
|
|
1023
|
+
)
|
|
1024
|
+
);
|
|
1025
|
+
try {
|
|
1026
|
+
const result = await uploader(file, {
|
|
1027
|
+
url: uploadUrl,
|
|
1028
|
+
onProgress: (percent) => {
|
|
1029
|
+
setFiles(
|
|
1030
|
+
(prev) => prev.map(
|
|
1031
|
+
(f) => f.id === entry.id ? { ...f, progress: percent } : f
|
|
1032
|
+
)
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
});
|
|
1036
|
+
setFiles(
|
|
1037
|
+
(prev) => prev.map(
|
|
1038
|
+
(f) => f.id === entry.id ? { ...f, status: "success", progress: 100, key: result.key } : f
|
|
1039
|
+
)
|
|
1040
|
+
);
|
|
1041
|
+
appendKey(result.key);
|
|
1042
|
+
setFiles((prev) => prev.filter((f) => f.id !== entry.id));
|
|
1043
|
+
} catch (e) {
|
|
1044
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
1045
|
+
const errEntry = {
|
|
1046
|
+
...entry,
|
|
1047
|
+
status: "error",
|
|
1048
|
+
error: message
|
|
1049
|
+
};
|
|
1050
|
+
setFiles(
|
|
1051
|
+
(prev) => prev.map((f) => f.id === entry.id ? errEntry : f)
|
|
1052
|
+
);
|
|
1053
|
+
onError?.(errEntry);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
},
|
|
1057
|
+
[
|
|
1058
|
+
accept,
|
|
1059
|
+
appendKey,
|
|
1060
|
+
currentValue.length,
|
|
1061
|
+
disabled,
|
|
1062
|
+
effectiveMax,
|
|
1063
|
+
files,
|
|
1064
|
+
maxSize,
|
|
1065
|
+
onError,
|
|
1066
|
+
reactId,
|
|
1067
|
+
uploadUrl,
|
|
1068
|
+
uploader
|
|
1069
|
+
]
|
|
1070
|
+
);
|
|
1071
|
+
const handleDrop = useCallback5(
|
|
1072
|
+
(e) => {
|
|
1073
|
+
e.preventDefault();
|
|
1074
|
+
setIsDragOver(false);
|
|
1075
|
+
void handleFiles(e.dataTransfer.files);
|
|
1076
|
+
},
|
|
1077
|
+
[handleFiles]
|
|
1078
|
+
);
|
|
1079
|
+
const handleDragOver = useCallback5(
|
|
1080
|
+
(e) => {
|
|
1081
|
+
e.preventDefault();
|
|
1082
|
+
if (!disabled) setIsDragOver(true);
|
|
1083
|
+
},
|
|
1084
|
+
[disabled]
|
|
1085
|
+
);
|
|
1086
|
+
const handleDragLeave = useCallback5(() => {
|
|
1087
|
+
setIsDragOver(false);
|
|
1088
|
+
}, []);
|
|
1089
|
+
const handleClick = useCallback5(() => {
|
|
1090
|
+
if (disabled) return;
|
|
1091
|
+
inputRef.current?.click();
|
|
1092
|
+
}, [disabled]);
|
|
1093
|
+
return /* @__PURE__ */ jsxs12(JoyBox, { className, "data-cfast-upload-field": filetype, children: [
|
|
1094
|
+
label != null ? /* @__PURE__ */ jsx17(JoyFormLabel, { htmlFor: `${reactId}-input`, sx: { mb: 0.5 }, children: label }) : null,
|
|
1095
|
+
/* @__PURE__ */ jsx17(
|
|
1096
|
+
JoyBox,
|
|
1097
|
+
{
|
|
1098
|
+
role: "button",
|
|
1099
|
+
tabIndex: disabled ? -1 : 0,
|
|
1100
|
+
"aria-disabled": disabled,
|
|
1101
|
+
"data-drag-over": isDragOver,
|
|
1102
|
+
"data-testid": "upload-field-drop-zone",
|
|
1103
|
+
onClick: handleClick,
|
|
1104
|
+
onDrop: handleDrop,
|
|
1105
|
+
onDragOver: handleDragOver,
|
|
1106
|
+
onDragLeave: handleDragLeave,
|
|
1107
|
+
onKeyDown: (e) => {
|
|
1108
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
1109
|
+
e.preventDefault();
|
|
1110
|
+
handleClick();
|
|
1111
|
+
}
|
|
1112
|
+
},
|
|
1113
|
+
sx: {
|
|
1114
|
+
borderStyle: "dashed",
|
|
1115
|
+
borderWidth: 2,
|
|
1116
|
+
borderColor: isDragOver ? "primary.400" : "neutral.outlinedBorder",
|
|
1117
|
+
borderRadius: "md",
|
|
1118
|
+
p: 4,
|
|
1119
|
+
textAlign: "center",
|
|
1120
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
1121
|
+
opacity: disabled ? 0.6 : 1,
|
|
1122
|
+
backgroundColor: "background.level1",
|
|
1123
|
+
transition: "border-color 0.2s",
|
|
1124
|
+
"&:hover": disabled ? void 0 : { borderColor: "primary.300" }
|
|
1125
|
+
},
|
|
1126
|
+
children: /* @__PURE__ */ jsx17(JoyTypography5, { level: "body-sm", color: "neutral", children: multiple ? "Drop files here or click to browse" : "Drop a file here or click to browse" })
|
|
1127
|
+
}
|
|
1128
|
+
),
|
|
1129
|
+
/* @__PURE__ */ jsx17(
|
|
1130
|
+
"input",
|
|
1131
|
+
{
|
|
1132
|
+
ref: inputRef,
|
|
1133
|
+
id: `${reactId}-input`,
|
|
1134
|
+
type: "file",
|
|
1135
|
+
accept,
|
|
1136
|
+
multiple,
|
|
1137
|
+
disabled,
|
|
1138
|
+
style: { display: "none" },
|
|
1139
|
+
onChange: (e) => {
|
|
1140
|
+
void handleFiles(e.target.files ?? []);
|
|
1141
|
+
e.target.value = "";
|
|
1142
|
+
},
|
|
1143
|
+
"data-testid": "upload-field-input"
|
|
1144
|
+
}
|
|
1145
|
+
),
|
|
1146
|
+
globalError != null ? /* @__PURE__ */ jsx17(
|
|
1147
|
+
JoyTypography5,
|
|
1148
|
+
{
|
|
1149
|
+
role: "alert",
|
|
1150
|
+
"data-testid": "upload-field-global-error",
|
|
1151
|
+
color: "danger",
|
|
1152
|
+
level: "body-sm",
|
|
1153
|
+
sx: { mt: 1 },
|
|
1154
|
+
children: globalError
|
|
1155
|
+
}
|
|
1156
|
+
) : null,
|
|
1157
|
+
currentValue.length > 0 ? /* @__PURE__ */ jsx17(
|
|
1158
|
+
JoyStack3,
|
|
1159
|
+
{
|
|
1160
|
+
spacing: 1,
|
|
1161
|
+
sx: { mt: 1 },
|
|
1162
|
+
"data-testid": "upload-field-value-list",
|
|
1163
|
+
children: currentValue.map((key) => /* @__PURE__ */ jsxs12(
|
|
1164
|
+
JoyBox,
|
|
1165
|
+
{
|
|
1166
|
+
"data-testid": "upload-field-value-item",
|
|
1167
|
+
sx: {
|
|
1168
|
+
display: "flex",
|
|
1169
|
+
alignItems: "center",
|
|
1170
|
+
gap: 1,
|
|
1171
|
+
p: 1,
|
|
1172
|
+
borderRadius: "sm",
|
|
1173
|
+
backgroundColor: "background.level1"
|
|
1174
|
+
},
|
|
1175
|
+
children: [
|
|
1176
|
+
looksLikeImageKey(key) ? /* @__PURE__ */ jsx17(
|
|
1177
|
+
JoyBox,
|
|
1178
|
+
{
|
|
1179
|
+
component: "img",
|
|
1180
|
+
src: `${normalizedBase}/${key.replace(/^\/+/, "")}`,
|
|
1181
|
+
alt: key,
|
|
1182
|
+
sx: {
|
|
1183
|
+
width: 40,
|
|
1184
|
+
height: 40,
|
|
1185
|
+
objectFit: "cover",
|
|
1186
|
+
borderRadius: "sm"
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
) : null,
|
|
1190
|
+
/* @__PURE__ */ jsx17(
|
|
1191
|
+
JoyTypography5,
|
|
1192
|
+
{
|
|
1193
|
+
level: "body-sm",
|
|
1194
|
+
sx: { flex: 1, overflow: "hidden", textOverflow: "ellipsis" },
|
|
1195
|
+
children: key
|
|
1196
|
+
}
|
|
1197
|
+
),
|
|
1198
|
+
/* @__PURE__ */ jsx17(
|
|
1199
|
+
JoyIconButton,
|
|
1200
|
+
{
|
|
1201
|
+
size: "sm",
|
|
1202
|
+
variant: "plain",
|
|
1203
|
+
color: "danger",
|
|
1204
|
+
"aria-label": `Remove ${key}`,
|
|
1205
|
+
disabled,
|
|
1206
|
+
onClick: () => removeKey(key),
|
|
1207
|
+
children: "\xD7"
|
|
1208
|
+
}
|
|
1209
|
+
)
|
|
1210
|
+
]
|
|
1211
|
+
},
|
|
1212
|
+
key
|
|
1213
|
+
))
|
|
1214
|
+
}
|
|
1215
|
+
) : null,
|
|
1216
|
+
files.length > 0 ? /* @__PURE__ */ jsx17(
|
|
1217
|
+
JoyStack3,
|
|
1218
|
+
{
|
|
1219
|
+
spacing: 1,
|
|
1220
|
+
sx: { mt: 1 },
|
|
1221
|
+
"data-testid": "upload-field-tracker",
|
|
1222
|
+
children: files.map((file) => /* @__PURE__ */ jsxs12(
|
|
1223
|
+
JoyBox,
|
|
1224
|
+
{
|
|
1225
|
+
"data-testid": "upload-field-tracker-item",
|
|
1226
|
+
"data-status": file.status,
|
|
1227
|
+
sx: {
|
|
1228
|
+
display: "flex",
|
|
1229
|
+
flexDirection: "column",
|
|
1230
|
+
gap: 0.5,
|
|
1231
|
+
p: 1,
|
|
1232
|
+
borderRadius: "sm",
|
|
1233
|
+
backgroundColor: "background.level1"
|
|
1234
|
+
},
|
|
1235
|
+
children: [
|
|
1236
|
+
/* @__PURE__ */ jsxs12(
|
|
1237
|
+
JoyBox,
|
|
1238
|
+
{
|
|
1239
|
+
sx: {
|
|
1240
|
+
display: "flex",
|
|
1241
|
+
alignItems: "center",
|
|
1242
|
+
gap: 1
|
|
1243
|
+
},
|
|
1244
|
+
children: [
|
|
1245
|
+
/* @__PURE__ */ jsx17(JoyTypography5, { level: "body-sm", sx: { flex: 1 }, children: file.name }),
|
|
1246
|
+
/* @__PURE__ */ jsx17(
|
|
1247
|
+
JoyTypography5,
|
|
1248
|
+
{
|
|
1249
|
+
level: "body-xs",
|
|
1250
|
+
color: "neutral",
|
|
1251
|
+
children: formatBytes2(file.size)
|
|
1252
|
+
}
|
|
1253
|
+
),
|
|
1254
|
+
/* @__PURE__ */ jsx17(
|
|
1255
|
+
JoyIconButton,
|
|
1256
|
+
{
|
|
1257
|
+
size: "sm",
|
|
1258
|
+
variant: "plain",
|
|
1259
|
+
color: "neutral",
|
|
1260
|
+
"aria-label": `Dismiss ${file.name}`,
|
|
1261
|
+
onClick: () => removeTrackerEntry(file.id),
|
|
1262
|
+
children: "\xD7"
|
|
1263
|
+
}
|
|
1264
|
+
)
|
|
1265
|
+
]
|
|
1266
|
+
}
|
|
1267
|
+
),
|
|
1268
|
+
file.status === "uploading" ? /* @__PURE__ */ jsx17(
|
|
1269
|
+
JoyLinearProgress2,
|
|
1270
|
+
{
|
|
1271
|
+
"data-testid": "upload-field-progress",
|
|
1272
|
+
determinate: true,
|
|
1273
|
+
value: file.progress
|
|
1274
|
+
}
|
|
1275
|
+
) : null,
|
|
1276
|
+
file.status === "error" && file.error != null ? /* @__PURE__ */ jsx17(
|
|
1277
|
+
JoyTypography5,
|
|
1278
|
+
{
|
|
1279
|
+
role: "alert",
|
|
1280
|
+
"data-testid": "upload-field-file-error",
|
|
1281
|
+
color: "danger",
|
|
1282
|
+
level: "body-xs",
|
|
1283
|
+
children: file.error
|
|
1284
|
+
}
|
|
1285
|
+
) : null
|
|
1286
|
+
]
|
|
1287
|
+
},
|
|
1288
|
+
file.id
|
|
1289
|
+
))
|
|
1290
|
+
}
|
|
1291
|
+
) : null
|
|
1292
|
+
] });
|
|
1293
|
+
}
|
|
1294
|
+
|
|
828
1295
|
// src/list-view.tsx
|
|
829
|
-
import { useState as
|
|
830
|
-
import JoyButton4 from "@mui/joy
|
|
831
|
-
import
|
|
832
|
-
import
|
|
1296
|
+
import { useState as useState4, useCallback as useCallback6 } from "react";
|
|
1297
|
+
import { Button as JoyButton4 } from "@mui/joy";
|
|
1298
|
+
import { Stack as JoyStack4 } from "@mui/joy";
|
|
1299
|
+
import { Typography as JoyTypography6 } from "@mui/joy";
|
|
833
1300
|
import { useActionStatus as useActionStatus4 } from "@cfast/ui";
|
|
834
|
-
import { jsx as
|
|
1301
|
+
import { jsx as jsx18, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
835
1302
|
function ListView({
|
|
836
1303
|
title,
|
|
837
1304
|
data,
|
|
@@ -846,8 +1313,8 @@ function ListView({
|
|
|
846
1313
|
bulkActions,
|
|
847
1314
|
breadcrumb
|
|
848
1315
|
}) {
|
|
849
|
-
const [selectedRows, setSelectedRows] =
|
|
850
|
-
const handleBulkAction =
|
|
1316
|
+
const [selectedRows, setSelectedRows] = useState4([]);
|
|
1317
|
+
const handleBulkAction = useCallback6(
|
|
851
1318
|
(action) => {
|
|
852
1319
|
if (action.handler) {
|
|
853
1320
|
action.handler(selectedRows);
|
|
@@ -855,13 +1322,13 @@ function ListView({
|
|
|
855
1322
|
},
|
|
856
1323
|
[selectedRows]
|
|
857
1324
|
);
|
|
858
|
-
const clearSelection =
|
|
1325
|
+
const clearSelection = useCallback6(() => {
|
|
859
1326
|
setSelectedRows([]);
|
|
860
1327
|
}, []);
|
|
861
|
-
const createButton = createAction ? /* @__PURE__ */
|
|
862
|
-
return /* @__PURE__ */
|
|
863
|
-
filters && filters.length > 0 ? /* @__PURE__ */
|
|
864
|
-
selectable && bulkActions && bulkActions.length > 0 ? /* @__PURE__ */
|
|
1328
|
+
const createButton = createAction ? /* @__PURE__ */ jsx18(CreateButton, { action: createAction, label: createLabel }) : null;
|
|
1329
|
+
return /* @__PURE__ */ jsx18(PageContainer, { title, breadcrumb, actions: createButton, children: /* @__PURE__ */ jsxs13(JoyStack4, { spacing: 2, children: [
|
|
1330
|
+
filters && filters.length > 0 ? /* @__PURE__ */ jsx18(FilterBar, { filters, searchable }) : null,
|
|
1331
|
+
selectable && bulkActions && bulkActions.length > 0 ? /* @__PURE__ */ jsx18(
|
|
865
1332
|
BulkActionBar,
|
|
866
1333
|
{
|
|
867
1334
|
selectedCount: selectedRows.length,
|
|
@@ -870,7 +1337,7 @@ function ListView({
|
|
|
870
1337
|
onClearSelection: clearSelection
|
|
871
1338
|
}
|
|
872
1339
|
) : null,
|
|
873
|
-
data.items.length === 0 && !data.isLoading ? /* @__PURE__ */
|
|
1340
|
+
data.items.length === 0 && !data.isLoading ? /* @__PURE__ */ jsx18(
|
|
874
1341
|
EmptyState,
|
|
875
1342
|
{
|
|
876
1343
|
title: `No ${title.toLowerCase()} found`,
|
|
@@ -878,7 +1345,7 @@ function ListView({
|
|
|
878
1345
|
createAction,
|
|
879
1346
|
createLabel
|
|
880
1347
|
}
|
|
881
|
-
) : /* @__PURE__ */
|
|
1348
|
+
) : /* @__PURE__ */ jsx18(
|
|
882
1349
|
DataTable,
|
|
883
1350
|
{
|
|
884
1351
|
data,
|
|
@@ -888,8 +1355,8 @@ function ListView({
|
|
|
888
1355
|
onSelectionChange: selectable ? (rows) => setSelectedRows(rows) : void 0
|
|
889
1356
|
}
|
|
890
1357
|
),
|
|
891
|
-
data.totalPages && data.totalPages > 1 && data.goToPage ? /* @__PURE__ */
|
|
892
|
-
/* @__PURE__ */
|
|
1358
|
+
data.totalPages && data.totalPages > 1 && data.goToPage ? /* @__PURE__ */ jsxs13(JoyStack4, { direction: "row", justifyContent: "center", alignItems: "center", spacing: 2, children: [
|
|
1359
|
+
/* @__PURE__ */ jsx18(
|
|
893
1360
|
JoyButton4,
|
|
894
1361
|
{
|
|
895
1362
|
size: "sm",
|
|
@@ -899,8 +1366,8 @@ function ListView({
|
|
|
899
1366
|
children: "Previous"
|
|
900
1367
|
}
|
|
901
1368
|
),
|
|
902
|
-
/* @__PURE__ */
|
|
903
|
-
/* @__PURE__ */
|
|
1369
|
+
/* @__PURE__ */ jsx18(JoyTypography6, { level: "body-sm", children: `Page ${data.currentPage ?? 1} of ${data.totalPages}` }),
|
|
1370
|
+
/* @__PURE__ */ jsx18(
|
|
904
1371
|
JoyButton4,
|
|
905
1372
|
{
|
|
906
1373
|
size: "sm",
|
|
@@ -911,19 +1378,19 @@ function ListView({
|
|
|
911
1378
|
}
|
|
912
1379
|
)
|
|
913
1380
|
] }) : null,
|
|
914
|
-
data.hasMore && data.loadMore ? /* @__PURE__ */
|
|
1381
|
+
data.hasMore && data.loadMore ? /* @__PURE__ */ jsx18(JoyStack4, { alignItems: "center", children: /* @__PURE__ */ jsx18(JoyButton4, { variant: "soft", onClick: data.loadMore, children: "Load more" }) }) : null
|
|
915
1382
|
] }) });
|
|
916
1383
|
}
|
|
917
1384
|
function CreateButton({ action, label }) {
|
|
918
1385
|
const status = useActionStatus4(action);
|
|
919
|
-
return /* @__PURE__ */
|
|
1386
|
+
return /* @__PURE__ */ jsx18(ActionButton, { action: status, variant: "solid", color: "primary", children: label });
|
|
920
1387
|
}
|
|
921
1388
|
|
|
922
1389
|
// src/detail-view.tsx
|
|
923
|
-
import JoyGrid from "@mui/joy
|
|
924
|
-
import
|
|
1390
|
+
import { Grid as JoyGrid } from "@mui/joy";
|
|
1391
|
+
import { Typography as JoyTypography7 } from "@mui/joy";
|
|
925
1392
|
import { fieldForColumn, getField as getField2 } from "@cfast/ui";
|
|
926
|
-
import { jsx as
|
|
1393
|
+
import { jsx as jsx19, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
927
1394
|
function normalizeFields(fields) {
|
|
928
1395
|
if (!fields) return [];
|
|
929
1396
|
return fields.map((col) => {
|
|
@@ -946,12 +1413,12 @@ function DetailView({
|
|
|
946
1413
|
}) {
|
|
947
1414
|
const fields = normalizeFields(fieldsProp);
|
|
948
1415
|
const displayFields = fields.length > 0 ? fields : inferFieldsFromRecord(record, exclude);
|
|
949
|
-
return /* @__PURE__ */
|
|
1416
|
+
return /* @__PURE__ */ jsx19(PageContainer, { title, breadcrumb, children: /* @__PURE__ */ jsx19(JoyGrid, { container: true, spacing: 2, children: displayFields.map((field) => {
|
|
950
1417
|
const value = getField2(record, field.key);
|
|
951
1418
|
const FieldComponent = field.render ? null : resolveFieldComponent(field.key, table);
|
|
952
|
-
return /* @__PURE__ */
|
|
953
|
-
/* @__PURE__ */
|
|
954
|
-
|
|
1419
|
+
return /* @__PURE__ */ jsxs14(JoyGrid, { xs: 12, md: 6, children: [
|
|
1420
|
+
/* @__PURE__ */ jsx19(
|
|
1421
|
+
JoyTypography7,
|
|
955
1422
|
{
|
|
956
1423
|
level: "body-xs",
|
|
957
1424
|
textTransform: "uppercase",
|
|
@@ -960,7 +1427,7 @@ function DetailView({
|
|
|
960
1427
|
children: field.label ?? field.key
|
|
961
1428
|
}
|
|
962
1429
|
),
|
|
963
|
-
/* @__PURE__ */
|
|
1430
|
+
/* @__PURE__ */ jsx19("div", { children: field.render ? field.render(value, record) : FieldComponent ? /* @__PURE__ */ jsx19(FieldComponent, { value }) : String(value ?? "\u2014") })
|
|
964
1431
|
] }, field.key);
|
|
965
1432
|
}) }) });
|
|
966
1433
|
}
|
|
@@ -982,25 +1449,25 @@ function resolveFieldComponent(_key, table) {
|
|
|
982
1449
|
|
|
983
1450
|
// src/avatar-with-initials.tsx
|
|
984
1451
|
import "react";
|
|
985
|
-
import Avatar2 from "@mui/joy
|
|
1452
|
+
import { Avatar as Avatar2 } from "@mui/joy";
|
|
986
1453
|
import { getInitials as getInitials2 } from "@cfast/ui";
|
|
987
|
-
import { jsx as
|
|
1454
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
988
1455
|
function AvatarWithInitials({
|
|
989
1456
|
src,
|
|
990
1457
|
name,
|
|
991
1458
|
size = "md"
|
|
992
1459
|
}) {
|
|
993
|
-
return /* @__PURE__ */
|
|
1460
|
+
return /* @__PURE__ */ jsx20(Avatar2, { src: src ?? void 0, alt: name, size, children: getInitials2(name) });
|
|
994
1461
|
}
|
|
995
1462
|
|
|
996
1463
|
// src/impersonation-banner.tsx
|
|
997
1464
|
import "react";
|
|
998
|
-
import Sheet2 from "@mui/joy
|
|
999
|
-
import Typography4 from "@mui/joy
|
|
1000
|
-
import Button3 from "@mui/joy
|
|
1001
|
-
import Stack5 from "@mui/joy
|
|
1465
|
+
import { Sheet as Sheet2 } from "@mui/joy";
|
|
1466
|
+
import { Typography as Typography4 } from "@mui/joy";
|
|
1467
|
+
import { Button as Button3 } from "@mui/joy";
|
|
1468
|
+
import { Stack as Stack5 } from "@mui/joy";
|
|
1002
1469
|
import { useCurrentUser as useCurrentUser2 } from "@cfast/auth/client";
|
|
1003
|
-
import { jsx as
|
|
1470
|
+
import { jsx as jsx21, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
1004
1471
|
function ImpersonationBanner({
|
|
1005
1472
|
stopAction = "/admin/stop-impersonation"
|
|
1006
1473
|
}) {
|
|
@@ -1008,7 +1475,7 @@ function ImpersonationBanner({
|
|
|
1008
1475
|
if (!user?.isImpersonating) {
|
|
1009
1476
|
return null;
|
|
1010
1477
|
}
|
|
1011
|
-
return /* @__PURE__ */
|
|
1478
|
+
return /* @__PURE__ */ jsx21(
|
|
1012
1479
|
Sheet2,
|
|
1013
1480
|
{
|
|
1014
1481
|
color: "warning",
|
|
@@ -1020,9 +1487,9 @@ function ImpersonationBanner({
|
|
|
1020
1487
|
py: 1,
|
|
1021
1488
|
px: 3
|
|
1022
1489
|
},
|
|
1023
|
-
children: /* @__PURE__ */
|
|
1024
|
-
/* @__PURE__ */
|
|
1025
|
-
/* @__PURE__ */
|
|
1490
|
+
children: /* @__PURE__ */ jsxs15(Stack5, { direction: "row", spacing: 2, alignItems: "center", justifyContent: "center", children: [
|
|
1491
|
+
/* @__PURE__ */ jsx21(Typography4, { level: "body-sm", sx: { fontWeight: "bold" }, children: `Viewing as ${user.name} (${user.email})` }),
|
|
1492
|
+
/* @__PURE__ */ jsx21("form", { method: "post", action: stopAction, children: /* @__PURE__ */ jsx21(Button3, { size: "sm", variant: "outlined", color: "warning", type: "submit", children: "Stop Impersonating" }) })
|
|
1026
1493
|
] })
|
|
1027
1494
|
}
|
|
1028
1495
|
);
|
|
@@ -1032,15 +1499,15 @@ function ImpersonationBanner({
|
|
|
1032
1499
|
import { PermissionGate } from "@cfast/ui";
|
|
1033
1500
|
|
|
1034
1501
|
// src/login-components.tsx
|
|
1035
|
-
import Box from "@mui/joy
|
|
1036
|
-
import Card from "@mui/joy
|
|
1037
|
-
import Input from "@mui/joy
|
|
1038
|
-
import Button4 from "@mui/joy
|
|
1039
|
-
import Alert2 from "@mui/joy
|
|
1040
|
-
import Divider from "@mui/joy
|
|
1041
|
-
import { Fragment as Fragment3, jsx as
|
|
1502
|
+
import { Box } from "@mui/joy";
|
|
1503
|
+
import { Card } from "@mui/joy";
|
|
1504
|
+
import { Input } from "@mui/joy";
|
|
1505
|
+
import { Button as Button4 } from "@mui/joy";
|
|
1506
|
+
import { Alert as Alert2 } from "@mui/joy";
|
|
1507
|
+
import { Divider } from "@mui/joy";
|
|
1508
|
+
import { Fragment as Fragment3, jsx as jsx22, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
1042
1509
|
function Layout({ children }) {
|
|
1043
|
-
return /* @__PURE__ */
|
|
1510
|
+
return /* @__PURE__ */ jsx22(
|
|
1044
1511
|
Box,
|
|
1045
1512
|
{
|
|
1046
1513
|
sx: {
|
|
@@ -1050,7 +1517,7 @@ function Layout({ children }) {
|
|
|
1050
1517
|
minHeight: "100vh",
|
|
1051
1518
|
bgcolor: "background.surface"
|
|
1052
1519
|
},
|
|
1053
|
-
children: /* @__PURE__ */
|
|
1520
|
+
children: /* @__PURE__ */ jsx22(Card, { variant: "outlined", sx: { maxWidth: 400, width: "100%", p: 4 }, children })
|
|
1054
1521
|
}
|
|
1055
1522
|
);
|
|
1056
1523
|
}
|
|
@@ -1058,7 +1525,7 @@ function EmailInput({
|
|
|
1058
1525
|
value,
|
|
1059
1526
|
onChange
|
|
1060
1527
|
}) {
|
|
1061
|
-
return /* @__PURE__ */
|
|
1528
|
+
return /* @__PURE__ */ jsx22(
|
|
1062
1529
|
Input,
|
|
1063
1530
|
{
|
|
1064
1531
|
type: "email",
|
|
@@ -1074,7 +1541,7 @@ function MagicLinkButton({
|
|
|
1074
1541
|
onClick,
|
|
1075
1542
|
loading
|
|
1076
1543
|
}) {
|
|
1077
|
-
return /* @__PURE__ */
|
|
1544
|
+
return /* @__PURE__ */ jsx22(
|
|
1078
1545
|
Button4,
|
|
1079
1546
|
{
|
|
1080
1547
|
onClick,
|
|
@@ -1089,9 +1556,9 @@ function PasskeyButton({
|
|
|
1089
1556
|
onClick,
|
|
1090
1557
|
loading
|
|
1091
1558
|
}) {
|
|
1092
|
-
return /* @__PURE__ */
|
|
1093
|
-
/* @__PURE__ */
|
|
1094
|
-
/* @__PURE__ */
|
|
1559
|
+
return /* @__PURE__ */ jsxs16(Fragment3, { children: [
|
|
1560
|
+
/* @__PURE__ */ jsx22(Divider, { children: "or" }),
|
|
1561
|
+
/* @__PURE__ */ jsx22(
|
|
1095
1562
|
Button4,
|
|
1096
1563
|
{
|
|
1097
1564
|
variant: "outlined",
|
|
@@ -1106,14 +1573,14 @@ function PasskeyButton({
|
|
|
1106
1573
|
] });
|
|
1107
1574
|
}
|
|
1108
1575
|
function SuccessMessage({ email }) {
|
|
1109
|
-
return /* @__PURE__ */
|
|
1576
|
+
return /* @__PURE__ */ jsxs16(Alert2, { color: "success", children: [
|
|
1110
1577
|
"Check your email (",
|
|
1111
1578
|
email,
|
|
1112
1579
|
") for a magic link. Click the link to sign in."
|
|
1113
1580
|
] });
|
|
1114
1581
|
}
|
|
1115
1582
|
function ErrorMessage({ error }) {
|
|
1116
|
-
return /* @__PURE__ */
|
|
1583
|
+
return /* @__PURE__ */ jsx22(Alert2, { color: "danger", sx: { mb: 2 }, children: error });
|
|
1117
1584
|
}
|
|
1118
1585
|
var joyLoginComponents = {
|
|
1119
1586
|
Layout,
|
|
@@ -1146,6 +1613,7 @@ export {
|
|
|
1146
1613
|
PermissionGate,
|
|
1147
1614
|
RoleBadge,
|
|
1148
1615
|
ToastProvider,
|
|
1616
|
+
UploadField,
|
|
1149
1617
|
UserMenu,
|
|
1150
1618
|
joyLoginComponents
|
|
1151
1619
|
};
|
package/llms.txt
CHANGED
|
@@ -32,6 +32,7 @@ Use `@cfast/joy` when you want MUI Joy UI styled implementations of `@cfast/ui`
|
|
|
32
32
|
- `DropZone` -- drag-and-drop upload. Integrates with `@cfast/storage`'s `useUpload()`.
|
|
33
33
|
- `ImagePreview` -- displays image from storage with signed URL handling.
|
|
34
34
|
- `FileList` -- list of uploaded files with download/delete.
|
|
35
|
+
- `UploadField` -- controlled multi-file upload field. Joy-styled variant of `@cfast/ui`'s `UploadField` with dashed drop zone, per-file `<LinearProgress>`, and inline image previews. Reports the set of uploaded R2 keys through `value` / `onChange` so it drops straight into `react-hook-form` — or is picked up automatically by `@cfast/forms/joy` when a Drizzle column uses the `upload()` helper.
|
|
35
36
|
|
|
36
37
|
### Composite views
|
|
37
38
|
- `ListView` -- full page: title + filters + data table + pagination + empty state + bulk actions.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cfast/joy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Joy UI plugin for @cfast/ui — styled components powered by MUI Joy",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -26,21 +26,44 @@
|
|
|
26
26
|
"access": "public"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
+
"@cfast/actions": ">=0.1.0 <0.3.0",
|
|
30
|
+
"@cfast/auth": ">=0.3.0 <0.5.0",
|
|
31
|
+
"@cfast/ui": ">=0.2.0 <0.4.0",
|
|
32
|
+
"@emotion/react": "^11.14.0",
|
|
33
|
+
"@emotion/styled": "^11.14.1",
|
|
34
|
+
"@mui/joy": ">=5.0.0-beta.0",
|
|
29
35
|
"react": ">=19",
|
|
30
36
|
"react-dom": ">=19",
|
|
31
37
|
"react-router": ">=7"
|
|
32
38
|
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"@cfast/actions": {
|
|
41
|
+
"optional": false
|
|
42
|
+
},
|
|
43
|
+
"@cfast/auth": {
|
|
44
|
+
"optional": false
|
|
45
|
+
},
|
|
46
|
+
"@cfast/ui": {
|
|
47
|
+
"optional": false
|
|
48
|
+
},
|
|
49
|
+
"@emotion/react": {
|
|
50
|
+
"optional": false
|
|
51
|
+
},
|
|
52
|
+
"@emotion/styled": {
|
|
53
|
+
"optional": false
|
|
54
|
+
},
|
|
55
|
+
"@mui/joy": {
|
|
56
|
+
"optional": false
|
|
57
|
+
}
|
|
58
|
+
},
|
|
33
59
|
"dependencies": {
|
|
34
|
-
"@emotion/react": "^11.14.0",
|
|
35
|
-
"@emotion/styled": "^11.14.1",
|
|
36
|
-
"@mui/joy": "^5.0.0-beta.52",
|
|
37
60
|
"@mui/material": "^6.5.0",
|
|
38
|
-
"sonner": "^2.0.3"
|
|
39
|
-
"@cfast/ui": "0.2.1",
|
|
40
|
-
"@cfast/actions": "0.1.1",
|
|
41
|
-
"@cfast/auth": "0.2.2"
|
|
61
|
+
"sonner": "^2.0.3"
|
|
42
62
|
},
|
|
43
63
|
"devDependencies": {
|
|
64
|
+
"@emotion/react": "^11.14.0",
|
|
65
|
+
"@emotion/styled": "^11.14.1",
|
|
66
|
+
"@mui/joy": "^5.0.0-beta.52",
|
|
44
67
|
"@storybook/react": "^8.6.14",
|
|
45
68
|
"@storybook/react-vite": "^8.6.14",
|
|
46
69
|
"@testing-library/react": "^16.3.0",
|
|
@@ -54,11 +77,14 @@
|
|
|
54
77
|
"storybook": "^8.6.14",
|
|
55
78
|
"tsup": "^8",
|
|
56
79
|
"typescript": "^5.7",
|
|
57
|
-
"vitest": "^4.1.0"
|
|
80
|
+
"vitest": "^4.1.0",
|
|
81
|
+
"@cfast/actions": "0.1.2",
|
|
82
|
+
"@cfast/auth": "0.4.0",
|
|
83
|
+
"@cfast/ui": "0.3.0"
|
|
58
84
|
},
|
|
59
85
|
"scripts": {
|
|
60
|
-
"build": "tsup src/index.ts --format esm --dts",
|
|
61
|
-
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
86
|
+
"build": "tsup src/index.ts --format esm --dts && node ../../scripts/fix-mui-joy-imports.mjs dist",
|
|
87
|
+
"dev": "tsup src/index.ts --format esm --dts --watch --onSuccess \"node ../../scripts/fix-mui-joy-imports.mjs dist\"",
|
|
62
88
|
"typecheck": "tsc --noEmit",
|
|
63
89
|
"lint": "eslint src/",
|
|
64
90
|
"test": "vitest run",
|