dinocollab-core 2.2.49 → 2.2.52

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 (93) hide show
  1. package/dist/components/index.js +1 -1
  2. package/dist/form/index.js +1 -1
  3. package/dist/src/components/buttons.js.map +1 -1
  4. package/dist/src/components/confirm-button.js +2 -0
  5. package/dist/src/components/confirm-button.js.map +1 -0
  6. package/dist/src/data-surface/view-grid/styleds.js +1 -1
  7. package/dist/src/data-surface/view-grid/styleds.js.map +1 -1
  8. package/dist/src/data-surface/view-list/helpers.js +1 -1
  9. package/dist/src/data-surface/view-list/helpers.js.map +1 -1
  10. package/dist/src/data-surface/view-list/index.js +1 -1
  11. package/dist/src/data-surface/view-list/index.js.map +1 -1
  12. package/dist/src/data-surface/view-list/styled.js +1 -1
  13. package/dist/src/data-surface/view-list/styled.js.map +1 -1
  14. package/dist/src/data-surface/view-list/types.js.map +1 -1
  15. package/dist/src/filter-bar/components/filter-input.units.js +1 -1
  16. package/dist/src/filter-bar/components/filter-input.units.js.map +1 -1
  17. package/dist/src/filter-bar/components/filter-sort.js +1 -1
  18. package/dist/src/filter-bar/components/filter-sort.js.map +1 -1
  19. package/dist/src/filter-bar/menu/create-form-field-string.js +1 -1
  20. package/dist/src/filter-bar/menu/create-form-field-string.js.map +1 -1
  21. package/dist/src/filter-bar/menu/create.js +1 -1
  22. package/dist/src/filter-bar/menu/create.js.map +1 -1
  23. package/dist/src/form/create.checkbox.js +2 -0
  24. package/dist/src/form/create.checkbox.js.map +1 -0
  25. package/dist/src/form/create.form-base.js +1 -1
  26. package/dist/src/form/create.form-base.js.map +1 -1
  27. package/dist/src/form/create.form-grid-layout.js +1 -1
  28. package/dist/src/form/create.form-grid-layout.js.map +1 -1
  29. package/dist/src/form/create.input.file.js +1 -1
  30. package/dist/src/form/create.input.file.js.map +1 -1
  31. package/dist/src/form/create.input.js.map +1 -1
  32. package/dist/src/form/create.select-simple.js +1 -1
  33. package/dist/src/form/create.select-simple.js.map +1 -1
  34. package/dist/src/form/create.select-with-api.js +1 -1
  35. package/dist/src/form/create.select-with-api.js.map +1 -1
  36. package/dist/src/form/decorator.form.js +1 -1
  37. package/dist/src/form/decorator.form.js.map +1 -1
  38. package/dist/src/form/decorator.units.js +1 -1
  39. package/dist/src/form/decorator.units.js.map +1 -1
  40. package/dist/src/form/dino-form.js +1 -1
  41. package/dist/src/form/dino-form.js.map +1 -1
  42. package/dist/src/form/error-handler.js +1 -1
  43. package/dist/src/form/error-handler.js.map +1 -1
  44. package/dist/src/form/helpers.js +1 -1
  45. package/dist/src/form/helpers.js.map +1 -1
  46. package/dist/src/form/v2/create.autocomplete.chips.js +2 -0
  47. package/dist/src/form/v2/create.autocomplete.chips.js.map +1 -0
  48. package/dist/src/form/v2/create.color-picker.js +2 -0
  49. package/dist/src/form/v2/create.color-picker.js.map +1 -0
  50. package/dist/src/form/v2/create.date-expired.js +2 -0
  51. package/dist/src/form/v2/create.date-expired.js.map +1 -0
  52. package/dist/src/form/v2/create.date-picker.js +2 -0
  53. package/dist/src/form/v2/create.date-picker.js.map +1 -0
  54. package/dist/src/form/v2/create.input.js +2 -0
  55. package/dist/src/form/v2/create.input.js.map +1 -0
  56. package/dist/src/form/v2/create.select-simple.js +2 -0
  57. package/dist/src/form/v2/create.select-simple.js.map +1 -0
  58. package/dist/src/form/v2/create.select-with-api.js +2 -0
  59. package/dist/src/form/v2/create.select-with-api.js.map +1 -0
  60. package/dist/src/form/validator.js +1 -1
  61. package/dist/src/form/validator.js.map +1 -1
  62. package/dist/types/components/confirm-button.d.ts +30 -0
  63. package/dist/types/components/index.d.ts +1 -0
  64. package/dist/types/data-surface/view-list/types.d.ts +2 -0
  65. package/dist/types/filter-bar/components/filter-input.types.d.ts +2 -0
  66. package/dist/types/filter-bar/components/filter-sort.types.d.ts +2 -0
  67. package/dist/types/filter-bar/index.d.ts +1 -0
  68. package/dist/types/filter-bar/menu/create-form-field-string.d.ts +1 -0
  69. package/dist/types/filter-bar/menu/types.d.ts +2 -0
  70. package/dist/types/form/create.checkbox.d.ts +41 -0
  71. package/dist/types/form/create.form-base.d.ts +14 -0
  72. package/dist/types/form/create.input.d.ts +1 -0
  73. package/dist/types/form/create.input.file.d.ts +109 -9
  74. package/dist/types/form/create.select-simple.d.ts +1 -1
  75. package/dist/types/form/create.select-with-api.d.ts +3 -3
  76. package/dist/types/form/decorator.form.d.ts +17 -0
  77. package/dist/types/form/dino-form.d.ts +17 -6
  78. package/dist/types/form/helpers.d.ts +4 -4
  79. package/dist/types/form/index.d.ts +12 -0
  80. package/dist/types/form/v2/create.autocomplete.chips.d.ts +45 -0
  81. package/dist/types/form/v2/create.color-picker.d.ts +37 -0
  82. package/dist/types/form/v2/create.date-expired.d.ts +53 -0
  83. package/dist/types/form/v2/create.date-picker.d.ts +43 -0
  84. package/dist/types/form/v2/create.input.d.ts +36 -0
  85. package/dist/types/form/v2/create.select-simple.d.ts +84 -0
  86. package/dist/types/form/v2/create.select-with-api.d.ts +66 -0
  87. package/package.json +1 -1
  88. package/dist/src/form/create.input-file.csv-local-parser.js +0 -2
  89. package/dist/src/form/create.input-file.csv-local-parser.js.map +0 -1
  90. package/dist/src/form/create.input.image-file.js +0 -2
  91. package/dist/src/form/create.input.image-file.js.map +0 -1
  92. package/dist/types/form/create.input-file.csv-local-parser.d.ts +0 -66
  93. package/dist/types/form/create.input.image-file.d.ts +0 -20
