doclific 0.1.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 (231) hide show
  1. package/.gitattributes +2 -0
  2. package/.prettierignore +5 -0
  3. package/.prettierrc +9 -0
  4. package/.vscode/settings.json +13 -0
  5. package/dist/bin/doclific.d.ts +3 -0
  6. package/dist/bin/doclific.d.ts.map +1 -0
  7. package/dist/bin/doclific.js +11 -0
  8. package/dist/core/codebase.js +31 -0
  9. package/dist/core/docs.js +75 -0
  10. package/dist/core/git.js +47 -0
  11. package/dist/server/index.d.ts +2 -0
  12. package/dist/server/index.d.ts.map +1 -0
  13. package/dist/server/index.js +46 -0
  14. package/dist/server/router.d.ts +9 -0
  15. package/dist/server/router.d.ts.map +1 -0
  16. package/dist/server/router.js +55 -0
  17. package/frontend/README.md +73 -0
  18. package/frontend/components.json +24 -0
  19. package/frontend/eslint.config.js +23 -0
  20. package/frontend/index.html +25 -0
  21. package/frontend/package-lock.json +15754 -0
  22. package/frontend/package.json +122 -0
  23. package/frontend/public/logo.svg +1 -0
  24. package/frontend/src/App.tsx +21 -0
  25. package/frontend/src/components/app-sidebar.tsx +393 -0
  26. package/frontend/src/components/editor/editor-base-kit.tsx +43 -0
  27. package/frontend/src/components/editor/editor-kit.tsx +93 -0
  28. package/frontend/src/components/editor/plugins/align-base-kit.tsx +16 -0
  29. package/frontend/src/components/editor/plugins/align-kit.tsx +18 -0
  30. package/frontend/src/components/editor/plugins/autoformat-kit.tsx +236 -0
  31. package/frontend/src/components/editor/plugins/basic-blocks-base-kit.tsx +35 -0
  32. package/frontend/src/components/editor/plugins/basic-blocks-kit.tsx +88 -0
  33. package/frontend/src/components/editor/plugins/basic-marks-base-kit.tsx +27 -0
  34. package/frontend/src/components/editor/plugins/basic-marks-kit.tsx +41 -0
  35. package/frontend/src/components/editor/plugins/basic-nodes-kit.tsx +6 -0
  36. package/frontend/src/components/editor/plugins/block-menu-kit.tsx +14 -0
  37. package/frontend/src/components/editor/plugins/block-placeholder-kit.tsx +17 -0
  38. package/frontend/src/components/editor/plugins/block-selection-kit.tsx +32 -0
  39. package/frontend/src/components/editor/plugins/callout-base-kit.tsx +7 -0
  40. package/frontend/src/components/editor/plugins/callout-kit.tsx +7 -0
  41. package/frontend/src/components/editor/plugins/code-block-base-kit.tsx +23 -0
  42. package/frontend/src/components/editor/plugins/code-block-kit.tsx +26 -0
  43. package/frontend/src/components/editor/plugins/codebase-kit.tsx +23 -0
  44. package/frontend/src/components/editor/plugins/column-base-kit.tsx +11 -0
  45. package/frontend/src/components/editor/plugins/column-kit.tsx +10 -0
  46. package/frontend/src/components/editor/plugins/comment-base-kit.tsx +7 -0
  47. package/frontend/src/components/editor/plugins/comment-kit.tsx +97 -0
  48. package/frontend/src/components/editor/plugins/cursor-overlay-kit.tsx +13 -0
  49. package/frontend/src/components/editor/plugins/date-base-kit.tsx +5 -0
  50. package/frontend/src/components/editor/plugins/date-kit.tsx +7 -0
  51. package/frontend/src/components/editor/plugins/discussion-kit.tsx +148 -0
  52. package/frontend/src/components/editor/plugins/dnd-kit.tsx +28 -0
  53. package/frontend/src/components/editor/plugins/docx-kit.tsx +6 -0
  54. package/frontend/src/components/editor/plugins/emoji-kit.tsx +13 -0
  55. package/frontend/src/components/editor/plugins/excalidraw-kit.tsx +9 -0
  56. package/frontend/src/components/editor/plugins/exit-break-kit.tsx +12 -0
  57. package/frontend/src/components/editor/plugins/floating-toolbar-kit.tsx +19 -0
  58. package/frontend/src/components/editor/plugins/font-base-kit.tsx +20 -0
  59. package/frontend/src/components/editor/plugins/font-kit.tsx +29 -0
  60. package/frontend/src/components/editor/plugins/indent-base-kit.tsx +19 -0
  61. package/frontend/src/components/editor/plugins/indent-kit.tsx +22 -0
  62. package/frontend/src/components/editor/plugins/line-height-base-kit.tsx +14 -0
  63. package/frontend/src/components/editor/plugins/line-height-kit.tsx +16 -0
  64. package/frontend/src/components/editor/plugins/link-base-kit.tsx +5 -0
  65. package/frontend/src/components/editor/plugins/link-kit.tsx +15 -0
  66. package/frontend/src/components/editor/plugins/list-base-kit.tsx +23 -0
  67. package/frontend/src/components/editor/plugins/list-kit.tsx +26 -0
  68. package/frontend/src/components/editor/plugins/markdown-kit.tsx +46 -0
  69. package/frontend/src/components/editor/plugins/math-base-kit.tsx +11 -0
  70. package/frontend/src/components/editor/plugins/math-kit.tsx +13 -0
  71. package/frontend/src/components/editor/plugins/media-base-kit.tsx +31 -0
  72. package/frontend/src/components/editor/plugins/media-kit.tsx +43 -0
  73. package/frontend/src/components/editor/plugins/mention-base-kit.tsx +7 -0
  74. package/frontend/src/components/editor/plugins/mention-kit.tsx +15 -0
  75. package/frontend/src/components/editor/plugins/slash-kit.tsx +18 -0
  76. package/frontend/src/components/editor/plugins/suggestion-base-kit.tsx +7 -0
  77. package/frontend/src/components/editor/plugins/suggestion-kit.tsx +90 -0
  78. package/frontend/src/components/editor/plugins/table-base-kit.tsx +20 -0
  79. package/frontend/src/components/editor/plugins/table-kit.tsx +22 -0
  80. package/frontend/src/components/editor/plugins/toc-base-kit.tsx +5 -0
  81. package/frontend/src/components/editor/plugins/toc-kit.tsx +14 -0
  82. package/frontend/src/components/editor/plugins/toggle-base-kit.tsx +7 -0
  83. package/frontend/src/components/editor/plugins/toggle-kit.tsx +11 -0
  84. package/frontend/src/components/editor/transforms.ts +194 -0
  85. package/frontend/src/components/markdown-to-slate-demo.tsx +50 -0
  86. package/frontend/src/components/mode-toggle.tsx +15 -0
  87. package/frontend/src/components/theme-provider.tsx +73 -0
  88. package/frontend/src/components/ui/alert-dialog.tsx +155 -0
  89. package/frontend/src/components/ui/align-toolbar-button.tsx +84 -0
  90. package/frontend/src/components/ui/avatar.tsx +51 -0
  91. package/frontend/src/components/ui/block-context-menu.tsx +199 -0
  92. package/frontend/src/components/ui/block-discussion.tsx +365 -0
  93. package/frontend/src/components/ui/block-draggable.tsx +512 -0
  94. package/frontend/src/components/ui/block-list-static.tsx +80 -0
  95. package/frontend/src/components/ui/block-list.tsx +87 -0
  96. package/frontend/src/components/ui/block-selection.tsx +42 -0
  97. package/frontend/src/components/ui/block-suggestion.tsx +473 -0
  98. package/frontend/src/components/ui/blockquote-node-static.tsx +11 -0
  99. package/frontend/src/components/ui/blockquote-node.tsx +13 -0
  100. package/frontend/src/components/ui/button.tsx +62 -0
  101. package/frontend/src/components/ui/calendar.tsx +218 -0
  102. package/frontend/src/components/ui/callout-node-static.tsx +36 -0
  103. package/frontend/src/components/ui/callout-node.tsx +63 -0
  104. package/frontend/src/components/ui/caption.tsx +63 -0
  105. package/frontend/src/components/ui/checkbox.tsx +30 -0
  106. package/frontend/src/components/ui/code-block-node-static.tsx +35 -0
  107. package/frontend/src/components/ui/code-block-node.tsx +287 -0
  108. package/frontend/src/components/ui/code-node-static.tsx +15 -0
  109. package/frontend/src/components/ui/code-node.tsx +17 -0
  110. package/frontend/src/components/ui/codebase-snippet-node.tsx +237 -0
  111. package/frontend/src/components/ui/column-node-static.tsx +29 -0
  112. package/frontend/src/components/ui/column-node.tsx +317 -0
  113. package/frontend/src/components/ui/command.tsx +182 -0
  114. package/frontend/src/components/ui/comment-node-static.tsx +15 -0
  115. package/frontend/src/components/ui/comment-node.tsx +45 -0
  116. package/frontend/src/components/ui/comment-toolbar-button.tsx +24 -0
  117. package/frontend/src/components/ui/comment.tsx +618 -0
  118. package/frontend/src/components/ui/context-menu.tsx +250 -0
  119. package/frontend/src/components/ui/cursor-overlay.tsx +66 -0
  120. package/frontend/src/components/ui/date-node-static.tsx +45 -0
  121. package/frontend/src/components/ui/date-node.tsx +93 -0
  122. package/frontend/src/components/ui/dialog.tsx +143 -0
  123. package/frontend/src/components/ui/dropdown-menu.tsx +255 -0
  124. package/frontend/src/components/ui/dynamic-icon.tsx +12 -0
  125. package/frontend/src/components/ui/editor-static.tsx +53 -0
  126. package/frontend/src/components/ui/editor.tsx +130 -0
  127. package/frontend/src/components/ui/emoji-node.tsx +69 -0
  128. package/frontend/src/components/ui/emoji-toolbar-button.tsx +628 -0
  129. package/frontend/src/components/ui/equation-node-static.tsx +98 -0
  130. package/frontend/src/components/ui/equation-node.tsx +235 -0
  131. package/frontend/src/components/ui/equation-toolbar-button.tsx +25 -0
  132. package/frontend/src/components/ui/excalidraw-node.tsx +36 -0
  133. package/frontend/src/components/ui/export-toolbar-button.tsx +174 -0
  134. package/frontend/src/components/ui/file-selector.tsx +339 -0
  135. package/frontend/src/components/ui/floating-toolbar-buttons.tsx +73 -0
  136. package/frontend/src/components/ui/floating-toolbar.tsx +85 -0
  137. package/frontend/src/components/ui/font-color-toolbar-button.tsx +831 -0
  138. package/frontend/src/components/ui/font-size-toolbar-button.tsx +152 -0
  139. package/frontend/src/components/ui/heading-node-static.tsx +68 -0
  140. package/frontend/src/components/ui/heading-node.tsx +58 -0
  141. package/frontend/src/components/ui/highlight-node-static.tsx +11 -0
  142. package/frontend/src/components/ui/highlight-node.tsx +13 -0
  143. package/frontend/src/components/ui/history-toolbar-button.tsx +50 -0
  144. package/frontend/src/components/ui/hr-node-static.tsx +20 -0
  145. package/frontend/src/components/ui/hr-node.tsx +33 -0
  146. package/frontend/src/components/ui/import-toolbar-button.tsx +97 -0
  147. package/frontend/src/components/ui/indent-toolbar-button.tsx +30 -0
  148. package/frontend/src/components/ui/inline-combobox.tsx +414 -0
  149. package/frontend/src/components/ui/input.tsx +21 -0
  150. package/frontend/src/components/ui/insert-toolbar-button.tsx +254 -0
  151. package/frontend/src/components/ui/kbd-node-static.tsx +15 -0
  152. package/frontend/src/components/ui/kbd-node.tsx +17 -0
  153. package/frontend/src/components/ui/layout-header.tsx +35 -0
  154. package/frontend/src/components/ui/line-height-toolbar-button.tsx +68 -0
  155. package/frontend/src/components/ui/link-node-static.tsx +21 -0
  156. package/frontend/src/components/ui/link-node.tsx +39 -0
  157. package/frontend/src/components/ui/link-toolbar-button.tsx +22 -0
  158. package/frontend/src/components/ui/link-toolbar.tsx +206 -0
  159. package/frontend/src/components/ui/list-toolbar-button.tsx +204 -0
  160. package/frontend/src/components/ui/mark-toolbar-button.tsx +19 -0
  161. package/frontend/src/components/ui/media-audio-node-static.tsx +17 -0
  162. package/frontend/src/components/ui/media-audio-node.tsx +39 -0
  163. package/frontend/src/components/ui/media-embed-node.tsx +136 -0
  164. package/frontend/src/components/ui/media-file-node-static.tsx +29 -0
  165. package/frontend/src/components/ui/media-file-node.tsx +47 -0
  166. package/frontend/src/components/ui/media-image-node-static.tsx +39 -0
  167. package/frontend/src/components/ui/media-image-node.tsx +80 -0
  168. package/frontend/src/components/ui/media-placeholder-node.tsx +249 -0
  169. package/frontend/src/components/ui/media-preview-dialog.tsx +152 -0
  170. package/frontend/src/components/ui/media-toolbar-button.tsx +225 -0
  171. package/frontend/src/components/ui/media-toolbar.tsx +115 -0
  172. package/frontend/src/components/ui/media-upload-toast.tsx +66 -0
  173. package/frontend/src/components/ui/media-video-node-static.tsx +30 -0
  174. package/frontend/src/components/ui/media-video-node.tsx +121 -0
  175. package/frontend/src/components/ui/mention-node-static.tsx +36 -0
  176. package/frontend/src/components/ui/mention-node.tsx +194 -0
  177. package/frontend/src/components/ui/mode-toolbar-button.tsx +123 -0
  178. package/frontend/src/components/ui/more-toolbar-button.tsx +80 -0
  179. package/frontend/src/components/ui/paragraph-node-static.tsx +13 -0
  180. package/frontend/src/components/ui/paragraph-node.tsx +15 -0
  181. package/frontend/src/components/ui/popover.tsx +46 -0
  182. package/frontend/src/components/ui/resize-handle.tsx +87 -0
  183. package/frontend/src/components/ui/separator.tsx +28 -0
  184. package/frontend/src/components/ui/sheet.tsx +139 -0
  185. package/frontend/src/components/ui/sidebar.tsx +726 -0
  186. package/frontend/src/components/ui/skeleton.tsx +13 -0
  187. package/frontend/src/components/ui/slash-node.tsx +233 -0
  188. package/frontend/src/components/ui/sonner.tsx +38 -0
  189. package/frontend/src/components/ui/suggestion-node-static.tsx +35 -0
  190. package/frontend/src/components/ui/suggestion-node.tsx +162 -0
  191. package/frontend/src/components/ui/suggestion-toolbar-button.tsx +25 -0
  192. package/frontend/src/components/ui/table-icons.tsx +862 -0
  193. package/frontend/src/components/ui/table-node-static.tsx +98 -0
  194. package/frontend/src/components/ui/table-node.tsx +656 -0
  195. package/frontend/src/components/ui/table-toolbar-button.tsx +264 -0
  196. package/frontend/src/components/ui/toc-node-static.tsx +92 -0
  197. package/frontend/src/components/ui/toc-node.tsx +55 -0
  198. package/frontend/src/components/ui/toggle-node-static.tsx +18 -0
  199. package/frontend/src/components/ui/toggle-node.tsx +36 -0
  200. package/frontend/src/components/ui/toggle-toolbar-button.tsx +22 -0
  201. package/frontend/src/components/ui/toolbar.tsx +387 -0
  202. package/frontend/src/components/ui/tooltip.tsx +59 -0
  203. package/frontend/src/components/ui/turn-into-toolbar-button.tsx +188 -0
  204. package/frontend/src/hooks/use-debounce.ts +18 -0
  205. package/frontend/src/hooks/use-is-touch-device.ts +24 -0
  206. package/frontend/src/hooks/use-mobile.ts +19 -0
  207. package/frontend/src/hooks/use-mounted.ts +11 -0
  208. package/frontend/src/hooks/use-upload-file.ts +128 -0
  209. package/frontend/src/index.css +128 -0
  210. package/frontend/src/layout.tsx +42 -0
  211. package/frontend/src/lib/markdown-joiner-transform.ts +239 -0
  212. package/frontend/src/lib/orpc.ts +13 -0
  213. package/frontend/src/lib/uploadthing.ts +19 -0
  214. package/frontend/src/lib/utils.ts +6 -0
  215. package/frontend/src/main.tsx +13 -0
  216. package/frontend/src/pages/editor.tsx +44 -0
  217. package/frontend/src/types/docs.d.ts +6 -0
  218. package/frontend/src/types/global.d.ts +9 -0
  219. package/frontend/src/types/router.d.ts +4 -0
  220. package/frontend/tsconfig.app.json +33 -0
  221. package/frontend/tsconfig.json +10 -0
  222. package/frontend/tsconfig.node.json +26 -0
  223. package/frontend/vite.config.ts +14 -0
  224. package/package.json +30 -0
  225. package/src/bin/doclific.ts +17 -0
  226. package/src/core/codebase.ts +39 -0
  227. package/src/core/docs.ts +90 -0
  228. package/src/core/git.ts +48 -0
  229. package/src/server/index.ts +55 -0
  230. package/src/server/router.ts +65 -0
  231. package/tsconfig.json +15 -0
