@modusoperandi/licit 0.1.4 → 0.1.8

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 (692) hide show
  1. package/.babelrc +54 -54
  2. package/.dockerignore +4 -4
  3. package/.eslintignore +3 -3
  4. package/.eslintrc.js +80 -80
  5. package/.flowconfig +37 -37
  6. package/.github/workflows/build.yml +35 -29
  7. package/.github/workflows/lint.yml +30 -30
  8. package/.prettierignore +5 -5
  9. package/.prettierrc +4 -4
  10. package/.stylelintignore +1 -1
  11. package/.stylelintrc.json +13 -13
  12. package/.travis.yml +18 -18
  13. package/CODEOWNERS +40 -40
  14. package/LICENSE +22 -22
  15. package/README.md +286 -284
  16. package/build_collab_server.py +7 -7
  17. package/build_customstyle_server.py +7 -7
  18. package/build_image_server.py +7 -7
  19. package/dist/BlockquoteInsertNewLineCommand.js.flow +55 -55
  20. package/dist/BlockquoteNodeSpec.js.flow +30 -30
  21. package/dist/BlockquoteToggleCommand.js.flow +34 -34
  22. package/dist/BookmarkNodeSpec.js.flow +39 -39
  23. package/dist/BulletListNodeSpec.js.flow +61 -61
  24. package/dist/CZIProseMirror.js.flow +90 -90
  25. package/dist/CodeBlockCommand.js.flow +43 -43
  26. package/dist/CodeBlockNodeSpec.js.flow +24 -24
  27. package/dist/CodeMarkSpec.js.flow +14 -14
  28. package/dist/ContentPlaceholderPlugin.js.flow +187 -187
  29. package/dist/CursorPlaceholderPlugin.js.flow +115 -115
  30. package/dist/DocLayoutCommand.js.flow +94 -94
  31. package/dist/DocNodeSpec.js.flow +64 -64
  32. package/dist/EMMarkSpec.js.flow +14 -14
  33. package/dist/EditorCommands.js.flow +128 -128
  34. package/dist/EditorKeyMap.js.flow +187 -187
  35. package/dist/EditorMarks.js.flow +71 -71
  36. package/dist/EditorNodes.js.flow +60 -60
  37. package/dist/EditorPageLayoutPlugin.js.flow +67 -67
  38. package/dist/EditorPlugins.js.flow +8 -8
  39. package/dist/EditorSchema.js.flow +12 -12
  40. package/dist/EditorState.js.flow +7 -7
  41. package/dist/FontSizeCommand.js +0 -8
  42. package/dist/FontSizeCommand.js.flow +57 -73
  43. package/dist/FontSizeMarkSpec.js.flow +49 -49
  44. package/dist/FontTypeCommand.js +0 -8
  45. package/dist/FontTypeCommand.js.flow +100 -116
  46. package/dist/FontTypeMarkSpec.js.flow +80 -80
  47. package/dist/HTMLMutator.js.flow +59 -59
  48. package/dist/HardBreakNodeSpec.js.flow +15 -15
  49. package/dist/HeadingCommand.js.flow +51 -51
  50. package/dist/HeadingNodeSpec.js.flow +54 -54
  51. package/dist/HistoryRedoCommand.js.flow +20 -20
  52. package/dist/HistoryUndoCommand.js.flow +20 -20
  53. package/dist/HorizontalRuleCommand.js.flow +49 -49
  54. package/dist/HorizontalRuleNodeSpec.js.flow +39 -39
  55. package/dist/ImageFromURLCommand.js.flow +14 -14
  56. package/dist/ImageNodeSpec.js.flow +90 -90
  57. package/dist/ImageSourceCommand.js.flow +117 -117
  58. package/dist/ImageUploadCommand.js.flow +36 -36
  59. package/dist/ImageUploadPlaceholderPlugin.js.flow +192 -192
  60. package/dist/IndentCommand.js +0 -9
  61. package/dist/IndentCommand.js.flow +41 -54
  62. package/dist/LinkMarkSpec.js.flow +32 -32
  63. package/dist/LinkSetURLCommand.js.flow +103 -103
  64. package/dist/LinkTooltipPlugin.js.flow +203 -203
  65. package/dist/ListItemInsertNewLineCommand.js.flow +55 -55
  66. package/dist/ListItemMergeCommand.js.flow +177 -177
  67. package/dist/ListItemNodeSpec.js.flow +51 -51
  68. package/dist/ListSplitCommand.js.flow +32 -32
  69. package/dist/ListToggleCommand.js +3 -45
  70. package/dist/ListToggleCommand.js.flow +77 -117
  71. package/dist/MarkNames.js +2 -4
  72. package/dist/MarkNames.js.flow +18 -19
  73. package/dist/MarkToggleCommand.js +3 -114
  74. package/dist/MarkToggleCommand.js.flow +66 -168
  75. package/dist/MarksClearCommand.js +1 -18
  76. package/dist/MarksClearCommand.js.flow +42 -55
  77. package/dist/MathEditCommand.js.flow +110 -110
  78. package/dist/MathNodeSpec.js.flow +46 -46
  79. package/dist/NodeNames.js.flow +23 -23
  80. package/dist/OrderedListNodeSpec.js.flow +132 -132
  81. package/dist/ParagraphNodeSpec.js +6 -115
  82. package/dist/ParagraphNodeSpec.js.flow +160 -250
  83. package/dist/ParagraphSpacingCommand.js.flow +121 -121
  84. package/dist/PrintCommand.js.flow +31 -31
  85. package/dist/SelectionPlaceholderPlugin.js.flow +131 -131
  86. package/dist/SpacerMarkSpec.js.flow +47 -47
  87. package/dist/StrikeMarkSpec.js.flow +21 -21
  88. package/dist/StrongMarkSpec.js.flow +25 -25
  89. package/dist/StyleView.js.flow +19 -19
  90. package/dist/TableBackgroundColorCommand.js.flow +75 -75
  91. package/dist/TableBorderColorCommand.js.flow +75 -75
  92. package/dist/TableCellColorCommand.js.flow +71 -71
  93. package/dist/TableCellMenuPlugin.js.flow +125 -125
  94. package/dist/TableInsertCommand.js.flow +112 -112
  95. package/dist/TableMergeCellsCommand.js.flow +90 -90
  96. package/dist/TableNodesSpecs.js.flow +78 -78
  97. package/dist/TablePlugins.js.flow +14 -14
  98. package/dist/TableResizePlugin.js.flow +631 -631
  99. package/dist/TextAlignCommand.js +0 -8
  100. package/dist/TextAlignCommand.js.flow +122 -138
  101. package/dist/TextColorCommand.js +0 -16
  102. package/dist/TextColorCommand.js.flow +87 -112
  103. package/dist/TextColorMarkSpec.js.flow +35 -35
  104. package/dist/TextHighlightCommand.js +0 -12
  105. package/dist/TextHighlightCommand.js.flow +91 -110
  106. package/dist/TextHighlightMarkSpec.js.flow +38 -38
  107. package/dist/TextInsertTabSpaceCommand.js +2 -5
  108. package/dist/TextInsertTabSpaceCommand.js.flow +83 -85
  109. package/dist/TextLineSpacingCommand.js.flow +157 -157
  110. package/dist/TextNoWrapMarkSpec.js.flow +14 -14
  111. package/dist/TextNodeSpec.js.flow +7 -7
  112. package/dist/TextSelectionMarkSpec.js.flow +24 -24
  113. package/dist/TextSubMarkSpec.js.flow +20 -20
  114. package/dist/TextSuperMarkSpec.js.flow +20 -20
  115. package/dist/TextUnderlineMarkSpec.js.flow +27 -27
  116. package/dist/Types.js +2 -121
  117. package/dist/Types.js.flow +75 -155
  118. package/dist/WebFontLoader.js.flow +22 -22
  119. package/dist/applyMark.js +3 -4
  120. package/dist/applyMark.js.flow +61 -64
  121. package/dist/blockQuoteInputRule.js.flow +36 -36
  122. package/dist/bom.xml +89 -89
  123. package/dist/browser.js.flow +7 -7
  124. package/dist/buildEditorPlugins.js +1 -3
  125. package/dist/buildEditorPlugins.js.flow +51 -53
  126. package/dist/buildInputRules.js.flow +81 -81
  127. package/dist/clearMarks.js +2 -5
  128. package/dist/clearMarks.js.flow +128 -132
  129. package/dist/client/CollabConnector.js +7 -7
  130. package/dist/client/CollabConnector.js.flow +71 -75
  131. package/dist/client/EditorConnection.js.flow +307 -307
  132. package/dist/client/Licit.js +197 -117
  133. package/dist/client/Licit.js.flow +562 -495
  134. package/dist/client/Licit.test.js +3 -57
  135. package/dist/client/Licit.test.js.flow +65 -120
  136. package/dist/client/Reporter.js.flow +37 -37
  137. package/dist/client/SimpleConnector.js.flow +53 -53
  138. package/dist/client/http.js.flow +66 -66
  139. package/dist/client/licit.css +12 -12
  140. package/dist/client/throttle.js.flow +27 -27
  141. package/dist/compareNumber.js.flow +11 -11
  142. package/dist/consolidateListNodes.js +27 -27
  143. package/dist/consolidateListNodes.js.flow +281 -281
  144. package/dist/convertFromDOMElement.js.flow +36 -36
  145. package/dist/convertFromHTML.js.flow +19 -19
  146. package/dist/convertFromJSON.js.flow +78 -78
  147. package/dist/convertToCSSPTValue.js.flow +22 -22
  148. package/dist/convertToJSON.js.flow +7 -7
  149. package/dist/createCommand.js.flow +40 -40
  150. package/dist/createEditorKeyMap.js.flow +94 -94
  151. package/dist/createEmptyEditorState.js.flow +41 -41
  152. package/dist/createTableResizingPlugin.js.flow +86 -86
  153. package/dist/findActionableCell.js.flow +74 -74
  154. package/dist/findActiveMark.js.flow +32 -32
  155. package/dist/findNodesWithSameMark.js.flow +89 -89
  156. package/dist/hyphenize.js.flow +17 -17
  157. package/dist/index.js +0 -14
  158. package/dist/index.js.flow +10 -11
  159. package/dist/insertTable.js.flow +56 -56
  160. package/dist/isBulletListNode.js.flow +9 -9
  161. package/dist/isEditorStateEmpty.js.flow +32 -32
  162. package/dist/isInsideListItem.js.flow +13 -13
  163. package/dist/isListNode.js.flow +13 -13
  164. package/dist/isNodeSelectionForNodeType.js.flow +15 -15
  165. package/dist/isOrderedListNode.js.flow +9 -9
  166. package/dist/isTableNode.js.flow +15 -15
  167. package/dist/isTextStyleMarkCommandEnabled.js.flow +49 -49
  168. package/dist/joinDown.js.flow +27 -27
  169. package/dist/joinListNode.js.flow +55 -55
  170. package/dist/joinUp.js.flow +39 -39
  171. package/dist/keymaps.js.flow +185 -185
  172. package/dist/lookUpElement.js.flow +14 -14
  173. package/dist/nodeAt.js.flow +12 -12
  174. package/dist/noop.js.flow +5 -5
  175. package/dist/normalizeHTML.js.flow +78 -78
  176. package/dist/patchAnchorElements.js.flow +38 -38
  177. package/dist/patchBreakElements.js.flow +22 -22
  178. package/dist/patchElementInlineStyles.js.flow +92 -92
  179. package/dist/patchListElements.js.flow +276 -276
  180. package/dist/patchMathElements.js.flow +60 -60
  181. package/dist/patchParagraphElements.js.flow +20 -20
  182. package/dist/patchStyleElements.js.flow +194 -194
  183. package/dist/patchTableElements.js.flow +89 -89
  184. package/dist/rebaseDocWithSteps.js.flow +42 -42
  185. package/dist/sanitizeURL.js.flow +13 -13
  186. package/dist/splitListItem.js.flow +191 -191
  187. package/dist/styles.css +19 -21
  188. package/dist/styles0.css +29 -30
  189. package/dist/toClosestFontPtSize.js.flow +22 -22
  190. package/dist/toSafeHTMLDocument.js.flow +9 -9
  191. package/dist/toggleBlockquote.js.flow +91 -91
  192. package/dist/toggleCodeBlock.js.flow +102 -102
  193. package/dist/toggleHeading.js.flow +113 -113
  194. package/dist/toggleList.js.flow +450 -450
  195. package/dist/transformAndPreserveTextSelection.js.flow +151 -151
  196. package/dist/ui/AlertInfo.js +1 -1
  197. package/dist/ui/AlertInfo.js.flow +64 -64
  198. package/dist/ui/BookmarkNodeView.js.flow +66 -66
  199. package/dist/ui/ColorEditor.js.flow +101 -101
  200. package/dist/ui/CommandButton.js.flow +68 -68
  201. package/dist/ui/CommandMenu.js.flow +75 -75
  202. package/dist/ui/CommandMenuButton.js.flow +131 -131
  203. package/dist/ui/CustomButton.js.flow +33 -33
  204. package/dist/ui/CustomEditorView.js.flow +28 -28
  205. package/dist/ui/CustomMenu.js.flow +17 -17
  206. package/dist/ui/CustomMenuItem.js.flow +36 -36
  207. package/dist/ui/CustomNodeView.js +6 -1
  208. package/dist/ui/CustomNodeView.js.flow +200 -196
  209. package/dist/ui/CustomRadioButton.js.flow +65 -65
  210. package/dist/ui/DocLayoutEditor.js.flow +146 -146
  211. package/dist/ui/Editor.js.flow +291 -291
  212. package/dist/ui/EditorFrameset.js.flow +81 -81
  213. package/dist/ui/EditorToolbar.js.flow +211 -211
  214. package/dist/ui/EditorToolbarConfig.js +0 -6
  215. package/dist/ui/EditorToolbarConfig.js.flow +172 -178
  216. package/dist/ui/FontSizeCommandMenuButton.js.flow +66 -66
  217. package/dist/ui/FontTypeCommandMenuButton.js.flow +49 -49
  218. package/dist/ui/Frag.js.flow +13 -13
  219. package/dist/ui/Icon.js.flow +89 -89
  220. package/dist/ui/ImageAlignEditor.js.flow +60 -60
  221. package/dist/ui/ImageInlineEditor.js.flow +67 -67
  222. package/dist/ui/ImageNodeView.js +1 -10
  223. package/dist/ui/ImageNodeView.js.flow +404 -414
  224. package/dist/ui/ImageResizeBox.js.flow +219 -219
  225. package/dist/ui/ImageURLEditor.js.flow +119 -119
  226. package/dist/ui/ImageUploadEditor.js.flow +117 -117
  227. package/dist/ui/KeyCodes.js.flow +12 -12
  228. package/dist/ui/LinkTooltip.js.flow +85 -85
  229. package/dist/ui/LinkURLEditor.js.flow +111 -111
  230. package/dist/ui/ListItemNodeView.js.flow +98 -98
  231. package/dist/ui/ListTypeButton.js.flow +131 -131
  232. package/dist/ui/ListTypeCommandButton.js +1 -1
  233. package/dist/ui/ListTypeCommandButton.js.flow +85 -86
  234. package/dist/ui/ListTypeMenu.js.flow +70 -70
  235. package/dist/ui/LoadingIndicator.js.flow +20 -20
  236. package/dist/ui/MathEditor.js.flow +78 -78
  237. package/dist/ui/MathInlineEditor.js.flow +102 -102
  238. package/dist/ui/MathNodeView.js.flow +175 -175
  239. package/dist/ui/PasteMenu.js.flow +57 -57
  240. package/dist/ui/PointerSurface.js.flow +141 -141
  241. package/dist/ui/PopUp.js.flow +77 -77
  242. package/dist/ui/PopUpManager.js.flow +213 -213
  243. package/dist/ui/PopUpPosition.js +0 -0
  244. package/dist/ui/PopUpPosition.js.flow +104 -104
  245. package/dist/ui/ResizeObserver.js.flow +106 -106
  246. package/dist/ui/RichTextEditor.js.flow +133 -133
  247. package/dist/ui/SelectionObserver.js.flow +134 -134
  248. package/dist/ui/TableCellMenu.js.flow +38 -38
  249. package/dist/ui/TableGridSizeEditor.js.flow +184 -184
  250. package/dist/ui/TableNodeView.js.flow +22 -22
  251. package/dist/ui/TooltipSurface.js.flow +76 -76
  252. package/dist/ui/bindScrollHandler.js.flow +46 -46
  253. package/dist/ui/canUseCSSFont.js.flow +43 -43
  254. package/dist/ui/clamp.js.flow +11 -11
  255. package/dist/ui/createPopUp.js.flow +205 -205
  256. package/dist/ui/czi-animations.css +15 -15
  257. package/dist/ui/czi-body-layout-editor.css +16 -16
  258. package/dist/ui/czi-bookmark-view.css +10 -10
  259. package/dist/ui/czi-color-editor.css +56 -56
  260. package/dist/ui/czi-cursor-placeholder.css +36 -36
  261. package/dist/ui/czi-custom-button.css +93 -93
  262. package/dist/ui/czi-custom-menu-button.css +18 -18
  263. package/dist/ui/czi-custom-menu-item.css +30 -30
  264. package/dist/ui/czi-custom-menu.css +8 -8
  265. package/dist/ui/czi-custom-radio-button.css +80 -80
  266. package/dist/ui/czi-custom-scrollbar.css +21 -21
  267. package/dist/ui/czi-editor-frameset.css +81 -81
  268. package/dist/ui/czi-editor-toolbar.css +122 -122
  269. package/dist/ui/czi-editor.css +220 -221
  270. package/dist/ui/czi-form.css +104 -104
  271. package/dist/ui/czi-frag.css +3 -3
  272. package/dist/ui/czi-heading.css +40 -40
  273. package/dist/ui/czi-icon.css +72 -72
  274. package/dist/ui/czi-image-resize-box.css +165 -165
  275. package/dist/ui/czi-image-upload-editor.css +57 -57
  276. package/dist/ui/czi-image-upload-placeholder.css +50 -50
  277. package/dist/ui/czi-image-url-editor.css +38 -38
  278. package/dist/ui/czi-image-view.css +125 -125
  279. package/dist/ui/czi-indent.css +137 -137
  280. package/dist/ui/czi-inline-editor.css +20 -20
  281. package/dist/ui/czi-link-tooltip.css +71 -71
  282. package/dist/ui/czi-list.css +410 -410
  283. package/dist/ui/czi-loading-indicator.css +111 -111
  284. package/dist/ui/czi-math-view.css +62 -62
  285. package/dist/ui/czi-pop-up.css +32 -32
  286. package/dist/ui/czi-selection-placeholder.css +24 -24
  287. package/dist/ui/czi-table-cell-menu.css +14 -14
  288. package/dist/ui/czi-table-grid-size-editor.css +37 -37
  289. package/dist/ui/czi-table.css +86 -86
  290. package/dist/ui/czi-tooltip-surface.css +45 -45
  291. package/dist/ui/czi-vars.css +46 -46
  292. package/dist/ui/findActiveFontSize.js.flow +58 -58
  293. package/dist/ui/findActiveFontType.js.flow +38 -38
  294. package/dist/ui/fonts.css +471 -471
  295. package/dist/ui/handleEditorDrop.js.flow +28 -28
  296. package/dist/ui/handleEditorKeyDown.js.flow +39 -39
  297. package/dist/ui/handleEditorPaste.js.flow +33 -33
  298. package/dist/ui/htmlElementToRect.js.flow +18 -18
  299. package/dist/ui/icon-font.css +10 -10
  300. package/dist/ui/injectStyleSheet.js.flow +42 -42
  301. package/dist/ui/isElementFullyVisible.js.flow +23 -23
  302. package/dist/ui/isOffline.js.flow +8 -8
  303. package/dist/ui/isReactClass.js.flow +12 -12
  304. package/dist/ui/listType.css +21 -21
  305. package/dist/ui/mathquill-editor/MathQuillEditor.js.flow +159 -159
  306. package/dist/ui/mathquill-editor/MathQuillEditorSymbols.js.flow +483 -483
  307. package/dist/ui/mathquill-editor/MathQuillEditorSymbolsPanel.js.flow +48 -48
  308. package/dist/ui/mathquill-editor/czi-mathquill-editor-symbols-panel.css +39 -39
  309. package/dist/ui/mathquill-editor/czi-mathquill-editor.css +50 -50
  310. package/dist/ui/mathquill-editor/mathquill-import-kludge.js.flow +24 -24
  311. package/dist/ui/preventEventDefault.js.flow +5 -5
  312. package/dist/ui/rects.js.flow +47 -47
  313. package/dist/ui/renderLaTeXAsHTML.js.flow +46 -46
  314. package/dist/ui/resolveImage.js.flow +123 -123
  315. package/dist/ui/toCSSColor.js.flow +51 -51
  316. package/dist/ui/toCSSLineSpacing.js.flow +82 -82
  317. package/dist/ui/toHexColor.js.flow +26 -26
  318. package/dist/ui/uuid.js.flow +9 -9
  319. package/dist/updateIndentLevel.js +1 -47
  320. package/dist/updateIndentLevel.js.flow +211 -260
  321. package/dist/uuid.js.flow +9 -9
  322. package/flow-typed/@modusoperandilicit-customstyles.js +5 -0
  323. package/flow-typed/@modusoperandilicit-doc-attrs-step.js +5 -5
  324. package/flow-typed/@molicit-citation.js +5 -5
  325. package/flow-typed/create-emotion.js +5 -5
  326. package/flow-typed/docs-editor.js +3 -3
  327. package/flow-typed/draft-convert.js +3 -3
  328. package/flow-typed/draft-js.js +3 -3
  329. package/flow-typed/flatted.js +5 -5
  330. package/flow-typed/jquery.js +5 -5
  331. package/flow-typed/katex.js +6 -6
  332. package/flow-typed/mathquill.js +5 -5
  333. package/flow-typed/prosemirror-collab.js +5 -5
  334. package/flow-typed/prosemirror-commands.js +5 -5
  335. package/flow-typed/prosemirror-dev-tools.js +5 -5
  336. package/flow-typed/prosemirror-dropcursor.js +5 -5
  337. package/flow-typed/prosemirror-gapcursor.js +5 -5
  338. package/flow-typed/prosemirror-history.js +5 -5
  339. package/flow-typed/prosemirror-inputrules.js +5 -5
  340. package/flow-typed/prosemirror-keymap.js +5 -5
  341. package/flow-typed/prosemirror-model.js +5 -5
  342. package/flow-typed/prosemirror-state.js +5 -5
  343. package/flow-typed/prosemirror-tables.js +5 -5
  344. package/flow-typed/prosemirror-transform.js +5 -5
  345. package/flow-typed/prosemirror-utils.js +5 -5
  346. package/flow-typed/prosemirror-view.js +5 -5
  347. package/flow-typed/resize-observer-polyfill.js +5 -5
  348. package/flow-typed/uuid.js +5 -5
  349. package/jest.setup.js +5 -5
  350. package/licit/client/CustomLicitRuntime.js +95 -200
  351. package/licit/client/CustomStyleRuntime.js +136 -0
  352. package/licit/client/index.js +366 -365
  353. package/licit/index.html +11 -11
  354. package/licit/server/collab/instance.js +221 -221
  355. package/licit/server/collab/route.js +69 -69
  356. package/licit/server/collab/server.js +297 -296
  357. package/licit/server/collab/start.js +13 -13
  358. package/licit/server/customstyles/start.js +184 -184
  359. package/licit/server/image/start.js +58 -58
  360. package/lint.sh +4 -4
  361. package/package.json +165 -165
  362. package/run_collab_server.py +21 -21
  363. package/run_customstyle_server.py +20 -20
  364. package/run_image_server.py +20 -20
  365. package/run_web_server.py +25 -25
  366. package/scripts/build_bin.js +10 -10
  367. package/scripts/build_bin.py +103 -103
  368. package/scripts/ci_check_dist.sh +13 -13
  369. package/scripts/env.js +6 -6
  370. package/scripts/webserver.js +35 -35
  371. package/sonar-project.properties +11 -11
  372. package/src/BlockquoteInsertNewLineCommand.js +55 -55
  373. package/src/BlockquoteNodeSpec.js +30 -30
  374. package/src/BlockquoteToggleCommand.js +34 -34
  375. package/src/BookmarkNodeSpec.js +39 -39
  376. package/src/BulletListNodeSpec.js +61 -61
  377. package/src/CZIProseMirror.js +90 -90
  378. package/src/CodeBlockCommand.js +43 -43
  379. package/src/CodeBlockNodeSpec.js +24 -24
  380. package/src/CodeMarkSpec.js +14 -14
  381. package/src/ContentPlaceholderPlugin.js +187 -187
  382. package/src/CursorPlaceholderPlugin.js +115 -115
  383. package/src/DocLayoutCommand.js +94 -94
  384. package/src/DocNodeSpec.js +64 -64
  385. package/src/EMMarkSpec.js +14 -14
  386. package/src/EditorCommands.js +128 -128
  387. package/src/EditorKeyMap.js +187 -187
  388. package/src/EditorMarks.js +71 -71
  389. package/src/EditorNodes.js +60 -60
  390. package/src/EditorPageLayoutPlugin.js +67 -67
  391. package/src/EditorPlugins.js +8 -8
  392. package/src/EditorSchema.js +12 -12
  393. package/src/EditorState.js +7 -7
  394. package/src/FontSizeCommand.js +57 -73
  395. package/src/FontSizeMarkSpec.js +49 -49
  396. package/src/FontTypeCommand.js +100 -116
  397. package/src/FontTypeMarkSpec.js +80 -80
  398. package/src/HTMLMutator.js +59 -59
  399. package/src/HardBreakNodeSpec.js +15 -15
  400. package/src/HeadingCommand.js +51 -51
  401. package/src/HeadingNodeSpec.js +54 -54
  402. package/src/HistoryRedoCommand.js +20 -20
  403. package/src/HistoryUndoCommand.js +20 -20
  404. package/src/HorizontalRuleCommand.js +49 -49
  405. package/src/HorizontalRuleNodeSpec.js +39 -39
  406. package/src/ImageFromURLCommand.js +14 -14
  407. package/src/ImageNodeSpec.js +90 -90
  408. package/src/ImageSourceCommand.js +117 -117
  409. package/src/ImageUploadCommand.js +36 -36
  410. package/src/ImageUploadPlaceholderPlugin.js +192 -192
  411. package/src/IndentCommand.js +41 -54
  412. package/src/LinkMarkSpec.js +32 -32
  413. package/src/LinkSetURLCommand.js +103 -103
  414. package/src/LinkTooltipPlugin.js +203 -203
  415. package/src/ListItemInsertNewLineCommand.js +55 -55
  416. package/src/ListItemMergeCommand.js +177 -177
  417. package/src/ListItemNodeSpec.js +51 -51
  418. package/src/ListSplitCommand.js +32 -32
  419. package/src/ListToggleCommand.js +77 -117
  420. package/src/MarkNames.js +18 -19
  421. package/src/MarkToggleCommand.js +66 -168
  422. package/src/MarksClearCommand.js +42 -55
  423. package/src/MathEditCommand.js +110 -110
  424. package/src/MathNodeSpec.js +46 -46
  425. package/src/NodeNames.js +23 -23
  426. package/src/OrderedListNodeSpec.js +132 -132
  427. package/src/ParagraphNodeSpec.js +160 -250
  428. package/src/ParagraphSpacingCommand.js +121 -121
  429. package/src/PrintCommand.js +31 -31
  430. package/src/SelectionPlaceholderPlugin.js +131 -131
  431. package/src/SpacerMarkSpec.js +47 -47
  432. package/src/StrikeMarkSpec.js +21 -21
  433. package/src/StrongMarkSpec.js +25 -25
  434. package/src/StyleView.js +19 -19
  435. package/src/TableBackgroundColorCommand.js +75 -75
  436. package/src/TableBorderColorCommand.js +75 -75
  437. package/src/TableCellColorCommand.js +71 -71
  438. package/src/TableCellMenuPlugin.js +125 -125
  439. package/src/TableInsertCommand.js +112 -112
  440. package/src/TableMergeCellsCommand.js +90 -90
  441. package/src/TableNodesSpecs.js +78 -78
  442. package/src/TablePlugins.js +14 -14
  443. package/src/TableResizePlugin.js +631 -631
  444. package/src/TextAlignCommand.js +122 -138
  445. package/src/TextColorCommand.js +87 -112
  446. package/src/TextColorMarkSpec.js +35 -35
  447. package/src/TextHighlightCommand.js +91 -110
  448. package/src/TextHighlightMarkSpec.js +38 -38
  449. package/src/TextInsertTabSpaceCommand.js +83 -85
  450. package/src/TextLineSpacingCommand.js +157 -157
  451. package/src/TextNoWrapMarkSpec.js +14 -14
  452. package/src/TextNodeSpec.js +7 -7
  453. package/src/TextSelectionMarkSpec.js +24 -24
  454. package/src/TextSubMarkSpec.js +20 -20
  455. package/src/TextSuperMarkSpec.js +20 -20
  456. package/src/TextUnderlineMarkSpec.js +27 -27
  457. package/src/Types.js +75 -155
  458. package/src/WebFontLoader.js +22 -22
  459. package/src/applyMark.js +61 -64
  460. package/src/blockQuoteInputRule.js +36 -36
  461. package/src/browser.js +7 -7
  462. package/src/buildEditorPlugins.js +51 -53
  463. package/src/buildInputRules.js +81 -81
  464. package/src/clearMarks.js +128 -132
  465. package/src/client/CollabConnector.js +71 -75
  466. package/src/client/EditorConnection.js +307 -307
  467. package/src/client/Licit.js +562 -495
  468. package/src/client/Licit.test.js +65 -120
  469. package/src/client/Reporter.js +37 -37
  470. package/src/client/SimpleConnector.js +53 -53
  471. package/src/client/http.js +66 -66
  472. package/src/client/licit.css +12 -12
  473. package/src/client/throttle.js +27 -27
  474. package/src/compareNumber.js +11 -11
  475. package/src/consolidateListNodes.js +281 -281
  476. package/src/convertFromDOMElement.js +36 -36
  477. package/src/convertFromHTML.js +19 -19
  478. package/src/convertFromJSON.js +78 -78
  479. package/src/convertToCSSPTValue.js +22 -22
  480. package/src/convertToJSON.js +7 -7
  481. package/src/createCommand.js +40 -40
  482. package/src/createEditorKeyMap.js +94 -94
  483. package/src/createEmptyEditorState.js +41 -41
  484. package/src/createTableResizingPlugin.js +86 -86
  485. package/src/findActionableCell.js +74 -74
  486. package/src/findActiveMark.js +32 -32
  487. package/src/findNodesWithSameMark.js +89 -89
  488. package/src/hyphenize.js +17 -17
  489. package/src/index.js +10 -11
  490. package/src/insertTable.js +56 -56
  491. package/src/isBulletListNode.js +9 -9
  492. package/src/isEditorStateEmpty.js +32 -32
  493. package/src/isInsideListItem.js +13 -13
  494. package/src/isListNode.js +13 -13
  495. package/src/isNodeSelectionForNodeType.js +15 -15
  496. package/src/isOrderedListNode.js +9 -9
  497. package/src/isTableNode.js +15 -15
  498. package/src/isTextStyleMarkCommandEnabled.js +49 -49
  499. package/src/joinDown.js +27 -27
  500. package/src/joinListNode.js +55 -55
  501. package/src/joinUp.js +39 -39
  502. package/src/keymaps.js +185 -185
  503. package/src/lookUpElement.js +14 -14
  504. package/src/nodeAt.js +12 -12
  505. package/src/noop.js +5 -5
  506. package/src/normalizeHTML.js +78 -78
  507. package/src/patchAnchorElements.js +38 -38
  508. package/src/patchBreakElements.js +22 -22
  509. package/src/patchElementInlineStyles.js +92 -92
  510. package/src/patchListElements.js +276 -276
  511. package/src/patchMathElements.js +60 -60
  512. package/src/patchParagraphElements.js +20 -20
  513. package/src/patchStyleElements.js +194 -194
  514. package/src/patchTableElements.js +89 -89
  515. package/src/rebaseDocWithSteps.js +42 -42
  516. package/src/sanitizeURL.js +13 -13
  517. package/src/splitListItem.js +191 -191
  518. package/src/styles.css +19 -21
  519. package/src/styles0.css +29 -30
  520. package/src/toClosestFontPtSize.js +22 -22
  521. package/src/toSafeHTMLDocument.js +9 -9
  522. package/src/toggleBlockquote.js +91 -91
  523. package/src/toggleCodeBlock.js +102 -102
  524. package/src/toggleHeading.js +113 -113
  525. package/src/toggleList.js +450 -450
  526. package/src/transformAndPreserveTextSelection.js +151 -151
  527. package/src/ui/AlertInfo.js +64 -64
  528. package/src/ui/BookmarkNodeView.js +66 -66
  529. package/src/ui/ColorEditor.js +101 -101
  530. package/src/ui/CommandButton.js +68 -68
  531. package/src/ui/CommandMenu.js +75 -75
  532. package/src/ui/CommandMenuButton.js +131 -131
  533. package/src/ui/CustomButton.js +33 -33
  534. package/src/ui/CustomEditorView.js +28 -28
  535. package/src/ui/CustomMenu.js +17 -17
  536. package/src/ui/CustomMenuItem.js +36 -36
  537. package/src/ui/CustomNodeView.js +200 -196
  538. package/src/ui/CustomRadioButton.js +65 -65
  539. package/src/ui/DocLayoutEditor.js +146 -146
  540. package/src/ui/Editor.js +291 -291
  541. package/src/ui/EditorFrameset.js +81 -81
  542. package/src/ui/EditorToolbar.js +211 -211
  543. package/src/ui/EditorToolbarConfig.js +172 -178
  544. package/src/ui/FontSizeCommandMenuButton.js +66 -66
  545. package/src/ui/FontTypeCommandMenuButton.js +49 -49
  546. package/src/ui/Frag.js +13 -13
  547. package/src/ui/Icon.js +89 -89
  548. package/src/ui/ImageAlignEditor.js +60 -60
  549. package/src/ui/ImageInlineEditor.js +67 -67
  550. package/src/ui/ImageNodeView.js +404 -414
  551. package/src/ui/ImageResizeBox.js +219 -219
  552. package/src/ui/ImageURLEditor.js +119 -119
  553. package/src/ui/ImageUploadEditor.js +117 -117
  554. package/src/ui/KeyCodes.js +12 -12
  555. package/src/ui/LinkTooltip.js +85 -85
  556. package/src/ui/LinkURLEditor.js +111 -111
  557. package/src/ui/ListItemNodeView.js +98 -98
  558. package/src/ui/ListTypeButton.js +131 -131
  559. package/src/ui/ListTypeCommandButton.js +85 -86
  560. package/src/ui/ListTypeMenu.js +70 -70
  561. package/src/ui/LoadingIndicator.js +20 -20
  562. package/src/ui/MathEditor.js +78 -78
  563. package/src/ui/MathInlineEditor.js +102 -102
  564. package/src/ui/MathNodeView.js +175 -175
  565. package/src/ui/PasteMenu.js +57 -57
  566. package/src/ui/PointerSurface.js +141 -141
  567. package/src/ui/PopUp.js +77 -77
  568. package/src/ui/PopUpManager.js +213 -213
  569. package/src/ui/PopUpPosition.js +104 -104
  570. package/src/ui/ResizeObserver.js +106 -106
  571. package/src/ui/RichTextEditor.js +133 -133
  572. package/src/ui/SelectionObserver.js +134 -134
  573. package/src/ui/TableCellMenu.js +38 -38
  574. package/src/ui/TableGridSizeEditor.js +184 -184
  575. package/src/ui/TableNodeView.js +22 -22
  576. package/src/ui/TooltipSurface.js +76 -76
  577. package/src/ui/bindScrollHandler.js +46 -46
  578. package/src/ui/canUseCSSFont.js +43 -43
  579. package/src/ui/clamp.js +11 -11
  580. package/src/ui/createPopUp.js +205 -205
  581. package/src/ui/czi-animations.css +15 -15
  582. package/src/ui/czi-body-layout-editor.css +16 -16
  583. package/src/ui/czi-bookmark-view.css +10 -10
  584. package/src/ui/czi-color-editor.css +56 -56
  585. package/src/ui/czi-cursor-placeholder.css +36 -36
  586. package/src/ui/czi-custom-button.css +93 -93
  587. package/src/ui/czi-custom-menu-button.css +18 -18
  588. package/src/ui/czi-custom-menu-item.css +30 -30
  589. package/src/ui/czi-custom-menu.css +8 -8
  590. package/src/ui/czi-custom-radio-button.css +80 -80
  591. package/src/ui/czi-custom-scrollbar.css +21 -21
  592. package/src/ui/czi-editor-frameset.css +81 -81
  593. package/src/ui/czi-editor-toolbar.css +122 -122
  594. package/src/ui/czi-editor.css +220 -221
  595. package/src/ui/czi-form.css +104 -104
  596. package/src/ui/czi-frag.css +3 -3
  597. package/src/ui/czi-heading.css +40 -40
  598. package/src/ui/czi-icon.css +72 -72
  599. package/src/ui/czi-image-resize-box.css +165 -165
  600. package/src/ui/czi-image-upload-editor.css +57 -57
  601. package/src/ui/czi-image-upload-placeholder.css +50 -50
  602. package/src/ui/czi-image-url-editor.css +38 -38
  603. package/src/ui/czi-image-view.css +125 -125
  604. package/src/ui/czi-indent.css +137 -137
  605. package/src/ui/czi-inline-editor.css +20 -20
  606. package/src/ui/czi-link-tooltip.css +71 -71
  607. package/src/ui/czi-list.css +410 -410
  608. package/src/ui/czi-loading-indicator.css +111 -111
  609. package/src/ui/czi-math-view.css +62 -62
  610. package/src/ui/czi-pop-up.css +32 -32
  611. package/src/ui/czi-selection-placeholder.css +24 -24
  612. package/src/ui/czi-table-cell-menu.css +14 -14
  613. package/src/ui/czi-table-grid-size-editor.css +37 -37
  614. package/src/ui/czi-table.css +86 -86
  615. package/src/ui/czi-tooltip-surface.css +45 -45
  616. package/src/ui/czi-vars.css +46 -46
  617. package/src/ui/findActiveFontSize.js +58 -58
  618. package/src/ui/findActiveFontType.js +38 -38
  619. package/src/ui/fonts.css +471 -471
  620. package/src/ui/handleEditorDrop.js +28 -28
  621. package/src/ui/handleEditorKeyDown.js +39 -39
  622. package/src/ui/handleEditorPaste.js +33 -33
  623. package/src/ui/htmlElementToRect.js +18 -18
  624. package/src/ui/icon-font.css +10 -10
  625. package/src/ui/injectStyleSheet.js +42 -42
  626. package/src/ui/isElementFullyVisible.js +23 -23
  627. package/src/ui/isOffline.js +8 -8
  628. package/src/ui/isReactClass.js +12 -12
  629. package/src/ui/listType.css +21 -21
  630. package/src/ui/mathquill-editor/MathQuillEditor.js +159 -159
  631. package/src/ui/mathquill-editor/MathQuillEditorSymbols.js +483 -483
  632. package/src/ui/mathquill-editor/MathQuillEditorSymbolsPanel.js +48 -48
  633. package/src/ui/mathquill-editor/czi-mathquill-editor-symbols-panel.css +39 -39
  634. package/src/ui/mathquill-editor/czi-mathquill-editor.css +50 -50
  635. package/src/ui/mathquill-editor/mathquill-import-kludge.js +24 -24
  636. package/src/ui/preventEventDefault.js +5 -5
  637. package/src/ui/rects.js +47 -47
  638. package/src/ui/renderLaTeXAsHTML.js +46 -46
  639. package/src/ui/resolveImage.js +123 -123
  640. package/src/ui/toCSSColor.js +51 -51
  641. package/src/ui/toCSSLineSpacing.js +82 -82
  642. package/src/ui/toHexColor.js +26 -26
  643. package/src/ui/uuid.js +9 -9
  644. package/src/updateIndentLevel.js +211 -260
  645. package/src/uuid.js +9 -9
  646. package/style-service.Dockerfile +26 -26
  647. package/utils/build_bin.js +9 -9
  648. package/utils/build_customstyle_server.js +71 -71
  649. package/utils/build_image_server.js +71 -71
  650. package/utils/build_licit_collab_server.js +75 -75
  651. package/utils/build_web_server.js +40 -40
  652. package/utils/env.js +6 -6
  653. package/webpack.config.js +126 -126
  654. package/dist/CustomStyleCommand.js +0 -1534
  655. package/dist/CustomStyleCommand.js.flow +0 -1690
  656. package/dist/StylePlugin.js +0 -533
  657. package/dist/StylePlugin.js.flow +0 -548
  658. package/dist/clearCustomStyleMarks.js +0 -43
  659. package/dist/clearCustomStyleMarks.js.flow +0 -34
  660. package/dist/customStyle.js +0 -185
  661. package/dist/customStyle.js.flow +0 -171
  662. package/dist/ui/CustomMenuButton.js +0 -155
  663. package/dist/ui/CustomMenuButton.js.flow +0 -129
  664. package/dist/ui/CustomMenuUI.js +0 -479
  665. package/dist/ui/CustomMenuUI.js.flow +0 -464
  666. package/dist/ui/CustomStyleEditor.js +0 -1216
  667. package/dist/ui/CustomStyleEditor.js.flow +0 -1325
  668. package/dist/ui/CustomStyleItem.js +0 -164
  669. package/dist/ui/CustomStyleItem.js.flow +0 -152
  670. package/dist/ui/CustomStyleSubMenu.js +0 -62
  671. package/dist/ui/CustomStyleSubMenu.js.flow +0 -54
  672. package/dist/ui/HeadingCommandMenuButton.js +0 -157
  673. package/dist/ui/HeadingCommandMenuButton.js.flow +0 -147
  674. package/dist/ui/custom-dropdown.css +0 -90
  675. package/dist/ui/custom-style-edit.css +0 -430
  676. package/dist/ui/czi-cust-style-numbered.css +0 -137
  677. package/dist/ui/findActiveCustomStyle.js +0 -53
  678. package/dist/ui/findActiveCustomStyle.js.flow +0 -38
  679. package/src/CustomStyleCommand.js +0 -1690
  680. package/src/StylePlugin.js +0 -548
  681. package/src/clearCustomStyleMarks.js +0 -34
  682. package/src/customStyle.js +0 -171
  683. package/src/ui/CustomMenuButton.js +0 -129
  684. package/src/ui/CustomMenuUI.js +0 -464
  685. package/src/ui/CustomStyleEditor.js +0 -1325
  686. package/src/ui/CustomStyleItem.js +0 -152
  687. package/src/ui/CustomStyleSubMenu.js +0 -54
  688. package/src/ui/HeadingCommandMenuButton.js +0 -147
  689. package/src/ui/custom-dropdown.css +0 -90
  690. package/src/ui/custom-style-edit.css +0 -430
  691. package/src/ui/czi-cust-style-numbered.css +0 -137
  692. package/src/ui/findActiveCustomStyle.js +0 -38
