react-lite-rich-text-editor 1.1.1 → 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/README.md +27 -10
- package/dist/index.cjs.js +754 -43
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +754 -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 FaObjectGroup = function FaObjectGroup(_ref16) {
|
|
528
|
+
var className = _ref16.className,
|
|
529
|
+
size = _ref16.size,
|
|
530
|
+
color = _ref16.color,
|
|
531
|
+
style = _ref16.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 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
|
+
}
|
|
544
|
+
});
|
|
545
|
+
};
|
|
546
|
+
var FaTrash = function FaTrash(_ref17) {
|
|
547
|
+
var className = _ref17.className,
|
|
548
|
+
size = _ref17.size,
|
|
549
|
+
color = _ref17.color,
|
|
550
|
+
style = _ref17.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 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
|
+
}
|
|
563
|
+
});
|
|
564
|
+
};
|
|
565
|
+
var FaVideo = function FaVideo(_ref18) {
|
|
566
|
+
var className = _ref18.className,
|
|
567
|
+
size = _ref18.size,
|
|
568
|
+
color = _ref18.color,
|
|
569
|
+
style = _ref18.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 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
|
+
}
|
|
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
|
+
videoModalOpen = _useState32[0],
|
|
771
|
+
setVideoModalOpen = _useState32[1];
|
|
772
|
+
var _useState33 = useState(""),
|
|
773
|
+
_useState34 = _slicedToArray(_useState33, 2),
|
|
774
|
+
videoUrl = _useState34[0],
|
|
775
|
+
setVideoUrl = _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;
|
|
@@ -701,6 +813,13 @@ function RichTextEditor(_ref) {
|
|
|
701
813
|
setSelectedImageUrl("");
|
|
702
814
|
setZoomLevel(1);
|
|
703
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
|
+
};
|
|
704
823
|
var handleZoomIn = function handleZoomIn() {
|
|
705
824
|
setZoomLevel(function (prevZoom) {
|
|
706
825
|
return prevZoom + 0.1;
|
|
@@ -746,6 +865,10 @@ function RichTextEditor(_ref) {
|
|
|
746
865
|
}, [imageModalOpen]);
|
|
747
866
|
useEffect(function () {
|
|
748
867
|
var handleClick = function handleClick(e) {
|
|
868
|
+
// Trigger selection update for toolbar reactivity
|
|
869
|
+
setSelectionVersion(function (v) {
|
|
870
|
+
return v + 1;
|
|
871
|
+
});
|
|
749
872
|
var deleteBtn = e.target.closest('button[title="Remove image"]');
|
|
750
873
|
if (deleteBtn && editable) {
|
|
751
874
|
e.preventDefault();
|
|
@@ -822,21 +945,6 @@ function RichTextEditor(_ref) {
|
|
|
822
945
|
var next = getCleanHtml();
|
|
823
946
|
setHtml(next);
|
|
824
947
|
}, []);
|
|
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
948
|
|
|
841
949
|
// Detect if selection is inside a list (ol or ul)
|
|
842
950
|
var detectListType = function detectListType() {
|
|
@@ -969,10 +1077,10 @@ function RichTextEditor(_ref) {
|
|
|
969
1077
|
triggerChange();
|
|
970
1078
|
focus();
|
|
971
1079
|
};
|
|
972
|
-
var
|
|
973
|
-
|
|
974
|
-
fontColor =
|
|
975
|
-
setFontColor =
|
|
1080
|
+
var _useState49 = useState("#000000"),
|
|
1081
|
+
_useState50 = _slicedToArray(_useState49, 2),
|
|
1082
|
+
fontColor = _useState50[0],
|
|
1083
|
+
setFontColor = _useState50[1];
|
|
976
1084
|
var handleColorChange = function handleColorChange(color) {
|
|
977
1085
|
setFontColor(color);
|
|
978
1086
|
exec("foreColor", color);
|
|
@@ -992,6 +1100,198 @@ function RichTextEditor(_ref) {
|
|
|
992
1100
|
setLinkModalOpen(true);
|
|
993
1101
|
}
|
|
994
1102
|
};
|
|
1103
|
+
var findParentTag = function findParentTag(node, tagName) {
|
|
1104
|
+
if (!node) return null;
|
|
1105
|
+
var curr = node;
|
|
1106
|
+
while (curr && curr !== editorRef.current) {
|
|
1107
|
+
if (curr.tagName === tagName) return curr;
|
|
1108
|
+
curr = curr.parentNode;
|
|
1109
|
+
}
|
|
1110
|
+
return null;
|
|
1111
|
+
};
|
|
1112
|
+
var tableAction = function tableAction(action) {
|
|
1113
|
+
var sel = window.getSelection();
|
|
1114
|
+
if (!sel || !sel.rangeCount) return;
|
|
1115
|
+
var cell = findParentTag(sel.anchorNode, 'TD') || findParentTag(sel.anchorNode, 'TH');
|
|
1116
|
+
if (!cell) return;
|
|
1117
|
+
var row = cell.parentNode;
|
|
1118
|
+
var table = row.parentNode.closest('table');
|
|
1119
|
+
switch (action) {
|
|
1120
|
+
case 'addRowAbove':
|
|
1121
|
+
var newRowAbove = table.insertRow(row.rowIndex);
|
|
1122
|
+
for (var i = 0; i < row.cells.length; i++) {
|
|
1123
|
+
var newCell = newRowAbove.insertCell(i);
|
|
1124
|
+
newCell.style.border = "1px solid #e5e7eb";
|
|
1125
|
+
newCell.style.padding = "12px";
|
|
1126
|
+
newCell.innerHTML = " ";
|
|
1127
|
+
}
|
|
1128
|
+
break;
|
|
1129
|
+
case 'addRowBelow':
|
|
1130
|
+
var newRowBelow = table.insertRow(row.rowIndex + 1);
|
|
1131
|
+
for (var _i = 0; _i < row.cells.length; _i++) {
|
|
1132
|
+
var _newCell = newRowBelow.insertCell(_i);
|
|
1133
|
+
_newCell.style.border = "1px solid #e5e7eb";
|
|
1134
|
+
_newCell.style.padding = "12px";
|
|
1135
|
+
_newCell.innerHTML = " ";
|
|
1136
|
+
}
|
|
1137
|
+
break;
|
|
1138
|
+
case 'addColBefore':
|
|
1139
|
+
var cellIndex = cell.cellIndex;
|
|
1140
|
+
for (var _i2 = 0; _i2 < table.rows.length; _i2++) {
|
|
1141
|
+
var _newCell2 = table.rows[_i2].insertCell(cellIndex);
|
|
1142
|
+
_newCell2.style.border = "1px solid #e5e7eb";
|
|
1143
|
+
_newCell2.style.padding = "12px";
|
|
1144
|
+
_newCell2.innerHTML = " ";
|
|
1145
|
+
}
|
|
1146
|
+
break;
|
|
1147
|
+
case 'addColAfter':
|
|
1148
|
+
var cellIndexAfter = cell.cellIndex + 1;
|
|
1149
|
+
for (var _i3 = 0; _i3 < table.rows.length; _i3++) {
|
|
1150
|
+
var _newCell3 = table.rows[_i3].insertCell(cellIndexAfter);
|
|
1151
|
+
_newCell3.style.border = "1px solid #e5e7eb";
|
|
1152
|
+
_newCell3.style.padding = "12px";
|
|
1153
|
+
_newCell3.innerHTML = " ";
|
|
1154
|
+
}
|
|
1155
|
+
break;
|
|
1156
|
+
case 'deleteRow':
|
|
1157
|
+
{
|
|
1158
|
+
var rowIndex = row.rowIndex;
|
|
1159
|
+
var _cellIndex = cell.cellIndex;
|
|
1160
|
+
table.deleteRow(rowIndex);
|
|
1161
|
+
if (table.rows.length === 0) {
|
|
1162
|
+
table.remove();
|
|
1163
|
+
} else {
|
|
1164
|
+
var targetRowIndex = Math.min(rowIndex, table.rows.length - 1);
|
|
1165
|
+
var targetRow = table.rows[targetRowIndex];
|
|
1166
|
+
var targetCell = targetRow.cells[Math.min(_cellIndex, targetRow.cells.length - 1)];
|
|
1167
|
+
if (targetCell) {
|
|
1168
|
+
var range = document.createRange();
|
|
1169
|
+
range.selectNodeContents(targetCell);
|
|
1170
|
+
range.collapse(true);
|
|
1171
|
+
sel.removeAllRanges();
|
|
1172
|
+
sel.addRange(range);
|
|
1173
|
+
setSelectionVersion(function (v) {
|
|
1174
|
+
return v + 1;
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
break;
|
|
1179
|
+
}
|
|
1180
|
+
case 'deleteCol':
|
|
1181
|
+
{
|
|
1182
|
+
var idx = cell.cellIndex;
|
|
1183
|
+
var _rowIndex = row.rowIndex;
|
|
1184
|
+
for (var _i4 = 0; _i4 < table.rows.length; _i4++) {
|
|
1185
|
+
table.rows[_i4].deleteCell(idx);
|
|
1186
|
+
}
|
|
1187
|
+
if (table.rows[0].cells.length === 0) {
|
|
1188
|
+
table.remove();
|
|
1189
|
+
} else {
|
|
1190
|
+
var _table$rows$_rowIndex;
|
|
1191
|
+
var targetColIndex = Math.min(idx, table.rows[0].cells.length - 1);
|
|
1192
|
+
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];
|
|
1193
|
+
if (_targetCell) {
|
|
1194
|
+
var _range = document.createRange();
|
|
1195
|
+
_range.selectNodeContents(_targetCell);
|
|
1196
|
+
_range.collapse(true);
|
|
1197
|
+
sel.removeAllRanges();
|
|
1198
|
+
sel.addRange(_range);
|
|
1199
|
+
setSelectionVersion(function (v) {
|
|
1200
|
+
return v + 1;
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
break;
|
|
1205
|
+
}
|
|
1206
|
+
case 'mergeRight':
|
|
1207
|
+
if (cell.nextElementSibling) {
|
|
1208
|
+
var nextCell = cell.nextElementSibling;
|
|
1209
|
+
cell.colSpan = (cell.colSpan || 1) + (nextCell.colSpan || 1);
|
|
1210
|
+
nextCell.remove();
|
|
1211
|
+
}
|
|
1212
|
+
break;
|
|
1213
|
+
case 'deleteTable':
|
|
1214
|
+
table.remove();
|
|
1215
|
+
break;
|
|
1216
|
+
}
|
|
1217
|
+
triggerChange && triggerChange();
|
|
1218
|
+
};
|
|
1219
|
+
var insertTable = function insertTable() {
|
|
1220
|
+
var rows = parseInt(tableRows) || 3;
|
|
1221
|
+
var cols = parseInt(tableCols) || 3;
|
|
1222
|
+
var tableHtml = '<table style="width: 100%; border-collapse: collapse; border: 1px solid #e5e7eb; margin: 16px 0;"><tbody>';
|
|
1223
|
+
for (var i = 0; i < rows; i++) {
|
|
1224
|
+
tableHtml += '<tr>';
|
|
1225
|
+
for (var j = 0; j < cols; j++) {
|
|
1226
|
+
tableHtml += '<td style="border: 1px solid #e5e7eb; padding: 12px; min-height: 20px;"> </td>';
|
|
1227
|
+
}
|
|
1228
|
+
tableHtml += '</tr>';
|
|
1229
|
+
}
|
|
1230
|
+
tableHtml += '</tbody></table><p> </p>';
|
|
1231
|
+
if (selectionRangeRef.current) {
|
|
1232
|
+
var sel = window.getSelection();
|
|
1233
|
+
sel.removeAllRanges();
|
|
1234
|
+
sel.addRange(selectionRangeRef.current);
|
|
1235
|
+
}
|
|
1236
|
+
document.execCommand("insertHTML", false, tableHtml);
|
|
1237
|
+
setTableModalOpen(false);
|
|
1238
|
+
triggerChange && triggerChange();
|
|
1239
|
+
};
|
|
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) {
|
|
1269
|
+
if (editorRef.current) {
|
|
1270
|
+
editorRef.current.focus();
|
|
1271
|
+
}
|
|
1272
|
+
if (selectionRangeRef.current) {
|
|
1273
|
+
var sel = window.getSelection();
|
|
1274
|
+
sel.removeAllRanges();
|
|
1275
|
+
sel.addRange(selectionRangeRef.current);
|
|
1276
|
+
}
|
|
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> </p>");
|
|
1278
|
+
try {
|
|
1279
|
+
document.execCommand("insertHTML", false, embedHtml);
|
|
1280
|
+
} catch (err) {
|
|
1281
|
+
console.error("Failed to insert Video HTML:", err);
|
|
1282
|
+
if (editorRef.current) {
|
|
1283
|
+
var div = document.createElement('div');
|
|
1284
|
+
div.innerHTML = embedHtml;
|
|
1285
|
+
editorRef.current.appendChild(div);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
setVideoModalOpen(false);
|
|
1289
|
+
setVideoUrl("");
|
|
1290
|
+
triggerChange && triggerChange();
|
|
1291
|
+
} else {
|
|
1292
|
+
console.warn("Invalid Video URL or Platform not supported");
|
|
1293
|
+
}
|
|
1294
|
+
};
|
|
995
1295
|
var processExistingImages = function processExistingImages(container) {
|
|
996
1296
|
if (!container) return;
|
|
997
1297
|
container.querySelectorAll("img").forEach(function (img) {
|
|
@@ -1514,8 +1814,8 @@ function RichTextEditor(_ref) {
|
|
|
1514
1814
|
var lastInsertedNode = null;
|
|
1515
1815
|
|
|
1516
1816
|
// Iterate through the selected text nodes and wrap them in spans
|
|
1517
|
-
for (var
|
|
1518
|
-
var textNode = _nodesToStyle[
|
|
1817
|
+
for (var _i5 = 0, _nodesToStyle = nodesToStyle; _i5 < _nodesToStyle.length; _i5++) {
|
|
1818
|
+
var textNode = _nodesToStyle[_i5];
|
|
1519
1819
|
var parent = textNode.parentNode;
|
|
1520
1820
|
|
|
1521
1821
|
// This is important: check if the parent is a block-level element
|
|
@@ -1612,6 +1912,9 @@ function RichTextEditor(_ref) {
|
|
|
1612
1912
|
}
|
|
1613
1913
|
}, [disabled]);
|
|
1614
1914
|
var handleEditorClick = useCallback(function (e) {
|
|
1915
|
+
setSelectionVersion(function (v) {
|
|
1916
|
+
return v + 1;
|
|
1917
|
+
});
|
|
1615
1918
|
// Check if the click is on a link
|
|
1616
1919
|
var clickedLink = e.target.closest('a');
|
|
1617
1920
|
if (clickedLink) {
|
|
@@ -1621,6 +1924,15 @@ function RichTextEditor(_ref) {
|
|
|
1621
1924
|
return;
|
|
1622
1925
|
}
|
|
1623
1926
|
|
|
1927
|
+
// NEW: Check if click is on an image for resizing
|
|
1928
|
+
var clickedImg = e.target.closest('img');
|
|
1929
|
+
if (clickedImg && !clickedImg.closest('.rte-modal')) {
|
|
1930
|
+
setSelectedImage(clickedImg);
|
|
1931
|
+
setResizeData({});
|
|
1932
|
+
} else if (!e.target.closest('.resize-handle')) {
|
|
1933
|
+
setSelectedImage(null);
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1624
1936
|
// If disabled is true, prevent editing
|
|
1625
1937
|
if (disabled === true) {
|
|
1626
1938
|
e.preventDefault();
|
|
@@ -1637,14 +1949,138 @@ function RichTextEditor(_ref) {
|
|
|
1637
1949
|
}, 0);
|
|
1638
1950
|
}
|
|
1639
1951
|
}, [editable, disabled]);
|
|
1952
|
+
var startResize = function startResize(e, direction) {
|
|
1953
|
+
e.preventDefault();
|
|
1954
|
+
e.stopPropagation();
|
|
1955
|
+
var img = selectedImage;
|
|
1956
|
+
var startX = e.clientX;
|
|
1957
|
+
var startY = e.clientY;
|
|
1958
|
+
var startWidth = img.offsetWidth;
|
|
1959
|
+
var startHeight = img.offsetHeight;
|
|
1960
|
+
var onMouseMove = function onMouseMove(moveEvent) {
|
|
1961
|
+
var newWidth = startWidth;
|
|
1962
|
+
var newHeight = startHeight;
|
|
1963
|
+
if (direction.includes('e')) newWidth = startWidth + (moveEvent.clientX - startX);
|
|
1964
|
+
if (direction.includes('w')) newWidth = startWidth - (moveEvent.clientX - startX);
|
|
1965
|
+
if (direction.includes('s')) newHeight = startHeight + (moveEvent.clientY - startY);
|
|
1966
|
+
if (direction.includes('n')) newHeight = startHeight - (moveEvent.clientY - startY);
|
|
1967
|
+
img.style.width = "".concat(newWidth, "px");
|
|
1968
|
+
img.style.height = "".concat(newHeight, "px");
|
|
1969
|
+
setResizeData({}); // Force re-render of handles
|
|
1970
|
+
};
|
|
1971
|
+
var _onMouseUp = function onMouseUp() {
|
|
1972
|
+
document.removeEventListener('mousemove', onMouseMove);
|
|
1973
|
+
document.removeEventListener('mouseup', _onMouseUp);
|
|
1974
|
+
triggerChange();
|
|
1975
|
+
};
|
|
1976
|
+
document.addEventListener('mousemove', onMouseMove);
|
|
1977
|
+
document.addEventListener('mouseup', _onMouseUp);
|
|
1978
|
+
};
|
|
1979
|
+
var renderResizeHandles = function renderResizeHandles() {
|
|
1980
|
+
if (!selectedImage || !editorRef.current) return null;
|
|
1981
|
+
var editorRect = editorRef.current.getBoundingClientRect();
|
|
1982
|
+
var imgRect = selectedImage.getBoundingClientRect();
|
|
1983
|
+
|
|
1984
|
+
// Relative position within editorRef using the more robust BoundingClientRect
|
|
1985
|
+
var top = imgRect.top - editorRect.top + editorRef.current.scrollTop;
|
|
1986
|
+
var left = imgRect.left - editorRect.left + editorRef.current.scrollLeft;
|
|
1987
|
+
var width = imgRect.width;
|
|
1988
|
+
var height = imgRect.height;
|
|
1989
|
+
var handleStyles = {
|
|
1990
|
+
position: 'absolute',
|
|
1991
|
+
width: '10px',
|
|
1992
|
+
height: '10px',
|
|
1993
|
+
background: '#3b82f6',
|
|
1994
|
+
border: '2px solid white',
|
|
1995
|
+
borderRadius: '50%',
|
|
1996
|
+
zIndex: 100
|
|
1997
|
+
};
|
|
1998
|
+
var handles = [{
|
|
1999
|
+
id: 'nw',
|
|
2000
|
+
style: {
|
|
2001
|
+
top: top - 5,
|
|
2002
|
+
left: left - 5,
|
|
2003
|
+
cursor: 'nw-resize'
|
|
2004
|
+
}
|
|
2005
|
+
}, {
|
|
2006
|
+
id: 'ne',
|
|
2007
|
+
style: {
|
|
2008
|
+
top: top - 5,
|
|
2009
|
+
left: left + width - 5,
|
|
2010
|
+
cursor: 'ne-resize'
|
|
2011
|
+
}
|
|
2012
|
+
}, {
|
|
2013
|
+
id: 'sw',
|
|
2014
|
+
style: {
|
|
2015
|
+
top: top + height - 5,
|
|
2016
|
+
left: left - 5,
|
|
2017
|
+
cursor: 'sw-resize'
|
|
2018
|
+
}
|
|
2019
|
+
}, {
|
|
2020
|
+
id: 'se',
|
|
2021
|
+
style: {
|
|
2022
|
+
top: top + height - 5,
|
|
2023
|
+
left: left + width - 5,
|
|
2024
|
+
cursor: 'se-resize'
|
|
2025
|
+
}
|
|
2026
|
+
}];
|
|
2027
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
2028
|
+
style: {
|
|
2029
|
+
position: 'absolute',
|
|
2030
|
+
top: 0,
|
|
2031
|
+
left: 0,
|
|
2032
|
+
width: '100%',
|
|
2033
|
+
height: '100%',
|
|
2034
|
+
pointerEvents: 'none'
|
|
2035
|
+
}
|
|
2036
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
2037
|
+
style: {
|
|
2038
|
+
position: 'absolute',
|
|
2039
|
+
top: top,
|
|
2040
|
+
left: left,
|
|
2041
|
+
width: width,
|
|
2042
|
+
height: height,
|
|
2043
|
+
border: '2px solid #3b82f6',
|
|
2044
|
+
pointerEvents: 'none'
|
|
2045
|
+
}
|
|
2046
|
+
}), handles.map(function (h) {
|
|
2047
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
2048
|
+
key: h.id,
|
|
2049
|
+
className: "resize-handle",
|
|
2050
|
+
onMouseDown: function onMouseDown(e) {
|
|
2051
|
+
return startResize(e, h.id);
|
|
2052
|
+
},
|
|
2053
|
+
style: _objectSpread2(_objectSpread2(_objectSpread2({}, handleStyles), h.style), {}, {
|
|
2054
|
+
pointerEvents: 'auto'
|
|
2055
|
+
})
|
|
2056
|
+
});
|
|
2057
|
+
}));
|
|
2058
|
+
};
|
|
1640
2059
|
return /*#__PURE__*/React.createElement("div", {
|
|
1641
2060
|
className: "rte-main-wrapper",
|
|
1642
2061
|
style: {
|
|
1643
|
-
width: '100%'
|
|
2062
|
+
width: '100%',
|
|
2063
|
+
position: 'relative'
|
|
1644
2064
|
}
|
|
1645
2065
|
}, label && /*#__PURE__*/React.createElement(LabelComponent, null, label), /*#__PURE__*/React.createElement("div", {
|
|
2066
|
+
style: {
|
|
2067
|
+
position: 'relative'
|
|
2068
|
+
},
|
|
1646
2069
|
className: !showBorder ? "" : "rte-container",
|
|
1647
2070
|
onClick: handleEditorClick,
|
|
2071
|
+
onMouseOver: function onMouseOver(e) {
|
|
2072
|
+
var table = e.target.closest('table');
|
|
2073
|
+
if (table && editorRef.current.contains(table)) {
|
|
2074
|
+
setHoveredTable(table);
|
|
2075
|
+
}
|
|
2076
|
+
},
|
|
2077
|
+
onMouseOut: function onMouseOut(e) {
|
|
2078
|
+
var table = e.target.closest('table');
|
|
2079
|
+
var related = e.relatedTarget;
|
|
2080
|
+
if (table && (!related || !table.contains(related)) && !(related !== null && related !== void 0 && related.closest('.rte-table-delete-hover'))) {
|
|
2081
|
+
setHoveredTable(null);
|
|
2082
|
+
}
|
|
2083
|
+
},
|
|
1648
2084
|
onDrop: handleDrop,
|
|
1649
2085
|
onDragOver: function onDragOver(e) {
|
|
1650
2086
|
e.preventDefault();
|
|
@@ -1659,7 +2095,7 @@ function RichTextEditor(_ref) {
|
|
|
1659
2095
|
e.preventDefault();
|
|
1660
2096
|
e.stopPropagation();
|
|
1661
2097
|
document.execCommand("bold");
|
|
1662
|
-
|
|
2098
|
+
handleInput();
|
|
1663
2099
|
focus();
|
|
1664
2100
|
},
|
|
1665
2101
|
className: "rte-toolbar-button ".concat(isBold ? "active" : "")
|
|
@@ -1672,7 +2108,7 @@ function RichTextEditor(_ref) {
|
|
|
1672
2108
|
e.preventDefault();
|
|
1673
2109
|
e.stopPropagation();
|
|
1674
2110
|
document.execCommand("italic");
|
|
1675
|
-
|
|
2111
|
+
handleInput();
|
|
1676
2112
|
focus();
|
|
1677
2113
|
},
|
|
1678
2114
|
className: "rte-toolbar-button ".concat(isItalic ? "active" : "")
|
|
@@ -1685,7 +2121,7 @@ function RichTextEditor(_ref) {
|
|
|
1685
2121
|
e.preventDefault();
|
|
1686
2122
|
e.stopPropagation();
|
|
1687
2123
|
document.execCommand("underline");
|
|
1688
|
-
|
|
2124
|
+
handleInput();
|
|
1689
2125
|
focus();
|
|
1690
2126
|
},
|
|
1691
2127
|
className: "rte-toolbar-button ".concat(isUnderline ? "active" : "")
|
|
@@ -1857,6 +2293,13 @@ function RichTextEditor(_ref) {
|
|
|
1857
2293
|
backgroundColor: '#e5e7eb',
|
|
1858
2294
|
margin: '0 4px'
|
|
1859
2295
|
}
|
|
2296
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
2297
|
+
style: {
|
|
2298
|
+
width: '1px',
|
|
2299
|
+
height: '20px',
|
|
2300
|
+
backgroundColor: '#e5e7eb',
|
|
2301
|
+
margin: '0 4px'
|
|
2302
|
+
}
|
|
1860
2303
|
}), /*#__PURE__*/React.createElement("button", {
|
|
1861
2304
|
type: "button",
|
|
1862
2305
|
title: "Add Link",
|
|
@@ -1897,7 +2340,145 @@ function RichTextEditor(_ref) {
|
|
|
1897
2340
|
}
|
|
1898
2341
|
}) : /*#__PURE__*/React.createElement(FaImage, {
|
|
1899
2342
|
size: 14
|
|
1900
|
-
}))
|
|
2343
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
2344
|
+
style: {
|
|
2345
|
+
width: '1px',
|
|
2346
|
+
height: '20px',
|
|
2347
|
+
backgroundColor: '#e5e7eb',
|
|
2348
|
+
margin: '0 4px'
|
|
2349
|
+
}
|
|
2350
|
+
}), /*#__PURE__*/React.createElement("button", {
|
|
2351
|
+
type: "button",
|
|
2352
|
+
title: "Insert Table",
|
|
2353
|
+
className: "rte-toolbar-button",
|
|
2354
|
+
onMouseDown: function onMouseDown(e) {
|
|
2355
|
+
e.preventDefault();
|
|
2356
|
+
var sel = window.getSelection();
|
|
2357
|
+
if (sel && sel.rangeCount > 0) {
|
|
2358
|
+
selectionRangeRef.current = sel.getRangeAt(0).cloneRange();
|
|
2359
|
+
}
|
|
2360
|
+
setTableModalOpen(true);
|
|
2361
|
+
}
|
|
2362
|
+
}, /*#__PURE__*/React.createElement(FaTable, {
|
|
2363
|
+
size: 14
|
|
2364
|
+
})), /*#__PURE__*/React.createElement("button", {
|
|
2365
|
+
type: "button",
|
|
2366
|
+
title: "Embed Video (YouTube, Vimeo, etc.)",
|
|
2367
|
+
className: "rte-toolbar-button ".concat(videoModalOpen ? 'active' : ''),
|
|
2368
|
+
onMouseDown: function onMouseDown(e) {
|
|
2369
|
+
e.preventDefault();
|
|
2370
|
+
saveSelection();
|
|
2371
|
+
setVideoModalOpen(true);
|
|
2372
|
+
}
|
|
2373
|
+
}, /*#__PURE__*/React.createElement(FaVideo, {
|
|
2374
|
+
size: 14
|
|
2375
|
+
})), function () {
|
|
2376
|
+
if (typeof window === "undefined") return null;
|
|
2377
|
+
var sel = window.getSelection();
|
|
2378
|
+
// Robust check: inside cell OR the table itself is selected
|
|
2379
|
+
var isCell = sel && sel.rangeCount > 0 && sel.anchorNode && (findParentTag(sel.anchorNode, 'TD') || findParentTag(sel.anchorNode, 'TH'));
|
|
2380
|
+
var isTable = sel && sel.rangeCount > 0 && sel.anchorNode && findParentTag(sel.anchorNode, 'TABLE');
|
|
2381
|
+
if (isCell || isTable) {
|
|
2382
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
2383
|
+
style: {
|
|
2384
|
+
width: '1px',
|
|
2385
|
+
height: '20px',
|
|
2386
|
+
backgroundColor: '#e5e7eb',
|
|
2387
|
+
margin: '0 4px'
|
|
2388
|
+
}
|
|
2389
|
+
}), /*#__PURE__*/React.createElement("button", {
|
|
2390
|
+
type: "button",
|
|
2391
|
+
title: "Add Row Above",
|
|
2392
|
+
className: "rte-toolbar-button",
|
|
2393
|
+
onMouseDown: function onMouseDown(e) {
|
|
2394
|
+
e.preventDefault();
|
|
2395
|
+
tableAction('addRowAbove');
|
|
2396
|
+
}
|
|
2397
|
+
}, "+R\u2191"), /*#__PURE__*/React.createElement("button", {
|
|
2398
|
+
type: "button",
|
|
2399
|
+
title: "Add Row Below",
|
|
2400
|
+
className: "rte-toolbar-button",
|
|
2401
|
+
onMouseDown: function onMouseDown(e) {
|
|
2402
|
+
e.preventDefault();
|
|
2403
|
+
tableAction('addRowBelow');
|
|
2404
|
+
}
|
|
2405
|
+
}, "+R\u2193"), /*#__PURE__*/React.createElement("button", {
|
|
2406
|
+
type: "button",
|
|
2407
|
+
title: "Add Col Before",
|
|
2408
|
+
className: "rte-toolbar-button",
|
|
2409
|
+
onMouseDown: function onMouseDown(e) {
|
|
2410
|
+
e.preventDefault();
|
|
2411
|
+
tableAction('addColBefore');
|
|
2412
|
+
}
|
|
2413
|
+
}, "+C\u2190"), /*#__PURE__*/React.createElement("button", {
|
|
2414
|
+
type: "button",
|
|
2415
|
+
title: "Add Col After",
|
|
2416
|
+
className: "rte-toolbar-button",
|
|
2417
|
+
onMouseDown: function onMouseDown(e) {
|
|
2418
|
+
e.preventDefault();
|
|
2419
|
+
tableAction('addColAfter');
|
|
2420
|
+
}
|
|
2421
|
+
}, "+C\u2192"), /*#__PURE__*/React.createElement("button", {
|
|
2422
|
+
type: "button",
|
|
2423
|
+
title: "Merge Cells (Right)",
|
|
2424
|
+
className: "rte-toolbar-button",
|
|
2425
|
+
onMouseDown: function onMouseDown(e) {
|
|
2426
|
+
e.preventDefault();
|
|
2427
|
+
tableAction('mergeRight');
|
|
2428
|
+
}
|
|
2429
|
+
}, /*#__PURE__*/React.createElement(FaObjectGroup, {
|
|
2430
|
+
size: 14
|
|
2431
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
2432
|
+
style: {
|
|
2433
|
+
display: 'flex',
|
|
2434
|
+
gap: '10px'
|
|
2435
|
+
}
|
|
2436
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
2437
|
+
type: "button",
|
|
2438
|
+
title: "Delete Row",
|
|
2439
|
+
className: "rte-toolbar-button rte-toolbar-button-danger",
|
|
2440
|
+
onMouseDown: function onMouseDown(e) {
|
|
2441
|
+
e.preventDefault();
|
|
2442
|
+
tableAction('deleteRow');
|
|
2443
|
+
}
|
|
2444
|
+
}, /*#__PURE__*/React.createElement(FaTrash, {
|
|
2445
|
+
size: 12
|
|
2446
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
2447
|
+
style: {
|
|
2448
|
+
fontSize: '10px'
|
|
2449
|
+
}
|
|
2450
|
+
}, "Row")), /*#__PURE__*/React.createElement("button", {
|
|
2451
|
+
type: "button",
|
|
2452
|
+
title: "Delete Column",
|
|
2453
|
+
className: "rte-toolbar-button rte-toolbar-button-danger",
|
|
2454
|
+
onMouseDown: function onMouseDown(e) {
|
|
2455
|
+
e.preventDefault();
|
|
2456
|
+
tableAction('deleteCol');
|
|
2457
|
+
}
|
|
2458
|
+
}, /*#__PURE__*/React.createElement(FaTrash, {
|
|
2459
|
+
size: 12
|
|
2460
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
2461
|
+
style: {
|
|
2462
|
+
fontSize: '10px'
|
|
2463
|
+
}
|
|
2464
|
+
}, "Col")), /*#__PURE__*/React.createElement("button", {
|
|
2465
|
+
type: "button",
|
|
2466
|
+
title: "Delete Table",
|
|
2467
|
+
className: "rte-toolbar-button rte-toolbar-button-danger",
|
|
2468
|
+
onMouseDown: function onMouseDown(e) {
|
|
2469
|
+
e.preventDefault();
|
|
2470
|
+
tableAction('deleteTable');
|
|
2471
|
+
}
|
|
2472
|
+
}, /*#__PURE__*/React.createElement(FaTrash, {
|
|
2473
|
+
size: 12
|
|
2474
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
2475
|
+
style: {
|
|
2476
|
+
fontSize: '10px'
|
|
2477
|
+
}
|
|
2478
|
+
}, "Table"))));
|
|
2479
|
+
}
|
|
2480
|
+
return null;
|
|
2481
|
+
}()), /*#__PURE__*/React.createElement("div", {
|
|
1901
2482
|
ref: editorRef,
|
|
1902
2483
|
contentEditable: editable && disabled !== true,
|
|
1903
2484
|
suppressContentEditableWarning: true,
|
|
@@ -1918,7 +2499,23 @@ function RichTextEditor(_ref) {
|
|
|
1918
2499
|
paddingLeft: paddingLeft || '12px'
|
|
1919
2500
|
},
|
|
1920
2501
|
className: "rte-content"
|
|
1921
|
-
}),
|
|
2502
|
+
}), renderResizeHandles(), /*#__PURE__*/React.createElement("div", {
|
|
2503
|
+
className: "rte-footer"
|
|
2504
|
+
}, function (_editorRef$current) {
|
|
2505
|
+
var text = ((_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 ? void 0 : _editorRef$current.innerText) || "";
|
|
2506
|
+
var cleanText = text.replace(/[\n\r]/g, ' ').trim();
|
|
2507
|
+
var words = cleanText ? cleanText.split(/\s+/).length : 0;
|
|
2508
|
+
var chars = text.length;
|
|
2509
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
2510
|
+
className: "rte-footer-content"
|
|
2511
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
2512
|
+
className: "rte-footer-item"
|
|
2513
|
+
}, /*#__PURE__*/React.createElement("b", null, words), " words"), /*#__PURE__*/React.createElement("span", {
|
|
2514
|
+
className: "rte-footer-separator"
|
|
2515
|
+
}, "\u2022"), /*#__PURE__*/React.createElement("span", {
|
|
2516
|
+
className: "rte-footer-item"
|
|
2517
|
+
}, /*#__PURE__*/React.createElement("b", null, chars), " characters"));
|
|
2518
|
+
}()), linkModalOpen && /*#__PURE__*/React.createElement("div", {
|
|
1922
2519
|
className: "rte-modal-overlay",
|
|
1923
2520
|
onClick: cancelLink
|
|
1924
2521
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -1929,42 +2526,156 @@ function RichTextEditor(_ref) {
|
|
|
1929
2526
|
}, /*#__PURE__*/React.createElement("h3", {
|
|
1930
2527
|
className: "rte-modal-title"
|
|
1931
2528
|
}, "Insert Link"), /*#__PURE__*/React.createElement("div", {
|
|
2529
|
+
className: "rte-modal-divider"
|
|
2530
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
2531
|
+
className: "rte-modal-body"
|
|
2532
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
2533
|
+
className: "rte-form-group"
|
|
2534
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
2535
|
+
className: "rte-label"
|
|
2536
|
+
}, "Link Text"), /*#__PURE__*/React.createElement("input", {
|
|
2537
|
+
type: "text",
|
|
2538
|
+
className: "rte-input",
|
|
2539
|
+
placeholder: "e.g. Google",
|
|
2540
|
+
value: linkText,
|
|
2541
|
+
onChange: function onChange(e) {
|
|
2542
|
+
return setLinkText(e.target.value);
|
|
2543
|
+
}
|
|
2544
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
1932
2545
|
className: "rte-form-group"
|
|
1933
2546
|
}, /*#__PURE__*/React.createElement("label", {
|
|
1934
2547
|
className: "rte-label"
|
|
1935
2548
|
}, "URL"), /*#__PURE__*/React.createElement("input", {
|
|
1936
|
-
type: "
|
|
2549
|
+
type: "text",
|
|
1937
2550
|
className: "rte-input",
|
|
2551
|
+
placeholder: "https://example.com",
|
|
1938
2552
|
value: linkUrl,
|
|
1939
2553
|
onChange: function onChange(e) {
|
|
1940
2554
|
return setLinkUrl(e.target.value);
|
|
1941
2555
|
},
|
|
1942
|
-
|
|
1943
|
-
|
|
2556
|
+
onKeyDown: function onKeyDown(e) {
|
|
2557
|
+
return e.key === 'Enter' && confirmLink();
|
|
2558
|
+
},
|
|
2559
|
+
autoFocus: true
|
|
2560
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
2561
|
+
className: "rte-modal-divider",
|
|
2562
|
+
style: {
|
|
2563
|
+
margin: '8px 0 20px 0'
|
|
2564
|
+
}
|
|
2565
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
2566
|
+
className: "rte-modal-footer"
|
|
2567
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
2568
|
+
type: "button",
|
|
2569
|
+
className: "rte-btn rte-btn-secondary",
|
|
2570
|
+
onClick: cancelLink
|
|
2571
|
+
}, "Cancel"), /*#__PURE__*/React.createElement("button", {
|
|
2572
|
+
type: "button",
|
|
2573
|
+
className: "rte-btn rte-btn-primary",
|
|
2574
|
+
onClick: confirmLink,
|
|
2575
|
+
disabled: !linkUrl
|
|
2576
|
+
}, "Insert")))), tableModalOpen && /*#__PURE__*/React.createElement("div", {
|
|
2577
|
+
className: "rte-modal-overlay",
|
|
2578
|
+
onClick: function onClick() {
|
|
2579
|
+
return setTableModalOpen(false);
|
|
2580
|
+
}
|
|
2581
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
2582
|
+
className: "rte-modal",
|
|
2583
|
+
onClick: function onClick(e) {
|
|
2584
|
+
return e.stopPropagation();
|
|
2585
|
+
}
|
|
2586
|
+
}, /*#__PURE__*/React.createElement("h3", {
|
|
2587
|
+
className: "rte-modal-title"
|
|
2588
|
+
}, "Insert Table"), /*#__PURE__*/React.createElement("div", {
|
|
2589
|
+
className: "rte-form-group"
|
|
2590
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
2591
|
+
className: "rte-label"
|
|
2592
|
+
}, "Rows"), /*#__PURE__*/React.createElement("input", {
|
|
2593
|
+
type: "number",
|
|
2594
|
+
className: "rte-input",
|
|
2595
|
+
value: tableRows,
|
|
2596
|
+
onChange: function onChange(e) {
|
|
2597
|
+
return setTableRows(e.target.value);
|
|
2598
|
+
},
|
|
2599
|
+
min: "1",
|
|
2600
|
+
max: "10"
|
|
2601
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
2602
|
+
className: "rte-form-group"
|
|
2603
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
2604
|
+
className: "rte-label"
|
|
2605
|
+
}, "Columns"), /*#__PURE__*/React.createElement("input", {
|
|
2606
|
+
type: "number",
|
|
2607
|
+
className: "rte-input",
|
|
2608
|
+
value: tableCols,
|
|
2609
|
+
onChange: function onChange(e) {
|
|
2610
|
+
return setTableCols(e.target.value);
|
|
2611
|
+
},
|
|
2612
|
+
min: "1",
|
|
2613
|
+
max: "10"
|
|
1944
2614
|
})), /*#__PURE__*/React.createElement("div", {
|
|
2615
|
+
className: "rte-modal-actions"
|
|
2616
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
2617
|
+
type: "button",
|
|
2618
|
+
className: "rte-button rte-button-secondary",
|
|
2619
|
+
onClick: function onClick() {
|
|
2620
|
+
return setTableModalOpen(false);
|
|
2621
|
+
}
|
|
2622
|
+
}, "Cancel"), /*#__PURE__*/React.createElement("button", {
|
|
2623
|
+
type: "button",
|
|
2624
|
+
className: "rte-button rte-button-primary",
|
|
2625
|
+
onClick: insertTable
|
|
2626
|
+
}, "Insert")))), videoModalOpen && /*#__PURE__*/React.createElement("div", {
|
|
2627
|
+
className: "rte-modal-overlay",
|
|
2628
|
+
onClick: function onClick() {
|
|
2629
|
+
return setVideoModalOpen(false);
|
|
2630
|
+
}
|
|
2631
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
2632
|
+
className: "rte-modal",
|
|
2633
|
+
onClick: function onClick(e) {
|
|
2634
|
+
return e.stopPropagation();
|
|
2635
|
+
}
|
|
2636
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
2637
|
+
className: "rte-modal-header"
|
|
2638
|
+
}, /*#__PURE__*/React.createElement("h3", {
|
|
2639
|
+
className: "rte-modal-title"
|
|
2640
|
+
}, "Embed Video")), /*#__PURE__*/React.createElement("div", {
|
|
1945
2641
|
className: "rte-form-group"
|
|
1946
2642
|
}, /*#__PURE__*/React.createElement("label", {
|
|
1947
2643
|
className: "rte-label"
|
|
1948
|
-
}, "
|
|
2644
|
+
}, "Paste Video URL (YouTube, Vimeo...) ", /*#__PURE__*/React.createElement("span", {
|
|
2645
|
+
style: {
|
|
2646
|
+
color: '#ef4444'
|
|
2647
|
+
}
|
|
2648
|
+
}, "*")), /*#__PURE__*/React.createElement("input", {
|
|
1949
2649
|
type: "text",
|
|
1950
2650
|
className: "rte-input",
|
|
1951
|
-
value:
|
|
2651
|
+
value: videoUrl,
|
|
1952
2652
|
onChange: function onChange(e) {
|
|
1953
|
-
return
|
|
2653
|
+
return setVideoUrl(e.target.value);
|
|
1954
2654
|
},
|
|
1955
|
-
placeholder: "
|
|
2655
|
+
placeholder: "Paste URL here...",
|
|
2656
|
+
autoFocus: true,
|
|
2657
|
+
onKeyDown: function onKeyDown(e) {
|
|
2658
|
+
if (e.key === 'Enter' && videoUrl.trim()) insertVideo();
|
|
2659
|
+
if (e.key === 'Escape') setVideoModalOpen(false);
|
|
2660
|
+
}
|
|
1956
2661
|
})), /*#__PURE__*/React.createElement("div", {
|
|
1957
2662
|
className: "rte-modal-actions"
|
|
1958
2663
|
}, /*#__PURE__*/React.createElement("button", {
|
|
1959
2664
|
type: "button",
|
|
1960
2665
|
className: "rte-button rte-button-secondary",
|
|
1961
|
-
onClick:
|
|
2666
|
+
onClick: function onClick() {
|
|
2667
|
+
return setVideoModalOpen(false);
|
|
2668
|
+
}
|
|
1962
2669
|
}, "Cancel"), /*#__PURE__*/React.createElement("button", {
|
|
1963
2670
|
type: "button",
|
|
1964
2671
|
className: "rte-button rte-button-primary",
|
|
1965
|
-
onClick:
|
|
1966
|
-
|
|
1967
|
-
|
|
2672
|
+
onClick: function onClick() {
|
|
2673
|
+
if (videoUrl.trim()) {
|
|
2674
|
+
insertVideo();
|
|
2675
|
+
}
|
|
2676
|
+
},
|
|
2677
|
+
disabled: !videoUrl.trim()
|
|
2678
|
+
}, "Embed Video")))), imageModalOpen && /*#__PURE__*/React.createElement("div", {
|
|
1968
2679
|
className: "rte-modal-overlay",
|
|
1969
2680
|
onClick: closeImageModal
|
|
1970
2681
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -2004,7 +2715,7 @@ function RichTextEditor(_ref) {
|
|
|
2004
2715
|
type: "button",
|
|
2005
2716
|
className: "rte-button rte-button-primary",
|
|
2006
2717
|
onClick: function onClick() {
|
|
2007
|
-
|
|
2718
|
+
onChange && onChange(html);
|
|
2008
2719
|
setEditable(false);
|
|
2009
2720
|
}
|
|
2010
2721
|
}, "Save Changes")));
|