@uipath/apollo-react 7.11.1 → 7.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/components/NodePropertyPanel/EditableText.cjs +4 -162
- package/dist/canvas/components/NodePropertyPanel/EditableText.d.ts +3 -16
- package/dist/canvas/components/NodePropertyPanel/EditableText.d.ts.map +1 -1
- package/dist/canvas/components/NodePropertyPanel/EditableText.js +7 -165
- package/dist/canvas/locales/de.cjs +1 -1
- package/dist/canvas/locales/de.d.ts.map +1 -1
- package/dist/canvas/locales/de.js +1 -1
- package/dist/canvas/locales/es-MX.cjs +1 -1
- package/dist/canvas/locales/es-MX.d.ts.map +1 -1
- package/dist/canvas/locales/es-MX.js +1 -1
- package/dist/canvas/locales/es.cjs +1 -1
- package/dist/canvas/locales/es.d.ts.map +1 -1
- package/dist/canvas/locales/es.js +1 -1
- package/dist/canvas/locales/fr.cjs +1 -1
- package/dist/canvas/locales/fr.d.ts.map +1 -1
- package/dist/canvas/locales/fr.js +1 -1
- package/dist/canvas/locales/ja.cjs +1 -1
- package/dist/canvas/locales/ja.d.ts.map +1 -1
- package/dist/canvas/locales/ja.js +1 -1
- package/dist/canvas/locales/ko.cjs +1 -1
- package/dist/canvas/locales/ko.d.ts.map +1 -1
- package/dist/canvas/locales/ko.js +1 -1
- package/dist/canvas/locales/pt-BR.cjs +1 -1
- package/dist/canvas/locales/pt-BR.d.ts.map +1 -1
- package/dist/canvas/locales/pt-BR.js +1 -1
- package/dist/canvas/locales/pt.cjs +1 -1
- package/dist/canvas/locales/pt.d.ts.map +1 -1
- package/dist/canvas/locales/pt.js +1 -1
- package/dist/canvas/locales/ro.cjs +1 -1
- package/dist/canvas/locales/ro.d.ts.map +1 -1
- package/dist/canvas/locales/ro.js +1 -1
- package/dist/canvas/locales/ru.cjs +1 -1
- package/dist/canvas/locales/ru.d.ts.map +1 -1
- package/dist/canvas/locales/ru.js +1 -1
- package/dist/canvas/locales/tr.cjs +1 -1
- package/dist/canvas/locales/tr.d.ts.map +1 -1
- package/dist/canvas/locales/tr.js +1 -1
- package/dist/canvas/locales/zh-CN.cjs +1 -1
- package/dist/canvas/locales/zh-CN.d.ts.map +1 -1
- package/dist/canvas/locales/zh-CN.js +1 -1
- package/dist/canvas/locales/zh-TW.cjs +1 -1
- package/dist/canvas/locales/zh-TW.d.ts.map +1 -1
- package/dist/canvas/locales/zh-TW.js +1 -1
- package/dist/canvas/styles/tailwind.canvas.css +1 -1
- package/dist/chat/headless/providers/attachments-provider.cjs +10 -6
- package/dist/chat/headless/providers/attachments-provider.d.ts.map +1 -1
- package/dist/chat/headless/providers/attachments-provider.js +10 -6
- package/dist/chat/locales/de.cjs +1 -1
- package/dist/chat/locales/de.d.ts.map +1 -1
- package/dist/chat/locales/de.js +1 -1
- package/dist/chat/locales/es-MX.cjs +1 -1
- package/dist/chat/locales/es-MX.d.ts.map +1 -1
- package/dist/chat/locales/es-MX.js +1 -1
- package/dist/chat/locales/es.cjs +1 -1
- package/dist/chat/locales/es.d.ts.map +1 -1
- package/dist/chat/locales/es.js +1 -1
- package/dist/chat/locales/fr.cjs +1 -1
- package/dist/chat/locales/fr.d.ts.map +1 -1
- package/dist/chat/locales/fr.js +1 -1
- package/dist/chat/locales/ja.cjs +1 -1
- package/dist/chat/locales/ja.d.ts.map +1 -1
- package/dist/chat/locales/ja.js +1 -1
- package/dist/chat/locales/ko.cjs +1 -1
- package/dist/chat/locales/ko.d.ts.map +1 -1
- package/dist/chat/locales/ko.js +1 -1
- package/dist/chat/locales/pt-BR.cjs +1 -1
- package/dist/chat/locales/pt-BR.d.ts.map +1 -1
- package/dist/chat/locales/pt-BR.js +1 -1
- package/dist/chat/locales/pt.cjs +1 -1
- package/dist/chat/locales/pt.d.ts.map +1 -1
- package/dist/chat/locales/pt.js +1 -1
- package/dist/chat/locales/ro.cjs +1 -1
- package/dist/chat/locales/ro.d.ts.map +1 -1
- package/dist/chat/locales/ro.js +1 -1
- package/dist/chat/locales/ru.cjs +1 -1
- package/dist/chat/locales/ru.d.ts.map +1 -1
- package/dist/chat/locales/ru.js +1 -1
- package/dist/chat/locales/tr.cjs +1 -1
- package/dist/chat/locales/tr.d.ts.map +1 -1
- package/dist/chat/locales/tr.js +1 -1
- package/dist/chat/locales/zh-CN.cjs +1 -1
- package/dist/chat/locales/zh-CN.d.ts.map +1 -1
- package/dist/chat/locales/zh-CN.js +1 -1
- package/dist/chat/locales/zh-TW.cjs +1 -1
- package/dist/chat/locales/zh-TW.d.ts.map +1 -1
- package/dist/chat/locales/zh-TW.js +1 -1
- package/dist/chat/styles/tailwind.chat.css +1 -1
- package/dist/material/components/ap-chat/components/common/attachments.cjs +2 -1
- package/dist/material/components/ap-chat/components/common/attachments.d.ts.map +1 -1
- package/dist/material/components/ap-chat/components/common/attachments.js +2 -1
- package/dist/material/components/ap-chat/components/input/tiptap/resource-chip-node-view.cjs +2 -2
- package/dist/material/components/ap-chat/components/input/tiptap/resource-chip-node-view.js +2 -2
- package/dist/material/components/ap-model-picker/locales/de.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/de.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/de.js +1 -1
- package/dist/material/components/ap-model-picker/locales/es-MX.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/es-MX.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/es-MX.js +1 -1
- package/dist/material/components/ap-model-picker/locales/es.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/es.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/es.js +1 -1
- package/dist/material/components/ap-model-picker/locales/fr.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/fr.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/fr.js +1 -1
- package/dist/material/components/ap-model-picker/locales/ja.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/ja.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/ja.js +1 -1
- package/dist/material/components/ap-model-picker/locales/ko.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/ko.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/ko.js +1 -1
- package/dist/material/components/ap-model-picker/locales/pt-BR.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/pt-BR.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/pt-BR.js +1 -1
- package/dist/material/components/ap-model-picker/locales/pt.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/pt.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/pt.js +1 -1
- package/dist/material/components/ap-model-picker/locales/ro.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/ro.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/ro.js +1 -1
- package/dist/material/components/ap-model-picker/locales/ru.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/ru.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/ru.js +1 -1
- package/dist/material/components/ap-model-picker/locales/tr.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/tr.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/tr.js +1 -1
- package/dist/material/components/ap-model-picker/locales/zh-CN.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/zh-CN.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/zh-CN.js +1 -1
- package/dist/material/components/ap-model-picker/locales/zh-TW.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/zh-TW.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/zh-TW.js +1 -1
- package/dist/material/components/ap-rich-text-editor/locales/ru.cjs +1 -1
- package/dist/material/components/ap-rich-text-editor/locales/ru.d.ts.map +1 -1
- package/dist/material/components/ap-rich-text-editor/locales/ru.js +1 -1
- package/dist/material/components/ap-tool-call/locales/ru.cjs +1 -1
- package/dist/material/components/ap-tool-call/locales/ru.d.ts.map +1 -1
- package/dist/material/components/ap-tool-call/locales/ru.js +1 -1
- package/package.json +3 -3
|
@@ -28,168 +28,10 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
});
|
|
29
29
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
30
30
|
const apollo_wind_namespaceObject = require("@uipath/apollo-wind");
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const READ_CLASS = {
|
|
36
|
-
lg: 'text-base font-semibold leading-5 tracking-[-0.3px] text-foreground',
|
|
37
|
-
sm: 'text-xs leading-4 text-foreground-muted'
|
|
38
|
-
};
|
|
39
|
-
const EDIT_CLASS = {
|
|
40
|
-
lg: 'text-base font-semibold leading-5 tracking-[-0.3px]',
|
|
41
|
-
sm: 'text-xs leading-4'
|
|
42
|
-
};
|
|
43
|
-
const LINE_HEIGHT = {
|
|
44
|
-
lg: 20,
|
|
45
|
-
sm: 16
|
|
46
|
-
};
|
|
47
|
-
const VERTICAL_PADDING = 4;
|
|
48
|
-
const CLAMP_CLASS = 'line-clamp-[var(--editable-text-lines)] whitespace-pre-line wrap-break-word';
|
|
49
|
-
const INTERACTIVE_CLASS = 'rounded px-1.5 py-0.5 -mx-1.5';
|
|
50
|
-
const ERROR_RING_CLASS = 'ring-1 ring-error';
|
|
51
|
-
function EditableText({ value, placeholder, size = 'lg', multiline, maxLines = 3, onChange, onSubmit, disabled, error, 'aria-label': ariaLabel, className, 'data-testid': dataTestId }) {
|
|
52
|
-
const allowNewlines = true === multiline;
|
|
53
|
-
const editable = !!onChange && !!onSubmit;
|
|
54
|
-
const [isEditing, setIsEditing] = (0, external_react_namespaceObject.useState)(false);
|
|
55
|
-
const inputRef = (0, external_react_namespaceObject.useRef)(null);
|
|
56
|
-
const openedWith = (0, external_react_namespaceObject.useRef)(value);
|
|
57
|
-
const errorId = `editable-text-${(0, external_react_namespaceObject.useId)().replace(/:/g, '')}-error`;
|
|
58
|
-
const hasError = !!error;
|
|
59
|
-
const describedBy = hasError ? errorId : void 0;
|
|
60
|
-
(0, useIsomorphicLayoutEffect_cjs_namespaceObject.useIsomorphicLayoutEffect)(()=>{
|
|
61
|
-
if (disabled) return setIsEditing(false);
|
|
62
|
-
if (!isEditing) return;
|
|
63
|
-
inputRef.current?.focus();
|
|
64
|
-
inputRef.current?.select();
|
|
65
|
-
}, [
|
|
66
|
-
isEditing,
|
|
67
|
-
disabled
|
|
68
|
-
]);
|
|
69
|
-
const commit = (0, external_react_namespaceObject.useCallback)(()=>{
|
|
70
|
-
setIsEditing(false);
|
|
71
|
-
const next = value.trim();
|
|
72
|
-
if (next !== value) onChange?.(next);
|
|
73
|
-
if (next !== openedWith.current) onSubmit?.(next);
|
|
74
|
-
}, [
|
|
75
|
-
value,
|
|
76
|
-
onChange,
|
|
77
|
-
onSubmit
|
|
78
|
-
]);
|
|
79
|
-
const cancel = (0, external_react_namespaceObject.useCallback)(()=>{
|
|
80
|
-
setIsEditing(false);
|
|
81
|
-
if (openedWith.current !== value) onChange?.(openedWith.current);
|
|
82
|
-
}, [
|
|
83
|
-
value,
|
|
84
|
-
onChange
|
|
85
|
-
]);
|
|
86
|
-
const handleKeyDown = (0, external_react_namespaceObject.useCallback)((e)=>{
|
|
87
|
-
if ('Enter' !== e.key || allowNewlines && e.shiftKey) {
|
|
88
|
-
if ('Escape' === e.key) {
|
|
89
|
-
e.preventDefault();
|
|
90
|
-
cancel();
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
e.preventDefault();
|
|
94
|
-
commit();
|
|
95
|
-
}
|
|
96
|
-
e.stopPropagation();
|
|
97
|
-
}, [
|
|
98
|
-
commit,
|
|
99
|
-
cancel,
|
|
100
|
-
allowNewlines
|
|
101
|
-
]);
|
|
102
|
-
const editorMaxHeight = multiline ? {
|
|
103
|
-
maxHeight: maxLines * LINE_HEIGHT[size] + VERTICAL_PADDING
|
|
104
|
-
} : void 0;
|
|
105
|
-
const readClampStyle = multiline ? {
|
|
106
|
-
'--editable-text-lines': maxLines
|
|
107
|
-
} : void 0;
|
|
108
|
-
const readClampClass = multiline ? CLAMP_CLASS : 'block truncate';
|
|
109
|
-
const message = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.FormFieldError, {
|
|
110
|
-
id: errorId,
|
|
111
|
-
"data-slot": "editable-text-error",
|
|
112
|
-
className: "-ml-1 mt-1",
|
|
113
|
-
children: error
|
|
114
|
-
});
|
|
115
|
-
if (!editable) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
116
|
-
children: [
|
|
117
|
-
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_CanvasTooltip_cjs_namespaceObject.CanvasTooltip, {
|
|
118
|
-
content: value || placeholder,
|
|
119
|
-
smartTooltip: true,
|
|
120
|
-
delay: true,
|
|
121
|
-
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
|
|
122
|
-
"data-slot": "editable-text",
|
|
123
|
-
"data-testid": dataTestId,
|
|
124
|
-
"aria-describedby": describedBy,
|
|
125
|
-
style: readClampStyle,
|
|
126
|
-
className: (0, apollo_wind_namespaceObject.cn)(readClampClass, READ_CLASS[size], !value && 'text-foreground-subtle', hasError && (0, apollo_wind_namespaceObject.cn)(INTERACTIVE_CLASS, ERROR_RING_CLASS), className),
|
|
127
|
-
children: value || placeholder
|
|
128
|
-
})
|
|
129
|
-
}),
|
|
130
|
-
message
|
|
131
|
-
]
|
|
132
|
-
});
|
|
133
|
-
if (isEditing && !disabled) {
|
|
134
|
-
const sharedProps = {
|
|
135
|
-
'data-slot': 'editable-text-input',
|
|
136
|
-
'data-testid': dataTestId ? `${dataTestId}-input` : void 0,
|
|
137
|
-
value,
|
|
138
|
-
placeholder,
|
|
139
|
-
'aria-label': ariaLabel,
|
|
140
|
-
'aria-describedby': describedBy,
|
|
141
|
-
'aria-errormessage': hasError ? errorId : void 0,
|
|
142
|
-
'aria-invalid': hasError || void 0,
|
|
143
|
-
onKeyDown: handleKeyDown,
|
|
144
|
-
onBlur: commit,
|
|
145
|
-
className: (0, apollo_wind_namespaceObject.cn)('nodrag nowheel w-full min-w-0 border-none bg-surface-overlay text-foreground outline-none ring-1', hasError ? 'ring-error' : 'ring-brand', INTERACTIVE_CLASS, EDIT_CLASS[size], className)
|
|
146
|
-
};
|
|
147
|
-
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
148
|
-
children: [
|
|
149
|
-
multiline ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("textarea", {
|
|
150
|
-
...sharedProps,
|
|
151
|
-
ref: inputRef,
|
|
152
|
-
rows: 1,
|
|
153
|
-
style: editorMaxHeight,
|
|
154
|
-
className: (0, apollo_wind_namespaceObject.cn)(sharedProps.className, 'field-sizing-content max-w-full resize-none overflow-y-auto wrap-break-word'),
|
|
155
|
-
onChange: (e)=>onChange?.(allowNewlines ? e.target.value : stripNewlines(e.target.value))
|
|
156
|
-
}) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("input", {
|
|
157
|
-
...sharedProps,
|
|
158
|
-
ref: inputRef,
|
|
159
|
-
autoComplete: "off",
|
|
160
|
-
onChange: (e)=>onChange?.(e.target.value)
|
|
161
|
-
}),
|
|
162
|
-
message
|
|
163
|
-
]
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
167
|
-
children: [
|
|
168
|
-
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_CanvasTooltip_cjs_namespaceObject.CanvasTooltip, {
|
|
169
|
-
content: value || placeholder,
|
|
170
|
-
smartTooltip: true,
|
|
171
|
-
delay: true,
|
|
172
|
-
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("button", {
|
|
173
|
-
type: "button",
|
|
174
|
-
"data-slot": "editable-text",
|
|
175
|
-
"data-testid": dataTestId,
|
|
176
|
-
"aria-label": ariaLabel && `${ariaLabel}: ${value || placeholder || ''}`,
|
|
177
|
-
"aria-describedby": describedBy,
|
|
178
|
-
"aria-errormessage": hasError ? errorId : void 0,
|
|
179
|
-
"aria-invalid": hasError || void 0,
|
|
180
|
-
"aria-disabled": disabled || void 0,
|
|
181
|
-
onClick: ()=>{
|
|
182
|
-
if (disabled) return;
|
|
183
|
-
openedWith.current = value;
|
|
184
|
-
setIsEditing(true);
|
|
185
|
-
},
|
|
186
|
-
style: readClampStyle,
|
|
187
|
-
className: (0, apollo_wind_namespaceObject.cn)('nodrag max-w-full cursor-text border-none bg-transparent text-left transition hover:bg-surface-overlay', 'aria-disabled:cursor-not-allowed aria-disabled:opacity-50 aria-disabled:hover:bg-transparent', readClampClass, INTERACTIVE_CLASS, READ_CLASS[size], !value && 'text-foreground-subtle', hasError && ERROR_RING_CLASS, className),
|
|
188
|
-
children: value || placeholder
|
|
189
|
-
})
|
|
190
|
-
}),
|
|
191
|
-
message
|
|
192
|
-
]
|
|
31
|
+
function EditableText({ className, ...props }) {
|
|
32
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.EditableText, {
|
|
33
|
+
...props,
|
|
34
|
+
className: (0, apollo_wind_namespaceObject.cn)('nodrag nowheel', className)
|
|
193
35
|
});
|
|
194
36
|
}
|
|
195
37
|
exports.EditableText = __webpack_exports__.EditableText;
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
placeholder?: string;
|
|
5
|
-
size?: 'sm' | 'lg';
|
|
6
|
-
multiline?: boolean | 'wrap';
|
|
7
|
-
maxLines?: number;
|
|
8
|
-
onChange?: (next: string) => void;
|
|
9
|
-
onSubmit?: (next: string) => void;
|
|
10
|
-
disabled?: boolean;
|
|
11
|
-
error?: ReactNode;
|
|
12
|
-
'aria-label'?: string;
|
|
13
|
-
className?: string;
|
|
14
|
-
'data-testid'?: string;
|
|
15
|
-
}
|
|
16
|
-
export declare function EditableText({ value, placeholder, size, multiline, maxLines, onChange, onSubmit, disabled, error, 'aria-label': ariaLabel, className, 'data-testid': dataTestId, }: EditableTextProps): import("react/jsx-runtime").JSX.Element;
|
|
1
|
+
import { type EditableTextProps } from '@uipath/apollo-wind';
|
|
2
|
+
export type { EditableTextProps };
|
|
3
|
+
export declare function EditableText({ className, ...props }: EditableTextProps): import("react/jsx-runtime").JSX.Element;
|
|
17
4
|
//# sourceMappingURL=EditableText.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditableText.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/NodePropertyPanel/EditableText.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditableText.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/NodePropertyPanel/EditableText.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAM,KAAK,iBAAiB,EAAoC,MAAM,qBAAqB,CAAC;AAEnG,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAMlC,wBAAgB,YAAY,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB,2CAEtE"}
|
|
@@ -1,167 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const READ_CLASS = {
|
|
8
|
-
lg: 'text-base font-semibold leading-5 tracking-[-0.3px] text-foreground',
|
|
9
|
-
sm: 'text-xs leading-4 text-foreground-muted'
|
|
10
|
-
};
|
|
11
|
-
const EDIT_CLASS = {
|
|
12
|
-
lg: 'text-base font-semibold leading-5 tracking-[-0.3px]',
|
|
13
|
-
sm: 'text-xs leading-4'
|
|
14
|
-
};
|
|
15
|
-
const LINE_HEIGHT = {
|
|
16
|
-
lg: 20,
|
|
17
|
-
sm: 16
|
|
18
|
-
};
|
|
19
|
-
const VERTICAL_PADDING = 4;
|
|
20
|
-
const CLAMP_CLASS = 'line-clamp-[var(--editable-text-lines)] whitespace-pre-line wrap-break-word';
|
|
21
|
-
const INTERACTIVE_CLASS = 'rounded px-1.5 py-0.5 -mx-1.5';
|
|
22
|
-
const ERROR_RING_CLASS = 'ring-1 ring-error';
|
|
23
|
-
function EditableText({ value, placeholder, size = 'lg', multiline, maxLines = 3, onChange, onSubmit, disabled, error, 'aria-label': ariaLabel, className, 'data-testid': dataTestId }) {
|
|
24
|
-
const allowNewlines = true === multiline;
|
|
25
|
-
const editable = !!onChange && !!onSubmit;
|
|
26
|
-
const [isEditing, setIsEditing] = useState(false);
|
|
27
|
-
const inputRef = useRef(null);
|
|
28
|
-
const openedWith = useRef(value);
|
|
29
|
-
const errorId = `editable-text-${useId().replace(/:/g, '')}-error`;
|
|
30
|
-
const hasError = !!error;
|
|
31
|
-
const describedBy = hasError ? errorId : void 0;
|
|
32
|
-
useIsomorphicLayoutEffect(()=>{
|
|
33
|
-
if (disabled) return setIsEditing(false);
|
|
34
|
-
if (!isEditing) return;
|
|
35
|
-
inputRef.current?.focus();
|
|
36
|
-
inputRef.current?.select();
|
|
37
|
-
}, [
|
|
38
|
-
isEditing,
|
|
39
|
-
disabled
|
|
40
|
-
]);
|
|
41
|
-
const commit = useCallback(()=>{
|
|
42
|
-
setIsEditing(false);
|
|
43
|
-
const next = value.trim();
|
|
44
|
-
if (next !== value) onChange?.(next);
|
|
45
|
-
if (next !== openedWith.current) onSubmit?.(next);
|
|
46
|
-
}, [
|
|
47
|
-
value,
|
|
48
|
-
onChange,
|
|
49
|
-
onSubmit
|
|
50
|
-
]);
|
|
51
|
-
const cancel = useCallback(()=>{
|
|
52
|
-
setIsEditing(false);
|
|
53
|
-
if (openedWith.current !== value) onChange?.(openedWith.current);
|
|
54
|
-
}, [
|
|
55
|
-
value,
|
|
56
|
-
onChange
|
|
57
|
-
]);
|
|
58
|
-
const handleKeyDown = useCallback((e)=>{
|
|
59
|
-
if ('Enter' !== e.key || allowNewlines && e.shiftKey) {
|
|
60
|
-
if ('Escape' === e.key) {
|
|
61
|
-
e.preventDefault();
|
|
62
|
-
cancel();
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
e.preventDefault();
|
|
66
|
-
commit();
|
|
67
|
-
}
|
|
68
|
-
e.stopPropagation();
|
|
69
|
-
}, [
|
|
70
|
-
commit,
|
|
71
|
-
cancel,
|
|
72
|
-
allowNewlines
|
|
73
|
-
]);
|
|
74
|
-
const editorMaxHeight = multiline ? {
|
|
75
|
-
maxHeight: maxLines * LINE_HEIGHT[size] + VERTICAL_PADDING
|
|
76
|
-
} : void 0;
|
|
77
|
-
const readClampStyle = multiline ? {
|
|
78
|
-
'--editable-text-lines': maxLines
|
|
79
|
-
} : void 0;
|
|
80
|
-
const readClampClass = multiline ? CLAMP_CLASS : 'block truncate';
|
|
81
|
-
const message = /*#__PURE__*/ jsx(FormFieldError, {
|
|
82
|
-
id: errorId,
|
|
83
|
-
"data-slot": "editable-text-error",
|
|
84
|
-
className: "-ml-1 mt-1",
|
|
85
|
-
children: error
|
|
86
|
-
});
|
|
87
|
-
if (!editable) return /*#__PURE__*/ jsxs(Fragment, {
|
|
88
|
-
children: [
|
|
89
|
-
/*#__PURE__*/ jsx(CanvasTooltip, {
|
|
90
|
-
content: value || placeholder,
|
|
91
|
-
smartTooltip: true,
|
|
92
|
-
delay: true,
|
|
93
|
-
children: /*#__PURE__*/ jsx("span", {
|
|
94
|
-
"data-slot": "editable-text",
|
|
95
|
-
"data-testid": dataTestId,
|
|
96
|
-
"aria-describedby": describedBy,
|
|
97
|
-
style: readClampStyle,
|
|
98
|
-
className: cn(readClampClass, READ_CLASS[size], !value && 'text-foreground-subtle', hasError && cn(INTERACTIVE_CLASS, ERROR_RING_CLASS), className),
|
|
99
|
-
children: value || placeholder
|
|
100
|
-
})
|
|
101
|
-
}),
|
|
102
|
-
message
|
|
103
|
-
]
|
|
104
|
-
});
|
|
105
|
-
if (isEditing && !disabled) {
|
|
106
|
-
const sharedProps = {
|
|
107
|
-
'data-slot': 'editable-text-input',
|
|
108
|
-
'data-testid': dataTestId ? `${dataTestId}-input` : void 0,
|
|
109
|
-
value,
|
|
110
|
-
placeholder,
|
|
111
|
-
'aria-label': ariaLabel,
|
|
112
|
-
'aria-describedby': describedBy,
|
|
113
|
-
'aria-errormessage': hasError ? errorId : void 0,
|
|
114
|
-
'aria-invalid': hasError || void 0,
|
|
115
|
-
onKeyDown: handleKeyDown,
|
|
116
|
-
onBlur: commit,
|
|
117
|
-
className: cn('nodrag nowheel w-full min-w-0 border-none bg-surface-overlay text-foreground outline-none ring-1', hasError ? 'ring-error' : 'ring-brand', INTERACTIVE_CLASS, EDIT_CLASS[size], className)
|
|
118
|
-
};
|
|
119
|
-
return /*#__PURE__*/ jsxs(Fragment, {
|
|
120
|
-
children: [
|
|
121
|
-
multiline ? /*#__PURE__*/ jsx("textarea", {
|
|
122
|
-
...sharedProps,
|
|
123
|
-
ref: inputRef,
|
|
124
|
-
rows: 1,
|
|
125
|
-
style: editorMaxHeight,
|
|
126
|
-
className: cn(sharedProps.className, 'field-sizing-content max-w-full resize-none overflow-y-auto wrap-break-word'),
|
|
127
|
-
onChange: (e)=>onChange?.(allowNewlines ? e.target.value : stripNewlines(e.target.value))
|
|
128
|
-
}) : /*#__PURE__*/ jsx("input", {
|
|
129
|
-
...sharedProps,
|
|
130
|
-
ref: inputRef,
|
|
131
|
-
autoComplete: "off",
|
|
132
|
-
onChange: (e)=>onChange?.(e.target.value)
|
|
133
|
-
}),
|
|
134
|
-
message
|
|
135
|
-
]
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
return /*#__PURE__*/ jsxs(Fragment, {
|
|
139
|
-
children: [
|
|
140
|
-
/*#__PURE__*/ jsx(CanvasTooltip, {
|
|
141
|
-
content: value || placeholder,
|
|
142
|
-
smartTooltip: true,
|
|
143
|
-
delay: true,
|
|
144
|
-
children: /*#__PURE__*/ jsx("button", {
|
|
145
|
-
type: "button",
|
|
146
|
-
"data-slot": "editable-text",
|
|
147
|
-
"data-testid": dataTestId,
|
|
148
|
-
"aria-label": ariaLabel && `${ariaLabel}: ${value || placeholder || ''}`,
|
|
149
|
-
"aria-describedby": describedBy,
|
|
150
|
-
"aria-errormessage": hasError ? errorId : void 0,
|
|
151
|
-
"aria-invalid": hasError || void 0,
|
|
152
|
-
"aria-disabled": disabled || void 0,
|
|
153
|
-
onClick: ()=>{
|
|
154
|
-
if (disabled) return;
|
|
155
|
-
openedWith.current = value;
|
|
156
|
-
setIsEditing(true);
|
|
157
|
-
},
|
|
158
|
-
style: readClampStyle,
|
|
159
|
-
className: cn('nodrag max-w-full cursor-text border-none bg-transparent text-left transition hover:bg-surface-overlay', 'aria-disabled:cursor-not-allowed aria-disabled:opacity-50 aria-disabled:hover:bg-transparent', readClampClass, INTERACTIVE_CLASS, READ_CLASS[size], !value && 'text-foreground-subtle', hasError && ERROR_RING_CLASS, className),
|
|
160
|
-
children: value || placeholder
|
|
161
|
-
})
|
|
162
|
-
}),
|
|
163
|
-
message
|
|
164
|
-
]
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { EditableText, cn } from "@uipath/apollo-wind";
|
|
3
|
+
function EditableText_EditableText({ className, ...props }) {
|
|
4
|
+
return /*#__PURE__*/ jsx(EditableText, {
|
|
5
|
+
...props,
|
|
6
|
+
className: cn('nodrag nowheel', className)
|
|
165
7
|
});
|
|
166
8
|
}
|
|
167
|
-
export { EditableText };
|
|
9
|
+
export { EditableText_EditableText as EditableText };
|