payload 1.1.19 → 1.1.21

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/README.md CHANGED
@@ -16,7 +16,7 @@
16
16
  </a>
17
17
 
18
18
  <a href="https://discord.com/invite/r6sCXqVk3v">
19
- <img alt="Discord" src="https://img.shields.io/discord/967097582721572934?label=Discord" />
19
+ <img alt="Discord" src="https://img.shields.io/discord/967097582721572934?label=Discord&color=7289da" />
20
20
  </a>
21
21
  </p>
22
22
 
@@ -68,6 +68,7 @@ Alternatively, it only takes about five minutes to [create an app from scratch](
68
68
  ### Documentation
69
69
 
70
70
  Check out the [Payload website](https://payloadcms.com/docs/getting-started/what-is-payload) to find in-depth documentation for everything that Payload offers.
71
+
71
72
  ### Contributing
72
73
 
73
74
  If you want to add contributions to this repository, please follow the instructions in [contributing.md](./contributing.md).
@@ -62,6 +62,10 @@ function fieldReducer(state, action) {
62
62
  const flattenedRowState = unflattenedRows.length > 0 ? flatten({ [path]: unflattenedRows }, { filters: flattenFilters }) : {};
63
63
  return {
64
64
  ...remainingFlattenedState,
65
+ [path]: {
66
+ ...(state[path] || {}),
67
+ disableFormData: unflattenedRows.length > 0,
68
+ },
65
69
  ...flattenedRowState,
66
70
  };
67
71
  }
@@ -82,6 +86,11 @@ function fieldReducer(state, action) {
82
86
  }
83
87
  const newState = {
84
88
  ...remainingFlattenedState,
89
+ [path]: {
90
+ ...(state[path] || {}),
91
+ value: unflattenedRows.length,
92
+ disableFormData: true,
93
+ },
85
94
  ...(flatten({ [path]: unflattenedRows }, { filters: flattenFilters })),
86
95
  };
87
96
  return newState;
@@ -99,6 +108,11 @@ function fieldReducer(state, action) {
99
108
  }
100
109
  const newState = {
101
110
  ...remainingFlattenedState,
111
+ [path]: {
112
+ ...(state[path] || {}),
113
+ value: unflattenedRows.length,
114
+ disableFormData: true,
115
+ },
102
116
  ...(flatten({ [path]: unflattenedRows }, { filters: flattenFilters })),
103
117
  };
104
118
  return newState;
@@ -51,33 +51,34 @@ const ArrayFieldType = (props) => {
51
51
  const memoizedValidate = useCallback((value, options) => {
52
52
  return validate(value, { ...options, minRows, maxRows, required });
53
53
  }, [maxRows, minRows, required, validate]);
54
- const { showError, errorMessage, value, setValue, } = useField({
54
+ const { showError, errorMessage, value, } = useField({
55
55
  path,
56
56
  validate: memoizedValidate,
57
57
  condition,
58
+ disableFormData: (rows === null || rows === void 0 ? void 0 : rows.length) > 0,
58
59
  });
59
60
  const addRow = useCallback(async (rowIndex) => {
60
61
  const subFieldState = await buildStateFromSchema({ fieldSchema: fields, operation, id, user, locale });
61
62
  dispatchFields({ type: 'ADD_ROW', rowIndex, subFieldState, path });
62
63
  dispatchRows({ type: 'ADD', rowIndex });
63
- setValue(value + 1);
64
+ setModified(true);
64
65
  setTimeout(() => {
65
66
  scrollToID(`${path}-row-${rowIndex + 1}`);
66
67
  }, 0);
67
- }, [dispatchRows, dispatchFields, fields, path, setValue, value, operation, id, user, locale]);
68
+ }, [dispatchRows, dispatchFields, fields, path, operation, id, user, locale, setModified]);
68
69
  const duplicateRow = useCallback(async (rowIndex) => {
69
70
  dispatchFields({ type: 'DUPLICATE_ROW', rowIndex, path });
70
71
  dispatchRows({ type: 'ADD', rowIndex });
71
- setValue(value + 1);
72
+ setModified(true);
72
73
  setTimeout(() => {
73
74
  scrollToID(`${path}-row-${rowIndex + 1}`);
74
75
  }, 0);
75
- }, [dispatchRows, dispatchFields, path, setValue, value]);
76
+ }, [dispatchRows, dispatchFields, path, setModified]);
76
77
  const removeRow = useCallback((rowIndex) => {
77
78
  dispatchRows({ type: 'REMOVE', rowIndex });
78
79
  dispatchFields({ type: 'REMOVE_ROW', rowIndex, path });
79
- setValue(value - 1);
80
- }, [dispatchRows, dispatchFields, path, value, setValue]);
80
+ setModified(true);
81
+ }, [dispatchRows, dispatchFields, path, setModified]);
81
82
  const moveRow = useCallback((moveFromIndex, moveToIndex) => {
82
83
  dispatchRows({ type: 'MOVE', moveFromIndex, moveToIndex });
83
84
  dispatchFields({ type: 'MOVE_ROW', moveFromIndex, moveToIndex, path });
@@ -146,17 +147,6 @@ const ArrayFieldType = (props) => {
146
147
  };
147
148
  initializeRowState();
148
149
  }, [formContext, path, getPreference, preferencesKey, initCollapsed]);
