@memori.ai/memori-react 8.5.2 → 8.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/CHANGELOG.md +19 -0
- package/dist/components/MemoriArtifactSystem/components/ArtifactActions/ArtifactActions.d.ts +3 -3
- package/dist/components/MemoriArtifactSystem/components/ArtifactActions/ArtifactActions.js +2 -2
- package/dist/components/MemoriArtifactSystem/components/ArtifactActions/ArtifactActions.js.map +1 -1
- package/dist/components/MemoriArtifactSystem/components/ArtifactActions/components/CopyButtonWithDropdown.js +129 -3
- package/dist/components/MemoriArtifactSystem/components/ArtifactActions/components/CopyButtonWithDropdown.js.map +1 -1
- package/dist/components/MemoriArtifactSystem/components/ArtifactActions/hooks/useCopyArtifact.js +189 -26
- package/dist/components/MemoriArtifactSystem/components/ArtifactActions/hooks/useCopyArtifact.js.map +1 -1
- package/dist/components/MemoriArtifactSystem/components/ArtifactActions/utils/PDFExporter.d.ts +2 -0
- package/dist/components/MemoriArtifactSystem/components/ArtifactActions/utils/PDFExporter.js +138 -17
- package/dist/components/MemoriArtifactSystem/components/ArtifactActions/utils/PDFExporter.js.map +1 -1
- package/dist/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.css +12 -0
- package/dist/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.js +63 -24
- package/dist/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.js.map +1 -1
- package/dist/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js +8 -3
- package/dist/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js.map +1 -1
- package/dist/components/MemoriArtifactSystem/components/ArtifactPreview/ArtifactPreview.css +2 -0
- package/dist/helpers/utils.d.ts +2 -0
- package/dist/helpers/utils.js +19 -1
- package/dist/helpers/utils.js.map +1 -1
- package/dist/locales/de.json +2 -1
- package/dist/locales/en.json +2 -1
- package/dist/locales/es.json +2 -1
- package/dist/locales/fr.json +2 -1
- package/dist/locales/it.json +2 -1
- package/esm/components/MemoriArtifactSystem/components/ArtifactActions/ArtifactActions.d.ts +3 -3
- package/esm/components/MemoriArtifactSystem/components/ArtifactActions/ArtifactActions.js +2 -2
- package/esm/components/MemoriArtifactSystem/components/ArtifactActions/ArtifactActions.js.map +1 -1
- package/esm/components/MemoriArtifactSystem/components/ArtifactActions/components/CopyButtonWithDropdown.js +129 -3
- package/esm/components/MemoriArtifactSystem/components/ArtifactActions/components/CopyButtonWithDropdown.js.map +1 -1
- package/esm/components/MemoriArtifactSystem/components/ArtifactActions/hooks/useCopyArtifact.js +188 -26
- package/esm/components/MemoriArtifactSystem/components/ArtifactActions/hooks/useCopyArtifact.js.map +1 -1
- package/esm/components/MemoriArtifactSystem/components/ArtifactActions/utils/PDFExporter.d.ts +2 -0
- package/esm/components/MemoriArtifactSystem/components/ArtifactActions/utils/PDFExporter.js +138 -17
- package/esm/components/MemoriArtifactSystem/components/ArtifactActions/utils/PDFExporter.js.map +1 -1
- package/esm/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.css +12 -0
- package/esm/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.js +63 -24
- package/esm/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.js.map +1 -1
- package/esm/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js +8 -3
- package/esm/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js.map +1 -1
- package/esm/components/MemoriArtifactSystem/components/ArtifactPreview/ArtifactPreview.css +2 -0
- package/esm/helpers/utils.d.ts +2 -0
- package/esm/helpers/utils.js +16 -0
- package/esm/helpers/utils.js.map +1 -1
- package/esm/locales/de.json +2 -1
- package/esm/locales/en.json +2 -1
- package/esm/locales/es.json +2 -1
- package/esm/locales/fr.json +2 -1
- package/esm/locales/it.json +2 -1
- package/package.json +1 -1
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/ArtifactActions.tsx +5 -5
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/components/CopyButtonWithDropdown.tsx +141 -3
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/hooks/useCopyArtifact.ts +211 -33
- package/src/components/MemoriArtifactSystem/components/ArtifactActions/utils/PDFExporter.ts +190 -26
- package/src/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.css +12 -0
- package/src/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.tsx +191 -161
- package/src/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.tsx +8 -3
- package/src/components/MemoriArtifactSystem/components/ArtifactPreview/ArtifactPreview.css +2 -0
- package/src/helpers/utils.ts +21 -0
- package/src/locales/de.json +2 -1
- package/src/locales/en.json +2 -1
- package/src/locales/es.json +2 -1
- package/src/locales/fr.json +2 -1
- package/src/locales/it.json +2 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* PDFExporter utility for converting markdown content to PDF
|
|
3
3
|
* Uses browser's print functionality with optimized CSS for PDF output
|
|
4
|
+
* Includes Safari-specific workarounds for better compatibility
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
7
|
import { PDFExportOptions } from '../types';
|
|
7
8
|
import { marked } from 'marked';
|
|
9
|
+
import { isSafari, isSafariIOS } from '../../../../../helpers/utils';
|
|
8
10
|
|
|
9
11
|
export class PDFExporter {
|
|
10
12
|
private static instance: PDFExporter;
|
|
@@ -209,6 +211,115 @@ export class PDFExporter {
|
|
|
209
211
|
`;
|
|
210
212
|
}
|
|
211
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Safari-specific PDF export using improved approach
|
|
216
|
+
*/
|
|
217
|
+
async exportAsPDFSafari(
|
|
218
|
+
content: string,
|
|
219
|
+
title: string = 'Artifact',
|
|
220
|
+
options: PDFExportOptions = {}
|
|
221
|
+
): Promise<void> {
|
|
222
|
+
return new Promise((resolve, reject) => {
|
|
223
|
+
try {
|
|
224
|
+
// Generate HTML content
|
|
225
|
+
const htmlContent = this.createPDFDocument(content, title, options);
|
|
226
|
+
|
|
227
|
+
// For Safari, we'll use a more reliable approach with a new window
|
|
228
|
+
// that opens the content and then triggers print
|
|
229
|
+
const printWindow = window.open('', '_blank', 'width=800,height=600,scrollbars=yes,resizable=yes');
|
|
230
|
+
|
|
231
|
+
if (!printWindow) {
|
|
232
|
+
// Fallback: try data URL approach
|
|
233
|
+
const dataUrl = `data:text/html;charset=utf-8,${encodeURIComponent(htmlContent)}`;
|
|
234
|
+
const link = document.createElement('a');
|
|
235
|
+
link.href = dataUrl;
|
|
236
|
+
link.download = `${title}.html`; // Safari might not support PDF download directly
|
|
237
|
+
link.target = '_blank';
|
|
238
|
+
link.style.display = 'none';
|
|
239
|
+
|
|
240
|
+
document.body.appendChild(link);
|
|
241
|
+
link.click();
|
|
242
|
+
document.body.removeChild(link);
|
|
243
|
+
|
|
244
|
+
resolve();
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Write content to the new window
|
|
249
|
+
printWindow.document.open('text/html', 'replace');
|
|
250
|
+
printWindow.document.write(htmlContent);
|
|
251
|
+
printWindow.document.close();
|
|
252
|
+
|
|
253
|
+
// Set title
|
|
254
|
+
printWindow.document.title = title;
|
|
255
|
+
|
|
256
|
+
// Wait for content to load, then trigger print
|
|
257
|
+
setTimeout(() => {
|
|
258
|
+
try {
|
|
259
|
+
// Focus the window first (important for Safari)
|
|
260
|
+
printWindow.focus();
|
|
261
|
+
|
|
262
|
+
// Trigger print dialog
|
|
263
|
+
printWindow.print();
|
|
264
|
+
|
|
265
|
+
// Close window after a delay
|
|
266
|
+
setTimeout(() => {
|
|
267
|
+
if (printWindow && !printWindow.closed) {
|
|
268
|
+
printWindow.close();
|
|
269
|
+
}
|
|
270
|
+
resolve();
|
|
271
|
+
}, 3000); // Give user time to interact with print dialog
|
|
272
|
+
|
|
273
|
+
} catch (printError) {
|
|
274
|
+
console.warn('Print failed, trying alternative:', printError);
|
|
275
|
+
|
|
276
|
+
// Alternative: show instructions to user
|
|
277
|
+
if (printWindow && !printWindow.closed) {
|
|
278
|
+
const instructionDiv = printWindow.document.createElement('div');
|
|
279
|
+
instructionDiv.style.cssText = `
|
|
280
|
+
position: fixed;
|
|
281
|
+
top: 20px;
|
|
282
|
+
left: 20px;
|
|
283
|
+
right: 20px;
|
|
284
|
+
background: #f0f8ff;
|
|
285
|
+
border: 2px solid #0066cc;
|
|
286
|
+
padding: 20px;
|
|
287
|
+
border-radius: 8px;
|
|
288
|
+
font-family: system-ui, sans-serif;
|
|
289
|
+
z-index: 10000;
|
|
290
|
+
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
|
291
|
+
`;
|
|
292
|
+
instructionDiv.innerHTML = `
|
|
293
|
+
<h3 style="margin: 0 0 10px 0; color: #0066cc;">📄 PDF Export Instructions</h3>
|
|
294
|
+
<p style="margin: 0 0 10px 0;">To save as PDF:</p>
|
|
295
|
+
<ol style="margin: 0 0 15px 0; padding-left: 20px;">
|
|
296
|
+
<li>Press <strong>Cmd+P</strong> (Mac) or <strong>Ctrl+P</strong> (Windows)</li>
|
|
297
|
+
<li>In the print dialog, click the "PDF" dropdown</li>
|
|
298
|
+
<li>Select "Save as PDF"</li>
|
|
299
|
+
<li>Choose your save location and click "Save"</li>
|
|
300
|
+
</ol>
|
|
301
|
+
<button onclick="this.parentElement.remove()" style="
|
|
302
|
+
background: #0066cc;
|
|
303
|
+
color: white;
|
|
304
|
+
border: none;
|
|
305
|
+
padding: 8px 16px;
|
|
306
|
+
border-radius: 4px;
|
|
307
|
+
cursor: pointer;
|
|
308
|
+
">Got it!</button>
|
|
309
|
+
`;
|
|
310
|
+
printWindow.document.body.appendChild(instructionDiv);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
resolve();
|
|
314
|
+
}
|
|
315
|
+
}, 1000); // Wait for content to fully load
|
|
316
|
+
|
|
317
|
+
} catch (error) {
|
|
318
|
+
reject(new Error(`Safari PDF export failed: ${error}`));
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
|
|
212
323
|
/**
|
|
213
324
|
* Export content as PDF using browser save functionality
|
|
214
325
|
*/
|
|
@@ -217,6 +328,11 @@ export class PDFExporter {
|
|
|
217
328
|
title: string = 'Artifact',
|
|
218
329
|
options: PDFExportOptions = {}
|
|
219
330
|
): Promise<void> {
|
|
331
|
+
// Use Safari-specific method if Safari is detected
|
|
332
|
+
if (isSafari()) {
|
|
333
|
+
return this.exportAsPDFSafari(content, title, options);
|
|
334
|
+
}
|
|
335
|
+
|
|
220
336
|
return new Promise((resolve, reject) => {
|
|
221
337
|
try {
|
|
222
338
|
// Close any existing window
|
|
@@ -224,8 +340,12 @@ export class PDFExporter {
|
|
|
224
340
|
this.printWindow.close();
|
|
225
341
|
}
|
|
226
342
|
|
|
227
|
-
// Create new window
|
|
228
|
-
|
|
343
|
+
// Create new window with Safari-friendly parameters
|
|
344
|
+
const windowFeatures = isSafariIOS()
|
|
345
|
+
? 'width=800,height=600,scrollbars=yes,resizable=yes'
|
|
346
|
+
: 'width=800,height=600,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no,status=no';
|
|
347
|
+
|
|
348
|
+
this.printWindow = window.open('', '_blank', windowFeatures);
|
|
229
349
|
if (!this.printWindow) {
|
|
230
350
|
reject(new Error('Popup blocked! Please enable popups to export PDF.'));
|
|
231
351
|
return;
|
|
@@ -234,33 +354,70 @@ export class PDFExporter {
|
|
|
234
354
|
// Generate HTML content
|
|
235
355
|
const htmlContent = this.createPDFDocument(content, title, options);
|
|
236
356
|
|
|
237
|
-
//
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
357
|
+
// Safari-specific content writing approach
|
|
358
|
+
if (isSafari()) {
|
|
359
|
+
// For Safari, use a more reliable approach
|
|
360
|
+
this.printWindow.document.open('text/html', 'replace');
|
|
361
|
+
this.printWindow.document.write(htmlContent);
|
|
362
|
+
this.printWindow.document.close();
|
|
363
|
+
|
|
364
|
+
// Wait for content to load with longer timeout for Safari
|
|
243
365
|
setTimeout(() => {
|
|
244
|
-
if (this.printWindow) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
this.printWindow.
|
|
366
|
+
if (this.printWindow && !this.printWindow.closed) {
|
|
367
|
+
try {
|
|
368
|
+
this.printWindow.document.title = title;
|
|
369
|
+
this.printWindow.focus();
|
|
370
|
+
this.printWindow.print();
|
|
371
|
+
|
|
372
|
+
// Close window after print dialog closes
|
|
373
|
+
setTimeout(() => {
|
|
374
|
+
if (this.printWindow && !this.printWindow.closed) {
|
|
375
|
+
this.printWindow.close();
|
|
376
|
+
}
|
|
253
377
|
resolve();
|
|
254
|
-
}
|
|
255
|
-
}
|
|
378
|
+
}, 2000); // Longer timeout for Safari
|
|
379
|
+
} catch (printError) {
|
|
380
|
+
console.warn('Print dialog failed, trying alternative method:', printError);
|
|
381
|
+
// Fallback: try to trigger print without focus
|
|
382
|
+
this.printWindow.print();
|
|
383
|
+
setTimeout(() => {
|
|
384
|
+
if (this.printWindow && !this.printWindow.closed) {
|
|
385
|
+
this.printWindow.close();
|
|
386
|
+
}
|
|
387
|
+
resolve();
|
|
388
|
+
}, 2000);
|
|
389
|
+
}
|
|
256
390
|
}
|
|
257
|
-
},
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
391
|
+
}, 1000); // Longer delay for Safari
|
|
392
|
+
} else {
|
|
393
|
+
// Standard approach for other browsers
|
|
394
|
+
this.printWindow.document.write(htmlContent);
|
|
395
|
+
this.printWindow.document.close();
|
|
396
|
+
|
|
397
|
+
// Wait for content to load
|
|
398
|
+
this.printWindow.onload = () => {
|
|
399
|
+
setTimeout(() => {
|
|
400
|
+
if (this.printWindow) {
|
|
401
|
+
// Trigger print dialog with PDF save option
|
|
402
|
+
this.printWindow.document.title = title;
|
|
403
|
+
this.printWindow.print();
|
|
404
|
+
|
|
405
|
+
// Close window after print dialog closes
|
|
406
|
+
setTimeout(() => {
|
|
407
|
+
if (this.printWindow) {
|
|
408
|
+
this.printWindow.close();
|
|
409
|
+
resolve();
|
|
410
|
+
}
|
|
411
|
+
}, 1000);
|
|
412
|
+
}
|
|
413
|
+
}, 500);
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
// Handle errors
|
|
417
|
+
this.printWindow.onerror = (error) => {
|
|
418
|
+
reject(new Error(`PDF export failed: ${error}`));
|
|
419
|
+
};
|
|
420
|
+
}
|
|
264
421
|
|
|
265
422
|
} catch (error) {
|
|
266
423
|
reject(new Error(`PDF export failed: ${error}`));
|
|
@@ -275,6 +432,13 @@ export class PDFExporter {
|
|
|
275
432
|
return typeof window !== 'undefined' && typeof window.open === 'function';
|
|
276
433
|
}
|
|
277
434
|
|
|
435
|
+
/**
|
|
436
|
+
* Check if Safari-specific PDF export is supported
|
|
437
|
+
*/
|
|
438
|
+
isSafariSupported(): boolean {
|
|
439
|
+
return isSafari() && typeof window !== 'undefined' && typeof window.open === 'function';
|
|
440
|
+
}
|
|
441
|
+
|
|
278
442
|
/**
|
|
279
443
|
* Clean up resources
|
|
280
444
|
*/
|
|
@@ -894,6 +894,18 @@
|
|
|
894
894
|
justify-content: flex-end;
|
|
895
895
|
}
|
|
896
896
|
|
|
897
|
+
.memori-artifact-drawer--close-desktop {
|
|
898
|
+
margin-left: 0 !important;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
.memori-artifact-drawer-container-actions--chatlog {
|
|
902
|
+
padding: 0rem 1rem;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
.memori-artifact-drawer-top-right--mobile {
|
|
906
|
+
justify-content: space-between;
|
|
907
|
+
}
|
|
908
|
+
|
|
897
909
|
/* Top Right Header Section */
|
|
898
910
|
.memori-artifact-drawer-top-right {
|
|
899
911
|
z-index: 1001;
|