@block-kit/plugin 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 (297) hide show
  1. package/dist/es/align/index.d.ts +12 -0
  2. package/dist/es/align/index.js +25 -0
  3. package/dist/es/align/types/index.d.ts +1 -0
  4. package/dist/es/align/types/index.js +3 -0
  5. package/dist/es/background/index.d.ts +12 -0
  6. package/dist/es/background/index.js +27 -0
  7. package/dist/es/background/types/index.d.ts +1 -0
  8. package/dist/es/background/types/index.js +3 -0
  9. package/dist/es/bold/index.d.ts +15 -0
  10. package/dist/es/bold/index.js +46 -0
  11. package/dist/es/bold/types/index.d.ts +1 -0
  12. package/dist/es/bold/types/index.js +3 -0
  13. package/dist/es/bullet-list/index.d.ts +16 -0
  14. package/dist/es/bullet-list/index.js +149 -0
  15. package/dist/es/bullet-list/types/index.d.ts +6 -0
  16. package/dist/es/bullet-list/types/index.js +8 -0
  17. package/dist/es/bullet-list/utils/is.d.ts +6 -0
  18. package/dist/es/bullet-list/view/list.d.ts +9 -0
  19. package/dist/es/divider/index.d.ts +17 -0
  20. package/dist/es/divider/index.js +60 -0
  21. package/dist/es/divider/types/index.d.ts +1 -0
  22. package/dist/es/divider/types/index.js +3 -0
  23. package/dist/es/dom-71a99400.js +45 -0
  24. package/dist/es/emoji/index.d.ts +16 -0
  25. package/dist/es/emoji/index.js +51 -0
  26. package/dist/es/emoji/types/index.d.ts +1 -0
  27. package/dist/es/emoji/types/index.js +3 -0
  28. package/dist/es/font-color/index.d.ts +12 -0
  29. package/dist/es/font-color/index.js +27 -0
  30. package/dist/es/font-color/types/index.d.ts +1 -0
  31. package/dist/es/font-color/types/index.js +3 -0
  32. package/dist/es/font-size/index.d.ts +12 -0
  33. package/dist/es/font-size/index.js +28 -0
  34. package/dist/es/font-size/types/index.d.ts +1 -0
  35. package/dist/es/font-size/types/index.js +3 -0
  36. package/dist/es/heading/index.d.ts +13 -0
  37. package/dist/es/heading/index.js +33 -0
  38. package/dist/es/heading/types/index.d.ts +1 -0
  39. package/dist/es/heading/types/index.js +3 -0
  40. package/dist/es/image/index.d.ts +21 -0
  41. package/dist/es/image/index.js +245 -0
  42. package/dist/es/image/types/index.d.ts +12 -0
  43. package/dist/es/image/types/index.js +14 -0
  44. package/dist/es/image/view/image.d.ts +10 -0
  45. package/dist/es/image/view/wrapper.d.ts +10 -0
  46. package/dist/es/indent/index.d.ts +14 -0
  47. package/dist/es/indent/index.js +67 -0
  48. package/dist/es/indent/types/index.d.ts +1 -0
  49. package/dist/es/indent/types/index.js +3 -0
  50. package/dist/es/index-1e46887d.js +205 -0
  51. package/dist/es/index-ddc2e5ac.js +493 -0
  52. package/dist/es/index.css +1 -0
  53. package/dist/es/index.d.ts +50 -0
  54. package/dist/es/index.js +64 -0
  55. package/dist/es/inline-code/index.d.ts +14 -0
  56. package/dist/es/inline-code/index.js +46 -0
  57. package/dist/es/inline-code/types/index.d.ts +1 -0
  58. package/dist/es/inline-code/types/index.js +3 -0
  59. package/dist/es/is-2b264ec8.js +11 -0
  60. package/dist/es/is-3de778e2.js +15 -0
  61. package/dist/es/is-7f3ae820.js +12 -0
  62. package/dist/es/italic/index.d.ts +15 -0
  63. package/dist/es/italic/index.js +43 -0
  64. package/dist/es/italic/types/index.d.ts +1 -0
  65. package/dist/es/italic/types/index.js +3 -0
  66. package/dist/es/line-height/index.d.ts +12 -0
  67. package/dist/es/line-height/index.js +25 -0
  68. package/dist/es/line-height/types/index.d.ts +1 -0
  69. package/dist/es/line-height/types/index.js +3 -0
  70. package/dist/es/link/index.d.ts +17 -0
  71. package/dist/es/link/index.js +64 -0
  72. package/dist/es/link/types/index.d.ts +3 -0
  73. package/dist/es/link/types/index.js +7 -0
  74. package/dist/es/link/view/a.d.ts +6 -0
  75. package/dist/es/marks-ac0ec630.js +46 -0
  76. package/dist/es/mention/index.d.ts +16 -0
  77. package/dist/es/mention/index.js +13 -0
  78. package/dist/es/mention/modules/suggest.d.ts +18 -0
  79. package/dist/es/mention/types/index.d.ts +2 -0
  80. package/dist/es/mention/types/index.js +4 -0
  81. package/dist/es/mention/utils/constant.d.ts +2 -0
  82. package/dist/es/mention/view/suggest.d.ts +9 -0
  83. package/dist/es/order-list/index.d.ts +16 -0
  84. package/dist/es/order-list/index.js +323 -0
  85. package/dist/es/order-list/types/index.d.ts +8 -0
  86. package/dist/es/order-list/types/index.js +10 -0
  87. package/dist/es/order-list/utils/format.d.ts +6 -0
  88. package/dist/es/order-list/utils/is.d.ts +6 -0
  89. package/dist/es/order-list/utils/serial.d.ts +10 -0
  90. package/dist/es/order-list/view/list.d.ts +10 -0
  91. package/dist/es/quote/index.d.ts +17 -0
  92. package/dist/es/quote/index.js +130 -0
  93. package/dist/es/quote/types/index.d.ts +1 -0
  94. package/dist/es/quote/types/index.js +3 -0
  95. package/dist/es/selection-badfb0bc.js +81 -0
  96. package/dist/es/shared/components/selection.d.ts +26 -0
  97. package/dist/es/shared/icons/divider.d.ts +2 -0
  98. package/dist/es/shared/icons/emoji.d.ts +2 -0
  99. package/dist/es/shared/icons/font-color.d.ts +2 -0
  100. package/dist/es/shared/icons/font-size.d.ts +2 -0
  101. package/dist/es/shared/icons/justify.d.ts +2 -0
  102. package/dist/es/shared/icons/line-height.d.ts +2 -0
  103. package/dist/es/shared/icons/text.d.ts +2 -0
  104. package/dist/es/shared/modules/selection.d.ts +12 -0
  105. package/dist/es/shared/utils/dom.d.ts +26 -0
  106. package/dist/es/shared/utils/event.d.ts +8 -0
  107. package/dist/es/shared/utils/is.d.ts +4 -0
  108. package/dist/es/shortcut/index.d.ts +14 -0
  109. package/dist/es/shortcut/index.js +85 -0
  110. package/dist/es/shortcut/modules/preset.d.ts +2 -0
  111. package/dist/es/shortcut/types/index.d.ts +10 -0
  112. package/dist/es/shortcut/types/index.js +3 -0
  113. package/dist/es/strike/index.d.ts +15 -0
  114. package/dist/es/strike/index.js +47 -0
  115. package/dist/es/strike/types/index.d.ts +1 -0
  116. package/dist/es/strike/types/index.js +3 -0
  117. package/dist/es/toolbar/context/basic.d.ts +4 -0
  118. package/dist/es/toolbar/context/float.d.ts +13 -0
  119. package/dist/es/toolbar/context/provider.d.ts +12 -0
  120. package/dist/es/toolbar/index.d.ts +26 -0
  121. package/dist/es/toolbar/index.js +34 -0
  122. package/dist/es/toolbar/modules/align.d.ts +2 -0
  123. package/dist/es/toolbar/modules/bold.d.ts +2 -0
  124. package/dist/es/toolbar/modules/bullet-list.d.ts +2 -0
  125. package/dist/es/toolbar/modules/cut.d.ts +3 -0
  126. package/dist/es/toolbar/modules/divider.d.ts +2 -0
  127. package/dist/es/toolbar/modules/emoji.d.ts +3 -0
  128. package/dist/es/toolbar/modules/font-color.d.ts +3 -0
  129. package/dist/es/toolbar/modules/font-size.d.ts +2 -0
  130. package/dist/es/toolbar/modules/heading.d.ts +2 -0
  131. package/dist/es/toolbar/modules/history.d.ts +2 -0
  132. package/dist/es/toolbar/modules/image.d.ts +2 -0
  133. package/dist/es/toolbar/modules/inline-code.d.ts +2 -0
  134. package/dist/es/toolbar/modules/italic.d.ts +2 -0
  135. package/dist/es/toolbar/modules/line-height.d.ts +3 -0
  136. package/dist/es/toolbar/modules/link.d.ts +5 -0
  137. package/dist/es/toolbar/modules/order-list.d.ts +2 -0
  138. package/dist/es/toolbar/modules/quote.d.ts +2 -0
  139. package/dist/es/toolbar/modules/strike.d.ts +2 -0
  140. package/dist/es/toolbar/modules/underline.d.ts +2 -0
  141. package/dist/es/toolbar/types/index.d.ts +8 -0
  142. package/dist/es/toolbar/types/index.js +7 -0
  143. package/dist/es/toolbar/utils/marks.d.ts +4 -0
  144. package/dist/es/tslib.es6-83956cc1.js +38 -0
  145. package/dist/es/underline/index.d.ts +15 -0
  146. package/dist/es/underline/index.js +45 -0
  147. package/dist/es/underline/types/index.d.ts +1 -0
  148. package/dist/es/underline/types/index.js +3 -0
  149. package/dist/lib/align/index.d.ts +12 -0
  150. package/dist/lib/align/index.js +29 -0
  151. package/dist/lib/align/types/index.d.ts +1 -0
  152. package/dist/lib/align/types/index.js +7 -0
  153. package/dist/lib/background/index.d.ts +12 -0
  154. package/dist/lib/background/index.js +31 -0
  155. package/dist/lib/background/types/index.d.ts +1 -0
  156. package/dist/lib/background/types/index.js +7 -0
  157. package/dist/lib/bold/index.d.ts +15 -0
  158. package/dist/lib/bold/index.js +50 -0
  159. package/dist/lib/bold/types/index.d.ts +1 -0
  160. package/dist/lib/bold/types/index.js +7 -0
  161. package/dist/lib/bullet-list/index.d.ts +16 -0
  162. package/dist/lib/bullet-list/index.js +153 -0
  163. package/dist/lib/bullet-list/types/index.d.ts +6 -0
  164. package/dist/lib/bullet-list/types/index.js +14 -0
  165. package/dist/lib/bullet-list/utils/is.d.ts +6 -0
  166. package/dist/lib/bullet-list/view/list.d.ts +9 -0
  167. package/dist/lib/divider/index.d.ts +17 -0
  168. package/dist/lib/divider/index.js +64 -0
  169. package/dist/lib/divider/types/index.d.ts +1 -0
  170. package/dist/lib/divider/types/index.js +7 -0
  171. package/dist/lib/dom-cb8b8e40.js +50 -0
  172. package/dist/lib/emoji/index.d.ts +16 -0
  173. package/dist/lib/emoji/index.js +59 -0
  174. package/dist/lib/emoji/types/index.d.ts +1 -0
  175. package/dist/lib/emoji/types/index.js +7 -0
  176. package/dist/lib/font-color/index.d.ts +12 -0
  177. package/dist/lib/font-color/index.js +31 -0
  178. package/dist/lib/font-color/types/index.d.ts +1 -0
  179. package/dist/lib/font-color/types/index.js +7 -0
  180. package/dist/lib/font-size/index.d.ts +12 -0
  181. package/dist/lib/font-size/index.js +32 -0
  182. package/dist/lib/font-size/types/index.d.ts +1 -0
  183. package/dist/lib/font-size/types/index.js +7 -0
  184. package/dist/lib/heading/index.d.ts +13 -0
  185. package/dist/lib/heading/index.js +37 -0
  186. package/dist/lib/heading/types/index.d.ts +1 -0
  187. package/dist/lib/heading/types/index.js +7 -0
  188. package/dist/lib/image/index.d.ts +21 -0
  189. package/dist/lib/image/index.js +249 -0
  190. package/dist/lib/image/types/index.d.ts +12 -0
  191. package/dist/lib/image/types/index.js +25 -0
  192. package/dist/lib/image/view/image.d.ts +10 -0
  193. package/dist/lib/image/view/wrapper.d.ts +10 -0
  194. package/dist/lib/indent/index.d.ts +14 -0
  195. package/dist/lib/indent/index.js +71 -0
  196. package/dist/lib/indent/types/index.d.ts +1 -0
  197. package/dist/lib/indent/types/index.js +7 -0
  198. package/dist/lib/index-f50053bf.js +506 -0
  199. package/dist/lib/index-ffc4bb34.js +212 -0
  200. package/dist/lib/index.css +1 -0
  201. package/dist/lib/index.d.ts +50 -0
  202. package/dist/lib/index.js +141 -0
  203. package/dist/lib/inline-code/index.d.ts +14 -0
  204. package/dist/lib/inline-code/index.js +50 -0
  205. package/dist/lib/inline-code/types/index.d.ts +1 -0
  206. package/dist/lib/inline-code/types/index.js +7 -0
  207. package/dist/lib/is-18806678.js +14 -0
  208. package/dist/lib/is-473d664a.js +18 -0
  209. package/dist/lib/is-fa1755d0.js +13 -0
  210. package/dist/lib/italic/index.d.ts +15 -0
  211. package/dist/lib/italic/index.js +47 -0
  212. package/dist/lib/italic/types/index.d.ts +1 -0
  213. package/dist/lib/italic/types/index.js +7 -0
  214. package/dist/lib/line-height/index.d.ts +12 -0
  215. package/dist/lib/line-height/index.js +29 -0
  216. package/dist/lib/line-height/types/index.d.ts +1 -0
  217. package/dist/lib/line-height/types/index.js +7 -0
  218. package/dist/lib/link/index.d.ts +17 -0
  219. package/dist/lib/link/index.js +68 -0
  220. package/dist/lib/link/types/index.d.ts +3 -0
  221. package/dist/lib/link/types/index.js +13 -0
  222. package/dist/lib/link/view/a.d.ts +6 -0
  223. package/dist/lib/marks-a30b8a0f.js +50 -0
  224. package/dist/lib/mention/index.d.ts +16 -0
  225. package/dist/lib/mention/index.js +21 -0
  226. package/dist/lib/mention/modules/suggest.d.ts +18 -0
  227. package/dist/lib/mention/types/index.d.ts +2 -0
  228. package/dist/lib/mention/types/index.js +9 -0
  229. package/dist/lib/mention/utils/constant.d.ts +2 -0
  230. package/dist/lib/mention/view/suggest.d.ts +9 -0
  231. package/dist/lib/order-list/index.d.ts +16 -0
  232. package/dist/lib/order-list/index.js +327 -0
  233. package/dist/lib/order-list/types/index.d.ts +8 -0
  234. package/dist/lib/order-list/types/index.js +17 -0
  235. package/dist/lib/order-list/utils/format.d.ts +6 -0
  236. package/dist/lib/order-list/utils/is.d.ts +6 -0
  237. package/dist/lib/order-list/utils/serial.d.ts +10 -0
  238. package/dist/lib/order-list/view/list.d.ts +10 -0
  239. package/dist/lib/quote/index.d.ts +17 -0
  240. package/dist/lib/quote/index.js +134 -0
  241. package/dist/lib/quote/types/index.d.ts +1 -0
  242. package/dist/lib/quote/types/index.js +7 -0
  243. package/dist/lib/selection-868f15c1.js +88 -0
  244. package/dist/lib/shared/components/selection.d.ts +26 -0
  245. package/dist/lib/shared/icons/divider.d.ts +2 -0
  246. package/dist/lib/shared/icons/emoji.d.ts +2 -0
  247. package/dist/lib/shared/icons/font-color.d.ts +2 -0
  248. package/dist/lib/shared/icons/font-size.d.ts +2 -0
  249. package/dist/lib/shared/icons/justify.d.ts +2 -0
  250. package/dist/lib/shared/icons/line-height.d.ts +2 -0
  251. package/dist/lib/shared/icons/text.d.ts +2 -0
  252. package/dist/lib/shared/modules/selection.d.ts +12 -0
  253. package/dist/lib/shared/utils/dom.d.ts +26 -0
  254. package/dist/lib/shared/utils/event.d.ts +8 -0
  255. package/dist/lib/shared/utils/is.d.ts +4 -0
  256. package/dist/lib/shortcut/index.d.ts +14 -0
  257. package/dist/lib/shortcut/index.js +89 -0
  258. package/dist/lib/shortcut/modules/preset.d.ts +2 -0
  259. package/dist/lib/shortcut/types/index.d.ts +10 -0
  260. package/dist/lib/shortcut/types/index.js +7 -0
  261. package/dist/lib/strike/index.d.ts +15 -0
  262. package/dist/lib/strike/index.js +51 -0
  263. package/dist/lib/strike/types/index.d.ts +1 -0
  264. package/dist/lib/strike/types/index.js +7 -0
  265. package/dist/lib/toolbar/context/basic.d.ts +4 -0
  266. package/dist/lib/toolbar/context/float.d.ts +13 -0
  267. package/dist/lib/toolbar/context/provider.d.ts +12 -0
  268. package/dist/lib/toolbar/index.d.ts +26 -0
  269. package/dist/lib/toolbar/index.js +44 -0
  270. package/dist/lib/toolbar/modules/align.d.ts +2 -0
  271. package/dist/lib/toolbar/modules/bold.d.ts +2 -0
  272. package/dist/lib/toolbar/modules/bullet-list.d.ts +2 -0
  273. package/dist/lib/toolbar/modules/cut.d.ts +3 -0
  274. package/dist/lib/toolbar/modules/divider.d.ts +2 -0
  275. package/dist/lib/toolbar/modules/emoji.d.ts +3 -0
  276. package/dist/lib/toolbar/modules/font-color.d.ts +3 -0
  277. package/dist/lib/toolbar/modules/font-size.d.ts +2 -0
  278. package/dist/lib/toolbar/modules/heading.d.ts +2 -0
  279. package/dist/lib/toolbar/modules/history.d.ts +2 -0
  280. package/dist/lib/toolbar/modules/image.d.ts +2 -0
  281. package/dist/lib/toolbar/modules/inline-code.d.ts +2 -0
  282. package/dist/lib/toolbar/modules/italic.d.ts +2 -0
  283. package/dist/lib/toolbar/modules/line-height.d.ts +3 -0
  284. package/dist/lib/toolbar/modules/link.d.ts +5 -0
  285. package/dist/lib/toolbar/modules/order-list.d.ts +2 -0
  286. package/dist/lib/toolbar/modules/quote.d.ts +2 -0
  287. package/dist/lib/toolbar/modules/strike.d.ts +2 -0
  288. package/dist/lib/toolbar/modules/underline.d.ts +2 -0
  289. package/dist/lib/toolbar/types/index.d.ts +8 -0
  290. package/dist/lib/toolbar/types/index.js +12 -0
  291. package/dist/lib/toolbar/utils/marks.d.ts +4 -0
  292. package/dist/lib/tslib.es6-d44c9a95.js +41 -0
  293. package/dist/lib/underline/index.d.ts +15 -0
  294. package/dist/lib/underline/index.js +49 -0
  295. package/dist/lib/underline/types/index.d.ts +1 -0
  296. package/dist/lib/underline/types/index.js +7 -0
  297. package/package.json +56 -0
