@firecms/collection_editor 3.0.0-beta.2-pre.1 → 3.0.0-beta.2-pre.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/form/Field.d.ts +53 -0
- package/dist/form/Formex.d.ts +4 -0
- package/dist/form/index.d.ts +5 -0
- package/dist/form/types.d.ts +25 -0
- package/dist/form/useCreateFormex.d.ts +9 -0
- package/dist/form/utils.d.ts +44 -0
- package/dist/index.es.js +2612 -2328
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/types/collection_editor_controller.d.ts +3 -2
- package/dist/types/config_controller.d.ts +3 -3
- package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +3 -5
- package/dist/ui/collection_editor/CollectionEditorWelcomeView.d.ts +2 -2
- package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +1 -2
- package/dist/ui/collection_editor/EnumForm.d.ts +1 -2
- package/dist/ui/collection_editor/PropertyEditView.d.ts +5 -5
- package/dist/ui/collection_editor/PropertyTree.d.ts +14 -13
- package/dist/ui/collection_editor/SwitchControl.d.ts +8 -0
- package/dist/ui/collection_editor/properties/CommonPropertyFields.d.ts +0 -1
- package/dist/ui/collection_editor/util.d.ts +1 -0
- package/package.json +5 -5
- package/src/ConfigControllerProvider.tsx +23 -21
- package/src/form/Field.tsx +162 -0
- package/src/form/Formex.tsx +8 -0
- package/src/form/README.md +165 -0
- package/src/form/index.ts +5 -0
- package/src/form/types.ts +27 -0
- package/src/form/useCreateFormex.tsx +137 -0
- package/src/form/utils.ts +169 -0
- package/src/types/collection_editor_controller.tsx +4 -3
- package/src/types/config_controller.tsx +3 -3
- package/src/ui/CollectionViewHeaderAction.tsx +1 -1
- package/src/ui/EditorCollectionAction.tsx +3 -3
- package/src/ui/HomePageEditorCollectionAction.tsx +2 -2
- package/src/ui/MissingReferenceWidget.tsx +2 -1
- package/src/ui/NewCollectionButton.tsx +3 -3
- package/src/ui/NewCollectionCard.tsx +2 -1
- package/src/ui/PropertyAddColumnComponent.tsx +1 -1
- package/src/ui/RootCollectionSuggestions.tsx +2 -1
- package/src/ui/collection_editor/CollectionDetailsForm.tsx +2 -2
- package/src/ui/collection_editor/CollectionEditorDialog.tsx +422 -374
- package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +19 -12
- package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +26 -18
- package/src/ui/collection_editor/EnumForm.tsx +118 -114
- package/src/ui/collection_editor/GetCodeDialog.tsx +1 -1
- package/src/ui/collection_editor/PropertyEditView.tsx +198 -142
- package/src/ui/collection_editor/PropertyFieldPreview.tsx +5 -1
- package/src/ui/collection_editor/PropertyTree.tsx +132 -113
- package/src/ui/collection_editor/SubcollectionsEditTab.tsx +18 -11
- package/src/ui/collection_editor/SwitchControl.tsx +39 -0
- package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +10 -2
- package/src/ui/collection_editor/properties/BlockPropertyField.tsx +2 -2
- package/src/ui/collection_editor/properties/BooleanPropertyField.tsx +13 -9
- package/src/ui/collection_editor/properties/CommonPropertyFields.tsx +11 -37
- package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +2 -2
- package/src/ui/collection_editor/properties/EnumPropertyField.tsx +3 -6
- package/src/ui/collection_editor/properties/MapPropertyField.tsx +2 -2
- package/src/ui/collection_editor/properties/NumberPropertyField.tsx +2 -2
- package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +11 -14
- package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +10 -9
- package/src/ui/collection_editor/properties/StoragePropertyField.tsx +15 -9
- package/src/ui/collection_editor/properties/StringPropertyField.tsx +2 -2
- package/src/ui/collection_editor/properties/UrlPropertyField.tsx +2 -2
- package/src/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +27 -18
- package/src/ui/collection_editor/properties/validation/ArrayPropertyValidation.tsx +2 -2
- package/src/ui/collection_editor/properties/validation/GeneralPropertyValidation.tsx +27 -16
- package/src/ui/collection_editor/properties/validation/NumberPropertyValidation.tsx +33 -18
- package/src/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +99 -80
- package/src/ui/collection_editor/util.ts +7 -0
- package/src/ui/collection_editor/utils/strings.ts +2 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { FormexController } from "./types";
|
|
3
|
+
export interface FieldInputProps<Value> {
|
|
4
|
+
/** Value of the field */
|
|
5
|
+
value: Value;
|
|
6
|
+
/** Name of the field */
|
|
7
|
+
name: string;
|
|
8
|
+
/** Multiple select? */
|
|
9
|
+
multiple?: boolean;
|
|
10
|
+
/** Is the field checked? */
|
|
11
|
+
checked?: boolean;
|
|
12
|
+
/** Change event handler */
|
|
13
|
+
onChange: (event: React.SyntheticEvent) => void;
|
|
14
|
+
/** Blur event handler */
|
|
15
|
+
onBlur: (event: React.FocusEvent) => void;
|
|
16
|
+
}
|
|
17
|
+
export interface FormexFieldProps<Value = any, FormValues extends object = any> {
|
|
18
|
+
field: FieldInputProps<Value>;
|
|
19
|
+
form: FormexController<FormValues>;
|
|
20
|
+
}
|
|
21
|
+
export type FieldValidator = (value: any) => string | void | Promise<string | void>;
|
|
22
|
+
export interface FieldConfig<V = any, C extends React.ElementType | undefined = undefined> {
|
|
23
|
+
/**
|
|
24
|
+
* Component to render. Can either be a string e.g. 'select', 'input', or 'textarea', or a component.
|
|
25
|
+
*/
|
|
26
|
+
as?: C | string | React.ForwardRefExoticComponent<any>;
|
|
27
|
+
/**
|
|
28
|
+
* Children render function <Field name>{props => ...}</Field>)
|
|
29
|
+
*/
|
|
30
|
+
children?: ((props: FormexFieldProps<V>) => React.ReactNode) | React.ReactNode;
|
|
31
|
+
/**
|
|
32
|
+
* Validate a single field value independently
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* Used for 'select' and related input types.
|
|
36
|
+
*/
|
|
37
|
+
multiple?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Field name
|
|
40
|
+
*/
|
|
41
|
+
name: string;
|
|
42
|
+
/** HTML input type */
|
|
43
|
+
type?: string;
|
|
44
|
+
/** Field value */
|
|
45
|
+
value?: any;
|
|
46
|
+
/** Inner ref */
|
|
47
|
+
innerRef?: (instance: any) => void;
|
|
48
|
+
}
|
|
49
|
+
export type FieldProps<T, C extends React.ElementType | undefined> = {
|
|
50
|
+
as?: C;
|
|
51
|
+
} & (C extends React.ElementType ? (React.ComponentProps<C> & FieldConfig<T, C>) : FieldConfig<T, C>);
|
|
52
|
+
export declare function Field<T, C extends React.ElementType | undefined = undefined>({ validate, name, children, as: is, // `as` is reserved in typescript lol
|
|
53
|
+
className, ...props }: FieldProps<T, C>): any;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { FormEvent } from "react";
|
|
2
|
+
export type FormexController<T extends object> = {
|
|
3
|
+
values: T;
|
|
4
|
+
setValues: (values: T) => void;
|
|
5
|
+
setFieldValue: (key: string, value: any, shouldValidate?: boolean) => void;
|
|
6
|
+
touched: Record<string, boolean>;
|
|
7
|
+
setFieldTouched: (key: string, touched: boolean, shouldValidate?: boolean) => void;
|
|
8
|
+
dirty: boolean;
|
|
9
|
+
setDirty: (dirty: boolean) => void;
|
|
10
|
+
setSubmitCount: (submitCount: number) => void;
|
|
11
|
+
errors: Record<string, string>;
|
|
12
|
+
setFieldError: (key: string, error?: string) => void;
|
|
13
|
+
handleChange: (event: React.SyntheticEvent) => void;
|
|
14
|
+
handleBlur: (event: React.FocusEvent) => void;
|
|
15
|
+
submitForm: (event?: FormEvent<HTMLFormElement>) => void;
|
|
16
|
+
validate: () => void;
|
|
17
|
+
resetForm: (props?: FormexResetProps<T>) => void;
|
|
18
|
+
submitCount: number;
|
|
19
|
+
isSubmitting: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type FormexResetProps<T extends object> = {
|
|
22
|
+
values?: T;
|
|
23
|
+
errors?: Record<string, string>;
|
|
24
|
+
touched?: Record<string, boolean>;
|
|
25
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FormexController } from "./types";
|
|
2
|
+
export declare function useCreateFormex<T extends object>({ initialValues, initialErrors, validation, validateOnChange, onSubmit, validateOnInitialRender }: {
|
|
3
|
+
initialValues: T;
|
|
4
|
+
initialErrors?: Record<string, string>;
|
|
5
|
+
validateOnChange?: boolean;
|
|
6
|
+
validateOnInitialRender?: boolean;
|
|
7
|
+
validation?: (values: T) => Record<string, string>;
|
|
8
|
+
onSubmit?: (values: T, controller: FormexController<T>) => void | Promise<void>;
|
|
9
|
+
}): FormexController<T>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** @private is the value an empty array? */
|
|
3
|
+
export declare const isEmptyArray: (value?: any) => boolean;
|
|
4
|
+
/** @private is the given object a Function? */
|
|
5
|
+
export declare const isFunction: (obj: any) => obj is Function;
|
|
6
|
+
/** @private is the given object an Object? */
|
|
7
|
+
export declare const isObject: (obj: any) => obj is Object;
|
|
8
|
+
/** @private is the given object an integer? */
|
|
9
|
+
export declare const isInteger: (obj: any) => boolean;
|
|
10
|
+
/** @private is the given object a string? */
|
|
11
|
+
export declare const isString: (obj: any) => obj is string;
|
|
12
|
+
/** @private is the given object a NaN? */
|
|
13
|
+
export declare const isNaN: (obj: any) => boolean;
|
|
14
|
+
/** @private Does a React component have exactly 0 children? */
|
|
15
|
+
export declare const isEmptyChildren: (children: any) => boolean;
|
|
16
|
+
/** @private is the given object/value a promise? */
|
|
17
|
+
export declare const isPromise: (value: any) => value is PromiseLike<any>;
|
|
18
|
+
/** @private is the given object/value a type of synthetic event? */
|
|
19
|
+
export declare const isInputEvent: (value: any) => value is React.SyntheticEvent<any, Event>;
|
|
20
|
+
/**
|
|
21
|
+
* Same as document.activeElement but wraps in a try-catch block. In IE it is
|
|
22
|
+
* not safe to call document.activeElement if there is nothing focused.
|
|
23
|
+
*
|
|
24
|
+
* The activeElement will be null only if the document or document body is not
|
|
25
|
+
* yet defined.
|
|
26
|
+
*
|
|
27
|
+
* @param {?Document} doc Defaults to current document.
|
|
28
|
+
* @return {Element | null}
|
|
29
|
+
* @see https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/dom/getActiveElement.js
|
|
30
|
+
*/
|
|
31
|
+
export declare function getActiveElement(doc?: Document): Element | null;
|
|
32
|
+
/**
|
|
33
|
+
* Deeply get a value from an object via its path.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getIn(obj: any, key: string | string[], def?: any, p?: number): any;
|
|
36
|
+
export declare function setIn(obj: any, path: string, value: any): any;
|
|
37
|
+
/**
|
|
38
|
+
* Recursively a set the same value for all keys and arrays nested object, cloning
|
|
39
|
+
* @param object
|
|
40
|
+
* @param value
|
|
41
|
+
* @param visited
|
|
42
|
+
* @param response
|
|
43
|
+
*/
|
|
44
|
+
export declare function setNestedObjectValues<T>(object: any, value: any, visited?: any, response?: any): T;
|