@modusoperandi/licit 1.0.4 → 1.0.7

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 (360) hide show
  1. package/BlockquoteInsertNewLineCommand.js +16 -18
  2. package/BlockquoteInsertNewLineCommand.js.flow +76 -77
  3. package/BlockquoteNodeSpec.js +3 -4
  4. package/BlockquoteNodeSpec.js.flow +29 -30
  5. package/BlockquoteToggleCommand.js +16 -17
  6. package/BlockquoteToggleCommand.js.flow +56 -56
  7. package/BookmarkNodeSpec.js +2 -2
  8. package/BookmarkNodeSpec.js.flow +39 -39
  9. package/BulletListNodeSpec.js.flow +61 -61
  10. package/CZIProseMirror.js.flow +90 -90
  11. package/CodeBlockCommand.js +17 -18
  12. package/CodeBlockCommand.js.flow +65 -65
  13. package/CodeBlockNodeSpec.js.flow +24 -24
  14. package/CodeMarkSpec.js.flow +14 -14
  15. package/ContentPlaceholderPlugin.js +20 -21
  16. package/ContentPlaceholderPlugin.js.flow +185 -187
  17. package/CursorPlaceholderPlugin.js +11 -11
  18. package/CursorPlaceholderPlugin.js.flow +115 -115
  19. package/DocLayoutCommand.js +18 -21
  20. package/DocLayoutCommand.js.flow +97 -99
  21. package/DocNodeSpec.js.flow +64 -64
  22. package/EMMarkSpec.js.flow +14 -14
  23. package/EditorCommands.js.flow +126 -126
  24. package/EditorKeyMap.js +0 -1
  25. package/EditorKeyMap.js.flow +185 -187
  26. package/EditorMarks.js +2 -2
  27. package/EditorMarks.js.flow +71 -71
  28. package/EditorNodes.js +2 -3
  29. package/EditorNodes.js.flow +58 -59
  30. package/EditorPageLayoutPlugin.js +10 -10
  31. package/EditorPageLayoutPlugin.js.flow +67 -67
  32. package/EditorPlugins.js.flow +8 -8
  33. package/EditorSchema.js.flow +12 -12
  34. package/EditorState.js.flow +7 -7
  35. package/FontSizeMarkSpec.js.flow +49 -49
  36. package/FontTypeMarkSpec.js +1 -1
  37. package/FontTypeMarkSpec.js.flow +80 -80
  38. package/HTMLMutator.js +6 -7
  39. package/HTMLMutator.js.flow +59 -59
  40. package/HardBreakNodeSpec.js.flow +15 -15
  41. package/HeadingNodeSpec.js +3 -13
  42. package/HeadingNodeSpec.js.flow +42 -52
  43. package/HistoryRedoCommand.js +15 -16
  44. package/HistoryRedoCommand.js.flow +41 -41
  45. package/HistoryUndoCommand.js +15 -16
  46. package/HistoryUndoCommand.js.flow +41 -41
  47. package/HorizontalRuleCommand.js +15 -16
  48. package/HorizontalRuleCommand.js.flow +71 -71
  49. package/HorizontalRuleNodeSpec.js.flow +39 -39
  50. package/ImageUploadPlaceholderPlugin.js +15 -17
  51. package/ImageUploadPlaceholderPlugin.js.flow +190 -192
  52. package/LinkMarkSpec.js +6 -1
  53. package/LinkMarkSpec.js.flow +37 -32
  54. package/LinkSetURLCommand.js +130 -60
  55. package/LinkSetURLCommand.js.flow +141 -117
  56. package/LinkTooltipPlugin.js +122 -34
  57. package/LinkTooltipPlugin.js.flow +261 -190
  58. package/ListItemInsertNewLineCommand.js +16 -18
  59. package/ListItemInsertNewLineCommand.js.flow +76 -77
  60. package/ListItemMergeCommand.js +24 -24
  61. package/ListItemMergeCommand.js.flow +198 -199
  62. package/ListItemNodeSpec.js.flow +52 -52
  63. package/ListSplitCommand.js +15 -16
  64. package/ListSplitCommand.js.flow +54 -54
  65. package/ListToggleCommand.js +19 -20
  66. package/ListToggleCommand.js.flow +99 -99
  67. package/MarkNames.js.flow +18 -18
  68. package/MarksClearCommand.js +17 -18
  69. package/MarksClearCommand.js.flow +65 -65
  70. package/MathEditCommand.js +17 -19
  71. package/MathEditCommand.js.flow +119 -120
  72. package/MathNodeSpec.js.flow +46 -46
  73. package/NodeNames.js.flow +23 -23
  74. package/OrderedListNodeSpec.js +2 -2
  75. package/OrderedListNodeSpec.js.flow +132 -132
  76. package/ParagraphNodeSpec.js +11 -2
  77. package/ParagraphNodeSpec.js.flow +163 -156
  78. package/ParagraphSpacingCommand.js +21 -23
  79. package/ParagraphSpacingCommand.js.flow +139 -144
  80. package/PrintCommand.js +17 -18
  81. package/PrintCommand.js.flow +53 -53
  82. package/SelectionPlaceholderPlugin.js +11 -11
  83. package/SelectionPlaceholderPlugin.js.flow +131 -131
  84. package/SpacerMarkSpec.js +2 -2
  85. package/SpacerMarkSpec.js.flow +47 -47
  86. package/StrikeMarkSpec.js.flow +21 -21
  87. package/StrongMarkSpec.js.flow +25 -25
  88. package/StyleView.js +5 -7
  89. package/StyleView.js.flow +18 -19
  90. package/TableBackgroundColorCommand.js +34 -23
  91. package/TableBackgroundColorCommand.js.flow +80 -75
  92. package/TableBorderColorCommand.js +34 -23
  93. package/TableBorderColorCommand.js.flow +81 -75
  94. package/TableCellColorCommand.js +20 -21
  95. package/TableCellColorCommand.js.flow +74 -75
  96. package/TableCellMenuPlugin.js +19 -19
  97. package/TableCellMenuPlugin.js.flow +130 -132
  98. package/TableInsertCommand.js +19 -22
  99. package/TableInsertCommand.js.flow +118 -120
  100. package/TableMergeCellsCommand.js +19 -19
  101. package/TableMergeCellsCommand.js.flow +113 -112
  102. package/TableNodesSpecs.js +4 -2
  103. package/TableNodesSpecs.js.flow +80 -78
  104. package/TablePlugins.js.flow +14 -14
  105. package/TableResizePlugin.js +20 -20
  106. package/TableResizePlugin.js.flow +631 -631
  107. package/TextColorMarkSpec.js.flow +35 -35
  108. package/TextHighlightMarkSpec.js.flow +38 -38
  109. package/TextInsertTabSpaceCommand.js +15 -16
  110. package/TextInsertTabSpaceCommand.js.flow +106 -106
  111. package/TextNoWrapMarkSpec.js.flow +14 -14
  112. package/TextNodeSpec.js.flow +7 -7
  113. package/TextSelectionMarkSpec.js.flow +24 -24
  114. package/TextSubMarkSpec.js.flow +20 -20
  115. package/TextSuperMarkSpec.js.flow +20 -20
  116. package/TextUnderlineMarkSpec.js.flow +27 -27
  117. package/Types.js +6 -0
  118. package/Types.js.flow +77 -75
  119. package/WebFontLoader.js +6 -7
  120. package/WebFontLoader.js.flow +22 -22
  121. package/blockQuoteInputRule.js.flow +36 -36
  122. package/bom.xml +17223 -25722
  123. package/browser.js.flow +7 -7
  124. package/buildEditorPlugins.js +6 -7
  125. package/buildEditorPlugins.js.flow +49 -49
  126. package/buildInputRules.js +8 -4
  127. package/buildInputRules.js.flow +85 -81
  128. package/client/CollabConnector.js +20 -20
  129. package/client/CollabConnector.js.flow +90 -90
  130. package/client/EditorConnection.js +10 -9
  131. package/client/EditorConnection.js.flow +324 -323
  132. package/client/Licit.js +78 -115
  133. package/client/Licit.js.flow +611 -643
  134. package/client/Licit.test.js +49 -39
  135. package/client/Licit.test.js.flow +104 -98
  136. package/client/Reporter.js +5 -6
  137. package/client/Reporter.js.flow +37 -37
  138. package/client/SimpleConnector.js +5 -5
  139. package/client/SimpleConnector.js.flow +61 -61
  140. package/client/http.js +0 -6
  141. package/client/http.js.flow +62 -70
  142. package/client/licit.css +12 -12
  143. package/client/throttle.js +8 -2
  144. package/client/throttle.js.flow +27 -27
  145. package/convertFromDOMElement.js +2 -4
  146. package/convertFromDOMElement.js.flow +33 -36
  147. package/convertFromHTML.js +2 -3
  148. package/convertFromHTML.js.flow +15 -17
  149. package/convertFromJSON.js +1 -2
  150. package/convertFromJSON.js.flow +55 -56
  151. package/convertToCSSPTValue.js +6 -10
  152. package/convertToCSSPTValue.js.flow +19 -22
  153. package/convertToJSON.js.flow +7 -7
  154. package/createCommand.js +16 -17
  155. package/createCommand.js.flow +62 -62
  156. package/createEditorKeyMap.js +2 -2
  157. package/createEditorKeyMap.js.flow +94 -94
  158. package/createEmptyEditorState.js +2 -3
  159. package/createEmptyEditorState.js.flow +29 -31
  160. package/createTableResizingPlugin.js +6 -6
  161. package/createTableResizingPlugin.js.flow +86 -86
  162. package/findActionableCell.js.flow +74 -74
  163. package/findActiveMark.js +1 -1
  164. package/findActiveMark.js.flow +32 -32
  165. package/hyphenize.js.flow +17 -17
  166. package/index.d.ts +165 -165
  167. package/index.js.flow +10 -10
  168. package/insertTable.js +0 -3
  169. package/insertTable.js.flow +54 -56
  170. package/isEditorStateEmpty.js.flow +32 -32
  171. package/isTableNode.js.flow +15 -15
  172. package/joinDown.js +1 -3
  173. package/joinDown.js.flow +25 -27
  174. package/joinListNode.js.flow +55 -55
  175. package/joinUp.js +1 -3
  176. package/joinUp.js.flow +37 -39
  177. package/keymaps.js.flow +185 -185
  178. package/lookUpElement.js +2 -1
  179. package/lookUpElement.js.flow +14 -14
  180. package/nodeAt.js.flow +12 -12
  181. package/normalizeHTML.js +3 -1
  182. package/normalizeHTML.js.flow +80 -78
  183. package/package.json +162 -156
  184. package/patchAnchorElements.js +1 -1
  185. package/patchAnchorElements.js.flow +38 -38
  186. package/patchBreakElements.js +3 -2
  187. package/patchBreakElements.js.flow +22 -22
  188. package/patchElementInlineStyles.js +1 -1
  189. package/patchElementInlineStyles.js.flow +92 -92
  190. package/patchListElements.js +4 -4
  191. package/patchListElements.js.flow +276 -276
  192. package/patchMathElements.js +5 -7
  193. package/patchMathElements.js.flow +58 -60
  194. package/patchParagraphElements.js.flow +20 -20
  195. package/patchStyleElements.js +1 -1
  196. package/patchStyleElements.js.flow +197 -196
  197. package/patchTableElements.js +2 -3
  198. package/patchTableElements.js.flow +88 -89
  199. package/rebaseDocWithSteps.js.flow +42 -42
  200. package/sanitizeURL.js +1 -1
  201. package/sanitizeURL.js.flow +13 -13
  202. package/splitListItem.js +3 -3
  203. package/splitListItem.js.flow +191 -191
  204. package/styles.css +19 -19
  205. package/styles0.css +29 -29
  206. package/toClosestFontPtSize.js.flow +22 -22
  207. package/toSafeHTMLDocument.js.flow +9 -9
  208. package/toggleBlockquote.js +4 -5
  209. package/toggleBlockquote.js.flow +101 -108
  210. package/toggleCodeBlock.js +6 -6
  211. package/toggleCodeBlock.js.flow +102 -102
  212. package/ui/AlertInfo.js +15 -16
  213. package/ui/AlertInfo.js.flow +64 -64
  214. package/ui/BookmarkNodeView.js +20 -21
  215. package/ui/BookmarkNodeView.js.flow +66 -66
  216. package/ui/CommandButton.js +15 -16
  217. package/ui/CommandButton.js.flow +68 -68
  218. package/ui/CommandMenu.js +19 -20
  219. package/ui/CommandMenu.js.flow +75 -75
  220. package/ui/CommandMenuButton.js +23 -25
  221. package/ui/CommandMenuButton.js.flow +130 -131
  222. package/ui/CustomEditorView.js +20 -20
  223. package/ui/CustomEditorView.js.flow +29 -28
  224. package/ui/CustomMenu.js +11 -12
  225. package/ui/CustomMenu.js.flow +17 -17
  226. package/ui/CustomMenuItem.js +16 -18
  227. package/ui/CustomMenuItem.js.flow +36 -36
  228. package/ui/CustomNodeView.js +29 -19
  229. package/ui/CustomNodeView.js.flow +207 -200
  230. package/ui/CustomRadioButton.js +18 -21
  231. package/ui/CustomRadioButton.js.flow +64 -65
  232. package/ui/DocLayoutEditor.js +18 -20
  233. package/ui/DocLayoutEditor.js.flow +145 -146
  234. package/ui/Editor.js +30 -28
  235. package/ui/Editor.js.flow +287 -288
  236. package/ui/EditorFrameset.js +13 -14
  237. package/ui/EditorFrameset.js.flow +81 -81
  238. package/ui/EditorToolbar.js +36 -42
  239. package/ui/EditorToolbar.js.flow +199 -218
  240. package/ui/EditorToolbarConfig.js +5 -5
  241. package/ui/EditorToolbarConfig.js.flow +164 -164
  242. package/ui/FontSizeCommandMenuButton.js +14 -15
  243. package/ui/FontSizeCommandMenuButton.js.flow +66 -66
  244. package/ui/FontTypeCommandMenuButton.js +15 -17
  245. package/ui/FontTypeCommandMenuButton.js.flow +60 -61
  246. package/ui/Frag.js +11 -12
  247. package/ui/Frag.js.flow +13 -13
  248. package/ui/Icon.js +21 -24
  249. package/ui/Icon.js.flow +89 -89
  250. package/ui/ImageInlineEditor.js +14 -15
  251. package/ui/ImageInlineEditor.js.flow +67 -67
  252. package/ui/KeyCodes.js.flow +12 -12
  253. package/ui/LinkTooltip.js +68 -34
  254. package/ui/LinkTooltip.js.flow +118 -85
  255. package/ui/LinkURLEditor.js +160 -43
  256. package/ui/LinkURLEditor.js.flow +243 -117
  257. package/ui/ListItemNodeView.js +6 -7
  258. package/ui/ListItemNodeView.js.flow +98 -98
  259. package/ui/ListTypeButton.js +23 -27
  260. package/ui/ListTypeButton.js.flow +128 -131
  261. package/ui/ListTypeCommandButton.js +14 -15
  262. package/ui/ListTypeCommandButton.js.flow +85 -85
  263. package/ui/ListTypeMenu.js +21 -22
  264. package/ui/ListTypeMenu.js.flow +70 -70
  265. package/ui/LoadingIndicator.js +11 -12
  266. package/ui/LoadingIndicator.js.flow +20 -20
  267. package/ui/MathEditor.js +17 -22
  268. package/ui/MathEditor.js.flow +72 -78
  269. package/ui/MathInlineEditor.js +20 -21
  270. package/ui/MathInlineEditor.js.flow +101 -102
  271. package/ui/MathNodeView.js +29 -30
  272. package/ui/MathNodeView.js.flow +176 -186
  273. package/ui/PasteMenu.js +19 -23
  274. package/ui/PasteMenu.js.flow +53 -57
  275. package/ui/ResizeObserver.js +1 -1
  276. package/ui/ResizeObserver.js.flow +106 -106
  277. package/ui/RichTextEditor.js +17 -18
  278. package/ui/RichTextEditor.js.flow +133 -133
  279. package/ui/SelectionObserver.js +8 -9
  280. package/ui/SelectionObserver.js.flow +134 -134
  281. package/ui/TableCellMenu.js +14 -15
  282. package/ui/TableCellMenu.js.flow +51 -51
  283. package/ui/TableGridSizeEditor.js +30 -33
  284. package/ui/TableGridSizeEditor.js.flow +187 -184
  285. package/ui/TableNodeView.js +18 -17
  286. package/ui/TableNodeView.js.flow +25 -25
  287. package/ui/bindScrollHandler.js +2 -1
  288. package/ui/bindScrollHandler.js.flow +46 -46
  289. package/ui/canUseCSSFont.js +5 -4
  290. package/ui/canUseCSSFont.js.flow +42 -43
  291. package/ui/czi-body-layout-editor.css +16 -16
  292. package/ui/czi-bookmark-view.css +10 -10
  293. package/ui/czi-cursor-placeholder.css +36 -36
  294. package/ui/czi-custom-menu-button.css +18 -18
  295. package/ui/czi-custom-menu-item.css +30 -30
  296. package/ui/czi-custom-menu.css +8 -8
  297. package/ui/czi-custom-radio-button.css +80 -80
  298. package/ui/czi-custom-scrollbar.css +21 -21
  299. package/ui/czi-editor-frameset.css +81 -81
  300. package/ui/czi-editor-toolbar.css +122 -122
  301. package/ui/czi-editor.css +217 -220
  302. package/ui/czi-form.css +201 -107
  303. package/ui/czi-frag.css +3 -3
  304. package/ui/czi-heading.css +40 -40
  305. package/ui/czi-icon.css +72 -72
  306. package/ui/czi-image-resize-box.css +165 -165
  307. package/ui/czi-image-upload-editor.css +57 -57
  308. package/ui/czi-image-upload-placeholder.css +50 -50
  309. package/ui/czi-image-url-editor.css +38 -38
  310. package/ui/czi-image-view.css +121 -125
  311. package/ui/czi-indent.css +137 -137
  312. package/ui/czi-inline-editor.css +20 -20
  313. package/ui/czi-link-tooltip.css +112 -71
  314. package/ui/czi-list.css +406 -410
  315. package/ui/czi-loading-indicator.css +66 -111
  316. package/ui/czi-math-view.css +62 -62
  317. package/ui/czi-selection-placeholder.css +24 -24
  318. package/ui/czi-table-cell-menu.css +16 -14
  319. package/ui/czi-table-grid-size-editor.css +37 -37
  320. package/ui/czi-table.css +87 -87
  321. package/ui/czi-vars.css +2 -2
  322. package/ui/findActiveFontSize.js +2 -1
  323. package/ui/findActiveFontSize.js.flow +55 -58
  324. package/ui/findActiveFontType.js +4 -3
  325. package/ui/findActiveFontType.js.flow +35 -38
  326. package/ui/fonts.css +460 -460
  327. package/ui/handleEditorDrop.js +1 -1
  328. package/ui/handleEditorDrop.js.flow +28 -28
  329. package/ui/handleEditorKeyDown.js +1 -1
  330. package/ui/handleEditorKeyDown.js.flow +39 -39
  331. package/ui/handleEditorPaste.js +1 -1
  332. package/ui/handleEditorPaste.js.flow +33 -33
  333. package/ui/htmlElementToRect.js.flow +18 -18
  334. package/ui/icon-font.css +9 -9
  335. package/ui/injectStyleSheet.js +2 -2
  336. package/ui/injectStyleSheet.js.flow +40 -42
  337. package/ui/isElementFullyVisible.js +1 -10
  338. package/ui/isElementFullyVisible.js.flow +14 -26
  339. package/ui/isOffline.js.flow +8 -8
  340. package/ui/isReactClass.js.flow +12 -12
  341. package/ui/listType.css +21 -21
  342. package/ui/mathquill-editor/MathQuillEditor.js +27 -30
  343. package/ui/mathquill-editor/MathQuillEditor.js.flow +158 -159
  344. package/ui/mathquill-editor/MathQuillEditorSymbols.js.flow +483 -483
  345. package/ui/mathquill-editor/MathQuillEditorSymbolsPanel.js +14 -15
  346. package/ui/mathquill-editor/MathQuillEditorSymbolsPanel.js.flow +50 -50
  347. package/ui/mathquill-editor/czi-mathquill-editor-symbols-panel.css +39 -39
  348. package/ui/mathquill-editor/czi-mathquill-editor.css +50 -50
  349. package/ui/mathquill-editor/mathquill-import-kludge.js +1 -8
  350. package/ui/mathquill-editor/mathquill-import-kludge.js.flow +17 -24
  351. package/ui/renderLaTeXAsHTML.js +4 -4
  352. package/ui/renderLaTeXAsHTML.js.flow +46 -46
  353. package/ui/resolveImage.js +5 -6
  354. package/ui/resolveImage.js.flow +121 -123
  355. package/ui/toCSSColor.js.flow +51 -51
  356. package/ui/toCSSLineSpacing.js +2 -3
  357. package/ui/toCSSLineSpacing.js.flow +53 -55
  358. package/ui/toHexColor.js.flow +26 -26
  359. package/ui/uuid.js.flow +9 -9
  360. package/uuid.js.flow +9 -9