@@ -0,0 +1,121 @@
1
+
2
+ import LiteYouTubeEmbed from 'react-lite-youtube-embed';
3
+ import ReactPlayer from 'react-player';
4
+
5
+ import type { TResizableProps, TVideoElement } from 'platejs';
6
+ import type { PlateElementProps } from 'platejs/react';
7
+
8
+ import { useDraggable } from '@platejs/dnd';
9
+ import { parseTwitterUrl, parseVideoUrl } from '@platejs/media';
10
+ import { useMediaState } from '@platejs/media/react';
11
+ import { ResizableProvider, useResizableValue } from '@platejs/resizable';
12
+ import { PlateElement, useEditorMounted, withHOC } from 'platejs/react';
13
+
14
+ import { cn } from '@/lib/utils';
15
+
16
+ import { Caption, CaptionTextarea } from './caption';
17
+ import {
18
+ mediaResizeHandleVariants,
19
+ Resizable,
20
+ ResizeHandle,
21
+ } from './resize-handle';
22
+
23
+ export const VideoElement = withHOC(
24
+ ResizableProvider,
25
+ function VideoElement(
26
+ props: PlateElementProps<TVideoElement & TResizableProps>
27
+ ) {
28
+ const {
29
+ align = 'center',
30
+ embed,
31
+ isUpload,
32
+ isYoutube,
33
+ readOnly,
34
+ unsafeUrl,
35
+ } = useMediaState({
36
+ urlParsers: [parseTwitterUrl, parseVideoUrl],
37
+ });
38
+ const width = useResizableValue('width');
39
+
40
+ const isEditorMounted = useEditorMounted();
41
+
42
+ const isTweet = true;
43
+
44
+ const { isDragging, handleRef } = useDraggable({
45
+ element: props.element,
46
+ });
47
+
48
+ return (
49
+ <PlateElement className="py-2.5" {...props}>
50
+ <figure className="relative m-0 cursor-default" contentEditable={false}>
51
+ <Resizable
52
+ className={cn(isDragging && 'opacity-50')}
53
+ align={align}
54
+ options={{
55
+ align,
56
+ maxWidth: isTweet ? 550 : '100%',
57
+ minWidth: isTweet ? 300 : 100,
58
+ readOnly,
59
+ }}
60
+ >
61
+ <div className="group/media">
62
+ <ResizeHandle
63
+ className={mediaResizeHandleVariants({ direction: 'left' })}
64
+ options={{ direction: 'left' }}
65
+ />
66
+
67
+ <ResizeHandle
68
+ className={mediaResizeHandleVariants({ direction: 'right' })}
69
+ options={{ direction: 'right' }}
70
+ />
71
+
72
+ {!isUpload && isYoutube && (
73
+ <div ref={handleRef}>
74
+ <LiteYouTubeEmbed
75
+ id={embed!.id!}
76
+ title="youtube"
77
+ wrapperClass={cn(
78
+ 'aspect-video rounded-sm',
79
+ 'relative block cursor-pointer bg-black bg-center bg-cover [contain:content]',
80
+ '[&.lyt-activated]:before:absolute [&.lyt-activated]:before:top-0 [&.lyt-activated]:before:h-[60px] [&.lyt-activated]:before:w-full [&.lyt-activated]:before:bg-top [&.lyt-activated]:before:bg-repeat-x [&.lyt-activated]:before:pb-[50px] [&.lyt-activated]:before:[transition:all_0.2s_cubic-bezier(0,_0,_0.2,_1)]',
81
+ '[&.lyt-activated]:before:bg-[url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAADGCAYAAAAT+OqFAAAAdklEQVQoz42QQQ7AIAgEF/T/D+kbq/RWAlnQyyazA4aoAB4FsBSA/bFjuF1EOL7VbrIrBuusmrt4ZZORfb6ehbWdnRHEIiITaEUKa5EJqUakRSaEYBJSCY2dEstQY7AuxahwXFrvZmWl2rh4JZ07z9dLtesfNj5q0FU3A5ObbwAAAABJRU5ErkJggg==)]',
82
+ 'after:block after:pb-[var(--aspect-ratio)] after:content-[""]',
83
+ '[&_>_iframe]:absolute [&_>_iframe]:top-0 [&_>_iframe]:left-0 [&_>_iframe]:size-full',
84
+ '[&_>_.lty-playbtn]:z-1 [&_>_.lty-playbtn]:h-[46px] [&_>_.lty-playbtn]:w-[70px] [&_>_.lty-playbtn]:rounded-[14%] [&_>_.lty-playbtn]:bg-[#212121] [&_>_.lty-playbtn]:opacity-80 [&_>_.lty-playbtn]:[transition:all_0.2s_cubic-bezier(0,_0,_0.2,_1)]',
85
+ '[&:hover_>_.lty-playbtn]:bg-[red] [&:hover_>_.lty-playbtn]:opacity-100',
86
+ '[&_>_.lty-playbtn]:before:border-[transparent_transparent_transparent_#fff] [&_>_.lty-playbtn]:before:border-y-[11px] [&_>_.lty-playbtn]:before:border-r-0 [&_>_.lty-playbtn]:before:border-l-[19px] [&_>_.lty-playbtn]:before:content-[""]',
87
+ '[&_>_.lty-playbtn]:absolute [&_>_.lty-playbtn]:top-1/2 [&_>_.lty-playbtn]:left-1/2 [&_>_.lty-playbtn]:[transform:translate3d(-50%,-50%,0)]',
88
+ '[&_>_.lty-playbtn]:before:absolute [&_>_.lty-playbtn]:before:top-1/2 [&_>_.lty-playbtn]:before:left-1/2 [&_>_.lty-playbtn]:before:[transform:translate3d(-50%,-50%,0)]',
89
+ '[&.lyt-activated]:cursor-[unset]',
90
+ '[&.lyt-activated]:before:pointer-events-none [&.lyt-activated]:before:opacity-0',
91
+ '[&.lyt-activated_>_.lty-playbtn]:pointer-events-none [&.lyt-activated_>_.lty-playbtn]:opacity-0!'
92
+ )}
93
+ />
94
+ </div>
95
+ )}
96
+
97
+ {isUpload && isEditorMounted && (
98
+ <div ref={handleRef}>
99
+ <ReactPlayer
100
+ height="100%"
101
+ src={unsafeUrl}
102
+ width="100%"
103
+ controls
104
+ />
105
+ </div>
106
+ )}
107
+ </div>
108
+ </Resizable>
109
+
110
+ <Caption style={{ width }} align={align}>
111
+ <CaptionTextarea
112
+ readOnly={readOnly}
113
+ placeholder="Write a caption..."
114
+ />
115
+ </Caption>
116
+ </figure>
117
+ {props.children}
118
+ </PlateElement>
119
+ );
120
+ }
121
+ );
@@ -0,0 +1,36 @@
1
+ import type { TMentionElement } from 'platejs';
2
+ import type { SlateElementProps } from 'platejs/static';
3
+
4
+ import { KEYS } from 'platejs';
5
+ import { SlateElement } from 'platejs/static';
6
+
7
+ import { cn } from '@/lib/utils';
8
+
9
+ export function MentionElementStatic(
10
+ props: SlateElementProps<TMentionElement> & {
11
+ prefix?: string;
12
+ }
13
+ ) {
14
+ const { prefix } = props;
15
+ const element = props.element;
16
+
17
+ return (
18
+ <SlateElement
19
+ {...props}
20
+ className={cn(
21
+ 'inline-block rounded-md bg-muted px-1.5 py-0.5 align-baseline font-medium text-sm',
22
+ element.children[0][KEYS.bold] === true && 'font-bold',
23
+ element.children[0][KEYS.italic] === true && 'italic',
24
+ element.children[0][KEYS.underline] === true && 'underline'
25
+ )}
26
+ attributes={{
27
+ ...props.attributes,
28
+ 'data-slate-value': element.value,
29
+ }}
30
+ >
31
+ {props.children}
32
+ {prefix}
33
+ {element.value}
34
+ </SlateElement>
35
+ );
36
+ }
@@ -0,0 +1,194 @@
1
+ import React from 'react';
2
+
3
+ import type { TComboboxInputElement, TMentionElement } from 'platejs';
4
+ import type { PlateElementProps } from 'platejs/react';
5
+
6
+ import { getMentionOnSelectItem } from '@platejs/mention';
7
+ import { IS_APPLE, KEYS } from 'platejs';
8
+ import {
9
+ PlateElement,
10
+ useFocused,
11
+ useReadOnly,
12
+ useSelected,
13
+ } from 'platejs/react';
14
+
15
+ import { cn } from '@/lib/utils';
16
+ import { useMounted } from '@/hooks/use-mounted';
17
+
18
+ import {
19
+ InlineCombobox,
20
+ InlineComboboxContent,
21
+ InlineComboboxEmpty,
22
+ InlineComboboxGroup,
23
+ InlineComboboxInput,
24
+ InlineComboboxItem,
25
+ } from './inline-combobox';
26
+
27
+ export function MentionElement(
28
+ props: PlateElementProps<TMentionElement> & {
29
+ prefix?: string;
30
+ }
31
+ ) {
32
+ const element = props.element;
33
+
34
+ const selected = useSelected();
35
+ const focused = useFocused();
36
+ const mounted = useMounted();
37
+ const readOnly = useReadOnly();
38
+
39
+ return (
40
+ <PlateElement
41
+ {...props}
42
+ className={cn(
43
+ 'inline-block rounded-md bg-muted px-1.5 py-0.5 align-baseline font-medium text-sm',
44
+ !readOnly && 'cursor-pointer',
45
+ selected && focused && 'ring-2 ring-ring',
46
+ element.children[0][KEYS.bold] === true && 'font-bold',
47
+ element.children[0][KEYS.italic] === true && 'italic',
48
+ element.children[0][KEYS.underline] === true && 'underline'
49
+ )}
50
+ attributes={{
51
+ ...props.attributes,
52
+ contentEditable: false,
53
+ 'data-slate-value': element.value,
54
+ draggable: true,
55
+ }}
56
+ >
57
+ {mounted && IS_APPLE ? (
58
+ // Mac OS IME https://github.com/ianstormtaylor/slate/issues/3490
59
+ <>
60
+ {props.children}
61
+ {props.prefix}
62
+ {element.value}
63
+ </>
64
+ ) : (
65
+ // Others like Android https://github.com/ianstormtaylor/slate/pull/5360
66
+ <>
67
+ {props.prefix}
68
+ {element.value}
69
+ {props.children}
70
+ </>
71
+ )}
72
+ </PlateElement>
73
+ );
74
+ }
75
+
76
+ const onSelectItem = getMentionOnSelectItem();
77
+
78
+ export function MentionInputElement(
79
+ props: PlateElementProps<TComboboxInputElement>
80
+ ) {
81
+ const { editor, element } = props;
82
+ const [search, setSearch] = React.useState('');
83
+
84
+ return (
85
+ <PlateElement {...props} as="span">
86
+ <InlineCombobox
87
+ value={search}
88
+ element={element}
89
+ setValue={setSearch}
90
+ showTrigger={false}
91
+ trigger="@"
92
+ >
93
+ <span className="inline-block rounded-md bg-muted px-1.5 py-0.5 align-baseline text-sm ring-ring focus-within:ring-2">
94
+ <InlineComboboxInput />
95
+ </span>
96
+
97
+ <InlineComboboxContent className="my-1.5">
98
+ <InlineComboboxEmpty>No results</InlineComboboxEmpty>
99
+
100
+ <InlineComboboxGroup>
101
+ {MENTIONABLES.map((item) => (
102
+ <InlineComboboxItem
103
+ key={item.key}
104
+ value={item.text}
105
+ onClick={() => onSelectItem(editor, item, search)}
106
+ >
107
+ {item.text}
108
+ </InlineComboboxItem>
109
+ ))}
110
+ </InlineComboboxGroup>
111
+ </InlineComboboxContent>
112
+ </InlineCombobox>
113
+
114
+ {props.children}
115
+ </PlateElement>
116
+ );
117
+ }
118
+
119
+ const MENTIONABLES = [
120
+ { key: '0', text: 'Aayla Secura' },
121
+ { key: '1', text: 'Adi Gallia' },
122
+ {
123
+ key: '2',
124
+ text: 'Admiral Dodd Rancit',
125
+ },
126
+ {
127
+ key: '3',
128
+ text: 'Admiral Firmus Piett',
129
+ },
130
+ {
131
+ key: '4',
132
+ text: 'Admiral Gial Ackbar',
133
+ },
134
+ { key: '5', text: 'Admiral Ozzel' },
135
+ { key: '6', text: 'Admiral Raddus' },
136
+ {
137
+ key: '7',
138
+ text: 'Admiral Terrinald Screed',
139
+ },
140
+ { key: '8', text: 'Admiral Trench' },
141
+ {
142
+ key: '9',
143
+ text: 'Admiral U.O. Statura',
144
+ },
145
+ { key: '10', text: 'Agen Kolar' },
146
+ { key: '11', text: 'Agent Kallus' },
147
+ {
148
+ key: '12',
149
+ text: 'Aiolin and Morit Astarte',
150
+ },
151
+ { key: '13', text: 'Aks Moe' },
152
+ { key: '14', text: 'Almec' },
153
+ { key: '15', text: 'Alton Kastle' },
154
+ { key: '16', text: 'Amee' },
155
+ { key: '17', text: 'AP-5' },
156
+ { key: '18', text: 'Armitage Hux' },
157
+ { key: '19', text: 'Artoo' },
158
+ { key: '20', text: 'Arvel Crynyd' },
159
+ { key: '21', text: 'Asajj Ventress' },
160
+ { key: '22', text: 'Aurra Sing' },
161
+ { key: '23', text: 'AZI-3' },
162
+ { key: '24', text: 'Bala-Tik' },
163
+ { key: '25', text: 'Barada' },
164
+ { key: '26', text: 'Bargwill Tomder' },
165
+ { key: '27', text: 'Baron Papanoida' },
166
+ { key: '28', text: 'Barriss Offee' },
167
+ { key: '29', text: 'Baze Malbus' },
168
+ { key: '30', text: 'Bazine Netal' },
169
+ { key: '31', text: 'BB-8' },
170
+ { key: '32', text: 'BB-9E' },
171
+ { key: '33', text: 'Ben Quadinaros' },
172
+ { key: '34', text: 'Berch Teller' },
173
+ { key: '35', text: 'Beru Lars' },
174
+ { key: '36', text: 'Bib Fortuna' },
175
+ {
176
+ key: '37',
177
+ text: 'Biggs Darklighter',
178
+ },
179
+ { key: '38', text: 'Black Krrsantan' },
180
+ { key: '39', text: 'Bo-Katan Kryze' },
181
+ { key: '40', text: 'Boba Fett' },
182
+ { key: '41', text: 'Bobbajo' },
183
+ { key: '42', text: 'Bodhi Rook' },
184
+ { key: '43', text: 'Borvo the Hutt' },
185
+ { key: '44', text: 'Boss Nass' },
186
+ { key: '45', text: 'Bossk' },
187
+ {
188
+ key: '46',
189
+ text: 'Breha Antilles-Organa',
190
+ },
191
+ { key: '47', text: 'Bren Derlin' },
192
+ { key: '48', text: 'Brendol Hux' },
193
+ { key: '49', text: 'BT-1' },
194
+ ];
@@ -0,0 +1,123 @@
1
+ import React from 'react';
2
+
3
+ import { SuggestionPlugin } from '@platejs/suggestion/react';
4
+ import {
5
+ type DropdownMenuProps,
6
+ DropdownMenuItemIndicator,
7
+ } from '@radix-ui/react-dropdown-menu';
8
+ import { CheckIcon, EyeIcon, PencilLineIcon, PenIcon } from 'lucide-react';
9
+ import { useEditorRef, usePlateState, usePluginOption } from 'platejs/react';
10
+
11
+ import {
12
+ DropdownMenu,
13
+ DropdownMenuContent,
14
+ DropdownMenuRadioGroup,
15
+ DropdownMenuRadioItem,
16
+ DropdownMenuTrigger,
17
+ } from '@/components/ui/dropdown-menu';
18
+
19
+ import { ToolbarButton } from './toolbar';
20
+
21
+ export function ModeToolbarButton(props: DropdownMenuProps) {
22
+ const editor = useEditorRef();
23
+ const [readOnly, setReadOnly] = usePlateState('readOnly');
24
+ const [open, setOpen] = React.useState(false);
25
+
26
+ const isSuggesting = usePluginOption(SuggestionPlugin, 'isSuggesting');
27
+
28
+ let value = 'editing';
29
+
30
+ if (readOnly) value = 'viewing';
31
+
32
+ if (isSuggesting) value = 'suggestion';
33
+
34
+ const item: Record<string, { icon: React.ReactNode; label: string }> = {
35
+ editing: {
36
+ icon: <PenIcon />,
37
+ label: 'Editing',
38
+ },
39
+ suggestion: {
40
+ icon: <PencilLineIcon />,
41
+ label: 'Suggestion',
42
+ },
43
+ viewing: {
44
+ icon: <EyeIcon />,
45
+ label: 'Viewing',
46
+ },
47
+ };
48
+
49
+ return (
50
+ <DropdownMenu open={open} onOpenChange={setOpen} modal={false} {...props}>
51
+ <DropdownMenuTrigger asChild>
52
+ <ToolbarButton pressed={open} tooltip="Editing mode" isDropdown>
53
+ {item[value].icon}
54
+ <span className="hidden lg:inline">{item[value].label}</span>
55
+ </ToolbarButton>
56
+ </DropdownMenuTrigger>
57
+
58
+ <DropdownMenuContent className="min-w-[180px]" align="start">
59
+ <DropdownMenuRadioGroup
60
+ value={value}
61
+ onValueChange={(newValue) => {
62
+ if (newValue === 'viewing') {
63
+ setReadOnly(true);
64
+
65
+ return;
66
+ }
67
+ setReadOnly(false);
68
+
69
+ if (newValue === 'suggestion') {
70
+ editor.setOption(SuggestionPlugin, 'isSuggesting', true);
71
+
72
+ return;
73
+ }
74
+ editor.setOption(SuggestionPlugin, 'isSuggesting', false);
75
+
76
+ if (newValue === 'editing') {
77
+ editor.tf.focus();
78
+
79
+ return;
80
+ }
81
+ }}
82
+ >
83
+ <DropdownMenuRadioItem
84
+ className="pl-2 *:first:[span]:hidden *:[svg]:text-muted-foreground"
85
+ value="editing"
86
+ >
87
+ <Indicator />
88
+ {item.editing.icon}
89
+ {item.editing.label}
90
+ </DropdownMenuRadioItem>
91
+
92
+ <DropdownMenuRadioItem
93
+ className="pl-2 *:first:[span]:hidden *:[svg]:text-muted-foreground"
94
+ value="viewing"
95
+ >
96
+ <Indicator />
97
+ {item.viewing.icon}
98
+ {item.viewing.label}
99
+ </DropdownMenuRadioItem>
100
+
101
+ <DropdownMenuRadioItem
102
+ className="pl-2 *:first:[span]:hidden *:[svg]:text-muted-foreground"
103
+ value="suggestion"
104
+ >
105
+ <Indicator />
106
+ {item.suggestion.icon}
107
+ {item.suggestion.label}
108
+ </DropdownMenuRadioItem>
109
+ </DropdownMenuRadioGroup>
110
+ </DropdownMenuContent>
111
+ </DropdownMenu>
112
+ );
113
+ }
114
+
115
+ function Indicator() {
116
+ return (
117
+ <span className="pointer-events-none absolute right-2 flex size-3.5 items-center justify-center">
118
+ <DropdownMenuItemIndicator>
119
+ <CheckIcon />
120
+ </DropdownMenuItemIndicator>
121
+ </span>
122
+ );
123
+ }
@@ -0,0 +1,80 @@
1
+ import React from 'react';
2
+
3
+ import type { DropdownMenuProps } from '@radix-ui/react-dropdown-menu';
4
+
5
+ import {
6
+ KeyboardIcon,
7
+ MoreHorizontalIcon,
8
+ SubscriptIcon,
9
+ SuperscriptIcon,
10
+ } from 'lucide-react';
11
+ import { KEYS } from 'platejs';
12
+ import { useEditorRef } from 'platejs/react';
13
+
14
+ import {
15
+ DropdownMenu,
16
+ DropdownMenuContent,
17
+ DropdownMenuGroup,
18
+ DropdownMenuItem,
19
+ DropdownMenuTrigger,
20
+ } from '@/components/ui/dropdown-menu';
21
+
22
+ import { ToolbarButton } from './toolbar';
23
+
24
+ export function MoreToolbarButton(props: DropdownMenuProps) {
25
+ const editor = useEditorRef();
26
+ const [open, setOpen] = React.useState(false);
27
+
28
+ return (
29
+ <DropdownMenu open={open} onOpenChange={setOpen} modal={false} {...props}>
30
+ <DropdownMenuTrigger asChild>
31
+ <ToolbarButton pressed={open} tooltip="Insert">
32
+ <MoreHorizontalIcon />
33
+ </ToolbarButton>
34
+ </DropdownMenuTrigger>
35
+
36
+ <DropdownMenuContent
37
+ className="ignore-click-outside/toolbar flex max-h-[500px] min-w-[180px] flex-col overflow-y-auto"
38
+ align="start"
39
+ >
40
+ <DropdownMenuGroup>
41
+ <DropdownMenuItem
42
+ onSelect={() => {
43
+ editor.tf.toggleMark(KEYS.kbd);
44
+ editor.tf.collapse({ edge: 'end' });
45
+ editor.tf.focus();
46
+ }}
47
+ >
48
+ <KeyboardIcon />
49
+ Keyboard input
50
+ </DropdownMenuItem>
51
+
52
+ <DropdownMenuItem
53
+ onSelect={() => {
54
+ editor.tf.toggleMark(KEYS.sup, {
55
+ remove: KEYS.sub,
56
+ });
57
+ editor.tf.focus();
58
+ }}
59
+ >
60
+ <SuperscriptIcon />
61
+ Superscript
62
+ {/* (⌘+,) */}
63
+ </DropdownMenuItem>
64
+ <DropdownMenuItem
65
+ onSelect={() => {
66
+ editor.tf.toggleMark(KEYS.sub, {
67
+ remove: KEYS.sup,
68
+ });
69
+ editor.tf.focus();
70
+ }}
71
+ >
72
+ <SubscriptIcon />
73
+ Subscript
74
+ {/* (⌘+.) */}
75
+ </DropdownMenuItem>
76
+ </DropdownMenuGroup>
77
+ </DropdownMenuContent>
78
+ </DropdownMenu>
79
+ );
80
+ }
@@ -0,0 +1,13 @@
1
+ import type { SlateElementProps } from 'platejs/static';
2
+
3
+ import { SlateElement } from 'platejs/static';
4
+
5
+ import { cn } from '@/lib/utils';
6
+
7
+ export function ParagraphElementStatic(props: SlateElementProps) {
8
+ return (
9
+ <SlateElement {...props} className={cn('m-0 px-0 py-1')}>
10
+ {props.children}
11
+ </SlateElement>
12
+ );
13
+ }
@@ -0,0 +1,15 @@
1
+
2
+
3
+ import type { PlateElementProps } from 'platejs/react';
4
+
5
+ import { PlateElement } from 'platejs/react';
6
+
7
+ import { cn } from '@/lib/utils';
8
+
9
+ export function ParagraphElement(props: PlateElementProps) {
10
+ return (
11
+ <PlateElement {...props} className={cn('m-0 px-0 py-1')}>
12
+ {props.children}
13
+ </PlateElement>
14
+ );
15
+ }
@@ -0,0 +1,46 @@
1
+ import * as React from "react"
2
+ import * as PopoverPrimitive from "@radix-ui/react-popover"
3
+
4
+ import { cn } from "@/lib/utils"
5
+
6
+ function Popover({
7
+ ...props
8
+ }: React.ComponentProps<typeof PopoverPrimitive.Root>) {
9
+ return <PopoverPrimitive.Root data-slot="popover" {...props} />
10
+ }
11
+
12
+ function PopoverTrigger({
13
+ ...props
14
+ }: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {
15
+ return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />
16
+ }
17
+
18
+ function PopoverContent({
19
+ className,
20
+ align = "center",
21
+ sideOffset = 4,
22
+ ...props
23
+ }: React.ComponentProps<typeof PopoverPrimitive.Content>) {
24
+ return (
25
+ <PopoverPrimitive.Portal>
26
+ <PopoverPrimitive.Content
27
+ data-slot="popover-content"
28
+ align={align}
29
+ sideOffset={sideOffset}
30
+ className={cn(
31
+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
32
+ className
33
+ )}
34
+ {...props}
35
+ />
36
+ </PopoverPrimitive.Portal>
37
+ )
38
+ }
39
+
40
+ function PopoverAnchor({
41
+ ...props
42
+ }: React.ComponentProps<typeof PopoverPrimitive.Anchor>) {
43
+ return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />
44
+ }
45
+
46
+ export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor }