@payloadcms/ui 3.34.0-canary.5 → 3.34.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 (58) hide show
  1. package/dist/elements/PublishButton/ScheduleDrawer/index.d.ts +2 -0
  2. package/dist/elements/PublishButton/ScheduleDrawer/index.d.ts.map +1 -1
  3. package/dist/elements/PublishButton/ScheduleDrawer/index.js +5 -3
  4. package/dist/elements/PublishButton/ScheduleDrawer/index.js.map +1 -1
  5. package/dist/elements/PublishButton/index.d.ts.map +1 -1
  6. package/dist/elements/PublishButton/index.js +127 -302
  7. package/dist/elements/PublishButton/index.js.map +1 -1
  8. package/dist/elements/Table/OrderableTable.js +0 -1
  9. package/dist/elements/Table/OrderableTable.js.map +1 -1
  10. package/dist/elements/Table/index.d.ts.map +1 -1
  11. package/dist/elements/Table/index.js +1 -1
  12. package/dist/elements/Table/index.js.map +1 -1
  13. package/dist/elements/WhereBuilder/Condition/DefaultFilter/index.js.map +1 -1
  14. package/dist/elements/WhereBuilder/Condition/Text/index.d.ts.map +1 -1
  15. package/dist/elements/WhereBuilder/Condition/Text/index.js +102 -17
  16. package/dist/elements/WhereBuilder/Condition/Text/index.js.map +1 -1
  17. package/dist/elements/WhereBuilder/Condition/Text/types.d.ts +1 -1
  18. package/dist/elements/WhereBuilder/Condition/Text/types.d.ts.map +1 -1
  19. package/dist/elements/WhereBuilder/Condition/Text/types.js.map +1 -1
  20. package/dist/exports/client/index.d.ts +3 -0
  21. package/dist/exports/client/index.d.ts.map +1 -1
  22. package/dist/exports/client/index.js +23 -23
  23. package/dist/exports/client/index.js.map +4 -4
  24. package/dist/forms/Form/fieldReducer.d.ts.map +1 -1
  25. package/dist/forms/Form/fieldReducer.js +16 -0
  26. package/dist/forms/Form/fieldReducer.js.map +1 -1
  27. package/dist/forms/Form/index.d.ts.map +1 -1
  28. package/dist/forms/Form/index.js +37 -54
  29. package/dist/forms/Form/index.js.map +1 -1
  30. package/dist/forms/Form/mergeServerFormState.d.ts +8 -9
  31. package/dist/forms/Form/mergeServerFormState.d.ts.map +1 -1
  32. package/dist/forms/Form/mergeServerFormState.js +50 -101
  33. package/dist/forms/Form/mergeServerFormState.js.map +1 -1
  34. package/dist/forms/Form/types.d.ts +7 -1
  35. package/dist/forms/Form/types.d.ts.map +1 -1
  36. package/dist/forms/Form/types.js.map +1 -1
  37. package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts.map +1 -1
  38. package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js +16 -5
  39. package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js.map +1 -1
  40. package/dist/forms/fieldSchemasToFormState/index.d.ts.map +1 -1
  41. package/dist/forms/fieldSchemasToFormState/index.js.map +1 -1
  42. package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts.map +1 -1
  43. package/dist/forms/fieldSchemasToFormState/iterateFields.js.map +1 -1
  44. package/dist/forms/fieldSchemasToFormState/renderField.js +1 -1
  45. package/dist/forms/fieldSchemasToFormState/renderField.js.map +1 -1
  46. package/dist/styles.css +1 -1
  47. package/dist/utilities/renderTable.d.ts.map +1 -1
  48. package/dist/utilities/renderTable.js +1 -5
  49. package/dist/utilities/renderTable.js.map +1 -1
  50. package/package.json +4 -4
  51. package/dist/forms/Form/mergeErrorPaths.d.ts +0 -5
  52. package/dist/forms/Form/mergeErrorPaths.d.ts.map +0 -1
  53. package/dist/forms/Form/mergeErrorPaths.js +0 -30
  54. package/dist/forms/Form/mergeErrorPaths.js.map +0 -1
  55. package/dist/utilities/arraysHaveSameStrings.d.ts +0 -2
  56. package/dist/utilities/arraysHaveSameStrings.d.ts.map +0 -1
  57. package/dist/utilities/arraysHaveSameStrings.js +0 -17
  58. package/dist/utilities/arraysHaveSameStrings.js.map +0 -1
@@ -1,119 +1,68 @@
1
1
  'use client';
2
2
 
3
3
  import { dequal } from 'dequal/lite'; // lite: no need for Map and Set support
4
- import { mergeErrorPaths } from './mergeErrorPaths.js';
5
4
  /**
6
- * Merges certain properties from the server state into the client state. These do not include values,
7
- * as we do not want to update them on the client like that, which would cause flickering.
5
+ * This function receives form state from the server and intelligently merges it into the client state.
6
+ * The server contains extra properties that the client may not have, e.g. custom components and error states.
7
+ * We typically do not want to merge properties that rely on user input, however, such as values, unless explicitly requested.
8
+ * Doing this would cause the client to lose any local changes to those fields.
8
9
  *
9
- * We want to use this to update the error state, and other properties that are not user input, as the error state
10
- * is the thing we want to keep in sync with the server (where it's calculated) on the client.
10
+ * This function will also a few defaults, as well as clean up the server response in preparation for the client.
11
+ * e.g. it will set `valid` and `passesCondition` to true if undefined, and remove `addedByServer` from the response.
11
12
  */
