react-lite-rich-text-editor 1.1.2 → 1.1.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/index.esm.js CHANGED
@@ -524,11 +524,11 @@ var FaTable = function FaTable(_ref14) {
524
524
  }
525
525
  });
526
526
  };
527
- var FaYoutube = function FaYoutube(_ref15) {
528
- var className = _ref15.className,
529
- size = _ref15.size,
530
- color = _ref15.color,
531
- style = _ref15.style;
527
+ var FaObjectGroup = function FaObjectGroup(_ref16) {
528
+ var className = _ref16.className,
529
+ size = _ref16.size,
530
+ color = _ref16.color,
531
+ style = _ref16.style;
532
532
  return /*#__PURE__*/React.createElement("span", {
533
533
  className: className,
534
534
  style: _objectSpread2({
@@ -539,15 +539,15 @@ var FaYoutube = function FaYoutube(_ref15) {
539
539
  color: color || 'inherit'
540
540
  }, style),
541
541
  dangerouslySetInnerHTML: {
542
- __html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 576 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M549.655 124.083c-6.281-23.65-24.787-42.276-48.284-48.597C458.781 64 288 64 288 64S117.22 64 74.629 75.486c-23.497 6.322-42.003 24.947-48.284 48.597-11.412 42.867-11.412 132.305-11.412 132.305s0 89.438 11.412 132.305c6.281 23.65 24.787 41.5 48.284 47.821C117.22 448 288 448 288 448s170.781 0 213.371-11.486c23.497-6.321 42.003-24.171 48.284-47.821 11.412-42.867 11.412-132.305 11.412-132.305s0-89.438-11.412-132.305zm-317.51 213.508V175.185l142.739 81.205-142.739 81.201z\"></path></svg>"
542
+ __html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 512 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M480 320h-48v48c0 17.7-14.3 32-32 32h-48v32c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V160c0-26.5 21.5-48 48-48h32v-48c0-17.7 14.3-32 32-32h48V0h32c26.5 0 48 21.5 48 48v48h48c17.7 0 32 14.3 32 32v48h32c26.5 0 48 21.5 48 48v128c0 26.5-21.5 48-48 48z\"></path></svg>"
543
543
  }
544
544
  });
545
545
  };
546
- var FaObjectGroup = function FaObjectGroup(_ref16) {
547
- var className = _ref16.className,
548
- size = _ref16.size,
549
- color = _ref16.color,
550
- style = _ref16.style;
546
+ var FaTrash = function FaTrash(_ref17) {
547
+ var className = _ref17.className,
548
+ size = _ref17.size,
549
+ color = _ref17.color,
550
+ style = _ref17.style;
551
551
  return /*#__PURE__*/React.createElement("span", {
552
552
  className: className,
553
553
  style: _objectSpread2({
@@ -558,15 +558,15 @@ var FaObjectGroup = function FaObjectGroup(_ref16) {
558
558
  color: color || 'inherit'
559
559
  }, style),
560
560
  dangerouslySetInnerHTML: {
561
- __html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 512 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M480 320h-48v48c0 17.7-14.3 32-32 32h-48v32c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V160c0-26.5 21.5-48 48-48h32v-48c0-17.7 14.3-32 32-32h48V0h32c26.5 0 48 21.5 48 48v48h48c17.7 0 32 14.3 32 32v48h32c26.5 0 48 21.5 48 48v128c0 26.5-21.5 48-48 48z\"></path></svg>"
561
+ __html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 448 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M432 32H312l-9.4-18.7A24 24 0 0 0 281.1 0H166.8a23.72 23.72 0 0 0-21.4 13.3L136 32H16A16 16 0 0 0 0 48v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16zM53.2 467a48 48 0 0 0 47.9 45h245.8a48 48 0 0 0 47.9-45L416 128H32z\"></path></svg>"
562
562
  }
563
563
  });
564
564
  };
565
- var FaTrash = function FaTrash(_ref17) {
566
- var className = _ref17.className,
567
- size = _ref17.size,
568
- color = _ref17.color,
569
- style = _ref17.style;
565
+ var FaVideo = function FaVideo(_ref18) {
566
+ var className = _ref18.className,
567
+ size = _ref18.size,
568
+ color = _ref18.color,
569
+ style = _ref18.style;
570
570
  return /*#__PURE__*/React.createElement("span", {
571
571
  className: className,
572
572
  style: _objectSpread2({
@@ -577,7 +577,7 @@ var FaTrash = function FaTrash(_ref17) {
577
577
  color: color || 'inherit'
578
578
  }, style),
579
579
  dangerouslySetInnerHTML: {
580
- __html: "<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 448 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M432 32H312l-9.4-18.7A24 24 0 0 0 281.1 0H166.8a23.72 23.72 0 0 0-21.4 13.3L136 32H16A16 16 0 0 0 0 48v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16zM53.2 467a48 48 0 0 0 47.9 45h245.8a48 48 0 0 0 47.9-45L416 128H32z\"></path></svg>"
580
+ __html: '<svg stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" viewBox=\"0 0 576 512\" height=\"1em\" width=\"1em\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M0 128C0 92.7 28.7 64 64 64H320c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128zM559.1 99.8c10.4 5.6 16.9 16.3 16.9 28.2V384c0 11.9-6.5 22.6-16.9 28.2s-23 5-32.9-1.6l-96-64L416 337.1V174.9l14.2-9.5 96-64c9.9-6.6 22.6-7.1 32.9-1.6z\"></path></svg>'
581
581
  }
582
582
  });
583
583
  };
@@ -767,12 +767,12 @@ function RichTextEditor(_ref) {
767
767
  setIsUploading = _useState30[1];
768
768
  var _useState31 = useState(false),
769
769
  _useState32 = _slicedToArray(_useState31, 2),
770
- youtubeModalOpen = _useState32[0],
771
- setYoutubeModalOpen = _useState32[1];
770
+ videoModalOpen = _useState32[0],
771
+ setVideoModalOpen = _useState32[1];
772
772
  var _useState33 = useState(""),
773
773
  _useState34 = _slicedToArray(_useState33, 2),
774
- youtubeUrl = _useState34[0],
775
- setYoutubeUrl = _useState34[1];
774
+ videoUrl = _useState34[0],
775
+ setVideoUrl = _useState34[1];
776
776
  var _useState35 = useState(false),
777
777
  _useState36 = _slicedToArray(_useState35, 2),
778
778
  tableModalOpen = _useState36[0],
@@ -813,6 +813,13 @@ function RichTextEditor(_ref) {
813
813
  setSelectedImageUrl("");
814
814
  setZoomLevel(1);
815
815
  };
816
+ var saveSelection = function saveSelection() {
817
+ if (typeof window === "undefined") return;
818
+ var sel = window.getSelection();
819
+ if (sel && sel.rangeCount > 0) {
820
+ selectionRangeRef.current = sel.getRangeAt(0).cloneRange();
821
+ }
822
+ };
816
823
  var handleZoomIn = function handleZoomIn() {
817
824
  setZoomLevel(function (prevZoom) {
818
825
  return prevZoom + 0.1;
@@ -1230,13 +1237,35 @@ function RichTextEditor(_ref) {
1230
1237
  setTableModalOpen(false);
1231
1238
  triggerChange && triggerChange();
1232
1239
  };
1233
- var insertYoutube = function insertYoutube() {
1234
- var url = youtubeUrl.trim();
1235
- // More robust regex for various YouTube formats
1236
- var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|watch\?vi=|\&vi=)([^#\&\?]*).*/;
1237
- var match = url.match(regExp);
1238
- var videoId = match && match[2].length === 11 ? match[2] : null;
1239
- if (videoId) {
1240
+ var parseVideoUrl = function parseVideoUrl(url) {
1241
+ url = url.trim();
1242
+ if (!url) return null;
1243
+
1244
+ // YouTube
1245
+ var ytRegExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|watch\?vi=|\&vi=)([^#\&\?]*).*/;
1246
+ var ytMatch = url.match(ytRegExp);
1247
+ if (ytMatch && ytMatch[2].length === 11) {
1248
+ return "https://www.youtube.com/embed/".concat(ytMatch[2]);
1249
+ }
1250
+
1251
+ // Vimeo
1252
+ var vimeoRegExp = /vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)/;
1253
+ var vimeoMatch = url.match(vimeoRegExp);
1254
+ if (vimeoMatch && vimeoMatch[3]) {
1255
+ return "https://player.vimeo.com/video/".concat(vimeoMatch[3]);
1256
+ }
1257
+
1258
+ // DailyMotion
1259
+ var dmRegExp = /dailymotion\.com\/video\/([a-zA-Z0-9]+)/;
1260
+ var dmMatch = url.match(dmRegExp);
1261
+ if (dmMatch && dmMatch[1]) {
1262
+ return "https://www.dailymotion.com/embed/video/".concat(dmMatch[1]);
1263
+ }
1264
+ return null;
1265
+ };
1266
+ var insertVideo = function insertVideo() {
1267
+ var embedUrl = parseVideoUrl(videoUrl);
1268
+ if (embedUrl) {
1240
1269
  if (editorRef.current) {
1241
1270
  editorRef.current.focus();
1242
1271
  }
@@ -1245,24 +1274,23 @@ function RichTextEditor(_ref) {
1245
1274
  sel.removeAllRanges();
1246
1275
  sel.addRange(selectionRangeRef.current);
1247
1276
  }
1248
- var embedHtml = "<div class=\"video-container\">\n <iframe \n src=\"https://www.youtube.com/embed/".concat(videoId, "\" \n frameborder=\"0\" \n allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" \n allowfullscreen\n ></iframe>\n </div><p>&nbsp;</p>");
1277
+ var embedHtml = "<div class=\"video-container\">\n <iframe \n src=\"".concat(embedUrl, "\" \n frameborder=\"0\" \n allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" \n allowfullscreen\n ></iframe>\n </div><p>&nbsp;</p>");
1249
1278
  try {
1250
1279
  document.execCommand("insertHTML", false, embedHtml);
1251
1280
  } catch (err) {
1252
- console.error("Failed to insert YouTube HTML:", err);
1253
- // Fallback: append to the end of the editor
1281
+ console.error("Failed to insert Video HTML:", err);
1254
1282
  if (editorRef.current) {
1255
1283
  var div = document.createElement('div');
1256
1284
  div.innerHTML = embedHtml;
1257
1285
  editorRef.current.appendChild(div);
1258
1286
  }
1259
1287
  }
1288
+ setVideoModalOpen(false);
1289
+ setVideoUrl("");
1290
+ triggerChange && triggerChange();
1260
1291
  } else {
1261
- console.warn("Invalid YouTube URL or Video ID not found");
1292
+ console.warn("Invalid Video URL or Platform not supported");
1262
1293
  }
1263
- setYoutubeModalOpen(false);
1264
- setYoutubeUrl("");
1265
- triggerChange && triggerChange();
1266
1294
  };
1267
1295
  var processExistingImages = function processExistingImages(container) {
1268
1296
  if (!container) return;
@@ -2335,17 +2363,14 @@ function RichTextEditor(_ref) {
2335
2363
  size: 14
2336
2364
  })), /*#__PURE__*/React.createElement("button", {
2337
2365
  type: "button",
2338
- title: "Embed YouTube Video",
2339
- className: "rte-toolbar-button",
2366
+ title: "Embed Video (YouTube, Vimeo, etc.)",
2367
+ className: "rte-toolbar-button ".concat(videoModalOpen ? 'active' : ''),
2340
2368
  onMouseDown: function onMouseDown(e) {
2341
2369
  e.preventDefault();
2342
- var sel = window.getSelection();
2343
- if (sel && sel.rangeCount > 0) {
2344
- selectionRangeRef.current = sel.getRangeAt(0).cloneRange();
2345
- }
2346
- setYoutubeModalOpen(true);
2370
+ saveSelection();
2371
+ setVideoModalOpen(true);
2347
2372
  }
2348
- }, /*#__PURE__*/React.createElement(FaYoutube, {
2373
+ }, /*#__PURE__*/React.createElement(FaVideo, {
2349
2374
  size: 14
2350
2375
  })), function () {
2351
2376
  if (typeof window === "undefined") return null;
@@ -2393,14 +2418,7 @@ function RichTextEditor(_ref) {
2393
2418
  e.preventDefault();
2394
2419
  tableAction('addColAfter');
2395
2420
  }
2396
- }, "+C\u2192"), /*#__PURE__*/React.createElement("div", {
2397
- style: {
2398
- width: '1px',
2399
- height: '20px',
2400
- backgroundColor: '#f3f4f6',
2401
- margin: '0 4px'
2402
- }
2403
- }), /*#__PURE__*/React.createElement("button", {
2421
+ }, "+C\u2192"), /*#__PURE__*/React.createElement("button", {
2404
2422
  type: "button",
2405
2423
  title: "Merge Cells (Right)",
2406
2424
  className: "rte-toolbar-button",
@@ -2410,17 +2428,22 @@ function RichTextEditor(_ref) {
2410
2428
  }
2411
2429
  }, /*#__PURE__*/React.createElement(FaObjectGroup, {
2412
2430
  size: 14
2413
- })), /*#__PURE__*/React.createElement("button", {
2431
+ })), /*#__PURE__*/React.createElement("div", {
2432
+ style: {
2433
+ display: 'flex',
2434
+ gap: '10px'
2435
+ }
2436
+ }, /*#__PURE__*/React.createElement("button", {
2414
2437
  type: "button",
2415
2438
  title: "Delete Row",
2416
- className: "rte-toolbar-button rte-toolbar-button-danger ",
2439
+ className: "rte-toolbar-button rte-toolbar-button-danger",
2417
2440
  onMouseDown: function onMouseDown(e) {
2418
2441
  e.preventDefault();
2419
2442
  tableAction('deleteRow');
2420
2443
  }
2421
2444
  }, /*#__PURE__*/React.createElement(FaTrash, {
2422
2445
  size: 12
2423
- }), " ", /*#__PURE__*/React.createElement("span", {
2446
+ }), /*#__PURE__*/React.createElement("span", {
2424
2447
  style: {
2425
2448
  fontSize: '10px'
2426
2449
  }
@@ -2434,10 +2457,9 @@ function RichTextEditor(_ref) {
2434
2457
  }
2435
2458
  }, /*#__PURE__*/React.createElement(FaTrash, {
2436
2459
  size: 12
2437
- }), " ", /*#__PURE__*/React.createElement("span", {
2460
+ }), /*#__PURE__*/React.createElement("span", {
2438
2461
  style: {
2439
- fontSize: '10px',
2440
- marginRight: "5px"
2462
+ fontSize: '10px'
2441
2463
  }
2442
2464
  }, "Col")), /*#__PURE__*/React.createElement("button", {
2443
2465
  type: "button",
@@ -2448,12 +2470,12 @@ function RichTextEditor(_ref) {
2448
2470
  tableAction('deleteTable');
2449
2471
  }
2450
2472
  }, /*#__PURE__*/React.createElement(FaTrash, {
2451
- size: 14
2452
- }), " ", /*#__PURE__*/React.createElement("span", {
2473
+ size: 12
2474
+ }), /*#__PURE__*/React.createElement("span", {
2453
2475
  style: {
2454
- fontWeight: '600'
2476
+ fontSize: '10px'
2455
2477
  }
2456
- }, "Table")));
2478
+ }, "Table"))));
2457
2479
  }
2458
2480
  return null;
2459
2481
  }()), /*#__PURE__*/React.createElement("div", {
@@ -2601,10 +2623,10 @@ function RichTextEditor(_ref) {
2601
2623
  type: "button",
2602
2624
  className: "rte-button rte-button-primary",
2603
2625
  onClick: insertTable
2604
- }, "Insert")))), youtubeModalOpen && /*#__PURE__*/React.createElement("div", {
2626
+ }, "Insert")))), videoModalOpen && /*#__PURE__*/React.createElement("div", {
2605
2627
  className: "rte-modal-overlay",
2606
2628
  onClick: function onClick() {
2607
- return setYoutubeModalOpen(false);
2629
+ return setVideoModalOpen(false);
2608
2630
  }
2609
2631
  }, /*#__PURE__*/React.createElement("div", {
2610
2632
  className: "rte-modal",
@@ -2615,22 +2637,26 @@ function RichTextEditor(_ref) {
2615
2637
  className: "rte-modal-header"
2616
2638
  }, /*#__PURE__*/React.createElement("h3", {
2617
2639
  className: "rte-modal-title"
2618
- }, "Embed YouTube Video")), /*#__PURE__*/React.createElement("div", {
2640
+ }, "Embed Video")), /*#__PURE__*/React.createElement("div", {
2619
2641
  className: "rte-form-group"
2620
2642
  }, /*#__PURE__*/React.createElement("label", {
2621
2643
  className: "rte-label"
2622
- }, "Paste YouTube Video URL"), /*#__PURE__*/React.createElement("input", {
2644
+ }, "Paste Video URL (YouTube, Vimeo...) ", /*#__PURE__*/React.createElement("span", {
2645
+ style: {
2646
+ color: '#ef4444'
2647
+ }
2648
+ }, "*")), /*#__PURE__*/React.createElement("input", {
2623
2649
  type: "text",
2624
2650
  className: "rte-input",
2625
- value: youtubeUrl,
2651
+ value: videoUrl,
2626
2652
  onChange: function onChange(e) {
2627
- return setYoutubeUrl(e.target.value);
2653
+ return setVideoUrl(e.target.value);
2628
2654
  },
2629
- placeholder: "https://www.youtube.com/watch?v=...",
2655
+ placeholder: "Paste URL here...",
2630
2656
  autoFocus: true,
2631
2657
  onKeyDown: function onKeyDown(e) {
2632
- if (e.key === 'Enter') insertYoutube();
2633
- if (e.key === 'Escape') setYoutubeModalOpen(false);
2658
+ if (e.key === 'Enter' && videoUrl.trim()) insertVideo();
2659
+ if (e.key === 'Escape') setVideoModalOpen(false);
2634
2660
  }
2635
2661
  })), /*#__PURE__*/React.createElement("div", {
2636
2662
  className: "rte-modal-actions"
@@ -2638,12 +2664,17 @@ function RichTextEditor(_ref) {
2638
2664
  type: "button",
2639
2665
  className: "rte-button rte-button-secondary",
2640
2666
  onClick: function onClick() {
2641
- return setYoutubeModalOpen(false);
2667
+ return setVideoModalOpen(false);
2642
2668
  }
2643
2669
  }, "Cancel"), /*#__PURE__*/React.createElement("button", {
2644
2670
  type: "button",
2645
2671
  className: "rte-button rte-button-primary",
2646
- onClick: insertYoutube
2672
+ onClick: function onClick() {
2673
+ if (videoUrl.trim()) {
2674
+ insertVideo();
2675
+ }
2676
+ },
2677
+ disabled: !videoUrl.trim()
2647
2678
  }, "Embed Video")))), imageModalOpen && /*#__PURE__*/React.createElement("div", {
2648
2679
  className: "rte-modal-overlay",
2649
2680
  onClick: closeImageModal