@nuasite/cms-mdx-editor 0.57.0 → 0.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,9 @@
7
7
  *
8
8
  * Emits `onChange` on blur (not per keystroke) so typing never triggers a node-view
9
9
  * re-render that would clobber the focused editor.
10
+ *
11
+ * `media` serves an image already in the slot (its preview, "Replace image"); the toolbar
12
+ * still offers no image insertion here.
10
13
  */
11
14
  import { defaultValueCtx, Editor, rootCtx } from '@milkdown/core'
12
15
  import { listener, listenerCtx } from '@milkdown/plugin-listener'
@@ -15,11 +18,19 @@ import { gfm } from '@milkdown/preset-gfm'
15
18
  import { replaceAll } from '@milkdown/utils'
16
19
  import { useEffect, useRef, useState } from 'react'
17
20
  import { FormatToolbar } from './format-toolbar'
21
+ import type { MediaContext, MediaSource } from './media-source'
18
22
 
19
23
  const wrapper: React.CSSProperties = { border: '1px solid #e4e4e7', borderRadius: 6, background: '#fff' }
20
24
  const host: React.CSSProperties = { padding: '6px 10px', minHeight: 60, fontSize: 13, lineHeight: 1.5, outline: 'none' }
21
25
 
22
- export function SlotEditor({ value, onChange }: { value: string; onChange: (markdown: string) => void }) {
26
+ export interface SlotEditorProps {
27
+ value: string
28
+ onChange: (markdown: string) => void
29
+ media?: MediaSource
30
+ mediaContext?: MediaContext
31
+ }
32
+
33
+ export function SlotEditor({ value, onChange, media, mediaContext }: SlotEditorProps) {
23
34
  const hostRef = useRef<HTMLDivElement>(null)
24
35
  const editorRef = useRef<Editor | null>(null)
25
36
  const [editor, setEditor] = useState<Editor | null>(null)
@@ -75,7 +86,7 @@ export function SlotEditor({ value, onChange }: { value: string; onChange: (mark
75
86
 
76
87
  return (
77
88
  <div style={wrapper}>
78
- <FormatToolbar editor={editor} />
89
+ <FormatToolbar editor={editor} media={media} mediaContext={mediaContext} field="children" allowImageInsert={false} />
79
90
  <div
80
91
  ref={hostRef}
81
92
  style={host}