@vkzstudio/muza-ui 1.0.18 → 1.0.19

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.
@@ -1,5 +1,4 @@
1
- interface FileItemProps {
2
- file: File;
1
+ interface FileItemBaseProps {
3
2
  uploaded?: boolean;
4
3
  progress?: number;
5
4
  size?: 'sm' | 'base' | 'lg';
@@ -10,6 +9,17 @@ interface FileItemProps {
10
9
  onDelete: () => void;
11
10
  onError?: (error: string, file?: File) => void;
12
11
  }
13
- export declare const FileItem: ({ file, uploaded, progress, size, disabled, readOnly, note, error, onDelete, onError, }: FileItemProps) => import("react/jsx-runtime").JSX.Element;
12
+ interface FileItemFileProps extends FileItemBaseProps {
13
+ source: 'file';
14
+ file: File;
15
+ }
16
+ interface FileItemUrlProps extends FileItemBaseProps {
17
+ source: 'url';
18
+ url: string;
19
+ name: string;
20
+ type?: string;
21
+ }
22
+ type FileItemProps = FileItemFileProps | FileItemUrlProps;
23
+ export declare const FileItem: (props: FileItemProps) => import("react/jsx-runtime").JSX.Element;
14
24
  export {};
15
25
  //# sourceMappingURL=FileItem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FileItem.d.ts","sourceRoot":"","sources":["../../../src/components/FileUpload/FileItem.tsx"],"names":[],"mappings":"AA4CA,UAAU,aAAa;IACrB,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAA;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,KAAK,IAAI,CAAA;CAC/C;AAyDD,eAAO,MAAM,QAAQ,GAAI,yFAWtB,aAAa,4CAmJf,CAAA"}
1
+ {"version":3,"file":"FileItem.d.ts","sourceRoot":"","sources":["../../../src/components/FileUpload/FileItem.tsx"],"names":[],"mappings":"AA4CA,UAAU,iBAAiB;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAA;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,KAAK,IAAI,CAAA;CAC/C;AAED,UAAU,iBAAkB,SAAQ,iBAAiB;IACnD,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,IAAI,CAAA;CACX;AAED,UAAU,gBAAiB,SAAQ,iBAAiB;IAClD,MAAM,EAAE,KAAK,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,KAAK,aAAa,GAAG,iBAAiB,GAAG,gBAAgB,CAAA;AA2DzD,eAAO,MAAM,QAAQ,GAAI,OAAO,aAAa,4CA6L5C,CAAA"}
@@ -1,21 +1,21 @@
1
- import { jsxs as u, jsx as o } from "react/jsx-runtime";
2
- import * as m from "react";
3
- import { cva as k } from "class-variance-authority";
4
- import { useMuzaTranslations as w } from "../../translations/TranslationContext.js";
5
- import { cn as i } from "../../utils/cn.js";
6
- import { GalleryOutline as N, CloseCircleBold as z, DownloadMinimalisticBold as L, TrashBinTrashBold as U } from "@solar-icons/react-perf";
7
- import { Typography as f } from "../Typography/Typography.js";
8
- const B = (a, l, t) => {
9
- let r = null, e = null;
1
+ import { jsxs as p, jsx as i } from "react/jsx-runtime";
2
+ import * as f from "react";
3
+ import { cva as z } from "class-variance-authority";
4
+ import { useMuzaTranslations as L } from "../../translations/TranslationContext.js";
5
+ import { cn as l } from "../../utils/cn.js";
6
+ import { GalleryOutline as B, CloseCircleBold as C, DownloadMinimalisticBold as R, TrashBinTrashBold as j } from "@solar-icons/react-perf";
7
+ import { Typography as b } from "../Typography/Typography.js";
8
+ const E = (e, a, t) => {
9
+ let r = null, o = null;
10
10
  try {
11
- r = URL.createObjectURL(a), e = document.createElement("a"), e.href = r, e.download = a.name, e.style.display = "none", document.body.appendChild(e), e.click();
11
+ r = URL.createObjectURL(e), o = document.createElement("a"), o.href = r, o.download = e.name, o.style.display = "none", document.body.appendChild(o), o.click();
12
12
  } catch (d) {
13
- const n = d instanceof Error ? d.message : t ?? "Download failed";
14
- console.error("Download failed:", d), l == null || l(n, a);
13
+ const s = d instanceof Error ? d.message : t ?? "Download failed";
14
+ console.error("Download failed:", d), a == null || a(s, e);
15
15
  } finally {
16
- e && document.body.contains(e) && document.body.removeChild(e), r && URL.revokeObjectURL(r);
16
+ o && document.body.contains(o) && document.body.removeChild(o), r && URL.revokeObjectURL(r);
17
17
  }
18
- }, C = k(
18
+ }, O = z(
19
19
  [
20
20
  "flex flex-1 items-center gap-sm rounded-full border transition-colors",
21
21
  "relative pr-comp-input-p-hor pl-comp-input-p-hor",
@@ -60,126 +60,140 @@ const B = (a, l, t) => {
60
60
  size: "base"
61
61
  }
62
62
  }
63
- ), b = i([
63
+ ), h = l([
64
64
  "relative h-fit w-fit border-none rounded-full focus-visible-default",
65
65
  "before:absolute before:inset-[-3px]",
66
66
  "bg-none cursor-pointer disabled:cursor-not-allowed",
67
67
  "text-comp-file-upload-icon-def-secondary",
68
68
  "disabled:text-comp-file-upload-icon-def-disabled"
69
- ]), D = ({
70
- file: a,
71
- uploaded: l,
72
- progress: t,
73
- size: r,
74
- disabled: e,
75
- readOnly: d = !1,
76
- note: n,
77
- error: c,
78
- onDelete: h,
79
- onError: v
80
- }) => {
81
- const s = w(), [x, g] = m.useState(!1), y = m.useMemo(() => e ? "disabled" : c ? "error" : typeof t == "number" && t > 0 ? "loading" : "default", [e, c, t]), p = m.useMemo(() => {
82
- if (a.type.startsWith("image/"))
83
- return URL.createObjectURL(a);
84
- }, [a]);
85
- return m.useEffect(() => {
86
- g(!1);
87
- }, [a]), /* @__PURE__ */ u("li", { className: "flex flex-col gap-sm", children: [
88
- /* @__PURE__ */ u(
69
+ ]), I = /\.(jpe?g|png|gif|webp|svg|bmp|ico|avif|tiff?)$/i, G = (e) => {
70
+ const {
71
+ uploaded: a,
72
+ progress: t,
73
+ size: r,
74
+ disabled: o,
75
+ readOnly: d = !1,
76
+ note: s,
77
+ error: c,
78
+ onDelete: x,
79
+ onError: k
80
+ } = e, m = L(), [g, y] = f.useState(!1), v = e.source === "file" ? e.file.name : e.name, w = e.source === "url" ? (e.type ?? "").startsWith("image/") || I.test(e.name) : e.file.type.startsWith("image/"), n = e.source === "file" ? e.file : e.url, U = f.useMemo(() => o ? "disabled" : c ? "error" : typeof t == "number" && t > 0 ? "loading" : "default", [o, c, t]), u = f.useMemo(() => {
81
+ if (w)
82
+ return typeof n == "string" ? n : URL.createObjectURL(n);
83
+ }, [w, n]);
84
+ return f.useEffect(() => y(!1), [n]), /* @__PURE__ */ p("li", { className: "flex flex-col gap-sm", children: [
85
+ /* @__PURE__ */ p(
89
86
  "div",
90
87
  {
91
- className: i(
92
- C({
93
- variant: y,
88
+ className: l(
89
+ O({
90
+ variant: U,
94
91
  size: r
95
92
  })
96
93
  ),
97
94
  children: [
98
- p && !x && /* @__PURE__ */ o(
95
+ u && !g && /* @__PURE__ */ i(
99
96
  "img",
100
97
  {
101
- src: p,
102
- alt: a.name,
98
+ src: u,
99
+ alt: v,
103
100
  width: 24,
104
101
  height: 24,
105
- onError: () => g(!0),
106
- className: i("size-icon-medium shrink-0 rounded-xs object-cover", {
107
- "opacity-50 saturate-0": e
102
+ onError: () => y(!0),
103
+ className: l("size-icon-medium shrink-0 rounded-xs object-cover", {
104
+ "opacity-50 saturate-0": o
108
105
  })
109
106
  }
110
107
  ),
111
- p && x && /* @__PURE__ */ o(
112
- N,
108
+ u && g && /* @__PURE__ */ i(
109
+ B,
113
110
  {
114
- className: i(
111
+ className: l(
115
112
  "text-icon-dark-secondary size-icon-medium shrink-0",
116
113
  {
117
- "opacity-50": e
114
+ "opacity-50": o
118
115
  }
119
116
  )
120
117
  }
121
118
  ),
122
- /* @__PURE__ */ o(
123
- f,
119
+ /* @__PURE__ */ i(
120
+ b,
124
121
  {
125
122
  className: "flex-grow truncate",
126
123
  component: "span",
127
124
  size: "sm",
128
125
  fixY: !0,
129
- children: a.name
126
+ children: v
130
127
  }
131
128
  ),
132
- !l && /* @__PURE__ */ o(
129
+ !a && /* @__PURE__ */ i(
133
130
  "button",
134
131
  {
135
- disabled: e,
136
- onClick: h,
137
- "aria-label": s.fileUpload.deleteButtonAriaLabel,
138
- className: i(
139
- b,
132
+ disabled: o,
133
+ onClick: x,
134
+ "aria-label": m.fileUpload.deleteButtonAriaLabel,
135
+ className: l(
136
+ h,
140
137
  "text-comp-file-upload-icon-def-secondary",
141
138
  "hover:text-comp-file-upload-icon-def-hover",
142
139
  "focus-visible:text-comp-file-upload-icon-def-focused",
143
140
  "disabled:text-comp-file-upload-icon-def-disabled"
144
141
  ),
145
- children: /* @__PURE__ */ o(z, { className: "size-icon-medium" })
142
+ children: /* @__PURE__ */ i(C, { className: "size-icon-medium" })
146
143
  }
147
144
  ),
148
- l && /* @__PURE__ */ u("div", { className: "flex gap-xl", children: [
149
- /* @__PURE__ */ o(
145
+ a && /* @__PURE__ */ p("div", { className: "flex gap-xl", children: [
146
+ /* @__PURE__ */ i(
150
147
  "button",
151
148
  {
152
- disabled: e,
153
- onClick: () => B(a, v, s.fileUpload.downloadError),
154
- "aria-label": s.fileUpload.downloadButtonAriaLabel,
155
- className: i(
156
- b,
149
+ disabled: o,
150
+ onClick: () => e.source === "url" ? (() => {
151
+ try {
152
+ const N = new URL(
153
+ e.url,
154
+ window.location.origin
155
+ );
156
+ ["http:", "https:", "blob:"].includes(N.protocol) && window.open(
157
+ N.href,
158
+ "_blank",
159
+ "noopener,noreferrer"
160
+ );
161
+ } catch {
162
+ }
163
+ })() : E(
164
+ e.file,
165
+ k,
166
+ m.fileUpload.downloadError
167
+ ),
168
+ "aria-label": m.fileUpload.downloadButtonAriaLabel,
169
+ className: l(
170
+ h,
157
171
  "text-comp-file-upload-icon-brand-def",
158
172
  "hover:text-comp-file-upload-icon-brand-hover",
159
173
  "focus-visible:text-comp-file-upload-icon-brand-focused",
160
174
  "disabled:text-comp-file-upload-icon-brand-disabled"
161
175
  ),
162
- children: /* @__PURE__ */ o(L, { className: "size-icon-medium" })
176
+ children: /* @__PURE__ */ i(R, { className: "size-icon-medium" })
163
177
  }
164
178
  ),
165
- !d && /* @__PURE__ */ o(
179
+ !d && /* @__PURE__ */ i(
166
180
  "button",
167
181
  {
168
- disabled: e,
169
- onClick: h,
170
- "aria-label": s.fileUpload.deleteButtonAriaLabel,
171
- className: i(
172
- b,
182
+ disabled: o,
183
+ onClick: x,
184
+ "aria-label": m.fileUpload.deleteButtonAriaLabel,
185
+ className: l(
186
+ h,
173
187
  "text-comp-file-upload-icon-error-def",
174
188
  "hover:text-comp-file-upload-icon-error-hover",
175
189
  "focus-visible:text-comp-file-upload-icon-error-focused",
176
190
  "disabled:text-comp-file-upload-icon-error-disabled"
177
191
  ),
178
- children: /* @__PURE__ */ o(U, { className: "size-icon-medium" })
192
+ children: /* @__PURE__ */ i(j, { className: "size-icon-medium" })
179
193
  }
180
194
  )
181
195
  ] }),
182
- typeof t == "number" && t !== 0 && /* @__PURE__ */ o(
196
+ typeof t == "number" && t !== 0 && /* @__PURE__ */ i(
183
197
  "div",
184
198
  {
185
199
  style: { width: `${t}%` },
@@ -189,19 +203,19 @@ const B = (a, l, t) => {
189
203
  ]
190
204
  }
191
205
  ),
192
- n && /* @__PURE__ */ o(
193
- f,
206
+ s && /* @__PURE__ */ i(
207
+ b,
194
208
  {
195
209
  size: "sm",
196
210
  component: "span",
197
211
  variant: "body",
198
212
  weight: "regular",
199
213
  className: "text-comp-input-text-secondary",
200
- children: n
214
+ children: s
201
215
  }
202
216
  ),
203
- c && /* @__PURE__ */ o(
204
- f,
217
+ c && /* @__PURE__ */ i(
218
+ b,
205
219
  {
206
220
  size: "sm",
207
221
  component: "span",
@@ -214,5 +228,5 @@ const B = (a, l, t) => {
214
228
  ] });
215
229
  };
216
230
  export {
217
- D as FileItem
231
+ G as FileItem
218
232
  };
@@ -6,6 +6,20 @@ declare const fileUploadVariants: (props?: ({
6
6
  isDragActive?: boolean | null | undefined;
7
7
  disabled?: boolean | null | undefined;
8
8
  } & import('class-variance-authority/types').ClassProp) | undefined) => string;
9
+ /**
10
+ * Represents a remote file that is already uploaded and accessible via URL.
11
+ * Used to display previously-uploaded files without re-fetching them as `File` objects.
12
+ */
13
+ export interface PreselectedUrl {
14
+ /** Direct URL to the file. */
15
+ url: string;
16
+ /** Display name for the file. */
17
+ name: string;
18
+ /** MIME type — if starts with `"image/"`, shows thumbnail. Falls back to extension sniffing from name. */
19
+ type?: string;
20
+ /** File size in bytes (for display). */
21
+ size?: number;
22
+ }
9
23
  /**
10
24
  * Props for the FileUpload component.
11
25
  * Extends standard div attributes except `onDrop`, `onError`, and `onChange`
@@ -85,6 +99,10 @@ export interface FileUploadProps extends Omit<React.HTMLAttributes<HTMLDivElemen
85
99
  onDelete?: (file: File, index: number) => void;
86
100
  /** Fires when the file list changes. Receives the updated array of all files. */
87
101
  onChange?: (files: File[]) => void;
102
+ /** Already-uploaded files to display via URL, without needing `File` objects. @default [] */
103
+ preselectedUrls?: PreselectedUrl[];
104
+ /** Fires when a URL-backed item is deleted. Receives the item and its index in the `preselectedUrls` array. */
105
+ onDeleteUrl?: (item: PreselectedUrl, index: number) => void;
88
106
  }
89
107
  declare const FileUpload: React.ForwardRefExoticComponent<FileUploadProps & React.RefAttributes<HTMLDivElement>>;
90
108
  export { FileUpload };
@@ -1 +1 @@
1
- {"version":3,"file":"FileUpload.d.ts","sourceRoot":"","sources":["../../../src/components/FileUpload/FileUpload.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,KAAK,YAAY,EAAO,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,KAAK,eAAe,EAAe,MAAM,gBAAgB,CAAA;AASlE,QAAA,MAAM,kBAAkB;;;;8EAoCvB,CAAA;AAgBD;;;;GAIG;AACH,MAAM,WAAW,eACf,SAAQ,IAAI,CACR,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,EACpC,QAAQ,GAAG,SAAS,GAAG,UAAU,CAClC,EACD,IAAI,CAAC,YAAY,CAAC,OAAO,kBAAkB,CAAC,EAAE,cAAc,CAAC;IAC/D,kFAAkF;IAClF,MAAM,CAAC,EAAE,CAAC,aAAa,EAAE,IAAI,EAAE,KAAK,IAAI,CAAA;IACxC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gHAAgH;IAChH,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,0EAA0E;IAC1E,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAA;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,sFAAsF;IACtF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,6CAA6C;IAC7C,KAAK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
- import { jsxs as u, jsx as i, Fragment as H } from "react/jsx-runtime";
2
- import * as M from "react";
3
- import { cva as T } from "class-variance-authority";
4
- import { useDropzone as E } from "react-dropzone";
5
- import { FileItem as C } from "./FileItem.js";
6
- import { useMuzaTranslations as ee } from "../../translations/TranslationContext.js";
7
- import { Flex as oe } from "../Flex/Flex.js";
8
- import { FormField as te } from "../FormField/FormField.js";
9
- import { cn as P } from "../../utils/cn.js";
10
- import { CloudUploadOutline as re } from "@solar-icons/react-perf";
11
- import { Typography as F } from "../Typography/Typography.js";
12
- const le = T(
1
+ import { jsxs as f, jsx as a, Fragment as ee } from "react/jsx-runtime";
2
+ import * as F from "react";
3
+ import { cva as B } from "class-variance-authority";
4
+ import { useDropzone as oe } from "react-dropzone";
5
+ import { FileItem as K } from "./FileItem.js";
6
+ import { useMuzaTranslations as te } from "../../translations/TranslationContext.js";
7
+ import { Flex as re } from "../Flex/Flex.js";
8
+ import { FormField as le } from "../FormField/FormField.js";
9
+ import { cn as _ } from "../../utils/cn.js";
10
+ import { CloudUploadOutline as se } from "@solar-icons/react-perf";
11
+ import { Typography as S } from "../Typography/Typography.js";
12
+ const ie = B(
13
13
  [
14
14
  "group relative cursor-pointer rounded-xl border-1 border-dashed transition-colors",
15
15
  "p-4xl pt-3xl pr-4xl pb-3xl",
@@ -45,7 +45,7 @@ const le = T(
45
45
  }
46
46
  }
47
47
  }
48
- ), se = T(
48
+ ), ae = B(
49
49
  [
50
50
  "text-center transition-colors",
51
51
  "text-comp-file-upload-text-dark-secondary"
@@ -57,166 +57,186 @@ const le = T(
57
57
  }
58
58
  }
59
59
  }
60
- ), ie = M.forwardRef(
60
+ ), de = F.forwardRef(
61
61
  ({
62
- className: S,
63
- onDrop: n,
64
- accept: f,
65
- multiple: U = !0,
66
- maxSize: x,
67
- maxSizeErrorMessage: V,
68
- size: K = "base",
69
- disabled: c = !1,
70
- readOnly: g = !1,
71
- dropzoneOptions: _,
72
- label: k,
73
- title: B,
74
- subtitle: y,
75
- preselectedFiles: G = [],
76
- fileStatus: J = [],
62
+ className: y,
63
+ onDrop: x,
64
+ accept: u,
65
+ multiple: k = !0,
66
+ maxSize: g,
67
+ maxSizeErrorMessage: G,
68
+ size: $ = "base",
69
+ disabled: p = !1,
70
+ readOnly: m = !1,
71
+ dropzoneOptions: J,
72
+ label: w,
73
+ title: L,
74
+ subtitle: N,
75
+ preselectedFiles: Q = [],
76
+ fileStatus: W = [],
77
77
  itemErrors: b,
78
78
  itemHints: h,
79
- error: L,
79
+ error: X,
80
80
  required: v,
81
- disableRequiredAsterisk: O,
81
+ disableRequiredAsterisk: Y,
82
82
  onError: t,
83
83
  onDelete: z,
84
- onChange: p,
85
- ...Q
86
- }, W) => {
87
- const m = ee(), [w, $] = M.useState(G), [N, I] = M.useState(!1), X = B ?? m.fileUpload.title, R = x ? m.fileUpload.maxSizeError.replace(
84
+ onChange: c,
85
+ preselectedUrls: U = [],
86
+ onDeleteUrl: M,
87
+ ...Z
88
+ }, q) => {
89
+ const n = te(), [I, R] = F.useState(Q), [j, A] = F.useState(!1), O = L ?? n.fileUpload.title, P = g ? n.fileUpload.maxSizeError.replace(
88
90
  "{size}",
89
- (x / (1024 * 1024)).toFixed(0)
90
- ) : "", j = V ?? R, { getRootProps: Y, getInputProps: Z, isDragActive: q } = E({
91
- onDrop: (o, a) => {
91
+ (g / (1024 * 1024)).toFixed(0)
92
+ ) : "", T = G ?? P, { getRootProps: H, getInputProps: D, isDragActive: E } = oe({
93
+ onDrop: (e, l) => {
92
94
  try {
93
- if (I(!1), a.length > 0 && a.some(
94
- (r) => r.errors.some((l) => l.code === "file-too-large")
95
+ if (A(!1), l.length > 0 && l.some(
96
+ (r) => r.errors.some((s) => s.code === "file-too-large")
95
97
  )) {
96
- I(!0);
97
- const r = j || R;
98
- t == null || t(r, a[0].file);
98
+ A(!0);
99
+ const r = T || P;
100
+ t == null || t(r, l[0].file);
99
101
  return;
100
102
  }
101
- $((e) => {
103
+ R((o) => {
102
104
  const r = new Set(
103
- e.map((s) => `${s.name}-${s.size}-${s.lastModified}`)
104
- ), l = o.filter(
105
- (s) => !r.has(`${s.name}-${s.size}-${s.lastModified}`)
106
- ), d = [...e, ...l];
107
- return p == null || p(d), d;
108
- }), n == null || n(o);
109
- } catch (e) {
110
- const r = e instanceof Error ? e.message : m.fileUpload.processingError;
105
+ o.map((i) => `${i.name}-${i.size}-${i.lastModified}`)
106
+ ), s = e.filter(
107
+ (i) => !r.has(`${i.name}-${i.size}-${i.lastModified}`)
108
+ ), d = [...o, ...s];
109
+ return c == null || c(d), d;
110
+ }), x == null || x(e);
111
+ } catch (o) {
112
+ const r = o instanceof Error ? o.message : n.fileUpload.processingError;
111
113
  t == null || t(r);
112
114
  }
113
115
  },
114
- accept: typeof f == "string" ? { [f]: [] } : f ? Object.fromEntries(f.map((o) => [o, []])) : void 0,
115
- multiple: U,
116
- maxSize: x,
117
- disabled: c,
118
- ..._
119
- }), A = g || !U && w.length > 0;
120
- return /* @__PURE__ */ u(oe, { direction: "column", gap: "lg", children: [
121
- (!A || k) && /* @__PURE__ */ i(
122
- te,
116
+ accept: typeof u == "string" ? { [u]: [] } : u ? Object.fromEntries(u.map((e) => [e, []])) : void 0,
117
+ multiple: k,
118
+ maxSize: g,
119
+ disabled: p,
120
+ ...J
121
+ }), V = m || !k && (I.length > 0 || U.length > 0);
122
+ return /* @__PURE__ */ f(re, { direction: "column", gap: "lg", children: [
123
+ (!V || w) && /* @__PURE__ */ a(
124
+ le,
123
125
  {
124
- label: k,
126
+ label: w,
125
127
  required: v,
126
- disableRequiredAsterisk: O,
127
- children: !A && /* @__PURE__ */ u(H, { children: [
128
- /* @__PURE__ */ u(
128
+ disableRequiredAsterisk: Y,
129
+ children: !V && /* @__PURE__ */ f(ee, { children: [
130
+ /* @__PURE__ */ f(
129
131
  "div",
130
132
  {
131
- ref: W,
132
- tabIndex: c ? void 0 : 0,
133
- className: P(
134
- le({
135
- error: L || N,
136
- disabled: c,
137
- className: S,
138
- isDragActive: q
133
+ ref: q,
134
+ tabIndex: p ? void 0 : 0,
135
+ className: _(
136
+ ie({
137
+ error: X || j,
138
+ disabled: p,
139
+ className: y,
140
+ isDragActive: E
139
141
  })
140
142
  ),
141
- ...Y(),
142
- ...Q,
143
+ ...H(),
144
+ ...Z,
143
145
  children: [
144
- /* @__PURE__ */ i(
146
+ /* @__PURE__ */ a(
145
147
  "input",
146
148
  {
147
- ...Z({ required: v }),
149
+ ...D({ required: v }),
148
150
  "aria-required": v
149
151
  }
150
152
  ),
151
- /* @__PURE__ */ i(re, { className: "inline size-comp-file-upload-ico-size" }),
152
- /* @__PURE__ */ u("div", { children: [
153
- /* @__PURE__ */ i(F, { size: "base", component: "p", weight: "medium", children: X }),
154
- y && /* @__PURE__ */ i(
155
- F,
153
+ /* @__PURE__ */ a(se, { className: "inline size-comp-file-upload-ico-size" }),
154
+ /* @__PURE__ */ f("div", { children: [
155
+ /* @__PURE__ */ a(S, { size: "base", component: "p", weight: "medium", children: O }),
156
+ N && /* @__PURE__ */ a(
157
+ S,
156
158
  {
157
159
  size: "sm",
158
160
  component: "p",
159
161
  weight: "regular",
160
- className: P(
161
- se({
162
- disabled: c,
163
- className: S
162
+ className: _(
163
+ ae({
164
+ disabled: p,
165
+ className: y
164
166
  })
165
167
  ),
166
- children: y
168
+ children: N
167
169
  }
168
170
  )
169
171
  ] })
170
172
  ]
171
173
  }
172
174
  ),
173
- N && /* @__PURE__ */ i(
174
- F,
175
+ j && /* @__PURE__ */ a(
176
+ S,
175
177
  {
176
178
  size: "sm",
177
179
  variant: "body",
178
180
  component: "p",
179
181
  weight: "regular",
180
182
  className: "text-comp-file-upload-text-error-def",
181
- children: j
183
+ children: T
182
184
  }
183
185
  )
184
186
  ] })
185
187
  }
186
188
  ),
187
- /* @__PURE__ */ i("ul", { className: "flex flex-col gap-md", children: w.map((o, a) => {
188
- const e = J[a], r = e == null ? void 0 : e.uploaded;
189
- return g && !r ? null : /* @__PURE__ */ i(
190
- C,
189
+ /* @__PURE__ */ f("ul", { className: "flex flex-col gap-md", children: [
190
+ U.map((e, l) => /* @__PURE__ */ a(
191
+ K,
191
192
  {
192
- file: o,
193
- uploaded: r,
194
- progress: e == null ? void 0 : e.progress,
195
- disabled: c,
196
- readOnly: g,
197
- error: b == null ? void 0 : b.get(o),
198
- note: h == null ? void 0 : h.get(o),
199
- onError: t,
200
- size: K,
201
- onDelete: () => {
202
- try {
203
- $((l) => {
204
- const d = l.filter((s, D) => D !== a);
205
- return p == null || p(d), d;
206
- }), z == null || z(o, a);
207
- } catch (l) {
208
- const d = l instanceof Error ? l.message : m.fileUpload.deleteError;
209
- t == null || t(d, o);
210
- }
211
- }
193
+ source: "url",
194
+ url: e.url,
195
+ name: e.name,
196
+ type: e.type,
197
+ uploaded: !0,
198
+ disabled: p,
199
+ readOnly: m,
200
+ size: $,
201
+ onDelete: () => M == null ? void 0 : M(e, l)
212
202
  },
213
- o.name
214
- );
215
- }) })
203
+ `url-${e.url}`
204
+ )),
205
+ I.map((e, l) => {
206
+ const o = W[l], r = o == null ? void 0 : o.uploaded;
207
+ return m && !r ? null : /* @__PURE__ */ a(
208
+ K,
209
+ {
210
+ source: "file",
211
+ file: e,
212
+ uploaded: r,
213
+ progress: o == null ? void 0 : o.progress,
214
+ disabled: p,
215
+ readOnly: m,
216
+ error: b == null ? void 0 : b.get(e),
217
+ note: h == null ? void 0 : h.get(e),
218
+ onError: t,
219
+ size: $,
220
+ onDelete: () => {
221
+ try {
222
+ R((s) => {
223
+ const d = s.filter((i, C) => C !== l);
224
+ return c == null || c(d), d;
225
+ }), z == null || z(e, l);
226
+ } catch (s) {
227
+ const d = s instanceof Error ? s.message : n.fileUpload.deleteError;
228
+ t == null || t(d, e);
229
+ }
230
+ }
231
+ },
232
+ e.name
233
+ );
234
+ })
235
+ ] })
216
236
  ] });
217
237
  }
218
238
  );
219
- ie.displayName = "FileUpload";
239
+ de.displayName = "FileUpload";
220
240
  export {
221
- ie as FileUpload
241
+ de as FileUpload
222
242
  };
@@ -17,4 +17,7 @@ export declare const Disabled: Story;
17
17
  export declare const WithErrorsAndHints: Story;
18
18
  export declare const ReadOnly: Story;
19
19
  export declare const UploadSimulation: Story;
20
+ export declare const PreselectedUrls: Story;
21
+ export declare const MixedFilesAndUrls: Story;
22
+ export declare const SingleFileWithUrl: Story;
20
23
  //# sourceMappingURL=FileUpload.stories.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FileUpload.stories.d.ts","sourceRoot":"","sources":["../../../src/components/FileUpload/FileUpload.stories.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAE3D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,UAAU,CAkKjC,CAAA;AAED,eAAe,IAAI,CAAA;AACnB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAA;AAElC,eAAO,MAAM,OAAO,EAAE,KAerB,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,KAgBtB,CAAA;AAED,eAAO,MAAM,KAAK,EAAE,KAmBnB,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,KAoBpC,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,KAsB9B,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,KAkB3B,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,KAiBxB,CAAA;AAED,eAAO,MAAM,mBAAmB,EAAE,KAqBjC,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,KAexB,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,KAiB3B,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,KAmBtB,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,KA0ChC,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,KAoBtB,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,KA0F9B,CAAA"}
1
+ {"version":3,"file":"FileUpload.stories.d.ts","sourceRoot":"","sources":["../../../src/components/FileUpload/FileUpload.stories.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAE3D,OAAO,EAAE,UAAU,EAAuB,MAAM,cAAc,CAAA;AAE9D,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,UAAU,CA8KjC,CAAA;AAED,eAAe,IAAI,CAAA;AACnB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAA;AAElC,eAAO,MAAM,OAAO,EAAE,KAerB,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,KAgBtB,CAAA;AAED,eAAO,MAAM,KAAK,EAAE,KAmBnB,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,KAoBpC,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,KAsB9B,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,KAkB3B,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,KAiBxB,CAAA;AAED,eAAO,MAAM,mBAAmB,EAAE,KAqBjC,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,KAexB,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,KAiB3B,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,KAmBtB,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,KA0ChC,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,KAoBtB,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,KA0F9B,CAAA;AAmBD,eAAO,MAAM,eAAe,EAAE,KA0B7B,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,KAoC/B,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,KAsB/B,CAAA"}
@@ -1,2 +1,2 @@
1
- export { FileUpload, type FileUploadProps } from './FileUpload';
1
+ export { FileUpload, type FileUploadProps, type PreselectedUrl, } from './FileUpload';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FileUpload/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FileUpload/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,eAAe,EACpB,KAAK,cAAc,GACpB,MAAM,cAAc,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vkzstudio/muza-ui",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "React component library built with Vite, shadcn/ui, and Tailwind CSS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",