@@ -1,78 +1,80 @@
1
- // @flow
2
-
3
- import {
4
- DOM_ATTRIBUTE_SIZE,
5
- HAIR_SPACE_CHAR,
6
- SPACER_SIZE_TAB,
7
- } from './SpacerMarkSpec.js';
8
- import patchAnchorElements from './patchAnchorElements.js';
9
- import patchBreakElements from './patchBreakElements.js';
10
- import patchElementInlineStyles from './patchElementInlineStyles.js';
11
- import patchListElements from './patchListElements.js';
12
- import patchMathElements from './patchMathElements.js';
13
- import patchParagraphElements from './patchParagraphElements.js';
14
- import patchStyleElements from './patchStyleElements.js';
15
- import patchTableElements from './patchTableElements.js';
16
- import toSafeHTMLDocument from './toSafeHTMLDocument.js';
17
-
18
- const HTML_BODY_PATTERN = /<body[\s>]/i;
19
- const LONG_UNDERLINE_PATTERN = /_+/g;
20
-
21
- // This is a workround to convert "&nbsp;&nbsp;......&nbsp;" into wider tab
22
- // tab spacers. For every 6 "&nbsp;", they will be converted into tab spacers.
23
- const LONG_TAB_SPACE_PATTERN = /(\&nbsp;){6}/g;
24
-
25
- const TAB_SPACER_HTML = new Array(6).join(
26
- `<span ${DOM_ATTRIBUTE_SIZE}="${SPACER_SIZE_TAB}">${HAIR_SPACE_CHAR}</span>`
27
- );
28
-
29
- function replaceNOBR(matched: string): string {
30
- // This is a workround to convert "_______" into none-wrapped text
31
- // that apppears like a horizontal line.
32
- if (matched && matched.length >= 20) {
33
- // needs extra space after it so user can escape the <nobr />.
34
- matched = `<nobr>${String(matched)}</nobr> `;
35
- }
36
- return matched;
37
- }
38
-
39
- export default function normalizeHTML(html: string): string {
40
- let body: ?HTMLElement = null;
41
-
42
- const sourceIsPage = HTML_BODY_PATTERN.test(html);
43
- html = html.replace(LONG_UNDERLINE_PATTERN, replaceNOBR);
44
-
45
- // Convert every two consecutive "&nbsp;" into a spacer tab.
46
- html = html.replace(LONG_TAB_SPACE_PATTERN, TAB_SPACER_HTML);
47
- const doc = toSafeHTMLDocument(html);
48
- if (doc) {
49
- // styles.
50
- patchStyleElements(doc);
51
- patchElementInlineStyles(doc);
52
- // contents.
53
- patchAnchorElements(doc);
54
- patchBreakElements(doc);
55
- patchListElements(doc);
56
- patchParagraphElements(doc);
57
- patchTableElements(doc);
58
- patchMathElements(doc);
59
- body = doc.getElementsByTagName('body')[0];
60
-
61
- if (body && sourceIsPage) {
62
- // Source HTML contains <body />, assumes this to be a complete
63
- // page HTML. Assume this <body /> may contain the style that indicates
64
- // page's layout.
65
- const frag = doc.createElement('html');
66
- frag.appendChild(body);
67
- return frag.innerHTML;
68
- }
69
- }
70
-
71
- if (!body) {
72
- // <body /> should alway be generated by doc.
73
- return 'Unsupported HTML content';
74
- }
75
-
76
- // HTML snippet only.
77
- return '<body>' + body.innerHTML + '</body>';
78
- }
1
+ // @flow
2
+
3
+ import {
4
+ DOM_ATTRIBUTE_SIZE,
5
+ HAIR_SPACE_CHAR,
6
+ SPACER_SIZE_TAB,
7
+ } from './SpacerMarkSpec.js';
8
+ import patchAnchorElements from './patchAnchorElements.js';
9
+ import patchBreakElements from './patchBreakElements.js';
10
+ import patchElementInlineStyles from './patchElementInlineStyles.js';
11
+ import patchListElements from './patchListElements.js';
12
+ import patchMathElements from './patchMathElements.js';
13
+ import patchParagraphElements from './patchParagraphElements.js';
14
+ import patchStyleElements from './patchStyleElements.js';
15
+ import patchTableElements from './patchTableElements.js';
16
+ import toSafeHTMLDocument from './toSafeHTMLDocument.js';
17
+
18
+ const HTML_BODY_PATTERN = /<body[\s>]/i;
19
+ const LONG_UNDERLINE_PATTERN = /_+/g;
20
+
21
+ // This is a workround to convert "&nbsp;&nbsp;......&nbsp;" into wider tab
22
+ // tab spacers. For every 6 "&nbsp;", they will be converted into tab spacers.
23
+ const LONG_TAB_SPACE_PATTERN = /(&nbsp;){6}/g;
24
+
25
+ const TAB_SPACER_HTML = new Array(6).join(
26
+ `<span ${DOM_ATTRIBUTE_SIZE}="${SPACER_SIZE_TAB}">${HAIR_SPACE_CHAR}</span>`
27
+ );
28
+
29
+ function replaceNOBR(matched: string): string {
30
+ // This is a workround to convert "_______" into none-wrapped text
31
+ // that apppears like a horizontal line.
32
+ if (matched && matched.length >= 20) {
33
+ // needs extra space after it so user can escape the <nobr />.
34
+ matched = `<nobr>${String(matched)}</nobr> `;
35
+ }
36
+ return matched;
37
+ }
38
+
39
+ export default function normalizeHTML(html: string): string {
40
+ let body: ?HTMLElement = null;
41
+
42
+ const sourceIsPage = HTML_BODY_PATTERN.test(html);
43
+ html = html.replace(LONG_UNDERLINE_PATTERN, replaceNOBR);
44
+
45
+ // Convert every two consecutive "&nbsp;" into a spacer tab.
46
+ html = html.replace(LONG_TAB_SPACE_PATTERN, TAB_SPACER_HTML);
47
+ // fix for jspdf copy paste text, from jspdf its always getting transparent
48
+ html = html.replace(/color:\s*transparent;/g, 'color: black;');
49
+ const doc = toSafeHTMLDocument(html);
50
+ if (doc) {
51
+ // styles.
52
+ patchStyleElements(doc);
53
+ patchElementInlineStyles(doc);
54
+ // contents.
55
+ patchAnchorElements(doc);
56
+ patchBreakElements(doc);
57
+ patchListElements(doc);
58
+ patchParagraphElements(doc);
59
+ patchTableElements(doc);
60
+ patchMathElements(doc);
61
+ body = doc.getElementsByTagName('body')[0];
62
+
63
+ if (body && sourceIsPage) {
64
+ // Source HTML contains <body />, assumes this to be a complete
65
+ // page HTML. Assume this <body /> may contain the style that indicates
66
+ // page's layout.
67
+ const frag = doc.createElement('html');
68
+ frag.appendChild(body);
69
+ return frag.innerHTML;
70
+ }
71
+ }
72
+
73
+ if (!body) {
74
+ // <body /> should alway be generated by doc.
75
+ return 'Unsupported HTML content';
76
+ }
77
+
78
+ // HTML snippet only.
79
+ return '<body>' + body.innerHTML + '</body>';
80
+ }
package/package.json CHANGED
@@ -1,156 +1,162 @@
1
- {
2
- "name": "@modusoperandi/licit",
3
- "version": "1.0.4",
4
- "type": "module",
5
- "subversion": "1",
6
- "description": "Rich text editor built with React and ProseMirror",
7
- "main": "index.js",
8
- "style": "styles.css",
9
- "types": "index.d.ts",
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/MO-Movia/licit.git"
13
- },
14
- "scripts": {
15
- "test": "jest --coverage",
16
- "test:unit": "jest",
17
- "test:coverage": "jest --coverage",
18
- "build:bom": "cyclonedx-npm --ignore-npm-errors --short-PURLs --output-format XML --output-file dist/bom.xml",
19
- "build:clean": "rm -rf dist/ && rm -f modusoperandi-licit-*.*.*.tgz",
20
- "build:css": "cp src/ui/*.css dist/ui && cp src/ui/mathquill-editor/*.css dist/ui/mathquill-editor && cp src/client/*.css dist/client && cp src/*.css dist",
21
- "build:fonts": "mkdirp ./dist/fonts && cp -r src/fonts/* dist/fonts",
22
- "build:babel": "babel src --out-dir dist",
23
- "build:flow": "flow-copy-source -v -i '**/__tests__/**' src dist",
24
- "build:dist": "npm run build:clean && npm run build:babel && npm run build:flow && npm run build:css && npm run build:fonts && npm run build:bom && cp src/*.d.ts dist/",
25
- "build:licit": "node utils/build_bin.js",
26
- "ci:bom": "cyclonedx-npm --ignore-npm-errors --short-PURLs --output-format XML --output-file dist/bom.xml",
27
- "ci:build": "npm run build:clean && npm run build:babel && npm run build:flow && npm run build:css && npm run build:fonts && npm run build:bom && copyfiles --up 1 \"src/**/*.d.ts\" dist/ && copyfiles --up 1 \"src/**/*.css\" dist && copyfiles package.json dist",
28
- "flow": "flow --show-all-errors",
29
- "lint:css": "stylelint \"**/*.css\"",
30
- "lint:js": "eslint \"src/**/*.js\" \"licit/**/*.js\"",
31
- "lint": "npm run lint:css & npm run lint:js",
32
- "start": "node scripts/webserver.js",
33
- "prebuild:style-service-docker": "node utils/build_customstyle_server.js",
34
- "build:style-service-docker": "docker build . -f style-service.Dockerfile -t style-service:latest"
35
- },
36
- "devDependencies": {
37
- "@babel/cli": "^7.19.3",
38
- "@babel/core": "^7.19.3",
39
- "@babel/eslint-parser": "^7.19.1",
40
- "@babel/plugin-proposal-class-properties": "^7.18.6",
41
- "@babel/plugin-proposal-decorators": "^7.19.3",
42
- "@babel/plugin-proposal-do-expressions": "^7.18.6",
43
- "@babel/plugin-proposal-export-default-from": "^7.18.10",
44
- "@babel/plugin-proposal-export-namespace-from": "^7.18.9",
45
- "@babel/plugin-proposal-function-sent": "^7.18.6",
46
- "@babel/plugin-proposal-logical-assignment-operators": "^7.18.9",
47
- "@babel/plugin-proposal-object-rest-spread": "^7.19.4",
48
- "@babel/plugin-proposal-pipeline-operator": "^7.18.9",
49
- "@babel/plugin-proposal-throw-expressions": "^7.18.6",
50
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
51
- "@babel/plugin-syntax-import-meta": "^7.10.4",
52
- "@babel/plugin-transform-flow-strip-types": "^7.10.4",
53
- "@babel/plugin-transform-parameters": "^7.18.8",
54
- "@babel/plugin-transform-runtime": "^7.19.1",
55
- "@babel/preset-env": "^7.19.4",
56
- "@babel/preset-flow": "^7.10.4",
57
- "@babel/preset-react": "^7.18.6",
58
- "@cyclonedx/cyclonedx-npm": "^1.11.0",
59
- "babel-jest": "^29.2.0",
60
- "babel-loader": "^9.1.3",
61
- "babel-plugin-flow-react-proptypes": "^26.0.0",
62
- "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
63
- "clean-webpack-plugin": "^4.0.0",
64
- "copy-webpack-plugin": "^12.0.2",
65
- "css-loader": "^6.9.1",
66
- "copyfiles": "^2.4.1",
67
- "enzyme": "^3.11.0",
68
- "eslint": "^8.25.0",
69
- "eslint-config-prettier": "^9.0.0",
70
- "eslint-plugin-jest": "^27.1.2",
71
- "eslint-plugin-prettier": "^4.2.1",
72
- "eslint-plugin-react": "^7.33.2",
73
- "exports-loader": "^1.1.0",
74
- "file-loader": "^6.2.0",
75
- "flow-bin": "^0.228.0",
76
- "flow-copy-source": "^2.0.9",
77
- "flow-webpack-plugin": "^1.2.0",
78
- "html-loader": "^5.0.0",
79
- "html-webpack-inline-source-plugin": "1.0.0-beta.2",
80
- "html-webpack-plugin": "^5.5.0",
81
- "husky": "^9.0.10",
82
- "identity-obj-proxy": "^3.0.0",
83
- "jest": "^29.2.0",
84
- "jest-environment-jsdom": "^29.3.1",
85
- "jest-junit": "^14.0.1",
86
- "jest-prosemirror": "^2.1.5",
87
- "jest-sonar-reporter": "^2.0.0",
88
- "lint-staged": "^13.0.3",
89
- "mkdirp": "^3.0.1",
90
- "prettier": "^2.1.2",
91
- "stylelint": "^15.6.0",
92
- "stylelint-config-standard": "^34.0.0",
93
- "stylelint-prettier": "^3.0.0",
94
- "terser-webpack-plugin": "^5.3.10",
95
- "ts-jest": "^29.1.2",
96
- "ts-loader": "^9.5.0",
97
- "ts-node": "^10.9.2",
98
- "webpack": "^5.74.0",
99
- "webpack-cli": "^5.1.4",
100
- "webpack-dev-server": "^5.0.2",
101
- "write-file-webpack-plugin": "^4.5.1"
102
- },
103
- "dependencies": {
104
- "@cfaester/enzyme-adapter-react-18": "^0.7.1",
105
- "body-parser": "^1.19.0",
106
- "browserkeymap": "^2.0.2",
107
- "cors": "^2.8.5",
108
- "express": "^4.17.1",
109
- "flatted": "^3.1.0",
110
- "flow-typed": "^3.3.1",
111
- "formidable": "^1.2.2",
112
- "invariant": "^2.2.4",
113
- "jquery": "^3.5.1",
114
- "katex": "^0.16.9",
115
- "mv": "^2.1.1",
116
- "node-mathquill": "^0.10.2",
117
- "prosemirror-collab": "^1.3.1",
118
- "prosemirror-tables": "^1.2.5",
119
- "query-string": "^6.13.1",
120
- "resize-observer-polyfill": "^1.5.1",
121
- "smooth-scroll-into-view-if-needed": "^2.0.2",
122
- "style-loader": "^3.3.3",
123
- "url": "^0.11.0",
124
- "webfontloader": "^1.6.28"
125
- },
126
- "peerDependencies": {
127
- "@modusoperandi/licit-ui-commands": "^1.0.0",
128
- "prosemirror-collab": "^1.2.2",
129
- "prosemirror-tables": "^1.2.5"
130
- },
131
- "overrides": {
132
- "semver": "^7.5.2"
133
- },
134
- "importSort": {
135
- ".js": {
136
- "parser": "babylon",
137
- "style": "module-grouping"
138
- }
139
- },
140
- "husky": {
141
- "hooks": {
142
- "pre-commit": "lint-staged"
143
- }
144
- },
145
- "lint-staged": {
146
- "*.css": [
147
- "stylelint --fix"
148
- ],
149
- "!(*test|*.setup).js": [
150
- "eslint --fix"
151
- ],
152
- "*.json": [
153
- "prettier --write"
154
- ]
155
- }
156
- }
1
+ {
2
+ "name": "@modusoperandi/licit",
3
+ "version": "1.0.7",
4
+ "type": "module",
5
+ "subversion": "1",
6
+ "description": "Rich text editor built with React and ProseMirror",
7
+ "main": "index.js",
8
+ "style": "styles.css",
9
+ "types": "index.d.ts",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/MO-Movia/licit.git"
13
+ },
14
+ "scripts": {
15
+ "test": "jest --coverage",
16
+ "test:unit": "jest",
17
+ "test:coverage": "jest --coverage",
18
+ "build:bom": "cyclonedx-npm --ignore-npm-errors --short-PURLs --output-format XML --output-file dist/bom.xml",
19
+ "build:clean": "rm -rf dist/ && rm -f modusoperandi-licit-*.*.*.tgz",
20
+ "build:css": "cp src/ui/*.css dist/ui && cp src/ui/mathquill-editor/*.css dist/ui/mathquill-editor && cp src/client/*.css dist/client && cp src/*.css dist",
21
+ "build:fonts": "mkdirp ./dist/fonts && cp -r src/fonts/* dist/fonts",
22
+ "build:babel": "babel src --out-dir dist",
23
+ "build:flow": "flow-copy-source -v -i '**/__tests__/**' src dist",
24
+ "build:dist": "npm run build:clean && npm run build:babel && npm run build:flow && npm run build:css && npm run build:fonts && npm run build:bom && cp src/*.d.ts dist/",
25
+ "build:licit": "node utils/build_bin.js",
26
+ "ci:bom": "cyclonedx-npm --ignore-npm-errors --short-PURLs --output-format XML --output-file dist/bom.xml",
27
+ "ci:build": "npm run build:clean && npm run build:babel && npm run build:flow && npm run build:css && npm run build:fonts && npm run build:bom && copyfiles --up 1 \"src/**/*.d.ts\" dist/ && copyfiles --up 1 \"src/**/*.css\" dist && copyfiles package.json dist",
28
+ "flow": "flow --show-all-errors",
29
+ "lint:css": "stylelint \"**/*.css\"",
30
+ "lint:js": "eslint \"src/**/*.js\"",
31
+ "lint": "npm run lint:css & npm run lint:js",
32
+ "start": "node scripts/webserver.js",
33
+ "prebuild:style-service-docker": "node utils/build_customstyle_server.js",
34
+ "build:style-service-docker": "docker build . -f style-service.Dockerfile -t style-service:latest"
35
+ },
36
+ "devDependencies": {
37
+ "@babel/cli": "^7.19.3",
38
+ "@babel/core": "^7.19.3",
39
+ "@babel/eslint-parser": "^7.19.1",
40
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
41
+ "@babel/plugin-proposal-decorators": "^7.19.3",
42
+ "@babel/plugin-proposal-do-expressions": "^7.18.6",
43
+ "@babel/plugin-proposal-export-default-from": "^7.18.10",
44
+ "@babel/plugin-proposal-export-namespace-from": "^7.18.9",
45
+ "@babel/plugin-proposal-function-sent": "^7.18.6",
46
+ "@babel/plugin-proposal-logical-assignment-operators": "^7.18.9",
47
+ "@babel/plugin-proposal-object-rest-spread": "^7.19.4",
48
+ "@babel/plugin-proposal-pipeline-operator": "^7.18.9",
49
+ "@babel/plugin-proposal-throw-expressions": "^7.18.6",
50
+ "@babel/plugin-syntax-dynamic-import": "^7.8.3",
51
+ "@babel/plugin-syntax-import-meta": "^7.10.4",
52
+ "@babel/plugin-transform-flow-strip-types": "^7.10.4",
53
+ "@babel/plugin-transform-parameters": "^7.18.8",
54
+ "@babel/plugin-transform-runtime": "^7.19.1",
55
+ "@babel/preset-env": "^7.19.4",
56
+ "@babel/preset-flow": "^7.10.4",
57
+ "@babel/preset-react": "^7.18.6",
58
+ "@cyclonedx/cyclonedx-npm": "^1.11.0",
59
+ "babel-jest": "^29.2.0",
60
+ "babel-loader": "^9.1.3",
61
+ "babel-plugin-flow-react-proptypes": "^26.0.0",
62
+ "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
63
+ "body-parser": "^1.19.0",
64
+ "clean-webpack-plugin": "^4.0.0",
65
+ "copy-webpack-plugin": "^12.0.2",
66
+ "copyfiles": "^2.4.1",
67
+ "cors": "^2.8.5",
68
+ "css-loader": "^7.1.1",
69
+ "enzyme": "^3.11.0",
70
+ "eslint": "^8.0.0",
71
+ "eslint-config-prettier": "^9.0.0",
72
+ "eslint-plugin-jest": "^28.2.0",
73
+ "eslint-plugin-prettier": "^5.1.3",
74
+ "eslint-plugin-react": "^7.33.2",
75
+ "exports-loader": "^5.0.0",
76
+ "express": "^4.17.1",
77
+ "file-loader": "^6.2.0",
78
+ "flow-bin": "^0.247.1",
79
+ "flow-copy-source": "^2.0.9",
80
+ "flow-typed": "^4.0.0",
81
+ "flow-webpack-plugin": "^1.2.0",
82
+ "formidable": "^3.5.1",
83
+ "html-loader": "^5.0.0",
84
+ "html-webpack-inline-source-plugin": "1.0.0-beta.2",
85
+ "html-webpack-plugin": "^5.5.0",
86
+ "husky": "^9.0.10",
87
+ "identity-obj-proxy": "^3.0.0",
88
+ "invariant": "^2.2.4",
89
+ "jest": "^29.2.0",
90
+ "jest-environment-jsdom": "^29.3.1",
91
+ "jest-junit": "^16.0.0",
92
+ "jest-prosemirror": "^3.0.0",
93
+ "jest-sonar-reporter": "^2.0.0",
94
+ "lint-staged": "^15.2.2",
95
+ "mkdirp": "^3.0.1",
96
+ "mv": "^2.1.1",
97
+ "prettier": "^3.2.5",
98
+ "style-loader": "^4.0.0",
99
+ "stylelint": "^16.2.1",
100
+ "stylelint-config-standard": "^36.0.0",
101
+ "stylelint-prettier": "^5.0.0",
102
+ "terser-webpack-plugin": "^5.3.10",
103
+ "ts-jest": "^29.1.2",
104
+ "ts-loader": "^9.5.0",
105
+ "ts-node": "^10.9.2",
106
+ "typescript": "5.5.4",
107
+ "webpack": "^5.74.0",
108
+ "webpack-cli": "^5.1.4",
109
+ "webpack-dev-server": "^5.0.2",
110
+ "write-file-webpack-plugin": "^4.5.1"
111
+ },
112
+ "dependencies": {
113
+ "@cfaester/enzyme-adapter-react-18": "^0.8.0",
114
+ "@modusoperandi/color-picker": "^1.0.1",
115
+ "body-parser": "^1.19.0",
116
+ "browserkeymap": "^2.0.2",
117
+ "flatted": "^3.1.0",
118
+ "flow-typed": "^4.0.0",
119
+ "formidable": "^3.5.1",
120
+ "invariant": "^2.2.4",
121
+ "jquery": "^3.5.1",
122
+ "katex": "^0.16.9",
123
+ "node-mathquill": "^0.10.2",
124
+ "react-tooltip": "^5.28.0",
125
+ "resize-observer-polyfill": "^1.5.1",
126
+ "smooth-scroll-into-view-if-needed": "^2.0.2",
127
+ "style-loader": "^4.0.0",
128
+ "url": "^0.11.0",
129
+ "webfontloader": "^1.6.28"
130
+ },
131
+ "peerDependencies": {
132
+ "@modusoperandi/licit-ui-commands": "^1.0.0",
133
+ "jquery": "^3.5.1",
134
+ "prosemirror-collab": "^1.2.2",
135
+ "prosemirror-tables": "^1.2.5"
136
+ },
137
+ "overrides": {
138
+ "libxmljs2": "^1.0.0"
139
+ },
140
+ "importSort": {
141
+ ".js": {
142
+ "parser": "babylon",
143
+ "style": "module-grouping"
144
+ }
145
+ },
146
+ "husky": {
147
+ "hooks": {
148
+ "pre-commit": "lint-staged"
149
+ }
150
+ },
151
+ "lint-staged": {
152
+ "*.css": [
153
+ "stylelint --fix"
154
+ ],
155
+ "!(*test|*.setup).js": [
156
+ "eslint --fix"
157
+ ],
158
+ "*.json": [
159
+ "prettier --write"
160
+ ]
161
+ }
162
+ }
@@ -15,7 +15,7 @@ function patchAnchorElement(node) {
15
15
  // <a id="t.0"></a>
16
16
  // <table class="c23">
17
17
  // and these anchor link should not be visible.
18
- var visible = node.id.indexOf('t.') !== 0;
18
+ var visible = !node.id.startsWith('t.');
19
19
  visible && node.setAttribute(ATTRIBUTE_BOOKMARK_VISIBLE, 'true');
20
20
  }
