kamotive_ui 19.3.26 → 20.3.26

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.
@@ -184,12 +184,16 @@ export const TextEditor = ({ defaultValue, attachedFiles, label, onSubmit, onCan
184
184
  }
185
185
  const range = selection.getRangeAt(0);
186
186
  const element = getElementFromRange(range);
187
+ const isInH2 = element ? checkFormatting(element, ['H2']) : false;
188
+ const isBold = isInH2
189
+ ? (element ? checkFormatting(element, ['B', 'STRONG']) : false)
190
+ : document.queryCommandState('bold');
187
191
  const newStates = {
188
- bold: document.queryCommandState('bold'),
192
+ bold: isBold,
189
193
  italic: document.queryCommandState('italic'),
190
194
  underline: document.queryCommandState('underline'),
191
195
  strikethrough: document.queryCommandState('strikethrough'),
192
- heading2: element ? checkFormatting(element, ['H2']) : false,
196
+ heading2: isInH2,
193
197
  olist: element ? (checkFormatting(element, ['OL']) || !!element.closest('ol')) : false,
194
198
  };
195
199
  setActiveStates(newStates);
@@ -222,7 +226,9 @@ export const TextEditor = ({ defaultValue, attachedFiles, label, onSubmit, onCan
222
226
  }
223
227
  if (h2Element) {
224
228
  const div = document.createElement('div');
225
- div.innerHTML = h2Element.innerHTML;
229
+ while (h2Element.firstChild) {
230
+ div.appendChild(h2Element.firstChild);
231
+ }
226
232
  const rangeOffset = range.startOffset;
227
233
  const textNode = range.startContainer;
228
234
  (_a = h2Element.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(div, h2Element);
@@ -482,6 +488,52 @@ export const TextEditor = ({ defaultValue, attachedFiles, label, onSubmit, onCan
482
488
  setEditorHtml(defaultValue || '');
483
489
  setTimeout(setCursorToEnd, 0);
484
490
  }, [defaultValue]);
491
+ const handleBoldToggle = () => {
492
+ var _a, _b;
493
+ const selection = window.getSelection();
494
+ if (!selection || selection.rangeCount === 0)
495
+ return;
496
+ const range = getSafeRange();
497
+ if (!range)
498
+ return;
499
+ const element = getElementFromRange(range);
500
+ const isInH2 = element ? checkFormatting(element, ['H2']) : false;
501
+ if (!isInH2) {
502
+ document.execCommand('bold', false, undefined);
503
+ return;
504
+ }
505
+ const hasBold = element ? checkFormatting(element, ['B', 'STRONG']) : false;
506
+ if (hasBold) {
507
+ document.execCommand('bold', false, undefined);
508
+ }
509
+ else if (!range.collapsed) {
510
+ try {
511
+ const b = document.createElement('b');
512
+ range.surroundContents(b);
513
+ const newRange = document.createRange();
514
+ newRange.selectNodeContents(b);
515
+ newRange.collapse(false);
516
+ selection.removeAllRanges();
517
+ selection.addRange(newRange);
518
+ (_a = pellRef.current) === null || _a === void 0 ? void 0 : _a.content.dispatchEvent(new Event('input', { bubbles: true }));
519
+ }
520
+ catch (_c) {
521
+ document.execCommand('insertHTML', false, `<b>${range.toString()}</b>`);
522
+ }
523
+ }
524
+ else {
525
+ const b = document.createElement('b');
526
+ const zws = document.createTextNode('\u200B');
527
+ b.appendChild(zws);
528
+ range.insertNode(b);
529
+ const newRange = document.createRange();
530
+ newRange.setStart(zws, 1);
531
+ newRange.collapse(true);
532
+ selection.removeAllRanges();
533
+ selection.addRange(newRange);
534
+ (_b = pellRef.current) === null || _b === void 0 ? void 0 : _b.content.dispatchEvent(new Event('input', { bubbles: true }));
535
+ }
536
+ };
485
537
  const setupToolbar = (pellEditor) => {
486
538
  if (!editorRef.current)
487
539
  return;
@@ -533,7 +585,10 @@ export const TextEditor = ({ defaultValue, attachedFiles, label, onSubmit, onCan
533
585
  htmlButton.addEventListener('mousedown', (e) => {
534
586
  e.preventDefault();
535
587
  e.stopPropagation();
536
- if (command === 'heading2') {
588
+ if (command === 'bold') {
589
+ handleBoldToggle();
590
+ }
591
+ else if (command === 'heading2') {
537
592
  toggleHeading2();
538
593
  }
539
594
  else if (command === 'olist') {
@@ -567,8 +622,9 @@ export const TextEditor = ({ defaultValue, attachedFiles, label, onSubmit, onCan
567
622
  (_a = uploaderRef.current) === null || _a === void 0 ? void 0 : _a.click();
568
623
  };
569
624
  const handleEditorChange = useCallback((html) => {
570
- setEditorHtml(html);
571
- redoContentRef.current = html;
625
+ const cleanHtml = html.replace(/\u200B/g, '');
626
+ setEditorHtml(cleanHtml);
627
+ redoContentRef.current = cleanHtml;
572
628
  updateActiveStates();
573
629
  }, [updateActiveStates]);
574
630
  useEffect(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kamotive_ui",
3
- "version": "19.3.26",
3
+ "version": "20.3.26",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [