@pixpilot/formily-shadcn 1.10.6 → 1.10.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/components/Form.d.ts +2 -2
  2. package/dist/components/FormGrid.d.ts +2 -2
  3. package/dist/components/Input.d.cts +3 -3
  4. package/dist/components/Rating.d.cts +4 -4
  5. package/dist/components/Rating.d.ts +4 -4
  6. package/dist/components/Row.d.cts +2 -2
  7. package/dist/components/Separator.d.ts +2 -2
  8. package/dist/components/Switch.d.cts +2 -2
  9. package/dist/components/TagsInputInline.d.cts +3 -3
  10. package/dist/components/Textarea.d.cts +2 -2
  11. package/dist/components/ToggleButton.d.cts +3 -3
  12. package/dist/components/array-tags/ArrayTags.d.ts +2 -2
  13. package/dist/components/array-toggle-group/ArrayToggleGroup.d.ts +2 -2
  14. package/dist/components/context/types.d.cts +4 -2
  15. package/dist/components/context/types.d.ts +4 -2
  16. package/dist/components/file-upload/index.cjs +2 -0
  17. package/dist/components/file-upload/index.d.cts +6 -3
  18. package/dist/components/file-upload/index.d.ts +6 -4
  19. package/dist/components/file-upload/index.js +2 -0
  20. package/dist/components/file-upload/map-upload-props.d.cts +43 -2
  21. package/dist/components/file-upload/map-upload-props.d.ts +43 -2
  22. package/dist/components/file-upload/types.d.cts +9 -0
  23. package/dist/components/file-upload/types.d.ts +9 -0
  24. package/dist/components/file-upload/use-file-upload-feedback.cjs +43 -29
  25. package/dist/components/file-upload/use-file-upload-feedback.d.cts +14 -0
  26. package/dist/components/file-upload/use-file-upload-feedback.d.ts +14 -0
  27. package/dist/components/file-upload/use-file-upload-feedback.js +43 -29
  28. package/dist/components/schema-field/schema-field-basics.d.cts +288 -288
  29. package/dist/components/schema-field/schema-field-basics.d.ts +299 -299
  30. package/dist/components/schema-field/schema-field-extended.d.cts +486 -486
  31. package/dist/components/schema-field/schema-field-extended.d.ts +33 -33
  32. package/dist/components/schema-field/schema-field.d.cts +398 -398
  33. package/dist/components/schema-field/schema-field.d.ts +409 -409
  34. package/dist/components/slider/Slider.d.cts +3 -3
  35. package/dist/components/slider/SliderInput.d.cts +3 -3
  36. package/dist/components/slider/SliderSelect.d.cts +3 -3
  37. package/dist/components/slider/SliderSelect.d.ts +3 -3
  38. package/dist/index.cjs +5 -1
  39. package/dist/index.d.cts +6 -3
  40. package/dist/index.d.ts +6 -3
  41. package/dist/index.js +3 -1
  42. package/dist/utils/resolve-field-options.d.cts +1 -1
  43. package/dist/utils/resolve-field-options.d.ts +1 -1
  44. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
1
  import { FormContextStates } from "./context/form-context.js";
2
2
  import "./context/index.js";
3
3
  import React from "react";
4
- import * as react_jsx_runtime1 from "react/jsx-runtime";
4
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
5
5
  import { Form } from "@formily/core";
6
6
 
7
7
  //#region src/components/Form.d.ts
@@ -25,6 +25,6 @@ declare function Form$1({
25
25
  onAutoSubmit,
26
26
  layout,
27
27
  settings
28
- }: IFormProps): react_jsx_runtime1.JSX.Element;
28
+ }: IFormProps): react_jsx_runtime0.JSX.Element;
29
29
  //#endregion
30
30
  export { Form$1 as Form };
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import * as react_jsx_runtime0 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime1 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/components/FormGrid.d.ts
5
5
  interface IFormGridProps extends React.HTMLAttributes<HTMLDivElement> {}
@@ -7,6 +7,6 @@ declare function FormGrid({
7
7
  className,
8
8
  children,
9
9
  ...rest
10
- }: IFormGridProps): react_jsx_runtime0.JSX.Element;
10
+ }: IFormGridProps): react_jsx_runtime1.JSX.Element;
11
11
  //#endregion
12
12
  export { FormGrid };
@@ -1,4 +1,4 @@
1
- import * as react12 from "react";
1
+ import * as react9 from "react";
2
2
 
3
3
  //#region src/components/Input.d.ts
4
4
 
@@ -6,12 +6,12 @@ import * as react12 from "react";
6
6
  * Formily-connected Input component
