@firecms/collection_editor 3.0.0-3.0.0-beta.4.pre.1.0

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 (140) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/ConfigControllerProvider.d.ts +37 -0
  4. package/dist/index.d.ts +11 -0
  5. package/dist/index.es.js +5454 -0
  6. package/dist/index.es.js.map +1 -0
  7. package/dist/index.umd.js +4 -0
  8. package/dist/index.umd.js.map +1 -0
  9. package/dist/types/collection_editor_controller.d.ts +36 -0
  10. package/dist/types/collection_inference.d.ts +2 -0
  11. package/dist/types/config_controller.d.ts +51 -0
  12. package/dist/types/config_permissions.d.ts +19 -0
  13. package/dist/types/persisted_collection.d.ts +6 -0
  14. package/dist/ui/CollectionViewHeaderAction.d.ts +10 -0
  15. package/dist/ui/EditorCollectionAction.d.ts +2 -0
  16. package/dist/ui/HomePageEditorCollectionAction.d.ts +2 -0
  17. package/dist/ui/MissingReferenceWidget.d.ts +3 -0
  18. package/dist/ui/NewCollectionButton.d.ts +1 -0
  19. package/dist/ui/NewCollectionCard.d.ts +2 -0
  20. package/dist/ui/PropertyAddColumnComponent.d.ts +6 -0
  21. package/dist/ui/RootCollectionSuggestions.d.ts +3 -0
  22. package/dist/ui/collection_editor/CollectionDetailsForm.d.ts +10 -0
  23. package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +36 -0
  24. package/dist/ui/collection_editor/CollectionEditorWelcomeView.d.ts +15 -0
  25. package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +19 -0
  26. package/dist/ui/collection_editor/CollectionYupValidation.d.ts +14 -0
  27. package/dist/ui/collection_editor/EntityCustomViewsSelectDialog.d.ts +4 -0
  28. package/dist/ui/collection_editor/EnumForm.d.ts +12 -0
  29. package/dist/ui/collection_editor/GetCodeDialog.d.ts +5 -0
  30. package/dist/ui/collection_editor/PropertyEditView.d.ts +40 -0
  31. package/dist/ui/collection_editor/PropertyFieldPreview.d.ts +15 -0
  32. package/dist/ui/collection_editor/PropertySelectItem.d.ts +8 -0
  33. package/dist/ui/collection_editor/PropertyTree.d.ts +33 -0
  34. package/dist/ui/collection_editor/SubcollectionsEditTab.d.ts +12 -0
  35. package/dist/ui/collection_editor/SwitchControl.d.ts +8 -0
  36. package/dist/ui/collection_editor/UnsavedChangesDialog.d.ts +9 -0
  37. package/dist/ui/collection_editor/import/CollectionEditorImportDataPreview.d.ts +7 -0
  38. package/dist/ui/collection_editor/import/CollectionEditorImportMapping.d.ts +7 -0
  39. package/dist/ui/collection_editor/import/clean_import_data.d.ts +7 -0
  40. package/dist/ui/collection_editor/properties/BlockPropertyField.d.ts +8 -0
  41. package/dist/ui/collection_editor/properties/BooleanPropertyField.d.ts +3 -0
  42. package/dist/ui/collection_editor/properties/CommonPropertyFields.d.ts +10 -0
  43. package/dist/ui/collection_editor/properties/DateTimePropertyField.d.ts +3 -0
  44. package/dist/ui/collection_editor/properties/EnumPropertyField.d.ts +8 -0
  45. package/dist/ui/collection_editor/properties/KeyValuePropertyField.d.ts +3 -0
  46. package/dist/ui/collection_editor/properties/MapPropertyField.d.ts +8 -0
  47. package/dist/ui/collection_editor/properties/NumberPropertyField.d.ts +3 -0
  48. package/dist/ui/collection_editor/properties/ReferencePropertyField.d.ts +13 -0
  49. package/dist/ui/collection_editor/properties/RepeatPropertyField.d.ts +10 -0
  50. package/dist/ui/collection_editor/properties/StoragePropertyField.d.ts +5 -0
  51. package/dist/ui/collection_editor/properties/StringPropertyField.d.ts +5 -0
  52. package/dist/ui/collection_editor/properties/UrlPropertyField.d.ts +4 -0
  53. package/dist/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.d.ts +3 -0
  54. package/dist/ui/collection_editor/properties/validation/ArrayPropertyValidation.d.ts +5 -0
  55. package/dist/ui/collection_editor/properties/validation/GeneralPropertyValidation.d.ts +4 -0
  56. package/dist/ui/collection_editor/properties/validation/NumberPropertyValidation.d.ts +3 -0
  57. package/dist/ui/collection_editor/properties/validation/StringPropertyValidation.d.ts +11 -0
  58. package/dist/ui/collection_editor/properties/validation/ValidationPanel.d.ts +2 -0
  59. package/dist/ui/collection_editor/templates/blog_template.d.ts +2 -0
  60. package/dist/ui/collection_editor/templates/pages_template.d.ts +2 -0
  61. package/dist/ui/collection_editor/templates/products_template.d.ts +2 -0
  62. package/dist/ui/collection_editor/templates/users_template.d.ts +2 -0
  63. package/dist/ui/collection_editor/util.d.ts +5 -0
  64. package/dist/ui/collection_editor/utils/strings.d.ts +1 -0
  65. package/dist/ui/collection_editor/utils/supported_fields.d.ts +3 -0
  66. package/dist/ui/collection_editor/utils/update_property_for_widget.d.ts +2 -0
  67. package/dist/ui/collection_editor/utils/useTraceUpdate.d.ts +1 -0
  68. package/dist/useCollectionEditorController.d.ts +6 -0
  69. package/dist/useCollectionEditorPlugin.d.ts +49 -0
  70. package/dist/useCollectionsConfigController.d.ts +6 -0
  71. package/dist/utils/arrays.d.ts +1 -0
  72. package/dist/utils/entities.d.ts +3 -0
  73. package/package.json +85 -0
  74. package/src/ConfigControllerProvider.tsx +338 -0
  75. package/src/index.ts +35 -0
  76. package/src/types/collection_editor_controller.tsx +43 -0
  77. package/src/types/collection_inference.ts +3 -0
  78. package/src/types/config_controller.tsx +60 -0
  79. package/src/types/config_permissions.ts +20 -0
  80. package/src/types/persisted_collection.ts +9 -0
  81. package/src/ui/CollectionViewHeaderAction.tsx +43 -0
  82. package/src/ui/EditorCollectionAction.tsx +109 -0
  83. package/src/ui/HomePageEditorCollectionAction.tsx +84 -0
  84. package/src/ui/MissingReferenceWidget.tsx +37 -0
  85. package/src/ui/NewCollectionButton.tsx +16 -0
  86. package/src/ui/NewCollectionCard.tsx +48 -0
  87. package/src/ui/PropertyAddColumnComponent.tsx +42 -0
  88. package/src/ui/RootCollectionSuggestions.tsx +63 -0
  89. package/src/ui/collection_editor/CollectionDetailsForm.tsx +365 -0
  90. package/src/ui/collection_editor/CollectionEditorDialog.tsx +801 -0
  91. package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +213 -0
  92. package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +506 -0
  93. package/src/ui/collection_editor/CollectionYupValidation.tsx +7 -0
  94. package/src/ui/collection_editor/EntityCustomViewsSelectDialog.tsx +37 -0
  95. package/src/ui/collection_editor/EnumForm.tsx +357 -0
  96. package/src/ui/collection_editor/GetCodeDialog.tsx +110 -0
  97. package/src/ui/collection_editor/PropertyEditView.tsx +615 -0
  98. package/src/ui/collection_editor/PropertyFieldPreview.tsx +207 -0
  99. package/src/ui/collection_editor/PropertySelectItem.tsx +32 -0
  100. package/src/ui/collection_editor/PropertyTree.tsx +252 -0
  101. package/src/ui/collection_editor/SubcollectionsEditTab.tsx +262 -0
  102. package/src/ui/collection_editor/SwitchControl.tsx +39 -0
  103. package/src/ui/collection_editor/UnsavedChangesDialog.tsx +47 -0
  104. package/src/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +37 -0
  105. package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +268 -0
  106. package/src/ui/collection_editor/import/clean_import_data.ts +53 -0
  107. package/src/ui/collection_editor/properties/BlockPropertyField.tsx +138 -0
  108. package/src/ui/collection_editor/properties/BooleanPropertyField.tsx +40 -0
  109. package/src/ui/collection_editor/properties/CommonPropertyFields.tsx +110 -0
  110. package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +86 -0
  111. package/src/ui/collection_editor/properties/EnumPropertyField.tsx +114 -0
  112. package/src/ui/collection_editor/properties/KeyValuePropertyField.tsx +20 -0
  113. package/src/ui/collection_editor/properties/MapPropertyField.tsx +150 -0
  114. package/src/ui/collection_editor/properties/NumberPropertyField.tsx +38 -0
  115. package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +160 -0
  116. package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +109 -0
  117. package/src/ui/collection_editor/properties/StoragePropertyField.tsx +200 -0
  118. package/src/ui/collection_editor/properties/StringPropertyField.tsx +79 -0
  119. package/src/ui/collection_editor/properties/UrlPropertyField.tsx +89 -0
  120. package/src/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +45 -0
  121. package/src/ui/collection_editor/properties/validation/ArrayPropertyValidation.tsx +50 -0
  122. package/src/ui/collection_editor/properties/validation/GeneralPropertyValidation.tsx +61 -0
  123. package/src/ui/collection_editor/properties/validation/NumberPropertyValidation.tsx +115 -0
  124. package/src/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +150 -0
  125. package/src/ui/collection_editor/properties/validation/ValidationPanel.tsx +28 -0
  126. package/src/ui/collection_editor/templates/blog_template.ts +115 -0
  127. package/src/ui/collection_editor/templates/pages_template.ts +188 -0
  128. package/src/ui/collection_editor/templates/products_template.ts +88 -0
  129. package/src/ui/collection_editor/templates/users_template.ts +42 -0
  130. package/src/ui/collection_editor/util.ts +28 -0
  131. package/src/ui/collection_editor/utils/strings.ts +9 -0
  132. package/src/ui/collection_editor/utils/supported_fields.tsx +29 -0
  133. package/src/ui/collection_editor/utils/update_property_for_widget.ts +271 -0
  134. package/src/ui/collection_editor/utils/useTraceUpdate.tsx +23 -0
  135. package/src/useCollectionEditorController.tsx +9 -0
  136. package/src/useCollectionEditorPlugin.tsx +154 -0
  137. package/src/useCollectionsConfigController.tsx +9 -0
  138. package/src/utils/arrays.ts +3 -0
  139. package/src/utils/entities.ts +38 -0
  140. package/src/vite-env.d.ts +1 -0
