@yamada-ui/editable 1.0.48-next-20241111190044 → 1.0.49-dev-20241123043353
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-PCLA7CWV.mjs → chunk-WCR6O63I.mjs} +48 -35
- package/dist/chunk-WCR6O63I.mjs.map +1 -0
- package/dist/editable.d.mts +15 -2
- package/dist/editable.d.ts +15 -2
- package/dist/editable.js +47 -34
- package/dist/editable.js.map +1 -1
- package/dist/editable.mjs +1 -1
- package/dist/index.js +47 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
- package/dist/chunk-PCLA7CWV.mjs.map +0 -1
@@ -28,11 +28,12 @@ import {
|
|
28
28
|
import { useCallback, useEffect, useRef, useState } from "react";
|
29
29
|
import { jsx } from "react/jsx-runtime";
|
30
30
|
var useEditable = (props) => {
|
31
|
-
|
31
|
+
let {
|
32
32
|
id,
|
33
33
|
defaultValue,
|
34
34
|
isPreviewFocusable = true,
|
35
35
|
placeholder,
|
36
|
+
previewFocusable,
|
36
37
|
selectAllOnFocus = true,
|
37
38
|
startWithEditView,
|
38
39
|
submitOnBlur = true,
|
@@ -43,12 +44,13 @@ var useEditable = (props) => {
|
|
43
44
|
onSubmit: onSubmitProp,
|
44
45
|
...rest
|
45
46
|
} = useFormControlProps(props);
|
47
|
+
previewFocusable != null ? previewFocusable : previewFocusable = isPreviewFocusable;
|
46
48
|
const onEditRef = useCallbackRef(onEditProp);
|
47
49
|
const { disabled, readOnly, required, ...formControlProps } = pickObject(
|
48
50
|
rest,
|
49
51
|
formControlProperties
|
50
52
|
);
|
51
|
-
const [
|
53
|
+
const [editing, setEditing] = useState(
|
52
54
|
!!startWithEditView && !disabled
|
53
55
|
);
|
54
56
|
const [value, setValue] = useControllableState({
|
@@ -56,8 +58,8 @@ var useEditable = (props) => {
|
|
56
58
|
value: valueProp,
|
57
59
|
onChange: onChangeProp
|
58
60
|
});
|
59
|
-
const
|
60
|
-
const
|
61
|
+
const interactive = !editing && !disabled;
|
62
|
+
const emptyValue = value.length === 0;
|
61
63
|
const [prevValue, setPrevValue] = useState(value);
|
62
64
|
const inputRef = useRef(null);
|
63
65
|
const previewRef = useRef(null);
|
@@ -67,45 +69,45 @@ var useEditable = (props) => {
|
|
67
69
|
useFocusOnPointerDown({
|
68
70
|
ref: inputRef,
|
69
71
|
elements: [cancelRef, submitRef],
|
70
|
-
enabled:
|
72
|
+
enabled: editing
|
71
73
|
});
|
72
74
|
useSafeLayoutEffect(() => {
|
73
75
|
var _a, _b;
|
74
|
-
if (!
|
76
|
+
if (!editing) return;
|
75
77
|
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
76
78
|
if (selectAllOnFocus) (_b = inputRef.current) == null ? void 0 : _b.select();
|
77
79
|
}, []);
|
78
80
|
useUpdateEffect(() => {
|
79
81
|
var _a, _b, _c;
|
80
|
-
if (!
|
82
|
+
if (!editing) {
|
81
83
|
(_a = editRef.current) == null ? void 0 : _a.focus();
|
82
84
|
return;
|
83
85
|
}
|
84
86
|
(_b = inputRef.current) == null ? void 0 : _b.focus();
|
85
87
|
if (selectAllOnFocus) (_c = inputRef.current) == null ? void 0 : _c.select();
|
86
88
|
onEditRef();
|
87
|
-
}, [
|
89
|
+
}, [editing, onEditRef, selectAllOnFocus]);
|
88
90
|
useEffect(() => {
|
89
|
-
if (
|
91
|
+
if (editing) return;
|
90
92
|
const el = inputRef.current;
|
91
93
|
const activeEl = el == null ? void 0 : el.ownerDocument.activeElement;
|
92
94
|
if (activeEl === el) el == null ? void 0 : el.blur();
|
93
|
-
}, [
|
95
|
+
}, [editing]);
|
94
96
|
const onChange = useCallback(
|
95
97
|
(ev) => setValue(ev.currentTarget.value),
|
96
98
|
[setValue]
|
97
99
|
);
|
98
100
|
const onUpdatePrevValue = useCallback(() => setPrevValue(value), [value]);
|
99
101
|
const onEdit = useCallback(() => {
|
100
|
-
if (
|
101
|
-
}, [
|
102
|
+
if (interactive) setEditing(true);
|
103
|
+
}, [interactive]);
|
102
104
|
const onCancel = useCallback(() => {
|
103
|
-
|
105
|
+
setEditing(false);
|
104
106
|
setValue(prevValue);
|
105
107
|
onCancelProp == null ? void 0 : onCancelProp(prevValue);
|
106
108
|
}, [prevValue, onCancelProp, setValue]);
|
107
109
|
const onSubmit = useCallback(() => {
|
108
|
-
|
110
|
+
setEditing(false);
|
109
111
|
setPrevValue(value);
|
110
112
|
onSubmitProp == null ? void 0 : onSubmitProp(value);
|
111
113
|
}, [onSubmitProp, value]);
|
@@ -133,7 +135,7 @@ var useEditable = (props) => {
|
|
133
135
|
const onBlur = useCallback(
|
134
136
|
(ev) => {
|
135
137
|
var _a;
|
136
|
-
if (!
|
138
|
+
if (!editing) return;
|
137
139
|
const ownerDocument = ev.currentTarget.ownerDocument;
|
138
140
|
const relatedTarget = (_a = ev.relatedTarget) != null ? _a : ownerDocument.activeElement;
|
139
141
|
const targetIsCancel = isContains(cancelRef.current, relatedTarget);
|
@@ -146,22 +148,22 @@ var useEditable = (props) => {
|
|
146
148
|
onCancel();
|
147
149
|
}
|
148
150
|
},
|
149
|
-
[
|
151
|
+
[editing, submitOnBlur, onSubmit, onCancel]
|
150
152
|
);
|
151
153
|
const getPreviewProps = useCallback(
|
152
154
|
(props2 = {}, ref = null) => ({
|
153
155
|
...props2,
|
154
156
|
ref: mergeRefs(ref, previewRef),
|
155
|
-
children:
|
156
|
-
hidden:
|
157
|
-
tabIndex:
|
157
|
+
children: emptyValue ? placeholder : value,
|
158
|
+
hidden: editing,
|
159
|
+
tabIndex: interactive && previewFocusable ? 0 : void 0,
|
158
160
|
onFocus: handlerAll(props2.onFocus, onEdit, onUpdatePrevValue)
|
159
161
|
}),
|
160
162
|
[
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
163
|
+
editing,
|
164
|
+
interactive,
|
165
|
+
previewFocusable,
|
166
|
+
emptyValue,
|
165
167
|
onEdit,
|
166
168
|
onUpdatePrevValue,
|
167
169
|
placeholder,
|
@@ -175,7 +177,7 @@ var useEditable = (props) => {
|
|
175
177
|
id,
|
176
178
|
ref: mergeRefs(ref, inputRef),
|
177
179
|
disabled,
|
178
|
-
hidden: !
|
180
|
+
hidden: !editing,
|
179
181
|
placeholder,
|
180
182
|
readOnly,
|
181
183
|
required,
|
@@ -188,7 +190,7 @@ var useEditable = (props) => {
|
|
188
190
|
[
|
189
191
|
disabled,
|
190
192
|
id,
|
191
|
-
|
193
|
+
editing,
|
192
194
|
onBlur,
|
193
195
|
onChange,
|
194
196
|
onKeyDown,
|
@@ -207,7 +209,7 @@ var useEditable = (props) => {
|
|
207
209
|
id,
|
208
210
|
ref: mergeRefs(ref, inputRef),
|
209
211
|
disabled,
|
210
|
-
hidden: !
|
212
|
+
hidden: !editing,
|
211
213
|
placeholder,
|
212
214
|
readOnly,
|
213
215
|
required,
|
@@ -220,7 +222,7 @@ var useEditable = (props) => {
|
|
220
222
|
[
|
221
223
|
disabled,
|
222
224
|
id,
|
223
|
-
|
225
|
+
editing,
|
224
226
|
onBlur,
|
225
227
|
onChange,
|
226
228
|
onKeyDownWithoutSubmit,
|
@@ -269,7 +271,7 @@ var useEditable = (props) => {
|
|
269
271
|
[disabled, onCancel, readOnly, formControlProps]
|
270
272
|
);
|
271
273
|
return {
|
272
|
-
|
274
|
+
editing,
|
273
275
|
value,
|
274
276
|
getCancelProps,
|
275
277
|
getEditProps,
|
@@ -283,8 +285,17 @@ var useEditable = (props) => {
|
|
283
285
|
};
|
284
286
|
};
|
285
287
|
var useEditableControl = () => {
|
286
|
-
const {
|
287
|
-
return {
|
288
|
+
const { editing, getCancelProps, getEditProps, getSubmitProps } = useEditableContext();
|
289
|
+
return {
|
290
|
+
editing,
|
291
|
+
/**
|
292
|
+
* @deprecated Use `editing` instead.
|
293
|
+
*/
|
294
|
+
isEditing: editing,
|
295
|
+
getCancelProps,
|
296
|
+
getEditProps,
|
297
|
+
getSubmitProps
|
298
|
+
};
|
288
299
|
};
|
289
300
|
var [EditableProvider, useEditableContext] = createContext({
|
290
301
|
name: "EditableContext",
|
@@ -297,7 +308,7 @@ var Editable = forwardRef(
|
|
297
308
|
focusBorderColor,
|
298
309
|
...props
|
299
310
|
});
|
300
|
-
|
311
|
+
let {
|
301
312
|
className,
|
302
313
|
children,
|
303
314
|
defaultValue,
|
@@ -307,6 +318,7 @@ var Editable = forwardRef(
|
|
307
318
|
isReadOnly,
|
308
319
|
isRequired,
|
309
320
|
placeholder,
|
321
|
+
previewFocusable,
|
310
322
|
selectAllOnFocus,
|
311
323
|
startWithEditView,
|
312
324
|
submitOnBlur,
|
@@ -317,8 +329,9 @@ var Editable = forwardRef(
|
|
317
329
|
onSubmit: onSubmitProp,
|
318
330
|
...rest
|
319
331
|
} = omitThemeProps(mergedProps);
|
332
|
+
previewFocusable != null ? previewFocusable : previewFocusable = isPreviewFocusable;
|
320
333
|
const {
|
321
|
-
|
334
|
+
editing,
|
322
335
|
getCancelProps,
|
323
336
|
getEditProps,
|
324
337
|
getInputProps,
|
@@ -346,7 +359,7 @@ var Editable = forwardRef(
|
|
346
359
|
onSubmit: onSubmitProp
|
347
360
|
});
|
348
361
|
const cloneChildren = runIfFunc(children, {
|
349
|
-
|
362
|
+
editing,
|
350
363
|
onCancel,
|
351
364
|
onEdit,
|
352
365
|
onSubmit
|
@@ -356,7 +369,7 @@ var Editable = forwardRef(
|
|
356
369
|
EditableProvider,
|
357
370
|
{
|
358
371
|
value: {
|
359
|
-
|
372
|
+
editing,
|
360
373
|
styles,
|
361
374
|
getCancelProps,
|
362
375
|
getEditProps,
|
@@ -460,4 +473,4 @@ export {
|
|
460
473
|
EditableInput,
|
461
474
|
EditableTextarea
|
462
475
|
};
|
463
|
-
//# sourceMappingURL=chunk-
|
476
|
+
//# sourceMappingURL=chunk-WCR6O63I.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/editable.tsx"],"sourcesContent":["import type {\n ColorModeToken,\n CSS,\n CSSUIObject,\n HTMLUIProps,\n PropGetter,\n ThemeProps,\n} from \"@yamada-ui/core\"\nimport type { FormControlOptions } from \"@yamada-ui/form-control\"\nimport type { ChangeEvent, FocusEvent, KeyboardEvent, ReactNode } from \"react\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentMultiStyle,\n} from \"@yamada-ui/core\"\nimport {\n formControlProperties,\n useFormControlProps,\n} from \"@yamada-ui/form-control\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useFocusOnPointerDown } from \"@yamada-ui/use-focus\"\nimport {\n createContext,\n cx,\n handlerAll,\n isContains,\n mergeRefs,\n pickObject,\n runIfFunc,\n useCallbackRef,\n useSafeLayoutEffect,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\n\nexport interface UseEditableProps extends FormControlOptions {\n /**\n * The initial value of the Editable in both edit & preview mode.\n */\n defaultValue?: string\n /**\n * If `true`, the read only view, has a `tabIndex` set to `0`\n * so it can receive focus via the keyboard or click.\n *\n * @default true\n *\n * @deprecated Use `previewFocusable` instead.\n */\n isPreviewFocusable?: boolean\n /**\n * The placeholder text when the value is empty.\n */\n placeholder?: string\n /**\n * If `true`, the read only view, has a `tabIndex` set to `0`\n * so it can receive focus via the keyboard or click.\n *\n * @default true\n */\n previewFocusable?: boolean\n /**\n * If `true`, the input's text will be highlighted on focus.\n *\n * @default true\n */\n selectAllOnFocus?: boolean\n /**\n * If `true`, the Editable will start with edit mode by default.\n */\n startWithEditView?: boolean\n /**\n * If `true`, it'll update the value onBlur and turn off the edit mode.\n *\n * @default true\n */\n submitOnBlur?: boolean\n /**\n * The value of the Editable in both edit & preview mode.\n */\n value?: string\n /**\n * Callback invoked when user cancels input with the `Esc` key.\n * It provides the last confirmed value as argument.\n */\n onCancel?: (preValue: string) => void\n /**\n * A callback invoked when user changes input.\n */\n onChange?: (value: string) => void\n /**\n * A callback invoked once the user enters edit mode.\n */\n onEdit?: () => void\n /**\n * A callback invoked when user confirms value with `enter` key or by blurring input.\n */\n onSubmit?: (value: string) => void\n}\n\nexport const useEditable = (props: UseEditableProps) => {\n let {\n id,\n defaultValue,\n isPreviewFocusable = true,\n placeholder,\n previewFocusable,\n selectAllOnFocus = true,\n startWithEditView,\n submitOnBlur = true,\n value: valueProp,\n onCancel: onCancelProp,\n onChange: onChangeProp,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n ...rest\n } = useFormControlProps(props)\n\n previewFocusable ??= isPreviewFocusable\n\n const onEditRef = useCallbackRef(onEditProp)\n const { disabled, readOnly, required, ...formControlProps } = pickObject(\n rest,\n formControlProperties,\n )\n\n const [editing, setEditing] = useState<boolean>(\n !!startWithEditView && !disabled,\n )\n\n const [value, setValue] = useControllableState({\n defaultValue: defaultValue || \"\",\n value: valueProp,\n onChange: onChangeProp,\n })\n\n const interactive = !editing && !disabled\n const emptyValue = value.length === 0\n\n const [prevValue, setPrevValue] = useState(value)\n\n const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null)\n const previewRef = useRef<HTMLElement>(null)\n const editRef = useRef<HTMLButtonElement>(null)\n const cancelRef = useRef<HTMLButtonElement>(null)\n const submitRef = useRef<HTMLButtonElement>(null)\n\n useFocusOnPointerDown({\n ref: inputRef,\n elements: [cancelRef, submitRef],\n enabled: editing,\n })\n\n useSafeLayoutEffect(() => {\n if (!editing) return\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n }, [])\n\n useUpdateEffect(() => {\n if (!editing) {\n editRef.current?.focus()\n\n return\n }\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n\n onEditRef()\n }, [editing, onEditRef, selectAllOnFocus])\n\n useEffect(() => {\n if (editing) return\n\n const el = inputRef.current\n const activeEl = el?.ownerDocument.activeElement\n\n if (activeEl === el) el?.blur()\n }, [editing])\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) =>\n setValue(ev.currentTarget.value),\n [setValue],\n )\n\n const onUpdatePrevValue = useCallback(() => setPrevValue(value), [value])\n\n const onEdit = useCallback(() => {\n if (interactive) setEditing(true)\n }, [interactive])\n\n const onCancel = useCallback(() => {\n setEditing(false)\n setValue(prevValue)\n onCancelProp?.(prevValue)\n }, [prevValue, onCancelProp, setValue])\n\n const onSubmit = useCallback(() => {\n setEditing(false)\n setPrevValue(value)\n onSubmitProp?.(value)\n }, [onSubmitProp, value])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\" && ev.key !== \"Enter\") return\n\n ev.preventDefault()\n\n if (ev.key === \"Escape\") {\n onCancel()\n } else {\n const { metaKey, shiftKey } = ev\n\n if (!shiftKey && !metaKey) onSubmit()\n }\n },\n [onCancel, onSubmit],\n )\n\n const onKeyDownWithoutSubmit = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\") return\n\n ev.preventDefault()\n onCancel()\n },\n [onCancel],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent) => {\n if (!editing) return\n\n const ownerDocument = ev.currentTarget.ownerDocument\n const relatedTarget = (ev.relatedTarget ??\n ownerDocument.activeElement) as HTMLElement\n const targetIsCancel = isContains(cancelRef.current, relatedTarget)\n const targetIsSubmit = isContains(submitRef.current, relatedTarget)\n const isValidBlur = !targetIsCancel && !targetIsSubmit\n\n if (!isValidBlur) return\n\n if (submitOnBlur) {\n onSubmit()\n } else {\n onCancel()\n }\n },\n [editing, submitOnBlur, onSubmit, onCancel],\n )\n\n const getPreviewProps: PropGetter<\"span\"> = useCallback(\n (props = {}, ref = null) => ({\n ...props,\n ref: mergeRefs(ref, previewRef),\n children: emptyValue ? placeholder : value,\n hidden: editing,\n tabIndex: interactive && previewFocusable ? 0 : undefined,\n onFocus: handlerAll(props.onFocus, onEdit, onUpdatePrevValue),\n }),\n [\n editing,\n interactive,\n previewFocusable,\n emptyValue,\n onEdit,\n onUpdatePrevValue,\n placeholder,\n value,\n ],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n id,\n ref: mergeRefs(ref, inputRef),\n disabled,\n hidden: !editing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n disabled,\n id,\n editing,\n onBlur,\n onChange,\n onKeyDown,\n onUpdatePrevValue,\n placeholder,\n readOnly,\n required,\n formControlProps,\n value,\n ],\n )\n\n const getTextareaProps: PropGetter<\"textarea\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n id,\n ref: mergeRefs(ref, inputRef),\n disabled,\n hidden: !editing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDownWithoutSubmit),\n }),\n [\n disabled,\n id,\n editing,\n onBlur,\n onChange,\n onKeyDownWithoutSubmit,\n onUpdatePrevValue,\n placeholder,\n readOnly,\n required,\n formControlProps,\n value,\n ],\n )\n\n const getEditProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(ref, editRef),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onEdit),\n }),\n [disabled, onEdit, readOnly, formControlProps],\n )\n\n const getSubmitProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(submitRef, ref),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onSubmit),\n }),\n [disabled, onSubmit, readOnly, formControlProps],\n )\n\n const getCancelProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(cancelRef, ref),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onCancel),\n }),\n [disabled, onCancel, readOnly, formControlProps],\n )\n\n return {\n editing,\n value,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n onCancel,\n onEdit,\n onSubmit,\n }\n}\n\nexport type UseEditableReturn = ReturnType<typeof useEditable>\n\nexport const useEditableControl = () => {\n const { editing, getCancelProps, getEditProps, getSubmitProps } =\n useEditableContext()\n\n return {\n editing,\n /**\n * @deprecated Use `editing` instead.\n */\n isEditing: editing,\n getCancelProps,\n getEditProps,\n getSubmitProps,\n }\n}\n\ninterface EditableContext {\n editing: boolean\n styles: { [key: string]: CSSUIObject | undefined }\n getCancelProps: PropGetter<\"button\">\n getEditProps: PropGetter<\"button\">\n getInputProps: PropGetter<\"input\">\n getPreviewProps: PropGetter<\"span\">\n getSubmitProps: PropGetter<\"button\">\n getTextareaProps: PropGetter<\"textarea\">\n}\n\nconst [EditableProvider, useEditableContext] = createContext<EditableContext>({\n name: \"EditableContext\",\n errorMessage:\n \"useEditableContext: context is undefined. Seems you forgot to wrap the editable components in `<Editable />`\",\n})\n\ninterface EditableElementProps\n extends Pick<\n UseEditableReturn,\n \"editing\" | \"onCancel\" | \"onEdit\" | \"onSubmit\"\n > {}\n\ntype EditableElement = (props: EditableElementProps) => ReactNode\n\ninterface EditableOptions {\n children?: EditableElement | ReactNode\n /**\n * The border color when the input is invalid.\n */\n errorBorderColor?: ColorModeToken<CSS.Property.BorderColor, \"colors\">\n /**\n * The border color when the input is focused.\n */\n focusBorderColor?: ColorModeToken<CSS.Property.BorderColor, \"colors\">\n}\n\nexport interface EditableProps\n extends Omit<\n HTMLUIProps,\n \"children\" | \"defaultValue\" | \"onChange\" | \"onSubmit\" | \"value\"\n >,\n ThemeProps<\"Editable\">,\n UseEditableProps,\n EditableOptions {}\n\n/**\n * `Editable` is a component used to obtain inline editable text input.\n *\n * @see Docs https://yamada-ui.com/components/forms/editable\n */\nexport const Editable = forwardRef<EditableProps, \"div\">(\n ({ errorBorderColor, focusBorderColor, ...props }, ref) => {\n const [styles, mergedProps] = useComponentMultiStyle(\"Editable\", {\n errorBorderColor,\n focusBorderColor,\n ...props,\n })\n let {\n className,\n children,\n defaultValue,\n isDisabled,\n isInvalid,\n isPreviewFocusable,\n isReadOnly,\n isRequired,\n placeholder,\n previewFocusable,\n selectAllOnFocus,\n startWithEditView,\n submitOnBlur,\n value,\n onCancel: onCancelProp,\n onChange,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n ...rest\n } = omitThemeProps(mergedProps)\n\n previewFocusable ??= isPreviewFocusable\n\n const {\n editing,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n onCancel,\n onEdit,\n onSubmit,\n } = useEditable({\n defaultValue,\n isDisabled,\n isInvalid,\n isPreviewFocusable,\n isReadOnly,\n isRequired,\n placeholder,\n selectAllOnFocus,\n startWithEditView,\n submitOnBlur,\n value,\n onCancel: onCancelProp,\n onChange,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n })\n\n const cloneChildren = runIfFunc(children, {\n editing,\n onCancel,\n onEdit,\n onSubmit,\n })\n\n const css: CSSUIObject = { ...styles.container }\n\n return (\n <EditableProvider\n value={{\n editing,\n styles,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n }}\n >\n <ui.div\n ref={ref}\n className={cx(\"ui-editable\", className)}\n {...rest}\n __css={css}\n >\n {cloneChildren}\n </ui.div>\n </EditableProvider>\n )\n },\n)\n\nEditable.displayName = \"Editable\"\nEditable.__ui__ = \"Editable\"\n\nexport interface EditablePreviewProps extends HTMLUIProps<\"span\"> {}\n\nexport const EditablePreview = forwardRef<EditablePreviewProps, \"span\">(\n ({ className, ...rest }, ref) => {\n const { styles, getPreviewProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n cursor: \"text\",\n display: \"inline-block\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n textAlign: \"inherit\",\n ...styles.preview,\n }\n\n return (\n <ui.span\n className={cx(\"ui-editable__preview\", className)}\n {...getPreviewProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditablePreview.displayName = \"EditablePreview\"\nEditablePreview.__ui__ = \"EditablePreview\"\n\nexport interface EditableInputProps extends HTMLUIProps<\"input\"> {}\n\nexport const EditableInput = forwardRef<EditableInputProps, \"input\">(\n ({ className, ...rest }, ref) => {\n const { styles, getInputProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n outline: 0,\n textAlign: \"inherit\",\n ...styles.input,\n }\n\n return (\n <ui.input\n className={cx(\"ui-editable__input\", className)}\n {...getInputProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditableInput.displayName = \"EditableInput\"\nEditableInput.__ui__ = \"EditableInput\"\n\nexport interface EditableTextareaProps extends HTMLUIProps<\"textarea\"> {}\n\nexport const EditableTextarea = forwardRef<EditableTextareaProps, \"textarea\">(\n ({ className, ...rest }, ref) => {\n const { styles, getTextareaProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n outline: 0,\n textAlign: \"inherit\",\n ...styles.textarea,\n }\n\n return (\n <ui.textarea\n className={cx(\"ui-editable__textarea\", className)}\n {...getTextareaProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditableTextarea.displayName = \"EditableTextarea\"\nEditableTextarea.__ui__ = \"EditableTextarea\"\n"],"mappings":";;;AAUA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,4BAA4B;AACrC,SAAS,6BAA6B;AACtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAC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A,MAAH;AAAA,QACC,WAAW,GAAG,yBAAyB,SAAS;AAAA,QAC/C,GAAG,iBAAiB,MAAM,GAAG;AAAA,QAC9B,OAAO;AAAA;AAAA,IACT;AAAA,EAEJ;AACF;AAEA,iBAAiB,cAAc;AAC/B,iBAAiB,SAAS;","names":["props"]}
|
package/dist/editable.d.mts
CHANGED
@@ -13,12 +13,21 @@ interface UseEditableProps extends FormControlOptions {
|
|
13
13
|
* so it can receive focus via the keyboard or click.
|
14
14
|
*
|
15
15
|
* @default true
|
16
|
+
*
|
17
|
+
* @deprecated Use `previewFocusable` instead.
|
16
18
|
*/
|
17
19
|
isPreviewFocusable?: boolean;
|
18
20
|
/**
|
19
21
|
* The placeholder text when the value is empty.
|
20
22
|
*/
|
21
23
|
placeholder?: string;
|
24
|
+
/**
|
25
|
+
* If `true`, the read only view, has a `tabIndex` set to `0`
|
26
|
+
* so it can receive focus via the keyboard or click.
|
27
|
+
*
|
28
|
+
* @default true
|
29
|
+
*/
|
30
|
+
previewFocusable?: boolean;
|
22
31
|
/**
|
23
32
|
* If `true`, the input's text will be highlighted on focus.
|
24
33
|
*
|
@@ -58,7 +67,7 @@ interface UseEditableProps extends FormControlOptions {
|
|
58
67
|
onSubmit?: (value: string) => void;
|
59
68
|
}
|
60
69
|
declare const useEditable: (props: UseEditableProps) => {
|
61
|
-
|
70
|
+
editing: boolean;
|
62
71
|
value: string;
|
63
72
|
getCancelProps: PropGetter<"button", undefined>;
|
64
73
|
getEditProps: PropGetter<"button", undefined>;
|
@@ -72,12 +81,16 @@ declare const useEditable: (props: UseEditableProps) => {
|
|
72
81
|
};
|
73
82
|
type UseEditableReturn = ReturnType<typeof useEditable>;
|
74
83
|
declare const useEditableControl: () => {
|
84
|
+
editing: boolean;
|
85
|
+
/**
|
86
|
+
* @deprecated Use `editing` instead.
|
87
|
+
*/
|
75
88
|
isEditing: boolean;
|
76
89
|
getCancelProps: PropGetter<"button", undefined>;
|
77
90
|
getEditProps: PropGetter<"button", undefined>;
|
78
91
|
getSubmitProps: PropGetter<"button", undefined>;
|
79
92
|
};
|
80
|
-
interface EditableElementProps extends Pick<UseEditableReturn, "
|
93
|
+
interface EditableElementProps extends Pick<UseEditableReturn, "editing" | "onCancel" | "onEdit" | "onSubmit"> {
|
81
94
|
}
|
82
95
|
type EditableElement = (props: EditableElementProps) => ReactNode;
|
83
96
|
interface EditableOptions {
|
package/dist/editable.d.ts
CHANGED
@@ -13,12 +13,21 @@ interface UseEditableProps extends FormControlOptions {
|
|
13
13
|
* so it can receive focus via the keyboard or click.
|
14
14
|
*
|
15
15
|
* @default true
|
16
|
+
*
|
17
|
+
* @deprecated Use `previewFocusable` instead.
|
16
18
|
*/
|
17
19
|
isPreviewFocusable?: boolean;
|
18
20
|
/**
|
19
21
|
* The placeholder text when the value is empty.
|
20
22
|
*/
|
21
23
|
placeholder?: string;
|
24
|
+
/**
|
25
|
+
* If `true`, the read only view, has a `tabIndex` set to `0`
|
26
|
+
* so it can receive focus via the keyboard or click.
|
27
|
+
*
|
28
|
+
* @default true
|
29
|
+
*/
|
30
|
+
previewFocusable?: boolean;
|
22
31
|
/**
|
23
32
|
* If `true`, the input's text will be highlighted on focus.
|
24
33
|
*
|
@@ -58,7 +67,7 @@ interface UseEditableProps extends FormControlOptions {
|
|
58
67
|
onSubmit?: (value: string) => void;
|
59
68
|
}
|
60
69
|
declare const useEditable: (props: UseEditableProps) => {
|
61
|
-
|
70
|
+
editing: boolean;
|
62
71
|
value: string;
|
63
72
|
getCancelProps: PropGetter<"button", undefined>;
|
64
73
|
getEditProps: PropGetter<"button", undefined>;
|
@@ -72,12 +81,16 @@ declare const useEditable: (props: UseEditableProps) => {
|
|
72
81
|
};
|
73
82
|
type UseEditableReturn = ReturnType<typeof useEditable>;
|
74
83
|
declare const useEditableControl: () => {
|
84
|
+
editing: boolean;
|
85
|
+
/**
|
86
|
+
* @deprecated Use `editing` instead.
|
87
|
+
*/
|
75
88
|
isEditing: boolean;
|
76
89
|
getCancelProps: PropGetter<"button", undefined>;
|
77
90
|
getEditProps: PropGetter<"button", undefined>;
|
78
91
|
getSubmitProps: PropGetter<"button", undefined>;
|
79
92
|
};
|
80
|
-
interface EditableElementProps extends Pick<UseEditableReturn, "
|
93
|
+
interface EditableElementProps extends Pick<UseEditableReturn, "editing" | "onCancel" | "onEdit" | "onSubmit"> {
|
81
94
|
}
|
82
95
|
type EditableElement = (props: EditableElementProps) => ReactNode;
|
83
96
|
interface EditableOptions {
|
package/dist/editable.js
CHANGED
@@ -37,11 +37,12 @@ var import_utils = require("@yamada-ui/utils");
|
|
37
37
|
var import_react = require("react");
|
38
38
|
var import_jsx_runtime = require("react/jsx-runtime");
|
39
39
|
var useEditable = (props) => {
|
40
|
-
|
40
|
+
let {
|
41
41
|
id,
|
42
42
|
defaultValue,
|
43
43
|
isPreviewFocusable = true,
|
44
44
|
placeholder,
|
45
|
+
previewFocusable,
|
45
46
|
selectAllOnFocus = true,
|
46
47
|
startWithEditView,
|
47
48
|
submitOnBlur = true,
|
@@ -52,12 +53,13 @@ var useEditable = (props) => {
|
|
52
53
|
onSubmit: onSubmitProp,
|
53
54
|
...rest
|
54
55
|
} = (0, import_form_control.useFormControlProps)(props);
|
56
|
+
previewFocusable != null ? previewFocusable : previewFocusable = isPreviewFocusable;
|
55
57
|
const onEditRef = (0, import_utils.useCallbackRef)(onEditProp);
|
56
58
|
const { disabled, readOnly, required, ...formControlProps } = (0, import_utils.pickObject)(
|
57
59
|
rest,
|
58
60
|
import_form_control.formControlProperties
|
59
61
|
);
|
60
|
-
const [
|
62
|
+
const [editing, setEditing] = (0, import_react.useState)(
|
61
63
|
!!startWithEditView && !disabled
|
62
64
|
);
|
63
65
|
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
@@ -65,8 +67,8 @@ var useEditable = (props) => {
|
|
65
67
|
value: valueProp,
|
66
68
|
onChange: onChangeProp
|
67
69
|
});
|
68
|
-
const
|
69
|
-
const
|
70
|
+
const interactive = !editing && !disabled;
|
71
|
+
const emptyValue = value.length === 0;
|
70
72
|
const [prevValue, setPrevValue] = (0, import_react.useState)(value);
|
71
73
|
const inputRef = (0, import_react.useRef)(null);
|
72
74
|
const previewRef = (0, import_react.useRef)(null);
|
@@ -76,45 +78,45 @@ var useEditable = (props) => {
|
|
76
78
|
(0, import_use_focus.useFocusOnPointerDown)({
|
77
79
|
ref: inputRef,
|
78
80
|
elements: [cancelRef, submitRef],
|
79
|
-
enabled:
|
81
|
+
enabled: editing
|
80
82
|
});
|
81
83
|
(0, import_utils.useSafeLayoutEffect)(() => {
|
82
84
|
var _a, _b;
|
83
|
-
if (!
|
85
|
+
if (!editing) return;
|
84
86
|
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
85
87
|
if (selectAllOnFocus) (_b = inputRef.current) == null ? void 0 : _b.select();
|
86
88
|
}, []);
|
87
89
|
(0, import_utils.useUpdateEffect)(() => {
|
88
90
|
var _a, _b, _c;
|
89
|
-
if (!
|
91
|
+
if (!editing) {
|
90
92
|
(_a = editRef.current) == null ? void 0 : _a.focus();
|
91
93
|
return;
|
92
94
|
}
|
93
95
|
(_b = inputRef.current) == null ? void 0 : _b.focus();
|
94
96
|
if (selectAllOnFocus) (_c = inputRef.current) == null ? void 0 : _c.select();
|
95
97
|
onEditRef();
|
96
|
-
}, [
|
98
|
+
}, [editing, onEditRef, selectAllOnFocus]);
|
97
99
|
(0, import_react.useEffect)(() => {
|
98
|
-
if (
|
100
|
+
if (editing) return;
|
99
101
|
const el = inputRef.current;
|
100
102
|
const activeEl = el == null ? void 0 : el.ownerDocument.activeElement;
|
101
103
|
if (activeEl === el) el == null ? void 0 : el.blur();
|
102
|
-
}, [
|
104
|
+
}, [editing]);
|
103
105
|
const onChange = (0, import_react.useCallback)(
|
104
106
|
(ev) => setValue(ev.currentTarget.value),
|
105
107
|
[setValue]
|
106
108
|
);
|
107
109
|
const onUpdatePrevValue = (0, import_react.useCallback)(() => setPrevValue(value), [value]);
|
108
110
|
const onEdit = (0, import_react.useCallback)(() => {
|
109
|
-
if (
|
110
|
-
}, [
|
111
|
+
if (interactive) setEditing(true);
|
112
|
+
}, [interactive]);
|
111
113
|
const onCancel = (0, import_react.useCallback)(() => {
|
112
|
-
|
114
|
+
setEditing(false);
|
113
115
|
setValue(prevValue);
|
114
116
|
onCancelProp == null ? void 0 : onCancelProp(prevValue);
|
115
117
|
}, [prevValue, onCancelProp, setValue]);
|
116
118
|
const onSubmit = (0, import_react.useCallback)(() => {
|
117
|
-
|
119
|
+
setEditing(false);
|
118
120
|
setPrevValue(value);
|
119
121
|
onSubmitProp == null ? void 0 : onSubmitProp(value);
|
120
122
|
}, [onSubmitProp, value]);
|
@@ -142,7 +144,7 @@ var useEditable = (props) => {
|
|
142
144
|
const onBlur = (0, import_react.useCallback)(
|
143
145
|
(ev) => {
|
144
146
|
var _a;
|
145
|
-
if (!
|
147
|
+
if (!editing) return;
|
146
148
|
const ownerDocument = ev.currentTarget.ownerDocument;
|
147
149
|
const relatedTarget = (_a = ev.relatedTarget) != null ? _a : ownerDocument.activeElement;
|
148
150
|
const targetIsCancel = (0, import_utils.isContains)(cancelRef.current, relatedTarget);
|
@@ -155,22 +157,22 @@ var useEditable = (props) => {
|
|
155
157
|
onCancel();
|
156
158
|
}
|
157
159
|
},
|
158
|
-
[
|
160
|
+
[editing, submitOnBlur, onSubmit, onCancel]
|
159
161
|
);
|
160
162
|
const getPreviewProps = (0, import_react.useCallback)(
|
161
163
|
(props2 = {}, ref = null) => ({
|
162
164
|
...props2,
|
163
165
|
ref: (0, import_utils.mergeRefs)(ref, previewRef),
|
164
|
-
children:
|
165
|
-
hidden:
|
166
|
-
tabIndex:
|
166
|
+
children: emptyValue ? placeholder : value,
|
167
|
+
hidden: editing,
|
168
|
+
tabIndex: interactive && previewFocusable ? 0 : void 0,
|
167
169
|
onFocus: (0, import_utils.handlerAll)(props2.onFocus, onEdit, onUpdatePrevValue)
|
168
170
|
}),
|
169
171
|
[
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
172
|
+
editing,
|
173
|
+
interactive,
|
174
|
+
previewFocusable,
|
175
|
+
emptyValue,
|
174
176
|
onEdit,
|
175
177
|
onUpdatePrevValue,
|
176
178
|
placeholder,
|
@@ -184,7 +186,7 @@ var useEditable = (props) => {
|
|
184
186
|
id,
|
185
187
|
ref: (0, import_utils.mergeRefs)(ref, inputRef),
|
186
188
|
disabled,
|
187
|
-
hidden: !
|
189
|
+
hidden: !editing,
|
188
190
|
placeholder,
|
189
191
|
readOnly,
|
190
192
|
required,
|
@@ -197,7 +199,7 @@ var useEditable = (props) => {
|
|
197
199
|
[
|
198
200
|
disabled,
|
199
201
|
id,
|
200
|
-
|
202
|
+
editing,
|
201
203
|
onBlur,
|
202
204
|
onChange,
|
203
205
|
onKeyDown,
|
@@ -216,7 +218,7 @@ var useEditable = (props) => {
|
|
216
218
|
id,
|
217
219
|
ref: (0, import_utils.mergeRefs)(ref, inputRef),
|
218
220
|
disabled,
|
219
|
-
hidden: !
|
221
|
+
hidden: !editing,
|
220
222
|
placeholder,
|
221
223
|
readOnly,
|
222
224
|
required,
|
@@ -229,7 +231,7 @@ var useEditable = (props) => {
|
|
229
231
|
[
|
230
232
|
disabled,
|
231
233
|
id,
|
232
|
-
|
234
|
+
editing,
|
233
235
|
onBlur,
|
234
236
|
onChange,
|
235
237
|
onKeyDownWithoutSubmit,
|
@@ -278,7 +280,7 @@ var useEditable = (props) => {
|
|
278
280
|
[disabled, onCancel, readOnly, formControlProps]
|
279
281
|
);
|
280
282
|
return {
|
281
|
-
|
283
|
+
editing,
|
282
284
|
value,
|
283
285
|
getCancelProps,
|
284
286
|
getEditProps,
|
@@ -292,8 +294,17 @@ var useEditable = (props) => {
|
|
292
294
|
};
|
293
295
|
};
|
294
296
|
var useEditableControl = () => {
|
295
|
-
const {
|
296
|
-
return {
|
297
|
+
const { editing, getCancelProps, getEditProps, getSubmitProps } = useEditableContext();
|
298
|
+
return {
|
299
|
+
editing,
|
300
|
+
/**
|
301
|
+
* @deprecated Use `editing` instead.
|
302
|
+
*/
|
303
|
+
isEditing: editing,
|
304
|
+
getCancelProps,
|
305
|
+
getEditProps,
|
306
|
+
getSubmitProps
|
307
|
+
};
|
297
308
|
};
|
298
309
|
var [EditableProvider, useEditableContext] = (0, import_utils.createContext)({
|
299
310
|
name: "EditableContext",
|
@@ -306,7 +317,7 @@ var Editable = (0, import_core.forwardRef)(
|
|
306
317
|
focusBorderColor,
|
307
318
|
...props
|
308
319
|
});
|
309
|
-
|
320
|
+
let {
|
310
321
|
className,
|
311
322
|
children,
|
312
323
|
defaultValue,
|
@@ -316,6 +327,7 @@ var Editable = (0, import_core.forwardRef)(
|
|
316
327
|
isReadOnly,
|
317
328
|
isRequired,
|
318
329
|
placeholder,
|
330
|
+
previewFocusable,
|
319
331
|
selectAllOnFocus,
|
320
332
|
startWithEditView,
|
321
333
|
submitOnBlur,
|
@@ -326,8 +338,9 @@ var Editable = (0, import_core.forwardRef)(
|
|
326
338
|
onSubmit: onSubmitProp,
|
327
339
|
...rest
|
328
340
|
} = (0, import_core.omitThemeProps)(mergedProps);
|
341
|
+
previewFocusable != null ? previewFocusable : previewFocusable = isPreviewFocusable;
|
329
342
|
const {
|
330
|
-
|
343
|
+
editing,
|
331
344
|
getCancelProps,
|
332
345
|
getEditProps,
|
333
346
|
getInputProps,
|
@@ -355,7 +368,7 @@ var Editable = (0, import_core.forwardRef)(
|
|
355
368
|
onSubmit: onSubmitProp
|
356
369
|
});
|
357
370
|
const cloneChildren = (0, import_utils.runIfFunc)(children, {
|
358
|
-
|
371
|
+
editing,
|
359
372
|
onCancel,
|
360
373
|
onEdit,
|
361
374
|
onSubmit
|
@@ -365,7 +378,7 @@ var Editable = (0, import_core.forwardRef)(
|
|
365
378
|
EditableProvider,
|
366
379
|
{
|
367
380
|
value: {
|
368
|
-
|
381
|
+
editing,
|
369
382
|
styles,
|
370
383
|
getCancelProps,
|
371
384
|
getEditProps,
|
package/dist/editable.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/editable.tsx"],"sourcesContent":["import type {\n ColorModeToken,\n CSS,\n CSSUIObject,\n HTMLUIProps,\n PropGetter,\n ThemeProps,\n} from \"@yamada-ui/core\"\nimport type { FormControlOptions } from \"@yamada-ui/form-control\"\nimport type { ChangeEvent, FocusEvent, KeyboardEvent, ReactNode } from \"react\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentMultiStyle,\n} from \"@yamada-ui/core\"\nimport {\n formControlProperties,\n useFormControlProps,\n} from \"@yamada-ui/form-control\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useFocusOnPointerDown } from \"@yamada-ui/use-focus\"\nimport {\n createContext,\n cx,\n handlerAll,\n isContains,\n mergeRefs,\n pickObject,\n runIfFunc,\n useCallbackRef,\n useSafeLayoutEffect,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\n\nexport interface UseEditableProps extends FormControlOptions {\n /**\n * The initial value of the Editable in both edit & preview mode.\n */\n defaultValue?: string\n /**\n * If `true`, the read only view, has a `tabIndex` set to `0`\n * so it can receive focus via the keyboard or click.\n *\n * @default true\n */\n isPreviewFocusable?: boolean\n /**\n * The placeholder text when the value is empty.\n */\n placeholder?: string\n /**\n * If `true`, the input's text will be highlighted on focus.\n *\n * @default true\n */\n selectAllOnFocus?: boolean\n /**\n * If `true`, the Editable will start with edit mode by default.\n */\n startWithEditView?: boolean\n /**\n * If `true`, it'll update the value onBlur and turn off the edit mode.\n *\n * @default true\n */\n submitOnBlur?: boolean\n /**\n * The value of the Editable in both edit & preview mode.\n */\n value?: string\n /**\n * Callback invoked when user cancels input with the `Esc` key.\n * It provides the last confirmed value as argument.\n */\n onCancel?: (preValue: string) => void\n /**\n * A callback invoked when user changes input.\n */\n onChange?: (value: string) => void\n /**\n * A callback invoked once the user enters edit mode.\n */\n onEdit?: () => void\n /**\n * A callback invoked when user confirms value with `enter` key or by blurring input.\n */\n onSubmit?: (value: string) => void\n}\n\nexport const useEditable = (props: UseEditableProps) => {\n const {\n id,\n defaultValue,\n isPreviewFocusable = true,\n placeholder,\n selectAllOnFocus = true,\n startWithEditView,\n submitOnBlur = true,\n value: valueProp,\n onCancel: onCancelProp,\n onChange: onChangeProp,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n ...rest\n } = useFormControlProps(props)\n const onEditRef = useCallbackRef(onEditProp)\n const { disabled, readOnly, required, ...formControlProps } = pickObject(\n rest,\n formControlProperties,\n )\n\n const [isEditing, setIsEditing] = useState<boolean>(\n !!startWithEditView && !disabled,\n )\n\n const [value, setValue] = useControllableState({\n defaultValue: defaultValue || \"\",\n value: valueProp,\n onChange: onChangeProp,\n })\n\n const isInteractive = !isEditing && !disabled\n const isValueEmpty = value.length === 0\n\n const [prevValue, setPrevValue] = useState(value)\n\n const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null)\n const previewRef = useRef<HTMLElement>(null)\n const editRef = useRef<HTMLButtonElement>(null)\n const cancelRef = useRef<HTMLButtonElement>(null)\n const submitRef = useRef<HTMLButtonElement>(null)\n\n useFocusOnPointerDown({\n ref: inputRef,\n elements: [cancelRef, submitRef],\n enabled: isEditing,\n })\n\n useSafeLayoutEffect(() => {\n if (!isEditing) return\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n }, [])\n\n useUpdateEffect(() => {\n if (!isEditing) {\n editRef.current?.focus()\n\n return\n }\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n\n onEditRef()\n }, [isEditing, onEditRef, selectAllOnFocus])\n\n useEffect(() => {\n if (isEditing) return\n\n const el = inputRef.current\n const activeEl = el?.ownerDocument.activeElement\n\n if (activeEl === el) el?.blur()\n }, [isEditing])\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) =>\n setValue(ev.currentTarget.value),\n [setValue],\n )\n\n const onUpdatePrevValue = useCallback(() => setPrevValue(value), [value])\n\n const onEdit = useCallback(() => {\n if (isInteractive) setIsEditing(true)\n }, [isInteractive])\n\n const onCancel = useCallback(() => {\n setIsEditing(false)\n setValue(prevValue)\n onCancelProp?.(prevValue)\n }, [prevValue, onCancelProp, setValue])\n\n const onSubmit = useCallback(() => {\n setIsEditing(false)\n setPrevValue(value)\n onSubmitProp?.(value)\n }, [onSubmitProp, value])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\" && ev.key !== \"Enter\") return\n\n ev.preventDefault()\n\n if (ev.key === \"Escape\") {\n onCancel()\n } else {\n const { metaKey, shiftKey } = ev\n\n if (!shiftKey && !metaKey) onSubmit()\n }\n },\n [onCancel, onSubmit],\n )\n\n const onKeyDownWithoutSubmit = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\") return\n\n ev.preventDefault()\n onCancel()\n },\n [onCancel],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent) => {\n if (!isEditing) return\n\n const ownerDocument = ev.currentTarget.ownerDocument\n const relatedTarget = (ev.relatedTarget ??\n ownerDocument.activeElement) as HTMLElement\n const targetIsCancel = isContains(cancelRef.current, relatedTarget)\n const targetIsSubmit = isContains(submitRef.current, relatedTarget)\n const isValidBlur = !targetIsCancel && !targetIsSubmit\n\n if (!isValidBlur) return\n\n if (submitOnBlur) {\n onSubmit()\n } else {\n onCancel()\n }\n },\n [isEditing, submitOnBlur, onSubmit, onCancel],\n )\n\n const getPreviewProps: PropGetter<\"span\"> = useCallback(\n (props = {}, ref = null) => ({\n ...props,\n ref: mergeRefs(ref, previewRef),\n children: isValueEmpty ? placeholder : value,\n hidden: isEditing,\n tabIndex: isInteractive && isPreviewFocusable ? 0 : undefined,\n onFocus: handlerAll(props.onFocus, onEdit, onUpdatePrevValue),\n }),\n [\n isEditing,\n isInteractive,\n isPreviewFocusable,\n isValueEmpty,\n onEdit,\n onUpdatePrevValue,\n placeholder,\n value,\n ],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n id,\n ref: mergeRefs(ref, inputRef),\n disabled,\n hidden: !isEditing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n disabled,\n id,\n isEditing,\n onBlur,\n onChange,\n onKeyDown,\n onUpdatePrevValue,\n placeholder,\n readOnly,\n required,\n formControlProps,\n value,\n ],\n )\n\n const getTextareaProps: PropGetter<\"textarea\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n id,\n ref: mergeRefs(ref, inputRef),\n disabled,\n hidden: !isEditing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDownWithoutSubmit),\n }),\n [\n disabled,\n id,\n isEditing,\n onBlur,\n onChange,\n onKeyDownWithoutSubmit,\n onUpdatePrevValue,\n placeholder,\n readOnly,\n required,\n formControlProps,\n value,\n ],\n )\n\n const getEditProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(ref, editRef),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onEdit),\n }),\n [disabled, onEdit, readOnly, formControlProps],\n )\n\n const getSubmitProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(submitRef, ref),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onSubmit),\n }),\n [disabled, onSubmit, readOnly, formControlProps],\n )\n\n const getCancelProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(cancelRef, ref),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onCancel),\n }),\n [disabled, onCancel, readOnly, formControlProps],\n )\n\n return {\n isEditing,\n value,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n onCancel,\n onEdit,\n onSubmit,\n }\n}\n\nexport type UseEditableReturn = ReturnType<typeof useEditable>\n\nexport const useEditableControl = () => {\n const { isEditing, getCancelProps, getEditProps, getSubmitProps } =\n useEditableContext()\n\n return { isEditing, getCancelProps, getEditProps, getSubmitProps }\n}\n\ninterface EditableContext {\n isEditing: boolean\n styles: { [key: string]: CSSUIObject | undefined }\n getCancelProps: PropGetter<\"button\">\n getEditProps: PropGetter<\"button\">\n getInputProps: PropGetter<\"input\">\n getPreviewProps: PropGetter<\"span\">\n getSubmitProps: PropGetter<\"button\">\n getTextareaProps: PropGetter<\"textarea\">\n}\n\nconst [EditableProvider, useEditableContext] = createContext<EditableContext>({\n name: \"EditableContext\",\n errorMessage:\n \"useEditableContext: context is undefined. Seems you forgot to wrap the editable components in `<Editable />`\",\n})\n\ninterface EditableElementProps\n extends Pick<\n UseEditableReturn,\n \"isEditing\" | \"onCancel\" | \"onEdit\" | \"onSubmit\"\n > {}\n\ntype EditableElement = (props: EditableElementProps) => ReactNode\n\ninterface EditableOptions {\n children?: EditableElement | ReactNode\n /**\n * The border color when the input is invalid.\n */\n errorBorderColor?: ColorModeToken<CSS.Property.BorderColor, \"colors\">\n /**\n * The border color when the input is focused.\n */\n focusBorderColor?: ColorModeToken<CSS.Property.BorderColor, \"colors\">\n}\n\nexport interface EditableProps\n extends Omit<\n HTMLUIProps,\n \"children\" | \"defaultValue\" | \"onChange\" | \"onSubmit\" | \"value\"\n >,\n ThemeProps<\"Editable\">,\n UseEditableProps,\n EditableOptions {}\n\n/**\n * `Editable` is a component used to obtain inline editable text input.\n *\n * @see Docs https://yamada-ui.com/components/forms/editable\n */\nexport const Editable = forwardRef<EditableProps, \"div\">(\n ({ errorBorderColor, focusBorderColor, ...props }, ref) => {\n const [styles, mergedProps] = useComponentMultiStyle(\"Editable\", {\n errorBorderColor,\n focusBorderColor,\n ...props,\n })\n const {\n className,\n children,\n defaultValue,\n isDisabled,\n isInvalid,\n isPreviewFocusable,\n isReadOnly,\n isRequired,\n placeholder,\n selectAllOnFocus,\n startWithEditView,\n submitOnBlur,\n value,\n onCancel: onCancelProp,\n onChange,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n ...rest\n } = omitThemeProps(mergedProps)\n const {\n isEditing,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n onCancel,\n onEdit,\n onSubmit,\n } = useEditable({\n defaultValue,\n isDisabled,\n isInvalid,\n isPreviewFocusable,\n isReadOnly,\n isRequired,\n placeholder,\n selectAllOnFocus,\n startWithEditView,\n submitOnBlur,\n value,\n onCancel: onCancelProp,\n onChange,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n })\n\n const cloneChildren = runIfFunc(children, {\n isEditing,\n onCancel,\n onEdit,\n onSubmit,\n })\n\n const css: CSSUIObject = { ...styles.container }\n\n return (\n <EditableProvider\n value={{\n isEditing,\n styles,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n }}\n >\n <ui.div\n ref={ref}\n className={cx(\"ui-editable\", className)}\n {...rest}\n __css={css}\n >\n {cloneChildren}\n </ui.div>\n </EditableProvider>\n )\n },\n)\n\nEditable.displayName = \"Editable\"\nEditable.__ui__ = \"Editable\"\n\nexport interface EditablePreviewProps extends HTMLUIProps<\"span\"> {}\n\nexport const EditablePreview = forwardRef<EditablePreviewProps, \"span\">(\n ({ className, ...rest }, ref) => {\n const { styles, getPreviewProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n cursor: \"text\",\n display: \"inline-block\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n textAlign: \"inherit\",\n ...styles.preview,\n }\n\n return (\n <ui.span\n className={cx(\"ui-editable__preview\", className)}\n {...getPreviewProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditablePreview.displayName = \"EditablePreview\"\nEditablePreview.__ui__ = \"EditablePreview\"\n\nexport interface EditableInputProps extends HTMLUIProps<\"input\"> {}\n\nexport const EditableInput = forwardRef<EditableInputProps, \"input\">(\n ({ className, ...rest }, ref) => {\n const { styles, getInputProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n outline: 0,\n textAlign: \"inherit\",\n ...styles.input,\n }\n\n return (\n <ui.input\n className={cx(\"ui-editable__input\", className)}\n {...getInputProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditableInput.displayName = \"EditableInput\"\nEditableInput.__ui__ = \"EditableInput\"\n\nexport interface EditableTextareaProps extends HTMLUIProps<\"textarea\"> {}\n\nexport const EditableTextarea = forwardRef<EditableTextareaProps, \"textarea\">(\n ({ className, ...rest }, ref) => {\n const { styles, getTextareaProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n outline: 0,\n textAlign: \"inherit\",\n ...styles.textarea,\n }\n\n return (\n <ui.textarea\n className={cx(\"ui-editable__textarea\", className)}\n {...getTextareaProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditableTextarea.displayName = \"EditableTextarea\"\nEditableTextarea.__ui__ = \"EditableTextarea\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,kBAKO;AACP,0BAGO;AACP,oCAAqC;AACrC,uBAAsC;AACtC,mBAWO;AACP,mBAAyD;AAyejD;AAhbD,IAAM,cAAc,CAAC,UAA4B;AACtD,QAAM;AAAA,I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":3,"sources":["../src/editable.tsx"],"sourcesContent":["import type {\n ColorModeToken,\n CSS,\n CSSUIObject,\n HTMLUIProps,\n PropGetter,\n ThemeProps,\n} from \"@yamada-ui/core\"\nimport type { FormControlOptions } from \"@yamada-ui/form-control\"\nimport type { ChangeEvent, FocusEvent, KeyboardEvent, ReactNode } from \"react\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentMultiStyle,\n} from \"@yamada-ui/core\"\nimport {\n formControlProperties,\n useFormControlProps,\n} from \"@yamada-ui/form-control\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useFocusOnPointerDown } from \"@yamada-ui/use-focus\"\nimport {\n createContext,\n cx,\n handlerAll,\n isContains,\n mergeRefs,\n pickObject,\n runIfFunc,\n useCallbackRef,\n useSafeLayoutEffect,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\n\nexport interface UseEditableProps extends FormControlOptions {\n /**\n * The initial value of the Editable in both edit & preview mode.\n */\n defaultValue?: string\n /**\n * If `true`, the read only view, has a `tabIndex` set to `0`\n * so it can receive focus via the keyboard or click.\n *\n * @default true\n *\n * @deprecated Use `previewFocusable` instead.\n */\n isPreviewFocusable?: boolean\n /**\n * The placeholder text when the value is empty.\n */\n placeholder?: string\n /**\n * If `true`, the read only view, has a `tabIndex` set to `0`\n * so it can receive focus via the keyboard or click.\n *\n * @default true\n */\n previewFocusable?: boolean\n /**\n * If `true`, the input's text will be highlighted on focus.\n *\n * @default true\n */\n selectAllOnFocus?: boolean\n /**\n * If `true`, the Editable will start with edit mode by default.\n */\n startWithEditView?: boolean\n /**\n * If `true`, it'll update the value onBlur and turn off the edit mode.\n *\n * @default true\n */\n submitOnBlur?: boolean\n /**\n * The value of the Editable in both edit & preview mode.\n */\n value?: string\n /**\n * Callback invoked when user cancels input with the `Esc` key.\n * It provides the last confirmed value as argument.\n */\n onCancel?: (preValue: string) => void\n /**\n * A callback invoked when user changes input.\n */\n onChange?: (value: string) => void\n /**\n * A callback invoked once the user enters edit mode.\n */\n onEdit?: () => void\n /**\n * A callback invoked when user confirms value with `enter` key or by blurring input.\n */\n onSubmit?: (value: string) => void\n}\n\nexport const useEditable = (props: UseEditableProps) => {\n let {\n id,\n defaultValue,\n isPreviewFocusable = true,\n placeholder,\n previewFocusable,\n selectAllOnFocus = true,\n startWithEditView,\n submitOnBlur = true,\n value: valueProp,\n onCancel: onCancelProp,\n onChange: onChangeProp,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n ...rest\n } = useFormControlProps(props)\n\n previewFocusable ??= isPreviewFocusable\n\n const onEditRef = useCallbackRef(onEditProp)\n const { disabled, readOnly, required, ...formControlProps } = pickObject(\n rest,\n formControlProperties,\n )\n\n const [editing, setEditing] = useState<boolean>(\n !!startWithEditView && !disabled,\n )\n\n const [value, setValue] = useControllableState({\n defaultValue: defaultValue || \"\",\n value: valueProp,\n onChange: onChangeProp,\n })\n\n const interactive = !editing && !disabled\n const emptyValue = value.length === 0\n\n const [prevValue, setPrevValue] = useState(value)\n\n const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null)\n const previewRef = useRef<HTMLElement>(null)\n const editRef = useRef<HTMLButtonElement>(null)\n const cancelRef = useRef<HTMLButtonElement>(null)\n const submitRef = useRef<HTMLButtonElement>(null)\n\n useFocusOnPointerDown({\n ref: inputRef,\n elements: [cancelRef, submitRef],\n enabled: editing,\n })\n\n useSafeLayoutEffect(() => {\n if (!editing) return\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n }, [])\n\n useUpdateEffect(() => {\n if (!editing) {\n editRef.current?.focus()\n\n return\n }\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n\n onEditRef()\n }, [editing, onEditRef, selectAllOnFocus])\n\n useEffect(() => {\n if (editing) return\n\n const el = inputRef.current\n const activeEl = el?.ownerDocument.activeElement\n\n if (activeEl === el) el?.blur()\n }, [editing])\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) =>\n setValue(ev.currentTarget.value),\n [setValue],\n )\n\n const onUpdatePrevValue = useCallback(() => setPrevValue(value), [value])\n\n const onEdit = useCallback(() => {\n if (interactive) setEditing(true)\n }, [interactive])\n\n const onCancel = useCallback(() => {\n setEditing(false)\n setValue(prevValue)\n onCancelProp?.(prevValue)\n }, [prevValue, onCancelProp, setValue])\n\n const onSubmit = useCallback(() => {\n setEditing(false)\n setPrevValue(value)\n onSubmitProp?.(value)\n }, [onSubmitProp, value])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\" && ev.key !== \"Enter\") return\n\n ev.preventDefault()\n\n if (ev.key === \"Escape\") {\n onCancel()\n } else {\n const { metaKey, shiftKey } = ev\n\n if (!shiftKey && !metaKey) onSubmit()\n }\n },\n [onCancel, onSubmit],\n )\n\n const onKeyDownWithoutSubmit = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\") return\n\n ev.preventDefault()\n onCancel()\n },\n [onCancel],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent) => {\n if (!editing) return\n\n const ownerDocument = ev.currentTarget.ownerDocument\n const relatedTarget = (ev.relatedTarget ??\n ownerDocument.activeElement) as HTMLElement\n const targetIsCancel = isContains(cancelRef.current, relatedTarget)\n const targetIsSubmit = isContains(submitRef.current, relatedTarget)\n const isValidBlur = !targetIsCancel && !targetIsSubmit\n\n if (!isValidBlur) return\n\n if (submitOnBlur) {\n onSubmit()\n } else {\n onCancel()\n }\n },\n [editing, submitOnBlur, onSubmit, onCancel],\n )\n\n const getPreviewProps: PropGetter<\"span\"> = useCallback(\n (props = {}, ref = null) => ({\n ...props,\n ref: mergeRefs(ref, previewRef),\n children: emptyValue ? placeholder : value,\n hidden: editing,\n tabIndex: interactive && previewFocusable ? 0 : undefined,\n onFocus: handlerAll(props.onFocus, onEdit, onUpdatePrevValue),\n }),\n [\n editing,\n interactive,\n previewFocusable,\n emptyValue,\n onEdit,\n onUpdatePrevValue,\n placeholder,\n value,\n ],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n id,\n ref: mergeRefs(ref, inputRef),\n disabled,\n hidden: !editing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n disabled,\n id,\n editing,\n onBlur,\n onChange,\n onKeyDown,\n onUpdatePrevValue,\n placeholder,\n readOnly,\n required,\n formControlProps,\n value,\n ],\n )\n\n const getTextareaProps: PropGetter<\"textarea\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n id,\n ref: mergeRefs(ref, inputRef),\n disabled,\n hidden: !editing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDownWithoutSubmit),\n }),\n [\n disabled,\n id,\n editing,\n onBlur,\n onChange,\n onKeyDownWithoutSubmit,\n onUpdatePrevValue,\n placeholder,\n readOnly,\n required,\n formControlProps,\n value,\n ],\n )\n\n const getEditProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(ref, editRef),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onEdit),\n }),\n [disabled, onEdit, readOnly, formControlProps],\n )\n\n const getSubmitProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(submitRef, ref),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onSubmit),\n }),\n [disabled, onSubmit, readOnly, formControlProps],\n )\n\n const getCancelProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(cancelRef, ref),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onCancel),\n }),\n [disabled, onCancel, readOnly, formControlProps],\n )\n\n return {\n editing,\n value,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n onCancel,\n onEdit,\n onSubmit,\n }\n}\n\nexport type UseEditableReturn = ReturnType<typeof useEditable>\n\nexport const useEditableControl = () => {\n const { editing, getCancelProps, getEditProps, getSubmitProps } =\n useEditableContext()\n\n return {\n editing,\n /**\n * @deprecated Use `editing` instead.\n */\n isEditing: editing,\n getCancelProps,\n getEditProps,\n getSubmitProps,\n }\n}\n\ninterface EditableContext {\n editing: boolean\n styles: { [key: string]: CSSUIObject | undefined }\n getCancelProps: PropGetter<\"button\">\n getEditProps: PropGetter<\"button\">\n getInputProps: PropGetter<\"input\">\n getPreviewProps: PropGetter<\"span\">\n getSubmitProps: PropGetter<\"button\">\n getTextareaProps: PropGetter<\"textarea\">\n}\n\nconst [EditableProvider, useEditableContext] = createContext<EditableContext>({\n name: \"EditableContext\",\n errorMessage:\n \"useEditableContext: context is undefined. Seems you forgot to wrap the editable components in `<Editable />`\",\n})\n\ninterface EditableElementProps\n extends Pick<\n UseEditableReturn,\n \"editing\" | \"onCancel\" | \"onEdit\" | \"onSubmit\"\n > {}\n\ntype EditableElement = (props: EditableElementProps) => ReactNode\n\ninterface EditableOptions {\n children?: EditableElement | ReactNode\n /**\n * The border color when the input is invalid.\n */\n errorBorderColor?: ColorModeToken<CSS.Property.BorderColor, \"colors\">\n /**\n * The border color when the input is focused.\n */\n focusBorderColor?: ColorModeToken<CSS.Property.BorderColor, \"colors\">\n}\n\nexport interface EditableProps\n extends Omit<\n HTMLUIProps,\n \"children\" | \"defaultValue\" | \"onChange\" | \"onSubmit\" | \"value\"\n >,\n ThemeProps<\"Editable\">,\n UseEditableProps,\n EditableOptions {}\n\n/**\n * `Editable` is a component used to obtain inline editable text input.\n *\n * @see Docs https://yamada-ui.com/components/forms/editable\n */\nexport const Editable = forwardRef<EditableProps, \"div\">(\n ({ errorBorderColor, focusBorderColor, ...props }, ref) => {\n const [styles, mergedProps] = useComponentMultiStyle(\"Editable\", {\n errorBorderColor,\n focusBorderColor,\n ...props,\n })\n let {\n className,\n children,\n defaultValue,\n isDisabled,\n isInvalid,\n isPreviewFocusable,\n isReadOnly,\n isRequired,\n placeholder,\n previewFocusable,\n selectAllOnFocus,\n startWithEditView,\n submitOnBlur,\n value,\n onCancel: onCancelProp,\n onChange,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n ...rest\n } = omitThemeProps(mergedProps)\n\n previewFocusable ??= isPreviewFocusable\n\n const {\n editing,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n onCancel,\n onEdit,\n onSubmit,\n } = useEditable({\n defaultValue,\n isDisabled,\n isInvalid,\n isPreviewFocusable,\n isReadOnly,\n isRequired,\n placeholder,\n selectAllOnFocus,\n startWithEditView,\n submitOnBlur,\n value,\n onCancel: onCancelProp,\n onChange,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n })\n\n const cloneChildren = runIfFunc(children, {\n editing,\n onCancel,\n onEdit,\n onSubmit,\n })\n\n const css: CSSUIObject = { ...styles.container }\n\n return (\n <EditableProvider\n value={{\n editing,\n styles,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n }}\n >\n <ui.div\n ref={ref}\n className={cx(\"ui-editable\", className)}\n {...rest}\n __css={css}\n >\n {cloneChildren}\n </ui.div>\n </EditableProvider>\n )\n },\n)\n\nEditable.displayName = \"Editable\"\nEditable.__ui__ = \"Editable\"\n\nexport interface EditablePreviewProps extends HTMLUIProps<\"span\"> {}\n\nexport const EditablePreview = forwardRef<EditablePreviewProps, \"span\">(\n ({ className, ...rest }, ref) => {\n const { styles, getPreviewProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n cursor: \"text\",\n display: \"inline-block\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n textAlign: \"inherit\",\n ...styles.preview,\n }\n\n return (\n <ui.span\n className={cx(\"ui-editable__preview\", className)}\n {...getPreviewProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditablePreview.displayName = \"EditablePreview\"\nEditablePreview.__ui__ = \"EditablePreview\"\n\nexport interface EditableInputProps extends HTMLUIProps<\"input\"> {}\n\nexport const EditableInput = forwardRef<EditableInputProps, \"input\">(\n ({ className, ...rest }, ref) => {\n const { styles, getInputProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n outline: 0,\n textAlign: \"inherit\",\n ...styles.input,\n }\n\n return (\n <ui.input\n className={cx(\"ui-editable__input\", className)}\n {...getInputProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditableInput.displayName = \"EditableInput\"\nEditableInput.__ui__ = \"EditableInput\"\n\nexport interface EditableTextareaProps extends HTMLUIProps<\"textarea\"> {}\n\nexport const EditableTextarea = forwardRef<EditableTextareaProps, \"textarea\">(\n ({ className, ...rest }, ref) => {\n const { styles, getTextareaProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n outline: 0,\n textAlign: \"inherit\",\n ...styles.textarea,\n }\n\n return (\n <ui.textarea\n className={cx(\"ui-editable__textarea\", className)}\n {...getTextareaProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditableTextarea.displayName = \"EditableTextarea\"\nEditableTextarea.__ui__ = \"EditableTextarea\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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AAA,IACZ;AAEA,WACE;AAAA,MAAC,eAAG;AAAA,MAAH;AAAA,QACC,eAAW,iBAAG,yBAAyB,SAAS;AAAA,QAC/C,GAAG,iBAAiB,MAAM,GAAG;AAAA,QAC9B,OAAO;AAAA;AAAA,IACT;AAAA,EAEJ;AACF;AAEA,iBAAiB,cAAc;AAC/B,iBAAiB,SAAS;","names":["props"]}
|
package/dist/editable.mjs
CHANGED
package/dist/index.js
CHANGED
@@ -39,11 +39,12 @@ var import_utils = require("@yamada-ui/utils");
|
|
39
39
|
var import_react = require("react");
|
40
40
|
var import_jsx_runtime = require("react/jsx-runtime");
|
41
41
|
var useEditable = (props) => {
|
42
|
-
|
42
|
+
let {
|
43
43
|
id,
|
44
44
|
defaultValue,
|
45
45
|
isPreviewFocusable = true,
|
46
46
|
placeholder,
|
47
|
+
previewFocusable,
|
47
48
|
selectAllOnFocus = true,
|
48
49
|
startWithEditView,
|
49
50
|
submitOnBlur = true,
|
@@ -54,12 +55,13 @@ var useEditable = (props) => {
|
|
54
55
|
onSubmit: onSubmitProp,
|
55
56
|
...rest
|
56
57
|
} = (0, import_form_control.useFormControlProps)(props);
|
58
|
+
previewFocusable != null ? previewFocusable : previewFocusable = isPreviewFocusable;
|
57
59
|
const onEditRef = (0, import_utils.useCallbackRef)(onEditProp);
|
58
60
|
const { disabled, readOnly, required, ...formControlProps } = (0, import_utils.pickObject)(
|
59
61
|
rest,
|
60
62
|
import_form_control.formControlProperties
|
61
63
|
);
|
62
|
-
const [
|
64
|
+
const [editing, setEditing] = (0, import_react.useState)(
|
63
65
|
!!startWithEditView && !disabled
|
64
66
|
);
|
65
67
|
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
@@ -67,8 +69,8 @@ var useEditable = (props) => {
|
|
67
69
|
value: valueProp,
|
68
70
|
onChange: onChangeProp
|
69
71
|
});
|
70
|
-
const
|
71
|
-
const
|
72
|
+
const interactive = !editing && !disabled;
|
73
|
+
const emptyValue = value.length === 0;
|
72
74
|
const [prevValue, setPrevValue] = (0, import_react.useState)(value);
|
73
75
|
const inputRef = (0, import_react.useRef)(null);
|
74
76
|
const previewRef = (0, import_react.useRef)(null);
|
@@ -78,45 +80,45 @@ var useEditable = (props) => {
|
|
78
80
|
(0, import_use_focus.useFocusOnPointerDown)({
|
79
81
|
ref: inputRef,
|
80
82
|
elements: [cancelRef, submitRef],
|
81
|
-
enabled:
|
83
|
+
enabled: editing
|
82
84
|
});
|
83
85
|
(0, import_utils.useSafeLayoutEffect)(() => {
|
84
86
|
var _a, _b;
|
85
|
-
if (!
|
87
|
+
if (!editing) return;
|
86
88
|
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
87
89
|
if (selectAllOnFocus) (_b = inputRef.current) == null ? void 0 : _b.select();
|
88
90
|
}, []);
|
89
91
|
(0, import_utils.useUpdateEffect)(() => {
|
90
92
|
var _a, _b, _c;
|
91
|
-
if (!
|
93
|
+
if (!editing) {
|
92
94
|
(_a = editRef.current) == null ? void 0 : _a.focus();
|
93
95
|
return;
|
94
96
|
}
|
95
97
|
(_b = inputRef.current) == null ? void 0 : _b.focus();
|
96
98
|
if (selectAllOnFocus) (_c = inputRef.current) == null ? void 0 : _c.select();
|
97
99
|
onEditRef();
|
98
|
-
}, [
|
100
|
+
}, [editing, onEditRef, selectAllOnFocus]);
|
99
101
|
(0, import_react.useEffect)(() => {
|
100
|
-
if (
|
102
|
+
if (editing) return;
|
101
103
|
const el = inputRef.current;
|
102
104
|
const activeEl = el == null ? void 0 : el.ownerDocument.activeElement;
|
103
105
|
if (activeEl === el) el == null ? void 0 : el.blur();
|
104
|
-
}, [
|
106
|
+
}, [editing]);
|
105
107
|
const onChange = (0, import_react.useCallback)(
|
106
108
|
(ev) => setValue(ev.currentTarget.value),
|
107
109
|
[setValue]
|
108
110
|
);
|
109
111
|
const onUpdatePrevValue = (0, import_react.useCallback)(() => setPrevValue(value), [value]);
|
110
112
|
const onEdit = (0, import_react.useCallback)(() => {
|
111
|
-
if (
|
112
|
-
}, [
|
113
|
+
if (interactive) setEditing(true);
|
114
|
+
}, [interactive]);
|
113
115
|
const onCancel = (0, import_react.useCallback)(() => {
|
114
|
-
|
116
|
+
setEditing(false);
|
115
117
|
setValue(prevValue);
|
116
118
|
onCancelProp == null ? void 0 : onCancelProp(prevValue);
|
117
119
|
}, [prevValue, onCancelProp, setValue]);
|
118
120
|
const onSubmit = (0, import_react.useCallback)(() => {
|
119
|
-
|
121
|
+
setEditing(false);
|
120
122
|
setPrevValue(value);
|
121
123
|
onSubmitProp == null ? void 0 : onSubmitProp(value);
|
122
124
|
}, [onSubmitProp, value]);
|
@@ -144,7 +146,7 @@ var useEditable = (props) => {
|
|
144
146
|
const onBlur = (0, import_react.useCallback)(
|
145
147
|
(ev) => {
|
146
148
|
var _a;
|
147
|
-
if (!
|
149
|
+
if (!editing) return;
|
148
150
|
const ownerDocument = ev.currentTarget.ownerDocument;
|
149
151
|
const relatedTarget = (_a = ev.relatedTarget) != null ? _a : ownerDocument.activeElement;
|
150
152
|
const targetIsCancel = (0, import_utils.isContains)(cancelRef.current, relatedTarget);
|
@@ -157,22 +159,22 @@ var useEditable = (props) => {
|
|
157
159
|
onCancel();
|
158
160
|
}
|
159
161
|
},
|
160
|
-
[
|
162
|
+
[editing, submitOnBlur, onSubmit, onCancel]
|
161
163
|
);
|
162
164
|
const getPreviewProps = (0, import_react.useCallback)(
|
163
165
|
(props2 = {}, ref = null) => ({
|
164
166
|
...props2,
|
165
167
|
ref: (0, import_utils.mergeRefs)(ref, previewRef),
|
166
|
-
children:
|
167
|
-
hidden:
|
168
|
-
tabIndex:
|
168
|
+
children: emptyValue ? placeholder : value,
|
169
|
+
hidden: editing,
|
170
|
+
tabIndex: interactive && previewFocusable ? 0 : void 0,
|
169
171
|
onFocus: (0, import_utils.handlerAll)(props2.onFocus, onEdit, onUpdatePrevValue)
|
170
172
|
}),
|
171
173
|
[
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
174
|
+
editing,
|
175
|
+
interactive,
|
176
|
+
previewFocusable,
|
177
|
+
emptyValue,
|
176
178
|
onEdit,
|
177
179
|
onUpdatePrevValue,
|
178
180
|
placeholder,
|
@@ -186,7 +188,7 @@ var useEditable = (props) => {
|
|
186
188
|
id,
|
187
189
|
ref: (0, import_utils.mergeRefs)(ref, inputRef),
|
188
190
|
disabled,
|
189
|
-
hidden: !
|
191
|
+
hidden: !editing,
|
190
192
|
placeholder,
|
191
193
|
readOnly,
|
192
194
|
required,
|
@@ -199,7 +201,7 @@ var useEditable = (props) => {
|
|
199
201
|
[
|
200
202
|
disabled,
|
201
203
|
id,
|
202
|
-
|
204
|
+
editing,
|
203
205
|
onBlur,
|
204
206
|
onChange,
|
205
207
|
onKeyDown,
|
@@ -218,7 +220,7 @@ var useEditable = (props) => {
|
|
218
220
|
id,
|
219
221
|
ref: (0, import_utils.mergeRefs)(ref, inputRef),
|
220
222
|
disabled,
|
221
|
-
hidden: !
|
223
|
+
hidden: !editing,
|
222
224
|
placeholder,
|
223
225
|
readOnly,
|
224
226
|
required,
|
@@ -231,7 +233,7 @@ var useEditable = (props) => {
|
|
231
233
|
[
|
232
234
|
disabled,
|
233
235
|
id,
|
234
|
-
|
236
|
+
editing,
|
235
237
|
onBlur,
|
236
238
|
onChange,
|
237
239
|
onKeyDownWithoutSubmit,
|
@@ -280,7 +282,7 @@ var useEditable = (props) => {
|
|
280
282
|
[disabled, onCancel, readOnly, formControlProps]
|
281
283
|
);
|
282
284
|
return {
|
283
|
-
|
285
|
+
editing,
|
284
286
|
value,
|
285
287
|
getCancelProps,
|
286
288
|
getEditProps,
|
@@ -294,8 +296,17 @@ var useEditable = (props) => {
|
|
294
296
|
};
|
295
297
|
};
|
296
298
|
var useEditableControl = () => {
|
297
|
-
const {
|
298
|
-
return {
|
299
|
+
const { editing, getCancelProps, getEditProps, getSubmitProps } = useEditableContext();
|
300
|
+
return {
|
301
|
+
editing,
|
302
|
+
/**
|
303
|
+
* @deprecated Use `editing` instead.
|
304
|
+
*/
|
305
|
+
isEditing: editing,
|
306
|
+
getCancelProps,
|
307
|
+
getEditProps,
|
308
|
+
getSubmitProps
|
309
|
+
};
|
299
310
|
};
|
300
311
|
var [EditableProvider, useEditableContext] = (0, import_utils.createContext)({
|
301
312
|
name: "EditableContext",
|
@@ -308,7 +319,7 @@ var Editable = (0, import_core.forwardRef)(
|
|
308
319
|
focusBorderColor,
|
309
320
|
...props
|
310
321
|
});
|
311
|
-
|
322
|
+
let {
|
312
323
|
className,
|
313
324
|
children,
|
314
325
|
defaultValue,
|
@@ -318,6 +329,7 @@ var Editable = (0, import_core.forwardRef)(
|
|
318
329
|
isReadOnly,
|
319
330
|
isRequired,
|
320
331
|
placeholder,
|
332
|
+
previewFocusable,
|
321
333
|
selectAllOnFocus,
|
322
334
|
startWithEditView,
|
323
335
|
submitOnBlur,
|
@@ -328,8 +340,9 @@ var Editable = (0, import_core.forwardRef)(
|
|
328
340
|
onSubmit: onSubmitProp,
|
329
341
|
...rest
|
330
342
|
} = (0, import_core.omitThemeProps)(mergedProps);
|
343
|
+
previewFocusable != null ? previewFocusable : previewFocusable = isPreviewFocusable;
|
331
344
|
const {
|
332
|
-
|
345
|
+
editing,
|
333
346
|
getCancelProps,
|
334
347
|
getEditProps,
|
335
348
|
getInputProps,
|
@@ -357,7 +370,7 @@ var Editable = (0, import_core.forwardRef)(
|
|
357
370
|
onSubmit: onSubmitProp
|
358
371
|
});
|
359
372
|
const cloneChildren = (0, import_utils.runIfFunc)(children, {
|
360
|
-
|
373
|
+
editing,
|
361
374
|
onCancel,
|
362
375
|
onEdit,
|
363
376
|
onSubmit
|
@@ -367,7 +380,7 @@ var Editable = (0, import_core.forwardRef)(
|
|
367
380
|
EditableProvider,
|
368
381
|
{
|
369
382
|
value: {
|
370
|
-
|
383
|
+
editing,
|
371
384
|
styles,
|
372
385
|
getCancelProps,
|
373
386
|
getEditProps,
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/editable.tsx"],"sourcesContent":["export {\n Editable,\n EditableInput,\n EditablePreview,\n EditableTextarea,\n useEditable,\n useEditableControl,\n} from \"./editable\"\nexport type {\n EditableInputProps,\n EditablePreviewProps,\n EditableProps,\n EditableTextareaProps,\n UseEditableProps,\n UseEditableReturn,\n} from \"./editable\"\n","import type {\n ColorModeToken,\n CSS,\n CSSUIObject,\n HTMLUIProps,\n PropGetter,\n ThemeProps,\n} from \"@yamada-ui/core\"\nimport type { FormControlOptions } from \"@yamada-ui/form-control\"\nimport type { ChangeEvent, FocusEvent, KeyboardEvent, ReactNode } from \"react\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentMultiStyle,\n} from \"@yamada-ui/core\"\nimport {\n formControlProperties,\n useFormControlProps,\n} from \"@yamada-ui/form-control\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useFocusOnPointerDown } from \"@yamada-ui/use-focus\"\nimport {\n createContext,\n cx,\n handlerAll,\n isContains,\n mergeRefs,\n pickObject,\n runIfFunc,\n useCallbackRef,\n useSafeLayoutEffect,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\n\nexport interface UseEditableProps extends FormControlOptions {\n /**\n * The initial value of the Editable in both edit & preview mode.\n */\n defaultValue?: string\n /**\n * If `true`, the read only view, has a `tabIndex` set to `0`\n * so it can receive focus via the keyboard or click.\n *\n * @default true\n */\n isPreviewFocusable?: boolean\n /**\n * The placeholder text when the value is empty.\n */\n placeholder?: string\n /**\n * If `true`, the input's text will be highlighted on focus.\n *\n * @default true\n */\n selectAllOnFocus?: boolean\n /**\n * If `true`, the Editable will start with edit mode by default.\n */\n startWithEditView?: boolean\n /**\n * If `true`, it'll update the value onBlur and turn off the edit mode.\n *\n * @default true\n */\n submitOnBlur?: boolean\n /**\n * The value of the Editable in both edit & preview mode.\n */\n value?: string\n /**\n * Callback invoked when user cancels input with the `Esc` key.\n * It provides the last confirmed value as argument.\n */\n onCancel?: (preValue: string) => void\n /**\n * A callback invoked when user changes input.\n */\n onChange?: (value: string) => void\n /**\n * A callback invoked once the user enters edit mode.\n */\n onEdit?: () => void\n /**\n * A callback invoked when user confirms value with `enter` key or by blurring input.\n */\n onSubmit?: (value: string) => void\n}\n\nexport const useEditable = (props: UseEditableProps) => {\n const {\n id,\n defaultValue,\n isPreviewFocusable = true,\n placeholder,\n selectAllOnFocus = true,\n startWithEditView,\n submitOnBlur = true,\n value: valueProp,\n onCancel: onCancelProp,\n onChange: onChangeProp,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n ...rest\n } = useFormControlProps(props)\n const onEditRef = useCallbackRef(onEditProp)\n const { disabled, readOnly, required, ...formControlProps } = pickObject(\n rest,\n formControlProperties,\n )\n\n const [isEditing, setIsEditing] = useState<boolean>(\n !!startWithEditView && !disabled,\n )\n\n const [value, setValue] = useControllableState({\n defaultValue: defaultValue || \"\",\n value: valueProp,\n onChange: onChangeProp,\n })\n\n const isInteractive = !isEditing && !disabled\n const isValueEmpty = value.length === 0\n\n const [prevValue, setPrevValue] = useState(value)\n\n const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null)\n const previewRef = useRef<HTMLElement>(null)\n const editRef = useRef<HTMLButtonElement>(null)\n const cancelRef = useRef<HTMLButtonElement>(null)\n const submitRef = useRef<HTMLButtonElement>(null)\n\n useFocusOnPointerDown({\n ref: inputRef,\n elements: [cancelRef, submitRef],\n enabled: isEditing,\n })\n\n useSafeLayoutEffect(() => {\n if (!isEditing) return\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n }, [])\n\n useUpdateEffect(() => {\n if (!isEditing) {\n editRef.current?.focus()\n\n return\n }\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n\n onEditRef()\n }, [isEditing, onEditRef, selectAllOnFocus])\n\n useEffect(() => {\n if (isEditing) return\n\n const el = inputRef.current\n const activeEl = el?.ownerDocument.activeElement\n\n if (activeEl === el) el?.blur()\n }, [isEditing])\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) =>\n setValue(ev.currentTarget.value),\n [setValue],\n )\n\n const onUpdatePrevValue = useCallback(() => setPrevValue(value), [value])\n\n const onEdit = useCallback(() => {\n if (isInteractive) setIsEditing(true)\n }, [isInteractive])\n\n const onCancel = useCallback(() => {\n setIsEditing(false)\n setValue(prevValue)\n onCancelProp?.(prevValue)\n }, [prevValue, onCancelProp, setValue])\n\n const onSubmit = useCallback(() => {\n setIsEditing(false)\n setPrevValue(value)\n onSubmitProp?.(value)\n }, [onSubmitProp, value])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\" && ev.key !== \"Enter\") return\n\n ev.preventDefault()\n\n if (ev.key === \"Escape\") {\n onCancel()\n } else {\n const { metaKey, shiftKey } = ev\n\n if (!shiftKey && !metaKey) onSubmit()\n }\n },\n [onCancel, onSubmit],\n )\n\n const onKeyDownWithoutSubmit = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\") return\n\n ev.preventDefault()\n onCancel()\n },\n [onCancel],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent) => {\n if (!isEditing) return\n\n const ownerDocument = ev.currentTarget.ownerDocument\n const relatedTarget = (ev.relatedTarget ??\n ownerDocument.activeElement) as HTMLElement\n const targetIsCancel = isContains(cancelRef.current, relatedTarget)\n const targetIsSubmit = isContains(submitRef.current, relatedTarget)\n const isValidBlur = !targetIsCancel && !targetIsSubmit\n\n if (!isValidBlur) return\n\n if (submitOnBlur) {\n onSubmit()\n } else {\n onCancel()\n }\n },\n [isEditing, submitOnBlur, onSubmit, onCancel],\n )\n\n const getPreviewProps: PropGetter<\"span\"> = useCallback(\n (props = {}, ref = null) => ({\n ...props,\n ref: mergeRefs(ref, previewRef),\n children: isValueEmpty ? placeholder : value,\n hidden: isEditing,\n tabIndex: isInteractive && isPreviewFocusable ? 0 : undefined,\n onFocus: handlerAll(props.onFocus, onEdit, onUpdatePrevValue),\n }),\n [\n isEditing,\n isInteractive,\n isPreviewFocusable,\n isValueEmpty,\n onEdit,\n onUpdatePrevValue,\n placeholder,\n value,\n ],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n id,\n ref: mergeRefs(ref, inputRef),\n disabled,\n hidden: !isEditing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n disabled,\n id,\n isEditing,\n onBlur,\n onChange,\n onKeyDown,\n onUpdatePrevValue,\n placeholder,\n readOnly,\n required,\n formControlProps,\n value,\n ],\n )\n\n const getTextareaProps: PropGetter<\"textarea\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n id,\n ref: mergeRefs(ref, inputRef),\n disabled,\n hidden: !isEditing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDownWithoutSubmit),\n }),\n [\n disabled,\n id,\n isEditing,\n onBlur,\n onChange,\n onKeyDownWithoutSubmit,\n onUpdatePrevValue,\n placeholder,\n readOnly,\n required,\n formControlProps,\n value,\n ],\n )\n\n const getEditProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(ref, editRef),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onEdit),\n }),\n [disabled, onEdit, readOnly, formControlProps],\n )\n\n const getSubmitProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(submitRef, ref),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onSubmit),\n }),\n [disabled, onSubmit, readOnly, formControlProps],\n )\n\n const getCancelProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(cancelRef, ref),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onCancel),\n }),\n [disabled, onCancel, readOnly, formControlProps],\n )\n\n return {\n isEditing,\n value,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n onCancel,\n onEdit,\n onSubmit,\n }\n}\n\nexport type UseEditableReturn = ReturnType<typeof useEditable>\n\nexport const useEditableControl = () => {\n const { isEditing, getCancelProps, getEditProps, getSubmitProps } =\n useEditableContext()\n\n return { isEditing, getCancelProps, getEditProps, getSubmitProps }\n}\n\ninterface EditableContext {\n isEditing: boolean\n styles: { [key: string]: CSSUIObject | undefined }\n getCancelProps: PropGetter<\"button\">\n getEditProps: PropGetter<\"button\">\n getInputProps: PropGetter<\"input\">\n getPreviewProps: PropGetter<\"span\">\n getSubmitProps: PropGetter<\"button\">\n getTextareaProps: PropGetter<\"textarea\">\n}\n\nconst [EditableProvider, useEditableContext] = createContext<EditableContext>({\n name: \"EditableContext\",\n errorMessage:\n \"useEditableContext: context is undefined. Seems you forgot to wrap the editable components in `<Editable />`\",\n})\n\ninterface EditableElementProps\n extends Pick<\n UseEditableReturn,\n \"isEditing\" | \"onCancel\" | \"onEdit\" | \"onSubmit\"\n > {}\n\ntype EditableElement = (props: EditableElementProps) => ReactNode\n\ninterface EditableOptions {\n children?: EditableElement | ReactNode\n /**\n * The border color when the input is invalid.\n */\n errorBorderColor?: ColorModeToken<CSS.Property.BorderColor, \"colors\">\n /**\n * The border color when the input is focused.\n */\n focusBorderColor?: ColorModeToken<CSS.Property.BorderColor, \"colors\">\n}\n\nexport interface EditableProps\n extends Omit<\n HTMLUIProps,\n \"children\" | \"defaultValue\" | \"onChange\" | \"onSubmit\" | \"value\"\n >,\n ThemeProps<\"Editable\">,\n UseEditableProps,\n EditableOptions {}\n\n/**\n * `Editable` is a component used to obtain inline editable text input.\n *\n * @see Docs https://yamada-ui.com/components/forms/editable\n */\nexport const Editable = forwardRef<EditableProps, \"div\">(\n ({ errorBorderColor, focusBorderColor, ...props }, ref) => {\n const [styles, mergedProps] = useComponentMultiStyle(\"Editable\", {\n errorBorderColor,\n focusBorderColor,\n ...props,\n })\n const {\n className,\n children,\n defaultValue,\n isDisabled,\n isInvalid,\n isPreviewFocusable,\n isReadOnly,\n isRequired,\n placeholder,\n selectAllOnFocus,\n startWithEditView,\n submitOnBlur,\n value,\n onCancel: onCancelProp,\n onChange,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n ...rest\n } = omitThemeProps(mergedProps)\n const {\n isEditing,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n onCancel,\n onEdit,\n onSubmit,\n } = useEditable({\n defaultValue,\n isDisabled,\n isInvalid,\n isPreviewFocusable,\n isReadOnly,\n isRequired,\n placeholder,\n selectAllOnFocus,\n startWithEditView,\n submitOnBlur,\n value,\n onCancel: onCancelProp,\n onChange,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n })\n\n const cloneChildren = runIfFunc(children, {\n isEditing,\n onCancel,\n onEdit,\n onSubmit,\n })\n\n const css: CSSUIObject = { ...styles.container }\n\n return (\n <EditableProvider\n value={{\n isEditing,\n styles,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n }}\n >\n <ui.div\n ref={ref}\n className={cx(\"ui-editable\", className)}\n {...rest}\n __css={css}\n >\n {cloneChildren}\n </ui.div>\n </EditableProvider>\n )\n },\n)\n\nEditable.displayName = \"Editable\"\nEditable.__ui__ = \"Editable\"\n\nexport interface EditablePreviewProps extends HTMLUIProps<\"span\"> {}\n\nexport const EditablePreview = forwardRef<EditablePreviewProps, \"span\">(\n ({ className, ...rest }, ref) => {\n const { styles, getPreviewProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n cursor: \"text\",\n display: \"inline-block\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n textAlign: \"inherit\",\n ...styles.preview,\n }\n\n return (\n <ui.span\n className={cx(\"ui-editable__preview\", className)}\n {...getPreviewProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditablePreview.displayName = \"EditablePreview\"\nEditablePreview.__ui__ = \"EditablePreview\"\n\nexport interface EditableInputProps extends HTMLUIProps<\"input\"> {}\n\nexport const EditableInput = forwardRef<EditableInputProps, \"input\">(\n ({ className, ...rest }, ref) => {\n const { styles, getInputProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n outline: 0,\n textAlign: \"inherit\",\n ...styles.input,\n }\n\n return (\n <ui.input\n className={cx(\"ui-editable__input\", className)}\n {...getInputProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditableInput.displayName = \"EditableInput\"\nEditableInput.__ui__ = \"EditableInput\"\n\nexport interface EditableTextareaProps extends HTMLUIProps<\"textarea\"> {}\n\nexport const EditableTextarea = forwardRef<EditableTextareaProps, \"textarea\">(\n ({ className, ...rest }, ref) => {\n const { styles, getTextareaProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n outline: 0,\n textAlign: \"inherit\",\n ...styles.textarea,\n }\n\n return (\n <ui.textarea\n className={cx(\"ui-editable__textarea\", className)}\n {...getTextareaProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditableTextarea.displayName = \"EditableTextarea\"\nEditableTextarea.__ui__ = \"EditableTextarea\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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QAC/C,GAAG,iBAAiB,MAAM,GAAG;AAAA,QAC9B,OAAO;AAAA;AAAA,IACT;AAAA,EAEJ;AACF;AAEA,iBAAiB,cAAc;AAC/B,iBAAiB,SAAS;","names":["props"]}
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/editable.tsx"],"sourcesContent":["export {\n Editable,\n EditableInput,\n EditablePreview,\n EditableTextarea,\n useEditable,\n useEditableControl,\n} from \"./editable\"\nexport type {\n EditableInputProps,\n EditablePreviewProps,\n EditableProps,\n EditableTextareaProps,\n UseEditableProps,\n UseEditableReturn,\n} from \"./editable\"\n","import type {\n ColorModeToken,\n CSS,\n CSSUIObject,\n HTMLUIProps,\n PropGetter,\n ThemeProps,\n} from \"@yamada-ui/core\"\nimport type { FormControlOptions } from \"@yamada-ui/form-control\"\nimport type { ChangeEvent, FocusEvent, KeyboardEvent, ReactNode } from \"react\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentMultiStyle,\n} from \"@yamada-ui/core\"\nimport {\n formControlProperties,\n useFormControlProps,\n} from \"@yamada-ui/form-control\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useFocusOnPointerDown } from \"@yamada-ui/use-focus\"\nimport {\n createContext,\n cx,\n handlerAll,\n isContains,\n mergeRefs,\n pickObject,\n runIfFunc,\n useCallbackRef,\n useSafeLayoutEffect,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\n\nexport interface UseEditableProps extends FormControlOptions {\n /**\n * The initial value of the Editable in both edit & preview mode.\n */\n defaultValue?: string\n /**\n * If `true`, the read only view, has a `tabIndex` set to `0`\n * so it can receive focus via the keyboard or click.\n *\n * @default true\n *\n * @deprecated Use `previewFocusable` instead.\n */\n isPreviewFocusable?: boolean\n /**\n * The placeholder text when the value is empty.\n */\n placeholder?: string\n /**\n * If `true`, the read only view, has a `tabIndex` set to `0`\n * so it can receive focus via the keyboard or click.\n *\n * @default true\n */\n previewFocusable?: boolean\n /**\n * If `true`, the input's text will be highlighted on focus.\n *\n * @default true\n */\n selectAllOnFocus?: boolean\n /**\n * If `true`, the Editable will start with edit mode by default.\n */\n startWithEditView?: boolean\n /**\n * If `true`, it'll update the value onBlur and turn off the edit mode.\n *\n * @default true\n */\n submitOnBlur?: boolean\n /**\n * The value of the Editable in both edit & preview mode.\n */\n value?: string\n /**\n * Callback invoked when user cancels input with the `Esc` key.\n * It provides the last confirmed value as argument.\n */\n onCancel?: (preValue: string) => void\n /**\n * A callback invoked when user changes input.\n */\n onChange?: (value: string) => void\n /**\n * A callback invoked once the user enters edit mode.\n */\n onEdit?: () => void\n /**\n * A callback invoked when user confirms value with `enter` key or by blurring input.\n */\n onSubmit?: (value: string) => void\n}\n\nexport const useEditable = (props: UseEditableProps) => {\n let {\n id,\n defaultValue,\n isPreviewFocusable = true,\n placeholder,\n previewFocusable,\n selectAllOnFocus = true,\n startWithEditView,\n submitOnBlur = true,\n value: valueProp,\n onCancel: onCancelProp,\n onChange: onChangeProp,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n ...rest\n } = useFormControlProps(props)\n\n previewFocusable ??= isPreviewFocusable\n\n const onEditRef = useCallbackRef(onEditProp)\n const { disabled, readOnly, required, ...formControlProps } = pickObject(\n rest,\n formControlProperties,\n )\n\n const [editing, setEditing] = useState<boolean>(\n !!startWithEditView && !disabled,\n )\n\n const [value, setValue] = useControllableState({\n defaultValue: defaultValue || \"\",\n value: valueProp,\n onChange: onChangeProp,\n })\n\n const interactive = !editing && !disabled\n const emptyValue = value.length === 0\n\n const [prevValue, setPrevValue] = useState(value)\n\n const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null)\n const previewRef = useRef<HTMLElement>(null)\n const editRef = useRef<HTMLButtonElement>(null)\n const cancelRef = useRef<HTMLButtonElement>(null)\n const submitRef = useRef<HTMLButtonElement>(null)\n\n useFocusOnPointerDown({\n ref: inputRef,\n elements: [cancelRef, submitRef],\n enabled: editing,\n })\n\n useSafeLayoutEffect(() => {\n if (!editing) return\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n }, [])\n\n useUpdateEffect(() => {\n if (!editing) {\n editRef.current?.focus()\n\n return\n }\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n\n onEditRef()\n }, [editing, onEditRef, selectAllOnFocus])\n\n useEffect(() => {\n if (editing) return\n\n const el = inputRef.current\n const activeEl = el?.ownerDocument.activeElement\n\n if (activeEl === el) el?.blur()\n }, [editing])\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) =>\n setValue(ev.currentTarget.value),\n [setValue],\n )\n\n const onUpdatePrevValue = useCallback(() => setPrevValue(value), [value])\n\n const onEdit = useCallback(() => {\n if (interactive) setEditing(true)\n }, [interactive])\n\n const onCancel = useCallback(() => {\n setEditing(false)\n setValue(prevValue)\n onCancelProp?.(prevValue)\n }, [prevValue, onCancelProp, setValue])\n\n const onSubmit = useCallback(() => {\n setEditing(false)\n setPrevValue(value)\n onSubmitProp?.(value)\n }, [onSubmitProp, value])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\" && ev.key !== \"Enter\") return\n\n ev.preventDefault()\n\n if (ev.key === \"Escape\") {\n onCancel()\n } else {\n const { metaKey, shiftKey } = ev\n\n if (!shiftKey && !metaKey) onSubmit()\n }\n },\n [onCancel, onSubmit],\n )\n\n const onKeyDownWithoutSubmit = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\") return\n\n ev.preventDefault()\n onCancel()\n },\n [onCancel],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent) => {\n if (!editing) return\n\n const ownerDocument = ev.currentTarget.ownerDocument\n const relatedTarget = (ev.relatedTarget ??\n ownerDocument.activeElement) as HTMLElement\n const targetIsCancel = isContains(cancelRef.current, relatedTarget)\n const targetIsSubmit = isContains(submitRef.current, relatedTarget)\n const isValidBlur = !targetIsCancel && !targetIsSubmit\n\n if (!isValidBlur) return\n\n if (submitOnBlur) {\n onSubmit()\n } else {\n onCancel()\n }\n },\n [editing, submitOnBlur, onSubmit, onCancel],\n )\n\n const getPreviewProps: PropGetter<\"span\"> = useCallback(\n (props = {}, ref = null) => ({\n ...props,\n ref: mergeRefs(ref, previewRef),\n children: emptyValue ? placeholder : value,\n hidden: editing,\n tabIndex: interactive && previewFocusable ? 0 : undefined,\n onFocus: handlerAll(props.onFocus, onEdit, onUpdatePrevValue),\n }),\n [\n editing,\n interactive,\n previewFocusable,\n emptyValue,\n onEdit,\n onUpdatePrevValue,\n placeholder,\n value,\n ],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n id,\n ref: mergeRefs(ref, inputRef),\n disabled,\n hidden: !editing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n disabled,\n id,\n editing,\n onBlur,\n onChange,\n onKeyDown,\n onUpdatePrevValue,\n placeholder,\n readOnly,\n required,\n formControlProps,\n value,\n ],\n )\n\n const getTextareaProps: PropGetter<\"textarea\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n id,\n ref: mergeRefs(ref, inputRef),\n disabled,\n hidden: !editing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDownWithoutSubmit),\n }),\n [\n disabled,\n id,\n editing,\n onBlur,\n onChange,\n onKeyDownWithoutSubmit,\n onUpdatePrevValue,\n placeholder,\n readOnly,\n required,\n formControlProps,\n value,\n ],\n )\n\n const getEditProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(ref, editRef),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onEdit),\n }),\n [disabled, onEdit, readOnly, formControlProps],\n )\n\n const getSubmitProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(submitRef, ref),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onSubmit),\n }),\n [disabled, onSubmit, readOnly, formControlProps],\n )\n\n const getCancelProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(cancelRef, ref),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onCancel),\n }),\n [disabled, onCancel, readOnly, formControlProps],\n )\n\n return {\n editing,\n value,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n onCancel,\n onEdit,\n onSubmit,\n }\n}\n\nexport type UseEditableReturn = ReturnType<typeof useEditable>\n\nexport const useEditableControl = () => {\n const { editing, getCancelProps, getEditProps, getSubmitProps } =\n useEditableContext()\n\n return {\n editing,\n /**\n * @deprecated Use `editing` instead.\n */\n isEditing: editing,\n getCancelProps,\n getEditProps,\n getSubmitProps,\n }\n}\n\ninterface EditableContext {\n editing: boolean\n styles: { [key: string]: CSSUIObject | undefined }\n getCancelProps: PropGetter<\"button\">\n getEditProps: PropGetter<\"button\">\n getInputProps: PropGetter<\"input\">\n getPreviewProps: PropGetter<\"span\">\n getSubmitProps: PropGetter<\"button\">\n getTextareaProps: PropGetter<\"textarea\">\n}\n\nconst [EditableProvider, useEditableContext] = createContext<EditableContext>({\n name: \"EditableContext\",\n errorMessage:\n \"useEditableContext: context is undefined. Seems you forgot to wrap the editable components in `<Editable />`\",\n})\n\ninterface EditableElementProps\n extends Pick<\n UseEditableReturn,\n \"editing\" | \"onCancel\" | \"onEdit\" | \"onSubmit\"\n > {}\n\ntype EditableElement = (props: EditableElementProps) => ReactNode\n\ninterface EditableOptions {\n children?: EditableElement | ReactNode\n /**\n * The border color when the input is invalid.\n */\n errorBorderColor?: ColorModeToken<CSS.Property.BorderColor, \"colors\">\n /**\n * The border color when the input is focused.\n */\n focusBorderColor?: ColorModeToken<CSS.Property.BorderColor, \"colors\">\n}\n\nexport interface EditableProps\n extends Omit<\n HTMLUIProps,\n \"children\" | \"defaultValue\" | \"onChange\" | \"onSubmit\" | \"value\"\n >,\n ThemeProps<\"Editable\">,\n UseEditableProps,\n EditableOptions {}\n\n/**\n * `Editable` is a component used to obtain inline editable text input.\n *\n * @see Docs https://yamada-ui.com/components/forms/editable\n */\nexport const Editable = forwardRef<EditableProps, \"div\">(\n ({ errorBorderColor, focusBorderColor, ...props }, ref) => {\n const [styles, mergedProps] = useComponentMultiStyle(\"Editable\", {\n errorBorderColor,\n focusBorderColor,\n ...props,\n })\n let {\n className,\n children,\n defaultValue,\n isDisabled,\n isInvalid,\n isPreviewFocusable,\n isReadOnly,\n isRequired,\n placeholder,\n previewFocusable,\n selectAllOnFocus,\n startWithEditView,\n submitOnBlur,\n value,\n onCancel: onCancelProp,\n onChange,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n ...rest\n } = omitThemeProps(mergedProps)\n\n previewFocusable ??= isPreviewFocusable\n\n const {\n editing,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n onCancel,\n onEdit,\n onSubmit,\n } = useEditable({\n defaultValue,\n isDisabled,\n isInvalid,\n isPreviewFocusable,\n isReadOnly,\n isRequired,\n placeholder,\n selectAllOnFocus,\n startWithEditView,\n submitOnBlur,\n value,\n onCancel: onCancelProp,\n onChange,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n })\n\n const cloneChildren = runIfFunc(children, {\n editing,\n onCancel,\n onEdit,\n onSubmit,\n })\n\n const css: CSSUIObject = { ...styles.container }\n\n return (\n <EditableProvider\n value={{\n editing,\n styles,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n }}\n >\n <ui.div\n ref={ref}\n className={cx(\"ui-editable\", className)}\n {...rest}\n __css={css}\n >\n {cloneChildren}\n </ui.div>\n </EditableProvider>\n )\n },\n)\n\nEditable.displayName = \"Editable\"\nEditable.__ui__ = \"Editable\"\n\nexport interface EditablePreviewProps extends HTMLUIProps<\"span\"> {}\n\nexport const EditablePreview = forwardRef<EditablePreviewProps, \"span\">(\n ({ className, ...rest }, ref) => {\n const { styles, getPreviewProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n cursor: \"text\",\n display: \"inline-block\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n textAlign: \"inherit\",\n ...styles.preview,\n }\n\n return (\n <ui.span\n className={cx(\"ui-editable__preview\", className)}\n {...getPreviewProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditablePreview.displayName = \"EditablePreview\"\nEditablePreview.__ui__ = \"EditablePreview\"\n\nexport interface EditableInputProps extends HTMLUIProps<\"input\"> {}\n\nexport const EditableInput = forwardRef<EditableInputProps, \"input\">(\n ({ className, ...rest }, ref) => {\n const { styles, getInputProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n outline: 0,\n textAlign: \"inherit\",\n ...styles.input,\n }\n\n return (\n <ui.input\n className={cx(\"ui-editable__input\", className)}\n {...getInputProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditableInput.displayName = \"EditableInput\"\nEditableInput.__ui__ = \"EditableInput\"\n\nexport interface EditableTextareaProps extends HTMLUIProps<\"textarea\"> {}\n\nexport const EditableTextarea = forwardRef<EditableTextareaProps, \"textarea\">(\n ({ className, ...rest }, ref) => {\n const { styles, getTextareaProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n outline: 0,\n textAlign: \"inherit\",\n ...styles.textarea,\n }\n\n return (\n <ui.textarea\n className={cx(\"ui-editable__textarea\", className)}\n {...getTextareaProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditableTextarea.displayName = \"EditableTextarea\"\nEditableTextarea.__ui__ = \"EditableTextarea\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUA,kBAKO;AACP,0BAGO;AACP,oCAAqC;AACrC,uBAAsC;AACtC,mBAWO;AACP,mBAAyD;AAmgBjD;AAjcD,IAAM,cAAc,CAAC,UAA4B;AACtD,MAAI;AAAA,IACF;AAAA,IACA;AAAA,IACA,qBAAqB;AAAA,IACrB;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,IACnB;AAAA,IACA,eAAe;AAAA,IACf,OAAO;AAAA,IACP,UAAU;AAAA,IACV,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,GAAG;AAAA,EACL,QAAI,yCAAoB,KAAK;AAE7B,mEAAqB;AAErB,QAAM,gBAAY,6BAAe,UAAU;AAC3C,QAAM,EAAE,UAAU,UAAU,UAAU,GAAG,iBAAiB,QAAI;AAAA,IAC5D;AAAA,IACA;AAAA,EACF;AAEA,QAAM,CAAC,SAAS,UAAU,QAAI;AAAA,IAC5B,CAAC,CAAC,qBAAqB,CAAC;AAAA,EAC1B;AAEA,QAAM,CAAC,OAAO,QAAQ,QAAI,oDAAqB;AAAA,IAC7C,cAAc,gBAAgB;AAAA,IAC9B,OAAO;AAAA,IACP,UAAU;AAAA,EACZ,CAAC;AAED,QAAM,cAAc,CAAC,WAAW,CAAC;AACjC,QAAM,aAAa,MAAM,WAAW;AAEpC,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAEhD,QAAM,eAAW,qBAA+C,IAAI;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3B,OAAO;AAAA;AAAA,IACT;AAAA,EAEJ;AACF;AAEA,cAAc,cAAc;AAC5B,cAAc,SAAS;AAIhB,IAAM,uBAAmB;AAAA,EAC9B,CAAC,EAAE,WAAW,GAAG,KAAK,GAAG,QAAQ;AAC/B,UAAM,EAAE,QAAQ,iBAAiB,IAAI,mBAAmB;AAExD,UAAM,MAAmB;AAAA,MACvB,IAAI;AAAA,MACJ,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,SAAS;AAAA,MACT,WAAW;AAAA,MACX,GAAG,OAAO;AAAA,IACZ;AAEA,WACE;AAAA,MAAC,eAAG;AAAA,MAAH;AAAA,QACC,eAAW,iBAAG,yBAAyB,SAAS;AAAA,QAC/C,GAAG,iBAAiB,MAAM,GAAG;AAAA,QAC9B,OAAO;AAAA;AAAA,IACT;AAAA,EAEJ;AACF;AAEA,iBAAiB,cAAc;AAC/B,iBAAiB,SAAS;","names":["props"]}
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@yamada-ui/editable",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.49-dev-20241123043353",
|
4
4
|
"description": "Yamada UI editable component",
|
5
5
|
"keywords": [
|
6
6
|
"yamada",
|
@@ -36,8 +36,8 @@
|
|
36
36
|
"url": "https://github.com/yamada-ui/yamada-ui/issues"
|
37
37
|
},
|
38
38
|
"dependencies": {
|
39
|
-
"@yamada-ui/core": "1.15.5
|
40
|
-
"@yamada-ui/form-control": "2.1.7
|
39
|
+
"@yamada-ui/core": "1.15.5",
|
40
|
+
"@yamada-ui/form-control": "2.1.7",
|
41
41
|
"@yamada-ui/use-controllable-state": "1.0.23",
|
42
42
|
"@yamada-ui/use-focus": "1.0.24",
|
43
43
|
"@yamada-ui/utils": "1.5.4"
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/editable.tsx"],"sourcesContent":["import type {\n ColorModeToken,\n CSS,\n CSSUIObject,\n HTMLUIProps,\n PropGetter,\n ThemeProps,\n} from \"@yamada-ui/core\"\nimport type { FormControlOptions } from \"@yamada-ui/form-control\"\nimport type { ChangeEvent, FocusEvent, KeyboardEvent, ReactNode } from \"react\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentMultiStyle,\n} from \"@yamada-ui/core\"\nimport {\n formControlProperties,\n useFormControlProps,\n} from \"@yamada-ui/form-control\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useFocusOnPointerDown } from \"@yamada-ui/use-focus\"\nimport {\n createContext,\n cx,\n handlerAll,\n isContains,\n mergeRefs,\n pickObject,\n runIfFunc,\n useCallbackRef,\n useSafeLayoutEffect,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\n\nexport interface UseEditableProps extends FormControlOptions {\n /**\n * The initial value of the Editable in both edit & preview mode.\n */\n defaultValue?: string\n /**\n * If `true`, the read only view, has a `tabIndex` set to `0`\n * so it can receive focus via the keyboard or click.\n *\n * @default true\n */\n isPreviewFocusable?: boolean\n /**\n * The placeholder text when the value is empty.\n */\n placeholder?: string\n /**\n * If `true`, the input's text will be highlighted on focus.\n *\n * @default true\n */\n selectAllOnFocus?: boolean\n /**\n * If `true`, the Editable will start with edit mode by default.\n */\n startWithEditView?: boolean\n /**\n * If `true`, it'll update the value onBlur and turn off the edit mode.\n *\n * @default true\n */\n submitOnBlur?: boolean\n /**\n * The value of the Editable in both edit & preview mode.\n */\n value?: string\n /**\n * Callback invoked when user cancels input with the `Esc` key.\n * It provides the last confirmed value as argument.\n */\n onCancel?: (preValue: string) => void\n /**\n * A callback invoked when user changes input.\n */\n onChange?: (value: string) => void\n /**\n * A callback invoked once the user enters edit mode.\n */\n onEdit?: () => void\n /**\n * A callback invoked when user confirms value with `enter` key or by blurring input.\n */\n onSubmit?: (value: string) => void\n}\n\nexport const useEditable = (props: UseEditableProps) => {\n const {\n id,\n defaultValue,\n isPreviewFocusable = true,\n placeholder,\n selectAllOnFocus = true,\n startWithEditView,\n submitOnBlur = true,\n value: valueProp,\n onCancel: onCancelProp,\n onChange: onChangeProp,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n ...rest\n } = useFormControlProps(props)\n const onEditRef = useCallbackRef(onEditProp)\n const { disabled, readOnly, required, ...formControlProps } = pickObject(\n rest,\n formControlProperties,\n )\n\n const [isEditing, setIsEditing] = useState<boolean>(\n !!startWithEditView && !disabled,\n )\n\n const [value, setValue] = useControllableState({\n defaultValue: defaultValue || \"\",\n value: valueProp,\n onChange: onChangeProp,\n })\n\n const isInteractive = !isEditing && !disabled\n const isValueEmpty = value.length === 0\n\n const [prevValue, setPrevValue] = useState(value)\n\n const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null)\n const previewRef = useRef<HTMLElement>(null)\n const editRef = useRef<HTMLButtonElement>(null)\n const cancelRef = useRef<HTMLButtonElement>(null)\n const submitRef = useRef<HTMLButtonElement>(null)\n\n useFocusOnPointerDown({\n ref: inputRef,\n elements: [cancelRef, submitRef],\n enabled: isEditing,\n })\n\n useSafeLayoutEffect(() => {\n if (!isEditing) return\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n }, [])\n\n useUpdateEffect(() => {\n if (!isEditing) {\n editRef.current?.focus()\n\n return\n }\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n\n onEditRef()\n }, [isEditing, onEditRef, selectAllOnFocus])\n\n useEffect(() => {\n if (isEditing) return\n\n const el = inputRef.current\n const activeEl = el?.ownerDocument.activeElement\n\n if (activeEl === el) el?.blur()\n }, [isEditing])\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) =>\n setValue(ev.currentTarget.value),\n [setValue],\n )\n\n const onUpdatePrevValue = useCallback(() => setPrevValue(value), [value])\n\n const onEdit = useCallback(() => {\n if (isInteractive) setIsEditing(true)\n }, [isInteractive])\n\n const onCancel = useCallback(() => {\n setIsEditing(false)\n setValue(prevValue)\n onCancelProp?.(prevValue)\n }, [prevValue, onCancelProp, setValue])\n\n const onSubmit = useCallback(() => {\n setIsEditing(false)\n setPrevValue(value)\n onSubmitProp?.(value)\n }, [onSubmitProp, value])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\" && ev.key !== \"Enter\") return\n\n ev.preventDefault()\n\n if (ev.key === \"Escape\") {\n onCancel()\n } else {\n const { metaKey, shiftKey } = ev\n\n if (!shiftKey && !metaKey) onSubmit()\n }\n },\n [onCancel, onSubmit],\n )\n\n const onKeyDownWithoutSubmit = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\") return\n\n ev.preventDefault()\n onCancel()\n },\n [onCancel],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent) => {\n if (!isEditing) return\n\n const ownerDocument = ev.currentTarget.ownerDocument\n const relatedTarget = (ev.relatedTarget ??\n ownerDocument.activeElement) as HTMLElement\n const targetIsCancel = isContains(cancelRef.current, relatedTarget)\n const targetIsSubmit = isContains(submitRef.current, relatedTarget)\n const isValidBlur = !targetIsCancel && !targetIsSubmit\n\n if (!isValidBlur) return\n\n if (submitOnBlur) {\n onSubmit()\n } else {\n onCancel()\n }\n },\n [isEditing, submitOnBlur, onSubmit, onCancel],\n )\n\n const getPreviewProps: PropGetter<\"span\"> = useCallback(\n (props = {}, ref = null) => ({\n ...props,\n ref: mergeRefs(ref, previewRef),\n children: isValueEmpty ? placeholder : value,\n hidden: isEditing,\n tabIndex: isInteractive && isPreviewFocusable ? 0 : undefined,\n onFocus: handlerAll(props.onFocus, onEdit, onUpdatePrevValue),\n }),\n [\n isEditing,\n isInteractive,\n isPreviewFocusable,\n isValueEmpty,\n onEdit,\n onUpdatePrevValue,\n placeholder,\n value,\n ],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n id,\n ref: mergeRefs(ref, inputRef),\n disabled,\n hidden: !isEditing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n disabled,\n id,\n isEditing,\n onBlur,\n onChange,\n onKeyDown,\n onUpdatePrevValue,\n placeholder,\n readOnly,\n required,\n formControlProps,\n value,\n ],\n )\n\n const getTextareaProps: PropGetter<\"textarea\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n id,\n ref: mergeRefs(ref, inputRef),\n disabled,\n hidden: !isEditing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDownWithoutSubmit),\n }),\n [\n disabled,\n id,\n isEditing,\n onBlur,\n onChange,\n onKeyDownWithoutSubmit,\n onUpdatePrevValue,\n placeholder,\n readOnly,\n required,\n formControlProps,\n value,\n ],\n )\n\n const getEditProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(ref, editRef),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onEdit),\n }),\n [disabled, onEdit, readOnly, formControlProps],\n )\n\n const getSubmitProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(submitRef, ref),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onSubmit),\n }),\n [disabled, onSubmit, readOnly, formControlProps],\n )\n\n const getCancelProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...formControlProps,\n ...props,\n ref: mergeRefs(cancelRef, ref),\n type: \"button\",\n disabled,\n readOnly,\n onClick: handlerAll(props.onClick, onCancel),\n }),\n [disabled, onCancel, readOnly, formControlProps],\n )\n\n return {\n isEditing,\n value,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n onCancel,\n onEdit,\n onSubmit,\n }\n}\n\nexport type UseEditableReturn = ReturnType<typeof useEditable>\n\nexport const useEditableControl = () => {\n const { isEditing, getCancelProps, getEditProps, getSubmitProps } =\n useEditableContext()\n\n return { isEditing, getCancelProps, getEditProps, getSubmitProps }\n}\n\ninterface EditableContext {\n isEditing: boolean\n styles: { [key: string]: CSSUIObject | undefined }\n getCancelProps: PropGetter<\"button\">\n getEditProps: PropGetter<\"button\">\n getInputProps: PropGetter<\"input\">\n getPreviewProps: PropGetter<\"span\">\n getSubmitProps: PropGetter<\"button\">\n getTextareaProps: PropGetter<\"textarea\">\n}\n\nconst [EditableProvider, useEditableContext] = createContext<EditableContext>({\n name: \"EditableContext\",\n errorMessage:\n \"useEditableContext: context is undefined. Seems you forgot to wrap the editable components in `<Editable />`\",\n})\n\ninterface EditableElementProps\n extends Pick<\n UseEditableReturn,\n \"isEditing\" | \"onCancel\" | \"onEdit\" | \"onSubmit\"\n > {}\n\ntype EditableElement = (props: EditableElementProps) => ReactNode\n\ninterface EditableOptions {\n children?: EditableElement | ReactNode\n /**\n * The border color when the input is invalid.\n */\n errorBorderColor?: ColorModeToken<CSS.Property.BorderColor, \"colors\">\n /**\n * The border color when the input is focused.\n */\n focusBorderColor?: ColorModeToken<CSS.Property.BorderColor, \"colors\">\n}\n\nexport interface EditableProps\n extends Omit<\n HTMLUIProps,\n \"children\" | \"defaultValue\" | \"onChange\" | \"onSubmit\" | \"value\"\n >,\n ThemeProps<\"Editable\">,\n UseEditableProps,\n EditableOptions {}\n\n/**\n * `Editable` is a component used to obtain inline editable text input.\n *\n * @see Docs https://yamada-ui.com/components/forms/editable\n */\nexport const Editable = forwardRef<EditableProps, \"div\">(\n ({ errorBorderColor, focusBorderColor, ...props }, ref) => {\n const [styles, mergedProps] = useComponentMultiStyle(\"Editable\", {\n errorBorderColor,\n focusBorderColor,\n ...props,\n })\n const {\n className,\n children,\n defaultValue,\n isDisabled,\n isInvalid,\n isPreviewFocusable,\n isReadOnly,\n isRequired,\n placeholder,\n selectAllOnFocus,\n startWithEditView,\n submitOnBlur,\n value,\n onCancel: onCancelProp,\n onChange,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n ...rest\n } = omitThemeProps(mergedProps)\n const {\n isEditing,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n onCancel,\n onEdit,\n onSubmit,\n } = useEditable({\n defaultValue,\n isDisabled,\n isInvalid,\n isPreviewFocusable,\n isReadOnly,\n isRequired,\n placeholder,\n selectAllOnFocus,\n startWithEditView,\n submitOnBlur,\n value,\n onCancel: onCancelProp,\n onChange,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n })\n\n const cloneChildren = runIfFunc(children, {\n isEditing,\n onCancel,\n onEdit,\n onSubmit,\n })\n\n const css: CSSUIObject = { ...styles.container }\n\n return (\n <EditableProvider\n value={{\n isEditing,\n styles,\n getCancelProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getSubmitProps,\n getTextareaProps,\n }}\n >\n <ui.div\n ref={ref}\n className={cx(\"ui-editable\", className)}\n {...rest}\n __css={css}\n >\n {cloneChildren}\n </ui.div>\n </EditableProvider>\n )\n },\n)\n\nEditable.displayName = \"Editable\"\nEditable.__ui__ = \"Editable\"\n\nexport interface EditablePreviewProps extends HTMLUIProps<\"span\"> {}\n\nexport const EditablePreview = forwardRef<EditablePreviewProps, \"span\">(\n ({ className, ...rest }, ref) => {\n const { styles, getPreviewProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n cursor: \"text\",\n display: \"inline-block\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n textAlign: \"inherit\",\n ...styles.preview,\n }\n\n return (\n <ui.span\n className={cx(\"ui-editable__preview\", className)}\n {...getPreviewProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditablePreview.displayName = \"EditablePreview\"\nEditablePreview.__ui__ = \"EditablePreview\"\n\nexport interface EditableInputProps extends HTMLUIProps<\"input\"> {}\n\nexport const EditableInput = forwardRef<EditableInputProps, \"input\">(\n ({ className, ...rest }, ref) => {\n const { styles, getInputProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n outline: 0,\n textAlign: \"inherit\",\n ...styles.input,\n }\n\n return (\n <ui.input\n className={cx(\"ui-editable__input\", className)}\n {...getInputProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditableInput.displayName = \"EditableInput\"\nEditableInput.__ui__ = \"EditableInput\"\n\nexport interface EditableTextareaProps extends HTMLUIProps<\"textarea\"> {}\n\nexport const EditableTextarea = forwardRef<EditableTextareaProps, \"textarea\">(\n ({ className, ...rest }, ref) => {\n const { styles, getTextareaProps } = useEditableContext()\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n fontSize: \"inherit\",\n fontWeight: \"inherit\",\n outline: 0,\n textAlign: \"inherit\",\n ...styles.textarea,\n }\n\n return (\n <ui.textarea\n className={cx(\"ui-editable__textarea\", className)}\n {...getTextareaProps(rest, ref)}\n __css={css}\n />\n )\n },\n)\n\nEditableTextarea.displayName = \"EditableTextarea\"\nEditableTextarea.__ui__ = \"EditableTextarea\"\n"],"mappings":";;;AAUA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,4BAA4B;AACrC,SAAS,6BAA6B;AACtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa,WAAW,QAAQ,gBAA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