@milkdown/crepe 7.21.1 → 7.21.2
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/cjs/feature/latex/index.js +1 -0
- package/lib/cjs/feature/latex/index.js.map +1 -1
- package/lib/cjs/feature/toolbar/index.js +5 -89
- package/lib/cjs/feature/toolbar/index.js.map +1 -1
- package/lib/cjs/index.js +5 -5
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/feature/latex/index.js +1 -0
- package/lib/esm/feature/latex/index.js.map +1 -1
- package/lib/esm/feature/toolbar/index.js +8 -92
- package/lib/esm/feature/toolbar/index.js.map +1 -1
- package/lib/esm/index.js +6 -6
- package/lib/esm/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/feature/latex/constants.d.ts +3 -0
- package/lib/types/feature/latex/constants.d.ts.map +1 -0
- package/lib/types/feature/latex/inline-latex.d.ts +2 -1
- package/lib/types/feature/latex/inline-latex.d.ts.map +1 -1
- package/lib/types/feature/link-tooltip/link-tooltip.spec.d.ts +2 -0
- package/lib/types/feature/link-tooltip/link-tooltip.spec.d.ts.map +1 -0
- package/lib/types/feature/toolbar/config.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/feature/latex/constants.ts +3 -0
- package/src/feature/latex/inline-latex.ts +3 -1
- package/src/feature/link-tooltip/link-tooltip.spec.ts +132 -0
- package/src/feature/toolbar/config.ts +5 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/feature/latex/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,gBAAgB,CAAA;AAEzC,eAAO,MAAM,sBAAsB,gBAAgB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline-latex.d.ts","sourceRoot":"","sources":["../../../../src/feature/latex/inline-latex.ts"],"names":[],"mappings":"AAGA,
|
|
1
|
+
{"version":3,"file":"inline-latex.d.ts","sourceRoot":"","sources":["../../../../src/feature/latex/inline-latex.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,EAAE,YAAY,EAAE,CAAA;AAQvB,eAAO,MAAM,gBAAgB,sDA2C1B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link-tooltip.spec.d.ts","sourceRoot":"","sources":["../../../../src/feature/link-tooltip/link-tooltip.spec.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/feature/toolbar/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAoB5C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,GAAG,CAAA;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/feature/toolbar/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAoB5C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,GAAG,CAAA;AAkB7C,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAA;IAC7B,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,wBAAgB,SAAS,CAAC,MAAM,CAAC,EAAE,oBAAoB,EAAE,GAAG,CAAC,EAAE,GAAG;;;;;;;;IAmHjE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/crepe",
|
|
3
|
-
"version": "7.21.
|
|
3
|
+
"version": "7.21.2",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"crepe",
|
|
6
6
|
"editor",
|
|
@@ -120,13 +120,13 @@
|
|
|
120
120
|
"clsx": "^2.0.0",
|
|
121
121
|
"codemirror": "^6.0.1",
|
|
122
122
|
"dompurify": "^3.2.5",
|
|
123
|
-
"katex": "^0.
|
|
123
|
+
"katex": "^0.17.0",
|
|
124
124
|
"lodash-es": "^4.17.21",
|
|
125
125
|
"prosemirror-virtual-cursor": "^0.4.2",
|
|
126
126
|
"remark-math": "^6.0.0",
|
|
127
127
|
"unist-util-visit": "^5.0.0",
|
|
128
128
|
"vue": "^3.5.20",
|
|
129
|
-
"@milkdown/kit": "7.21.
|
|
129
|
+
"@milkdown/kit": "7.21.2"
|
|
130
130
|
},
|
|
131
131
|
"scripts": {
|
|
132
132
|
"build": "pnpm run build:es && pnpm run build:theme && echo",
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/vitest'
|
|
2
|
+
import { linkTooltipAPI } from '@milkdown/kit/component/link-tooltip'
|
|
3
|
+
import { editorViewCtx } from '@milkdown/kit/core'
|
|
4
|
+
import { linkSchema } from '@milkdown/kit/preset/commonmark'
|
|
5
|
+
import { afterEach, describe, expect, test } from 'vitest'
|
|
6
|
+
|
|
7
|
+
import { Crepe } from '../../core'
|
|
8
|
+
import { CrepeFeature } from '../index'
|
|
9
|
+
|
|
10
|
+
function waitForAsync() {
|
|
11
|
+
return new Promise<void>((resolve) => setTimeout(resolve, 0))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getEditTooltip() {
|
|
15
|
+
return document.body.querySelector<HTMLElement>('.milkdown-link-edit')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function createCrepe(defaultValue: string) {
|
|
19
|
+
// Disable Cursor feature: prosemirror-virtual-cursor uses Range.getClientRects
|
|
20
|
+
// which jsdom does not implement.
|
|
21
|
+
return new Crepe({
|
|
22
|
+
defaultValue,
|
|
23
|
+
features: {
|
|
24
|
+
[CrepeFeature.Cursor]: false,
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe('link tooltip edit', () => {
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
document.body.replaceChildren()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('inserts URL as linked text when selection is empty', async () => {
|
|
35
|
+
const crepe = createCrepe('hello')
|
|
36
|
+
|
|
37
|
+
await crepe.create()
|
|
38
|
+
await waitForAsync()
|
|
39
|
+
|
|
40
|
+
// Cursor between "h" and "ello" — empty selection.
|
|
41
|
+
const cursorPos = 2
|
|
42
|
+
crepe.editor.ctx.get(linkTooltipAPI.key).addLink(cursorPos, cursorPos)
|
|
43
|
+
await waitForAsync()
|
|
44
|
+
|
|
45
|
+
const tooltip = getEditTooltip()
|
|
46
|
+
expect(tooltip).toHaveAttribute('data-show', 'true')
|
|
47
|
+
|
|
48
|
+
const input = tooltip!.querySelector('input') as HTMLInputElement
|
|
49
|
+
input.value = 'https://example.com'
|
|
50
|
+
input.dispatchEvent(new Event('input', { bubbles: true }))
|
|
51
|
+
input.dispatchEvent(
|
|
52
|
+
new KeyboardEvent('keydown', { key: 'Enter', bubbles: true })
|
|
53
|
+
)
|
|
54
|
+
await waitForAsync()
|
|
55
|
+
|
|
56
|
+
const linkType = linkSchema.type(crepe.editor.ctx)
|
|
57
|
+
const updated = crepe.editor.ctx.get(editorViewCtx).state.doc
|
|
58
|
+
let foundHref: string | null = null
|
|
59
|
+
let linkedText = ''
|
|
60
|
+
updated.descendants((node) => {
|
|
61
|
+
const linkMark = node.marks.find((m) => m.type === linkType)
|
|
62
|
+
if (linkMark) {
|
|
63
|
+
foundHref = linkMark.attrs.href
|
|
64
|
+
linkedText = node.text ?? ''
|
|
65
|
+
}
|
|
66
|
+
return true
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
expect(foundHref).toBe('https://example.com')
|
|
70
|
+
expect(linkedText).toBe('https://example.com')
|
|
71
|
+
expect(getEditTooltip()).toHaveAttribute('data-show', 'false')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('does nothing when confirming an empty URL on empty selection', async () => {
|
|
75
|
+
const crepe = createCrepe('hello')
|
|
76
|
+
|
|
77
|
+
await crepe.create()
|
|
78
|
+
await waitForAsync()
|
|
79
|
+
|
|
80
|
+
const before = crepe.editor.ctx.get(editorViewCtx).state.doc.toJSON()
|
|
81
|
+
crepe.editor.ctx.get(linkTooltipAPI.key).addLink(2, 2)
|
|
82
|
+
await waitForAsync()
|
|
83
|
+
|
|
84
|
+
const input = getEditTooltip()!.querySelector('input') as HTMLInputElement
|
|
85
|
+
input.dispatchEvent(
|
|
86
|
+
new KeyboardEvent('keydown', { key: 'Enter', bubbles: true })
|
|
87
|
+
)
|
|
88
|
+
await waitForAsync()
|
|
89
|
+
|
|
90
|
+
const after = crepe.editor.ctx.get(editorViewCtx).state.doc.toJSON()
|
|
91
|
+
expect(after).toEqual(before)
|
|
92
|
+
expect(getEditTooltip()).toHaveAttribute('data-show', 'false')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test('closes the edit tooltip when clicking outside', async () => {
|
|
96
|
+
const crepe = createCrepe('hello world')
|
|
97
|
+
|
|
98
|
+
await crepe.create()
|
|
99
|
+
await waitForAsync()
|
|
100
|
+
|
|
101
|
+
crepe.editor.ctx.get(linkTooltipAPI.key).addLink(1, 6)
|
|
102
|
+
await waitForAsync()
|
|
103
|
+
|
|
104
|
+
expect(getEditTooltip()).toHaveAttribute('data-show', 'true')
|
|
105
|
+
|
|
106
|
+
const outside = document.createElement('div')
|
|
107
|
+
document.body.appendChild(outside)
|
|
108
|
+
outside.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }))
|
|
109
|
+
await waitForAsync()
|
|
110
|
+
|
|
111
|
+
expect(getEditTooltip()).toHaveAttribute('data-show', 'false')
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
test('keeps the edit tooltip open when clicking inside it', async () => {
|
|
115
|
+
const crepe = createCrepe('hello world')
|
|
116
|
+
|
|
117
|
+
await crepe.create()
|
|
118
|
+
await waitForAsync()
|
|
119
|
+
|
|
120
|
+
crepe.editor.ctx.get(linkTooltipAPI.key).addLink(1, 6)
|
|
121
|
+
await waitForAsync()
|
|
122
|
+
|
|
123
|
+
const tooltip = getEditTooltip()!
|
|
124
|
+
expect(tooltip).toHaveAttribute('data-show', 'true')
|
|
125
|
+
|
|
126
|
+
const input = tooltip.querySelector('input') as HTMLInputElement
|
|
127
|
+
input.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }))
|
|
128
|
+
await waitForAsync()
|
|
129
|
+
|
|
130
|
+
expect(getEditTooltip()).toHaveAttribute('data-show', 'true')
|
|
131
|
+
})
|
|
132
|
+
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Ctx } from '@milkdown/kit/ctx'
|
|
2
2
|
|
|
3
3
|
import { toggleLinkCommand } from '@milkdown/kit/component/link-tooltip'
|
|
4
|
-
import { commandsCtx, editorViewCtx } from '@milkdown/kit/core'
|
|
4
|
+
import { commandsCtx, editorViewCtx, schemaCtx } from '@milkdown/kit/core'
|
|
5
5
|
import {
|
|
6
6
|
emphasisSchema,
|
|
7
7
|
inlineCodeSchema,
|
|
@@ -34,8 +34,7 @@ import {
|
|
|
34
34
|
import { GroupBuilder } from '../../utils/group-builder'
|
|
35
35
|
import { aiProviderConfig } from '../ai/commands'
|
|
36
36
|
import { aiInstructionTooltipAPI } from '../ai/instruction-tooltip'
|
|
37
|
-
import {
|
|
38
|
-
import { mathInlineSchema } from '../latex/inline-latex'
|
|
37
|
+
import { mathInlineId, toggleLatexCommandName } from '../latex/constants'
|
|
39
38
|
|
|
40
39
|
export type ToolbarItem = {
|
|
41
40
|
active: (ctx: Ctx) => boolean
|
|
@@ -110,14 +109,12 @@ export function getGroups(config?: ToolbarFeatureConfig, ctx?: Ctx) {
|
|
|
110
109
|
icon: config?.latexIcon ?? functionsIcon,
|
|
111
110
|
active: (ctx) => {
|
|
112
111
|
const commands = ctx.get(commandsCtx)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
mathInlineSchema.type(ctx)
|
|
116
|
-
)
|
|
112
|
+
const nodeType = ctx.get(schemaCtx).nodes[mathInlineId]
|
|
113
|
+
return commands.call(isNodeSelectedCommand.key, nodeType)
|
|
117
114
|
},
|
|
118
115
|
onRun: (ctx) => {
|
|
119
116
|
const commands = ctx.get(commandsCtx)
|
|
120
|
-
commands.call(
|
|
117
|
+
commands.call(toggleLatexCommandName)
|
|
121
118
|
},
|
|
122
119
|
})
|
|
123
120
|
}
|