@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,12 @@
1
+ import type { Editor } from "@block-kit/core";
2
+ import type { AttributeMap } from "@block-kit/delta";
3
+ import type { ReactLineContext } from "@block-kit/react";
4
+ import { EditorPlugin } from "@block-kit/react";
5
+ import type { ReactNode } from "react";
6
+ export declare class AlignPlugin extends EditorPlugin {
7
+ key: string;
8
+ destroy(): void;
9
+ constructor(editor: Editor);
10
+ match(attrs: AttributeMap): boolean;
11
+ renderLine(context: ReactLineContext): ReactNode;
12
+ }
@@ -0,0 +1,25 @@
1
+ import { EditorPlugin } from '@block-kit/react';
2
+ import { ALIGN_KEY } from './types/index.js';
3
+
4
+ class AlignPlugin extends EditorPlugin {
5
+ destroy() { }
6
+ constructor(editor) {
7
+ super();
8
+ this.key = ALIGN_KEY;
9
+ editor.command.register(ALIGN_KEY, context => {
10
+ const sel = editor.selection.get();
11
+ sel && editor.perform.applyLineMarks(sel, { [ALIGN_KEY]: context.value });
12
+ });
13
+ }
14
+ match(attrs) {
15
+ return !!attrs[ALIGN_KEY];
16
+ }
17
+ renderLine(context) {
18
+ const attrs = context.attributes || {};
19
+ const align = attrs[ALIGN_KEY];
20
+ context.style.textAlign = align;
21
+ return context.children;
22
+ }
23
+ }
24
+
25
+ export { AlignPlugin };
@@ -0,0 +1 @@
1
+ export declare const ALIGN_KEY = "align";
@@ -0,0 +1,3 @@
1
+ const ALIGN_KEY = "align";
2
+
3
+ export { ALIGN_KEY };
@@ -0,0 +1,12 @@
1
+ import type { Editor } from "@block-kit/core";
2
+ import type { AttributeMap } from "@block-kit/delta";
3
+ import type { ReactLeafContext } from "@block-kit/react";
4
+ import { EditorPlugin } from "@block-kit/react";
5
+ import type { ReactNode } from "react";
6
+ export declare class BackgroundPlugin extends EditorPlugin {
7
+ key: string;
8
+ destroy(): void;
9
+ constructor(editor: Editor);
10
+ match(attrs: AttributeMap): boolean;
11
+ renderLeaf(context: ReactLeafContext): ReactNode;
12
+ }
@@ -0,0 +1,27 @@
1
+ import { EditorPlugin } from '@block-kit/react';
2
+ import { BACKGROUND_KEY } from './types/index.js';
3
+
4
+ class BackgroundPlugin extends EditorPlugin {
5
+ destroy() { }
6
+ constructor(editor) {
7
+ super();
8
+ this.key = BACKGROUND_KEY;
9
+ editor.command.register(BACKGROUND_KEY, context => {
10
+ const sel = editor.selection.get();
11
+ sel && editor.perform.applyMarks(sel, { [BACKGROUND_KEY]: context.value });
12
+ });
13
+ }
14
+ match(attrs) {
15
+ return !!attrs[BACKGROUND_KEY];
16
+ }
17
+ renderLeaf(context) {
18
+ const attrs = context.attributes || {};
19
+ const background = attrs[BACKGROUND_KEY];
20
+ if (background) {
21
+ context.style.backgroundColor = background;
22
+ }
23
+ return context.children;
24
+ }
25
+ }
26
+
27
+ export { BackgroundPlugin };
@@ -0,0 +1 @@
1
+ export declare const BACKGROUND_KEY = "background";
@@ -0,0 +1,3 @@
1
+ const BACKGROUND_KEY = "background";
2
+
3
+ export { BACKGROUND_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 BoldPlugin 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,46 @@
1
+ import { isMatchHTMLTag, applyMarker } from '@block-kit/core';
2
+ import { EditorPlugin } from '@block-kit/react';
3
+ import { isHTMLElement, TRULY } from '@block-kit/utils';
4
+ import { BOLD_KEY } from './types/index.js';
5
+
6
+ class BoldPlugin extends EditorPlugin {
7
+ destroy() { }
8
+ constructor(editor) {
9
+ super();
10
+ this.key = BOLD_KEY;
11
+ editor.command.register(BOLD_KEY, context => {
12
+ const sel = editor.selection.get();
13
+ sel && editor.perform.applyMarks(sel, { [BOLD_KEY]: context.value });
14
+ });
15
+ }
16
+ match(attrs) {
17
+ return !!attrs[BOLD_KEY];
18
+ }
19
+ serialize(context) {
20
+ const { op, html } = context;
21
+ if (op.attributes && op.attributes[BOLD_KEY]) {
22
+ const strong = document.createElement("strong");
23
+ // 采用 Wrap Base Node 加原地替换的方式
24
+ strong.appendChild(html);
25
+ context.html = strong;
26
+ }
27
+ return context;
28
+ }
29
+ deserialize(context) {
30
+ const { delta, html } = context;
31
+ if (!isHTMLElement(html))
32
+ return context;
33
+ if (isMatchHTMLTag(html, "strong") ||
34
+ isMatchHTMLTag(html, "b") ||
35
+ html.style.fontWeight === "bold") {
36
+ applyMarker(delta, { [BOLD_KEY]: TRULY });
37
+ }
38
+ return context;
39
+ }
40
+ renderLeaf(context) {
41
+ context.style.fontWeight = "bold";
42
+ return context.children;
43
+ }
44
+ }
45
+
46
+ export { BoldPlugin };
@@ -0,0 +1 @@
1
+ export declare const BOLD_KEY = "bold";
@@ -0,0 +1,3 @@
1
+ const BOLD_KEY = "bold";
2
+
3
+ export { BOLD_KEY };
@@ -0,0 +1,16 @@
1
+ import type { CMDPayload, Editor } from "@block-kit/core";
2
+ import type { AttributeMap } from "@block-kit/delta";
3
+ import type { ReactLineContext } from "@block-kit/react";
4
+ import { EditorPlugin } from "@block-kit/react";
5
+ import type { EventContext } from "@block-kit/utils";
6
+ import type { ReactNode } from "react";
7
+ export declare class BulletListPlugin extends EditorPlugin {
8
+ protected editor: Editor;
9
+ key: string;
10
+ constructor(editor: Editor);
11
+ destroy(): void;
12
+ match(attrs: AttributeMap): boolean;
13
+ renderLine(context: ReactLineContext): ReactNode;
14
+ protected onExec(payload: CMDPayload): undefined;
15
+ protected onKeyDown(event: KeyboardEvent, context: EventContext): undefined;
16
+ }
@@ -0,0 +1,149 @@
1
+ import { _ as __decorate } from '../tslib.es6-83956cc1.js';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { EDITOR_EVENT, RawPoint, Point } from '@block-kit/core';
4
+ import { Delta } from '@block-kit/delta';
5
+ import { EditorPlugin } from '@block-kit/react';
6
+ import { cs, Bind, KEY_CODE, NIL } from '@block-kit/utils';
7
+ import { INDENT_LEVEL_KEY } from '../indent/types/index.js';
8
+ import { p as preventContextEvent } from '../dom-71a99400.js';
9
+ import { a as isKeyCode, i as isEmptyLine } from '../is-3de778e2.js';
10
+ import { BULLET_LIST_KEY, LIST_TYPE_KEY, BULLET_LIST_TYPE } from './types/index.js';
11
+ import { i as isBulletList } from '../is-2b264ec8.js';
12
+
13
+ const BulletListView = props => {
14
+ const { level, children } = props;
15
+ return (jsx("ul", { className: "block-kit-bullet-list", children: jsx("li", { className: cs("block-kit-bullet-item", `block-kit-li-level-${level % 3}`), children: children }) }));
16
+ };
17
+
18
+ class BulletListPlugin extends EditorPlugin {
19
+ constructor(editor) {
20
+ super();
21
+ this.editor = editor;
22
+ this.key = BULLET_LIST_KEY;
23
+ editor.command.register(this.key, this.onExec);
24
+ editor.event.on(EDITOR_EVENT.KEY_DOWN, this.onKeyDown);
25
+ }
26
+ destroy() {
27
+ this.editor.event.off(EDITOR_EVENT.KEY_DOWN, this.onKeyDown);
28
+ }
29
+ match(attrs) {
30
+ return isBulletList(attrs);
31
+ }
32
+ renderLine(context) {
33
+ const level = Number(context.attributes[INDENT_LEVEL_KEY]) || 0;
34
+ // 这里需要注意, 必须要将 context.children 作为 React 的子元素
35
+ // 否则, 在 React 的渲染过程中, 会出现奇怪的 Crash 问题
36
+ return (jsx(BulletListView, { level: level, editor: this.editor, context: context, children: context.children }));
37
+ }
38
+ onExec(payload) {
39
+ const editor = this.editor;
40
+ const sel = editor.selection.get() || payload.range;
41
+ if (!sel)
42
+ return void 0;
43
+ const { start, end } = sel;
44
+ // 先检查当前需要设置/解除列表状态
45
+ const lines = editor.state.block.getLines().slice(start.line, end.line + 1);
46
+ const isBullet = lines.every(line => isBulletList(line.attributes));
47
+ // 计算需要操作的范围
48
+ const rawPoint = RawPoint.fromPoint(this.editor, Point.from(start.line, 0));
49
+ if (!rawPoint)
50
+ return void 0;
51
+ const block = this.editor.state.block;
52
+ const delta = new Delta();
53
+ delta.retain(rawPoint.offset);
54
+ // 根据行的状态, 逐行设置列表状态
55
+ for (let i = start.line; i <= end.line; i++) {
56
+ const lineState = block.getLine(i);
57
+ if (!lineState)
58
+ break;
59
+ delta.retain(lineState.length - 1);
60
+ const attrs = {
61
+ [LIST_TYPE_KEY]: isBullet ? NIL : BULLET_LIST_TYPE,
62
+ };
63
+ if (!isBullet && lineState.attributes[INDENT_LEVEL_KEY]) {
64
+ attrs[INDENT_LEVEL_KEY] = lineState.attributes[INDENT_LEVEL_KEY];
65
+ }
66
+ delta.retain(1, attrs);
67
+ }
68
+ this.editor.state.apply(delta, { autoCaret: false });
69
+ }
70
+ onKeyDown(event, context) {
71
+ const sel = this.editor.selection.get();
72
+ if (!sel)
73
+ return void 0;
74
+ const block = this.editor.state.block;
75
+ const startLine = block.getLine(sel.start.line);
76
+ if (!startLine)
77
+ return void 0;
78
+ const prevLine = startLine.prev();
79
+ const attrs = startLine.attributes;
80
+ // 当前行是列表行, 且按下回车键, 且选区折叠, 且当前行是空行
81
+ // => 处理列表的缩进等级
82
+ if (isKeyCode(event, KEY_CODE.ENTER) &&
83
+ isBulletList(attrs) &&
84
+ sel.isCollapsed &&
85
+ isEmptyLine(startLine)) {
86
+ const level = Number(attrs[INDENT_LEVEL_KEY]);
87
+ const nextAttrs = {};
88
+ if (level > 0) {
89
+ // 缩进等级大于 0, 则减少缩进等级
90
+ const nextLevel = level - 1 > 0 ? String(level - 1) : NIL;
91
+ nextAttrs[INDENT_LEVEL_KEY] = nextLevel;
92
+ }
93
+ else {
94
+ // 否则, 取消列表状态
95
+ nextAttrs[LIST_TYPE_KEY] = NIL;
96
+ }
97
+ const delta = new Delta().retain(startLine.start + startLine.length - 1).retain(1, nextAttrs);
98
+ this.editor.state.apply(delta, { autoCaret: false });
99
+ preventContextEvent(event, context);
100
+ return void 0;
101
+ }
102
+ // 当前行是列表行, 且按下回车键, 且选区折叠, 且位于行首, 且上一行是列表行
103
+ // => 继续列表格式, 避免默认的处理, 保持列表的连续性
104
+ if (isKeyCode(event, KEY_CODE.ENTER) &&
105
+ isBulletList(attrs) &&
106
+ sel.isCollapsed &&
107
+ sel.start.offset === 0 &&
108
+ prevLine &&
109
+ isBulletList(prevLine.attributes)) {
110
+ const nextAttrs = Object.assign({}, prevLine.attributes);
111
+ if (attrs[INDENT_LEVEL_KEY]) {
112
+ // 缩进层级优先取当前行的缩进层级
113
+ nextAttrs[INDENT_LEVEL_KEY] = attrs[INDENT_LEVEL_KEY];
114
+ }
115
+ const delta = new Delta().retain(startLine.start).insertEOL(nextAttrs);
116
+ this.editor.state.apply(delta);
117
+ preventContextEvent(event, context);
118
+ return void 0;
119
+ }
120
+ // 当前行是列表行, 且按下回车键
121
+ // => 在列表行内部插入换行符, 且携带列表状态
122
+ if (isKeyCode(event, KEY_CODE.ENTER) && isBulletList(attrs) && sel.start.offset) {
123
+ this.editor.perform.insertBreak(sel, attrs);
124
+ preventContextEvent(event, context);
125
+ return void 0;
126
+ }
127
+ // 当前行是列表行, 且折叠选区, 且在行首, 且按下退格键
128
+ // => 将当前行的列表状态移除, 保留缩进的等级
129
+ if (isKeyCode(event, KEY_CODE.BACKSPACE) &&
130
+ sel.isCollapsed &&
131
+ isBulletList(attrs) &&
132
+ !sel.start.offset) {
133
+ const delta = new Delta()
134
+ .retain(startLine.start + startLine.length - 1)
135
+ .retain(1, { [LIST_TYPE_KEY]: NIL });
136
+ this.editor.state.apply(delta, { autoCaret: false });
137
+ preventContextEvent(event, context);
138
+ return void 0;
139
+ }
140
+ }
141
+ }
142
+ __decorate([
143
+ Bind
144
+ ], BulletListPlugin.prototype, "onExec", null);
145
+ __decorate([
146
+ Bind
147
+ ], BulletListPlugin.prototype, "onKeyDown", null);
148
+
149
+ export { BulletListPlugin };
@@ -0,0 +1,6 @@
1
+ /** 无序列表插件标识 */
2
+ export declare const BULLET_LIST_KEY = "bullet-list";
3
+ /** 列表类型 key => 无序列表/有序列表 */
4
+ export declare const LIST_TYPE_KEY = "list";
5
+ /** 无序列表类型值 */
6
+ export declare const BULLET_LIST_TYPE = "bullet";
@@ -0,0 +1,8 @@
1
+ /** 无序列表插件标识 */
2
+ const BULLET_LIST_KEY = "bullet-list";
3
+ /** 列表类型 key => 无序列表/有序列表 */
4
+ const LIST_TYPE_KEY = "list";
5
+ /** 无序列表类型值 */
6
+ const BULLET_LIST_TYPE = "bullet";
7
+
8
+ export { BULLET_LIST_KEY, BULLET_LIST_TYPE, LIST_TYPE_KEY };
@@ -0,0 +1,6 @@
1
+ import type { AttributeMap } from "@block-kit/delta";
2
+ /**
3
+ * 检查无序列表
4
+ * @param attrs
5
+ */
6
+ export declare const isBulletList: (attrs: AttributeMap) => boolean;
@@ -0,0 +1,9 @@
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 BulletListView: FC<{
6
+ context: ReactLineContext;
7
+ editor: Editor;
8
+ level: number;
9
+ }>;
@@ -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 { ReactLeafContext } from "@block-kit/react";
5
+ import { EditorPlugin } from "@block-kit/react";
6
+ import type { ReactNode } from "react";
7
+ import { SelectionPlugin } from "../shared/modules/selection";
8
+ export declare class DividerPlugin extends EditorPlugin {
9
+ protected editor: Editor;
10
+ key: string;
11
+ selection: SelectionPlugin;
12
+ constructor(editor: Editor);
13
+ destroy(): void;
14
+ protected onExec(context: CMDPayload): undefined;
15
+ match(attrs: AttributeMap): boolean;
16
+ renderLeaf(context: ReactLeafContext): ReactNode;
17
+ }
@@ -0,0 +1,60 @@
1
+ import { _ as __decorate } from '../tslib.es6-83956cc1.js';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { Point, Range } from '@block-kit/core';
4
+ import { Delta } from '@block-kit/delta';
5
+ import { EditorPlugin, Void } from '@block-kit/react';
6
+ import { Bind, TRULY } from '@block-kit/utils';
7
+ import { a as SelectionPlugin, S as SelectionHOC } from '../selection-badfb0bc.js';
8
+ import { i as isEmptyLine } from '../is-3de778e2.js';
9
+ import { DIVIDER_KEY } from './types/index.js';
10
+ import 'react';
11
+
12
+ class DividerPlugin extends EditorPlugin {
13
+ constructor(editor) {
14
+ super();
15
+ this.editor = editor;
16
+ this.key = DIVIDER_KEY;
17
+ this.selection = new SelectionPlugin(editor);
18
+ editor.command.register(DIVIDER_KEY, this.onExec);
19
+ }
20
+ destroy() {
21
+ this.selection.destroy();
22
+ }
23
+ onExec(context) {
24
+ const editor = this.editor;
25
+ const sel = editor.selection.get() || context.range;
26
+ const line = sel && editor.state.block.getLine(sel.start.line);
27
+ if (!sel || !line)
28
+ return void 0;
29
+ const isEmptyTextLine = isEmptyLine(line);
30
+ let nextLineIndex = line.index + 1;
31
+ const delta = new Delta();
32
+ if (isEmptyTextLine) {
33
+ // 当前选区为空行
34
+ delta.retain(line.start);
35
+ }
36
+ else {
37
+ // 移动选区到当前行最后
38
+ delta.retain(line.start + line.length);
39
+ }
40
+ delta.insert(" ", { [DIVIDER_KEY]: TRULY }).insertEOL();
41
+ if (!isEmptyTextLine) {
42
+ nextLineIndex++;
43
+ delta.insertEOL();
44
+ }
45
+ const point = new Point(nextLineIndex, 0);
46
+ editor.state.apply(delta, { autoCaret: false });
47
+ editor.selection.set(new Range(point, point.clone()));
48
+ }
49
+ match(attrs) {
50
+ return !!attrs[DIVIDER_KEY];
51
+ }
52
+ renderLeaf(context) {
53
+ return (jsx(SelectionHOC, { selection: this.selection, leaf: context.leafState, children: jsx(Void, { tag: "div", className: "block-kit-divider-container", context: context, children: jsx("div", { className: "block-kit-divider" }) }) }));
54
+ }
55
+ }
56
+ __decorate([
57
+ Bind
58
+ ], DividerPlugin.prototype, "onExec", null);
59
+
60
+ export { DividerPlugin };
@@ -0,0 +1 @@
1
+ export declare const DIVIDER_KEY = "divider";
@@ -0,0 +1,3 @@
1
+ const DIVIDER_KEY = "divider";
2
+
3
+ export { DIVIDER_KEY };
@@ -0,0 +1,45 @@
1
+ const EDITOR_TO_DOM = new WeakMap();
2
+ /**
3
+ * 设置挂载 DOM
4
+ * @param editor
5
+ * @param dom
6
+ */
7
+ const setMountDOM = (editor, dom) => {
8
+ EDITOR_TO_DOM.set(editor, dom);
9
+ };
10
+ /**
11
+ * 获取挂载 DOM
12
+ * @param editor
13
+ * @param dom
14
+ */
15
+ const getMountDOM = (editor) => {
16
+ return EDITOR_TO_DOM.get(editor) || document.body;
17
+ };
18
+ /**
19
+ * 阻止所有编辑器分发的事件
20
+ * @param event
21
+ * @param context
22
+ */
23
+ const preventContextEvent = (event, context) => {
24
+ context.stop();
25
+ context.prevent();
26
+ event.preventDefault();
27
+ event.stopPropagation();
28
+ };
29
+ /**
30
+ * 滚动到指定元素
31
+ * @param container
32
+ * @param child
33
+ */
34
+ const scrollIfNeeded = (container, child, buffer = 0) => {
35
+ const rect = child.getBoundingClientRect();
36
+ const containerRect = container.getBoundingClientRect();
37
+ if (rect.bottom > containerRect.bottom) {
38
+ container.scrollTop = container.scrollTop + rect.bottom - containerRect.bottom + buffer;
39
+ }
40
+ else if (rect.top < containerRect.top) {
41
+ container.scrollTop = container.scrollTop - containerRect.top + rect.top - buffer;
42
+ }
43
+ };
44
+
45
+ export { setMountDOM as a, getMountDOM as g, preventContextEvent as p, scrollIfNeeded as s };
@@ -0,0 +1,16 @@
1
+ import "./styles/index.scss";
2
+ import type { CMDPayload } from "@block-kit/core";
3
+ import type { Editor } from "@block-kit/core";
4
+ import type { AttributeMap } from "@block-kit/delta";
5
+ import type { ReactLeafContext } from "@block-kit/react";
6
+ import { EditorPlugin } from "@block-kit/react";
7
+ import type { ReactNode } from "react";
8
+ export declare class EmojiPlugin extends EditorPlugin {
9
+ protected editor: Editor;
10
+ key: string;
11
+ constructor(editor: Editor);
12
+ destroy(): void;
13
+ match(attrs: AttributeMap): boolean;
14
+ onExec(payload: CMDPayload): undefined;
15
+ renderLeaf(context: ReactLeafContext): ReactNode;
16
+ }
@@ -0,0 +1,51 @@
1
+ import { _ as __decorate } from '../tslib.es6-83956cc1.js';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { RawRange } from '@block-kit/core';
4
+ import { Delta } from '@block-kit/delta';
5
+ import { EditorPlugin, Embed } from '@block-kit/react';
6
+ import { Bind } from '@block-kit/utils';
7
+ import data from '@emoji-mart/data';
8
+ import { init } from 'emoji-mart';
9
+ import { EMOJI_KEY } from './types/index.js';
10
+
11
+ class EmojiPlugin extends EditorPlugin {
12
+ constructor(editor) {
13
+ super();
14
+ this.editor = editor;
15
+ this.key = EMOJI_KEY;
16
+ init({ data });
17
+ editor.command.register(EMOJI_KEY, this.onExec);
18
+ }
19
+ destroy() { }
20
+ match(attrs) {
21
+ return !!attrs[EMOJI_KEY];
22
+ }
23
+ onExec(payload) {
24
+ const editor = this.editor;
25
+ const sel = payload.range || editor.selection.get();
26
+ if (!sel)
27
+ return void 0;
28
+ const value = payload.value;
29
+ const delta = new Delta();
30
+ const raw = RawRange.fromRange(editor, sel);
31
+ if (!raw)
32
+ return void 0;
33
+ delta
34
+ .retain(raw.start)
35
+ .delete(raw.len)
36
+ .insert(" ", { [EMOJI_KEY]: value });
37
+ editor.state.apply(delta);
38
+ }
39
+ renderLeaf(context) {
40
+ const attrs = context.attributes || {};
41
+ const id = attrs[EMOJI_KEY];
42
+ if (!id)
43
+ return context.children;
44
+ return (jsx(Embed, { className: "block-kit-emoji", context: context, children: jsx("em-emoji", { id: id }) }));
45
+ }
46
+ }
47
+ __decorate([
48
+ Bind
49
+ ], EmojiPlugin.prototype, "onExec", null);
50
+
51
+ export { EmojiPlugin };
@@ -0,0 +1 @@
1
+ export declare const EMOJI_KEY = "emoji";
@@ -0,0 +1,3 @@
1
+ const EMOJI_KEY = "emoji";
2
+
3
+ export { EMOJI_KEY };
@@ -0,0 +1,12 @@
1
+ import type { Editor } from "@block-kit/core";
2
+ import type { AttributeMap } from "@block-kit/delta";
3
+ import type { ReactLeafContext } from "@block-kit/react";
4
+ import { EditorPlugin } from "@block-kit/react";
5
+ import type { ReactNode } from "react";
6
+ export declare class FontColorPlugin extends EditorPlugin {
7
+ key: string;
8
+ destroy(): void;
9
+ constructor(editor: Editor);
10
+ match(attrs: AttributeMap): boolean;
11
+ renderLeaf(context: ReactLeafContext): ReactNode;
12
+ }
@@ -0,0 +1,27 @@
1
+ import { EditorPlugin } from '@block-kit/react';
2
+ import { FONT_COLOR_KEY } from './types/index.js';
3
+
4
+ class FontColorPlugin extends EditorPlugin {
5
+ destroy() { }
6
+ constructor(editor) {
7
+ super();
8
+ this.key = FONT_COLOR_KEY;
9
+ editor.command.register(FONT_COLOR_KEY, context => {
10
+ const sel = editor.selection.get();
11
+ sel && editor.perform.applyMarks(sel, { [FONT_COLOR_KEY]: context.value });
12
+ });
13
+ }
14
+ match(attrs) {
15
+ return !!attrs[FONT_COLOR_KEY];
16
+ }
17
+ renderLeaf(context) {
18
+ const attrs = context.attributes || {};
19
+ const color = attrs[FONT_COLOR_KEY];
20
+ if (color) {
21
+ context.style.color = color;
22
+ }
23
+ return context.children;
24
+ }
25
+ }
26
+
27
+ export { FontColorPlugin };
@@ -0,0 +1 @@
1
+ export declare const FONT_COLOR_KEY = "color";
@@ -0,0 +1,3 @@
1
+ const FONT_COLOR_KEY = "color";
2
+
3
+ export { FONT_COLOR_KEY };
@@ -0,0 +1,12 @@
1
+ import type { Editor } from "@block-kit/core";
2
+ import type { AttributeMap } from "@block-kit/delta";
3
+ import type { ReactLeafContext } from "@block-kit/react";
4
+ import { EditorPlugin } from "@block-kit/react";
5
+ import type { ReactNode } from "react";
6
+ export declare class FontSizePlugin extends EditorPlugin {
7
+ key: string;
8
+ destroy(): void;
9
+ constructor(editor: Editor);
10
+ match(attrs: AttributeMap): boolean;
11
+ renderLeaf(context: ReactLeafContext): ReactNode;
12
+ }