21
21
  var nextNode = node.nextElementSibling;
@@ -1,38 +1,38 @@
1
- // @flow
2
-
3
- import {
4
- ATTRIBUTE_BOOKMARK_ID,
5
- ATTRIBUTE_BOOKMARK_VISIBLE,
6
- } from './BookmarkNodeSpec.js';
7
-
8
- const BLOCK_NODE_NAME_PATTERN = /(P|H1|H2|H3|H4|H5|H6)/;
9
-
10
- export default function patchAnchorElements(doc: Document): void {
11
- Array.from(doc.querySelectorAll('a[id]')).forEach(patchAnchorElement);
12
- }
13
-
14
- function patchAnchorElement(node: HTMLElement): void {
15
- const { id } = node;
16
- if (id && node.childElementCount === 0) {
17
- // This looks like a bookmark generated from Google Doc, will render
18
- // this as BookmarkNode.
19
- node.setAttribute(ATTRIBUTE_BOOKMARK_ID, id);
20
-
21
- // Google Doc always inject anchor links before <table />.
22
- // <a id="t.3060ecccc199a88a1e4cc1252769f957b88f2207"></a>
23
- // <a id="t.0"></a>
24
- // <table class="c23">
25
- // and these anchor link should not be visible.
26
- const visible = node.id.indexOf('t.') !== 0;
27
-
28
- visible && node.setAttribute(ATTRIBUTE_BOOKMARK_VISIBLE, 'true');
29
- }
30
- const nextNode = node.nextElementSibling;
31
- if (!nextNode) {
32
- return;
33
- }
34
- // If this is next to a block element, make that block element the bookmark.
35
- if (BLOCK_NODE_NAME_PATTERN.test(nextNode.nodeName)) {
36
- nextNode.insertBefore(node, nextNode.firstChild);
37
- }
38
- }
1
+ // @flow
2
+
3
+ import {
4
+ ATTRIBUTE_BOOKMARK_ID,
5
+ ATTRIBUTE_BOOKMARK_VISIBLE,
6
+ } from './BookmarkNodeSpec.js';
7
+
8
+ const BLOCK_NODE_NAME_PATTERN = /(P|H1|H2|H3|H4|H5|H6)/;
9
+
10
+ export default function patchAnchorElements(doc: Document): void {
11
+ Array.from(doc.querySelectorAll('a[id]')).forEach(patchAnchorElement);
12
+ }
13
+
14
+ function patchAnchorElement(node: HTMLElement): void {
15
+ const { id } = node;
16
+ if (id && node.childElementCount === 0) {
17
+ // This looks like a bookmark generated from Google Doc, will render
18
+ // this as BookmarkNode.
19
+ node.setAttribute(ATTRIBUTE_BOOKMARK_ID, id);
20
+
21
+ // Google Doc always inject anchor links before <table />.
22
+ // <a id="t.3060ecccc199a88a1e4cc1252769f957b88f2207"></a>
23
+ // <a id="t.0"></a>
24
+ // <table class="c23">
25
+ // and these anchor link should not be visible.
26
+ const visible = !node.id.startsWith('t.');
27
+
28
+ visible && node.setAttribute(ATTRIBUTE_BOOKMARK_VISIBLE, 'true');
29
+ }
30
+ const nextNode = node.nextElementSibling;
31
+ if (!nextNode) {
32
+ return;
33
+ }
34
+ // If this is next to a block element, make that block element the bookmark.
35
+ if (BLOCK_NODE_NAME_PATTERN.test(nextNode.nodeName)) {
36
+ nextNode.insertBefore(node, nextNode.firstChild);
37
+ }
38
+ }
@@ -6,15 +6,16 @@ export default function patchBreakElements(doc) {
6
6
  Array.from(doc.querySelectorAll(selector)).forEach(patchBreakElement);
7
7
  }
