proje-react-panel 1.1.0 → 1.1.2-test-1

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.
@@ -9,9 +9,6 @@ export type OnSubmitFN<T> = (data: T | FormData) => Promise<T | FormData>;
9
9
  interface FormOptions<T extends AnyClass> {
10
10
  onSubmit: OnSubmitFN<T>;
11
11
  getDetailsData?: GetDetailsDataFN<T>;
12
- onSelectPreloader?: (
13
- inputOptions: InputConfiguration
14
- ) => Promise<{ label: string; value: string }[]>;
15
12
  redirectBackOnSuccess?: boolean;
16
13
  type?: 'json' | 'formData';
17
14
  }
@@ -32,12 +29,16 @@ export function Form<T extends AnyClass>(options?: FormOptions<T>): ClassDecorat
32
29
  export function getFormConfiguration<T extends AnyClass, K extends AnyClassConstructor<T>>(
33
30
  entityClass: K
34
31
  ): FormConfiguration<T> {
35
- const formConfiguration = Reflect.getMetadata(DETAILS_METADATA_KEY, entityClass as Object);
36
- if (!formConfiguration) {
32
+ const formOptions: FormOptions<T> = Reflect.getMetadata(
33
+ DETAILS_METADATA_KEY,
34
+ entityClass as Object
35
+ );
36
+ if (!formOptions) {
37
37
  throw new Error('Form decerator should be used on class');
38
38
  }
39
39
  return {
40
- ...formConfiguration,
41
- type: formConfiguration.type ?? 'json',
40
+ ...formOptions,
41
+ type: formOptions.type ?? 'json',
42
+ redirectBackOnSuccess: formOptions.redirectBackOnSuccess ?? true,
42
43
  };
43
44
  }
@@ -7,20 +7,25 @@ const isFieldSensitive = (fieldName: string): boolean => {
7
7
  return ['password'].some(term => fieldName.toLowerCase().includes(term));
8
8
  };
9
9
 
10
+ export type InputTypes = 'input' | 'textarea' | 'file-upload' | 'checkbox' | 'hidden' | 'nested';
11
+ export type ExtendedInputTypes = InputTypes | 'select';
12
+
10
13
  export interface InputOptions {
11
- type?: 'input' | 'select' | 'textarea' | 'file-upload' | 'checkbox' | 'hidden' | 'nested';
14
+ type?: InputTypes;
12
15
  inputType?: 'text' | 'email' | 'tel' | 'password' | 'number' | 'date';
13
16
  name?: string;
14
17
  label?: string;
15
18
  placeholder?: string;
16
- cancelPasswordValidationOnEdit?: boolean;
17
- options?: { value: string; label: string }[];
18
- optionsPreload?: boolean;
19
19
  nestedFields?: InputConfiguration[];
20
20
  }
21
21
 
22
- export interface InputConfiguration extends InputOptions {
22
+ export interface ExtendedInputOptions extends Omit<InputOptions, 'type'> {
23
+ type: ExtendedInputTypes;
24
+ }
25
+
26
+ export interface InputConfiguration extends Omit<InputOptions, 'type'> {
23
27
  name: string;
28
+ type: ExtendedInputTypes;
24
29
  }
25
30
 
26
31
  export function Input(options?: InputOptions): PropertyDecorator {
@@ -35,6 +40,18 @@ export function Input(options?: InputOptions): PropertyDecorator {
35
40
  };
36
41
  }
37
42
 
43
+ export function ExtendedInput(options?: ExtendedInputOptions): PropertyDecorator {
44
+ return (target, propertyKey) => {
45
+ const existingInputs: string[] = Reflect.getMetadata(INPUT_KEY, target) || [];
46
+ Reflect.defineMetadata(INPUT_KEY, [...existingInputs, propertyKey.toString()], target);
47
+
48
+ if (options) {
49
+ const keyString = `${INPUT_KEY.toString()}:${propertyKey.toString()}:options`;
50
+ Reflect.defineMetadata(keyString, options, target);
51
+ }
52
+ };
53
+ }
54
+
38
55
  export function getInputFields<T extends AnyClass>(
39
56
  entityClass: AnyClassConstructor<T>
40
57
  ): InputConfiguration[] {
@@ -53,8 +70,6 @@ export function getInputFields<T extends AnyClass>(
53
70
  inputType: inputType,
54
71
  type: fields?.type ?? 'input',
55
72
  selectOptions: fields?.selectOptions ?? [],
56
- cancelPasswordValidationOnEdit:
57
- fields?.cancelPasswordValidationOnEdit ?? inputType === 'password',
58
73
  };
59
74
  });
60
75
  }
@@ -0,0 +1,19 @@
1
+ import { ExtendedInput, ExtendedInputOptions, InputConfiguration, InputOptions } from '../Input';
2
+
3
+ export interface SelectInputOptions extends InputOptions {
4
+ onSelectPreloader?: () => Promise<{ label: string; value: any }[]>;
5
+ defaultOptions?: { value: any; label: string }[];
6
+ }
7
+
8
+ export interface SelectInputConfiguration extends InputConfiguration {
9
+ type: 'select';
10
+ onSelectPreloader?: () => Promise<{ label: string; value: string }[]>;
11
+ defaultOptions?: { value: any; label: string }[];
12
+ }
13
+
14
+ export function SelectInput(options?: SelectInputOptions): PropertyDecorator {
15
+ return ExtendedInput({
16
+ ...options,
17
+ type: 'select',
18
+ } as ExtendedInputOptions);
19
+ }
package/src/index.ts CHANGED
@@ -18,6 +18,7 @@ export { Cell } from './decorators/list/Cell';
18
18
  export { FormPage } from './components/form/FormPage';
19
19
  export { Form, type OnSubmitFN } from './decorators/form/Form';
20
20
  export { Input } from './decorators/form/Input';
21
+ export { SelectInput } from './decorators/form/inputs/SelectInput';
21
22
  //for nested form fields
22
23
  export { getInputFields } from './decorators/form/Input';
23
24