@use-kona/editor 0.1.3 → 0.1.5

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 (217) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.js +1 -2
  3. package/dist/plugins/CodeBlockPlugin/index.d.ts +1 -0
  4. package/dist/plugins/CommandsPlugin/Menu.js +5 -3
  5. package/dist/plugins/EmojiPlugin/Menu.js +6 -4
  6. package/dist/plugins/FloatingMenuPlugin/FloatingMenu.js +15 -28
  7. package/dist/plugins/FloatingMenuPlugin/types.d.ts +4 -1
  8. package/dist/plugins/HighlightsPlugin/HighlightsPlugin.d.ts +1 -0
  9. package/dist/plugins/HighlightsPlugin/HighlightsPlugin.js +3 -0
  10. package/dist/plugins/index.d.ts +1 -1
  11. package/package.json +12 -11
  12. package/src/index.ts +0 -1
  13. package/src/plugins/CodeBlockPlugin/index.ts +1 -0
  14. package/src/plugins/CommandsPlugin/Menu.tsx +5 -3
  15. package/src/plugins/EmojiPlugin/Menu.tsx +7 -4
  16. package/src/plugins/FloatingMenuPlugin/FloatingMenu.tsx +13 -22
  17. package/src/plugins/FloatingMenuPlugin/types.ts +4 -1
  18. package/src/plugins/HighlightsPlugin/HighlightsPlugin.tsx +4 -0
  19. package/src/plugins/index.ts +1 -1
  20. package/dist/examples/Backdrop.d.ts +0 -5
  21. package/dist/examples/Backdrop.js +0 -13
  22. package/dist/examples/Backdrop.module.js +0 -5
  23. package/dist/examples/Backdrop_module.css +0 -6
  24. package/dist/examples/CodeBlock.d.ts +0 -12
  25. package/dist/examples/CodeBlock.js +0 -163
  26. package/dist/examples/CodeBlock.module.js +0 -9
  27. package/dist/examples/CodeBlock_module.css +0 -66
  28. package/dist/examples/DragBlock.d.ts +0 -11
  29. package/dist/examples/DragBlock.js +0 -38
  30. package/dist/examples/DragBlock.module.js +0 -9
  31. package/dist/examples/DragBlock_module.css +0 -43
  32. package/dist/examples/DragHandler.d.ts +0 -2
  33. package/dist/examples/DragHandler.js +0 -44
  34. package/dist/examples/DragHandler.module.js +0 -8
  35. package/dist/examples/DragHandler_module.css +0 -18
  36. package/dist/examples/Editor.d.ts +0 -8
  37. package/dist/examples/Editor.js +0 -44
  38. package/dist/examples/Editor.module.js +0 -12
  39. package/dist/examples/Editor_module.css +0 -127
  40. package/dist/examples/Emoji.d.ts +0 -5
  41. package/dist/examples/Emoji.js +0 -8
  42. package/dist/examples/EmojiSelector.d.ts +0 -16
  43. package/dist/examples/EmojiSelector.js +0 -91
  44. package/dist/examples/EmojiSelector.module.js +0 -7
  45. package/dist/examples/EmojiSelector_module.css +0 -36
  46. package/dist/examples/FloatingMenu.d.ts +0 -19
  47. package/dist/examples/FloatingMenu.js +0 -244
  48. package/dist/examples/FloatingMenu.module.js +0 -9
  49. package/dist/examples/FloatingMenu_module.css +0 -75
  50. package/dist/examples/LinksHint.d.ts +0 -7
  51. package/dist/examples/LinksHint.js +0 -50
  52. package/dist/examples/LinksHint.module.js +0 -6
  53. package/dist/examples/LinksHint_module.css +0 -28
  54. package/dist/examples/Menu.d.ts +0 -6
  55. package/dist/examples/Menu.js +0 -94
  56. package/dist/examples/Menu.module.js +0 -8
  57. package/dist/examples/Menu_module.css +0 -38
  58. package/dist/examples/colors.d.ts +0 -10
  59. package/dist/examples/colors.js +0 -12
  60. package/dist/examples/getCommands.d.ts +0 -2
  61. package/dist/examples/getCommands.js +0 -100
  62. package/dist/examples/getPlugins.d.ts +0 -2
  63. package/dist/examples/getPlugins.js +0 -144
  64. package/dist/examples/getShortcuts.d.ts +0 -2
  65. package/dist/examples/getShortcuts.js +0 -90
  66. package/dist/examples/icons/bold.d.ts +0 -2
  67. package/dist/examples/icons/bold.js +0 -27
  68. package/dist/examples/icons/check.d.ts +0 -2
  69. package/dist/examples/icons/check.js +0 -24
  70. package/dist/examples/icons/chevronRight.d.ts +0 -2
  71. package/dist/examples/icons/chevronRight.js +0 -24
  72. package/dist/examples/icons/code.d.ts +0 -2
  73. package/dist/examples/icons/code.js +0 -30
  74. package/dist/examples/icons/color.d.ts +0 -2
  75. package/dist/examples/icons/color.js +0 -30
  76. package/dist/examples/icons/copy.d.ts +0 -2
  77. package/dist/examples/icons/copy.js +0 -27
  78. package/dist/examples/icons/cross.d.ts +0 -2
  79. package/dist/examples/icons/cross.js +0 -27
  80. package/dist/examples/icons/drag.d.ts +0 -2
  81. package/dist/examples/icons/drag.js +0 -39
  82. package/dist/examples/icons/edit.d.ts +0 -2
  83. package/dist/examples/icons/edit.js +0 -30
  84. package/dist/examples/icons/external.d.ts +0 -2
  85. package/dist/examples/icons/external.js +0 -30
  86. package/dist/examples/icons/heading1.d.ts +0 -2
  87. package/dist/examples/icons/heading1.js +0 -45
  88. package/dist/examples/icons/heading2.d.ts +0 -2
  89. package/dist/examples/icons/heading2.js +0 -45
  90. package/dist/examples/icons/heading3.d.ts +0 -2
  91. package/dist/examples/icons/heading3.js +0 -48
  92. package/dist/examples/icons/italic.d.ts +0 -2
  93. package/dist/examples/icons/italic.js +0 -30
  94. package/dist/examples/icons/link.d.ts +0 -2
  95. package/dist/examples/icons/link.js +0 -30
  96. package/dist/examples/icons/ol.d.ts +0 -2
  97. package/dist/examples/icons/ol.js +0 -36
  98. package/dist/examples/icons/strikethrough.d.ts +0 -2
  99. package/dist/examples/icons/strikethrough.js +0 -27
  100. package/dist/examples/icons/text.d.ts +0 -2
  101. package/dist/examples/icons/text.js +0 -22
  102. package/dist/examples/icons/types.d.ts +0 -3
  103. package/dist/examples/icons/types.js +0 -0
  104. package/dist/examples/icons/ul.d.ts +0 -2
  105. package/dist/examples/icons/ul.js +0 -39
  106. package/dist/examples/icons/underline.d.ts +0 -2
  107. package/dist/examples/icons/underline.js +0 -27
  108. package/dist/examples/store.d.ts +0 -9
  109. package/dist/examples/store.js +0 -7
  110. package/dist/examples/styles.module.js +0 -11
  111. package/dist/examples/styles_module.css +0 -78
  112. package/dist/examples/text.d.ts +0 -3
  113. package/dist/examples/text.js +0 -65
  114. package/dist/examples/ui/Button/Button.d.ts +0 -8
  115. package/dist/examples/ui/Button/Button.js +0 -15
  116. package/dist/examples/ui/Button/ButtonWrapper.d.ts +0 -4
  117. package/dist/examples/ui/Button/ButtonWrapper.js +0 -14
  118. package/dist/examples/ui/Button/index.d.ts +0 -2
  119. package/dist/examples/ui/Button/index.js +0 -3
  120. package/dist/examples/ui/Button/styles.module.js +0 -10
  121. package/dist/examples/ui/Button/styles_module.css +0 -72
  122. package/dist/examples/ui/Button/types.d.ts +0 -1
  123. package/dist/examples/ui/Button/types.js +0 -0
  124. package/dist/examples/ui/Dropdown/Dropdown.d.ts +0 -16
  125. package/dist/examples/ui/Dropdown/Dropdown.js +0 -75
  126. package/dist/examples/ui/Dropdown/index.d.ts +0 -1
  127. package/dist/examples/ui/Dropdown/index.js +0 -2
  128. package/dist/examples/ui/Menu/Menu.d.ts +0 -41
  129. package/dist/examples/ui/Menu/Menu.js +0 -404
  130. package/dist/examples/ui/Menu/MenuDelimiter.d.ts +0 -1
  131. package/dist/examples/ui/Menu/MenuDelimiter.js +0 -6
  132. package/dist/examples/ui/Menu/MenuHotkey.d.ts +0 -6
  133. package/dist/examples/ui/Menu/MenuHotkey.js +0 -12
  134. package/dist/examples/ui/Menu/MenuIcon.d.ts +0 -6
  135. package/dist/examples/ui/Menu/MenuIcon.js +0 -12
  136. package/dist/examples/ui/Menu/MenuItem.d.ts +0 -6
  137. package/dist/examples/ui/Menu/MenuItem.js +0 -17
  138. package/dist/examples/ui/Menu/MenuTitle.d.ts +0 -6
  139. package/dist/examples/ui/Menu/MenuTitle.js +0 -12
  140. package/dist/examples/ui/Menu/SafeSpace.d.ts +0 -6
  141. package/dist/examples/ui/Menu/SafeSpace.js +0 -65
  142. package/dist/examples/ui/Menu/index.d.ts +0 -2
  143. package/dist/examples/ui/Menu/index.js +0 -2
  144. package/dist/examples/ui/Menu/styles.module.js +0 -21
  145. package/dist/examples/ui/Menu/styles_module.css +0 -140
  146. package/dist/examples/ui/Menu/types.d.ts +0 -16
  147. package/dist/examples/ui/Menu/types.js +0 -0
  148. package/dist/examples/ui/useMenuPosition.d.ts +0 -18
  149. package/dist/examples/ui/useMenuPosition.js +0 -51
  150. package/dist/examples/ui/useMergeRefs.d.ts +0 -23
  151. package/dist/examples/ui/useMergeRefs.js +0 -11
  152. package/src/examples/Backdrop.module.css +0 -8
  153. package/src/examples/Backdrop.tsx +0 -16
  154. package/src/examples/CodeBlock.module.css +0 -65
  155. package/src/examples/CodeBlock.tsx +0 -109
  156. package/src/examples/DragBlock.module.css +0 -42
  157. package/src/examples/DragBlock.tsx +0 -57
  158. package/src/examples/DragHandler.module.css +0 -17
  159. package/src/examples/DragHandler.tsx +0 -39
  160. package/src/examples/Editor.module.css +0 -129
  161. package/src/examples/Editor.tsx +0 -68
  162. package/src/examples/Emoji.tsx +0 -9
  163. package/src/examples/EmojiSelector.module.css +0 -35
  164. package/src/examples/EmojiSelector.tsx +0 -115
  165. package/src/examples/FloatingMenu.module.css +0 -74
  166. package/src/examples/FloatingMenu.tsx +0 -278
  167. package/src/examples/LinksHint.module.css +0 -27
  168. package/src/examples/LinksHint.tsx +0 -58
  169. package/src/examples/Menu.module.css +0 -37
  170. package/src/examples/Menu.tsx +0 -94
  171. package/src/examples/colors.ts +0 -11
  172. package/src/examples/getCommands.tsx +0 -92
  173. package/src/examples/getPlugins.tsx +0 -164
  174. package/src/examples/getShortcuts.ts +0 -107
  175. package/src/examples/icons/bold.tsx +0 -20
  176. package/src/examples/icons/check.tsx +0 -19
  177. package/src/examples/icons/chevronRight.tsx +0 -19
  178. package/src/examples/icons/code.tsx +0 -21
  179. package/src/examples/icons/color.tsx +0 -23
  180. package/src/examples/icons/copy.tsx +0 -20
  181. package/src/examples/icons/cross.tsx +0 -20
  182. package/src/examples/icons/drag.tsx +0 -24
  183. package/src/examples/icons/edit.tsx +0 -21
  184. package/src/examples/icons/external.tsx +0 -21
  185. package/src/examples/icons/heading1.tsx +0 -26
  186. package/src/examples/icons/heading2.tsx +0 -26
  187. package/src/examples/icons/heading3.tsx +0 -27
  188. package/src/examples/icons/italic.tsx +0 -21
  189. package/src/examples/icons/link.tsx +0 -21
  190. package/src/examples/icons/ol.tsx +0 -23
  191. package/src/examples/icons/strikethrough.tsx +0 -20
  192. package/src/examples/icons/text.tsx +0 -18
  193. package/src/examples/icons/types.ts +0 -3
  194. package/src/examples/icons/ul.tsx +0 -24
  195. package/src/examples/icons/underline.tsx +0 -20
  196. package/src/examples/store.ts +0 -16
  197. package/src/examples/styles.module.css +0 -77
  198. package/src/examples/text.tsx +0 -138
  199. package/src/examples/ui/Button/Button.tsx +0 -34
  200. package/src/examples/ui/Button/ButtonWrapper.tsx +0 -22
  201. package/src/examples/ui/Button/index.ts +0 -2
  202. package/src/examples/ui/Button/styles.module.css +0 -75
  203. package/src/examples/ui/Button/types.ts +0 -1
  204. package/src/examples/ui/Dropdown/Dropdown.tsx +0 -101
  205. package/src/examples/ui/Dropdown/index.ts +0 -1
  206. package/src/examples/ui/Menu/Menu.tsx +0 -576
  207. package/src/examples/ui/Menu/MenuDelimiter.tsx +0 -3
  208. package/src/examples/ui/Menu/MenuHotkey.tsx +0 -17
  209. package/src/examples/ui/Menu/MenuIcon.tsx +0 -17
  210. package/src/examples/ui/Menu/MenuItem.tsx +0 -45
  211. package/src/examples/ui/Menu/MenuTitle.tsx +0 -17
  212. package/src/examples/ui/Menu/SafeSpace.tsx +0 -84
  213. package/src/examples/ui/Menu/index.ts +0 -2
  214. package/src/examples/ui/Menu/styles.module.css +0 -143
  215. package/src/examples/ui/Menu/types.ts +0 -18
  216. package/src/examples/ui/useMenuPosition.ts +0 -72
  217. package/src/examples/ui/useMergeRefs.ts +0 -39
package/dist/index.d.ts CHANGED
@@ -3,7 +3,6 @@ export { deserialize } from './core/deserialize';
3
3
  export { serialize } from './core/serialize';
4
4
  export { defaultValue } from './defaultValue';
5
5
  export * from './editor';
6
- export { ExampleEditor } from './examples/Editor';
7
6
  export * from './plugins';
8
7
  export type { EditorRef, IPlugin } from './types';
9
8
  export { isEmpty } from './utils';
package/dist/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import { deserialize } from "./core/deserialize.js";
2
2
  import { serialize } from "./core/serialize.js";
3
3
  import { defaultValue } from "./defaultValue.js";
4
- import { ExampleEditor } from "./examples/Editor.js";
5
4
  import { isEmpty } from "./utils.js";
6
5
  export * from "./editor.js";
7
6
  export * from "./plugins/index.js";
8
- export { ExampleEditor, defaultValue, deserialize, isEmpty, serialize };
7
+ export { defaultValue, deserialize, isEmpty, serialize };
@@ -1 +1,2 @@
1
1
  export { CodeBlockPlugin } from './CodeBlockPlugin';
2
+ export type { CodeElement } from './types';
@@ -16,6 +16,7 @@ const Menu = (props)=>{
16
16
  const selection = useSlateSelection();
17
17
  const editor = useSlate();
18
18
  const isFocused = useFocused();
19
+ const ref = useRef(null);
19
20
  const entry = Editor.above(editor, {
20
21
  match: (n)=>Editor.isBlock(editor, n)
21
22
  });
@@ -95,7 +96,8 @@ const Menu = (props)=>{
95
96
  }, [
96
97
  store.filter
97
98
  ]);
98
- const handleMenuLayout = (element)=>{
99
+ useLayoutEffect(()=>{
100
+ const element = ref.current;
99
101
  if (element) {
100
102
  const { height, top } = element.getBoundingClientRect();
101
103
  const domSelection = window.getSelection();
@@ -106,7 +108,7 @@ const Menu = (props)=>{
106
108
  top: `${top - height - (rect?.height ?? 22)}px`
107
109
  }));
108
110
  }
109
- };
111
+ }, []);
110
112
  if (!commands.length) return null;
111
113
  if (entry && ignoreNodes.includes(entry[0].type)) return null;
112
114
  return /*#__PURE__*/ createPortal(renderMenu(/*#__PURE__*/ jsxs(Fragment, {
@@ -118,7 +120,7 @@ const Menu = (props)=>{
118
120
  }
119
121
  }),
120
122
  /*#__PURE__*/ jsx("div", {
121
- ref: handleMenuLayout,
123
+ ref: ref,
122
124
  style: style,
123
125
  className: styles_module.menu,
124
126
  onMouseDown: (event)=>{
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useLayoutEffect, useState } from "react";
2
+ import { useLayoutEffect, useRef, useState } from "react";
3
3
  import { createPortal } from "react-dom";
4
4
  import { useFocused, useSlateSelection } from "slate-react";
5
5
  import styles_module from "./styles.module.js";
@@ -7,6 +7,7 @@ const Menu = (props)=>{
7
7
  const { isOpen, children } = props;
8
8
  const isFocused = useFocused();
9
9
  const selection = useSlateSelection();
10
+ const ref = useRef(null);
10
11
  const [style, setStyle] = useState({});
11
12
  useLayoutEffect(()=>{
12
13
  if (!selection || !isFocused) return void setStyle(void 0);
@@ -29,7 +30,8 @@ const Menu = (props)=>{
29
30
  isFocused,
30
31
  isOpen
31
32
  ]);
32
- const handleMenuLayout = (element)=>{
33
+ useLayoutEffect(()=>{
34
+ const element = ref.current;
33
35
  if (element) {
34
36
  const { height, top } = element.getBoundingClientRect();
35
37
  const domSelection = window.getSelection();
@@ -40,9 +42,9 @@ const Menu = (props)=>{
40
42
  top: `${top - height - (rect?.height ?? 22)}px`
41
43
  }));
42
44
  }
43
- };
45
+ }, []);
44
46
  return /*#__PURE__*/ createPortal(/*#__PURE__*/ jsx("div", {
45
- ref: handleMenuLayout,
47
+ ref: ref,
46
48
  style: style,
47
49
  className: styles_module.root,
48
50
  children: children
@@ -1,4 +1,4 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
1
+ import { jsx } from "react/jsx-runtime";
2
2
  import { useLayoutEffect, useRef, useState } from "react";
3
3
  import { createPortal } from "react-dom";
4
4
  import { Editor, Range } from "slate";
@@ -57,33 +57,20 @@ const FloatingMenu = (props)=>{
57
57
  });
58
58
  };
59
59
  if (!isVisible) return null;
60
- return /*#__PURE__*/ createPortal(/*#__PURE__*/ jsxs(Fragment, {
61
- children: [
62
- /*#__PURE__*/ jsx("div", {
63
- onMouseDown: ()=>{
64
- setStyle(void 0);
65
- },
66
- children: options.renderBackdrop?.({
67
- onClose,
68
- onUpdate: handleUpdate
69
- })
70
- }),
71
- /*#__PURE__*/ jsx("div", {
72
- ref: ref,
73
- style: {
74
- ...style,
75
- display: 'block'
76
- },
77
- className: styles_module.root,
78
- onMouseDown: (event)=>{
79
- event.preventDefault();
80
- },
81
- children: options.renderMenu(editor, {
82
- onClose,
83
- onUpdate: handleUpdate
84
- })
85
- })
86
- ]
60
+ return /*#__PURE__*/ createPortal(/*#__PURE__*/ jsx("div", {
61
+ ref: ref,
62
+ style: {
63
+ ...style,
64
+ display: 'block'
65
+ },
66
+ className: styles_module.root,
67
+ onMouseDown: (event)=>{
68
+ event.preventDefault();
69
+ },
70
+ children: options.renderMenu(editor, {
71
+ onClose,
72
+ onUpdate: handleUpdate
73
+ })
87
74
  }), document.body);
88
75
  };
89
76
  export { FloatingMenu };
@@ -3,7 +3,10 @@ import type { Editor } from 'slate';
3
3
  export type Options = {
4
4
  ignoreNodes?: string[];
5
5
  renderMenu: (editor: Editor, commands: Commands) => ReactNode;
6
- renderBackdrop: (commands: {
6
+ /**
7
+ * @deprecated
8
+ */
9
+ renderBackdrop?: (commands: {
7
10
  onClose: () => void;
8
11
  onUpdate: () => void;
9
12
  }) => ReactNode;
@@ -9,6 +9,7 @@ export declare class HighlightsPlugin implements IPlugin {
9
9
  constructor(options: Options);
10
10
  static toggleHighlight(editor: Editor, color: string): void;
11
11
  static isHighlightActive(editor: Editor, color: string): boolean;
12
+ static removeHighlight(editor: Editor): void;
12
13
  leafs: {
13
14
  render: (props: RenderLeafProps) => import("react/jsx-runtime").JSX.Element;
14
15
  }[];
@@ -14,6 +14,9 @@ class HighlightsPlugin {
14
14
  const marks = Editor.marks(editor);
15
15
  return marks ? marks.highlight === color : false;
16
16
  }
17
+ static removeHighlight(editor) {
18
+ Editor.removeMark(editor, 'highlight');
19
+ }
17
20
  leafs = [
18
21
  {
19
22
  render: (props)=>{
@@ -1,7 +1,7 @@
1
1
  export { AttachmentsPlugin } from './AttachmentsPlugin';
2
2
  export { BasicFormattingPlugin } from './BasicFormattingPlugin';
3
3
  export { BreaksPlugin } from './BreaksPlugin';
4
- export { CodeBlockPlugin } from './CodeBlockPlugin';
4
+ export { CodeBlockPlugin, type CodeElement } from './CodeBlockPlugin';
5
5
  export { type Command, CommandsPlugin } from './CommandsPlugin';
6
6
  export { DnDPlugin } from './DnDPlugin';
7
7
  export { EmojiPlugin } from './EmojiPlugin';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@use-kona/editor",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
@@ -22,8 +22,6 @@
22
22
  },
23
23
  "devDependencies": {
24
24
  "@biomejs/biome": "2.0.0",
25
- "@emoji-mart/data": "^1.2.1",
26
- "@emoji-mart/react": "^1.1.1",
27
25
  "@rsbuild/core": "~1.4.0",
28
26
  "@rsbuild/plugin-react": "^1.3.2",
29
27
  "@rslib/core": "^0.10.4",
@@ -41,7 +39,6 @@
41
39
  "@types/is-url": "^1.2.32",
42
40
  "@types/react": "^19.1.8",
43
41
  "@types/react-dom": "18",
44
- "emoji-mart": "^5.6.0",
45
42
  "jsdom": "^26.1.0",
46
43
  "react": "^18.3.1",
47
44
  "react-dnd": "^16.0.1",
@@ -51,13 +48,21 @@
51
48
  "storybook-addon-rslib": "^2.0.2",
52
49
  "storybook-react-rsbuild": "^2.0.2",
53
50
  "typescript": "^5.8.3",
54
- "vitest": "^3.2.4"
51
+ "vitest": "^3.2.4",
52
+ "slate": "^0.117.2",
53
+ "slate-history": "^0.113.1",
54
+ "slate-hyperscript": "^0.100.0",
55
+ "slate-react": "^0.117.3"
55
56
  },
56
57
  "peerDependencies": {
57
58
  "react": ">=16.9.0",
58
59
  "react-dnd": "^16.0.1",
59
60
  "react-dnd-html5-backend": "^16.0.1",
60
- "react-dom": "18"
61
+ "react-dom": "18",
62
+ "slate": "^0.117.2",
63
+ "slate-history": "^0.113.1",
64
+ "slate-hyperscript": "^0.100.0",
65
+ "slate-react": "^0.117.3"
61
66
  },
62
67
  "dependencies": {
63
68
  "@nanostores/react": "^1.0.0",
@@ -66,10 +71,6 @@
66
71
  "is-hotkey": "^0.2.0",
67
72
  "is-url": "^1.2.4",
68
73
  "nanostores": "^1.0.1",
69
- "prismjs": "^1.30.0",
70
- "slate": "^0.117.2",
71
- "slate-history": "^0.113.1",
72
- "slate-hyperscript": "^0.100.0",
73
- "slate-react": "^0.117.3"
74
+ "prismjs": "^1.30.0"
74
75
  }
75
76
  }
package/src/index.ts CHANGED
@@ -3,7 +3,6 @@ export { deserialize } from './core/deserialize';
3
3
  export { serialize } from './core/serialize';
4
4
  export { defaultValue } from './defaultValue';
5
5
  export * from './editor';
6
- export { ExampleEditor } from './examples/Editor';
7
6
  export * from './plugins';
8
7
  export type { EditorRef, IPlugin } from './types';
9
8
  export { isEmpty } from './utils';
@@ -1 +1,2 @@
1
1
  export { CodeBlockPlugin } from './CodeBlockPlugin';
2
+ export type { CodeElement } from './types';
@@ -35,6 +35,7 @@ export const Menu = (props: Props) => {
35
35
  const selection = useSlateSelection();
36
36
  const editor = useSlate() as Editor;
37
37
  const isFocused = useFocused();
38
+ const ref = useRef<HTMLDivElement>(null)
38
39
 
39
40
  const entry = Editor.above<CustomElement>(editor, {
40
41
  match: (n) => Editor.isBlock(editor, n as CustomElement),
@@ -137,7 +138,8 @@ export const Menu = (props: Props) => {
137
138
  }
138
139
  }, [store.filter]);
139
140
 
140
- const handleMenuLayout = (element: HTMLDivElement) => {
141
+ useLayoutEffect(() => {
142
+ const element = ref.current;
141
143
  if (element) {
142
144
  const { height, top } = element.getBoundingClientRect();
143
145
 
@@ -152,7 +154,7 @@ export const Menu = (props: Props) => {
152
154
  }));
153
155
  }
154
156
  }
155
- };
157
+ }, []);
156
158
 
157
159
  if (!commands.length) {
158
160
  return null;
@@ -174,7 +176,7 @@ export const Menu = (props: Props) => {
174
176
  />
175
177
  )}
176
178
  <div
177
- ref={handleMenuLayout}
179
+ ref={ref}
178
180
  style={style}
179
181
  className={styles.menu}
180
182
  onMouseDown={(event) => {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  type CSSProperties,
3
3
  type ReactNode,
4
- useLayoutEffect,
4
+ useLayoutEffect, useRef,
5
5
  useState,
6
6
  } from 'react';
7
7
  import { createPortal } from 'react-dom';
@@ -18,6 +18,7 @@ export const Menu = (props: Props) => {
18
18
 
19
19
  const isFocused = useFocused();
20
20
  const selection = useSlateSelection();
21
+ const ref = useRef<HTMLDivElement>(null);
21
22
 
22
23
  const [style, setStyle] = useState<CSSProperties | undefined>({});
23
24
 
@@ -48,7 +49,8 @@ export const Menu = (props: Props) => {
48
49
  }, 0);
49
50
  }, [selection, isFocused, isOpen]);
50
51
 
51
- const handleMenuLayout = (element: HTMLDivElement) => {
52
+ useLayoutEffect(() => {
53
+ const element = ref.current;
52
54
  if (element) {
53
55
  const { height, top } = element.getBoundingClientRect();
54
56
 
@@ -63,10 +65,11 @@ export const Menu = (props: Props) => {
63
65
  }));
64
66
  }
65
67
  }
66
- };
68
+ }, []);
69
+
67
70
 
68
71
  return createPortal(
69
- <div ref={handleMenuLayout} style={style} className={styles.root}>
72
+ <div ref={ref} style={style} className={styles.root}>
70
73
  {children}
71
74
  </div>,
72
75
  document.body,
@@ -117,28 +117,19 @@ export const FloatingMenu = (props: Props) => {
117
117
  }
118
118
 
119
119
  return createPortal(
120
- <>
121
- <div
122
- onMouseDown={() => {
123
- setStyle(undefined);
124
- }}
125
- >
126
- {options.renderBackdrop?.({ onClose, onUpdate: handleUpdate })}
127
- </div>
128
- <div
129
- ref={ref}
130
- style={{
131
- ...style,
132
- display: 'block',
133
- }}
134
- className={styles.root}
135
- onMouseDown={(event) => {
136
- event.preventDefault();
137
- }}
138
- >
139
- {options.renderMenu(editor, { onClose, onUpdate: handleUpdate })}
140
- </div>
141
- </>,
120
+ <div
121
+ ref={ref}
122
+ style={{
123
+ ...style,
124
+ display: 'block',
125
+ }}
126
+ className={styles.root}
127
+ onMouseDown={(event) => {
128
+ event.preventDefault();
129
+ }}
130
+ >
131
+ {options.renderMenu(editor, { onClose, onUpdate: handleUpdate })}
132
+ </div>,
142
133
  document.body,
143
134
  );
144
135
  };
@@ -4,7 +4,10 @@ import type { Editor } from 'slate';
4
4
  export type Options = {
5
5
  ignoreNodes?: string[];
6
6
  renderMenu: (editor: Editor, commands: Commands) => ReactNode;
7
- renderBackdrop: (commands: {
7
+ /**
8
+ * @deprecated
9
+ */
10
+ renderBackdrop?: (commands: {
8
11
  onClose: () => void;
9
12
  onUpdate: () => void;
10
13
  }) => ReactNode;
@@ -27,6 +27,10 @@ export class HighlightsPlugin implements IPlugin {
27
27
  return marks ? marks.highlight === color : false;
28
28
  }
29
29
 
30
+ static removeHighlight(editor: Editor) {
31
+ Editor.removeMark(editor, 'highlight');
32
+ }
33
+
30
34
  leafs = [
31
35
  {
32
36
  render: (props: RenderLeafProps) => {
@@ -1,7 +1,7 @@
1
1
  export { AttachmentsPlugin } from './AttachmentsPlugin';
2
2
  export { BasicFormattingPlugin } from './BasicFormattingPlugin';
3
3
  export { BreaksPlugin } from './BreaksPlugin';
4
- export { CodeBlockPlugin } from './CodeBlockPlugin';
4
+ export { CodeBlockPlugin, type CodeElement } from './CodeBlockPlugin';
5
5
  export { type Command, CommandsPlugin } from './CommandsPlugin';
6
6
  export { DnDPlugin } from './DnDPlugin';
7
7
  export { EmojiPlugin } from './EmojiPlugin';
@@ -1,5 +0,0 @@
1
- type Props = {
2
- onClose: () => void;
3
- };
4
- export declare const Backdrop: (props: Props) => import("react/jsx-runtime").JSX.Element | null;
5
- export {};
@@ -1,13 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { useStore } from "@nanostores/react";
3
- import Backdrop_module from "./Backdrop.module.js";
4
- import { $store } from "./store.js";
5
- const Backdrop = (props)=>{
6
- const { isFloatingMenuOpen } = useStore($store);
7
- const { onClose } = props;
8
- return isFloatingMenuOpen ? /*#__PURE__*/ jsx("div", {
9
- className: Backdrop_module.root,
10
- onClick: onClose
11
- }) : null;
12
- };
13
- export { Backdrop };
@@ -1,5 +0,0 @@
1
- import "./Backdrop_module.css";
2
- const Backdrop_module = {
3
- root: "root-f5Zwn7"
4
- };
5
- export { Backdrop_module as default };
@@ -1,6 +0,0 @@
1
- .root-f5Zwn7 {
2
- z-index: 1;
3
- position: fixed;
4
- inset: 0;
5
- }
6
-
@@ -1,12 +0,0 @@
1
- import { type ReactNode } from 'react';
2
- import type { CustomElement } from '../../types';
3
- type Props = {
4
- value: string;
5
- onChange: (value: string) => void;
6
- params: {
7
- element: CustomElement;
8
- Content: () => ReactNode;
9
- };
10
- };
11
- export declare const CodeBlock: (props: Props) => import("react/jsx-runtime").JSX.Element;
12
- export {};
@@ -1,163 +0,0 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { forwardRef, useMemo } from "react";
3
- import { Node } from "slate";
4
- import CodeBlock_module from "./CodeBlock.module.js";
5
- import { CheckIcon } from "./icons/check.js";
6
- import { CopyIcon } from "./icons/copy.js";
7
- import { Button } from "./ui/Button/index.js";
8
- import { Dropdown } from "./ui/Dropdown/index.js";
9
- import { Menu } from "./ui/Menu/index.js";
10
- const languages = [
11
- {
12
- value: "javascript",
13
- label: 'JavaScript'
14
- },
15
- {
16
- value: "typescript",
17
- label: 'TypeScript'
18
- },
19
- {
20
- value: 'jsx',
21
- label: 'JSX'
22
- },
23
- {
24
- value: 'tsx',
25
- label: 'TSX'
26
- },
27
- {
28
- value: 'html',
29
- label: 'HTML'
30
- },
31
- {
32
- value: 'css',
33
- label: 'CSS'
34
- },
35
- {
36
- value: 'json',
37
- label: 'JSON'
38
- },
39
- {
40
- value: 'python',
41
- label: 'Python'
42
- },
43
- {
44
- value: 'java',
45
- label: 'Java'
46
- },
47
- {
48
- value: 'c',
49
- label: 'C'
50
- },
51
- {
52
- value: 'cpp',
53
- label: 'C++'
54
- },
55
- {
56
- value: 'csharp',
57
- label: 'C#'
58
- },
59
- {
60
- value: 'go',
61
- label: 'Go'
62
- },
63
- {
64
- value: 'rust',
65
- label: 'Rust'
66
- },
67
- {
68
- value: 'ruby',
69
- label: 'Ruby'
70
- },
71
- {
72
- value: 'php',
73
- label: 'PHP'
74
- },
75
- {
76
- value: 'bash',
77
- label: 'Bash'
78
- },
79
- {
80
- value: 'sql',
81
- label: 'SQL'
82
- },
83
- {
84
- value: 'markdown',
85
- label: 'Markdown'
86
- },
87
- {
88
- value: 'yaml',
89
- label: 'YAML'
90
- },
91
- {
92
- value: 'plaintext',
93
- label: 'Plain Text'
94
- }
95
- ];
96
- const CodeBlock = (props)=>{
97
- const { value: language, onChange, params: { element, Content } } = props;
98
- const handleCopyClick = ()=>{
99
- const text = Array.from(Node.texts(element)).map((nodeEntry)=>nodeEntry[0].text).join('\n');
100
- navigator.clipboard.writeText(text);
101
- };
102
- const menuConfig = useMemo(()=>({
103
- items: languages.map(({ label, value })=>({
104
- render: ()=>/*#__PURE__*/ jsxs(Fragment, {
105
- children: [
106
- /*#__PURE__*/ jsx(Menu.Icon, {
107
- children: value === language && /*#__PURE__*/ jsx(CheckIcon, {
108
- size: 16
109
- })
110
- }),
111
- /*#__PURE__*/ jsx(Menu.Title, {
112
- children: label
113
- })
114
- ]
115
- }),
116
- onSelect: ()=>{
117
- onChange(value);
118
- }
119
- }))
120
- }), [
121
- language
122
- ]);
123
- return /*#__PURE__*/ jsxs("div", {
124
- className: CodeBlock_module.root,
125
- children: [
126
- /*#__PURE__*/ jsxs("div", {
127
- className: CodeBlock_module.menu,
128
- children: [
129
- /*#__PURE__*/ jsx(Dropdown, {
130
- config: menuConfig,
131
- Menu: /*#__PURE__*/ forwardRef((props, ref)=>/*#__PURE__*/ jsx("div", {
132
- ...props,
133
- ref: ref,
134
- className: [
135
- CodeBlock_module.customMenu,
136
- props.className
137
- ].join(' ')
138
- })),
139
- children: ({ ref, onClick })=>/*#__PURE__*/ jsx(Button, {
140
- ref: ref,
141
- size: "sm",
142
- onClick: onClick,
143
- children: languages.find((l)=>l.value === language)?.label || 'Select language'
144
- })
145
- }),
146
- /*#__PURE__*/ jsx(Button, {
147
- size: "sm",
148
- type: "button",
149
- onClick: handleCopyClick,
150
- children: /*#__PURE__*/ jsx(CopyIcon, {
151
- size: 16
152
- })
153
- })
154
- ]
155
- }),
156
- /*#__PURE__*/ jsx("div", {
157
- className: CodeBlock_module.content,
158
- children: /*#__PURE__*/ jsx(Content, {})
159
- })
160
- ]
161
- });
162
- };
163
- export { CodeBlock };
@@ -1,9 +0,0 @@
1
- import "./CodeBlock_module.css";
2
- const CodeBlock_module = {
3
- root: "root-qalHKY",
4
- button: "button-NFVN8i",
5
- menu: "menu-tWodT1",
6
- content: "content-vvTcTm",
7
- customMenu: "customMenu-PLCVVP"
8
- };
9
- export { CodeBlock_module as default };