@payloadcms/ui 3.59.0-internal.ff6711a → 3.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/elements/Collapsible/index.d.ts +2 -15
- package/dist/elements/Collapsible/index.d.ts.map +1 -1
- package/dist/elements/Collapsible/index.js +60 -59
- package/dist/elements/Collapsible/index.js.map +1 -1
- package/dist/elements/Collapsible/index.scss +2 -6
- package/dist/elements/DocumentDrawer/Provider.d.ts +1 -1
- package/dist/elements/DocumentDrawer/Provider.js.map +1 -1
- package/dist/elements/Nav/context.d.ts +0 -6
- package/dist/elements/Nav/context.d.ts.map +1 -1
- package/dist/elements/Nav/context.js +0 -6
- package/dist/elements/Nav/context.js.map +1 -1
- package/dist/elements/PageControls/index.d.ts +0 -9
- package/dist/elements/PageControls/index.d.ts.map +1 -1
- package/dist/elements/PageControls/index.js +45 -101
- package/dist/elements/PageControls/index.js.map +1 -1
- package/dist/elements/StickyToolbar/index.d.ts +0 -3
- package/dist/elements/StickyToolbar/index.d.ts.map +1 -1
- package/dist/elements/StickyToolbar/index.js +0 -3
- package/dist/elements/StickyToolbar/index.js.map +1 -1
- package/dist/exports/client/{CodeEditor-2AHTKKBE.js → CodeEditor-UTOLPRAV.js} +2 -2
- package/dist/exports/client/{chunk-6UH4KUYK.js → chunk-S2X3JKSP.js} +1 -1
- package/dist/exports/client/{chunk-6UH4KUYK.js.map → chunk-S2X3JKSP.js.map} +1 -1
- package/dist/exports/client/index.d.ts +2 -4
- 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 +1 -3
- package/dist/fields/Code/index.js.map +1 -1
- package/dist/fields/Slug/index.d.ts +8 -0
- package/dist/fields/Slug/index.d.ts.map +1 -0
- package/dist/fields/Slug/index.js +128 -0
- package/dist/fields/Slug/index.js.map +1 -0
- package/dist/fields/Slug/index.scss +17 -0
- 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/hooks/useControllableState.d.ts +0 -2
- package/dist/hooks/useControllableState.d.ts.map +1 -1
- package/dist/hooks/useControllableState.js +11 -44
- package/dist/hooks/useControllableState.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/package.json +4 -4
- /package/dist/exports/client/{CodeEditor-2AHTKKBE.js.map → CodeEditor-UTOLPRAV.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;AAkIrB,eAAO,MAAM,SAAS;;;;;;;+EAAoC,CAAA"}
|
|
@@ -25,7 +25,6 @@ const CodeFieldComponent = props => {
|
|
|
25
25
|
className,
|
|
26
26
|
description,
|
|
27
27
|
editorOptions,
|
|
28
|
-
editorProps,
|
|
29
28
|
language = 'javascript'
|
|
30
29
|
} = {},
|
|
31
30
|
label,
|
|
@@ -116,8 +115,7 @@ const CodeFieldComponent = props => {
|
|
|
116
115
|
value: stringValueRef.current,
|
|
117
116
|
wrapperProps: {
|
|
118
117
|
id: `field-${path?.replace(/\./g, '__')}`
|
|
119
|
-
}
|
|
120
|
-
...(editorProps || {})
|
|
118
|
+
}
|
|
121
119
|
}), AfterInput]
|
|
122
120
|
}), /*#__PURE__*/_jsx(RenderCustomComponent, {
|
|
123
121
|
CustomComponent: Description,
|
|
@@ -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","
|
|
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","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, 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 />\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;AACN;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,QAAA,GAAW;MAAY,CAAE,GAAG,CAAC,CAAC;MAC9EC,KAAK;MACL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AA,CAAS,IAAIA,QAAA;QACvD6C,QAAA,EAAUd,YAAA;QACV3B,OAAA,EAASA,OAAA;QACTa,OAAA,EAASlB,aAAA;QACTQ,QAAA,EAAUA,QAAA,IAAYiB,QAAA;QACtBb,oBAAA,EAAsBA,oBAAA;QACtBK,KAAA,EAAOa,cAAA,CAAeI,OAAO;QAC7Ba,YAAA,EAAc;UACZC,EAAA,EAAI,SAAS1C,IAAA,EAAM2C,OAAA,CAAQ,OAAO;QACpC;UAED7B,UAAA;qBAEHsB,IAAA,CAAC5D,qBAAA;MACC6D,eAAA,EAAiBrB,WAAA;MACjBsB,QAAA,eAAUF,IAAA,CAAC3D,gBAAA;QAAiBgB,WAAA,EAAaA,WAAA;QAAaO,IAAA,EAAMA;;;;AAIpE;AAEA,OAAO,MAAM4C,SAAA,GAAY/D,aAAA,CAAcO,kBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SlugFieldProps } from 'payload';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import './index.scss';
|
|
4
|
+
/**
|
|
5
|
+
* @experimental This component is experimental and may change or be removed in the future. Use at your own risk.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SlugField: React.FC<SlugFieldProps>;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Slug/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAG7C,OAAO,KAAgC,MAAM,OAAO,CAAA;AAOpD,OAAO,cAAc,CAAA;AAErB;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CA6D9C,CAAA"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { c as _c } from "react/compiler-runtime";
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { slugify } from 'payload/shared';
|
|
6
|
+
import React, { useCallback, useState } from 'react';
|
|
7
|
+
import { Button } from '../../elements/Button/index.js';
|
|
8
|
+
import { useForm } from '../../forms/Form/index.js';
|
|
9
|
+
import { useField } from '../../forms/useField/index.js';
|
|
10
|
+
import { FieldLabel } from '../FieldLabel/index.js';
|
|
11
|
+
import { TextInput } from '../Text/index.js';
|
|
12
|
+
import './index.scss';
|
|
13
|
+
/**
|
|
14
|
+
* @experimental This component is experimental and may change or be removed in the future. Use at your own risk.
|
|
15
|
+
*/
|
|
16
|
+
export const SlugField = t0 => {
|
|
17
|
+
const $ = _c(18);
|
|
18
|
+
const {
|
|
19
|
+
field,
|
|
20
|
+
fieldToUse,
|
|
21
|
+
path,
|
|
22
|
+
readOnly: readOnlyFromProps
|
|
23
|
+
} = t0;
|
|
24
|
+
const {
|
|
25
|
+
label
|
|
26
|
+
} = field;
|
|
27
|
+
const t1 = path || field.name;
|
|
28
|
+
let t2;
|
|
29
|
+
if ($[0] !== t1) {
|
|
30
|
+
t2 = {
|
|
31
|
+
path: t1
|
|
32
|
+
};
|
|
33
|
+
$[0] = t1;
|
|
34
|
+
$[1] = t2;
|
|
35
|
+
} else {
|
|
36
|
+
t2 = $[1];
|
|
37
|
+
}
|
|
38
|
+
const {
|
|
39
|
+
setValue,
|
|
40
|
+
value
|
|
41
|
+
} = useField(t2);
|
|
42
|
+
const {
|
|
43
|
+
getDataByPath
|
|
44
|
+
} = useForm();
|
|
45
|
+
const [isLocked, setIsLocked] = useState(true);
|
|
46
|
+
let t3;
|
|
47
|
+
if ($[2] !== fieldToUse || $[3] !== getDataByPath || $[4] !== setValue || $[5] !== value) {
|
|
48
|
+
t3 = e => {
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
const targetFieldValue = getDataByPath(fieldToUse);
|
|
51
|
+
if (targetFieldValue) {
|
|
52
|
+
const formattedSlug = slugify(targetFieldValue);
|
|
53
|
+
if (value !== formattedSlug) {
|
|
54
|
+
setValue(formattedSlug);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
if (value !== "") {
|
|
58
|
+
setValue("");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
$[2] = fieldToUse;
|
|
63
|
+
$[3] = getDataByPath;
|
|
64
|
+
$[4] = setValue;
|
|
65
|
+
$[5] = value;
|
|
66
|
+
$[6] = t3;
|
|
67
|
+
} else {
|
|
68
|
+
t3 = $[6];
|
|
69
|
+
}
|
|
70
|
+
const handleGenerate = t3;
|
|
71
|
+
let t4;
|
|
72
|
+
if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
|
|
73
|
+
t4 = e_0 => {
|
|
74
|
+
e_0.preventDefault();
|
|
75
|
+
setIsLocked(_temp);
|
|
76
|
+
};
|
|
77
|
+
$[7] = t4;
|
|
78
|
+
} else {
|
|
79
|
+
t4 = $[7];
|
|
80
|
+
}
|
|
81
|
+
const toggleLock = t4;
|
|
82
|
+
const t5 = `field-${path}`;
|
|
83
|
+
let t6;
|
|
84
|
+
if ($[8] !== field.name || $[9] !== handleGenerate || $[10] !== isLocked || $[11] !== label || $[12] !== path || $[13] !== readOnlyFromProps || $[14] !== setValue || $[15] !== t5 || $[16] !== value) {
|
|
85
|
+
t6 = _jsxs("div", {
|
|
86
|
+
className: "field-type slug-field-component",
|
|
87
|
+
children: [_jsxs("div", {
|
|
88
|
+
className: "label-wrapper",
|
|
89
|
+
children: [_jsx(FieldLabel, {
|
|
90
|
+
htmlFor: t5,
|
|
91
|
+
label
|
|
92
|
+
}), !isLocked && _jsx(Button, {
|
|
93
|
+
buttonStyle: "none",
|
|
94
|
+
className: "lock-button",
|
|
95
|
+
onClick: handleGenerate,
|
|
96
|
+
children: "Generate"
|
|
97
|
+
}), _jsx(Button, {
|
|
98
|
+
buttonStyle: "none",
|
|
99
|
+
className: "lock-button",
|
|
100
|
+
onClick: toggleLock,
|
|
101
|
+
children: isLocked ? "Unlock" : "Lock"
|
|
102
|
+
})]
|
|
103
|
+
}), _jsx(TextInput, {
|
|
104
|
+
onChange: setValue,
|
|
105
|
+
path: path || field.name,
|
|
106
|
+
readOnly: Boolean(readOnlyFromProps || isLocked),
|
|
107
|
+
value
|
|
108
|
+
})]
|
|
109
|
+
});
|
|
110
|
+
$[8] = field.name;
|
|
111
|
+
$[9] = handleGenerate;
|
|
112
|
+
$[10] = isLocked;
|
|
113
|
+
$[11] = label;
|
|
114
|
+
$[12] = path;
|
|
115
|
+
$[13] = readOnlyFromProps;
|
|
116
|
+
$[14] = setValue;
|
|
117
|
+
$[15] = t5;
|
|
118
|
+
$[16] = value;
|
|
119
|
+
$[17] = t6;
|
|
120
|
+
} else {
|
|
121
|
+
t6 = $[17];
|
|
122
|
+
}
|
|
123
|
+
return t6;
|
|
124
|
+
};
|
|
125
|
+
function _temp(prev) {
|
|
126
|
+
return !prev;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","slugify","React","useCallback","useState","Button","useForm","useField","FieldLabel","TextInput","SlugField","t0","$","field","fieldToUse","path","readOnly","readOnlyFromProps","label","t1","name","t2","setValue","value","getDataByPath","isLocked","setIsLocked","t3","e","preventDefault","targetFieldValue","formattedSlug","handleGenerate","t4","Symbol","for","e_0","_temp","toggleLock","t5","t6","_jsxs","className","children","_jsx","htmlFor","buttonStyle","onClick","onChange","Boolean","prev"],"sources":["../../../src/fields/Slug/index.tsx"],"sourcesContent":["'use client'\nimport type { SlugFieldProps } from 'payload'\n\nimport { slugify } from 'payload/shared'\nimport React, { useCallback, useState } from 'react'\n\nimport { Button } from '../../elements/Button/index.js'\nimport { useForm } from '../../forms/Form/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { FieldLabel } from '../FieldLabel/index.js'\nimport { TextInput } from '../Text/index.js'\nimport './index.scss'\n\n/**\n * @experimental This component is experimental and may change or be removed in the future. Use at your own risk.\n */\nexport const SlugField: React.FC<SlugFieldProps> = ({\n field,\n fieldToUse,\n path,\n readOnly: readOnlyFromProps,\n}) => {\n const { label } = field\n\n const { setValue, value } = useField<string>({ path: path || field.name })\n\n const { getDataByPath } = useForm()\n\n const [isLocked, setIsLocked] = useState(true)\n\n const handleGenerate = useCallback(\n (e: React.MouseEvent<Element>) => {\n e.preventDefault()\n\n const targetFieldValue = getDataByPath(fieldToUse)\n\n if (targetFieldValue) {\n const formattedSlug = slugify(targetFieldValue as string)\n\n if (value !== formattedSlug) {\n setValue(formattedSlug)\n }\n } else {\n if (value !== '') {\n setValue('')\n }\n }\n },\n [setValue, value, fieldToUse, getDataByPath],\n )\n\n const toggleLock = useCallback((e: React.MouseEvent<Element>) => {\n e.preventDefault()\n setIsLocked((prev) => !prev)\n }, [])\n\n return (\n <div className=\"field-type slug-field-component\">\n <div className=\"label-wrapper\">\n <FieldLabel htmlFor={`field-${path}`} label={label} />\n {!isLocked && (\n <Button buttonStyle=\"none\" className=\"lock-button\" onClick={handleGenerate}>\n Generate\n </Button>\n )}\n <Button buttonStyle=\"none\" className=\"lock-button\" onClick={toggleLock}>\n {isLocked ? 'Unlock' : 'Lock'}\n </Button>\n </div>\n <TextInput\n onChange={setValue}\n path={path || field.name}\n readOnly={Boolean(readOnlyFromProps || isLocked)}\n value={value}\n />\n </div>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,OAAO,QAAQ;AACxB,OAAOC,KAAA,IAASC,WAAW,EAAEC,QAAQ,QAAQ;AAE7C,SAASC,MAAM,QAAQ;AACvB,SAASC,OAAO,QAAQ;AACxB,SAASC,QAAQ,QAAQ;AACzB,SAASC,UAAU,QAAQ;AAC3B,SAASC,SAAS,QAAQ;AAC1B,OAAO;AAEP;;;AAGA,OAAO,MAAMC,SAAA,GAAsCC,EAAA;EAAA,MAAAC,CAAA,GAAAZ,EAAA;EAAC;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AA7DmD,SAAAH,MAAAa,IAAA;EAAA,QAqCxBA,IAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
@layer payload-default {
|
|
2
|
+
.slug-field-component {
|
|
3
|
+
width: 100%;
|
|
4
|
+
|
|
5
|
+
.label-wrapper {
|
|
6
|
+
display: flex;
|
|
7
|
+
justify-content: space-between;
|
|
8
|
+
align-items: center;
|
|
9
|
+
gap: calc(var(--base) / 2);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.lock-button {
|
|
13
|
+
margin: 0;
|
|
14
|
+
padding-bottom: 0.3125rem;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -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 }\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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,IA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@@ -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 risk.
|
|
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 risk.
|
|
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 risk.\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 risk.
|
|
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 risk.
|
|
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 risk.
|
|
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 risk.
|
|
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 risk.\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 risk.\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":[]}
|
|
@@ -1,8 +1,6 @@
|
|
|
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
|
|
6
4
|
*/
|
|
7
5
|
export declare function useControllableState<T>(propValue: T, defaultValue?: T): [T, (value: ((prev: T) => T) | T) => void];
|
|
8
6
|
//# 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":"AAEA;;;GAGG;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"}
|