@payloadcms/ui 3.59.0-internal.6aee982 → 3.59.0-internal.76b6b9a
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/dist/elements/DocumentDrawer/Provider.d.ts +1 -1
- package/dist/elements/DocumentDrawer/Provider.js.map +1 -1
- package/dist/elements/DocumentLocked/index.js +1 -1
- package/dist/elements/DocumentLocked/index.js.map +1 -1
- package/dist/exports/client/{CodeEditor-UTOLPRAV.js → CodeEditor-2AHTKKBE.js} +2 -2
- package/dist/exports/client/{chunk-S2X3JKSP.js → chunk-6UH4KUYK.js} +1 -1
- package/dist/exports/client/{chunk-S2X3JKSP.js.map → chunk-6UH4KUYK.js.map} +1 -1
- package/dist/exports/client/index.d.ts +0 -1
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +12 -12
- package/dist/exports/client/index.js.map +4 -4
- package/dist/forms/Form/fieldReducer.d.ts.map +1 -1
- package/dist/forms/Form/fieldReducer.js +40 -16
- package/dist/forms/Form/fieldReducer.js.map +1 -1
- package/dist/forms/Form/types.d.ts +2 -2
- package/dist/forms/Form/types.js.map +1 -1
- package/dist/forms/RenderFields/context.d.ts +2 -2
- package/dist/forms/RenderFields/context.js +2 -2
- package/dist/forms/RenderFields/context.js.map +1 -1
- package/dist/providers/Config/index.d.ts +1 -1
- package/dist/providers/Config/index.js +1 -1
- package/dist/providers/Config/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/utilities/handleLivePreview.d.ts +1 -1
- package/dist/utilities/handleLivePreview.d.ts.map +1 -1
- package/dist/utilities/handleLivePreview.js +1 -1
- package/dist/utilities/handleLivePreview.js.map +1 -1
- package/dist/views/Edit/index.d.ts.map +1 -1
- package/dist/views/Edit/index.js +5 -1
- package/dist/views/Edit/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/fields/Slug/index.d.ts +0 -8
- package/dist/fields/Slug/index.d.ts.map +0 -1
- package/dist/fields/Slug/index.js +0 -128
- package/dist/fields/Slug/index.js.map +0 -1
- package/dist/fields/Slug/index.scss +0 -17
- /package/dist/exports/client/{CodeEditor-UTOLPRAV.js.map → CodeEditor-2AHTKKBE.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldReducer.d.ts","sourceRoot":"","sources":["../../../src/forms/Form/fieldReducer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,SAAS,EAAO,MAAM,SAAS,CAAA;AAMxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAO7C;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"fieldReducer.d.ts","sourceRoot":"","sources":["../../../src/forms/Form/fieldReducer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,SAAS,EAAO,MAAM,SAAS,CAAA;AAMxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAO7C;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,CAqb7E"}
|
|
@@ -119,6 +119,12 @@ export function fieldReducer(state, action) {
|
|
|
119
119
|
}, {});
|
|
120
120
|
return newState;
|
|
121
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Duplicates a row in an array or blocks field.
|
|
124
|
+
* It needs to manipulate two distinct parts of the form state:
|
|
125
|
+
* - The `rows` property of the parent field, e.g. `array.rows`, `blocks.rows`, etc.
|
|
126
|
+
* - The row's state, e.g. `array.0.id`, `array.0.text`, etc.
|
|
127
|
+
*/
|
|
122
128
|
case 'DUPLICATE_ROW':
|
|
123
129
|
{
|
|
124
130
|
const {
|
|
@@ -129,35 +135,53 @@ export function fieldReducer(state, action) {
|
|
|
129
135
|
remainingFields,
|
|
130
136
|
rows
|
|
131
137
|
} = separateRows(path, state);
|
|
132
|
-
|
|
133
|
-
const
|
|
138
|
+
// 1. Duplicate the `rows` property of the parent field, e.g. `array.rows`, `blocks.rows`, etc.
|
|
139
|
+
const newRows = [...(state[path].rows || [])];
|
|
140
|
+
const newRow = deepCopyObjectSimpleWithoutReactComponents(newRows[rowIndex]);
|
|
134
141
|
const newRowID = new ObjectId().toHexString();
|
|
135
142
|
if (newRow.id) {
|
|
136
143
|
newRow.id = newRowID;
|
|
137
144
|
}
|
|
138
|
-
if (
|
|
145
|
+
if (newRows[rowIndex]?.customComponents?.RowLabel) {
|
|
139
146
|
newRow.customComponents = {
|
|
140
|
-
RowLabel:
|
|
147
|
+
RowLabel: newRows[rowIndex].customComponents.RowLabel
|
|
141
148
|
};
|
|
142
149
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
150
|
+
// 2. Duplicate the row's state, e.g. `array.0.id`, `array.0.text`, etc.
|
|
151
|
+
const newRowState = deepCopyObjectSimpleWithoutReactComponents(rows[rowIndex]);
|
|
152
|
+
// Ensure that `id` in form state exactly matches the row id on the parent field
|
|
153
|
+
if (newRowState.id) {
|
|
154
|
+
newRowState.id.value = newRowID;
|
|
155
|
+
newRowState.id.initialValue = newRowID;
|
|
147
156
|
}
|
|
148
|
-
for
|
|
149
|
-
|
|
157
|
+
// Generate new ids for all nested id fields, e.g. `array.0.nestedArray.0.id`
|
|
158
|
+
for (const key of Object.keys(newRowState).filter(key => key.endsWith('.id'))) {
|
|
159
|
+
const idState = newRowState[key];
|
|
150
160
|
const newNestedFieldID = new ObjectId().toHexString();
|
|
151
161
|
if (idState && typeof idState.value === 'string' && ObjectId.isValid(idState.value)) {
|
|
152
|
-
|
|
153
|
-
|
|
162
|
+
newRowState[key].value = newNestedFieldID;
|
|
163
|
+
newRowState[key].initialValue = newNestedFieldID;
|
|
164
|
+
// Apply the ID to its corresponding parent field's rows, e.g. `array.0.nestedArray.rows[0].id`
|
|
165
|
+
const segments = key.split('.');
|
|
166
|
+
const rowIndex = parseInt(segments[segments.length - 2], 10);
|
|
167
|
+
const parentFieldPath = segments.slice(0, segments.length - 2).join('.');
|
|
168
|
+
const parentFieldRows = newRowState?.[parentFieldPath]?.rows;
|
|
169
|
+
if (newRowState[parentFieldPath] && Array.isArray(parentFieldRows)) {
|
|
170
|
+
if (!parentFieldRows[rowIndex]) {
|
|
171
|
+
parentFieldRows[rowIndex] = {
|
|
172
|
+
id: newNestedFieldID
|
|
173
|
+
};
|
|
174
|
+
} else {
|
|
175
|
+
parentFieldRows[rowIndex].id = newNestedFieldID;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
154
178
|
}
|
|
155
179
|
}
|
|
156
180
|
// If there are subfields
|
|
157
|
-
if (Object.keys(
|
|
181
|
+
if (Object.keys(newRowState).length > 0) {
|
|
158
182
|
// Add new object containing subfield names to unflattenedRows array
|
|
159
|
-
rows.splice(rowIndex + 1, 0,
|
|
160
|
-
|
|
183
|
+
rows.splice(rowIndex + 1, 0, newRowState);
|
|
184
|
+
newRows.splice(rowIndex + 1, 0, newRow);
|
|
161
185
|
}
|
|
162
186
|
const newState = {
|
|
163
187
|
...remainingFields,
|
|
@@ -165,7 +189,7 @@ export function fieldReducer(state, action) {
|
|
|
165
189
|
[path]: {
|
|
166
190
|
...state[path],
|
|
167
191
|
disableFormData: true,
|
|
168
|
-
rows:
|
|
192
|
+
rows: newRows,
|
|
169
193
|
value: rows.length
|
|
170
194
|
}
|
|
171
195
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldReducer.js","names":["ObjectIdImport","dequal","deepCopyObjectSimpleWithoutReactComponents","mergeServerFormState","flattenRows","separateRows","ObjectId","default","fieldReducer","state","action","type","blockType","path","rowIndex","rowIndexFromArgs","subFieldState","rows","length","withNewRow","newRow","id","value","toHexString","isLoading","splice","initialValue","valid","remainingFields","siblingRows","newState","passesCondition","disableFormData","errorPaths","errors","forEach","message","fieldPath","errorMessage","segments","split","push","fieldErrorPath","parentPath","slice","join","Object","entries","reduce","acc","fieldState","fieldErrorPaths","errorACC","startsWith","changed","newErrorPaths","Array","isArray","includes","rowsWithDuplicate","newRowID","customComponents","RowLabel","duplicateRowState","key","keys","filter","endsWith","idState","newNestedFieldID","isValid","acceptValues","prevStateRef","serverState","currentState","incomingState","current","moveFromIndex","moveToIndex","topLevelRows","copyOfMovingRow","rowsWithinField","copyOfMovingRow2","rowsMetadata","rowIndexArg","Math","max","min","undefined","collapsed","optimize","newField","oldField","sanitize","field","values","updatedRows","isModified","formState"],"sources":["../../../src/forms/Form/fieldReducer.ts"],"sourcesContent":["'use client'\nimport type { FormField, FormState, Row } from 'payload'\n\nimport ObjectIdImport from 'bson-objectid'\nimport { dequal } from 'dequal/lite' // lite: no need for Map and Set support\nimport { deepCopyObjectSimpleWithoutReactComponents } from 'payload/shared'\n\nimport type { FieldAction } from './types.js'\n\nimport { mergeServerFormState } from './mergeServerFormState.js'\nimport { flattenRows, separateRows } from './rows.js'\n\nconst ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport\n\n/**\n * Reducer which modifies the form field state (all the current data of the fields in the form). When called using dispatch, it will return a new state object.\n */\nexport function fieldReducer(state: FormState, action: FieldAction): FormState {\n switch (action.type) {\n case 'ADD_ROW': {\n const { blockType, path, rowIndex: rowIndexFromArgs, subFieldState = {} } = action\n\n const rowIndex =\n typeof rowIndexFromArgs === 'number' ? rowIndexFromArgs : state[path]?.rows?.length || 0\n\n const withNewRow = [...(state[path]?.rows || [])]\n\n const newRow: Row = {\n id: (subFieldState?.id?.value as string) || new ObjectId().toHexString(),\n isLoading: true,\n }\n\n if (blockType) {\n newRow.blockType = blockType\n }\n\n withNewRow.splice(rowIndex, 0, newRow)\n\n if (blockType) {\n subFieldState.blockType = {\n initialValue: blockType,\n valid: true,\n value: blockType,\n }\n }\n\n // add new row to array _field state_\n const { remainingFields, rows: siblingRows } = separateRows(path, state)\n\n siblingRows.splice(rowIndex, 0, subFieldState)\n\n const newState: FormState = {\n ...remainingFields,\n ...flattenRows(path, siblingRows),\n [`${path}.${rowIndex}.id`]: {\n initialValue: newRow.id,\n passesCondition: true,\n valid: true,\n value: newRow.id,\n },\n [path]: {\n ...state[path],\n disableFormData: true,\n rows: withNewRow,\n value: siblingRows.length,\n },\n }\n\n return newState\n }\n\n case 'ADD_SERVER_ERRORS': {\n let newState = { ...state }\n\n const errorPaths: { fieldErrorPath: string; parentPath: string }[] = []\n\n action.errors.forEach(({ message, path: fieldPath }) => {\n newState[fieldPath] = {\n ...(newState[fieldPath] || {\n initialValue: null,\n value: null,\n }),\n errorMessage: message,\n valid: false,\n }\n\n const segments = fieldPath.split('.')\n if (segments.length > 1) {\n errorPaths.push({\n fieldErrorPath: fieldPath,\n parentPath: segments.slice(0, segments.length - 1).join('.'),\n })\n }\n })\n\n newState = Object.entries(newState).reduce((acc, [path, fieldState]) => {\n const fieldErrorPaths = errorPaths.reduce((errorACC, { fieldErrorPath, parentPath }) => {\n if (parentPath.startsWith(path)) {\n errorACC.push(fieldErrorPath)\n }\n return errorACC\n }, [])\n\n let changed = false\n\n if (fieldErrorPaths.length > 0) {\n const newErrorPaths = Array.isArray(fieldState.errorPaths) ? fieldState.errorPaths : []\n\n fieldErrorPaths.forEach((fieldErrorPath) => {\n if (!newErrorPaths.includes(fieldErrorPath)) {\n newErrorPaths.push(fieldErrorPath)\n changed = true\n }\n })\n\n if (changed) {\n acc[path] = {\n ...fieldState,\n errorPaths: newErrorPaths,\n }\n }\n }\n\n if (!changed) {\n acc[path] = fieldState\n }\n\n return acc\n }, {})\n\n return newState\n }\n\n case 'DUPLICATE_ROW': {\n const { path, rowIndex } = action\n const { remainingFields, rows } = separateRows(path, state)\n const rowsWithDuplicate = [...(state[path].rows || [])]\n\n const newRow = deepCopyObjectSimpleWithoutReactComponents(rowsWithDuplicate[rowIndex])\n\n const newRowID = new ObjectId().toHexString()\n\n if (newRow.id) {\n newRow.id = newRowID\n }\n\n if (rowsWithDuplicate[rowIndex]?.customComponents?.RowLabel) {\n newRow.customComponents = {\n RowLabel: rowsWithDuplicate[rowIndex].customComponents.RowLabel,\n }\n }\n\n const duplicateRowState = deepCopyObjectSimpleWithoutReactComponents(rows[rowIndex])\n\n if (duplicateRowState.id) {\n duplicateRowState.id.value = newRowID\n duplicateRowState.id.initialValue = newRowID\n }\n\n for (const key of Object.keys(duplicateRowState).filter((key) => key.endsWith('.id'))) {\n const idState = duplicateRowState[key]\n\n const newNestedFieldID = new ObjectId().toHexString()\n\n if (idState && typeof idState.value === 'string' && ObjectId.isValid(idState.value)) {\n duplicateRowState[key].value = newNestedFieldID\n duplicateRowState[key].initialValue = newNestedFieldID\n }\n }\n\n // If there are subfields\n if (Object.keys(duplicateRowState).length > 0) {\n // Add new object containing subfield names to unflattenedRows array\n rows.splice(rowIndex + 1, 0, duplicateRowState)\n rowsWithDuplicate.splice(rowIndex + 1, 0, newRow)\n }\n\n const newState = {\n ...remainingFields,\n ...flattenRows(path, rows),\n [path]: {\n ...state[path],\n disableFormData: true,\n rows: rowsWithDuplicate,\n value: rows.length,\n },\n }\n\n return newState\n }\n\n case 'MERGE_SERVER_STATE': {\n const { acceptValues, prevStateRef, serverState } = action\n\n const newState = mergeServerFormState({\n acceptValues,\n currentState: state || {},\n incomingState: serverState,\n })\n\n prevStateRef.current = newState\n\n return newState\n }\n\n case 'MOVE_ROW': {\n const { moveFromIndex, moveToIndex, path } = action\n\n // Handle moving rows on the top-level, i.e. `array.0.text` -> `array.1.text`\n const { remainingFields, rows: topLevelRows } = separateRows(path, state)\n const copyOfMovingRow = topLevelRows[moveFromIndex]\n topLevelRows.splice(moveFromIndex, 1)\n topLevelRows.splice(moveToIndex, 0, copyOfMovingRow)\n\n // modify array/block internal row state (i.e. collapsed, blockType)\n const rowsWithinField = [...(state[path]?.rows || [])]\n const copyOfMovingRow2 = { ...rowsWithinField[moveFromIndex] }\n rowsWithinField.splice(moveFromIndex, 1)\n rowsWithinField.splice(moveToIndex, 0, copyOfMovingRow2)\n\n const newState = {\n ...remainingFields,\n ...flattenRows(path, topLevelRows),\n [path]: {\n ...state[path],\n rows: rowsWithinField,\n },\n }\n\n return newState\n }\n\n case 'REMOVE': {\n const newState = { ...state }\n if (newState[action.path]) {\n delete newState[action.path]\n }\n return newState\n }\n\n case 'REMOVE_ROW': {\n const { path, rowIndex } = action\n const { remainingFields, rows } = separateRows(path, state)\n const rowsMetadata = [...(state[path]?.rows || [])]\n\n rows.splice(rowIndex, 1)\n rowsMetadata.splice(rowIndex, 1)\n\n const newState: FormState = {\n ...remainingFields,\n [path]: {\n ...state[path],\n disableFormData: rows.length > 0,\n rows: rowsMetadata,\n value: rows.length,\n },\n ...flattenRows(path, rows),\n }\n\n return newState\n }\n\n case 'REPLACE_ROW': {\n const { blockType, path, rowIndex: rowIndexArg, subFieldState = {} } = action\n\n const { remainingFields, rows: siblingRows } = separateRows(path, state)\n const rowIndex = Math.max(0, Math.min(rowIndexArg, siblingRows?.length - 1 || 0))\n\n const rowsMetadata = [...(state[path]?.rows || [])]\n rowsMetadata[rowIndex] = {\n id: new ObjectId().toHexString(),\n blockType: blockType || undefined,\n collapsed: false,\n }\n\n if (blockType) {\n subFieldState.blockType = {\n initialValue: blockType,\n valid: true,\n value: blockType,\n }\n }\n\n // replace form _field state_\n siblingRows[rowIndex] = subFieldState\n\n const newState: FormState = {\n ...remainingFields,\n ...flattenRows(path, siblingRows),\n [path]: {\n ...state[path],\n disableFormData: true,\n rows: rowsMetadata,\n value: siblingRows.length,\n },\n }\n\n return newState\n }\n\n case 'REPLACE_STATE': {\n if (action.optimize !== false) {\n // Only update fields that have changed\n // by comparing old value / initialValue to new\n // ..\n // This is a performance enhancement for saving\n // large documents with hundreds of fields\n const newState: FormState = {}\n\n for (const [path, newField] of Object.entries(action.state)) {\n const oldField = state[path]\n\n if (newField.valid !== false) {\n newField.valid = true\n }\n if (newField.passesCondition !== false) {\n newField.passesCondition = true\n }\n\n if (!dequal(oldField, newField)) {\n newState[path] = newField\n } else if (oldField) {\n newState[path] = oldField\n }\n }\n\n return newState\n }\n\n // TODO: Remove this in 4.0 - this is a temporary fix to prevent a breaking change\n if (action.sanitize) {\n for (const field of Object.values(action.state)) {\n if (field.valid !== false) {\n field.valid = true\n }\n if (field.passesCondition !== false) {\n field.passesCondition = true\n }\n }\n }\n // If we're not optimizing, just set the state to the new state\n return action.state\n }\n\n case 'SET_ALL_ROWS_COLLAPSED': {\n const { path, updatedRows } = action\n\n return {\n ...state,\n [path]: {\n ...state[path],\n rows: updatedRows,\n },\n }\n }\n\n case 'SET_ROW_COLLAPSED': {\n const { path, updatedRows } = action\n\n const newState = {\n ...state,\n [path]: {\n ...state[path],\n rows: updatedRows,\n },\n }\n\n return newState\n }\n\n case 'UPDATE': {\n const newField = Object.entries(action).reduce(\n (field, [key, value]) => {\n if (\n [\n 'disableFormData',\n 'errorMessage',\n 'initialValue',\n 'rows',\n 'valid',\n 'validate',\n 'value',\n ].includes(key)\n ) {\n return {\n ...field,\n [key]: value,\n ...(key === 'value' ? { isModified: true } : {}),\n }\n }\n\n return field\n },\n state?.[action.path] || ({} as FormField),\n )\n\n const newState = {\n ...state,\n [action.path]: newField,\n }\n\n // reset `isModified` in all other fields\n if ('value' in action) {\n for (const [path, field] of Object.entries(newState)) {\n if (path !== action.path && 'isModified' in field) {\n delete newState[path].isModified\n }\n }\n }\n\n return newState\n }\n\n case 'UPDATE_MANY': {\n const newState = { ...state }\n\n Object.entries(action.formState).forEach(([path, field]) => {\n newState[path] = field\n })\n\n return newState\n }\n\n default: {\n return state\n }\n }\n}\n"],"mappings":"AAAA;;AAGA,OAAOA,cAAA,MAAoB;AAC3B,SAASC,MAAM,QAAQ,cAAa,CAAC;AACrC,SAASC,0CAA0C,QAAQ;AAI3D,SAASC,oBAAoB,QAAQ;AACrC,SAASC,WAAW,EAAEC,YAAY,QAAQ;AAE1C,MAAMC,QAAA,GAAW,aAAaN,cAAA,GAAiBA,cAAA,CAAeO,OAAO,GAAGP,cAAA;AAExE;;;AAGA,OA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OAAO;cACL,GAAG8B,KAAK;cACR,CAAC9B,GAAA,GAAM1C,KAAA;cACP,IAAI0C,GAAA,KAAQ,UAAU;gBAAEiC,UAAA,EAAY;cAAK,IAAI,CAAC,CAAC;YACjD;UACF;UAEA,OAAOH,KAAA;QACT,GACArF,KAAA,GAAQC,MAAA,CAAOG,IAAI,CAAC,IAAK,CAAC;QAG5B,MAAMiB,QAAA,GAAW;UACf,GAAGrB,KAAK;UACR,CAACC,MAAA,CAAOG,IAAI,GAAG8E;QACjB;QAEA;QACA,IAAI,WAAWjF,MAAA,EAAQ;UACrB,KAAK,MAAM,CAACG,IAAA,EAAMiF,KAAA,CAAM,IAAIhD,MAAA,CAAOC,OAAO,CAACjB,QAAA,GAAW;YACpD,IAAIjB,IAAA,KAASH,MAAA,CAAOG,IAAI,IAAI,gBAAgBiF,KAAA,EAAO;cACjD,OAAOhE,QAAQ,CAACjB,IAAA,CAAK,CAACoF,UAAU;YAClC;UACF;QACF;QAEA,OAAOnE,QAAA;MACT;IAEA,KAAK;MAAe;QAClB,MAAMA,QAAA,GAAW;UAAE,GAAGrB;QAAM;QAE5BqC,MAAA,CAAOC,OAAO,CAACrC,MAAA,CAAOwF,SAAS,EAAE/D,OAAO,CAAC,CAAC,CAACtB,IAAA,EAAMiF,KAAA,CAAM;UACrDhE,QAAQ,CAACjB,IAAA,CAAK,GAAGiF,KAAA;QACnB;QAEA,OAAOhE,QAAA;MACT;IAEA;MAAS;QACP,OAAOrB,KAAA;MACT;EACF;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"fieldReducer.js","names":["ObjectIdImport","dequal","deepCopyObjectSimpleWithoutReactComponents","mergeServerFormState","flattenRows","separateRows","ObjectId","default","fieldReducer","state","action","type","blockType","path","rowIndex","rowIndexFromArgs","subFieldState","rows","length","withNewRow","newRow","id","value","toHexString","isLoading","splice","initialValue","valid","remainingFields","siblingRows","newState","passesCondition","disableFormData","errorPaths","errors","forEach","message","fieldPath","errorMessage","segments","split","push","fieldErrorPath","parentPath","slice","join","Object","entries","reduce","acc","fieldState","fieldErrorPaths","errorACC","startsWith","changed","newErrorPaths","Array","isArray","includes","newRows","newRowID","customComponents","RowLabel","newRowState","key","keys","filter","endsWith","idState","newNestedFieldID","isValid","parseInt","parentFieldPath","parentFieldRows","acceptValues","prevStateRef","serverState","currentState","incomingState","current","moveFromIndex","moveToIndex","topLevelRows","copyOfMovingRow","rowsWithinField","copyOfMovingRow2","rowsMetadata","rowIndexArg","Math","max","min","undefined","collapsed","optimize","newField","oldField","sanitize","field","values","updatedRows","isModified","formState"],"sources":["../../../src/forms/Form/fieldReducer.ts"],"sourcesContent":["'use client'\nimport type { FormField, FormState, Row } from 'payload'\n\nimport ObjectIdImport from 'bson-objectid'\nimport { dequal } from 'dequal/lite' // lite: no need for Map and Set support\nimport { deepCopyObjectSimpleWithoutReactComponents } from 'payload/shared'\n\nimport type { FieldAction } from './types.js'\n\nimport { mergeServerFormState } from './mergeServerFormState.js'\nimport { flattenRows, separateRows } from './rows.js'\n\nconst ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport\n\n/**\n * Reducer which modifies the form field state (all the current data of the fields in the form). When called using dispatch, it will return a new state object.\n */\nexport function fieldReducer(state: FormState, action: FieldAction): FormState {\n switch (action.type) {\n case 'ADD_ROW': {\n const { blockType, path, rowIndex: rowIndexFromArgs, subFieldState = {} } = action\n\n const rowIndex =\n typeof rowIndexFromArgs === 'number' ? rowIndexFromArgs : state[path]?.rows?.length || 0\n\n const withNewRow = [...(state[path]?.rows || [])]\n\n const newRow: Row = {\n id: (subFieldState?.id?.value as string) || new ObjectId().toHexString(),\n isLoading: true,\n }\n\n if (blockType) {\n newRow.blockType = blockType\n }\n\n withNewRow.splice(rowIndex, 0, newRow)\n\n if (blockType) {\n subFieldState.blockType = {\n initialValue: blockType,\n valid: true,\n value: blockType,\n }\n }\n\n // add new row to array _field state_\n const { remainingFields, rows: siblingRows } = separateRows(path, state)\n\n siblingRows.splice(rowIndex, 0, subFieldState)\n\n const newState: FormState = {\n ...remainingFields,\n ...flattenRows(path, siblingRows),\n [`${path}.${rowIndex}.id`]: {\n initialValue: newRow.id,\n passesCondition: true,\n valid: true,\n value: newRow.id,\n },\n [path]: {\n ...state[path],\n disableFormData: true,\n rows: withNewRow,\n value: siblingRows.length,\n },\n }\n\n return newState\n }\n\n case 'ADD_SERVER_ERRORS': {\n let newState = { ...state }\n\n const errorPaths: { fieldErrorPath: string; parentPath: string }[] = []\n\n action.errors.forEach(({ message, path: fieldPath }) => {\n newState[fieldPath] = {\n ...(newState[fieldPath] || {\n initialValue: null,\n value: null,\n }),\n errorMessage: message,\n valid: false,\n }\n\n const segments = fieldPath.split('.')\n if (segments.length > 1) {\n errorPaths.push({\n fieldErrorPath: fieldPath,\n parentPath: segments.slice(0, segments.length - 1).join('.'),\n })\n }\n })\n\n newState = Object.entries(newState).reduce((acc, [path, fieldState]) => {\n const fieldErrorPaths = errorPaths.reduce((errorACC, { fieldErrorPath, parentPath }) => {\n if (parentPath.startsWith(path)) {\n errorACC.push(fieldErrorPath)\n }\n return errorACC\n }, [])\n\n let changed = false\n\n if (fieldErrorPaths.length > 0) {\n const newErrorPaths = Array.isArray(fieldState.errorPaths) ? fieldState.errorPaths : []\n\n fieldErrorPaths.forEach((fieldErrorPath) => {\n if (!newErrorPaths.includes(fieldErrorPath)) {\n newErrorPaths.push(fieldErrorPath)\n changed = true\n }\n })\n\n if (changed) {\n acc[path] = {\n ...fieldState,\n errorPaths: newErrorPaths,\n }\n }\n }\n\n if (!changed) {\n acc[path] = fieldState\n }\n\n return acc\n }, {})\n\n return newState\n }\n\n /**\n * Duplicates a row in an array or blocks field.\n * It needs to manipulate two distinct parts of the form state:\n * - The `rows` property of the parent field, e.g. `array.rows`, `blocks.rows`, etc.\n * - The row's state, e.g. `array.0.id`, `array.0.text`, etc.\n */\n case 'DUPLICATE_ROW': {\n const { path, rowIndex } = action\n const { remainingFields, rows } = separateRows(path, state)\n\n // 1. Duplicate the `rows` property of the parent field, e.g. `array.rows`, `blocks.rows`, etc.\n const newRows = [...(state[path].rows || [])]\n\n const newRow = deepCopyObjectSimpleWithoutReactComponents(newRows[rowIndex])\n\n const newRowID = new ObjectId().toHexString()\n\n if (newRow.id) {\n newRow.id = newRowID\n }\n\n if (newRows[rowIndex]?.customComponents?.RowLabel) {\n newRow.customComponents = {\n RowLabel: newRows[rowIndex].customComponents.RowLabel,\n }\n }\n\n // 2. Duplicate the row's state, e.g. `array.0.id`, `array.0.text`, etc.\n const newRowState = deepCopyObjectSimpleWithoutReactComponents(rows[rowIndex])\n\n // Ensure that `id` in form state exactly matches the row id on the parent field\n if (newRowState.id) {\n newRowState.id.value = newRowID\n newRowState.id.initialValue = newRowID\n }\n\n // Generate new ids for all nested id fields, e.g. `array.0.nestedArray.0.id`\n for (const key of Object.keys(newRowState).filter((key) => key.endsWith('.id'))) {\n const idState = newRowState[key]\n\n const newNestedFieldID = new ObjectId().toHexString()\n\n if (idState && typeof idState.value === 'string' && ObjectId.isValid(idState.value)) {\n newRowState[key].value = newNestedFieldID\n newRowState[key].initialValue = newNestedFieldID\n\n // Apply the ID to its corresponding parent field's rows, e.g. `array.0.nestedArray.rows[0].id`\n const segments = key.split('.')\n const rowIndex = parseInt(segments[segments.length - 2], 10)\n const parentFieldPath = segments.slice(0, segments.length - 2).join('.')\n const parentFieldRows = newRowState?.[parentFieldPath]?.rows\n\n if (newRowState[parentFieldPath] && Array.isArray(parentFieldRows)) {\n if (!parentFieldRows[rowIndex]) {\n parentFieldRows[rowIndex] = {\n id: newNestedFieldID,\n }\n } else {\n parentFieldRows[rowIndex].id = newNestedFieldID\n }\n }\n }\n }\n\n // If there are subfields\n if (Object.keys(newRowState).length > 0) {\n // Add new object containing subfield names to unflattenedRows array\n rows.splice(rowIndex + 1, 0, newRowState)\n newRows.splice(rowIndex + 1, 0, newRow)\n }\n\n const newState = {\n ...remainingFields,\n ...flattenRows(path, rows),\n [path]: {\n ...state[path],\n disableFormData: true,\n rows: newRows,\n value: rows.length,\n },\n }\n\n return newState\n }\n\n case 'MERGE_SERVER_STATE': {\n const { acceptValues, prevStateRef, serverState } = action\n\n const newState = mergeServerFormState({\n acceptValues,\n currentState: state || {},\n incomingState: serverState,\n })\n\n prevStateRef.current = newState\n\n return newState\n }\n\n case 'MOVE_ROW': {\n const { moveFromIndex, moveToIndex, path } = action\n\n // Handle moving rows on the top-level, i.e. `array.0.text` -> `array.1.text`\n const { remainingFields, rows: topLevelRows } = separateRows(path, state)\n const copyOfMovingRow = topLevelRows[moveFromIndex]\n topLevelRows.splice(moveFromIndex, 1)\n topLevelRows.splice(moveToIndex, 0, copyOfMovingRow)\n\n // modify array/block internal row state (i.e. collapsed, blockType)\n const rowsWithinField = [...(state[path]?.rows || [])]\n const copyOfMovingRow2 = { ...rowsWithinField[moveFromIndex] }\n rowsWithinField.splice(moveFromIndex, 1)\n rowsWithinField.splice(moveToIndex, 0, copyOfMovingRow2)\n\n const newState = {\n ...remainingFields,\n ...flattenRows(path, topLevelRows),\n [path]: {\n ...state[path],\n rows: rowsWithinField,\n },\n }\n\n return newState\n }\n\n case 'REMOVE': {\n const newState = { ...state }\n if (newState[action.path]) {\n delete newState[action.path]\n }\n return newState\n }\n\n case 'REMOVE_ROW': {\n const { path, rowIndex } = action\n const { remainingFields, rows } = separateRows(path, state)\n const rowsMetadata = [...(state[path]?.rows || [])]\n\n rows.splice(rowIndex, 1)\n rowsMetadata.splice(rowIndex, 1)\n\n const newState: FormState = {\n ...remainingFields,\n [path]: {\n ...state[path],\n disableFormData: rows.length > 0,\n rows: rowsMetadata,\n value: rows.length,\n },\n ...flattenRows(path, rows),\n }\n\n return newState\n }\n\n case 'REPLACE_ROW': {\n const { blockType, path, rowIndex: rowIndexArg, subFieldState = {} } = action\n\n const { remainingFields, rows: siblingRows } = separateRows(path, state)\n const rowIndex = Math.max(0, Math.min(rowIndexArg, siblingRows?.length - 1 || 0))\n\n const rowsMetadata = [...(state[path]?.rows || [])]\n rowsMetadata[rowIndex] = {\n id: new ObjectId().toHexString(),\n blockType: blockType || undefined,\n collapsed: false,\n }\n\n if (blockType) {\n subFieldState.blockType = {\n initialValue: blockType,\n valid: true,\n value: blockType,\n }\n }\n\n // replace form _field state_\n siblingRows[rowIndex] = subFieldState\n\n const newState: FormState = {\n ...remainingFields,\n ...flattenRows(path, siblingRows),\n [path]: {\n ...state[path],\n disableFormData: true,\n rows: rowsMetadata,\n value: siblingRows.length,\n },\n }\n\n return newState\n }\n\n case 'REPLACE_STATE': {\n if (action.optimize !== false) {\n // Only update fields that have changed\n // by comparing old value / initialValue to new\n // ..\n // This is a performance enhancement for saving\n // large documents with hundreds of fields\n const newState: FormState = {}\n\n for (const [path, newField] of Object.entries(action.state)) {\n const oldField = state[path]\n\n if (newField.valid !== false) {\n newField.valid = true\n }\n if (newField.passesCondition !== false) {\n newField.passesCondition = true\n }\n\n if (!dequal(oldField, newField)) {\n newState[path] = newField\n } else if (oldField) {\n newState[path] = oldField\n }\n }\n\n return newState\n }\n\n // TODO: Remove this in 4.0 - this is a temporary fix to prevent a breaking change\n if (action.sanitize) {\n for (const field of Object.values(action.state)) {\n if (field.valid !== false) {\n field.valid = true\n }\n if (field.passesCondition !== false) {\n field.passesCondition = true\n }\n }\n }\n // If we're not optimizing, just set the state to the new state\n return action.state\n }\n\n case 'SET_ALL_ROWS_COLLAPSED': {\n const { path, updatedRows } = action\n\n return {\n ...state,\n [path]: {\n ...state[path],\n rows: updatedRows,\n },\n }\n }\n\n case 'SET_ROW_COLLAPSED': {\n const { path, updatedRows } = action\n\n const newState = {\n ...state,\n [path]: {\n ...state[path],\n rows: updatedRows,\n },\n }\n\n return newState\n }\n\n case 'UPDATE': {\n const newField = Object.entries(action).reduce(\n (field, [key, value]) => {\n if (\n [\n 'disableFormData',\n 'errorMessage',\n 'initialValue',\n 'rows',\n 'valid',\n 'validate',\n 'value',\n ].includes(key)\n ) {\n return {\n ...field,\n [key]: value,\n ...(key === 'value' ? { isModified: true } : {}),\n }\n }\n\n return field\n },\n state?.[action.path] || ({} as FormField),\n )\n\n const newState = {\n ...state,\n [action.path]: newField,\n }\n\n // reset `isModified` in all other fields\n if ('value' in action) {\n for (const [path, field] of Object.entries(newState)) {\n if (path !== action.path && 'isModified' in field) {\n delete newState[path].isModified\n }\n }\n }\n\n return newState\n }\n\n case 'UPDATE_MANY': {\n const newState = { ...state }\n\n Object.entries(action.formState).forEach(([path, field]) => {\n newState[path] = field\n })\n\n return newState\n }\n\n default: {\n return state\n }\n }\n}\n"],"mappings":"AAAA;;AAGA,OAAOA,cAAA,MAAoB;AAC3B,SAASC,MAAM,QAAQ,cAAa,CAAC;AACrC,SAASC,0CAA0C,QAAQ;AAI3D,SAASC,oBAAoB,QAAQ;AACrC,SAASC,WAAW,EAAEC,YAAY,QAAQ;AAE1C,MAAMC,QAAA,GAAW,aAAaN,cAAA,GAAiBA,cAAA,CAAeO,OAAO,GAAGP,cAAA;AAExE;;;AAGA,OAAO,SAASQ,aAAaC,KAAgB,EAAEC,MAAmB;EAChE,QAAQA,MAAA,CAAOC,IAAI;IACjB,KAAK;MAAW;QACd,MAAM;UAAEC,SAAS;UAAEC,IAAI;UAAEC,QAAA,EAAUC,gBAAgB;UAAEC,aAAA,GAAgB,CAAC;QAAC,CAAE,GAAGN,MAAA;QAE5E,MAAMI,QAAA,GACJ,OAAOC,gBAAA,KAAqB,WAAWA,gBAAA,GAAmBN,KAAK,CAACI,IAAA,CAAK,EAAEI,IAAA,EAAMC,MAAA,IAAU;QAEzF,MAAMC,UAAA,GAAa,C,IAAKV,KAAK,CAACI,IAAA,CAAK,EAAEI,IAAA,IAAQ,EAAE,EAAE;QAEjD,MAAMG,MAAA,GAAc;UAClBC,EAAA,EAAIL,aAAC,EAAeK,EAAA,EAAIC,KAAA,IAAoB,IAAIhB,QAAA,GAAWiB,WAAW;UACtEC,SAAA,EAAW;QACb;QAEA,IAAIZ,SAAA,EAAW;UACbQ,MAAA,CAAOR,SAAS,GAAGA,SAA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GiC,KAAK;cACR,CAACjC,GAAA,GAAM1C,KAAA;cACP,IAAI0C,GAAA,KAAQ,UAAU;gBAAEoC,UAAA,EAAY;cAAK,IAAI,CAAC,CAAC;YACjD;UACF;UAEA,OAAOH,KAAA;QACT,GACAxF,KAAA,GAAQC,MAAA,CAAOG,IAAI,CAAC,IAAK,CAAC;QAG5B,MAAMiB,QAAA,GAAW;UACf,GAAGrB,KAAK;UACR,CAACC,MAAA,CAAOG,IAAI,GAAGiF;QACjB;QAEA;QACA,IAAI,WAAWpF,MAAA,EAAQ;UACrB,KAAK,MAAM,CAACG,IAAA,EAAMoF,KAAA,CAAM,IAAInD,MAAA,CAAOC,OAAO,CAACjB,QAAA,GAAW;YACpD,IAAIjB,IAAA,KAASH,MAAA,CAAOG,IAAI,IAAI,gBAAgBoF,KAAA,EAAO;cACjD,OAAOnE,QAAQ,CAACjB,IAAA,CAAK,CAACuF,UAAU;YAClC;UACF;QACF;QAEA,OAAOtE,QAAA;MACT;IAEA,KAAK;MAAe;QAClB,MAAMA,QAAA,GAAW;UAAE,GAAGrB;QAAM;QAE5BqC,MAAA,CAAOC,OAAO,CAACrC,MAAA,CAAO2F,SAAS,EAAElE,OAAO,CAAC,CAAC,CAACtB,IAAA,EAAMoF,KAAA,CAAM;UACrDnE,QAAQ,CAACjB,IAAA,CAAK,GAAGoF,KAAA;QACnB;QAEA,OAAOnE,QAAA;MACT;IAEA;MAAS;QACP,OAAOrB,KAAA;MACT;EACF;AACF","ignoreList":[]}
|
|
@@ -97,11 +97,11 @@ export type DispatchFields = React.Dispatch<any>;
|
|
|
97
97
|
export type Submit = <T extends Response, C extends Record<string, unknown>>(options?: SubmitOptions<C>, e?: React.FormEvent<HTMLFormElement>) => Promise</**
|
|
98
98
|
* Returns the form state and the response from the server.
|
|
99
99
|
*
|
|
100
|
-
* @experimental - Note: the `{ res: ... }` return type is experimental and may change in the future. Use at your own
|
|
100
|
+
* @experimental - Note: the `{ res: ... }` return type is experimental and may change in the future. Use at your own discretion.
|
|
101
101
|
*/ /**
|
|
102
102
|
* Returns the form state and the response from the server.
|
|
103
103
|
*
|
|
104
|
-
* @experimental - Note: the `{ res: ... }` return type is experimental and may change in the future. Use at your own
|
|
104
|
+
* @experimental - Note: the `{ res: ... }` return type is experimental and may change in the future. Use at your own discretion.
|
|
105
105
|
*/ {
|
|
106
106
|
formState?: FormState;
|
|
107
107
|
res: T;
|
|
@@ -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 TypedUser,\n ValidationFieldError,\n} from 'payload'\nimport type React from 'react'\nimport type { Dispatch } from 'react'\n\nimport type { AcceptValues } from './mergeServerFormState.js'\n\nexport type Preferences = {\n [key: string]: unknown\n}\n\nexport type FormOnSuccess<T = unknown, C = Record<string, unknown>> = (\n json: T,\n ctx?: {\n /**\n * Arbitrary context passed to the onSuccess callback.\n */\n context?: C\n /**\n * The form state that was sent with the request when retrieving the `json` arg.\n */\n formState?: FormState\n },\n) => Promise<FormState | void> | void\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?: FormOnSuccess\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<C = Record<string, unknown>> = {\n acceptValues?: AcceptValues\n action?: string\n /**\n * If you want to pass additional data to the onSuccess callback, you can use this context object.\n *\n * @experimental This property is experimental and may change in the future.\n */\n context?: C\n /**\n * When true, will disable the form while it is processing.\n * @default true\n */\n disableFormWhileProcessing?: boolean\n /**\n * When true, will disable the success toast after form submission.\n * @default false\n */\n disableSuccessStatus?: boolean\n method?: string\n overrides?: ((formState) => FormData) | Record<string, unknown>\n /**\n * When true, will skip validation before submitting the form.\n * @default false\n */\n skipValidation?: boolean\n}\n\nexport type DispatchFields = React.Dispatch<any>\n\nexport type Submit = <T extends Response, C extends Record<string, unknown>>(\n options?: SubmitOptions<C>,\n e?: React.FormEvent<HTMLFormElement>,\n) => Promise</**\n * Returns the form state and the response from the server.\n *\n * @experimental - Note: the `{ res: ... }` return type is experimental and may change in the future. Use at your own
|
|
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 TypedUser,\n ValidationFieldError,\n} from 'payload'\nimport type React from 'react'\nimport type { Dispatch } from 'react'\n\nimport type { AcceptValues } from './mergeServerFormState.js'\n\nexport type Preferences = {\n [key: string]: unknown\n}\n\nexport type FormOnSuccess<T = unknown, C = Record<string, unknown>> = (\n json: T,\n ctx?: {\n /**\n * Arbitrary context passed to the onSuccess callback.\n */\n context?: C\n /**\n * The form state that was sent with the request when retrieving the `json` arg.\n */\n formState?: FormState\n },\n) => Promise<FormState | void> | void\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?: FormOnSuccess\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<C = Record<string, unknown>> = {\n acceptValues?: AcceptValues\n action?: string\n /**\n * If you want to pass additional data to the onSuccess callback, you can use this context object.\n *\n * @experimental This property is experimental and may change in the future.\n */\n context?: C\n /**\n * When true, will disable the form while it is processing.\n * @default true\n */\n disableFormWhileProcessing?: boolean\n /**\n * When true, will disable the success toast after form submission.\n * @default false\n */\n disableSuccessStatus?: boolean\n method?: string\n overrides?: ((formState) => FormData) | Record<string, unknown>\n /**\n * When true, will skip validation before submitting the form.\n * @default false\n */\n skipValidation?: boolean\n}\n\nexport type DispatchFields = React.Dispatch<any>\n\nexport type Submit = <T extends Response, C extends Record<string, unknown>>(\n options?: SubmitOptions<C>,\n e?: React.FormEvent<HTMLFormElement>,\n) => Promise</**\n * Returns the form state and the response from the server.\n *\n * @experimental - Note: the `{ res: ... }` return type is experimental and may change in the future. Use at your own discretion.\n */\n{ formState?: FormState; res: T } | 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?: {\n /**\n * If provided, will use this instead of of derived data from the current form state.\n */\n data?: Data\n mergeOverrideData?: boolean\n },\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: TypedUser\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?: AcceptValues\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":"AAwQA","ignoreList":[]}
|
|
@@ -20,14 +20,14 @@ import React from 'react';
|
|
|
20
20
|
* }
|
|
21
21
|
* ```
|
|
22
22
|
*
|
|
23
|
-
* @experimental This is an experimental API and may change at any time. Use at your own
|
|
23
|
+
* @experimental This is an experimental API and may change at any time. Use at your own discretion.
|
|
24
24
|
*/
|
|
25
25
|
export declare const FieldPathContext: React.Context<string>;
|
|
26
26
|
/**
|
|
27
27
|
* Gets the current field path from the nearest `FieldPathContext` provider.
|
|
28
28
|
* All fields are wrapped in this context by default.
|
|
29
29
|
*
|
|
30
|
-
* @experimental This is an experimental API and may change at any time. Use at your own
|
|
30
|
+
* @experimental This is an experimental API and may change at any time. Use at your own discretion.
|
|
31
31
|
*/
|
|
32
32
|
export declare const useFieldPath: () => string;
|
|
33
33
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -20,14 +20,14 @@ import React from 'react';
|
|
|
20
20
|
* }
|
|
21
21
|
* ```
|
|
22
22
|
*
|
|
23
|
-
* @experimental This is an experimental API and may change at any time. Use at your own
|
|
23
|
+
* @experimental This is an experimental API and may change at any time. Use at your own discretion.
|
|
24
24
|
*/
|
|
25
25
|
export const FieldPathContext = React.createContext(undefined);
|
|
26
26
|
/**
|
|
27
27
|
* Gets the current field path from the nearest `FieldPathContext` provider.
|
|
28
28
|
* All fields are wrapped in this context by default.
|
|
29
29
|
*
|
|
30
|
-
* @experimental This is an experimental API and may change at any time. Use at your own
|
|
30
|
+
* @experimental This is an experimental API and may change at any time. Use at your own discretion.
|
|
31
31
|
*/
|
|
32
32
|
export const useFieldPath = () => {
|
|
33
33
|
const context = React.useContext(FieldPathContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":["React","FieldPathContext","createContext","undefined","useFieldPath","context","useContext"],"sources":["../../../src/forms/RenderFields/context.ts"],"sourcesContent":["import React from 'react'\n\n/**\n * All fields are wrapped in a `FieldPathContext` provider by default.\n * The `useFieldPath` hook will return this value if it exists, not the path the field was explicitly given.\n * This means if you render a field directly, you will need to wrap it with a new `FieldPathContext` provider.\n * Otherwise, it will return the parent's path, not the path it was explicitly given.\n * @example\n * ```tsx\n * 'use client'\n * import React from 'react'\n * import { TextField, FieldPathContext } from '@payloadcms/ui'\n * import type { TextFieldClientComponent } from 'payload'\n *\n * export const MyCustomField: TextFieldClientComponent = (props) => {\n * return (\n * <FieldPathContext value=\"path.to.some.other.field\">\n * <TextField {...props} />\n * </FieldPathContext>\n * )\n * }\n * ```\n *\n * @experimental This is an experimental API and may change at any time. Use at your own
|
|
1
|
+
{"version":3,"file":"context.js","names":["React","FieldPathContext","createContext","undefined","useFieldPath","context","useContext"],"sources":["../../../src/forms/RenderFields/context.ts"],"sourcesContent":["import React from 'react'\n\n/**\n * All fields are wrapped in a `FieldPathContext` provider by default.\n * The `useFieldPath` hook will return this value if it exists, not the path the field was explicitly given.\n * This means if you render a field directly, you will need to wrap it with a new `FieldPathContext` provider.\n * Otherwise, it will return the parent's path, not the path it was explicitly given.\n * @example\n * ```tsx\n * 'use client'\n * import React from 'react'\n * import { TextField, FieldPathContext } from '@payloadcms/ui'\n * import type { TextFieldClientComponent } from 'payload'\n *\n * export const MyCustomField: TextFieldClientComponent = (props) => {\n * return (\n * <FieldPathContext value=\"path.to.some.other.field\">\n * <TextField {...props} />\n * </FieldPathContext>\n * )\n * }\n * ```\n *\n * @experimental This is an experimental API and may change at any time. Use at your own discretion.\n */\nexport const FieldPathContext = React.createContext<string>(undefined)\n\n/**\n * Gets the current field path from the nearest `FieldPathContext` provider.\n * All fields are wrapped in this context by default.\n *\n * @experimental This is an experimental API and may change at any time. Use at your own discretion.\n */\nexport const useFieldPath = () => {\n const context = React.useContext(FieldPathContext)\n\n if (!context) {\n // swallow the error, not all fields are wrapped in a FieldPathContext\n return undefined\n }\n\n return context\n}\n"],"mappings":"AAAA,OAAOA,KAAA,MAAW;AAElB;;;;;;;;;;;;;;;;;;;;;;;AAuBA,OAAO,MAAMC,gBAAA,GAAmBD,KAAA,CAAME,aAAa,CAASC,SAAA;AAE5D;;;;;;AAMA,OAAO,MAAMC,YAAA,GAAeA,CAAA;EAC1B,MAAAC,OAAA,GAAgBL,KAAA,CAAAM,UAAA,CAAAL,gBAAiB;EAAA,KAE5BI,OAAA;IAAA;EAAA;EAAA,OAKEA,OAAA;AAAA,CACT","ignoreList":[]}
|
|
@@ -38,7 +38,7 @@ export declare const useConfig: () => ClientConfigContext;
|
|
|
38
38
|
* If the config here has the same reference as the config from the layout, we
|
|
39
39
|
* simply reuse the context from the layout to avoid unnecessary re-renders.
|
|
40
40
|
*
|
|
41
|
-
* @experimental This component is experimental and may change or be removed in future releases. Use at your own
|
|
41
|
+
* @experimental This component is experimental and may change or be removed in future releases. Use at your own discretion.
|
|
42
42
|
*/
|
|
43
43
|
export declare const PageConfigProvider: React.FC<{
|
|
44
44
|
readonly children: React.ReactNode;
|
|
@@ -67,7 +67,7 @@ export const useConfig = () => use(RootConfigContext);
|
|
|
67
67
|
* If the config here has the same reference as the config from the layout, we
|
|
68
68
|
* simply reuse the context from the layout to avoid unnecessary re-renders.
|
|
69
69
|
*
|
|
70
|
-
* @experimental This component is experimental and may change or be removed in future releases. Use at your own
|
|
70
|
+
* @experimental This component is experimental and may change or be removed in future releases. Use at your own discretion.
|
|
71
71
|
*/
|
|
72
72
|
export const PageConfigProvider = t0 => {
|
|
73
73
|
const $ = _c(7);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","React","createContext","use","useCallback","useEffect","useMemo","useRef","useState","RootConfigContext","undefined","ConfigProvider","children","config","configFromProps","setConfig","isFirstRenderRef","current","collectionsBySlug","globalsBySlug","collection","collections","slug","global","globals","getEntityConfig","args","collectionSlug","globalSlug","value","_jsx","useConfig","PageConfigProvider","t0","$","rootConfig","setRootConfig","t1","t2","unauthenticated","t3"],"sources":["../../../src/providers/Config/index.tsx"],"sourcesContent":["/* eslint-disable perfectionist/sort-object-types */ // Need to disable this rule because the order of the overloads is important\n'use client'\nimport type {\n ClientCollectionConfig,\n ClientConfig,\n ClientGlobalConfig,\n CollectionSlug,\n GlobalSlug,\n} from 'payload'\n\nimport React, { createContext, use, useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\ntype GetEntityConfigFn = {\n // Overload #1: collectionSlug only\n // @todo remove \"{} |\" in 4.0, which would be a breaking change\n (args: { collectionSlug: {} | CollectionSlug; globalSlug?: never }): ClientCollectionConfig\n\n // Overload #2: globalSlug only\n // @todo remove \"{} |\" in 4.0, which would be a breaking change\n (args: { collectionSlug?: never; globalSlug: {} | GlobalSlug }): ClientGlobalConfig\n\n // Overload #3: both/none (fall back to union | null)\n (args: {\n collectionSlug?: {} | CollectionSlug\n globalSlug?: {} | GlobalSlug\n }): ClientCollectionConfig | ClientGlobalConfig | null\n}\n\nexport type ClientConfigContext = {\n config: ClientConfig\n /**\n * Get a collection or global config by its slug. This is preferred over\n * using `config.collections.find` or `config.globals.find`, because\n * getEntityConfig uses a lookup map for O(1) lookups.\n */\n getEntityConfig: GetEntityConfigFn\n setConfig: (config: ClientConfig) => void\n}\n\nconst RootConfigContext = createContext<ClientConfigContext | undefined>(undefined)\n\nexport const ConfigProvider: React.FC<{\n readonly children: React.ReactNode\n readonly config: ClientConfig\n}> = ({ children, config: configFromProps }) => {\n const [config, setConfig] = useState<ClientConfig>(configFromProps)\n\n const isFirstRenderRef = useRef(true)\n\n // Need to update local config state if config from props changes, for HMR.\n // That way, config changes will be updated in the UI immediately without needing a refresh.\n useEffect(() => {\n if (isFirstRenderRef.current) {\n isFirstRenderRef.current = false\n return\n }\n\n setConfig(configFromProps)\n }, [configFromProps, setConfig])\n\n // Build lookup maps for collections and globals so we can do O(1) lookups by slug\n const { collectionsBySlug, globalsBySlug } = useMemo(() => {\n const collectionsBySlug: Record<string, ClientCollectionConfig> = {}\n const globalsBySlug: Record<string, ClientGlobalConfig> = {}\n\n for (const collection of config.collections) {\n collectionsBySlug[collection.slug] = collection\n }\n\n for (const global of config.globals) {\n globalsBySlug[global.slug] = global\n }\n\n return { collectionsBySlug, globalsBySlug }\n }, [config])\n\n const getEntityConfig = useCallback<GetEntityConfigFn>(\n (args) => {\n if ('collectionSlug' in args) {\n return collectionsBySlug[args.collectionSlug] ?? null\n }\n\n if ('globalSlug' in args) {\n return globalsBySlug[args.globalSlug] ?? null\n }\n\n return null as any\n },\n [collectionsBySlug, globalsBySlug],\n )\n\n const value = useMemo(\n () => ({ config, getEntityConfig, setConfig }),\n [config, getEntityConfig, setConfig],\n )\n\n return <RootConfigContext value={value}>{children}</RootConfigContext>\n}\n\nexport const useConfig = (): ClientConfigContext => use(RootConfigContext)\n\n/**\n * This provider shadows the `ConfigProvider` on the _page_ level, allowing us to\n * update the config when needed, e.g. after authentication.\n * The layout `ConfigProvider` is not updated on page navigation / authentication,\n * as the layout does not re-render in those cases.\n *\n * If the config here has the same reference as the config from the layout, we\n * simply reuse the context from the layout to avoid unnecessary re-renders.\n *\n * @experimental This component is experimental and may change or be removed in future releases. Use at your own
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","React","createContext","use","useCallback","useEffect","useMemo","useRef","useState","RootConfigContext","undefined","ConfigProvider","children","config","configFromProps","setConfig","isFirstRenderRef","current","collectionsBySlug","globalsBySlug","collection","collections","slug","global","globals","getEntityConfig","args","collectionSlug","globalSlug","value","_jsx","useConfig","PageConfigProvider","t0","$","rootConfig","setRootConfig","t1","t2","unauthenticated","t3"],"sources":["../../../src/providers/Config/index.tsx"],"sourcesContent":["/* eslint-disable perfectionist/sort-object-types */ // Need to disable this rule because the order of the overloads is important\n'use client'\nimport type {\n ClientCollectionConfig,\n ClientConfig,\n ClientGlobalConfig,\n CollectionSlug,\n GlobalSlug,\n} from 'payload'\n\nimport React, { createContext, use, useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\ntype GetEntityConfigFn = {\n // Overload #1: collectionSlug only\n // @todo remove \"{} |\" in 4.0, which would be a breaking change\n (args: { collectionSlug: {} | CollectionSlug; globalSlug?: never }): ClientCollectionConfig\n\n // Overload #2: globalSlug only\n // @todo remove \"{} |\" in 4.0, which would be a breaking change\n (args: { collectionSlug?: never; globalSlug: {} | GlobalSlug }): ClientGlobalConfig\n\n // Overload #3: both/none (fall back to union | null)\n (args: {\n collectionSlug?: {} | CollectionSlug\n globalSlug?: {} | GlobalSlug\n }): ClientCollectionConfig | ClientGlobalConfig | null\n}\n\nexport type ClientConfigContext = {\n config: ClientConfig\n /**\n * Get a collection or global config by its slug. This is preferred over\n * using `config.collections.find` or `config.globals.find`, because\n * getEntityConfig uses a lookup map for O(1) lookups.\n */\n getEntityConfig: GetEntityConfigFn\n setConfig: (config: ClientConfig) => void\n}\n\nconst RootConfigContext = createContext<ClientConfigContext | undefined>(undefined)\n\nexport const ConfigProvider: React.FC<{\n readonly children: React.ReactNode\n readonly config: ClientConfig\n}> = ({ children, config: configFromProps }) => {\n const [config, setConfig] = useState<ClientConfig>(configFromProps)\n\n const isFirstRenderRef = useRef(true)\n\n // Need to update local config state if config from props changes, for HMR.\n // That way, config changes will be updated in the UI immediately without needing a refresh.\n useEffect(() => {\n if (isFirstRenderRef.current) {\n isFirstRenderRef.current = false\n return\n }\n\n setConfig(configFromProps)\n }, [configFromProps, setConfig])\n\n // Build lookup maps for collections and globals so we can do O(1) lookups by slug\n const { collectionsBySlug, globalsBySlug } = useMemo(() => {\n const collectionsBySlug: Record<string, ClientCollectionConfig> = {}\n const globalsBySlug: Record<string, ClientGlobalConfig> = {}\n\n for (const collection of config.collections) {\n collectionsBySlug[collection.slug] = collection\n }\n\n for (const global of config.globals) {\n globalsBySlug[global.slug] = global\n }\n\n return { collectionsBySlug, globalsBySlug }\n }, [config])\n\n const getEntityConfig = useCallback<GetEntityConfigFn>(\n (args) => {\n if ('collectionSlug' in args) {\n return collectionsBySlug[args.collectionSlug] ?? null\n }\n\n if ('globalSlug' in args) {\n return globalsBySlug[args.globalSlug] ?? null\n }\n\n return null as any\n },\n [collectionsBySlug, globalsBySlug],\n )\n\n const value = useMemo(\n () => ({ config, getEntityConfig, setConfig }),\n [config, getEntityConfig, setConfig],\n )\n\n return <RootConfigContext value={value}>{children}</RootConfigContext>\n}\n\nexport const useConfig = (): ClientConfigContext => use(RootConfigContext)\n\n/**\n * This provider shadows the `ConfigProvider` on the _page_ level, allowing us to\n * update the config when needed, e.g. after authentication.\n * The layout `ConfigProvider` is not updated on page navigation / authentication,\n * as the layout does not re-render in those cases.\n *\n * If the config here has the same reference as the config from the layout, we\n * simply reuse the context from the layout to avoid unnecessary re-renders.\n *\n * @experimental This component is experimental and may change or be removed in future releases. Use at your own discretion.\n */\nexport const PageConfigProvider: React.FC<{\n readonly children: React.ReactNode\n readonly config: ClientConfig\n}> = ({ children, config: configFromProps }) => {\n const { config: rootConfig, setConfig: setRootConfig } = useConfig()\n\n /**\n * This `useEffect` is required in order for the _page_ to be able to refresh the client config,\n * which may have been cached on the _layout_ level, where the `ConfigProvider` is managed.\n * Since the layout does not re-render on page navigation / authentication, we need to manually\n * update the config, as the user may have been authenticated in the process, which affects the client config.\n */\n useEffect(() => {\n setRootConfig(configFromProps)\n }, [configFromProps, setRootConfig])\n\n // If this component receives a different config than what is in context from the layout, it is stale.\n // While stale, we instantiate a new context provider that provides the new config until the root context is updated.\n // Unfortunately, referential equality alone does not work bc the reference is lost during server/client serialization,\n // so we need to also compare the `unauthenticated` property.\n if (\n rootConfig !== configFromProps &&\n rootConfig.unauthenticated !== configFromProps.unauthenticated\n ) {\n return <ConfigProvider config={configFromProps}>{children}</ConfigProvider>\n }\n\n return children\n}\n"],"mappings":"AAAA,sDAAsD;AACtD;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AASA,OAAOC,KAAA,IAASC,aAAa,EAAEC,GAAG,EAAEC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AA6B7F,MAAMC,iBAAA,gBAAoBP,aAAA,CAA+CQ,SAAA;AAEzE,OAAO,MAAMC,cAAA,GAGRA,CAAC;EAAEC,QAAQ;EAAEC,MAAA,EAAQC;AAAe,CAAE;EACzC,MAAM,CAACD,MAAA,EAAQE,SAAA,CAAU,GAAGP,QAAA,CAAuBM,eAAA;EAEnD,MAAME,gBAAA,GAAmBT,MAAA,CAAO;EAEhC;EACA;EACAF,SAAA,CAAU;IACR,IAAIW,gBAAA,CAAiBC,OAAO,EAAE;MAC5BD,gBAAA,CAAiBC,OAAO,GAAG;MAC3B;IACF;IAEAF,SAAA,CAAUD,eAAA;EACZ,GAAG,CAACA,eAAA,EAAiBC,SAAA,CAAU;EAE/B;EACA,MAAM;IAAEG,iBAAiB,EAAjBA,mBAAiB;IAAEC,aAAa,EAAbA;EAAa,CAAE,GAAGb,OAAA,CAAQ;IACnD,MAAMY,iBAAA,GAA4D,CAAC;IACnE,MAAMC,aAAA,GAAoD,CAAC;IAE3D,KAAK,MAAMC,UAAA,IAAcP,MAAA,CAAOQ,WAAW,EAAE;MAC3CH,iBAAiB,C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