@firecms/collection_editor 3.0.0-beta.2-pre.2 → 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.
Files changed (71) hide show
  1. package/dist/form/Field.d.ts +53 -0
  2. package/dist/form/Formex.d.ts +4 -0
  3. package/dist/form/index.d.ts +5 -0
  4. package/dist/form/types.d.ts +25 -0
  5. package/dist/form/useCreateFormex.d.ts +9 -0
  6. package/dist/form/utils.d.ts +44 -0
  7. package/dist/index.es.js +2612 -2328
  8. package/dist/index.es.js.map +1 -1
  9. package/dist/index.umd.js +2 -2
  10. package/dist/index.umd.js.map +1 -1
  11. package/dist/types/collection_editor_controller.d.ts +3 -2
  12. package/dist/types/config_controller.d.ts +3 -3
  13. package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +3 -5
  14. package/dist/ui/collection_editor/CollectionEditorWelcomeView.d.ts +2 -2
  15. package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +1 -2
  16. package/dist/ui/collection_editor/EnumForm.d.ts +1 -2
  17. package/dist/ui/collection_editor/PropertyEditView.d.ts +5 -5
  18. package/dist/ui/collection_editor/PropertyTree.d.ts +14 -13
  19. package/dist/ui/collection_editor/SwitchControl.d.ts +8 -0
  20. package/dist/ui/collection_editor/properties/CommonPropertyFields.d.ts +0 -1
  21. package/dist/ui/collection_editor/util.d.ts +1 -0
  22. package/package.json +5 -5
  23. package/src/ConfigControllerProvider.tsx +23 -21
  24. package/src/form/Field.tsx +162 -0
  25. package/src/form/Formex.tsx +8 -0
  26. package/src/form/README.md +165 -0
  27. package/src/form/index.ts +5 -0
  28. package/src/form/types.ts +27 -0
  29. package/src/form/useCreateFormex.tsx +137 -0
  30. package/src/form/utils.ts +169 -0
  31. package/src/types/collection_editor_controller.tsx +4 -3
  32. package/src/types/config_controller.tsx +3 -3
  33. package/src/ui/CollectionViewHeaderAction.tsx +1 -1
  34. package/src/ui/EditorCollectionAction.tsx +3 -3
  35. package/src/ui/HomePageEditorCollectionAction.tsx +2 -2
  36. package/src/ui/MissingReferenceWidget.tsx +2 -1
  37. package/src/ui/NewCollectionButton.tsx +3 -3
  38. package/src/ui/NewCollectionCard.tsx +2 -1
  39. package/src/ui/PropertyAddColumnComponent.tsx +1 -1
  40. package/src/ui/RootCollectionSuggestions.tsx +2 -1
  41. package/src/ui/collection_editor/CollectionDetailsForm.tsx +2 -2
  42. package/src/ui/collection_editor/CollectionEditorDialog.tsx +422 -374
  43. package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +19 -12
  44. package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +26 -18
  45. package/src/ui/collection_editor/EnumForm.tsx +118 -114
  46. package/src/ui/collection_editor/GetCodeDialog.tsx +1 -1
  47. package/src/ui/collection_editor/PropertyEditView.tsx +198 -142
  48. package/src/ui/collection_editor/PropertyFieldPreview.tsx +5 -1
  49. package/src/ui/collection_editor/PropertyTree.tsx +132 -113
  50. package/src/ui/collection_editor/SubcollectionsEditTab.tsx +18 -11
  51. package/src/ui/collection_editor/SwitchControl.tsx +39 -0
  52. package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +10 -2
  53. package/src/ui/collection_editor/properties/BlockPropertyField.tsx +2 -2
  54. package/src/ui/collection_editor/properties/BooleanPropertyField.tsx +13 -9
  55. package/src/ui/collection_editor/properties/CommonPropertyFields.tsx +11 -37
  56. package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +2 -2
  57. package/src/ui/collection_editor/properties/EnumPropertyField.tsx +3 -6
  58. package/src/ui/collection_editor/properties/MapPropertyField.tsx +2 -2
  59. package/src/ui/collection_editor/properties/NumberPropertyField.tsx +2 -2
  60. package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +11 -14
  61. package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +10 -9
  62. package/src/ui/collection_editor/properties/StoragePropertyField.tsx +15 -9
  63. package/src/ui/collection_editor/properties/StringPropertyField.tsx +2 -2
  64. package/src/ui/collection_editor/properties/UrlPropertyField.tsx +2 -2
  65. package/src/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +27 -18
  66. package/src/ui/collection_editor/properties/validation/ArrayPropertyValidation.tsx +2 -2
  67. package/src/ui/collection_editor/properties/validation/GeneralPropertyValidation.tsx +27 -16
  68. package/src/ui/collection_editor/properties/validation/NumberPropertyValidation.tsx +33 -18
  69. package/src/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +99 -80
  70. package/src/ui/collection_editor/util.ts +7 -0
  71. package/src/ui/collection_editor/utils/strings.ts +2 -1
