@seafile/seafile-editor 0.4.7 → 1.0.0

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 (443) hide show
  1. package/.babelrc +5 -0
  2. package/.eslintignore +19 -0
  3. package/.eslintrc.json +52 -0
  4. package/.github/workflows/nodejs.yml +25 -0
  5. package/.vscode/settings.json +5 -0
  6. package/config/config.common.js +157 -0
  7. package/config/config.dev.js +53 -0
  8. package/config/jest/cssTransform.js +16 -0
  9. package/config/jest/fileTransform.js +40 -0
  10. package/config/utils/theme.css.js +103 -0
  11. package/config.js +61 -0
  12. package/dev-server.js +145 -0
  13. package/jest.config.js +16 -0
  14. package/package.json +81 -132
  15. package/public/locales/en/seafile-editor.json +145 -148
  16. package/public/locales/zh-CN/seafile-editor.json +123 -135
  17. package/public/media/seafile-ui.css +6 -11166
  18. package/scripts/ejs.js +16 -0
  19. package/site/_i18n/index.js +35 -0
  20. package/site/api/index.js +212 -0
  21. package/site/app.js +21 -0
  22. package/site/assets/css/app.css +47 -0
  23. package/site/assets/css/seafile-editor.css +33 -0
  24. package/site/commons/loading/index.js +14 -0
  25. package/site/commons/loading/style.css +49 -0
  26. package/site/commons/switch/index.css +14 -0
  27. package/site/commons/switch/index.js +37 -0
  28. package/site/commons/toast/alert.js +106 -0
  29. package/site/commons/toast/index.js +5 -0
  30. package/site/commons/toast/toast.js +195 -0
  31. package/site/commons/toast/toastManager.js +138 -0
  32. package/site/commons/toast/toaster.js +64 -0
  33. package/site/index.html +23 -0
  34. package/site/index.js +21 -0
  35. package/site/pages/home.js +21 -0
  36. package/site/pages/plain-markdown-view.js +6 -0
  37. package/site/pages/rich-seafile-editor.js +72 -0
  38. package/site/pages/seafile-editor.js +39 -0
  39. package/site/pages/seafile-viewer.js +45 -0
  40. package/site/pages/simple-editor.js +44 -0
  41. package/site/pages/wiki-viewer.js +7 -0
  42. package/site/setting.js +36 -0
  43. package/site/setting.local.dist.js +23 -0
  44. package/src/assets/css/slate-editor.css +57 -0
  45. package/src/constants/event-types.js +11 -0
  46. package/src/constants/hot-keys.js +47 -0
  47. package/src/containers/article-info/index.js +49 -0
  48. package/src/containers/article-info/style.css +52 -0
  49. package/src/containers/custom/get-event-transfer.js +28 -0
  50. package/{dist → src}/containers/custom/set-event-transfer.js +13 -11
  51. package/src/containers/hotkeys-helper/classify-hotkeys.js +30 -0
  52. package/src/containers/hotkeys-helper/index.js +43 -0
  53. package/{dist/assets/css/user-help.css → src/containers/hotkeys-helper/style.css} +37 -29
  54. package/src/containers/loading/index.js +14 -0
  55. package/src/containers/loading/style.css +49 -0
  56. package/src/containers/outline/index.js +75 -0
  57. package/src/containers/outline/outline-item.js +28 -0
  58. package/src/containers/outline/style.css +45 -0
  59. package/src/editors/plain-markdown-editor/code-mirror.css +8 -0
  60. package/src/editors/plain-markdown-editor/code-mirror.js +73 -0
  61. package/src/editors/plain-markdown-editor/index.js +136 -0
  62. package/{dist/assets/editor/plain-editor.css → src/editors/plain-markdown-editor/style.css} +12 -4
  63. package/src/editors/simple-slate-editor /index.js +71 -0
  64. package/src/editors/simple-slate-editor /with-props-editor.js +15 -0
  65. package/src/editors/slate-editor/editor-help/index.js +46 -0
  66. package/src/editors/slate-editor/editor-help/style.css +15 -0
  67. package/src/editors/slate-editor/index.js +77 -0
  68. package/src/editors/slate-editor/with-props-editor.js +15 -0
  69. package/src/editors/slate-viewer/index.js +35 -0
  70. package/src/editors/slate-viewer/style.css +40 -0
  71. package/src/extension/commons/element-popover/index.js +52 -0
  72. package/src/extension/commons/index.js +10 -0
  73. package/src/extension/commons/menu/index.js +9 -0
  74. package/src/extension/commons/menu/menu-drop-down.js +110 -0
  75. package/src/extension/commons/menu/menu-group.js +20 -0
  76. package/src/extension/commons/menu/menu-item.js +60 -0
  77. package/src/extension/commons/menu/menu.css +120 -0
  78. package/src/extension/commons/tooltip/index.css +21 -0
  79. package/src/extension/commons/tooltip/index.js +26 -0
  80. package/src/extension/constants/element-types.js +23 -0
  81. package/src/extension/constants/index.js +37 -0
  82. package/src/extension/constants/keyboard.js +29 -0
  83. package/src/extension/constants/menus-config.js +149 -0
  84. package/src/extension/core/index.js +3 -0
  85. package/src/extension/core/queries/index.js +410 -0
  86. package/src/extension/core/transforms/focus-editor.js +12 -0
  87. package/src/extension/core/transforms/index.js +4 -0
  88. package/src/extension/core/transforms/move-children.js +23 -0
  89. package/src/extension/core/transforms/remove-node-children.js +8 -0
  90. package/src/extension/core/transforms/replace-node-children.js +14 -0
  91. package/src/extension/core/utils/index.js +76 -0
  92. package/src/extension/editor.js +14 -0
  93. package/src/extension/index.js +15 -0
  94. package/src/extension/plugins/blockquote/helpers.js +65 -0
  95. package/src/extension/plugins/blockquote/index.js +13 -0
  96. package/src/extension/plugins/blockquote/menu/index.js +31 -0
  97. package/src/extension/plugins/blockquote/plugin.js +64 -0
  98. package/src/extension/plugins/blockquote/render-elem.js +9 -0
  99. package/src/extension/plugins/check-list/helper.js +34 -0
  100. package/src/extension/plugins/check-list/index.js +14 -0
  101. package/src/extension/plugins/check-list/menu/index.js +44 -0
  102. package/src/extension/plugins/check-list/plugin.js +46 -0
  103. package/src/extension/plugins/check-list/render-elem.js +23 -0
  104. package/src/extension/plugins/clear-format/helpers.js +48 -0
  105. package/src/extension/plugins/clear-format/menu/index.js +39 -0
  106. package/src/extension/plugins/code-block/helpers.js +107 -0
  107. package/src/extension/plugins/code-block/index.js +14 -0
  108. package/src/extension/plugins/code-block/menu/index.js +40 -0
  109. package/src/extension/plugins/code-block/plugin.js +210 -0
  110. package/src/extension/plugins/code-block/render-elem/constant.js +17 -0
  111. package/src/extension/plugins/code-block/render-elem/index.js +55 -0
  112. package/src/extension/plugins/code-block/render-elem/language-selector.js +38 -0
  113. package/src/extension/plugins/code-block/render-elem/style.css +27 -0
  114. package/src/extension/plugins/formula/formula.css +22 -0
  115. package/src/extension/plugins/formula/helper.js +68 -0
  116. package/src/extension/plugins/formula/index.js +14 -0
  117. package/src/extension/plugins/formula/menu/formula-modal.js +73 -0
  118. package/src/extension/plugins/formula/menu/index.js +63 -0
  119. package/src/extension/plugins/formula/plugin.js +18 -0
  120. package/src/extension/plugins/formula/render-elem.js +40 -0
  121. package/src/extension/plugins/header/helper.js +47 -0
  122. package/src/extension/plugins/header/index.js +14 -0
  123. package/src/extension/plugins/header/menu/index.js +114 -0
  124. package/src/extension/plugins/header/menu/style.css +115 -0
  125. package/src/extension/plugins/header/plugin.js +134 -0
  126. package/src/extension/plugins/header/render-elem.js +31 -0
  127. package/src/extension/plugins/image/helper.js +50 -0
  128. package/src/extension/plugins/image/index.js +14 -0
  129. package/src/extension/plugins/image/menu/image-menu-dialog.js +68 -0
  130. package/src/extension/plugins/image/menu/image-menu-popover.js +76 -0
  131. package/src/extension/plugins/image/menu/index.js +61 -0
  132. package/src/extension/plugins/image/menu/style.css +36 -0
  133. package/src/extension/plugins/image/plugin.js +23 -0
  134. package/src/extension/plugins/image/render-element/image-previewer.js +71 -0
  135. package/src/extension/plugins/image/render-element/index.js +94 -0
  136. package/src/extension/plugins/image/render-element/style.css +60 -0
  137. package/src/extension/plugins/index.js +47 -0
  138. package/src/extension/plugins/link/helper.js +161 -0
  139. package/src/extension/plugins/link/index.js +14 -0
  140. package/src/extension/plugins/link/menu/index.js +82 -0
  141. package/src/extension/plugins/link/menu/link-modal.js +135 -0
  142. package/src/extension/plugins/link/plugin.js +85 -0
  143. package/src/extension/plugins/link/render-elem/index.js +69 -0
  144. package/src/extension/plugins/link/render-elem/link-popover.js +79 -0
  145. package/src/extension/plugins/link/render-elem/style.css +60 -0
  146. package/src/extension/plugins/list/constant.js +3 -0
  147. package/src/extension/plugins/list/helpers.js +53 -0
  148. package/src/extension/plugins/list/index.js +14 -0
  149. package/src/extension/plugins/list/menu/index.js +48 -0
  150. package/src/extension/plugins/list/plugin/index.js +48 -0
  151. package/src/extension/plugins/list/plugin/insert-break-list.js +25 -0
  152. package/src/extension/plugins/list/plugin/insert-fragment-list.js +162 -0
  153. package/src/extension/plugins/list/plugin/normalize-list.js +64 -0
  154. package/src/extension/plugins/list/plugin/on-tab-handle.js +34 -0
  155. package/src/extension/plugins/list/queries/index.js +39 -0
  156. package/src/extension/plugins/list/render-elem/index.js +26 -0
  157. package/src/extension/plugins/list/render-elem/style.css +6 -0
  158. package/src/extension/plugins/list/transforms/index.js +23 -0
  159. package/src/extension/plugins/list/transforms/insert-list-item.js +65 -0
  160. package/src/extension/plugins/list/transforms/move-list-item-down.js +40 -0
  161. package/src/extension/plugins/list/transforms/move-list-item-up.js +105 -0
  162. package/src/extension/plugins/list/transforms/move-list-items-to-list.js +58 -0
  163. package/src/extension/plugins/list/transforms/move-list-items.js +76 -0
  164. package/src/extension/plugins/list/transforms/normalize-list-item.js +92 -0
  165. package/src/extension/plugins/list/transforms/normalize-nested-list.js +31 -0
  166. package/src/extension/plugins/list/transforms/remove-first-list-item.js +11 -0
  167. package/src/extension/plugins/list/transforms/transforms-to-list.js +91 -0
  168. package/src/extension/plugins/list/transforms/unwrap-list.js +44 -0
  169. package/src/extension/plugins/node-id/constants.js +18 -0
  170. package/src/extension/plugins/node-id/helpers.js +61 -0
  171. package/src/extension/plugins/node-id/index.js +7 -0
  172. package/src/extension/plugins/node-id/with-node-id.js +37 -0
  173. package/src/extension/plugins/paragraph/helper.js +9 -0
  174. package/src/extension/plugins/paragraph/index.js +12 -0
  175. package/src/extension/plugins/paragraph/plugin.js +40 -0
  176. package/src/extension/plugins/paragraph/render-elem.js +11 -0
  177. package/src/extension/plugins/table/constant.js +3 -0
  178. package/src/extension/plugins/table/helper.js +175 -0
  179. package/src/extension/plugins/table/index.js +15 -0
  180. package/src/extension/plugins/table/menu/index.js +69 -0
  181. package/src/extension/plugins/table/menu/style.css +32 -0
  182. package/src/extension/plugins/table/menu/table-operator.js +101 -0
  183. package/src/extension/plugins/table/menu/table-size-selector.js +71 -0
  184. package/src/extension/plugins/table/model.js +69 -0
  185. package/src/extension/plugins/table/plugin.js +159 -0
  186. package/src/extension/plugins/table/render-elem/context-menu.js +78 -0
  187. package/src/extension/plugins/table/render-elem/index.js +157 -0
  188. package/src/extension/plugins/table/render-elem/style.css +94 -0
  189. package/src/extension/plugins/table/table-operations.js +162 -0
  190. package/src/extension/plugins/text-style/helpers.js +38 -0
  191. package/src/extension/plugins/text-style/index.js +12 -0
  192. package/src/extension/plugins/text-style/menu/index.js +41 -0
  193. package/src/extension/plugins/text-style/plugin.js +37 -0
  194. package/src/extension/plugins/text-style/render-elem.js +45 -0
  195. package/src/extension/render/render-element.js +82 -0
  196. package/src/extension/render/render-leaf.js +16 -0
  197. package/src/extension/toolbar/header-toolbar/index.js +129 -0
  198. package/src/extension/toolbar/header-toolbar/style.css +41 -0
  199. package/src/extension/toolbar/index.js +5 -0
  200. package/src/extension/toolbar/user-help/shortcut-dialog.js +144 -0
  201. package/src/hooks/use-mathjax.js +44 -0
  202. package/src/hooks/use-scroll-context.js +14 -0
  203. package/src/hooks/use-selection-update.js +14 -0
  204. package/src/index.js +22 -0
  205. package/src/pages/markdown-editor.js +53 -0
  206. package/src/pages/markdown-view.js +36 -0
  207. package/src/pages/rich-markdown-editor.js +95 -0
  208. package/src/pages/simple-editor.js +52 -0
  209. package/src/slate-convert/html-to-slate/constants.js +54 -0
  210. package/src/slate-convert/html-to-slate/helper.js +22 -0
  211. package/src/slate-convert/html-to-slate/index.js +144 -0
  212. package/src/slate-convert/html-to-slate/rules/blockquote.js +16 -0
  213. package/src/slate-convert/html-to-slate/rules/check-list.js +22 -0
  214. package/src/slate-convert/html-to-slate/rules/code-block.js +91 -0
  215. package/src/slate-convert/html-to-slate/rules/header.js +18 -0
  216. package/src/slate-convert/html-to-slate/rules/image.js +18 -0
  217. package/src/slate-convert/html-to-slate/rules/index.js +23 -0
  218. package/src/slate-convert/html-to-slate/rules/link.js +24 -0
  219. package/src/slate-convert/html-to-slate/rules/list.js +52 -0
  220. package/src/slate-convert/html-to-slate/rules/paragraph.js +16 -0
  221. package/src/slate-convert/html-to-slate/rules/table.js +37 -0
  222. package/src/slate-convert/html-to-slate/rules/text.js +63 -0
  223. package/src/slate-convert/index.js +11 -0
  224. package/src/slate-convert/md-to-html/index.js +44 -0
  225. package/src/slate-convert/md-to-html/sanitize-schema.js +41 -0
  226. package/src/slate-convert/md-to-slate/index.js +42 -0
  227. package/src/slate-convert/md-to-slate/transform.js +336 -0
  228. package/src/slate-convert/slate-to-md/index.js +44 -0
  229. package/src/slate-convert/slate-to-md/transform.js +248 -0
  230. package/src/utils/common.js +30 -0
  231. package/src/utils/deserialize-html.js +174 -0
  232. package/src/utils/dom-utils.js +45 -0
  233. package/src/utils/event-bus.js +37 -0
  234. package/src/utils/event-handler.js +36 -0
  235. package/src/utils/object-utils.js +51 -0
  236. package/tests/core/constants/index.js +54 -0
  237. package/tests/core/index.js +11 -0
  238. package/tests/core/jsx/index.js +9 -0
  239. package/tests/core/stub-editor/index.js +26 -0
  240. package/tests/core/utils.js +58 -0
  241. package/tests/extension/plugins/list/insert-block.test.js +40 -0
  242. package/tests/extension/plugins/list/insert-fragment-list.test.js +392 -0
  243. package/tests/extension/plugins/list/toggle-list.test.js +160 -0
  244. package/tests/extension/plugins/text/text.test.js +29 -0
  245. package/tests/extension/plugins/text-style/toggle-text-style.test.js +148 -0
  246. package/tests/slate-convert/html-to-slate/blockquote.test.js +107 -0
  247. package/tests/slate-convert/html-to-slate/code-block.test.js +32 -0
  248. package/tests/slate-convert/html-to-slate/header.test.js +56 -0
  249. package/tests/slate-convert/html-to-slate/link.test.js +77 -0
  250. package/tests/slate-convert/html-to-slate/list.test.js +190 -0
  251. package/tests/slate-convert/html-to-slate/paragraph.test.js +40 -0
  252. package/tests/slate-convert/html-to-slate/text.test.js +131 -0
  253. package/tests/slate-convert/md-to-html/blockquote.test.js +110 -0
  254. package/tests/slate-convert/md-to-html/check-list.test.js +19 -0
  255. package/tests/slate-convert/md-to-html/code-block.test.js +19 -0
  256. package/tests/slate-convert/md-to-html/header.test.js +20 -0
  257. package/tests/slate-convert/md-to-html/image.test.js +17 -0
  258. package/tests/slate-convert/md-to-html/image_reference.test.js +17 -0
  259. package/tests/slate-convert/md-to-html/link.test.js +15 -0
  260. package/tests/slate-convert/md-to-html/link_reference.test.js +15 -0
  261. package/tests/slate-convert/md-to-html/list-ordered.test.js +22 -0
  262. package/tests/slate-convert/md-to-html/list-unordered.test.js +22 -0
  263. package/tests/slate-convert/md-to-html/paragraph.test.js +15 -0
  264. package/tests/slate-convert/md-to-html/table.test.js +29 -0
  265. package/tests/slate-convert/md-to-html/text_base.test.js +14 -0
  266. package/tests/slate-convert/md-to-html/text_bold.test.js +14 -0
  267. package/tests/slate-convert/md-to-html/text_bold_italic.test.js +15 -0
  268. package/tests/slate-convert/md-to-html/text_code.test.js +14 -0
  269. package/tests/slate-convert/md-to-html/text_code_bold.test.js +14 -0
  270. package/tests/slate-convert/md-to-html/text_code_bold_italic.test.js +14 -0
  271. package/tests/slate-convert/md-to-html/text_code_italic.test.js +14 -0
  272. package/tests/slate-convert/md-to-html/text_italic.test.js +14 -0
  273. package/tests/slate-convert/md-to-slate/blockquote.test.js +200 -0
  274. package/tests/slate-convert/md-to-slate/check-list.test.js +34 -0
  275. package/tests/slate-convert/md-to-slate/code-block.test.js +32 -0
  276. package/tests/slate-convert/md-to-slate/header.test.js +49 -0
  277. package/tests/slate-convert/md-to-slate/image.test.js +31 -0
  278. package/tests/slate-convert/md-to-slate/link.test.js +30 -0
  279. package/tests/slate-convert/md-to-slate/list-ordered.test.js +42 -0
  280. package/tests/slate-convert/md-to-slate/list-unordered.test.js +42 -0
  281. package/tests/slate-convert/md-to-slate/paragraph.test.js +19 -0
  282. package/tests/slate-convert/md-to-slate/table.test.js +34 -0
  283. package/tests/slate-convert/md-to-slate/text_base.test.js +19 -0
  284. package/tests/slate-convert/md-to-slate/text_bold.test.js +22 -0
  285. package/tests/slate-convert/md-to-slate/text_bold_italic.test.js +23 -0
  286. package/tests/slate-convert/md-to-slate/text_code.test.js +22 -0
  287. package/tests/slate-convert/md-to-slate/text_code_bold.test.js +23 -0
  288. package/tests/slate-convert/md-to-slate/text_code_bold_italic.test.js +24 -0
  289. package/tests/slate-convert/md-to-slate/text_code_italic.test.js +23 -0
  290. package/tests/slate-convert/md-to-slate/text_italic.test.js +22 -0
  291. package/tests/slate-convert/slate-to-md/blockquote.test.js +416 -0
  292. package/tests/slate-convert/slate-to-md/check-list.test.js +96 -0
  293. package/tests/slate-convert/slate-to-md/code-block.test.js +35 -0
  294. package/tests/slate-convert/slate-to-md/formula.test.js +26 -0
  295. package/tests/slate-convert/slate-to-md/header.test.js +109 -0
  296. package/tests/slate-convert/slate-to-md/image.test.js +98 -0
  297. package/tests/slate-convert/slate-to-md/link.test.js +52 -0
  298. package/tests/slate-convert/slate-to-md/list-ordered.test.js +87 -0
  299. package/tests/slate-convert/slate-to-md/list-unordered.test.js +81 -0
  300. package/tests/slate-convert/slate-to-md/paragraph.test.js +28 -0
  301. package/tests/slate-convert/slate-to-md/table.test.js +56 -0
  302. package/tests/slate-convert/slate-to-md/text_base.test.js +28 -0
  303. package/tests/slate-convert/slate-to-md/text_bold.test.js +36 -0
  304. package/tests/slate-convert/slate-to-md/text_bold_italic.test.js +42 -0
  305. package/tests/slate-convert/slate-to-md/text_code.test.js +31 -0
  306. package/tests/slate-convert/slate-to-md/text_code_bold.test.js +37 -0
  307. package/tests/slate-convert/slate-to-md/text_code_bold_italic.test.js +43 -0
  308. package/tests/slate-convert/slate-to-md/text_code_italic.test.js +37 -0
  309. package/tests/slate-convert/slate-to-md/text_italic.test.js +36 -0
  310. package/README.md +0 -52
  311. package/TODO.md +0 -55
  312. package/dist/assets/css/comment-dialog.css +0 -50
  313. package/dist/assets/css/diff-viewer.css +0 -105
  314. package/dist/assets/css/formula.css +0 -19
  315. package/dist/assets/css/history-viewer.css +0 -104
  316. package/dist/assets/css/image.css +0 -134
  317. package/dist/assets/css/issue-card.css +0 -43
  318. package/dist/assets/css/link.css +0 -7
  319. package/dist/assets/css/markdown-editor.css +0 -12
  320. package/dist/assets/css/markdown-viewer.css +0 -69
  321. package/dist/assets/css/navbar-imgbutton.css +0 -83
  322. package/dist/assets/css/outline.css +0 -29
  323. package/dist/assets/css/table.css +0 -57
  324. package/dist/assets/css/textlink-hovermenu.css +0 -47
  325. package/dist/assets/css/topbar.css +0 -350
  326. package/dist/assets/css/tree-view.css +0 -67
  327. package/dist/assets/editor/seatable-editor.css +0 -77
  328. package/dist/assets/editor/simple-editor.css +0 -77
  329. package/dist/components/click-outside.js +0 -46
  330. package/dist/components/context-menu.js +0 -97
  331. package/dist/components/dialogs/add-formula-dialog.js +0 -116
  332. package/dist/components/dialogs/add-image-dialog.js +0 -69
  333. package/dist/components/dialogs/add-link-dialog.js +0 -133
  334. package/dist/components/dialogs/comment-dialog.js +0 -97
  335. package/dist/components/dialogs/shortcut-dialog.js +0 -131
  336. package/dist/components/error-boundary.js +0 -28
  337. package/dist/components/load-script/index.js +0 -69
  338. package/dist/components/loading.js +0 -25
  339. package/dist/components/markdown-lint.js +0 -72
  340. package/dist/components/menu/index.js +0 -4
  341. package/dist/components/menu/item.js +0 -49
  342. package/dist/components/menu/menu.js +0 -38
  343. package/dist/components/menu/style.css +0 -42
  344. package/dist/components/modal-portal.js +0 -38
  345. package/dist/components/outline/index.js +0 -92
  346. package/dist/components/outline/outline-item.js +0 -58
  347. package/dist/components/select/_option.js +0 -44
  348. package/dist/components/select/field-setting.js +0 -106
  349. package/dist/components/select/index.js +0 -149
  350. package/dist/components/select/style.css +0 -144
  351. package/dist/components/svg-icons/check-mark-icon.js +0 -14
  352. package/dist/components/svg-icons/column-icon.js +0 -17
  353. package/dist/components/svg-icons/text-icon.js +0 -34
  354. package/dist/components/text-link-hover-menu/index.js +0 -123
  355. package/dist/components/toast/alert.js +0 -138
  356. package/dist/components/toast/index.js +0 -3
  357. package/dist/components/toast/toast.js +0 -159
  358. package/dist/components/toast/toastManager.js +0 -139
  359. package/dist/components/toast/toaster.js +0 -65
  360. package/dist/components/toolbar/header-list.js +0 -114
  361. package/dist/components/toolbar/help-group.js +0 -33
  362. package/dist/components/toolbar/index.js +0 -4
  363. package/dist/components/toolbar/insert-image.js +0 -106
  364. package/dist/components/toolbar/insert-table.js +0 -136
  365. package/dist/components/toolbar/table-group.js +0 -74
  366. package/dist/components/toolbar/toolbar.js +0 -317
  367. package/dist/components/toolbar/widgets/button-group.js +0 -24
  368. package/dist/components/toolbar/widgets/button-item.js +0 -129
  369. package/dist/components/toolbar/widgets/drop-list.js +0 -88
  370. package/dist/components/user-help/index.js +0 -179
  371. package/dist/constants/cell-types.js +0 -29
  372. package/dist/constants/column.js +0 -4
  373. package/dist/containers/code-highlight-package.js +0 -14
  374. package/dist/containers/controller/block-element-controller.js +0 -375
  375. package/dist/containers/controller/index.js +0 -5
  376. package/dist/containers/controller/inline-element-controller.js +0 -134
  377. package/dist/containers/controller/normalize-controller.js +0 -95
  378. package/dist/containers/controller/shortcut-controller.js +0 -385
  379. package/dist/containers/controller/void-element-controller.js +0 -9
  380. package/dist/containers/custom/custom.js +0 -18
  381. package/dist/containers/custom/get-event-transfer.js +0 -33
  382. package/dist/containers/custom/getNodesByTypeAtRange.js +0 -57
  383. package/dist/containers/custom/insertNodes.js +0 -120
  384. package/dist/containers/custom/is-empty-paragraph.js +0 -9
  385. package/dist/containers/custom/split-nodes-at-point.js +0 -136
  386. package/dist/containers/custom/unwrap-node-by-type-at-range.js +0 -70
  387. package/dist/containers/editor-context.js +0 -85
  388. package/dist/containers/editor-utils/block-element-utils/blockquote-utils.js +0 -80
  389. package/dist/containers/editor-utils/block-element-utils/code-utils.js +0 -145
  390. package/dist/containers/editor-utils/block-element-utils/formula-utils.js +0 -51
  391. package/dist/containers/editor-utils/block-element-utils/index.js +0 -31
  392. package/dist/containers/editor-utils/block-element-utils/list-utils.js +0 -395
  393. package/dist/containers/editor-utils/block-element-utils/table-utils.js +0 -412
  394. package/dist/containers/editor-utils/clear-format-utils.js +0 -84
  395. package/dist/containers/editor-utils/common-editor-utils.js +0 -492
  396. package/dist/containers/editor-utils/inline-element-utils/index.js +0 -95
  397. package/dist/containers/editor-utils/mark-utils.js +0 -20
  398. package/dist/containers/editor-utils/range-utils.js +0 -7
  399. package/dist/containers/editor-utils/selection-utils.js +0 -30
  400. package/dist/containers/editor-utils/text-utils.js +0 -117
  401. package/dist/containers/editor-widgets/check-list-item.js +0 -53
  402. package/dist/containers/editor-widgets/code-block.js +0 -128
  403. package/dist/containers/editor-widgets/column.js +0 -100
  404. package/dist/containers/editor-widgets/formula.js +0 -67
  405. package/dist/containers/editor-widgets/image.js +0 -237
  406. package/dist/containers/editor-widgets/link.js +0 -9
  407. package/dist/containers/editor-widgets/table.js +0 -144
  408. package/dist/containers/element-model/blockquote.js +0 -13
  409. package/dist/containers/element-model/column.js +0 -19
  410. package/dist/containers/element-model/image.js +0 -16
  411. package/dist/containers/element-model/link.js +0 -16
  412. package/dist/containers/element-model/table.js +0 -57
  413. package/dist/containers/element-model/text.js +0 -10
  414. package/dist/containers/render-utils/common-utils.js +0 -80
  415. package/dist/containers/render-utils/editor-utils.js +0 -133
  416. package/dist/containers/render-utils/viewer-utils.js +0 -198
  417. package/dist/containers/viewer-widgets/viewer-formula/index.js +0 -54
  418. package/dist/containers/viewer-widgets/viewer-image/index.js +0 -70
  419. package/dist/containers/viewer-widgets/viewer-image/viewer-image.css +0 -3
  420. package/dist/editors/index.js +0 -78
  421. package/dist/editors/markdown-editor.js +0 -280
  422. package/dist/editors/plain-markdown-editor.js +0 -285
  423. package/dist/editors/seatable-editor.js +0 -210
  424. package/dist/editors/simple-editor.js +0 -200
  425. package/dist/index.js +0 -11
  426. package/dist/utils/deserialize-html.js +0 -260
  427. package/dist/utils/diff/compare-strings.js +0 -35
  428. package/dist/utils/diff/diff.js +0 -769
  429. package/dist/utils/diff/index.js +0 -2
  430. package/dist/utils/seafile-markdown2html.js +0 -52
  431. package/dist/utils/slate2markdown/deserialize.js +0 -588
  432. package/dist/utils/slate2markdown/index.js +0 -3
  433. package/dist/utils/slate2markdown/serialize.js +0 -366
  434. package/dist/utils/utils.js +0 -68
  435. package/dist/viewer/diff-viewer.js +0 -85
  436. package/dist/viewer/index.js +0 -4
  437. package/dist/viewer/markdown-viewer.js +0 -121
  438. package/dist/viewer/seatable-viewer.js +0 -63
  439. package/dist/viewer/slate-viewer.js +0 -71
  440. package/public/index.html +0 -45
  441. package/public/manifest.json +0 -15
  442. package/public/media/seafile-logo.png +0 -0
  443. /package/{dist/assets/css/keyboard-shortcuts.css → src/extension/toolbar/user-help/style.css} +0 -0
