@payloadcms/ui 3.59.1 → 3.60.0-canary.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/CodeEditor/CodeEditor.js +1 -1
- package/dist/elements/CodeEditor/CodeEditor.js.map +1 -1
- package/dist/elements/Collapsible/index.d.ts +15 -2
- package/dist/elements/Collapsible/index.d.ts.map +1 -1
- package/dist/elements/Collapsible/index.js +59 -60
- package/dist/elements/Collapsible/index.js.map +1 -1
- package/dist/elements/Collapsible/index.scss +6 -2
- 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/Nav/context.d.ts +6 -0
- package/dist/elements/Nav/context.d.ts.map +1 -1
- package/dist/elements/Nav/context.js +6 -0
- package/dist/elements/Nav/context.js.map +1 -1
- 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-UTOLPRAV.js → CodeEditor-WXQZOS3M.js} +2 -2
- package/dist/exports/client/{chunk-S2X3JKSP.js → chunk-PDWTBQPH.js} +2 -2
- package/dist/exports/client/{chunk-S2X3JKSP.js.map → chunk-PDWTBQPH.js.map} +3 -3
- package/dist/exports/client/index.d.ts +6 -1
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +12 -12
- package/dist/exports/client/index.js.map +4 -4
- package/dist/fields/Code/index.d.ts.map +1 -1
- package/dist/fields/Code/index.js +5 -2
- package/dist/fields/Code/index.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 +5 -5
- /package/dist/exports/client/{CodeEditor-UTOLPRAV.js.map → CodeEditor-WXQZOS3M.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 => {
|
|
@@ -25,6 +26,7 @@ const CodeFieldComponent = props => {
|
|
|
25
26
|
className,
|
|
26
27
|
description,
|
|
27
28
|
editorOptions,
|
|
29
|
+
editorProps,
|
|
28
30
|
language = 'javascript'
|
|
29
31
|
} = {},
|
|
30
32
|
label,
|
|
@@ -115,7 +117,8 @@ const CodeFieldComponent = props => {
|
|
|
115
117
|
value: stringValueRef.current,
|
|
116
118
|
wrapperProps: {
|
|
117
119
|
id: `field-${path?.replace(/\./g, '__')}`
|
|
118
|
-
}
|
|
120
|
+
},
|
|
121
|
+
...(editorProps || {})
|
|
119
122
|
}), AfterInput]
|
|
120
123
|
}), /*#__PURE__*/_jsx(RenderCustomComponent, {
|
|
121
124
|
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","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;
|
|
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;AAC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A,QAAsB;8BACvCuD,IAAA,CAAC9D,qBAAA;QACC+D,eAAA,EAAiBpB,KAAA;QACjBqB,QAAA,eAAUF,IAAA,CAAC5D,UAAA;UAAWwB,IAAA,EAAMA,IAAA;UAAMsB,SAAA,EAAWA;;UAE9CP,WAAA,E,aACDqB,IAAA,CAAC/D,UAAA;QACCkE,eAAA,EAAiBzD,wBAAwB,CAACa,QAAA,CAAS,IAAIA,QAAA;QACvD6C,QAAA,EAAUd,YAAA;QACV3B,OAAA,EAASA,OAAA;QACTa,OAAA,EAASnB,aAAA;QACTS,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;QACC,IAAIjD,WAAA,IAAe,CAAC,CAAC;UAEvBoB,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,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((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