@topconsultnpm/sdkui-react 6.20.0-dev1.82 → 6.20.0-dev1.83
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/lib/assets/Toppy-help-center.png +0 -0
- package/lib/components/features/assistant/TMToppyDraggableHelpCenter.d.ts +15 -0
- package/lib/components/features/assistant/TMToppyDraggableHelpCenter.js +460 -0
- package/lib/components/features/assistant/TMToppySpeechBubble.d.ts +11 -0
- package/lib/components/features/assistant/TMToppySpeechBubble.js +126 -0
- package/lib/components/features/documents/TMDcmtForm.js +3 -2
- package/lib/components/features/search/TMSearchResult.js +2 -2
- package/lib/components/index.d.ts +1 -1
- package/lib/components/index.js +1 -1
- package/package.json +1 -1
- package/lib/components/features/assistant/ToppyDraggableHelpCenter.d.ts +0 -30
- package/lib/components/features/assistant/ToppyDraggableHelpCenter.js +0 -482
- package/lib/components/features/assistant/ToppySpeechBubble.d.ts +0 -9
- package/lib/components/features/assistant/ToppySpeechBubble.js +0 -117
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface TMToppyDraggableHelpCenterProps {
|
|
3
|
+
/** Contenuto da visualizzare nella speech bubble */
|
|
4
|
+
content?: React.ReactNode;
|
|
5
|
+
/** Se true, renderizza Toppy nel document.body tramite Portal invece che nel parent */
|
|
6
|
+
usePortal?: boolean;
|
|
7
|
+
/** Allineamento iniziale del componente (destra o sinistra) */
|
|
8
|
+
align?: 'right' | 'left';
|
|
9
|
+
/** Visibilità del componente */
|
|
10
|
+
isVisible?: boolean;
|
|
11
|
+
/** Callback chiamato quando si clicca sull'immagine di Toppy */
|
|
12
|
+
onToppyImageClick?: () => void;
|
|
13
|
+
}
|
|
14
|
+
declare const TMToppyDraggableHelpCenter: (props: TMToppyDraggableHelpCenterProps) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export default TMToppyDraggableHelpCenter;
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import ReactDOM from 'react-dom';
|
|
4
|
+
import styled from 'styled-components';
|
|
5
|
+
import { DeviceType, useDeviceType } from '../../base/TMDeviceProvider';
|
|
6
|
+
import TMToppySpeechBubble from './TMToppySpeechBubble';
|
|
7
|
+
import ToppyHelpCenterImage from '../../../assets/Toppy-help-center.png';
|
|
8
|
+
import { SDKUI_Localizator } from '../../../helper';
|
|
9
|
+
import { IconWindowMaximize } from '../../../helper/TMIcons';
|
|
10
|
+
// Keyframes per l'animazione pulse sull'immagine quando Toppy è collassato
|
|
11
|
+
const pulseAnimation = `
|
|
12
|
+
@keyframes toppyImagePulse {
|
|
13
|
+
0% {
|
|
14
|
+
transform: translateY(-2px) scale(1);
|
|
15
|
+
filter: drop-shadow(0 0 0 rgba(59, 130, 246, 0));
|
|
16
|
+
}
|
|
17
|
+
25% {
|
|
18
|
+
transform: translateY(-2px) scale(1.08);
|
|
19
|
+
filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.6));
|
|
20
|
+
}
|
|
21
|
+
50% {
|
|
22
|
+
transform: translateY(-2px) scale(1);
|
|
23
|
+
filter: drop-shadow(0 0 12px rgba(118, 75, 162, 0.5));
|
|
24
|
+
}
|
|
25
|
+
75% {
|
|
26
|
+
transform: translateY(-2px) scale(1.05);
|
|
27
|
+
filter: drop-shadow(0 0 6px rgba(240, 147, 251, 0.4));
|
|
28
|
+
}
|
|
29
|
+
100% {
|
|
30
|
+
transform: translateY(-2px) scale(1);
|
|
31
|
+
filter: drop-shadow(0 0 0 rgba(59, 130, 246, 0));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
const TMToppyButton = styled.div.attrs((props) => ({
|
|
36
|
+
style: {
|
|
37
|
+
// Applica left/top come stili inline per evitare la generazione di troppe classi CSS
|
|
38
|
+
...(props.$x !== undefined && props.$y !== undefined
|
|
39
|
+
? {
|
|
40
|
+
left: `${props.$x}px`,
|
|
41
|
+
top: `${props.$y}px`,
|
|
42
|
+
bottom: 'auto',
|
|
43
|
+
right: 'auto',
|
|
44
|
+
}
|
|
45
|
+
: {}),
|
|
46
|
+
// Cursore applicato come stile inline
|
|
47
|
+
cursor: props.$isDragging ? 'grabbing' : 'grab',
|
|
48
|
+
},
|
|
49
|
+
})) `
|
|
50
|
+
${pulseAnimation}
|
|
51
|
+
display: ${(props) => (props.$isVisible ? 'flex' : 'none')};
|
|
52
|
+
align-items: center;
|
|
53
|
+
justify-content: center;
|
|
54
|
+
position: ${(props) => props.$usePortal ? 'fixed' : 'absolute'};
|
|
55
|
+
/* Posizionamento di default quando non è draggato (x e y non sono definiti) */
|
|
56
|
+
${(props) => props.$x === undefined || props.$y === undefined ?
|
|
57
|
+
`bottom: 0px;
|
|
58
|
+
${props.$align === 'left' ? 'left: 10px;' : 'right: 0px;'};` : ''}
|
|
59
|
+
width: ${(props) => props.$isCollapsed ? '56px' : '110px'};
|
|
60
|
+
height: ${(props) => props.$isCollapsed ? '56px' : '110px'};
|
|
61
|
+
max-width: 100%;
|
|
62
|
+
max-height: 100%;
|
|
63
|
+
z-index: 2147483647;
|
|
64
|
+
background-color: ${(props) => props.$isCollapsed ? '#ffffff' : 'transparent'};
|
|
65
|
+
border: ${(props) => props.$isCollapsed ? '3px solid #3b82f6' : 'none'};
|
|
66
|
+
border-radius: ${(props) => props.$isCollapsed ? '50%' : '0'};
|
|
67
|
+
padding: 0;
|
|
68
|
+
outline: none;
|
|
69
|
+
user-select: none;
|
|
70
|
+
transition: background-color 0.3s ease, border 0.3s ease, border-radius 0.3s ease, box-shadow 0.3s ease, width 0.3s ease, height 0.3s ease;
|
|
71
|
+
|
|
72
|
+
img {
|
|
73
|
+
width: ${(props) => props.$isCollapsed ? '40px' : '110px'};
|
|
74
|
+
height: ${(props) => props.$isCollapsed ? '40px' : '110px'};
|
|
75
|
+
pointer-events: ${(props) => (props.$isMobile ? 'auto' : 'none')};
|
|
76
|
+
transform: ${(props) => props.$isCollapsed ? 'rotate(0deg)' : props.$align === 'left' ? 'rotate(20deg)' : 'rotate(-20deg)'};
|
|
77
|
+
transition: transform 0.3s ease, width 0.3s ease, height 0.3s ease, filter 0.3s ease;
|
|
78
|
+
object-fit: contain;
|
|
79
|
+
${(props) => props.$isCollapsed && `animation: toppyImagePulse 2.5s ease-in-out infinite;`}
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
/**
|
|
83
|
+
* Pulsante di espansione quando Toppy è minimizzato
|
|
84
|
+
*/
|
|
85
|
+
const ExpandButton = styled.button `
|
|
86
|
+
position: absolute;
|
|
87
|
+
top: -8px;
|
|
88
|
+
right: -8px;
|
|
89
|
+
width: 24px;
|
|
90
|
+
height: 24px;
|
|
91
|
+
border-radius: 50%;
|
|
92
|
+
border: 2px solid rgba(255, 255, 255, 0.9);
|
|
93
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
94
|
+
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4), 0 0 20px rgba(118, 75, 162, 0.2);
|
|
95
|
+
cursor: pointer;
|
|
96
|
+
display: flex;
|
|
97
|
+
align-items: center;
|
|
98
|
+
justify-content: center;
|
|
99
|
+
transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
|
|
100
|
+
z-index: 10001;
|
|
101
|
+
color: white;
|
|
102
|
+
font-size: 14px;
|
|
103
|
+
|
|
104
|
+
&:hover {
|
|
105
|
+
background: linear-gradient(135deg, #764ba2 0%, #f093fb 100%);
|
|
106
|
+
box-shadow: 0 6px 20px rgba(118, 75, 162, 0.6), 0 0 30px rgba(240, 147, 251, 0.4);
|
|
107
|
+
border-color: rgba(255, 255, 255, 1);
|
|
108
|
+
transform: scale(1.1);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
&:active {
|
|
112
|
+
transform: scale(0.95);
|
|
113
|
+
box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
&:focus {
|
|
117
|
+
outline: none;
|
|
118
|
+
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4), 0 0 0 3px rgba(102, 126, 234, 0.2);
|
|
119
|
+
}
|
|
120
|
+
`;
|
|
121
|
+
/**
|
|
122
|
+
* Overlay trasparente per bloccare le interazioni durante il drag
|
|
123
|
+
* Previene problemi di performance con iframe e altri elementi interattivi
|
|
124
|
+
*/
|
|
125
|
+
const DragOverlay = styled.div `
|
|
126
|
+
position: fixed;
|
|
127
|
+
top: 0;
|
|
128
|
+
left: 0;
|
|
129
|
+
right: 0;
|
|
130
|
+
bottom: 0;
|
|
131
|
+
z-index: 2147483646;
|
|
132
|
+
cursor: grabbing;
|
|
133
|
+
`;
|
|
134
|
+
const TMToppyDraggableHelpCenter = (props) => {
|
|
135
|
+
const { content, usePortal, align = 'right', isVisible = true, onToppyImageClick } = props;
|
|
136
|
+
// Get the current device type (e.g., mobile, tablet, desktop) using a custom hook.
|
|
137
|
+
const deviceType = useDeviceType();
|
|
138
|
+
// This avoids unnecessary re-renders by only recalculating when deviceType changes.
|
|
139
|
+
const isMobile = useMemo(() => { return deviceType === DeviceType.MOBILE; }, [deviceType]);
|
|
140
|
+
// Ref per il contenitore principale
|
|
141
|
+
const toppyButtonRef = useRef(null);
|
|
142
|
+
// Ref per la speech bubble per calcolare le sue dimensioni
|
|
143
|
+
const bubbleRef = useRef(null);
|
|
144
|
+
// Dimensioni della bubble (aggiornate dinamicamente)
|
|
145
|
+
const bubbleDimensions = useRef({ width: 0, height: 0 });
|
|
146
|
+
// Posizione corrente del componente (null = posizione di default)
|
|
147
|
+
const [position, setPosition] = useState(null);
|
|
148
|
+
// Stato per tracciare se il componente è in fase di trascinamento
|
|
149
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
150
|
+
// Stato per controllare se il componente è collassato o espanso
|
|
151
|
+
const [isCollapsed, setIsCollapsed] = useState(false);
|
|
152
|
+
// Refs per gestire il drag
|
|
153
|
+
const dragStartPos = useRef(null);
|
|
154
|
+
const dragOffset = useRef(null);
|
|
155
|
+
const hasMoved = useRef(false);
|
|
156
|
+
// Ref per tracciare il dragging dell'ExpandButton
|
|
157
|
+
const isExpandButtonDraggingRef = useRef(false);
|
|
158
|
+
const expandButtonMouseDownPosRef = useRef(null);
|
|
159
|
+
// Soglia minima di movimento in pixel per attivare il drag
|
|
160
|
+
const DRAG_THRESHOLD = 5;
|
|
161
|
+
// Calcola le dimensioni della bubble quando il contenuto cambia
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (bubbleRef.current) {
|
|
164
|
+
const rect = bubbleRef.current.getBoundingClientRect();
|
|
165
|
+
bubbleDimensions.current = { width: rect.width, height: rect.height };
|
|
166
|
+
}
|
|
167
|
+
}, [content, isCollapsed]);
|
|
168
|
+
// Handler per l'inizio del drag (mouse)
|
|
169
|
+
const handleMouseDown = (e) => {
|
|
170
|
+
if (isMobile)
|
|
171
|
+
return;
|
|
172
|
+
e.preventDefault();
|
|
173
|
+
const rect = toppyButtonRef.current?.getBoundingClientRect();
|
|
174
|
+
if (!rect)
|
|
175
|
+
return;
|
|
176
|
+
// Salva la posizione iniziale del mouse e l'offset rispetto al componente
|
|
177
|
+
dragStartPos.current = { x: e.clientX, y: e.clientY };
|
|
178
|
+
dragOffset.current = {
|
|
179
|
+
x: e.clientX - rect.left,
|
|
180
|
+
y: e.clientY - rect.top,
|
|
181
|
+
};
|
|
182
|
+
hasMoved.current = false;
|
|
183
|
+
// Aggiungi listener globali per il movimento e il rilascio
|
|
184
|
+
document.addEventListener('mousemove', handleDragMove);
|
|
185
|
+
document.addEventListener('mouseup', handleDragEnd);
|
|
186
|
+
};
|
|
187
|
+
// Handler per l'inizio del drag (touch)
|
|
188
|
+
const handleTouchStart = (e) => {
|
|
189
|
+
if (!isMobile)
|
|
190
|
+
return;
|
|
191
|
+
const touch = e.touches[0];
|
|
192
|
+
if (!touch)
|
|
193
|
+
return;
|
|
194
|
+
const rect = toppyButtonRef.current?.getBoundingClientRect();
|
|
195
|
+
if (!rect)
|
|
196
|
+
return;
|
|
197
|
+
// Salva la posizione iniziale del touch e l'offset rispetto al componente
|
|
198
|
+
dragStartPos.current = { x: touch.clientX, y: touch.clientY };
|
|
199
|
+
dragOffset.current = {
|
|
200
|
+
x: touch.clientX - rect.left,
|
|
201
|
+
y: touch.clientY - rect.top,
|
|
202
|
+
};
|
|
203
|
+
hasMoved.current = false;
|
|
204
|
+
// Aggiungi listener globali per il movimento e il rilascio
|
|
205
|
+
document.addEventListener('touchmove', handleDragMove, { passive: false });
|
|
206
|
+
document.addEventListener('touchend', handleDragEnd);
|
|
207
|
+
};
|
|
208
|
+
// Handler unificato per il movimento durante il drag (mouse e touch)
|
|
209
|
+
const handleDragMove = (e) => {
|
|
210
|
+
if (!dragStartPos.current || !dragOffset.current || !toppyButtonRef.current)
|
|
211
|
+
return;
|
|
212
|
+
// Estrae le coordinate dal tipo di evento appropriato
|
|
213
|
+
const clientX = 'touches' in e ? e.touches[0]?.clientX : e.clientX;
|
|
214
|
+
const clientY = 'touches' in e ? e.touches[0]?.clientY : e.clientY;
|
|
215
|
+
if (clientX === undefined || clientY === undefined)
|
|
216
|
+
return;
|
|
217
|
+
// Calcola la distanza dal punto iniziale
|
|
218
|
+
const deltaX = clientX - dragStartPos.current.x;
|
|
219
|
+
const deltaY = clientY - dragStartPos.current.y;
|
|
220
|
+
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
221
|
+
// Attiva il drag solo se il movimento supera la soglia
|
|
222
|
+
if (!hasMoved.current && distance < DRAG_THRESHOLD)
|
|
223
|
+
return;
|
|
224
|
+
if (!hasMoved.current) {
|
|
225
|
+
hasMoved.current = true;
|
|
226
|
+
setIsDragging(true);
|
|
227
|
+
}
|
|
228
|
+
// Previeni lo scroll durante il drag (solo per touch)
|
|
229
|
+
if ('touches' in e) {
|
|
230
|
+
e.preventDefault();
|
|
231
|
+
}
|
|
232
|
+
// Calcola la nuova posizione
|
|
233
|
+
let newX = clientX - dragOffset.current.x;
|
|
234
|
+
let newY = clientY - dragOffset.current.y;
|
|
235
|
+
// Se non usa portal, converti le coordinate da viewport a relative al parent
|
|
236
|
+
if (!usePortal) {
|
|
237
|
+
const parentElement = toppyButtonRef.current.offsetParent;
|
|
238
|
+
if (parentElement) {
|
|
239
|
+
const parentRect = parentElement.getBoundingClientRect();
|
|
240
|
+
newX -= parentRect.left;
|
|
241
|
+
newY -= parentRect.top;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
// Ottieni le dimensioni del componente
|
|
245
|
+
const componentRect = toppyButtonRef.current.getBoundingClientRect();
|
|
246
|
+
const componentWidth = componentRect.width;
|
|
247
|
+
const componentHeight = componentRect.height;
|
|
248
|
+
// Limiti del parent considerando anche la bubble
|
|
249
|
+
let maxX = 0;
|
|
250
|
+
let maxY = 0;
|
|
251
|
+
let minX = 0;
|
|
252
|
+
let minY = 0;
|
|
253
|
+
// Considera le dimensioni della bubble per i limiti solo se non è collassato
|
|
254
|
+
const bubbleWidth = isCollapsed ? 0 : (bubbleDimensions.current.width || 0);
|
|
255
|
+
const bubbleHeight = isCollapsed ? 0 : (bubbleDimensions.current.height || 0);
|
|
256
|
+
// Offset dell'ExpandButton quando Toppy è collassato (top: -8px, right: -8px)
|
|
257
|
+
const expandButtonOffset = isCollapsed ? 8 : 0;
|
|
258
|
+
if (usePortal) {
|
|
259
|
+
// Se usa portal, i limiti sono quelli della viewport
|
|
260
|
+
// Limite superiore: deve lasciare spazio per la bubble sopra o per l'ExpandButton se collassato
|
|
261
|
+
minY = isCollapsed ? expandButtonOffset : bubbleHeight;
|
|
262
|
+
// Limite inferiore: il componente non può uscire dalla viewport
|
|
263
|
+
maxY = window.innerHeight - componentHeight;
|
|
264
|
+
// Limiti orizzontali dipendono dall'allineamento della bubble
|
|
265
|
+
if (align === 'right') {
|
|
266
|
+
// Bubble a sinistra del componente: serve spazio a sinistra
|
|
267
|
+
minX = Math.max(0, bubbleWidth - componentWidth);
|
|
268
|
+
// Quando collassato, l'ExpandButton sporge a destra di 8px
|
|
269
|
+
maxX = window.innerWidth - componentWidth - expandButtonOffset;
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
// Bubble a destra del componente: serve spazio a destra
|
|
273
|
+
minX = 0;
|
|
274
|
+
maxX = window.innerWidth - Math.max(componentWidth, bubbleWidth) - expandButtonOffset;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
// Se non usa portal, le coordinate devono essere relative al parent
|
|
279
|
+
const parentElement = toppyButtonRef.current.offsetParent;
|
|
280
|
+
if (parentElement) {
|
|
281
|
+
// Usa le dimensioni del parent come riferimento
|
|
282
|
+
const parentWidth = parentElement.clientWidth;
|
|
283
|
+
const parentHeight = parentElement.clientHeight;
|
|
284
|
+
// Limite superiore: deve lasciare spazio per la bubble sopra o per l'ExpandButton se collassato
|
|
285
|
+
minY = isCollapsed ? expandButtonOffset : bubbleHeight;
|
|
286
|
+
// Limite inferiore: il componente non può uscire dal parent
|
|
287
|
+
maxY = parentHeight - componentHeight;
|
|
288
|
+
// Limiti orizzontali dipendono dall'allineamento della bubble
|
|
289
|
+
if (align === 'right') {
|
|
290
|
+
// Bubble a sinistra del componente: serve spazio a sinistra
|
|
291
|
+
minX = Math.max(0, bubbleWidth - componentWidth);
|
|
292
|
+
// Quando collassato, l'ExpandButton sporge a destra di 8px
|
|
293
|
+
maxX = parentWidth - componentWidth - expandButtonOffset;
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
// Bubble a destra del componente: serve spazio a destra
|
|
297
|
+
minX = 0;
|
|
298
|
+
maxX = parentWidth - Math.max(componentWidth, bubbleWidth) - expandButtonOffset;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// Applica i limiti
|
|
303
|
+
newX = Math.max(minX, Math.min(newX, maxX));
|
|
304
|
+
newY = Math.max(minY, Math.min(newY, maxY));
|
|
305
|
+
setPosition({ x: newX, y: newY });
|
|
306
|
+
};
|
|
307
|
+
// Handler unificato per il rilascio del drag (mouse e touch)
|
|
308
|
+
const handleDragEnd = () => {
|
|
309
|
+
dragStartPos.current = null;
|
|
310
|
+
dragOffset.current = null;
|
|
311
|
+
setIsDragging(false);
|
|
312
|
+
// Rimuovi tutti i listener globali
|
|
313
|
+
document.removeEventListener('mousemove', handleDragMove);
|
|
314
|
+
document.removeEventListener('mouseup', handleDragEnd);
|
|
315
|
+
document.removeEventListener('touchmove', handleDragMove);
|
|
316
|
+
document.removeEventListener('touchend', handleDragEnd);
|
|
317
|
+
};
|
|
318
|
+
// Handler per il doppio click (collassa/espande Toppy su desktop)
|
|
319
|
+
const toggleCollapse = () => {
|
|
320
|
+
setIsCollapsed(prev => {
|
|
321
|
+
const newIsCollapsed = !prev;
|
|
322
|
+
// Se stiamo espandendo (da collassato a espanso), dobbiamo verificare i limiti
|
|
323
|
+
if (!newIsCollapsed && position && toppyButtonRef.current && content) {
|
|
324
|
+
// Usa setTimeout per permettere al DOM di aggiornarsi con le nuove dimensioni
|
|
325
|
+
setTimeout(() => {
|
|
326
|
+
if (!toppyButtonRef.current)
|
|
327
|
+
return;
|
|
328
|
+
// Dimensioni espanse del componente (110px come da styled-component)
|
|
329
|
+
const expandedSize = 110;
|
|
330
|
+
// Ottieni le dimensioni della bubble (usa valori di default se non disponibili)
|
|
331
|
+
const bubbleWidth = bubbleDimensions.current.width || 250;
|
|
332
|
+
const bubbleHeight = bubbleDimensions.current.height || 100;
|
|
333
|
+
let newX = position.x;
|
|
334
|
+
let newY = position.y;
|
|
335
|
+
let needsUpdate = false;
|
|
336
|
+
if (usePortal) {
|
|
337
|
+
// Limiti della viewport considerando la bubble
|
|
338
|
+
const minY = bubbleHeight;
|
|
339
|
+
const maxY = window.innerHeight - expandedSize;
|
|
340
|
+
let minX;
|
|
341
|
+
let maxX;
|
|
342
|
+
if (align === 'right') {
|
|
343
|
+
minX = Math.max(0, bubbleWidth - expandedSize);
|
|
344
|
+
maxX = window.innerWidth - expandedSize;
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
minX = 0;
|
|
348
|
+
maxX = window.innerWidth - Math.max(expandedSize, bubbleWidth);
|
|
349
|
+
}
|
|
350
|
+
// Verifica e correggi la posizione
|
|
351
|
+
if (newX < minX) {
|
|
352
|
+
newX = minX;
|
|
353
|
+
needsUpdate = true;
|
|
354
|
+
}
|
|
355
|
+
if (newX > maxX) {
|
|
356
|
+
newX = maxX;
|
|
357
|
+
needsUpdate = true;
|
|
358
|
+
}
|
|
359
|
+
if (newY < minY) {
|
|
360
|
+
newY = minY;
|
|
361
|
+
needsUpdate = true;
|
|
362
|
+
}
|
|
363
|
+
if (newY > maxY) {
|
|
364
|
+
newY = maxY;
|
|
365
|
+
needsUpdate = true;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
// Limiti del parent
|
|
370
|
+
const offsetParent = toppyButtonRef.current.offsetParent;
|
|
371
|
+
if (offsetParent) {
|
|
372
|
+
const minY = bubbleHeight;
|
|
373
|
+
const maxY = offsetParent.clientHeight - expandedSize;
|
|
374
|
+
let minX;
|
|
375
|
+
let maxX;
|
|
376
|
+
if (align === 'right') {
|
|
377
|
+
minX = Math.max(0, bubbleWidth - expandedSize);
|
|
378
|
+
maxX = offsetParent.clientWidth - expandedSize;
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
minX = 0;
|
|
382
|
+
maxX = offsetParent.clientWidth - Math.max(expandedSize, bubbleWidth);
|
|
383
|
+
}
|
|
384
|
+
// Verifica e correggi la posizione
|
|
385
|
+
if (newX < minX) {
|
|
386
|
+
newX = minX;
|
|
387
|
+
needsUpdate = true;
|
|
388
|
+
}
|
|
389
|
+
if (newX > maxX) {
|
|
390
|
+
newX = maxX;
|
|
391
|
+
needsUpdate = true;
|
|
392
|
+
}
|
|
393
|
+
if (newY < minY) {
|
|
394
|
+
newY = minY;
|
|
395
|
+
needsUpdate = true;
|
|
396
|
+
}
|
|
397
|
+
if (newY > maxY) {
|
|
398
|
+
newY = maxY;
|
|
399
|
+
needsUpdate = true;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
// Aggiorna la posizione solo se necessario
|
|
404
|
+
if (needsUpdate) {
|
|
405
|
+
setPosition({ x: newX, y: newY });
|
|
406
|
+
}
|
|
407
|
+
}, 50); // Piccolo delay per permettere l'aggiornamento delle dimensioni
|
|
408
|
+
}
|
|
409
|
+
onToppyImageClick?.();
|
|
410
|
+
return newIsCollapsed;
|
|
411
|
+
});
|
|
412
|
+
};
|
|
413
|
+
// Cleanup degli event listener al dismount
|
|
414
|
+
useEffect(() => {
|
|
415
|
+
return () => {
|
|
416
|
+
document.removeEventListener('mousemove', handleDragMove);
|
|
417
|
+
document.removeEventListener('mouseup', handleDragEnd);
|
|
418
|
+
document.removeEventListener('touchmove', handleDragMove);
|
|
419
|
+
document.removeEventListener('touchend', handleDragEnd);
|
|
420
|
+
};
|
|
421
|
+
}, []);
|
|
422
|
+
// Reset della posizione quando cambia la dimensione della finestra/parent
|
|
423
|
+
// Questo evita che Toppy rimanga nascosto oltre i limiti dopo un resize
|
|
424
|
+
useEffect(() => {
|
|
425
|
+
const handleResize = () => {
|
|
426
|
+
// Resetta alla posizione iniziale (bottom-right o bottom-left in base ad align)
|
|
427
|
+
setPosition(null);
|
|
428
|
+
};
|
|
429
|
+
window.addEventListener('resize', handleResize);
|
|
430
|
+
return () => {
|
|
431
|
+
window.removeEventListener('resize', handleResize);
|
|
432
|
+
};
|
|
433
|
+
}, []);
|
|
434
|
+
const toppyContent = (_jsxs(_Fragment, { children: [isDragging && _jsx(DragOverlay, {}), _jsxs(TMToppyButton, { ref: toppyButtonRef, "$align": align, "$isDragging": isDragging, "$isVisible": isVisible, "$isCollapsed": isCollapsed, "$isMobile": isMobile, "$usePortal": usePortal, onContextMenu: (e) => e.preventDefault(), onMouseDown: !isMobile ? handleMouseDown : undefined, onTouchStart: isMobile ? handleTouchStart : undefined, onDoubleClick: !isMobile ? toggleCollapse : undefined, "$x": position?.x, "$y": position?.y, children: [(content && !isCollapsed) && _jsx(TMToppySpeechBubble, { ref: bubbleRef, align: align, onClose: toggleCollapse, children: content }), (content && isCollapsed) && (_jsx(ExpandButton, { onMouseDown: (e) => {
|
|
435
|
+
isExpandButtonDraggingRef.current = false;
|
|
436
|
+
expandButtonMouseDownPosRef.current = { x: e.clientX, y: e.clientY };
|
|
437
|
+
}, onMouseMove: (e) => {
|
|
438
|
+
if (!expandButtonMouseDownPosRef.current)
|
|
439
|
+
return;
|
|
440
|
+
const deltaX = Math.abs(e.clientX - expandButtonMouseDownPosRef.current.x);
|
|
441
|
+
const deltaY = Math.abs(e.clientY - expandButtonMouseDownPosRef.current.y);
|
|
442
|
+
// Considera drag solo se il movimento supera 3px
|
|
443
|
+
if (deltaX > 3 || deltaY > 3) {
|
|
444
|
+
isExpandButtonDraggingRef.current = true;
|
|
445
|
+
}
|
|
446
|
+
}, onMouseUp: () => {
|
|
447
|
+
expandButtonMouseDownPosRef.current = null;
|
|
448
|
+
}, onClick: (e) => {
|
|
449
|
+
if (isExpandButtonDraggingRef.current) {
|
|
450
|
+
e.stopPropagation();
|
|
451
|
+
e.preventDefault();
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
e.stopPropagation();
|
|
455
|
+
toggleCollapse();
|
|
456
|
+
}, onContextMenu: (e) => e.preventDefault(), "aria-label": SDKUI_Localizator.Maximize, title: SDKUI_Localizator.Maximize, type: "button", children: _jsx(IconWindowMaximize, {}) })), _jsx("img", { src: ToppyHelpCenterImage, alt: "Toppy Help", draggable: false })] })] }));
|
|
457
|
+
// Renderizza nel document.body usando un Portal se usePortal è true, altrimenti renderizza normalmente
|
|
458
|
+
return usePortal ? ReactDOM.createPortal(toppyContent, document.body) : toppyContent;
|
|
459
|
+
};
|
|
460
|
+
export default TMToppyDraggableHelpCenter;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface TMToppySpeechBubbleProps {
|
|
3
|
+
/** Contenuto da visualizzare nella speech bubble */
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
/** Allineamento della speech bubble (destra o sinistra) */
|
|
6
|
+
align?: 'right' | 'left';
|
|
7
|
+
/** Callback per chiudere/minimizzare la bubble */
|
|
8
|
+
onClose?: () => void;
|
|
9
|
+
}
|
|
10
|
+
declare const TMToppySpeechBubble: React.ForwardRefExoticComponent<TMToppySpeechBubbleProps & React.RefAttributes<HTMLDivElement>>;
|
|
11
|
+
export default TMToppySpeechBubble;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useRef } from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { SDKUI_Localizator } from '../../../helper';
|
|
5
|
+
import { IconWindowMinimize } from '../../../helper/TMIcons';
|
|
6
|
+
// Offset del CloseButton che sporge oltre i bordi della bubble
|
|
7
|
+
const CLOSE_BUTTON_OFFSET = 8;
|
|
8
|
+
/**
|
|
9
|
+
* Wrapper che include lo spazio per il CloseButton sporgente
|
|
10
|
+
* Il ref viene passato qui per includere le dimensioni complete nel calcolo
|
|
11
|
+
*/
|
|
12
|
+
const BubbleWrapper = styled.div `
|
|
13
|
+
position: relative;
|
|
14
|
+
padding-top: ${({ $hasCloseButton }) => $hasCloseButton ? `${CLOSE_BUTTON_OFFSET}px` : '0'};
|
|
15
|
+
padding-right: ${({ $hasCloseButton }) => $hasCloseButton ? `${CLOSE_BUTTON_OFFSET}px` : '0'};
|
|
16
|
+
`;
|
|
17
|
+
/**
|
|
18
|
+
* Pulsante di chiusura/minimizzazione in alto a destra della bubble
|
|
19
|
+
* Posizionato all'interno del padding del BubbleWrapper
|
|
20
|
+
*/
|
|
21
|
+
const CloseButton = styled.button `
|
|
22
|
+
position: absolute;
|
|
23
|
+
top: 0;
|
|
24
|
+
right: 0;
|
|
25
|
+
width: 24px;
|
|
26
|
+
height: 24px;
|
|
27
|
+
border-radius: 50%;
|
|
28
|
+
border: 2px solid rgba(255, 255, 255, 0.9);
|
|
29
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
30
|
+
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4), 0 0 20px rgba(118, 75, 162, 0.2);
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
display: flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
justify-content: center;
|
|
35
|
+
transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
|
|
36
|
+
z-index: 10001;
|
|
37
|
+
color: white;
|
|
38
|
+
font-size: 14px;
|
|
39
|
+
|
|
40
|
+
&:hover {
|
|
41
|
+
background: linear-gradient(135deg, #764ba2 0%, #f093fb 100%);
|
|
42
|
+
box-shadow: 0 6px 20px rgba(118, 75, 162, 0.6), 0 0 30px rgba(240, 147, 251, 0.4);
|
|
43
|
+
border-color: rgba(255, 255, 255, 1);
|
|
44
|
+
transform: scale(1.1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&:active {
|
|
48
|
+
transform: scale(0.95);
|
|
49
|
+
box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&:focus {
|
|
53
|
+
outline: none;
|
|
54
|
+
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4), 0 0 0 3px rgba(102, 126, 234, 0.2);
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
const BubbleContainer = styled.div `
|
|
58
|
+
position: absolute;
|
|
59
|
+
bottom: 100%;
|
|
60
|
+
${({ $align }) => $align === 'right' ? 'right: 0px;' : 'left: 0px;'}
|
|
61
|
+
z-index: 10;
|
|
62
|
+
`;
|
|
63
|
+
const Bubble = styled.div `
|
|
64
|
+
position: relative;
|
|
65
|
+
background: linear-gradient(180deg, rgba(0, 113, 188, 0.45) 0%,rgba(27, 20, 100, 0.65) 100%);
|
|
66
|
+
color: #333;
|
|
67
|
+
padding: 10px;
|
|
68
|
+
box-sizing: border-box;
|
|
69
|
+
border-radius: 18px;
|
|
70
|
+
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
|
|
71
|
+
font-size: 14px;
|
|
72
|
+
line-height: 1.5;
|
|
73
|
+
width: max-content;
|
|
74
|
+
|
|
75
|
+
// Arrow styles
|
|
76
|
+
&::after {
|
|
77
|
+
transform: ${({ $align }) => ($align === 'left' ? 'skewX(15deg)' : 'skewX(-15deg)')};
|
|
78
|
+
content: "";
|
|
79
|
+
position: absolute;
|
|
80
|
+
top: 100%;
|
|
81
|
+
${({ $align }) => ($align === 'left' ? 'left: 20px;' : 'right: 15px;')}
|
|
82
|
+
border-width: 22px 22px 0 0;
|
|
83
|
+
border-style: solid;
|
|
84
|
+
border-color: rgba(27, 20, 100, 0.65) transparent;
|
|
85
|
+
display: block;
|
|
86
|
+
width: 0;
|
|
87
|
+
height: 0;
|
|
88
|
+
z-index: 1;
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
const Content = styled.div `position: relative; z-index: 1;`;
|
|
92
|
+
const TMToppySpeechBubble = forwardRef((props, ref) => {
|
|
93
|
+
const { children, align = 'right', onClose } = props;
|
|
94
|
+
// Ref per tracciare il dragging del CloseButton
|
|
95
|
+
const isCloseButtonDraggingRef = useRef(false);
|
|
96
|
+
const closeButtonMouseDownPosRef = useRef(null);
|
|
97
|
+
const handleMouseDown = (e) => {
|
|
98
|
+
isCloseButtonDraggingRef.current = false;
|
|
99
|
+
closeButtonMouseDownPosRef.current = { x: e.clientX, y: e.clientY };
|
|
100
|
+
};
|
|
101
|
+
const handleMouseMove = (e) => {
|
|
102
|
+
if (!closeButtonMouseDownPosRef.current)
|
|
103
|
+
return;
|
|
104
|
+
const deltaX = Math.abs(e.clientX - closeButtonMouseDownPosRef.current.x);
|
|
105
|
+
const deltaY = Math.abs(e.clientY - closeButtonMouseDownPosRef.current.y);
|
|
106
|
+
// Considera drag solo se il movimento supera 3px
|
|
107
|
+
if (deltaX > 3 || deltaY > 3) {
|
|
108
|
+
isCloseButtonDraggingRef.current = true;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const handleMouseUp = () => {
|
|
112
|
+
closeButtonMouseDownPosRef.current = null;
|
|
113
|
+
};
|
|
114
|
+
const handleClick = (e) => {
|
|
115
|
+
if (isCloseButtonDraggingRef.current) {
|
|
116
|
+
e.stopPropagation();
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
e.stopPropagation();
|
|
121
|
+
onClose?.();
|
|
122
|
+
};
|
|
123
|
+
return (_jsx(BubbleContainer, { "$align": align, children: _jsxs(BubbleWrapper, { ref: ref, "$hasCloseButton": !!onClose, children: [onClose && (_jsx(CloseButton, { onMouseDown: handleMouseDown, onMouseMove: handleMouseMove, onMouseUp: handleMouseUp, onClick: handleClick, "aria-label": SDKUI_Localizator.Minimize, title: SDKUI_Localizator.Minimize, type: "button", children: _jsx(IconWindowMinimize, {}) })), _jsx(Bubble, { "$align": align, children: _jsx(Content, { children: children }) })] }) }));
|
|
124
|
+
});
|
|
125
|
+
TMToppySpeechBubble.displayName = 'TMToppySpeechBubble';
|
|
126
|
+
export default TMToppySpeechBubble;
|
|
@@ -40,12 +40,12 @@ import TMDcmtTasks from './TMDcmtTasks';
|
|
|
40
40
|
import TMToppyMessage from '../../../helper/TMToppyMessage';
|
|
41
41
|
import { getTaskAssignedToMe } from '../tasks/TMTasksUtils';
|
|
42
42
|
import TMCustomButton from '../../base/TMCustomButton';
|
|
43
|
-
import ToppyDraggableHelpCenter from '../assistant/ToppyDraggableHelpCenter';
|
|
44
43
|
import { useCheckInOutOperations } from '../../../hooks/useCheckInOutOperations';
|
|
45
44
|
import TMViewHistoryDcmt from '../search/TMViewHistoryDcmt';
|
|
46
45
|
import TMDcmtCheckoutInfoForm from '../search/TMDcmtCheckoutInfoForm';
|
|
47
46
|
import styled from 'styled-components';
|
|
48
47
|
import { ContextMenu } from '../../NewComponents/ContextMenu';
|
|
48
|
+
import TMToppyDraggableHelpCenter from '../assistant/TMToppyDraggableHelpCenter';
|
|
49
49
|
//#region Interfaces, Types and Enums
|
|
50
50
|
/**
|
|
51
51
|
* Definisce il contesto da cui è stato invocato il TMDcmtForm.
|
|
@@ -638,6 +638,7 @@ const TMDcmtForm = ({ allTasks = [], getAllTasks, deleteTaskByIdsCallback, addTa
|
|
|
638
638
|
const showToppyForApprove = useMemo(() => layoutMode === LayoutModes.Update && !fetchError && workItems.length > 0 && !isOpenDetails && !isOpenMaster, [layoutMode, fetchError, workItems.length, isOpenDetails, isOpenMaster]);
|
|
639
639
|
const showToppyForCompleteMoreInfo = useMemo(() => layoutMode === LayoutModes.Update && !!isTaskMoreInfo(taskMoreInfo?.name) && taskMoreInfo?.state !== Task_States.Completed, [layoutMode, taskMoreInfo?.name, taskMoreInfo?.state]);
|
|
640
640
|
const showToppyForReferences = useMemo(() => allowButtonsRefs && layoutMode === LayoutModes.Update && !!(dcmtReferences && dcmtReferences.length > 0) && !isOpenDetails && !isOpenMaster, [allowButtonsRefs, layoutMode, dcmtReferences, isOpenDetails, isOpenMaster]);
|
|
641
|
+
const isToppyVisible = useMemo(() => Boolean((showToppyForApprove || showToppyForCompleteMoreInfo || showToppyForReferences) && !openS4TViewer), [showToppyForApprove, showToppyForCompleteMoreInfo, showToppyForReferences, openS4TViewer]);
|
|
641
642
|
const isMobile = useMemo(() => deviceType === DeviceType.MOBILE, [deviceType]);
|
|
642
643
|
const isApprView = useMemo(() => {
|
|
643
644
|
if (!fromDTD)
|
|
@@ -1552,7 +1553,7 @@ const TMDcmtForm = ({ allTasks = [], getAllTasks, deleteTaskByIdsCallback, addTa
|
|
|
1552
1553
|
isEditable: true,
|
|
1553
1554
|
value: FormulaHelper.addFormulaTag(newFormula.expression)
|
|
1554
1555
|
}));
|
|
1555
|
-
} }), showApprovePopup && _jsx(WorkFlowApproveRejectPopUp, { deviceType: deviceType, onCompleted: handleWFOperationCompleted, TID: approvalVID, DID: DID, isReject: 0, onClose: () => setShowApprovePopup(false) }), showRejectPopup && _jsx(WorkFlowApproveRejectPopUp, { deviceType: deviceType, onCompleted: handleWFOperationCompleted, TID: approvalVID, DID: DID, isReject: 1, onClose: () => setShowRejectPopup(false) }), showReAssignPopup && _jsx(WorkFlowReAssignPopUp, { deviceType: deviceType, onCompleted: handleWFOperationCompleted, TID: approvalVID, DID: DID, onClose: () => setShowReAssignPopup(false) }), showMoreInfoPopup && _jsx(WorkFlowMoreInfoPopUp, { deviceType: deviceType, onCompleted: handleWFOperationCompleted, TID: approvalVID, DID: DID, onClose: () => setShowMoreInfoPopup(false) }), (isModal && onClose) && _jsx("div", { id: "TMDcmtFormShowConfirmForClose-" + id })] }) }), _jsx(
|
|
1556
|
+
} }), showApprovePopup && _jsx(WorkFlowApproveRejectPopUp, { deviceType: deviceType, onCompleted: handleWFOperationCompleted, TID: approvalVID, DID: DID, isReject: 0, onClose: () => setShowApprovePopup(false) }), showRejectPopup && _jsx(WorkFlowApproveRejectPopUp, { deviceType: deviceType, onCompleted: handleWFOperationCompleted, TID: approvalVID, DID: DID, isReject: 1, onClose: () => setShowRejectPopup(false) }), showReAssignPopup && _jsx(WorkFlowReAssignPopUp, { deviceType: deviceType, onCompleted: handleWFOperationCompleted, TID: approvalVID, DID: DID, onClose: () => setShowReAssignPopup(false) }), showMoreInfoPopup && _jsx(WorkFlowMoreInfoPopUp, { deviceType: deviceType, onCompleted: handleWFOperationCompleted, TID: approvalVID, DID: DID, onClose: () => setShowMoreInfoPopup(false) }), (isModal && onClose) && _jsx("div", { id: "TMDcmtFormShowConfirmForClose-" + id })] }) }), _jsx(TMToppyDraggableHelpCenter, { isVisible: isToppyVisible, content: _jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: '10px' }, children: [showToppyForApprove && (workItems.length === 1 ?
|
|
1556
1557
|
_jsx(WorkFlowOperationButtons, { deviceType: deviceType, onApprove: () => setShowApprovePopup(true), onSignApprove: handleSignApprove, onReject: () => setShowRejectPopup(true), onReAssign: () => setShowReAssignPopup(true), onMoreInfo: () => setShowMoreInfoPopup(true), dtd: fromDTD })
|
|
1557
1558
|
:
|
|
1558
1559
|
_jsxs("div", { style: { padding: 10, color: 'white', maxWidth: '180px', borderRadius: 10, background: '#1B1464 0% 0% no-repeat padding-box', border: '1px solid #FFFFFF' }, children: [`Questo documento è associato a ${workItems.length} workitem.`, _jsx("br", {}), `Per approvare, vai alla pagina "Approvazione workflow".`] })), showToppyForCompleteMoreInfo && (_jsxs(_Fragment, { children: [_jsx("div", { style: { padding: 10, color: 'white', maxWidth: '180px', borderRadius: 10, background: '#1B1464 0% 0% no-repeat padding-box', border: '1px solid #FFFFFF' }, children: `${SDKUI_Localizator.MoreInfoCompleteRequestSentBy} ${taskMoreInfo?.fromName}!` }), _jsx(TMButton, { caption: SDKUI_Localizator.CommentAndComplete, color: 'success', showTooltip: false, onClick: () => {
|