payload 1.1.7 → 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/forms.ts +10 -0
- package/dist/admin/components/elements/Autosave/index.js +3 -3
- package/dist/admin/components/elements/Nav/index.scss +1 -5
- package/dist/admin/components/elements/ReactSelect/index.scss +5 -1
- package/dist/admin/components/forms/Form/context.d.ts +5 -2
- package/dist/admin/components/forms/Form/context.js +9 -2
- package/dist/admin/components/forms/Form/fieldReducer.d.ts +2 -2
- package/dist/admin/components/forms/Form/fieldReducer.js +4 -1
- package/dist/admin/components/forms/Form/getSiblingData.js +11 -5
- package/dist/admin/components/forms/Form/index.js +12 -12
- package/dist/admin/components/forms/Form/initContextState.js +0 -3
- package/dist/admin/components/forms/Form/reduceFieldsToValues.js +6 -3
- package/dist/admin/components/forms/Form/types.d.ts +49 -7
- package/dist/admin/components/forms/field-types/Code/Code.js +0 -1
- package/dist/admin/components/forms/field-types/ConfirmPassword/index.js +2 -4
- package/dist/admin/components/forms/field-types/Email/index.js +0 -1
- package/dist/admin/components/forms/field-types/Number/index.js +0 -1
- package/dist/admin/components/forms/field-types/Password/index.js +0 -1
- package/dist/admin/components/forms/field-types/Point/index.js +0 -1
- package/dist/admin/components/forms/field-types/Relationship/AddNew/Modal/index.d.ts +4 -0
- package/dist/admin/components/forms/field-types/Relationship/AddNew/Modal/index.js +67 -0
- package/dist/admin/components/forms/field-types/Relationship/AddNew/Modal/index.scss +117 -0
- package/dist/admin/components/forms/field-types/Relationship/AddNew/Modal/types.d.ts +6 -0
- package/dist/admin/components/forms/field-types/Relationship/AddNew/Modal/types.js +1 -0
- package/dist/admin/components/forms/field-types/Relationship/AddNew/index.d.ts +4 -0
- package/dist/admin/components/forms/field-types/Relationship/AddNew/index.js +79 -0
- package/dist/admin/components/forms/field-types/Relationship/AddNew/index.scss +60 -0
- package/dist/admin/components/forms/field-types/Relationship/AddNew/types.d.ts +10 -0
- package/dist/admin/components/forms/field-types/Relationship/AddNew/types.js +1 -0
- package/dist/admin/components/forms/field-types/Relationship/AddNew/useRelatedCollections.d.ts +2 -0
- package/dist/admin/components/forms/field-types/Relationship/AddNew/useRelatedCollections.js +10 -0
- package/dist/admin/components/forms/field-types/Relationship/index.js +57 -45
- package/dist/admin/components/forms/field-types/Relationship/index.scss +15 -12
- package/dist/admin/components/forms/field-types/Relationship/optionsReducer.js +8 -7
- package/dist/admin/components/forms/field-types/Relationship/types.d.ts +1 -3
- package/dist/admin/components/forms/field-types/RichText/elements/relationship/Button/Fields/index.js +2 -3
- package/dist/admin/components/forms/field-types/Select/index.scss +1 -9
- package/dist/admin/components/forms/field-types/Text/index.js +0 -1
- package/dist/admin/components/forms/field-types/Textarea/index.js +0 -1
- package/dist/admin/components/forms/field-types/Upload/SelectExisting/index.js +2 -2
- package/dist/admin/components/forms/useField/index.js +71 -97
- package/dist/admin/components/forms/useField/types.d.ts +0 -2
- package/dist/admin/components/forms/withCondition/index.js +10 -5
- package/dist/admin/components/modals/LeaveWithoutSaving/index.scss +2 -2
- package/dist/admin/components/templates/Default/index.scss +1 -1
- package/dist/admin/components/utilities/EditDepth/index.d.ts +3 -0
- package/dist/admin/components/utilities/EditDepth/index.js +3 -0
- package/dist/admin/components/views/collections/Edit/Auth/APIKey.js +2 -3
- package/dist/admin/components/views/collections/Edit/Auth/index.js +3 -3
- package/dist/admin/components/views/collections/Edit/Default.js +9 -9
- package/dist/admin/components/views/collections/Edit/index.js +15 -12
- package/dist/admin/components/views/collections/Edit/types.d.ts +6 -0
- package/dist/admin/hooks/useTitle.js +2 -3
- package/dist/admin/index.js +1 -1
- package/dist/admin/scss/app.scss +6 -1
- package/dist/collections/config/defaults.d.ts +5 -5
- package/dist/config/types.d.ts +6 -1
- package/dist/express/types.d.ts +2 -2
- package/dist/fields/config/types.d.ts +2 -2
- package/docs/admin/components.mdx +3 -45
- package/docs/admin/customizing-css.mdx +1 -1
- package/docs/admin/hooks.mdx +271 -0
- package/docs/admin/preferences.mdx +1 -1
- package/docs/admin/webpack.mdx +1 -1
- package/docs/local-api/overview.mdx +1 -1
- package/package.json +2 -1
- package/types.d.ts +4 -0
package/components/forms.ts
CHANGED
|
@@ -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';
|
|
@@ -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 {
|
|
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
|
|
17
|
+
const [fields] = useAllFormFields();
|
|
18
18
|
const modified = useFormModified();
|
|
19
19
|
const locale = useLocale();
|
|
20
20
|
const { replace } = useHistory();
|
|
@@ -98,7 +98,7 @@ const Autosave = ({ collection, global, id, publishedDocUpdatedAt }) => {
|
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
100
|
autosave();
|
|
101
|
-
}, [debouncedFields, modified, serverURL, api, collection, global, id,
|
|
101
|
+
}, [debouncedFields, modified, serverURL, api, collection, global, id, getVersions, locale]);
|
|
102
102
|
useEffect(() => {
|
|
103
103
|
var _a;
|
|
104
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:
|
|
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;
|
|
@@ -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
|
-
|
|
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.
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
45
|
-
|
|
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 },
|
|
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
|
-
|
|
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
|
|
12
|
+
return (0, flatley_1.unflatten)(data, { safe: true });
|
|
11
13
|
}
|
|
12
14
|
return data;
|
|
13
15
|
};
|
|
14
|
-
|
|
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
|
-
|
|
61
|
-
|
|
101
|
+
/**
|
|
102
|
+
* @deprecated Form context fields may be outdated and should not be relied on. Instead, prefer `useFormFields`.
|
|
103
|
+
*/
|
|
62
104
|
fields: Fields;
|
|
63
|
-
|
|
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;
|
|
@@ -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 {
|
|
5
|
+
import { useFormFields } from '../../Form/context';
|
|
6
6
|
import './index.scss';
|
|
7
7
|
const ConfirmPassword = () => {
|
|
8
|
-
const
|
|
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',
|
|
@@ -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
|
+
};
|