@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,85 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
import { type TTableCellElement, type TTableElement } from 'platejs';
|
|
5
|
+
|
|
6
|
+
import { BaseTablePlugin } from '@platejs/table';
|
|
7
|
+
|
|
8
|
+
import { SlateElement, type SlateElementProps } from 'platejs/static';
|
|
9
|
+
|
|
10
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
11
|
+
|
|
12
|
+
export function TableElementStatic(props: SlateElementProps<TTableElement>) {
|
|
13
|
+
const { disableMarginLeft } = props.editor.getOptions(BaseTablePlugin);
|
|
14
|
+
const marginLeft = disableMarginLeft ? 0 : props.element.marginLeft;
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<SlateElement
|
|
18
|
+
{...props}
|
|
19
|
+
className="overflow-x-auto py-5"
|
|
20
|
+
style={{ paddingLeft: marginLeft }}>
|
|
21
|
+
<div className="group/table relative w-fit">
|
|
22
|
+
<table className="mr-0 ml-px table h-px table-fixed border-collapse">
|
|
23
|
+
<tbody className="min-w-full">{props.children}</tbody>
|
|
24
|
+
</table>
|
|
25
|
+
</div>
|
|
26
|
+
</SlateElement>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function TableRowElementStatic(props: SlateElementProps) {
|
|
31
|
+
return <SlateElement {...props} as="tr" className="h-full" />;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function TableCellElementStatic({
|
|
35
|
+
isHeader,
|
|
36
|
+
...props
|
|
37
|
+
}: SlateElementProps<TTableCellElement> & {
|
|
38
|
+
isHeader?: boolean;
|
|
39
|
+
}) {
|
|
40
|
+
const { editor, element } = props;
|
|
41
|
+
const { api } = editor.getPlugin(BaseTablePlugin);
|
|
42
|
+
|
|
43
|
+
const { minHeight, width } = api.table.getCellSize({ element });
|
|
44
|
+
const borders = api.table.getCellBorders({ element });
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<SlateElement
|
|
48
|
+
{...props}
|
|
49
|
+
as={isHeader ? 'th' : 'td'}
|
|
50
|
+
attributes={{
|
|
51
|
+
...props.attributes,
|
|
52
|
+
colSpan: api.table.getColSpan(element),
|
|
53
|
+
rowSpan: api.table.getRowSpan(element)
|
|
54
|
+
}}
|
|
55
|
+
className={cn(
|
|
56
|
+
'h-full overflow-visible border-none bg-background p-0',
|
|
57
|
+
element.background ? 'bg-(--cellBackground)' : 'bg-background',
|
|
58
|
+
isHeader && 'text-left font-normal *:m-0',
|
|
59
|
+
'before:size-full',
|
|
60
|
+
"before:absolute before:box-border before:select-none before:content-['']",
|
|
61
|
+
'before:border before:border-border',
|
|
62
|
+
borders.bottom?.size && 'before:border-b before:border-b-border',
|
|
63
|
+
borders.right?.size && 'before:border-r before:border-r-border',
|
|
64
|
+
borders.left?.size && 'before:border-l before:border-l-border',
|
|
65
|
+
borders.top?.size && 'before:border-t before:border-t-border'
|
|
66
|
+
)}
|
|
67
|
+
style={
|
|
68
|
+
{
|
|
69
|
+
'--cellBackground': element.background,
|
|
70
|
+
maxWidth: width || 240,
|
|
71
|
+
minWidth: width || 120
|
|
72
|
+
} as CSSProperties
|
|
73
|
+
}>
|
|
74
|
+
<div
|
|
75
|
+
className="relative z-20 box-border h-full px-4 py-2"
|
|
76
|
+
style={{ minHeight }}>
|
|
77
|
+
{props.children}
|
|
78
|
+
</div>
|
|
79
|
+
</SlateElement>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function TableCellHeaderElementStatic(props: SlateElementProps) {
|
|
84
|
+
return <TableCellElementStatic {...props} isHeader />;
|
|
85
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type CSSProperties, type ComponentProps } from 'react';
|
|
4
|
+
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
|
|
7
|
+
import { ResizeHandle } from '@platejs/resizable';
|
|
8
|
+
import { useBlockSelected } from '@platejs/selection/react';
|
|
9
|
+
import {
|
|
10
|
+
TablePlugin,
|
|
11
|
+
TableProvider,
|
|
12
|
+
useTableCellElement,
|
|
13
|
+
useTableCellElementResizable,
|
|
14
|
+
useTableElement
|
|
15
|
+
} from '@platejs/table/react';
|
|
16
|
+
import { cva } from 'class-variance-authority';
|
|
17
|
+
import { PlusIcon } from 'lucide-react';
|
|
18
|
+
import { KEYS, type TTableCellElement } from 'platejs';
|
|
19
|
+
import {
|
|
20
|
+
PlateElement,
|
|
21
|
+
type PlateElementProps,
|
|
22
|
+
useEditorPlugin,
|
|
23
|
+
useElementSelector,
|
|
24
|
+
useReadOnly,
|
|
25
|
+
useSelected,
|
|
26
|
+
withHOC
|
|
27
|
+
} from 'platejs/react';
|
|
28
|
+
|
|
29
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
30
|
+
|
|
31
|
+
import { blockSelectionVariants } from './block-selection';
|
|
32
|
+
|
|
33
|
+
import { Button } from './button';
|
|
34
|
+
|
|
35
|
+
export const TableElement = withHOC(
|
|
36
|
+
TableProvider,
|
|
37
|
+
(props: PlateElementProps) => {
|
|
38
|
+
const { editor, element } = props;
|
|
39
|
+
const { tf } = useEditorPlugin(TablePlugin);
|
|
40
|
+
const readOnly = useReadOnly();
|
|
41
|
+
const {
|
|
42
|
+
isSelectingCell,
|
|
43
|
+
marginLeft,
|
|
44
|
+
props: tableProps
|
|
45
|
+
} = useTableElement();
|
|
46
|
+
|
|
47
|
+
const isSelectingTable = useBlockSelected(props.element.id as string);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<PlateElement
|
|
51
|
+
{...props}
|
|
52
|
+
className="overflow-x-auto py-5"
|
|
53
|
+
style={{ paddingLeft: marginLeft }}>
|
|
54
|
+
<div className="group/table relative w-fit">
|
|
55
|
+
<table
|
|
56
|
+
className={cn(
|
|
57
|
+
'mr-0 ml-px table h-px table-fixed border-collapse',
|
|
58
|
+
isSelectingCell && 'selection:bg-transparent'
|
|
59
|
+
)}
|
|
60
|
+
{...tableProps}>
|
|
61
|
+
<tbody className="min-w-full">{props.children}</tbody>
|
|
62
|
+
</table>
|
|
63
|
+
|
|
64
|
+
{!readOnly && (
|
|
65
|
+
<>
|
|
66
|
+
<div
|
|
67
|
+
className={cn(
|
|
68
|
+
'absolute inset-x-0 bottom-[-18px] flex flex-row opacity-0 transition-opacity hover:opacity-100',
|
|
69
|
+
'group-has-[tr:last-child:hover]/table:opacity-100 max-sm:group-has-[tr[data-selected]:last-child]/table:opacity-100'
|
|
70
|
+
)}>
|
|
71
|
+
<Button
|
|
72
|
+
className="flex h-4 w-full grow items-center justify-center bg-muted"
|
|
73
|
+
onClick={() => tf.insert.tableRow({ at: editor.api.findPath(element) })}
|
|
74
|
+
onMouseDown={e => e.preventDefault()}
|
|
75
|
+
size="none"
|
|
76
|
+
tooltip="Add a new row"
|
|
77
|
+
tooltipContentProps={{ side: 'bottom' }}
|
|
78
|
+
variant="ghost">
|
|
79
|
+
<PlusIcon className="!size-3.5 text-muted-foreground" />
|
|
80
|
+
</Button>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<div
|
|
84
|
+
className={cn(
|
|
85
|
+
'absolute inset-y-0 right-[-18px] flex opacity-0 transition-opacity hover:opacity-100',
|
|
86
|
+
'group-has-[td:last-child:hover,th:last-child:hover]/table:opacity-100 max-sm:group-has-[td[data-selected]:last-child,th[data-selected]:last-child]/table:opacity-100'
|
|
87
|
+
)}>
|
|
88
|
+
<Button
|
|
89
|
+
className="flex h-full w-4 grow items-center justify-center bg-muted"
|
|
90
|
+
onClick={() => tf.insert.tableColumn({
|
|
91
|
+
at: editor.api.findPath(element)
|
|
92
|
+
})}
|
|
93
|
+
onMouseDown={e => e.preventDefault()}
|
|
94
|
+
size="none"
|
|
95
|
+
tooltip="Add a new column"
|
|
96
|
+
tooltipContentProps={{ side: 'bottom' }}
|
|
97
|
+
variant="ghost">
|
|
98
|
+
<PlusIcon className="!size-3.5 text-muted-foreground" />
|
|
99
|
+
</Button>
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<div
|
|
103
|
+
className={cn(
|
|
104
|
+
'absolute right-[-18px] bottom-[-18px] flex flex-row opacity-0 transition-opacity hover:opacity-100',
|
|
105
|
+
'group-has-[td:last-child:hover,th:last-child:hover]/table:group-has-[tr:last-child:hover]/table:opacity-100 max-sm:group-has-[td[data-selected]:last-child,th[data-selected]:last-child]/table:group-has-[tr[data-selected]:last-child]/table:opacity-100'
|
|
106
|
+
)}>
|
|
107
|
+
<Button
|
|
108
|
+
className="flex size-4 items-center justify-center rounded-full bg-muted"
|
|
109
|
+
onClick={() => {
|
|
110
|
+
editor.tf.withoutNormalizing(() => {
|
|
111
|
+
tf.insert.tableRow({ at: editor.api.findPath(element) });
|
|
112
|
+
tf.insert.tableColumn({
|
|
113
|
+
at: editor.api.findPath(element)
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}}
|
|
117
|
+
onMouseDown={e => e.preventDefault()}
|
|
118
|
+
size="none"
|
|
119
|
+
tooltip="Add a new row and column"
|
|
120
|
+
tooltipContentProps={{ side: 'bottom' }}
|
|
121
|
+
variant="ghost">
|
|
122
|
+
<PlusIcon className="!size-3.5 text-muted-foreground" />
|
|
123
|
+
</Button>
|
|
124
|
+
</div>
|
|
125
|
+
</>
|
|
126
|
+
)}
|
|
127
|
+
|
|
128
|
+
{isSelectingTable && (
|
|
129
|
+
<div className={blockSelectionVariants()} contentEditable={false} />
|
|
130
|
+
)}
|
|
131
|
+
</div>
|
|
132
|
+
</PlateElement>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
export function TableRowElement(props: PlateElementProps) {
|
|
138
|
+
const selected = useSelected();
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<PlateElement
|
|
142
|
+
{...props}
|
|
143
|
+
as="tr"
|
|
144
|
+
className="h-full"
|
|
145
|
+
data-selected={selected ? 'true' : undefined} />
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function TableCellElement({
|
|
150
|
+
isHeader,
|
|
151
|
+
...props
|
|
152
|
+
}: PlateElementProps<TTableCellElement> & {
|
|
153
|
+
isHeader?: boolean;
|
|
154
|
+
}) {
|
|
155
|
+
const { api } = useEditorPlugin(TablePlugin);
|
|
156
|
+
const readOnly = useReadOnly();
|
|
157
|
+
const { element } = props;
|
|
158
|
+
|
|
159
|
+
const rowId = useElementSelector(([node]) => node.id as string, [], {
|
|
160
|
+
key: KEYS.tr
|
|
161
|
+
});
|
|
162
|
+
const isSelectingRow = useBlockSelected(rowId);
|
|
163
|
+
|
|
164
|
+
const {
|
|
165
|
+
borders,
|
|
166
|
+
colIndex,
|
|
167
|
+
colSpan,
|
|
168
|
+
isSelectingCell,
|
|
169
|
+
minHeight,
|
|
170
|
+
rowIndex,
|
|
171
|
+
selected,
|
|
172
|
+
width
|
|
173
|
+
} = useTableCellElement();
|
|
174
|
+
|
|
175
|
+
const {
|
|
176
|
+
bottomProps, hiddenLeft, leftProps, rightProps
|
|
177
|
+
}
|
|
178
|
+
= useTableCellElementResizable({
|
|
179
|
+
colIndex,
|
|
180
|
+
colSpan,
|
|
181
|
+
rowIndex
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<PlateElement
|
|
186
|
+
{...props}
|
|
187
|
+
as={isHeader ? 'th' : 'td'}
|
|
188
|
+
attributes={{
|
|
189
|
+
...props.attributes,
|
|
190
|
+
colSpan: api.table.getColSpan(element),
|
|
191
|
+
rowSpan: api.table.getRowSpan(element)
|
|
192
|
+
}}
|
|
193
|
+
className={cn(
|
|
194
|
+
'h-full overflow-visible border-none bg-background p-0',
|
|
195
|
+
element.background ? 'bg-(--cellBackground)' : 'bg-background',
|
|
196
|
+
isHeader && 'text-left *:m-0',
|
|
197
|
+
'before:size-full',
|
|
198
|
+
selected && 'before:z-10 before:bg-muted',
|
|
199
|
+
"before:absolute before:box-border before:select-none before:content-['']",
|
|
200
|
+
borders.bottom?.size && 'before:border-b before:border-b-border',
|
|
201
|
+
borders.right?.size && 'before:border-r before:border-r-border',
|
|
202
|
+
borders.left?.size && 'before:border-l before:border-l-border',
|
|
203
|
+
borders.top?.size && 'before:border-t before:border-t-border'
|
|
204
|
+
)}
|
|
205
|
+
style={
|
|
206
|
+
{
|
|
207
|
+
'--cellBackground': element.background,
|
|
208
|
+
maxWidth: width || 240,
|
|
209
|
+
minWidth: width || 120
|
|
210
|
+
} as CSSProperties
|
|
211
|
+
}>
|
|
212
|
+
<div
|
|
213
|
+
className="relative z-20 box-border h-full px-4 py-2"
|
|
214
|
+
style={{ minHeight }}>
|
|
215
|
+
{props.children}
|
|
216
|
+
</div>
|
|
217
|
+
|
|
218
|
+
{!isSelectingCell && (
|
|
219
|
+
<div
|
|
220
|
+
className="group absolute top-0 size-full select-none"
|
|
221
|
+
contentEditable={false}
|
|
222
|
+
suppressContentEditableWarning={true}>
|
|
223
|
+
{!readOnly && (
|
|
224
|
+
<>
|
|
225
|
+
<ResizeHandle
|
|
226
|
+
{...rightProps}
|
|
227
|
+
className="-top-2 -right-1 h-[calc(100%_+_8px)] w-2"
|
|
228
|
+
data-col={colIndex} />
|
|
229
|
+
<ResizeHandle {...bottomProps} className="-bottom-1 h-2" />
|
|
230
|
+
{!hiddenLeft && (
|
|
231
|
+
<ResizeHandle
|
|
232
|
+
{...leftProps}
|
|
233
|
+
className="-left-1 top-0 w-2"
|
|
234
|
+
data-resizer-left={colIndex === 0 ? 'true' : undefined} />
|
|
235
|
+
)}
|
|
236
|
+
|
|
237
|
+
<div
|
|
238
|
+
className={cn(
|
|
239
|
+
'absolute top-0 z-30 hidden h-full w-1 bg-ring',
|
|
240
|
+
'right-[-1.5px]',
|
|
241
|
+
columnResizeVariants({ colIndex: colIndex as any })
|
|
242
|
+
)} />
|
|
243
|
+
{colIndex === 0 && (
|
|
244
|
+
<div
|
|
245
|
+
className={cn(
|
|
246
|
+
'absolute top-0 z-30 h-full w-1 bg-ring',
|
|
247
|
+
'left-[-1.5px]',
|
|
248
|
+
'fade-in hidden animate-in group-has-[[data-resizer-left]:hover]/table:block group-has-[[data-resizer-left][data-resizing="true"]]/table:block'
|
|
249
|
+
)} />
|
|
250
|
+
)}
|
|
251
|
+
</>
|
|
252
|
+
)}
|
|
253
|
+
</div>
|
|
254
|
+
)}
|
|
255
|
+
|
|
256
|
+
{isSelectingRow && (
|
|
257
|
+
<div className={blockSelectionVariants()} contentEditable={false} />
|
|
258
|
+
)}
|
|
259
|
+
</PlateElement>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function TableCellHeaderElement(
|
|
264
|
+
props: ComponentProps<typeof TableCellElement>
|
|
265
|
+
) {
|
|
266
|
+
return <TableCellElement {...props} isHeader />;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const columnResizeVariants = cva('fade-in hidden animate-in', {
|
|
270
|
+
variants: {
|
|
271
|
+
colIndex: {
|
|
272
|
+
0: 'group-has-[[data-col="0"]:hover]/table:block group-has-[[data-col="0"][data-resizing="true"]]/table:block',
|
|
273
|
+
1: 'group-has-[[data-col="1"]:hover]/table:block group-has-[[data-col="1"][data-resizing="true"]]/table:block',
|
|
274
|
+
2: 'group-has-[[data-col="2"]:hover]/table:block group-has-[[data-col="2"][data-resizing="true"]]/table:block',
|
|
275
|
+
3: 'group-has-[[data-col="3"]:hover]/table:block group-has-[[data-col="3"][data-resizing="true"]]/table:block',
|
|
276
|
+
4: 'group-has-[[data-col="4"]:hover]/table:block group-has-[[data-col="4"][data-resizing="true"]]/table:block',
|
|
277
|
+
5: 'group-has-[[data-col="5"]:hover]/table:block group-has-[[data-col="5"][data-resizing="true"]]/table:block',
|
|
278
|
+
6: 'group-has-[[data-col="6"]:hover]/table:block group-has-[[data-col="6"][data-resizing="true"]]/table:block',
|
|
279
|
+
7: 'group-has-[[data-col="7"]:hover]/table:block group-has-[[data-col="7"][data-resizing="true"]]/table:block',
|
|
280
|
+
8: 'group-has-[[data-col="8"]:hover]/table:block group-has-[[data-col="8"][data-resizing="true"]]/table:block',
|
|
281
|
+
9: 'group-has-[[data-col="9"]:hover]/table:block group-has-[[data-col="9"][data-resizing="true"]]/table:block',
|
|
282
|
+
10: 'group-has-[[data-col="10"]:hover]/table:block group-has-[[data-col="10"][data-resizing="true"]]/table:block'
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
});
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
|
|
7
|
+
import { TablePlugin, useTableMergeState } from '@platejs/table/react';
|
|
8
|
+
import {
|
|
9
|
+
ArrowDown,
|
|
10
|
+
ArrowLeft,
|
|
11
|
+
ArrowRight,
|
|
12
|
+
ArrowUp,
|
|
13
|
+
Combine,
|
|
14
|
+
Grid3x3Icon,
|
|
15
|
+
Table,
|
|
16
|
+
Trash2Icon,
|
|
17
|
+
Ungroup,
|
|
18
|
+
XIcon
|
|
19
|
+
} from 'lucide-react';
|
|
20
|
+
import { KEYS } from 'platejs';
|
|
21
|
+
import { useEditorPlugin, useEditorSelector } from 'platejs/react';
|
|
22
|
+
|
|
23
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
DropdownMenu,
|
|
27
|
+
DropdownMenuContent,
|
|
28
|
+
DropdownMenuGroup,
|
|
29
|
+
DropdownMenuItem,
|
|
30
|
+
DropdownMenuPortal,
|
|
31
|
+
DropdownMenuSub,
|
|
32
|
+
DropdownMenuSubContent,
|
|
33
|
+
DropdownMenuSubTrigger,
|
|
34
|
+
DropdownMenuTrigger,
|
|
35
|
+
type DropdownMenuProps
|
|
36
|
+
} from './dropdown-menu';
|
|
37
|
+
|
|
38
|
+
import { ToolbarButton } from './toolbar';
|
|
39
|
+
|
|
40
|
+
export function TableToolbarButton(props: DropdownMenuProps) {
|
|
41
|
+
const tableSelected = useEditorSelector(
|
|
42
|
+
editor => editor?.api?.some({ match: { type: KEYS.table } }) ?? false,
|
|
43
|
+
[]
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const { editor, tf } = useEditorPlugin(TablePlugin);
|
|
47
|
+
const [open, setOpen] = useState(false);
|
|
48
|
+
const mergeState = useTableMergeState();
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<DropdownMenu open={open} onOpenChange={setOpen} modal={false} {...props}>
|
|
52
|
+
<DropdownMenuTrigger asChild>
|
|
53
|
+
<ToolbarButton pressed={open} tooltip="Table" isDropdown>
|
|
54
|
+
<Table />
|
|
55
|
+
</ToolbarButton>
|
|
56
|
+
</DropdownMenuTrigger>
|
|
57
|
+
|
|
58
|
+
<DropdownMenuPortal>
|
|
59
|
+
<DropdownMenuContent
|
|
60
|
+
className="flex w-[180px] min-w-0 flex-col"
|
|
61
|
+
align="start">
|
|
62
|
+
<DropdownMenuGroup>
|
|
63
|
+
<DropdownMenuSub>
|
|
64
|
+
<DropdownMenuSubTrigger className="gap-2 data-[disabled]:pointer-events-none data-[disabled]:opacity-50">
|
|
65
|
+
<Grid3x3Icon className="size-4" />
|
|
66
|
+
<span>Table</span>
|
|
67
|
+
</DropdownMenuSubTrigger>
|
|
68
|
+
<DropdownMenuSubContent className="m-0 p-0">
|
|
69
|
+
<TablePicker />
|
|
70
|
+
</DropdownMenuSubContent>
|
|
71
|
+
</DropdownMenuSub>
|
|
72
|
+
|
|
73
|
+
<DropdownMenuSub>
|
|
74
|
+
<DropdownMenuSubTrigger
|
|
75
|
+
className="gap-2 data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
|
|
76
|
+
disabled={!tableSelected}>
|
|
77
|
+
<div className="size-4" />
|
|
78
|
+
<span>Cell</span>
|
|
79
|
+
</DropdownMenuSubTrigger>
|
|
80
|
+
<DropdownMenuSubContent>
|
|
81
|
+
<DropdownMenuItem
|
|
82
|
+
className="min-w-[180px]"
|
|
83
|
+
disabled={!mergeState.canMerge}
|
|
84
|
+
onSelect={() => {
|
|
85
|
+
tf.table.merge();
|
|
86
|
+
editor.tf.focus();
|
|
87
|
+
}}>
|
|
88
|
+
<Combine />
|
|
89
|
+
Merge cells
|
|
90
|
+
</DropdownMenuItem>
|
|
91
|
+
<DropdownMenuItem
|
|
92
|
+
className="min-w-[180px]"
|
|
93
|
+
disabled={!mergeState.canSplit}
|
|
94
|
+
onSelect={() => {
|
|
95
|
+
tf.table.split();
|
|
96
|
+
editor.tf.focus();
|
|
97
|
+
}}>
|
|
98
|
+
<Ungroup />
|
|
99
|
+
Split cell
|
|
100
|
+
</DropdownMenuItem>
|
|
101
|
+
</DropdownMenuSubContent>
|
|
102
|
+
</DropdownMenuSub>
|
|
103
|
+
|
|
104
|
+
<DropdownMenuSub>
|
|
105
|
+
<DropdownMenuSubTrigger
|
|
106
|
+
className="gap-2 data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
|
|
107
|
+
disabled={!tableSelected}>
|
|
108
|
+
<div className="size-4" />
|
|
109
|
+
<span>Row</span>
|
|
110
|
+
</DropdownMenuSubTrigger>
|
|
111
|
+
<DropdownMenuSubContent>
|
|
112
|
+
<DropdownMenuItem
|
|
113
|
+
className="min-w-[180px]"
|
|
114
|
+
disabled={!tableSelected}
|
|
115
|
+
onSelect={() => {
|
|
116
|
+
tf.insert.tableRow({ before: true });
|
|
117
|
+
editor.tf.focus();
|
|
118
|
+
}}>
|
|
119
|
+
<ArrowUp />
|
|
120
|
+
Insert row before
|
|
121
|
+
</DropdownMenuItem>
|
|
122
|
+
<DropdownMenuItem
|
|
123
|
+
className="min-w-[180px]"
|
|
124
|
+
disabled={!tableSelected}
|
|
125
|
+
onSelect={() => {
|
|
126
|
+
tf.insert.tableRow();
|
|
127
|
+
editor.tf.focus();
|
|
128
|
+
}}>
|
|
129
|
+
<ArrowDown />
|
|
130
|
+
Insert row after
|
|
131
|
+
</DropdownMenuItem>
|
|
132
|
+
<DropdownMenuItem
|
|
133
|
+
className="min-w-[180px]"
|
|
134
|
+
disabled={!tableSelected}
|
|
135
|
+
onSelect={() => {
|
|
136
|
+
tf.remove.tableRow();
|
|
137
|
+
editor.tf.focus();
|
|
138
|
+
}}>
|
|
139
|
+
<XIcon />
|
|
140
|
+
Delete row
|
|
141
|
+
</DropdownMenuItem>
|
|
142
|
+
</DropdownMenuSubContent>
|
|
143
|
+
</DropdownMenuSub>
|
|
144
|
+
|
|
145
|
+
<DropdownMenuSub>
|
|
146
|
+
<DropdownMenuSubTrigger
|
|
147
|
+
className="gap-2 data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
|
|
148
|
+
disabled={!tableSelected}>
|
|
149
|
+
<div className="size-4" />
|
|
150
|
+
<span>Column</span>
|
|
151
|
+
</DropdownMenuSubTrigger>
|
|
152
|
+
<DropdownMenuSubContent>
|
|
153
|
+
<DropdownMenuItem
|
|
154
|
+
className="min-w-[180px]"
|
|
155
|
+
disabled={!tableSelected}
|
|
156
|
+
onSelect={() => {
|
|
157
|
+
tf.insert.tableColumn({ before: true });
|
|
158
|
+
editor.tf.focus();
|
|
159
|
+
}}>
|
|
160
|
+
<ArrowLeft />
|
|
161
|
+
Insert column before
|
|
162
|
+
</DropdownMenuItem>
|
|
163
|
+
<DropdownMenuItem
|
|
164
|
+
className="min-w-[180px]"
|
|
165
|
+
disabled={!tableSelected}
|
|
166
|
+
onSelect={() => {
|
|
167
|
+
tf.insert.tableColumn();
|
|
168
|
+
editor.tf.focus();
|
|
169
|
+
}}>
|
|
170
|
+
<ArrowRight />
|
|
171
|
+
Insert column after
|
|
172
|
+
</DropdownMenuItem>
|
|
173
|
+
<DropdownMenuItem
|
|
174
|
+
className="min-w-[180px]"
|
|
175
|
+
disabled={!tableSelected}
|
|
176
|
+
onSelect={() => {
|
|
177
|
+
tf.remove.tableColumn();
|
|
178
|
+
editor.tf.focus();
|
|
179
|
+
}}>
|
|
180
|
+
<XIcon />
|
|
181
|
+
Delete column
|
|
182
|
+
</DropdownMenuItem>
|
|
183
|
+
</DropdownMenuSubContent>
|
|
184
|
+
</DropdownMenuSub>
|
|
185
|
+
|
|
186
|
+
<DropdownMenuItem
|
|
187
|
+
className="min-w-[180px]"
|
|
188
|
+
disabled={!tableSelected}
|
|
189
|
+
onSelect={() => {
|
|
190
|
+
tf.remove.table();
|
|
191
|
+
editor.tf.focus();
|
|
192
|
+
}}>
|
|
193
|
+
<Trash2Icon />
|
|
194
|
+
Delete table
|
|
195
|
+
</DropdownMenuItem>
|
|
196
|
+
</DropdownMenuGroup>
|
|
197
|
+
</DropdownMenuContent>
|
|
198
|
+
</DropdownMenuPortal>
|
|
199
|
+
</DropdownMenu>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function TablePicker() {
|
|
204
|
+
const { editor, tf } = useEditorPlugin(TablePlugin);
|
|
205
|
+
|
|
206
|
+
const [tablePicker, setTablePicker] = useState({
|
|
207
|
+
grid: Array.from({ length: 8 }, () => Array.from({ length: 8 }).fill(0)),
|
|
208
|
+
size: { colCount: 0, rowCount: 0 }
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const onCellMove = (rowIndex: number, colIndex: number) => {
|
|
212
|
+
const newGrid = [...tablePicker.grid];
|
|
213
|
+
|
|
214
|
+
for (let i = 0; i < newGrid.length; i++) {
|
|
215
|
+
for (let j = 0; j < newGrid[i].length; j++) {
|
|
216
|
+
newGrid[i][j]
|
|
217
|
+
= i >= 0 && i <= rowIndex && j >= 0 && j <= colIndex ? 1 : 0;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
setTablePicker({
|
|
222
|
+
grid: newGrid,
|
|
223
|
+
size: { colCount: colIndex + 1, rowCount: rowIndex + 1 }
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
return (
|
|
228
|
+
<div
|
|
229
|
+
className="flex! m-0 flex-col p-0"
|
|
230
|
+
onClick={() => {
|
|
231
|
+
tf.insert.table(tablePicker.size, { select: true });
|
|
232
|
+
editor.tf.focus();
|
|
233
|
+
}}
|
|
234
|
+
role="button">
|
|
235
|
+
<div className="grid size-[130px] grid-cols-8 gap-0.5 p-1">
|
|
236
|
+
{tablePicker.grid.map((rows, rowIndex) => rows.map((value, columIndex) => (
|
|
237
|
+
<div
|
|
238
|
+
key={`(${rowIndex},${columIndex})`}
|
|
239
|
+
className={cn(
|
|
240
|
+
'col-span-1 size-3 border border-solid bg-secondary',
|
|
241
|
+
!!value && 'border-current'
|
|
242
|
+
)}
|
|
243
|
+
onMouseMove={() => {
|
|
244
|
+
onCellMove(rowIndex, columIndex);
|
|
245
|
+
}} />
|
|
246
|
+
)))}
|
|
247
|
+
</div>
|
|
248
|
+
|
|
249
|
+
<div className="text-center text-current text-xs">
|
|
250
|
+
{tablePicker.size.rowCount} x {tablePicker.size.colCount}
|
|
251
|
+
</div>
|
|
252
|
+
</div>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type ComponentProps } from 'react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
import { TextareaAutosize as ReactTextareaAutosize } from '@platejs/caption/react';
|
|
5
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
6
|
+
|
|
7
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
8
|
+
|
|
9
|
+
export const textareaVariants = cva(
|
|
10
|
+
cn(
|
|
11
|
+
'resize-none text-sm disabled:cursor-not-allowed disabled:opacity-50',
|
|
12
|
+
'placeholder:text-muted-foreground/80'
|
|
13
|
+
),
|
|
14
|
+
{
|
|
15
|
+
defaultVariants: {
|
|
16
|
+
variant: 'default'
|
|
17
|
+
},
|
|
18
|
+
variants: {
|
|
19
|
+
variant: {
|
|
20
|
+
ai: 'max-h-[240px] border-transparent bg-transparent py-2 focus:outline-none focus:ring-0',
|
|
21
|
+
default:
|
|
22
|
+
'rounded-md border-[1.5px] border-input bg-muted/80 px-1 pt-1 pb-0.5 read-only:ring-0 focus:border-brand/50 focus:ring-2 focus:ring-brand/30 read-only:focus:border-input',
|
|
23
|
+
equation: 'max-h-[50vh] min-h-[60px] font-mono text-sm',
|
|
24
|
+
equationInline: 'max-h-[50vh] font-mono text-sm'
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export type TextareaAutosizeProps = ComponentProps<
|
|
31
|
+
typeof ReactTextareaAutosize
|
|
32
|
+
>
|
|
33
|
+
& VariantProps<typeof textareaVariants>;
|
|
34
|
+
|
|
35
|
+
export function Textarea({ className, variant, ...props }: TextareaProps) {
|
|
36
|
+
return (
|
|
37
|
+
<textarea
|
|
38
|
+
className={cn(textareaVariants({ variant }), className)}
|
|
39
|
+
{...props} />
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type TextareaProps = ComponentProps<'textarea'>
|
|
44
|
+
& VariantProps<typeof textareaVariants>;
|
|
45
|
+
|
|
46
|
+
export function TextareaAutosize({
|
|
47
|
+
children: _children,
|
|
48
|
+
className,
|
|
49
|
+
variant,
|
|
50
|
+
...props
|
|
51
|
+
}: TextareaAutosizeProps) {
|
|
52
|
+
return (
|
|
53
|
+
<ReactTextareaAutosize
|
|
54
|
+
autoComplete="off"
|
|
55
|
+
className={cn(textareaVariants({ variant }), className)}
|
|
56
|
+
{...props} />
|
|
57
|
+
);
|
|
58
|
+
}
|