@jvs-milkdown/components 1.2.2 → 1.2.4
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/__internal__/components/icon.d.ts +24 -0
- package/lib/__internal__/components/icon.d.ts.map +1 -0
- package/lib/__internal__/components/image-input.d.ts +17 -0
- package/lib/__internal__/components/image-input.d.ts.map +1 -0
- package/lib/__internal__/keep-alive.d.ts +2 -0
- package/lib/__internal__/keep-alive.d.ts.map +1 -0
- package/lib/__internal__/meta.d.ts +3 -0
- package/lib/__internal__/meta.d.ts.map +1 -0
- package/lib/__tests__/setup.d.ts +2 -0
- package/lib/__tests__/setup.d.ts.map +1 -0
- package/lib/code-block/config.d.ts +25 -0
- package/lib/code-block/config.d.ts.map +1 -0
- package/lib/code-block/index.d.ts +5 -0
- package/lib/code-block/index.d.ts.map +1 -0
- package/lib/code-block/view/components/code-block.d.ts +18 -0
- package/lib/code-block/view/components/code-block.d.ts.map +1 -0
- package/lib/code-block/view/components/copy-button.d.ts +9 -0
- package/lib/code-block/view/components/copy-button.d.ts.map +1 -0
- package/lib/code-block/view/components/language-picker.d.ts +5 -0
- package/lib/code-block/view/components/language-picker.d.ts.map +1 -0
- package/lib/code-block/view/components/preview-panel.d.ts +9 -0
- package/lib/code-block/view/components/preview-panel.d.ts.map +1 -0
- package/lib/code-block/view/index.d.ts +3 -0
- package/lib/code-block/view/index.d.ts.map +1 -0
- package/lib/code-block/view/loader.d.ts +13 -0
- package/lib/code-block/view/loader.d.ts.map +1 -0
- package/lib/code-block/view/node-view.d.ts +43 -0
- package/lib/code-block/view/node-view.d.ts.map +1 -0
- package/lib/image-block/config.d.ts +21 -0
- package/lib/image-block/config.d.ts.map +1 -0
- package/lib/image-block/convert-plugin.d.ts +2 -0
- package/lib/image-block/convert-plugin.d.ts.map +1 -0
- package/lib/image-block/index.d.ts +9 -0
- package/lib/image-block/index.d.ts.map +1 -0
- package/lib/image-block/index.js +1 -1
- package/lib/image-block/index.js.map +1 -1
- package/lib/image-block/paste-rule.d.ts +2 -0
- package/lib/image-block/paste-rule.d.ts.map +1 -0
- package/lib/image-block/remark-plugin.d.ts +2 -0
- package/lib/image-block/remark-plugin.d.ts.map +1 -0
- package/lib/image-block/schema.d.ts +3 -0
- package/lib/image-block/schema.d.ts.map +1 -0
- package/lib/image-block/view/components/__tests__/image-viewer.onImageLoadError.spec.d.ts +2 -0
- package/lib/image-block/view/components/__tests__/image-viewer.onImageLoadError.spec.d.ts.map +1 -0
- package/lib/image-block/view/components/image-block.d.ts +27 -0
- package/lib/image-block/view/components/image-block.d.ts.map +1 -0
- package/lib/image-block/view/components/image-viewer.d.ts +3 -0
- package/lib/image-block/view/components/image-viewer.d.ts.map +1 -0
- package/lib/image-block/view/index.d.ts +3 -0
- package/lib/image-block/view/index.d.ts.map +1 -0
- package/lib/image-inline/components/image-inline.d.ts +18 -0
- package/lib/image-inline/components/image-inline.d.ts.map +1 -0
- package/lib/image-inline/config.d.ts +11 -0
- package/lib/image-inline/config.d.ts.map +1 -0
- package/lib/image-inline/index.d.ts +5 -0
- package/lib/image-inline/index.d.ts.map +1 -0
- package/lib/image-inline/view.d.ts +3 -0
- package/lib/image-inline/view.d.ts.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/link-tooltip/command.d.ts +2 -0
- package/lib/link-tooltip/command.d.ts.map +1 -0
- package/lib/link-tooltip/configure.d.ts +3 -0
- package/lib/link-tooltip/configure.d.ts.map +1 -0
- package/lib/link-tooltip/edit/component.d.ts +11 -0
- package/lib/link-tooltip/edit/component.d.ts.map +1 -0
- package/lib/link-tooltip/edit/edit-configure.d.ts +3 -0
- package/lib/link-tooltip/edit/edit-configure.d.ts.map +1 -0
- package/lib/link-tooltip/edit/edit-view.d.ts +15 -0
- package/lib/link-tooltip/edit/edit-view.d.ts.map +1 -0
- package/lib/link-tooltip/index.d.ts +7 -0
- package/lib/link-tooltip/index.d.ts.map +1 -0
- package/lib/link-tooltip/index.js +1 -2
- package/lib/link-tooltip/index.js.map +1 -1
- package/lib/link-tooltip/preview/component.d.ts +11 -0
- package/lib/link-tooltip/preview/component.d.ts.map +1 -0
- package/lib/link-tooltip/preview/preview-configure.d.ts +3 -0
- package/lib/link-tooltip/preview/preview-configure.d.ts.map +1 -0
- package/lib/link-tooltip/preview/preview-view.d.ts +14 -0
- package/lib/link-tooltip/preview/preview-view.d.ts.map +1 -0
- package/lib/link-tooltip/slices.d.ts +34 -0
- package/lib/link-tooltip/slices.d.ts.map +1 -0
- package/lib/link-tooltip/tooltips.d.ts +3 -0
- package/lib/link-tooltip/tooltips.d.ts.map +1 -0
- package/lib/link-tooltip/utils.d.ts +14 -0
- package/lib/link-tooltip/utils.d.ts.map +1 -0
- package/lib/list-item-block/component.d.ts +19 -0
- package/lib/list-item-block/component.d.ts.map +1 -0
- package/lib/list-item-block/config.d.ts +13 -0
- package/lib/list-item-block/config.d.ts.map +1 -0
- package/lib/list-item-block/index.d.ts +6 -0
- package/lib/list-item-block/index.d.ts.map +1 -0
- package/lib/list-item-block/view.d.ts +3 -0
- package/lib/list-item-block/view.d.ts.map +1 -0
- package/lib/table-block/config.d.ts +8 -0
- package/lib/table-block/config.d.ts.map +1 -0
- package/lib/table-block/dnd/calc-drag-over.d.ts +3 -0
- package/lib/table-block/dnd/calc-drag-over.d.ts.map +1 -0
- package/lib/table-block/dnd/create-drag-handler.d.ts +5 -0
- package/lib/table-block/dnd/create-drag-handler.d.ts.map +1 -0
- package/lib/table-block/dnd/drag-over-handler.d.ts +3 -0
- package/lib/table-block/dnd/drag-over-handler.d.ts.map +1 -0
- package/lib/table-block/dnd/prepare-dnd-context.d.ts +3 -0
- package/lib/table-block/dnd/prepare-dnd-context.d.ts.map +1 -0
- package/lib/table-block/dnd/preview.d.ts +3 -0
- package/lib/table-block/dnd/preview.d.ts.map +1 -0
- package/lib/table-block/index.d.ts +5 -0
- package/lib/table-block/index.d.ts.map +1 -0
- package/lib/table-block/index.js +68 -10
- package/lib/table-block/index.js.map +1 -1
- package/lib/table-block/view/component.d.ts +16 -0
- package/lib/table-block/view/component.d.ts.map +1 -0
- package/lib/table-block/view/drag.d.ts +10 -0
- package/lib/table-block/view/drag.d.ts.map +1 -0
- package/lib/table-block/view/index.d.ts +2 -0
- package/lib/table-block/view/index.d.ts.map +1 -0
- package/lib/table-block/view/operation.d.ts +15 -0
- package/lib/table-block/view/operation.d.ts.map +1 -0
- package/lib/table-block/view/pointer.d.ts +7 -0
- package/lib/table-block/view/pointer.d.ts.map +1 -0
- package/lib/table-block/view/types.d.ts +28 -0
- package/lib/table-block/view/types.d.ts.map +1 -0
- package/lib/table-block/view/utils.d.ts +12 -0
- package/lib/table-block/view/utils.d.ts.map +1 -0
- package/lib/table-block/view/view.d.ts +22 -0
- package/lib/table-block/view/view.d.ts.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/image-block/convert-plugin.ts +1 -1
- package/src/image-block/paste-rule.ts +1 -21
- package/src/link-tooltip/edit/component.tsx +0 -1
- package/src/table-block/view/component.tsx +31 -13
- package/src/table-block/view/operation.ts +62 -0
- package/src/table-block/view/utils.ts +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jvs-milkdown/components",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"milkdown",
|
|
6
6
|
"milkdown plugin"
|
|
@@ -50,15 +50,15 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@floating-ui/dom": "^1.5.1",
|
|
53
|
-
"@jvs-milkdown/core": "^1.2.
|
|
54
|
-
"@jvs-milkdown/ctx": "^1.2.
|
|
55
|
-
"@jvs-milkdown/exception": "^1.2.
|
|
56
|
-
"@jvs-milkdown/plugin-tooltip": "^1.2.
|
|
57
|
-
"@jvs-milkdown/preset-commonmark": "^1.2.
|
|
58
|
-
"@jvs-milkdown/preset-gfm": "^1.2.
|
|
59
|
-
"@jvs-milkdown/prose": "^1.2.
|
|
60
|
-
"@jvs-milkdown/transformer": "^1.2.
|
|
61
|
-
"@jvs-milkdown/utils": "^1.2.
|
|
53
|
+
"@jvs-milkdown/core": "^1.2.4",
|
|
54
|
+
"@jvs-milkdown/ctx": "^1.2.4",
|
|
55
|
+
"@jvs-milkdown/exception": "^1.2.4",
|
|
56
|
+
"@jvs-milkdown/plugin-tooltip": "^1.2.4",
|
|
57
|
+
"@jvs-milkdown/preset-commonmark": "^1.2.4",
|
|
58
|
+
"@jvs-milkdown/preset-gfm": "^1.2.4",
|
|
59
|
+
"@jvs-milkdown/prose": "^1.2.4",
|
|
60
|
+
"@jvs-milkdown/transformer": "^1.2.4",
|
|
61
|
+
"@jvs-milkdown/utils": "^1.2.4",
|
|
62
62
|
"@types/lodash-es": "^4.17.12",
|
|
63
63
|
"clsx": "^2.0.0",
|
|
64
64
|
"dompurify": "^3.2.5",
|
|
@@ -30,7 +30,7 @@ export const imageBlockConvertPlugin = $prose((ctx) => {
|
|
|
30
30
|
|
|
31
31
|
// Debug: log all paragraphs with their children
|
|
32
32
|
let foundImages = 0
|
|
33
|
-
newState.doc.descendants((node
|
|
33
|
+
newState.doc.descendants((node) => {
|
|
34
34
|
if (node.type === imageType) foundImages++
|
|
35
35
|
})
|
|
36
36
|
if (foundImages > 0) {
|
|
@@ -21,27 +21,7 @@ function toImageBlock(
|
|
|
21
21
|
})
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
/// Returns the list of image nodes found, or null if there's other content.
|
|
26
|
-
function extractParagraphImages(
|
|
27
|
-
node: ProsemirrorNode,
|
|
28
|
-
imageType: ProsemirrorNode['type']
|
|
29
|
-
): ProsemirrorNode[] | null {
|
|
30
|
-
const images: ProsemirrorNode[] = []
|
|
31
|
-
for (let i = 0; i < node.childCount; i++) {
|
|
32
|
-
const child = node.child(i)
|
|
33
|
-
if (child.type === imageType) {
|
|
34
|
-
images.push(child)
|
|
35
|
-
} else if (child.type.name === 'hardbreak') {
|
|
36
|
-
continue
|
|
37
|
-
} else if (child.isText && child.text?.trim() === '') {
|
|
38
|
-
continue
|
|
39
|
-
} else {
|
|
40
|
-
return null
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return images.length > 0 ? images : null
|
|
44
|
-
}
|
|
24
|
+
|
|
45
25
|
|
|
46
26
|
/// A paste rule that converts standalone inline images to image-block nodes.
|
|
47
27
|
/// Handles the slice structures produced when pasting HTML from external pages
|
|
@@ -87,7 +87,6 @@ export const EditLink = defineComponent<EditLinkProps>({
|
|
|
87
87
|
class={clsx('button confirm', !isValidUrl(link.value) && 'disabled')}
|
|
88
88
|
icon={config.value.confirmButton}
|
|
89
89
|
onClick={onConfirmEdit}
|
|
90
|
-
style={!isValidUrl(link.value) ? { opacity: 0.5, cursor: 'not-allowed' } : undefined}
|
|
91
90
|
/>
|
|
92
91
|
) : null}
|
|
93
92
|
</div>
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
CellSelection,
|
|
8
8
|
mergeCells,
|
|
9
9
|
splitCell,
|
|
10
|
+
selectedRect,
|
|
10
11
|
} from '@jvs-milkdown/prose/tables'
|
|
11
12
|
import {
|
|
12
13
|
defineComponent,
|
|
@@ -195,7 +196,8 @@ export const TableBlock = defineComponent<TableBlockProps>({
|
|
|
195
196
|
addColByIndex,
|
|
196
197
|
selectCol,
|
|
197
198
|
selectRow,
|
|
198
|
-
|
|
199
|
+
deleteRowByIndex,
|
|
200
|
+
deleteColByIndex,
|
|
199
201
|
onAlign,
|
|
200
202
|
onMergeCells,
|
|
201
203
|
onSplitCell,
|
|
@@ -397,18 +399,34 @@ export const TableBlock = defineComponent<TableBlockProps>({
|
|
|
397
399
|
|
|
398
400
|
if (isCellSelection(selection)) {
|
|
399
401
|
const selAny = selection as any
|
|
402
|
+
const rect = selectedRect(view.state)
|
|
403
|
+
|
|
400
404
|
if (selAny.isColSelection()) {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
+
if (
|
|
406
|
+
activeColIndex.value >= rect.left &&
|
|
407
|
+
activeColIndex.value < rect.right
|
|
408
|
+
) {
|
|
409
|
+
// Keep current col index if it's within the selection
|
|
410
|
+
} else {
|
|
411
|
+
const $headCell = selAny.$headCell
|
|
412
|
+
activeColIndex.value = $headCell
|
|
413
|
+
? $headCell.index($headCell.depth)
|
|
414
|
+
: -1
|
|
415
|
+
}
|
|
405
416
|
activeRowIndex.value = -1
|
|
406
417
|
} else if (selAny.isRowSelection()) {
|
|
407
|
-
|
|
418
|
+
if (
|
|
419
|
+
activeRowIndex.value >= rect.top &&
|
|
420
|
+
activeRowIndex.value < rect.bottom
|
|
421
|
+
) {
|
|
422
|
+
// Keep current row index if it's within the selection
|
|
423
|
+
} else {
|
|
424
|
+
const $headCell = selAny.$headCell
|
|
425
|
+
activeRowIndex.value = $headCell
|
|
426
|
+
? $headCell.index($headCell.depth - 1)
|
|
427
|
+
: -1
|
|
428
|
+
}
|
|
408
429
|
activeColIndex.value = -1
|
|
409
|
-
activeRowIndex.value = $headCell
|
|
410
|
-
? $headCell.index($headCell.depth - 1)
|
|
411
|
-
: -1
|
|
412
430
|
} else {
|
|
413
431
|
activeColIndex.value = -1
|
|
414
432
|
activeRowIndex.value = -1
|
|
@@ -603,9 +621,9 @@ export const TableBlock = defineComponent<TableBlockProps>({
|
|
|
603
621
|
</button>
|
|
604
622
|
<button
|
|
605
623
|
type="button"
|
|
606
|
-
onPointerdown={(
|
|
624
|
+
onPointerdown={() => {
|
|
607
625
|
hoverIndex.value = [0, i]
|
|
608
|
-
|
|
626
|
+
deleteColByIndex(i)
|
|
609
627
|
}}
|
|
610
628
|
>
|
|
611
629
|
<Icon icon={config.renderButton('delete_col')} />
|
|
@@ -691,9 +709,9 @@ export const TableBlock = defineComponent<TableBlockProps>({
|
|
|
691
709
|
) : undefined}
|
|
692
710
|
<button
|
|
693
711
|
type="button"
|
|
694
|
-
onPointerdown={(
|
|
712
|
+
onPointerdown={() => {
|
|
695
713
|
hoverIndex.value = [i, 0]
|
|
696
|
-
|
|
714
|
+
deleteRowByIndex(i)
|
|
697
715
|
}}
|
|
698
716
|
>
|
|
699
717
|
<Icon icon={config.renderButton('delete_row')} />
|
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
TableMap,
|
|
18
18
|
type TableRect,
|
|
19
19
|
addColumn,
|
|
20
|
+
removeRow,
|
|
21
|
+
removeColumn,
|
|
20
22
|
} from '@jvs-milkdown/prose/tables'
|
|
21
23
|
|
|
22
24
|
import type { Refs } from './types'
|
|
@@ -116,6 +118,64 @@ export function useOperation(
|
|
|
116
118
|
})
|
|
117
119
|
}
|
|
118
120
|
|
|
121
|
+
const deleteRowByIndex = (index: number) => {
|
|
122
|
+
if (!ctx || !ctx.get(editorViewCtx).editable) return
|
|
123
|
+
const view = ctx.get(editorViewCtx)
|
|
124
|
+
const tablePos = getPos?.()
|
|
125
|
+
if (tablePos == null) return
|
|
126
|
+
|
|
127
|
+
const table = view.state.doc.nodeAt(tablePos)
|
|
128
|
+
if (!table) return
|
|
129
|
+
|
|
130
|
+
const tableStart = tablePos + 1
|
|
131
|
+
const map = TableMap.get(table)
|
|
132
|
+
const tr = view.state.tr
|
|
133
|
+
const rect: TableRect = {
|
|
134
|
+
map,
|
|
135
|
+
tableStart,
|
|
136
|
+
table,
|
|
137
|
+
left: 0,
|
|
138
|
+
right: map.width,
|
|
139
|
+
top: 0,
|
|
140
|
+
bottom: map.height,
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
removeRow(tr, rect, index)
|
|
144
|
+
view.dispatch(tr)
|
|
145
|
+
requestAnimationFrame(() => {
|
|
146
|
+
ctx.get(editorViewCtx).focus()
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const deleteColByIndex = (index: number) => {
|
|
151
|
+
if (!ctx || !ctx.get(editorViewCtx).editable) return
|
|
152
|
+
const view = ctx.get(editorViewCtx)
|
|
153
|
+
const tablePos = getPos?.()
|
|
154
|
+
if (tablePos == null) return
|
|
155
|
+
|
|
156
|
+
const table = view.state.doc.nodeAt(tablePos)
|
|
157
|
+
if (!table) return
|
|
158
|
+
|
|
159
|
+
const tableStart = tablePos + 1
|
|
160
|
+
const map = TableMap.get(table)
|
|
161
|
+
const tr = view.state.tr
|
|
162
|
+
const rect: TableRect = {
|
|
163
|
+
map,
|
|
164
|
+
tableStart,
|
|
165
|
+
table,
|
|
166
|
+
left: 0,
|
|
167
|
+
right: map.width,
|
|
168
|
+
top: 0,
|
|
169
|
+
bottom: map.height,
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
removeColumn(tr, rect, index)
|
|
173
|
+
view.dispatch(tr)
|
|
174
|
+
requestAnimationFrame(() => {
|
|
175
|
+
ctx.get(editorViewCtx).focus()
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
119
179
|
const onAlign =
|
|
120
180
|
(direction: 'left' | 'center' | 'right') => (e: PointerEvent) => {
|
|
121
181
|
if (!ctx) return
|
|
@@ -225,6 +285,8 @@ export function useOperation(
|
|
|
225
285
|
selectCol,
|
|
226
286
|
selectRow,
|
|
227
287
|
deleteSelected,
|
|
288
|
+
deleteRowByIndex,
|
|
289
|
+
deleteColByIndex,
|
|
228
290
|
onAlign,
|
|
229
291
|
onMergeCells,
|
|
230
292
|
onSplitCell,
|
|
@@ -3,7 +3,8 @@ import type { EditorView } from '@jvs-milkdown/prose/view'
|
|
|
3
3
|
import type { Ref } from 'vue'
|
|
4
4
|
|
|
5
5
|
import { findParent } from '@jvs-milkdown/prose'
|
|
6
|
-
import {
|
|
6
|
+
import { findTable } from '@jvs-milkdown/prose/tables'
|
|
7
|
+
import type { CellSelection } from '@jvs-milkdown/prose/tables'
|
|
7
8
|
|
|
8
9
|
import type { CellIndex, Refs } from './types'
|
|
9
10
|
|
|
@@ -99,13 +100,13 @@ export function recoveryStateBetweenUpdate(
|
|
|
99
100
|
const table = findTable($from)
|
|
100
101
|
if (!table || table.node !== node) return
|
|
101
102
|
|
|
102
|
-
if (selection.isColSelection()) {
|
|
103
|
+
if ((selection as any as CellSelection).isColSelection()) {
|
|
103
104
|
const { $head } = selection
|
|
104
105
|
const colIndex = $head.index($head.depth - 1)
|
|
105
106
|
refs.hoverIndex.value = [0, colIndex]
|
|
106
107
|
return
|
|
107
108
|
}
|
|
108
|
-
if (selection.isRowSelection()) {
|
|
109
|
+
if ((selection as any as CellSelection).isRowSelection()) {
|
|
109
110
|
const { $head } = selection
|
|
110
111
|
const rowNode = findParent(
|
|
111
112
|
(node) =>
|