Skip to content

Commit b1e9bc7

Browse files
authored
feat: 🎸 migrate image block to vue (#1803)
1 parent 0f07788 commit b1e9bc7

File tree

24 files changed

+550
-280
lines changed

24 files changed

+550
-280
lines changed

Diff for: .oxlintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"plugins": ["import", "typescript", "unicorn", "promise"],
33
"rules": {
4-
"no-console": "error",
4+
"no-console": ["error", { "allow": ["warn", "error"] }],
55
"for-direction": "error",
66
"require-yield": "error",
77
"use-isnan": "error",

Diff for: packages/components/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@
103103
"@codemirror/view": "^6"
104104
},
105105
"dependencies": {
106+
"@atomico/hooks": "^4.1.2",
107+
"@floating-ui/dom": "^1.5.1",
106108
"@milkdown/core": "workspace:*",
107109
"@milkdown/ctx": "workspace:*",
110+
"@milkdown/exception": "workspace:*",
108111
"@milkdown/plugin-tooltip": "workspace:*",
109112
"@milkdown/preset-commonmark": "workspace:*",
110113
"@milkdown/preset-gfm": "workspace:*",
111114
"@milkdown/prose": "workspace:*",
112115
"@milkdown/transformer": "workspace:*",
113116
"@milkdown/utils": "workspace:*",
114-
"@atomico/hooks": "^4.1.2",
115-
"@floating-ui/dom": "^1.5.1",
116-
"@milkdown/exception": "workspace:*",
117117
"@types/lodash.debounce": "^4.0.7",
118118
"@types/lodash.throttle": "^4.1.9",
119119
"atomico": "^1.75.1",
@@ -122,7 +122,8 @@
122122
"lodash.throttle": "^4.1.1",
123123
"nanoid": "^5.0.9",
124124
"tslib": "^2.8.1",
125-
"unist-util-visit": "^5.0.0"
125+
"unist-util-visit": "^5.0.0",
126+
"vue": "^3.5.13"
126127
},
127128
"devDependencies": {
128129
"@codemirror/language": "^6.10.1",

Diff for: packages/components/src/__internal__/icon.tsx

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import clsx from 'clsx'
2+
import { h } from 'vue'
3+
4+
h
5+
6+
type IconProps = {
7+
icon: string | null
8+
class?: string
9+
}
10+
11+
export function Icon({ icon, class: className }: IconProps) {
12+
return (
13+
<span
14+
class={clsx('milkdown-icon', className)}
15+
ref={(el) => {
16+
if (el && icon) {
17+
;(el as HTMLElement).innerHTML = icon
18+
}
19+
}}
20+
/>
21+
)
22+
}
23+
24+
Icon.props = {
25+
icon: {
26+
type: String,
27+
required: false,
28+
},
29+
class: {
30+
type: String,
31+
required: false,
32+
},
33+
}

Diff for: packages/components/src/image-block/config.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { $ctx } from '@milkdown/utils'
2-
import { html } from 'atomico'
32
import { withMeta } from '../__internal__/meta'
43

54
export interface ImageBlockConfig {
6-
imageIcon: () => ReturnType<typeof html> | string | HTMLElement
7-
captionIcon: () => ReturnType<typeof html> | string | HTMLElement
8-
uploadButton: () => ReturnType<typeof html> | string | HTMLElement
9-
confirmButton: () => ReturnType<typeof html> | string | HTMLElement
5+
imageIcon: () => string | null
6+
captionIcon: () => string | null
7+
uploadButton: () => string | null
8+
confirmButton: () => string | null
109
uploadPlaceholderText: string
1110
captionPlaceholderText: string
1211
onUpload: (file: File) => Promise<string>
@@ -16,8 +15,8 @@ export interface ImageBlockConfig {
1615
export const defaultImageBlockConfig: ImageBlockConfig = {
1716
imageIcon: () => '🌌',
1817
captionIcon: () => '💬',
19-
uploadButton: () => html`Upload file`,
20-
confirmButton: () => html`Confirm ⏎`,
18+
uploadButton: () => 'Upload file',
19+
confirmButton: () => 'Confirm ⏎',
2120
uploadPlaceholderText: 'or paste the image link ...',
2221
captionPlaceholderText: 'Image caption',
2322
onUpload: (file) => Promise.resolve(URL.createObjectURL(file)),

Diff for: packages/components/src/image-block/view/component.ts

-195
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { h, Fragment, type Ref, defineComponent } from 'vue'
2+
import type { ImageBlockConfig } from '../../config'
3+
import { ImageViewer } from './image-viewer'
4+
import { ImageInput } from './image-input'
5+
6+
h
7+
Fragment
8+
9+
type Attrs = {
10+
src: string
11+
caption: string
12+
ratio: number
13+
}
14+
15+
export type MilkdownImageBlockProps = {
16+
selected: Ref<boolean | undefined>
17+
readonly: Ref<boolean | undefined>
18+
setAttr: <T extends keyof Attrs>(attr: T, value: Attrs[T]) => void
19+
config: ImageBlockConfig
20+
} & {
21+
[P in keyof Attrs]: Ref<Attrs[P] | undefined>
22+
}
23+
24+
export const MilkdownImageBlock = defineComponent<MilkdownImageBlockProps>({
25+
props: {
26+
src: {
27+
type: Object,
28+
required: true,
29+
},
30+
caption: {
31+
type: Object,
32+
required: true,
33+
},
34+
ratio: {
35+
type: Object,
36+
required: true,
37+
},
38+
selected: {
39+
type: Object,
40+
required: true,
41+
},
42+
readonly: {
43+
type: Object,
44+
required: true,
45+
},
46+
setAttr: {
47+
type: Function,
48+
required: true,
49+
},
50+
config: {
51+
type: Object,
52+
required: true,
53+
},
54+
},
55+
setup(props) {
56+
const { src } = props
57+
58+
return () => {
59+
if (!src.value?.length) {
60+
return <ImageInput {...props} />
61+
}
62+
return <ImageViewer {...props} />
63+
}
64+
},
65+
})

0 commit comments

Comments
 (0)