payload 1.1.6 → 1.1.8

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 (67) hide show
  1. package/components/forms.ts +10 -0
  2. package/dist/admin/api.js +8 -3
  3. package/dist/admin/components/elements/Autosave/index.js +5 -3
  4. package/dist/admin/components/elements/Nav/index.scss +1 -5
  5. package/dist/admin/components/elements/WhereBuilder/Condition/Relationship/index.js +2 -2
  6. package/dist/admin/components/forms/Form/context.d.ts +5 -2
  7. package/dist/admin/components/forms/Form/context.js +9 -2
  8. package/dist/admin/components/forms/Form/fieldReducer.d.ts +2 -2
  9. package/dist/admin/components/forms/Form/fieldReducer.js +4 -1
  10. package/dist/admin/components/forms/Form/getSiblingData.js +11 -5
  11. package/dist/admin/components/forms/Form/index.js +12 -12
  12. package/dist/admin/components/forms/Form/initContextState.js +0 -3
  13. package/dist/admin/components/forms/Form/reduceFieldsToValues.js +6 -3
  14. package/dist/admin/components/forms/Form/types.d.ts +49 -7
  15. package/dist/admin/components/forms/field-types/Code/Code.js +0 -1
  16. package/dist/admin/components/forms/field-types/ConfirmPassword/index.js +2 -4
  17. package/dist/admin/components/forms/field-types/Email/index.js +0 -1
  18. package/dist/admin/components/forms/field-types/Number/index.js +0 -1
  19. package/dist/admin/components/forms/field-types/Password/index.js +0 -1
  20. package/dist/admin/components/forms/field-types/Point/index.js +0 -1
  21. package/dist/admin/components/forms/field-types/Relationship/AddNew/Modal/index.d.ts +4 -0
  22. package/dist/admin/components/forms/field-types/Relationship/AddNew/Modal/index.js +67 -0
  23. package/dist/admin/components/forms/field-types/Relationship/AddNew/Modal/index.scss +117 -0
  24. package/dist/admin/components/forms/field-types/Relationship/AddNew/Modal/types.d.ts +6 -0
  25. package/dist/admin/components/forms/field-types/Relationship/AddNew/Modal/types.js +1 -0
  26. package/dist/admin/components/forms/field-types/Relationship/AddNew/index.d.ts +4 -0
  27. package/dist/admin/components/forms/field-types/Relationship/AddNew/index.js +79 -0
  28. package/dist/admin/components/forms/field-types/Relationship/AddNew/index.scss +60 -0
  29. package/dist/admin/components/forms/field-types/Relationship/AddNew/types.d.ts +10 -0
  30. package/dist/admin/components/forms/field-types/Relationship/AddNew/types.js +1 -0
  31. package/dist/admin/components/forms/field-types/Relationship/AddNew/useRelatedCollections.d.ts +2 -0
  32. package/dist/admin/components/forms/field-types/Relationship/AddNew/useRelatedCollections.js +10 -0
  33. package/dist/admin/components/forms/field-types/Relationship/index.js +59 -47
  34. package/dist/admin/components/forms/field-types/Relationship/index.scss +23 -12
  35. package/dist/admin/components/forms/field-types/Relationship/optionsReducer.js +8 -7
  36. package/dist/admin/components/forms/field-types/Relationship/types.d.ts +1 -3
  37. package/dist/admin/components/forms/field-types/RichText/elements/relationship/Button/Fields/index.js +2 -3
  38. package/dist/admin/components/forms/field-types/Text/index.js +0 -1
  39. package/dist/admin/components/forms/field-types/Textarea/index.js +0 -1
  40. package/dist/admin/components/forms/field-types/Upload/Input.js +1 -1
  41. package/dist/admin/components/forms/field-types/Upload/SelectExisting/index.js +2 -2
  42. package/dist/admin/components/forms/useField/index.js +71 -97
  43. package/dist/admin/components/forms/useField/types.d.ts +0 -2
  44. package/dist/admin/components/forms/withCondition/index.js +10 -5
  45. package/dist/admin/components/modals/LeaveWithoutSaving/index.scss +2 -2
  46. package/dist/admin/components/templates/Default/index.scss +1 -1
  47. package/dist/admin/components/utilities/DocumentInfo/index.js +3 -3
  48. package/dist/admin/components/utilities/EditDepth/index.d.ts +3 -0
  49. package/dist/admin/components/utilities/EditDepth/index.js +3 -0
  50. package/dist/admin/components/views/Verify/index.js +1 -1
  51. package/dist/admin/components/views/Version/Compare/index.js +1 -1
  52. package/dist/admin/components/views/collections/Edit/Auth/APIKey.js +2 -3
  53. package/dist/admin/components/views/collections/Edit/Auth/index.js +4 -3
  54. package/dist/admin/components/views/collections/Edit/Default.js +9 -9
  55. package/dist/admin/components/views/collections/Edit/index.js +15 -12
  56. package/dist/admin/components/views/collections/Edit/types.d.ts +6 -0
  57. package/dist/admin/components/views/collections/List/RelationshipProvider/index.js +1 -1
  58. package/dist/admin/hooks/useTitle.js +2 -3
  59. package/dist/admin/index.js +1 -1
  60. package/dist/admin/scss/app.scss +6 -1
  61. package/docs/admin/components.mdx +3 -45
  62. package/docs/admin/customizing-css.mdx +1 -1
  63. package/docs/admin/hooks.mdx +271 -0
  64. package/docs/admin/preferences.mdx +1 -1
  65. package/docs/admin/webpack.mdx +1 -1
  66. package/docs/local-api/overview.mdx +1 -1
  67. package/package.json +2 -1
@@ -1,12 +1,21 @@
1
1
  export {
2
2
  useForm,
3
+ /**
4
+ * @deprecated useWatchForm is no longer preferred. If you need all form fields, prefer `useAllFormFields`.
5
+ */
3
6
  useWatchForm,
7
+ useFormFields,
8
+ useAllFormFields,
4
9
  useFormSubmitted,
5
10
  useFormProcessing,
6
11
  useFormModified,
7
12
  } from '../dist/admin/components/forms/Form/context';
