@milkdown/crepe 7.21.0 → 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.
Files changed (40) hide show
  1. package/lib/cjs/feature/latex/index.js +1 -0
  2. package/lib/cjs/feature/latex/index.js.map +1 -1
  3. package/lib/cjs/feature/toolbar/index.js +5 -89
  4. package/lib/cjs/feature/toolbar/index.js.map +1 -1
  5. package/lib/cjs/index.js +5 -5
  6. package/lib/cjs/index.js.map +1 -1
  7. package/lib/cjs/llm-providers/anthropic/index.js +6 -1
  8. package/lib/cjs/llm-providers/anthropic/index.js.map +1 -1
  9. package/lib/cjs/llm-providers/openai/index.js +6 -1
  10. package/lib/cjs/llm-providers/openai/index.js.map +1 -1
  11. package/lib/esm/feature/latex/index.js +1 -0
  12. package/lib/esm/feature/latex/index.js.map +1 -1
  13. package/lib/esm/feature/toolbar/index.js +8 -92
  14. package/lib/esm/feature/toolbar/index.js.map +1 -1
  15. package/lib/esm/index.js +6 -6
  16. package/lib/esm/index.js.map +1 -1
  17. package/lib/esm/llm-providers/anthropic/index.js +6 -1
  18. package/lib/esm/llm-providers/anthropic/index.js.map +1 -1
  19. package/lib/esm/llm-providers/openai/index.js +6 -1
  20. package/lib/esm/llm-providers/openai/index.js.map +1 -1
  21. package/lib/tsconfig.tsbuildinfo +1 -1
  22. package/lib/types/feature/latex/constants.d.ts +3 -0
  23. package/lib/types/feature/latex/constants.d.ts.map +1 -0
  24. package/lib/types/feature/latex/inline-latex.d.ts +2 -1
  25. package/lib/types/feature/latex/inline-latex.d.ts.map +1 -1
  26. package/lib/types/feature/link-tooltip/link-tooltip.spec.d.ts +2 -0
  27. package/lib/types/feature/link-tooltip/link-tooltip.spec.d.ts.map +1 -0
  28. package/lib/types/feature/toolbar/config.d.ts.map +1 -1
  29. package/lib/types/llm-providers/anthropic/index.d.ts.map +1 -1
  30. package/lib/types/llm-providers/openai/index.d.ts.map +1 -1
  31. package/lib/types/llm-providers/shared.d.ts +1 -0
  32. package/lib/types/llm-providers/shared.d.ts.map +1 -1
  33. package/package.json +3 -3
  34. package/src/feature/latex/constants.ts +3 -0
  35. package/src/feature/latex/inline-latex.ts +3 -1
  36. package/src/feature/link-tooltip/link-tooltip.spec.ts +132 -0
  37. package/src/feature/toolbar/config.ts +5 -8
  38. package/src/llm-providers/anthropic/index.ts +2 -1
  39. package/src/llm-providers/openai/index.ts +2 -1
  40. package/src/llm-providers/shared.ts +10 -0
@@ -0,0 +1,3 @@
1
+ export declare const mathInlineId = "math_inline";
2
+ export declare const toggleLatexCommandName = "ToggleLatex";
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -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,3 +1,4 @@
1
- export declare const mathInlineId = "math_inline";
1
+ import { mathInlineId } from './constants';
2
+ export { mathInlineId };
2
3
  export declare const mathInlineSchema: import("@milkdown/utils").$NodeSchema<"math_inline">;
3
4
  //# sourceMappingURL=inline-latex.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"inline-latex.d.ts","sourceRoot":"","sources":["../../../../src/feature/latex/inline-latex.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,gBAAgB,CAAA;AAQzC,eAAO,MAAM,gBAAgB,sDA2C1B,CAAA"}
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,2 @@
1
+ import '@testing-library/jest-dom/vitest';
2
+ //# sourceMappingURL=link-tooltip.spec.d.ts.map
@@ -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;AAmB7C,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;;;;;;;;IAqHjE"}
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/llm-providers/anthropic/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEzE,OAAO,EACL,KAAK,kBAAkB,EAMxB,M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E,CACd,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,KAC3D,4BAA4B,CAAA;IAIjC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAaD,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,uBAAuB,GAC9B,UAAU,CAsEZ"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/llm-providers/openai/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEzE,OAAO,EACL,KAAK,kBAAkB,EAMxB,MAAM,WAAW,CAAA;AAKlB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAA;IACrC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAM9D,aAAa,CAAC,EAAE,CACd,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,KAC3D,iBAAiB,EAAE,CAAA;IAIxB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAYD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,UAAU,CAkD7E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/llm-providers/openai/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEzE,OAAO,EACL,KAAK,kBAAkB,EAOxB,MAAM,WAAW,CAAA;AAKlB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAA;IACrC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAM9D,aAAa,CAAC,EAAE,CACd,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,KAC3D,iBAAiB,EAAE,CAAA;IAIxB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAYD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,UAAU,CAkD7E"}
@@ -11,6 +11,7 @@ export interface BaseProviderConfig {
11
11
  }
