@use-kona/editor 0.1.3 → 0.1.4

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 (213) 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/FloatingMenuPlugin/FloatingMenu.js +15 -28
  5. package/dist/plugins/FloatingMenuPlugin/types.d.ts +4 -1
  6. package/dist/plugins/HighlightsPlugin/HighlightsPlugin.d.ts +1 -0
  7. package/dist/plugins/HighlightsPlugin/HighlightsPlugin.js +3 -0
  8. package/dist/plugins/index.d.ts +1 -1
  9. package/package.json +12 -11
  10. package/src/index.ts +0 -1
  11. package/src/plugins/CodeBlockPlugin/index.ts +1 -0
  12. package/src/plugins/FloatingMenuPlugin/FloatingMenu.tsx +13 -22
  13. package/src/plugins/FloatingMenuPlugin/types.ts +4 -1
  14. package/src/plugins/HighlightsPlugin/HighlightsPlugin.tsx +4 -0
  15. package/src/plugins/index.ts +1 -1
  16. package/dist/examples/Backdrop.d.ts +0 -5
  17. package/dist/examples/Backdrop.js +0 -13
  18. package/dist/examples/Backdrop.module.js +0 -5
  19. package/dist/examples/Backdrop_module.css +0 -6
  20. package/dist/examples/CodeBlock.d.ts +0 -12
  21. package/dist/examples/CodeBlock.js +0 -163
  22. package/dist/examples/CodeBlock.module.js +0 -9
  23. package/dist/examples/CodeBlock_module.css +0 -66
  24. package/dist/examples/DragBlock.d.ts +0 -11
  25. package/dist/examples/DragBlock.js +0 -38
  26. package/dist/examples/DragBlock.module.js +0 -9
  27. package/dist/examples/DragBlock_module.css +0 -43
  28. package/dist/examples/DragHandler.d.ts +0 -2
  29. package/dist/examples/DragHandler.js +0 -44
  30. package/dist/examples/DragHandler.module.js +0 -8
  31. package/dist/examples/DragHandler_module.css +0 -18
  32. package/dist/examples/Editor.d.ts +0 -8
  33. package/dist/examples/Editor.js +0 -44
  34. package/dist/examples/Editor.module.js +0 -12
  35. package/dist/examples/Editor_module.css +0 -127
  36. package/dist/examples/Emoji.d.ts +0 -5
  37. package/dist/examples/Emoji.js +0 -8
  38. package/dist/examples/EmojiSelector.d.ts +0 -16
  39. package/dist/examples/EmojiSelector.js +0 -91
  40. package/dist/examples/EmojiSelector.module.js +0 -7
  41. package/dist/examples/EmojiSelector_module.css +0 -36
  42. package/dist/examples/FloatingMenu.d.ts +0 -19
  43. package/dist/examples/FloatingMenu.js +0 -244
  44. package/dist/examples/FloatingMenu.module.js +0 -9
  45. package/dist/examples/FloatingMenu_module.css +0 -75
  46. package/dist/examples/LinksHint.d.ts +0 -7
  47. package/dist/examples/LinksHint.js +0 -50
  48. package/dist/examples/LinksHint.module.js +0 -6
  49. package/dist/examples/LinksHint_module.css +0 -28
  50. package/dist/examples/Menu.d.ts +0 -6
  51. package/dist/examples/Menu.js +0 -94
  52. package/dist/examples/Menu.module.js +0 -8
  53. package/dist/examples/Menu_module.css +0 -38
  54. package/dist/examples/colors.d.ts +0 -10
  55. package/dist/examples/colors.js +0 -12
  56. package/dist/examples/getCommands.d.ts +0 -2
  57. package/dist/examples/getCommands.js +0 -100
  58. package/dist/examples/getPlugins.d.ts +0 -2
  59. package/dist/examples/getPlugins.js +0 -144
  60. package/dist/examples/getShortcuts.d.ts +0 -2
  61. package/dist/examples/getShortcuts.js +0 -90
  62. package/dist/examples/icons/bold.d.ts +0 -2
  63. package/dist/examples/icons/bold.js +0 -27
  64. package/dist/examples/icons/check.d.ts +0 -2
  65. package/dist/examples/icons/check.js +0 -24
  66. package/dist/examples/icons/chevronRight.d.ts +0 -2
  67. package/dist/examples/icons/chevronRight.js +0 -24
  68. package/dist/examples/icons/code.d.ts +0 -2
  69. package/dist/examples/icons/code.js +0 -30
  70. package/dist/examples/icons/color.d.ts +0 -2
  71. package/dist/examples/icons/color.js +0 -30
  72. package/dist/examples/icons/copy.d.ts +0 -2
  73. package/dist/examples/icons/copy.js +0 -27
  74. package/dist/examples/icons/cross.d.ts +0 -2
  75. package/dist/examples/icons/cross.js +0 -27
  76. package/dist/examples/icons/drag.d.ts +0 -2
  77. package/dist/examples/icons/drag.js +0 -39
  78. package/dist/examples/icons/edit.d.ts +0 -2
  79. package/dist/examples/icons/edit.js +0 -30
  80. package/dist/examples/icons/external.d.ts +0 -2
  81. package/dist/examples/icons/external.js +0 -30
  82. package/dist/examples/icons/heading1.d.ts +0 -2
  83. package/dist/examples/icons/heading1.js +0 -45
  84. package/dist/examples/icons/heading2.d.ts +0 -2
  85. package/dist/examples/icons/heading2.js +0 -45
  86. package/dist/examples/icons/heading3.d.ts +0 -2
  87. package/dist/examples/icons/heading3.js +0 -48
  88. package/dist/examples/icons/italic.d.ts +0 -2
  89. package/dist/examples/icons/italic.js +0 -30
  90. package/dist/examples/icons/link.d.ts +0 -2
  91. package/dist/examples/icons/link.js +0 -30
  92. package/dist/examples/icons/ol.d.ts +0 -2
  93. package/dist/examples/icons/ol.js +0 -36
  94. package/dist/examples/icons/strikethrough.d.ts +0 -2
  95. package/dist/examples/icons/strikethrough.js +0 -27
  96. package/dist/examples/icons/text.d.ts +0 -2
  97. package/dist/examples/icons/text.js +0 -22
  98. package/dist/examples/icons/types.d.ts +0 -3
  99. package/dist/examples/icons/types.js +0 -0
  100. package/dist/examples/icons/ul.d.ts +0 -2
  101. package/dist/examples/icons/ul.js +0 -39
  102. package/dist/examples/icons/underline.d.ts +0 -2
  103. package/dist/examples/icons/underline.js +0 -27
  104. package/dist/examples/store.d.ts +0 -9
  105. package/dist/examples/store.js +0 -7
  106. package/dist/examples/styles.module.js +0 -11
  107. package/dist/examples/styles_module.css +0 -78
  108. package/dist/examples/text.d.ts +0 -3
  109. package/dist/examples/text.js +0 -65
  110. package/dist/examples/ui/Button/Button.d.ts +0 -8
  111. package/dist/examples/ui/Button/Button.js +0 -15
  112. package/dist/examples/ui/Button/ButtonWrapper.d.ts +0 -4
  113. package/dist/examples/ui/Button/ButtonWrapper.js +0 -14
  114. package/dist/examples/ui/Button/index.d.ts +0 -2
  115. package/dist/examples/ui/Button/index.js +0 -3
  116. package/dist/examples/ui/Button/styles.module.js +0 -10
  117. package/dist/examples/ui/Button/styles_module.css +0 -72
  118. package/dist/examples/ui/Button/types.d.ts +0 -1
  119. package/dist/examples/ui/Button/types.js +0 -0
  120. package/dist/examples/ui/Dropdown/Dropdown.d.ts +0 -16
  121. package/dist/examples/ui/Dropdown/Dropdown.js +0 -75
  122. package/dist/examples/ui/Dropdown/index.d.ts +0 -1
  123. package/dist/examples/ui/Dropdown/index.js +0 -2
  124. package/dist/examples/ui/Menu/Menu.d.ts +0 -41
  125. package/dist/examples/ui/Menu/Menu.js +0 -404
  126. package/dist/examples/ui/Menu/MenuDelimiter.d.ts +0 -1
  127. package/dist/examples/ui/Menu/MenuDelimiter.js +0 -6
  128. package/dist/examples/ui/Menu/MenuHotkey.d.ts +0 -6
  129. package/dist/examples/ui/Menu/MenuHotkey.js +0 -12
  130. package/dist/examples/ui/Menu/MenuIcon.d.ts +0 -6
  131. package/dist/examples/ui/Menu/MenuIcon.js +0 -12
  132. package/dist/examples/ui/Menu/MenuItem.d.ts +0 -6
  133. package/dist/examples/ui/Menu/MenuItem.js +0 -17
  134. package/dist/examples/ui/Menu/MenuTitle.d.ts +0 -6
  135. package/dist/examples/ui/Menu/MenuTitle.js +0 -12
  136. package/dist/examples/ui/Menu/SafeSpace.d.ts +0 -6
  137. package/dist/examples/ui/Menu/SafeSpace.js +0 -65
  138. package/dist/examples/ui/Menu/index.d.ts +0 -2
  139. package/dist/examples/ui/Menu/index.js +0 -2
  140. package/dist/examples/ui/Menu/styles.module.js +0 -21
  141. package/dist/examples/ui/Menu/styles_module.css +0 -140
  142. package/dist/examples/ui/Menu/types.d.ts +0 -16
  143. package/dist/examples/ui/Menu/types.js +0 -0
  144. package/dist/examples/ui/useMenuPosition.d.ts +0 -18
  145. package/dist/examples/ui/useMenuPosition.js +0 -51
  146. package/dist/examples/ui/useMergeRefs.d.ts +0 -23
  147. package/dist/examples/ui/useMergeRefs.js +0 -11
  148. package/src/examples/Backdrop.module.css +0 -8
  149. package/src/examples/Backdrop.tsx +0 -16
  150. package/src/examples/CodeBlock.module.css +0 -65
  151. package/src/examples/CodeBlock.tsx +0 -109
  152. package/src/examples/DragBlock.module.css +0 -42
  153. package/src/examples/DragBlock.tsx +0 -57
  154. package/src/examples/DragHandler.module.css +0 -17
  155. package/src/examples/DragHandler.tsx +0 -39
  156. package/src/examples/Editor.module.css +0 -129
  157. package/src/examples/Editor.tsx +0 -68
  158. package/src/examples/Emoji.tsx +0 -9
  159. package/src/examples/EmojiSelector.module.css +0 -35
  160. package/src/examples/EmojiSelector.tsx +0 -115
  161. package/src/examples/FloatingMenu.module.css +0 -74
  162. package/src/examples/FloatingMenu.tsx +0 -278
  163. package/src/examples/LinksHint.module.css +0 -27
  164. package/src/examples/LinksHint.tsx +0 -58
  165. package/src/examples/Menu.module.css +0 -37
  166. package/src/examples/Menu.tsx +0 -94
  167. package/src/examples/colors.ts +0 -11
  168. package/src/examples/getCommands.tsx +0 -92
  169. package/src/examples/getPlugins.tsx +0 -164
  170. package/src/examples/getShortcuts.ts +0 -107
  171. package/src/examples/icons/bold.tsx +0 -20
  172. package/src/examples/icons/check.tsx +0 -19
  173. package/src/examples/icons/chevronRight.tsx +0 -19
  174. package/src/examples/icons/code.tsx +0 -21
  175. package/src/examples/icons/color.tsx +0 -23
  176. package/src/examples/icons/copy.tsx +0 -20
  177. package/src/examples/icons/cross.tsx +0 -20
  178. package/src/examples/icons/drag.tsx +0 -24
  179. package/src/examples/icons/edit.tsx +0 -21
  180. package/src/examples/icons/external.tsx +0 -21
  181. package/src/examples/icons/heading1.tsx +0 -26
  182. package/src/examples/icons/heading2.tsx +0 -26
  183. package/src/examples/icons/heading3.tsx +0 -27
  184. package/src/examples/icons/italic.tsx +0 -21
  185. package/src/examples/icons/link.tsx +0 -21
  186. package/src/examples/icons/ol.tsx +0 -23
  187. package/src/examples/icons/strikethrough.tsx +0 -20
  188. package/src/examples/icons/text.tsx +0 -18
  189. package/src/examples/icons/types.ts +0 -3
  190. package/src/examples/icons/ul.tsx +0 -24
  191. package/src/examples/icons/underline.tsx +0 -20
  192. package/src/examples/store.ts +0 -16
  193. package/src/examples/styles.module.css +0 -77
  194. package/src/examples/text.tsx +0 -138
  195. package/src/examples/ui/Button/Button.tsx +0 -34
  196. package/src/examples/ui/Button/ButtonWrapper.tsx +0 -22
  197. package/src/examples/ui/Button/index.ts +0 -2
  198. package/src/examples/ui/Button/styles.module.css +0 -75
  199. package/src/examples/ui/Button/types.ts +0 -1
  200. package/src/examples/ui/Dropdown/Dropdown.tsx +0 -101
  201. package/src/examples/ui/Dropdown/index.ts +0 -1
  202. package/src/examples/ui/Menu/Menu.tsx +0 -576
  203. package/src/examples/ui/Menu/MenuDelimiter.tsx +0 -3
  204. package/src/examples/ui/Menu/MenuHotkey.tsx +0 -17
  205. package/src/examples/ui/Menu/MenuIcon.tsx +0 -17
  206. package/src/examples/ui/Menu/MenuItem.tsx +0 -45
  207. package/src/examples/ui/Menu/MenuTitle.tsx +0 -17
  208. package/src/examples/ui/Menu/SafeSpace.tsx +0 -84
  209. package/src/examples/ui/Menu/index.ts +0 -2
  210. package/src/examples/ui/Menu/styles.module.css +0 -143
  211. package/src/examples/ui/Menu/types.ts +0 -18
  212. package/src/examples/ui/useMenuPosition.ts +0 -72
  213. package/src/examples/ui/useMergeRefs.ts +0 -39