7
7
  * Automatically connects shadcn Input to Formily field state
8
8
  */
9
- declare const Input: react12.ForwardRefExoticComponent<Omit<Partial<react12.ClassAttributes<HTMLInputElement> & react12.InputHTMLAttributes<HTMLInputElement> & {
9
+ declare const Input: react9.ForwardRefExoticComponent<Omit<Partial<react9.ClassAttributes<HTMLInputElement> & react9.InputHTMLAttributes<HTMLInputElement> & {
10
10
  prefix?: React.ReactNode;
11
11
  suffix?: React.ReactNode;
12
12
  groupClassName?: string;
13
13
  prefixClassName?: string;
14
14
  suffixClassName?: string;
15
- }>, "ref"> & react12.RefAttributes<unknown>>;
15
+ }>, "ref"> & react9.RefAttributes<unknown>>;
16
16
  //#endregion
17
17
  export { Input };
@@ -1,4 +1,4 @@
1
- import * as react9 from "react";
1
+ import * as react13 from "react";
2
2
  import * as _pixpilot_shadcn_ui0 from "@pixpilot/shadcn-ui";
3
3
 
4
4
  //#region src/components/Rating.d.ts
@@ -6,8 +6,8 @@ import * as _pixpilot_shadcn_ui0 from "@pixpilot/shadcn-ui";
6
6
  * Formily-connected Rating component
7
7
  * Automatically connects shadcn-ui Rating to Formily field state
8
8
  */
9
- declare const Rating: react9.ForwardRefExoticComponent<Partial<_pixpilot_shadcn_ui0.RatingProps & {
10
- children?: react9.ReactNode | undefined;
11
- }> & react9.RefAttributes<unknown>>;
9
+ declare const Rating: react13.ForwardRefExoticComponent<Partial<_pixpilot_shadcn_ui0.RatingProps & {
10
+ children?: react13.ReactNode | undefined;
11
+ }> & react13.RefAttributes<unknown>>;
12
12
  //#endregion
13
13
  export { Rating };
@@ -1,4 +1,4 @@
1
- import * as react13 from "react";
1
+ import * as react16 from "react";
2
2
  import * as _pixpilot_shadcn_ui0 from "@pixpilot/shadcn-ui";
3
3
 
4
4
  //#region src/components/Rating.d.ts
@@ -6,8 +6,8 @@ import * as _pixpilot_shadcn_ui0 from "@pixpilot/shadcn-ui";
6
6
  * Formily-connected Rating component
7
7
  * Automatically connects shadcn-ui Rating to Formily field state
8
8
  */
9
- declare const Rating$1: react13.ForwardRefExoticComponent<Partial<_pixpilot_shadcn_ui0.RatingProps & {
10
- children?: react13.ReactNode | undefined;
11
- }> & react13.RefAttributes<unknown>>;
9
+ declare const Rating$1: react16.ForwardRefExoticComponent<Partial<_pixpilot_shadcn_ui0.RatingProps & {
10
+ children?: react16.ReactNode | undefined;
11
+ }> & react16.RefAttributes<unknown>>;
12
12
  //#endregion
13
13
  export { Rating$1 as Rating };
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import * as react_jsx_runtime3 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime4 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/components/Row.d.ts
5
5
  interface IRowProps {
@@ -36,6 +36,6 @@ interface IRowProps {
36
36
  declare function Row({
37
37
  className,
38
38
  children
39
- }: IRowProps): react_jsx_runtime3.JSX.Element;
39
+ }: IRowProps): react_jsx_runtime4.JSX.Element;
40
40
  //#endregion
41
41
  export { Row };
@@ -1,4 +1,4 @@
1
- import * as react16 from "react";
1
+ import * as react13 from "react";
2
2
  import * as _radix_ui_react_separator0 from "@radix-ui/react-separator";
3
3
 
4
4
  //#region src/components/Separator.d.ts
@@ -6,6 +6,6 @@ import * as _radix_ui_react_separator0 from "@radix-ui/react-separator";
6
6
  * Formily-connected Separator component
7
7
  * A visual divider for content sections
8
8
  */
9
- declare const Separator: react16.ForwardRefExoticComponent<Omit<Partial<_radix_ui_react_separator0.SeparatorProps & react16.RefAttributes<HTMLDivElement>>, "ref"> & react16.RefAttributes<unknown>>;
9
+ declare const Separator: react13.ForwardRefExoticComponent<Omit<Partial<_radix_ui_react_separator0.SeparatorProps & react13.RefAttributes<HTMLDivElement>>, "ref"> & react13.RefAttributes<unknown>>;
10
10
  //#endregion
11
11
  export { Separator };