12
13
  export const mergeServerFormState = ({
13
14
  acceptValues,
14
- existingState,
15
+ currentState = {},
15
16
  incomingState
16
17
  }) => {
17
- let changed = false;
18
- const newState = {};
19
- if (existingState) {
20
- const serverPropsToAccept = ['passesCondition', 'valid', 'errorMessage', 'errorPaths', 'customComponents'];
21
- if (acceptValues) {
22
- serverPropsToAccept.push('value');
23
- serverPropsToAccept.push('initialValue');
18
+ const newState = {
19
+ ...currentState
20
+ };
21
+ for (const [path, incomingField] of Object.entries(incomingState || {})) {
22
+ if (!(path in currentState) && !incomingField.addedByServer) {
23
+ continue;
24
24
  }
25
- for (const [path, newFieldState] of Object.entries(existingState)) {
26
- if (!incomingState[path]) {
27
- continue;
28
- }
29
- let fieldChanged = false;
30
- /**
31
- * Handle error paths
32
- */
33
- const errorPathsResult = mergeErrorPaths(newFieldState.errorPaths, incomingState[path].errorPaths);
34
- if (errorPathsResult.result) {
35
- if (errorPathsResult.changed) {
36
- changed = errorPathsResult.changed;
37
- }
38
- newFieldState.errorPaths = errorPathsResult.result;
39
- }
40
- /**
41
- * Handle filterOptions
42
- */
43
- if (incomingState[path]?.filterOptions || newFieldState.filterOptions) {
44
- if (!dequal(incomingState[path]?.filterOptions, newFieldState.filterOptions)) {
45
- changed = true;
46
- fieldChanged = true;
47
- newFieldState.filterOptions = incomingState[path].filterOptions;
48
- }
49
- }
50
- /**
51
- * Need to intelligently merge the rows array to ensure changes to local state are not lost while the request was pending
52
- * For example, the server response could come back with a row which has been deleted on the client
53
- * Loop over the incoming rows, if it exists in client side form state, merge in any new properties from the server
54
- */
55
- if (Array.isArray(incomingState[path].rows)) {
56
- incomingState[path].rows.forEach(row => {
57
- const matchedExistingRowIndex = newFieldState.rows.findIndex(existingRow => existingRow.id === row.id);
58
- if (matchedExistingRowIndex > -1) {
59
- newFieldState.rows[matchedExistingRowIndex] = {
60
- ...newFieldState.rows[matchedExistingRowIndex],
61
- ...row
62
- };
63
- }
64
- });
65
- }
66
- /**
67
- * Handle adding all the remaining props that should be updated in the local form state from the server form state
68
- */
69
- serverPropsToAccept.forEach(propFromServer => {
70
- if (!dequal(incomingState[path]?.[propFromServer], newFieldState[propFromServer])) {
71
- changed = true;
72
- fieldChanged = true;
73
- if (newFieldState?.serverPropsToIgnore?.includes(propFromServer)) {
74
- // Remove the ignored prop for the next request
75
- newFieldState.serverPropsToIgnore = newFieldState.serverPropsToIgnore.filter(prop => prop !== propFromServer);
76
- // if no keys left, remove the entire object
77
- if (!newFieldState.serverPropsToIgnore.length) {
78
- delete newFieldState.serverPropsToIgnore;
79
- }
80
- return;
81
- }
82
- if (!(propFromServer in incomingState[path])) {
83
- // Regarding excluding the customComponents prop from being deleted: the incoming state might not have been rendered, as rendering components for every form onchange is expensive.
84
- // Thus, we simply re-use the initial render state
85
- if (propFromServer !== 'customComponents') {
86
- delete newFieldState[propFromServer];
87
- }
88
- } else {
89
- newFieldState[propFromServer] = incomingState[path][propFromServer];
90
- }
25
+ if (!acceptValues && !incomingField.addedByServer) {
26
+ delete incomingField.value;
27
+ delete incomingField.initialValue;
28
+ }
29
+ newState[path] = {
30
+ ...currentState[path],
31
+ ...incomingField
32
+ };
33
+ /**
34
+ * Intelligently merge the rows array to ensure changes to local state are not lost while the request was pending
35
+ * For example, the server response could come back with a row which has been deleted on the client
36
+ * Loop over the incoming rows, if it exists in client side form state, merge in any new properties from the server
37
+ * Note: read `currentState` and not `newState` here, as the `rows` property have already been merged above
38
+ */
39
+ if (Array.isArray(incomingField.rows) && path in currentState) {
40
+ newState[path].rows = [...(currentState[path]?.rows || [])] // shallow copy to avoid mutating the original array
41
+ ;
42
+ incomingField.rows.forEach(row => {
43
+ const indexInCurrentState = currentState[path].rows.findIndex(existingRow => existingRow.id === row.id);
44
+ if (indexInCurrentState > -1) {
45
+ newState[path].rows[indexInCurrentState] = {
46
+ ...currentState[path].rows[indexInCurrentState],
47
+ ...row
48
+ };
91
49
  }
92
50
  });
93
- if (newFieldState.valid !== false) {
94
- newFieldState.valid = true;
95
- }
96
- if (newFieldState.passesCondition !== false) {
97
- newFieldState.passesCondition = true;
98
- }
99
- // Conditions don't work if we don't memcopy the new state, as the object references would otherwise be the same
100
- newState[path] = fieldChanged ? {
101
- ...newFieldState
102
- } : newFieldState;
103
51
  }
104
- // Now loop over values that are part of incoming state but not part of existing state, and add them to the new state.
105
- // This can happen if a new array row was added. In our local state, we simply add out stubbed `array` and `array.[index].id` entries to the local form state.
106
- // However, all other array sub-fields are not added to the local state - those will be added by the server and may be incoming here.
107
- for (const [path, field] of Object.entries(incomingState)) {
108
- if (!existingState[path]) {
109
- changed = true;
110
- newState[path] = field;
111
- }
52
+ // If `valid` is `undefined`, mark it as `true`
53
+ if (incomingField.valid !== false) {
54
+ newState[path].valid = true;
55
+ }
56
+ // If `passesCondition` is `undefined`, mark it as `true`
57
+ if (incomingField.passesCondition !== false) {
58
+ newState[path].passesCondition = true;
112
59
  }
60
+ // Strip away the `addedByServer` property from the client
61
+ // This will prevent it from being passed back to the server
62
+ delete newState[path].addedByServer;
113
63
  }
114
- return {
115
- changed,
116
- newState
117
- };
64
+ // Return the original object reference if the state is unchanged
65
+ // This will avoid unnecessary re-renders and dependency updates
66
+ return dequal(newState, currentState) ? currentState : newState;
118
67
  };
119
68
  //# sourceMappingURL=mergeServerFormState.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mergeServerFormState.js","names":["dequal","mergeErrorPaths","mergeServerFormState","acceptValues","existingState","incomingState","changed","newState","serverPropsToAccept","push","path","newFieldState","Object","entries","fieldChanged","errorPathsResult","errorPaths","result","filterOptions","Array","isArray","rows","forEach","row","matchedExistingRowIndex","findIndex","existingRow","id","propFromServer","serverPropsToIgnore","includes","filter","prop","length","valid","passesCondition","field"],"sources":["../../../src/forms/Form/mergeServerFormState.ts"],"sourcesContent":["'use client'\nimport type { FieldState, FormState } from 'payload'\n\nimport { dequal } from 'dequal/lite' // lite: no need for Map and Set support\n\nimport { mergeErrorPaths } from './mergeErrorPaths.js'\n\ntype Args = {\n acceptValues?: boolean\n existingState: FormState\n incomingState: FormState\n}\n\n/**\n * Merges certain properties from the server state into the client state. These do not include values,\n * as we do not want to update them on the client like that, which would cause flickering.\n *\n * We want to use this to update the error state, and other properties that are not user input, as the error state\n * is the thing we want to keep in sync with the server (where it's calculated) on the client.\n */\nexport const mergeServerFormState = ({\n acceptValues,\n existingState,\n incomingState,\n}: Args): { changed: boolean; newState: FormState } => {\n let changed = false\n\n const newState = {}\n\n if (existingState) {\n const serverPropsToAccept: Array<keyof FieldState> = [\n 'passesCondition',\n 'valid',\n 'errorMessage',\n 'errorPaths',\n 'customComponents',\n ]\n\n if (acceptValues) {\n serverPropsToAccept.push('value')\n serverPropsToAccept.push('initialValue')\n }\n\n for (const [path, newFieldState] of Object.entries(existingState)) {\n if (!incomingState[path]) {\n continue\n }\n\n let fieldChanged = false\n\n /**\n * Handle error paths\n */\n const errorPathsResult = mergeErrorPaths(\n newFieldState.errorPaths,\n incomingState[path].errorPaths as unknown as string[],\n )\n\n if (errorPathsResult.result) {\n if (errorPathsResult.changed) {\n changed = errorPathsResult.changed\n }\n newFieldState.errorPaths = errorPathsResult.result\n }\n\n /**\n * Handle filterOptions\n */\n if (incomingState[path]?.filterOptions || newFieldState.filterOptions) {\n if (!dequal(incomingState[path]?.filterOptions, newFieldState.filterOptions)) {\n changed = true\n fieldChanged = true\n newFieldState.filterOptions = incomingState[path].filterOptions\n }\n }\n\n /**\n * Need to intelligently merge the rows array to ensure changes to local state are not lost while the request was pending\n * For example, the server response could come back with a row which has been deleted on the client\n * Loop over the incoming rows, if it exists in client side form state, merge in any new properties from the server\n */\n if (Array.isArray(incomingState[path].rows)) {\n incomingState[path].rows.forEach((row) => {\n const matchedExistingRowIndex = newFieldState.rows.findIndex(\n (existingRow) => existingRow.id === row.id,\n )\n\n if (matchedExistingRowIndex > -1) {\n newFieldState.rows[matchedExistingRowIndex] = {\n ...newFieldState.rows[matchedExistingRowIndex],\n ...row,\n }\n }\n })\n }\n\n /**\n * Handle adding all the remaining props that should be updated in the local form state from the server form state\n */\n serverPropsToAccept.forEach((propFromServer) => {\n if (!dequal(incomingState[path]?.[propFromServer], newFieldState[propFromServer])) {\n changed = true\n fieldChanged = true\n\n if (newFieldState?.serverPropsToIgnore?.includes(propFromServer)) {\n // Remove the ignored prop for the next request\n newFieldState.serverPropsToIgnore = newFieldState.serverPropsToIgnore.filter(\n (prop) => prop !== propFromServer,\n )\n\n // if no keys left, remove the entire object\n if (!newFieldState.serverPropsToIgnore.length) {\n delete newFieldState.serverPropsToIgnore\n }\n\n return\n }\n\n if (!(propFromServer in incomingState[path])) {\n // Regarding excluding the customComponents prop from being deleted: the incoming state might not have been rendered, as rendering components for every form onchange is expensive.\n // Thus, we simply re-use the initial render state\n if (propFromServer !== 'customComponents') {\n delete newFieldState[propFromServer]\n }\n } else {\n newFieldState[propFromServer as any] = incomingState[path][propFromServer]\n }\n }\n })\n\n if (newFieldState.valid !== false) {\n newFieldState.valid = true\n }\n\n if (newFieldState.passesCondition !== false) {\n newFieldState.passesCondition = true\n }\n\n // Conditions don't work if we don't memcopy the new state, as the object references would otherwise be the same\n newState[path] = fieldChanged ? { ...newFieldState } : newFieldState\n }\n\n // Now loop over values that are part of incoming state but not part of existing state, and add them to the new state.\n // This can happen if a new array row was added. In our local state, we simply add out stubbed `array` and `array.[index].id` entries to the local form state.\n // However, all other array sub-fields are not added to the local state - those will be added by the server and may be incoming here.\n for (const [path, field] of Object.entries(incomingState)) {\n if (!existingState[path]) {\n changed = true\n newState[path] = field\n }\n }\n }\n\n return { changed, newState }\n}\n"],"mappings":"AAAA;;AAGA,SAASA,MAAM,QAAQ,cAAa,CAAC;AAErC,SAASC,eAAe,QAAQ;AAQhC;;;;;;;AAOA,OAAO,MAAMC,oBAAA,GAAuBA,CAAC;EACnCC,YAAY;EACZC,aAAa;EACbC;AAAa,CACR;EACL,IAAIC,OAAA,GAAU;EAEd,MAAMC,QAAA,GAAW,CAAC;EAElB,IAAIH,aAAA,EAAe;IACjB,MAAMI,mBAAA,GAA+C,CACnD,mBACA,SACA,gBACA,cACA,mBACD;IAED,IAAIL,YAAA,EAAc;MAChBK,mBAAA,CAAoBC,IAAI,CAAC;MACzBD,mBAAA,CAAoBC,IAAI,CAAC;IAC3B;IAEA,KAAK,MAAM,CAACC,IAAA,EAAMC,aAAA,CAAc,IAAIC,MAAA,CAAOC,OAAO,CAACT,aAAA,GAAgB;MACjE,IAAI,CAACC,aAAa,CAACK,IAAA,CAAK,EAAE;QACxB;MACF;MAEA,IAAII,YAAA,GAAe;MAEnB;;;MAGA,MAAMC,gBAAA,GAAmBd,eAAA,CACvBU,aAAA,CAAcK,UAAU,EACxBX,aAAa,CAACK,IAAA,CAAK,CAACM,UAAU;MAGhC,IAAID,gBAAA,CAAiBE,MAAM,EAAE;QAC3B,IAAIF,gBAAA,CAAiBT,OAAO,EAAE;UAC5BA,OAAA,GAAUS,gBAAA,CAAiBT,OAAO;QACpC;QACAK,aAAA,CAAcK,UAAU,GAAGD,gBAAA,CAAiBE,MAAM;MACpD;MAEA;;;MAGA,IAAIZ,aAAa,CAACK,IAAA,CAAK,EAAEQ,aAAA,IAAiBP,aAAA,CAAcO,aAAa,EAAE;QACrE,IAAI,CAAClB,MAAA,CAAOK,aAAa,CAACK,IAAA,CAAK,EAAEQ,aAAA,EAAeP,aAAA,CAAcO,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oB;cACzC,OAAOjB,aAAa,CAACiB,cAAA,CAAe;YACtC;UACF,OAAO;YACLjB,aAAa,CAACiB,cAAA,CAAsB,GAAGvB,aAAa,CAACK,IAAA,CAAK,CAACkB,cAAA,CAAe;UAC5E;QACF;MACF;MAEA,IAAIjB,aAAA,CAAcuB,KAAK,KAAK,OAAO;QACjCvB,aAAA,CAAcuB,KAAK,GAAG;MACxB;MAEA,IAAIvB,aAAA,CAAcwB,eAAe,KAAK,OAAO;QAC3CxB,aAAA,CAAcwB,eAAe,GAAG;MAClC;MAEA;MACA5B,QAAQ,CAACG,IAAA,CAAK,GAAGI,YAAA,GAAe;QAAE,GAAGH;MAAc,IAAIA,aAAA;IACzD;IAEA;IACA;IACA;IACA,KAAK,MAAM,CAACD,IAAA,EAAM0B,KAAA,CAAM,IAAIxB,MAAA,CAAOC,OAAO,CAACR,aAAA,GAAgB;MACzD,IAAI,CAACD,aAAa,CAACM,IAAA,CAAK,EAAE;QACxBJ,OAAA,GAAU;QACVC,QAAQ,CAACG,IAAA,CAAK,GAAG0B,KAAA;MACnB;IACF;EACF;EAEA,OAAO;IAAE9B,OAAA;IAASC;EAAS;AAC7B","ignoreList":[]}
1
+ {"version":3,"file":"mergeServerFormState.js","names":["dequal","mergeServerFormState","acceptValues","currentState","incomingState","newState","path","incomingField","Object","entries","addedByServer","value","initialValue","Array","isArray","rows","forEach","row","indexInCurrentState","findIndex","existingRow","id","valid","passesCondition"],"sources":["../../../src/forms/Form/mergeServerFormState.ts"],"sourcesContent":["'use client'\nimport type { FormState } from 'payload'\n\nimport { dequal } from 'dequal/lite' // lite: no need for Map and Set support\n\ntype Args = {\n acceptValues?: boolean\n currentState?: FormState\n incomingState: FormState\n}\n\n/**\n * This function receives form state from the server and intelligently merges it into the client state.\n * The server contains extra properties that the client may not have, e.g. custom components and error states.\n * We typically do not want to merge properties that rely on user input, however, such as values, unless explicitly requested.\n * Doing this would cause the client to lose any local changes to those fields.\n *\n * This function will also a few defaults, as well as clean up the server response in preparation for the client.\n * e.g. it will set `valid` and `passesCondition` to true if undefined, and remove `addedByServer` from the response.\n */\nexport const mergeServerFormState = ({\n acceptValues,\n currentState = {},\n incomingState,\n}: Args): FormState => {\n const newState = { ...currentState }\n\n for (const [path, incomingField] of Object.entries(incomingState || {})) {\n if (!(path in currentState) && !incomingField.addedByServer) {\n continue\n }\n\n if (!acceptValues && !incomingField.addedByServer) {\n delete incomingField.value\n delete incomingField.initialValue\n }\n\n newState[path] = {\n ...currentState[path],\n ...incomingField,\n }\n\n /**\n * Intelligently merge the rows array to ensure changes to local state are not lost while the request was pending\n * For example, the server response could come back with a row which has been deleted on the client\n * Loop over the incoming rows, if it exists in client side form state, merge in any new properties from the server\n * Note: read `currentState` and not `newState` here, as the `rows` property have already been merged above\n */\n if (Array.isArray(incomingField.rows) && path in currentState) {\n newState[path].rows = [...(currentState[path]?.rows || [])] // shallow copy to avoid mutating the original array\n\n incomingField.rows.forEach((row) => {\n const indexInCurrentState = currentState[path].rows.findIndex(\n (existingRow) => existingRow.id === row.id,\n )\n\n if (indexInCurrentState > -1) {\n newState[path].rows[indexInCurrentState] = {\n ...currentState[path].rows[indexInCurrentState],\n ...row,\n }\n }\n })\n }\n\n // If `valid` is `undefined`, mark it as `true`\n if (incomingField.valid !== false) {\n newState[path].valid = true\n }\n\n // If `passesCondition` is `undefined`, mark it as `true`\n if (incomingField.passesCondition !== false) {\n newState[path].passesCondition = true\n }\n\n // Strip away the `addedByServer` property from the client\n // This will prevent it from being passed back to the server\n delete newState[path].addedByServer\n }\n\n // Return the original object reference if the state is unchanged\n // This will avoid unnecessary re-renders and dependency updates\n return dequal(newState, currentState) ? currentState : newState\n}\n"],"mappings":"AAAA;;AAGA,SAASA,MAAM,QAAQ,cAAa,CAAC;AAQrC;;;;;;;;;AASA,OAAO,MAAMC,oBAAA,GAAuBA,CAAC;EACnCC,YAAY;EACZC,YAAA,GAAe,CAAC,CAAC;EACjBC;AAAa,CACR;EACL,MAAMC,QAAA,GAAW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cgB,eAAe,KAAK,OAAO;MAC3ClB,QAAQ,CAACC,IAAA,CAAK,CAACiB,eAAe,GAAG;IACnC;IAEA;IACA;IACA,OAAOlB,QAAQ,CAACC,IAAA,CAAK,CAACI,aAAa;EACrC;EAEA;EACA;EACA,OAAOV,MAAA,CAAOK,QAAA,EAAUF,YAAA,IAAgBA,YAAA,GAAeE,QAAA;AACzD","ignoreList":[]}
@@ -121,6 +121,12 @@ export type ADD_ROW = {
121
121
  subFieldState?: FormState;
122
122
  type: 'ADD_ROW';
123
123
  };
124
+ export type MERGE_SERVER_STATE = {
125
+ acceptValues?: boolean;
126
+ prevStateRef: React.RefObject<FormState>;
127
+ serverState: FormState;
128
+ type: 'MERGE_SERVER_STATE';
129
+ };
124
130
  export type REPLACE_ROW = {
125
131
  blockType?: string;
126
132
  path: string;
@@ -153,7 +159,7 @@ export type SET_ALL_ROWS_COLLAPSED = {
153
159
  type: 'SET_ALL_ROWS_COLLAPSED';
154
160
  updatedRows: Row[];
155
161
  };
156
- export type FieldAction = ADD_ROW | ADD_SERVER_ERRORS | DUPLICATE_ROW | MODIFY_CONDITION | MOVE_ROW | REMOVE | REMOVE_ROW | REPLACE_ROW | REPLACE_STATE | SET_ALL_ROWS_COLLAPSED | SET_ROW_COLLAPSED | UPDATE | UPDATE_MANY;
162
+ export type FieldAction = ADD_ROW | ADD_SERVER_ERRORS | DUPLICATE_ROW | MERGE_SERVER_STATE | MODIFY_CONDITION | MOVE_ROW | REMOVE | REMOVE_ROW | REPLACE_ROW | REPLACE_STATE | SET_ALL_ROWS_COLLAPSED | SET_ROW_COLLAPSED | UPDATE | UPDATE_MANY;
157
163
  export type FormFieldsContext = [FormState, Dispatch<FieldAction>];
158
164
  export type Context = {
159
165
  addFieldRow: ({ blockType, path, rowIndex, schemaPath, subFieldState, }: {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/forms/Form/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV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;;OAGG;IACH,uBAAuB,EAAE,aAAa,CAAA;IACtC,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAA;IACxC,UAAU,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAA;IACzC,WAAW,EAAE,WAAW,CAAA;IACxB,aAAa,EAAE,aAAa,CAAA;IAC5B,YAAY,EAAE,YAAY,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,YAAY,EAAE,YAAY,CAAA;CAC3B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/forms/Form/types.ts"],"sourcesContent":["import type {\n ClientField,\n Data,\n FormField,\n FormState,\n Row,\n User,\n ValidationFieldError,\n} from 'payload'\nimport type React from 'react'\nimport type { Dispatch } from 'react'\n\nexport type Preferences = {\n [key: string]: unknown\n}\n\nexport type FormProps = {\n beforeSubmit?: ((args: { formState: FormState }) => Promise<FormState>)[]\n children?: React.ReactNode\n className?: string\n disabled?: boolean\n disableSuccessStatus?: boolean\n /**\n * If you would like to solely leverage server-side validation on submit,\n * you can disable checks that the form makes before it submits\n */\n disableValidationOnSubmit?: boolean\n /**\n * If you don't want the form to be a <form> element, you can pass a string here to use as the wrapper element.\n */\n el?: string\n /**\n * By default, the form will get the field schema (not data) from the current document. If you pass this in, you can override that behavior.\n * This is very useful for sub-forms, where the form's field schema is not necessarily the field schema of the current document (e.g. for the Blocks\n * feature of the Lexical Rich Text field)\n */\n fields?: ClientField[]\n handleResponse?: (\n res: Response,\n successToast: (value: string) => void,\n errorToast: (value: string) => void,\n ) => void\n initialState?: FormState\n /**\n * Determines if this Form is the main, top-level Form of a document. If set to true, the\n * Form's children will be wrapped in a DocumentFormContext, which lets you access this document\n * Form's data and fields from any child component - even if that child component is wrapped in a child\n * Form (e.g. a lexical block).\n */\n isDocumentForm?: boolean\n isInitializing?: boolean\n log?: boolean\n onChange?: ((args: { formState: FormState; submitted?: boolean }) => Promise<FormState>)[]\n onSubmit?: (fields: FormState, data: Data) => void\n onSuccess?: (json: unknown) => Promise<FormState | void> | void\n redirect?: string\n submitted?: boolean\n uuid?: string\n validationOperation?: 'create' | 'update'\n waitForAutocomplete?: boolean\n} & (\n | {\n action: (formData: FormData) => Promise<void>\n }\n | {\n action?: string\n method?: 'DELETE' | 'GET' | 'PATCH' | 'POST'\n }\n)\n\nexport type SubmitOptions = {\n action?: string\n method?: string\n overrides?: ((formState) => FormData) | Record<string, unknown>\n skipValidation?: boolean\n}\n\nexport type DispatchFields = React.Dispatch<any>\nexport type Submit = (\n options?: SubmitOptions,\n e?: React.FormEvent<HTMLFormElement>,\n) => Promise<void>\n\nexport type ValidateForm = () => Promise<boolean>\n\nexport type CreateFormData = (\n overrides?: Record<string, unknown>,\n /**\n * If mergeOverrideData true, the data will be merged with the existing data in the form state.\n * @default true\n */\n options?: { mergeOverrideData?: boolean },\n) => FormData | Promise<FormData>\n\nexport type GetFields = () => FormState\nexport type GetField = (path: string) => FormField\nexport type GetData = () => Data\nexport type GetSiblingData = (path: string) => Data\nexport type GetDataByPath = <T = unknown>(path: string) => T\nexport type SetModified = (modified: boolean) => void\nexport type SetSubmitted = (submitted: boolean) => void\nexport type SetProcessing = (processing: boolean) => void\n\nexport type Reset = (data: unknown) => Promise<void>\n\nexport type REPLACE_STATE = {\n optimize?: boolean\n /**\n * If `sanitize` is true, default values will be set for form field properties that are not present in the incoming state.\n * For example, `valid` will be set to true if it is not present in the incoming state.\n */\n sanitize?: boolean\n state: FormState\n type: 'REPLACE_STATE'\n}\n\nexport type REMOVE = {\n path: string\n type: 'REMOVE'\n}\n\nexport type MODIFY_CONDITION = {\n path: string\n result: boolean\n type: 'MODIFY_CONDITION'\n user: User\n}\n\nexport type UPDATE = {\n path: string\n type: 'UPDATE'\n} & Partial<FormField>\n\nexport type UPDATE_MANY = {\n formState: FormState\n type: 'UPDATE_MANY'\n}\n\nexport type REMOVE_ROW = {\n path: string\n rowIndex: number\n type: 'REMOVE_ROW'\n}\n\nexport type ADD_ROW = {\n blockType?: string\n path: string\n rowIndex?: number\n subFieldState?: FormState\n type: 'ADD_ROW'\n}\n\nexport type REPLACE_ROW = {\n blockType?: string\n path: string\n rowIndex: number\n subFieldState?: FormState\n type: 'REPLACE_ROW'\n}\n\nexport type DUPLICATE_ROW = {\n path: string\n rowIndex: number\n type: 'DUPLICATE_ROW'\n}\n\nexport type MOVE_ROW = {\n moveFromIndex: number\n moveToIndex: number\n path: string\n type: 'MOVE_ROW'\n}\n\nexport type ADD_SERVER_ERRORS = {\n errors: ValidationFieldError[]\n type: 'ADD_SERVER_ERRORS'\n}\n\nexport type SET_ROW_COLLAPSED = {\n path: string\n type: 'SET_ROW_COLLAPSED'\n updatedRows: Row[]\n}\n\nexport type SET_ALL_ROWS_COLLAPSED = {\n path: string\n type: 'SET_ALL_ROWS_COLLAPSED'\n updatedRows: Row[]\n}\n\nexport type FieldAction =\n | ADD_ROW\n | ADD_SERVER_ERRORS\n | DUPLICATE_ROW\n | MODIFY_CONDITION\n | MOVE_ROW\n | REMOVE\n | REMOVE_ROW\n | REPLACE_ROW\n | REPLACE_STATE\n | SET_ALL_ROWS_COLLAPSED\n | SET_ROW_COLLAPSED\n | UPDATE\n | UPDATE_MANY\n\nexport type FormFieldsContext = [FormState, Dispatch<FieldAction>]\n\nexport type Context = {\n addFieldRow: ({\n blockType,\n path,\n rowIndex,\n schemaPath,\n subFieldState,\n }: {\n blockType?: string\n path: string\n rowIndex?: number\n schemaPath: string\n subFieldState?: FormState\n }) => void\n buildRowErrors: () => void\n createFormData: CreateFormData\n disabled: boolean\n dispatchFields: Dispatch<FieldAction>\n /**\n * Form context fields may be outdated and should not be relied on. Instead, prefer `useFormFields`.\n */\n fields: FormState\n formRef: React.RefObject<HTMLFormElement>\n getData: GetData\n getDataByPath: GetDataByPath\n getField: GetField\n getFields: GetFields\n getSiblingData: GetSiblingData\n initializing: boolean\n /**\n * Tracks wether the form state passes validation.\n * For example the state could be submitted but invalid as field errors have been returned.\n */\n isValid: boolean\n moveFieldRow: ({\n moveFromIndex,\n moveToIndex,\n path,\n }: {\n moveFromIndex: number\n moveToIndex: number\n path: string\n }) => void\n removeFieldRow: ({ path, rowIndex }: { path: string; rowIndex: number }) => void\n replaceFieldRow: ({\n blockType,\n path,\n rowIndex,\n schemaPath,\n subFieldState,\n }: {\n blockType?: string\n path: string\n rowIndex: number\n schemaPath: string\n subFieldState?: FormState\n }) => void\n replaceState: (state: FormState) => void\n reset: Reset\n /**\n * If the form has started processing in the background (e.g.\n * if autosave is running), this will be true.\n */\n setBackgroundProcessing: SetProcessing\n setDisabled: (disabled: boolean) => void\n setIsValid: (processing: boolean) => void\n setModified: SetModified\n setProcessing: SetProcessing\n setSubmitted: SetSubmitted\n submit: Submit\n uuid?: string\n validateForm: ValidateForm\n}\n"],"mappings":"AA+MA","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/forms/Form/types.ts"],"sourcesContent":["import type {\n ClientField,\n Data,\n FormField,\n FormState,\n Row,\n User,\n ValidationFieldError,\n} from 'payload'\nimport type React from 'react'\nimport type { Dispatch } from 'react'\n\nexport type Preferences = {\n [key: string]: unknown\n}\n\nexport type FormProps = {\n beforeSubmit?: ((args: { formState: FormState }) => Promise<FormState>)[]\n children?: React.ReactNode\n className?: string\n disabled?: boolean\n disableSuccessStatus?: boolean\n /**\n * If you would like to solely leverage server-side validation on submit,\n * you can disable checks that the form makes before it submits\n */\n disableValidationOnSubmit?: boolean\n /**\n * If you don't want the form to be a <form> element, you can pass a string here to use as the wrapper element.\n */\n el?: string\n /**\n * By default, the form will get the field schema (not data) from the current document. If you pass this in, you can override that behavior.\n * This is very useful for sub-forms, where the form's field schema is not necessarily the field schema of the current document (e.g. for the Blocks\n * feature of the Lexical Rich Text field)\n */\n fields?: ClientField[]\n handleResponse?: (\n res: Response,\n successToast: (value: string) => void,\n errorToast: (value: string) => void,\n ) => void\n initialState?: FormState\n /**\n * Determines if this Form is the main, top-level Form of a document. If set to true, the\n * Form's children will be wrapped in a DocumentFormContext, which lets you access this document\n * Form's data and fields from any child component - even if that child component is wrapped in a child\n * Form (e.g. a lexical block).\n */\n isDocumentForm?: boolean\n isInitializing?: boolean\n log?: boolean\n onChange?: ((args: { formState: FormState; submitted?: boolean }) => Promise<FormState>)[]\n onSubmit?: (fields: FormState, data: Data) => void\n onSuccess?: (json: unknown) => Promise<FormState | void> | void\n redirect?: string\n submitted?: boolean\n uuid?: string\n validationOperation?: 'create' | 'update'\n waitForAutocomplete?: boolean\n} & (\n | {\n action: (formData: FormData) => Promise<void>\n }\n | {\n action?: string\n method?: 'DELETE' | 'GET' | 'PATCH' | 'POST'\n }\n)\n\nexport type SubmitOptions = {\n action?: string\n method?: string\n overrides?: ((formState) => FormData) | Record<string, unknown>\n skipValidation?: boolean\n}\n\nexport type DispatchFields = React.Dispatch<any>\nexport type Submit = (\n options?: SubmitOptions,\n e?: React.FormEvent<HTMLFormElement>,\n) => Promise<void>\n\nexport type ValidateForm = () => Promise<boolean>\n\nexport type CreateFormData = (\n overrides?: Record<string, unknown>,\n /**\n * If mergeOverrideData true, the data will be merged with the existing data in the form state.\n * @default true\n */\n options?: { mergeOverrideData?: boolean },\n) => FormData | Promise<FormData>\n\nexport type GetFields = () => FormState\nexport type GetField = (path: string) => FormField\nexport type GetData = () => Data\nexport type GetSiblingData = (path: string) => Data\nexport type GetDataByPath = <T = unknown>(path: string) => T\nexport type SetModified = (modified: boolean) => void\nexport type SetSubmitted = (submitted: boolean) => void\nexport type SetProcessing = (processing: boolean) => void\n\nexport type Reset = (data: unknown) => Promise<void>\n\nexport type REPLACE_STATE = {\n optimize?: boolean\n /**\n * If `sanitize` is true, default values will be set for form field properties that are not present in the incoming state.\n * For example, `valid` will be set to true if it is not present in the incoming state.\n */\n sanitize?: boolean\n state: FormState\n type: 'REPLACE_STATE'\n}\n\nexport type REMOVE = {\n path: string\n type: 'REMOVE'\n}\n\nexport type MODIFY_CONDITION = {\n path: string\n result: boolean\n type: 'MODIFY_CONDITION'\n user: User\n}\n\nexport type UPDATE = {\n path: string\n type: 'UPDATE'\n} & Partial<FormField>\n\nexport type UPDATE_MANY = {\n formState: FormState\n type: 'UPDATE_MANY'\n}\n\nexport type REMOVE_ROW = {\n path: string\n rowIndex: number\n type: 'REMOVE_ROW'\n}\n\nexport type ADD_ROW = {\n blockType?: string\n path: string\n rowIndex?: number\n subFieldState?: FormState\n type: 'ADD_ROW'\n}\n\nexport type MERGE_SERVER_STATE = {\n acceptValues?: boolean\n prevStateRef: React.RefObject<FormState>\n serverState: FormState\n type: 'MERGE_SERVER_STATE'\n}\n\nexport type REPLACE_ROW = {\n blockType?: string\n path: string\n rowIndex: number\n subFieldState?: FormState\n type: 'REPLACE_ROW'\n}\n\nexport type DUPLICATE_ROW = {\n path: string\n rowIndex: number\n type: 'DUPLICATE_ROW'\n}\n\nexport type MOVE_ROW = {\n moveFromIndex: number\n moveToIndex: number\n path: string\n type: 'MOVE_ROW'\n}\n\nexport type ADD_SERVER_ERRORS = {\n errors: ValidationFieldError[]\n type: 'ADD_SERVER_ERRORS'\n}\n\nexport type SET_ROW_COLLAPSED = {\n path: string\n type: 'SET_ROW_COLLAPSED'\n updatedRows: Row[]\n}\n\nexport type SET_ALL_ROWS_COLLAPSED = {\n path: string\n type: 'SET_ALL_ROWS_COLLAPSED'\n updatedRows: Row[]\n}\n\nexport type FieldAction =\n | ADD_ROW\n | ADD_SERVER_ERRORS\n | DUPLICATE_ROW\n | MERGE_SERVER_STATE\n | MODIFY_CONDITION\n | MOVE_ROW\n | REMOVE\n | REMOVE_ROW\n | REPLACE_ROW\n | REPLACE_STATE\n | SET_ALL_ROWS_COLLAPSED\n | SET_ROW_COLLAPSED\n | UPDATE\n | UPDATE_MANY\n\nexport type FormFieldsContext = [FormState, Dispatch<FieldAction>]\n\nexport type Context = {\n addFieldRow: ({\n blockType,\n path,\n rowIndex,\n schemaPath,\n subFieldState,\n }: {\n blockType?: string\n path: string\n rowIndex?: number\n schemaPath: string\n subFieldState?: FormState\n }) => void\n buildRowErrors: () => void\n createFormData: CreateFormData\n disabled: boolean\n dispatchFields: Dispatch<FieldAction>\n /**\n * Form context fields may be outdated and should not be relied on. Instead, prefer `useFormFields`.\n */\n fields: FormState\n formRef: React.RefObject<HTMLFormElement>\n getData: GetData\n getDataByPath: GetDataByPath\n getField: GetField\n getFields: GetFields\n getSiblingData: GetSiblingData\n initializing: boolean\n /**\n * Tracks wether the form state passes validation.\n * For example the state could be submitted but invalid as field errors have been returned.\n */\n isValid: boolean\n moveFieldRow: ({\n moveFromIndex,\n moveToIndex,\n path,\n }: {\n moveFromIndex: number\n moveToIndex: number\n path: string\n }) => void\n removeFieldRow: ({ path, rowIndex }: { path: string; rowIndex: number }) => void\n replaceFieldRow: ({\n blockType,\n path,\n rowIndex,\n schemaPath,\n subFieldState,\n }: {\n blockType?: string\n path: string\n rowIndex: number\n schemaPath: string\n subFieldState?: FormState\n }) => void\n replaceState: (state: FormState) => void\n reset: Reset\n /**\n * If the form has started processing in the background (e.g.\n * if autosave is running), this will be true.\n */\n setBackgroundProcessing: SetProcessing\n setDisabled: (disabled: boolean) => void\n setIsValid: (processing: boolean) => void\n setModified: SetModified\n setProcessing: SetProcessing\n setSubmitted: SetSubmitted\n submit: Submit\n uuid?: string\n validateForm: ValidateForm\n}\n"],"mappings":"AAuNA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"addFieldStatePromise.d.ts","sourceRoot":"","sources":["../../../src/forms/fieldSchemasToFormState/addFieldStatePromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,IAAI,EACJ,mBAAmB,EACnB,KAAK,EACL,cAAc,EAGd,SAAS,EACT,0BAA0B,EAC1B,cAAc,EAGd,0BAA0B,EAC1B,UAAU,EACV,UAAU,EAEX,MAAM,SAAS,CAAA;AAehB,OAAO,KAAK,EAAE,iBAAiB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AAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,KAAK,EAAE,0BAA0B,CAAA;CAClC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,SAAgB,wBAAwB,KAAG,OAAO,CAAC,IAAI,CAqyBvF,CAAA"}
1
+ {"version":3,"file":"addFieldStatePromise.d.ts","sourceRoot":"","sources":["../../../src/forms/fieldSchemasToFormState/addFieldStatePromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,IAAI,EACJ,mBAAmB,EACnB,KAAK,EACL,cAAc,EAGd,SAAS,EACT,0BAA0B,EAC1B,cAAc,EAGd,0BAA0B,EAC1B,UAAU,EACV,UAAU,EAEX,MAAM,SAAS,CAAA;AAehB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAQnD,MAAM,MAAM,wBAAwB,GAAG;IACrC,oBAAoB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAA;IACjD;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B;;OAEG;IACH,SAAS,EAAE,IAAI,GAAG,SAAS,CAAA;IAC3B,oBAAoB,CAAC,EAAE,oBAAoB,CAAA;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,KAAK,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,cAAc,CAAA;IAC9B;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,wBAAwB,KAAK,OAAO,CAAA;IACpD;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,EAAE,IAAI,CAAA;IACd,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAA;IACzC;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,eAAe,EAAE,MAAM,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,iBAAiB,EAAE,0BAA0B,CAAA;IAC7C,gBAAgB,EAAE,MAAM,CAAA;IACxB,eAAe,EAAE,OAAO,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,mBAAmB,CAAA;IAChC,iBAAiB,EAAE,SAAS,CAAA;IAC5B,eAAe,EAAE,OAAO,CAAA;IACxB,aAAa,EAAE,iBAAiB,CAAA;IAChC;;;OAGG;IACH,GAAG,EAAE,cAAc,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,KAAK,EAAE,0BAA0B,CAAA;CAClC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,SAAgB,wBAAwB,KAAG,OAAO,CAAC,IAAI,CAkzBvF,CAAA"}
@@ -47,15 +47,24 @@ export const addFieldStatePromise = async args => {
47
47
  if (!args.clientFieldSchemaMap && args.renderFieldFn) {
48
48
  console.warn('clientFieldSchemaMap is not passed to addFieldStatePromise - this will reduce performance');
49
49
  }
50
- const lastRenderedPath = previousFormState?.[path]?.lastRenderedPath;
51
50
  let fieldPermissions = true;
52
51
  const fieldState = {};
52
+ const lastRenderedPath = previousFormState?.[path]?.lastRenderedPath;
53
+ // Append only if true to avoid sending '$undefined' through the network
53
54
  if (lastRenderedPath) {
54
55
  fieldState.lastRenderedPath = lastRenderedPath;
55
56
  }
57
+ // If we're rendering all fields, no need to flag this as added by server
58
+ const addedByServer = !renderAllFields && !previousFormState?.[path];
59
+ // Append only if true to avoid sending '$undefined' through the network
60
+ if (addedByServer) {
61
+ fieldState.addedByServer = true;
62
+ }
63
+ // Append only if true to avoid sending '$undefined' through the network
56
64
  if (passesCondition === false) {
57
65
  fieldState.passesCondition = false;
58
66
  }
67
+ // Append only if true to avoid sending '$undefined' through the network
59
68
  if (includeSchema) {
60
69
  fieldState.fieldSchema = field;
61
70
  }
@@ -485,7 +494,7 @@ export const addFieldStatePromise = async args => {
485
494
  }
486
495
  }
487
496
  } else if (fieldHasSubFields(field) && !fieldAffectsData(field)) {
488
- // Handle field types that do not use names (row, etc)
497
+ // Handle field types that do not use names (row, collapsible, etc)
489
498
  if (!filter || filter(args)) {
490
499
  state[path] = {
491
500
  disableFormData: true
@@ -623,7 +632,6 @@ export const addFieldStatePromise = async args => {
623
632
  }
624
633
  }
625
634
  if (renderFieldFn && !fieldIsHiddenOrDisabled(field)) {
626
- const fieldState = state[path];
627
635
  const fieldConfig = fieldSchemaMap.get(schemaPath);
628
636
  if (!fieldConfig && !mockRSCs) {
629
637
  if (schemaPath.endsWith('.blockType')) {
@@ -632,11 +640,14 @@ export const addFieldStatePromise = async args => {
632
640
  throw new Error(`Field config not found for ${schemaPath}`);
633
641
  }
634
642
  }
635
- if (!fieldState) {
643
+ if (!state[path]) {
636
644
  // Some fields (ie `Tab`) do not live in form state
637
645
  // therefore we cannot attach customComponents to them
638
646
  return;
639
647
  }
648
+ if (addedByServer) {
649
+ state[path].addedByServer = addedByServer;
650
+ }
640
651
  renderFieldFn({
641
652
  id,
642
653
  clientFieldSchemaMap,
@@ -644,7 +655,7 @@ export const addFieldStatePromise = async args => {
644
655
  data: fullData,
645
656
  fieldConfig: fieldConfig,
646
657
  fieldSchemaMap,
647
- fieldState,
658
+ fieldState: state[path],
648
659
  formState: state,
649
660
  indexPath,
650
661
  lastRenderedPath,