149
- useEffect(() => {
150
- if (typeof rows !== 'undefined') {
151
- const disableFormData = rows.length > 0;
152
- dispatchFields({
153
- type: 'UPDATE',
154
- path,
155
- disableFormData,
156
- value: rows.length,
157
- });
158
- }
159
- }, [rows, dispatchFields, path]);
160
150
  const hasMaxRows = maxRows && (rows === null || rows === void 0 ? void 0 : rows.length) >= maxRows;
161
151
  const classes = [
162
152
  'field-type',
@@ -44,14 +44,15 @@ const BlocksField = (props) => {
44
44
  const locale = useLocale();
45
45
  const operation = useOperation();
46
46
  const { dispatchFields, setModified } = formContext;
47
+ const [selectorIndexOpen, setSelectorIndexOpen] = useState();
47
48
  const memoizedValidate = useCallback((value, options) => {
48
49
  return validate(value, { ...options, minRows, maxRows, required });
49
50
  }, [maxRows, minRows, required, validate]);
50
- const [selectorIndexOpen, setSelectorIndexOpen] = useState();
51
- const { showError, errorMessage, value, setValue, } = useField({
51
+ const { showError, errorMessage, value, } = useField({
52
52
  path,
53
53
  validate: memoizedValidate,
54
54
  condition,
55
+ disableFormData: (rows === null || rows === void 0 ? void 0 : rows.length) > 0,
55
56
  });
56
57
  const onAddPopupToggle = useCallback((open) => {
57
58
  if (!open) {
@@ -63,24 +64,24 @@ const BlocksField = (props) => {
63
64
  const subFieldState = await buildStateFromSchema({ fieldSchema: block.fields, operation, id, user, locale });
64
65
  dispatchFields({ type: 'ADD_ROW', rowIndex, subFieldState, path, blockType });
65
66
  dispatchRows({ type: 'ADD', rowIndex, blockType });
66
- setValue(value + 1);
67
+ setModified(true);
67
68
  setTimeout(() => {
68
69
  scrollToID(`${path}-row-${rowIndex + 1}`);
69
70
  }, 0);
70
- }, [path, setValue, value, blocks, dispatchFields, operation, id, user, locale]);
71
+ }, [path, blocks, dispatchFields, operation, id, user, locale, setModified]);
71
72
  const duplicateRow = useCallback(async (rowIndex, blockType) => {
72
73
  dispatchFields({ type: 'DUPLICATE_ROW', rowIndex, path });
73
74
  dispatchRows({ type: 'ADD', rowIndex, blockType });
74
- setValue(value + 1);
75
+ setModified(true);
75
76
  setTimeout(() => {
76
77
  scrollToID(`${path}-row-${rowIndex + 1}`);
77
78
  }, 0);
78
- }, [dispatchRows, dispatchFields, path, setValue, value]);
79
+ }, [dispatchRows, dispatchFields, path, setModified]);
79
80
  const removeRow = useCallback((rowIndex) => {
80
81
  dispatchRows({ type: 'REMOVE', rowIndex });
81
82
  dispatchFields({ type: 'REMOVE_ROW', rowIndex, path });
82
- setValue(value - 1);
83
- }, [path, setValue, value, dispatchFields]);
83
+ setModified(true);
84
+ }, [path, dispatchFields, setModified]);
84
85
  const moveRow = useCallback((moveFromIndex, moveToIndex) => {
85
86
  dispatchRows({ type: 'MOVE', moveFromIndex, moveToIndex });
86
87
  dispatchFields({ type: 'MOVE_ROW', moveFromIndex, moveToIndex, path });
@@ -150,17 +151,6 @@ const BlocksField = (props) => {
150
151
  };
151
152
  initializeRowState();
152
153
  }, [formContext, path, getPreference, preferencesKey, initCollapsed]);
153
- useEffect(() => {
154
- if (typeof rows !== 'undefined') {
155
- const disableFormData = rows.length > 0;
156
- dispatchFields({
157
- type: 'UPDATE',
158
- path,
159
- disableFormData,
160
- value: rows.length,
161
- });
162
- }
163
- }, [rows, dispatchFields, path]);
164
154
  const hasMaxRows = maxRows && (rows === null || rows === void 0 ? void 0 : rows.length) >= maxRows;
165
155
  const classes = [
166
156
  'field-type',
@@ -8,7 +8,7 @@ keywords: overview, config, configuration, documentation, Content Management Sys
8
8
 
9
9
  Payload is a *config-based*, code-first CMS and application framework. The Payload config is central to everything that Payload does. It scaffolds the data that Payload stores as well as maintains custom React components, hook logic, custom validations, and much more. The config itself and all of its dependencies are run through Babel, so you can take full advantage of newer JavaScript features and even directly import React components containing JSX.
10
10
 
11
- <strong>Also, because the Payload source code is fully written in TypeScript, its configs are strongly typed—meaning that even if you aren't using TypeScript to build your project, your IDE (such as VSCode) may still provide helpful information like type-ahead suggestions while you write your config.</strong>
11
+ **Also, because the Payload source code is fully written in TypeScript, its configs are strongly typed—meaning that even if you aren't using TypeScript to build your project, your IDE (such as VSCode) may still provide helpful information like type-ahead suggestions while you write your config.**
12
12
 
13
13
  <Banner type="warning">
14
14
  <strong>Important:</strong><br />This file is included in the Payload admin bundle, so make sure you do not embed any sensitive information.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload",
3
- "version": "1.1.19",
3
+ "version": "1.1.21",
4
4
  "description": "Node, React and MongoDB Headless CMS and Application Framework",
5
5
  "license": "MIT",
6
6
  "engines": {