@@ -1,4 +1,4 @@
1
- import * as react21 from "react";
1
+ import * as react19 from "react";
2
2
  import * as _radix_ui_react_switch0 from "@radix-ui/react-switch";
3
3
 
4
4
  //#region src/components/Switch.d.ts
@@ -6,6 +6,6 @@ import * as _radix_ui_react_switch0 from "@radix-ui/react-switch";
6
6
  * Formily-connected Switch component
7
7
  * Toggle switch for boolean values
8
8
  */
9
- declare const Switch: react21.ForwardRefExoticComponent<Omit<Partial<_radix_ui_react_switch0.SwitchProps & react21.RefAttributes<HTMLButtonElement>>, "ref"> & react21.RefAttributes<unknown>>;
9
+ declare const Switch: react19.ForwardRefExoticComponent<Omit<Partial<_radix_ui_react_switch0.SwitchProps & react19.RefAttributes<HTMLButtonElement>>, "ref"> & react19.RefAttributes<unknown>>;
10
10
  //#endregion
11
11
  export { Switch };
@@ -1,5 +1,5 @@
1
- import * as react19 from "react";
2
- import * as _pixpilot_shadcn_ui1 from "@pixpilot/shadcn-ui";
1
+ import * as react25 from "react";
2
+ import * as _pixpilot_shadcn_ui2 from "@pixpilot/shadcn-ui";
3
3
 
4
4
  //#region src/components/TagsInputInline.d.ts
5
5
 
@@ -10,6 +10,6 @@ import * as _pixpilot_shadcn_ui1 from "@pixpilot/shadcn-ui";
10
10
  * Based on DiceUI's tags-input for inline tag editing with keyboard navigation
11
11
  * and validation support.
12
12
  */
13
- declare const TagsInputInLine: react19.ForwardRefExoticComponent<Partial<_pixpilot_shadcn_ui1.TagsInputProps> & react19.RefAttributes<unknown>>;
13
+ declare const TagsInputInLine: react25.ForwardRefExoticComponent<Partial<_pixpilot_shadcn_ui2.TagsInputProps> & react25.RefAttributes<unknown>>;
14
14
  //#endregion
15
15
  export { TagsInputInLine };
@@ -1,9 +1,9 @@
1
- import * as react24 from "react";
1
+ import * as react27 from "react";
2
2
 
3
3
  //#region src/components/Textarea.d.ts
4
4
  /**
5
5
  * Formily-connected Textarea component
6
6
  */
7
- declare const Textarea: react24.ForwardRefExoticComponent<Omit<Partial<react24.ClassAttributes<HTMLTextAreaElement> & react24.TextareaHTMLAttributes<HTMLTextAreaElement>>, "ref"> & react24.RefAttributes<unknown>>;
7
+ declare const Textarea: react27.ForwardRefExoticComponent<Omit<Partial<react27.ClassAttributes<HTMLTextAreaElement> & react27.TextareaHTMLAttributes<HTMLTextAreaElement>>, "ref"> & react27.RefAttributes<unknown>>;
8
8
  //#endregion
9
9
  export { Textarea };
@@ -1,11 +1,11 @@
1
- import * as react28 from "react";
2
- import * as _pixpilot_shadcn_ui2 from "@pixpilot/shadcn-ui";
1
+ import * as react22 from "react";
2
+ import * as _pixpilot_shadcn_ui1 from "@pixpilot/shadcn-ui";
3
3
 
4
4
  //#region src/components/ToggleButton.d.ts
5
5
  /**
6
6
  * Formily-connected IconToggle component
7
7
  * Toggle button with customizable icons for boolean values
8
8
  */
9
- declare const ToggleButton: react28.ForwardRefExoticComponent<Omit<Partial<Omit<_pixpilot_shadcn_ui2.ToggleButtonProps, "ref"> & react28.RefAttributes<HTMLButtonElement>>, "ref"> & react28.RefAttributes<unknown>>;
9
+ declare const ToggleButton: react22.ForwardRefExoticComponent<Omit<Partial<Omit<_pixpilot_shadcn_ui1.ToggleButtonProps, "ref"> & react22.RefAttributes<HTMLButtonElement>>, "ref"> & react22.RefAttributes<unknown>>;
10
10
  //#endregion
11
11
  export { ToggleButton };
@@ -1,4 +1,4 @@
1
- import * as _formily_react102 from "@formily/react";
1
+ import * as _formily_react0 from "@formily/react";
2
2
  import React from "react";
3
3
  import { TagsInputProps } from "@pixpilot/shadcn-ui";
4
4
 
@@ -54,6 +54,6 @@ interface ArrayTagsProps extends TagsInputProps {
54
54
  * };
