@docyrus/ui-pro-ai-assistant 0.0.1
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/dist/index.js +26161 -0
- package/dist/index.js.map +1 -0
- package/package.json +155 -0
- package/src/components/assistant-animations.tsx +29 -0
- package/src/components/assistant-dialogs.tsx +235 -0
- package/src/components/code-view.tsx +278 -0
- package/src/components/create-agent-task.tsx +104 -0
- package/src/components/create-new-work-version.tsx +30 -0
- package/src/components/extract-web.tsx +160 -0
- package/src/components/forward-to-agent.tsx +90 -0
- package/src/components/generate-chart.tsx +101 -0
- package/src/components/generative-action-button.tsx +122 -0
- package/src/components/generative-tool.tsx +685 -0
- package/src/components/generative-ui-object.tsx +210 -0
- package/src/components/input-area.tsx +1209 -0
- package/src/components/json-schema-layout.tsx +326 -0
- package/src/components/list-item-card.tsx +92 -0
- package/src/components/mermaid-diagram.tsx +192 -0
- package/src/components/preview-image.tsx +47 -0
- package/src/components/request-approval.tsx +48 -0
- package/src/components/request-user-input.tsx +270 -0
- package/src/components/search-web.tsx +319 -0
- package/src/components/sheet-command.tsx +88 -0
- package/src/components/shell-canvas.tsx +122 -0
- package/src/components/show-advanced-data-table.tsx +352 -0
- package/src/components/show-generated-content-options.tsx +93 -0
- package/src/components/show-people-cards.tsx +180 -0
- package/src/components/subagent-tool.tsx +180 -0
- package/src/components/text-editor-tool.tsx +328 -0
- package/src/components/work-canvas.tsx +88 -0
- package/src/components/work-card.tsx +42 -0
- package/src/declarations.d.ts +1 -0
- package/src/docy-assistant.tsx +1962 -0
- package/src/hooks/index.ts +7 -0
- package/src/hooks/use-assistant-api.ts +507 -0
- package/src/hooks/use-deployment-data.ts +162 -0
- package/src/hooks/use-project-state.ts +347 -0
- package/src/hooks/use-session-state.ts +207 -0
- package/src/hooks/use-speech-recognition.ts +137 -0
- package/src/hooks/use-ui-state.ts +185 -0
- package/src/hooks/use-works-state.ts +146 -0
- package/src/i18n/context.tsx +253 -0
- package/src/i18n/index.ts +19 -0
- package/src/i18n/locales/de.json +198 -0
- package/src/i18n/locales/el.json +198 -0
- package/src/i18n/locales/en.json +226 -0
- package/src/i18n/locales/es.json +198 -0
- package/src/i18n/locales/fr.json +198 -0
- package/src/i18n/locales/it.json +198 -0
- package/src/i18n/locales/pt.json +198 -0
- package/src/i18n/locales/sl.json +198 -0
- package/src/i18n/locales/tr.json +211 -0
- package/src/i18n/types.ts +23 -0
- package/src/i18n/use-translation.ts +17 -0
- package/src/index.ts +18 -0
- package/src/internal/plate-editor/editor/auth-context.ts +11 -0
- package/src/internal/plate-editor/editor/editor-base-kit.tsx +39 -0
- package/src/internal/plate-editor/editor/editor-kit.tsx +89 -0
- package/src/internal/plate-editor/editor/plate-editor.tsx +75 -0
- package/src/internal/plate-editor/editor/plate-types.ts +126 -0
- package/src/internal/plate-editor/editor/plugins/ai-kit.tsx +172 -0
- package/src/internal/plate-editor/editor/plugins/autoformat-kit.tsx +211 -0
- package/src/internal/plate-editor/editor/plugins/basic-blocks-base-kit.tsx +26 -0
- package/src/internal/plate-editor/editor/plugins/basic-blocks-kit.tsx +51 -0
- package/src/internal/plate-editor/editor/plugins/basic-marks-base-kit.tsx +24 -0
- package/src/internal/plate-editor/editor/plugins/basic-marks-kit.tsx +38 -0
- package/src/internal/plate-editor/editor/plugins/basic-nodes-kit.tsx +6 -0
- package/src/internal/plate-editor/editor/plugins/block-menu-kit.tsx +14 -0
- package/src/internal/plate-editor/editor/plugins/block-placeholder-kit.tsx +17 -0
- package/src/internal/plate-editor/editor/plugins/block-selection-kit.tsx +31 -0
- package/src/internal/plate-editor/editor/plugins/callout-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/callout-kit.tsx +7 -0
- package/src/internal/plate-editor/editor/plugins/code-block-base-kit.tsx +23 -0
- package/src/internal/plate-editor/editor/plugins/code-block-kit.tsx +26 -0
- package/src/internal/plate-editor/editor/plugins/column-base-kit.tsx +8 -0
- package/src/internal/plate-editor/editor/plugins/column-kit.tsx +7 -0
- package/src/internal/plate-editor/editor/plugins/comment-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/comment-kit.tsx +174 -0
- package/src/internal/plate-editor/editor/plugins/copilot-kit.tsx +68 -0
- package/src/internal/plate-editor/editor/plugins/cursor-overlay-kit.tsx +13 -0
- package/src/internal/plate-editor/editor/plugins/date-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/date-kit.tsx +7 -0
- package/src/internal/plate-editor/editor/plugins/discussion-kit.tsx +36 -0
- package/src/internal/plate-editor/editor/plugins/dnd-kit.tsx +27 -0
- package/src/internal/plate-editor/editor/plugins/docx-export-kit.tsx +43 -0
- package/src/internal/plate-editor/editor/plugins/docx-kit.tsx +6 -0
- package/src/internal/plate-editor/editor/plugins/emoji-kit.tsx +15 -0
- package/src/internal/plate-editor/editor/plugins/exit-break-kit.tsx +12 -0
- package/src/internal/plate-editor/editor/plugins/floating-toolbar-kit.tsx +19 -0
- package/src/internal/plate-editor/editor/plugins/font-base-kit.tsx +36 -0
- package/src/internal/plate-editor/editor/plugins/font-kit.tsx +47 -0
- package/src/internal/plate-editor/editor/plugins/indent-base-kit.tsx +19 -0
- package/src/internal/plate-editor/editor/plugins/indent-kit.tsx +22 -0
- package/src/internal/plate-editor/editor/plugins/link-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/link-kit.tsx +35 -0
- package/src/internal/plate-editor/editor/plugins/list-base-kit.tsx +24 -0
- package/src/internal/plate-editor/editor/plugins/list-kit.tsx +27 -0
- package/src/internal/plate-editor/editor/plugins/markdown-kit.tsx +18 -0
- package/src/internal/plate-editor/editor/plugins/math-base-kit.tsx +8 -0
- package/src/internal/plate-editor/editor/plugins/math-kit.tsx +10 -0
- package/src/internal/plate-editor/editor/plugins/media-base-kit.tsx +37 -0
- package/src/internal/plate-editor/editor/plugins/media-kit.tsx +53 -0
- package/src/internal/plate-editor/editor/plugins/mention-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/mention-kit.tsx +36 -0
- package/src/internal/plate-editor/editor/plugins/slash-kit.tsx +17 -0
- package/src/internal/plate-editor/editor/plugins/suggestion-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/suggestion-kit.tsx +95 -0
- package/src/internal/plate-editor/editor/plugins/table-base-kit.tsx +20 -0
- package/src/internal/plate-editor/editor/plugins/table-kit.tsx +22 -0
- package/src/internal/plate-editor/editor/plugins/toc-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/toc-kit.tsx +14 -0
- package/src/internal/plate-editor/editor/plugins/toggle-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/toggle-kit.tsx +9 -0
- package/src/internal/plate-editor/editor/transforms.ts +165 -0
- package/src/internal/plate-editor/editor/use-chat.ts +152 -0
- package/src/internal/plate-editor/hooks/index.ts +3 -0
- package/src/internal/plate-editor/hooks/use-copy-to-clipboard.ts +31 -0
- package/src/internal/plate-editor/hooks/use-is-touch-device.ts +26 -0
- package/src/internal/plate-editor/hooks/use-lock-scroll.ts +21 -0
- package/src/internal/plate-editor/hooks/use-media-query.ts +44 -0
- package/src/internal/plate-editor/hooks/use-mounted.ts +18 -0
- package/src/internal/plate-editor/hooks/use-on-click-outside.ts +114 -0
- package/src/internal/plate-editor/hooks/use-upload-file.ts +81 -0
- package/src/internal/plate-editor/i18n/context.tsx +58 -0
- package/src/internal/plate-editor/i18n/index.ts +3 -0
- package/src/internal/plate-editor/i18n/locales/de.json +57 -0
- package/src/internal/plate-editor/i18n/locales/el.json +57 -0
- package/src/internal/plate-editor/i18n/locales/en.json +57 -0
- package/src/internal/plate-editor/i18n/locales/es.json +57 -0
- package/src/internal/plate-editor/i18n/locales/fr.json +57 -0
- package/src/internal/plate-editor/i18n/locales/it.json +57 -0
- package/src/internal/plate-editor/i18n/locales/pt.json +57 -0
- package/src/internal/plate-editor/i18n/locales/sl.json +57 -0
- package/src/internal/plate-editor/i18n/locales/tr.json +57 -0
- package/src/internal/plate-editor/i18n/types.ts +59 -0
- package/src/internal/plate-editor/i18n/use-translation.ts +22 -0
- package/src/internal/plate-editor/index.ts +39 -0
- package/src/internal/plate-editor/lib/ai-output-converter.ts +153 -0
- package/src/internal/plate-editor/lib/download-file.ts +17 -0
- package/src/internal/plate-editor/plate-ui/ai-chat-editor.tsx +26 -0
- package/src/internal/plate-editor/plate-ui/ai-menu.tsx +828 -0
- package/src/internal/plate-editor/plate-ui/ai-node.tsx +41 -0
- package/src/internal/plate-editor/plate-ui/ai-toolbar-button.tsx +27 -0
- package/src/internal/plate-editor/plate-ui/alert-dialog.tsx +147 -0
- package/src/internal/plate-editor/plate-ui/align-toolbar-button.tsx +90 -0
- package/src/internal/plate-editor/plate-ui/avatar.tsx +3 -0
- package/src/internal/plate-editor/plate-ui/block-context-menu.tsx +106 -0
- package/src/internal/plate-editor/plate-ui/block-discussion.tsx +364 -0
- package/src/internal/plate-editor/plate-ui/block-draggable.tsx +556 -0
- package/src/internal/plate-editor/plate-ui/block-list-static.tsx +78 -0
- package/src/internal/plate-editor/plate-ui/block-list.tsx +85 -0
- package/src/internal/plate-editor/plate-ui/block-menu.tsx +557 -0
- package/src/internal/plate-editor/plate-ui/block-selection.tsx +47 -0
- package/src/internal/plate-editor/plate-ui/block-suggestion.tsx +469 -0
- package/src/internal/plate-editor/plate-ui/blockquote-node-static.tsx +10 -0
- package/src/internal/plate-editor/plate-ui/blockquote-node.tsx +11 -0
- package/src/internal/plate-editor/plate-ui/button.tsx +190 -0
- package/src/internal/plate-editor/plate-ui/calendar.tsx +3 -0
- package/src/internal/plate-editor/plate-ui/callout-node-static.tsx +76 -0
- package/src/internal/plate-editor/plate-ui/callout-node.tsx +54 -0
- package/src/internal/plate-editor/plate-ui/caption.tsx +48 -0
- package/src/internal/plate-editor/plate-ui/checkbox.tsx +3 -0
- package/src/internal/plate-editor/plate-ui/code-block-node-static.tsx +172 -0
- package/src/internal/plate-editor/plate-ui/code-block-node.tsx +228 -0
- package/src/internal/plate-editor/plate-ui/code-node-static.tsx +11 -0
- package/src/internal/plate-editor/plate-ui/code-node.tsx +12 -0
- package/src/internal/plate-editor/plate-ui/column-node-static.tsx +65 -0
- package/src/internal/plate-editor/plate-ui/column-node.tsx +24 -0
- package/src/internal/plate-editor/plate-ui/command.tsx +204 -0
- package/src/internal/plate-editor/plate-ui/comment-node-static.tsx +12 -0
- package/src/internal/plate-editor/plate-ui/comment-node.tsx +45 -0
- package/src/internal/plate-editor/plate-ui/comment-toolbar-button.tsx +24 -0
- package/src/internal/plate-editor/plate-ui/comment.tsx +619 -0
- package/src/internal/plate-editor/plate-ui/cursor-overlay.tsx +85 -0
- package/src/internal/plate-editor/plate-ui/date-node-static.tsx +43 -0
- package/src/internal/plate-editor/plate-ui/date-node.tsx +56 -0
- package/src/internal/plate-editor/plate-ui/dialog.tsx +426 -0
- package/src/internal/plate-editor/plate-ui/dropdown-menu.tsx +266 -0
- package/src/internal/plate-editor/plate-ui/editor-static.tsx +40 -0
- package/src/internal/plate-editor/plate-ui/editor.tsx +148 -0
- package/src/internal/plate-editor/plate-ui/emoji-node.tsx +48 -0
- package/src/internal/plate-editor/plate-ui/emoji-toolbar-button.tsx +626 -0
- package/src/internal/plate-editor/plate-ui/equation-node-static.tsx +155 -0
- package/src/internal/plate-editor/plate-ui/equation-node.tsx +226 -0
- package/src/internal/plate-editor/plate-ui/equation-toolbar-button.tsx +26 -0
- package/src/internal/plate-editor/plate-ui/export-toolbar-button.tsx +208 -0
- package/src/internal/plate-editor/plate-ui/fixed-toolbar-buttons.tsx +157 -0
- package/src/internal/plate-editor/plate-ui/fixed-toolbar.tsx +27 -0
- package/src/internal/plate-editor/plate-ui/floating-discussion.tsx +1129 -0
- package/src/internal/plate-editor/plate-ui/floating-toolbar-buttons.tsx +129 -0
- package/src/internal/plate-editor/plate-ui/floating-toolbar.tsx +99 -0
- package/src/internal/plate-editor/plate-ui/font-color-toolbar-button.tsx +211 -0
- package/src/internal/plate-editor/plate-ui/font-size-toolbar-button.tsx +154 -0
- package/src/internal/plate-editor/plate-ui/ghost-text.tsx +20 -0
- package/src/internal/plate-editor/plate-ui/heading-node-static.tsx +52 -0
- package/src/internal/plate-editor/plate-ui/heading-node.tsx +56 -0
- package/src/internal/plate-editor/plate-ui/highlight-node-static.tsx +9 -0
- package/src/internal/plate-editor/plate-ui/highlight-node.tsx +11 -0
- package/src/internal/plate-editor/plate-ui/history-toolbar-button.tsx +52 -0
- package/src/internal/plate-editor/plate-ui/hover-card.tsx +7 -0
- package/src/internal/plate-editor/plate-ui/hr-node-static.tsx +18 -0
- package/src/internal/plate-editor/plate-ui/hr-node.tsx +28 -0
- package/src/internal/plate-editor/plate-ui/import-toolbar-button.tsx +124 -0
- package/src/internal/plate-editor/plate-ui/indent-toolbar-button.tsx +34 -0
- package/src/internal/plate-editor/plate-ui/inline-combobox.tsx +409 -0
- package/src/internal/plate-editor/plate-ui/input.tsx +39 -0
- package/src/internal/plate-editor/plate-ui/insert-toolbar-button.tsx +260 -0
- package/src/internal/plate-editor/plate-ui/label.tsx +1 -0
- package/src/internal/plate-editor/plate-ui/line-height-toolbar-button.tsx +71 -0
- package/src/internal/plate-editor/plate-ui/link-node-static.tsx +15 -0
- package/src/internal/plate-editor/plate-ui/link-node.tsx +33 -0
- package/src/internal/plate-editor/plate-ui/link-toolbar-button.tsx +30 -0
- package/src/internal/plate-editor/plate-ui/link-toolbar.tsx +149 -0
- package/src/internal/plate-editor/plate-ui/list-toolbar-button.tsx +179 -0
- package/src/internal/plate-editor/plate-ui/mark-toolbar-button.tsx +36 -0
- package/src/internal/plate-editor/plate-ui/media-audio-node-static.tsx +21 -0
- package/src/internal/plate-editor/plate-ui/media-audio-node.tsx +32 -0
- package/src/internal/plate-editor/plate-ui/media-embed-node.tsx +103 -0
- package/src/internal/plate-editor/plate-ui/media-file-node-static.tsx +30 -0
- package/src/internal/plate-editor/plate-ui/media-file-node.tsx +52 -0
- package/src/internal/plate-editor/plate-ui/media-image-node-static.tsx +37 -0
- package/src/internal/plate-editor/plate-ui/media-image-node.tsx +183 -0
- package/src/internal/plate-editor/plate-ui/media-placeholder-node.tsx +441 -0
- package/src/internal/plate-editor/plate-ui/media-preview-dialog.tsx +127 -0
- package/src/internal/plate-editor/plate-ui/media-toolbar-button.tsx +229 -0
- package/src/internal/plate-editor/plate-ui/media-toolbar.tsx +216 -0
- package/src/internal/plate-editor/plate-ui/media-upload-toast.tsx +73 -0
- package/src/internal/plate-editor/plate-ui/media-video-node-static.tsx +35 -0
- package/src/internal/plate-editor/plate-ui/media-video-node.tsx +119 -0
- package/src/internal/plate-editor/plate-ui/mention-node-static.tsx +46 -0
- package/src/internal/plate-editor/plate-ui/mention-node.tsx +79 -0
- package/src/internal/plate-editor/plate-ui/menu.tsx +532 -0
- package/src/internal/plate-editor/plate-ui/mode-toolbar-button.tsx +126 -0
- package/src/internal/plate-editor/plate-ui/more-toolbar-button.tsx +34 -0
- package/src/internal/plate-editor/plate-ui/paragraph-node-static.tsx +15 -0
- package/src/internal/plate-editor/plate-ui/paragraph-node.tsx +16 -0
- package/src/internal/plate-editor/plate-ui/popover.tsx +77 -0
- package/src/internal/plate-editor/plate-ui/progress.tsx +1 -0
- package/src/internal/plate-editor/plate-ui/remote-cursor-overlay.tsx +81 -0
- package/src/internal/plate-editor/plate-ui/resize-handle.tsx +88 -0
- package/src/internal/plate-editor/plate-ui/separator.tsx +43 -0
- package/src/internal/plate-editor/plate-ui/slash-node.tsx +435 -0
- package/src/internal/plate-editor/plate-ui/spinner.tsx +1 -0
- package/src/internal/plate-editor/plate-ui/suggestion-node-static.tsx +35 -0
- package/src/internal/plate-editor/plate-ui/suggestion-node.tsx +168 -0
- package/src/internal/plate-editor/plate-ui/suggestion-toolbar-button.tsx +24 -0
- package/src/internal/plate-editor/plate-ui/table-node-static.tsx +85 -0
- package/src/internal/plate-editor/plate-ui/table-node.tsx +285 -0
- package/src/internal/plate-editor/plate-ui/table-toolbar-button.tsx +254 -0
- package/src/internal/plate-editor/plate-ui/tabs.tsx +3 -0
- package/src/internal/plate-editor/plate-ui/textarea.tsx +58 -0
- package/src/internal/plate-editor/plate-ui/toc-node-static.tsx +142 -0
- package/src/internal/plate-editor/plate-ui/toc-node.tsx +57 -0
- package/src/internal/plate-editor/plate-ui/toc-sidebar.tsx +50 -0
- package/src/internal/plate-editor/plate-ui/toggle-node-static.tsx +18 -0
- package/src/internal/plate-editor/plate-ui/toggle-node.tsx +33 -0
- package/src/internal/plate-editor/plate-ui/toggle-toolbar-button.tsx +26 -0
- package/src/internal/plate-editor/plate-ui/toggle.tsx +3 -0
- package/src/internal/plate-editor/plate-ui/toolbar.tsx +380 -0
- package/src/internal/plate-editor/plate-ui/tooltip.tsx +149 -0
- package/src/internal/plate-editor/plate-ui/turn-into-toolbar-button.tsx +177 -0
- package/src/internal/plate-editor/types/index.ts +22 -0
- package/src/internal/plate-editor/vite.ts +284 -0
- package/src/internal/sheets/components/univer-sheets.tsx +1104 -0
- package/src/internal/sheets/i18n/context.tsx +183 -0
- package/src/internal/sheets/i18n/index.ts +19 -0
- package/src/internal/sheets/i18n/locales/de.json +21 -0
- package/src/internal/sheets/i18n/locales/el.json +21 -0
- package/src/internal/sheets/i18n/locales/en.json +21 -0
- package/src/internal/sheets/i18n/locales/es.json +21 -0
- package/src/internal/sheets/i18n/locales/fr.json +21 -0
- package/src/internal/sheets/i18n/locales/it.json +21 -0
- package/src/internal/sheets/i18n/locales/pt.json +21 -0
- package/src/internal/sheets/i18n/locales/sl.json +21 -0
- package/src/internal/sheets/i18n/locales/tr.json +21 -0
- package/src/internal/sheets/i18n/types.ts +23 -0
- package/src/internal/sheets/i18n/use-translation.ts +17 -0
- package/src/internal/sheets/index.ts +14 -0
- package/src/internal/sheets/types/css.d.ts +11 -0
- package/src/internal/sheets/types/index.ts +260 -0
- package/src/internal/sheets/xlsx.ts +1169 -0
- package/src/lib/api-client.ts +77 -0
- package/src/lib/assistant-api-actions.ts +549 -0
- package/src/lib/assistant-config.tsx +71 -0
- package/src/lib/class-utils.ts +40 -0
- package/src/lib/index.ts +7 -0
- package/src/lib/message-utils.ts +131 -0
- package/src/tools/tools-schema.json +512 -0
- package/src/types/index.ts +235 -0
- package/src/views/assistant-view.tsx +1137 -0
- package/src/views/canvas-app.tsx +839 -0
- package/src/views/canvas-code.tsx +93 -0
- package/src/views/canvas-deep-research.tsx +44 -0
- package/src/views/canvas-image.tsx +25 -0
- package/src/views/canvas-record-view.tsx +285 -0
- package/src/views/canvas-spreadsheet.tsx +125 -0
- package/src/views/canvas-text.tsx +52 -0
- package/src/views/canvas.tsx +274 -0
- package/src/views/chat-panel.tsx +149 -0
- package/src/views/index.ts +20 -0
- package/src/views/memories-panel.tsx +365 -0
- package/src/views/message-list.tsx +370 -0
- package/src/views/project-detail.tsx +257 -0
- package/src/views/projects-panel.tsx +131 -0
- package/src/views/sessions-list.tsx +98 -0
- package/src/views/sidebar-content.tsx +256 -0
- package/src/views/work-detail.tsx +98 -0
- package/src/vite.ts +284 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
|
|
2
|
+
import { type TEquationElement } from 'platejs';
|
|
3
|
+
|
|
4
|
+
import { getEquationHtml } from '@platejs/math';
|
|
5
|
+
|
|
6
|
+
import { SlateElement, type SlateElementProps } from 'platejs/static';
|
|
7
|
+
|
|
8
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
9
|
+
|
|
10
|
+
export function EquationElementStatic(
|
|
11
|
+
props: SlateElementProps<TEquationElement>
|
|
12
|
+
) {
|
|
13
|
+
const { element } = props;
|
|
14
|
+
|
|
15
|
+
const html = getEquationHtml({
|
|
16
|
+
element,
|
|
17
|
+
options: {
|
|
18
|
+
displayMode: true,
|
|
19
|
+
errorColor: '#cc0000',
|
|
20
|
+
fleqn: false,
|
|
21
|
+
leqno: false,
|
|
22
|
+
macros: { '\\f': '#1f(#2)' },
|
|
23
|
+
output: 'htmlAndMathml',
|
|
24
|
+
strict: 'warn',
|
|
25
|
+
throwOnError: false,
|
|
26
|
+
trust: false
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<SlateElement className="my-1" {...props}>
|
|
32
|
+
<div
|
|
33
|
+
className={cn(
|
|
34
|
+
'flex select-none items-center justify-center rounded-sm',
|
|
35
|
+
element.texExpression.length === 0 ? 'bg-muted p-3' : 'px-2 py-1'
|
|
36
|
+
)}>
|
|
37
|
+
<span
|
|
38
|
+
dangerouslySetInnerHTML={{
|
|
39
|
+
__html: html
|
|
40
|
+
}} />
|
|
41
|
+
</div>
|
|
42
|
+
{props.children}
|
|
43
|
+
</SlateElement>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function InlineEquationElementStatic(
|
|
48
|
+
props: SlateElementProps<TEquationElement>
|
|
49
|
+
) {
|
|
50
|
+
const { element } = props;
|
|
51
|
+
|
|
52
|
+
const html = getEquationHtml({
|
|
53
|
+
element,
|
|
54
|
+
options: {
|
|
55
|
+
displayMode: true,
|
|
56
|
+
errorColor: '#cc0000',
|
|
57
|
+
fleqn: false,
|
|
58
|
+
leqno: false,
|
|
59
|
+
macros: { '\\f': '#1f(#2)' },
|
|
60
|
+
output: 'htmlAndMathml',
|
|
61
|
+
strict: 'warn',
|
|
62
|
+
throwOnError: false,
|
|
63
|
+
trust: false
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<SlateElement
|
|
69
|
+
className="inline-block select-none rounded-sm [&_.katex-display]:my-0"
|
|
70
|
+
{...props}>
|
|
71
|
+
<div
|
|
72
|
+
className={cn(
|
|
73
|
+
'after:-top-0.5 after:-left-1 after:absolute after:inset-0 after:z-1 after:h-[calc(100%)+4px] after:w-[calc(100%+8px)] after:rounded-sm after:content-[""]',
|
|
74
|
+
'h-6',
|
|
75
|
+
element.texExpression.length === 0
|
|
76
|
+
&& 'text-muted-foreground after:bg-neutral-500/10'
|
|
77
|
+
)}>
|
|
78
|
+
<span
|
|
79
|
+
className={cn(
|
|
80
|
+
element.texExpression.length === 0 && 'hidden',
|
|
81
|
+
'font-mono leading-none'
|
|
82
|
+
)}
|
|
83
|
+
dangerouslySetInnerHTML={{
|
|
84
|
+
__html: html
|
|
85
|
+
}} />
|
|
86
|
+
</div>
|
|
87
|
+
{props.children}
|
|
88
|
+
</SlateElement>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* DOCX-compatible block equation component.
|
|
94
|
+
* Displays LaTeX source code with styling.
|
|
95
|
+
*/
|
|
96
|
+
export function EquationElementDocx(
|
|
97
|
+
props: SlateElementProps<TEquationElement>
|
|
98
|
+
) {
|
|
99
|
+
const { element } = props;
|
|
100
|
+
|
|
101
|
+
if (!element.texExpression || element.texExpression.length === 0) {
|
|
102
|
+
return (
|
|
103
|
+
<SlateElement {...props}>
|
|
104
|
+
<p style={{ color: '#888', fontStyle: 'italic' }}>[Empty equation]</p>
|
|
105
|
+
{props.children}
|
|
106
|
+
</SlateElement>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<SlateElement {...props}>
|
|
112
|
+
<p
|
|
113
|
+
style={{
|
|
114
|
+
fontFamily: 'Cambria Math, Consolas, monospace',
|
|
115
|
+
fontSize: '12pt',
|
|
116
|
+
margin: '8pt 0',
|
|
117
|
+
textAlign: 'center'
|
|
118
|
+
}}>
|
|
119
|
+
{element.texExpression}
|
|
120
|
+
</p>
|
|
121
|
+
{props.children}
|
|
122
|
+
</SlateElement>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* DOCX-compatible inline equation component.
|
|
128
|
+
* Displays LaTeX source code inline.
|
|
129
|
+
*/
|
|
130
|
+
export function InlineEquationElementDocx(
|
|
131
|
+
props: SlateElementProps<TEquationElement>
|
|
132
|
+
) {
|
|
133
|
+
const { element } = props;
|
|
134
|
+
|
|
135
|
+
if (!element.texExpression || element.texExpression.length === 0) {
|
|
136
|
+
return (
|
|
137
|
+
<SlateElement {...props} as="span">
|
|
138
|
+
<span style={{ color: '#888', fontStyle: 'italic' }}>[equation]</span>
|
|
139
|
+
{props.children}
|
|
140
|
+
</SlateElement>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<SlateElement {...props} as="span">
|
|
146
|
+
<span
|
|
147
|
+
style={{
|
|
148
|
+
fontFamily: 'Cambria Math, Consolas, monospace'
|
|
149
|
+
}}>
|
|
150
|
+
{element.texExpression}
|
|
151
|
+
</span>
|
|
152
|
+
{props.children}
|
|
153
|
+
</SlateElement>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
import { type TEquationElement } from 'platejs';
|
|
6
|
+
|
|
7
|
+
import { useEquationElement, useEquationInput } from '@platejs/math/react';
|
|
8
|
+
import { BlockSelectionPlugin } from '@platejs/selection/react';
|
|
9
|
+
import { CornerDownLeftIcon, RadicalIcon } from 'lucide-react';
|
|
10
|
+
import {
|
|
11
|
+
createPrimitiveComponent,
|
|
12
|
+
PlateElement,
|
|
13
|
+
type PlateElementProps,
|
|
14
|
+
useEditorRef,
|
|
15
|
+
useEditorSelector,
|
|
16
|
+
useElement,
|
|
17
|
+
useReadOnly,
|
|
18
|
+
useSelected
|
|
19
|
+
} from 'platejs/react';
|
|
20
|
+
|
|
21
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
22
|
+
|
|
23
|
+
import { BlockActionButton } from './block-context-menu';
|
|
24
|
+
import { Button } from './button';
|
|
25
|
+
import { Popover, PopoverContent, PopoverTrigger } from './popover';
|
|
26
|
+
import { TextareaAutosize, type TextareaAutosizeProps } from './textarea';
|
|
27
|
+
|
|
28
|
+
export function EquationElement(props: PlateElementProps) {
|
|
29
|
+
const element = useElement<TEquationElement>();
|
|
30
|
+
const selected = useSelected();
|
|
31
|
+
const [open, setOpen] = useState(selected);
|
|
32
|
+
const katexRef = useRef<HTMLDivElement | null>(null);
|
|
33
|
+
|
|
34
|
+
useEquationElement({
|
|
35
|
+
element,
|
|
36
|
+
katexRef,
|
|
37
|
+
options: {
|
|
38
|
+
displayMode: true,
|
|
39
|
+
errorColor: '#cc0000',
|
|
40
|
+
fleqn: false,
|
|
41
|
+
leqno: false,
|
|
42
|
+
macros: { '\\f': '#1f(#2)' },
|
|
43
|
+
output: 'htmlAndMathml',
|
|
44
|
+
strict: 'warn',
|
|
45
|
+
throwOnError: false,
|
|
46
|
+
trust: false
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<PlateElement className="my-1" {...props}>
|
|
52
|
+
<Popover modal={false} onOpenChange={setOpen} open={open}>
|
|
53
|
+
<PopoverTrigger asChild>
|
|
54
|
+
<div
|
|
55
|
+
className={cn(
|
|
56
|
+
'group flex cursor-pointer select-none items-center justify-center rounded-sm hover:bg-primary/10 data-[selected=true]:bg-primary/10',
|
|
57
|
+
element.texExpression.length === 0 ? 'bg-muted p-3 pr-9' : 'px-2 py-1'
|
|
58
|
+
)}
|
|
59
|
+
contentEditable={false}
|
|
60
|
+
data-selected={selected}
|
|
61
|
+
role="button">
|
|
62
|
+
{element.texExpression.length > 0 ? (
|
|
63
|
+
<span ref={katexRef} />
|
|
64
|
+
) : (
|
|
65
|
+
<div className="flex h-7 w-full items-center gap-2 whitespace-nowrap text-muted-foreground text-sm">
|
|
66
|
+
<RadicalIcon className="size-6 text-muted-foreground/80" />
|
|
67
|
+
<div>Add a Tex equation</div>
|
|
68
|
+
</div>
|
|
69
|
+
)}
|
|
70
|
+
</div>
|
|
71
|
+
</PopoverTrigger>
|
|
72
|
+
|
|
73
|
+
<EquationPopoverContent
|
|
74
|
+
isInline={false}
|
|
75
|
+
open={open}
|
|
76
|
+
placeholder={'f(x) = \\begin{cases}\n x^2, &\\quad x > 0 \\\\\n 0, &\\quad x = 0 \\\\\n -x^2, &\\quad x < 0\n\\end{cases}'}
|
|
77
|
+
setOpen={setOpen}
|
|
78
|
+
variant="equation" />
|
|
79
|
+
</Popover>
|
|
80
|
+
|
|
81
|
+
<BlockActionButton />
|
|
82
|
+
|
|
83
|
+
{props.children}
|
|
84
|
+
</PlateElement>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function InlineEquationElement(
|
|
89
|
+
props: PlateElementProps<TEquationElement>
|
|
90
|
+
) {
|
|
91
|
+
const { element } = props;
|
|
92
|
+
const katexRef = useRef<HTMLDivElement | null>(null);
|
|
93
|
+
const selected = useSelected();
|
|
94
|
+
const isCollapsed = useEditorSelector(
|
|
95
|
+
editor => editor?.api?.isCollapsed() ?? false,
|
|
96
|
+
[]
|
|
97
|
+
);
|
|
98
|
+
const [open, setOpen] = useState(selected && isCollapsed);
|
|
99
|
+
|
|
100
|
+
// Sync popover open state from editor selection
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if (selected && isCollapsed) {
|
|
103
|
+
setOpen(true);
|
|
104
|
+
}
|
|
105
|
+
}, [selected, isCollapsed]);
|
|
106
|
+
|
|
107
|
+
useEquationElement({
|
|
108
|
+
element,
|
|
109
|
+
katexRef,
|
|
110
|
+
options: {
|
|
111
|
+
displayMode: true,
|
|
112
|
+
errorColor: '#cc0000',
|
|
113
|
+
fleqn: false,
|
|
114
|
+
leqno: false,
|
|
115
|
+
macros: { '\\f': '#1f(#2)' },
|
|
116
|
+
output: 'htmlAndMathml',
|
|
117
|
+
strict: 'warn',
|
|
118
|
+
throwOnError: false,
|
|
119
|
+
trust: false
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<PlateElement
|
|
125
|
+
className="mx-1 inline-block select-none rounded-sm [&_.katex-display]:my-0!"
|
|
126
|
+
{...props}>
|
|
127
|
+
<Popover modal={false} onOpenChange={setOpen} open={open}>
|
|
128
|
+
<PopoverTrigger asChild>
|
|
129
|
+
<div
|
|
130
|
+
className={cn(
|
|
131
|
+
'after:-top-0.5 after:-left-1 after:absolute after:inset-0 after:z-1 after:h-[calc(100%)+4px] after:w-[calc(100%+8px)] after:rounded-sm after:content-[""]',
|
|
132
|
+
'h-6',
|
|
133
|
+
((element.texExpression.length > 0 && open) || selected)
|
|
134
|
+
&& 'after:bg-brand/15',
|
|
135
|
+
element.texExpression.length === 0
|
|
136
|
+
&& 'text-muted-foreground after:bg-neutral-500/10'
|
|
137
|
+
)}
|
|
138
|
+
contentEditable={false}>
|
|
139
|
+
<span
|
|
140
|
+
className={cn(
|
|
141
|
+
element.texExpression.length === 0 && 'hidden',
|
|
142
|
+
'font-mono leading-none'
|
|
143
|
+
)}
|
|
144
|
+
ref={katexRef} />
|
|
145
|
+
{element.texExpression.length === 0 && (
|
|
146
|
+
<span>
|
|
147
|
+
<RadicalIcon className="mr-1 inline-block h-[19px] w-4 py-[1.5px] align-text-bottom" />
|
|
148
|
+
New equation
|
|
149
|
+
</span>
|
|
150
|
+
)}
|
|
151
|
+
</div>
|
|
152
|
+
</PopoverTrigger>
|
|
153
|
+
|
|
154
|
+
<EquationPopoverContent
|
|
155
|
+
className="my-auto"
|
|
156
|
+
isInline={true}
|
|
157
|
+
open={open}
|
|
158
|
+
placeholder="E = mc^2"
|
|
159
|
+
setOpen={setOpen}
|
|
160
|
+
variant="equationInline" />
|
|
161
|
+
</Popover>
|
|
162
|
+
|
|
163
|
+
{props.children}
|
|
164
|
+
</PlateElement>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const EquationInput = createPrimitiveComponent(TextareaAutosize)({
|
|
169
|
+
propsHook: useEquationInput
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
function EquationPopoverContent({
|
|
173
|
+
className,
|
|
174
|
+
isInline,
|
|
175
|
+
open,
|
|
176
|
+
setOpen,
|
|
177
|
+
...props
|
|
178
|
+
}: {
|
|
179
|
+
isInline: boolean;
|
|
180
|
+
open: boolean;
|
|
181
|
+
setOpen: (open: boolean) => void;
|
|
182
|
+
} & TextareaAutosizeProps) {
|
|
183
|
+
const editor = useEditorRef();
|
|
184
|
+
const readOnly = useReadOnly();
|
|
185
|
+
const element = useElement<TEquationElement>();
|
|
186
|
+
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
if (isInline && open) {
|
|
189
|
+
setOpen(true);
|
|
190
|
+
}
|
|
191
|
+
}, [isInline, open, setOpen]);
|
|
192
|
+
|
|
193
|
+
if (readOnly) return null;
|
|
194
|
+
|
|
195
|
+
const onClose = () => {
|
|
196
|
+
setOpen(false);
|
|
197
|
+
|
|
198
|
+
if (isInline) {
|
|
199
|
+
editor.tf.select(element, { focus: true, next: true });
|
|
200
|
+
} else {
|
|
201
|
+
editor
|
|
202
|
+
.getApi(BlockSelectionPlugin)
|
|
203
|
+
.blockSelection.set(element.id as string);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<PopoverContent
|
|
209
|
+
className="flex gap-2"
|
|
210
|
+
contentEditable={false}
|
|
211
|
+
onEscapeKeyDown={(e) => {
|
|
212
|
+
e.preventDefault();
|
|
213
|
+
}}
|
|
214
|
+
variant="equation">
|
|
215
|
+
<EquationInput
|
|
216
|
+
autoFocus
|
|
217
|
+
className={cn('grow', className)}
|
|
218
|
+
state={{ isInline, open: true, onClose }}
|
|
219
|
+
{...props} />
|
|
220
|
+
|
|
221
|
+
<Button className="px-3" onClick={onClose} variant="brand">
|
|
222
|
+
Done <CornerDownLeftIcon className="size-3.5" />
|
|
223
|
+
</Button>
|
|
224
|
+
</PopoverContent>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type ComponentProps } from 'react';
|
|
4
|
+
|
|
5
|
+
import { insertInlineEquation } from '@platejs/math';
|
|
6
|
+
import { RadicalIcon } from 'lucide-react';
|
|
7
|
+
import { useEditorRef } from 'platejs/react';
|
|
8
|
+
|
|
9
|
+
import { ToolbarButton } from './toolbar';
|
|
10
|
+
|
|
11
|
+
export function InlineEquationToolbarButton(
|
|
12
|
+
props: ComponentProps<typeof ToolbarButton>
|
|
13
|
+
) {
|
|
14
|
+
const editor = useEditorRef();
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<ToolbarButton
|
|
18
|
+
tooltip="Mark as equation"
|
|
19
|
+
{...props}
|
|
20
|
+
onClick={() => {
|
|
21
|
+
insertInlineEquation(editor);
|
|
22
|
+
}}>
|
|
23
|
+
<RadicalIcon />
|
|
24
|
+
</ToolbarButton>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
|
|
7
|
+
import { type SlatePlugin, createSlateEditor } from 'platejs';
|
|
8
|
+
|
|
9
|
+
import { exportToDocx } from '@platejs/docx-io';
|
|
10
|
+
import { MarkdownPlugin } from '@platejs/markdown';
|
|
11
|
+
import { ArrowDownToLineIcon } from 'lucide-react';
|
|
12
|
+
import { useEditorRef } from 'platejs/react';
|
|
13
|
+
import { PlateStatic, serializeHtml } from 'platejs/static';
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
DropdownMenu,
|
|
17
|
+
DropdownMenuContent,
|
|
18
|
+
DropdownMenuGroup,
|
|
19
|
+
DropdownMenuItem,
|
|
20
|
+
DropdownMenuPortal,
|
|
21
|
+
DropdownMenuTrigger,
|
|
22
|
+
type DropdownMenuProps
|
|
23
|
+
} from './dropdown-menu';
|
|
24
|
+
import { BaseEditorKit } from '../editor/editor-base-kit';
|
|
25
|
+
import { ToolbarButton } from './toolbar';
|
|
26
|
+
import { DocxExportKit } from '../editor/plugins/docx-export-kit';
|
|
27
|
+
|
|
28
|
+
const siteUrl = 'https://platejs.org';
|
|
29
|
+
|
|
30
|
+
export function ExportToolbarButton(props: DropdownMenuProps) {
|
|
31
|
+
const editor = useEditorRef();
|
|
32
|
+
const [open, setOpen] = useState(false);
|
|
33
|
+
|
|
34
|
+
const getCanvas = async () => {
|
|
35
|
+
const { default: html2canvas } = await import('html2canvas-pro');
|
|
36
|
+
|
|
37
|
+
const style = document.createElement('style');
|
|
38
|
+
|
|
39
|
+
document.head.append(style);
|
|
40
|
+
|
|
41
|
+
const canvas = await html2canvas(editor.api.toDOMNode(editor)!, {
|
|
42
|
+
onclone: (document: Document) => {
|
|
43
|
+
const editorElement = document.querySelector(
|
|
44
|
+
'[contenteditable="true"]'
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
if (editorElement) {
|
|
48
|
+
Array.from(editorElement.querySelectorAll('*')).forEach((element) => {
|
|
49
|
+
const existingStyle = element.getAttribute('style') || '';
|
|
50
|
+
|
|
51
|
+
element.setAttribute(
|
|
52
|
+
'style',
|
|
53
|
+
`${existingStyle}; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important`
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
style.remove();
|
|
61
|
+
|
|
62
|
+
return canvas;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const downloadFile = async (url: string, filename: string) => {
|
|
66
|
+
const response = await fetch(url);
|
|
67
|
+
|
|
68
|
+
const blob = await response.blob();
|
|
69
|
+
const blobUrl = window.URL.createObjectURL(blob);
|
|
70
|
+
|
|
71
|
+
const link = document.createElement('a');
|
|
72
|
+
|
|
73
|
+
link.href = blobUrl;
|
|
74
|
+
link.download = filename;
|
|
75
|
+
document.body.append(link);
|
|
76
|
+
link.click();
|
|
77
|
+
link.remove();
|
|
78
|
+
|
|
79
|
+
// Clean up the blob URL
|
|
80
|
+
window.URL.revokeObjectURL(blobUrl);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const exportToPdf = async () => {
|
|
84
|
+
const canvas = await getCanvas();
|
|
85
|
+
|
|
86
|
+
const PDFLib = await import('pdf-lib');
|
|
87
|
+
const pdfDoc = await PDFLib.PDFDocument.create();
|
|
88
|
+
const page = pdfDoc.addPage([canvas.width, canvas.height]);
|
|
89
|
+
const imageEmbed = await pdfDoc.embedPng(canvas.toDataURL('PNG'));
|
|
90
|
+
const { height, width } = imageEmbed.scale(1);
|
|
91
|
+
|
|
92
|
+
page.drawImage(imageEmbed, {
|
|
93
|
+
height,
|
|
94
|
+
width,
|
|
95
|
+
x: 0,
|
|
96
|
+
y: 0
|
|
97
|
+
});
|
|
98
|
+
const pdfBase64 = await pdfDoc.saveAsBase64({ dataUri: true });
|
|
99
|
+
|
|
100
|
+
await downloadFile(pdfBase64, 'plate.pdf');
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const exportToImage = async () => {
|
|
104
|
+
const canvas = await getCanvas();
|
|
105
|
+
|
|
106
|
+
await downloadFile(canvas.toDataURL('image/png'), 'plate.png');
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const exportToHtml = async () => {
|
|
110
|
+
const editorStatic = createSlateEditor({
|
|
111
|
+
plugins: BaseEditorKit,
|
|
112
|
+
value: editor.children
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const editorHtml = await serializeHtml(editorStatic, {
|
|
116
|
+
editorComponent: PlateStatic,
|
|
117
|
+
props: { style: { padding: '0 calc(50% - 350px)', paddingBottom: '' } }
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const tailwindCss = `<link rel="stylesheet" href="${siteUrl}/tailwind.css">`;
|
|
121
|
+
const katexCss = `<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.18/dist/katex.css" integrity="sha384-9PvLvaiSKCPkFKB1ZsEoTjgnJn+O3KvEwtsz37/XrkYft3DTk2gHdYvd9oWgW3tV" crossorigin="anonymous">`;
|
|
122
|
+
|
|
123
|
+
const html = `<!DOCTYPE html>
|
|
124
|
+
<html lang="en">
|
|
125
|
+
<head>
|
|
126
|
+
<meta charset="utf-8" />
|
|
127
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
128
|
+
<meta name="color-scheme" content="light dark" />
|
|
129
|
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
130
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
131
|
+
<link
|
|
132
|
+
href="https://fonts.googleapis.com/css2?family=Inter:wght@400..700&family=JetBrains+Mono:wght@400..700&display=swap"
|
|
133
|
+
rel="stylesheet"
|
|
134
|
+
/>
|
|
135
|
+
${tailwindCss}
|
|
136
|
+
${katexCss}
|
|
137
|
+
<style>
|
|
138
|
+
:root {
|
|
139
|
+
--font-sans: 'Inter', 'Inter Fallback';
|
|
140
|
+
--font-mono: 'JetBrains Mono', 'JetBrains Mono Fallback';
|
|
141
|
+
}
|
|
142
|
+
</style>
|
|
143
|
+
</head>
|
|
144
|
+
<body>
|
|
145
|
+
${editorHtml}
|
|
146
|
+
</body>
|
|
147
|
+
</html>`;
|
|
148
|
+
|
|
149
|
+
const url = `data:text/html;charset=utf-8,${encodeURIComponent(html)}`;
|
|
150
|
+
|
|
151
|
+
await downloadFile(url, 'plate.html');
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const exportToMarkdown = async () => {
|
|
155
|
+
const md = editor.getApi(MarkdownPlugin).markdown.serialize();
|
|
156
|
+
const url = `data:text/markdown;charset=utf-8,${encodeURIComponent(md)}`;
|
|
157
|
+
|
|
158
|
+
await downloadFile(url, 'plate.md');
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const exportToWord = async () => {
|
|
162
|
+
const blob = await exportToDocx(editor.children, {
|
|
163
|
+
editorPlugins: [...BaseEditorKit, ...DocxExportKit] as SlatePlugin[]
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const url = URL.createObjectURL(blob);
|
|
167
|
+
const link = document.createElement('a');
|
|
168
|
+
|
|
169
|
+
link.href = url;
|
|
170
|
+
link.download = 'plate.docx';
|
|
171
|
+
document.body.append(link);
|
|
172
|
+
link.click();
|
|
173
|
+
link.remove();
|
|
174
|
+
URL.revokeObjectURL(url);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<DropdownMenu open={open} onOpenChange={setOpen} modal={false} {...props}>
|
|
179
|
+
<DropdownMenuTrigger asChild>
|
|
180
|
+
<ToolbarButton pressed={open} tooltip="Export" isDropdown>
|
|
181
|
+
<ArrowDownToLineIcon className="size-4" />
|
|
182
|
+
</ToolbarButton>
|
|
183
|
+
</DropdownMenuTrigger>
|
|
184
|
+
|
|
185
|
+
<DropdownMenuPortal>
|
|
186
|
+
<DropdownMenuContent align="start">
|
|
187
|
+
<DropdownMenuGroup>
|
|
188
|
+
<DropdownMenuItem onSelect={exportToHtml}>
|
|
189
|
+
Export as HTML
|
|
190
|
+
</DropdownMenuItem>
|
|
191
|
+
<DropdownMenuItem onSelect={exportToPdf}>
|
|
192
|
+
Export as PDF
|
|
193
|
+
</DropdownMenuItem>
|
|
194
|
+
<DropdownMenuItem onSelect={exportToImage}>
|
|
195
|
+
Export as Image
|
|
196
|
+
</DropdownMenuItem>
|
|
197
|
+
<DropdownMenuItem onSelect={exportToMarkdown}>
|
|
198
|
+
Export as Markdown
|
|
199
|
+
</DropdownMenuItem>
|
|
200
|
+
<DropdownMenuItem onSelect={exportToWord}>
|
|
201
|
+
Export as Word
|
|
202
|
+
</DropdownMenuItem>
|
|
203
|
+
</DropdownMenuGroup>
|
|
204
|
+
</DropdownMenuContent>
|
|
205
|
+
</DropdownMenuPortal>
|
|
206
|
+
</DropdownMenu>
|
|
207
|
+
);
|
|
208
|
+
}
|