@@ -0,0 +1,45 @@
1
+ import { ComponentType } from 'react';
2
+ import { BoxProps, TextFieldProps } from '@mui/material';
3
+ import { IFormInputBase } from '../types';
4
+ export interface IAutocompleteChipSlots {
5
+ optionItems?: string[];
6
+ limitTags?: number;
7
+ separator?: string;
8
+ saveLocalStorageByKey?: string;
9
+ wrapProps?: BoxProps;
10
+ textFieldProps?: TextFieldProps;
11
+ }
12
+ export interface IAutocompleteChipProps<T> extends IFormInputBase<T, IAutocompleteChipSlots> {
13
+ onChange?: (value: string[]) => void;
14
+ }
15
+ export interface IAutocompleteChipState {
16
+ value: string[];
17
+ options: string[];
18
+ }
19
+ export interface IAutocompleteChipParams<T = any> extends IAutocompleteChipSlots {
20
+ }
21
+ export declare const autocompleteChipClasses: {
22
+ root: string;
23
+ label: string;
24
+ input: string;
25
+ chip: string;
26
+ error: string;
27
+ };
28
+ /**
29
+ * Modern Custom Styled Autocomplete Chips Creator for DinoForm V2.
30
+ *
31
+ * Synchronized with V2 design aesthetics (Top Label, rounded corners 10px, #cbd5e1 border, modern tags).
32
+ *
33
+ * @example
34
+ * @formField({
35
+ * type: String,
36
+ * label: 'Skills (Tags)',
37
+ * renderInput: DinoForm.createAutocompleteChipV2({
38
+ * optionItems: ['React', 'TypeScript', 'Material-UI', 'Node.js'],
39
+ * limitTags: 3
40
+ * })
41
+ * })
42
+ * skills?: string
43
+ */
44
+ export declare function createAutocompleteChip<T = any>(params?: IAutocompleteChipParams<T>): ComponentType<IAutocompleteChipProps<T>>;
45
+ export default createAutocompleteChip;
@@ -0,0 +1,37 @@
1
+ import { ComponentType } from 'react';
2
+ import { BoxProps, TextFieldProps } from '@mui/material';
3
+ import { IFormInputBase } from '../types';
4
+ export interface IColorPickerSlots {
5
+ wrapProps?: BoxProps;
6
+ textFieldProps?: TextFieldProps;
7
+ }
8
+ export interface IColorPickerProps<T = any> extends IFormInputBase<T, IColorPickerSlots> {
9
+ onChange?: (value: string) => void;
10
+ }
11
+ export interface IColorPickerState {
12
+ value: string;
13
+ }
14
+ export interface IColorPickerParams<T = any> extends IColorPickerSlots {
15
+ }
16
+ export declare const colorPickerClasses: {
17
+ root: string;
18
+ label: string;
19
+ input: string;
20
+ swatch: string;
21
+ error: string;
22
+ };
23
+ /**
24
+ * Modern Custom Styled Color Picker Component Creator for DinoForm V2.
25
+ *
26
+ * Synchronized with V2 design aesthetics (Top Label, rounded corners 10px, #cbd5e1 border, color swatch).
27
+ *
28
+ * @example
29
+ * @formField({
30
+ * type: String,
31
+ * label: 'Brand Color',
32
+ * renderInput: DinoForm.createColorPickerV2()
33
+ * })
34
+ * themeColor?: string
35
+ */
36
+ export declare function createColorPicker<T = any>(params?: IColorPickerParams<T>): ComponentType<IColorPickerProps<T>>;
37
+ export default createColorPicker;
@@ -0,0 +1,53 @@
1
+ import { ComponentType } from 'react';
2
+ import { TextFieldProps, SwitchProps, BoxProps } from '@mui/material';
3
+ import { IFormInputBase } from '../types';
4
+ export declare const dateExpiredClasses: {
5
+ root: string;
6
+ control: string;
7
+ labelWrapper: string;
8
+ label: string;
9
+ expired: string;
10
+ labelSwitch: string;
11
+ input: string;
12
+ switch: string;
13
+ expiredDateText: string;
14
+ };
15
+ export interface IDateExpiredSlots<T = any> {
16
+ rootProps?: BoxProps;
17
+ switchProps?: SwitchProps;
18
+ textFieldProps?: Partial<TextFieldProps>;
19
+ }
20
+ export interface IDateExpiredConfig<T = any> extends IDateExpiredSlots<T> {
21
+ defaultValue?: any;
22
+ /** @default 'string' */
23
+ inputType?: 'number' | 'string';
24
+ switchChecked?: boolean;
25
+ switchCheckedGetter?: (value: any, model?: Partial<T>) => boolean;
26
+ }
27
+ export interface IMergeConfig<T> extends IDateExpiredConfig<T> {
28
+ switchChecked: boolean;
29
+ handleBlur: () => void;
30
+ }
31
+ export interface IDateExpiredProps<T> extends IFormInputBase<T>, IDateExpiredConfig<T> {
32
+ slots?: IDateExpiredSlots<T>;
33
+ onChange?: (value: string | number) => void;
34
+ }
35
+ export interface IDateExpiredState {
36
+ numberOfDays: number;
37
+ switchChecked: boolean;
38
+ }
39
+ /**
40
+ * Modern Custom Styled Date Expired Component Creator for DinoForm V2.
41
+ *
42
+ * Synchronized with V2 design aesthetics (Top Header with Switch, 10px rounded input, calculated expiration date subtext).
43
+ *
44
+ * @example
45
+ * @formField({
46
+ * type: String,
47
+ * label: 'Account Expiration (Days)',
48
+ * renderInput: DinoForm.createDateExpiredV2()
49
+ * })
50
+ * expirationDate?: string
51
+ */
52
+ export declare function createDateExpired<T = any>(param?: IDateExpiredConfig<T>): ComponentType<IDateExpiredProps<T>>;
53
+ export default createDateExpired;
@@ -0,0 +1,43 @@
1
+ import { ComponentType } from 'react';
2
+ import { Dayjs } from 'dayjs';
3
+ import { BoxProps } from '@mui/material';
4
+ import { DatePickerProps } from '@mui/x-date-pickers';
5
+ import { IFormInputBase } from '../types';
6
+ export interface IDatePickerSlots {
7
+ defaultValue?: string;
8
+ minDate?: Dayjs;
9
+ minDateOffset?: number;
10
+ datePickerProps?: DatePickerProps<Dayjs>;
11
+ wrapProps?: BoxProps;
12
+ }
13
+ export interface IDatePickerProps<T> extends IFormInputBase<T> {
14
+ format?: string;
15
+ slots?: Omit<IDatePickerSlots, 'defaultValue'>;
16
+ onChange?: (value: Dayjs | null) => void;
17
+ }
18
+ export interface IDatePickerState {
19
+ value: Dayjs | null;
20
+ }
21
+ export interface IDatePickerParams<T = any> extends IDatePickerSlots {
22
+ }
23
+ export declare const datePickerClasses: {
24
+ root: string;
25
+ label: string;
26
+ input: string;
27
+ error: string;
28
+ };
29
+ /**
30
+ * Modern Custom Styled Date Picker Component Creator for DinoForm V2.
31
+ *
32
+ * Synchronized with V2 design aesthetics (Top Label, rounded corners 10px, #cbd5e1 border).
33
+ *
34
+ * @example
35
+ * @formField({
36
+ * type: String,
37
+ * label: 'Birth Date',
38
+ * renderInput: DinoForm.createDatePickerV2()
39
+ * })
40
+ * birthDate?: string
41
+ */
42
+ export declare function createDatePicker<T = any>(params?: IDatePickerParams<T>): ComponentType<IDatePickerProps<T>>;
43
+ export default createDatePicker;
@@ -0,0 +1,36 @@
1
+ import React, { ComponentType } from 'react';
2
+ import { TextFieldProps } from '@mui/material';
3
+ import { IFormInputBase } from './../types';
4
+ import { IImageWithFallbackPropsOwner } from '../../components/image-with-fallback';
5
+ import { IRichTooltipPanelConfig } from '../../components/rich-tooltip';
6
+ export interface InputBaseImage<T> extends Omit<Partial<IImageWithFallbackPropsOwner>, 'src'> {
7
+ src?: string | ((value: any, model?: Partial<T>) => string | undefined);
8
+ element?: React.ComponentType<{
9
+ value: any;
10
+ model?: Partial<T>;
11
+ }>;
12
+ mirror?: boolean;
13
+ }
14
+ export interface IInputSlots<T> {
15
+ maxLength?: number;
16
+ placeholder?: string;
17
+ textFieldProps?: TextFieldProps;
18
+ pastenable?: boolean;
19
+ imageLeft?: InputBaseImage<T>;
20
+ imageRight?: InputBaseImage<T>;
21
+ tooltip?: IRichTooltipPanelConfig;
22
+ }
23
+ export interface IInputProps<T> extends IFormInputBase<T, IInputSlots<T>> {
24
+ }
25
+ export interface IInputState {
26
+ value?: string;
27
+ }
28
+ export interface IInputParams<T> extends IInputSlots<T> {
29
+ }
30
+ declare const createInput: <T>(params?: IInputParams<T> | undefined) => React.ComponentType<IInputProps<T>>;
31
+ export default createInput;
32
+ export declare const inputClasses: {
33
+ root: string;
34
+ label: string;
35
+ input: string;
36
+ };
@@ -0,0 +1,84 @@
1
+ import { BoxProps, SelectProps } from '@mui/material';
2
+ import type { ComponentType } from 'react';
3
+ import type { IFormInputBase } from '../types';
4
+ import type { IRichTooltipPanelConfig } from '../../components/rich-tooltip';
5
+ export interface ISelectSimpleOption<T = any> {
6
+ /** The value of the option. */
7
+ value: T;
8
+ /** Display label for the option. If omitted, value is used as label. */
9
+ label?: string;
10
+ }
11
+ export declare function getOptionDisplayLabel(item: ISelectSimpleOption): string;
12
+ export interface ISelectSimpleSlots {
13
+ /** MUI Select component props override. */
14
+ selectProps?: Omit<SelectProps, 'variant'>;
15
+ /** Automatically select the first option if no value/defaultValue is provided. @default false */
16
+ autoSelectFirst?: boolean;
17
+ /** Outer container Box props override. */
18
+ wrapProps?: BoxProps;
19
+ }
20
+ export interface ISelectSimpleProps<T> extends Partial<IFormInputBase<T, ISelectSimpleSlots>> {
21
+ /** List of predefined options. */
22
+ options?: ISelectSimpleOption[];
23
+ /** Controlled value. */
24
+ value?: any;
25
+ /** Placeholder text shown when no option is selected. @default 'Select [label]' */
26
+ placeholder?: string;
27
+ /** Callback fired when an option is selected. */
28
+ onChange?: (value: ISelectSimpleOption) => void;
29
+ /** Slots override props. */
30
+ slots?: ISelectSimpleSlots;
31
+ /** @default true */
32
+ fullWidth?: boolean;
33
+ /** Rich Tooltip configuration. */
34
+ tooltip?: IRichTooltipPanelConfig;
35
+ /** Element placed at the end of the input. */
36
+ endAdornment?: React.ReactNode;
37
+ }
38
+ export interface ISelectSimpleState {
39
+ value?: string;
40
+ }
41
+ export interface ISelectSimpleParams extends ISelectSimpleSlots {
42
+ /** List of predefined options. */
43
+ options?: ISelectSimpleOption[];
44
+ /** Placeholder text shown when no option is selected. @default 'Select [label]' */
45
+ placeholder?: string;
46
+ /** Automatically select the first option if no value/defaultValue is provided. @default false */
47
+ autoSelectFirst?: boolean;
48
+ /** Rich Tooltip configuration. */
49
+ tooltip?: IRichTooltipPanelConfig;
50
+ /** Element placed at the end of the input. */
51
+ endAdornment?: React.ReactNode;
52
+ }
53
+ export declare const selectSimpleClasses: {
54
+ root: string;
55
+ label: string;
56
+ select: string;
57
+ selectHeader: string;
58
+ placeholder: string;
59
+ tooltipWrap: string;
60
+ small: string;
61
+ tooltip: string;
62
+ endAdornment: string;
63
+ };
64
+ /**
65
+ * Modern Custom Styled Select Simple Creator for DinoForm V2.
66
+ *
67
+ * Synchronized with V2 design aesthetics (Top Label, rounded corners 10px, #cbd5e1 border, placeholder when unselected, styled menu items).
68
+ *
69
+ * @example
70
+ * @formField({
71
+ * type: String,
72
+ * label: 'Language',
73
+ * renderInput: DinoForm.createSelectSimpleV2({
74
+ * options: [
75
+ * { label: 'English', value: 'en' },
76
+ * { label: 'Spanish', value: 'es' }
77
+ * ],
78
+ * placeholder: 'Select a language'
79
+ * })
80
+ * })
81
+ * language?: string
82
+ */
83
+ export declare function createSelectSimple<T = any>(args?: ISelectSimpleParams): ComponentType<ISelectSimpleProps<T>>;
84
+ export default createSelectSimple;
@@ -0,0 +1,66 @@
1
+ import React, { ComponentType } from 'react';
2
+ import { BoxProps, TextFieldProps } from '@mui/material';
3
+ import { IFormInputBase } from '../types';
4
+ import type { AutocompleteRenderOptionState } from '@mui/material';
5
+ import type { IRichTooltipPanelConfig } from '../../components/rich-tooltip';
6
+ export interface ISelectWithApiOption<TOther = any> {
7
+ value: string;
8
+ label?: string;
9
+ other?: TOther;
10
+ }
11
+ export interface ISelectWithApiPropsSlots<O extends ISelectWithApiOption = ISelectWithApiOption> {
12
+ textFieldProps?: TextFieldProps;
13
+ wrapProps?: BoxProps;
14
+ renderOption?: (props: React.HTMLAttributes<HTMLElement>, option: O, state: AutocompleteRenderOptionState) => React.ReactNode;
15
+ }
16
+ export type ISelectWithApiFetchData<O extends ISelectWithApiOption> = (value?: string, signal?: AbortSignal) => Promise<O[]>;
17
+ export interface ISelectWithApiProps<T, O extends ISelectWithApiOption = ISelectWithApiOption> extends IFormInputBase<T, ISelectWithApiPropsSlots<O>>, ISelectWithApiParams<O> {
18
+ placeholder?: string;
19
+ tooltip?: IRichTooltipPanelConfig;
20
+ onChange?: (value: O | null) => void;
21
+ existedIds?: string[];
22
+ slots?: ISelectWithApiPropsSlots<O>;
23
+ }
24
+ export interface ISelectWithApiState<O extends ISelectWithApiOption> {
25
+ options: O[];
26
+ statusText?: string;
27
+ optionSelected: O | null;
28
+ inputValue: string;
29
+ loading?: boolean;
30
+ }
31
+ export interface ISelectWithApiParams<O extends ISelectWithApiOption = ISelectWithApiOption> {
32
+ placeholder?: string;
33
+ fetchData?: ISelectWithApiFetchData<O>;
34
+ tooltip?: IRichTooltipPanelConfig;
35
+ renderOption?: (props: React.HTMLAttributes<HTMLElement>, option: O, state: AutocompleteRenderOptionState) => React.ReactNode;
36
+ slots?: ISelectWithApiPropsSlots<O>;
37
+ }
38
+ export interface ISelectWithApiHandle {
39
+ clear: () => void;
40
+ }
41
+ export declare const selectWithApiClasses: {
42
+ root: string;
43
+ label: string;
44
+ input: string;
45
+ error: string;
46
+ tooltip: string;
47
+ tooltipWrap: string;
48
+ };
49
+ /**
50
+ * Modern Custom Styled Select With API Creator for DinoForm V2.
51
+ *
52
+ * Synchronized with V2 design aesthetics (Top Label, rounded corners 10px, #cbd5e1 border, styled dropdown paper & items).
53
+ *
54
+ * @example
55
+ * @formField({
56
+ * type: String,
57
+ * label: 'Assignee',
58
+ * renderInput: DinoForm.createSelectWithApiV2({
59
+ * placeholder: 'Search assignee...',
60
+ * fetchData: async (search) => fetchUsers(search)
61
+ * })
62
+ * })
63
+ * assigneeId?: string
64
+ */
65
+ export declare function createSelectWithApi<T = any, O extends ISelectWithApiOption = ISelectWithApiOption>(params?: ISelectWithApiParams<O>): ComponentType<ISelectWithApiProps<T, O>>;
66
+ export default createSelectWithApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dinocollab-core",
3
- "version": "2.2.49",
3
+ "version": "2.2.52",
4
4
  "description": "Dinocollab core - libraries for building collaborative applications with React 18",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -1,2 +0,0 @@
