@jvs-milkdown/crepe 1.2.5 → 1.2.7
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/builder.js +2 -0
- package/lib/cjs/builder.js.map +1 -1
- package/lib/cjs/feature/block-edit/index.js +6 -2
- package/lib/cjs/feature/block-edit/index.js.map +1 -1
- package/lib/cjs/feature/code-mirror/index.js +2 -0
- package/lib/cjs/feature/code-mirror/index.js.map +1 -1
- package/lib/cjs/feature/cursor/index.js +2 -0
- package/lib/cjs/feature/cursor/index.js.map +1 -1
- package/lib/cjs/feature/image-block/index.js +3 -4
- package/lib/cjs/feature/image-block/index.js.map +1 -1
- package/lib/cjs/feature/latex/index.js +2 -0
- package/lib/cjs/feature/latex/index.js.map +1 -1
- package/lib/cjs/feature/link-tooltip/index.js +2 -0
- package/lib/cjs/feature/link-tooltip/index.js.map +1 -1
- package/lib/cjs/feature/list-item/index.js +2 -0
- package/lib/cjs/feature/list-item/index.js.map +1 -1
- package/lib/cjs/feature/placeholder/index.js +4 -1
- package/lib/cjs/feature/placeholder/index.js.map +1 -1
- package/lib/cjs/feature/table/index.js +2 -0
- package/lib/cjs/feature/table/index.js.map +1 -1
- package/lib/cjs/feature/toolbar/index.js +242 -7
- package/lib/cjs/feature/toolbar/index.js.map +1 -1
- package/lib/cjs/index.js +1238 -962
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/builder.js +2 -0
- package/lib/esm/builder.js.map +1 -1
- package/lib/esm/feature/block-edit/index.js +6 -2
- package/lib/esm/feature/block-edit/index.js.map +1 -1
- package/lib/esm/feature/code-mirror/index.js +2 -0
- package/lib/esm/feature/code-mirror/index.js.map +1 -1
- package/lib/esm/feature/cursor/index.js +2 -0
- package/lib/esm/feature/cursor/index.js.map +1 -1
- package/lib/esm/feature/image-block/index.js +3 -4
- package/lib/esm/feature/image-block/index.js.map +1 -1
- package/lib/esm/feature/latex/index.js +2 -0
- package/lib/esm/feature/latex/index.js.map +1 -1
- package/lib/esm/feature/link-tooltip/index.js +2 -0
- package/lib/esm/feature/link-tooltip/index.js.map +1 -1
- package/lib/esm/feature/list-item/index.js +2 -0
- package/lib/esm/feature/list-item/index.js.map +1 -1
- package/lib/esm/feature/placeholder/index.js +4 -1
- package/lib/esm/feature/placeholder/index.js.map +1 -1
- package/lib/esm/feature/table/index.js +2 -0
- package/lib/esm/feature/table/index.js.map +1 -1
- package/lib/esm/feature/toolbar/index.js +242 -7
- package/lib/esm/feature/toolbar/index.js.map +1 -1
- package/lib/esm/index.js +1251 -975
- package/lib/esm/index.js.map +1 -1
- package/lib/theme/common/table.css +11 -7
- package/lib/theme/common/toolbar.css +6 -6
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/core/locale.d.ts +2 -0
- package/lib/types/core/locale.d.ts.map +1 -1
- package/lib/types/feature/attachment/view/components/attachment-block.d.ts.map +1 -1
- package/lib/types/feature/attachment/view/index.d.ts.map +1 -1
- package/lib/types/feature/block-edit/handle/component.d.ts.map +1 -1
- package/lib/types/feature/block-edit/handle/index.d.ts.map +1 -1
- package/lib/types/feature/block-edit/index.d.ts.map +1 -1
- package/lib/types/feature/block-edit/menu/api.d.ts.map +1 -1
- package/lib/types/feature/block-edit/menu/component.d.ts.map +1 -1
- package/lib/types/feature/block-edit/menu/index.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/component.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/config.d.ts +9 -1
- package/lib/types/feature/fixed-toolbar/config.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/document-header.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/index.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/menu-bar.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/outline-panel.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/shortcut-help-modal.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/view-menu-state.d.ts.map +1 -1
- package/lib/types/feature/index.d.ts +1 -1
- package/lib/types/feature/index.d.ts.map +1 -1
- package/lib/types/feature/latex/inline-tooltip/component.d.ts.map +1 -1
- package/lib/types/feature/latex/inline-tooltip/view.d.ts.map +1 -1
- package/lib/types/feature/loader.d.ts.map +1 -1
- package/lib/types/feature/placeholder/index.d.ts.map +1 -1
- package/lib/types/feature/toolbar/color.d.ts +1 -1
- package/lib/types/feature/toolbar/color.d.ts.map +1 -1
- package/lib/types/feature/toolbar/component.d.ts.map +1 -1
- package/lib/types/feature/toolbar/font.d.ts +1 -1
- package/lib/types/feature/toolbar/highlight-mark.d.ts +1 -1
- package/lib/types/feature/toolbar/index.d.ts.map +1 -1
- package/lib/types/feature/toolbar/underline.d.ts +1 -1
- package/lib/types/icons/crop.d.ts +1 -1
- package/lib/types/icons/crop.d.ts.map +1 -1
- package/lib/types/icons/format-painter.d.ts +2 -0
- package/lib/types/icons/format-painter.d.ts.map +1 -0
- package/lib/types/icons/index.d.ts +1 -0
- package/lib/types/icons/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/core/locale.ts +2 -0
- package/src/feature/attachment/view/components/attachment-block.tsx +12 -7
- package/src/feature/attachment/view/index.ts +1 -0
- package/src/feature/block-edit/handle/component.tsx +5 -4
- package/src/feature/block-edit/handle/index.ts +1 -0
- package/src/feature/block-edit/index.ts +4 -1
- package/src/feature/block-edit/menu/api.ts +6 -1
- package/src/feature/block-edit/menu/component.tsx +49 -46
- package/src/feature/block-edit/menu/index.ts +1 -0
- package/src/feature/fixed-toolbar/component.tsx +3 -2
- package/src/feature/fixed-toolbar/config.ts +198 -146
- package/src/feature/fixed-toolbar/document-header.tsx +22 -12
- package/src/feature/fixed-toolbar/index.ts +2 -1
- package/src/feature/fixed-toolbar/menu-bar.tsx +15 -10
- package/src/feature/fixed-toolbar/outline-panel.tsx +17 -16
- package/src/feature/fixed-toolbar/shortcut-help-modal.tsx +3 -2
- package/src/feature/fixed-toolbar/view-menu-state.ts +1 -0
- package/src/feature/index.ts +1 -1
- package/src/feature/latex/inline-tooltip/component.tsx +3 -2
- package/src/feature/latex/inline-tooltip/view.ts +1 -0
- package/src/feature/loader.ts +1 -1
- package/src/feature/placeholder/index.ts +2 -1
- package/src/feature/toolbar/color.ts +77 -73
- package/src/feature/toolbar/component.tsx +321 -35
- package/src/feature/toolbar/index.ts +1 -0
- package/src/icons/align-center.ts +1 -1
- package/src/icons/bold.ts +1 -1
- package/src/icons/bullet-list.ts +1 -1
- package/src/icons/crop.ts +1 -4
- package/src/icons/divider.ts +1 -1
- package/src/icons/format-painter.ts +5 -0
- package/src/icons/h2.ts +1 -1
- package/src/icons/index.ts +1 -0
- package/src/icons/ordered-list.ts +1 -1
- package/src/icons/quote.ts +1 -1
- package/src/icons/strikethrough.ts +1 -1
- package/src/icons/text.ts +0 -1
- package/src/theme/common/table.css +11 -7
- package/src/theme/common/toolbar.css +6 -6
- package/src/feature/table/test.ts +0 -9
|
@@ -2,6 +2,7 @@ import type { Ctx } from '@jvs-milkdown/kit/ctx'
|
|
|
2
2
|
import type { Node as ProseNode } from '@jvs-milkdown/kit/prose/model'
|
|
3
3
|
|
|
4
4
|
import { imageBlockSchema } from '@jvs-milkdown/kit/component/image-block'
|
|
5
|
+
import { toggleLinkCommand } from '@jvs-milkdown/kit/component/link-tooltip'
|
|
5
6
|
import { commandsCtx, editorViewCtx } from '@jvs-milkdown/kit/core'
|
|
6
7
|
import {
|
|
7
8
|
addBlockTypeCommand,
|
|
@@ -19,6 +20,10 @@ import {
|
|
|
19
20
|
setBlockTypeCommand,
|
|
20
21
|
selectTextNearPosCommand,
|
|
21
22
|
liftListItemCommand,
|
|
23
|
+
inlineCodeSchema,
|
|
24
|
+
isMarkSelectedCommand,
|
|
25
|
+
linkSchema,
|
|
26
|
+
toggleInlineCodeCommand,
|
|
22
27
|
} from '@jvs-milkdown/kit/preset/commonmark'
|
|
23
28
|
import { createTable } from '@jvs-milkdown/kit/preset/gfm'
|
|
24
29
|
import { findNodeInSelection } from '@jvs-milkdown/kit/prose'
|
|
@@ -42,10 +47,17 @@ import {
|
|
|
42
47
|
codeIcon,
|
|
43
48
|
tableIcon,
|
|
44
49
|
functionsIcon,
|
|
50
|
+
highLineCodeIcon,
|
|
51
|
+
linCodeIcon,
|
|
52
|
+
linkIcon,
|
|
45
53
|
} from '../../icons'
|
|
46
54
|
import { attachmentSchema } from '../attachment/schema'
|
|
47
55
|
import { CrepeFeature } from '../index'
|
|
48
56
|
import { toggleLatexCommand } from '../latex/command'
|
|
57
|
+
import {
|
|
58
|
+
toggleHighlightMarkCommand,
|
|
59
|
+
highlightMarkSchema,
|
|
60
|
+
} from '../toolbar/highlight-mark'
|
|
49
61
|
|
|
50
62
|
/**
|
|
51
63
|
* Convert any headings in the selection to paragraphs before wrapping in a list.
|
|
@@ -79,151 +91,10 @@ export function buildDefaultFixedToolbar(
|
|
|
79
91
|
const isLatexEnabled = flags?.includes(CrepeFeature.Latex)
|
|
80
92
|
const isImageBlockEnabled = flags?.includes(CrepeFeature.ImageBlock)
|
|
81
93
|
const isTableEnabled = flags?.includes(CrepeFeature.Table)
|
|
82
|
-
|
|
83
|
-
const hasFunctionGroup = builder.build().some((g) => g.key === 'function')
|
|
84
|
-
const embedGroup = hasFunctionGroup
|
|
85
|
-
? builder.getGroup('function')
|
|
86
|
-
: builder.addGroup('embed', 'Embed')
|
|
87
|
-
if (isImageBlockEnabled) {
|
|
88
|
-
embedGroup.addItem('image', {
|
|
89
|
-
label: ctx ? i18n(ctx, 'menu.item.image') : 'Image',
|
|
90
|
-
icon: imageIcon,
|
|
91
|
-
active: () => false,
|
|
92
|
-
onRun: (ctx) => {
|
|
93
|
-
const commands = ctx.get(commandsCtx)
|
|
94
|
-
commands.call(addBlockTypeCommand.key, {
|
|
95
|
-
nodeType: imageBlockSchema.type(ctx),
|
|
96
|
-
})
|
|
97
|
-
},
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
|
|
101
94
|
const isAttachmentEnabled = flags?.includes(CrepeFeature.Attachment)
|
|
102
|
-
if (isAttachmentEnabled) {
|
|
103
|
-
embedGroup.addItem('attachment', {
|
|
104
|
-
label: ctx ? i18n(ctx, 'menu.item.attachment') : 'Video or File',
|
|
105
|
-
icon: fileLinkIcon,
|
|
106
|
-
active: () => false,
|
|
107
|
-
onRun: (ctx) => {
|
|
108
|
-
const commands = ctx.get(commandsCtx)
|
|
109
|
-
commands.call(addBlockTypeCommand.key, {
|
|
110
|
-
nodeType: attachmentSchema.type(ctx),
|
|
111
|
-
})
|
|
112
|
-
},
|
|
113
|
-
})
|
|
114
|
-
}
|
|
115
95
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
icon: codeIcon,
|
|
119
|
-
active: (ctx) => {
|
|
120
|
-
const view = ctx.get(editorViewCtx)
|
|
121
|
-
const result = findNodeInSelection(view.state, codeBlockSchema.type(ctx))
|
|
122
|
-
return result.hasNode && result.target?.attrs?.language !== 'LaTex'
|
|
123
|
-
},
|
|
124
|
-
onRun: (ctx) => {
|
|
125
|
-
const commands = ctx.get(commandsCtx)
|
|
126
|
-
const view = ctx.get(editorViewCtx)
|
|
127
|
-
const { state, dispatch } = view
|
|
128
|
-
const { selection, tr } = state
|
|
129
|
-
const { from, to } = selection
|
|
130
|
-
|
|
131
|
-
let text = ''
|
|
132
|
-
let blockCount = 0
|
|
133
|
-
|
|
134
|
-
state.doc.nodesBetween(from, to, (node) => {
|
|
135
|
-
if (node.isTextblock) {
|
|
136
|
-
text += (blockCount > 0 ? '\n' : '') + node.textContent
|
|
137
|
-
blockCount++
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
if (blockCount > 1) {
|
|
142
|
-
if (dispatch) {
|
|
143
|
-
const range = selection.$from.blockRange(selection.$to)
|
|
144
|
-
const codeBlock = codeBlockSchema
|
|
145
|
-
.type(ctx)
|
|
146
|
-
.createAndFill({}, text ? state.schema.text(text) : undefined)
|
|
147
|
-
if (range && codeBlock) {
|
|
148
|
-
tr.replaceWith(range.start, range.end, codeBlock)
|
|
149
|
-
dispatch(tr.scrollIntoView())
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
commands.call(setBlockTypeCommand.key, {
|
|
156
|
-
nodeType: codeBlockSchema.type(ctx),
|
|
157
|
-
})
|
|
158
|
-
},
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
if (isTableEnabled) {
|
|
162
|
-
embedGroup.addItem('table', {
|
|
163
|
-
label: ctx ? i18n(ctx, 'menu.item.table') : 'Table',
|
|
164
|
-
icon: tableIcon,
|
|
165
|
-
active: () => false,
|
|
166
|
-
onRun: (ctx) => {
|
|
167
|
-
const commands = ctx.get(commandsCtx)
|
|
168
|
-
const view = ctx.get(editorViewCtx)
|
|
169
|
-
const { from } = view.state.selection
|
|
170
|
-
commands.call(addBlockTypeCommand.key, {
|
|
171
|
-
nodeType: createTable(ctx, 3, 3),
|
|
172
|
-
})
|
|
173
|
-
commands.call(selectTextNearPosCommand.key, { pos: from })
|
|
174
|
-
},
|
|
175
|
-
})
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (isLatexEnabled) {
|
|
179
|
-
embedGroup.addItem('math-block', {
|
|
180
|
-
label: ctx ? i18n(ctx, 'menu.item.math') : 'Math Block',
|
|
181
|
-
icon: functionsIcon,
|
|
182
|
-
active: (ctx) => {
|
|
183
|
-
const view = ctx.get(editorViewCtx)
|
|
184
|
-
const result = findNodeInSelection(
|
|
185
|
-
view.state,
|
|
186
|
-
codeBlockSchema.type(ctx)
|
|
187
|
-
)
|
|
188
|
-
return result.hasNode && result.target?.attrs?.language === 'LaTex'
|
|
189
|
-
},
|
|
190
|
-
onRun: (ctx) => {
|
|
191
|
-
const commands = ctx.get(commandsCtx)
|
|
192
|
-
commands.call(toggleLatexCommand.key)
|
|
193
|
-
},
|
|
194
|
-
})
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const blockGroup = builder.addGroup('block', 'Block')
|
|
198
|
-
blockGroup
|
|
199
|
-
.addItem('quote', {
|
|
200
|
-
label: ctx ? i18n(ctx, 'menu.item.quote') : 'Quote',
|
|
201
|
-
icon: quoteIcon,
|
|
202
|
-
active: (ctx) => {
|
|
203
|
-
const view = ctx.get(editorViewCtx)
|
|
204
|
-
const result = findNodeInSelection(
|
|
205
|
-
view.state,
|
|
206
|
-
blockquoteSchema.type(ctx)
|
|
207
|
-
)
|
|
208
|
-
return result.hasNode
|
|
209
|
-
},
|
|
210
|
-
onRun: (ctx) => {
|
|
211
|
-
const view = ctx.get(editorViewCtx)
|
|
212
|
-
const commands = ctx.get(commandsCtx)
|
|
213
|
-
const isActive = findNodeInSelection(
|
|
214
|
-
view.state,
|
|
215
|
-
blockquoteSchema.type(ctx)
|
|
216
|
-
).hasNode
|
|
217
|
-
|
|
218
|
-
if (isActive) {
|
|
219
|
-
lift(view.state, view.dispatch)
|
|
220
|
-
} else {
|
|
221
|
-
commands.call(wrapInBlockTypeCommand.key, {
|
|
222
|
-
nodeType: blockquoteSchema.type(ctx),
|
|
223
|
-
})
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
})
|
|
96
|
+
const listGroup = builder.addGroup('list', 'List')
|
|
97
|
+
listGroup
|
|
227
98
|
.addItem('divider', {
|
|
228
99
|
label: ctx ? i18n(ctx, 'menu.item.divider') : 'Divider',
|
|
229
100
|
icon: dividerIcon,
|
|
@@ -233,9 +104,6 @@ export function buildDefaultFixedToolbar(
|
|
|
233
104
|
commands.call(addBlockTypeCommand.key, { nodeType: hrSchema.type(ctx) })
|
|
234
105
|
},
|
|
235
106
|
})
|
|
236
|
-
|
|
237
|
-
const listGroup = blockGroup
|
|
238
|
-
listGroup
|
|
239
107
|
.addItem('bullet-list', {
|
|
240
108
|
label: ctx ? i18n(ctx, 'menu.item.bulletList') : 'Bullet List',
|
|
241
109
|
icon: bulletListIcon,
|
|
@@ -498,4 +366,188 @@ export function buildDefaultFixedToolbar(
|
|
|
498
366
|
if (result) return
|
|
499
367
|
},
|
|
500
368
|
})
|
|
369
|
+
|
|
370
|
+
const blockGroup = builder.addGroup('block', 'Block')
|
|
371
|
+
blockGroup
|
|
372
|
+
.addItem('quote', {
|
|
373
|
+
label: ctx ? i18n(ctx, 'menu.item.quote') : 'Quote',
|
|
374
|
+
icon: quoteIcon,
|
|
375
|
+
active: (ctx) => {
|
|
376
|
+
const view = ctx.get(editorViewCtx)
|
|
377
|
+
const result = findNodeInSelection(
|
|
378
|
+
view.state,
|
|
379
|
+
blockquoteSchema.type(ctx)
|
|
380
|
+
)
|
|
381
|
+
return result.hasNode
|
|
382
|
+
},
|
|
383
|
+
onRun: (ctx) => {
|
|
384
|
+
const view = ctx.get(editorViewCtx)
|
|
385
|
+
const commands = ctx.get(commandsCtx)
|
|
386
|
+
const isActive = findNodeInSelection(
|
|
387
|
+
view.state,
|
|
388
|
+
blockquoteSchema.type(ctx)
|
|
389
|
+
).hasNode
|
|
390
|
+
|
|
391
|
+
if (isActive) {
|
|
392
|
+
lift(view.state, view.dispatch)
|
|
393
|
+
} else {
|
|
394
|
+
commands.call(wrapInBlockTypeCommand.key, {
|
|
395
|
+
nodeType: blockquoteSchema.type(ctx),
|
|
396
|
+
})
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
})
|
|
400
|
+
.addItem('highlight', {
|
|
401
|
+
label: ctx ? i18n(ctx, 'menu.item.highlight') : 'Highlight',
|
|
402
|
+
icon: highLineCodeIcon,
|
|
403
|
+
active: (ctx) => {
|
|
404
|
+
const commands = ctx.get(commandsCtx)
|
|
405
|
+
return commands.call(
|
|
406
|
+
isMarkSelectedCommand.key,
|
|
407
|
+
highlightMarkSchema.type(ctx)
|
|
408
|
+
)
|
|
409
|
+
},
|
|
410
|
+
onRun: (ctx) => {
|
|
411
|
+
const commands = ctx.get(commandsCtx)
|
|
412
|
+
commands.call(toggleHighlightMarkCommand.key)
|
|
413
|
+
},
|
|
414
|
+
})
|
|
415
|
+
.addItem('code', {
|
|
416
|
+
label: ctx ? i18n(ctx, 'menu.item.lineCode') : 'Inline Code',
|
|
417
|
+
icon: linCodeIcon,
|
|
418
|
+
active: (ctx) => {
|
|
419
|
+
const commands = ctx.get(commandsCtx)
|
|
420
|
+
return commands.call(
|
|
421
|
+
isMarkSelectedCommand.key,
|
|
422
|
+
inlineCodeSchema.type(ctx)
|
|
423
|
+
)
|
|
424
|
+
},
|
|
425
|
+
onRun: (ctx) => {
|
|
426
|
+
const commands = ctx.get(commandsCtx)
|
|
427
|
+
commands.call(toggleInlineCodeCommand.key)
|
|
428
|
+
},
|
|
429
|
+
})
|
|
430
|
+
.addItem('link', {
|
|
431
|
+
label: ctx ? i18n(ctx, 'menu.item.link') : 'Link',
|
|
432
|
+
icon: linkIcon,
|
|
433
|
+
active: (ctx) => {
|
|
434
|
+
const commands = ctx.get(commandsCtx)
|
|
435
|
+
return commands.call(isMarkSelectedCommand.key, linkSchema.type(ctx))
|
|
436
|
+
},
|
|
437
|
+
onRun: (ctx) => {
|
|
438
|
+
const commands = ctx.get(commandsCtx)
|
|
439
|
+
commands.call(toggleLinkCommand.key)
|
|
440
|
+
},
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
if (isImageBlockEnabled) {
|
|
444
|
+
blockGroup.addItem('image', {
|
|
445
|
+
label: ctx ? i18n(ctx, 'menu.item.image') : 'Image',
|
|
446
|
+
icon: imageIcon,
|
|
447
|
+
active: () => false,
|
|
448
|
+
onRun: (ctx) => {
|
|
449
|
+
const commands = ctx.get(commandsCtx)
|
|
450
|
+
commands.call(addBlockTypeCommand.key, {
|
|
451
|
+
nodeType: imageBlockSchema.type(ctx),
|
|
452
|
+
})
|
|
453
|
+
},
|
|
454
|
+
})
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (isAttachmentEnabled) {
|
|
458
|
+
blockGroup.addItem('attachment', {
|
|
459
|
+
label: ctx ? i18n(ctx, 'menu.item.attachment') : 'Video or File',
|
|
460
|
+
icon: fileLinkIcon,
|
|
461
|
+
active: () => false,
|
|
462
|
+
onRun: (ctx) => {
|
|
463
|
+
const commands = ctx.get(commandsCtx)
|
|
464
|
+
commands.call(addBlockTypeCommand.key, {
|
|
465
|
+
nodeType: attachmentSchema.type(ctx),
|
|
466
|
+
})
|
|
467
|
+
},
|
|
468
|
+
})
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
blockGroup.addItem('code-block', {
|
|
472
|
+
label: ctx ? i18n(ctx, 'menu.item.code') : 'Code Block',
|
|
473
|
+
icon: codeIcon,
|
|
474
|
+
active: (ctx) => {
|
|
475
|
+
const view = ctx.get(editorViewCtx)
|
|
476
|
+
const result = findNodeInSelection(view.state, codeBlockSchema.type(ctx))
|
|
477
|
+
return result.hasNode && result.target?.attrs?.language !== 'LaTex'
|
|
478
|
+
},
|
|
479
|
+
onRun: (ctx) => {
|
|
480
|
+
const commands = ctx.get(commandsCtx)
|
|
481
|
+
const view = ctx.get(editorViewCtx)
|
|
482
|
+
const { state, dispatch } = view
|
|
483
|
+
const { selection, tr } = state
|
|
484
|
+
const { from, to } = selection
|
|
485
|
+
|
|
486
|
+
let text = ''
|
|
487
|
+
let blockCount = 0
|
|
488
|
+
|
|
489
|
+
state.doc.nodesBetween(from, to, (node) => {
|
|
490
|
+
if (node.isTextblock) {
|
|
491
|
+
text += (blockCount > 0 ? '\n' : '') + node.textContent
|
|
492
|
+
blockCount++
|
|
493
|
+
}
|
|
494
|
+
})
|
|
495
|
+
|
|
496
|
+
if (blockCount > 1) {
|
|
497
|
+
if (dispatch) {
|
|
498
|
+
const range = selection.$from.blockRange(selection.$to)
|
|
499
|
+
const codeBlock = codeBlockSchema
|
|
500
|
+
.type(ctx)
|
|
501
|
+
.createAndFill({}, text ? state.schema.text(text) : undefined)
|
|
502
|
+
if (range && codeBlock) {
|
|
503
|
+
tr.replaceWith(range.start, range.end, codeBlock)
|
|
504
|
+
dispatch(tr.scrollIntoView())
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
return
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
commands.call(setBlockTypeCommand.key, {
|
|
511
|
+
nodeType: codeBlockSchema.type(ctx),
|
|
512
|
+
})
|
|
513
|
+
},
|
|
514
|
+
})
|
|
515
|
+
|
|
516
|
+
if (isTableEnabled) {
|
|
517
|
+
blockGroup.addItem('table', {
|
|
518
|
+
label: ctx ? i18n(ctx, 'menu.item.table') : 'Table',
|
|
519
|
+
icon: tableIcon,
|
|
520
|
+
active: () => false,
|
|
521
|
+
onRun: (ctx) => {
|
|
522
|
+
const commands = ctx.get(commandsCtx)
|
|
523
|
+
const view = ctx.get(editorViewCtx)
|
|
524
|
+
const { from } = view.state.selection
|
|
525
|
+
commands.call(addBlockTypeCommand.key, {
|
|
526
|
+
nodeType: createTable(ctx, 3, 3),
|
|
527
|
+
})
|
|
528
|
+
commands.call(selectTextNearPosCommand.key, { pos: from })
|
|
529
|
+
},
|
|
530
|
+
})
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if (isLatexEnabled) {
|
|
534
|
+
blockGroup.addItem('math-block', {
|
|
535
|
+
label: ctx ? i18n(ctx, 'menu.item.math') : 'Math Block',
|
|
536
|
+
icon: functionsIcon,
|
|
537
|
+
active: (ctx) => {
|
|
538
|
+
const view = ctx.get(editorViewCtx)
|
|
539
|
+
const result = findNodeInSelection(
|
|
540
|
+
view.state,
|
|
541
|
+
codeBlockSchema.type(ctx)
|
|
542
|
+
)
|
|
543
|
+
return result.hasNode && result.target?.attrs?.language === 'LaTex'
|
|
544
|
+
},
|
|
545
|
+
onRun: (ctx) => {
|
|
546
|
+
const commands = ctx.get(commandsCtx)
|
|
547
|
+
commands.call(toggleLatexCommand.key)
|
|
548
|
+
},
|
|
549
|
+
})
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
return builder.build()
|
|
501
553
|
}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { Ctx } from '@jvs-milkdown/kit/ctx'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import {
|
|
5
|
+
defineComponent,
|
|
6
|
+
computed,
|
|
7
|
+
ref,
|
|
8
|
+
watch,
|
|
9
|
+
onMounted,
|
|
10
|
+
onUnmounted,
|
|
11
|
+
} from 'vue'
|
|
4
12
|
|
|
5
13
|
import type { FixedToolbarConfig } from './index'
|
|
6
14
|
|
|
@@ -12,7 +20,7 @@ export const DocumentHeader = defineComponent({
|
|
|
12
20
|
ctx: { type: Object as () => Ctx, required: true },
|
|
13
21
|
config: { type: Object as () => FixedToolbarConfig, required: false },
|
|
14
22
|
},
|
|
15
|
-
setup(props) {
|
|
23
|
+
setup(props: any) {
|
|
16
24
|
const viewState = computed(() => props.ctx.get(viewMenuStateCtx.key))
|
|
17
25
|
const title = ref('')
|
|
18
26
|
|
|
@@ -57,7 +65,7 @@ export const DocumentHeader = defineComponent({
|
|
|
57
65
|
|
|
58
66
|
watch(
|
|
59
67
|
() => viewState.value.showCover,
|
|
60
|
-
(newVal) => {
|
|
68
|
+
(newVal: any) => {
|
|
61
69
|
if (newVal && !viewState.value.coverUrl) {
|
|
62
70
|
viewState.value.coverUrl = randomCover(
|
|
63
71
|
props.config?.defaultCoverImages
|
|
@@ -185,11 +193,11 @@ export const DocumentHeader = defineComponent({
|
|
|
185
193
|
onClick={() => {
|
|
186
194
|
state.coverUrl = src
|
|
187
195
|
}}
|
|
188
|
-
onMouseenter={(e) => {
|
|
196
|
+
onMouseenter={(e: any) => {
|
|
189
197
|
if (state.coverUrl !== src)
|
|
190
198
|
(e.currentTarget as HTMLElement).style.opacity = '1'
|
|
191
199
|
}}
|
|
192
|
-
onMouseleave={(e) => {
|
|
200
|
+
onMouseleave={(e: MouseEvent) => {
|
|
193
201
|
if (state.coverUrl !== src)
|
|
194
202
|
(e.currentTarget as HTMLElement).style.opacity =
|
|
195
203
|
'0.7'
|
|
@@ -213,11 +221,11 @@ export const DocumentHeader = defineComponent({
|
|
|
213
221
|
flexShrink: 0,
|
|
214
222
|
userSelect: 'none',
|
|
215
223
|
}}
|
|
216
|
-
onMouseenter={(e) => {
|
|
224
|
+
onMouseenter={(e: any) => {
|
|
217
225
|
;(e.currentTarget as HTMLElement).style.backgroundColor =
|
|
218
226
|
'rgba(255,255,255,0.35)'
|
|
219
227
|
}}
|
|
220
|
-
onMouseleave={(e) => {
|
|
228
|
+
onMouseleave={(e: MouseEvent) => {
|
|
221
229
|
;(e.currentTarget as HTMLElement).style.backgroundColor =
|
|
222
230
|
'rgba(255,255,255,0.2)'
|
|
223
231
|
}}
|
|
@@ -255,12 +263,14 @@ export const DocumentHeader = defineComponent({
|
|
|
255
263
|
style={{
|
|
256
264
|
width: '100%',
|
|
257
265
|
maxWidth:
|
|
258
|
-
editorWidthMap[state.editorWidth] === 'none'
|
|
266
|
+
(editorWidthMap as any)[state.editorWidth] === 'none'
|
|
259
267
|
? undefined
|
|
260
|
-
: editorWidthMap[state.editorWidth],
|
|
268
|
+
: (editorWidthMap as any)[state.editorWidth],
|
|
261
269
|
margin:
|
|
262
|
-
editorWidthMap[state.editorWidth] === 'none'
|
|
263
|
-
|
|
270
|
+
(editorWidthMap as any)[state.editorWidth] === 'none'
|
|
271
|
+
? '0'
|
|
272
|
+
: '0 auto',
|
|
273
|
+
padding: `40px ${(editorWidthMap as any)[state.editorWidth] === 'none' ? '80px' : '0'} 0`,
|
|
264
274
|
}}
|
|
265
275
|
>
|
|
266
276
|
<style>{`.milkdown-document-title::placeholder { color: #BFBFBF; }`}</style>
|
|
@@ -269,7 +279,7 @@ export const DocumentHeader = defineComponent({
|
|
|
269
279
|
class="milkdown-document-title"
|
|
270
280
|
placeholder="请输入标题"
|
|
271
281
|
value={title.value}
|
|
272
|
-
onInput={(e) => {
|
|
282
|
+
onInput={(e: any) => {
|
|
273
283
|
title.value = (e.target as HTMLTextAreaElement).value
|
|
274
284
|
adjustTitleHeight()
|
|
275
285
|
}}
|
|
@@ -4,6 +4,7 @@ import type { EditorView } from '@jvs-milkdown/kit/prose/view'
|
|
|
4
4
|
|
|
5
5
|
import { Plugin, PluginKey } from '@jvs-milkdown/kit/prose/state'
|
|
6
6
|
import { $ctx, $prose } from '@jvs-milkdown/kit/utils'
|
|
7
|
+
// @ts-ignore
|
|
7
8
|
import {
|
|
8
9
|
createApp,
|
|
9
10
|
ref,
|
|
@@ -218,7 +219,7 @@ class FixedToolbarView implements PluginView {
|
|
|
218
219
|
this.#content.style.marginRight = '0'
|
|
219
220
|
}
|
|
220
221
|
|
|
221
|
-
const maxWidth = editorWidthMap[viewState.editorWidth]
|
|
222
|
+
const maxWidth = (editorWidthMap as any)[viewState.editorWidth]
|
|
222
223
|
const isFull = maxWidth === 'none'
|
|
223
224
|
const px = isFull ? '80px' : '0'
|
|
224
225
|
this.#view.dom.style.maxWidth = maxWidth
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Ctx } from '@jvs-milkdown/kit/ctx'
|
|
2
2
|
|
|
3
3
|
import { Icon } from '@jvs-milkdown/kit/component'
|
|
4
|
-
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import { defineComponent, ref, onUnmounted, computed, onMounted } from 'vue'
|
|
5
6
|
|
|
6
7
|
import type { FixedToolbarConfig } from './index'
|
|
7
8
|
|
|
@@ -16,10 +17,10 @@ const ToggleSwitch = defineComponent({
|
|
|
16
17
|
modelValue: { type: Boolean, required: true },
|
|
17
18
|
},
|
|
18
19
|
emits: ['update:modelValue'],
|
|
19
|
-
setup(props, { emit }) {
|
|
20
|
+
setup(props: any, { emit }: any) {
|
|
20
21
|
return () => (
|
|
21
22
|
<div
|
|
22
|
-
onClick={(e) => {
|
|
23
|
+
onClick={(e: MouseEvent) => {
|
|
23
24
|
e.stopPropagation()
|
|
24
25
|
emit('update:modelValue', !props.modelValue)
|
|
25
26
|
}}
|
|
@@ -58,7 +59,7 @@ export const MenuBar = defineComponent({
|
|
|
58
59
|
ctx: { type: Object as () => Ctx, required: true },
|
|
59
60
|
config: { type: Object as () => FixedToolbarConfig, required: false },
|
|
60
61
|
},
|
|
61
|
-
setup(props) {
|
|
62
|
+
setup(props: any) {
|
|
62
63
|
const showMenu = ref(false)
|
|
63
64
|
const activeSubmenu = ref<string | null>(null)
|
|
64
65
|
const mainRef = ref<HTMLElement | null>(null)
|
|
@@ -163,11 +164,11 @@ export const MenuBar = defineComponent({
|
|
|
163
164
|
color: 'var(--crepe-color-on-surface)',
|
|
164
165
|
userSelect: 'none',
|
|
165
166
|
}}
|
|
166
|
-
onMouseenter={(e) => {
|
|
167
|
+
onMouseenter={(e: MouseEvent) => {
|
|
167
168
|
;(e.currentTarget as HTMLElement).style.backgroundColor =
|
|
168
169
|
'var(--crepe-color-hover)'
|
|
169
170
|
}}
|
|
170
|
-
onMouseleave={(e) => {
|
|
171
|
+
onMouseleave={(e: MouseEvent) => {
|
|
171
172
|
if (!showMenu.value)
|
|
172
173
|
(e.currentTarget as HTMLElement).style.backgroundColor =
|
|
173
174
|
'transparent'
|
|
@@ -216,7 +217,9 @@ export const MenuBar = defineComponent({
|
|
|
216
217
|
boxShadow: '0 4px 12px rgba(0,0,0,0.1)',
|
|
217
218
|
cursor: 'default',
|
|
218
219
|
}}
|
|
219
|
-
onClick={(e) =>
|
|
220
|
+
onClick={(e: MouseEvent) => {
|
|
221
|
+
e.stopPropagation()
|
|
222
|
+
}}
|
|
220
223
|
>
|
|
221
224
|
{menuKeys.map((menuKey) => {
|
|
222
225
|
const isHovered = activeSubmenu.value === menuKey
|
|
@@ -226,7 +229,9 @@ export const MenuBar = defineComponent({
|
|
|
226
229
|
return (
|
|
227
230
|
<div
|
|
228
231
|
key={menuKey}
|
|
229
|
-
onMouseenter={() =>
|
|
232
|
+
onMouseenter={() => {
|
|
233
|
+
onMouseEnterItem(menuKey)
|
|
234
|
+
}}
|
|
230
235
|
onMouseleave={() => {
|
|
231
236
|
if (hasSubmenu(menuKey)) {
|
|
232
237
|
activeSubmenu.value = null
|
|
@@ -410,7 +415,7 @@ export const MenuBar = defineComponent({
|
|
|
410
415
|
{bgColors.map((bg) => (
|
|
411
416
|
<div
|
|
412
417
|
key={bg.value || 'default'}
|
|
413
|
-
onClick={(e) => {
|
|
418
|
+
onClick={(e: MouseEvent) => {
|
|
414
419
|
e.stopPropagation()
|
|
415
420
|
state.documentBackground = bg.value
|
|
416
421
|
}}
|
|
@@ -513,7 +518,7 @@ export const MenuBar = defineComponent({
|
|
|
513
518
|
<button
|
|
514
519
|
key={key}
|
|
515
520
|
type="button"
|
|
516
|
-
onClick={(e) => {
|
|
521
|
+
onClick={(e: MouseEvent) => {
|
|
517
522
|
e.stopPropagation()
|
|
518
523
|
state.editorWidth = key
|
|
519
524
|
}}
|