8
13
 
9
14
  export { default as useField } from '../dist/admin/components/forms/useField';
15
+
16
+ /**
17
+ * @deprecated This method is now called useField. The useFieldType alias will be removed in an upcoming version.
18
+ */
10
19
  export { default as useFieldType } from '../dist/admin/components/forms/useField';
11
20
 
12
21
  export { default as Form } from '../dist/admin/components/forms/Form';
@@ -24,5 +33,6 @@ export { default as Submit } from '../dist/admin/components/forms/Submit';
24
33
  export { default as Label } from '../dist/admin/components/forms/Label';
25
34
 
26
35
  export { default as reduceFieldsToValues } from '../dist/admin/components/forms/Form/reduceFieldsToValues';
36
+ export { default as getSiblingData } from '../dist/admin/components/forms/Form/getSiblingData';
27
37
 
28
38
  export { default as withCondition } from '../dist/admin/components/forms/withCondition';
package/dist/admin/api.js CHANGED
@@ -2,13 +2,14 @@ import qs from 'qs';
2
2
  export const requests = {
3
3
  get: (url, params = {}) => {
4
4
  const query = qs.stringify(params, { addQueryPrefix: true });
5
- return fetch(`${url}${query}`);
5
+ return fetch(`${url}${query}`, { credentials: 'include' });
6
6
  },
7
7
  post: (url, options = { headers: {} }) => {
8
8
  const headers = options && options.headers ? { ...options.headers } : {};
9
9
  const formattedOptions = {
10
10
  ...options,
11
11
  method: 'post',
12
+ credentials: 'include',
12
13
  headers: {
13
14
  ...headers,
14
15
  },
@@ -20,6 +21,7 @@ export const requests = {
20
21
  const formattedOptions = {
21
22
  ...options,
22
23
  method: 'put',
24
+ credentials: 'include',
23
25
  headers: {
24
26
  ...headers,
25
27
  },
@@ -31,6 +33,7 @@ export const requests = {
31
33
  const formattedOptions = {
32
34
  ...options,
33
35
  method: 'PATCH',
36
+ credentials: 'include',
34
37
  headers: {
35
38
  ...headers,
36
39
  },
@@ -39,12 +42,14 @@ export const requests = {
39
42
  },
40
43
  delete: (url, options = { headers: {} }) => {
41
44
  const headers = options && options.headers ? { ...options.headers } : {};
42
- return fetch(url, {
45
+ const formattedOptions = {
43
46
  ...options,
44
47
  method: 'delete',
48
+ credentials: 'include',
45
49
  headers: {
46
50
  ...headers,
47
51
  },
48
- });
52
+ };
53
+ return fetch(url, formattedOptions);
49
54
  },
50
55
  };
@@ -3,7 +3,7 @@ import { useHistory } from 'react-router-dom';
3
3
  import { toast } from 'react-toastify';
4
4
  import React, { useCallback, useEffect, useRef, useState } from 'react';
5
5
  import { useConfig } from '../../utilities/Config';
6
- import { useWatchForm, useFormModified } from '../../forms/Form/context';
6
+ import { useFormModified, useAllFormFields } from '../../forms/Form/context';
7
7
  import { useLocale } from '../../utilities/Locale';
8
8
  import reduceFieldsToValues from '../../forms/Form/reduceFieldsToValues';
9
9
  import { useDocumentInfo } from '../../utilities/DocumentInfo';
@@ -14,7 +14,7 @@ const Autosave = ({ collection, global, id, publishedDocUpdatedAt }) => {
14
14
  var _a, _b, _c, _d;
15
15
  const { serverURL, routes: { api, admin } } = useConfig();
16
16
  const { versions, getVersions } = useDocumentInfo();
17
- const { fields, dispatchFields } = useWatchForm();
17
+ const [fields] = useAllFormFields();
18
18
  const modified = useFormModified();
19
19
  const locale = useLocale();
20
20
  const { replace } = useHistory();
@@ -34,6 +34,7 @@ const Autosave = ({ collection, global, id, publishedDocUpdatedAt }) => {
34
34
  const createCollectionDoc = useCallback(async () => {
35
35
  const res = await fetch(`${serverURL}${api}/${collection.slug}?locale=${locale}&fallback-locale=null&depth=0&draft=true`, {
36
36
  method: 'POST',
37
+ credentials: 'include',
37
38
  headers: {
38
39
  'Content-Type': 'application/json',
39
40
  },
@@ -81,6 +82,7 @@ const Autosave = ({ collection, global, id, publishedDocUpdatedAt }) => {
81
82
  setTimeout(async () => {
82
83
  const res = await fetch(url, {
83
84
  method,
85
+ credentials: 'include',
84
86
  headers: {
85
87
  'Content-Type': 'application/json',
86
88
  },
@@ -96,7 +98,7 @@ const Autosave = ({ collection, global, id, publishedDocUpdatedAt }) => {
96
98
  }
97
99
  };
98
100
  autosave();
99
- }, [debouncedFields, modified, serverURL, api, collection, global, id, dispatchFields, getVersions, locale]);
101
+ }, [debouncedFields, modified, serverURL, api, collection, global, id, getVersions, locale]);
100
102
  useEffect(() => {
101
103
  var _a;
102
104
  if ((_a = versions === null || versions === void 0 ? void 0 : versions.docs) === null || _a === void 0 ? void 0 : _a[0]) {
@@ -6,7 +6,7 @@
6
6
  top: 0;
7
7
  left: 0;
8
8
  height: 100vh;
9
- width: base(9);
9
+ width: var(--nav-width);
10
10
  overflow: hidden;
11
11
  border-right: 1px solid var(--theme-elevation-100);
12
12
 
@@ -120,10 +120,6 @@
120
120
  }
121
121
  }
122
122
 
123
- @include large-break {
124
- width: base(8);
125
- }
126
-
127
123
  @include mid-break {
128
124
  @include blur-bg;
129
125
  position: fixed;
@@ -35,7 +35,7 @@ const RelationshipField = (props) => {
35
35
  const collection = collections.find((coll) => coll.slug === relation);
36
36
  const fieldToSearch = ((_a = collection === null || collection === void 0 ? void 0 : collection.admin) === null || _a === void 0 ? void 0 : _a.useAsTitle) || 'id';
37
37
  const searchParam = searchArg ? `&where[${fieldToSearch}][like]=${searchArg}` : '';
38
- const response = await fetch(`${serverURL}${api}/${relation}?limit=${maxResultsPerRequest}&page=${lastLoadedPageToUse}&depth=0${searchParam}`);
38
+ const response = await fetch(`${serverURL}${api}/${relation}?limit=${maxResultsPerRequest}&page=${lastLoadedPageToUse}&depth=0${searchParam}`, { credentials: 'include' });
39
39
  if (response.ok) {
40
40
  const data = await response.json();
41
41
  if (data.docs.length > 0) {
@@ -111,7 +111,7 @@ const RelationshipField = (props) => {
111
111
  }, [search]);
112
112
  const addOptionByID = useCallback(async (id, relation) => {
113
113
  if (!errorLoading && id !== 'null') {
114
- const response = await fetch(`${serverURL}${api}/${relation}/${id}?depth=0`);
114
+ const response = await fetch(`${serverURL}${api}/${relation}/${id}?depth=0`, { credentials: 'include' });
115
115
  if (response.ok) {
116
116
  const data = await response.json();
117
117
  addOptions({ docs: [data] }, relation);
@@ -1,13 +1,16 @@
1
1
  /// <reference types="react" />
2
- import { Context } from './types';
2
+ import { Context, FormFieldsContext as FormFieldsContextType } from './types';
3
3
  declare const FormContext: import("react").Context<Context>;
4
4
  declare const FormWatchContext: import("react").Context<Context>;
5
5
  declare const SubmittedContext: import("react").Context<boolean>;
6
6
  declare const ProcessingContext: import("react").Context<boolean>;
7
7
  declare const ModifiedContext: import("react").Context<boolean>;
8
+ declare const FormFieldsContext: import("use-context-selector").Context<FormFieldsContextType>;
8
9
  declare const useForm: () => Context;
9
10
  declare const useWatchForm: () => Context;
10
11
  declare const useFormSubmitted: () => boolean;
11
12
  declare const useFormProcessing: () => boolean;
12
13
  declare const useFormModified: () => boolean;
13
- export { FormContext, FormWatchContext, SubmittedContext, ProcessingContext, ModifiedContext, useForm, useWatchForm, useFormSubmitted, useFormProcessing, useFormModified, };
14
+ declare const useFormFields: <Value = unknown>(selector: (context: FormFieldsContextType) => Value) => Value;
15
+ declare const useAllFormFields: () => FormFieldsContextType;
16
+ export { SubmittedContext, ProcessingContext, ModifiedContext, useFormSubmitted, useFormProcessing, useFormModified, useForm, FormContext, FormFieldsContext, useFormFields, useAllFormFields, FormWatchContext, useWatchForm, };
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useFormModified = exports.useFormProcessing = exports.useFormSubmitted = exports.useWatchForm = exports.useForm = exports.ModifiedContext = exports.ProcessingContext = exports.SubmittedContext = exports.FormWatchContext = exports.FormContext = void 0;
3
+ exports.useWatchForm = exports.FormWatchContext = exports.useAllFormFields = exports.useFormFields = exports.FormFieldsContext = exports.FormContext = exports.useForm = exports.useFormModified = exports.useFormProcessing = exports.useFormSubmitted = exports.ModifiedContext = exports.ProcessingContext = exports.SubmittedContext = void 0;
4
4
  const react_1 = require("react");
5
+ const use_context_selector_1 = require("use-context-selector");
5
6
  const FormContext = (0, react_1.createContext)({});
6
7
  exports.FormContext = FormContext;
7
8
  const FormWatchContext = (0, react_1.createContext)({});
@@ -12,6 +13,8 @@ const ProcessingContext = (0, react_1.createContext)(false);
12
13
  exports.ProcessingContext = ProcessingContext;
13
14
  const ModifiedContext = (0, react_1.createContext)(false);
14
15
  exports.ModifiedContext = ModifiedContext;
16
+ const FormFieldsContext = (0, use_context_selector_1.createContext)([{}, () => null]);
17
+ exports.FormFieldsContext = FormFieldsContext;
15
18
  const useForm = () => (0, react_1.useContext)(FormContext);
16
19
  exports.useForm = useForm;
17
20
  const useWatchForm = () => (0, react_1.useContext)(FormWatchContext);
@@ -22,4 +25,8 @@ const useFormProcessing = () => (0, react_1.useContext)(ProcessingContext);
22
25
  exports.useFormProcessing = useFormProcessing;
23
26
  const useFormModified = () => (0, react_1.useContext)(ModifiedContext);
24
27
  exports.useFormModified = useFormModified;
25
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udGV4dC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9hZG1pbi9jb21wb25lbnRzL2Zvcm1zL0Zvcm0vY29udGV4dC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxpQ0FBa0Q7QUFHbEQsTUFBTSxXQUFXLEdBQUcsSUFBQSxxQkFBYSxFQUFDLEVBQWEsQ0FBQyxDQUFDO0FBYS9DLGtDQUFXO0FBWmIsTUFBTSxnQkFBZ0IsR0FBRyxJQUFBLHFCQUFhLEVBQUMsRUFBYSxDQUFDLENBQUM7QUFhcEQsNENBQWdCO0FBWmxCLE1BQU0sZ0JBQWdCLEdBQUcsSUFBQSxxQkFBYSxFQUFDLEtBQUssQ0FBQyxDQUFDO0FBYTVDLDRDQUFnQjtBQVpsQixNQUFNLGlCQUFpQixHQUFHLElBQUEscUJBQWEsRUFBQyxLQUFLLENBQUMsQ0FBQztBQWE3Qyw4Q0FBaUI7QUFabkIsTUFBTSxlQUFlLEdBQUcsSUFBQSxxQkFBYSxFQUFDLEtBQUssQ0FBQyxDQUFDO0FBYTNDLDBDQUFlO0FBWGpCLE1BQU0sT0FBTyxHQUFHLEdBQVksRUFBRSxDQUFDLElBQUEsa0JBQVUsRUFBQyxXQUFXLENBQUMsQ0FBQztBQVlyRCwwQkFBTztBQVhULE1BQU0sWUFBWSxHQUFHLEdBQVksRUFBRSxDQUFDLElBQUEsa0JBQVUsRUFBQyxnQkFBZ0IsQ0FBQyxDQUFDO0FBWS9ELG9DQUFZO0FBWGQsTUFBTSxnQkFBZ0IsR0FBRyxHQUFZLEVBQUUsQ0FBQyxJQUFBLGtCQUFVLEVBQUMsZ0JBQWdCLENBQUMsQ0FBQztBQVluRSw0Q0FBZ0I7QUFYbEIsTUFBTSxpQkFBaUIsR0FBRyxHQUFZLEVBQUUsQ0FBQyxJQUFBLGtCQUFVLEVBQUMsaUJBQWlCLENBQUMsQ0FBQztBQVlyRSw4Q0FBaUI7QUFYbkIsTUFBTSxlQUFlLEdBQUcsR0FBWSxFQUFFLENBQUMsSUFBQSxrQkFBVSxFQUFDLGVBQWUsQ0FBQyxDQUFDO0FBWWpFLDBDQUFlIn0=
28
+ const useFormFields = (selector) => (0, use_context_selector_1.useContextSelector)(FormFieldsContext, selector);
29
+ exports.useFormFields = useFormFields;
30
+ const useAllFormFields = () => (0, use_context_selector_1.useContext)(FormFieldsContext);
31
+ exports.useAllFormFields = useAllFormFields;
32
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udGV4dC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9hZG1pbi9jb21wb25lbnRzL2Zvcm1zL0Zvcm0vY29udGV4dC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxpQ0FBa0Q7QUFDbEQsK0RBQWdJO0FBR2hJLE1BQU0sV0FBVyxHQUFHLElBQUEscUJBQWEsRUFBQyxFQUFhLENBQUMsQ0FBQztBQXdCL0Msa0NBQVc7QUF2QmIsTUFBTSxnQkFBZ0IsR0FBRyxJQUFBLHFCQUFhLEVBQUMsRUFBYSxDQUFDLENBQUM7QUEyQnBELDRDQUFnQjtBQTFCbEIsTUFBTSxnQkFBZ0IsR0FBRyxJQUFBLHFCQUFhLEVBQUMsS0FBSyxDQUFDLENBQUM7QUFlNUMsNENBQWdCO0FBZGxCLE1BQU0saUJBQWlCLEdBQUcsSUFBQSxxQkFBYSxFQUFDLEtBQUssQ0FBQyxDQUFDO0FBZTdDLDhDQUFpQjtBQWRuQixNQUFNLGVBQWUsR0FBRyxJQUFBLHFCQUFhLEVBQUMsS0FBSyxDQUFDLENBQUM7QUFlM0MsMENBQWU7QUFkakIsTUFBTSxpQkFBaUIsR0FBRyxJQUFBLG9DQUFxQixFQUF3QixDQUFDLEVBQUUsRUFBRSxHQUFHLEVBQUUsQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDO0FBb0J2Riw4Q0FBaUI7QUFsQm5CLE1BQU0sT0FBTyxHQUFHLEdBQVksRUFBRSxDQUFDLElBQUEsa0JBQVUsRUFBQyxXQUFXLENBQUMsQ0FBQztBQWdCckQsMEJBQU87QUFmVCxNQUFNLFlBQVksR0FBRyxHQUFZLEVBQUUsQ0FBQyxJQUFBLGtCQUFVLEVBQUMsZ0JBQWdCLENBQUMsQ0FBQztBQXFCL0Qsb0NBQVk7QUFwQmQsTUFBTSxnQkFBZ0IsR0FBRyxHQUFZLEVBQUUsQ0FBQyxJQUFBLGtCQUFVLEVBQUMsZ0JBQWdCLENBQUMsQ0FBQztBQVduRSw0Q0FBZ0I7QUFWbEIsTUFBTSxpQkFBaUIsR0FBRyxHQUFZLEVBQUUsQ0FBQyxJQUFBLGtCQUFVLEVBQUMsaUJBQWlCLENBQUMsQ0FBQztBQVdyRSw4Q0FBaUI7QUFWbkIsTUFBTSxlQUFlLEdBQUcsR0FBWSxFQUFFLENBQUMsSUFBQSxrQkFBVSxFQUFDLGVBQWUsQ0FBQyxDQUFDO0FBV2pFLDBDQUFlO0FBVGpCLE1BQU0sYUFBYSxHQUFHLENBQWtCLFFBQW1ELEVBQVMsRUFBRSxDQUFDLElBQUEseUNBQWtCLEVBQUMsaUJBQWlCLEVBQUUsUUFBUSxDQUFDLENBQUM7QUFhckosc0NBQWE7QUFaZixNQUFNLGdCQUFnQixHQUFHLEdBQTBCLEVBQUUsQ0FBQyxJQUFBLGlDQUFjLEVBQUMsaUJBQWlCLENBQUMsQ0FBQztBQWF0Riw0Q0FBZ0IifQ==
@@ -1,3 +1,3 @@
1
- import { Fields } from './types';
2
- declare function fieldReducer(state: Fields, action: any): Fields;
1
+ import { FieldAction, Fields } from './types';
2
+ declare function fieldReducer(state: Fields, action: FieldAction): Fields;
3
3
  export default fieldReducer;
@@ -145,7 +145,7 @@ function fieldReducer(state, action) {
145
145
  };
146
146
  }, {});
147
147
  }
148
- default: {
148
+ case 'UPDATE': {
149
149
  const newField = {
150
150
  value: action.value,
151
151
  valid: action.valid,
@@ -161,6 +161,9 @@ function fieldReducer(state, action) {
161
161
  [action.path]: newField,
162
162
  };
163
163
  }
164
+ default: {
165
+ return state;
166
+ }
164
167
  }
165
168
  }
166
169
  export default fieldReducer;
@@ -1,8 +1,13 @@
1
- import { unflatten } from 'flatley';
2
- import reduceFieldsToValues from './reduceFieldsToValues';
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const flatley_1 = require("flatley");
7
+ const reduceFieldsToValues_1 = __importDefault(require("./reduceFieldsToValues"));
3
8
  const getSiblingData = (fields, path) => {
4
9
  if (path.indexOf('.') === -1) {
5
- return reduceFieldsToValues(fields, true);
10
+ return (0, reduceFieldsToValues_1.default)(fields, true);
6
11
  }
7
12
  const siblingFields = {};
8
13
  // If this field is nested
@@ -13,6 +18,7 @@ const getSiblingData = (fields, path) => {
13
18
  siblingFields[fieldKey.replace(parentFieldPath, '')] = fields[fieldKey].value;
14
19
  }
15
20
  });
16
- return unflatten(siblingFields, { safe: true });
21
+ return (0, flatley_1.unflatten)(siblingFields, { safe: true });
17
22
  };
18
- export default getSiblingData;
23
+ exports.default = getSiblingData;
24
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2V0U2libGluZ0RhdGEuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvYWRtaW4vY29tcG9uZW50cy9mb3Jtcy9Gb3JtL2dldFNpYmxpbmdEYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEscUNBQW9DO0FBRXBDLGtGQUEwRDtBQUUxRCxNQUFNLGNBQWMsR0FBRyxDQUFDLE1BQWMsRUFBRSxJQUFZLEVBQVEsRUFBRTtJQUM1RCxJQUFJLElBQUksQ0FBQyxPQUFPLENBQUMsR0FBRyxDQUFDLEtBQUssQ0FBQyxDQUFDLEVBQUU7UUFDNUIsT0FBTyxJQUFBLDhCQUFvQixFQUFDLE1BQU0sRUFBRSxJQUFJLENBQUMsQ0FBQztLQUMzQztJQUNELE1BQU0sYUFBYSxHQUFHLEVBQUUsQ0FBQztJQUV6QiwwQkFBMEI7SUFDMUIsMENBQTBDO0lBQzFDLE1BQU0sZUFBZSxHQUFHLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQyxFQUFFLElBQUksQ0FBQyxXQUFXLENBQUMsR0FBRyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUM7SUFDckUsTUFBTSxDQUFDLElBQUksQ0FBQyxNQUFNLENBQUMsQ0FBQyxPQUFPLENBQUMsQ0FBQyxRQUFRLEVBQUUsRUFBRTtRQUN2QyxJQUFJLENBQUMsTUFBTSxDQUFDLFFBQVEsQ0FBQyxDQUFDLGVBQWUsSUFBSSxRQUFRLENBQUMsT0FBTyxDQUFDLGVBQWUsQ0FBQyxLQUFLLENBQUMsRUFBRTtZQUNoRixhQUFhLENBQUMsUUFBUSxDQUFDLE9BQU8sQ0FBQyxlQUFlLEVBQUUsRUFBRSxDQUFDLENBQUMsR0FBRyxNQUFNLENBQUMsUUFBUSxDQUFDLENBQUMsS0FBSyxDQUFDO1NBQy9FO0lBQ0gsQ0FBQyxDQUFDLENBQUM7SUFFSCxPQUFPLElBQUEsbUJBQVMsRUFBQyxhQUFhLEVBQUUsRUFBRSxJQUFJLEVBQUUsSUFBSSxFQUFFLENBQUMsQ0FBQztBQUNsRCxDQUFDLENBQUM7QUFFRixrQkFBZSxjQUFjLENBQUMifQ==
@@ -17,7 +17,7 @@ import getDataByPathFunc from './getDataByPath';
17
17
  import wait from '../../../../utilities/wait';
18
18
  import buildInitialState from './buildInitialState';
19
19
  import errorMessages from './errorMessages';
20
- import { SubmittedContext, ProcessingContext, ModifiedContext, FormContext, FormWatchContext } from './context';
20
+ import { SubmittedContext, ProcessingContext, ModifiedContext, FormContext, FormFieldsContext, FormWatchContext } from './context';
21
21
  import buildStateFromSchema from './buildStateFromSchema';
22
22
  import { useOperation } from '../../utilities/OperationProvider';
23
23
  const baseClass = 'form';
@@ -41,10 +41,10 @@ const Form = (props) => {
41
41
  initialFieldState = formattedInitialData;
42
42
  if (initialState)
43
43
  initialFieldState = initialState;
44
- // Allow access to initialState for field types such as Blocks and Array
45
- contextRef.current.initialState = initialState;
46
- const [fields, dispatchFields] = useReducer(fieldReducer, {}, () => initialFieldState);
44
+ const fieldsReducer = useReducer(fieldReducer, {}, () => initialFieldState);
45
+ const [fields, dispatchFields] = fieldsReducer;
47
46
  contextRef.current.fields = fields;
47
+ contextRef.current.dispatchFields = dispatchFields;
48
48
  const validateForm = useCallback(async () => {
49
49
  const validatedFieldState = {};
50
50
  let isValid = true;
@@ -78,7 +78,7 @@ const Form = (props) => {
78
78
  dispatchFields({ type: 'REPLACE_STATE', state: validatedFieldState });
79
79
  }
80
80
  return isValid;
81
- }, [contextRef, id, user, operation]);
81
+ }, [contextRef, id, user, operation, dispatchFields]);
82
82
  const submit = useCallback(async (options = {}, e) => {
83
83
  const { overrides = {}, action: actionToUse = action, method: methodToUse = method, skipValidation, } = options;
84
84
  if (disabled) {
@@ -189,6 +189,7 @@ const Form = (props) => {
189
189
  fieldErrors.forEach((err) => {
190
190
  var _a, _b;
191
191
  dispatchFields({
192
+ type: 'UPDATE',
192
193
  ...(((_b = (_a = contextRef.current) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b[err.field]) || {}),
193
194
  valid: false,
194
195
  errorMessage: err.message,
@@ -213,6 +214,7 @@ const Form = (props) => {
213
214
  action,
214
215
  disableSuccessStatus,
215
216
  disabled,
217
+ dispatchFields,
216
218
  fields,
217
219
  handleResponse,
218
220
  history,
@@ -227,7 +229,6 @@ const Form = (props) => {
227
229
  const getData = useCallback(() => reduceFieldsToValues(contextRef.current.fields, true), [contextRef]);
228
230
  const getSiblingData = useCallback((path) => getSiblingDataFunc(contextRef.current.fields, path), [contextRef]);
229
231
  const getDataByPath = useCallback((path) => getDataByPathFunc(contextRef.current.fields, path), [contextRef]);
230
- const getUnflattenedValues = useCallback(() => reduceFieldsToValues(contextRef.current.fields), [contextRef]);
231
232
  const createFormData = useCallback((overrides = {}) => {
232
233
  const data = reduceFieldsToValues(contextRef.current.fields, true);
233
234
  const file = data === null || data === void 0 ? void 0 : data.file;
@@ -250,15 +251,13 @@ const Form = (props) => {
250
251
  const state = await buildStateFromSchema({ fieldSchema, data, user, id, operation, locale });
251
252
  contextRef.current = { ...initContextState };
252
253
  dispatchFields({ type: 'REPLACE_STATE', state });
253
- }, [id, user, operation, locale]);
254
- contextRef.current.dispatchFields = dispatchFields;
254
+ }, [id, user, operation, locale, dispatchFields]);
255
255
  contextRef.current.submit = submit;
256
256
  contextRef.current.getFields = getFields;
257
257
  contextRef.current.getField = getField;
258
258
  contextRef.current.getData = getData;
259
259
  contextRef.current.getSiblingData = getSiblingData;
260
260
  contextRef.current.getDataByPath = getDataByPath;
261
- contextRef.current.getUnflattenedValues = getUnflattenedValues;
262
261
  contextRef.current.validateForm = validateForm;
263
262
  contextRef.current.createFormData = createFormData;
264
263
  contextRef.current.setModified = setModified;
@@ -272,7 +271,7 @@ const Form = (props) => {
272
271
  contextRef.current = { ...initContextState };
273
272
  dispatchFields({ type: 'REPLACE_STATE', state: initialState });
274
273
  }
275
- }, [initialState]);
274
+ }, [initialState, dispatchFields]);
276
275
  useEffect(() => {
277
276
  if (initialData) {
278
277
  contextRef.current = { ...initContextState };
@@ -280,7 +279,7 @@ const Form = (props) => {
280
279
  setFormattedInitialData(builtState);
281
280
  dispatchFields({ type: 'REPLACE_STATE', state: builtState });
282
281
  }
283
- }, [initialData]);
282
+ }, [initialData, dispatchFields]);
284
283
  useThrottledEffect(() => {
285
284
  refreshCookie();
286
285
  }, 15000, [fields]);
@@ -307,6 +306,7 @@ const Form = (props) => {
307
306
  } },
308
307
  React.createElement(SubmittedContext.Provider, { value: submitted },
309
308
  React.createElement(ProcessingContext.Provider, { value: processing },
310
- React.createElement(ModifiedContext.Provider, { value: modified }, children)))))));
309
+ React.createElement(ModifiedContext.Provider, { value: modified },
310
+ React.createElement(FormFieldsContext.Provider, { value: fieldsReducer }, children))))))));
311
311
  };
312
312
  export default Form;
@@ -1,6 +1,5 @@
1
1
  const submit = () => undefined;
2
2
  const getSiblingData = () => undefined;
3
- const getUnflattenedValues = () => ({});
4
3
  const dispatchFields = () => undefined;
5
4
  const validateForm = () => undefined;
6
5
  const createFormData = () => undefined;
@@ -14,7 +13,6 @@ const initialContextState = {
14
13
  getData: () => undefined,
15
14
  getSiblingData,
16
15
  getDataByPath: () => undefined,
17
- getUnflattenedValues,
18
16
  validateForm,
19
17
  createFormData,
20
18
  submit,
@@ -22,7 +20,6 @@ const initialContextState = {
22
20
  setModified,
23
21
  setProcessing,
24
22
  setSubmitted,
25
- initialState: {},
26
23
  fields: {},
27
24
  disabled: false,
28
25
  formRef: null,
@@ -1,4 +1,6 @@
1
- import { unflatten as flatleyUnflatten } from 'flatley';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const flatley_1 = require("flatley");
2
4
  const reduceFieldsToValues = (fields, unflatten) => {
3
5
  const data = {};
4
6
  Object.keys(fields).forEach((key) => {
@@ -7,8 +9,9 @@ const reduceFieldsToValues = (fields, unflatten) => {
7
9
  }
8
10
  });
9
11
  if (unflatten) {
10
- return flatleyUnflatten(data, { safe: true });
12
+ return (0, flatley_1.unflatten)(data, { safe: true });
11
13
  }
12
14
  return data;
13
15
  };
14
- export default reduceFieldsToValues;
16
+ exports.default = reduceFieldsToValues;
17
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVkdWNlRmllbGRzVG9WYWx1ZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvYWRtaW4vY29tcG9uZW50cy9mb3Jtcy9Gb3JtL3JlZHVjZUZpZWxkc1RvVmFsdWVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEscUNBQXdEO0FBR3hELE1BQU0sb0JBQW9CLEdBQUcsQ0FBQyxNQUFjLEVBQUUsU0FBbUIsRUFBUSxFQUFFO0lBQ3pFLE1BQU0sSUFBSSxHQUFHLEVBQUUsQ0FBQztJQUVoQixNQUFNLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxDQUFDLE9BQU8sQ0FBQyxDQUFDLEdBQUcsRUFBRSxFQUFFO1FBQ2xDLElBQUksQ0FBQyxNQUFNLENBQUMsR0FBRyxDQUFDLENBQUMsZUFBZSxFQUFFO1lBQ2hDLElBQUksQ0FBQyxHQUFHLENBQUMsR0FBRyxNQUFNLENBQUMsR0FBRyxDQUFDLENBQUMsS0FBSyxDQUFDO1NBQy9CO0lBQ0gsQ0FBQyxDQUFDLENBQUM7SUFFSCxJQUFJLFNBQVMsRUFBRTtRQUNiLE9BQU8sSUFBQSxtQkFBZ0IsRUFBQyxJQUFJLEVBQUUsRUFBRSxJQUFJLEVBQUUsSUFBSSxFQUFFLENBQUMsQ0FBQztLQUMvQztJQUVELE9BQU8sSUFBSSxDQUFDO0FBQ2QsQ0FBQyxDQUFDO0FBRUYsa0JBQWUsb0JBQW9CLENBQUMifQ==
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { Dispatch } from 'react';
2
2
  import { Field as FieldConfig, Condition, Validate } from '../../../../fields/config/types';
3
3
  export declare type Field = {
4
4
  value: unknown;
@@ -43,24 +43,67 @@ export declare type SubmitOptions = {
43
43
  skipValidation?: boolean;
44
44
  };
45
45
  export declare type DispatchFields = React.Dispatch<any>;
46
- export declare type Submit = (options?: SubmitOptions, e?: React.FormEvent<HTMLFormElement>) => void;
46
+ export declare type Submit = (options?: SubmitOptions, e?: React.FormEvent<HTMLFormElement>) => Promise<void>;
47
47
  export declare type ValidateForm = () => Promise<boolean>;
48
48
  export declare type CreateFormData = (overrides?: any) => FormData;
49
49
  export declare type GetFields = () => Fields;
50
50
  export declare type GetField = (path: string) => Field;
51
51
  export declare type GetData = () => Data;
52
52
  export declare type GetSiblingData = (path: string) => Data;
53
- export declare type GetUnflattenedValues = () => Data;
54
53
  export declare type GetDataByPath = <T = unknown>(path: string) => T;
55
54
  export declare type SetModified = (modified: boolean) => void;
56
55
  export declare type SetSubmitted = (submitted: boolean) => void;
57
56
  export declare type SetProcessing = (processing: boolean) => void;
58
57
  export declare type Reset = (fieldSchema: FieldConfig[], data: unknown) => Promise<void>;
58
+ export declare type REPLACE_STATE = {
59
+ type: 'REPLACE_STATE';
60
+ state: Fields;
61
+ };
62
+ export declare type REMOVE = {
63
+ type: 'REMOVE';
64
+ path: string;
65
+ };
66
+ export declare type REMOVE_ROW = {
67
+ type: 'REMOVE_ROW';
68
+ rowIndex: number;
69
+ path: string;
70
+ };
71
+ export declare type ADD_ROW = {
72
+ type: 'ADD_ROW';
73
+ rowIndex: number;
74
+ path: string;
75
+ subFieldState?: Fields;
76
+ blockType?: string;
77
+ };
78
+ export declare type DUPLICATE_ROW = {
79
+ type: 'DUPLICATE_ROW';
80
+ rowIndex: number;
81
+ path: string;
82
+ };
83
+ export declare type MOVE_ROW = {
84
+ type: 'MOVE_ROW';
85
+ moveFromIndex: number;
86
+ moveToIndex: number;
87
+ path: string;
88
+ };
89
+ export declare type MODIFY_CONDITION = {
90
+ type: 'MODIFY_CONDITION';
91
+ path: string;
92
+ result: boolean;
93
+ };
94
+ export declare type UPDATE = {
95
+ type: 'UPDATE';
96
+ path: string;
97
+ } & Partial<Field>;
98
+ export declare type FieldAction = REPLACE_STATE | REMOVE | REMOVE_ROW | ADD_ROW | DUPLICATE_ROW | MOVE_ROW | MODIFY_CONDITION | UPDATE;
99
+ export declare type FormFieldsContext = [Fields, Dispatch<FieldAction>];
59
100
  export declare type Context = {
60
- dispatchFields: DispatchFields;
61
- submit: Submit;
101
+ /**
102
+ * @deprecated Form context fields may be outdated and should not be relied on. Instead, prefer `useFormFields`.
103
+ */
62
104
  fields: Fields;
63
- initialState: Fields;
105
+ submit: Submit;
106
+ dispatchFields: Dispatch<FieldAction>;
64
107
  validateForm: ValidateForm;
65
108
  createFormData: CreateFormData;
66
109
  disabled: boolean;
@@ -68,7 +111,6 @@ export declare type Context = {
68
111
  getField: GetField;
69
112
  getData: GetData;
70
113
  getSiblingData: GetSiblingData;
71
- getUnflattenedValues: GetUnflattenedValues;
72
114
  getDataByPath: GetDataByPath;
73
115
  setModified: SetModified;
74
116
  setProcessing: SetProcessing;
@@ -32,7 +32,6 @@ const Code = (props) => {
32
32
  const { value, showError, setValue, errorMessage, } = useField({
33
33
  path,
34
34
  validate: memoizedValidate,
35
- enableDebouncedValue: true,
36
35
  condition,
37
36
  });
38
37
  const classes = [
@@ -2,11 +2,10 @@ import React, { useCallback } from 'react';
2
2
  import useField from '../../useField';
3
3
  import Label from '../../Label';
4
4
  import Error from '../../Error';
5
- import { useWatchForm } from '../../Form/context';
5
+ import { useFormFields } from '../../Form/context';
6
6
  import './index.scss';
7
7
  const ConfirmPassword = () => {
8
- const { getField } = useWatchForm();
9
- const password = getField('password');
8
+ const password = useFormFields(([fields]) => fields.password);
10
9
  const validate = useCallback((value) => {
11
10
  if (!value) {
12
11
  return 'This field is required';
@@ -20,7 +19,6 @@ const ConfirmPassword = () => {
20
19
  path: 'confirm-password',
21
20
  disableFormData: true,
22
21
  validate,
23
- enableDebouncedValue: true,
24
22
  });
25
23
  const classes = [
26
24
  'field-type',
@@ -15,7 +15,6 @@ const Email = (props) => {
15
15
  const fieldType = useField({
16
16
  path,
17
17
  validate: memoizedValidate,
18
- enableDebouncedValue: true,
19
18
  condition,
20
19
  });
21
20
  const { value, showError, setValue, errorMessage, } = fieldType;
@@ -15,7 +15,6 @@ const NumberField = (props) => {
15
15
  const { value, showError, setValue, errorMessage, } = useField({
16
16
  path,
17
17
  validate: memoizedValidate,
18
- enableDebouncedValue: true,
19
18
  condition,
20
19
  });
21
20
  const handleChange = useCallback((e) => {
@@ -15,7 +15,6 @@ const Password = (props) => {
15
15
  const { value, showError, formProcessing, setValue, errorMessage, } = useField({
16
16
  path,
17
17
  validate: memoizedValidate,
18
- enableDebouncedValue: true,
19
18
  });
20
19
  const classes = [
21
20
  'field-type',
@@ -16,7 +16,6 @@ const PointField = (props) => {
16
16
  const { value = [null, null], showError, setValue, errorMessage, } = useField({
17
17
  path,
18
18
  validate: memoizedValidate,
19
- enableDebouncedValue: true,
20
19
  condition,
21
20
  });
22
21
  const handleChange = useCallback((e, index) => {
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { Props } from './types';
3
+ import './index.scss';
4
+ export declare const AddNewRelationModal: React.FC<Props>;
@@ -0,0 +1,67 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Modal, useModal } from '@faceless-ui/modal';
3
+ import { useWindowInfo } from '@faceless-ui/window-info';
4
+ import Button from '../../../../../elements/Button';
5
+ import { useAuth } from '../../../../../utilities/Auth';
6
+ import RenderCustomComponent from '../../../../../utilities/RenderCustomComponent';
7
+ import { useLocale } from '../../../../../utilities/Locale';
8
+ import { useConfig } from '../../../../../utilities/Config';
9
+ import DefaultEdit from '../../../../../views/collections/Edit/Default';
10
+ import X from '../../../../../icons/X';
11
+ import buildStateFromSchema from '../../../../Form/buildStateFromSchema';
12
+ import { EditDepthContext, useEditDepth } from '../../../../../utilities/EditDepth';
13
+ import './index.scss';
14
+ const baseClass = 'relationship-add-new-modal';
15
+ export const AddNewRelationModal = ({ modalCollection, onSave, modalSlug }) => {
16
+ var _a, _b, _c;
17
+ const { serverURL, routes: { api } } = useConfig();
18
+ const { toggleModal } = useModal();
19
+ const { breakpoints: { m: midBreak } } = useWindowInfo();
20
+ const locale = useLocale();
21
+ const { permissions, user } = useAuth();
22
+ const [initialState, setInitialState] = useState();
23
+ const [isAnimated, setIsAnimated] = useState(false);
24
+ const editDepth = useEditDepth();
25
+ const modalAction = `${serverURL}${api}/${modalCollection.slug}?locale=${locale}&depth=0&fallback-locale=null`;
26
+ useEffect(() => {
27
+ const buildState = async () => {
28
+ const state = await buildStateFromSchema({ fieldSchema: modalCollection.fields, data: {}, user, operation: 'create', locale });
29
+ setInitialState(state);
30
+ };
31
+ buildState();
32
+ }, [modalCollection, locale, user]);
33
+ useEffect(() => {
34
+ setIsAnimated(true);
35
+ }, []);
36
+ return (React.createElement(Modal, { slug: modalSlug, className: [
37
+ baseClass,
38
+ isAnimated && `${baseClass}--animated`,
39
+ ].filter(Boolean).join(' ') },
40
+ editDepth === 1 && (React.createElement("div", { className: `${baseClass}__blur-bg` })),
41
+ React.createElement(EditDepthContext.Provider, { value: editDepth + 1 },
42
+ React.createElement("button", { className: `${baseClass}__close`, type: "button", onClick: () => toggleModal(modalSlug), style: {
43
+ width: `calc(${midBreak ? 'var(--gutter-h)' : 'var(--nav-width)'} + ${editDepth - 1} * 25px)`,
44
+ } },
45
+ React.createElement("span", null, "Close")),
46
+ React.createElement(RenderCustomComponent, { DefaultComponent: DefaultEdit, CustomComponent: (_c = (_b = (_a = modalCollection.admin) === null || _a === void 0 ? void 0 : _a.components) === null || _b === void 0 ? void 0 : _b.views) === null || _c === void 0 ? void 0 : _c.Edit, componentProps: {
47
+ isLoading: !initialState,
48
+ data: {},
49
+ collection: modalCollection,
50
+ permissions: permissions.collections[modalCollection.slug],
51
+ isEditing: false,
52
+ onSave,
53
+ initialState,
54
+ hasSavePermission: true,
55
+ action: modalAction,
56
+ disableEyebrow: true,
57
+ disableActions: true,
58
+ disableLeaveWithoutSaving: true,
59
+ customHeader: (React.createElement("div", { className: `${baseClass}__header` },
60
+ React.createElement("h2", null,
61
+ "Add new",
62
+ ' ',
63
+ modalCollection.labels.singular),
64
+ React.createElement(Button, { buttonStyle: "none", className: `${baseClass}__header-close`, onClick: () => toggleModal(modalSlug) },
65
+ React.createElement(X, null)))),
66
+ } }))));
67
+ };