@akinon/ui-editor 1.0.9 → 1.1.1

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.
Files changed (37) hide show
  1. package/dist/cjs/tiptap/extensions/__tests__/comment-extension.test.js +8 -4
  2. package/dist/cjs/tiptap/extensions/__tests__/comment-extension.test.ts +10 -4
  3. package/dist/cjs/tiptap/extensions/__tests__/custom-table-cell-extension.test.tsx +13 -1
  4. package/dist/cjs/tiptap/utils/tiptap-extensions.js +1 -1
  5. package/dist/esm/tiptap/extensions/__tests__/comment-extension.test.js +8 -4
  6. package/dist/esm/tiptap/extensions/__tests__/comment-extension.test.ts +10 -4
  7. package/dist/esm/tiptap/extensions/__tests__/custom-table-cell-extension.test.tsx +13 -1
  8. package/dist/esm/tiptap/utils/tiptap-extensions.js +1 -1
  9. package/package.json +9 -9
  10. package/dist/cjs/tiptap/utils/__tests__/format-html.test.d.ts +0 -2
  11. package/dist/cjs/tiptap/utils/__tests__/format-html.test.d.ts.map +0 -1
  12. package/dist/cjs/tiptap/utils/__tests__/format-html.test.js +0 -68
  13. package/dist/cjs/tiptap/utils/__tests__/format-html.test.ts +0 -91
  14. package/dist/cjs/tiptap/utils/__tests__/normalize-html.test.d.ts +0 -2
  15. package/dist/cjs/tiptap/utils/__tests__/normalize-html.test.d.ts.map +0 -1
  16. package/dist/cjs/tiptap/utils/__tests__/normalize-html.test.js +0 -53
  17. package/dist/cjs/tiptap/utils/__tests__/normalize-html.test.ts +0 -77
  18. package/dist/cjs/tiptap/utils/format-html.d.ts +0 -6
  19. package/dist/cjs/tiptap/utils/format-html.d.ts.map +0 -1
  20. package/dist/cjs/tiptap/utils/format-html.js +0 -108
  21. package/dist/cjs/tiptap/utils/normalize-html.d.ts +0 -7
  22. package/dist/cjs/tiptap/utils/normalize-html.d.ts.map +0 -1
  23. package/dist/cjs/tiptap/utils/normalize-html.js +0 -109
  24. package/dist/esm/tiptap/utils/__tests__/format-html.test.d.ts +0 -2
  25. package/dist/esm/tiptap/utils/__tests__/format-html.test.d.ts.map +0 -1
  26. package/dist/esm/tiptap/utils/__tests__/format-html.test.js +0 -68
  27. package/dist/esm/tiptap/utils/__tests__/format-html.test.ts +0 -91
  28. package/dist/esm/tiptap/utils/__tests__/normalize-html.test.d.ts +0 -2
  29. package/dist/esm/tiptap/utils/__tests__/normalize-html.test.d.ts.map +0 -1
  30. package/dist/esm/tiptap/utils/__tests__/normalize-html.test.js +0 -53
  31. package/dist/esm/tiptap/utils/__tests__/normalize-html.test.ts +0 -77
  32. package/dist/esm/tiptap/utils/format-html.d.ts +0 -6
  33. package/dist/esm/tiptap/utils/format-html.d.ts.map +0 -1
  34. package/dist/esm/tiptap/utils/format-html.js +0 -108
  35. package/dist/esm/tiptap/utils/normalize-html.d.ts +0 -7
  36. package/dist/esm/tiptap/utils/normalize-html.d.ts.map +0 -1
  37. package/dist/esm/tiptap/utils/normalize-html.js +0 -109