@@ -7,7 +7,7 @@ import { PersistedCollection } from "./persisted_collection";
7
7
  */
8
8
  export interface CollectionEditorController {
9
9
  editCollection: (props: {
10
- path?: string;
10
+ id?: string;
11
11
  fullPath?: string;
12
12
  parentCollectionIds: string[];
13
13
  parentCollection?: PersistedCollection;
@@ -21,12 +21,13 @@ export interface CollectionEditorController {
21
21
  parentCollectionIds: string[];
22
22
  parentCollection?: PersistedCollection;
23
23
  redirect: boolean;
24
+ sourceClick?: string;
24
25
  }) => void;
25
26
  editProperty: (props: {
26
27
  propertyKey?: string;
27
28
  property?: Property;
28
29
  currentPropertiesOrder?: string[];
29
- editedCollectionPath: string;
30
+ editedCollectionId: string;
30
31
  parentCollectionIds: string[];
31
32
  collection: PersistedCollection;
32
33
  }) => void;
@@ -21,13 +21,13 @@ export interface CollectionsConfigController {
21
21
  export type UpdateCollectionParams<M extends Record<string, any>> = {
22
22
  id: string;
23
23
  collectionData: Partial<PersistedCollection<M>>;
24
- previousPath?: string;
24
+ previousId?: string;
25
25
  parentCollectionIds?: string[];
26
26
  };
27
27
  export type SaveCollectionParams<M extends Record<string, any>> = {
28
28
  id: string;
29
29
  collectionData: PersistedCollection<M>;
30
- previousPath?: string;
30
+ previousId?: string;
31
31
  parentCollectionIds?: string[];
32
32
  };
33
33
  export type SavePropertyParams = {
@@ -46,6 +46,6 @@ export type DeletePropertyParams = {
46
46
  parentCollectionIds?: string[];
47
47
  };
48
48
  export type DeleteCollectionParams = {
49
- path: string;
49
+ id: string;
50
50
  parentCollectionIds?: string[];
51
51
  };
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { CMSType, EntityCollection, User } from "@firecms/core";
2
+ import { EntityCollection, User } from "@firecms/core";
3
3
  import { CollectionsConfigController } from "../../types/config_controller";
4
4
  import { CollectionInference } from "../../types/collection_inference";
5
5
  import { PersistedCollection } from "../../types/persisted_collection";
@@ -11,7 +11,7 @@ export interface CollectionEditorDialogProps {
11
11
  path?: string;
12
12
  name?: string;
13
13
  };
14
- editedCollectionPath?: string;
14
+ editedCollectionId?: string;
15
15
  fullPath?: string;
16
16
  parentCollectionIds?: string[];
17
17
  handleClose: (collection?: EntityCollection) => void;
@@ -30,9 +30,7 @@ export interface CollectionEditorDialogProps {
30
30
  parentCollection?: PersistedCollection;
31
31
  }
32
32
  export declare function CollectionEditorDialog(props: CollectionEditorDialogProps): import("react/jsx-runtime").JSX.Element;
33
- export declare function CollectionEditorDialogInternal<M extends {
34
- [Key: string]: CMSType;
35
- }>({ isNewCollection, initialValues: initialValuesProp, configController, editedCollectionPath, parentCollectionIds, fullPath, collectionInference, handleClose, reservedGroups, extraView, handleCancel, setFormDirty, pathSuggestions, getUser, parentCollection, getData }: CollectionEditorDialogProps & {
33
+ export declare function CollectionEditor<M extends Record<string, any>>(props: CollectionEditorDialogProps & {
36
34
  handleCancel: () => void;
37
35
  setFormDirty: (dirty: boolean) => void;
38
36
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,11 @@
1
1
  import React from "react";
2
2
  import { EntityCollection } from "@firecms/core";
3
- export declare function CollectionEditorWelcomeView({ path, pathSuggestions, parentCollection, onContinue, collections }: {
3
+ export declare function CollectionEditorWelcomeView({ path, pathSuggestions, parentCollection, onContinue, existingCollectionPaths }: {
4
4
  path: string;
5
5
  pathSuggestions?: (path: string) => Promise<string[]>;
6
6
  parentCollection?: EntityCollection;
7
7
  onContinue: (importData?: object[]) => void;
8
- collections?: EntityCollection[];
8
+ existingCollectionPaths?: string[];
9
9
  }): import("react/jsx-runtime").JSX.Element;
10
10
  export declare function TemplateButton({ title, subtitle, icon, onClick }: {
11
11
  title: string;
@@ -1,12 +1,11 @@
1
1
  import React from "react";
2
- import { FormikErrors } from "formik";
3
2
  import { EntityCollection, PropertyConfig, User } from "@firecms/core";
4
3
  import { PersistedCollection } from "../../types/persisted_collection";
5
4
  type CollectionEditorFormProps = {
6
5
  showErrors: boolean;
7
6
  isNewCollection: boolean;
8
7
  propertyErrorsRef?: React.MutableRefObject<any>;
9
- onPropertyError: (propertyKey: string, namespace: string | undefined, error?: FormikErrors<any>) => void;
8
+ onPropertyError: (propertyKey: string, namespace: string | undefined, error?: Record<string, any>) => void;
10
9
  setDirty?: (dirty: boolean) => void;
11
10
  reservedGroups?: string[];
12
11
  extraIcon: React.ReactNode;
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import { EnumValueConfig } from "@firecms/core";
3
2
  type EnumFormProps = {
4
3
  enumValues: EnumValueConfig[];
@@ -9,5 +8,5 @@ type EnumFormProps = {
9
8
  allowDataInference?: boolean;
10
9
  getData?: () => Promise<string[]>;
11
10
  };
12
- export declare const EnumForm: React.NamedExoticComponent<EnumFormProps>;
11
+ export declare function EnumForm({ enumValues, onValuesChanged, onError, updateIds, disabled, allowDataInference, getData }: EnumFormProps): import("react/jsx-runtime").JSX.Element;
13
12
  export {};
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { FormikErrors, FormikProps } from "formik";
2
+ import { FormexController } from "../../form";
3
3
  import { Property, PropertyConfig } from "@firecms/core";
4
4
  export type PropertyWithId = Property & {
5
5
  id?: string;
@@ -22,13 +22,13 @@ export type PropertyFormProps = {
22
22
  onPropertyChanged?: (params: OnPropertyChangedParams) => void;
23
23
  onPropertyChangedImmediate?: boolean;
24
24
  onDelete?: (id?: string, namespace?: string) => void;
25
- onError?: (id: string, namespace?: string, error?: FormikErrors<any>) => void;
26
- initialErrors?: FormikErrors<any>;
27
- forceShowErrors?: boolean;
25
+ onError?: (id: string, namespace?: string, error?: Record<string, any>) => void;
26
+ initialErrors?: Record<string, any>;
28
27
  existingPropertyKeys?: string[];
28
+ forceShowErrors?: boolean;
29
29
  allowDataInference: boolean;
30
30
  getData?: () => Promise<object[]>;
31
- getHelpers?: (formikProps: FormikProps<PropertyWithId>) => void;
31
+ getController?: (formex: FormexController<PropertyWithId>) => void;
32
32
  propertyConfigs: Record<string, PropertyConfig>;
33
33
  collectionEditable: boolean;
34
34
  };
@@ -1,22 +1,23 @@
1
+ import React from "react";
1
2
  import { AdditionalFieldDelegate, CMSType, PropertiesOrBuilders, PropertyOrBuilder } from "@firecms/core";
2
3
  import { DraggableProvided } from "@hello-pangea/dnd";
3
- export declare function PropertyTree<M extends {
4
+ export declare const PropertyTree: React.MemoExoticComponent<(<M extends {
4
5
  [Key: string]: CMSType;
5
- }>({ namespace, selectedPropertyKey, onPropertyClick, properties, propertiesOrder: propertiesOrderProp, additionalFields, errors, onPropertyMove, onPropertyRemove, className, inferredPropertyKeys, collectionEditable, }: {
6
- namespace?: string;
7
- selectedPropertyKey?: string;
8
- onPropertyClick?: (propertyKey: string, namespace?: string) => void;
6
+ }>({ namespace, selectedPropertyKey, onPropertyClick, properties, propertiesOrder: propertiesOrderProp, additionalFields, errors, onPropertyMove, onPropertyRemove, className, inferredPropertyKeys, collectionEditable }: {
7
+ namespace?: string | undefined;
8
+ selectedPropertyKey?: string | undefined;
9
+ onPropertyClick?: ((propertyKey: string, namespace?: string) => void) | undefined;
9
10
  properties: PropertiesOrBuilders<M>;
10
- propertiesOrder?: string[];
11
- additionalFields?: AdditionalFieldDelegate<M>[];
11
+ propertiesOrder?: string[] | undefined;
12
+ additionalFields?: AdditionalFieldDelegate<M, import("@firecms/core").User>[] | undefined;
12
13
  errors: Record<string, any>;
13
- onPropertyMove?: (propertiesOrder: string[], namespace?: string) => void;
14
- onPropertyRemove?: (propertyKey: string, namespace?: string) => void;
15
- className?: string;
16
- inferredPropertyKeys?: string[];
14
+ onPropertyMove?: ((propertiesOrder: string[], namespace?: string) => void) | undefined;
15
+ onPropertyRemove?: ((propertyKey: string, namespace?: string) => void) | undefined;
16
+ className?: string | undefined;
17
+ inferredPropertyKeys?: string[] | undefined;
17
18
  collectionEditable: boolean;
18
- }): import("react/jsx-runtime").JSX.Element;
19
- export declare function PropertyTreeEntry({ propertyKey, namespace, propertyOrBuilder, additionalField, provided, selectedPropertyKey, errors, onPropertyClick, onPropertyMove, onPropertyRemove, inferredPropertyKeys, collectionEditable, }: {
19
+ }) => import("react/jsx-runtime").JSX.Element)>;
20
+ export declare function PropertyTreeEntry({ propertyKey, namespace, propertyOrBuilder, additionalField, provided, selectedPropertyKey, errors, onPropertyClick, onPropertyMove, onPropertyRemove, inferredPropertyKeys, collectionEditable }: {
20
21
  propertyKey: string;
21
22
  namespace?: string;
22
23
  propertyOrBuilder: PropertyOrBuilder;
@@ -0,0 +1,8 @@
1
+ import { FormexFieldProps } from "../../form";
2
+ export declare function SwitchControl({ field, form, label, tooltip, disabled, size, allowIndeterminate }: FormexFieldProps & {
3
+ label: string;
4
+ tooltip?: string;
5
+ disabled?: boolean;
6
+ size?: "small" | "medium";
7
+ allowIndeterminate?: boolean;
8
+ }): import("react/jsx-runtime").JSX.Element;
@@ -2,7 +2,6 @@ import React from "react";
2
2
  type CommonPropertyFieldsProps = {
3
3
  showErrors: boolean;
4
4
  disabledId: boolean;
5
- existingPropertyKeys?: string[];
6
5
  disabled: boolean;
7
6
  isNewProperty: boolean;
8
7
  autoUpdateId: boolean;
@@ -2,3 +2,4 @@ export declare function idToPropertiesPath(id: string): string;
2
2
  export declare function namespaceToPropertiesPath(namespace?: string): string;
3
3
  export declare function namespaceToPropertiesOrderPath(namespace?: string): string;
4
4
  export declare function getFullId(propertyKey: string, propertyNamespace?: string): string;
5
+ export declare function getFullIdPath(propertyKey: string, propertyNamespace?: string): string;
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@firecms/collection_editor",
3
3
  "type": "module",
4
- "version": "3.0.0-beta.2-pre.2",
4
+ "version": "3.0.0-beta.2-pre.3",
5
5
  "main": "./dist/index.umd.js",
6
6
  "module": "./dist/index.es.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "source": "src/index.ts",
9
9
  "dependencies": {
10
- "@firecms/data_import_export": "^3.0.0-beta.2-pre.2",
11
- "@firecms/schema_inference": "^3.0.0-beta.2-pre.2",
12
- "@firecms/ui": "^3.0.0-beta.2-pre.2",
10
+ "@firecms/data_import_export": "^3.0.0-beta.2-pre.3",
11
+ "@firecms/schema_inference": "^3.0.0-beta.2-pre.3",
12
+ "@firecms/ui": "^3.0.0-beta.2-pre.3",
13
13
  "json5": "^2.2.3",
14
14
  "prism-react-renderer": "^2.3.1"
15
15
  },
@@ -72,5 +72,5 @@
72
72
  "publishConfig": {
73
73
  "access": "public"
74
74
  },
75
- "gitHead": "f3f62fc3cbc4f0d9d1a26817a14cff06393b7c2b"
75
+ "gitHead": "c78c58643c73ba776dfbcb8315d1a99160bb607a"
76
76
  }
@@ -94,7 +94,7 @@ export const ConfigControllerProvider = React.memo(
94
94
  const [currentDialog, setCurrentDialog] = React.useState<{
95
95
  isNewCollection: boolean,
96
96
  parentCollection?: PersistedCollection,
97
- editedCollectionPath?: string,
97
+ editedCollectionId?: string,
98
98
  fullPath?: string,
99
99
  parentCollectionIds: string[],
100
100
  initialValues?: {
@@ -111,7 +111,7 @@ export const ConfigControllerProvider = React.memo(
111
111
  namespace?: string,
112
112
  parentCollection?: PersistedCollection,
113
113
  currentPropertiesOrder?: string[],
114
- editedCollectionPath: string,
114
+ editedCollectionId: string,
115
115
  fullPath?: string,
116
116
  parentCollectionIds: string[],
117
117
  collectionEditable: boolean;
@@ -124,20 +124,20 @@ export const ConfigControllerProvider = React.memo(
124
124
  }), []);
125
125
 
126
126
  const editCollection = useCallback(({
127
- path,
127
+ id,
128
128
  fullPath,
129
129
  parentCollectionIds,
130
130
  parentCollection
131
131
  }: {
132
- path?: string,
132
+ id?: string,
133
133
  fullPath?: string,
134
134
  parentCollectionIds: string[],
135
135
  parentCollection?: PersistedCollection
136
136
  }) => {
137
- console.debug("edit collection", path, fullPath, parentCollectionIds, parentCollection);
138
- onAnalyticsEvent?.("edit_collection", { path, fullPath });
137
+ console.debug("Edit collection", id, fullPath, parentCollectionIds, parentCollection);
138
+ onAnalyticsEvent?.("edit_collection", { id, fullPath });
139
139
  setCurrentDialog({
140
- editedCollectionPath: path,
140
+ editedCollectionId: id,
141
141
  fullPath,
142
142
  parentCollectionIds,
143
143
  isNewCollection: false,
@@ -149,7 +149,7 @@ export const ConfigControllerProvider = React.memo(
149
149
  const editProperty = useCallback(({
150
150
  propertyKey,
151
151
  property,
152
- editedCollectionPath,
152
+ editedCollectionId,
153
153
  currentPropertiesOrder,
154
154
  parentCollectionIds,
155
155
  collection
@@ -157,12 +157,12 @@ export const ConfigControllerProvider = React.memo(
157
157
  propertyKey?: string,
158
158
  property?: Property,
159
159
  currentPropertiesOrder?: string[],
160
- editedCollectionPath: string,
160
+ editedCollectionId: string,
161
161
  parentCollectionIds: string[],
162
162
  collection: PersistedCollection,
163
163
  }) => {
164
- console.debug("edit property", propertyKey, property, editedCollectionPath, currentPropertiesOrder, parentCollectionIds, collection);
165
- onAnalyticsEvent?.("edit_property", { propertyKey, editedCollectionPath });
164
+ console.debug("edit property", propertyKey, property, editedCollectionId, currentPropertiesOrder, parentCollectionIds, collection);
165
+ onAnalyticsEvent?.("edit_property", { propertyKey, editedCollectionId });
166
166
  // namespace is all the path until the last dot
167
167
  const namespace = propertyKey && propertyKey.includes(".")
168
168
  ? propertyKey.substring(0, propertyKey.lastIndexOf("."))
@@ -175,7 +175,7 @@ export const ConfigControllerProvider = React.memo(
175
175
  property,
176
176
  namespace,
177
177
  currentPropertiesOrder,
178
- editedCollectionPath,
178
+ editedCollectionId: editedCollectionId,
179
179
  parentCollectionIds,
180
180
  collectionEditable: collection?.editable ?? false
181
181
  });
@@ -185,7 +185,8 @@ export const ConfigControllerProvider = React.memo(
185
185
  parentCollectionIds,
186
186
  parentCollection,
187
187
  initialValues,
188
- redirect
188
+ redirect,
189
+ sourceClick
189
190
  }: {
190
191
  parentCollectionIds: string[],
191
192
  parentCollection?: PersistedCollection
@@ -194,10 +195,11 @@ export const ConfigControllerProvider = React.memo(
194
195
  path?: string,
195
196
  name?: string
196
197
  },
197
- redirect: boolean
198
+ redirect: boolean,
199
+ sourceClick?: string
198
200
  }) => {
199
- console.debug("create collection", parentCollectionIds, parentCollection, initialValues, redirect);
200
- onAnalyticsEvent?.("create_collection", { parentCollectionIds, parentCollection, initialValues, redirect });
201
+ console.debug("Create collection", { parentCollectionIds, parentCollection, initialValues, redirect, sourceClick });
202
+ onAnalyticsEvent?.("create_collection", { parentCollectionIds, parentCollection, initialValues, redirect, sourceClick });
201
203
  setCurrentDialog({
202
204
  isNewCollection: true,
203
205
  parentCollectionIds,
@@ -260,10 +262,10 @@ export const ConfigControllerProvider = React.memo(
260
262
  autoOpenTypeSelect={!currentPropertyDialog ? false : !currentPropertyDialog?.propertyKey}
261
263
  inArray={false}
262
264
  collectionEditable={currentPropertyDialog?.collectionEditable ?? false}
263
- getData={getData && currentPropertyDialog?.editedCollectionPath
265
+ getData={getData && currentPropertyDialog?.editedCollectionId
264
266
  ? () => {
265
- console.debug("get data for property", currentPropertyDialog?.editedCollectionPath);
266
- const resolvedPath = navigation.resolveAliasesFrom(currentPropertyDialog.editedCollectionPath!)
267
+ console.debug("get data for property", currentPropertyDialog?.editedCollectionId);
268
+ const resolvedPath = navigation.resolveAliasesFrom(currentPropertyDialog.editedCollectionId!)
267
269
  return getData(resolvedPath, []);
268
270
  }
269
271
  : undefined}
@@ -275,7 +277,7 @@ export const ConfigControllerProvider = React.memo(
275
277
  if (!id) return;
276
278
  const newProperty = !(currentPropertyDialog.propertyKey);
277
279
  return collectionConfigController.saveProperty({
278
- path: currentPropertyDialog?.editedCollectionPath,
280
+ path: currentPropertyDialog?.editedCollectionId,
279
281
  property,
280
282
  propertyKey: id,
281
283
  newPropertiesOrder: newProperty && currentPropertyDialog.currentPropertiesOrder ? [...currentPropertyDialog.currentPropertiesOrder, id] : undefined,
@@ -296,7 +298,7 @@ export const ConfigControllerProvider = React.memo(
296
298
  if (!currentPropertyDialog?.propertyKey) return;
297
299
  const newPropertiesOrder = currentPropertyDialog?.currentPropertiesOrder?.filter(p => p !== currentPropertyDialog?.propertyKey);
298
300
  return collectionConfigController.deleteProperty({
299
- path: currentPropertyDialog?.editedCollectionPath,
301
+ path: currentPropertyDialog?.editedCollectionId,
300
302
  propertyKey: currentPropertyDialog?.propertyKey,
301
303
  namespace: currentPropertyDialog?.namespace,
302
304
  newPropertiesOrder,
@@ -0,0 +1,162 @@
1
+ import * as React from "react";
2
+ import { useFormex } from "./Formex";
3
+ import { getIn, isFunction, isObject } from "./utils";
4
+ import { FormexController } from "./types";
5
+
6
+ export interface FieldInputProps<Value> {
7
+ /** Value of the field */
8
+ value: Value;
9
+ /** Name of the field */
10
+ name: string;
11
+ /** Multiple select? */
12
+ multiple?: boolean;
13
+ /** Is the field checked? */
14
+ checked?: boolean;
15
+ /** Change event handler */
16
+ onChange: (event: React.SyntheticEvent) => void,
17
+ /** Blur event handler */
18
+ onBlur: (event: React.FocusEvent) => void,
19
+ }
20
+
21
+ export interface FormexFieldProps<Value = any, FormValues extends object = any> {
22
+ field: FieldInputProps<Value>;
23
+ form: FormexController<FormValues>;
24
+ }
25
+
26
+ export type FieldValidator = (
27
+ value: any
28
+ ) => string | void | Promise<string | void>;
29
+
30
+ export interface FieldConfig<V = any, C extends React.ElementType | undefined = undefined> {
31
+
32
+ /**
33
+ * Component to render. Can either be a string e.g. 'select', 'input', or 'textarea', or a component.
34
+ */
35
+ as?:
36
+ | C
37
+ | string
38
+ | React.ForwardRefExoticComponent<any>;
39
+
40
+ /**
41
+ * Children render function <Field name>{props => ...}</Field>)
42
+ */
43
+ children?: ((props: FormexFieldProps<V>) => React.ReactNode) | React.ReactNode;
44
+
45
+ /**
46
+ * Validate a single field value independently
47
+ */
48
+ // validate?: FieldValidator;
49
+
50
+ /**
51
+ * Used for 'select' and related input types.
52
+ */
53
+ multiple?: boolean;
54
+
55
+ /**
56
+ * Field name
57
+ */
58
+ name: string;
59
+
60
+ /** HTML input type */
61
+ type?: string;
62
+
63
+ /** Field value */
64
+ value?: any;
65
+
66
+ /** Inner ref */
67
+ innerRef?: (instance: any) => void;
68
+
69
+ }
70
+
71
+ export type FieldProps<T, C extends React.ElementType | undefined> = {
72
+ as?: C;
73
+ } & (C extends React.ElementType ? (React.ComponentProps<C> & FieldConfig<T, C>) : FieldConfig<T, C>);
74
+
75
+ export function Field<T, C extends React.ElementType | undefined = undefined>({
76
+ validate,
77
+ name,
78
+ children,
79
+ as: is, // `as` is reserved in typescript lol
80
+ // component,
81
+ className,
82
+ ...props
83
+ }: FieldProps<T, C>) {
84
+ const formex = useFormex();
85
+
86
+ const field = getFieldProps({ name, ...props }, formex);
87
+
88
+ if (isFunction(children)) {
89
+ return children({ field, form: formex });
90
+ }
91
+
92
+ // if (component) {
93
+ // if (typeof component === "string") {
94
+ // const { innerRef, ...rest } = props;
95
+ // return React.createElement(
96
+ // component,
97
+ // { ref: innerRef, ...field, ...rest, className },
98
+ // children
99
+ // );
100
+ // }
101
+ // return React.createElement(
102
+ // component,
103
+ // { field, form: formex, ...props, className },
104
+ // children
105
+ // );
106
+ // }
107
+
108
+ // default to input here so we can check for both `as` and `children` above
109
+ const asElement = is || "input";
110
+
111
+ if (typeof asElement === "string") {
112
+ const { innerRef, ...rest } = props;
113
+ return React.createElement(
114
+ asElement,
115
+ { ref: innerRef, ...field, ...rest, className },
116
+ children
117
+ );
118
+ }
119
+
120
+ return React.createElement(asElement, { ...field, ...props, className }, children);
121
+ }
122
+
123
+ const getFieldProps = (nameOrOptions: string | FieldConfig<any>, formex:FormexController<any>): FieldInputProps<any> => {
124
+ const isAnObject = isObject(nameOrOptions);
125
+ const name = isAnObject
126
+ ? (nameOrOptions as FieldConfig<any>).name
127
+ : nameOrOptions;
128
+ const valueState = getIn(formex.values, name);
129
+
130
+ const field: FieldInputProps<any> = {
131
+ name,
132
+ value: valueState,
133
+ onChange: formex.handleChange,
134
+ onBlur: formex.handleBlur,
135
+ };
136
+ if (isAnObject) {
137
+ const {
138
+ type,
139
+ value: valueProp, // value is special for checkboxes
140
+ as: is,
141
+ multiple,
142
+ } = nameOrOptions as FieldConfig<any>;
143
+
144
+ if (type === "checkbox") {
145
+ if (valueProp === undefined) {
146
+ field.checked = !!valueState;
147
+ } else {
148
+ field.checked = !!(
149
+ Array.isArray(valueState) && ~valueState.indexOf(valueProp)
150
+ );
151
+ field.value = valueProp;
152
+ }
153
+ } else if (type === "radio") {
154
+ field.checked = valueState === valueProp;
155
+ field.value = valueProp;
156
+ } else if (is === "select" && multiple) {
157
+ field.value = field.value || [];
158
+ field.multiple = true;
159
+ }
160
+ }
161
+ return field;
162
+ };
@@ -0,0 +1,8 @@
1
+ import React, { useContext } from "react";
2
+ import { FormexController } from "./types";
3
+
4
+ const FormexContext = React.createContext<FormexController<any>>({} as any);
5
+
6
+ export const useFormex = <T extends object>() => useContext<FormexController<T>>(FormexContext);
7
+
8
+ export const Formex = FormexContext.Provider;