@@ -1,631 +1,631 @@
1
- // @flow
2
-
3
- // Copyright (C) 2015-2016 by Marijn Haverbeke <marijnh@gmail.com> and others
4
- // Permission is hereby granted, free of charge, to any person obtaining a copy
5
- // of this software and associated documentation files (the "Software"), to deal
6
- // in the Software without restriction, including without limitation the rights
7
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- // copies of the Software, and to permit persons to whom the Software is
9
- // furnished to do so, subject to the following conditions:
10
-
11
- // The above copyright notice and this permission notice shall be included in
12
- // all copies or substantial portions of the Software.
13
-
14
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- // THE SOFTWARE.
21
-
22
- // License about this file:
23
- // This file is originally forked from
24
- // https://github.com/ProseMirror/prosemirror-tables/blob/0e74c6a1761651ccf3701eb8529fa9187ad5c91d/src/columnresizing.js
25
- // and most of the original codes had been modified to support the bevaviors
26
- // that czi-prosemirror needs.
27
- // The plugin provides the following behaviors:
28
- // - Let user resize a column without changing the total width of the table.
29
- // - Let user set the left margin of the table.
30
- // - Let user set the right margin of the table.
31
-
32
- import TableNodeView from './ui/TableNodeView';
33
- import { Node } from 'prosemirror-model';
34
- import { EditorState, Plugin, PluginKey } from 'prosemirror-state';
35
- import { Transform } from 'prosemirror-transform';
36
- import { Decoration, DecorationSet, EditorView } from 'prosemirror-view';
37
- import { findParentNodeOfTypeClosestToPos } from 'prosemirror-utils';
38
- import nullthrows from 'nullthrows';
39
- import {
40
- cellAround,
41
- pointsAtCell,
42
- setAttr,
43
- tableNodeTypes,
44
- TableMap,
45
- TableView,
46
- } from 'prosemirror-tables';
47
-
48
- type DraggingInfo = {
49
- columnElements: Array<HTMLElement>,
50
- startX: number,
51
- tableElement: HTMLElement,
52
- tableMarginLeft: number,
53
- tableMarginRight: number,
54
- tableWidth: number,
55
- tableWrapperWidth: number,
56
- taregtColumnIndex: number,
57
- };
58
-
59
- type PointerEvent = {
60
- target: null,
61
- clientX: number,
62
- clientY: number,
63
- };
64
-
65
- const PLUGIN_KEY = new PluginKey('tableColumnResizing');
66
-
67
- // [FS] IRAD-949 2020-05-27
68
- // Fix:Cell Resize Handler causes edit diificult to firsrst/last two chars in the cell.
69
- // Rezie cursor position issue fixed.
70
-
71
- const CELL_MIN_WIDTH = 30;
72
- const HANDLE_WIDTH = 5;
73
- const HANDLE_RIGHT_WIDTH = 20;
74
-
75
- let cancelDrag: ?Function = null;
76
- let isEnabled = true;
77
-
78
- // The immutable plugin state that stores the information for resizing.
79
- class ResizeState {
80
- cellPos: ?number;
81
- forMarginLeft: ?boolean;
82
- draggingInfo: ?DraggingInfo;
83
-
84
- constructor(
85
- cellPos: ?number,
86
- forMarginLeft: ?boolean,
87
- draggingInfo: ?DraggingInfo
88
- ) {
89
- this.cellPos = cellPos;
90
- this.draggingInfo = draggingInfo;
91
- this.forMarginLeft = forMarginLeft;
92
- }
93
-
94
- apply(tr: Transform): ResizeState {
95
- let state = this;
96
- const action = tr.getMeta(PLUGIN_KEY);
97
- if (action && typeof action.setCellPos === 'number') {
98
- return new ResizeState(action.setCellPos, action.setForMarginLeft, null);
99
- }
100
-
101
- if (action && action.setDraggingInfo !== undefined) {
102
- return new ResizeState(
103
- state.cellPos,
104
- state.forMarginLeft,
105
- action.setDraggingInfo
106
- );
107
- }
108
-
109
- if (state.cellPos && state.cellPos > -1 && tr.docChanged) {
110
- let cellPos = tr.mapping.map(state.cellPos, -1);
111
- if (!pointsAtCell(tr.doc.resolve(cellPos))) {
112
- cellPos = null;
113
- }
114
- state = new ResizeState(
115
- cellPos,
116
- cellPos ? state.forMarginLeft : false,
117
- state.draggingInfo
118
- );
119
- }
120
- return state;
121
- }
122
- }
123
-
124
- // Function that handles the mousemove event inside table cell.
125
- function handleMouseMove(view: EditorView, event: PointerEvent): void {
126
- const resizeState = PLUGIN_KEY.getState(view.state);
127
- if (resizeState.draggingInfo) {
128
- return;
129
- }
130
-
131
- const target = domCellAround(event.target);
132
- let forMarginLeft = false;
133
- let cell = -1;
134
-
135
- if (target instanceof HTMLTableCellElement) {
136
- const { left, right } = target.getBoundingClientRect();
137
- const offsetLeft = event.clientX - left;
138
- // [FS] IRAD-949 2020-05-27
139
- // Fix:Cell Resize Handler causes edit diificult to firsrst/last two chars in the cell.
140
- // Rezie cursor position issue fixed.
141
- if (offsetLeft <= HANDLE_WIDTH) {
142
- if (target.cellIndex === 0) {
143
- forMarginLeft = true;
144
- cell = edgeCell(view, event, 'right');
145
- } else {
146
- cell = edgeCell(view, event, 'left');
147
- }
148
- } else if (right - event.clientX <= HANDLE_WIDTH) {
149
- cell = edgeCell(view, event, 'right');
150
- }
151
- }
152
-
153
- if (
154
- cell === resizeState.cellPos &&
155
- forMarginLeft === resizeState.forMarginLeft
156
- ) {
157
- return;
158
- }
159
-
160
- if (cell !== -1) {
161
- const $cell = view.state.doc.resolve(cell);
162
- if (!$cell) {
163
- return;
164
- }
165
- }
166
- updateResizeHandle(view, cell, forMarginLeft);
167
- }
168
-
169
- // Function that handles the mouseleave event from the table cell.
170
- function handleMouseLeave(view: EditorView): void {
171
- const resizeState = PLUGIN_KEY.getState(view.state);
172
- const { cellPos, draggingInfo } = resizeState;
173
- if (cellPos > -1 && !draggingInfo) {
174
- updateResizeHandle(view, -1, false);
175
- }
176
- }
177
-
178
- // Function that handles the mousedown event from the table cell.
179
- function handleMouseDown(view: EditorView, event: MouseEvent): boolean {
180
- // It's possible that the resize action that happened earlier was inturrupted
181
- // while its dependent mouse events were stopped or prevented by others.
182
- // We need to stop the previous resize action if it did not finish.
183
- cancelDrag && cancelDrag(event);
184
-
185
- const resizeState = PLUGIN_KEY.getState(view.state);
186
- if (resizeState.cellPos === -1 || resizeState.draggingInfo) {
187
- return false;
188
- }
189
-
190
- let dragStarted = false;
191
- let dragMoveHandler = null;
192
-
193
- const finish = (event: MouseEvent) => {
194
- window.removeEventListener('mouseup', finish, true);
195
- window.removeEventListener('mousemove', this.move, true);
196
- dragStarted && handleDragEnd(view, event);
197
- cancelDrag = null;
198
- };
199
-
200
- const move = (event: any) => {
201
- if (event.which) {
202
- if (!dragStarted) {
203
- handleDragStart(view, event);
204
- dragStarted = true;
205
- }
206
- // Move events should be batched to avoid over-handling the mouse
207
- // event.
208
- dragMoveHandler = dragMoveHandler || batchMouseHandler(handleDragMove);
209
- dragMoveHandler(view, event);
210
- } else {
211
- finish(event);
212
- }
213
- };
214
-
215
- cancelDrag = finish;
216
- window.addEventListener('mouseup', finish, true);
217
- window.addEventListener('mousemove', move, true);
218
- event.preventDefault();
219
- return true;
220
- }
221
-
222
- function handleDragStart(view: EditorView, event: MouseEvent): void {
223
- const resizeState = PLUGIN_KEY.getState(view.state);
224
- if (resizeState.cellPos === -1 || resizeState.draggingInfo) {
225
- return;
226
- }
227
-
228
- view.dispatch(
229
- view.state.tr.setMeta(PLUGIN_KEY, {
230
- setDraggingInfo: calculateDraggingInfo(view, event, resizeState),
231
- })
232
- );
233
- }
234
-
235
- // Function that handles the mouse event while resizing the table cell.
236
- // This will temporarily updates the table's style until the resize ends.
237
- function handleDragMove(view: EditorView, event: PointerEvent): void {
238
- const resizeState = PLUGIN_KEY.getState(view.state);
239
- const { draggingInfo, forMarginLeft } = resizeState;
240
- if (!draggingInfo) {
241
- return;
242
- }
243
- const {
244
- startX,
245
- columnWidths,
246
- taregtColumnIndex,
247
- columnElements,
248
- tableElement,
249
- tableMarginLeft,
250
- tableMarginRight,
251
- } = draggingInfo;
252
-
253
- let totalWidth = 0;
254
- let ml = tableMarginLeft;
255
-
256
- const dx = event.clientX - startX;
257
- const lastIndex = columnWidths.length - 1;
258
- const widths = columnWidths.map((cw, index) => {
259
- let ww;
260
- if (forMarginLeft) {
261
- if (index === 0) {
262
- // Resize the first column.
263
- ww = Math.min(Math.max(CELL_MIN_WIDTH, cw - dx), cw + tableMarginLeft);
264
- // Resize table's left margin.
265
- ml = Math.max(0, tableMarginLeft + cw - ww);
266
- } else {
267
- // The rest columns remain the same,
268
- ww = cw;
269
- }
270
- } else if (index === taregtColumnIndex && index === lastIndex) {
271
- // Resize the last column.
272
- ww = Math.min(cw + tableMarginRight, Math.max(CELL_MIN_WIDTH, cw + dx));
273
- } else if (index === taregtColumnIndex) {
274
- // Resize the column.
275
- ww = Math.min(
276
- Math.max(CELL_MIN_WIDTH, cw + dx),
277
- cw + (columnWidths[index + 1] || 0) - CELL_MIN_WIDTH
278
- );
279
- } else if (index === taregtColumnIndex + 1) {
280
- // Resize the column's previous column.
281
- ww = Math.min(
282
- Math.max(CELL_MIN_WIDTH, cw - dx),
283
- cw + (columnWidths[index - 1] || 0) - CELL_MIN_WIDTH
284
- );
285
- } else {
286
- // This column does not resize.
287
- ww = cw;
288
- }
289
-
290
- totalWidth += ww;
291
- return ww;
292
- });
293
-
294
- const tableElementStyle = tableElement.style;
295
- tableElementStyle.marginLeft = `${ml}px`;
296
- // [FS] IRAD-993 2020-06-26
297
- // Fix:Table exceeds the canvas
298
- tableElementStyle.width = Math.round(totalWidth - ml) + 'px';
299
- tableElementStyle.minWidth = '';
300
- columnElements.forEach((colEl, index) => {
301
- colEl.style.width = Math.round(widths[index]) + 'px';
302
- });
303
- }
304
-
305
- // Function that handles the mouse event while stop resizing the table cell.
306
- function handleDragEnd(view: EditorView, event: any): void {
307
- const resizeState = PLUGIN_KEY.getState(view.state);
308
- const { cellPos, draggingInfo } = resizeState;
309
- if (!draggingInfo) {
310
- return;
311
- }
312
- const { columnElements, tableElement } = draggingInfo;
313
- const widths = columnElements.map((colEl) => {
314
- return parseFloat(colEl.style.width);
315
- });
316
-
317
- const $cell = view.state.doc.resolve(cellPos);
318
- const start = $cell.start(-1);
319
- const table = $cell.node(-1);
320
- const map = TableMap.get(table);
321
- let tr = view.state.tr;
322
- for (let row = 0; row < map.height; row++) {
323
- for (let col = 0; col < widths.length; col++) {
324
- const mapIndex = row * map.width + col;
325
- if (row && map.map[mapIndex] == map.map[mapIndex - map.width]) {
326
- // Rowspanning cell that has already been handled
327
- continue;
328
- }
329
- const pos = map.map[mapIndex];
330
- const { attrs } = table.nodeAt(pos);
331
- const colspan = attrs.colspan || 1;
332
- const colwidth = widths.slice(col, col + colspan);
333
-
334
- if (colspan > 1) {
335
- // The current cell spans across multiple columns, this forwards to
336
- // the next cell for the next iteration.
337
- col += colspan - 1;
338
- }
339
-
340
- if (attrs.colwidth && compareNumbersList(attrs.colwidth, colwidth)) {
341
- continue;
342
- }
343
-
344
- tr = tr.setNodeMarkup(
345
- start + pos,
346
- null,
347
- setAttr(attrs, 'colwidth', colwidth)
348
- );
349
- }
350
- }
351
-
352
- const marginLeft = parseFloat(tableElement.style.marginLeft) || null;
353
- if (table.attrs.marginLeft !== marginLeft) {
354
- const nodeType = table.type;
355
- const attrs = {
356
- ...table.attrs,
357
- marginLeft,
358
- };
359
- const tableLookup = findParentNodeOfTypeClosestToPos(
360
- $cell,
361
- view.state.schema.nodes[nodeType.name]
362
- );
363
- const tablePos = nullthrows(tableLookup && tableLookup.pos);
364
- tr = tr.setNodeMarkup(tablePos, nodeType, attrs);
365
- }
366
-
367
- if (tr.docChanged) {
368
- // Let editor know the change.
369
- view.dispatch(tr);
370
- }
371
- // Hides the resize handle bars.
372
- view.dispatch(view.state.tr.setMeta(PLUGIN_KEY, { setDraggingInfo: null }));
373
- }
374
-
375
- // Helper that prepares the information needed before the resizing starts.
376
- function calculateDraggingInfo(
377
- view: EditorView,
378
- event: MouseEvent,
379
- resizeState: ResizeState
380
- ): ?DraggingInfo {
381
- const { cellPos, forMarginLeft } = resizeState;
382
- const dom = view.domAtPos(cellPos);
383
- const tableEl = dom.node.closest('table');
384
- const tableWrapper = tableEl.closest('.tableWrapper');
385
- const colGroupEl = tableEl.querySelector('colgroup');
386
- const colEls = colGroupEl
387
- ? Array.from(colGroupEl.querySelectorAll('col'))
388
- : [];
389
- const tableWrapperRect = tableWrapper.getBoundingClientRect();
390
- const tableRect = tableEl.getBoundingClientRect();
391
- const defaultColumnWidth = tableWrapperRect.width / colEls.length;
392
- const startX = event.clientX;
393
- const offsetLeft = startX - tableRect.left;
394
-
395
- let tableWidth = 0;
396
- let taregtColumnIndex = -1;
397
-
398
- const tableMarginLeftStyle = tableEl.style.marginLeft;
399
- const tableMarginLeft =
400
- tableMarginLeftStyle && /\d+px/.test(tableMarginLeftStyle)
401
- ? parseFloat(tableMarginLeftStyle)
402
- : 0;
403
-
404
- const tableMarginRight = tableWrapperRect.right - tableRect.right;
405
-
406
- // Calculate the inital width of each column.
407
- // Calculate the inital width of the table.
408
- // Find out the target column to resize.
409
- const columnWidths = Array.from(colEls).map((colEl, ii) => {
410
- const cssWidth = colEl.style.width;
411
- let colWidth = Math.max(
412
- CELL_MIN_WIDTH,
413
- (cssWidth && parseFloat(cssWidth)) || defaultColumnWidth
414
- );
415
-
416
- if (tableWidth + colWidth > tableWrapperRect.width) {
417
- // column is too wide, make it fit.
418
- // colWidth -= tableWrapperRect.width - (tableWidth + colWidth);
419
- // [FS] IRAD-993 2020-06-24
420
- // Fix:Table exceeds the canvas
421
- const tosub = Math.abs(tableWrapperRect.width - (tableWidth + colWidth));
422
- colWidth = colWidth - tosub;
423
- }
424
-
425
- // The edges of the column's right border.
426
- // [FS] IRAD-949 2020-05-27
427
- // Fix:Cell Resize Handler causes edit diificult to firsrst/last two chars in the cell.
428
- const edgeLeft = tableWidth + colWidth - HANDLE_RIGHT_WIDTH / 2;
429
- const edgeRight = tableWidth + colWidth + HANDLE_RIGHT_WIDTH / 2;
430
- if (offsetLeft >= edgeLeft && offsetLeft <= edgeRight) {
431
- // [FS] IRAD-993 2020-06-24
432
- // Fix:Table exceeds the canvas
433
- if (taregtColumnIndex === -1) {
434
- // This is the column to resize.
435
- taregtColumnIndex = ii;
436
- }
437
- }
438
- tableWidth += colWidth;
439
- return colWidth;
440
- });
441
-
442
- if (forMarginLeft) {
443
- // Both the first column and the table's left margin should resize.
444
- taregtColumnIndex = 0;
445
- }
446
-
447
- if (taregtColumnIndex < 0) {
448
- // Nothing to resize. This happens when the mouse isn't nearby any position
449
- // that is alllowed to resize a column.
450
- return null;
451
- }
452
-
453
- return {
454
- columnElements: colEls,
455
- taregtColumnIndex,
456
- columnWidths,
457
- startX,
458
- tableElement: tableEl,
459
- tableMarginLeft,
460
- tableMarginRight,
461
- tableWidth,
462
- tableWrapperWidth: tableWrapperRect.width,
463
- };
464
- }
465
-
466
- // Helper that finds the closest cell element from a given event target.
467
- function domCellAround(target: any): ?Element {
468
- while (target && target.nodeName !== 'TD' && target.nodeName !== 'TH') {
469
- target = target.classList.contains('ProseMirror')
470
- ? null
471
- : target.parentElement;
472
- }
473
- return target;
474
- }
475
-
476
- // Helper that resolves the prose-mirror node postion of a cell from a given
477
- // event target.
478
- function edgeCell(view: EditorView, event: PointerEvent, side: string): number {
479
- const { pos } = view.posAtCoords({ left: event.clientX, top: event.clientY });
480
- const $cell = cellAround(view.state.doc.resolve(pos));
481
- if (!$cell) {
482
- return -1;
483
- }
484
- if (side == 'right') {
485
- return $cell.pos;
486
- }
487
- const map = TableMap.get($cell.node(-1));
488
- const start = $cell.start(-1);
489
- const index = map.map.indexOf($cell.pos - start);
490
- return index % map.width == 0 ? -1 : start + map.map[index - 1];
491
- }
492
-
493
- // Update the resize handler (UI) state.
494
- function updateResizeHandle(
495
- view: EditorView,
496
- cellPos: number,
497
- forMarginLeft: boolean
498
- ): void {
499
- view.dispatch(
500
- view.state.tr.setMeta(PLUGIN_KEY, {
501
- setCellPos: cellPos,
502
- setForMarginLeft: forMarginLeft,
503
- })
504
- );
505
- }
506
-
507
- // Get the decorations that renders the resize handle bars.
508
- function handleDecorations(
509
- state: EditorState,
510
- resizeState: ResizeState
511
- ): DecorationSet {
512
- if (!resizeState.cellPos) {
513
- return DecorationSet.create(state.doc, []);
514
- }
515
- const decorations = [];
516
- const $cell = state.doc.resolve(resizeState.cellPos);
517
- const table = $cell.node(-1);
518
-
519
- const map = TableMap.get(table);
520
- const start = $cell.start(-1);
521
- const col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan;
522
- for (let row = 0; row < map.height; row++) {
523
- const index = col + row * map.width - 1;
524
- // For positions that are have either a different cell or the end
525
- // of the table to their right, and either the top of the table or
526
- // a different cell above them, add a decoration
527
- if (
528
- (col === map.width || map.map[index] !== map.map[index + 1]) &&
529
- (row === 0 || map.map[index - 1] !== map.map[index - 1 - map.width])
530
- ) {
531
- const cellPos = map.map[index];
532
- const pos = start + cellPos + table.nodeAt(cellPos).nodeSize - 1;
533
- const dom = document.createElement('div');
534
- let className = 'column-resize-handle';
535
- if (resizeState.forMarginLeft) {
536
- className += ' for-margin-left';
537
- }
538
- dom.className = className;
539
- decorations.push(Decoration.widget(pos, dom));
540
- }
541
- }
542
- return DecorationSet.create(state.doc, decorations);
543
- }
544
-
545
- // Creates a custom table view that renders the margin-left style.
546
- function createTableView(node: Node, view: EditorView): TableView {
547
- // [FS] IRAD-1008 2020-07-16
548
- // Does not allow Table cell Resize in disable mode
549
- isEnabled = view.editable;
550
- return new TableNodeView(node, CELL_MIN_WIDTH, view);
551
- }
552
-
553
- function batchMouseHandler(
554
- handler: (view: EditorView, pe: PointerEvent) => void
555
- ): (view: EditorView, me: MouseEvent) => void {
556
- let target: any = null;
557
- let clientX = 0;
558
- let clientY = 0;
559
- let view = null;
560
- const onMouseEvent = () => {
561
- if (view && target) {
562
- const pointerEvent: PointerEvent = {
563
- target,
564
- clientX,
565
- clientY,
566
- };
567
- handler(view, pointerEvent);
568
- }
569
- };
570
- return function (ev: EditorView, me: MouseEvent) {
571
- target = me.target;
572
- clientX = me.clientX;
573
- clientY = me.clientY;
574
- view = ev;
575
- requestAnimationFrame(onMouseEvent);
576
- };
577
- }
578
-
579
- function compareNumbersList(one: Array<number>, two: Array<number>): boolean {
580
- if (one.length !== two.length) {
581
- return false;
582
- }
583
-
584
- return !one.some((value, index) => two[index] !== value);
585
- }
586
-
587
- // Plugin that supports table columns resizing.
588
- export default class TableResizePlugin extends Plugin {
589
- // [FS] IRAD-1005 2020-07-07
590
- // Upgrade outdated packages.
591
- //spec: Object;
592
-
593
- constructor() {
594
- super({
595
- key: PLUGIN_KEY,
596
- state: {
597
- init(_: any, state: EditorState): ResizeState {
598
- this.spec.props.nodeViews[
599
- tableNodeTypes(state.schema).table.name
600
- ] = createTableView;
601
- return new ResizeState(-1, null);
602
- },
603
- apply(tr: Transform, prev: EditorState): EditorState {
604
- return prev.apply(tr);
605
- },
606
- },
607
- props: {
608
- attributes(state: EditorState): ?Object {
609
- const resizeState = PLUGIN_KEY.getState(state);
610
- return resizeState.cellPos > -1 ? { class: 'resize-cursor' } : null;
611
- },
612
- handleDOMEvents: {
613
- // Move events should be batched to avoid over-handling the mouse
614
- // event.
615
- mousemove: batchMouseHandler(handleMouseMove),
616
- mouseleave: handleMouseLeave,
617
- mousedown: handleMouseDown,
618
- },
619
- decorations(state: EditorState): ?DecorationSet {
620
- const resizeState = PLUGIN_KEY.getState(state);
621
- // [FS] IRAD-1008 2020-07-16
622
- // Does not allow Table cell Resize in disable mode
623
- return resizeState.cellPos > -1 && isEnabled
624
- ? handleDecorations(state, resizeState)
625
- : undefined;
626
- },
627
- nodeViews: {},
628
- },
629
- });
630
- }
631
- }
1
+ // @flow
2
+
3
+ // Copyright (C) 2015-2016 by Marijn Haverbeke <marijnh@gmail.com> and others
4
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ // of this software and associated documentation files (the "Software"), to deal
6
+ // in the Software without restriction, including without limitation the rights
7
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ // copies of the Software, and to permit persons to whom the Software is
9
+ // furnished to do so, subject to the following conditions:
10
+
11
+ // The above copyright notice and this permission notice shall be included in
12
+ // all copies or substantial portions of the Software.
13
+
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ // THE SOFTWARE.
21
+
22
+ // License about this file:
23
+ // This file is originally forked from
24
+ // https://github.com/ProseMirror/prosemirror-tables/blob/0e74c6a1761651ccf3701eb8529fa9187ad5c91d/src/columnresizing.js
25
+ // and most of the original codes had been modified to support the bevaviors
26
+ // that czi-prosemirror needs.
27
+ // The plugin provides the following behaviors:
28
+ // - Let user resize a column without changing the total width of the table.
29
+ // - Let user set the left margin of the table.
30
+ // - Let user set the right margin of the table.
31
+
32
+ import TableNodeView from './ui/TableNodeView';
33
+ import { Node } from 'prosemirror-model';
34
+ import { EditorState, Plugin, PluginKey } from 'prosemirror-state';
35
+ import { Transform } from 'prosemirror-transform';
36
+ import { Decoration, DecorationSet, EditorView } from 'prosemirror-view';
37
+ import { findParentNodeOfTypeClosestToPos } from 'prosemirror-utils';
38
+ import nullthrows from 'nullthrows';
39
+ import {
40
+ cellAround,
41
+ pointsAtCell,
42
+ setAttr,
43
+ tableNodeTypes,
44
+ TableMap,
45
+ TableView,
46
+ } from 'prosemirror-tables';
47
+
48
+ type DraggingInfo = {
49
+ columnElements: Array<HTMLElement>,
50
+ startX: number,
51
+ tableElement: HTMLElement,
52
+ tableMarginLeft: number,
53
+ tableMarginRight: number,
54
+ tableWidth: number,
55
+ tableWrapperWidth: number,
56
+ taregtColumnIndex: number,
57
+ };
58
+
59
+ type PointerEvent = {
60
+ target: null,
61
+ clientX: number,
62
+ clientY: number,
63
+ };
64
+
65
+ const PLUGIN_KEY = new PluginKey('tableColumnResizing');
66
+
67
+ // [FS] IRAD-949 2020-05-27
68
+ // Fix:Cell Resize Handler causes edit diificult to firsrst/last two chars in the cell.
69
+ // Rezie cursor position issue fixed.
70
+
71
+ const CELL_MIN_WIDTH = 30;
72
+ const HANDLE_WIDTH = 5;
73
+ const HANDLE_RIGHT_WIDTH = 20;
74
+
75
+ let cancelDrag: ?Function = null;
76
+ let isEnabled = true;
77
+
78
+ // The immutable plugin state that stores the information for resizing.
79
+ class ResizeState {
80
+ cellPos: ?number;
81
+ forMarginLeft: ?boolean;
82
+ draggingInfo: ?DraggingInfo;
83
+
84
+ constructor(
85
+ cellPos: ?number,
86
+ forMarginLeft: ?boolean,
87
+ draggingInfo: ?DraggingInfo
88
+ ) {
89
+ this.cellPos = cellPos;
90
+ this.draggingInfo = draggingInfo;
91
+ this.forMarginLeft = forMarginLeft;
92
+ }
93
+
94
+ apply(tr: Transform): ResizeState {
95
+ let state = this;
96
+ const action = tr.getMeta(PLUGIN_KEY);
97
+ if (action && typeof action.setCellPos === 'number') {
98
+ return new ResizeState(action.setCellPos, action.setForMarginLeft, null);
99
+ }
100
+
101
+ if (action && action.setDraggingInfo !== undefined) {
102
+ return new ResizeState(
103
+ state.cellPos,
104
+ state.forMarginLeft,
105
+ action.setDraggingInfo
106
+ );
107
+ }
108
+
109
+ if (state.cellPos && state.cellPos > -1 && tr.docChanged) {
110
+ let cellPos = tr.mapping.map(state.cellPos, -1);
111
+ if (!pointsAtCell(tr.doc.resolve(cellPos))) {
112
+ cellPos = null;
113
+ }
114
+ state = new ResizeState(
115
+ cellPos,
116
+ cellPos ? state.forMarginLeft : false,
117
+ state.draggingInfo
118
+ );
119
+ }
120
+ return state;
121
+ }
122
+ }
123
+
124
+ // Function that handles the mousemove event inside table cell.
125
+ function handleMouseMove(view: EditorView, event: PointerEvent): void {
126
+ const resizeState = PLUGIN_KEY.getState(view.state);
127
+ if (resizeState.draggingInfo) {
128
+ return;
129
+ }
130
+
131
+ const target = domCellAround(event.target);
132
+ let forMarginLeft = false;
133
+ let cell = -1;
134
+
135
+ if (target instanceof HTMLTableCellElement) {
136
+ const { left, right } = target.getBoundingClientRect();
137
+ const offsetLeft = event.clientX - left;
138
+ // [FS] IRAD-949 2020-05-27
139
+ // Fix:Cell Resize Handler causes edit diificult to firsrst/last two chars in the cell.
140
+ // Rezie cursor position issue fixed.
141
+ if (offsetLeft <= HANDLE_WIDTH) {
142
+ if (target.cellIndex === 0) {
143
+ forMarginLeft = true;
144
+ cell = edgeCell(view, event, 'right');
145
+ } else {
146
+ cell = edgeCell(view, event, 'left');
147
+ }
148
+ } else if (right - event.clientX <= HANDLE_WIDTH) {
149
+ cell = edgeCell(view, event, 'right');
150
+ }
151
+ }
152
+
153
+ if (
154
+ cell === resizeState.cellPos &&
155
+ forMarginLeft === resizeState.forMarginLeft
156
+ ) {
157
+ return;
158
+ }
159
+
160
+ if (cell !== -1) {
161
+ const $cell = view.state.doc.resolve(cell);
162
+ if (!$cell) {
163
+ return;
164
+ }
165
+ }
166
+ updateResizeHandle(view, cell, forMarginLeft);
167
+ }
168
+
169
+ // Function that handles the mouseleave event from the table cell.
170
+ function handleMouseLeave(view: EditorView): void {
171
+ const resizeState = PLUGIN_KEY.getState(view.state);
172
+ const { cellPos, draggingInfo } = resizeState;
173
+ if (cellPos > -1 && !draggingInfo) {
174
+ updateResizeHandle(view, -1, false);
175
+ }
176
+ }
177
+
178
+ // Function that handles the mousedown event from the table cell.
179
+ function handleMouseDown(view: EditorView, event: MouseEvent): boolean {
180
+ // It's possible that the resize action that happened earlier was inturrupted
181
+ // while its dependent mouse events were stopped or prevented by others.
182
+ // We need to stop the previous resize action if it did not finish.
183
+ cancelDrag && cancelDrag(event);
184
+
185
+ const resizeState = PLUGIN_KEY.getState(view.state);
186
+ if (resizeState.cellPos === -1 || resizeState.draggingInfo) {
187
+ return false;
188
+ }
189
+
190
+ let dragStarted = false;
191
+ let dragMoveHandler = null;
192
+
193
+ const finish = (event: MouseEvent) => {
194
+ window.removeEventListener('mouseup', finish, true);
195
+ window.removeEventListener('mousemove', this.move, true);
196
+ dragStarted && handleDragEnd(view, event);
197
+ cancelDrag = null;
198
+ };
199
+
200
+ const move = (event: any) => {
201
+ if (event.which) {
202
+ if (!dragStarted) {
203
+ handleDragStart(view, event);
204
+ dragStarted = true;
205
+ }
206
+ // Move events should be batched to avoid over-handling the mouse
207
+ // event.
208
+ dragMoveHandler = dragMoveHandler || batchMouseHandler(handleDragMove);
209
+ dragMoveHandler(view, event);
210
+ } else {
211
+ finish(event);
212
+ }
213
+ };
214
+
215
+ cancelDrag = finish;
216
+ window.addEventListener('mouseup', finish, true);
217
+ window.addEventListener('mousemove', move, true);
218
+ event.preventDefault();
219
+ return true;
220
+ }
221
+
222
+ function handleDragStart(view: EditorView, event: MouseEvent): void {
223
+ const resizeState = PLUGIN_KEY.getState(view.state);
224
+ if (resizeState.cellPos === -1 || resizeState.draggingInfo) {
225
+ return;
226
+ }
227
+
228
+ view.dispatch(
229
+ view.state.tr.setMeta(PLUGIN_KEY, {
230
+ setDraggingInfo: calculateDraggingInfo(view, event, resizeState),
231
+ })
232
+ );
233
+ }
234
+
235
+ // Function that handles the mouse event while resizing the table cell.
236
+ // This will temporarily updates the table's style until the resize ends.
237
+ function handleDragMove(view: EditorView, event: PointerEvent): void {
238
+ const resizeState = PLUGIN_KEY.getState(view.state);
239
+ const { draggingInfo, forMarginLeft } = resizeState;
240
+ if (!draggingInfo) {
241
+ return;
242
+ }
243
+ const {
244
+ startX,
245
+ columnWidths,
246
+ taregtColumnIndex,
247
+ columnElements,
248
+ tableElement,
249
+ tableMarginLeft,
250
+ tableMarginRight,
251
+ } = draggingInfo;
252
+
253
+ let totalWidth = 0;
254
+ let ml = tableMarginLeft;
255
+
256
+ const dx = event.clientX - startX;
257
+ const lastIndex = columnWidths.length - 1;
258
+ const widths = columnWidths.map((cw, index) => {
259
+ let ww;
260
+ if (forMarginLeft) {
261
+ if (index === 0) {
262
+ // Resize the first column.
263
+ ww = Math.min(Math.max(CELL_MIN_WIDTH, cw - dx), cw + tableMarginLeft);
264
+ // Resize table's left margin.
265
+ ml = Math.max(0, tableMarginLeft + cw - ww);
266
+ } else {
267
+ // The rest columns remain the same,
268
+ ww = cw;
269
+ }
270
+ } else if (index === taregtColumnIndex && index === lastIndex) {
271
+ // Resize the last column.
272
+ ww = Math.min(cw + tableMarginRight, Math.max(CELL_MIN_WIDTH, cw + dx));
273
+ } else if (index === taregtColumnIndex) {
274
+ // Resize the column.
275
+ ww = Math.min(
276
+ Math.max(CELL_MIN_WIDTH, cw + dx),
277
+ cw + (columnWidths[index + 1] || 0) - CELL_MIN_WIDTH
278
+ );
279
+ } else if (index === taregtColumnIndex + 1) {
280
+ // Resize the column's previous column.
281
+ ww = Math.min(
282
+ Math.max(CELL_MIN_WIDTH, cw - dx),
283
+ cw + (columnWidths[index - 1] || 0) - CELL_MIN_WIDTH
284
+ );
285
+ } else {
286
+ // This column does not resize.
287
+ ww = cw;
288
+ }
289
+
290
+ totalWidth += ww;
291
+ return ww;
292
+ });
293
+
294
+ const tableElementStyle = tableElement.style;
295
+ tableElementStyle.marginLeft = `${ml}px`;
296
+ // [FS] IRAD-993 2020-06-26
297
+ // Fix:Table exceeds the canvas
298
+ tableElementStyle.width = Math.round(totalWidth - ml) + 'px';
299
+ tableElementStyle.minWidth = '';
300
+ columnElements.forEach((colEl, index) => {
301
+ colEl.style.width = Math.round(widths[index]) + 'px';
302
+ });
303
+ }
304
+
305
+ // Function that handles the mouse event while stop resizing the table cell.
306
+ function handleDragEnd(view: EditorView, event: any): void {
307
+ const resizeState = PLUGIN_KEY.getState(view.state);
308
+ const { cellPos, draggingInfo } = resizeState;
309
+ if (!draggingInfo) {
310
+ return;
311
+ }
312
+ const { columnElements, tableElement } = draggingInfo;
313
+ const widths = columnElements.map((colEl) => {
314
+ return parseFloat(colEl.style.width);
315
+ });
316
+
317
+ const $cell = view.state.doc.resolve(cellPos);
318
+ const start = $cell.start(-1);
319
+ const table = $cell.node(-1);
320
+ const map = TableMap.get(table);
321
+ let tr = view.state.tr;
322
+ for (let row = 0; row < map.height; row++) {
323
+ for (let col = 0; col < widths.length; col++) {
324
+ const mapIndex = row * map.width + col;
325
+ if (row && map.map[mapIndex] == map.map[mapIndex - map.width]) {
326
+ // Rowspanning cell that has already been handled
327
+ continue;
328
+ }
329
+ const pos = map.map[mapIndex];
330
+ const { attrs } = table.nodeAt(pos);
331
+ const colspan = attrs.colspan || 1;
332
+ const colwidth = widths.slice(col, col + colspan);
333
+
334
+ if (colspan > 1) {
335
+ // The current cell spans across multiple columns, this forwards to
336
+ // the next cell for the next iteration.
337
+ col += colspan - 1;
338
+ }
339
+
340
+ if (attrs.colwidth && compareNumbersList(attrs.colwidth, colwidth)) {
341
+ continue;
342
+ }
343
+
344
+ tr = tr.setNodeMarkup(
345
+ start + pos,
346
+ null,
347
+ setAttr(attrs, 'colwidth', colwidth)
348
+ );
349
+ }
350
+ }
351
+
352
+ const marginLeft = parseFloat(tableElement.style.marginLeft) || null;
353
+ if (table.attrs.marginLeft !== marginLeft) {
354
+ const nodeType = table.type;
355
+ const attrs = {
356
+ ...table.attrs,
357
+ marginLeft,
358
+ };
359
+ const tableLookup = findParentNodeOfTypeClosestToPos(
360
+ $cell,
361
+ view.state.schema.nodes[nodeType.name]
362
+ );
363
+ const tablePos = nullthrows(tableLookup && tableLookup.pos);
364
+ tr = tr.setNodeMarkup(tablePos, nodeType, attrs);
365
+ }
366
+
367
+ if (tr.docChanged) {
368
+ // Let editor know the change.
369
+ view.dispatch(tr);
370
+ }
371
+ // Hides the resize handle bars.
372
+ view.dispatch(view.state.tr.setMeta(PLUGIN_KEY, { setDraggingInfo: null }));
373
+ }
374
+
375
+ // Helper that prepares the information needed before the resizing starts.
376
+ function calculateDraggingInfo(
377
+ view: EditorView,
378
+ event: MouseEvent,
379
+ resizeState: ResizeState
380
+ ): ?DraggingInfo {
381
+ const { cellPos, forMarginLeft } = resizeState;
382
+ const dom = view.domAtPos(cellPos);
383
+ const tableEl = dom.node.closest('table');
384
+ const tableWrapper = tableEl.closest('.tableWrapper');
385
+ const colGroupEl = tableEl.querySelector('colgroup');
386
+ const colEls = colGroupEl
387
+ ? Array.from(colGroupEl.querySelectorAll('col'))
388
+ : [];
389
+ const tableWrapperRect = tableWrapper.getBoundingClientRect();
390
+ const tableRect = tableEl.getBoundingClientRect();
391
+ const defaultColumnWidth = tableWrapperRect.width / colEls.length;
392
+ const startX = event.clientX;
393
+ const offsetLeft = startX - tableRect.left;
394
+
395
+ let tableWidth = 0;
396
+ let taregtColumnIndex = -1;
397
+
398
+ const tableMarginLeftStyle = tableEl.style.marginLeft;
399
+ const tableMarginLeft =
400
+ tableMarginLeftStyle && /\d+px/.test(tableMarginLeftStyle)
401
+ ? parseFloat(tableMarginLeftStyle)
402
+ : 0;
403
+
404
+ const tableMarginRight = tableWrapperRect.right - tableRect.right;
405
+
406
+ // Calculate the inital width of each column.
407
+ // Calculate the inital width of the table.
408
+ // Find out the target column to resize.
409
+ const columnWidths = Array.from(colEls).map((colEl, ii) => {
410
+ const cssWidth = colEl.style.width;
411
+ let colWidth = Math.max(
412
+ CELL_MIN_WIDTH,
413
+ (cssWidth && parseFloat(cssWidth)) || defaultColumnWidth
414
+ );
415
+
416
+ if (tableWidth + colWidth > tableWrapperRect.width) {
417
+ // column is too wide, make it fit.
418
+ // colWidth -= tableWrapperRect.width - (tableWidth + colWidth);
419
+ // [FS] IRAD-993 2020-06-24
420
+ // Fix:Table exceeds the canvas
421
+ const tosub = Math.abs(tableWrapperRect.width - (tableWidth + colWidth));
422
+ colWidth = colWidth - tosub;
423
+ }
424
+
425
+ // The edges of the column's right border.
426
+ // [FS] IRAD-949 2020-05-27
427
+ // Fix:Cell Resize Handler causes edit diificult to firsrst/last two chars in the cell.
428
+ const edgeLeft = tableWidth + colWidth - HANDLE_RIGHT_WIDTH / 2;
429
+ const edgeRight = tableWidth + colWidth + HANDLE_RIGHT_WIDTH / 2;
430
+ if (offsetLeft >= edgeLeft && offsetLeft <= edgeRight) {
431
+ // [FS] IRAD-993 2020-06-24
432
+ // Fix:Table exceeds the canvas
433
+ if (taregtColumnIndex === -1) {
434
+ // This is the column to resize.
435
+ taregtColumnIndex = ii;
436
+ }
437
+ }
438
+ tableWidth += colWidth;
439
+ return colWidth;
440
+ });
441
+
442
+ if (forMarginLeft) {
443
+ // Both the first column and the table's left margin should resize.
444
+ taregtColumnIndex = 0;
445
+ }
446
+
447
+ if (taregtColumnIndex < 0) {
448
+ // Nothing to resize. This happens when the mouse isn't nearby any position
449
+ // that is alllowed to resize a column.
450
+ return null;
451
+ }
452
+
453
+ return {
454
+ columnElements: colEls,
455
+ taregtColumnIndex,
456
+ columnWidths,
457
+ startX,
458
+ tableElement: tableEl,
459
+ tableMarginLeft,
460
+ tableMarginRight,
461
+ tableWidth,
462
+ tableWrapperWidth: tableWrapperRect.width,
463
+ };
464
+ }
465
+
466
+ // Helper that finds the closest cell element from a given event target.
467
+ function domCellAround(target: any): ?Element {
468
+ while (target && target.nodeName !== 'TD' && target.nodeName !== 'TH') {
469
+ target = target.classList.contains('ProseMirror')
470
+ ? null
471
+ : target.parentElement;
472
+ }
473
+ return target;
474
+ }
475
+
476
+ // Helper that resolves the prose-mirror node postion of a cell from a given
477
+ // event target.
478
+ function edgeCell(view: EditorView, event: PointerEvent, side: string): number {
479
+ const { pos } = view.posAtCoords({ left: event.clientX, top: event.clientY });
480
+ const $cell = cellAround(view.state.doc.resolve(pos));
481
+ if (!$cell) {
482
+ return -1;
483
+ }
484
+ if (side == 'right') {
485
+ return $cell.pos;
486
+ }
487
+ const map = TableMap.get($cell.node(-1));
488
+ const start = $cell.start(-1);
489
+ const index = map.map.indexOf($cell.pos - start);
490
+ return index % map.width == 0 ? -1 : start + map.map[index - 1];
491
+ }
492
+
493
+ // Update the resize handler (UI) state.
494
+ function updateResizeHandle(
495
+ view: EditorView,
496
+ cellPos: number,
497
+ forMarginLeft: boolean
498
+ ): void {
499
+ view.dispatch(
500
+ view.state.tr.setMeta(PLUGIN_KEY, {
501
+ setCellPos: cellPos,
502
+ setForMarginLeft: forMarginLeft,
503
+ })
504
+ );
505
+ }
506
+
507
+ // Get the decorations that renders the resize handle bars.
508
+ function handleDecorations(
509
+ state: EditorState,
510
+ resizeState: ResizeState
511
+ ): DecorationSet {
512
+ if (!resizeState.cellPos) {
513
+ return DecorationSet.create(state.doc, []);
514
+ }
515
+ const decorations = [];
516
+ const $cell = state.doc.resolve(resizeState.cellPos);
517
+ const table = $cell.node(-1);
518
+
519
+ const map = TableMap.get(table);
520
+ const start = $cell.start(-1);
521
+ const col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan;
522
+ for (let row = 0; row < map.height; row++) {
523
+ const index = col + row * map.width - 1;
524
+ // For positions that are have either a different cell or the end
525
+ // of the table to their right, and either the top of the table or
526
+ // a different cell above them, add a decoration
527
+ if (
528
+ (col === map.width || map.map[index] !== map.map[index + 1]) &&
529
+ (row === 0 || map.map[index - 1] !== map.map[index - 1 - map.width])
530
+ ) {
531
+ const cellPos = map.map[index];
532
+ const pos = start + cellPos + table.nodeAt(cellPos).nodeSize - 1;
533
+ const dom = document.createElement('div');
534
+ let className = 'column-resize-handle';
535
+ if (resizeState.forMarginLeft) {
536
+ className += ' for-margin-left';
537
+ }
538
+ dom.className = className;
539
+ decorations.push(Decoration.widget(pos, dom));
540
+ }
541
+ }
542
+ return DecorationSet.create(state.doc, decorations);
543
+ }
544
+
545
+ // Creates a custom table view that renders the margin-left style.
546
+ function createTableView(node: Node, view: EditorView): TableView {
547
+ // [FS] IRAD-1008 2020-07-16
548
+ // Does not allow Table cell Resize in disable mode
549
+ isEnabled = view.editable;
550
+ return new TableNodeView(node, CELL_MIN_WIDTH, view);
551
+ }
552
+
553
+ function batchMouseHandler(
554
+ handler: (view: EditorView, pe: PointerEvent) => void
555
+ ): (view: EditorView, me: MouseEvent) => void {
556
+ let target: any = null;
557
+ let clientX = 0;
558
+ let clientY = 0;
559
+ let view = null;
560
+ const onMouseEvent = () => {
561
+ if (view && target) {
562
+ const pointerEvent: PointerEvent = {
563
+ target,
564
+ clientX,
565
+ clientY,
566
+ };
567
+ handler(view, pointerEvent);
568
+ }
569
+ };
570
+ return function (ev: EditorView, me: MouseEvent) {
571
+ target = me.target;
572
+ clientX = me.clientX;
573
+ clientY = me.clientY;
574
+ view = ev;
575
+ requestAnimationFrame(onMouseEvent);
576
+ };
577
+ }
578
+
579
+ function compareNumbersList(one: Array<number>, two: Array<number>): boolean {
580
+ if (one.length !== two.length) {
581
+ return false;
582
+ }
583
+
584
+ return !one.some((value, index) => two[index] !== value);
585
+ }
586
+
587
+ // Plugin that supports table columns resizing.
588
+ export default class TableResizePlugin extends Plugin {
589
+ // [FS] IRAD-1005 2020-07-07
590
+ // Upgrade outdated packages.
591
+ //spec: Object;
592
+
593
+ constructor() {
594
+ super({
595
+ key: PLUGIN_KEY,
596
+ state: {
597
+ init(_: any, state: EditorState): ResizeState {
598
+ this.spec.props.nodeViews[
599
+ tableNodeTypes(state.schema).table.name
600
+ ] = createTableView;
601
+ return new ResizeState(-1, null);
602
+ },
603
+ apply(tr: Transform, prev: EditorState): EditorState {
604
+ return prev.apply(tr);
605
+ },
606
+ },
607
+ props: {
608
+ attributes(state: EditorState): ?Object {
609
+ const resizeState = PLUGIN_KEY.getState(state);
610
+ return resizeState.cellPos > -1 ? { class: 'resize-cursor' } : null;
611
+ },
612
+ handleDOMEvents: {
613
+ // Move events should be batched to avoid over-handling the mouse
614
+ // event.
615
+ mousemove: batchMouseHandler(handleMouseMove),
616
+ mouseleave: handleMouseLeave,
617
+ mousedown: handleMouseDown,
618
+ },
619
+ decorations(state: EditorState): ?DecorationSet {
620
+ const resizeState = PLUGIN_KEY.getState(state);
621
+ // [FS] IRAD-1008 2020-07-16
622
+ // Does not allow Table cell Resize in disable mode
623
+ return resizeState.cellPos > -1 && isEnabled
624
+ ? handleDecorations(state, resizeState)
625
+ : undefined;
626
+ },
627
+ nodeViews: {},
628
+ },
629
+ });
630
+ }
631
+ }