@@ -0,0 +1,78 @@
1
+ import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import PropTypes from 'prop-types';
4
+ import { insertColumn, insertRow, removeColumn, removeRow } from '../table-operations';
5
+ import { INSERT_POSITION } from '../../../constants';
6
+
7
+ const ContextMenu = ({ position, editor, handleCloseContextMenu }) => {
8
+ const [contextMenuStyle, setContextMenuStyle] = useState({});
9
+ const contextMenuRef = useRef(null);
10
+ const { t } = useTranslation();
11
+
12
+ useLayoutEffect(() => {
13
+ generateContextMenuStyle(position);
14
+ // eslint-disable-next-line react-hooks/exhaustive-deps
15
+ }, [position]);
16
+
17
+ const generateContextMenuStyle = useCallback((position) => {
18
+ const menuHeight = contextMenuRef.current.offsetHeight;
19
+ // get height of context menu when the menu is drawing completed in this page
20
+ menuHeight === 0 && requestAnimationFrame(generateContextMenuStyle);
21
+ const documentHeight = document.body.clientHeight;
22
+ const isContextMenuOutOfScreen = position.top + menuHeight > documentHeight;
23
+ let top = isContextMenuOutOfScreen ? documentHeight - menuHeight - 5 : position.top;
24
+ const left = position.left + 3;
25
+ setContextMenuStyle({ top, left, zIndex: '1071', display: 'block' });
26
+ }, []);
27
+
28
+ const handleClickOperationBtn = (callback, ...arg) => {
29
+ callback && callback(editor, ...arg);
30
+ handleCloseContextMenu();
31
+ };
32
+
33
+ return (
34
+ <div onClick={() => handleCloseContextMenu} contentEditable={false} style={contextMenuStyle} ref={contextMenuRef} className={'sf-context-menu sf-dropdown-list'} >
35
+ <button
36
+ onClickCapture={() => handleClickOperationBtn(insertRow, INSERT_POSITION.BEFORE)}
37
+ className={'sf-context-menu-item sf-dropdown-menu-item'}>
38
+ {t('Insert_row_before')}
39
+ </button>
40
+ <button
41
+ onClick={() => handleClickOperationBtn(insertRow)}
42
+ className={'sf-context-menu-item sf-dropdown-menu-item'}>
43
+ {t('Insert_row_after')}
44
+ </button>
45
+ <button
46
+ onClick={() => handleClickOperationBtn(insertColumn, INSERT_POSITION.BEFORE)}
47
+ className={'sf-context-menu-item sf-dropdown-menu-item'}>
48
+ {t('Insert_column_before')}
49
+ </button>
50
+ <button
51
+ onClick={() => handleClickOperationBtn(insertColumn, INSERT_POSITION.AFTER)}
52
+ className={'sf-context-menu-item sf-dropdown-menu-item'}>
53
+ {t('Insert_column_after')}
54
+ </button>
55
+ <div className={'sf-divider dropdown-divider'}></div>
56
+ <button
57
+ onClick={() => handleClickOperationBtn(removeRow)}
58
+ className={'sf-context-menu-item sf-dropdown-menu-item'}>
59
+ {t('Remove_row')}
60
+ </button>
61
+ <button
62
+ onClick={() => handleClickOperationBtn(removeColumn)}
63
+ className={'sf-context-menu-item sf-dropdown-menu-item'}>
64
+ {t('Remove_column')}
65
+ </button>
66
+ </div>
67
+ );
68
+ };
69
+
70
+ ContextMenu.propTypes = {
71
+ editor: PropTypes.object.isRequired,
72
+ position: PropTypes.shape({
73
+ top: PropTypes.number.isRequired,
74
+ left: PropTypes.number.isRequired,
75
+ }).isRequired,
76
+ };
77
+
78
+ export default ContextMenu;
@@ -0,0 +1,157 @@
1
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { useReadOnly } from 'slate-react';
3
+ import { TEXT_ALIGN } from '../../../constants';
4
+ import { TABLE_BODY_NODE_NAME, TABLE_CELL_NODE_NAME, TABLE_ROW_NODE_NAME } from '../constant';
5
+ import ContextMenu from './context-menu';
6
+
7
+ import './style.css';
8
+
9
+ const RenderTableContainer = ({ attributes, children, element }, editor) => {
10
+ const tableRef = useRef(null);
11
+ const startGridRef = useRef({ rowIndex: -1, colIndex: -1 });
12
+ const [, setSelectGridRange] = useState({ startRowIndex: -1, startColIndex: -1, endRowIndex: -1, endColIndex: -1 });
13
+ const [isShowContextMenu, setIsShowContextMenu] = useState(false);
14
+ const [contextMenuPosition, setContextMenuPosition] = useState({ top: 0, left: 0 });
15
+ const isReadonly = useReadOnly();
16
+
17
+ useEffect(() => {
18
+ if (isReadonly) return null;
19
+ clearSelectedCells();
20
+ document.addEventListener('contextmenu', handleContextMenu);
21
+ return () => {
22
+ document.removeEventListener('contextmenu', handleContextMenu);
23
+ document.removeEventListener('mousedown', unregisterEventHandler);
24
+ document.removeEventListener('keyup', unregisterEventHandler);
25
+ document.removeEventListener('keyup', clearSelectedCells);
26
+ document.removeEventListener('mousedown', clearSelectedCells);
27
+ };
28
+ // eslint-disable-next-line react-hooks/exhaustive-deps
29
+ }, []);
30
+
31
+ const getTableElement = useCallback((node, type) => {
32
+ let target = node;
33
+ if (target.nodeName.toLowerCase() === type) return target;
34
+ while (target.nodeName.toLowerCase() !== type) {
35
+ target = target.parentNode;
36
+ }
37
+ return target;
38
+ }, []);
39
+
40
+ const clearSelectedCells = useCallback((e) => {
41
+ isShowContextMenu && handleCloseContextMenu();
42
+ tableRef.current.querySelectorAll('.selected-cell')
43
+ .forEach(selectedCell => {
44
+ selectedCell.classList.remove(
45
+ 'selected-cell',
46
+ 'selected-cell-left',
47
+ 'selected-cell-bottom',
48
+ 'selected-cell-top',
49
+ 'selected-cell-right'
50
+ );
51
+ });
52
+ document.removeEventListener('keyup', clearSelectedCells);
53
+ document.removeEventListener('click', clearSelectedCells);
54
+ }, [isShowContextMenu]);
55
+
56
+ const updateSelectedCellStyles = useCallback((startRowIndex, endRowIndex, startColIndex, endColIndex,) => {
57
+ clearSelectedCells();
58
+ if (startColIndex < 0 || startRowIndex < 0) return;
59
+ for (let rowIndex = startRowIndex; rowIndex <= endRowIndex; rowIndex++) {
60
+ let currentRow = tableRef.current.querySelectorAll(TABLE_ROW_NODE_NAME)[rowIndex];
61
+ for (let colIndex = startColIndex; colIndex <= endColIndex; colIndex++) {
62
+ const selectedCell = currentRow.querySelectorAll(TABLE_CELL_NODE_NAME)[colIndex];
63
+ selectedCell.classList.add('selected-cell');
64
+ // Set selected cell border
65
+ rowIndex === startRowIndex && selectedCell.classList.add('selected-cell-top');
66
+ colIndex === startColIndex && selectedCell.classList.add('selected-cell-left');
67
+ colIndex === endColIndex && selectedCell.classList.add('selected-cell-right');
68
+ rowIndex === endRowIndex && selectedCell.classList.add('selected-cell-bottom');
69
+ }
70
+ }
71
+ setSelectGridRange({ startRowIndex, endRowIndex, startColIndex, endColIndex, });
72
+ }, [clearSelectedCells]);
73
+
74
+ const selectCellsInTable = useCallback((e) => {
75
+ // Check if the target is in the table
76
+ if (e.target.nodeName.toLowerCase() === TABLE_BODY_NODE_NAME || !tableRef.current.contains(e.target)) return;
77
+ // Figure out select range
78
+ const { startRowIndex, startColIndex } = startGridRef.current;
79
+ const endRowIndex = getTableElement(e.target, TABLE_ROW_NODE_NAME).rowIndex;
80
+ const endColIndex = getTableElement(e.target, TABLE_CELL_NODE_NAME).cellIndex;
81
+ const minRowIndex = Math.min(startRowIndex, endRowIndex);
82
+ const maxRowIndex = Math.max(startRowIndex, endRowIndex);
83
+ const minColIndex = Math.min(startColIndex, endColIndex);
84
+ const maxColIndex = Math.max(startColIndex, endColIndex);
85
+ // Select one cell
86
+ if (minRowIndex === maxRowIndex && minColIndex === maxColIndex) return;
87
+ // collapse selection
88
+ window.getSelection().collapseToEnd();
89
+ updateSelectedCellStyles(minRowIndex, maxRowIndex, minColIndex, maxColIndex);
90
+ }, [getTableElement, updateSelectedCellStyles]);
91
+
92
+ const handleMouseUp = useCallback((e) => {
93
+ document.removeEventListener('mousemove', selectCellsInTable);
94
+ document.removeEventListener('mouseup', handleMouseUp);
95
+ document.addEventListener('keyup', clearSelectedCells);
96
+ document.addEventListener('mousedown', clearSelectedCells);
97
+ }, [clearSelectedCells, selectCellsInTable]);
98
+
99
+ const handleMouseDown = useCallback((e) => {
100
+ // Clear last rendered styles
101
+ clearSelectedCells();
102
+ // Set new select range
103
+ const startRowIndex = getTableElement(e.target, TABLE_ROW_NODE_NAME).rowIndex;
104
+ const startColIndex = getTableElement(e.target, TABLE_CELL_NODE_NAME).cellIndex;
105
+ startGridRef.current = { startRowIndex: startRowIndex, startColIndex: startColIndex };
106
+ document.addEventListener('mousemove', selectCellsInTable);
107
+ document.addEventListener('mouseup', handleMouseUp);
108
+ }, [clearSelectedCells, getTableElement, handleMouseUp, selectCellsInTable]);
109
+
110
+ const handleContextMenu = useCallback((e) => {
111
+ if (!tableRef.current.contains(e.target)) return;
112
+ e.preventDefault();
113
+ e.stopPropagation();
114
+ const { x, y } = tableRef.current.getBoundingClientRect();
115
+ setContextMenuPosition({ top: e.clientY - y, left: e.clientX - x });
116
+ setIsShowContextMenu(true);
117
+ document.addEventListener('mousedown', unregisterEventHandler);
118
+ document.addEventListener('keyup', unregisterEventHandler);
119
+ // eslint-disable-next-line react-hooks/exhaustive-deps
120
+ }, []);
121
+
122
+ const unregisterEventHandler = useCallback(() => {
123
+ document.removeEventListener('mousedown', handleContextMenu);
124
+ }, [handleContextMenu]);
125
+
126
+ const handleCloseContextMenu = () => {
127
+ setIsShowContextMenu(false);
128
+ };
129
+
130
+ return (
131
+ <div style={{ position: 'relative' }} >
132
+ <table ref={tableRef} onMouseDown={handleMouseDown} className='sf-table-container'>
133
+ <tbody {...attributes}>
134
+ {children}
135
+ </tbody>
136
+ </table>
137
+ {isShowContextMenu && <ContextMenu handleCloseContextMenu={handleCloseContextMenu} position={contextMenuPosition} editor={editor} />}
138
+ </div>
139
+ );
140
+ };
141
+
142
+ export default RenderTableContainer;
143
+
144
+ export const RenderTableRow = ({ attributes, children, element }) => {
145
+ return (
146
+ <tr {...attributes}>{children}</tr>
147
+ );
148
+ };
149
+
150
+ export const RenderTableCell = ({ attributes, children, element }) => {
151
+ const { align = TEXT_ALIGN.LEFT } = element;
152
+ return (
153
+ <td data-root='true' style={{ textAlign: align }} {...attributes}>
154
+ {children}
155
+ </td>
156
+ );
157
+ };
@@ -0,0 +1,94 @@
1
+ .sf-table-container td {
2
+ position: relative;
3
+ }
4
+
5
+ .sf-table-container .selected-cell {
6
+ caret-color: transparent;
7
+ background-color: #fff4e6;
8
+ }
9
+
10
+ .sf-table-container .selected-cell-top:before {
11
+ content: "";
12
+ position: absolute;
13
+ top: 0;
14
+ left: 0;
15
+ bottom: 0;
16
+ right: 0;
17
+ margin: -1px;
18
+ border-top: 1px double #ffa94d;
19
+ z-index: 2;
20
+ }
21
+
22
+ .sf-table-container .selected-cell-bottom:before {
23
+ content: "";
24
+ position: absolute;
25
+ left: 0;
26
+ right: 0;
27
+ top: 0;
28
+ bottom: 0;
29
+ margin: -1px;
30
+ border-bottom: 1px double #ffa94d;
31
+ z-index: 2;
32
+ }
33
+
34
+ .sf-table-container .selected-cell-left:before {
35
+ content: "";
36
+ position: absolute;
37
+ top: 0;
38
+ left: 0;
39
+ bottom: 0;
40
+ right: 0;
41
+ margin: -1px;
42
+ border-left: 1px double #ffa94d;
43
+ z-index: 2;
44
+ }
45
+
46
+ .sf-table-container .selected-cell-right:before {
47
+ content: "";
48
+ position: absolute;
49
+ top: 0;
50
+ right: 0;
51
+ left: 0;
52
+ bottom: 0;
53
+ margin: -1px;
54
+ border-right: 1px double #ffa94d;
55
+ z-index: 2;
56
+ }
57
+
58
+ .sf-context-menu {
59
+ position: absolute;
60
+ top: 0;
61
+ left: 0;
62
+ display: flex;
63
+ /* float: left; */
64
+ z-index: 1000;
65
+ flex-direction: column;
66
+ border: 1px solid rgba(0, 40, 100, 0.12);
67
+ border-radius: 3px;
68
+ background-color: #fff;
69
+ }
70
+
71
+ .sf-context-menu .sf-context-menu-item {
72
+ display: flex;
73
+ clear: both;
74
+ padding: 0.25rem 1.5rem;
75
+ border: none;
76
+ white-space: nowrap;
77
+ color: #212529;
78
+ background-color: #fff;
79
+ }
80
+
81
+ .sf-context-menu .sf-context-menu-item:hover,
82
+ .sf-context-menu .sf-context-menu-item:focus {
83
+ color: #16181b;
84
+ text-decoration: none;
85
+ background-color: #f8f9fa;
86
+ }
87
+
88
+ .sf-context-menu .sf-divider {
89
+ width: 100%;
90
+ height: 1px;
91
+ margin: 5px 0;
92
+ color: #eee;
93
+ cursor: default;
94
+ }
@@ -0,0 +1,162 @@
1
+ import { Editor, Transforms } from 'slate';
2
+ import { INSERT_POSITION } from '../../constants';
3
+ import { getSelectGrid, getTableEntry, getTableFocusingInfos } from './helper';
4
+ import { generateTableCell, generateTableRow } from './model';
5
+ import { focusEditor } from '../../core';
6
+
7
+ /**
8
+ * @param {Object} editor
9
+ * @param {INSERT_POSITION.AFTER | INSERT_POSITION.BEFORE} insertPosition by default is INSERT_POSITION.AFTER
10
+ */
11
+ const insertRow = (editor, position = INSERT_POSITION.AFTER) => {
12
+ const {
13
+ tableEntry: [, tablePath],
14
+ rowEntry: [rowNode],
15
+ rowIndex,
16
+ } = getTableFocusingInfos(editor);
17
+
18
+ const getInsertPath = (rowIndex) => {
19
+ const handlePosition = {
20
+ [INSERT_POSITION.BEFORE]: (rowIndex) => tablePath.concat(rowIndex),
21
+ [INSERT_POSITION.AFTER]: (rowIndex) => tablePath.concat(rowIndex + 1),
22
+ };
23
+ return handlePosition[position](rowIndex);
24
+ };
25
+
26
+ const insertPath = getInsertPath(rowIndex);
27
+ const insertRowChildren = rowNode.children.map(({ align }) => generateTableCell({ align }));
28
+ const insertRow = generateTableRow({ childrenOrText: insertRowChildren });
29
+ Transforms.insertNodes(editor, insertRow, { at: insertPath });
30
+ };
31
+
32
+ const removeRow = (editor) => {
33
+ const {
34
+ tableEntry: [tableNode, tablePath],
35
+ rowEntry: [, rowPath],
36
+ rowIndex,
37
+ } = getTableFocusingInfos(editor);
38
+
39
+ let focusPoint = null;
40
+ const tableHeight = tableNode.children.length;
41
+ // If table has one more row, remove row, else remove table
42
+ if (tableHeight > 1) {
43
+ // If removing row is the last row, focus on the previous row
44
+ const isRemovingLastRow = rowIndex === tableHeight - 1;
45
+
46
+ focusPoint = isRemovingLastRow
47
+ ? Editor.start(editor, tablePath.concat(rowIndex - 1))
48
+ : Editor.start(editor, rowPath);
49
+
50
+ Transforms.removeNodes(editor, { at: rowPath });
51
+ focusEditor(editor, focusPoint);
52
+ } else {
53
+ removeTable(editor);
54
+ }
55
+ };
56
+
57
+ const removeTable = (editor) => {
58
+ const [tableNodeEntry] = getTableEntry(editor);
59
+ if (!tableNodeEntry) return;
60
+
61
+ const [, tablePath] = tableNodeEntry;
62
+ const previousNodeEntry = Editor.previous(editor, { at: tablePath });
63
+ const focusPoint = Editor.end(editor, previousNodeEntry[1]);
64
+ Transforms.removeNodes(editor, { at: tablePath });
65
+ focusEditor(editor, focusPoint);
66
+ };
67
+
68
+ /**
69
+ * @param {Object} editor
70
+ * @param {INSERT_POSITION.AFTER | INSERT_POSITION.BEFORE} insertPosition by default is INSERT_POSITION.AFTER
71
+ */
72
+ const insertColumn = (editor, insertPosition = INSERT_POSITION.AFTER) => {
73
+ const {
74
+ tableEntry: [tableNode, tablePath],
75
+ rowIndex,
76
+ columnIndex,
77
+ } = getTableFocusingInfos(editor);
78
+
79
+ const getInsertPath = (rowIndex, columnIndex) => {
80
+ const newCellPath = {
81
+ [INSERT_POSITION.BEFORE]: (rowIndex, columnIndex) => tablePath.concat(rowIndex, columnIndex),
82
+ [INSERT_POSITION.AFTER]: (rowIndex, columnIndex) => tablePath.concat(rowIndex, columnIndex + 1),
83
+ };
84
+ return newCellPath[insertPosition](rowIndex, columnIndex);
85
+ };
86
+
87
+ tableNode.children.forEach((row, rowIndex) => {
88
+ const insertPath = getInsertPath(rowIndex, columnIndex);
89
+ const newCell = generateTableCell(rowIndex, columnIndex);
90
+ Transforms.insertNodes(editor, newCell, { at: insertPath });
91
+ });
92
+
93
+ const focusPoint = Editor.start(editor, getInsertPath(rowIndex, columnIndex));
94
+ focusEditor(editor, focusPoint);
95
+ };
96
+
97
+ const removeColumn = (editor) => {
98
+ const {
99
+ tableEntry: [tableNode, tablePath],
100
+ rowEntry: [rowNode, rowPath],
101
+ columnIndex,
102
+ } = getTableFocusingInfos(editor);
103
+
104
+ const tableWidth = rowNode.children.length;
105
+ let focusPoint = null;
106
+
107
+ // If table has one more column, remove column, else remove table
108
+ if (tableWidth > 1) {
109
+ // If removing column is the last column, focus on the previous column
110
+ const isRemovingLastColumn = columnIndex === tableWidth - 1;
111
+
112
+ tableNode.children.forEach((row, rowIndex) => {
113
+ const removePath = tablePath.concat(rowIndex, columnIndex);
114
+ Transforms.removeNodes(editor, { at: removePath });
115
+ });
116
+
117
+ focusPoint = isRemovingLastColumn
118
+ ? Editor.start(editor, rowPath.concat(columnIndex - 1))
119
+ : Editor.start(editor, rowPath.concat(columnIndex));
120
+
121
+ focusEditor(editor, focusPoint);
122
+ } else {
123
+ removeTable(editor);
124
+ }
125
+ };
126
+
127
+ /**
128
+ * @param {Object} editor
129
+ * @param {keyof TEXT_ALIGN} align Text align
130
+ */
131
+ const changeCellAlign = (editor, align) => {
132
+ const {
133
+ tableEntry: [, tablePath],
134
+ columnIndex,
135
+ rowIndex,
136
+ } = getTableFocusingInfos(editor);
137
+ const selectGrid = getSelectGrid(editor);
138
+
139
+ // If select a range in table
140
+ if (selectGrid) {
141
+ const { startRowIndex, endRowIndex, startColIndex, endColIndex } = selectGrid;
142
+ for (let rowIndex = startRowIndex; rowIndex <= endRowIndex; rowIndex++) {
143
+ for (let columnIndex = startColIndex; columnIndex <= endColIndex; columnIndex++) {
144
+ const cellPath = tablePath.concat(rowIndex, columnIndex);
145
+ Transforms.setNodes(editor, { align }, { at: cellPath });
146
+ }
147
+ }
148
+ } else {
149
+ // If select a cell in table
150
+ const cellPath = tablePath.concat(rowIndex, columnIndex);
151
+ Transforms.setNodes(editor, { align }, { at: cellPath });
152
+ }
153
+ };
154
+
155
+ export {
156
+ insertRow,
157
+ removeRow,
158
+ removeTable,
159
+ insertColumn,
160
+ removeColumn,
161
+ changeCellAlign
162
+ };
@@ -0,0 +1,38 @@
1
+ import { Editor } from 'slate';
2
+ import { isInCodeBlock } from '../code-block/helpers';
3
+
4
+ export const isMenuDisabled = (editor, isReadonly) => {
5
+ if (isReadonly) return true;
6
+ const { selection } = editor;
7
+ if (!selection) return true;
8
+ if (isInCodeBlock(editor)) return true;
9
+ return false;
10
+ };
11
+
12
+ export const isMarkActive = (editor, mark) => {
13
+ const marks = Editor.marks(editor);
14
+
15
+ // If curMarks exists, you need to set this parameter manually. curMarks prevails
16
+ if (marks && Object.keys(marks).length > 0) {
17
+ return !!marks[mark];
18
+ } else {
19
+ const [match] = Editor.nodes(editor, {
20
+ match: n => n[mark] === true,
21
+ });
22
+
23
+ return !!match;
24
+ }
25
+ };
26
+
27
+ export const addMark = (editor, type) => {
28
+ Editor.addMark(editor, type, true);
29
+ };
30
+
31
+ export const removeMark = (editor, type) => {
32
+ Editor.removeMark(editor, type);
33
+ };
34
+
35
+ export const toggleTextStyle = (editor, type) => {
36
+ const isActive = isMarkActive(editor, type);
37
+ isActive ? removeMark(editor, type) : addMark(editor, type);
38
+ };
@@ -0,0 +1,12 @@
1
+ import TextStyleMenu from './menu';
2
+ import withTextStyle from './plugin';
3
+ import renderText from './render-elem';
4
+
5
+ const TextPlugin = {
6
+ type: 'text',
7
+ editorMenus: [TextStyleMenu],
8
+ editorPlugin: withTextStyle,
9
+ renderElements: [renderText]
10
+ };
11
+
12
+ export default TextPlugin;
@@ -0,0 +1,41 @@
1
+ import React, { useCallback } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { MENUS_CONFIG_MAP, TEXT_STYLE_MAP } from '../../../constants';
4
+ import MenuItem from '../../../commons/menu/menu-item';
5
+ import { isMenuDisabled, isMarkActive, toggleTextStyle } from '../helpers';
6
+
7
+ const textStyleList = [TEXT_STYLE_MAP.ITALIC, TEXT_STYLE_MAP.BOLD, TEXT_STYLE_MAP.CODE];
8
+
9
+ const TextStyleMenu = ({ editor, readonly, type, isRichEditor, className }) => {
10
+ const config = MENUS_CONFIG_MAP[type];
11
+ const isDisabled = isMenuDisabled(editor, readonly);
12
+ const isActive = isMarkActive(editor, type);
13
+
14
+ const handleClickMenu = useCallback((e, toggleType) => {
15
+ toggleTextStyle(editor, type);
16
+ }, [editor, type]);
17
+
18
+ return (
19
+ <div>
20
+ <MenuItem
21
+ editor={editor}
22
+ disabled={isDisabled}
23
+ isActive={isActive}
24
+ isRichEditor={isRichEditor}
25
+ className={className}
26
+ onMouseDown={handleClickMenu}
27
+ {...config}
28
+ />
29
+ </div>
30
+ );
31
+ };
32
+
33
+ TextStyleMenu.propTypes = {
34
+ editor: PropTypes.object.isRequired,
35
+ readonly: PropTypes.bool.isRequired,
36
+ type: PropTypes.oneOf(textStyleList).isRequired,
37
+ isRichEditor: PropTypes.bool,
38
+ className: PropTypes.string,
39
+ };
40
+
41
+ export default TextStyleMenu;
@@ -0,0 +1,37 @@
1
+ import isHotkey from 'is-hotkey';
2
+ import { TEXT_STYLE_MAP } from '../../constants';
3
+ import { isMenuDisabled, toggleTextStyle } from './helpers';
4
+
5
+ const withTextStyle = (editor) => {
6
+ const { onHotKeyDown } = editor;
7
+ const newEditor = editor;
8
+
9
+ newEditor.onHotKeyDown = (event) => {
10
+
11
+ // Does not meet text hotkey processing conditions
12
+ if (!isHotkey('mod+b', event) && !isHotkey('mod+i', event)) {
13
+ return onHotKeyDown && onHotKeyDown(event);
14
+ }
15
+
16
+ // handled by text hotkey
17
+ if (isMenuDisabled(newEditor)) {
18
+ return true;
19
+ }
20
+
21
+ if (isHotkey('mod+b', event)) {
22
+ toggleTextStyle(newEditor, TEXT_STYLE_MAP.BOLD);
23
+ return true;
24
+ }
25
+
26
+ if (isHotkey('mod+i', event)) {
27
+ toggleTextStyle(newEditor, TEXT_STYLE_MAP.ITALIC);
28
+ return true;
29
+ }
30
+
31
+ return false;
32
+ };
33
+
34
+ return newEditor;
35
+ };
36
+
37
+ export default withTextStyle;
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import { TEXT_STYLE_MAP } from '../../constants';
3
+
4
+ const renderText = (props, editor) => {
5
+ const { attributes, children, leaf } = props;
6
+ const { text, ...rest } = leaf;
7
+
8
+ let markedChildren = React.cloneElement(children);
9
+
10
+ if (leaf[TEXT_STYLE_MAP.BOLD]) {
11
+ markedChildren = <strong>{markedChildren}</strong>;
12
+ }
13
+
14
+ if (leaf[TEXT_STYLE_MAP.ITALIC]) {
15
+ markedChildren = <i>{markedChildren}</i>;
16
+ }
17
+
18
+ if (leaf[TEXT_STYLE_MAP.UNDERLINE]) {
19
+ markedChildren = <span style={{ textDecoration: 'underline' }}>{markedChildren}</span>;
20
+ }
21
+
22
+ if (leaf[TEXT_STYLE_MAP.CODE]) {
23
+ markedChildren = <code>{markedChildren}</code>;
24
+ }
25
+
26
+ if (leaf[TEXT_STYLE_MAP.DELETE]) {
27
+ markedChildren = <del>{markedChildren}</del>;
28
+ }
29
+
30
+ if (leaf[TEXT_STYLE_MAP.ADD]) {
31
+ markedChildren = <span>{markedChildren}</span>;
32
+ }
33
+
34
+ if (leaf.decoration) {
35
+ markedChildren = <span className={`token ${leaf.type}`}>{markedChildren}</span>;
36
+ }
37
+
38
+ return (
39
+ <span data-id={leaf.id} {...attributes} className={Object.keys(rest).join(' ')}>
40
+ {markedChildren}
41
+ </span>
42
+ );
43
+ };
44
+
45
+ export default renderText;