@@ -0,0 +1,6 @@
1
+ import type { AttributeMap } from "@block-kit/delta";
2
+ /**
3
+ * 检查有序列表
4
+ * @param attrs
5
+ */
6
+ export declare const isOrderList: (attrs: AttributeMap) => boolean;
@@ -0,0 +1,10 @@
1
+ import type { Range } from "@block-kit/core";
2
+ import type { Editor } from "@block-kit/core";
3
+ /**
4
+ * 批量刷新选区的列表序号 [批量刷新简单方便]
5
+ * - 从选区开始的第一个列表项开始,逐个刷新序号
6
+ * - 全量刷新序号数据, 最后需要在渲染时批量刷新
7
+ * @param editor
8
+ * @param sel
9
+ */
10
+ export declare const applyNewOrderList: (editor: Editor, range?: Range) => undefined;
@@ -0,0 +1,10 @@
1
+ import "../styles/index.scss";
2
+ import type { Editor } from "@block-kit/core";
3
+ import type { ReactLineContext } from "@block-kit/react";
4
+ import type { FC } from "react";
5
+ export declare const OrderListView: FC<{
6
+ context: ReactLineContext;
7
+ editor: Editor;
8
+ level: number;
9
+ start: number;
10
+ }>;
@@ -0,0 +1,17 @@
1
+ import "./styles/index.scss";
2
+ import type { CMDPayload, Editor } from "@block-kit/core";
3
+ import type { AttributeMap } from "@block-kit/delta";
4
+ import type { ReactWrapLineContext } from "@block-kit/react";
5
+ import { EditorPlugin } from "@block-kit/react";
6
+ import type { EventContext } from "@block-kit/utils";
7
+ import type { ReactNode } from "react";
8
+ export declare class QuotePlugin extends EditorPlugin {
9
+ protected editor: Editor;
10
+ key: string;
11
+ constructor(editor: Editor);
12
+ destroy(): void;
13
+ match(attrs: AttributeMap): boolean;
14
+ wrapLine(context: ReactWrapLineContext): ReactNode;
15
+ protected onExec(payload: CMDPayload): undefined;
16
+ protected onKeyDown(event: KeyboardEvent, context: EventContext): undefined;
17
+ }
@@ -0,0 +1,134 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var tslib_es6 = require('../tslib.es6-d44c9a95.js');
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+ var core = require('@block-kit/core');
8
+ var delta = require('@block-kit/delta');
9
+ var react = require('@block-kit/react');
10
+ var utils = require('@block-kit/utils');
11
+ var dom = require('../dom-cb8b8e40.js');
12
+ var is = require('../is-473d664a.js');
13
+ var quote_types_index = require('./types/index.js');
14
+
15
+ class QuotePlugin extends react.EditorPlugin {
16
+ constructor(editor) {
17
+ super();
18
+ this.editor = editor;
19
+ this.key = quote_types_index.QUOTE_KEY;
20
+ editor.command.register(this.key, this.onExec);
21
+ editor.event.on(core.EDITOR_EVENT.KEY_DOWN, this.onKeyDown);
22
+ }
23
+ destroy() {
24
+ this.editor.event.off(core.EDITOR_EVENT.KEY_DOWN, this.onKeyDown);
25
+ }
26
+ match(attrs) {
27
+ return !!attrs[quote_types_index.QUOTE_KEY];
28
+ }
29
+ wrapLine(context) {
30
+ if (!context.lineState.attributes[quote_types_index.QUOTE_KEY]) {
31
+ return context.children;
32
+ }
33
+ return jsxRuntime.jsx("div", { className: "block-kit-quote", children: context.children });
34
+ }
35
+ onExec(payload) {
36
+ const editor = this.editor;
37
+ const sel = editor.selection.get() || payload.range;
38
+ if (!sel)
39
+ return void 0;
40
+ const { start, end } = sel;
41
+ // 先检查当前需要设置/解除引用状态
42
+ const lines = editor.state.block.getLines().slice(start.line, end.line + 1);
43
+ const isQuote = lines.every(line => line.attributes[quote_types_index.QUOTE_KEY]);
44
+ // 计算需要操作的范围
45
+ const rawPoint = core.RawPoint.fromPoint(this.editor, core.Point.from(start.line, 0));
46
+ if (!rawPoint)
47
+ return void 0;
48
+ const block = this.editor.state.block;
49
+ const delta$1 = new delta.Delta();
50
+ delta$1.retain(rawPoint.offset);
51
+ // 根据行的状态, 逐行设置引用状态
52
+ for (let i = start.line; i <= end.line; i++) {
53
+ const lineState = block.getLine(i);
54
+ if (!lineState)
55
+ break;
56
+ delta$1.retain(lineState.length - 1);
57
+ const attrs = {
58
+ [quote_types_index.QUOTE_KEY]: isQuote ? utils.NIL : utils.TRULY,
59
+ };
60
+ delta$1.retain(1, attrs);
61
+ }
62
+ this.editor.state.apply(delta$1, { autoCaret: false });
63
+ }
64
+ onKeyDown(event, context) {
65
+ const sel = this.editor.selection.get();
66
+ if (!sel)
67
+ return void 0;
68
+ const block = this.editor.state.block;
69
+ const startLine = block.getLine(sel.start.line);
70
+ if (!startLine)
71
+ return void 0;
72
+ const prevLine = startLine.prev();
73
+ const attrs = startLine.attributes;
74
+ // 当前行是引用行, 且按下回车键, 且选区折叠, 且当前行是空行
75
+ // => 删除当前的引用行格式
76
+ if (is.isKeyCode(event, utils.KEY_CODE.ENTER) &&
77
+ attrs[quote_types_index.QUOTE_KEY] &&
78
+ sel.isCollapsed &&
79
+ is.isEmptyLine(startLine)) {
80
+ const nextAttrs = {
81
+ [quote_types_index.QUOTE_KEY]: utils.NIL,
82
+ };
83
+ const delta$1 = new delta.Delta().retain(startLine.start + startLine.length - 1).retain(1, nextAttrs);
84
+ this.editor.state.apply(delta$1, { autoCaret: false });
85
+ dom.preventContextEvent(event, context);
86
+ return void 0;
87
+ }
88
+ // 当前行是引用行, 且按下回车键, 且选区折叠, 且位于行首, 且上一行是引用行
89
+ // => 继续引用格式, 避免默认的处理, 保持引用的连续性
90
+ if (is.isKeyCode(event, utils.KEY_CODE.ENTER) &&
91
+ attrs[quote_types_index.QUOTE_KEY] &&
92
+ sel.isCollapsed &&
93
+ sel.start.offset === 0 &&
94
+ prevLine &&
95
+ prevLine.attributes[quote_types_index.QUOTE_KEY]) {
96
+ const nextAttrs = Object.assign({}, prevLine.attributes);
97
+ const delta$1 = new delta.Delta().retain(startLine.start).insertEOL(nextAttrs);
98
+ this.editor.state.apply(delta$1);
99
+ dom.preventContextEvent(event, context);
100
+ return void 0;
101
+ }
102
+ // 当前行是引用行, 且按下回车键, 且非行首
103
+ // => 在引用行内部插入换行符, 且携带引用状态
104
+ if (is.isKeyCode(event, utils.KEY_CODE.ENTER) && attrs[quote_types_index.QUOTE_KEY] && sel.start.offset) {
105
+ this.editor.perform.insertBreak(sel, attrs);
106
+ dom.preventContextEvent(event, context);
107
+ return void 0;
108
+ }
109
+ // 当前行是引用行, 且折叠选区, 且在行首, 且按下退格键
110
+ // => 将当前行的引用状态移除
111
+ if (is.isKeyCode(event, utils.KEY_CODE.BACKSPACE) &&
112
+ sel.isCollapsed &&
113
+ attrs[quote_types_index.QUOTE_KEY] &&
114
+ !sel.start.offset) {
115
+ const delta$1 = new delta.Delta()
116
+ .retain(startLine.start + startLine.length - 1)
117
+ .retain(1, { [quote_types_index.QUOTE_KEY]: utils.NIL });
118
+ this.editor.state.apply(delta$1, { autoCaret: false });
119
+ dom.preventContextEvent(event, context);
120
+ return void 0;
121
+ }
122
+ }
123
+ }
124
+ tslib_es6.__decorate([
125
+ react.InjectWrapKeys(quote_types_index.QUOTE_KEY)
126
+ ], QuotePlugin.prototype, "wrapLine", null);
127
+ tslib_es6.__decorate([
128
+ utils.Bind
129
+ ], QuotePlugin.prototype, "onExec", null);
130
+ tslib_es6.__decorate([
131
+ utils.Bind
132
+ ], QuotePlugin.prototype, "onKeyDown", null);
133
+
134
+ exports.QuotePlugin = QuotePlugin;
@@ -0,0 +1 @@
1
+ export declare const QUOTE_KEY = "quote";
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const QUOTE_KEY = "quote";
6
+
7
+ exports.QUOTE_KEY = QUOTE_KEY;
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var core = require('@block-kit/core');
5
+ var react = require('@block-kit/react');
6
+ var utils = require('@block-kit/utils');
7
+ var React = require('react');
8
+ var tslib_es6 = require('./tslib.es6-d44c9a95.js');
9
+
10
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
+
12
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
13
+
14
+ class SelectionHOC extends React__default["default"].PureComponent {
15
+ constructor(props) {
16
+ super(props);
17
+ this.state = {
18
+ id: utils.getId(),
19
+ selected: false,
20
+ };
21
+ this.editor = this.props.selection.editor;
22
+ }
23
+ componentDidMount() {
24
+ // FIX: UNDO 时内容与选区变化同样需要更新状态
25
+ const range = this.editor.selection.get();
26
+ this.onSelectionChange(range);
27
+ this.props.selection.mountView(this.state.id, this);
28
+ }
29
+ componentWillUnmount() {
30
+ this.props.selection.unmountView(this.state.id);
31
+ }
32
+ onSelectionChange(range) {
33
+ const leaf = this.props.leaf;
34
+ const leafRange = leaf.toRange();
35
+ const nextState = range ? core.Range.intersection(leafRange, range) : false;
36
+ if (this.state.selected !== nextState) {
37
+ this.setState({ selected: nextState });
38
+ }
39
+ }
40
+ render() {
41
+ const selected = this.state.selected;
42
+ const { border = true } = this.props;
43
+ // readonly context
44
+ if (this.context) {
45
+ return this.props.children;
46
+ }
47
+ return (jsxRuntime.jsx("div", { className: utils.cs(this.props.className, selected && border && "block-kit-embed-selected"), "data-selection": true, children: React__default["default"].Children.map(this.props.children, child => {
48
+ if (React__default["default"].isValidElement(child)) {
49
+ const { props } = child;
50
+ return React__default["default"].cloneElement(child, Object.assign(Object.assign({}, props), { selected: selected }));
51
+ }
52
+ else {
53
+ return child;
54
+ }
55
+ }) }));
56
+ }
57
+ }
58
+ SelectionHOC.contextType = react.ReadonlyContext;
59
+
60
+ class SelectionPlugin {
61
+ constructor(editor) {
62
+ this.editor = editor;
63
+ this.idToView = new Map();
64
+ editor.event.on(core.EDITOR_EVENT.SELECTION_CHANGE, this.onSelectionChange);
65
+ }
66
+ destroy() {
67
+ this.idToView.clear();
68
+ this.editor.event.off(core.EDITOR_EVENT.SELECTION_CHANGE, this.onSelectionChange);
69
+ }
70
+ mountView(id, view) {
71
+ this.idToView.set(id, view);
72
+ }
73
+ unmountView(id) {
74
+ this.idToView.delete(id);
75
+ }
76
+ onSelectionChange(e) {
77
+ const current = e.current;
78
+ this.idToView.forEach(view => {
79
+ view.onSelectionChange(current);
80
+ });
81
+ }
82
+ }
83
+ tslib_es6.__decorate([
84
+ utils.Bind
85
+ ], SelectionPlugin.prototype, "onSelectionChange", null);
86
+
87
+ exports.SelectionHOC = SelectionHOC;
88
+ exports.SelectionPlugin = SelectionPlugin;
@@ -0,0 +1,26 @@
1
+ import "../styles/selection.scss";
2
+ import type { LeafState } from "@block-kit/core";
3
+ import type { Editor } from "@block-kit/core";
4
+ import { Range } from "@block-kit/core";
5
+ import React from "react";
6
+ import type { SelectionPlugin } from "../modules/selection";
7
+ type Props = {
8
+ leaf: LeafState;
9
+ border?: boolean;
10
+ className?: string;
11
+ selection: SelectionPlugin;
12
+ };
13
+ type State = {
14
+ id: string;
15
+ selected: boolean;
16
+ };
17
+ export declare class SelectionHOC extends React.PureComponent<Props, State> {
18
+ protected editor: Editor;
19
+ static contextType: React.Context<boolean>;
20
+ constructor(props: Props);
21
+ componentDidMount(): void;
22
+ componentWillUnmount(): void;
23
+ onSelectionChange(range: Range | null): void;
24
+ render(): React.ReactNode;
25
+ }
26
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { FC } from "react";
2
+ export declare const DividerIcon: FC;
@@ -0,0 +1,2 @@
1
+ import type { FC } from "react";
2
+ export declare const EmojiIcon: FC;
@@ -0,0 +1,2 @@
1
+ import type { FC } from "react";
2
+ export declare const FontColorIcon: FC;
@@ -0,0 +1,2 @@
1
+ import type { FC } from "react";
2
+ export declare const FontSizeIcon: FC;
@@ -0,0 +1,2 @@
1
+ import type { FC } from "react";
2
+ export declare const JustifyIcon: FC;
@@ -0,0 +1,2 @@
1
+ import type { FC } from "react";
2
+ export declare const LineHeightIcon: FC;
@@ -0,0 +1,2 @@
1
+ import type { FC } from "react";
2
+ export declare const TextIcon: FC;
@@ -0,0 +1,12 @@
1
+ import type { Editor, SelectionChangeEvent } from "@block-kit/core";
2
+ import type { SelectionHOC } from "../components/selection";
3
+ export declare class SelectionPlugin {
4
+ editor: Editor;
5
+ /** id <-> React.ReactNode */
6
+ protected idToView: Map<string, SelectionHOC>;
7
+ constructor(editor: Editor);
8
+ destroy(): void;
9
+ mountView(id: string, view: SelectionHOC): void;
10
+ unmountView(id: string): void;
11
+ protected onSelectionChange(e: SelectionChangeEvent): void;
12
+ }
@@ -0,0 +1,26 @@
1
+ import type { Editor } from "@block-kit/core";
2
+ import type { EventContext } from "@block-kit/utils";
3
+ /**
4
+ * 设置挂载 DOM
5
+ * @param editor
6
+ * @param dom
7
+ */
8
+ export declare const setMountDOM: (editor: Editor, dom: HTMLElement | null) => void;
9
+ /**
10
+ * 获取挂载 DOM
11
+ * @param editor
12
+ * @param dom
13
+ */
14
+ export declare const getMountDOM: (editor: Editor) => HTMLElement;
15
+ /**
16
+ * 阻止所有编辑器分发的事件
17
+ * @param event
18
+ * @param context
19
+ */
20
+ export declare const preventContextEvent: (event: Event, context: EventContext) => void;
21
+ /**
22
+ * 滚动到指定元素
23
+ * @param container
24
+ * @param child
25
+ */
26
+ export declare const scrollIfNeeded: (container: HTMLDivElement, child: Element, buffer?: number) => void;
@@ -0,0 +1,8 @@
1
+ export declare const PLUGIN_EVENTS: {
2
+ readonly SHORTCUT_MARKS_CHANGE: "SHORTCUT_MARKS_CHANGE";
3
+ };
4
+ declare module "@block-kit/utils/dist/es/event-bus" {
5
+ interface EventBusType {
6
+ [PLUGIN_EVENTS.SHORTCUT_MARKS_CHANGE]: null;
7
+ }
8
+ }
@@ -0,0 +1,4 @@
1
+ import type { LineState } from "@block-kit/core";
2
+ import type { P } from "@block-kit/utils/dist/es/types";
3
+ export declare const isEmptyLine: (line: LineState | P.Nil) => boolean | null;
4
+ export declare const isKeyCode: (event: KeyboardEvent, code: number) => boolean;
@@ -0,0 +1,14 @@
1
+ import type { Editor } from "@block-kit/core";
2
+ import { CorePlugin } from "@block-kit/core";
3
+ import type { O } from "@block-kit/utils/dist/es/types";
4
+ import type { ShortcutFunc, ShortcutFuncMap } from "./types";
5
+ export declare class Shortcut extends CorePlugin {
6
+ protected editor: Editor;
7
+ key: string;
8
+ protected config: ShortcutFunc[];
9
+ constructor(editor: Editor, config?: ShortcutFuncMap);
10
+ destroy(): void;
11
+ match(): boolean;
12
+ protected getKeys(): O.Map<string>;
13
+ protected onKeydown(event: KeyboardEvent): void;
14
+ }
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var tslib_es6 = require('../tslib.es6-d44c9a95.js');
6
+ var core = require('@block-kit/core');
7
+ var utils = require('@block-kit/utils');
8
+ var marks = require('../marks-a30b8a0f.js');
9
+ var bold_types_index = require('../bold/types/index.js');
10
+ var italic_types_index = require('../italic/types/index.js');
11
+ var is = require('../is-473d664a.js');
12
+ var shortcut_types_index = require('./types/index.js');
13
+ require('@block-kit/delta');
14
+
15
+ const PRESET_SHORTCUT = {
16
+ [bold_types_index.BOLD_KEY]: (event, payload) => {
17
+ if (event[utils.CTRL_KEY] && is.isKeyCode(event, utils.KEY_CODE.B) && payload.sel) {
18
+ const { editor, keys, sel } = payload;
19
+ editor.perform.applyMarks(sel, { [bold_types_index.BOLD_KEY]: keys[bold_types_index.BOLD_KEY] ? utils.NIL : utils.TRULY });
20
+ return true;
21
+ }
22
+ },
23
+ [italic_types_index.ITALIC_KEY]: (event, payload) => {
24
+ if (event[utils.CTRL_KEY] && is.isKeyCode(event, utils.KEY_CODE.I) && payload.sel) {
25
+ const { editor, keys, sel } = payload;
26
+ editor.perform.applyMarks(sel, { [italic_types_index.ITALIC_KEY]: keys[italic_types_index.ITALIC_KEY] ? utils.NIL : utils.TRULY });
27
+ return true;
28
+ }
29
+ },
30
+ };
31
+
32
+ class Shortcut extends core.CorePlugin {
33
+ constructor(editor, config) {
34
+ super();
35
+ this.editor = editor;
36
+ this.key = shortcut_types_index.SHORTCUT_KEY;
37
+ this.config = Object.values(Object.assign(Object.assign({}, PRESET_SHORTCUT), config));
38
+ this.editor.event.on(core.EDITOR_EVENT.KEY_DOWN, this.onKeydown, 1000);
39
+ }
40
+ destroy() {
41
+ this.editor.event.off(core.EDITOR_EVENT.KEY_DOWN, this.onKeydown);
42
+ }
43
+ match() {
44
+ return false;
45
+ }
46
+ getKeys() {
47
+ const current = this.editor.selection.get();
48
+ if (!current) {
49
+ return {};
50
+ }
51
+ const lines = this.editor.state.block.getLines();
52
+ const { start, end } = current;
53
+ const lineMarkMap = marks.filterLineMarkMap(lines.slice(start.line, end.line + 1).map(line => line.attributes));
54
+ if (current.isCollapsed) {
55
+ return Object.assign(Object.assign({}, this.editor.collect.marks), lineMarkMap);
56
+ }
57
+ const ops = [];
58
+ if (current.isCollapsed) {
59
+ const op = this.editor.collect.getOpAtPoint(current.start);
60
+ op && ops.push(op);
61
+ }
62
+ else {
63
+ const fragment = this.editor.collect.getFragment();
64
+ fragment && ops.push(...fragment);
65
+ }
66
+ const markMap = marks.filterMarkMap(ops);
67
+ return Object.assign(Object.assign({}, markMap), lineMarkMap);
68
+ }
69
+ onKeydown(event) {
70
+ const keys = this.getKeys();
71
+ const payload = {
72
+ keys,
73
+ editor: this.editor,
74
+ sel: this.editor.selection.get(),
75
+ };
76
+ for (const func of this.config) {
77
+ const result = func(event, payload);
78
+ if (!result)
79
+ continue;
80
+ this.editor.event.trigger(marks.PLUGIN_EVENTS.SHORTCUT_MARKS_CHANGE, null);
81
+ break;
82
+ }
83
+ }
84
+ }
85
+ tslib_es6.__decorate([
86
+ utils.Bind
87
+ ], Shortcut.prototype, "onKeydown", null);
88
+
89
+ exports.Shortcut = Shortcut;
@@ -0,0 +1,2 @@
1
+ import type { ShortcutFuncMap } from "../types";
2
+ export declare const PRESET_SHORTCUT: ShortcutFuncMap;
@@ -0,0 +1,10 @@
1
+ import type { Editor } from "@block-kit/core";
2
+ import type { Range } from "@block-kit/core";
3
+ import type { O, P } from "@block-kit/utils/dist/es/types";
4
+ export declare const SHORTCUT_KEY = "SHORTCUT_KEY";
5
+ export type ShortcutFunc = (event: KeyboardEvent, payload: {
6
+ editor: Editor;
7
+ keys: O.Map<string>;
8
+ sel: Range | null;
9
+ }) => true | P.Nil;
10
+ export type ShortcutFuncMap = O.Map<ShortcutFunc>;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const SHORTCUT_KEY = "SHORTCUT_KEY";
6
+
7
+ exports.SHORTCUT_KEY = SHORTCUT_KEY;
@@ -0,0 +1,15 @@
1
+ import type { DeserializeContext, SerializeContext } from "@block-kit/core";
2
+ import type { Editor } from "@block-kit/core";
3
+ import type { AttributeMap } from "@block-kit/delta";
4
+ import type { ReactLeafContext } from "@block-kit/react";
5
+ import { EditorPlugin } from "@block-kit/react";
6
+ import type { ReactNode } from "react";
7
+ export declare class StrikePlugin extends EditorPlugin {
8
+ key: string;
9
+ destroy(): void;
10
+ constructor(editor: Editor);
11
+ match(attrs: AttributeMap): boolean;
12
+ serialize(context: SerializeContext): SerializeContext;
13
+ deserialize(context: DeserializeContext): DeserializeContext;
14
+ renderLeaf(context: ReactLeafContext): ReactNode;
15
+ }
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@block-kit/core');
6
+ var react = require('@block-kit/react');
7
+ var utils = require('@block-kit/utils');
8
+ var strike_types_index = require('./types/index.js');
9
+
10
+ class StrikePlugin extends react.EditorPlugin {
11
+ destroy() { }
12
+ constructor(editor) {
13
+ super();
14
+ this.key = strike_types_index.STRIKE_KEY;
15
+ editor.command.register(strike_types_index.STRIKE_KEY, context => {
16
+ const sel = editor.selection.get();
17
+ sel && editor.perform.applyMarks(sel, { [strike_types_index.STRIKE_KEY]: context.value });
18
+ });
19
+ }
20
+ match(attrs) {
21
+ return !!attrs[strike_types_index.STRIKE_KEY];
22
+ }
23
+ serialize(context) {
24
+ const { op, html } = context;
25
+ if (op.attributes && op.attributes[strike_types_index.STRIKE_KEY]) {
26
+ const strong = document.createElement("del");
27
+ strong.appendChild(html);
28
+ context.html = strong;
29
+ }
30
+ return context;
31
+ }
32
+ deserialize(context) {
33
+ const { delta, html } = context;
34
+ if (!utils.isHTMLElement(html))
35
+ return context;
36
+ if (core.isMatchHTMLTag(html, "s") ||
37
+ core.isMatchHTMLTag(html, "del") ||
38
+ html.style.textDecorationLine === "line-through") {
39
+ core.applyMarker(delta, { [strike_types_index.STRIKE_KEY]: utils.TRULY });
40
+ }
41
+ return context;
42
+ }
43
+ renderLeaf(context) {
44
+ context.style.textDecoration = context.style.textDecoration
45
+ ? context.style.textDecoration + " line-through"
46
+ : "line-through";
47
+ return context.children;
48
+ }
49
+ }
50
+
51
+ exports.StrikePlugin = StrikePlugin;
@@ -0,0 +1 @@
1
+ export declare const STRIKE_KEY = "strike";
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const STRIKE_KEY = "strike";
6
+
7
+ exports.STRIKE_KEY = STRIKE_KEY;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import "../styles/index.scss";
3
+ import type { ToolbarProps } from "../types";
4
+ export declare const Toolbar: import("react").ForwardRefExoticComponent<ToolbarProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,13 @@
1
+ import "../styles/float.scss";
2
+ import type { FC } from "react";
3
+ export declare const FloatToolbar: FC<{
4
+ className?: string;
5
+ /**
6
+ * Top 偏移
7
+ */
8
+ offsetTop?: number;
9
+ /**
10
+ * Left 偏移
11
+ */
12
+ offsetLeft?: number;
13
+ }>;
@@ -0,0 +1,12 @@
1
+ import type { Editor } from "@block-kit/core";
2
+ import type { Range } from "@block-kit/core";
3
+ import React from "react";
4
+ export type ToolbarContextType = {
5
+ editor: Editor;
6
+ refreshMarks: () => void;
7
+ keys: Record<string, string>;
8
+ setKeys: (v: Record<string, string>) => void;
9
+ selection: Range | null;
10
+ };
11
+ export declare const ToolbarContext: React.Context<ToolbarContextType>;
12
+ export declare const useToolbarContext: () => ToolbarContextType;