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.
- package/.gitattributes +2 -0
- package/.prettierignore +5 -0
- package/.prettierrc +9 -0
- package/.vscode/settings.json +13 -0
- package/dist/bin/doclific.d.ts +3 -0
- package/dist/bin/doclific.d.ts.map +1 -0
- package/dist/bin/doclific.js +11 -0
- package/dist/core/codebase.js +31 -0
- package/dist/core/docs.js +75 -0
- package/dist/core/git.js +47 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +46 -0
- package/dist/server/router.d.ts +9 -0
- package/dist/server/router.d.ts.map +1 -0
- package/dist/server/router.js +55 -0
- package/frontend/README.md +73 -0
- package/frontend/components.json +24 -0
- package/frontend/eslint.config.js +23 -0
- package/frontend/index.html +25 -0
- package/frontend/package-lock.json +15754 -0
- package/frontend/package.json +122 -0
- package/frontend/public/logo.svg +1 -0
- package/frontend/src/App.tsx +21 -0
- package/frontend/src/components/app-sidebar.tsx +393 -0
- package/frontend/src/components/editor/editor-base-kit.tsx +43 -0
- package/frontend/src/components/editor/editor-kit.tsx +93 -0
- package/frontend/src/components/editor/plugins/align-base-kit.tsx +16 -0
- package/frontend/src/components/editor/plugins/align-kit.tsx +18 -0
- package/frontend/src/components/editor/plugins/autoformat-kit.tsx +236 -0
- package/frontend/src/components/editor/plugins/basic-blocks-base-kit.tsx +35 -0
- package/frontend/src/components/editor/plugins/basic-blocks-kit.tsx +88 -0
- package/frontend/src/components/editor/plugins/basic-marks-base-kit.tsx +27 -0
- package/frontend/src/components/editor/plugins/basic-marks-kit.tsx +41 -0
- package/frontend/src/components/editor/plugins/basic-nodes-kit.tsx +6 -0
- package/frontend/src/components/editor/plugins/block-menu-kit.tsx +14 -0
- package/frontend/src/components/editor/plugins/block-placeholder-kit.tsx +17 -0
- package/frontend/src/components/editor/plugins/block-selection-kit.tsx +32 -0
- package/frontend/src/components/editor/plugins/callout-base-kit.tsx +7 -0
- package/frontend/src/components/editor/plugins/callout-kit.tsx +7 -0
- package/frontend/src/components/editor/plugins/code-block-base-kit.tsx +23 -0
- package/frontend/src/components/editor/plugins/code-block-kit.tsx +26 -0
- package/frontend/src/components/editor/plugins/codebase-kit.tsx +23 -0
- package/frontend/src/components/editor/plugins/column-base-kit.tsx +11 -0
- package/frontend/src/components/editor/plugins/column-kit.tsx +10 -0
- package/frontend/src/components/editor/plugins/comment-base-kit.tsx +7 -0
- package/frontend/src/components/editor/plugins/comment-kit.tsx +97 -0
- package/frontend/src/components/editor/plugins/cursor-overlay-kit.tsx +13 -0
- package/frontend/src/components/editor/plugins/date-base-kit.tsx +5 -0
- package/frontend/src/components/editor/plugins/date-kit.tsx +7 -0
- package/frontend/src/components/editor/plugins/discussion-kit.tsx +148 -0
- package/frontend/src/components/editor/plugins/dnd-kit.tsx +28 -0
- package/frontend/src/components/editor/plugins/docx-kit.tsx +6 -0
- package/frontend/src/components/editor/plugins/emoji-kit.tsx +13 -0
- package/frontend/src/components/editor/plugins/excalidraw-kit.tsx +9 -0
- package/frontend/src/components/editor/plugins/exit-break-kit.tsx +12 -0
- package/frontend/src/components/editor/plugins/floating-toolbar-kit.tsx +19 -0
- package/frontend/src/components/editor/plugins/font-base-kit.tsx +20 -0
- package/frontend/src/components/editor/plugins/font-kit.tsx +29 -0
- package/frontend/src/components/editor/plugins/indent-base-kit.tsx +19 -0
- package/frontend/src/components/editor/plugins/indent-kit.tsx +22 -0
- package/frontend/src/components/editor/plugins/line-height-base-kit.tsx +14 -0
- package/frontend/src/components/editor/plugins/line-height-kit.tsx +16 -0
- package/frontend/src/components/editor/plugins/link-base-kit.tsx +5 -0
- package/frontend/src/components/editor/plugins/link-kit.tsx +15 -0
- package/frontend/src/components/editor/plugins/list-base-kit.tsx +23 -0
- package/frontend/src/components/editor/plugins/list-kit.tsx +26 -0
- package/frontend/src/components/editor/plugins/markdown-kit.tsx +46 -0
- package/frontend/src/components/editor/plugins/math-base-kit.tsx +11 -0
- package/frontend/src/components/editor/plugins/math-kit.tsx +13 -0
- package/frontend/src/components/editor/plugins/media-base-kit.tsx +31 -0
- package/frontend/src/components/editor/plugins/media-kit.tsx +43 -0
- package/frontend/src/components/editor/plugins/mention-base-kit.tsx +7 -0
- package/frontend/src/components/editor/plugins/mention-kit.tsx +15 -0
- package/frontend/src/components/editor/plugins/slash-kit.tsx +18 -0
- package/frontend/src/components/editor/plugins/suggestion-base-kit.tsx +7 -0
- package/frontend/src/components/editor/plugins/suggestion-kit.tsx +90 -0
- package/frontend/src/components/editor/plugins/table-base-kit.tsx +20 -0
- package/frontend/src/components/editor/plugins/table-kit.tsx +22 -0
- package/frontend/src/components/editor/plugins/toc-base-kit.tsx +5 -0
- package/frontend/src/components/editor/plugins/toc-kit.tsx +14 -0
- package/frontend/src/components/editor/plugins/toggle-base-kit.tsx +7 -0
- package/frontend/src/components/editor/plugins/toggle-kit.tsx +11 -0
- package/frontend/src/components/editor/transforms.ts +194 -0
- package/frontend/src/components/markdown-to-slate-demo.tsx +50 -0
- package/frontend/src/components/mode-toggle.tsx +15 -0
- package/frontend/src/components/theme-provider.tsx +73 -0
- package/frontend/src/components/ui/alert-dialog.tsx +155 -0
- package/frontend/src/components/ui/align-toolbar-button.tsx +84 -0
- package/frontend/src/components/ui/avatar.tsx +51 -0
- package/frontend/src/components/ui/block-context-menu.tsx +199 -0
- package/frontend/src/components/ui/block-discussion.tsx +365 -0
- package/frontend/src/components/ui/block-draggable.tsx +512 -0
- package/frontend/src/components/ui/block-list-static.tsx +80 -0
- package/frontend/src/components/ui/block-list.tsx +87 -0
- package/frontend/src/components/ui/block-selection.tsx +42 -0
- package/frontend/src/components/ui/block-suggestion.tsx +473 -0
- package/frontend/src/components/ui/blockquote-node-static.tsx +11 -0
- package/frontend/src/components/ui/blockquote-node.tsx +13 -0
- package/frontend/src/components/ui/button.tsx +62 -0
- package/frontend/src/components/ui/calendar.tsx +218 -0
- package/frontend/src/components/ui/callout-node-static.tsx +36 -0
- package/frontend/src/components/ui/callout-node.tsx +63 -0
- package/frontend/src/components/ui/caption.tsx +63 -0
- package/frontend/src/components/ui/checkbox.tsx +30 -0
- package/frontend/src/components/ui/code-block-node-static.tsx +35 -0
- package/frontend/src/components/ui/code-block-node.tsx +287 -0
- package/frontend/src/components/ui/code-node-static.tsx +15 -0
- package/frontend/src/components/ui/code-node.tsx +17 -0
- package/frontend/src/components/ui/codebase-snippet-node.tsx +237 -0
- package/frontend/src/components/ui/column-node-static.tsx +29 -0
- package/frontend/src/components/ui/column-node.tsx +317 -0
- package/frontend/src/components/ui/command.tsx +182 -0
- package/frontend/src/components/ui/comment-node-static.tsx +15 -0
- package/frontend/src/components/ui/comment-node.tsx +45 -0
- package/frontend/src/components/ui/comment-toolbar-button.tsx +24 -0
- package/frontend/src/components/ui/comment.tsx +618 -0
- package/frontend/src/components/ui/context-menu.tsx +250 -0
- package/frontend/src/components/ui/cursor-overlay.tsx +66 -0
- package/frontend/src/components/ui/date-node-static.tsx +45 -0
- package/frontend/src/components/ui/date-node.tsx +93 -0
- package/frontend/src/components/ui/dialog.tsx +143 -0
- package/frontend/src/components/ui/dropdown-menu.tsx +255 -0
- package/frontend/src/components/ui/dynamic-icon.tsx +12 -0
- package/frontend/src/components/ui/editor-static.tsx +53 -0
- package/frontend/src/components/ui/editor.tsx +130 -0
- package/frontend/src/components/ui/emoji-node.tsx +69 -0
- package/frontend/src/components/ui/emoji-toolbar-button.tsx +628 -0
- package/frontend/src/components/ui/equation-node-static.tsx +98 -0
- package/frontend/src/components/ui/equation-node.tsx +235 -0
- package/frontend/src/components/ui/equation-toolbar-button.tsx +25 -0
- package/frontend/src/components/ui/excalidraw-node.tsx +36 -0
- package/frontend/src/components/ui/export-toolbar-button.tsx +174 -0
- package/frontend/src/components/ui/file-selector.tsx +339 -0
- package/frontend/src/components/ui/floating-toolbar-buttons.tsx +73 -0
- package/frontend/src/components/ui/floating-toolbar.tsx +85 -0
- package/frontend/src/components/ui/font-color-toolbar-button.tsx +831 -0
- package/frontend/src/components/ui/font-size-toolbar-button.tsx +152 -0
- package/frontend/src/components/ui/heading-node-static.tsx +68 -0
- package/frontend/src/components/ui/heading-node.tsx +58 -0
- package/frontend/src/components/ui/highlight-node-static.tsx +11 -0
- package/frontend/src/components/ui/highlight-node.tsx +13 -0
- package/frontend/src/components/ui/history-toolbar-button.tsx +50 -0
- package/frontend/src/components/ui/hr-node-static.tsx +20 -0
- package/frontend/src/components/ui/hr-node.tsx +33 -0
- package/frontend/src/components/ui/import-toolbar-button.tsx +97 -0
- package/frontend/src/components/ui/indent-toolbar-button.tsx +30 -0
- package/frontend/src/components/ui/inline-combobox.tsx +414 -0
- package/frontend/src/components/ui/input.tsx +21 -0
- package/frontend/src/components/ui/insert-toolbar-button.tsx +254 -0
- package/frontend/src/components/ui/kbd-node-static.tsx +15 -0
- package/frontend/src/components/ui/kbd-node.tsx +17 -0
- package/frontend/src/components/ui/layout-header.tsx +35 -0
- package/frontend/src/components/ui/line-height-toolbar-button.tsx +68 -0
- package/frontend/src/components/ui/link-node-static.tsx +21 -0
- package/frontend/src/components/ui/link-node.tsx +39 -0
- package/frontend/src/components/ui/link-toolbar-button.tsx +22 -0
- package/frontend/src/components/ui/link-toolbar.tsx +206 -0
- package/frontend/src/components/ui/list-toolbar-button.tsx +204 -0
- package/frontend/src/components/ui/mark-toolbar-button.tsx +19 -0
- package/frontend/src/components/ui/media-audio-node-static.tsx +17 -0
- package/frontend/src/components/ui/media-audio-node.tsx +39 -0
- package/frontend/src/components/ui/media-embed-node.tsx +136 -0
- package/frontend/src/components/ui/media-file-node-static.tsx +29 -0
- package/frontend/src/components/ui/media-file-node.tsx +47 -0
- package/frontend/src/components/ui/media-image-node-static.tsx +39 -0
- package/frontend/src/components/ui/media-image-node.tsx +80 -0
- package/frontend/src/components/ui/media-placeholder-node.tsx +249 -0
- package/frontend/src/components/ui/media-preview-dialog.tsx +152 -0
- package/frontend/src/components/ui/media-toolbar-button.tsx +225 -0
- package/frontend/src/components/ui/media-toolbar.tsx +115 -0
- package/frontend/src/components/ui/media-upload-toast.tsx +66 -0
- package/frontend/src/components/ui/media-video-node-static.tsx +30 -0
- package/frontend/src/components/ui/media-video-node.tsx +121 -0
- package/frontend/src/components/ui/mention-node-static.tsx +36 -0
- package/frontend/src/components/ui/mention-node.tsx +194 -0
- package/frontend/src/components/ui/mode-toolbar-button.tsx +123 -0
- package/frontend/src/components/ui/more-toolbar-button.tsx +80 -0
- package/frontend/src/components/ui/paragraph-node-static.tsx +13 -0
- package/frontend/src/components/ui/paragraph-node.tsx +15 -0
- package/frontend/src/components/ui/popover.tsx +46 -0
- package/frontend/src/components/ui/resize-handle.tsx +87 -0
- package/frontend/src/components/ui/separator.tsx +28 -0
- package/frontend/src/components/ui/sheet.tsx +139 -0
- package/frontend/src/components/ui/sidebar.tsx +726 -0
- package/frontend/src/components/ui/skeleton.tsx +13 -0
- package/frontend/src/components/ui/slash-node.tsx +233 -0
- package/frontend/src/components/ui/sonner.tsx +38 -0
- package/frontend/src/components/ui/suggestion-node-static.tsx +35 -0
- package/frontend/src/components/ui/suggestion-node.tsx +162 -0
- package/frontend/src/components/ui/suggestion-toolbar-button.tsx +25 -0
- package/frontend/src/components/ui/table-icons.tsx +862 -0
- package/frontend/src/components/ui/table-node-static.tsx +98 -0
- package/frontend/src/components/ui/table-node.tsx +656 -0
- package/frontend/src/components/ui/table-toolbar-button.tsx +264 -0
- package/frontend/src/components/ui/toc-node-static.tsx +92 -0
- package/frontend/src/components/ui/toc-node.tsx +55 -0
- package/frontend/src/components/ui/toggle-node-static.tsx +18 -0
- package/frontend/src/components/ui/toggle-node.tsx +36 -0
- package/frontend/src/components/ui/toggle-toolbar-button.tsx +22 -0
- package/frontend/src/components/ui/toolbar.tsx +387 -0
- package/frontend/src/components/ui/tooltip.tsx +59 -0
- package/frontend/src/components/ui/turn-into-toolbar-button.tsx +188 -0
- package/frontend/src/hooks/use-debounce.ts +18 -0
- package/frontend/src/hooks/use-is-touch-device.ts +24 -0
- package/frontend/src/hooks/use-mobile.ts +19 -0
- package/frontend/src/hooks/use-mounted.ts +11 -0
- package/frontend/src/hooks/use-upload-file.ts +128 -0
- package/frontend/src/index.css +128 -0
- package/frontend/src/layout.tsx +42 -0
- package/frontend/src/lib/markdown-joiner-transform.ts +239 -0
- package/frontend/src/lib/orpc.ts +13 -0
- package/frontend/src/lib/uploadthing.ts +19 -0
- package/frontend/src/lib/utils.ts +6 -0
- package/frontend/src/main.tsx +13 -0
- package/frontend/src/pages/editor.tsx +44 -0
- package/frontend/src/types/docs.d.ts +6 -0
- package/frontend/src/types/global.d.ts +9 -0
- package/frontend/src/types/router.d.ts +4 -0
- package/frontend/tsconfig.app.json +33 -0
- package/frontend/tsconfig.json +10 -0
- package/frontend/tsconfig.node.json +26 -0
- package/frontend/vite.config.ts +14 -0
- package/package.json +30 -0
- package/src/bin/doclific.ts +17 -0
- package/src/core/codebase.ts +39 -0
- package/src/core/docs.ts +90 -0
- package/src/core/git.ts +48 -0
- package/src/server/index.ts +55 -0
- package/src/server/router.ts +65 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { CaptionPlugin } from '@platejs/caption/react';
|
|
4
|
+
import {
|
|
5
|
+
AudioPlugin,
|
|
6
|
+
FilePlugin,
|
|
7
|
+
ImagePlugin,
|
|
8
|
+
MediaEmbedPlugin,
|
|
9
|
+
PlaceholderPlugin,
|
|
10
|
+
VideoPlugin,
|
|
11
|
+
} from '@platejs/media/react';
|
|
12
|
+
import { KEYS } from 'platejs';
|
|
13
|
+
|
|
14
|
+
import { AudioElement } from '@/components/ui/media-audio-node';
|
|
15
|
+
import { MediaEmbedElement } from '@/components/ui/media-embed-node';
|
|
16
|
+
import { FileElement } from '@/components/ui/media-file-node';
|
|
17
|
+
import { ImageElement } from '@/components/ui/media-image-node';
|
|
18
|
+
import { PlaceholderElement } from '@/components/ui/media-placeholder-node';
|
|
19
|
+
import { MediaPreviewDialog } from '@/components/ui/media-preview-dialog';
|
|
20
|
+
import { MediaUploadToast } from '@/components/ui/media-upload-toast';
|
|
21
|
+
import { VideoElement } from '@/components/ui/media-video-node';
|
|
22
|
+
|
|
23
|
+
export const MediaKit = [
|
|
24
|
+
ImagePlugin.configure({
|
|
25
|
+
options: { disableUploadInsert: true },
|
|
26
|
+
render: { afterEditable: MediaPreviewDialog, node: ImageElement },
|
|
27
|
+
}),
|
|
28
|
+
MediaEmbedPlugin.withComponent(MediaEmbedElement),
|
|
29
|
+
VideoPlugin.withComponent(VideoElement),
|
|
30
|
+
AudioPlugin.withComponent(AudioElement),
|
|
31
|
+
FilePlugin.withComponent(FileElement),
|
|
32
|
+
PlaceholderPlugin.configure({
|
|
33
|
+
options: { disableEmptyPlaceholder: true },
|
|
34
|
+
render: { afterEditable: MediaUploadToast, node: PlaceholderElement },
|
|
35
|
+
}),
|
|
36
|
+
CaptionPlugin.configure({
|
|
37
|
+
options: {
|
|
38
|
+
query: {
|
|
39
|
+
allow: [KEYS.img, KEYS.video, KEYS.audio, KEYS.file, KEYS.mediaEmbed],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { MentionInputPlugin, MentionPlugin } from '@platejs/mention/react';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
MentionElement,
|
|
7
|
+
MentionInputElement,
|
|
8
|
+
} from '@/components/ui/mention-node';
|
|
9
|
+
|
|
10
|
+
export const MentionKit = [
|
|
11
|
+
MentionPlugin.configure({
|
|
12
|
+
options: { triggerPreviousCharPattern: /^$|^[\s"']$/ },
|
|
13
|
+
}).withComponent(MentionElement),
|
|
14
|
+
MentionInputPlugin.withComponent(MentionInputElement),
|
|
15
|
+
];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { SlashInputPlugin, SlashPlugin } from '@platejs/slash-command/react';
|
|
4
|
+
import { KEYS } from 'platejs';
|
|
5
|
+
|
|
6
|
+
import { SlashInputElement } from '@/components/ui/slash-node';
|
|
7
|
+
|
|
8
|
+
export const SlashKit = [
|
|
9
|
+
SlashPlugin.configure({
|
|
10
|
+
options: {
|
|
11
|
+
triggerQuery: (editor) =>
|
|
12
|
+
!editor.api.some({
|
|
13
|
+
match: { type: editor.getType(KEYS.codeBlock) },
|
|
14
|
+
}),
|
|
15
|
+
},
|
|
16
|
+
}),
|
|
17
|
+
SlashInputPlugin.withComponent(SlashInputElement),
|
|
18
|
+
];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type { ExtendConfig, Path } from 'platejs';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type BaseSuggestionConfig,
|
|
7
|
+
BaseSuggestionPlugin,
|
|
8
|
+
} from '@platejs/suggestion';
|
|
9
|
+
import { isSlateEditor, isSlateString } from 'platejs';
|
|
10
|
+
import { toTPlatePlugin } from 'platejs/react';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
SuggestionLeaf,
|
|
14
|
+
SuggestionLineBreak,
|
|
15
|
+
} from '@/components/ui/suggestion-node';
|
|
16
|
+
|
|
17
|
+
import { discussionPlugin } from './discussion-kit';
|
|
18
|
+
|
|
19
|
+
export type SuggestionConfig = ExtendConfig<
|
|
20
|
+
BaseSuggestionConfig,
|
|
21
|
+
{
|
|
22
|
+
activeId: string | null;
|
|
23
|
+
hoverId: string | null;
|
|
24
|
+
uniquePathMap: Map<string, Path>;
|
|
25
|
+
}
|
|
26
|
+
>;
|
|
27
|
+
|
|
28
|
+
export const suggestionPlugin = toTPlatePlugin<SuggestionConfig>(
|
|
29
|
+
BaseSuggestionPlugin,
|
|
30
|
+
({ editor }) => ({
|
|
31
|
+
options: {
|
|
32
|
+
activeId: null,
|
|
33
|
+
currentUserId: editor.getOption(discussionPlugin, 'currentUserId'),
|
|
34
|
+
hoverId: null,
|
|
35
|
+
uniquePathMap: new Map(),
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
).configure({
|
|
39
|
+
handlers: {
|
|
40
|
+
// unset active suggestion when clicking outside of suggestion
|
|
41
|
+
onClick: ({ api, event, setOption, type }) => {
|
|
42
|
+
let leaf = event.target as HTMLElement;
|
|
43
|
+
let isSet = false;
|
|
44
|
+
|
|
45
|
+
const isBlockLeaf = leaf.dataset.blockSuggestion === 'true';
|
|
46
|
+
|
|
47
|
+
const unsetActiveSuggestion = () => {
|
|
48
|
+
setOption('activeId', null);
|
|
49
|
+
isSet = true;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if (!isSlateString(leaf) && !isBlockLeaf) {
|
|
53
|
+
unsetActiveSuggestion();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
while (leaf.parentElement && !isSlateEditor(leaf.parentElement)) {
|
|
57
|
+
const isBlockSuggestion = leaf.dataset.blockSuggestion === 'true';
|
|
58
|
+
|
|
59
|
+
if (leaf.classList.contains(`slate-${type}`) || isBlockSuggestion) {
|
|
60
|
+
const suggestionEntry = api.suggestion!.node({
|
|
61
|
+
isText: !isBlockSuggestion,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (!suggestionEntry) {
|
|
65
|
+
unsetActiveSuggestion();
|
|
66
|
+
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const id = api.suggestion!.nodeId(suggestionEntry[0]);
|
|
71
|
+
setOption('activeId', id ?? null);
|
|
72
|
+
|
|
73
|
+
isSet = true;
|
|
74
|
+
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
leaf = leaf.parentElement;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!isSet) unsetActiveSuggestion();
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
render: {
|
|
85
|
+
belowNodes: SuggestionLineBreak as any,
|
|
86
|
+
node: SuggestionLeaf,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export const SuggestionKit = [suggestionPlugin];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseTableCellHeaderPlugin,
|
|
3
|
+
BaseTableCellPlugin,
|
|
4
|
+
BaseTablePlugin,
|
|
5
|
+
BaseTableRowPlugin,
|
|
6
|
+
} from '@platejs/table';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
TableCellElementStatic,
|
|
10
|
+
TableCellHeaderElementStatic,
|
|
11
|
+
TableElementStatic,
|
|
12
|
+
TableRowElementStatic,
|
|
13
|
+
} from '@/components/ui/table-node-static';
|
|
14
|
+
|
|
15
|
+
export const BaseTableKit = [
|
|
16
|
+
BaseTablePlugin.withComponent(TableElementStatic),
|
|
17
|
+
BaseTableRowPlugin.withComponent(TableRowElementStatic),
|
|
18
|
+
BaseTableCellPlugin.withComponent(TableCellElementStatic),
|
|
19
|
+
BaseTableCellHeaderPlugin.withComponent(TableCellHeaderElementStatic),
|
|
20
|
+
];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
TableCellHeaderPlugin,
|
|
5
|
+
TableCellPlugin,
|
|
6
|
+
TablePlugin,
|
|
7
|
+
TableRowPlugin,
|
|
8
|
+
} from '@platejs/table/react';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
TableCellElement,
|
|
12
|
+
TableCellHeaderElement,
|
|
13
|
+
TableElement,
|
|
14
|
+
TableRowElement,
|
|
15
|
+
} from '@/components/ui/table-node';
|
|
16
|
+
|
|
17
|
+
export const TableKit = [
|
|
18
|
+
TablePlugin.withComponent(TableElement),
|
|
19
|
+
TableRowPlugin.withComponent(TableRowElement),
|
|
20
|
+
TableCellPlugin.withComponent(TableCellElement),
|
|
21
|
+
TableCellHeaderPlugin.withComponent(TableCellHeaderElement),
|
|
22
|
+
];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { TocPlugin } from '@platejs/toc/react';
|
|
4
|
+
|
|
5
|
+
import { TocElement } from '@/components/ui/toc-node';
|
|
6
|
+
|
|
7
|
+
export const TocKit = [
|
|
8
|
+
TocPlugin.configure({
|
|
9
|
+
options: {
|
|
10
|
+
// isScroll: true,
|
|
11
|
+
topOffset: 80,
|
|
12
|
+
},
|
|
13
|
+
}).withComponent(TocElement),
|
|
14
|
+
];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { TogglePlugin } from '@platejs/toggle/react';
|
|
4
|
+
|
|
5
|
+
import { IndentKit } from '@/components/editor/plugins/indent-kit';
|
|
6
|
+
import { ToggleElement } from '@/components/ui/toggle-node';
|
|
7
|
+
|
|
8
|
+
export const ToggleKit = [
|
|
9
|
+
...IndentKit,
|
|
10
|
+
TogglePlugin.withComponent(ToggleElement),
|
|
11
|
+
];
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type { PlateEditor } from 'platejs/react';
|
|
4
|
+
|
|
5
|
+
import { insertCallout } from '@platejs/callout';
|
|
6
|
+
import { insertCodeBlock, toggleCodeBlock } from '@platejs/code-block';
|
|
7
|
+
import { insertDate } from '@platejs/date';
|
|
8
|
+
import { insertExcalidraw } from '@platejs/excalidraw';
|
|
9
|
+
import { insertColumnGroup, toggleColumnGroup } from '@platejs/layout';
|
|
10
|
+
import { triggerFloatingLink } from '@platejs/link/react';
|
|
11
|
+
import { insertEquation, insertInlineEquation } from '@platejs/math';
|
|
12
|
+
import {
|
|
13
|
+
insertAudioPlaceholder,
|
|
14
|
+
insertFilePlaceholder,
|
|
15
|
+
insertMedia,
|
|
16
|
+
insertVideoPlaceholder,
|
|
17
|
+
} from '@platejs/media';
|
|
18
|
+
import { SuggestionPlugin } from '@platejs/suggestion/react';
|
|
19
|
+
import { TablePlugin } from '@platejs/table/react';
|
|
20
|
+
import { insertToc } from '@platejs/toc';
|
|
21
|
+
import { type NodeEntry, type Path, type TElement, KEYS, PathApi } from 'platejs';
|
|
22
|
+
import { CodebaseSnippetType } from './plugins/codebase-kit';
|
|
23
|
+
|
|
24
|
+
const ACTION_THREE_COLUMNS = 'action_three_columns';
|
|
25
|
+
|
|
26
|
+
const insertList = (editor: PlateEditor, type: string) => {
|
|
27
|
+
editor.tf.insertNodes(
|
|
28
|
+
editor.api.create.block({
|
|
29
|
+
indent: 1,
|
|
30
|
+
listStyleType: type,
|
|
31
|
+
}),
|
|
32
|
+
{ select: true }
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const insertBlockMap: Record<string, (editor: PlateEditor, type: string) => void> = {
|
|
37
|
+
[KEYS.listTodo]: insertList,
|
|
38
|
+
[KEYS.ol]: insertList,
|
|
39
|
+
[KEYS.ul]: insertList,
|
|
40
|
+
[ACTION_THREE_COLUMNS]: (editor) => insertColumnGroup(editor, { columns: 3, select: true }),
|
|
41
|
+
[KEYS.audio]: (editor) => insertAudioPlaceholder(editor, { select: true }),
|
|
42
|
+
[KEYS.callout]: (editor) => insertCallout(editor, { select: true }),
|
|
43
|
+
[KEYS.codeBlock]: (editor) => insertCodeBlock(editor, { select: true }),
|
|
44
|
+
[KEYS.equation]: (editor) => insertEquation(editor, { select: true }),
|
|
45
|
+
[KEYS.excalidraw]: (editor) => insertExcalidraw(editor, {}, { select: true }),
|
|
46
|
+
[KEYS.file]: (editor) => insertFilePlaceholder(editor, { select: true }),
|
|
47
|
+
[KEYS.img]: (editor) =>
|
|
48
|
+
insertMedia(editor, {
|
|
49
|
+
select: true,
|
|
50
|
+
type: KEYS.img,
|
|
51
|
+
}),
|
|
52
|
+
[KEYS.mediaEmbed]: (editor) =>
|
|
53
|
+
insertMedia(editor, {
|
|
54
|
+
select: true,
|
|
55
|
+
type: KEYS.mediaEmbed,
|
|
56
|
+
}),
|
|
57
|
+
[KEYS.table]: (editor) => editor.getTransforms(TablePlugin).insert.table({}, { select: true }),
|
|
58
|
+
[KEYS.toc]: (editor) => insertToc(editor, { select: true }),
|
|
59
|
+
[KEYS.video]: (editor) => insertVideoPlaceholder(editor, { select: true }),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const insertInlineMap: Record<string, (editor: PlateEditor, type: string) => void> = {
|
|
63
|
+
[KEYS.date]: (editor) => insertDate(editor, { select: true }),
|
|
64
|
+
[KEYS.inlineEquation]: (editor) => insertInlineEquation(editor, '', { select: true }),
|
|
65
|
+
[KEYS.link]: (editor) => triggerFloatingLink(editor, { focused: true }),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
type InsertBlockOptions = {
|
|
69
|
+
upsert?: boolean;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const insertBlock = (
|
|
73
|
+
editor: PlateEditor,
|
|
74
|
+
type: string,
|
|
75
|
+
options: InsertBlockOptions = {}
|
|
76
|
+
) => {
|
|
77
|
+
const { upsert = false } = options;
|
|
78
|
+
|
|
79
|
+
editor.tf.withoutNormalizing(() => {
|
|
80
|
+
const block = editor.api.block();
|
|
81
|
+
|
|
82
|
+
if (!block) return;
|
|
83
|
+
|
|
84
|
+
const [currentNode, path] = block;
|
|
85
|
+
const isCurrentBlockEmpty = editor.api.isEmpty(currentNode);
|
|
86
|
+
const currentBlockType = getBlockType(currentNode);
|
|
87
|
+
|
|
88
|
+
const isSameBlockType = type === currentBlockType;
|
|
89
|
+
|
|
90
|
+
if (upsert && isCurrentBlockEmpty && isSameBlockType) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (type in insertBlockMap) {
|
|
95
|
+
insertBlockMap[type](editor, type);
|
|
96
|
+
} else if (type === CodebaseSnippetType) {
|
|
97
|
+
editor.tf.insertNodes({
|
|
98
|
+
type: CodebaseSnippetType,
|
|
99
|
+
filePath: '',
|
|
100
|
+
lineStart: '',
|
|
101
|
+
lineEnd: '',
|
|
102
|
+
children: [{ text: '' }],
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
editor.tf.insertNodes(editor.api.create.block({ type }), {
|
|
106
|
+
at: PathApi.next(path),
|
|
107
|
+
select: true,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!isSameBlockType) {
|
|
112
|
+
editor.getApi(SuggestionPlugin).suggestion.withoutSuggestions(() => {
|
|
113
|
+
editor.tf.removeNodes({ previousEmptyBlock: true });
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const insertInlineElement = (editor: PlateEditor, type: string) => {
|
|
120
|
+
if (insertInlineMap[type]) {
|
|
121
|
+
insertInlineMap[type](editor, type);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const setList = (editor: PlateEditor, type: string, entry: NodeEntry<TElement>) => {
|
|
126
|
+
editor.tf.setNodes(
|
|
127
|
+
editor.api.create.block({
|
|
128
|
+
indent: 1,
|
|
129
|
+
listStyleType: type,
|
|
130
|
+
}),
|
|
131
|
+
{
|
|
132
|
+
at: entry[1],
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const setBlockMap: Record<
|
|
138
|
+
string,
|
|
139
|
+
(editor: PlateEditor, type: string, entry: NodeEntry<TElement>) => void
|
|
140
|
+
> = {
|
|
141
|
+
[KEYS.listTodo]: setList,
|
|
142
|
+
[KEYS.ol]: setList,
|
|
143
|
+
[KEYS.ul]: setList,
|
|
144
|
+
[ACTION_THREE_COLUMNS]: (editor) => toggleColumnGroup(editor, { columns: 3 }),
|
|
145
|
+
[KEYS.codeBlock]: (editor) => toggleCodeBlock(editor),
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export const setBlockType = (editor: PlateEditor, type: string, { at }: { at?: Path } = {}) => {
|
|
149
|
+
editor.tf.withoutNormalizing(() => {
|
|
150
|
+
const setEntry = (entry: NodeEntry<TElement>) => {
|
|
151
|
+
const [node, path] = entry;
|
|
152
|
+
|
|
153
|
+
if (node[KEYS.listType]) {
|
|
154
|
+
editor.tf.unsetNodes([KEYS.listType, 'indent'], { at: path });
|
|
155
|
+
}
|
|
156
|
+
if (type in setBlockMap) {
|
|
157
|
+
return setBlockMap[type](editor, type, entry);
|
|
158
|
+
}
|
|
159
|
+
if (node.type !== type) {
|
|
160
|
+
editor.tf.setNodes({ type }, { at: path });
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
if (at) {
|
|
165
|
+
const entry = editor.api.node<TElement>(at);
|
|
166
|
+
|
|
167
|
+
if (entry) {
|
|
168
|
+
setEntry(entry);
|
|
169
|
+
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const entries = editor.api.blocks({ mode: 'lowest' });
|
|
175
|
+
|
|
176
|
+
entries.forEach((entry) => {
|
|
177
|
+
setEntry(entry);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export const getBlockType = (block: TElement) => {
|
|
183
|
+
if (block[KEYS.listType]) {
|
|
184
|
+
if (block[KEYS.listType] === KEYS.ol) {
|
|
185
|
+
return KEYS.ol;
|
|
186
|
+
}
|
|
187
|
+
if (block[KEYS.listType] === KEYS.listTodo) {
|
|
188
|
+
return KEYS.listTodo;
|
|
189
|
+
}
|
|
190
|
+
return KEYS.ul;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return block.type;
|
|
194
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { MarkdownPlugin, remarkMdx, remarkMention } from '@platejs/markdown';
|
|
2
|
+
import { Plate, usePlateEditor } from 'platejs/react';
|
|
3
|
+
import remarkEmoji from 'remark-emoji';
|
|
4
|
+
import remarkGfm from 'remark-gfm';
|
|
5
|
+
import remarkMath from 'remark-math';
|
|
6
|
+
import { useEffect, useRef } from 'react';
|
|
7
|
+
|
|
8
|
+
import { EditorKit } from '@/components/editor/editor-kit';
|
|
9
|
+
import { Editor, EditorContainer } from '@/components/ui/editor';
|
|
10
|
+
|
|
11
|
+
export default function MarkdownDemo(
|
|
12
|
+
{ initialMarkdown, onUpdate }: { initialMarkdown: string, onUpdate: (content: string) => void }
|
|
13
|
+
) {
|
|
14
|
+
const previousMarkdown = useRef<string>('');
|
|
15
|
+
const editor = usePlateEditor(
|
|
16
|
+
{
|
|
17
|
+
plugins: EditorKit,
|
|
18
|
+
value: (editor) => editor.getApi(MarkdownPlugin).markdown.deserialize(initialMarkdown, {
|
|
19
|
+
remarkPlugins: [
|
|
20
|
+
remarkMath,
|
|
21
|
+
remarkGfm,
|
|
22
|
+
remarkMdx,
|
|
23
|
+
remarkMention,
|
|
24
|
+
remarkEmoji as any,
|
|
25
|
+
],
|
|
26
|
+
})
|
|
27
|
+
},
|
|
28
|
+
[]
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// useEffect that runs every 250ms and logs the serialized markdown to the console
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const interval = setInterval(() => {
|
|
34
|
+
const serialized = editor.getApi(MarkdownPlugin).markdown.serialize();
|
|
35
|
+
if (serialized !== previousMarkdown.current) {
|
|
36
|
+
previousMarkdown.current = serialized;
|
|
37
|
+
onUpdate(serialized);
|
|
38
|
+
}
|
|
39
|
+
}, 500);
|
|
40
|
+
return () => clearInterval(interval);
|
|
41
|
+
}, [editor, onUpdate]);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<Plate editor={editor}>
|
|
45
|
+
<EditorContainer>
|
|
46
|
+
<Editor variant="none" className="px-8 py-2" />
|
|
47
|
+
</EditorContainer>
|
|
48
|
+
</Plate>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Moon, Sun } from "lucide-react"
|
|
2
|
+
import { Button } from "@/components/ui/button"
|
|
3
|
+
import { useTheme } from "@/components/theme-provider"
|
|
4
|
+
|
|
5
|
+
export function ModeToggle() {
|
|
6
|
+
const { setTheme, theme } = useTheme()
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<Button variant="outline" size="icon" onClick={() => setTheme(theme === "dark" ? "light" : "dark")}>
|
|
10
|
+
<Sun className="h-[1.2rem] w-[1.2rem] scale-100 rotate-0 transition-all dark:scale-0 dark:-rotate-90" />
|
|
11
|
+
<Moon className="absolute h-[1.2rem] w-[1.2rem] scale-0 rotate-90 transition-all dark:scale-100 dark:rotate-0" />
|
|
12
|
+
<span className="sr-only">Toggle theme</span>
|
|
13
|
+
</Button>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createContext, useContext, useEffect, useState } from "react"
|
|
2
|
+
|
|
3
|
+
type Theme = "dark" | "light" | "system"
|
|
4
|
+
|
|
5
|
+
type ThemeProviderProps = {
|
|
6
|
+
children: React.ReactNode
|
|
7
|
+
defaultTheme?: Theme
|
|
8
|
+
storageKey?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type ThemeProviderState = {
|
|
12
|
+
theme: Theme
|
|
13
|
+
setTheme: (theme: Theme) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const initialState: ThemeProviderState = {
|
|
17
|
+
theme: "system",
|
|
18
|
+
setTheme: () => null,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const ThemeProviderContext = createContext<ThemeProviderState>(initialState)
|
|
22
|
+
|
|
23
|
+
export function ThemeProvider({
|
|
24
|
+
children,
|
|
25
|
+
defaultTheme = "system",
|
|
26
|
+
storageKey = "vite-ui-theme",
|
|
27
|
+
...props
|
|
28
|
+
}: ThemeProviderProps) {
|
|
29
|
+
const [theme, setTheme] = useState<Theme>(
|
|
30
|
+
() => (localStorage.getItem(storageKey) as Theme) || defaultTheme
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const root = window.document.documentElement
|
|
35
|
+
|
|
36
|
+
root.classList.remove("light", "dark")
|
|
37
|
+
|
|
38
|
+
if (theme === "system") {
|
|
39
|
+
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)")
|
|
40
|
+
.matches
|
|
41
|
+
? "dark"
|
|
42
|
+
: "light"
|
|
43
|
+
|
|
44
|
+
root.classList.add(systemTheme)
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
root.classList.add(theme)
|
|
49
|
+
}, [theme])
|
|
50
|
+
|
|
51
|
+
const value = {
|
|
52
|
+
theme,
|
|
53
|
+
setTheme: (theme: Theme) => {
|
|
54
|
+
localStorage.setItem(storageKey, theme)
|
|
55
|
+
setTheme(theme)
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<ThemeProviderContext.Provider {...props} value={value}>
|
|
61
|
+
{children}
|
|
62
|
+
</ThemeProviderContext.Provider>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const useTheme = () => {
|
|
67
|
+
const context = useContext(ThemeProviderContext)
|
|
68
|
+
|
|
69
|
+
if (context === undefined)
|
|
70
|
+
throw new Error("useTheme must be used within a ThemeProvider")
|
|
71
|
+
|
|
72
|
+
return context
|
|
73
|
+
}
|