@@ -1,42 +0,0 @@
1
- .root {
2
- position: relative;
3
- border-top: 2px solid transparent;
4
- border-bottom: 2px solid transparent;
5
- }
6
-
7
- .top {
8
- border-top: 2px solid #3498db;
9
- }
10
-
11
- .bottom {
12
- border-bottom: 2px solid #3498db;
13
- }
14
-
15
- .drag {
16
- display: inline-block;
17
- vertical-align: baseline;
18
- width: 16px;
19
- cursor: move;
20
- line-height: 1.2;
21
- opacity: 0;
22
- transition: opacity 0.25s;
23
- }
24
-
25
- .block {
26
- position: relative;
27
- border-radius: 4px;
28
- display: grid;
29
- grid-template-columns: 16px 1fr;
30
- column-gap: 8px;
31
- align-items: start;
32
- padding: 4px 8px 4px 8px;
33
- transition: background-color 0.25s;
34
-
35
- &:hover {
36
- background-color: rgba(0, 0, 0, 0.015);
37
- }
38
-
39
- &:hover .drag {
40
- opacity: 1;
41
- }
42
- }
@@ -1,57 +0,0 @@
1
- import cn from 'clsx';
2
- import type {
3
- ConnectDragPreview,
4
- ConnectDragSource,
5
- ConnectDropTarget,
6
- } from 'react-dnd';
7
- import type { RenderElementProps } from 'slate-react';
8
- import styles from './DragBlock.module.css';
9
- import { DragHandler } from './DragHandler';
10
-
11
- type Props = {
12
- props: RenderElementProps;
13
- dragRef: ConnectDragSource;
14
- dropRef: ConnectDropTarget;
15
- previewRef: ConnectDragPreview;
16
- position: 'top' | 'bottom' | null;
17
- };
18
-
19
- export const DragBlock = (props: Props) => {
20
- const {
21
- props: { attributes, element, children },
22
- dragRef: drag,
23
- dropRef: drop,
24
- previewRef: preview,
25
- position,
26
- } = props;
27
-
28
- return (
29
- <div
30
- className={cn(styles.root, {
31
- [styles.top]: position === 'top',
32
- [styles.bottom]: position === 'bottom',
33
- })}
34
- {...attributes}
35
- >
36
- <div
37
- className={styles.block}
38
- ref={(e) => {
39
- drop(preview(e));
40
- }}
41
- >
42
- <div
43
- className={styles.drag}
44
- ref={(element) => {
45
- drag(element);
46
- }}
47
- contentEditable={false}
48
- >
49
- <DragHandler attributes={attributes} element={element}>
50
- {children}
51
- </DragHandler>
52
- </div>
53
- <div>{children}</div>
54
- </div>
55
- </div>
56
- );
57
- };
@@ -1,17 +0,0 @@
1
- .dragHandler {
2
- position: absolute;
3
- cursor: grab;
4
- top: 9px;
5
- }
6
-
7
- .dragHandlerHeading1 {
8
- top: 10px;
9
- }
10
-
11
- .dragHandlerHeading2 {
12
- top: 8px;
13
- }
14
-
15
- .dragHandlerHeading3 {
16
- top: 6px;
17
- }
@@ -1,39 +0,0 @@
1
- import type { RenderElementProps } from 'slate-react';
2
- import { HeadingsPlugin, ListsPlugin } from '../plugins';
3
- import styles from './DragHandler.module.css';
4
- import { DragIcon } from './icons/drag';
5
-
6
- export const DragHandler = (props: RenderElementProps) => {
7
- switch (props.element.type) {
8
- case ListsPlugin.LIST_ITEM_ELEMENT:
9
- return (
10
- <div className={styles.dragHandler}>
11
- <DragIcon size={16} />
12
- </div>
13
- );
14
- case HeadingsPlugin.HeadingLevel1:
15
- return (
16
- <div className={styles.dragHandlerHeading1}>
17
- <DragIcon size={16} />
18
- </div>
19
- );
20
- case HeadingsPlugin.HeadingLevel2:
21
- return (
22
- <div className={styles.dragHandlerHeading2}>
23
- <DragIcon size={16} />
24
- </div>
25
- );
26
- case HeadingsPlugin.HeadingLevel3:
27
- return (
28
- <div className={styles.dragHandlerHeading3}>
29
- <DragIcon size={16} />
30
- </div>
31
- );
32
- default:
33
- return (
34
- <div className={styles.dragHandler}>
35
- <DragIcon size={16} />
36
- </div>
37
- );
38
- }
39
- };
@@ -1,129 +0,0 @@
1
- .root {
2
- width: 600px;
3
- height: calc(100vh - 128px * 2);
4
- overflow: hidden;
5
- max-height: 100vh;
6
- border: 1px solid var(--kona-editor-border-color);
7
- border-radius: 8px;
8
- }
9
-
10
- .root {
11
- [role="textbox"] {
12
- outline: none;
13
- padding: 16px 16px;
14
- }
15
-
16
- h1 {
17
- font-size: 24px;
18
- font-weight: 600;
19
- }
20
-
21
- h2 {
22
- font-size: 20px;
23
- font-weight: 600;
24
- }
25
-
26
- h3 {
27
- font-size: 18px;
28
- font-weight: 600;
29
- }
30
-
31
- ol {
32
- list-style: decimal;
33
- }
34
-
35
- ul {
36
- list-style: disc;
37
- }
38
-
39
- li {
40
- list-style-position: inside;
41
- }
42
- }
43
-
44
- .button {
45
- width: 24px;
46
- height: 24px;
47
- border-radius: 4px;
48
- cursor: pointer;
49
- padding: 0;
50
- margin: 0;
51
- outline: none;
52
- background-color: transparent;
53
- border: none;
54
- display: inline-flex;
55
- align-items: center;
56
- justify-content: center;
57
- color: inherit;
58
- transition: background-color 0.25s;
59
- }
60
-
61
- .button.active {
62
- background-color: #eee;
63
- }
64
-
65
- .divider {
66
- display: inline-block;
67
- background-color: #ccc;
68
- width: 1px;
69
- height: 24px;
70
- }
71
-
72
- .floating {
73
- height: 24px;
74
- }
75
-
76
- .hint {
77
- background-color: var(--background-color);
78
- color: var(--text-color);
79
- padding: 2px;
80
- border-radius: 4px;
81
- border: 1px solid var(--border-color);
82
- }
83
-
84
- .editorToolbar {
85
- display: flex;
86
- justify-content: space-between;
87
- column-gap: 4px;
88
- padding: 8px;
89
- background-color: #f9f9f9;
90
-
91
- & select {
92
- border: 1px solid #ddd;
93
- border-radius: 4px;
94
- padding: 4px;
95
- background-color: #fff;
96
- color: inherit;
97
- outline: none;
98
- }
99
-
100
- & button {
101
- border: 1px solid #ddd;
102
- border-radius: 4px;
103
- display: inline-flex;
104
- align-items: center;
105
- padding: 4px;
106
- background-color: #fff;
107
- cursor: pointer;
108
- color: inherit;
109
- outline: none;
110
- }
111
- }
112
-
113
- .backdrop {
114
- position: fixed;
115
- top: 0;
116
- left: 0;
117
- right: 0;
118
- bottom: 0;
119
- z-index: 1;
120
- }
121
-
122
- .hint {
123
- background-color: #fff;
124
- color: #444;
125
- padding: 2px;
126
- border-radius: 4px;
127
- border: 1px solid #ccc;
128
- box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.06);
129
- }
@@ -1,68 +0,0 @@
1
- import {
2
- forwardRef,
3
- useEffect,
4
- useImperativeHandle,
5
- useRef,
6
- useState,
7
- } from 'react';
8
- import { DndProvider } from 'react-dnd';
9
- import { HTML5Backend } from 'react-dnd-html5-backend';
10
- import type { Descendant } from 'slate';
11
- import type { CustomElement } from '../../types';
12
- import { deserialize } from '../core/deserialize';
13
- import { serialize } from '../core/serialize';
14
- import { KonaEditor } from '../editor';
15
- import type { EditorRef } from '../types';
16
- import styles from './Editor.module.css';
17
- import { getPlugins } from './getPlugins';
18
- import { text } from './text';
19
-
20
- const initialValue = text;
21
-
22
- type Props = {
23
- initialValueType?: 'kona-editor' | 'html';
24
- value?: any;
25
- onChange?: (value: Descendant[]) => void;
26
- };
27
-
28
- export const ExampleEditor = forwardRef((props: Props, ref) => {
29
- const { value: defaultValue = text, initialValueType = 'kona-editor' } =
30
- props;
31
- const [plugins] = useState(getPlugins());
32
- const [value, setValue] = useState<Descendant[] | null>(null);
33
-
34
- const editorRef = useRef<EditorRef>(null);
35
-
36
- useImperativeHandle(
37
- ref,
38
- () => ({
39
- serialize: serialize(plugins),
40
- }),
41
- [plugins],
42
- );
43
-
44
- // biome-ignore lint/correctness/useExhaustiveDependencies: only on init
45
- useEffect(() => {
46
- if (initialValueType === 'kona-editor') {
47
- setValue(defaultValue);
48
- } else {
49
- const parsed = deserialize(plugins)(defaultValue);
50
- parsed && setValue(parsed as Descendant[]);
51
- }
52
- }, []);
53
-
54
- return (
55
- <DndProvider backend={HTML5Backend}>
56
- <div className={[styles.root].join(' ')}>
57
- {value && (
58
- <KonaEditor
59
- ref={editorRef}
60
- initialValue={value || (initialValue as CustomElement[])}
61
- plugins={plugins}
62
- onChange={props.onChange || console.log}
63
- />
64
- )}
65
- </div>
66
- </DndProvider>
67
- );
68
- });
@@ -1,9 +0,0 @@
1
- import styles from './EmojiSelector.module.css';
2
-
3
- type Props = {
4
- id: string;
5
- };
6
-
7
- export const Emoji = (props: Props) => {
8
- return <em-emoji class={styles.emoji} id={props.id} size="16px" />;
9
- };
@@ -1,35 +0,0 @@
1
- .root {
2
- display: flex;
3
- gap: 4px;
4
- background-color: var(--kona-editor-background-color);
5
- border: 1px solid var(--kona-editor-border-color);
6
- border-radius: 8px;
7
- padding: 4px 4px;
8
- }
9
-
10
- .emoji {
11
- width: 24px;
12
- height: 24px;
13
- display: inline-flex;
14
- align-items: center;
15
- justify-content: center;
16
- cursor: pointer;
17
- border-radius: 4px;
18
- vertical-align: text-bottom;
19
-
20
- & span {
21
- display: inline-flex;
22
- align-items: center;
23
- justify-content: center;
24
- height: 20px;
25
- width: 20px;
26
- }
27
-
28
- &:hover {
29
- background-color: var(--kona-editor-alt-background-color);
30
- }
31
- }
32
-
33
- .selected {
34
- background-color: var(--kona-editor-alt-background-color);
35
- }
@@ -1,115 +0,0 @@
1
- /** biome-ignore-all lint/nursery/useUniqueElementIds: em-emoji uses id */
2
- import data from '@emoji-mart/data';
3
- import { useStore } from '@nanostores/react';
4
- import clsx from 'clsx';
5
- import { init, SearchIndex } from 'emoji-mart';
6
- import { useEffect, useState } from 'react';
7
- import { useSlateStatic } from 'slate-react';
8
- import styles from './EmojiSelector.module.css';
9
- import { $store } from './store';
10
-
11
- init({
12
- data,
13
- set: 'apple',
14
- custom: [
15
- {
16
- id: 'custom',
17
- name: 'Custom',
18
- emojis: [
19
- {
20
- id: 'kona',
21
- name: 'Kona',
22
- keywords: ['kona'],
23
- skins: [{ src: '/kona.svg' }],
24
- },
25
- ],
26
- },
27
- ],
28
- });
29
-
30
- declare module 'react/jsx-runtime' {
31
- namespace JSX {
32
- interface IntrinsicElements {
33
- 'em-emoji': {
34
- id: string;
35
- size: string | number;
36
- class?: string;
37
- };
38
- }
39
- }
40
- }
41
-
42
- type Props = {
43
- onConfirm: (emoji, query, editor) => void;
44
- };
45
-
46
- export const EmojiSelector = (props: Props) => {
47
- const { onConfirm } = props;
48
-
49
- const editor = useSlateStatic();
50
-
51
- const { emojiSearch } = useStore($store);
52
- const [index, setIndex] = useState(-1);
53
-
54
- const [items, setItems] = useState<
55
- Array<{
56
- id: string;
57
- }>
58
- >([]);
59
-
60
- useEffect(() => {
61
- const search = async () => {
62
- const emojis = await SearchIndex.search(emojiSearch);
63
-
64
- setItems(emojis.slice(0, 10));
65
- setIndex(0);
66
- };
67
-
68
- search();
69
- }, [emojiSearch]);
70
-
71
- // biome-ignore lint/correctness/useExhaustiveDependencies: we don't need onConfirm
72
- useEffect(() => {
73
- const handleKeyDown = (event: KeyboardEvent) => {
74
- switch (event.key) {
75
- case 'ArrowRight':
76
- event.preventDefault();
77
- setIndex((index) => (index + 1) % items.length);
78
- break;
79
- case 'ArrowLeft':
80
- event.preventDefault();
81
- setIndex((index) => (index - 1 + items.length) % items.length);
82
- break;
83
- case 'Enter':
84
- event.preventDefault();
85
- onConfirm(items[index]?.id, emojiSearch, editor);
86
- break;
87
- }
88
- };
89
-
90
- document.addEventListener('keydown', handleKeyDown, true);
91
-
92
- return () => {
93
- document.removeEventListener('keydown', handleKeyDown, true);
94
- };
95
- }, [items, index, emojiSearch]);
96
-
97
- if (!items.length) {
98
- return null;
99
- }
100
-
101
- return (
102
- <div className={styles.root}>
103
- {items.map((item, idx) => {
104
- return (
105
- <span
106
- className={clsx(styles.emoji, { [styles.selected]: idx === index })}
107
- key={item.id}
108
- >
109
- <em-emoji class={styles.emoji} id={item.id} size="20px" />
110
- </span>
111
- );
112
- })}
113
- </div>
114
- );
115
- };
@@ -1,74 +0,0 @@
1
- .root {
2
- height: 24px;
3
- background-color: var(--kona-editor-background-color);
4
- border: 1px solid var(--kona-editor-border-color);
5
- border-radius: 4px;
6
- overflow: hidden;
7
- z-index: 2;
8
- }
9
-
10
- .button {
11
- width: 24px;
12
- height: 24px;
13
- cursor: pointer;
14
- padding: 0;
15
- margin: 0;
16
- outline: none;
17
- background-color: transparent;
18
- border: none;
19
- display: inline-flex;
20
- align-items: center;
21
- justify-content: center;
22
- color: inherit;
23
- transition: opacity 0.25s;
24
- opacity: 0.65;
25
- }
26
-
27
- .button.active {
28
- opacity: 1;
29
- }
30
-
31
- .button:first-child {
32
- border-top-left-radius: 4px;
33
- border-bottom-left-radius: 4px;
34
- }
35
-
36
- .button:last-child {
37
- border-top-right-radius: 4px;
38
- border-bottom-right-radius: 4px;
39
- }
40
-
41
- .color {
42
- width: 16px;
43
- height: 16px;
44
- border-radius: 4px;
45
- }
46
-
47
- .link {
48
- display: flex;
49
- overflow: hidden;
50
- width: 250px;
51
- column-gap: 1px;
52
-
53
- & input {
54
- background-color: transparent;
55
- padding: 0 8px;
56
- color: inherit;
57
- height: 24px;
58
- box-sizing: border-box;
59
- flex: 1;
60
- min-width: 0;
61
- outline: none;
62
- border: none;
63
- font-size: 14px;
64
- }
65
-
66
- & button {
67
- color: inherit;
68
- border: none;
69
- background-color: transparent;
70
- height: 24px;
71
- display: flex;
72
- align-items: center;
73
- }
74
- }