@cfast/joy 0.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
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
@@ -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 useState3, useCallback as useCallback5 } from "react";
1296
+ import { useState as useState4, useCallback as useCallback6 } from "react";
830
1297
  import { Button as JoyButton4 } from "@mui/joy";
831
- import { Stack as JoyStack3 } from "@mui/joy";
832
- import { Typography as JoyTypography5 } 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 jsx17, jsxs as jsxs12 } from "react/jsx-runtime";
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] = useState3([]);
850
- const handleBulkAction = useCallback5(
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 = useCallback5(() => {
1325
+ const clearSelection = useCallback6(() => {
859
1326
  setSelectedRows([]);
860
1327
  }, []);
861
- const createButton = createAction ? /* @__PURE__ */ jsx17(CreateButton, { action: createAction, label: createLabel }) : null;
862
- return /* @__PURE__ */ jsx17(PageContainer, { title, breadcrumb, actions: createButton, children: /* @__PURE__ */ jsxs12(JoyStack3, { spacing: 2, children: [
863
- filters && filters.length > 0 ? /* @__PURE__ */ jsx17(FilterBar, { filters, searchable }) : null,
864
- selectable && bulkActions && bulkActions.length > 0 ? /* @__PURE__ */ jsx17(
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__ */ jsx17(
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__ */ jsx17(
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__ */ jsxs12(JoyStack3, { direction: "row", justifyContent: "center", alignItems: "center", spacing: 2, children: [
892
- /* @__PURE__ */ jsx17(
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__ */ jsx17(JoyTypography5, { level: "body-sm", children: `Page ${data.currentPage ?? 1} of ${data.totalPages}` }),
903
- /* @__PURE__ */ jsx17(
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__ */ jsx17(JoyStack3, { alignItems: "center", children: /* @__PURE__ */ jsx17(JoyButton4, { variant: "soft", onClick: data.loadMore, children: "Load more" }) }) : null
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__ */ jsx17(ActionButton, { action: status, variant: "solid", color: "primary", children: label });
1386
+ return /* @__PURE__ */ jsx18(ActionButton, { action: status, variant: "solid", color: "primary", children: label });
920
1387
  }
921
1388
 
922
1389
  // src/detail-view.tsx
923
1390
  import { Grid as JoyGrid } from "@mui/joy";
924
- import { Typography as JoyTypography6 } 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 jsx18, jsxs as jsxs13 } from "react/jsx-runtime";
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__ */ jsx18(PageContainer, { title, breadcrumb, children: /* @__PURE__ */ jsx18(JoyGrid, { container: true, spacing: 2, children: displayFields.map((field) => {
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__ */ jsxs13(JoyGrid, { xs: 12, md: 6, children: [
953
- /* @__PURE__ */ jsx18(
954
- JoyTypography6,
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__ */ jsx18("div", { children: field.render ? field.render(value, record) : FieldComponent ? /* @__PURE__ */ jsx18(FieldComponent, { value }) : String(value ?? "\u2014") })
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
  }
@@ -984,13 +1451,13 @@ function resolveFieldComponent(_key, table) {
984
1451
  import "react";
985
1452
  import { Avatar as Avatar2 } from "@mui/joy";
986
1453
  import { getInitials as getInitials2 } from "@cfast/ui";
987
- import { jsx as jsx19 } from "react/jsx-runtime";
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__ */ jsx19(Avatar2, { src: src ?? void 0, alt: name, size, children: getInitials2(name) });
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
@@ -1000,7 +1467,7 @@ import { Typography as Typography4 } from "@mui/joy";
1000
1467
  import { Button as Button3 } from "@mui/joy";
1001
1468
  import { Stack as Stack5 } from "@mui/joy";
1002
1469
  import { useCurrentUser as useCurrentUser2 } from "@cfast/auth/client";
1003
- import { jsx as jsx20, jsxs as jsxs14 } from "react/jsx-runtime";
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__ */ jsx20(
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__ */ jsxs14(Stack5, { direction: "row", spacing: 2, alignItems: "center", justifyContent: "center", children: [
1024
- /* @__PURE__ */ jsx20(Typography4, { level: "body-sm", sx: { fontWeight: "bold" }, children: `Viewing as ${user.name} (${user.email})` }),
1025
- /* @__PURE__ */ jsx20("form", { method: "post", action: stopAction, children: /* @__PURE__ */ jsx20(Button3, { size: "sm", variant: "outlined", color: "warning", type: "submit", children: "Stop Impersonating" }) })
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
  );
@@ -1038,9 +1505,9 @@ import { Input } from "@mui/joy";
1038
1505
  import { Button as Button4 } from "@mui/joy";
1039
1506
  import { Alert as Alert2 } from "@mui/joy";
1040
1507
  import { Divider } from "@mui/joy";
1041
- import { Fragment as Fragment3, jsx as jsx21, jsxs as jsxs15 } from "react/jsx-runtime";
1508
+ import { Fragment as Fragment3, jsx as jsx22, jsxs as jsxs16 } from "react/jsx-runtime";
1042
1509
  function Layout({ children }) {
1043
- return /* @__PURE__ */ jsx21(
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__ */ jsx21(Card, { variant: "outlined", sx: { maxWidth: 400, width: "100%", p: 4 }, children })
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__ */ jsx21(
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__ */ jsx21(
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__ */ jsxs15(Fragment3, { children: [
1093
- /* @__PURE__ */ jsx21(Divider, { children: "or" }),
1094
- /* @__PURE__ */ jsx21(
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__ */ jsxs15(Alert2, { color: "success", children: [
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__ */ jsx21(Alert2, { color: "danger", sx: { mb: 2 }, children: error });
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.1.1",
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/auth": "0.2.2",
41
- "@cfast/actions": "0.1.1"
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,7 +77,10 @@
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
86
  "build": "tsup src/index.ts --format esm --dts && node ../../scripts/fix-mui-joy-imports.mjs dist",