55
55
  * ```
56
56
  */
57
- declare const ArrayTags: React.MemoExoticComponent<_formily_react102.ReactFC<ArrayTagsProps>>;
57
+ declare const ArrayTags: React.MemoExoticComponent<_formily_react0.ReactFC<ArrayTagsProps>>;
58
58
  //#endregion
59
59
  export { ArrayTags, ArrayTagsProps };
@@ -1,4 +1,4 @@
1
- import * as _formily_react101 from "@formily/react";
1
+ import * as _formily_react0 from "@formily/react";
2
2
  import React from "react";
3
3
  import { ToggleGroupProps } from "@pixpilot/shadcn-ui";
4
4
 
@@ -60,6 +60,6 @@ interface ArrayToggleGroupProps extends Omit<ToggleGroupProps, 'value' | 'onChan
60
60
  * };
61
61
  * ```
62
62
  */
63
- declare const ArrayToggleGroup: React.MemoExoticComponent<_formily_react101.ReactFC<Omit<ArrayToggleGroupProps, "ref">>>;
63
+ declare const ArrayToggleGroup: React.MemoExoticComponent<_formily_react0.ReactFC<Omit<ArrayToggleGroupProps, "ref">>>;
64
64
  //#endregion
65
65
  export { ArrayToggleGroup, ArrayToggleGroupProps };
@@ -2,11 +2,13 @@ import { ActionItem } from "../array-base/types.cjs";
2
2
  import "../array-base/index.cjs";
3
3
  import { FormSpace } from "../../types/form.cjs";
4
4
  import { DescriptionPlacement, LabelPlacement } from "../../types/form-item.cjs";
5
- import { DialogContentProps, FileUploadProgressCallBacks, IconProvider, PopoverContentProps, RichTextEditorProps } from "@pixpilot/shadcn-ui";
5
+ import { FormFileUploadOptions } from "../file-upload/types.cjs";
6
+ import "../file-upload/index.cjs";
7
+ import { DialogContentProps, IconProvider, PopoverContentProps, RichTextEditorProps } from "@pixpilot/shadcn-ui";
6
8
 
7
9
  //#region src/components/context/types.d.ts
8
10
  interface FomFileUpload {
9
- onUpload?: (files: File[], options: FileUploadProgressCallBacks) => void;
11
+ onUpload?: (files: File[], options: FormFileUploadOptions) => void;
10
12
  maxSize?: number;
11
13
  }
