@payloadcms/ui 3.59.0-internal.b804ca6 → 3.59.0-internal.c8403a3
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/CodeEditor/CodeEditor.js +1 -1
- package/dist/elements/CodeEditor/CodeEditor.js.map +1 -1
- package/dist/elements/Combobox/index.d.ts +30 -0
- package/dist/elements/Combobox/index.d.ts.map +1 -0
- package/dist/elements/Combobox/index.js +96 -0
- package/dist/elements/Combobox/index.js.map +1 -0
- package/dist/elements/Combobox/index.scss +49 -0
- package/dist/elements/PageControls/index.d.ts +9 -0
- package/dist/elements/PageControls/index.d.ts.map +1 -1
- package/dist/elements/PageControls/index.js +101 -45
- package/dist/elements/PageControls/index.js.map +1 -1
- package/dist/elements/Popup/PopupButtonList/index.scss +3 -4
- package/dist/elements/Popup/index.scss +2 -0
- package/dist/elements/StickyToolbar/index.d.ts +3 -0
- package/dist/elements/StickyToolbar/index.d.ts.map +1 -1
- package/dist/elements/StickyToolbar/index.js +3 -0
- package/dist/elements/StickyToolbar/index.js.map +1 -1
- package/dist/exports/client/{CodeEditor-2AHTKKBE.js → CodeEditor-DSS2HY4R.js} +2 -2
- package/dist/exports/client/{chunk-6UH4KUYK.js → chunk-UFVHYD7C.js} +2 -2
- package/dist/exports/client/{chunk-6UH4KUYK.js.map → chunk-UFVHYD7C.js.map} +3 -3
- package/dist/exports/client/index.d.ts +5 -0
- 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/fields/Code/index.d.ts.map +1 -1
- package/dist/fields/Code/index.js +2 -1
- package/dist/fields/Code/index.js.map +1 -1
- 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/hooks/useControllableState.d.ts +2 -0
- package/dist/hooks/useControllableState.d.ts.map +1 -1
- package/dist/hooks/useControllableState.js +44 -11
- package/dist/hooks/useControllableState.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +4 -4
- /package/dist/exports/client/{CodeEditor-2AHTKKBE.js.map → CodeEditor-DSS2HY4R.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Code/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAWxE,OAAO,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Code/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAWxE,OAAO,cAAc,CAAA;AAoIrB,eAAO,MAAM,SAAS;;;;;;;+EAAoC,CAAA"}
|
|
@@ -14,7 +14,8 @@ import { fieldBaseClass } from '../shared/index.js';
|
|
|
14
14
|
import './index.scss';
|
|
15
15
|
const prismToMonacoLanguageMap = {
|
|
16
16
|
js: 'javascript',
|
|
17
|
-
ts: 'typescript'
|
|
17
|
+
ts: 'typescript',
|
|
18
|
+
tsx: 'typescript'
|
|
18
19
|
};
|
|
19
20
|
const baseClass = 'code-field';
|
|
20
21
|
const CodeFieldComponent = props => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","useCallback","useEffect","useMemo","useState","CodeEditor","RenderCustomComponent","FieldDescription","FieldError","FieldLabel","useField","withCondition","mergeFieldStyles","fieldBaseClass","prismToMonacoLanguageMap","js","ts","baseClass","CodeFieldComponent","props","field","admin","className","description","editorOptions","editorProps","language","label","localized","required","onMount","path","pathFromProps","readOnly","validate","inputChangeFromRef","useRef","recalculatedHeightAt","setRecalculatedHeightAt","Date","now","memoizedValidate","value","options","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","initialValue","setValue","showError","potentiallyStalePath","stringValueRef","undefined","handleChange","val","current","e","styles","_jsxs","filter","Boolean","join","style","_jsx","CustomComponent","Fallback","defaultLanguage","onChange","wrapperProps","id","replace","CodeField"],"sources":["../../../src/fields/Code/index.tsx"],"sourcesContent":["'use client'\nimport type { CodeFieldClientComponent } from 'payload'\n\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport { CodeEditor } from '../../elements/CodeEditor/index.js'\nimport { RenderCustomComponent } from '../../elements/RenderCustomComponent/index.js'\nimport { FieldDescription } from '../../fields/FieldDescription/index.js'\nimport { FieldError } from '../../fields/FieldError/index.js'\nimport { FieldLabel } from '../../fields/FieldLabel/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { mergeFieldStyles } from '../mergeFieldStyles.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst prismToMonacoLanguageMap = {\n js: 'javascript',\n ts: 'typescript',\n}\n\nconst baseClass = 'code-field'\n\nconst CodeFieldComponent: CodeFieldClientComponent = (props) => {\n const {\n field,\n field: {\n admin: { className, description, editorOptions, editorProps, language = 'javascript' } = {},\n label,\n localized,\n required,\n },\n onMount,\n path: pathFromProps,\n readOnly,\n validate,\n } = props\n\n const inputChangeFromRef = React.useRef<'formState' | 'internalEditor'>('formState')\n const [recalculatedHeightAt, setRecalculatedHeightAt] = useState<number | undefined>(Date.now())\n\n const memoizedValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function') {\n return validate(value, { ...options, required })\n }\n },\n [validate, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled,\n initialValue,\n path,\n setValue,\n showError,\n value,\n } = useField<string>({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const stringValueRef = React.useRef<string>(\n (value || initialValue) !== undefined ? (value ?? initialValue) : undefined,\n )\n\n const handleChange = useCallback(\n (val: string) => {\n if (readOnly || disabled) {\n return\n }\n inputChangeFromRef.current = 'internalEditor'\n\n try {\n setValue(val ? val : null)\n stringValueRef.current = val\n } catch (e) {\n setValue(val ? val : null)\n stringValueRef.current = val\n }\n },\n [readOnly, disabled, setValue],\n )\n\n useEffect(() => {\n if (inputChangeFromRef.current === 'formState') {\n stringValueRef.current =\n (value || initialValue) !== undefined ? (value ?? initialValue) : undefined\n setRecalculatedHeightAt(Date.now())\n }\n\n inputChangeFromRef.current = 'formState'\n }, [initialValue, path, value])\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n showError && 'error',\n (readOnly || disabled) && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n style={styles}\n >\n <RenderCustomComponent\n CustomComponent={Label}\n Fallback={\n <FieldLabel label={label} localized={localized} path={path} required={required} />\n }\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n {BeforeInput}\n <CodeEditor\n defaultLanguage={prismToMonacoLanguageMap[language] || language}\n onChange={handleChange}\n onMount={onMount}\n options={editorOptions}\n readOnly={readOnly || disabled}\n recalculatedHeightAt={recalculatedHeightAt}\n value={stringValueRef.current}\n wrapperProps={{\n id: `field-${path?.replace(/\\./g, '__')}`,\n }}\n {...(editorProps || {})}\n />\n {AfterInput}\n </div>\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n )\n}\n\nexport const CodeField = withCondition(CodeFieldComponent)\n"],"mappings":"AAAA;;;AAGA,OAAOA,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AAEjE,SAASC,UAAU,QAAQ;AAC3B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,UAAU,QAAQ;AAC3B,SAASC,UAAU,QAAQ;AAC3B,SAASC,QAAQ,QAAQ;AACzB,SAASC,aAAa,QAAQ;AAC9B,SAASC,gBAAgB,QAAQ;AACjC,SAASC,cAAc,QAAQ;AAC/B,OAAO;AAEP,MAAMC,wBAAA,GAA2B;EAC/BC,EAAA,EAAI;EACJC,EAAA,EAAI;
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","useCallback","useEffect","useMemo","useState","CodeEditor","RenderCustomComponent","FieldDescription","FieldError","FieldLabel","useField","withCondition","mergeFieldStyles","fieldBaseClass","prismToMonacoLanguageMap","js","ts","tsx","baseClass","CodeFieldComponent","props","field","admin","className","description","editorOptions","editorProps","language","label","localized","required","onMount","path","pathFromProps","readOnly","validate","inputChangeFromRef","useRef","recalculatedHeightAt","setRecalculatedHeightAt","Date","now","memoizedValidate","value","options","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","initialValue","setValue","showError","potentiallyStalePath","stringValueRef","undefined","handleChange","val","current","e","styles","_jsxs","filter","Boolean","join","style","_jsx","CustomComponent","Fallback","defaultLanguage","onChange","wrapperProps","id","replace","CodeField"],"sources":["../../../src/fields/Code/index.tsx"],"sourcesContent":["'use client'\nimport type { CodeFieldClientComponent } from 'payload'\n\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport { CodeEditor } from '../../elements/CodeEditor/index.js'\nimport { RenderCustomComponent } from '../../elements/RenderCustomComponent/index.js'\nimport { FieldDescription } from '../../fields/FieldDescription/index.js'\nimport { FieldError } from '../../fields/FieldError/index.js'\nimport { FieldLabel } from '../../fields/FieldLabel/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { mergeFieldStyles } from '../mergeFieldStyles.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst prismToMonacoLanguageMap = {\n js: 'javascript',\n ts: 'typescript',\n tsx: 'typescript',\n}\n\nconst baseClass = 'code-field'\n\nconst CodeFieldComponent: CodeFieldClientComponent = (props) => {\n const {\n field,\n field: {\n admin: { className, description, editorOptions, editorProps, language = 'javascript' } = {},\n label,\n localized,\n required,\n },\n onMount,\n path: pathFromProps,\n readOnly,\n validate,\n } = props\n\n const inputChangeFromRef = React.useRef<'formState' | 'internalEditor'>('formState')\n const [recalculatedHeightAt, setRecalculatedHeightAt] = useState<number | undefined>(Date.now())\n\n const memoizedValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function') {\n return validate(value, { ...options, required })\n }\n },\n [validate, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled,\n initialValue,\n path,\n setValue,\n showError,\n value,\n } = useField<string>({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const stringValueRef = React.useRef<string>(\n (value || initialValue) !== undefined ? (value ?? initialValue) : undefined,\n )\n\n const handleChange = useCallback(\n (val: string) => {\n if (readOnly || disabled) {\n return\n }\n inputChangeFromRef.current = 'internalEditor'\n\n try {\n setValue(val ? val : null)\n stringValueRef.current = val\n } catch (e) {\n setValue(val ? val : null)\n stringValueRef.current = val\n }\n },\n [readOnly, disabled, setValue],\n )\n\n useEffect(() => {\n if (inputChangeFromRef.current === 'formState') {\n stringValueRef.current =\n (value || initialValue) !== undefined ? (value ?? initialValue) : undefined\n setRecalculatedHeightAt(Date.now())\n }\n\n inputChangeFromRef.current = 'formState'\n }, [initialValue, path, value])\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n showError && 'error',\n (readOnly || disabled) && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n style={styles}\n >\n <RenderCustomComponent\n CustomComponent={Label}\n Fallback={\n <FieldLabel label={label} localized={localized} path={path} required={required} />\n }\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n {BeforeInput}\n <CodeEditor\n defaultLanguage={prismToMonacoLanguageMap[language] || language}\n onChange={handleChange}\n onMount={onMount}\n options={editorOptions}\n readOnly={readOnly || disabled}\n recalculatedHeightAt={recalculatedHeightAt}\n value={stringValueRef.current}\n wrapperProps={{\n id: `field-${path?.replace(/\\./g, '__')}`,\n }}\n {...(editorProps || {})}\n />\n {AfterInput}\n </div>\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n )\n}\n\nexport const CodeField = withCondition(CodeFieldComponent)\n"],"mappings":"AAAA;;;AAGA,OAAOA,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AAEjE,SAASC,UAAU,QAAQ;AAC3B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,UAAU,QAAQ;AAC3B,SAASC,UAAU,QAAQ;AAC3B,SAASC,QAAQ,QAAQ;AACzB,SAASC,aAAa,QAAQ;AAC9B,SAASC,gBAAgB,QAAQ;AACjC,SAASC,cAAc,QAAQ;AAC/B,OAAO;AAEP,MAAMC,wBAAA,GAA2B;EAC/BC,EAAA,EAAI;EACJC,EAAA,EAAI;EACJC,GAAA,EAAK;AACP;AAEA,MAAMC,SAAA,GAAY;AAElB,MAAMC,kBAAA,GAAgDC,KAAA;EACpD,MAAM;IACJC,KAAK;IACLA,KAAA,EAAO;MACLC,KAAA,EAAO;QAAEC,SAAS;QAAEC,WAAW;QAAEC,aAAa;QAAEC,WAAW;QAAEC,QAAA,GAAW;MAAY,CAAE,GAAG,CAAC,CAAC;MAC3FC,KAAK;MACLC,SAAS;MACTC;IAAQ,CACT;IACDC,OAAO;IACPC,IAAA,EAAMC,aAAa;IACnBC,QAAQ;IACRC;EAAQ,CACT,GAAGf,KAAA;EAEJ,MAAMgB,kBAAA,GAAqBpC,KAAA,CAAMqC,MAAM,CAAiC;EACxE,MAAM,CAACC,oBAAA,EAAsBC,uBAAA,CAAwB,GAAGnC,QAAA,CAA6BoC,IAAA,CAAKC,GAAG;EAE7F,MAAMC,gBAAA,GAAmBzC,WAAA,CACvB,CAAC0C,KAAA,EAAOC,OAAA;IACN,IAA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AEvBoB,UAAA;qBAEHsB,IAAA,CAAC9D,qBAAA;MACC+D,eAAA,EAAiBrB,WAAA;MACjBsB,QAAA,eAAUF,IAAA,CAAC7D,gBAAA;QAAiBiB,WAAA,EAAaA,WAAA;QAAaQ,IAAA,EAAMA;;;;AAIpE;AAEA,OAAO,MAAM4C,SAAA,GAAYjE,aAAA,CAAcQ,kBAAA","ignoreList":[]}
|
|
@@ -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,EAA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AAA,EAAK1C,KAAA,CAAM;UAClB,IACE,CACE,mBACA,gBACA,gBACA,QACA,SACA,YACA,QACD,CAACoC,QAAQ,CAACM,GAAA,GACX;YACA,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,IA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AAA,CAAM;UAClB,IACE,CACE,mBACA,gBACA,gBACA,QACA,SACA,YACA,QACD,CAACoC,QAAQ,CAACM,GAAA,GACX;YACA,OAAO;cACL,GAAGiC,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":[]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A hook for managing state that can be controlled by props but also overridden locally.
|
|
3
3
|
* Props always take precedence if they change, but local state can override them temporarily.
|
|
4
|
+
*
|
|
5
|
+
* @internal - may change or be removed without a major version bump
|
|
4
6
|
*/
|
|
5
7
|
export declare function useControllableState<T>(propValue: T, defaultValue?: T): [T, (value: ((prev: T) => T) | T) => void];
|
|
6
8
|
//# sourceMappingURL=useControllableState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useControllableState.d.ts","sourceRoot":"","sources":["../../src/hooks/useControllableState.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useControllableState.d.ts","sourceRoot":"","sources":["../../src/hooks/useControllableState.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,SAAS,EAAE,CAAC,EACZ,YAAY,CAAC,EAAE,CAAC,GACf,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAkB5C"}
|
|
@@ -1,21 +1,54 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { c as _c } from "react/compiler-runtime";
|
|
1
4
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
5
|
/**
|
|
3
6
|
* A hook for managing state that can be controlled by props but also overridden locally.
|
|
4
7
|
* Props always take precedence if they change, but local state can override them temporarily.
|
|
8
|
+
*
|
|
9
|
+
* @internal - may change or be removed without a major version bump
|
|
5
10
|
*/
|
|
6
11
|
export function useControllableState(propValue, defaultValue) {
|
|
12
|
+
const $ = _c(6);
|
|
7
13
|
const [localValue, setLocalValue] = useState(propValue ?? defaultValue);
|
|
8
14
|
const initialRenderRef = useRef(true);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
let t0;
|
|
16
|
+
let t1;
|
|
17
|
+
if ($[0] !== propValue) {
|
|
18
|
+
t0 = () => {
|
|
19
|
+
if (initialRenderRef.current) {
|
|
20
|
+
initialRenderRef.current = false;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
setLocalValue(propValue);
|
|
24
|
+
};
|
|
25
|
+
t1 = [propValue];
|
|
26
|
+
$[0] = propValue;
|
|
27
|
+
$[1] = t0;
|
|
28
|
+
$[2] = t1;
|
|
29
|
+
} else {
|
|
30
|
+
t0 = $[1];
|
|
31
|
+
t1 = $[2];
|
|
32
|
+
}
|
|
33
|
+
useEffect(t0, t1);
|
|
34
|
+
let t2;
|
|
35
|
+
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
|
|
36
|
+
t2 = value => {
|
|
37
|
+
setLocalValue(value);
|
|
38
|
+
};
|
|
39
|
+
$[3] = t2;
|
|
40
|
+
} else {
|
|
41
|
+
t2 = $[3];
|
|
42
|
+
}
|
|
43
|
+
const setValue = t2;
|
|
44
|
+
let t3;
|
|
45
|
+
if ($[4] !== localValue) {
|
|
46
|
+
t3 = [localValue, setValue];
|
|
47
|
+
$[4] = localValue;
|
|
48
|
+
$[5] = t3;
|
|
49
|
+
} else {
|
|
50
|
+
t3 = $[5];
|
|
51
|
+
}
|
|
52
|
+
return t3;
|
|
20
53
|
}
|
|
21
54
|
//# sourceMappingURL=useControllableState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useControllableState.js","names":["useCallback","useEffect","useRef","useState","useControllableState","propValue","defaultValue","localValue","setLocalValue","initialRenderRef","current","
|
|
1
|
+
{"version":3,"file":"useControllableState.js","names":["c","_c","useCallback","useEffect","useRef","useState","useControllableState","propValue","defaultValue","$","localValue","setLocalValue","initialRenderRef","t0","t1","current","t2","Symbol","for","value","setValue","t3"],"sources":["../../src/hooks/useControllableState.ts"],"sourcesContent":["'use client'\nimport { useCallback, useEffect, useRef, useState } from 'react'\n\n/**\n * A hook for managing state that can be controlled by props but also overridden locally.\n * Props always take precedence if they change, but local state can override them temporarily.\n *\n * @internal - may change or be removed without a major version bump\n */\nexport function useControllableState<T>(\n propValue: T,\n defaultValue?: T,\n): [T, (value: ((prev: T) => T) | T) => void] {\n const [localValue, setLocalValue] = useState<T>(propValue ?? defaultValue)\n const initialRenderRef = useRef(true)\n\n useEffect(() => {\n if (initialRenderRef.current) {\n initialRenderRef.current = false\n return\n }\n\n setLocalValue(propValue)\n }, [propValue])\n\n const setValue = useCallback((value: ((prev: T) => T) | T) => {\n setLocalValue(value)\n }, [])\n\n return [localValue, setValue]\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AACA,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAEzD;;;;;;AAMA,OAAO,SAAAC,qBAAAC,SAAA,EAAAC,YAAA;EAAA,MAAAC,CAAA,GAAAR,EAAA;EAIL,OAAAS,UAAA,EAAAC,aAAA,IAAoCN,QAAA,CAAYE,SAAA,IAAaC,YAAA;EAC7D,MAAAI,gBAAA,GAAyBR,MAAA,KAAO;EAAA,IAAAS,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAL,CAAA,QAAAF,SAAA;IAEtBM,EAAA,GAAAA,CAAA;MAAA,IACJD,gBAAA,CAAAG,OAAA;QACFH,gBAAA,CAAAG,OAAA;QAAA;MAAA;MAIFJ,aAAA,CAAcJ,SAAA;IAAA;IACbO,EAAA,IAACP,SAAA;IAAUE,CAAA,MAAAF,SAAA;IAAAE,CAAA,MAAAI,EAAA;IAAAJ,CAAA,MAAAK,EAAA;EAAA;IAAAD,EAAA,GAAAJ,CAAA;IAAAK,EAAA,GAAAL,CAAA;EAAA;EAPdN,SAAA,CAAUU,EAOV,EAAGC,EAAW;EAAA,IAAAE,EAAA;EAAA,IAAAP,CAAA,QAAAQ,MAAA,CAAAC,GAAA;IAEeF,EAAA,GAAAG,KAAA;MAC3BR,aAAA,CAAcQ,KAAA;IAAA;IAChBV,CAAA,MAAAO,EAAA;EAAA;IAAAA,EAAA,GAAAP,CAAA;EAAA;EAFA,MAAAW,QAAA,GAAiBJ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