@malaya_jeeva/rich-text-editor 1.0.3 → 1.0.4

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.js CHANGED
@@ -407,12 +407,23 @@ function RichTextEditor({ value, onChange }) {
407
407
  setSelCells([]);
408
408
  dragStartCell.current = null;
409
409
  }, []);
410
+ const fixListNesting = (0, import_react.useCallback)(() => {
411
+ const editor = editorRef.current;
412
+ if (!editor) return;
413
+ editor.querySelectorAll("ol > ol, ol > ul, ul > ol, ul > ul").forEach((orphan) => {
414
+ const prev = orphan.previousElementSibling;
415
+ if (prev && prev.tagName === "LI") {
416
+ prev.appendChild(orphan);
417
+ }
418
+ });
419
+ }, []);
410
420
  const exec = (0, import_react.useCallback)((cmd, val = null) => {
411
421
  var _a2;
412
422
  (_a2 = editorRef.current) == null ? void 0 : _a2.focus();
413
423
  document.execCommand(cmd, false, val != null ? val : void 0);
424
+ fixListNesting();
414
425
  refresh();
415
- }, []);
426
+ }, [fixListNesting]);
416
427
  const refresh = (0, import_react.useCallback)(() => {
417
428
  var _a2, _b, _c, _d;
418
429
  const raw = document.queryCommandValue("formatBlock").toLowerCase().replace(/[<>]/g, "");
package/dist/index.mjs CHANGED
@@ -386,12 +386,23 @@ function RichTextEditor({ value, onChange }) {
386
386
  setSelCells([]);
387
387
  dragStartCell.current = null;
388
388
  }, []);
389
+ const fixListNesting = useCallback(() => {
390
+ const editor = editorRef.current;
391
+ if (!editor) return;
392
+ editor.querySelectorAll("ol > ol, ol > ul, ul > ol, ul > ul").forEach((orphan) => {
393
+ const prev = orphan.previousElementSibling;
394
+ if (prev && prev.tagName === "LI") {
395
+ prev.appendChild(orphan);
396
+ }
397
+ });
398
+ }, []);
389
399
  const exec = useCallback((cmd, val = null) => {
390
400
  var _a2;
391
401
  (_a2 = editorRef.current) == null ? void 0 : _a2.focus();
392
402
  document.execCommand(cmd, false, val != null ? val : void 0);
403
+ fixListNesting();
393
404
  refresh();
394
- }, []);
405
+ }, [fixListNesting]);
395
406
  const refresh = useCallback(() => {
396
407
  var _a2, _b, _c, _d;
397
408
  const raw = document.queryCommandValue("formatBlock").toLowerCase().replace(/[<>]/g, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malaya_jeeva/rich-text-editor",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Custom React Rich Text Editor",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",