12
14
  interface FormSettings {
@@ -2,11 +2,13 @@ import { ActionItem } from "../array-base/types.js";
2
2
  import "../array-base/index.js";
3
3
  import { FormSpace } from "../../types/form.js";
4
4
  import { DescriptionPlacement, LabelPlacement } from "../../types/form-item.js";
5
- import { DialogContentProps, FileUploadProgressCallBacks, IconProvider, PopoverContentProps, RichTextEditorProps } from "@pixpilot/shadcn-ui";
5
+ import { FormFileUploadOptions } from "../file-upload/types.js";
6
+ import "../file-upload/index.js";
7
+ import { DialogContentProps, IconProvider, PopoverContentProps, RichTextEditorProps } from "@pixpilot/shadcn-ui";
6
8
 
7
9
  //#region src/components/context/types.d.ts
8
10
  interface FomFileUpload {
9
- onUpload?: (files: File[], options: FileUploadProgressCallBacks) => void;
11
+ onUpload?: (files: File[], options: FormFileUploadOptions) => void;
10
12
  maxSize?: number;
11
13
  }
12
14
  interface FormSettings {
@@ -1,3 +1,5 @@
1
+ const require_map_upload_props = require('./map-upload-props.cjs');
2
+ const require_use_file_upload_feedback = require('./use-file-upload-feedback.cjs');
1
3
  const require_AvatarUpload = require('./AvatarUpload.cjs');
2
4
  const require_FileUpload = require('./FileUpload.cjs');
3
5
  const require_FileUploadInline = require('./FileUploadInline.cjs');
@@ -1,3 +1,6 @@
1
- import { AvatarUpload, AvatarUploadProps as AvatarUploadProps$1 } from "./AvatarUpload.cjs";
2
- import { FileUpload, FileUploadProps as FileUploadProps$1 } from "./FileUpload.cjs";
3
- import { FileUploadInline, FileUploadInlineProps as FileUploadInlineProps$1 } from "./FileUploadInline.cjs";
1
+ import { FormilyUploadProps, UploadFieldCallbacks, UploadValueMapper, mapUploadProps } from "./map-upload-props.cjs";
2
+ import { AvatarUpload, AvatarUploadProps } from "./AvatarUpload.cjs";
3
+ import { FileUpload, FileUploadProps } from "./FileUpload.cjs";
4
+ import { FileUploadInline, FileUploadInlineProps } from "./FileUploadInline.cjs";
5
+ import { FormFileUploadOptions } from "./types.cjs";
6
+ import { useFileUploadFeedback } from "./use-file-upload-feedback.cjs";
@@ -1,4 +1,6 @@
1
- import { AvatarUpload as AvatarUpload$1, AvatarUploadProps as AvatarUploadProps$1 } from "./AvatarUpload.js";
2
- import { FileUpload as FileUpload$1, FileUploadProps as FileUploadProps$1 } from "./FileUpload.js";
3
- import { FileUploadInline as FileUploadInline$1, FileUploadInlineProps as FileUploadInlineProps$1 } from "./FileUploadInline.js";
4
- import "@pixpilot/shadcn-ui";
1
+ import { FormilyUploadProps, UploadFieldCallbacks, UploadValueMapper, mapUploadProps } from "./map-upload-props.js";
2
+ import { AvatarUpload, AvatarUploadProps } from "./AvatarUpload.js";
3
+ import { FileUpload, FileUploadProps } from "./FileUpload.js";
4
+ import { FileUploadInline, FileUploadInlineProps } from "./FileUploadInline.js";
5
+ import { FormFileUploadOptions } from "./types.js";
6
+ import { useFileUploadFeedback } from "./use-file-upload-feedback.js";
@@ -1,3 +1,5 @@
1
+ import { mapUploadProps } from "./map-upload-props.js";
2
+ import { useFileUploadFeedback } from "./use-file-upload-feedback.js";
1
3
  import { AvatarUpload } from "./AvatarUpload.js";
2
4
  import { FileUpload } from "./FileUpload.js";
3
5
  import { FileUploadInline } from "./FileUploadInline.js";
@@ -1,4 +1,4 @@
1
- import "@formily/core";
1
+ import { Field } from "@formily/core";
2
2
  import { FileMetadata } from "@pixpilot/shadcn-ui";
3
3
 
4
4
  //#region src/components/file-upload/map-upload-props.d.ts
@@ -12,5 +12,46 @@ interface UploadValueMapper<TValue$1 extends SingleFileUploadValue = SingleFileU
12
12
  type FormilyUploadProps<P> = P extends {
13
13
  multiple: true;
14
14
  } ? P : P & UploadValueMapper<ExtractSingleFileValue<P>>;
15
+ /**
16
+ * Callbacks that the shadcn upload components expose at the single-file level.
17
+ * `FileUploadProps`, `AvatarUploadProps` and `FileUploadInlineProps` all carry
18
+ * these when used in single-file mode.
19
+ */
20
+ interface UploadFieldCallbacks<TValue$1 extends SingleFileUploadValue = SingleFileUploadValue> extends UploadValueMapper<TValue$1> {
21
+ onFileSuccess?: (fileMeta: FileMetadata) => void;
22
+ onFileError?: (file: File, error: string) => void;
23
+ }
24
+ interface MapUploadPropsOptions {
25
+ forceSingle?: boolean;
26
+ }
27
+ /**
28
+ * Shared `mapProps` mapper for all Formily-connected upload components.
29
+ *
30
+ * - Forwards `field.value` (defaulting to `null`) as the `value` prop so the
31
+ * component displays the currently stored file metadata.
32
+ * - Applies `mapValue` to the field value before forwarding it so callers can
33
+ * derive a display-ready file object without mutating the stored form value.
34
+ * - Provides a guarded `onChange` that only writes to the field on deletions
35
+ * (value becomes `null` for single-file, or the array shrinks for
36
+ * multi-file). New-file accepts fire `onChange` before the upload
37
+ * completes with incomplete metadata (no `url`), so those calls are
38
+ * intentionally ignored here — `onFileSuccess` handles the final write
39
+ * once the upload finishes.
40
+ * - Wraps `onFileSuccess` so that `field.setValue(fileMeta)` is called only
41
+ * after a successful upload, followed by the original `onFileSuccess`
42
+ * callback if one was supplied. When the field value is an array (multiple
43
+ * mode), the new file is appended to the existing array rather than
44
+ * replacing it.
45
+ * - Wraps `onFileError` so that `field.setFeedback({ type: 'error', … })` is
46
+ * set on upload failure, followed by the original `onFileError` callback if
47
+ * one was supplied.
48
+ *
49
+ * The generic `P extends object` constraint keeps the return type identical to
50
+ * the input type so that the mapper satisfies Formily's `IStateMapper<T>`.
51
+ * Internally the props are cast to `UploadFieldCallbacks` to access the
52
+ * upload-specific callbacks; both single-file and multiple-file modes share
53
+ * the same `onFileSuccess`/`onFileError` callbacks that fire per file.
54
+ */
55
+ declare function mapUploadProps<P extends object>(props: P, field: Field, options?: MapUploadPropsOptions): P;
15
56
  //#endregion
16
- export { FormilyUploadProps, UploadValueMapper };
57
+ export { FormilyUploadProps, UploadFieldCallbacks, UploadValueMapper, mapUploadProps };
@@ -1,5 +1,5 @@
1
1
  import { FileMetadata } from "@pixpilot/shadcn-ui";
2
- import "@formily/core";
2
+ import { Field } from "@formily/core";
3
3
 
4
4
  //#region src/components/file-upload/map-upload-props.d.ts
5
5
  type SingleFileUploadValue = FileMetadata | null;
@@ -12,5 +12,46 @@ interface UploadValueMapper<TValue$1 extends SingleFileUploadValue = SingleFileU
12
12
  type FormilyUploadProps<P> = P extends {
13
13
  multiple: true;
14
14
  } ? P : P & UploadValueMapper<ExtractSingleFileValue<P>>;
15
+ /**
16
+ * Callbacks that the shadcn upload components expose at the single-file level.
17
+ * `FileUploadProps`, `AvatarUploadProps` and `FileUploadInlineProps` all carry
18
+ * these when used in single-file mode.
19
+ */
20
+ interface UploadFieldCallbacks<TValue$1 extends SingleFileUploadValue = SingleFileUploadValue> extends UploadValueMapper<TValue$1> {
21
+ onFileSuccess?: (fileMeta: FileMetadata) => void;
22
+ onFileError?: (file: File, error: string) => void;
23
+ }
24
+ interface MapUploadPropsOptions {
25
+ forceSingle?: boolean;
26
+ }
27
+ /**
28
+ * Shared `mapProps` mapper for all Formily-connected upload components.
29
+ *
30
+ * - Forwards `field.value` (defaulting to `null`) as the `value` prop so the
31
+ * component displays the currently stored file metadata.
32
+ * - Applies `mapValue` to the field value before forwarding it so callers can
33
+ * derive a display-ready file object without mutating the stored form value.
34
+ * - Provides a guarded `onChange` that only writes to the field on deletions
35
+ * (value becomes `null` for single-file, or the array shrinks for
36
+ * multi-file). New-file accepts fire `onChange` before the upload
37
+ * completes with incomplete metadata (no `url`), so those calls are
38
+ * intentionally ignored here — `onFileSuccess` handles the final write
39
+ * once the upload finishes.
40
+ * - Wraps `onFileSuccess` so that `field.setValue(fileMeta)` is called only
41
+ * after a successful upload, followed by the original `onFileSuccess`
42
+ * callback if one was supplied. When the field value is an array (multiple
43
+ * mode), the new file is appended to the existing array rather than
44
+ * replacing it.
45
+ * - Wraps `onFileError` so that `field.setFeedback({ type: 'error', … })` is
46
+ * set on upload failure, followed by the original `onFileError` callback if
47
+ * one was supplied.
48
+ *
49
+ * The generic `P extends object` constraint keeps the return type identical to
50
+ * the input type so that the mapper satisfies Formily's `IStateMapper<T>`.
51
+ * Internally the props are cast to `UploadFieldCallbacks` to access the
52
+ * upload-specific callbacks; both single-file and multiple-file modes share
53
+ * the same `onFileSuccess`/`onFileError` callbacks that fire per file.
54
+ */
55
+ declare function mapUploadProps<P extends object>(props: P, field: Field, options?: MapUploadPropsOptions): P;
15
56
  //#endregion
16
- export { FormilyUploadProps, UploadValueMapper };
57
+ export { FormilyUploadProps, UploadFieldCallbacks, UploadValueMapper, mapUploadProps };
@@ -0,0 +1,9 @@
1
+ import { FileUploadProgressCallBacks } from "@pixpilot/shadcn-ui";
2
+
3
+ //#region src/components/file-upload/types.d.ts
4
+ interface FormFileUploadOptions extends FileUploadProgressCallBacks {
5
+ component: string;
6
+ componentProps: Record<string, any>;
7
+ }
8
+ //#endregion
9
+ export { FormFileUploadOptions };
@@ -0,0 +1,9 @@
1
+ import { FileUploadProgressCallBacks } from "@pixpilot/shadcn-ui";
2
+
3
+ //#region src/components/file-upload/types.d.ts
4
+ interface FormFileUploadOptions extends FileUploadProgressCallBacks {
5
+ component: string;
6
+ componentProps: Record<string, any>;
7
+ }
8
+ //#endregion
9
+ export { FormFileUploadOptions };
@@ -19,39 +19,53 @@ function useFileUploadFeedback(props) {
19
19
  if (onUpload == null) {
20
20
  if (process.env.NODE_ENV !== "production") throw new Error("onUpload prop required for FileUploadInline. Provide handler on form or field props.");
21
21
  }
22
- return {
23
- onUpload,
22
+ const handleFilesRejection = react.default.useCallback((files) => {
23
+ onFilesReject?.(files);
24
+ const maximumError = files.filter((f) => f.message.startsWith("Maximum"));
25
+ const withFileSizeError = files.filter((f) => f.message.startsWith("File too large"));
26
+ const otherErrors = files.filter((f) => !withFileSizeError.includes(f) && !maximumError.includes(f));
27
+ const messages = [];
28
+ if (maximumError.length > 0) messages.push(maximumError[0].message);
29
+ if (maxSize != null && withFileSizeError.length > 0) {
30
+ const fileList = withFileSizeError.map((f) => `${f.file.name} (${(0, pretty_bytes.default)(f.file.size)})`).join("\n");
31
+ messages.push(`Files exceed ${(0, pretty_bytes.default)(maxSize)} limit:\n${fileList}`);
32
+ }
33
+ if (otherErrors.length > 0) otherErrors.forEach((f) => {
34
+ messages.push(`${f.message}: ${f.file.name}`);
35
+ });
36
+ field.setFeedback({
37
+ type: "warning",
38
+ messages: [messages.join("\n")]
39
+ });
40
+ }, [
41
+ field,
24
42
  maxSize,
25
- handleFilesRejection: react.default.useCallback((files) => {
26
- onFilesReject?.(files);
27
- const maximumError = files.filter((f) => f.message.startsWith("Maximum"));
28
- const withFileSizeError = files.filter((f) => f.message.startsWith("File too large"));
29
- const otherErrors = files.filter((f) => !withFileSizeError.includes(f) && !maximumError.includes(f));
30
- const messages = [];
31
- if (maximumError.length > 0) messages.push(maximumError[0].message);
32
- if (maxSize != null && withFileSizeError.length > 0) {
33
- const fileList = withFileSizeError.map((f) => `${f.file.name} (${(0, pretty_bytes.default)(f.file.size)})`).join("\n");
34
- messages.push(`Files exceed ${(0, pretty_bytes.default)(maxSize)} limit:\n${fileList}`);
35
- }
36
- if (otherErrors.length > 0) otherErrors.forEach((f) => {
37
- messages.push(`${f.message}: ${f.file.name}`);
38
- });
39
- field.setFeedback({
40
- type: "warning",
41
- messages: [messages.join("\n")]
43
+ onFilesReject
44
+ ]);
45
+ const handleFileValidate = react.default.useCallback((file) => {
46
+ field.setFeedback({
47
+ type: "warning",
48
+ messages: []
49
+ });
50
+ return onFileValidate?.(file);
51
+ }, [field, onFileValidate]);
52
+ return {
53
+ onUpload: react.default.useCallback(async (files, options) => {
54
+ if (onUploadProp) return onUploadProp(files, options);
55
+ return onUpload?.(files, {
56
+ ...options,
57
+ component: field.componentType,
58
+ componentProps: { ...field.componentProps }
42
59
  });
43
60
  }, [
44
- field,
45
- maxSize,
46
- onFilesReject
61
+ field.componentProps,
62
+ field.componentType,
63
+ onUpload,
64
+ onUploadProp
47
65
  ]),
48
- handleFileValidate: react.default.useCallback((file) => {
49
- field.setFeedback({
50
- type: "warning",
51
- messages: []
52
- });
53
- return onFileValidate?.(file);
54
- }, [field, onFileValidate])
66
+ maxSize,
67
+ handleFilesRejection,
68
+ handleFileValidate
55
69
  };
56
70
  }
57
71
 
@@ -0,0 +1,14 @@
1
+ import { FileUploadBaseProps } from "@pixpilot/shadcn-ui";
2
+
3
+ //#region src/components/file-upload/use-file-upload-feedback.d.ts
4
+ declare function useFileUploadFeedback(props: FileUploadBaseProps): {
5
+ onUpload: ((...args: any[]) => any) | undefined;
6
+ maxSize: number | undefined;
7
+ handleFilesRejection: (files: Array<{
8
+ file: File;
9
+ message: string;
10
+ }>) => void;
11
+ handleFileValidate: (file: File) => string | null | undefined;
12
+ };
13
+ //#endregion
14
+ export { useFileUploadFeedback };
@@ -0,0 +1,14 @@
1
+ import { FileUploadBaseProps } from "@pixpilot/shadcn-ui";
2
+
3
+ //#region src/components/file-upload/use-file-upload-feedback.d.ts
4
+ declare function useFileUploadFeedback(props: FileUploadBaseProps): {
5
+ onUpload: ((...args: any[]) => any) | undefined;
6
+ maxSize: number | undefined;
7
+ handleFilesRejection: (files: Array<{
8
+ file: File;
9
+ message: string;
10
+ }>) => void;
11
+ handleFileValidate: (file: File) => string | null | undefined;
12
+ };
13
+ //#endregion
14
+ export { useFileUploadFeedback };
@@ -13,39 +13,53 @@ function useFileUploadFeedback(props) {
13
13
  const onUpload = onUploadProp ?? fileUpload?.onUpload;
14
14
  const maxSize = maxSizeProp ?? fileUpload?.maxSize;
15
15
  if (onUpload == null) throw new Error("onUpload prop required for FileUploadInline. Provide handler on form or field props.");
16
- return {
17
- onUpload,
16
+ const handleFilesRejection = React.useCallback((files) => {
17
+ onFilesReject?.(files);
18
+ const maximumError = files.filter((f) => f.message.startsWith("Maximum"));
19
+ const withFileSizeError = files.filter((f) => f.message.startsWith("File too large"));
20
+ const otherErrors = files.filter((f) => !withFileSizeError.includes(f) && !maximumError.includes(f));
21
+ const messages = [];
22
+ if (maximumError.length > 0) messages.push(maximumError[0].message);
23
+ if (maxSize != null && withFileSizeError.length > 0) {
24
+ const fileList = withFileSizeError.map((f) => `${f.file.name} (${prettyBytes(f.file.size)})`).join("\n");
25
+ messages.push(`Files exceed ${prettyBytes(maxSize)} limit:\n${fileList}`);
26
+ }
27
+ if (otherErrors.length > 0) otherErrors.forEach((f) => {
28
+ messages.push(`${f.message}: ${f.file.name}`);
29
+ });
30
+ field.setFeedback({
31
+ type: "warning",
32
+ messages: [messages.join("\n")]
33
+ });
34
+ }, [
35
+ field,
18
36
  maxSize,
19
- handleFilesRejection: React.useCallback((files) => {
20
- onFilesReject?.(files);
21
- const maximumError = files.filter((f) => f.message.startsWith("Maximum"));
22
- const withFileSizeError = files.filter((f) => f.message.startsWith("File too large"));
23
- const otherErrors = files.filter((f) => !withFileSizeError.includes(f) && !maximumError.includes(f));
24
- const messages = [];
25
- if (maximumError.length > 0) messages.push(maximumError[0].message);
26
- if (maxSize != null && withFileSizeError.length > 0) {
27
- const fileList = withFileSizeError.map((f) => `${f.file.name} (${prettyBytes(f.file.size)})`).join("\n");
28
- messages.push(`Files exceed ${prettyBytes(maxSize)} limit:\n${fileList}`);
29
- }
30
- if (otherErrors.length > 0) otherErrors.forEach((f) => {
31
- messages.push(`${f.message}: ${f.file.name}`);
32
- });
33
- field.setFeedback({
34
- type: "warning",
35
- messages: [messages.join("\n")]
37
+ onFilesReject
38
+ ]);
39
+ const handleFileValidate = React.useCallback((file) => {
40
+ field.setFeedback({
41
+ type: "warning",
42
+ messages: []
43
+ });
44
+ return onFileValidate?.(file);
45
+ }, [field, onFileValidate]);
46
+ return {
47
+ onUpload: React.useCallback(async (files, options) => {
48
+ if (onUploadProp) return onUploadProp(files, options);
49
+ return onUpload?.(files, {
50
+ ...options,
51
+ component: field.componentType,
52
+ componentProps: { ...field.componentProps }
36
53
  });
37
54
  }, [
38
- field,
39
- maxSize,
40
- onFilesReject
55
+ field.componentProps,
56
+ field.componentType,
57
+ onUpload,
58
+ onUploadProp
41
59
  ]),
42
- handleFileValidate: React.useCallback((file) => {
43
- field.setFeedback({
44
- type: "warning",
45
- messages: []
46
- });
47
- return onFileValidate?.(file);
48
- }, [field, onFileValidate])
60
+ maxSize,
61
+ handleFilesRejection,
62
+ handleFileValidate
49
63
  };
50
64
  }
51
65