Skip to content

Commit

Permalink
fix: Add Excalidraw support to Writing component
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Feb 3, 2024
1 parent 6897840 commit e7dfbd0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/components/modules/dashboard/writing/Writing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
import { callCommand } from '@milkdown/utils'

import { SimpleIconsMermaid } from '~/components/icons/mermaid'
import { useEditorCtx } from '~/components/ui/editor/Milkdown/ctx'
import { excalidrawSchema } from '~/components/ui/editor/Milkdown/plugins/Excalidraw'
import { useEventCallback } from '~/hooks/common/use-event-callback'
import { clsxm } from '~/lib/helper'
import { jotaiStore } from '~/lib/store'
Expand Down Expand Up @@ -51,6 +53,8 @@ export const Writing: FC<{
const MenuBar = () => {
const editorRef = useEditorRef()

const ctx = useEditorCtx()

const menuList = [
{
icon: 'icon-[material-symbols--undo]',
Expand Down Expand Up @@ -102,24 +106,21 @@ const MenuBar = () => {
{
icon: 'icon-[mingcute--drawing-board-line]',
action: () => {
const ctx = editorRef?.editor.ctx
if (!ctx) return
const view = ctx.get(editorViewCtx)
if (!view) return
const state = view.state

const currentCursorPosition = state.selection.from
const nextNode = ctx.get(schemaCtx).node('code_block', {
language: 'excalidraw',
})
const schema = ctx.get(schemaCtx)
const nextNode = schema.node(excalidrawSchema.type(ctx), {})

view.dispatch(state.tr.insert(currentCursorPosition, nextNode))
},
},
{
icon: <SimpleIconsMermaid />,
action: () => {
const ctx = editorRef?.editor.ctx
if (!ctx) return
const view = ctx.get(editorViewCtx)
if (!view) return
Expand Down
1 change: 1 addition & 0 deletions src/components/ui/editor/Milkdown/plugins/Excalidraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const excalidrawSchema = $nodeSchema(id, () => {
defining: true,
atom: true,
isolating: true,

attrs: {
value: {
default: '',
Expand Down

0 comments on commit e7dfbd0

Please sign in to comment.