@pixpilot/shadcn-ui 0.4.0 → 0.4.2
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/AbsoluteFill.cjs +24 -1
- package/dist/AbsoluteFill.js +21 -1
- package/dist/Alert.cjs +82 -1
- package/dist/Alert.js +77 -1
- package/dist/Button.cjs +84 -1
- package/dist/Button.d.cts +1 -1
- package/dist/Button.d.ts +1 -1
- package/dist/Button.js +79 -1
- package/dist/CloseButtonAbsolute.cjs +20 -1
- package/dist/CloseButtonAbsolute.js +16 -1
- package/dist/CloseButtonRounded.cjs +22 -1
- package/dist/CloseButtonRounded.js +17 -1
- package/dist/Combobox.cjs +53 -1
- package/dist/Combobox.js +48 -1
- package/dist/CommandOptionList.cjs +29 -1
- package/dist/CommandOptionList.js +25 -1
- package/dist/ContentCard.cjs +27 -1
- package/dist/ContentCard.d.cts +1 -1
- package/dist/ContentCard.js +23 -1
- package/dist/DatePicker.cjs +38 -1
- package/dist/DatePicker.d.cts +1 -1
- package/dist/DatePicker.js +33 -1
- package/dist/LoadingOverlay.cjs +65 -1
- package/dist/LoadingOverlay.js +60 -1
- package/dist/Select.cjs +27 -1
- package/dist/Select.d.cts +1 -1
- package/dist/Select.js +23 -1
- package/dist/Slider.cjs +19 -1
- package/dist/Slider.js +15 -1
- package/dist/ThemeToggle.cjs +98 -1
- package/dist/ThemeToggle.js +94 -1
- package/dist/_virtual/rolldown_runtime.cjs +25 -1
- package/dist/confirmation-dialog/ConfirmationDialog.cjs +46 -1
- package/dist/confirmation-dialog/ConfirmationDialog.d.cts +1 -0
- package/dist/confirmation-dialog/ConfirmationDialog.js +42 -1
- package/dist/confirmation-dialog/DialogProvider.cjs +16 -1
- package/dist/confirmation-dialog/DialogProvider.js +12 -1
- package/dist/confirmation-dialog/confirmation-dialogs.cjs +14 -1
- package/dist/confirmation-dialog/confirmation-dialogs.js +12 -1
- package/dist/confirmation-dialog/index.cjs +6 -1
- package/dist/confirmation-dialog/index.js +6 -1
- package/dist/file-upload/FileUpload.cjs +68 -1
- package/dist/file-upload/FileUpload.d.ts +2 -2
- package/dist/file-upload/FileUpload.js +63 -1
- package/dist/file-upload/FileUploadItems.cjs +36 -1
- package/dist/file-upload/FileUploadItems.js +32 -1
- package/dist/file-upload/FileUploadListItem.cjs +88 -1
- package/dist/file-upload/FileUploadListItem.js +82 -1
- package/dist/file-upload/hooks/index.cjs +3 -1
- package/dist/file-upload/hooks/index.d.cts +2 -0
- package/dist/file-upload/hooks/index.js +3 -1
- package/dist/file-upload/hooks/use-file-error.cjs +15 -1
- package/dist/file-upload/hooks/use-file-error.js +13 -1
- package/dist/file-upload/hooks/use-file-upload-progress-callbacks.cjs +34 -1
- package/dist/file-upload/hooks/use-file-upload-progress-callbacks.d.cts +1 -0
- package/dist/file-upload/hooks/use-file-upload-progress-callbacks.js +31 -1
- package/dist/file-upload/hooks/use-file-upload-store.cjs +77 -1
- package/dist/file-upload/hooks/use-file-upload-store.d.cts +2 -0
- package/dist/file-upload/hooks/use-file-upload-store.js +75 -1
- package/dist/file-upload/index.cjs +5 -1
- package/dist/file-upload/index.d.cts +2 -1
- package/dist/file-upload/index.js +5 -1
- package/dist/file-upload/utils/create-placeholder-file.cjs +11 -1
- package/dist/file-upload/utils/create-placeholder-file.js +10 -1
- package/dist/file-upload/utils/get-file-key.cjs +8 -1
- package/dist/file-upload/utils/get-file-key.d.cts +1 -0
- package/dist/file-upload/utils/get-file-key.js +7 -1
- package/dist/file-upload/utils/get-file-meta.cjs +23 -1
- package/dist/file-upload/utils/get-file-meta.d.cts +1 -0
- package/dist/file-upload/utils/get-file-meta.js +21 -1
- package/dist/file-upload/utils/index.d.cts +4 -0
- package/dist/file-upload/utils/is-file-equal.cjs +9 -1
- package/dist/file-upload/utils/is-file-equal.d.cts +1 -0
- package/dist/file-upload/utils/is-file-equal.js +8 -1
- package/dist/file-upload/utils/merge-file-metadata.cjs +26 -1
- package/dist/file-upload/utils/merge-file-metadata.d.cts +1 -0
- package/dist/file-upload/utils/merge-file-metadata.js +26 -1
- package/dist/file-upload-inline/FileUploadInline.cjs +71 -1
- package/dist/file-upload-inline/FileUploadInline.d.ts +2 -2
- package/dist/file-upload-inline/FileUploadInline.js +66 -1
- package/dist/file-upload-inline/FileUploadInlineItem.cjs +94 -1
- package/dist/file-upload-inline/FileUploadInlineItem.js +88 -1
- package/dist/file-upload-inline/defaults.cjs +11 -1
- package/dist/file-upload-inline/defaults.js +10 -1
- package/dist/file-upload-inline/index.cjs +1 -1
- package/dist/file-upload-inline/index.js +1 -1
- package/dist/file-upload-inline/utils.cjs +36 -1
- package/dist/file-upload-inline/utils.js +34 -1
- package/dist/hooks/index.cjs +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/use-media-query.cjs +9 -1
- package/dist/hooks/use-media-query.js +7 -1
- package/dist/icon-selector/IconPicker.cjs +93 -1
- package/dist/icon-selector/IconPicker.d.cts +0 -1
- package/dist/icon-selector/IconPicker.d.ts +0 -1
- package/dist/icon-selector/IconPicker.js +88 -1
- package/dist/icon-selector/constants.cjs +6 -1
- package/dist/icon-selector/constants.js +5 -0
- package/dist/icon-selector/icon-picker-container.cjs +35 -1
- package/dist/icon-selector/icon-picker-container.js +32 -1
- package/dist/icon-selector/icon-picker-content.cjs +146 -1
- package/dist/icon-selector/icon-picker-content.js +141 -1
- package/dist/icon-selector/index.cjs +1 -1
- package/dist/icon-selector/index.d.cts +2 -2
- package/dist/icon-selector/index.d.ts +2 -2
- package/dist/icon-selector/index.js +1 -1
- package/dist/icon-selector/use-async-providers.cjs +69 -1
- package/dist/icon-selector/use-async-providers.js +67 -1
- package/dist/icon-selector/utils/is-valid-provider.cjs +11 -1
- package/dist/icon-selector/utils/is-valid-provider.js +10 -1
- package/dist/icon-selector/virtualized-icon-grid.cjs +137 -1
- package/dist/icon-selector/virtualized-icon-grid.js +132 -1
- package/dist/index.cjs +76 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +37 -1
- package/dist/node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/dist/clsx.cjs +18 -0
- package/dist/node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/dist/clsx.js +17 -0
- package/dist/node_modules/.pnpm/tailwind-merge@3.4.0/node_modules/tailwind-merge/dist/bundle-mjs.cjs +1894 -0
- package/dist/node_modules/.pnpm/tailwind-merge@3.4.0/node_modules/tailwind-merge/dist/bundle-mjs.js +1893 -0
- package/dist/packages/shadcn/src/lib/utils.cjs +10 -1
- package/dist/packages/shadcn/src/lib/utils.js +10 -1
- package/dist/pagination/Pagination.cjs +156 -1
- package/dist/pagination/Pagination.js +151 -1
- package/dist/pagination/index.cjs +1 -1
- package/dist/pagination/index.js +1 -1
- package/dist/rich-text-editor/RichTextEditor.cjs +132 -1
- package/dist/rich-text-editor/RichTextEditor.js +126 -1
- package/dist/rich-text-editor/index.cjs +1 -1
- package/dist/rich-text-editor/index.js +1 -1
- package/dist/rich-text-editor/predefined-toolbar-options.cjs +84 -1
- package/dist/rich-text-editor/predefined-toolbar-options.js +81 -1
- package/dist/spinner/index.cjs +1 -1
- package/dist/spinner/index.js +1 -1
- package/dist/spinner/spinner.cjs +73 -6
- package/dist/spinner/spinner.js +70 -6
- package/dist/spinner/styles.cjs +24 -12
- package/dist/spinner/styles.js +23 -12
- package/dist/tags-input.cjs +226 -1
- package/dist/tags-input.js +222 -1
- package/dist/theme-provider/ThemeProvider.cjs +27 -1
- package/dist/theme-provider/ThemeProvider.js +23 -1
- package/dist/theme-provider/index.cjs +4 -1
- package/dist/theme-provider/index.js +4 -1
- package/dist/toast/AlertToast.cjs +36 -1
- package/dist/toast/AlertToast.js +31 -1
- package/dist/toast/index.cjs +1 -1
- package/dist/toast/index.js +1 -1
- package/dist/toast/toast.cjs +75 -1
- package/dist/toast/toast.js +66 -1
- package/package.json +2 -2
- package/dist/_virtual/rolldown_runtime.js +0 -1
- package/dist/node_modules/.pnpm/@diceui_shared@0.12.0_@floating-ui_react@0.27.16_react-dom@19.2.0_react@19.2.0__react@1_2c51ffe880f01dd537d5b6a13313daf4/node_modules/@diceui/shared/dist/index.cjs +0 -1
- package/dist/node_modules/.pnpm/@diceui_shared@0.12.0_@floating-ui_react@0.27.16_react-dom@19.2.0_react@19.2.0__react@1_2c51ffe880f01dd537d5b6a13313daf4/node_modules/@diceui/shared/dist/index.js +0 -1
- package/dist/node_modules/.pnpm/@diceui_tags-input@0.7.2_@floating-ui_react@0.27.16_react-dom@19.2.0_react@19.2.0__reac_e193dc2ff0d426ed009417f8d89778fd/node_modules/@diceui/tags-input/dist/index.cjs +0 -1
- package/dist/node_modules/.pnpm/@diceui_tags-input@0.7.2_@floating-ui_react@0.27.16_react-dom@19.2.0_react@19.2.0__reac_e193dc2ff0d426ed009417f8d89778fd/node_modules/@diceui/tags-input/dist/index.js +0 -1
- package/dist/node_modules/.pnpm/@floating-ui_core@1.7.3/node_modules/@floating-ui/core/dist/floating-ui.core.cjs +0 -1
- package/dist/node_modules/.pnpm/@floating-ui_core@1.7.3/node_modules/@floating-ui/core/dist/floating-ui.core.js +0 -1
- package/dist/node_modules/.pnpm/@floating-ui_dom@1.7.4/node_modules/@floating-ui/dom/dist/floating-ui.dom.cjs +0 -1
- package/dist/node_modules/.pnpm/@floating-ui_dom@1.7.4/node_modules/@floating-ui/dom/dist/floating-ui.dom.js +0 -1
- package/dist/node_modules/.pnpm/@floating-ui_react-dom@2.1.6_react-dom@19.2.0_react@19.2.0__react@19.2.0/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.cjs +0 -1
- package/dist/node_modules/.pnpm/@floating-ui_react-dom@2.1.6_react-dom@19.2.0_react@19.2.0__react@19.2.0/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js +0 -1
- package/dist/node_modules/.pnpm/@floating-ui_react@0.27.16_react-dom@19.2.0_react@19.2.0__react@19.2.0/node_modules/@floating-ui/react/dist/floating-ui.react.esm.cjs +0 -1
- package/dist/node_modules/.pnpm/@floating-ui_react@0.27.16_react-dom@19.2.0_react@19.2.0__react@19.2.0/node_modules/@floating-ui/react/dist/floating-ui.react.esm.js +0 -1
- package/dist/node_modules/.pnpm/@floating-ui_react@0.27.16_react-dom@19.2.0_react@19.2.0__react@19.2.0/node_modules/@floating-ui/react/dist/floating-ui.react.utils.cjs +0 -1
- package/dist/node_modules/.pnpm/@floating-ui_react@0.27.16_react-dom@19.2.0_react@19.2.0__react@19.2.0/node_modules/@floating-ui/react/dist/floating-ui.react.utils.js +0 -1
- package/dist/node_modules/.pnpm/@floating-ui_utils@0.2.10/node_modules/@floating-ui/utils/dist/floating-ui.utils.cjs +0 -1
- package/dist/node_modules/.pnpm/@floating-ui_utils@0.2.10/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.cjs +0 -1
- package/dist/node_modules/.pnpm/@floating-ui_utils@0.2.10/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js +0 -1
- package/dist/node_modules/.pnpm/@floating-ui_utils@0.2.10/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +0 -1
- package/dist/node_modules/.pnpm/tabbable@6.3.0/node_modules/tabbable/dist/index.cjs +0 -1
- package/dist/node_modules/.pnpm/tabbable@6.3.0/node_modules/tabbable/dist/index.esm.js +0 -1
- package/dist/packages/shadcn/src/components/index.cjs +0 -1
- package/dist/packages/shadcn/src/components/index.js +0 -1
- package/dist/packages/shadcn/src/components/ui/OrContinueWithSeparator.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/OrContinueWithSeparator.js +0 -1
- package/dist/packages/shadcn/src/components/ui/alert-dialog.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/alert-dialog.js +0 -1
- package/dist/packages/shadcn/src/components/ui/alert.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/alert.js +0 -1
- package/dist/packages/shadcn/src/components/ui/avatar.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/avatar.js +0 -1
- package/dist/packages/shadcn/src/components/ui/badge.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/badge.js +0 -1
- package/dist/packages/shadcn/src/components/ui/button.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/button.js +0 -1
- package/dist/packages/shadcn/src/components/ui/calendar.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/calendar.js +0 -1
- package/dist/packages/shadcn/src/components/ui/card.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/card.js +0 -1
- package/dist/packages/shadcn/src/components/ui/checkbox.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/checkbox.js +0 -1
- package/dist/packages/shadcn/src/components/ui/command.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/command.js +0 -1
- package/dist/packages/shadcn/src/components/ui/dialog.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/dialog.js +0 -1
- package/dist/packages/shadcn/src/components/ui/dropdown-menu.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/dropdown-menu.js +0 -1
- package/dist/packages/shadcn/src/components/ui/file-upload.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/file-upload.js +0 -1
- package/dist/packages/shadcn/src/components/ui/form.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/form.js +0 -1
- package/dist/packages/shadcn/src/components/ui/index.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/index.js +0 -1
- package/dist/packages/shadcn/src/components/ui/input.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/input.js +0 -1
- package/dist/packages/shadcn/src/components/ui/label.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/label.js +0 -1
- package/dist/packages/shadcn/src/components/ui/pagination.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/pagination.js +0 -1
- package/dist/packages/shadcn/src/components/ui/popover.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/popover.js +0 -1
- package/dist/packages/shadcn/src/components/ui/radio-group.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/radio-group.js +0 -1
- package/dist/packages/shadcn/src/components/ui/select.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/select.js +0 -1
- package/dist/packages/shadcn/src/components/ui/separator.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/separator.js +0 -1
- package/dist/packages/shadcn/src/components/ui/shadcn-io/tags/index.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/shadcn-io/tags/index.js +0 -1
- package/dist/packages/shadcn/src/components/ui/shadcn-io/tags-input-inline/index.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/shadcn-io/tags-input-inline/index.js +0 -1
- package/dist/packages/shadcn/src/components/ui/sheet.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/sheet.js +0 -1
- package/dist/packages/shadcn/src/components/ui/slider.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/slider.js +0 -1
- package/dist/packages/shadcn/src/components/ui/switch.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/switch.js +0 -1
- package/dist/packages/shadcn/src/components/ui/tabs.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/tabs.js +0 -1
- package/dist/packages/shadcn/src/components/ui/textarea.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/textarea.js +0 -1
- package/dist/packages/shadcn/src/components/ui/tooltip.cjs +0 -1
- package/dist/packages/shadcn/src/components/ui/tooltip.js +0 -1
- package/dist/packages/shadcn/src/lib/index.cjs +0 -1
- package/dist/packages/shadcn/src/lib/index.js +0 -1
|
@@ -1 +1,34 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_get_file_meta = require('../utils/get-file-meta.cjs');
|
|
3
|
+
let __pixpilot_shadcn = require("@pixpilot/shadcn");
|
|
4
|
+
__pixpilot_shadcn = require_rolldown_runtime.__toESM(__pixpilot_shadcn);
|
|
5
|
+
let react = require("react");
|
|
6
|
+
react = require_rolldown_runtime.__toESM(react);
|
|
7
|
+
|
|
8
|
+
//#region src/file-upload/hooks/use-file-upload-progress-callbacks.ts
|
|
9
|
+
function useFileUploadProgressCallbacks(file, callBacks) {
|
|
10
|
+
const { onChange } = callBacks;
|
|
11
|
+
const fileMeta = (0, react.useMemo)(() => require_get_file_meta.getFileMeta(file), [file]);
|
|
12
|
+
const isChangeTrigged = (0, react.useRef)(false);
|
|
13
|
+
const isUploadSuccess = (0, __pixpilot_shadcn.useFileUpload)((store) => {
|
|
14
|
+
const storeFile = store.files.get(file);
|
|
15
|
+
if (storeFile?.status === "success") {
|
|
16
|
+
storeFile.status = "idle";
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
});
|
|
21
|
+
(0, react.useEffect)(() => {
|
|
22
|
+
if (isUploadSuccess && !isChangeTrigged.current) {
|
|
23
|
+
isChangeTrigged.current = true;
|
|
24
|
+
onChange?.(fileMeta);
|
|
25
|
+
}
|
|
26
|
+
}, [
|
|
27
|
+
isUploadSuccess,
|
|
28
|
+
onChange,
|
|
29
|
+
fileMeta
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
exports.useFileUploadProgressCallbacks = useFileUploadProgressCallbacks;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../types/index.cjs";
|
|
@@ -1 +1,31 @@
|
|
|
1
|
-
import{getFileMeta
|
|
1
|
+
import { getFileMeta } from "../utils/get-file-meta.js";
|
|
2
|
+
import { useFileUpload } from "@pixpilot/shadcn";
|
|
3
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/file-upload/hooks/use-file-upload-progress-callbacks.ts
|
|
6
|
+
function useFileUploadProgressCallbacks(file, callBacks) {
|
|
7
|
+
const { onChange } = callBacks;
|
|
8
|
+
const fileMeta = useMemo(() => getFileMeta(file), [file]);
|
|
9
|
+
const isChangeTrigged = useRef(false);
|
|
10
|
+
const isUploadSuccess = useFileUpload((store) => {
|
|
11
|
+
const storeFile = store.files.get(file);
|
|
12
|
+
if (storeFile?.status === "success") {
|
|
13
|
+
storeFile.status = "idle";
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
});
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (isUploadSuccess && !isChangeTrigged.current) {
|
|
20
|
+
isChangeTrigged.current = true;
|
|
21
|
+
onChange?.(fileMeta);
|
|
22
|
+
}
|
|
23
|
+
}, [
|
|
24
|
+
isUploadSuccess,
|
|
25
|
+
onChange,
|
|
26
|
+
fileMeta
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { useFileUploadProgressCallbacks };
|
|
@@ -1 +1,77 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_get_file_key = require('../utils/get-file-key.cjs');
|
|
3
|
+
const require_get_file_meta = require('../utils/get-file-meta.cjs');
|
|
4
|
+
const require_is_file_equal = require('../utils/is-file-equal.cjs');
|
|
5
|
+
const require_merge_file_metadata = require('../utils/merge-file-metadata.cjs');
|
|
6
|
+
const require_utils = require('../../file-upload-inline/utils.cjs');
|
|
7
|
+
const require_create_placeholder_file = require('../utils/create-placeholder-file.cjs');
|
|
8
|
+
let react = require("react");
|
|
9
|
+
react = require_rolldown_runtime.__toESM(react);
|
|
10
|
+
|
|
11
|
+
//#region src/file-upload/hooks/use-file-upload-store.ts
|
|
12
|
+
function useFileUploadStore({ value, onChange, multiple, preventDuplicates = false }) {
|
|
13
|
+
const [uploadFiles, setFiles] = (0, react.useState)([]);
|
|
14
|
+
const onChangeRef = (0, react.useRef)(onChange);
|
|
15
|
+
onChangeRef.current = onChange;
|
|
16
|
+
const fileCacheRef = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
17
|
+
const getFile = (0, react.useCallback)((fileMeta) => {
|
|
18
|
+
if (fileMeta.file) return fileMeta.file;
|
|
19
|
+
const key = require_get_file_key.getFileKey(fileMeta);
|
|
20
|
+
const cached = fileCacheRef.current.get(key);
|
|
21
|
+
if (cached) return cached;
|
|
22
|
+
const created = require_create_placeholder_file.createPlaceholderFile(fileMeta);
|
|
23
|
+
fileCacheRef.current.set(key, created);
|
|
24
|
+
return created;
|
|
25
|
+
}, []);
|
|
26
|
+
const handleAccept = (0, react.useCallback)((acceptedFiles) => {
|
|
27
|
+
const newFiles = preventDuplicates ? acceptedFiles.filter((file) => {
|
|
28
|
+
const key = require_get_file_key.getFileKey(file);
|
|
29
|
+
return !uploadFiles.some((existing) => require_get_file_key.getFileKey(existing) === key);
|
|
30
|
+
}) : acceptedFiles;
|
|
31
|
+
setFiles((prev) => [...prev, ...newFiles]);
|
|
32
|
+
require_utils.handleFileValueChange(require_utils.normalizeToArray(value), newFiles, multiple, onChangeRef.current);
|
|
33
|
+
}, [
|
|
34
|
+
preventDuplicates,
|
|
35
|
+
multiple,
|
|
36
|
+
value,
|
|
37
|
+
uploadFiles
|
|
38
|
+
]);
|
|
39
|
+
const displayFiles = (0, react.useMemo)(() => {
|
|
40
|
+
const files = (() => {
|
|
41
|
+
if (!value) return uploadFiles.map((file) => require_get_file_meta.getFileMetaAndFile(file));
|
|
42
|
+
return require_merge_file_metadata.mergeFileMetadata(require_utils.normalizeToArray(value), uploadFiles);
|
|
43
|
+
})();
|
|
44
|
+
files.forEach((fileWithMeta) => {
|
|
45
|
+
if (fileWithMeta.file) fileCacheRef.current.set(require_get_file_key.getFileKey(fileWithMeta), fileWithMeta.file);
|
|
46
|
+
});
|
|
47
|
+
return files;
|
|
48
|
+
}, [uploadFiles, value]);
|
|
49
|
+
const orgValue = (0, react.useMemo)(() => displayFiles.map(getFile), [displayFiles, getFile]);
|
|
50
|
+
const deleteUploadFile = (0, react.useCallback)((file) => {
|
|
51
|
+
setFiles((prevFiles) => prevFiles.filter((f) => f !== file));
|
|
52
|
+
}, []);
|
|
53
|
+
return {
|
|
54
|
+
uploadFiles,
|
|
55
|
+
handleAccept,
|
|
56
|
+
displayFiles,
|
|
57
|
+
deleteFile: (0, react.useCallback)((fileMeta) => {
|
|
58
|
+
if (fileMeta.file) deleteUploadFile(fileMeta.file);
|
|
59
|
+
const key = require_get_file_key.getFileKey(fileMeta);
|
|
60
|
+
fileCacheRef.current.delete(key);
|
|
61
|
+
if (!multiple) {
|
|
62
|
+
onChangeRef.current?.(null);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
require_utils.callOnChange(displayFiles.filter((f) => !require_is_file_equal.isFileEqual(f, fileMeta)), multiple, onChangeRef.current);
|
|
66
|
+
}, [
|
|
67
|
+
deleteUploadFile,
|
|
68
|
+
multiple,
|
|
69
|
+
displayFiles
|
|
70
|
+
]),
|
|
71
|
+
getFile,
|
|
72
|
+
orgValue
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
exports.useFileUploadStore = useFileUploadStore;
|
|
@@ -1 +1,75 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getFileKey } from "../utils/get-file-key.js";
|
|
2
|
+
import { getFileMetaAndFile } from "../utils/get-file-meta.js";
|
|
3
|
+
import { isFileEqual } from "../utils/is-file-equal.js";
|
|
4
|
+
import { mergeFileMetadata } from "../utils/merge-file-metadata.js";
|
|
5
|
+
import { callOnChange, handleFileValueChange, normalizeToArray } from "../../file-upload-inline/utils.js";
|
|
6
|
+
import { createPlaceholderFile } from "../utils/create-placeholder-file.js";
|
|
7
|
+
import { useCallback, useMemo, useRef, useState } from "react";
|
|
8
|
+
|
|
9
|
+
//#region src/file-upload/hooks/use-file-upload-store.ts
|
|
10
|
+
function useFileUploadStore({ value, onChange, multiple, preventDuplicates = false }) {
|
|
11
|
+
const [uploadFiles, setFiles] = useState([]);
|
|
12
|
+
const onChangeRef = useRef(onChange);
|
|
13
|
+
onChangeRef.current = onChange;
|
|
14
|
+
const fileCacheRef = useRef(/* @__PURE__ */ new Map());
|
|
15
|
+
const getFile = useCallback((fileMeta) => {
|
|
16
|
+
if (fileMeta.file) return fileMeta.file;
|
|
17
|
+
const key = getFileKey(fileMeta);
|
|
18
|
+
const cached = fileCacheRef.current.get(key);
|
|
19
|
+
if (cached) return cached;
|
|
20
|
+
const created = createPlaceholderFile(fileMeta);
|
|
21
|
+
fileCacheRef.current.set(key, created);
|
|
22
|
+
return created;
|
|
23
|
+
}, []);
|
|
24
|
+
const handleAccept = useCallback((acceptedFiles) => {
|
|
25
|
+
const newFiles = preventDuplicates ? acceptedFiles.filter((file) => {
|
|
26
|
+
const key = getFileKey(file);
|
|
27
|
+
return !uploadFiles.some((existing) => getFileKey(existing) === key);
|
|
28
|
+
}) : acceptedFiles;
|
|
29
|
+
setFiles((prev) => [...prev, ...newFiles]);
|
|
30
|
+
handleFileValueChange(normalizeToArray(value), newFiles, multiple, onChangeRef.current);
|
|
31
|
+
}, [
|
|
32
|
+
preventDuplicates,
|
|
33
|
+
multiple,
|
|
34
|
+
value,
|
|
35
|
+
uploadFiles
|
|
36
|
+
]);
|
|
37
|
+
const displayFiles = useMemo(() => {
|
|
38
|
+
const files = (() => {
|
|
39
|
+
if (!value) return uploadFiles.map((file) => getFileMetaAndFile(file));
|
|
40
|
+
return mergeFileMetadata(normalizeToArray(value), uploadFiles);
|
|
41
|
+
})();
|
|
42
|
+
files.forEach((fileWithMeta) => {
|
|
43
|
+
if (fileWithMeta.file) fileCacheRef.current.set(getFileKey(fileWithMeta), fileWithMeta.file);
|
|
44
|
+
});
|
|
45
|
+
return files;
|
|
46
|
+
}, [uploadFiles, value]);
|
|
47
|
+
const orgValue = useMemo(() => displayFiles.map(getFile), [displayFiles, getFile]);
|
|
48
|
+
const deleteUploadFile = useCallback((file) => {
|
|
49
|
+
setFiles((prevFiles) => prevFiles.filter((f) => f !== file));
|
|
50
|
+
}, []);
|
|
51
|
+
return {
|
|
52
|
+
uploadFiles,
|
|
53
|
+
handleAccept,
|
|
54
|
+
displayFiles,
|
|
55
|
+
deleteFile: useCallback((fileMeta) => {
|
|
56
|
+
if (fileMeta.file) deleteUploadFile(fileMeta.file);
|
|
57
|
+
const key = getFileKey(fileMeta);
|
|
58
|
+
fileCacheRef.current.delete(key);
|
|
59
|
+
if (!multiple) {
|
|
60
|
+
onChangeRef.current?.(null);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
callOnChange(displayFiles.filter((f) => !isFileEqual(f, fileMeta)), multiple, onChangeRef.current);
|
|
64
|
+
}, [
|
|
65
|
+
deleteUploadFile,
|
|
66
|
+
multiple,
|
|
67
|
+
displayFiles
|
|
68
|
+
]),
|
|
69
|
+
getFile,
|
|
70
|
+
orgValue
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
export { useFileUploadStore };
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_use_file_upload_store = require('./hooks/use-file-upload-store.cjs');
|
|
2
|
+
const require_FileUpload = require('./FileUpload.cjs');
|
|
3
|
+
const require_use_file_error = require('./hooks/use-file-error.cjs');
|
|
4
|
+
const require_use_file_upload_progress_callbacks = require('./hooks/use-file-upload-progress-callbacks.cjs');
|
|
5
|
+
require('./hooks/index.cjs');
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { FileMetadata, FileUploadBaseProps, FileUploadProgressCallBacks, FileUploadProps, MultiFileUploadProps, OnChangeMultipleFiles, OnChangeSingleFile, SingleFileUploadProps } from "./types/index.cjs";
|
|
2
|
-
import { FileUpload } from "./FileUpload.cjs";
|
|
2
|
+
import { FileUpload } from "./FileUpload.cjs";
|
|
3
|
+
import "./hooks/index.cjs";
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useFileUploadStore } from "./hooks/use-file-upload-store.js";
|
|
2
|
+
import { FileUpload } from "./FileUpload.js";
|
|
3
|
+
import { useFileError } from "./hooks/use-file-error.js";
|
|
4
|
+
import { useFileUploadProgressCallbacks } from "./hooks/use-file-upload-progress-callbacks.js";
|
|
5
|
+
import "./hooks/index.js";
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/file-upload/utils/create-placeholder-file.ts
|
|
3
|
+
function createPlaceholderFile(meta) {
|
|
4
|
+
return new File([], meta.name, {
|
|
5
|
+
type: meta.type,
|
|
6
|
+
lastModified: meta.lastModified
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
exports.createPlaceholderFile = createPlaceholderFile;
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/file-upload/utils/create-placeholder-file.ts
|
|
2
|
+
function createPlaceholderFile(meta) {
|
|
3
|
+
return new File([], meta.name, {
|
|
4
|
+
type: meta.type,
|
|
5
|
+
lastModified: meta.lastModified
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { createPlaceholderFile };
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/file-upload/utils/get-file-key.ts
|
|
3
|
+
function getFileKey(file) {
|
|
4
|
+
return `${file.name}-${file.lastModified}-${file.type}-${file.size}`;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.getFileKey = getFileKey;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../types/index.cjs";
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/file-upload/utils/get-file-key.ts
|
|
2
|
+
function getFileKey(file) {
|
|
3
|
+
return `${file.name}-${file.lastModified}-${file.type}-${file.size}`;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { getFileKey };
|
|
@@ -1 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/file-upload/utils/get-file-meta.ts
|
|
3
|
+
function getFileMeta(file) {
|
|
4
|
+
return {
|
|
5
|
+
name: file.name,
|
|
6
|
+
size: file.size,
|
|
7
|
+
type: file.type,
|
|
8
|
+
lastModified: file.lastModified
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function getFileMetaAndFile(file) {
|
|
12
|
+
return {
|
|
13
|
+
name: file.name,
|
|
14
|
+
size: file.size,
|
|
15
|
+
type: file.type,
|
|
16
|
+
lastModified: file.lastModified,
|
|
17
|
+
file
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.getFileMeta = getFileMeta;
|
|
23
|
+
exports.getFileMetaAndFile = getFileMetaAndFile;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../types/index.cjs";
|
|
@@ -1 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/file-upload/utils/get-file-meta.ts
|
|
2
|
+
function getFileMeta(file) {
|
|
3
|
+
return {
|
|
4
|
+
name: file.name,
|
|
5
|
+
size: file.size,
|
|
6
|
+
type: file.type,
|
|
7
|
+
lastModified: file.lastModified
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function getFileMetaAndFile(file) {
|
|
11
|
+
return {
|
|
12
|
+
name: file.name,
|
|
13
|
+
size: file.size,
|
|
14
|
+
type: file.type,
|
|
15
|
+
lastModified: file.lastModified,
|
|
16
|
+
file
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { getFileMeta, getFileMetaAndFile };
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/file-upload/utils/is-file-equal.ts
|
|
3
|
+
function isFileEqual(a, b) {
|
|
4
|
+
if (!a || !b) return false;
|
|
5
|
+
return a.name === b.name && a.size === b.size && a.lastModified === b.lastModified;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.isFileEqual = isFileEqual;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../types/index.cjs";
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/file-upload/utils/is-file-equal.ts
|
|
2
|
+
function isFileEqual(a, b) {
|
|
3
|
+
if (!a || !b) return false;
|
|
4
|
+
return a.name === b.name && a.size === b.size && a.lastModified === b.lastModified;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { isFileEqual };
|
|
@@ -1 +1,26 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_get_file_meta = require('./get-file-meta.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/file-upload/utils/merge-file-metadata.ts
|
|
4
|
+
/**
|
|
5
|
+
* Merges newly selected files with existing files (when multiple is true)
|
|
6
|
+
* Removes duplicates by filename and lastModified, keeping all unique versions
|
|
7
|
+
*
|
|
8
|
+
* @param existingFiles - The current files from value prop
|
|
9
|
+
* @param newFiles - The newly selected File objects from input
|
|
10
|
+
* @returns Array of merged FileMetadata objects
|
|
11
|
+
*/
|
|
12
|
+
function mergeFileMetadata(existingFiles, newFiles) {
|
|
13
|
+
const fileMap = /* @__PURE__ */ new Map();
|
|
14
|
+
existingFiles.forEach((fileMetaData) => {
|
|
15
|
+
const key = `${fileMetaData.name}-${fileMetaData.lastModified}`;
|
|
16
|
+
fileMap.set(key, fileMetaData);
|
|
17
|
+
});
|
|
18
|
+
newFiles.forEach((file) => {
|
|
19
|
+
const key = `${file.name}-${file.lastModified}`;
|
|
20
|
+
fileMap.set(key, require_get_file_meta.getFileMetaAndFile(file));
|
|
21
|
+
});
|
|
22
|
+
return Array.from(fileMap.values());
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.mergeFileMetadata = mergeFileMetadata;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../types/index.cjs";
|
|
@@ -1 +1,26 @@
|
|
|
1
|
-
import{getFileMetaAndFile
|
|
1
|
+
import { getFileMetaAndFile } from "./get-file-meta.js";
|
|
2
|
+
|
|
3
|
+
//#region src/file-upload/utils/merge-file-metadata.ts
|
|
4
|
+
/**
|
|
5
|
+
* Merges newly selected files with existing files (when multiple is true)
|
|
6
|
+
* Removes duplicates by filename and lastModified, keeping all unique versions
|
|
7
|
+
*
|
|
8
|
+
* @param existingFiles - The current files from value prop
|
|
9
|
+
* @param newFiles - The newly selected File objects from input
|
|
10
|
+
* @returns Array of merged FileMetadata objects
|
|
11
|
+
*/
|
|
12
|
+
function mergeFileMetadata(existingFiles, newFiles) {
|
|
13
|
+
const fileMap = /* @__PURE__ */ new Map();
|
|
14
|
+
existingFiles.forEach((fileMetaData) => {
|
|
15
|
+
const key = `${fileMetaData.name}-${fileMetaData.lastModified}`;
|
|
16
|
+
fileMap.set(key, fileMetaData);
|
|
17
|
+
});
|
|
18
|
+
newFiles.forEach((file) => {
|
|
19
|
+
const key = `${file.name}-${file.lastModified}`;
|
|
20
|
+
fileMap.set(key, getFileMetaAndFile(file));
|
|
21
|
+
});
|
|
22
|
+
return Array.from(fileMap.values());
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { mergeFileMetadata };
|
|
@@ -1 +1,71 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
5
|
+
const require_use_file_upload_store = require('../file-upload/hooks/use-file-upload-store.cjs');
|
|
6
|
+
require('../file-upload/index.cjs');
|
|
7
|
+
const require_defaults = require('./defaults.cjs');
|
|
8
|
+
const require_FileUploadInlineItem = require('./FileUploadInlineItem.cjs');
|
|
9
|
+
let __pixpilot_shadcn = require("@pixpilot/shadcn");
|
|
10
|
+
__pixpilot_shadcn = require_rolldown_runtime.__toESM(__pixpilot_shadcn);
|
|
11
|
+
let lucide_react = require("lucide-react");
|
|
12
|
+
lucide_react = require_rolldown_runtime.__toESM(lucide_react);
|
|
13
|
+
let react = require("react");
|
|
14
|
+
react = require_rolldown_runtime.__toESM(react);
|
|
15
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
16
|
+
react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
|
|
17
|
+
|
|
18
|
+
//#region src/file-upload-inline/FileUploadInline.tsx
|
|
19
|
+
/**
|
|
20
|
+
* FileUploadInline - An inline file upload component using FileUpload primitives
|
|
21
|
+
*/
|
|
22
|
+
function FileUploadInline(props) {
|
|
23
|
+
const { value, onChange, className, disabled = require_defaults.defaultOptions.disabled, multiple = require_defaults.defaultOptions.multiple, buttonText, showIcon = require_defaults.defaultOptions.showIcon, onAccept, preventDuplicates,...rest } = props;
|
|
24
|
+
const { handleAccept, displayFiles, deleteFile, getFile, orgValue } = require_use_file_upload_store.useFileUploadStore({
|
|
25
|
+
value,
|
|
26
|
+
onChange,
|
|
27
|
+
multiple,
|
|
28
|
+
preventDuplicates
|
|
29
|
+
});
|
|
30
|
+
const handleFileAccept = (0, react.useCallback)((files) => {
|
|
31
|
+
onAccept?.(files);
|
|
32
|
+
handleAccept(files);
|
|
33
|
+
}, [handleAccept, onAccept]);
|
|
34
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.FileUpload, {
|
|
35
|
+
...rest,
|
|
36
|
+
value: orgValue,
|
|
37
|
+
onAccept: handleFileAccept,
|
|
38
|
+
disabled,
|
|
39
|
+
multiple,
|
|
40
|
+
className: (0, __pixpilot_shadcn.cn)("space-y-2", className),
|
|
41
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(multiple || !multiple && displayFiles.length === 0) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.FileUploadDropzone, {
|
|
42
|
+
className: (0, __pixpilot_shadcn.cn)("rounded-md border border-input border-solid flex-row bg-background px-3 py-0 display-block w-full cursor-pointer", "hover:bg-accent/50 transition-colors m-0", disabled && "cursor-not-allowed opacity-50"),
|
|
43
|
+
children: [showIcon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.CloudUpload, { className: "h-4 w-4 shrink-0 mx-1 text-muted-foreground" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.FileUploadTrigger, {
|
|
44
|
+
asChild: true,
|
|
45
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.Button, {
|
|
46
|
+
variant: "link",
|
|
47
|
+
size: "sm",
|
|
48
|
+
className: "h-auto py-2 px-0 text-sm text-muted-foreground hover:no-underline justify-start flex-1",
|
|
49
|
+
disabled,
|
|
50
|
+
children: buttonText
|
|
51
|
+
})
|
|
52
|
+
})]
|
|
53
|
+
}), displayFiles.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.FileUploadList, {
|
|
54
|
+
className: "space-y-1 m-0",
|
|
55
|
+
forceMount: true,
|
|
56
|
+
children: displayFiles.map((data) => {
|
|
57
|
+
const { name, lastModified } = data;
|
|
58
|
+
const key = `${name}-${lastModified}`;
|
|
59
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_FileUploadInlineItem.FileUploadInlineItem, {
|
|
60
|
+
...data,
|
|
61
|
+
file: getFile(data),
|
|
62
|
+
disabled,
|
|
63
|
+
onDelete: deleteFile
|
|
64
|
+
}, key);
|
|
65
|
+
})
|
|
66
|
+
})] })
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
exports.FileUploadInline = FileUploadInline;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { FileUploadInlineProps } from "./types.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react_jsx_runtime6 from "react/jsx-runtime";
|
|
3
3
|
|
|
4
4
|
//#region src/file-upload-inline/FileUploadInline.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* FileUploadInline - An inline file upload component using FileUpload primitives
|
|
7
7
|
*/
|
|
8
|
-
declare function FileUploadInline(props: FileUploadInlineProps):
|
|
8
|
+
declare function FileUploadInline(props: FileUploadInlineProps): react_jsx_runtime6.JSX.Element;
|
|
9
9
|
//#endregion
|
|
10
10
|
export { FileUploadInline };
|
|
@@ -1 +1,66 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { useFileUploadStore } from "../file-upload/hooks/use-file-upload-store.js";
|
|
5
|
+
import "../file-upload/index.js";
|
|
6
|
+
import { defaultOptions } from "./defaults.js";
|
|
7
|
+
import { FileUploadInlineItem } from "./FileUploadInlineItem.js";
|
|
8
|
+
import { Button, FileUpload, FileUploadDropzone, FileUploadList, FileUploadTrigger, cn } from "@pixpilot/shadcn";
|
|
9
|
+
import { CloudUpload } from "lucide-react";
|
|
10
|
+
import { useCallback } from "react";
|
|
11
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
|
|
13
|
+
//#region src/file-upload-inline/FileUploadInline.tsx
|
|
14
|
+
/**
|
|
15
|
+
* FileUploadInline - An inline file upload component using FileUpload primitives
|
|
16
|
+
*/
|
|
17
|
+
function FileUploadInline(props) {
|
|
18
|
+
const { value, onChange, className, disabled = defaultOptions.disabled, multiple = defaultOptions.multiple, buttonText, showIcon = defaultOptions.showIcon, onAccept, preventDuplicates,...rest } = props;
|
|
19
|
+
const { handleAccept, displayFiles, deleteFile, getFile, orgValue } = useFileUploadStore({
|
|
20
|
+
value,
|
|
21
|
+
onChange,
|
|
22
|
+
multiple,
|
|
23
|
+
preventDuplicates
|
|
24
|
+
});
|
|
25
|
+
const handleFileAccept = useCallback((files) => {
|
|
26
|
+
onAccept?.(files);
|
|
27
|
+
handleAccept(files);
|
|
28
|
+
}, [handleAccept, onAccept]);
|
|
29
|
+
return /* @__PURE__ */ jsx(FileUpload, {
|
|
30
|
+
...rest,
|
|
31
|
+
value: orgValue,
|
|
32
|
+
onAccept: handleFileAccept,
|
|
33
|
+
disabled,
|
|
34
|
+
multiple,
|
|
35
|
+
className: cn("space-y-2", className),
|
|
36
|
+
children: /* @__PURE__ */ jsxs(Fragment, { children: [(multiple || !multiple && displayFiles.length === 0) && /* @__PURE__ */ jsxs(FileUploadDropzone, {
|
|
37
|
+
className: cn("rounded-md border border-input border-solid flex-row bg-background px-3 py-0 display-block w-full cursor-pointer", "hover:bg-accent/50 transition-colors m-0", disabled && "cursor-not-allowed opacity-50"),
|
|
38
|
+
children: [showIcon && /* @__PURE__ */ jsx(CloudUpload, { className: "h-4 w-4 shrink-0 mx-1 text-muted-foreground" }), /* @__PURE__ */ jsx(FileUploadTrigger, {
|
|
39
|
+
asChild: true,
|
|
40
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
41
|
+
variant: "link",
|
|
42
|
+
size: "sm",
|
|
43
|
+
className: "h-auto py-2 px-0 text-sm text-muted-foreground hover:no-underline justify-start flex-1",
|
|
44
|
+
disabled,
|
|
45
|
+
children: buttonText
|
|
46
|
+
})
|
|
47
|
+
})]
|
|
48
|
+
}), displayFiles.length > 0 && /* @__PURE__ */ jsx(FileUploadList, {
|
|
49
|
+
className: "space-y-1 m-0",
|
|
50
|
+
forceMount: true,
|
|
51
|
+
children: displayFiles.map((data) => {
|
|
52
|
+
const { name, lastModified } = data;
|
|
53
|
+
const key = `${name}-${lastModified}`;
|
|
54
|
+
return /* @__PURE__ */ jsx(FileUploadInlineItem, {
|
|
55
|
+
...data,
|
|
56
|
+
file: getFile(data),
|
|
57
|
+
disabled,
|
|
58
|
+
onDelete: deleteFile
|
|
59
|
+
}, key);
|
|
60
|
+
})
|
|
61
|
+
})] })
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { FileUploadInline };
|