@@ -0,0 +1,79 @@
1
+ import React from "react";
2
+ import { StringPropertyValidation } from "./validation/StringPropertyValidation";
3
+ import { ValidationPanel } from "./validation/ValidationPanel";
4
+ import { getIn, useFormex } from "@firecms/formex";
5
+
6
+ import { TextField } from "@firecms/ui";
7
+
8
+ export function StringPropertyField({
9
+ widgetId,
10
+ disabled,
11
+ showErrors
12
+ }: {
13
+ widgetId: "text_field" | "multiline" | "markdown" | "email";
14
+ disabled: boolean;
15
+ showErrors: boolean;
16
+ }) {
17
+
18
+ const { values, setFieldValue } = useFormex();
19
+
20
+ return (
21
+ <>
22
+ <div className={"col-span-12"}>
23
+
24
+ <ValidationPanel>
25
+
26
+ {widgetId === "text_field" &&
27
+ <StringPropertyValidation disabled={disabled}
28
+ length={true}
29
+ lowercase={true}
30
+ matches={true}
31
+ max={true}
32
+ min={true}
33
+ trim={true}
34
+ uppercase={true}
35
+ showErrors={showErrors}/>}
36
+ {widgetId === "multiline" &&
37
+ <StringPropertyValidation disabled={disabled}
38
+ length={true}
39
+ lowercase={true}
40
+ max={true}
41
+ min={true}
42
+ trim={true}
43
+ uppercase={true}
44
+ showErrors={showErrors}/>}
45
+ {widgetId === "markdown" &&
46
+ <StringPropertyValidation disabled={disabled}
47
+ length={true}
48
+ lowercase={true}
49
+ max={true}
50
+ min={true}
51
+ trim={true}
52
+ uppercase={true}
53
+ showErrors={showErrors}/>}
54
+
55
+ {widgetId === "email" &&
56
+ <StringPropertyValidation disabled={disabled}
57
+ max={true}
58
+ min={true}
59
+ trim={true}
60
+ showErrors={showErrors}/>}
61
+
62
+ </ValidationPanel>
63
+
64
+ </div>
65
+
66
+ <div className={"col-span-12"}>
67
+
68
+ <TextField name={"defaultValue"}
69
+ disabled={disabled}
70
+ onChange={(e: any) => {
71
+ setFieldValue("defaultValue", e.target.value === "" ? undefined : e.target.value);
72
+ }}
73
+ label={"Default value"}
74
+ value={getIn(values, "defaultValue") ?? ""}/>
75
+
76
+ </div>
77
+ </>
78
+ );
79
+ }
@@ -0,0 +1,89 @@
1
+ import React from "react";
2
+ import { StringPropertyValidation } from "./validation/StringPropertyValidation";
3
+ import { ValidationPanel } from "./validation/ValidationPanel";
4
+ import { getIn, useFormex } from "@firecms/formex";
5
+
6
+ import { Select, SelectItem, TextField } from "@firecms/ui";
7
+
8
+ export function UrlPropertyField({
9
+ disabled,
10
+ showErrors
11
+ }: {
12
+ disabled: boolean;
13
+ showErrors: boolean;
14
+ }) {
15
+
16
+ const { values, setFieldValue } = useFormex();
17
+
18
+ const urlValue = getIn(values, "url");
19
+
20
+ return (
21
+ <>
22
+ <div className={"col-span-12"}>
23
+
24
+ <Select
25
+ disabled={disabled}
26
+ position={"item-aligned"}
27
+ onValueChange={(value: string) => {
28
+ if (value === "[NONE]")
29
+ setFieldValue("url", true);
30
+ else
31
+ setFieldValue("url", value);
32
+ }}
33
+ label={"Preview type"}
34
+ renderValue={(value: string) => {
35
+ switch (value) {
36
+ case "image":
37
+ return "Image";
38
+ case "video":
39
+ return "Video";
40
+ case "audio":
41
+ return "Audio";
42
+ default:
43
+ return "Display URL";
44
+ }
45
+ }}
46
+ value={urlValue ?? "[NONE]"}>
47
+ <SelectItem value={"[NONE]"}>
48
+ Display URL
49
+ </SelectItem>
50
+ <SelectItem value={"image"}>
51
+ Image
52
+ </SelectItem>
53
+ <SelectItem value={"video"}>
54
+ Video
55
+ </SelectItem>
56
+ <SelectItem value={"audio"}>
57
+ Audio
58
+ </SelectItem>
59
+ </Select>
60
+ </div>
61
+
62
+ <div className={"col-span-12"}>
63
+
64
+ <ValidationPanel>
65
+
66
+ <StringPropertyValidation disabled={disabled}
67
+ max={true}
68
+ min={true}
69
+ trim={true}
70
+ showErrors={showErrors}/>
71
+
72
+ </ValidationPanel>
73
+
74
+ </div>
75
+
76
+ <div className={"col-span-12"}>
77
+
78
+ <TextField name={"defaultValue"}
79
+ disabled={disabled}
80
+ onChange={(e: any) => {
81
+ setFieldValue("defaultValue", e.target.value === "" ? undefined : e.target.value);
82
+ }}
83
+ label={"Default value"}
84
+ value={getIn(values, "defaultValue") ?? ""}/>
85
+
86
+ </div>
87
+ </>
88
+ );
89
+ }
@@ -0,0 +1,45 @@
1
+ import React from "react";
2
+
3
+ import { Field, FormexFieldProps } from "@firecms/formex";
4
+ import { SwitchControl } from "../../SwitchControl";
5
+
6
+ export function AdvancedPropertyValidation({ disabled }: {
7
+ disabled: boolean
8
+ }) {
9
+
10
+ const columnWidth = "columnWidth";
11
+ const hideFromCollection = "hideFromCollection";
12
+ const readOnly = "readOnly";
13
+
14
+ return (
15
+
16
+ <div className={"grid grid-cols-12 gap-2"}>
17
+ <div className={"col-span-12"}>
18
+ <Field type="checkbox" name={hideFromCollection}>
19
+ {({ field, form }: FormexFieldProps) => {
20
+ return <SwitchControl
21
+ label={"Hide from collection"}
22
+ disabled={disabled}
23
+ form={form}
24
+ tooltip={"Hide this field from the collection view. It will still be visible in the form view"}
25
+ field={field}/>
26
+ }}
27
+ </Field>
28
+ </div>
29
+
30
+ <div className={"col-span-12"}>
31
+ <Field name={readOnly}
32
+ type="checkbox">
33
+ {({ field, form }: FormexFieldProps) => {
34
+ return <SwitchControl
35
+ label={"Read only"}
36
+ disabled={disabled}
37
+ tooltip={"Is this a read only field. Display only as a preview"}
38
+ form={form}
39
+ field={field}/>
40
+ }}
41
+ </Field>
42
+ </div>
43
+ </div>
44
+ );
45
+ }
@@ -0,0 +1,50 @@
1
+ import React from "react";
2
+
3
+ import { getIn, useFormex } from "@firecms/formex";
4
+ import { DebouncedTextField } from "@firecms/ui";
5
+ import { GeneralPropertyValidation } from "./GeneralPropertyValidation";
6
+
7
+ export function ArrayPropertyValidation({
8
+ max = true,
9
+ min = true,
10
+ disabled
11
+ }: {
12
+ min?: boolean;
13
+ max?: boolean;
14
+ disabled: boolean;
15
+ }) {
16
+
17
+ const {
18
+ values,
19
+ handleChange
20
+ } = useFormex();
21
+
22
+ const validationMin = "validation.min";
23
+ const validationMax = "validation.max";
24
+
25
+ return (
26
+ <div className={"grid grid-cols-12 gap-2"}>
27
+
28
+ <GeneralPropertyValidation disabled={disabled}/>
29
+
30
+ {min && <div className={"col-span-6"}>
31
+ <DebouncedTextField value={getIn(values, validationMin)}
32
+ disabled={disabled}
33
+ label={"Min length"}
34
+ name={validationMin}
35
+ type="number"
36
+ size="small"
37
+ onChange={handleChange}/>
38
+ </div>}
39
+ {max && <div className={"col-span-6"}>
40
+ <DebouncedTextField value={getIn(values, validationMax)}
41
+ disabled={disabled}
42
+ label={"Max length"}
43
+ name={validationMax}
44
+ type="number"
45
+ size="small"
46
+ onChange={handleChange}/>
47
+ </div>}
48
+ </div>
49
+ );
50
+ }
@@ -0,0 +1,61 @@
1
+ import React from "react";
2
+
3
+ import { Field, FormexFieldProps, getIn, useFormex } from "@firecms/formex";
4
+ import { DebouncedTextField } from "@firecms/ui";
5
+ import { SwitchControl } from "../../SwitchControl";
6
+
7
+ export function GeneralPropertyValidation({ disabled }: {
8
+ required?: boolean;
9
+ disabled: boolean;
10
+ }) {
11
+
12
+ const { values, handleChange } = useFormex();
13
+
14
+ const validationRequired = "validation.required";
15
+ const validationRequiredMessage = "validation.requiredMessage";
16
+ const validationUnique = "validation.unique";
17
+ const validationUniqueInArray = "validation.uniqueInArray";
18
+
19
+ return (
20
+ <>
21
+ <div className={"col-span-6"}>
22
+ <Field name={validationRequired}
23
+ type="checkbox">
24
+ {({ field, form }: FormexFieldProps) => {
25
+ return <SwitchControl
26
+ disabled={disabled}
27
+ label={"Required"}
28
+ tooltip={"You won't be able to save this entity if this value is not set"}
29
+ form={form}
30
+ field={field}/>
31
+ }}
32
+ </Field>
33
+ </div>
34
+
35
+ <div className={"col-span-6"}>
36
+
37
+ <Field name={validationUnique}
38
+ type="checkbox">
39
+ {({ field, form }: FormexFieldProps) => {
40
+ return <SwitchControl
41
+ disabled={disabled}
42
+ label={"Unique"}
43
+ tooltip={"There cannot be multiple entities with the same value"}
44
+ form={form}
45
+ field={field}/>
46
+ }}
47
+ </Field>
48
+ </div>
49
+
50
+ {getIn(values, validationRequired) && <div className={"col-span-12"}>
51
+ <DebouncedTextField
52
+ disabled={disabled}
53
+ value={getIn(values, validationRequiredMessage)}
54
+ label={"Required message"}
55
+ name={validationRequiredMessage}
56
+ size="small"
57
+ onChange={handleChange}/>
58
+ </div>}
59
+ </>
60
+ );
61
+ }
@@ -0,0 +1,115 @@
1
+ import React from "react";
2
+
3
+ import { Field, FormexFieldProps, getIn, useFormex } from "@firecms/formex";
4
+ import { DebouncedTextField } from "@firecms/ui";
5
+ import { GeneralPropertyValidation } from "./GeneralPropertyValidation";
6
+ import { SwitchControl } from "../../SwitchControl";
7
+
8
+ export function NumberPropertyValidation({ disabled }: {
9
+ disabled: boolean;
10
+ }) {
11
+
12
+ const {
13
+ values,
14
+ handleChange
15
+ } = useFormex();
16
+
17
+ const validationMin = "validation.min";
18
+ const validationMax = "validation.max";
19
+ const validationLessThan = "validation.lessThan";
20
+ const validationMoreThan = "validation.moreThan";
21
+ const validationPositive = "validation.positive";
22
+ const validationNegative = "validation.negative";
23
+ const validationInteger = "validation.integer";
24
+
25
+ return (
26
+
27
+ <div className={"grid grid-cols-12 gap-2"}>
28
+ <GeneralPropertyValidation disabled={disabled}/>
29
+
30
+
31
+ <div className={"col-span-6"}>
32
+ <DebouncedTextField value={getIn(values, validationMin)}
33
+ label={"Min value"}
34
+ name={validationMin}
35
+ type="number"
36
+ size="small"
37
+ disabled={disabled}
38
+ onChange={handleChange}/>
39
+ </div>
40
+
41
+ <div className={"col-span-6"}>
42
+ <DebouncedTextField value={getIn(values, validationMax)}
43
+ label={"Max value"}
44
+ name={validationMax}
45
+ type="number"
46
+ size="small"
47
+
48
+ disabled={disabled}
49
+ onChange={handleChange}/>
50
+ </div>
51
+
52
+
53
+ <div className={"col-span-6"}>
54
+ <DebouncedTextField
55
+ value={getIn(values, validationLessThan)}
56
+ label={"Less than"}
57
+ name={validationLessThan}
58
+ type="number"
59
+ size="small"
60
+
61
+ disabled={disabled}
62
+ onChange={handleChange}/>
63
+ </div>
64
+
65
+ <div className={"col-span-6"}>
66
+ <DebouncedTextField
67
+ value={getIn(values, validationMoreThan)}
68
+ label={"More than"}
69
+ name={validationMoreThan}
70
+ type="number"
71
+ size="small"
72
+
73
+ disabled={disabled}
74
+ onChange={handleChange}/>
75
+ </div>
76
+
77
+ <div className={"col-span-4"}>
78
+ <Field name={validationPositive}
79
+ type="checkbox">
80
+ {({ field, form }: FormexFieldProps) => {
81
+ return <SwitchControl
82
+ label={"Positive value"}
83
+ disabled={disabled}
84
+ form={form}
85
+ field={field}/>
86
+ }}
87
+ </Field>
88
+ </div>
89
+ <div className={"col-span-4"}>
90
+ <Field name={validationNegative}
91
+ type="checkbox">
92
+ {({ field, form }: FormexFieldProps) => {
93
+ return <SwitchControl
94
+ label={"Negative value"}
95
+ disabled={disabled}
96
+ form={form}
97
+ field={field}/>
98
+ }}
99
+ </Field>
100
+ </div>
101
+ <div className={"col-span-4"}>
102
+ <Field name={validationInteger}
103
+ type="checkbox">
104
+ {({ field, form }: FormexFieldProps) => {
105
+ return <SwitchControl
106
+ label={"Integer value"}
107
+ disabled={disabled}
108
+ form={form}
109
+ field={field}/>
110
+ }}
111
+ </Field>
112
+ </div>
113
+ </div>
114
+ );
115
+ }
@@ -0,0 +1,150 @@
1
+ import React from "react";
2
+
3
+ import { Field, FormexFieldProps, getIn, useFormex } from "@firecms/formex";
4
+ import { FieldCaption, serializeRegExp } from "@firecms/core";
5
+ import { DebouncedTextField, } from "@firecms/ui";
6
+ import { GeneralPropertyValidation } from "./GeneralPropertyValidation";
7
+ import { SwitchControl } from "../../SwitchControl";
8
+
9
+ export function StringPropertyValidation({
10
+ length,
11
+ lowercase,
12
+ matches,
13
+ max,
14
+ min,
15
+ trim,
16
+ uppercase,
17
+ disabled,
18
+ showErrors
19
+ }: {
20
+ length?: boolean;
21
+ min?: boolean;
22
+ max?: boolean;
23
+ trim?: boolean;
24
+ matches?: boolean;
25
+ lowercase?: boolean;
26
+ uppercase?: boolean;
27
+ disabled: boolean;
28
+ showErrors: boolean;
29
+ }) {
30
+
31
+ const {
32
+ values,
33
+ handleChange,
34
+ errors
35
+ } = useFormex();
36
+
37
+ const validationLength = "validation.length";
38
+ const validationMin = "validation.min";
39
+ const validationMax = "validation.max";
40
+ const validationTrim = "validation.trim";
41
+ const validationMatches = "validation.matches";
42
+ const validationLowercase = "validation.lowercase";
43
+ const validationUppercase = "validation.uppercase";
44
+
45
+ const matchesError = getIn(errors, validationMatches);
46
+
47
+ const matchesValue = getIn(values, validationMatches);
48
+ const matchesStringValue = typeof matchesValue === "string" ? matchesValue : serializeRegExp(matchesValue);
49
+ return (
50
+ <div className={"grid grid-cols-12 gap-2"}>
51
+
52
+ <GeneralPropertyValidation disabled={disabled}/>
53
+
54
+ <div className={"grid grid-cols-12 gap-2 col-span-12"}>
55
+
56
+ {lowercase && <div className={"col-span-4"}>
57
+ <Field name={validationLowercase}
58
+ type="checkbox">
59
+ {({ field, form }: FormexFieldProps) => {
60
+ return <SwitchControl
61
+ label={"Lowercase"}
62
+ disabled={disabled}
63
+ form={form}
64
+ field={field}/>
65
+ }}
66
+ </Field>
67
+ </div>}
68
+
69
+ {uppercase && <div className={"col-span-4"}>
70
+ <Field name={validationUppercase}
71
+ type="checkbox">
72
+ {({ field, form }: FormexFieldProps) => {
73
+ return <SwitchControl
74
+ label={"Uppercase"}
75
+ disabled={disabled}
76
+ form={form}
77
+ field={field}/>
78
+ }}
79
+ </Field>
80
+ </div>}
81
+
82
+ {trim && <div className={"col-span-4"}>
83
+ <Field name={validationTrim}
84
+ type="checkbox">
85
+ {({ field, form }: FormexFieldProps) => {
86
+ return <SwitchControl
87
+ label={"Trim"}
88
+ disabled={disabled}
89
+ form={form}
90
+ field={field}/>
91
+ }}
92
+ </Field>
93
+ </div>}
94
+
95
+ </div>
96
+
97
+ <div className={"grid grid-cols-12 gap-2 col-span-12"}>
98
+ {length && <div className={"col-span-4"}>
99
+ <DebouncedTextField
100
+ value={getIn(values, validationLength)}
101
+ label={"Exact length"}
102
+ name={validationLength}
103
+ type="number"
104
+ size="small"
105
+
106
+ disabled={disabled}
107
+ onChange={handleChange}/>
108
+ </div>}
109
+
110
+ {min && <div className={"col-span-4"}>
111
+ <DebouncedTextField value={getIn(values, validationMin)}
112
+ label={"Min length"}
113
+ name={validationMin}
114
+ type="number"
115
+ size="small"
116
+
117
+ disabled={disabled}
118
+ onChange={handleChange}/>
119
+ </div>}
120
+
121
+ {max && <div className={"col-span-4"}>
122
+ <DebouncedTextField value={getIn(values, validationMax)}
123
+ label={"Max length"}
124
+ name={validationMax}
125
+ type="number"
126
+ size="small"
127
+
128
+ disabled={disabled}
129
+ onChange={handleChange}/>
130
+ </div>}
131
+
132
+ </div>
133
+
134
+ {matches && <div className={"col-span-12"}>
135
+ <Field name={validationMatches}
136
+ as={DebouncedTextField}
137
+ label={"Matches regex"}
138
+ size="small"
139
+ disabled={disabled}
140
+ value={matchesStringValue}
141
+ error={Boolean(matchesError)}/>
142
+ <FieldCaption error={Boolean(matchesError)}>
143
+ {matchesError ? "Not a valid regexp" : "e.g. /^\\d+$/ for digits only"}
144
+ </FieldCaption>
145
+ </div>}
146
+
147
+ </div>
148
+ );
149
+
150
+ }
@@ -0,0 +1,28 @@
1
+ import { PropsWithChildren } from "react";
2
+
3
+ import { ExpandablePanel, RuleIcon, Typography } from "@firecms/ui";
4
+
5
+ export function ValidationPanel({
6
+ children
7
+ }: PropsWithChildren<{}>) {
8
+
9
+ return (
10
+ <ExpandablePanel
11
+ initiallyExpanded={false}
12
+ asField={true}
13
+ className="p-4"
14
+ title={
15
+ <div className="flex flex-row text-gray-500">
16
+ <RuleIcon/>
17
+ <Typography variant={"subtitle2"}
18
+ className="ml-2">
19
+ Validation
20
+ </Typography>
21
+ </div>
22
+ }>
23
+
24
+ {children}
25
+
26
+ </ExpandablePanel>
27
+ )
28
+ }