1
- import{objectSpread2 as e,inherits as n,createClass as r,classCallCheck as t,callSuper as i,defineProperty as o,asyncToGenerator as l,regenerator as a}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as s,jsxs as u}from"react/jsx-runtime";import{Component as p}from"react";import{styled as d,Typography as g,Box as m,TextField as f}from"@mui/material";import c from"@mui/icons-material/Download";import{getErrorMessage as h}from"./helpers.js";import{tryParseCsvFileToArray as v}from"../utils/helpers.js";import"../utils/dayjs-config.js";import"../utils/query-param.js";function C(d){var C=function(){function C(n){var r;return t(this,C),r=i(this,C,[n]),o(r,"mergeConfigsCache",{name:"",onBlur:function(){},messageErrors:{}}),o(r,"refInput",null),o(r,"refTextFiled",null),o(r,"getTextFieldProps",function(){var n,t=r.props,i=t.label,o=t.name,l=h(r.mergeConfigs.messageErrors,r.mergeConfigs.name),a=null!=d&&d.subName?d.subName:"".concat(null==o?void 0:o.toString()).concat(null!==(n=null==d?void 0:d.suffixName)&&void 0!==n?n:"_file");return e({label:i,error:l.error,helperText:l.message,name:o?a:void 0,type:"file",variant:"outlined",fullWidth:!0,onChange:r.handleChange,inputProps:{accept:"text/csv"},InputLabelProps:{shrink:r.mergeConfigs.labelShrink}},r.mergeConfigs.textFieldProps)}),o(r,"upgradeMergeConfigs",function(e){var n,r,t,i,o,l,a,s,u,p,g,m,f=e.name,c=e.label,h=e.onBlur,v=e.messageErrors;return{textFieldProps:Object.assign({},null==d?void 0:d.textFieldProps,null===(n=e.slots)||void 0===n?void 0:n.textFieldProps),wrapProps:Object.assign({},null==d?void 0:d.wrapProps,null===(r=e.slots)||void 0===r?void 0:r.wrapProps),name:f,onBlur:h||function(){},messageErrors:v||{},downloadSampleUrl:null!==(t=null===(i=e.slots)||void 0===i?void 0:i.downloadSampleUrl)&&void 0!==t?t:null==d?void 0:d.downloadSampleUrl,titleText:null!==(o=null===(l=e.slots)||void 0===l?void 0:l.titleText)&&void 0!==o?o:null==d?void 0:d.titleText,subText:null!==(a=null===(s=e.slots)||void 0===s?void 0:s.subText)&&void 0!==a?a:null==d?void 0:d.subText,instructionalText:null!==(u=null===(p=e.slots)||void 0===p?void 0:p.instructionalText)&&void 0!==u?u:null==d?void 0:d.instructionalText,labelShrink:!1!==(null!==(g=null===(m=e.slots)||void 0===m?void 0:m.labelShrink)&&void 0!==g?g:null==d?void 0:d.labelShrink)&&!!c}}),o(r,"handleChange",function(){var e=l(a().m(function e(n){var t,i,o,l;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(i=null===(t=n.target.files)||void 0===t?void 0:t[0]){e.n=1;break}return e.a(2);case 1:return e.p=1,e.n=2,v(i);case 2:o=e.v,r.refInput&&(r.refInput.value=JSON.stringify(o)),r.setState({parsedData:o},function(){r.props.onChange&&r.props.onChange(o),r.mergeConfigs.onBlur(r.mergeConfigs.name)}),e.n=4;break;case 3:e.p=3,l=e.v,console.error("Error parsing CSV:",l),r.mergeConfigs.onBlur(r.mergeConfigs.name);case 4:return e.a(2)}},e,null,[[1,3]])}));return function(n){return e.apply(this,arguments)}}()),r.mergeConfigsCache=r.upgradeMergeConfigs(n),r.state={parsedData:[]},r}return n(C,p),r(C,[{key:"mergeConfigs",get:function(){return this.mergeConfigsCache}},{key:"inputValue",get:function(){return this.state.parsedData.length>0?JSON.stringify(this.state.parsedData):""}},{key:"shouldComponentUpdate",value:function(e){return e!==this.props&&(this.mergeConfigsCache=this.upgradeMergeConfigs(e)),!0}},{key:"render",value:function(){var n,r,t=this;return u(m,e(e({},this.mergeConfigs.wrapProps),{},{children:[this.mergeConfigs.titleText&&s(g,{variant:"subtitle1",component:"h6",sx:{fontWeight:600,mb:.5},children:this.mergeConfigs.titleText}),this.mergeConfigs.downloadSampleUrl&&u(m,{sx:{display:"flex",alignItems:"center",mb:1},children:[s(g,{variant:"subtitle2",component:"span",children:null!==(n=this.mergeConfigs.instructionalText)&&void 0!==n?n:"Metadata file, please fill out the form we provide."}),u(x,{href:this.mergeConfigs.downloadSampleUrl,children:[s("span",{children:" Download sample"}),s(c,{fontSize:"small"})]})]}),this.mergeConfigs.subText&&s(g,{variant:"body2",component:"span",sx:{display:"block",mb:1},children:this.mergeConfigs.subText}),s("input",{hidden:!0,name:null===(r=this.props.name)||void 0===r?void 0:r.toString(),type:"text",ref:function(e){return t.refInput=e},defaultValue:""}),s(f,e(e({},this.getTextFieldProps()),{},{inputRef:function(e){return t.refTextFiled=e}}))]}))}}])}();return C}var x=d(function(n){return s(g,e({variant:"subtitle2",component:"a",target:"_blank",download:!0},n))})(function(e){var n=e.theme;return{display:"flex",alignItems:"center",color:n.palette.primary.light,cursor:"pointer",fontWeight:600,marginLeft:"6px",gap:"4px",transition:"all 0.3s ease","&:hover":{textDecoration:"underline",color:n.palette.primary.dark}}});export{C as createInputFileCsvLocalParser};
2
- //# sourceMappingURL=create.input-file.csv-local-parser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create.input-file.csv-local-parser.js","sources":["../../../src/form/create.input-file.csv-local-parser.tsx"],"sourcesContent":["import React, { Component, ComponentType } from 'react'\r\nimport { Box, BoxProps, styled, TextField, TextFieldProps, Typography, TypographyProps } from '@mui/material'\r\nimport DownloadIcon from '@mui/icons-material/Download'\r\nimport { getErrorMessage } from './helpers'\r\nimport { tryParseCsvFileToArray } from '../utils'\r\nimport { IFormBase, IFormInputBase } from './types'\r\n\r\nexport interface IInputFileCsvLocalParserSlots {\r\n /**\r\n * The URL of the sample CSV file that users can download.\r\n * If provided, a \"Download sample\" link will be displayed.\r\n * Example: '/sample.csv' or 'https://example.com/sample.csv'\r\n */\r\n downloadSampleUrl?: string\r\n /**\r\n * Instructional text displayed alongside the download link or file input.\r\n * Useful for guiding users on how to use or fill out the CSV file.\r\n */\r\n instructionalText?: string\r\n /**\r\n * The title text displayed at the top.\r\n */\r\n titleText?: string\r\n /**\r\n * Optional sub text displayed below the title or above the download link.\r\n */\r\n subText?: string\r\n /**\r\n * Props to customize the TextField used for uploading the CSV file.\r\n * Allows customization of appearance and behavior (e.g., placeholder, onChange, disabled).\r\n */\r\n textFieldProps?: TextFieldProps\r\n /**\r\n * Props passed to the wrapper element (typically a Box).\r\n * Useful for customizing layout styles such as margin, padding, or display.\r\n */\r\n wrapProps?: BoxProps\r\n /**\r\n * Whether the label should shrink when displayed.\r\n * Defaults to `true` if a label is present to prevent overlap.\r\n * @default true\r\n */\r\n labelShrink?: boolean\r\n}\r\n\r\nexport interface IInputFileCsvLocalParserParams extends IInputFileCsvLocalParserSlots {\r\n /** Optional sub name for the input field. */\r\n subName?: string\r\n /**\r\n * Optional suffix name for the input field. When `subName` is provided, `suffixName` will be not used.\r\n * @default '_file'\r\n * */\r\n suffixName?: string\r\n}\r\n\r\nexport interface IInputFileCsvLocalParserProps<T, C> extends IFormInputBase<T, IInputFileCsvLocalParserSlots> {\r\n onChange?: (value: C[]) => void\r\n}\r\n\r\nexport interface IInputFileCsvLocalParserState<C> {\r\n parsedData: C[]\r\n}\r\n\r\ntype IPickConfigs<T> = Required<Pick<IFormBase<T>, 'onBlur' | 'messageErrors'>>\r\n\r\ninterface IMergeConfigs<T> extends IPickConfigs<T>, IInputFileCsvLocalParserSlots {\r\n name: keyof T\r\n}\r\n\r\n/**\r\n * Creates a React component that renders a file input specifically for CSV files,\r\n * parses the selected file locally into a structured array, and integrates with a form system.\r\n *\r\n * @template T - The main data model used in the form. Represents the shape of the overall form data.\r\n * @template C - The type of each individual item parsed from the CSV file.\r\n *\r\n * @param params - Optional slot parameters to customize the appearance or behavior of the text field.\r\n * @returns A React component configured for uploading and parsing local CSV files.\r\n */\r\nexport function createInputFileCsvLocalParser<T, C>(params?: IInputFileCsvLocalParserParams): ComponentType<IInputFileCsvLocalParserProps<T, C>> {\r\n class InputFileCsvLocalParser extends Component<IInputFileCsvLocalParserProps<T, C>, IInputFileCsvLocalParserState<C>> {\r\n private mergeConfigsCache: IMergeConfigs<T> = { name: '' as keyof T, onBlur: () => {}, messageErrors: {} }\r\n constructor(props: IInputFileCsvLocalParserProps<T, C>) {\r\n super(props)\r\n this.mergeConfigsCache = this.upgradeMergeConfigs(props)\r\n this.state = { parsedData: [] }\r\n }\r\n\r\n get mergeConfigs(): IMergeConfigs<T> {\r\n return this.mergeConfigsCache\r\n }\r\n\r\n get inputValue() {\r\n return this.state.parsedData.length > 0 ? JSON.stringify(this.state.parsedData) : ''\r\n }\r\n\r\n shouldComponentUpdate(nextProps: Readonly<IInputFileCsvLocalParserProps<T, C>>): boolean {\r\n if (nextProps !== this.props) this.mergeConfigsCache = this.upgradeMergeConfigs(nextProps)\r\n return true\r\n }\r\n\r\n refInput: HTMLInputElement | null = null\r\n refTextFiled: HTMLInputElement | null = null\r\n render() {\r\n return (\r\n <Box {...this.mergeConfigs.wrapProps}>\r\n {this.mergeConfigs.titleText && (\r\n <Typography variant='subtitle1' component='h6' sx={{ fontWeight: 600, mb: 0.5 }}>\r\n {this.mergeConfigs.titleText}\r\n </Typography>\r\n )}\r\n {this.mergeConfigs.downloadSampleUrl && (\r\n <Box sx={{ display: 'flex', alignItems: 'center', mb: 1 }}>\r\n <Typography variant='subtitle2' component='span'>\r\n {this.mergeConfigs.instructionalText ?? 'Metadata file, please fill out the form we provide.'}\r\n </Typography>\r\n <DownloadButton href={this.mergeConfigs.downloadSampleUrl}>\r\n <span> Download sample</span>\r\n <DownloadIcon fontSize='small' />\r\n </DownloadButton>\r\n </Box>\r\n )}\r\n {this.mergeConfigs.subText && (\r\n <Typography variant='body2' component='span' sx={{ display: 'block', mb: 1 }}>\r\n {this.mergeConfigs.subText}\r\n </Typography>\r\n )}\r\n <input hidden name={this.props.name?.toString()} type='text' ref={(ref) => (this.refInput = ref)} defaultValue='' />\r\n <TextField {...this.getTextFieldProps()} inputRef={(ref) => (this.refTextFiled = ref)} />\r\n </Box>\r\n )\r\n }\r\n\r\n getTextFieldProps = (): TextFieldProps => {\r\n const { label, name } = this.props\r\n const eMessage = getErrorMessage(this.mergeConfigs.messageErrors, this.mergeConfigs.name)\r\n const subName = params?.subName ? params.subName : `${name?.toString()}${params?.suffixName ?? '_file'}`\r\n const mergedProps: TextFieldProps = {\r\n label,\r\n error: eMessage.error,\r\n helperText: eMessage.message,\r\n name: name ? subName : undefined,\r\n type: 'file',\r\n variant: 'outlined',\r\n fullWidth: true,\r\n onChange: this.handleChange,\r\n inputProps: { accept: 'text/csv' },\r\n InputLabelProps: { shrink: this.mergeConfigs.labelShrink },\r\n ...this.mergeConfigs.textFieldProps\r\n }\r\n return mergedProps\r\n }\r\n\r\n upgradeMergeConfigs = (currentProps: IInputFileCsvLocalParserProps<T, C>): IMergeConfigs<T> => {\r\n const { name, label, onBlur, messageErrors } = currentProps\r\n return {\r\n textFieldProps: Object.assign({}, params?.textFieldProps, currentProps.slots?.textFieldProps),\r\n wrapProps: Object.assign({}, params?.wrapProps, currentProps.slots?.wrapProps),\r\n name: name as keyof T,\r\n onBlur: onBlur || (() => {}),\r\n messageErrors: messageErrors || {},\r\n downloadSampleUrl: currentProps.slots?.downloadSampleUrl ?? params?.downloadSampleUrl,\r\n titleText: currentProps.slots?.titleText ?? params?.titleText,\r\n subText: currentProps.slots?.subText ?? params?.subText,\r\n instructionalText: currentProps.slots?.instructionalText ?? params?.instructionalText,\r\n labelShrink: (currentProps.slots?.labelShrink ?? params?.labelShrink) !== false && !!label\r\n }\r\n }\r\n\r\n handleChange = async (e: React.ChangeEvent<HTMLInputElement>) => {\r\n const file = e.target.files?.[0]\r\n if (!file) return\r\n try {\r\n const result = await tryParseCsvFileToArray(file)\r\n if (this.refInput) this.refInput.value = JSON.stringify(result)\r\n this.setState({ parsedData: result as C[] }, () => {\r\n this.props.onChange && this.props.onChange(result as C[])\r\n this.mergeConfigs.onBlur(this.mergeConfigs.name)\r\n })\r\n } catch (err) {\r\n console.error('Error parsing CSV:', err)\r\n this.mergeConfigs.onBlur(this.mergeConfigs.name)\r\n }\r\n }\r\n }\r\n return InputFileCsvLocalParser\r\n}\r\n\r\nconst DownloadButton = styled((p: TypographyProps & { href: string }) => (\r\n <Typography variant='subtitle2' component='a' target='_blank' download {...p} />\r\n))(({ theme }) => ({\r\n display: 'flex',\r\n alignItems: 'center',\r\n color: theme.palette.primary.light,\r\n cursor: 'pointer',\r\n fontWeight: 600,\r\n marginLeft: '6px',\r\n gap: '4px',\r\n transition: 'all 0.3s ease',\r\n '&:hover': {\r\n textDecoration: 'underline',\r\n color: theme.palette.primary.dark\r\n }\r\n}))\r\n"],"names":["createInputFileCsvLocalParser","params","InputFileCsvLocalParser","props","_this","_classCallCheck","_callSuper","_defineProperty","name","onBlur","messageErrors","_params$suffixName","_this$props","label","eMessage","getErrorMessage","mergeConfigs","subName","concat","toString","suffixName","_objectSpread","error","helperText","message","undefined","type","variant","fullWidth","onChange","handleChange","inputProps","accept","InputLabelProps","shrink","labelShrink","textFieldProps","currentProps","_currentProps$slots","_currentProps$slots2","_currentProps$slots$d","_currentProps$slots3","_currentProps$slots$t","_currentProps$slots4","_currentProps$slots$s","_currentProps$slots5","_currentProps$slots$i","_currentProps$slots6","_currentProps$slots$l","_currentProps$slots7","Object","assign","slots","wrapProps","downloadSampleUrl","titleText","subText","instructionalText","_ref","_asyncToGenerator","_regenerator","m","_callee","e","_e$target$files","file","result","_t","w","_context","p","n","target","files","a","tryParseCsvFileToArray","v","refInput","value","JSON","stringify","setState","parsedData","console","_x","apply","this","arguments","mergeConfigsCache","upgradeMergeConfigs","state","_inherits","Component","_createClass","key","get","length","nextProps","_this$mergeConfigs$in","_this$props$name","_this2","_jsxs","Box","children","_jsx","Typography","component","sx","fontWeight","mb","display","alignItems","DownloadButton","href","DownloadIcon","fontSize","hidden","ref","defaultValue","TextField","getTextFieldProps","inputRef","refTextFiled","styled","download","_ref3","theme","color","palette","primary","light","cursor","marginLeft","gap","transition","textDecoration","dark"],"mappings":"qkBA+EM,SAAUA,EAAoCC,GAAuC,IACnFC,aAEJ,SAAAA,EAAYC,GAA0C,IAAAC,EAGrB,OAHqBC,OAAAH,GACpDE,EAAAE,EAAAJ,KAAAA,GAAMC,IAAMI,EAAAH,EAFgC,oBAAA,CAAEI,KAAM,GAAeC,OAAQ,WAAQ,EAAEC,cAAe,CAAA,IAAIH,EAAAH,EAAA,WAoBtE,MAAIG,EAAAH,EAAA,eACA,MAAIG,EAAAH,EAAA,oBA+BxB,WAAqB,IAAAO,EACvCC,EAAwBR,EAAKD,MAArBU,EAAKD,EAALC,MAAOL,EAAII,EAAJJ,KACTM,EAAWC,EAAgBX,EAAKY,aAAaN,cAAeN,EAAKY,aAAaR,MAC9ES,EAAUhB,SAAAA,EAAQgB,QAAUhB,EAAOgB,QAAOC,GAAAA,OAAMV,aAAAA,EAAAA,EAAMW,YAAUD,OAAqBP,QAArBA,EAAGV,eAAAA,EAAQmB,sBAAUT,EAAAA,EAAI,SAc/F,OAbiBU,EAAA,CACfR,MAAAA,EACAS,MAAOR,EAASQ,MAChBC,WAAYT,EAASU,QACrBhB,KAAMA,EAAOS,OAAUQ,EACvBC,KAAM,OACNC,QAAS,WACTC,WAAW,EACXC,SAAUzB,EAAK0B,aACfC,WAAY,CAAEC,OAAQ,YACtBC,gBAAiB,CAAEC,OAAQ9B,EAAKY,aAA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MAAMK,YAAX2F,IAAeA,OAAfA,EAAAA,EAAiBhF,WAAYO,KAAK,OAAO2F,IAAK,SAACA,GAAG,OAAMjB,EAAKvB,SAAWwC,CAAI,EAAEC,aAAa,KAC/Gd,EAACe,EAASlG,EAAAA,EAAK,CAAA,EAAAiE,KAAKkC,qBAAmB,GAAA,CAAEC,SAAU,SAACJ,GAAG,OAAMjB,EAAKsB,aAAeL,CAAG,QAG1F,IAAC,IAsDH,OAAOnH,CACT,CAEA,IAAM8G,EAAiBW,EAAO,SAACrD,GAAqC,OAClEkC,EAACC,EAAUpF,EAAA,CAACM,QAAQ,YAAY+E,UAAU,IAAIlC,OAAO,SAASoD,UAAQ,GAAKtD,GAAK,EAD3DqD,CAEpB,SAAAE,GAAA,IAAGC,EAAKD,EAALC,MAAK,MAAQ,CACjBhB,QAAS,OACTC,WAAY,SACZgB,MAAOD,EAAME,QAAQC,QAAQC,MAC7BC,OAAQ,UACRvB,WAAY,IACZwB,WAAY,MACZC,IAAK,MACLC,WAAY,gBACZ,UAAW,CACTC,eAAgB,YAChBR,MAAOD,EAAME,QAAQC,QAAQO,MAEhC"}
@@ -1,2 +0,0 @@
1
- import{inherits as t,createClass as e,objectSpread2 as r,classCallCheck as o,callSuper as i,defineProperty as n}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as l,jsx as s}from"react/jsx-runtime";import{Component as a}from"react";import{styled as p,Box as u,TextField as m,Collapse as d,InputAdornment as c}from"@mui/material";import{getErrorMessage as h}from"./helpers.js";import{RichTooltip as g,HelpOutlinePulseIcon as f}from"../components/rich-tooltip.js";function v(p){return function(){function v(t){var e;return o(this,v),e=i(this,v,[t]),n(e,"getTextFieldProps",function(){var t=e.props,o=t.name,i=t.messageErrors,n=t.slots,l=t.onBlur,a=h(i,o),p=r(r({name:null==o?void 0:o.toString(),error:a.error,helperText:a.message},null==n?void 0:n.inputProps),{},{onBlur:function(){o&&l&&l(o)},onChange:e.handleChange});return p.InputProps||(p.InputProps={}),e.slots.tooltip&&(p.InputProps.endAdornment=s(c,{position:"end",children:e.slots.tooltip&&s(g,{panel:e.slots.tooltip,children:s(f,{fontSize:"small"})})})),p}),n(e,"handleChange",function(t){var r,o=null===(r=t.target.files)||void 0===r?void 0:r[0];if(o){var i=URL.createObjectURL(o);e.setState({imageUrl:i},function(){e.props.name&&e.props.onBlur&&e.props.onBlur(e.props.name)})}}),n(e,"getImageUrl",function(){var t=e.props.data,r=null!=p&&p.imageGetter?p.imageGetter(t):void 0;return e.state.imageUrl||r||""}),e.state={},e}return t(v,a),e(v,[{key:"slots",get:function(){return{tooltip:this.props.tooltip||(null==p?void 0:p.tooltip)}}},{key:"render",value:function(){var t,e=this.getImageUrl();return l(x,r(r({},null===(t=this.props.slots)||void 0===t?void 0:t.wrapProps),{},{children:[s(u,{sx:{flex:1},children:s(m,r({variant:"outlined",type:"file",fullWidth:!0,inputProps:{accept:"image/*",multiple:!1}},this.getTextFieldProps()))}),s(d,{in:!!e,orientation:"horizontal",unmountOnExit:!0,children:s(P,{children:s("img",{src:e,alt:"berlintomek-image"})})})]}))}}])}()}var x=p(u)({display:"flex",gap:"9px",alignItems:"start"}),P=p(u)({height:"56px",width:"56px",marginRight:"6px",borderRadius:"4px",overflow:"hidden",border:"1px solid rgba(145, 158, 171, .16)","& > img":{width:"100%",height:"100%",objectFit:"cover"}});export{v as default};
2
- //# sourceMappingURL=create.input.image-file.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create.input.image-file.js","sources":["../../../src/form/create.input.image-file.tsx"],"sourcesContent":["import React, { Component, ComponentType } from 'react'\r\nimport { Box, BoxProps, Collapse, InputAdornment, styled, TextField, TextFieldProps } from '@mui/material'\r\nimport { IFormInputBase } from './types'\r\nimport { getErrorMessage } from './helpers'\r\nimport { IRichTooltipPanelConfig, RichTooltip, HelpOutlinePulseIcon } from '../components/rich-tooltip'\r\n\r\nexport interface IInputImageFileSlots {\r\n wrapProps?: BoxProps\r\n inputProps?: TextFieldProps\r\n}\r\n\r\nexport interface IInputImageFileProps<T> extends IFormInputBase<T, IInputImageFileSlots> {\r\n tooltip?: IRichTooltipPanelConfig\r\n}\r\n\r\nexport interface IInputImageFileState {\r\n imageUrl?: string\r\n}\r\n\r\nexport interface IInputImageFileParams<T> {\r\n imageGetter?: (data?: Partial<T>) => string | undefined\r\n tooltip?: IRichTooltipPanelConfig\r\n}\r\n\r\nfunction createInputImageFile<T>(params?: IInputImageFileParams<T>): ComponentType<IInputImageFileProps<T>> {\r\n class InputImageFile extends Component<IInputImageFileProps<T>, IInputImageFileState> {\r\n constructor(props: IInputImageFileProps<T>) {\r\n super(props)\r\n this.state = {}\r\n }\r\n\r\n private get slots() {\r\n return {\r\n tooltip: this.props.tooltip || params?.tooltip\r\n }\r\n }\r\n\r\n render() {\r\n const url = this.getImageUrl()\r\n return (\r\n <Wrap {...this.props.slots?.wrapProps}>\r\n <Box sx={{ flex: 1 }}>\r\n <TextField variant='outlined' type='file' fullWidth inputProps={{ accept: 'image/*', multiple: false }} {...this.getTextFieldProps()} />\r\n </Box>\r\n <Collapse in={!!url} orientation='horizontal' unmountOnExit>\r\n <ImageWrap>\r\n <img src={url} alt='berlintomek-image' />\r\n </ImageWrap>\r\n </Collapse>\r\n </Wrap>\r\n )\r\n }\r\n\r\n getTextFieldProps = (): TextFieldProps => {\r\n const { name, messageErrors, slots, onBlur } = this.props\r\n const errorMessage = getErrorMessage(messageErrors, name)\r\n const tfp: TextFieldProps = {\r\n name: name?.toString(),\r\n error: errorMessage.error,\r\n helperText: errorMessage.message,\r\n ...slots?.inputProps,\r\n onBlur: () => {\r\n if (!name || !onBlur) return\r\n onBlur(name)\r\n },\r\n onChange: this.handleChange\r\n }\r\n if (!tfp.InputProps) tfp.InputProps = {}\r\n if (this.slots.tooltip) {\r\n tfp.InputProps.endAdornment = (\r\n <InputAdornment position='end'>\r\n {this.slots.tooltip && (\r\n <RichTooltip panel={this.slots.tooltip}>\r\n <HelpOutlinePulseIcon fontSize='small' />\r\n </RichTooltip>\r\n )}\r\n </InputAdornment>\r\n )\r\n }\r\n return tfp\r\n }\r\n\r\n handleChange: React.ChangeEventHandler<HTMLInputElement> = (event) => {\r\n const file = event.target.files?.[0]\r\n if (file) {\r\n const imageUrl = URL.createObjectURL(file)\r\n this.setState({ imageUrl }, () => {\r\n if (!this.props.name) return\r\n this.props.onBlur && this.props.onBlur(this.props.name)\r\n })\r\n }\r\n }\r\n\r\n getImageUrl = () => {\r\n const { data } = this.props\r\n const value = params?.imageGetter ? params.imageGetter(data) : undefined\r\n return this.state.imageUrl || value || ''\r\n }\r\n }\r\n return InputImageFile\r\n}\r\nexport default createInputImageFile\r\n\r\nconst Wrap = styled(Box)({\r\n display: 'flex',\r\n gap: '9px',\r\n alignItems: 'start'\r\n})\r\n\r\nconst ImageWrap = styled(Box)({\r\n height: '56px',\r\n width: '56px',\r\n marginRight: '6px',\r\n borderRadius: '4px',\r\n overflow: 'hidden',\r\n border: '1px solid rgba(145, 158, 171, .16)',\r\n '& > img': {\r\n width: '100%',\r\n height: '100%',\r\n objectFit: 'cover'\r\n }\r\n})\r\n"],"names":["createInputImageFile","params","InputImageFile","props","_this","_classCallCheck","_callSuper","_defineProperty","_this$props","name","messageErrors","slots","onBlur","errorMessage","getErrorMessage","tfp","_objectSpread","toString","error","helperText","message","inputProps","onChange","handleChange","InputProps","tooltip","endAdornment","_jsx","InputAdornment","position","RichTooltip","panel","children","HelpOutlinePulseIcon","fontSize","event","_event$target$files","file","target","files","imageUrl","URL","createObjectURL","setState","data","value","imageGetter","undefined","state","_inherits","Component","_createClass","key","get","this","_this$props$slots","url","getImageUrl","_jsxs","Wrap","wrapProps","Box","sx","flex","TextField","variant","type","fullWidth","accept","multiple","getTextFieldProps","Collapse","in","orientation","unmountOnExit","ImageWrap","src","alt","styled","display","gap","alignItems","height","width","marginRight","borderRadius","overflow","border","objectFit"],"mappings":"4dAwBA,SAASA,EAAwBC,GA2E/B,kBAzEE,SAAAC,EAAYC,GAA8B,IAAAC,EAEzB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AA/C,EAJ0BgD,GAI1BC,EAAAjD,EAAA,CAAA,CAAAkD,IAAA,QAAAC,IAED,WACE,MAAO,CACL5B,QAAS6B,KAAKnD,MAAMsB,UAAWxB,aAAAA,EAAAA,EAAQwB,SAE3C,GAAC,CAAA2B,IAAA,SAAAP,MAED,WAAM,IAAAU,EACEC,EAAMF,KAAKG,cACjB,OACEC,EAACC,EAAI3C,EAAAA,KAAqB,QAArBuC,EAAKD,KAAKnD,MAAMQ,aAAX4C,IAAgBA,OAAhBA,EAAAA,EAAkBK,WAAS,GAAA,WACnCjC,EAACkC,GAAIC,GAAI,CAAEC,KAAM,YACfpC,EAACqC,EAAShD,EAAA,CAACiD,QAAQ,WAAWC,KAAK,OAAOC,WAAU,EAAA9C,WAAY,CAAE+C,OAAQ,UAAWC,UAAU,IAAaf,KAAKgB,wBAEnH3C,EAAC4C,EAAS,CAAAC,KAAMhB,EAAKiB,YAAY,aAAaC,eAAa,EAAA1C,SACzDL,EAACgD,EAAS,CAAA3C,SACRL,SAAKiD,IAAKpB,EAAKqB,IAAI,6BAK7B,IAAC,GAiDL,CAGA,IAAMlB,EAAOmB,EAAOjB,EAAPiB,CAAY,CACvBC,QAAS,OACTC,IAAK,MACLC,WAAY,UAGRN,EAAYG,EAAOjB,EAAPiB,CAAY,CAC5BI,OAAQ,OACRC,MAAO,OACPC,YAAa,MACbC,aAAc,MACdC,SAAU,SACVC,OAAQ,qCACR,UAAW,CACTJ,MAAO,OACPD,OAAQ,OACRM,UAAW"}
@@ -1,66 +0,0 @@
1
- import { ComponentType } from 'react';
2
- import { BoxProps, TextFieldProps } from '@mui/material';
3
- import { IFormInputBase } from './types';
4
- export interface IInputFileCsvLocalParserSlots {
5
- /**
6
- * The URL of the sample CSV file that users can download.
7
- * If provided, a "Download sample" link will be displayed.
8
- * Example: '/sample.csv' or 'https://example.com/sample.csv'
9
- */
10
- downloadSampleUrl?: string;
11
- /**
12
- * Instructional text displayed alongside the download link or file input.
13
- * Useful for guiding users on how to use or fill out the CSV file.
14
- */
15
- instructionalText?: string;
16
- /**
17
- * The title text displayed at the top.
18
- */
19
- titleText?: string;
20
- /**
21
- * Optional sub text displayed below the title or above the download link.
22
- */
23
- subText?: string;
24
- /**
25
- * Props to customize the TextField used for uploading the CSV file.
26
- * Allows customization of appearance and behavior (e.g., placeholder, onChange, disabled).
27
- */
28
- textFieldProps?: TextFieldProps;
29
- /**
30
- * Props passed to the wrapper element (typically a Box).
31
- * Useful for customizing layout styles such as margin, padding, or display.
32
- */
33
- wrapProps?: BoxProps;
34
- /**
35
- * Whether the label should shrink when displayed.
36
- * Defaults to `true` if a label is present to prevent overlap.
37
- * @default true
38
- */
39
- labelShrink?: boolean;
40
- }
41
- export interface IInputFileCsvLocalParserParams extends IInputFileCsvLocalParserSlots {
42
- /** Optional sub name for the input field. */
43
- subName?: string;
44
- /**
45
- * Optional suffix name for the input field. When `subName` is provided, `suffixName` will be not used.
46
- * @default '_file'
47
- * */
48
- suffixName?: string;
49
- }
50
- export interface IInputFileCsvLocalParserProps<T, C> extends IFormInputBase<T, IInputFileCsvLocalParserSlots> {
51
- onChange?: (value: C[]) => void;
52
- }
53
- export interface IInputFileCsvLocalParserState<C> {
54
- parsedData: C[];
55
- }
56
- /**
57
- * Creates a React component that renders a file input specifically for CSV files,
58
- * parses the selected file locally into a structured array, and integrates with a form system.
59
- *
60
- * @template T - The main data model used in the form. Represents the shape of the overall form data.
61
- * @template C - The type of each individual item parsed from the CSV file.
62
- *
63
- * @param params - Optional slot parameters to customize the appearance or behavior of the text field.
64
- * @returns A React component configured for uploading and parsing local CSV files.
65
- */
66
- export declare function createInputFileCsvLocalParser<T, C>(params?: IInputFileCsvLocalParserParams): ComponentType<IInputFileCsvLocalParserProps<T, C>>;
@@ -1,20 +0,0 @@
1
- import { ComponentType } from 'react';
2
- import { BoxProps, TextFieldProps } from '@mui/material';
3
- import { IFormInputBase } from './types';
4
- import { IRichTooltipPanelConfig } from '../components/rich-tooltip';
5
- export interface IInputImageFileSlots {
6
- wrapProps?: BoxProps;
7
- inputProps?: TextFieldProps;
8
- }
9
- export interface IInputImageFileProps<T> extends IFormInputBase<T, IInputImageFileSlots> {
10
- tooltip?: IRichTooltipPanelConfig;
11
- }
12
- export interface IInputImageFileState {
13
- imageUrl?: string;
14
- }
15
- export interface IInputImageFileParams<T> {
16
- imageGetter?: (data?: Partial<T>) => string | undefined;
17
- tooltip?: IRichTooltipPanelConfig;
18
- }
19
- declare function createInputImageFile<T>(params?: IInputImageFileParams<T>): ComponentType<IInputImageFileProps<T>>;
20
- export default createInputImageFile;