12
12
  export declare function assertBrowserSafe(config: BaseProviderConfig, providerName: string): void;
13
13
  export declare function resolveSystemPrompt(systemPrompt: string | null | undefined): string | null;
14
+ export declare function stripTrailingSlashes(url: string): string;
14
15
  export declare function parseSSE(response: Response, signal: AbortSignal): AsyncGenerator<string>;
15
16
  export declare function readErrorBody(response: Response, providerName: string): Promise<Error>;
16
17
  //# sourceMappingURL=shared.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/llm-providers/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAK1D,eAAO,MAAM,qBAAqB,mpBAOgF,CAAA;AAIlH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAOxE;AAGD,MAAM,WAAW,kBAAkB;IAGjC,MAAM,CAAC,EAAE,MAAM,CAAA;IAKf,OAAO,CAAC,EAAE,MAAM,CAAA;IAIhB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAGhC,KAAK,EAAE,MAAM,CAAA;IAKb,YAAY,CAAC,EAAE,MAAM,GA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B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIxD;AAMD,wBAAuB,QAAQ,CAC7B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,WAAW,GAClB,cAAc,CAAC,MAAM,CAAC,CAkCxB;AAID,wBAAsB,aAAa,CACjC,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,KAAK,CAAC,CAWhB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milkdown/crepe",
3
- "version": "7.21.0",
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.16.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.0"
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,3 @@
1
+ export const mathInlineId = 'math_inline'
2
+
3
+ export const toggleLatexCommandName = 'ToggleLatex'
@@ -1,7 +1,9 @@
1
1
  import { $nodeSchema } from '@milkdown/kit/utils'
2
2
  import katex from 'katex'
3
3
 
4
- export const mathInlineId = 'math_inline'
4
+ import { mathInlineId } from './constants'
5
+
6
+ export { mathInlineId }
5
7
 
6
8
  /// Schema for inline math node.
7
9
  /// Add support for:
@@ -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 { toggleLatexCommand } from '../latex/command'
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
- return commands.call(
114
- isNodeSelectedCommand.key,
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(toggleLatexCommand.key)
117
+ commands.call(toggleLatexCommandName)
121
118
  },
122
119
  })
123
120
  }
@@ -7,6 +7,7 @@ import {
7
7
  parseSSE,
8
8
  readErrorBody,
9
9
  resolveSystemPrompt,
10
+ stripTrailingSlashes,
10
11
  } from '../shared'
11
12
 
12
13
  const PROVIDER_NAME = 'milkdown/providers/anthropic'
@@ -75,7 +76,7 @@ export function createAnthropicProvider(
75
76
  ] satisfies AnthropicMessage[],
76
77
  }
77
78
 
78
- const baseURL = (config.baseURL ?? DEFAULT_BASE_URL).replace(/\/+$/, '')
79
+ const baseURL = stripTrailingSlashes(config.baseURL ?? DEFAULT_BASE_URL)
79
80
  const url = `${baseURL}/v1/messages`
80
81
 
81
82
  const headers: Record<string, string> = {
@@ -7,6 +7,7 @@ import {
7
7
  parseSSE,
8
8
  readErrorBody,
9
9
  resolveSystemPrompt,
10
+ stripTrailingSlashes,
10
11
  } from '../shared'
11
12
 
12
13
  const PROVIDER_NAME = 'milkdown/providers/openai'
@@ -54,7 +55,7 @@ export function createOpenAIProvider(config: OpenAIProviderConfig): AIProvider {
54
55
  ? config.buildMessages(context, { systemPrompt, userMessage })
55
56
  : defaultMessages(systemPrompt, userMessage)
56
57
 
57
- const baseURL = (config.baseURL ?? DEFAULT_BASE_URL).replace(/\/+$/, '')
58
+ const baseURL = stripTrailingSlashes(config.baseURL ?? DEFAULT_BASE_URL)
58
59
  const url = `${baseURL}/v1/chat/completions`
59
60
 
60
61
  const headers: Record<string, string> = {
@@ -98,6 +98,16 @@ export function resolveSystemPrompt(
98
98
  return systemPrompt ?? DEFAULT_SYSTEM_PROMPT
99
99
  }
100
100
 
101
+ /// Strip trailing `/` characters from a URL. Uses a linear scan instead
102
+ /// of a regex like `/\/+$/` because the latter backtracks quadratically
103
+ /// on caller-supplied input ending in many slashes followed by a
104
+ /// non-slash (CodeQL js/polynomial-redos).
105
+ export function stripTrailingSlashes(url: string): string {
106
+ let end = url.length
107
+ while (end > 0 && url.charCodeAt(end - 1) === 47 /* '/' */) end--
108
+ return end === url.length ? url : url.slice(0, end)
109
+ }
110
+
101
111
  /// Parse an SSE stream from `response.body`. Yields the payload after
102
112
  /// `data: ` for each event; ignores `event:`, `id:`, `retry:`, and
103
113
  /// comment lines. Stops cleanly when the signal aborts or the stream