@jvs-milkdown/components 1.0.0 → 1.1.1
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/lib/image-block/index.js +47 -8
- package/lib/image-block/index.js.map +1 -1
- package/lib/image-block/view/components/image-viewer.d.ts.map +1 -1
- package/lib/table-block/config.d.ts +1 -1
- package/lib/table-block/config.d.ts.map +1 -1
- package/lib/table-block/index.js +622 -421
- package/lib/table-block/index.js.map +1 -1
- package/lib/table-block/view/component.d.ts.map +1 -1
- package/lib/table-block/view/operation.d.ts +2 -0
- package/lib/table-block/view/operation.d.ts.map +1 -1
- package/lib/table-block/view/view.d.ts.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +80 -54
- package/src/image-block/view/components/image-viewer.tsx +49 -8
- package/src/table-block/config.ts +6 -0
- package/src/table-block/dnd/create-drag-handler.ts +1 -13
- package/src/table-block/dnd/prepare-dnd-context.ts +0 -8
- package/src/table-block/view/component.tsx +484 -83
- package/src/table-block/view/drag.ts +2 -16
- package/src/table-block/view/operation.ts +108 -49
- package/src/table-block/view/pointer.ts +3 -155
- package/src/table-block/view/types.ts +0 -6
- package/src/table-block/view/utils.ts +2 -81
- package/src/table-block/view/view.ts +19 -58
- package/LICENSE +0 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jvs-milkdown/components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"milkdown",
|
|
6
6
|
"milkdown plugin"
|
|
@@ -17,55 +17,108 @@
|
|
|
17
17
|
],
|
|
18
18
|
"type": "module",
|
|
19
19
|
"sideEffects": false,
|
|
20
|
-
"main": "./
|
|
20
|
+
"main": "./src/index.ts",
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
|
-
"
|
|
24
|
-
"import": "./lib/index.js"
|
|
23
|
+
"import": "./src/index.ts"
|
|
25
24
|
},
|
|
26
25
|
"./image-block": {
|
|
27
|
-
"
|
|
28
|
-
"import": "./lib/image-block/index.js"
|
|
26
|
+
"import": "./src/image-block/index.ts"
|
|
29
27
|
},
|
|
30
28
|
"./code-block": {
|
|
31
|
-
"
|
|
32
|
-
"import": "./lib/code-block/index.js"
|
|
29
|
+
"import": "./src/code-block/index.ts"
|
|
33
30
|
},
|
|
34
31
|
"./list-item-block": {
|
|
35
|
-
"
|
|
36
|
-
"import": "./lib/list-item-block/index.js"
|
|
32
|
+
"import": "./src/list-item-block/index.ts"
|
|
37
33
|
},
|
|
38
34
|
"./link-tooltip": {
|
|
39
|
-
"
|
|
40
|
-
"import": "./lib/link-tooltip/index.js"
|
|
35
|
+
"import": "./src/link-tooltip/index.ts"
|
|
41
36
|
},
|
|
42
37
|
"./image-inline": {
|
|
43
|
-
"
|
|
44
|
-
"import": "./lib/image-inline/index.js"
|
|
38
|
+
"import": "./src/image-inline/index.ts"
|
|
45
39
|
},
|
|
46
40
|
"./table-block": {
|
|
47
|
-
"
|
|
48
|
-
"import": "./lib/table-block/index.js"
|
|
41
|
+
"import": "./src/table-block/index.ts"
|
|
49
42
|
}
|
|
50
43
|
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"exports": {
|
|
46
|
+
".": {
|
|
47
|
+
"types": "./lib/index.d.ts",
|
|
48
|
+
"import": "./lib/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./image-block": {
|
|
51
|
+
"types": "./lib/image-block/index.d.ts",
|
|
52
|
+
"import": "./lib/image-block/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./code-block": {
|
|
55
|
+
"types": "./lib/code-block/index.d.ts",
|
|
56
|
+
"import": "./lib/code-block/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./list-item-block": {
|
|
59
|
+
"types": "./lib/list-item-block/index.d.ts",
|
|
60
|
+
"import": "./lib/list-item-block/index.js"
|
|
61
|
+
},
|
|
62
|
+
"./link-tooltip": {
|
|
63
|
+
"types": "./lib/link-tooltip/index.d.ts",
|
|
64
|
+
"import": "./lib/link-tooltip/index.js"
|
|
65
|
+
},
|
|
66
|
+
"./image-inline": {
|
|
67
|
+
"types": "./lib/image-inline/index.d.ts",
|
|
68
|
+
"import": "./lib/image-inline/index.js"
|
|
69
|
+
},
|
|
70
|
+
"./table-block": {
|
|
71
|
+
"types": "./lib/table-block/index.d.ts",
|
|
72
|
+
"import": "./lib/table-block/index.js"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"main": "./lib/index.js",
|
|
76
|
+
"types": "./lib/index.d.ts",
|
|
77
|
+
"typesVersions": {
|
|
78
|
+
"*": {
|
|
79
|
+
"image-block": [
|
|
80
|
+
"./lib/image-block/index.d.ts"
|
|
81
|
+
],
|
|
82
|
+
"code-block": [
|
|
83
|
+
"./lib/code-block/index.d.ts"
|
|
84
|
+
],
|
|
85
|
+
"list-item-block": [
|
|
86
|
+
"./lib/list-item-block/index.d.ts"
|
|
87
|
+
],
|
|
88
|
+
"link-tooltip": [
|
|
89
|
+
"./lib/link-tooltip/index.d.ts"
|
|
90
|
+
],
|
|
91
|
+
"image-inline": [
|
|
92
|
+
"./lib/image-inline/index.d.ts"
|
|
93
|
+
],
|
|
94
|
+
"table-block": [
|
|
95
|
+
"./lib/table-block/index.d.ts"
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"scripts": {
|
|
101
|
+
"build": "rollup -c",
|
|
102
|
+
"test": "vitest run"
|
|
103
|
+
},
|
|
51
104
|
"dependencies": {
|
|
52
105
|
"@floating-ui/dom": "^1.5.1",
|
|
106
|
+
"@jvs-milkdown/core": "^1.1.0",
|
|
107
|
+
"@jvs-milkdown/ctx": "^1.1.0",
|
|
108
|
+
"@jvs-milkdown/exception": "^1.1.0",
|
|
109
|
+
"@jvs-milkdown/plugin-tooltip": "^1.1.0",
|
|
110
|
+
"@jvs-milkdown/preset-commonmark": "^1.1.0",
|
|
111
|
+
"@jvs-milkdown/preset-gfm": "^1.1.0",
|
|
112
|
+
"@jvs-milkdown/prose": "^1.1.0",
|
|
113
|
+
"@jvs-milkdown/transformer": "^1.1.0",
|
|
114
|
+
"@jvs-milkdown/utils": "^1.1.0",
|
|
53
115
|
"@types/lodash-es": "^4.17.12",
|
|
54
116
|
"clsx": "^2.0.0",
|
|
55
117
|
"dompurify": "^3.2.5",
|
|
56
118
|
"lodash-es": "^4.17.21",
|
|
57
119
|
"nanoid": "^5.0.9",
|
|
58
120
|
"unist-util-visit": "^5.0.0",
|
|
59
|
-
"vue": "^3.5.20"
|
|
60
|
-
"@jvs-milkdown/core": "1.0.0",
|
|
61
|
-
"@jvs-milkdown/exception": "1.0.0",
|
|
62
|
-
"@jvs-milkdown/ctx": "1.0.0",
|
|
63
|
-
"@jvs-milkdown/preset-commonmark": "1.0.0",
|
|
64
|
-
"@jvs-milkdown/preset-gfm": "1.0.0",
|
|
65
|
-
"@jvs-milkdown/transformer": "1.0.0",
|
|
66
|
-
"@jvs-milkdown/plugin-tooltip": "1.0.0",
|
|
67
|
-
"@jvs-milkdown/utils": "1.0.0",
|
|
68
|
-
"@jvs-milkdown/prose": "1.0.0"
|
|
121
|
+
"vue": "^3.5.20"
|
|
69
122
|
},
|
|
70
123
|
"devDependencies": {
|
|
71
124
|
"@codemirror/language": "^6.10.1",
|
|
@@ -79,32 +132,5 @@
|
|
|
79
132
|
"@codemirror/language": "^6",
|
|
80
133
|
"@codemirror/state": "^6",
|
|
81
134
|
"@codemirror/view": "^6"
|
|
82
|
-
},
|
|
83
|
-
"scripts": {
|
|
84
|
-
"build": "rollup -c",
|
|
85
|
-
"test": "vitest run"
|
|
86
|
-
},
|
|
87
|
-
"types": "./lib/index.d.ts",
|
|
88
|
-
"typesVersions": {
|
|
89
|
-
"*": {
|
|
90
|
-
"image-block": [
|
|
91
|
-
"./lib/image-block/index.d.ts"
|
|
92
|
-
],
|
|
93
|
-
"code-block": [
|
|
94
|
-
"./lib/code-block/index.d.ts"
|
|
95
|
-
],
|
|
96
|
-
"list-item-block": [
|
|
97
|
-
"./lib/list-item-block/index.d.ts"
|
|
98
|
-
],
|
|
99
|
-
"link-tooltip": [
|
|
100
|
-
"./lib/link-tooltip/index.d.ts"
|
|
101
|
-
],
|
|
102
|
-
"image-inline": [
|
|
103
|
-
"./lib/image-inline/index.d.ts"
|
|
104
|
-
],
|
|
105
|
-
"table-block": [
|
|
106
|
-
"./lib/table-block/index.d.ts"
|
|
107
|
-
]
|
|
108
|
-
}
|
|
109
135
|
}
|
|
110
|
-
}
|
|
136
|
+
}
|
|
@@ -41,10 +41,15 @@ export const ImageViewer = defineComponent<MilkdownImageBlockProps>({
|
|
|
41
41
|
},
|
|
42
42
|
setup({ src, caption, ratio, readonly, setAttr, config }) {
|
|
43
43
|
const imageRef = ref<HTMLImageElement>()
|
|
44
|
-
const resizeHandle = ref<HTMLDivElement>()
|
|
45
44
|
const showCaption = ref(Boolean(caption.value?.length))
|
|
46
45
|
const timer = ref(0)
|
|
47
46
|
|
|
47
|
+
let resizeDir = ''
|
|
48
|
+
let startY = 0
|
|
49
|
+
let startX = 0
|
|
50
|
+
let startHeight = 0
|
|
51
|
+
let startWidth = 0
|
|
52
|
+
|
|
48
53
|
const onImageLoad = () => {
|
|
49
54
|
const image = imageRef.value
|
|
50
55
|
if (!image) return
|
|
@@ -105,11 +110,26 @@ export const ImageViewer = defineComponent<MilkdownImageBlockProps>({
|
|
|
105
110
|
e.preventDefault()
|
|
106
111
|
const image = imageRef.value
|
|
107
112
|
if (!image) return
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
|
|
114
|
+
const deltaY = e.clientY - startY
|
|
115
|
+
const deltaX = e.clientX - startX
|
|
116
|
+
|
|
117
|
+
const aspect = startHeight / (startWidth || 1)
|
|
118
|
+
let dhY = resizeDir.includes('bottom') ? deltaY : -deltaY
|
|
119
|
+
let dhX = 0
|
|
120
|
+
if (resizeDir.includes('right')) {
|
|
121
|
+
dhX = deltaX * aspect
|
|
122
|
+
} else if (resizeDir.includes('left')) {
|
|
123
|
+
dhX = -deltaX * aspect
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const dh = Math.abs(dhX) > Math.abs(dhY) ? dhX : dhY
|
|
127
|
+
let height = startHeight + dh
|
|
128
|
+
|
|
129
|
+
if (height < 20) height = 20
|
|
111
130
|
if (config.maxHeight && height > config.maxHeight)
|
|
112
131
|
height = config.maxHeight
|
|
132
|
+
|
|
113
133
|
const h = Number(height).toFixed(2)
|
|
114
134
|
image.dataset.height = h
|
|
115
135
|
image.style.height = `${h}px`
|
|
@@ -132,10 +152,18 @@ export const ImageViewer = defineComponent<MilkdownImageBlockProps>({
|
|
|
132
152
|
setAttr('ratio', ratio)
|
|
133
153
|
}
|
|
134
154
|
|
|
135
|
-
const onResizeHandlePointerDown = (e: PointerEvent) => {
|
|
155
|
+
const onResizeHandlePointerDown = (e: PointerEvent, dir: string) => {
|
|
136
156
|
if (readonly.value) return
|
|
137
157
|
e.preventDefault()
|
|
138
158
|
e.stopPropagation()
|
|
159
|
+
resizeDir = dir
|
|
160
|
+
startY = e.clientY
|
|
161
|
+
startX = e.clientX
|
|
162
|
+
const image = imageRef.value
|
|
163
|
+
if (image) {
|
|
164
|
+
startHeight = image.getBoundingClientRect().height
|
|
165
|
+
startWidth = image.getBoundingClientRect().width
|
|
166
|
+
}
|
|
139
167
|
window.addEventListener('pointermove', onResizeHandlePointerMove)
|
|
140
168
|
window.addEventListener('pointerup', onResizeHandlePointerUp)
|
|
141
169
|
}
|
|
@@ -160,9 +188,22 @@ export const ImageViewer = defineComponent<MilkdownImageBlockProps>({
|
|
|
160
188
|
}
|
|
161
189
|
/>
|
|
162
190
|
<div
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
191
|
+
class="image-resize-handle top-left"
|
|
192
|
+
onPointerdown={(e) => onResizeHandlePointerDown(e, 'top-left')}
|
|
193
|
+
/>
|
|
194
|
+
<div
|
|
195
|
+
class="image-resize-handle top-right"
|
|
196
|
+
onPointerdown={(e) => onResizeHandlePointerDown(e, 'top-right')}
|
|
197
|
+
/>
|
|
198
|
+
<div
|
|
199
|
+
class="image-resize-handle bottom-left"
|
|
200
|
+
onPointerdown={(e) => onResizeHandlePointerDown(e, 'bottom-left')}
|
|
201
|
+
/>
|
|
202
|
+
<div
|
|
203
|
+
class="image-resize-handle bottom-right"
|
|
204
|
+
onPointerdown={(e) =>
|
|
205
|
+
onResizeHandlePointerDown(e, 'bottom-right')
|
|
206
|
+
}
|
|
166
207
|
/>
|
|
167
208
|
</div>
|
|
168
209
|
{showCaption.value && (
|
|
@@ -12,6 +12,8 @@ export type RenderType =
|
|
|
12
12
|
| 'align_col_right'
|
|
13
13
|
| 'col_drag_handle'
|
|
14
14
|
| 'row_drag_handle'
|
|
15
|
+
| 'merge_cells'
|
|
16
|
+
| 'split_cell'
|
|
15
17
|
|
|
16
18
|
export interface TableBlockConfig {
|
|
17
19
|
renderButton: (renderType: RenderType) => string
|
|
@@ -38,6 +40,10 @@ const defaultTableBlockConfig: TableBlockConfig = {
|
|
|
38
40
|
return '='
|
|
39
41
|
case 'row_drag_handle':
|
|
40
42
|
return '='
|
|
43
|
+
case 'merge_cells':
|
|
44
|
+
return '⊞'
|
|
45
|
+
case 'split_cell':
|
|
46
|
+
return '⊟'
|
|
41
47
|
}
|
|
42
48
|
},
|
|
43
49
|
}
|
|
@@ -46,18 +46,10 @@ function updateDragInfo(
|
|
|
46
46
|
context: DragContext,
|
|
47
47
|
refs: Refs
|
|
48
48
|
) {
|
|
49
|
-
const { xHandle, yHandle,
|
|
49
|
+
const { xHandle, yHandle, preview } = context
|
|
50
50
|
xHandle.dataset.displayType = axis === 'y' ? 'indicator' : 'none'
|
|
51
51
|
yHandle.dataset.displayType = axis === 'x' ? 'indicator' : 'none'
|
|
52
52
|
|
|
53
|
-
if (axis === 'y') {
|
|
54
|
-
colHandle.dataset.show = 'false'
|
|
55
|
-
hideButtonGroup(rowHandle)
|
|
56
|
-
} else {
|
|
57
|
-
rowHandle.dataset.show = 'false'
|
|
58
|
-
hideButtonGroup(colHandle)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
53
|
const { hoverIndex, dragInfo } = refs
|
|
62
54
|
const [rowIndex, colIndex] = hoverIndex.value
|
|
63
55
|
|
|
@@ -93,7 +85,3 @@ function handleDrag(
|
|
|
93
85
|
fn(context)
|
|
94
86
|
})
|
|
95
87
|
}
|
|
96
|
-
|
|
97
|
-
function hideButtonGroup(handle: HTMLElement) {
|
|
98
|
-
handle.querySelector('.button-group')?.setAttribute('data-show', 'false')
|
|
99
|
-
}
|
|
@@ -7,8 +7,6 @@ export function prepareDndContext(refs: Refs): DragContext | undefined {
|
|
|
7
7
|
contentWrapperRef,
|
|
8
8
|
yLineHandleRef,
|
|
9
9
|
xLineHandleRef,
|
|
10
|
-
colHandleRef,
|
|
11
|
-
rowHandleRef,
|
|
12
10
|
} = refs
|
|
13
11
|
|
|
14
12
|
const preview = dragPreviewRef.value
|
|
@@ -25,10 +23,6 @@ export function prepareDndContext(refs: Refs): DragContext | undefined {
|
|
|
25
23
|
if (!yHandle) return
|
|
26
24
|
const xHandle = xLineHandleRef.value
|
|
27
25
|
if (!xHandle) return
|
|
28
|
-
const colHandle = colHandleRef.value
|
|
29
|
-
if (!colHandle) return
|
|
30
|
-
const rowHandle = rowHandleRef.value
|
|
31
|
-
if (!rowHandle) return
|
|
32
26
|
|
|
33
27
|
const context = {
|
|
34
28
|
preview,
|
|
@@ -38,8 +32,6 @@ export function prepareDndContext(refs: Refs): DragContext | undefined {
|
|
|
38
32
|
previewRoot,
|
|
39
33
|
yHandle,
|
|
40
34
|
xHandle,
|
|
41
|
-
colHandle,
|
|
42
|
-
rowHandle,
|
|
43
35
|
}
|
|
44
36
|
|
|
45
37
|
return context
|