@uipath/apollo-react 7.6.0 → 7.6.1
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/chat/headless/hooks/use-attachment-intake.cjs +39 -8
- package/dist/chat/headless/hooks/use-attachment-intake.d.ts +8 -1
- package/dist/chat/headless/hooks/use-attachment-intake.d.ts.map +1 -1
- package/dist/chat/headless/hooks/use-attachment-intake.js +35 -7
- package/dist/chat/headless/hooks/use-attachment-limits.cjs +35 -1
- package/dist/chat/headless/hooks/use-attachment-limits.d.ts +6 -0
- package/dist/chat/headless/hooks/use-attachment-limits.d.ts.map +1 -1
- package/dist/chat/headless/hooks/use-attachment-limits.js +32 -1
- package/dist/chat/headless/providers/attachments-provider.cjs +20 -10
- package/dist/chat/headless/providers/attachments-provider.d.ts +1 -0
- package/dist/chat/headless/providers/attachments-provider.d.ts.map +1 -1
- package/dist/chat/headless/providers/attachments-provider.js +20 -10
- package/dist/material/components/ap-chat/components/dropzone/dropzone.cjs +9 -31
- package/dist/material/components/ap-chat/components/dropzone/dropzone.d.ts.map +1 -1
- package/dist/material/components/ap-chat/components/dropzone/dropzone.js +9 -31
- package/package.json +3 -3
|
@@ -33,9 +33,10 @@ var __webpack_require__ = {};
|
|
|
33
33
|
var __webpack_exports__ = {};
|
|
34
34
|
__webpack_require__.r(__webpack_exports__);
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
useAttachmentIntake: ()=>useAttachmentIntake,
|
|
37
36
|
checkAttachmentFiles: ()=>checkAttachmentFiles,
|
|
38
|
-
|
|
37
|
+
useAttachmentIntake: ()=>useAttachmentIntake,
|
|
38
|
+
getAcceptedFileTypes: ()=>getAcceptedFileTypes,
|
|
39
|
+
dropAttachedFiles: ()=>dropAttachedFiles
|
|
39
40
|
});
|
|
40
41
|
const react_namespaceObject = require("@lingui/react");
|
|
41
42
|
const external_react_namespaceObject = require("react");
|
|
@@ -52,7 +53,7 @@ function getAcceptedFileTypes(types) {
|
|
|
52
53
|
}
|
|
53
54
|
function checkAttachmentFiles(files, allowed, existingCount = 0) {
|
|
54
55
|
const accept = getAcceptedFileTypes(allowed.types).map((entry)=>entry.toLowerCase());
|
|
55
|
-
const remaining =
|
|
56
|
+
const remaining = allowed.maxCount ? allowed.maxCount - existingCount : 1 / 0;
|
|
56
57
|
const accepted = [];
|
|
57
58
|
const rejected = [];
|
|
58
59
|
for (const file of files){
|
|
@@ -77,15 +78,39 @@ function checkAttachmentFiles(files, allowed, existingCount = 0) {
|
|
|
77
78
|
rejected
|
|
78
79
|
};
|
|
79
80
|
}
|
|
81
|
+
const sameFile = (a, b)=>a.name === b.name && a.size === b.size;
|
|
82
|
+
function dropAttachedFiles(accepted, rejected, draft, maxCount) {
|
|
83
|
+
const seen = [
|
|
84
|
+
...draft
|
|
85
|
+
];
|
|
86
|
+
const isNew = (file)=>{
|
|
87
|
+
if (seen.some((other)=>sameFile(other, file))) return false;
|
|
88
|
+
seen.push(file);
|
|
89
|
+
return true;
|
|
90
|
+
};
|
|
91
|
+
const candidates = [
|
|
92
|
+
...accepted,
|
|
93
|
+
...rejected.filter(({ reason })=>'count' === reason).map(({ file })=>file)
|
|
94
|
+
].filter(isNew);
|
|
95
|
+
const free = maxCount ? Math.max(0, maxCount - draft.length) : 1 / 0;
|
|
96
|
+
return {
|
|
97
|
+
accepted: candidates.slice(0, free),
|
|
98
|
+
rejected: [
|
|
99
|
+
...rejected.filter(({ reason, file })=>'count' !== reason && !draft.some((other)=>sameFile(other, file))),
|
|
100
|
+
...candidates.slice(free).map((file)=>({
|
|
101
|
+
file,
|
|
102
|
+
reason: 'count'
|
|
103
|
+
}))
|
|
104
|
+
]
|
|
105
|
+
};
|
|
106
|
+
}
|
|
80
107
|
function useAttachmentIntake() {
|
|
81
108
|
const { _ } = (0, react_namespaceObject.useLingui)();
|
|
82
|
-
const { addAttachments,
|
|
109
|
+
const { addAttachments, getAttachments } = (0, attachments_provider_cjs_namespaceObject.useAttachments)();
|
|
83
110
|
const { setError } = (0, error_provider_cjs_namespaceObject.useError)();
|
|
84
111
|
const { allowedAttachments } = (0, chat_state_provider_cjs_namespaceObject.useChatState)();
|
|
85
|
-
const attachmentsCount = external_react_default().useRef(attachments.length);
|
|
86
|
-
attachmentsCount.current = attachments.length;
|
|
87
112
|
const handleRejections = external_react_default().useCallback((parsedFiles, rejections)=>{
|
|
88
|
-
if (!allowedAttachments.multiple && (parsedFiles.length > 1 ||
|
|
113
|
+
if (!allowedAttachments.multiple && (parsedFiles.length > 1 || parsedFiles.length > 0 && getAttachments().length > 0 || rejections.length > 1)) {
|
|
89
114
|
setError(_({
|
|
90
115
|
id: 'autopilot-chat.error.multiple-files'
|
|
91
116
|
}));
|
|
@@ -127,12 +152,14 @@ function useAttachmentIntake() {
|
|
|
127
152
|
}, [
|
|
128
153
|
_,
|
|
129
154
|
setError,
|
|
155
|
+
getAttachments,
|
|
130
156
|
allowedAttachments.maxCount,
|
|
131
157
|
allowedAttachments.maxSize,
|
|
132
158
|
allowedAttachments.multiple
|
|
133
159
|
]);
|
|
134
|
-
return external_react_default().useCallback(async (
|
|
160
|
+
return external_react_default().useCallback(async (checked, checkRejected)=>{
|
|
135
161
|
try {
|
|
162
|
+
const { accepted, rejected } = dropAttachedFiles(checked, checkRejected, getAttachments(), allowedAttachments.maxCount);
|
|
136
163
|
const parsedFiles = await (0, file_reader_cjs_namespaceObject.parseFiles)(accepted);
|
|
137
164
|
if (handleRejections(parsedFiles, rejected)) return;
|
|
138
165
|
if (0 === rejected.length) setError(void 0);
|
|
@@ -145,16 +172,20 @@ function useAttachmentIntake() {
|
|
|
145
172
|
}
|
|
146
173
|
}, [
|
|
147
174
|
addAttachments,
|
|
175
|
+
getAttachments,
|
|
148
176
|
setError,
|
|
177
|
+
allowedAttachments.maxCount,
|
|
149
178
|
allowedAttachments.multiple,
|
|
150
179
|
handleRejections
|
|
151
180
|
]);
|
|
152
181
|
}
|
|
153
182
|
exports.checkAttachmentFiles = __webpack_exports__.checkAttachmentFiles;
|
|
183
|
+
exports.dropAttachedFiles = __webpack_exports__.dropAttachedFiles;
|
|
154
184
|
exports.getAcceptedFileTypes = __webpack_exports__.getAcceptedFileTypes;
|
|
155
185
|
exports.useAttachmentIntake = __webpack_exports__.useAttachmentIntake;
|
|
156
186
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
157
187
|
"checkAttachmentFiles",
|
|
188
|
+
"dropAttachedFiles",
|
|
158
189
|
"getAcceptedFileTypes",
|
|
159
190
|
"useAttachmentIntake"
|
|
160
191
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
@@ -9,5 +9,12 @@ export declare function checkAttachmentFiles(files: readonly File[], allowed: Au
|
|
|
9
9
|
accepted: File[];
|
|
10
10
|
rejected: ChatAttachmentRejection[];
|
|
11
11
|
};
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function dropAttachedFiles(accepted: readonly File[], rejected: readonly ChatAttachmentRejection[], draft: readonly {
|
|
13
|
+
name: string;
|
|
14
|
+
size: number;
|
|
15
|
+
}[], maxCount: number | undefined): {
|
|
16
|
+
accepted: File[];
|
|
17
|
+
rejected: ChatAttachmentRejection[];
|
|
18
|
+
};
|
|
19
|
+
export declare function useAttachmentIntake(): (checked: File[], checkRejected: ChatAttachmentRejection[]) => Promise<void>;
|
|
13
20
|
//# sourceMappingURL=use-attachment-intake.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-attachment-intake.d.ts","sourceRoot":"","sources":["../../../../src/chat/headless/hooks/use-attachment-intake.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,+BAA+B,EAAyB,MAAM,eAAe,CAAC;AAU5F,MAAM,MAAM,6BAA6B,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAEhF,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,6BAA6B,CAAC;CACvC;AAMD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,+BAA+B,CAAC,OAAO,CAAC,GAAG,MAAM,EAAE,CAE9F;
|
|
1
|
+
{"version":3,"file":"use-attachment-intake.d.ts","sourceRoot":"","sources":["../../../../src/chat/headless/hooks/use-attachment-intake.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,+BAA+B,EAAyB,MAAM,eAAe,CAAC;AAU5F,MAAM,MAAM,6BAA6B,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAEhF,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,6BAA6B,CAAC;CACvC;AAMD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,+BAA+B,CAAC,OAAO,CAAC,GAAG,MAAM,EAAE,CAE9F;AAOD,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,OAAO,EAAE,+BAA+B,EACxC,aAAa,SAAI,GAChB;IAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAAC,QAAQ,EAAE,uBAAuB,EAAE,CAAA;CAAE,CAwB3D;AAUD,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,SAAS,IAAI,EAAE,EACzB,QAAQ,EAAE,SAAS,uBAAuB,EAAE,EAC5C,KAAK,EAAE,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,EAChD,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B;IAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAAC,QAAQ,EAAE,uBAAuB,EAAE,CAAA;CAAE,CAsB3D;AASD,wBAAgB,mBAAmB,cA+Ef,IAAI,EAAE,iBAAiB,uBAAuB,EAAE,mBAiCnE"}
|
|
@@ -12,7 +12,7 @@ function getAcceptedFileTypes(types) {
|
|
|
12
12
|
}
|
|
13
13
|
function checkAttachmentFiles(files, allowed, existingCount = 0) {
|
|
14
14
|
const accept = getAcceptedFileTypes(allowed.types).map((entry)=>entry.toLowerCase());
|
|
15
|
-
const remaining =
|
|
15
|
+
const remaining = allowed.maxCount ? allowed.maxCount - existingCount : 1 / 0;
|
|
16
16
|
const accepted = [];
|
|
17
17
|
const rejected = [];
|
|
18
18
|
for (const file of files){
|
|
@@ -37,15 +37,39 @@ function checkAttachmentFiles(files, allowed, existingCount = 0) {
|
|
|
37
37
|
rejected
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
+
const sameFile = (a, b)=>a.name === b.name && a.size === b.size;
|
|
41
|
+
function dropAttachedFiles(accepted, rejected, draft, maxCount) {
|
|
42
|
+
const seen = [
|
|
43
|
+
...draft
|
|
44
|
+
];
|
|
45
|
+
const isNew = (file)=>{
|
|
46
|
+
if (seen.some((other)=>sameFile(other, file))) return false;
|
|
47
|
+
seen.push(file);
|
|
48
|
+
return true;
|
|
49
|
+
};
|
|
50
|
+
const candidates = [
|
|
51
|
+
...accepted,
|
|
52
|
+
...rejected.filter(({ reason })=>'count' === reason).map(({ file })=>file)
|
|
53
|
+
].filter(isNew);
|
|
54
|
+
const free = maxCount ? Math.max(0, maxCount - draft.length) : 1 / 0;
|
|
55
|
+
return {
|
|
56
|
+
accepted: candidates.slice(0, free),
|
|
57
|
+
rejected: [
|
|
58
|
+
...rejected.filter(({ reason, file })=>'count' !== reason && !draft.some((other)=>sameFile(other, file))),
|
|
59
|
+
...candidates.slice(free).map((file)=>({
|
|
60
|
+
file,
|
|
61
|
+
reason: 'count'
|
|
62
|
+
}))
|
|
63
|
+
]
|
|
64
|
+
};
|
|
65
|
+
}
|
|
40
66
|
function useAttachmentIntake() {
|
|
41
67
|
const { _ } = useLingui();
|
|
42
|
-
const { addAttachments,
|
|
68
|
+
const { addAttachments, getAttachments } = useAttachments();
|
|
43
69
|
const { setError } = useError();
|
|
44
70
|
const { allowedAttachments } = useChatState();
|
|
45
|
-
const attachmentsCount = react.useRef(attachments.length);
|
|
46
|
-
attachmentsCount.current = attachments.length;
|
|
47
71
|
const handleRejections = react.useCallback((parsedFiles, rejections)=>{
|
|
48
|
-
if (!allowedAttachments.multiple && (parsedFiles.length > 1 ||
|
|
72
|
+
if (!allowedAttachments.multiple && (parsedFiles.length > 1 || parsedFiles.length > 0 && getAttachments().length > 0 || rejections.length > 1)) {
|
|
49
73
|
setError(_({
|
|
50
74
|
id: 'autopilot-chat.error.multiple-files'
|
|
51
75
|
}));
|
|
@@ -87,12 +111,14 @@ function useAttachmentIntake() {
|
|
|
87
111
|
}, [
|
|
88
112
|
_,
|
|
89
113
|
setError,
|
|
114
|
+
getAttachments,
|
|
90
115
|
allowedAttachments.maxCount,
|
|
91
116
|
allowedAttachments.maxSize,
|
|
92
117
|
allowedAttachments.multiple
|
|
93
118
|
]);
|
|
94
|
-
return react.useCallback(async (
|
|
119
|
+
return react.useCallback(async (checked, checkRejected)=>{
|
|
95
120
|
try {
|
|
121
|
+
const { accepted, rejected } = dropAttachedFiles(checked, checkRejected, getAttachments(), allowedAttachments.maxCount);
|
|
96
122
|
const parsedFiles = await parseFiles(accepted);
|
|
97
123
|
if (handleRejections(parsedFiles, rejected)) return;
|
|
98
124
|
if (0 === rejected.length) setError(void 0);
|
|
@@ -105,9 +131,11 @@ function useAttachmentIntake() {
|
|
|
105
131
|
}
|
|
106
132
|
}, [
|
|
107
133
|
addAttachments,
|
|
134
|
+
getAttachments,
|
|
108
135
|
setError,
|
|
136
|
+
allowedAttachments.maxCount,
|
|
109
137
|
allowedAttachments.multiple,
|
|
110
138
|
handleRejections
|
|
111
139
|
]);
|
|
112
140
|
}
|
|
113
|
-
export { checkAttachmentFiles, getAcceptedFileTypes, useAttachmentIntake };
|
|
141
|
+
export { checkAttachmentFiles, dropAttachedFiles, getAcceptedFileTypes, useAttachmentIntake };
|
|
@@ -33,6 +33,7 @@ var __webpack_require__ = {};
|
|
|
33
33
|
var __webpack_exports__ = {};
|
|
34
34
|
__webpack_require__.r(__webpack_exports__);
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
useDropzoneLimitHints: ()=>useDropzoneLimitHints,
|
|
36
37
|
useAttachmentLimits: ()=>useAttachmentLimits
|
|
37
38
|
});
|
|
38
39
|
const react_namespaceObject = require("@lingui/react");
|
|
@@ -68,9 +69,42 @@ function useAttachmentLimits(allowed) {
|
|
|
68
69
|
allowed
|
|
69
70
|
]);
|
|
70
71
|
}
|
|
72
|
+
function useDropzoneLimitHints(allowed) {
|
|
73
|
+
const { _ } = (0, react_namespaceObject.useLingui)();
|
|
74
|
+
return external_react_default().useMemo(()=>{
|
|
75
|
+
const maxCount = allowed.maxCount;
|
|
76
|
+
const maxSize = allowed.maxSize / 1024 / 1024;
|
|
77
|
+
const fileTypes = Object.values(allowed.types).flat().join(', ');
|
|
78
|
+
return {
|
|
79
|
+
countHint: maxCount && maxCount > 1 && allowed.multiple ? _({
|
|
80
|
+
id: 'autopilot-chat.dropzone.overlay-max-count',
|
|
81
|
+
values: {
|
|
82
|
+
maxCount: maxCount
|
|
83
|
+
}
|
|
84
|
+
}) : '',
|
|
85
|
+
sizeHint: _({
|
|
86
|
+
id: 'autopilot-chat.dropzone.overlay-max-size',
|
|
87
|
+
values: {
|
|
88
|
+
maxSize: maxSize
|
|
89
|
+
}
|
|
90
|
+
}),
|
|
91
|
+
typesHint: _({
|
|
92
|
+
id: 'autopilot-chat.dropzone.allowed-file-types',
|
|
93
|
+
values: {
|
|
94
|
+
fileTypes: fileTypes
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
};
|
|
98
|
+
}, [
|
|
99
|
+
_,
|
|
100
|
+
allowed
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
71
103
|
exports.useAttachmentLimits = __webpack_exports__.useAttachmentLimits;
|
|
104
|
+
exports.useDropzoneLimitHints = __webpack_exports__.useDropzoneLimitHints;
|
|
72
105
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
73
|
-
"useAttachmentLimits"
|
|
106
|
+
"useAttachmentLimits",
|
|
107
|
+
"useDropzoneLimitHints"
|
|
74
108
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
75
109
|
Object.defineProperty(exports, '__esModule', {
|
|
76
110
|
value: true
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { AutopilotChatAllowedAttachments } from '../../service';
|
|
2
2
|
export declare function useAttachmentLimits(allowed: AutopilotChatAllowedAttachments): string[];
|
|
3
|
+
export interface DropzoneLimitHints {
|
|
4
|
+
countHint: string;
|
|
5
|
+
sizeHint: string;
|
|
6
|
+
typesHint: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function useDropzoneLimitHints(allowed: AutopilotChatAllowedAttachments): DropzoneLimitHints;
|
|
3
9
|
//# sourceMappingURL=use-attachment-limits.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-attachment-limits.d.ts","sourceRoot":"","sources":["../../../../src/chat/headless/hooks/use-attachment-limits.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAMrE,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,EAAE,CAkCtF"}
|
|
1
|
+
{"version":3,"file":"use-attachment-limits.d.ts","sourceRoot":"","sources":["../../../../src/chat/headless/hooks/use-attachment-limits.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAMrE,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,EAAE,CAkCtF;AAED,MAAM,WAAW,kBAAkB;IAEjC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAGD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,+BAA+B,GACvC,kBAAkB,CA+BpB"}
|
|
@@ -30,4 +30,35 @@ function useAttachmentLimits(allowed) {
|
|
|
30
30
|
allowed
|
|
31
31
|
]);
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
function useDropzoneLimitHints(allowed) {
|
|
34
|
+
const { _ } = useLingui();
|
|
35
|
+
return react.useMemo(()=>{
|
|
36
|
+
const maxCount = allowed.maxCount;
|
|
37
|
+
const maxSize = allowed.maxSize / 1024 / 1024;
|
|
38
|
+
const fileTypes = Object.values(allowed.types).flat().join(', ');
|
|
39
|
+
return {
|
|
40
|
+
countHint: maxCount && maxCount > 1 && allowed.multiple ? _({
|
|
41
|
+
id: 'autopilot-chat.dropzone.overlay-max-count',
|
|
42
|
+
values: {
|
|
43
|
+
maxCount: maxCount
|
|
44
|
+
}
|
|
45
|
+
}) : '',
|
|
46
|
+
sizeHint: _({
|
|
47
|
+
id: 'autopilot-chat.dropzone.overlay-max-size',
|
|
48
|
+
values: {
|
|
49
|
+
maxSize: maxSize
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
typesHint: _({
|
|
53
|
+
id: 'autopilot-chat.dropzone.allowed-file-types',
|
|
54
|
+
values: {
|
|
55
|
+
fileTypes: fileTypes
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
};
|
|
59
|
+
}, [
|
|
60
|
+
_,
|
|
61
|
+
allowed
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
export { useAttachmentLimits, useDropzoneLimitHints };
|
|
@@ -49,6 +49,7 @@ const external_chat_state_provider_cjs_namespaceObject = require("./chat-state-p
|
|
|
49
49
|
const external_error_provider_cjs_namespaceObject = require("./error-provider.cjs");
|
|
50
50
|
const AutopilotAttachmentsContext = /*#__PURE__*/ external_react_default().createContext({
|
|
51
51
|
attachments: [],
|
|
52
|
+
getAttachments: ()=>[],
|
|
52
53
|
attachmentsLoading: [],
|
|
53
54
|
addAttachments: ()=>{},
|
|
54
55
|
removeAttachment: ()=>{},
|
|
@@ -63,6 +64,12 @@ function AutopilotAttachmentsProvider({ children }) {
|
|
|
63
64
|
const [attachments, setAttachments] = external_react_default().useState(prompt?.attachments ?? []);
|
|
64
65
|
const [attachmentsLoading, setAttachmentsLoading] = external_react_default().useState([]);
|
|
65
66
|
const attachmentsRef = external_react_default().useRef(attachments);
|
|
67
|
+
const latestRef = external_react_default().useRef(attachments);
|
|
68
|
+
const update = external_react_default().useCallback((next)=>{
|
|
69
|
+
latestRef.current = next;
|
|
70
|
+
setAttachments(next);
|
|
71
|
+
}, []);
|
|
72
|
+
const getAttachments = external_react_default().useCallback(()=>latestRef.current, []);
|
|
66
73
|
external_react_default().useEffect(()=>{
|
|
67
74
|
const currentAttachmentsWithoutContent = attachmentsRef.current.map(({ content: _content, ...rest })=>rest);
|
|
68
75
|
const newAttachmentsWithoutContent = attachments.map(({ content: _content, ...rest })=>rest);
|
|
@@ -83,9 +90,10 @@ function AutopilotAttachmentsProvider({ children }) {
|
|
|
83
90
|
chatService
|
|
84
91
|
]);
|
|
85
92
|
const addAttachments = external_react_default().useCallback((newFiles)=>{
|
|
93
|
+
const current = latestRef.current;
|
|
86
94
|
const filesToAdd = [
|
|
87
|
-
...
|
|
88
|
-
...newFiles.filter((file)=>!
|
|
95
|
+
...current,
|
|
96
|
+
...newFiles.filter((file)=>!current.some((existing)=>existing.name === file.name && existing.size === file.size))
|
|
89
97
|
];
|
|
90
98
|
const totalCount = filesToAdd.length;
|
|
91
99
|
if (allowedAttachments.maxCount && totalCount > allowedAttachments.maxCount) return void setError(_({
|
|
@@ -97,19 +105,20 @@ function AutopilotAttachmentsProvider({ children }) {
|
|
|
97
105
|
if (!allowedAttachments.multiple && totalCount > 1) return void setError(_({
|
|
98
106
|
id: 'autopilot-chat.error.multiple-files'
|
|
99
107
|
}));
|
|
100
|
-
|
|
108
|
+
update(filesToAdd);
|
|
101
109
|
}, [
|
|
102
110
|
allowedAttachments.maxCount,
|
|
103
111
|
allowedAttachments.multiple,
|
|
104
112
|
setError,
|
|
105
|
-
_
|
|
113
|
+
_,
|
|
114
|
+
update
|
|
115
|
+
]);
|
|
116
|
+
const removeAttachment = external_react_default().useCallback((name, index)=>update(latestRef.current.filter((file, i)=>i !== index || file.name !== name)), [
|
|
117
|
+
update
|
|
118
|
+
]);
|
|
119
|
+
const clearAttachments = external_react_default().useCallback(()=>update([]), [
|
|
120
|
+
update
|
|
106
121
|
]);
|
|
107
|
-
const removeAttachment = external_react_default().useCallback((name, index)=>{
|
|
108
|
-
setAttachments((current)=>current.filter((file, i)=>i !== index || file.name !== name));
|
|
109
|
-
}, []);
|
|
110
|
-
const clearAttachments = external_react_default().useCallback(()=>{
|
|
111
|
-
setAttachments([]);
|
|
112
|
-
}, []);
|
|
113
122
|
external_react_default().useEffect(()=>{
|
|
114
123
|
if (!chatService) return;
|
|
115
124
|
const unsubscribeSetAttachmentsLoading = chatService.__internalService__.on(index_cjs_namespaceObject.AutopilotChatInternalEvent.SetAttachmentsLoading, (state)=>{
|
|
@@ -130,6 +139,7 @@ function AutopilotAttachmentsProvider({ children }) {
|
|
|
130
139
|
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(AutopilotAttachmentsContext.Provider, {
|
|
131
140
|
value: {
|
|
132
141
|
attachments,
|
|
142
|
+
getAttachments,
|
|
133
143
|
attachmentsLoading,
|
|
134
144
|
addAttachments,
|
|
135
145
|
removeAttachment,
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { type AutopilotChatFileInfo } from '../../service';
|
|
3
3
|
interface AutopilotAttachmentsContextType {
|
|
4
4
|
attachments: AutopilotChatFileInfo[];
|
|
5
|
+
getAttachments: () => AutopilotChatFileInfo[];
|
|
5
6
|
attachmentsLoading: AutopilotChatFileInfo[];
|
|
6
7
|
addAttachments: (files: AutopilotChatFileInfo[]) => void;
|
|
7
8
|
removeAttachment: (name: string, index: number) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachments-provider.d.ts","sourceRoot":"","sources":["../../../../src/chat/headless/providers/attachments-provider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAEL,KAAK,qBAAqB,EAG3B,MAAM,eAAe,CAAC;AAMvB,UAAU,+BAA+B;IACvC,WAAW,EAAE,qBAAqB,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"attachments-provider.d.ts","sourceRoot":"","sources":["../../../../src/chat/headless/providers/attachments-provider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAEL,KAAK,qBAAqB,EAG3B,MAAM,eAAe,CAAC;AAMvB,UAAU,+BAA+B;IACvC,WAAW,EAAE,qBAAqB,EAAE,CAAC;IAErC,cAAc,EAAE,MAAM,qBAAqB,EAAE,CAAC;IAC9C,kBAAkB,EAAE,qBAAqB,EAAE,CAAC;IAC5C,cAAc,EAAE,CAAC,KAAK,EAAE,qBAAqB,EAAE,KAAK,IAAI,CAAC;IACzD,gBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxD,gBAAgB,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED,eAAO,MAAM,2BAA2B,gDAOtC,CAAC;AAEH,wBAAgB,4BAA4B,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,2CAmJvF;AAED,wBAAgB,cAAc,oCAQ7B"}
|
|
@@ -9,6 +9,7 @@ import { useChatState } from "./chat-state-provider.js";
|
|
|
9
9
|
import { useError } from "./error-provider.js";
|
|
10
10
|
const AutopilotAttachmentsContext = /*#__PURE__*/ react.createContext({
|
|
11
11
|
attachments: [],
|
|
12
|
+
getAttachments: ()=>[],
|
|
12
13
|
attachmentsLoading: [],
|
|
13
14
|
addAttachments: ()=>{},
|
|
14
15
|
removeAttachment: ()=>{},
|
|
@@ -23,6 +24,12 @@ function AutopilotAttachmentsProvider({ children }) {
|
|
|
23
24
|
const [attachments, setAttachments] = react.useState(prompt?.attachments ?? []);
|
|
24
25
|
const [attachmentsLoading, setAttachmentsLoading] = react.useState([]);
|
|
25
26
|
const attachmentsRef = react.useRef(attachments);
|
|
27
|
+
const latestRef = react.useRef(attachments);
|
|
28
|
+
const update = react.useCallback((next)=>{
|
|
29
|
+
latestRef.current = next;
|
|
30
|
+
setAttachments(next);
|
|
31
|
+
}, []);
|
|
32
|
+
const getAttachments = react.useCallback(()=>latestRef.current, []);
|
|
26
33
|
react.useEffect(()=>{
|
|
27
34
|
const currentAttachmentsWithoutContent = attachmentsRef.current.map(({ content: _content, ...rest })=>rest);
|
|
28
35
|
const newAttachmentsWithoutContent = attachments.map(({ content: _content, ...rest })=>rest);
|
|
@@ -43,9 +50,10 @@ function AutopilotAttachmentsProvider({ children }) {
|
|
|
43
50
|
chatService
|
|
44
51
|
]);
|
|
45
52
|
const addAttachments = react.useCallback((newFiles)=>{
|
|
53
|
+
const current = latestRef.current;
|
|
46
54
|
const filesToAdd = [
|
|
47
|
-
...
|
|
48
|
-
...newFiles.filter((file)=>!
|
|
55
|
+
...current,
|
|
56
|
+
...newFiles.filter((file)=>!current.some((existing)=>existing.name === file.name && existing.size === file.size))
|
|
49
57
|
];
|
|
50
58
|
const totalCount = filesToAdd.length;
|
|
51
59
|
if (allowedAttachments.maxCount && totalCount > allowedAttachments.maxCount) return void setError(_({
|
|
@@ -57,19 +65,20 @@ function AutopilotAttachmentsProvider({ children }) {
|
|
|
57
65
|
if (!allowedAttachments.multiple && totalCount > 1) return void setError(_({
|
|
58
66
|
id: 'autopilot-chat.error.multiple-files'
|
|
59
67
|
}));
|
|
60
|
-
|
|
68
|
+
update(filesToAdd);
|
|
61
69
|
}, [
|
|
62
70
|
allowedAttachments.maxCount,
|
|
63
71
|
allowedAttachments.multiple,
|
|
64
72
|
setError,
|
|
65
|
-
_
|
|
73
|
+
_,
|
|
74
|
+
update
|
|
75
|
+
]);
|
|
76
|
+
const removeAttachment = react.useCallback((name, index)=>update(latestRef.current.filter((file, i)=>i !== index || file.name !== name)), [
|
|
77
|
+
update
|
|
78
|
+
]);
|
|
79
|
+
const clearAttachments = react.useCallback(()=>update([]), [
|
|
80
|
+
update
|
|
66
81
|
]);
|
|
67
|
-
const removeAttachment = react.useCallback((name, index)=>{
|
|
68
|
-
setAttachments((current)=>current.filter((file, i)=>i !== index || file.name !== name));
|
|
69
|
-
}, []);
|
|
70
|
-
const clearAttachments = react.useCallback(()=>{
|
|
71
|
-
setAttachments([]);
|
|
72
|
-
}, []);
|
|
73
82
|
react.useEffect(()=>{
|
|
74
83
|
if (!chatService) return;
|
|
75
84
|
const unsubscribeSetAttachmentsLoading = chatService.__internalService__.on(AutopilotChatInternalEvent.SetAttachmentsLoading, (state)=>{
|
|
@@ -90,6 +99,7 @@ function AutopilotAttachmentsProvider({ children }) {
|
|
|
90
99
|
return /*#__PURE__*/ jsx(AutopilotAttachmentsContext.Provider, {
|
|
91
100
|
value: {
|
|
92
101
|
attachments,
|
|
102
|
+
getAttachments,
|
|
93
103
|
attachmentsLoading,
|
|
94
104
|
addAttachments,
|
|
95
105
|
removeAttachment,
|
|
@@ -42,6 +42,7 @@ const styles_namespaceObject = require("@mui/material/styles");
|
|
|
42
42
|
const apollo_core_namespaceObject = require("@uipath/apollo-core");
|
|
43
43
|
var apollo_core_default = /*#__PURE__*/ __webpack_require__.n(apollo_core_namespaceObject);
|
|
44
44
|
const use_attachment_intake_cjs_namespaceObject = require("../../../../../chat/headless/hooks/use-attachment-intake.cjs");
|
|
45
|
+
const use_attachment_limits_cjs_namespaceObject = require("../../../../../chat/headless/hooks/use-attachment-limits.cjs");
|
|
45
46
|
const chat_state_provider_cjs_namespaceObject = require("../../../../../chat/headless/providers/chat-state-provider.cjs");
|
|
46
47
|
const index_cjs_namespaceObject = require("../../../ap-typography/index.cjs");
|
|
47
48
|
const external_react_namespaceObject = require("react");
|
|
@@ -91,6 +92,7 @@ function AutopilotChatDropzoneComponent({ children, ...dropzoneOptions }) {
|
|
|
91
92
|
const { _ } = (0, react_namespaceObject.useLingui)();
|
|
92
93
|
const { disabledFeatures, allowedAttachments } = (0, chat_state_provider_cjs_namespaceObject.useChatState)();
|
|
93
94
|
const takeFiles = (0, use_attachment_intake_cjs_namespaceObject.useAttachmentIntake)();
|
|
95
|
+
const { countHint, sizeHint, typesHint } = (0, use_attachment_limits_cjs_namespaceObject.useDropzoneLimitHints)(allowedAttachments);
|
|
94
96
|
const handleDrop = external_react_default().useCallback((files, fileRejections)=>takeFiles(files, fileRejections.map(({ file, errors })=>({
|
|
95
97
|
file,
|
|
96
98
|
reason: rejectionReason(errors[0]?.code)
|
|
@@ -130,44 +132,20 @@ function AutopilotChatDropzoneComponent({ children, ...dropzoneOptions }) {
|
|
|
130
132
|
id: 'autopilot-chat.dropzone.overlay-title'
|
|
131
133
|
})
|
|
132
134
|
}),
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
children: _({
|
|
139
|
-
id: 'autopilot-chat.dropzone.overlay-max-count',
|
|
140
|
-
values: {
|
|
141
|
-
maxCount: maxCount
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
});
|
|
145
|
-
})(),
|
|
135
|
+
countHint && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.ApTypography, {
|
|
136
|
+
variant: apollo_core_namespaceObject.FontVariantToken.fontSizeS,
|
|
137
|
+
color: 'var(--color-foreground)',
|
|
138
|
+
children: countHint
|
|
139
|
+
}),
|
|
146
140
|
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.ApTypography, {
|
|
147
141
|
variant: apollo_core_namespaceObject.FontVariantToken.fontSizeS,
|
|
148
142
|
color: 'var(--color-foreground)',
|
|
149
|
-
children:
|
|
150
|
-
const maxSize = allowedAttachments.maxSize / 1024 / 1024;
|
|
151
|
-
return _({
|
|
152
|
-
id: 'autopilot-chat.dropzone.overlay-max-size',
|
|
153
|
-
values: {
|
|
154
|
-
maxSize: maxSize
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
})()
|
|
143
|
+
children: sizeHint
|
|
158
144
|
}),
|
|
159
145
|
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.ApTypography, {
|
|
160
146
|
variant: apollo_core_namespaceObject.FontVariantToken.fontSizeS,
|
|
161
147
|
color: 'var(--color-foreground)',
|
|
162
|
-
children:
|
|
163
|
-
const fileTypes = Object.values(allowedAttachments.types).flat().join(', ');
|
|
164
|
-
return _({
|
|
165
|
-
id: 'autopilot-chat.dropzone.allowed-file-types',
|
|
166
|
-
values: {
|
|
167
|
-
fileTypes: fileTypes
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
})()
|
|
148
|
+
children: typesHint
|
|
171
149
|
})
|
|
172
150
|
]
|
|
173
151
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropzone.d.ts","sourceRoot":"","sources":["../../../../../../src/material/components/ap-chat/components/dropzone/dropzone.tsx"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,6BAA6B,EAEnC,MAAM,gEAAgE,CAAC;
|
|
1
|
+
{"version":3,"file":"dropzone.d.ts","sourceRoot":"","sources":["../../../../../../src/material/components/ap-chat/components/dropzone/dropzone.tsx"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,6BAA6B,EAEnC,MAAM,gEAAgE,CAAC;AAIxE,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,eAAe,EAA8C,MAAM,gBAAgB,CAAC;AAElG,UAAU,0BAA2B,SAAQ,eAAe;IAC1D,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAkCD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,6BAA6B,CAWvF;AAED,iBAAS,8BAA8B,CAAC,EACtC,QAAQ,EACR,GAAG,eAAe,EACnB,EAAE,0BAA0B,2CA8D5B;AAED,eAAO,MAAM,qBAAqB,kEAA6C,CAAC"}
|
|
@@ -3,6 +3,7 @@ import { useLingui } from "@lingui/react";
|
|
|
3
3
|
import { styled } from "@mui/material/styles";
|
|
4
4
|
import apollo_core, { FontVariantToken } from "@uipath/apollo-core";
|
|
5
5
|
import { useAttachmentIntake } from "../../../../../chat/headless/hooks/use-attachment-intake.js";
|
|
6
|
+
import { useDropzoneLimitHints } from "../../../../../chat/headless/hooks/use-attachment-limits.js";
|
|
6
7
|
import { useChatState } from "../../../../../chat/headless/providers/chat-state-provider.js";
|
|
7
8
|
import { ApTypography } from "../../../ap-typography/index.js";
|
|
8
9
|
import react from "react";
|
|
@@ -51,6 +52,7 @@ function AutopilotChatDropzoneComponent({ children, ...dropzoneOptions }) {
|
|
|
51
52
|
const { _ } = useLingui();
|
|
52
53
|
const { disabledFeatures, allowedAttachments } = useChatState();
|
|
53
54
|
const takeFiles = useAttachmentIntake();
|
|
55
|
+
const { countHint, sizeHint, typesHint } = useDropzoneLimitHints(allowedAttachments);
|
|
54
56
|
const handleDrop = react.useCallback((files, fileRejections)=>takeFiles(files, fileRejections.map(({ file, errors })=>({
|
|
55
57
|
file,
|
|
56
58
|
reason: rejectionReason(errors[0]?.code)
|
|
@@ -90,44 +92,20 @@ function AutopilotChatDropzoneComponent({ children, ...dropzoneOptions }) {
|
|
|
90
92
|
id: 'autopilot-chat.dropzone.overlay-title'
|
|
91
93
|
})
|
|
92
94
|
}),
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
children: _({
|
|
99
|
-
id: 'autopilot-chat.dropzone.overlay-max-count',
|
|
100
|
-
values: {
|
|
101
|
-
maxCount: maxCount
|
|
102
|
-
}
|
|
103
|
-
})
|
|
104
|
-
});
|
|
105
|
-
})(),
|
|
95
|
+
countHint && /*#__PURE__*/ jsx(ApTypography, {
|
|
96
|
+
variant: FontVariantToken.fontSizeS,
|
|
97
|
+
color: 'var(--color-foreground)',
|
|
98
|
+
children: countHint
|
|
99
|
+
}),
|
|
106
100
|
/*#__PURE__*/ jsx(ApTypography, {
|
|
107
101
|
variant: FontVariantToken.fontSizeS,
|
|
108
102
|
color: 'var(--color-foreground)',
|
|
109
|
-
children:
|
|
110
|
-
const maxSize = allowedAttachments.maxSize / 1024 / 1024;
|
|
111
|
-
return _({
|
|
112
|
-
id: 'autopilot-chat.dropzone.overlay-max-size',
|
|
113
|
-
values: {
|
|
114
|
-
maxSize: maxSize
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
})()
|
|
103
|
+
children: sizeHint
|
|
118
104
|
}),
|
|
119
105
|
/*#__PURE__*/ jsx(ApTypography, {
|
|
120
106
|
variant: FontVariantToken.fontSizeS,
|
|
121
107
|
color: 'var(--color-foreground)',
|
|
122
|
-
children:
|
|
123
|
-
const fileTypes = Object.values(allowedAttachments.types).flat().join(', ');
|
|
124
|
-
return _({
|
|
125
|
-
id: 'autopilot-chat.dropzone.allowed-file-types',
|
|
126
|
-
values: {
|
|
127
|
-
fileTypes: fileTypes
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
})()
|
|
108
|
+
children: typesHint
|
|
131
109
|
})
|
|
132
110
|
]
|
|
133
111
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uipath/apollo-react",
|
|
3
|
-
"version": "7.6.
|
|
3
|
+
"version": "7.6.1",
|
|
4
4
|
"description": "Apollo Design System - React component library with Material UI theming",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -245,8 +245,8 @@
|
|
|
245
245
|
"zod": "^4.3.5",
|
|
246
246
|
"zustand": "^5.0.9",
|
|
247
247
|
"@uipath/apollo-core": "5.15.2",
|
|
248
|
-
"@uipath/apollo-
|
|
249
|
-
"@uipath/apollo-
|
|
248
|
+
"@uipath/apollo-wind": "2.72.2",
|
|
249
|
+
"@uipath/apollo-ui-icons": "1.2.0"
|
|
250
250
|
},
|
|
251
251
|
"devDependencies": {
|
|
252
252
|
"@lingui/cli": "^5.6.1",
|