8
8
  function patchBreakElement(brElement) {
9
+ var _brElement$parentElem, _div$parentElement;
9
10
  var ownerDocument = brElement.ownerDocument,
10
11
  parentElement = brElement.parentElement;
11
12
  if (!ownerDocument || !parentElement) {
12
13
  return;
13
14
  }
14
- var div = brElement.parentElement && brElement.parentElement.parentElement;
15
+ var div = (_brElement$parentElem = brElement.parentElement) === null || _brElement$parentElem === void 0 ? void 0 : _brElement$parentElem.parentElement;
15
16
  if (!div) {
16
17
  return;
17
18
  }
18
19
  var pp = ownerDocument.createElement('p');
19
- div.parentElement && div.parentElement.replaceChild(pp, div);
20
+ (_div$parentElement = div.parentElement) === null || _div$parentElement === void 0 || _div$parentElement.replaceChild(pp, div);
20
21
  }
@@ -1,22 +1,22 @@
1
- // @flow
2
-
3
- export default function patchBreakElements(doc: Document): void {
4
- // This is a workaround to handle HTML converted from DraftJS that
5
- // `<div><span><br /></span><div>` becomes `<p><br /><br /></p>`.
6
- // Block with single `<br />` inside should be collapsed into `<p />`.
7
- const selector = 'div > span:only-child > br:only-child';
8
- Array.from(doc.querySelectorAll(selector)).forEach(patchBreakElement);
9
- }
10
-
11
- function patchBreakElement(brElement: HTMLElement): void {
12
- const { ownerDocument, parentElement } = brElement;
13
- if (!ownerDocument || !parentElement) {
14
- return;
15
- }
16
- const div = brElement.parentElement && brElement.parentElement.parentElement;
17
- if (!div) {
18
- return;
19
- }
20
- const pp = ownerDocument.createElement('p');
21
- div.parentElement && div.parentElement.replaceChild(pp, div);
22
- }
1
+ // @flow
2
+
3
+ export default function patchBreakElements(doc: Document): void {
4
+ // This is a workaround to handle HTML converted from DraftJS that
5
+ // `<div><span><br /></span><div>` becomes `<p><br /><br /></p>`.
6
+ // Block with single `<br />` inside should be collapsed into `<p />`.
7
+ const selector = 'div > span:only-child > br:only-child';
8
+ Array.from(doc.querySelectorAll(selector)).forEach(patchBreakElement);
9
+ }
10
+
11
+ function patchBreakElement(brElement: HTMLElement): void {
12
+ const { ownerDocument, parentElement } = brElement;
13
+ if (!ownerDocument || !parentElement) {
14
+ return;
15
+ }
16
+ const div = brElement.parentElement?.parentElement;
17
+ if (!div) {
18
+ return;
19
+ }
20
+ const pp = ownerDocument.createElement('p');
21
+ div.parentElement?.replaceChild(pp, div);
22
+ }