@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.
- package/dist/types/format-toolbar.d.ts +11 -2
- package/dist/types/format-toolbar.d.ts.map +1 -1
- package/dist/types/image-popover.d.ts +7 -1
- package/dist/types/image-popover.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/media-annotation-editor.d.ts +20 -0
- package/dist/types/media-annotation-editor.d.ts.map +1 -0
- package/dist/types/media-library.d.ts.map +1 -1
- package/dist/types/media-source.d.ts +8 -0
- package/dist/types/media-source.d.ts.map +1 -1
- package/dist/types/milkdown-utils.d.ts +17 -0
- package/dist/types/milkdown-utils.d.ts.map +1 -1
- package/dist/types/slot-editor.d.ts +6 -2
- package/dist/types/slot-editor.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/format-toolbar.tsx +95 -9
- package/src/image-popover.tsx +32 -6
- package/src/index.ts +1 -1
- package/src/mdx-block-card.tsx +1 -1
- package/src/media-annotation-editor.tsx +105 -0
- package/src/media-library.tsx +75 -24
- package/src/media-source.ts +5 -0
- package/src/milkdown-utils.ts +48 -1
- package/src/slot-editor.tsx +13 -2
package/src/slot-editor.tsx
CHANGED
|
@@ -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
|
|
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}
|