react-lite-rich-text-editor 1.1.1 → 1.1.2
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.cjs.js +723 -43
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +723 -43
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -505,6 +505,82 @@ var FaFont = function FaFont(_ref12) {
|
|
|
505
505
|
}
|
|
506
506
|
});
|
|
507
507
|
};
|
|
508
|
+
var FaTable = function FaTable(_ref14) {
|
|
509
|
+
var className = _ref14.className,
|
|
510
|
+
size = _ref14.size,
|
|
511
|
+
color = _ref14.color,
|
|
512
|
+
style = _ref14.style;
|
|
513
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
514
|
+
className: className,
|
|
515
|
+
style: _objectSpread2({
|
|
516
|
+
display: 'inline-flex',
|
|
517
|
+
alignItems: 'center',
|
|
518
|
+
justifyContent: 'center',
|
|
519
|
+
fontSize: size || '1em',
|
|
520
|
+
color: color || 'inherit'
|
|
521
|
+
}, style),
|
|
522
|
+
dangerouslySetInnerHTML: {
|
|
523
|
+
__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=\"M64 448c-35.3 0-64-28.7-64-64V128c0-35.3 28.7-64 64-64H448c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64zm96-288H64v64h96v-64zm0 96H64v64h96v-64zm0 96H64c0 17.7 14.3 32 32 32h64v-32zm128-192h-96v64h96v-64zm0 96h-96v64h96v-64zm0 96h-96v96h96v-96zm160-192h-96v64h96v-64zm0 96h-96v64h96v-64zm0 96h-96v64h64c17.7 0 32-14.3 32-32v-32z\"></path></svg>"
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
};
|
|
527
|
+
var FaYoutube = function FaYoutube(_ref15) {
|
|
528
|
+
var className = _ref15.className,
|
|
529
|
+
size = _ref15.size,
|
|
530
|
+
color = _ref15.color,
|
|
531
|
+
style = _ref15.style;
|
|
532
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
533
|
+
className: className,
|
|
534
|
+
style: _objectSpread2({
|
|
535
|
+
display: 'inline-flex',
|
|
536
|
+
alignItems: 'center',
|
|
537
|
+
justifyContent: 'center',
|
|
538
|
+
fontSize: size || '1em',
|
|
539
|
+
color: color || 'inherit'
|
|
540
|
+
}, style),
|
|
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>"
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
};
|
|
546
|
+
var FaObjectGroup = function FaObjectGroup(_ref16) {
|
|
547
|
+
var className = _ref16.className,
|
|
548
|
+
size = _ref16.size,
|
|
549
|
+
color = _ref16.color,
|
|
550
|
+
style = _ref16.style;
|
|
551
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
552
|
+
className: className,
|
|
553
|
+
style: _objectSpread2({
|
|
554
|
+
display: 'inline-flex',
|
|
555
|
+
alignItems: 'center',
|
|
556
|
+
justifyContent: 'center',
|
|
557
|
+
fontSize: size || '1em',
|
|
558
|
+
color: color || 'inherit'
|
|
559
|
+
}, style),
|
|
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>"
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
};
|
|
565
|
+
var FaTrash = function FaTrash(_ref17) {
|
|
566
|
+
var className = _ref17.className,
|
|
567
|
+
size = _ref17.size,
|
|
568
|
+
color = _ref17.color,
|
|
569
|
+
style = _ref17.style;
|
|
570
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
571
|
+
className: className,
|
|
572
|
+
style: _objectSpread2({
|
|
573
|
+
display: 'inline-flex',
|
|
574
|
+
alignItems: 'center',
|
|
575
|
+
justifyContent: 'center',
|
|
576
|
+
fontSize: size || '1em',
|
|
577
|
+
color: color || 'inherit'
|
|
578
|
+
}, style),
|
|
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>"
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
};
|
|
508
584
|
|
|
509
585
|
// DraftJS helper stubs
|
|
510
586
|
// Since we are removing specific DraftJS dependencies for this package,
|
|
@@ -577,7 +653,7 @@ function styleInject(css, ref) {
|
|
|
577
653
|
}
|
|
578
654
|
}
|
|
579
655
|
|
|
580
|
-
var css_248z = ".rte-container{background-color:#fff;border:1px solid #e5e7eb;border-radius:12px;box-shadow:0 1px 3px rgba(0,0,0,.05);overflow:hidden;transition:all .2s cubic-bezier(.4,0,.2,1)}.rte-container:focus-within{border-color:#3b82f6;box-shadow:0 0 0 3px rgba(59,130,246,.1)}.rte-toolbar{align-items:center;background-color:#f9fafb;border-bottom:1px solid #f3f4f6;display:flex;flex-wrap:wrap;gap:4px;padding:8px}.rte-toolbar-button{align-items:center;background:transparent;border:none;border-radius:6px;color:#4b5563;cursor:pointer;display:flex;height:32px;justify-content:center;padding:0;transition:all .15s ease;width:32px}.rte-toolbar-button:hover{background-color:#f3f4f6;color:#111827}.rte-toolbar-button.active{background-color:#eff6ff;color:#2563eb}.rte-toolbar-button:disabled{cursor:not-allowed;opacity:.5}.rte-toolbar-select{background-color:#fff;border:1px solid #e5e7eb;border-radius:6px;color:#374151;cursor:pointer;font-size:14px;height:32px;outline:none;padding:0 8px;transition:border-color .15s ease}.rte-toolbar-select:hover{border-color:#d1d5db}.rte-toolbar-select:focus{border-color:#3b82f6}.rte-color-picker-label{align-items:center;border-radius:6px;cursor:pointer;display:flex;height:32px;justify-content:center;position:relative;transition:background-color .15s ease;width:32px}.rte-color-picker-label:hover{background-color:#f3f4f6}.rte-color-input{cursor:pointer;height:100%;inset:0;opacity:0;position:absolute;width:100%}.rte-content{color:#1f2937;font-family:inherit;font-size:16px;line-height:1.6;min-height:150px;outline:none;overflow-y:auto;padding:12px;word-break:break-word}.rte-content ul{list-style-type:disc;margin-left:1.5rem}.rte-content ol{list-style-type:decimal;margin-left:1.5rem}.rte-content img{border-radius:8px;height:auto;max-width:100%}.rte-modal-overlay{align-items:center;animation:rte-fade-in .2s ease-out;backdrop-filter:blur(4px);background-color:rgba(0,0,0,.5);display:flex;inset:0;justify-content:center;position:fixed;z-index:9999}.rte-modal{animation:rte-zoom-in .2s ease-out;background-color:#fff;border:1px solid #f3f4f6;border-radius:16px;box-shadow:0 20px 25px -5px rgba(0,0,0,.1),0 10px 10px -5px rgba(0,0,0,.04);display:flex;flex-direction:column;gap:16px;max-width:400px;padding:
|
|
656
|
+
var css_248z = ".rte-container{background-color:#fff;border:1px solid #e5e7eb;border-radius:12px;box-shadow:0 1px 3px rgba(0,0,0,.05);overflow:hidden;transition:all .2s cubic-bezier(.4,0,.2,1)}.rte-container:focus-within{border-color:#3b82f6;box-shadow:0 0 0 3px rgba(59,130,246,.1)}.rte-toolbar{align-items:center;background-color:#f9fafb;border-bottom:1px solid #f3f4f6;display:flex;flex-wrap:wrap;gap:4px;padding:8px}.rte-toolbar-button{align-items:center;background:transparent;border:none;border-radius:6px;color:#4b5563;cursor:pointer;display:flex;height:32px;justify-content:center;padding:0;transition:all .15s ease;width:32px}.rte-toolbar-button:hover{background-color:#f3f4f6;color:#111827}.rte-toolbar-button.active{background-color:#eff6ff;color:#2563eb}.rte-toolbar-button:disabled{cursor:not-allowed;opacity:.5}.rte-toolbar-button-danger:hover{background-color:#fef2f2!important;color:#dc2626!important}.rte-toolbar-select{background-color:#fff;border:1px solid #e5e7eb;border-radius:6px;color:#374151;cursor:pointer;font-size:14px;height:32px;outline:none;padding:0 8px;transition:border-color .15s ease}.rte-toolbar-select:hover{border-color:#d1d5db}.rte-toolbar-select:focus{border-color:#3b82f6}.rte-color-picker-label{align-items:center;border-radius:6px;cursor:pointer;display:flex;height:32px;justify-content:center;position:relative;transition:background-color .15s ease;width:32px}.rte-color-picker-label:hover{background-color:#f3f4f6}.rte-color-input{cursor:pointer;height:100%;inset:0;opacity:0;position:absolute;width:100%}.rte-content{color:#1f2937;font-family:inherit;font-size:16px;line-height:1.6;min-height:150px;outline:none;overflow-y:auto;padding:12px;word-break:break-word}.rte-content ul{list-style-type:disc;margin-left:1.5rem}.rte-content ol{list-style-type:decimal;margin-left:1.5rem}.rte-content img{border-radius:8px;display:block;height:auto;max-width:100%}.rte-content table{border-collapse:collapse;margin:16px 0;width:100%}.rte-content td,.rte-content th{border:1px solid #e5e7eb;min-width:40px;padding:12px;word-break:break-word}.video-container{border-radius:12px;box-shadow:0 4px 6px -1px rgba(0,0,0,.1);height:0;margin:16px 0;overflow:hidden;padding-bottom:56.25%;position:relative}.video-container iframe{height:100%;left:0;position:absolute;top:0;width:100%}.rte-modal-overlay{align-items:center;animation:rte-fade-in .2s ease-out;backdrop-filter:blur(4px);background-color:rgba(0,0,0,.5);display:flex;inset:0;justify-content:center;position:fixed;z-index:9999}.rte-modal{animation:rte-zoom-in .2s ease-out;background-color:#fff;border:1px solid #f3f4f6;border-radius:16px;box-shadow:0 20px 25px -5px rgba(0,0,0,.1),0 10px 10px -5px rgba(0,0,0,.04);display:flex;flex-direction:column;gap:16px;max-width:400px;padding:0;width:100%}.rte-modal-title{color:#111827;flex:1;font-size:18px;font-weight:600;margin:0;text-align:center}.rte-modal-header{align-items:center;border-bottom:1px solid #f3f4f6;display:flex;justify-content:space-between;padding:20px 24px 16px}.rte-form-group{display:flex;flex-direction:column;gap:8px;padding:16px 24px}.rte-label{color:#374151;font-size:14px;font-weight:600}.rte-input{border:1px solid #d1d5db;border-radius:8px;outline:none;padding:8px 12px;transition:all .15s ease;width:93%}.rte-input:focus{border-color:#3b82f6;box-shadow:0 0 0 3px rgba(59,130,246,.1)}.rte-modal-actions{border-top:1px solid #f3f4f6;display:flex;gap:12px;justify-content:flex-end;padding:16px 24px 20px}.rte-button{border:none;border-radius:8px;cursor:pointer;font-weight:500;padding:8px 16px;transition:all .15s ease}.rte-button-secondary{background-color:#f3f4f6;color:#4b5563}.rte-button-secondary:hover{background-color:#e5e7eb}.rte-button-primary{background-color:#2563eb;box-shadow:0 1px 2px rgba(0,0,0,.05);color:#fff}.rte-button-primary:hover{background-color:#1d4ed8}.rte-button-primary:disabled{cursor:not-allowed;opacity:.5}.rte-spinner-container{align-items:center;display:flex;justify-content:center;padding:16px}.rte-spinner{animation:rte-spin .8s linear infinite;border:3px solid #eff6ff;border-radius:50%;border-top-color:#3b82f6;height:32px;width:32px}@keyframes rte-spin{to{transform:rotate(1turn)}}@keyframes rte-fade-in{0%{opacity:0}to{opacity:1}}@keyframes rte-zoom-in{0%{opacity:0;transform:scale(.95)}to{opacity:1;transform:scale(1)}}.image-container{background:#f9fafb;border:1px solid #f3f4f6;border-radius:12px;box-sizing:border-box;margin:15px;max-width:100%;position:relative;transition:all .2s ease}.image-container.image-align-center{display:block;height:300px;margin:24px auto;width:100%}.image-container.image-align-left,.image-container.image-align-right{display:inline-block;height:300px;width:350px}.image-container.image-align-left{float:left;margin-right:24px}.image-container.image-align-right{float:right;margin-left:24px}.image-container img{background:#fff;border-radius:12px;display:block;height:100%;margin:0 auto;object-fit:contain;width:100%}.image-delete-button{align-items:center;background:#ef4444;border:3px solid #fff;border-radius:9999px;box-shadow:0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -1px rgba(0,0,0,.06);color:#fff;cursor:pointer;display:flex;font-size:18px;font-weight:700;height:26px;justify-content:center;line-height:1;padding:0;position:absolute;right:0;top:0;transform:translate(50%,-50%);transition:all .2s cubic-bezier(.4,0,.2,1);width:26px;z-index:50}.image-delete-button:hover{background:#b91c1c;box-shadow:0 10px 15px -3px rgba(0,0,0,.1);transform:translate(50%,-50%) scale(1.1)}.rte-table-delete-btn,.rte-table-delete-hover{align-items:center;display:flex;justify-content:center}.rte-table-delete-btn{background:#fff;border:1px solid #ef4444;border-radius:6px;box-shadow:0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -1px rgba(0,0,0,.06);color:#ef4444;cursor:pointer;height:28px;padding:0;transition:all .2s ease;width:28px}.rte-table-delete-btn:hover{background:#ef4444;color:#fff;transform:scale(1.1)}.rte-table-delete-btn:active{transform:scale(.95)}.image-container:after{clear:both;content:\"\";display:table}.rte-footer{background-color:#fcfcfd;border-top:1px solid #f3f4f6;display:flex;justify-content:flex-end;padding:6px 16px;user-select:none}.rte-footer-content{align-items:center;color:#9ca3af;display:flex;font-size:11px;gap:10px;letter-spacing:.025em}.rte-footer-separator{color:#e5e7eb;font-size:14px;line-height:1}.rte-footer-item b{color:#6b7280;font-weight:600}";
|
|
581
657
|
styleInject(css_248z);
|
|
582
658
|
|
|
583
659
|
// Helper functions for HTML escaping
|
|
@@ -593,9 +669,9 @@ var escapeAttr = function escapeAttr(str) {
|
|
|
593
669
|
var URL_REGEX = /(https?:\/\/[^\s]+)/g;
|
|
594
670
|
function RichTextEditor(_ref) {
|
|
595
671
|
var onChange = _ref.onChange,
|
|
596
|
-
showEditButton = _ref.showEditButton
|
|
597
|
-
|
|
598
|
-
_ref$disabled = _ref.disabled,
|
|
672
|
+
showEditButton = _ref.showEditButton;
|
|
673
|
+
_ref.onBlur;
|
|
674
|
+
var _ref$disabled = _ref.disabled,
|
|
599
675
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
600
676
|
_ref$editable = _ref.editable,
|
|
601
677
|
defaultEditable = _ref$editable === void 0 ? false : _ref$editable,
|
|
@@ -689,6 +765,42 @@ function RichTextEditor(_ref) {
|
|
|
689
765
|
_useState30 = _slicedToArray(_useState29, 2),
|
|
690
766
|
isUploading = _useState30[0],
|
|
691
767
|
setIsUploading = _useState30[1];
|
|
768
|
+
var _useState31 = useState(false),
|
|
769
|
+
_useState32 = _slicedToArray(_useState31, 2),
|
|
770
|
+
youtubeModalOpen = _useState32[0],
|
|
771
|
+
setYoutubeModalOpen = _useState32[1];
|
|
772
|
+
var _useState33 = useState(""),
|
|
773
|
+
_useState34 = _slicedToArray(_useState33, 2),
|
|
774
|
+
youtubeUrl = _useState34[0],
|
|
775
|
+
setYoutubeUrl = _useState34[1];
|
|
776
|
+
var _useState35 = useState(false),
|
|
777
|
+
_useState36 = _slicedToArray(_useState35, 2),
|
|
778
|
+
tableModalOpen = _useState36[0],
|
|
779
|
+
setTableModalOpen = _useState36[1];
|
|
780
|
+
var _useState37 = useState(null),
|
|
781
|
+
_useState38 = _slicedToArray(_useState37, 2);
|
|
782
|
+
_useState38[0];
|
|
783
|
+
var setHoveredTable = _useState38[1];
|
|
784
|
+
var _useState39 = useState(3),
|
|
785
|
+
_useState40 = _slicedToArray(_useState39, 2),
|
|
786
|
+
tableRows = _useState40[0],
|
|
787
|
+
setTableRows = _useState40[1];
|
|
788
|
+
var _useState41 = useState(3),
|
|
789
|
+
_useState42 = _slicedToArray(_useState41, 2),
|
|
790
|
+
tableCols = _useState42[0],
|
|
791
|
+
setTableCols = _useState42[1];
|
|
792
|
+
var _useState43 = useState(0),
|
|
793
|
+
_useState44 = _slicedToArray(_useState43, 2);
|
|
794
|
+
_useState44[0];
|
|
795
|
+
var setSelectionVersion = _useState44[1];
|
|
796
|
+
var _useState45 = useState(null),
|
|
797
|
+
_useState46 = _slicedToArray(_useState45, 2),
|
|
798
|
+
selectedImage = _useState46[0],
|
|
799
|
+
setSelectedImage = _useState46[1];
|
|
800
|
+
var _useState47 = useState(null),
|
|
801
|
+
_useState48 = _slicedToArray(_useState47, 2);
|
|
802
|
+
_useState48[0];
|
|
803
|
+
var setResizeData = _useState48[1];
|
|
692
804
|
var openImageModal = function openImageModal(url) {
|
|
693
805
|
if (editorRef.current) {
|
|
694
806
|
scrollTopRef.current = editorRef.current.scrollTop;
|
|
@@ -746,6 +858,10 @@ function RichTextEditor(_ref) {
|
|
|
746
858
|
}, [imageModalOpen]);
|
|
747
859
|
useEffect(function () {
|
|
748
860
|
var handleClick = function handleClick(e) {
|
|
861
|
+
// Trigger selection update for toolbar reactivity
|
|
862
|
+
setSelectionVersion(function (v) {
|
|
863
|
+
return v + 1;
|
|
864
|
+
});
|
|
749
865
|
var deleteBtn = e.target.closest('button[title="Remove image"]');
|
|
750
866
|
if (deleteBtn && editable) {
|
|
751
867
|
e.preventDefault();
|
|
@@ -822,21 +938,6 @@ function RichTextEditor(_ref) {
|
|
|
822
938
|
var next = getCleanHtml();
|
|
823
939
|
setHtml(next);
|
|
824
940
|
}, []);
|
|
825
|
-
var handleChange = function handleChange() {
|
|
826
|
-
if (!editorRef.current) return;
|
|
827
|
-
|
|
828
|
-
// Clone editor content
|
|
829
|
-
var tempDiv = document.createElement('div');
|
|
830
|
-
tempDiv.innerHTML = editorRef.current.innerHTML;
|
|
831
|
-
|
|
832
|
-
// Remove delete buttons from the clone
|
|
833
|
-
tempDiv.querySelectorAll('button[title="Remove image"]').forEach(function (btn) {
|
|
834
|
-
return btn.remove();
|
|
835
|
-
});
|
|
836
|
-
|
|
837
|
-
// Send cleaned HTML to onBlur
|
|
838
|
-
onBlur && onBlur(tempDiv.innerHTML);
|
|
839
|
-
};
|
|
840
941
|
|
|
841
942
|
// Detect if selection is inside a list (ol or ul)
|
|
842
943
|
var detectListType = function detectListType() {
|
|
@@ -969,10 +1070,10 @@ function RichTextEditor(_ref) {
|
|
|
969
1070
|
triggerChange();
|
|
970
1071
|
focus();
|
|
971
1072
|
};
|
|
972
|
-
var
|
|
973
|
-
|
|
974
|
-
fontColor =
|
|
975
|
-
setFontColor =
|
|
1073
|
+
var _useState49 = useState("#000000"),
|
|
1074
|
+
_useState50 = _slicedToArray(_useState49, 2),
|
|
1075
|
+
fontColor = _useState50[0],
|
|
1076
|
+
setFontColor = _useState50[1];
|
|
976
1077
|
var handleColorChange = function handleColorChange(color) {
|
|
977
1078
|
setFontColor(color);
|
|
978
1079
|
exec("foreColor", color);
|
|
@@ -992,6 +1093,177 @@ function RichTextEditor(_ref) {
|
|
|
992
1093
|
setLinkModalOpen(true);
|
|
993
1094
|
}
|
|
994
1095
|
};
|
|
1096
|
+
var findParentTag = function findParentTag(node, tagName) {
|
|
1097
|
+
if (!node) return null;
|
|
1098
|
+
var curr = node;
|
|
1099
|
+
while (curr && curr !== editorRef.current) {
|
|
1100
|
+
if (curr.tagName === tagName) return curr;
|
|
1101
|
+
curr = curr.parentNode;
|
|
1102
|
+
}
|
|
1103
|
+
return null;
|
|
1104
|
+
};
|
|
1105
|
+
var tableAction = function tableAction(action) {
|
|
1106
|
+
var sel = window.getSelection();
|
|
1107
|
+
if (!sel || !sel.rangeCount) return;
|
|
1108
|
+
var cell = findParentTag(sel.anchorNode, 'TD') || findParentTag(sel.anchorNode, 'TH');
|
|
1109
|
+
if (!cell) return;
|
|
1110
|
+
var row = cell.parentNode;
|
|
1111
|
+
var table = row.parentNode.closest('table');
|
|
1112
|
+
switch (action) {
|
|
1113
|
+
case 'addRowAbove':
|
|
1114
|
+
var newRowAbove = table.insertRow(row.rowIndex);
|
|
1115
|
+
for (var i = 0; i < row.cells.length; i++) {
|
|
1116
|
+
var newCell = newRowAbove.insertCell(i);
|
|
1117
|
+
newCell.style.border = "1px solid #e5e7eb";
|
|
1118
|
+
newCell.style.padding = "12px";
|
|
1119
|
+
newCell.innerHTML = " ";
|
|
1120
|
+
}
|
|
1121
|
+
break;
|
|
1122
|
+
case 'addRowBelow':
|
|
1123
|
+
var newRowBelow = table.insertRow(row.rowIndex + 1);
|
|
1124
|
+
for (var _i = 0; _i < row.cells.length; _i++) {
|
|
1125
|
+
var _newCell = newRowBelow.insertCell(_i);
|
|
1126
|
+
_newCell.style.border = "1px solid #e5e7eb";
|
|
1127
|
+
_newCell.style.padding = "12px";
|
|
1128
|
+
_newCell.innerHTML = " ";
|
|
1129
|
+
}
|
|
1130
|
+
break;
|
|
1131
|
+
case 'addColBefore':
|
|
1132
|
+
var cellIndex = cell.cellIndex;
|
|
1133
|
+
for (var _i2 = 0; _i2 < table.rows.length; _i2++) {
|
|
1134
|
+
var _newCell2 = table.rows[_i2].insertCell(cellIndex);
|
|
1135
|
+
_newCell2.style.border = "1px solid #e5e7eb";
|
|
1136
|
+
_newCell2.style.padding = "12px";
|
|
1137
|
+
_newCell2.innerHTML = " ";
|
|
1138
|
+
}
|
|
1139
|
+
break;
|
|
1140
|
+
case 'addColAfter':
|
|
1141
|
+
var cellIndexAfter = cell.cellIndex + 1;
|
|
1142
|
+
for (var _i3 = 0; _i3 < table.rows.length; _i3++) {
|
|
1143
|
+
var _newCell3 = table.rows[_i3].insertCell(cellIndexAfter);
|
|
1144
|
+
_newCell3.style.border = "1px solid #e5e7eb";
|
|
1145
|
+
_newCell3.style.padding = "12px";
|
|
1146
|
+
_newCell3.innerHTML = " ";
|
|
1147
|
+
}
|
|
1148
|
+
break;
|
|
1149
|
+
case 'deleteRow':
|
|
1150
|
+
{
|
|
1151
|
+
var rowIndex = row.rowIndex;
|
|
1152
|
+
var _cellIndex = cell.cellIndex;
|
|
1153
|
+
table.deleteRow(rowIndex);
|
|
1154
|
+
if (table.rows.length === 0) {
|
|
1155
|
+
table.remove();
|
|
1156
|
+
} else {
|
|
1157
|
+
var targetRowIndex = Math.min(rowIndex, table.rows.length - 1);
|
|
1158
|
+
var targetRow = table.rows[targetRowIndex];
|
|
1159
|
+
var targetCell = targetRow.cells[Math.min(_cellIndex, targetRow.cells.length - 1)];
|
|
1160
|
+
if (targetCell) {
|
|
1161
|
+
var range = document.createRange();
|
|
1162
|
+
range.selectNodeContents(targetCell);
|
|
1163
|
+
range.collapse(true);
|
|
1164
|
+
sel.removeAllRanges();
|
|
1165
|
+
sel.addRange(range);
|
|
1166
|
+
setSelectionVersion(function (v) {
|
|
1167
|
+
return v + 1;
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
break;
|
|
1172
|
+
}
|
|
1173
|
+
case 'deleteCol':
|
|
1174
|
+
{
|
|
1175
|
+
var idx = cell.cellIndex;
|
|
1176
|
+
var _rowIndex = row.rowIndex;
|
|
1177
|
+
for (var _i4 = 0; _i4 < table.rows.length; _i4++) {
|
|
1178
|
+
table.rows[_i4].deleteCell(idx);
|
|
1179
|
+
}
|
|
1180
|
+
if (table.rows[0].cells.length === 0) {
|
|
1181
|
+
table.remove();
|
|
1182
|
+
} else {
|
|
1183
|
+
var _table$rows$_rowIndex;
|
|
1184
|
+
var targetColIndex = Math.min(idx, table.rows[0].cells.length - 1);
|
|
1185
|
+
var _targetCell = ((_table$rows$_rowIndex = table.rows[_rowIndex]) === null || _table$rows$_rowIndex === void 0 ? void 0 : _table$rows$_rowIndex.cells[targetColIndex]) || table.rows[0].cells[targetColIndex];
|
|
1186
|
+
if (_targetCell) {
|
|
1187
|
+
var _range = document.createRange();
|
|
1188
|
+
_range.selectNodeContents(_targetCell);
|
|
1189
|
+
_range.collapse(true);
|
|
1190
|
+
sel.removeAllRanges();
|
|
1191
|
+
sel.addRange(_range);
|
|
1192
|
+
setSelectionVersion(function (v) {
|
|
1193
|
+
return v + 1;
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
break;
|
|
1198
|
+
}
|
|
1199
|
+
case 'mergeRight':
|
|
1200
|
+
if (cell.nextElementSibling) {
|
|
1201
|
+
var nextCell = cell.nextElementSibling;
|
|
1202
|
+
cell.colSpan = (cell.colSpan || 1) + (nextCell.colSpan || 1);
|
|
1203
|
+
nextCell.remove();
|
|
1204
|
+
}
|
|
1205
|
+
break;
|
|
1206
|
+
case 'deleteTable':
|
|
1207
|
+
table.remove();
|
|
1208
|
+
break;
|
|
1209
|
+
}
|
|
1210
|
+
triggerChange && triggerChange();
|
|
1211
|
+
};
|
|
1212
|
+
var insertTable = function insertTable() {
|
|
1213
|
+
var rows = parseInt(tableRows) || 3;
|
|
1214
|
+
var cols = parseInt(tableCols) || 3;
|
|
1215
|
+
var tableHtml = '<table style="width: 100%; border-collapse: collapse; border: 1px solid #e5e7eb; margin: 16px 0;"><tbody>';
|
|
1216
|
+
for (var i = 0; i < rows; i++) {
|
|
1217
|
+
tableHtml += '<tr>';
|
|
1218
|
+
for (var j = 0; j < cols; j++) {
|
|
1219
|
+
tableHtml += '<td style="border: 1px solid #e5e7eb; padding: 12px; min-height: 20px;"> </td>';
|
|
1220
|
+
}
|
|
1221
|
+
tableHtml += '</tr>';
|
|
1222
|
+
}
|
|
1223
|
+
tableHtml += '</tbody></table><p> </p>';
|
|
1224
|
+
if (selectionRangeRef.current) {
|
|
1225
|
+
var sel = window.getSelection();
|
|
1226
|
+
sel.removeAllRanges();
|
|
1227
|
+
sel.addRange(selectionRangeRef.current);
|
|
1228
|
+
}
|
|
1229
|
+
document.execCommand("insertHTML", false, tableHtml);
|
|
1230
|
+
setTableModalOpen(false);
|
|
1231
|
+
triggerChange && triggerChange();
|
|
1232
|
+
};
|
|
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
|
+
if (editorRef.current) {
|
|
1241
|
+
editorRef.current.focus();
|
|
1242
|
+
}
|
|
1243
|
+
if (selectionRangeRef.current) {
|
|
1244
|
+
var sel = window.getSelection();
|
|
1245
|
+
sel.removeAllRanges();
|
|
1246
|
+
sel.addRange(selectionRangeRef.current);
|
|
1247
|
+
}
|
|
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> </p>");
|
|
1249
|
+
try {
|
|
1250
|
+
document.execCommand("insertHTML", false, embedHtml);
|
|
1251
|
+
} catch (err) {
|
|
1252
|
+
console.error("Failed to insert YouTube HTML:", err);
|
|
1253
|
+
// Fallback: append to the end of the editor
|
|
1254
|
+
if (editorRef.current) {
|
|
1255
|
+
var div = document.createElement('div');
|
|
1256
|
+
div.innerHTML = embedHtml;
|
|
1257
|
+
editorRef.current.appendChild(div);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
} else {
|
|
1261
|
+
console.warn("Invalid YouTube URL or Video ID not found");
|
|
1262
|
+
}
|
|
1263
|
+
setYoutubeModalOpen(false);
|
|
1264
|
+
setYoutubeUrl("");
|
|
1265
|
+
triggerChange && triggerChange();
|
|
1266
|
+
};
|
|
995
1267
|
var processExistingImages = function processExistingImages(container) {
|
|
996
1268
|
if (!container) return;
|
|
997
1269
|
container.querySelectorAll("img").forEach(function (img) {
|
|
@@ -1514,8 +1786,8 @@ function RichTextEditor(_ref) {
|
|
|
1514
1786
|
var lastInsertedNode = null;
|
|
1515
1787
|
|
|
1516
1788
|
// Iterate through the selected text nodes and wrap them in spans
|
|
1517
|
-
for (var
|
|
1518
|
-
var textNode = _nodesToStyle[
|
|
1789
|
+
for (var _i5 = 0, _nodesToStyle = nodesToStyle; _i5 < _nodesToStyle.length; _i5++) {
|
|
1790
|
+
var textNode = _nodesToStyle[_i5];
|
|
1519
1791
|
var parent = textNode.parentNode;
|
|
1520
1792
|
|
|
1521
1793
|
// This is important: check if the parent is a block-level element
|
|
@@ -1612,6 +1884,9 @@ function RichTextEditor(_ref) {
|
|
|
1612
1884
|
}
|
|
1613
1885
|
}, [disabled]);
|
|
1614
1886
|
var handleEditorClick = useCallback(function (e) {
|
|
1887
|
+
setSelectionVersion(function (v) {
|
|
1888
|
+
return v + 1;
|
|
1889
|
+
});
|
|
1615
1890
|
// Check if the click is on a link
|
|
1616
1891
|
var clickedLink = e.target.closest('a');
|
|
1617
1892
|
if (clickedLink) {
|
|
@@ -1621,6 +1896,15 @@ function RichTextEditor(_ref) {
|
|
|
1621
1896
|
return;
|
|
1622
1897
|
}
|
|
1623
1898
|
|
|
1899
|
+
// NEW: Check if click is on an image for resizing
|
|
1900
|
+
var clickedImg = e.target.closest('img');
|
|
1901
|
+
if (clickedImg && !clickedImg.closest('.rte-modal')) {
|
|
1902
|
+
setSelectedImage(clickedImg);
|
|
1903
|
+
setResizeData({});
|
|
1904
|
+
} else if (!e.target.closest('.resize-handle')) {
|
|
1905
|
+
setSelectedImage(null);
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1624
1908
|
// If disabled is true, prevent editing
|
|
1625
1909
|
if (disabled === true) {
|
|
1626
1910
|
e.preventDefault();
|
|
@@ -1637,14 +1921,138 @@ function RichTextEditor(_ref) {
|
|
|
1637
1921
|
}, 0);
|
|
1638
1922
|
}
|
|
1639
1923
|
}, [editable, disabled]);
|
|
1924
|
+
var startResize = function startResize(e, direction) {
|
|
1925
|
+
e.preventDefault();
|
|
1926
|
+
e.stopPropagation();
|
|
1927
|
+
var img = selectedImage;
|
|
1928
|
+
var startX = e.clientX;
|
|
1929
|
+
var startY = e.clientY;
|
|
1930
|
+
var startWidth = img.offsetWidth;
|
|
1931
|
+
var startHeight = img.offsetHeight;
|
|
1932
|
+
var onMouseMove = function onMouseMove(moveEvent) {
|
|
1933
|
+
var newWidth = startWidth;
|
|
1934
|
+
var newHeight = startHeight;
|
|
1935
|
+
if (direction.includes('e')) newWidth = startWidth + (moveEvent.clientX - startX);
|
|
1936
|
+
if (direction.includes('w')) newWidth = startWidth - (moveEvent.clientX - startX);
|
|
1937
|
+
if (direction.includes('s')) newHeight = startHeight + (moveEvent.clientY - startY);
|
|
1938
|
+
if (direction.includes('n')) newHeight = startHeight - (moveEvent.clientY - startY);
|
|
1939
|
+
img.style.width = "".concat(newWidth, "px");
|
|
1940
|
+
img.style.height = "".concat(newHeight, "px");
|
|
1941
|
+
setResizeData({}); // Force re-render of handles
|
|
1942
|
+
};
|
|
1943
|
+
var _onMouseUp = function onMouseUp() {
|
|
1944
|
+
document.removeEventListener('mousemove', onMouseMove);
|
|
1945
|
+
document.removeEventListener('mouseup', _onMouseUp);
|
|
1946
|
+
triggerChange();
|
|
1947
|
+
};
|
|
1948
|
+
document.addEventListener('mousemove', onMouseMove);
|
|
1949
|
+
document.addEventListener('mouseup', _onMouseUp);
|
|
1950
|
+
};
|
|
1951
|
+
var renderResizeHandles = function renderResizeHandles() {
|
|
1952
|
+
if (!selectedImage || !editorRef.current) return null;
|
|
1953
|
+
var editorRect = editorRef.current.getBoundingClientRect();
|
|
1954
|
+
var imgRect = selectedImage.getBoundingClientRect();
|
|
1955
|
+
|
|
1956
|
+
// Relative position within editorRef using the more robust BoundingClientRect
|
|
1957
|
+
var top = imgRect.top - editorRect.top + editorRef.current.scrollTop;
|
|
1958
|
+
var left = imgRect.left - editorRect.left + editorRef.current.scrollLeft;
|
|
1959
|
+
var width = imgRect.width;
|
|
1960
|
+
var height = imgRect.height;
|
|
1961
|
+
var handleStyles = {
|
|
1962
|
+
position: 'absolute',
|
|
1963
|
+
width: '10px',
|
|
1964
|
+
height: '10px',
|
|
1965
|
+
background: '#3b82f6',
|
|
1966
|
+
border: '2px solid white',
|
|
1967
|
+
borderRadius: '50%',
|
|
1968
|
+
zIndex: 100
|
|
1969
|
+
};
|
|
1970
|
+
var handles = [{
|
|
1971
|
+
id: 'nw',
|
|
1972
|
+
style: {
|
|
1973
|
+
top: top - 5,
|
|
1974
|
+
left: left - 5,
|
|
1975
|
+
cursor: 'nw-resize'
|
|
1976
|
+
}
|
|
1977
|
+
}, {
|
|
1978
|
+
id: 'ne',
|
|
1979
|
+
style: {
|
|
1980
|
+
top: top - 5,
|
|
1981
|
+
left: left + width - 5,
|
|
1982
|
+
cursor: 'ne-resize'
|
|
1983
|
+
}
|
|
1984
|
+
}, {
|
|
1985
|
+
id: 'sw',
|
|
1986
|
+
style: {
|
|
1987
|
+
top: top + height - 5,
|
|
1988
|
+
left: left - 5,
|
|
1989
|
+
cursor: 'sw-resize'
|
|
1990
|
+
}
|
|
1991
|
+
}, {
|
|
1992
|
+
id: 'se',
|
|
1993
|
+
style: {
|
|
1994
|
+
top: top + height - 5,
|
|
1995
|
+
left: left + width - 5,
|
|
1996
|
+
cursor: 'se-resize'
|
|
1997
|
+
}
|
|
1998
|
+
}];
|
|
1999
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
2000
|
+
style: {
|
|
2001
|
+
position: 'absolute',
|
|
2002
|
+
top: 0,
|
|
2003
|
+
left: 0,
|
|
2004
|
+
width: '100%',
|
|
2005
|
+
height: '100%',
|
|
2006
|
+
pointerEvents: 'none'
|
|
2007
|
+
}
|
|
2008
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
2009
|
+
style: {
|
|
2010
|
+
position: 'absolute',
|
|
2011
|
+
top: top,
|
|
2012
|
+
left: left,
|
|
2013
|
+
width: width,
|
|
2014
|
+
height: height,
|
|
2015
|
+
border: '2px solid #3b82f6',
|
|
2016
|
+
pointerEvents: 'none'
|
|
2017
|
+
}
|
|
2018
|
+
}), handles.map(function (h) {
|
|
2019
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
2020
|
+
key: h.id,
|
|
2021
|
+
className: "resize-handle",
|
|
2022
|
+
onMouseDown: function onMouseDown(e) {
|
|
2023
|
+
return startResize(e, h.id);
|
|
2024
|
+
},
|
|
2025
|
+
style: _objectSpread2(_objectSpread2(_objectSpread2({}, handleStyles), h.style), {}, {
|
|
2026
|
+
pointerEvents: 'auto'
|
|
2027
|
+
})
|
|
2028
|
+
});
|
|
2029
|
+
}));
|
|
2030
|
+
};
|
|
1640
2031
|
return /*#__PURE__*/React.createElement("div", {
|
|
1641
2032
|
className: "rte-main-wrapper",
|
|
1642
2033
|
style: {
|
|
1643
|
-
width: '100%'
|
|
2034
|
+
width: '100%',
|
|
2035
|
+
position: 'relative'
|
|
1644
2036
|
}
|
|
1645
2037
|
}, label && /*#__PURE__*/React.createElement(LabelComponent, null, label), /*#__PURE__*/React.createElement("div", {
|
|
2038
|
+
style: {
|
|
2039
|
+
position: 'relative'
|
|
2040
|
+
},
|
|
1646
2041
|
className: !showBorder ? "" : "rte-container",
|
|
1647
2042
|
onClick: handleEditorClick,
|
|
2043
|
+
onMouseOver: function onMouseOver(e) {
|
|
2044
|
+
var table = e.target.closest('table');
|
|
2045
|
+
if (table && editorRef.current.contains(table)) {
|
|
2046
|
+
setHoveredTable(table);
|
|
2047
|
+
}
|
|
2048
|
+
},
|
|
2049
|
+
onMouseOut: function onMouseOut(e) {
|
|
2050
|
+
var table = e.target.closest('table');
|
|
2051
|
+
var related = e.relatedTarget;
|
|
2052
|
+
if (table && (!related || !table.contains(related)) && !(related !== null && related !== void 0 && related.closest('.rte-table-delete-hover'))) {
|
|
2053
|
+
setHoveredTable(null);
|
|
2054
|
+
}
|
|
2055
|
+
},
|
|
1648
2056
|
onDrop: handleDrop,
|
|
1649
2057
|
onDragOver: function onDragOver(e) {
|
|
1650
2058
|
e.preventDefault();
|
|
@@ -1659,7 +2067,7 @@ function RichTextEditor(_ref) {
|
|
|
1659
2067
|
e.preventDefault();
|
|
1660
2068
|
e.stopPropagation();
|
|
1661
2069
|
document.execCommand("bold");
|
|
1662
|
-
|
|
2070
|
+
handleInput();
|
|
1663
2071
|
focus();
|
|
1664
2072
|
},
|
|
1665
2073
|
className: "rte-toolbar-button ".concat(isBold ? "active" : "")
|
|
@@ -1672,7 +2080,7 @@ function RichTextEditor(_ref) {
|
|
|
1672
2080
|
e.preventDefault();
|
|
1673
2081
|
e.stopPropagation();
|
|
1674
2082
|
document.execCommand("italic");
|
|
1675
|
-
|
|
2083
|
+
handleInput();
|
|
1676
2084
|
focus();
|
|
1677
2085
|
},
|
|
1678
2086
|
className: "rte-toolbar-button ".concat(isItalic ? "active" : "")
|
|
@@ -1685,7 +2093,7 @@ function RichTextEditor(_ref) {
|
|
|
1685
2093
|
e.preventDefault();
|
|
1686
2094
|
e.stopPropagation();
|
|
1687
2095
|
document.execCommand("underline");
|
|
1688
|
-
|
|
2096
|
+
handleInput();
|
|
1689
2097
|
focus();
|
|
1690
2098
|
},
|
|
1691
2099
|
className: "rte-toolbar-button ".concat(isUnderline ? "active" : "")
|
|
@@ -1857,6 +2265,13 @@ function RichTextEditor(_ref) {
|
|
|
1857
2265
|
backgroundColor: '#e5e7eb',
|
|
1858
2266
|
margin: '0 4px'
|
|
1859
2267
|
}
|
|
2268
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
2269
|
+
style: {
|
|
2270
|
+
width: '1px',
|
|
2271
|
+
height: '20px',
|
|
2272
|
+
backgroundColor: '#e5e7eb',
|
|
2273
|
+
margin: '0 4px'
|
|
2274
|
+
}
|
|
1860
2275
|
}), /*#__PURE__*/React.createElement("button", {
|
|
1861
2276
|
type: "button",
|
|
1862
2277
|
title: "Add Link",
|
|
@@ -1897,7 +2312,151 @@ function RichTextEditor(_ref) {
|
|
|
1897
2312
|
}
|
|
1898
2313
|
}) : /*#__PURE__*/React.createElement(FaImage, {
|
|
1899
2314
|
size: 14
|
|
1900
|
-
}))
|
|
2315
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
2316
|
+
style: {
|
|
2317
|
+
width: '1px',
|
|
2318
|
+
height: '20px',
|
|
2319
|
+
backgroundColor: '#e5e7eb',
|
|
2320
|
+
margin: '0 4px'
|
|
2321
|
+
}
|
|
2322
|
+
}), /*#__PURE__*/React.createElement("button", {
|
|
2323
|
+
type: "button",
|
|
2324
|
+
title: "Insert Table",
|
|
2325
|
+
className: "rte-toolbar-button",
|
|
2326
|
+
onMouseDown: function onMouseDown(e) {
|
|
2327
|
+
e.preventDefault();
|
|
2328
|
+
var sel = window.getSelection();
|
|
2329
|
+
if (sel && sel.rangeCount > 0) {
|
|
2330
|
+
selectionRangeRef.current = sel.getRangeAt(0).cloneRange();
|
|
2331
|
+
}
|
|
2332
|
+
setTableModalOpen(true);
|
|
2333
|
+
}
|
|
2334
|
+
}, /*#__PURE__*/React.createElement(FaTable, {
|
|
2335
|
+
size: 14
|
|
2336
|
+
})), /*#__PURE__*/React.createElement("button", {
|
|
2337
|
+
type: "button",
|
|
2338
|
+
title: "Embed YouTube Video",
|
|
2339
|
+
className: "rte-toolbar-button",
|
|
2340
|
+
onMouseDown: function onMouseDown(e) {
|
|
2341
|
+
e.preventDefault();
|
|
2342
|
+
var sel = window.getSelection();
|
|
2343
|
+
if (sel && sel.rangeCount > 0) {
|
|
2344
|
+
selectionRangeRef.current = sel.getRangeAt(0).cloneRange();
|
|
2345
|
+
}
|
|
2346
|
+
setYoutubeModalOpen(true);
|
|
2347
|
+
}
|
|
2348
|
+
}, /*#__PURE__*/React.createElement(FaYoutube, {
|
|
2349
|
+
size: 14
|
|
2350
|
+
})), function () {
|
|
2351
|
+
if (typeof window === "undefined") return null;
|
|
2352
|
+
var sel = window.getSelection();
|
|
2353
|
+
// Robust check: inside cell OR the table itself is selected
|
|
2354
|
+
var isCell = sel && sel.rangeCount > 0 && sel.anchorNode && (findParentTag(sel.anchorNode, 'TD') || findParentTag(sel.anchorNode, 'TH'));
|
|
2355
|
+
var isTable = sel && sel.rangeCount > 0 && sel.anchorNode && findParentTag(sel.anchorNode, 'TABLE');
|
|
2356
|
+
if (isCell || isTable) {
|
|
2357
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
2358
|
+
style: {
|
|
2359
|
+
width: '1px',
|
|
2360
|
+
height: '20px',
|
|
2361
|
+
backgroundColor: '#e5e7eb',
|
|
2362
|
+
margin: '0 4px'
|
|
2363
|
+
}
|
|
2364
|
+
}), /*#__PURE__*/React.createElement("button", {
|
|
2365
|
+
type: "button",
|
|
2366
|
+
title: "Add Row Above",
|
|
2367
|
+
className: "rte-toolbar-button",
|
|
2368
|
+
onMouseDown: function onMouseDown(e) {
|
|
2369
|
+
e.preventDefault();
|
|
2370
|
+
tableAction('addRowAbove');
|
|
2371
|
+
}
|
|
2372
|
+
}, "+R\u2191"), /*#__PURE__*/React.createElement("button", {
|
|
2373
|
+
type: "button",
|
|
2374
|
+
title: "Add Row Below",
|
|
2375
|
+
className: "rte-toolbar-button",
|
|
2376
|
+
onMouseDown: function onMouseDown(e) {
|
|
2377
|
+
e.preventDefault();
|
|
2378
|
+
tableAction('addRowBelow');
|
|
2379
|
+
}
|
|
2380
|
+
}, "+R\u2193"), /*#__PURE__*/React.createElement("button", {
|
|
2381
|
+
type: "button",
|
|
2382
|
+
title: "Add Col Before",
|
|
2383
|
+
className: "rte-toolbar-button",
|
|
2384
|
+
onMouseDown: function onMouseDown(e) {
|
|
2385
|
+
e.preventDefault();
|
|
2386
|
+
tableAction('addColBefore');
|
|
2387
|
+
}
|
|
2388
|
+
}, "+C\u2190"), /*#__PURE__*/React.createElement("button", {
|
|
2389
|
+
type: "button",
|
|
2390
|
+
title: "Add Col After",
|
|
2391
|
+
className: "rte-toolbar-button",
|
|
2392
|
+
onMouseDown: function onMouseDown(e) {
|
|
2393
|
+
e.preventDefault();
|
|
2394
|
+
tableAction('addColAfter');
|
|
2395
|
+
}
|
|
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", {
|
|
2404
|
+
type: "button",
|
|
2405
|
+
title: "Merge Cells (Right)",
|
|
2406
|
+
className: "rte-toolbar-button",
|
|
2407
|
+
onMouseDown: function onMouseDown(e) {
|
|
2408
|
+
e.preventDefault();
|
|
2409
|
+
tableAction('mergeRight');
|
|
2410
|
+
}
|
|
2411
|
+
}, /*#__PURE__*/React.createElement(FaObjectGroup, {
|
|
2412
|
+
size: 14
|
|
2413
|
+
})), /*#__PURE__*/React.createElement("button", {
|
|
2414
|
+
type: "button",
|
|
2415
|
+
title: "Delete Row",
|
|
2416
|
+
className: "rte-toolbar-button rte-toolbar-button-danger ",
|
|
2417
|
+
onMouseDown: function onMouseDown(e) {
|
|
2418
|
+
e.preventDefault();
|
|
2419
|
+
tableAction('deleteRow');
|
|
2420
|
+
}
|
|
2421
|
+
}, /*#__PURE__*/React.createElement(FaTrash, {
|
|
2422
|
+
size: 12
|
|
2423
|
+
}), " ", /*#__PURE__*/React.createElement("span", {
|
|
2424
|
+
style: {
|
|
2425
|
+
fontSize: '10px'
|
|
2426
|
+
}
|
|
2427
|
+
}, "Row")), /*#__PURE__*/React.createElement("button", {
|
|
2428
|
+
type: "button",
|
|
2429
|
+
title: "Delete Column",
|
|
2430
|
+
className: "rte-toolbar-button rte-toolbar-button-danger",
|
|
2431
|
+
onMouseDown: function onMouseDown(e) {
|
|
2432
|
+
e.preventDefault();
|
|
2433
|
+
tableAction('deleteCol');
|
|
2434
|
+
}
|
|
2435
|
+
}, /*#__PURE__*/React.createElement(FaTrash, {
|
|
2436
|
+
size: 12
|
|
2437
|
+
}), " ", /*#__PURE__*/React.createElement("span", {
|
|
2438
|
+
style: {
|
|
2439
|
+
fontSize: '10px',
|
|
2440
|
+
marginRight: "5px"
|
|
2441
|
+
}
|
|
2442
|
+
}, "Col")), /*#__PURE__*/React.createElement("button", {
|
|
2443
|
+
type: "button",
|
|
2444
|
+
title: "Delete Table",
|
|
2445
|
+
className: "rte-toolbar-button rte-toolbar-button-danger",
|
|
2446
|
+
onMouseDown: function onMouseDown(e) {
|
|
2447
|
+
e.preventDefault();
|
|
2448
|
+
tableAction('deleteTable');
|
|
2449
|
+
}
|
|
2450
|
+
}, /*#__PURE__*/React.createElement(FaTrash, {
|
|
2451
|
+
size: 14
|
|
2452
|
+
}), " ", /*#__PURE__*/React.createElement("span", {
|
|
2453
|
+
style: {
|
|
2454
|
+
fontWeight: '600'
|
|
2455
|
+
}
|
|
2456
|
+
}, "Table")));
|
|
2457
|
+
}
|
|
2458
|
+
return null;
|
|
2459
|
+
}()), /*#__PURE__*/React.createElement("div", {
|
|
1901
2460
|
ref: editorRef,
|
|
1902
2461
|
contentEditable: editable && disabled !== true,
|
|
1903
2462
|
suppressContentEditableWarning: true,
|
|
@@ -1918,7 +2477,23 @@ function RichTextEditor(_ref) {
|
|
|
1918
2477
|
paddingLeft: paddingLeft || '12px'
|
|
1919
2478
|
},
|
|
1920
2479
|
className: "rte-content"
|
|
1921
|
-
}),
|
|
2480
|
+
}), renderResizeHandles(), /*#__PURE__*/React.createElement("div", {
|
|
2481
|
+
className: "rte-footer"
|
|
2482
|
+
}, function (_editorRef$current) {
|
|
2483
|
+
var text = ((_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 ? void 0 : _editorRef$current.innerText) || "";
|
|
2484
|
+
var cleanText = text.replace(/[\n\r]/g, ' ').trim();
|
|
2485
|
+
var words = cleanText ? cleanText.split(/\s+/).length : 0;
|
|
2486
|
+
var chars = text.length;
|
|
2487
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
2488
|
+
className: "rte-footer-content"
|
|
2489
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
2490
|
+
className: "rte-footer-item"
|
|
2491
|
+
}, /*#__PURE__*/React.createElement("b", null, words), " words"), /*#__PURE__*/React.createElement("span", {
|
|
2492
|
+
className: "rte-footer-separator"
|
|
2493
|
+
}, "\u2022"), /*#__PURE__*/React.createElement("span", {
|
|
2494
|
+
className: "rte-footer-item"
|
|
2495
|
+
}, /*#__PURE__*/React.createElement("b", null, chars), " characters"));
|
|
2496
|
+
}()), linkModalOpen && /*#__PURE__*/React.createElement("div", {
|
|
1922
2497
|
className: "rte-modal-overlay",
|
|
1923
2498
|
onClick: cancelLink
|
|
1924
2499
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -1929,42 +2504,147 @@ function RichTextEditor(_ref) {
|
|
|
1929
2504
|
}, /*#__PURE__*/React.createElement("h3", {
|
|
1930
2505
|
className: "rte-modal-title"
|
|
1931
2506
|
}, "Insert Link"), /*#__PURE__*/React.createElement("div", {
|
|
2507
|
+
className: "rte-modal-divider"
|
|
2508
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
2509
|
+
className: "rte-modal-body"
|
|
2510
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
2511
|
+
className: "rte-form-group"
|
|
2512
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
2513
|
+
className: "rte-label"
|
|
2514
|
+
}, "Link Text"), /*#__PURE__*/React.createElement("input", {
|
|
2515
|
+
type: "text",
|
|
2516
|
+
className: "rte-input",
|
|
2517
|
+
placeholder: "e.g. Google",
|
|
2518
|
+
value: linkText,
|
|
2519
|
+
onChange: function onChange(e) {
|
|
2520
|
+
return setLinkText(e.target.value);
|
|
2521
|
+
}
|
|
2522
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
1932
2523
|
className: "rte-form-group"
|
|
1933
2524
|
}, /*#__PURE__*/React.createElement("label", {
|
|
1934
2525
|
className: "rte-label"
|
|
1935
2526
|
}, "URL"), /*#__PURE__*/React.createElement("input", {
|
|
1936
|
-
type: "
|
|
2527
|
+
type: "text",
|
|
1937
2528
|
className: "rte-input",
|
|
2529
|
+
placeholder: "https://example.com",
|
|
1938
2530
|
value: linkUrl,
|
|
1939
2531
|
onChange: function onChange(e) {
|
|
1940
2532
|
return setLinkUrl(e.target.value);
|
|
1941
2533
|
},
|
|
1942
|
-
|
|
1943
|
-
|
|
2534
|
+
onKeyDown: function onKeyDown(e) {
|
|
2535
|
+
return e.key === 'Enter' && confirmLink();
|
|
2536
|
+
},
|
|
2537
|
+
autoFocus: true
|
|
2538
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
2539
|
+
className: "rte-modal-divider",
|
|
2540
|
+
style: {
|
|
2541
|
+
margin: '8px 0 20px 0'
|
|
2542
|
+
}
|
|
2543
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
2544
|
+
className: "rte-modal-footer"
|
|
2545
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
2546
|
+
type: "button",
|
|
2547
|
+
className: "rte-btn rte-btn-secondary",
|
|
2548
|
+
onClick: cancelLink
|
|
2549
|
+
}, "Cancel"), /*#__PURE__*/React.createElement("button", {
|
|
2550
|
+
type: "button",
|
|
2551
|
+
className: "rte-btn rte-btn-primary",
|
|
2552
|
+
onClick: confirmLink,
|
|
2553
|
+
disabled: !linkUrl
|
|
2554
|
+
}, "Insert")))), tableModalOpen && /*#__PURE__*/React.createElement("div", {
|
|
2555
|
+
className: "rte-modal-overlay",
|
|
2556
|
+
onClick: function onClick() {
|
|
2557
|
+
return setTableModalOpen(false);
|
|
2558
|
+
}
|
|
2559
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
2560
|
+
className: "rte-modal",
|
|
2561
|
+
onClick: function onClick(e) {
|
|
2562
|
+
return e.stopPropagation();
|
|
2563
|
+
}
|
|
2564
|
+
}, /*#__PURE__*/React.createElement("h3", {
|
|
2565
|
+
className: "rte-modal-title"
|
|
2566
|
+
}, "Insert Table"), /*#__PURE__*/React.createElement("div", {
|
|
2567
|
+
className: "rte-form-group"
|
|
2568
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
2569
|
+
className: "rte-label"
|
|
2570
|
+
}, "Rows"), /*#__PURE__*/React.createElement("input", {
|
|
2571
|
+
type: "number",
|
|
2572
|
+
className: "rte-input",
|
|
2573
|
+
value: tableRows,
|
|
2574
|
+
onChange: function onChange(e) {
|
|
2575
|
+
return setTableRows(e.target.value);
|
|
2576
|
+
},
|
|
2577
|
+
min: "1",
|
|
2578
|
+
max: "10"
|
|
1944
2579
|
})), /*#__PURE__*/React.createElement("div", {
|
|
1945
2580
|
className: "rte-form-group"
|
|
1946
2581
|
}, /*#__PURE__*/React.createElement("label", {
|
|
1947
2582
|
className: "rte-label"
|
|
1948
|
-
}, "
|
|
2583
|
+
}, "Columns"), /*#__PURE__*/React.createElement("input", {
|
|
2584
|
+
type: "number",
|
|
2585
|
+
className: "rte-input",
|
|
2586
|
+
value: tableCols,
|
|
2587
|
+
onChange: function onChange(e) {
|
|
2588
|
+
return setTableCols(e.target.value);
|
|
2589
|
+
},
|
|
2590
|
+
min: "1",
|
|
2591
|
+
max: "10"
|
|
2592
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
2593
|
+
className: "rte-modal-actions"
|
|
2594
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
2595
|
+
type: "button",
|
|
2596
|
+
className: "rte-button rte-button-secondary",
|
|
2597
|
+
onClick: function onClick() {
|
|
2598
|
+
return setTableModalOpen(false);
|
|
2599
|
+
}
|
|
2600
|
+
}, "Cancel"), /*#__PURE__*/React.createElement("button", {
|
|
2601
|
+
type: "button",
|
|
2602
|
+
className: "rte-button rte-button-primary",
|
|
2603
|
+
onClick: insertTable
|
|
2604
|
+
}, "Insert")))), youtubeModalOpen && /*#__PURE__*/React.createElement("div", {
|
|
2605
|
+
className: "rte-modal-overlay",
|
|
2606
|
+
onClick: function onClick() {
|
|
2607
|
+
return setYoutubeModalOpen(false);
|
|
2608
|
+
}
|
|
2609
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
2610
|
+
className: "rte-modal",
|
|
2611
|
+
onClick: function onClick(e) {
|
|
2612
|
+
return e.stopPropagation();
|
|
2613
|
+
}
|
|
2614
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
2615
|
+
className: "rte-modal-header"
|
|
2616
|
+
}, /*#__PURE__*/React.createElement("h3", {
|
|
2617
|
+
className: "rte-modal-title"
|
|
2618
|
+
}, "Embed YouTube Video")), /*#__PURE__*/React.createElement("div", {
|
|
2619
|
+
className: "rte-form-group"
|
|
2620
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
2621
|
+
className: "rte-label"
|
|
2622
|
+
}, "Paste YouTube Video URL"), /*#__PURE__*/React.createElement("input", {
|
|
1949
2623
|
type: "text",
|
|
1950
2624
|
className: "rte-input",
|
|
1951
|
-
value:
|
|
2625
|
+
value: youtubeUrl,
|
|
1952
2626
|
onChange: function onChange(e) {
|
|
1953
|
-
return
|
|
2627
|
+
return setYoutubeUrl(e.target.value);
|
|
1954
2628
|
},
|
|
1955
|
-
placeholder: "
|
|
2629
|
+
placeholder: "https://www.youtube.com/watch?v=...",
|
|
2630
|
+
autoFocus: true,
|
|
2631
|
+
onKeyDown: function onKeyDown(e) {
|
|
2632
|
+
if (e.key === 'Enter') insertYoutube();
|
|
2633
|
+
if (e.key === 'Escape') setYoutubeModalOpen(false);
|
|
2634
|
+
}
|
|
1956
2635
|
})), /*#__PURE__*/React.createElement("div", {
|
|
1957
2636
|
className: "rte-modal-actions"
|
|
1958
2637
|
}, /*#__PURE__*/React.createElement("button", {
|
|
1959
2638
|
type: "button",
|
|
1960
2639
|
className: "rte-button rte-button-secondary",
|
|
1961
|
-
onClick:
|
|
2640
|
+
onClick: function onClick() {
|
|
2641
|
+
return setYoutubeModalOpen(false);
|
|
2642
|
+
}
|
|
1962
2643
|
}, "Cancel"), /*#__PURE__*/React.createElement("button", {
|
|
1963
2644
|
type: "button",
|
|
1964
2645
|
className: "rte-button rte-button-primary",
|
|
1965
|
-
onClick:
|
|
1966
|
-
|
|
1967
|
-
}, "Insert")))), imageModalOpen && /*#__PURE__*/React.createElement("div", {
|
|
2646
|
+
onClick: insertYoutube
|
|
2647
|
+
}, "Embed Video")))), imageModalOpen && /*#__PURE__*/React.createElement("div", {
|
|
1968
2648
|
className: "rte-modal-overlay",
|
|
1969
2649
|
onClick: closeImageModal
|
|
1970
2650
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -2004,7 +2684,7 @@ function RichTextEditor(_ref) {
|
|
|
2004
2684
|
type: "button",
|
|
2005
2685
|
className: "rte-button rte-button-primary",
|
|
2006
2686
|
onClick: function onClick() {
|
|
2007
|
-
|
|
2687
|
+
onChange && onChange(html);
|
|
2008
2688
|
setEditable(false);
|
|
2009
2689
|
}
|
|
2010
2690
|
}, "Save Changes")));
|