Skip to content

Commit

Permalink
Fix editor initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
petyosi committed Apr 7, 2024
1 parent e3e0f23 commit e614ce6
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 186 deletions.
4 changes: 2 additions & 2 deletions app/editor/demo/live-demo.tsx → app/DemoEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use client'
import MDXEditor from '@/app/editor'
import {
toolbarPlugin,
KitchenSinkToolbar,
Expand All @@ -20,6 +19,7 @@ import {
diffSourcePlugin,
markdownShortcutPlugin,
SandpackConfig,
MDXEditor,
} from '@mdxeditor/editor'

const defaultSnippetContent = `
Expand Down Expand Up @@ -68,7 +68,7 @@ const allPlugins = (diffMarkdown: string) => [
markdownShortcutPlugin(),
]

export function LiveDemo({ markdown }: { markdown: string }) {
export default function DemoEditor({ markdown }: { markdown: string }) {
return (
<MDXEditor
markdown={markdown}
Expand Down
2 changes: 1 addition & 1 deletion app/homepage-editor.tsx → app/HomepageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
listsPlugin,
codeBlockPlugin,
codeMirrorPlugin,
MDXEditor,
} from '@mdxeditor/editor'
import MDXEditor from './editor'

const markdown = `
Click here to start editing this text.
Expand Down
6 changes: 4 additions & 2 deletions app/editor/demo/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import fs from 'fs'
import { LiveDemo } from './live-demo'
import dynamic from 'next/dynamic'

// eslint-disable-next-line react-refresh/only-export-components
export const metadata = {
title: 'Live demo | MDXEditor',
description: 'Live demo of MDXEditor, an open-source React component for markdown editing',
}

const LiveDemoEditor = dynamic(() => import('@/app/DemoEditor'), { ssr: false })

export default function Page() {
const demoMarkdown = fs.readFileSync('./docs/live-demo-contents.md', 'utf-8')
return <LiveDemo markdown={demoMarkdown} />
return <LiveDemoEditor markdown={demoMarkdown} />
}
4 changes: 3 additions & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { createElement, JSX } from 'react'
import { twMerge } from 'tailwind-merge'
import HomepageEditor from './homepage-editor'
import SampleCodeBlock from './sample-code-block'
import { FeatureOverviewItem } from './FeatureOverviewItem'
import SlashedArrowIcon from './images/slashed_arrow.svg'
import Image from 'next/image'
import SandpackScreenshot from './images/sandpack-screenshot.png'
import AppScreenshot from './images/app-screenshot.png'
import dynamic from 'next/dynamic'

function twElement<T extends keyof JSX.IntrinsicElements>(elemTagName: T, className: string) {
return ({ className: classNameProp, ...props }: JSX.IntrinsicElements[T]) => {
return createElement(elemTagName, { ...props, className: twMerge(className, classNameProp) })
}
}

const HomepageEditor = dynamic(() => import('./HomepageEditor'), { ssr: false })

const ActionLinkButton = twElement(
'a',
'border-solid border-[1px] rounded-md border-neutral-textContrast px-8 py-3 bg-white font-mono text-sm'
Expand Down
Loading

0 comments on commit e614ce6

Please sign in to comment.