@limetech/lime-elements 38.13.0 → 38.13.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 CHANGED
@@ -1,3 +1,11 @@
1
+ ## [38.13.1](https://github.com/Lundalogik/lime-elements/compare/v38.13.0...v38.13.1) (2025-05-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+
7
+ * **text-editor:** prevent Excel tables from being processed as images when pasted ([8ec93fb](https://github.com/Lundalogik/lime-elements/commit/8ec93fbeb751ba3c984d572a117a71de40f5c94a))
8
+
1
9
  ## [38.13.0](https://github.com/Lundalogik/lime-elements/compare/v38.12.5...v38.13.0) (2025-05-20)
2
10
 
3
11
 
@@ -26458,9 +26458,29 @@ const processPasteEvent = (view, event, slice) => {
26458
26458
  if (!clipboardData) {
26459
26459
  return false;
26460
26460
  }
26461
+ const isImageFilePasted = handlePastedImages(view, clipboardData);
26462
+ const filteredSlice = new Slice(filterImageNodes(slice.content), slice.openStart, slice.openEnd);
26463
+ if (filteredSlice.content.childCount < slice.content.childCount) {
26464
+ const { state, dispatch } = view;
26465
+ const tr = state.tr.replaceSelection(filteredSlice);
26466
+ dispatch(tr);
26467
+ return true;
26468
+ }
26469
+ return isImageFilePasted;
26470
+ };
26471
+ /**
26472
+ * Processes any image files found in the clipboard data and dispatches an imagePasted event.
26473
+ *
26474
+ * @param view - The ProseMirror editor view
26475
+ * @param clipboardData - The clipboard data transfer object containing potential image files
26476
+ * @returns True if at least one valid image file was found and processed, false otherwise
26477
+ */
26478
+ function handlePastedImages(view, clipboardData) {
26479
+ let isImageFilePasted = false;
26461
26480
  const files$1 = Array.from(clipboardData.files || []);
26462
26481
  for (const file of files$1) {
26463
- if (file.type.startsWith('image/')) {
26482
+ if (isImageFile(file, clipboardData)) {
26483
+ isImageFilePasted = true;
26464
26484
  const reader = new FileReader();
26465
26485
  reader.onloadend = () => {
26466
26486
  view.dom.dispatchEvent(new CustomEvent('imagePasted', {
@@ -26470,15 +26490,45 @@ const processPasteEvent = (view, event, slice) => {
26470
26490
  reader.readAsDataURL(file);
26471
26491
  }
26472
26492
  }
26473
- const filteredSlice = new Slice(filterImageNodes(slice.content), slice.openStart, slice.openEnd);
26474
- if (filteredSlice.content.childCount < slice.content.childCount) {
26475
- const { state, dispatch } = view;
26476
- const tr = state.tr.replaceSelection(filteredSlice);
26477
- dispatch(tr);
26478
- return true;
26493
+ return isImageFilePasted;
26494
+ }
26495
+ /**
26496
+ * Determines if a file is an image that should be processed by the image handler.
26497
+ *
26498
+ * This function checks both the file's MIME type and the clipboard HTML content.
26499
+ * It filters out HTML content from Excel and HTML tables, as they are not relevant for image processing.
26500
+ *
26501
+ * @param file - The file object to check
26502
+ * @param clipboardData - The full clipboard data transfer object to examine for context
26503
+ * @returns True if the file is an image that should be processed, false otherwise
26504
+ */
26505
+ function isImageFile(file, clipboardData) {
26506
+ var _a, _b;
26507
+ if (!isContentTypeImage(file)) {
26508
+ return false;
26479
26509
  }
26480
- return files$1.length > 0;
26481
- };
26510
+ const html = (_b = (_a = clipboardData === null || clipboardData === void 0 ? void 0 : clipboardData.getData('text/html')) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
26511
+ return !isHtmlFromExcel(html) && !isHtmlTable(html);
26512
+ }
26513
+ function isContentTypeImage(file) {
26514
+ if (!(file === null || file === void 0 ? void 0 : file.type)) {
26515
+ return false;
26516
+ }
26517
+ return file.type.startsWith('image/');
26518
+ }
26519
+ function isHtmlFromExcel(html) {
26520
+ if (!html) {
26521
+ return false;
26522
+ }
26523
+ return (html.includes('name=generator content="microsoft excel"') ||
26524
+ html.includes('xmlns:x="urn:schemas-microsoft-com:office:excel"'));
26525
+ }
26526
+ function isHtmlTable(html) {
26527
+ if (!html) {
26528
+ return false;
26529
+ }
26530
+ return html.includes('<table');
26531
+ }
26482
26532
 
26483
26533
  const MIN_WIDTH = 10;
26484
26534
  const createImageViewPlugin = (language) => {