@@ -1,109 +0,0 @@
1
- import { HTML_ELEMENTS } from '../constants';
2
- /**
3
- * Normalizes HTML by removing formatting whitespace (newlines and indentation)
4
- * while preserving meaningful whitespace within text content.
5
- * Used when converting from source mode back to visual editor.
6
- */
7
- export const normalizeHtml = (html) => {
8
- const div = document.createElement(HTML_ELEMENTS.DIV);
9
- div.innerHTML = html;
10
- cleanScriptsAndStyles(div);
11
- convertCommentsToSpans(div);
12
- unwrapHrFromParagraphs(div);
13
- flattenEmptyParagraphs(div);
14
- mergeConsecutiveBreaks(div);
15
- mergeConsecutiveBreaks(div);
16
- return div.innerHTML;
17
- };
18
- const convertCommentsToSpans = (root) => {
19
- const iterator = document.createNodeIterator(root, NodeFilter.SHOW_COMMENT, null);
20
- let currentNode;
21
- const comments = [];
22
- while ((currentNode = iterator.nextNode())) {
23
- comments.push(currentNode);
24
- }
25
- comments.forEach(comment => {
26
- var _a;
27
- const span = document.createElement(HTML_ELEMENTS.SPAN);
28
- span.setAttribute('data-type', 'comment');
29
- span.setAttribute('data-content', comment.textContent || '');
30
- (_a = comment.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(span, comment);
31
- });
32
- };
33
- const cleanScriptsAndStyles = (root) => {
34
- const scripts = root.querySelectorAll(`${HTML_ELEMENTS.SCRIPT}, ${HTML_ELEMENTS.STYLE}`);
35
- scripts.forEach(el => {
36
- const content = el.textContent;
37
- if (content && content.trim()) {
38
- el.textContent = dedent(content);
39
- }
40
- });
41
- };
42
- const unwrapHrFromParagraphs = (root) => {
43
- const hrs = root.querySelectorAll(HTML_ELEMENTS.HR);
44
- hrs.forEach(hr => {
45
- var _a;
46
- const parent = hr.parentElement;
47
- if (parent && parent.tagName.toLowerCase() === HTML_ELEMENTS.P) {
48
- // If HR is the only child (or only meaningful child), replace the p with hr
49
- const siblings = Array.from(parent.childNodes).filter(node => {
50
- var _a;
51
- return node !== hr &&
52
- !(node.nodeType === Node.TEXT_NODE && !((_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim()));
53
- });
54
- if (siblings.length === 0) {
55
- (_a = parent.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(hr, parent);
56
- }
57
- }
58
- });
59
- };
60
- const flattenEmptyParagraphs = (root) => {
61
- // Remove empty paragraphs that only contain <br>
62
- const paragraphs = root.querySelectorAll(HTML_ELEMENTS.P);
63
- paragraphs.forEach(p => {
64
- var _a;
65
- const hasOnlyBrOrWhitespace = Array.from(p.childNodes).every(child => {
66
- var _a;
67
- return (child.nodeType === Node.ELEMENT_NODE &&
68
- child.tagName.toLowerCase() === HTML_ELEMENTS.BR) ||
69
- (child.nodeType === Node.TEXT_NODE && !((_a = child.textContent) === null || _a === void 0 ? void 0 : _a.trim()));
70
- });
71
- if (hasOnlyBrOrWhitespace && p.childNodes.length > 0) {
72
- // Replace <p><br></p> with just <br>
73
- const br = document.createElement(HTML_ELEMENTS.BR);
74
- (_a = p.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(br, p);
75
- }
76
- });
77
- };
78
- const mergeConsecutiveBreaks = (root) => {
79
- const brs = root.querySelectorAll(HTML_ELEMENTS.BR);
80
- brs.forEach(br => {
81
- var _a, _b;
82
- let next = br.nextSibling;
83
- // Skip whitespace nodes
84
- while (next &&
85
- next.nodeType === Node.TEXT_NODE &&
86
- !((_a = next.textContent) === null || _a === void 0 ? void 0 : _a.trim())) {
87
- next = next.nextSibling;
88
- }
89
- // If next is also a br, remove this one
90
- if (next &&
91
- next.nodeType === Node.ELEMENT_NODE &&
92
- next.tagName.toLowerCase() === HTML_ELEMENTS.BR) {
93
- (_b = br.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(br);
94
- }
95
- });
96
- };
97
- const dedent = (str) => {
98
- const lines = str.split('\n');
99
- const nonEmptyLines = lines.filter(line => line.trim());
100
- const LEADING_WHITESPACE_REGEX = /^\s*/;
101
- const minIndent = nonEmptyLines.reduce((min, line) => {
102
- const indent = line.match(LEADING_WHITESPACE_REGEX)[0].length;
103
- return Math.min(min, indent);
104
- }, Infinity);
105
- return lines
106
- .map(line => (line.length >= minIndent ? line.slice(minIndent) : line))
107
- .join('\n')
108
- .trim();
109
- };