@jvs-milkdown/crepe 1.2.4 → 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 +1254 -960
- 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 +1329 -1035
- 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 +45 -14
- 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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Ctx } from '@jvs-milkdown/kit/ctx'
|
|
2
2
|
|
|
3
3
|
import { editorViewCtx } from '@jvs-milkdown/kit/core'
|
|
4
|
-
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import { defineComponent, onMounted, onUnmounted, ref, computed } from 'vue'
|
|
5
6
|
|
|
6
7
|
import { i18n } from '../../core/locale'
|
|
7
8
|
import { viewMenuStateCtx } from './view-menu-state'
|
|
@@ -17,7 +18,7 @@ export const OutlinePanel = defineComponent({
|
|
|
17
18
|
props: {
|
|
18
19
|
ctx: { type: Object as () => Ctx, required: true },
|
|
19
20
|
},
|
|
20
|
-
setup(props) {
|
|
21
|
+
setup(props: any) {
|
|
21
22
|
const items = ref<OutlineItem[]>([])
|
|
22
23
|
const viewState = computed(() => props.ctx.get(viewMenuStateCtx.key))
|
|
23
24
|
const isResizing = ref(false)
|
|
@@ -75,7 +76,7 @@ export const OutlinePanel = defineComponent({
|
|
|
75
76
|
const view = props.ctx.get(editorViewCtx)
|
|
76
77
|
if (!view) return
|
|
77
78
|
const newItems: OutlineItem[] = []
|
|
78
|
-
view.state.doc.descendants((node, pos) => {
|
|
79
|
+
view.state.doc.descendants((node: any, pos: number) => {
|
|
79
80
|
if (node.type.name === 'heading' && node.textContent.trim()) {
|
|
80
81
|
newItems.push({
|
|
81
82
|
text: node.textContent,
|
|
@@ -119,7 +120,7 @@ export const OutlinePanel = defineComponent({
|
|
|
119
120
|
const threshold = containerRect.top + toolbarHeight + 50
|
|
120
121
|
|
|
121
122
|
let active = headings[0]
|
|
122
|
-
for (const h of headings) {
|
|
123
|
+
for (const h of headings as HTMLElement[]) {
|
|
123
124
|
const rect = h.getBoundingClientRect()
|
|
124
125
|
if (rect.top <= threshold) {
|
|
125
126
|
active = h
|
|
@@ -127,7 +128,7 @@ export const OutlinePanel = defineComponent({
|
|
|
127
128
|
break
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
|
-
activeId.value = active?.id || ''
|
|
131
|
+
activeId.value = (active as any)?.id || ''
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
const scrollToHeading = (id: string) => {
|
|
@@ -305,13 +306,13 @@ export const OutlinePanel = defineComponent({
|
|
|
305
306
|
color: 'var(--crepe-color-outline)',
|
|
306
307
|
}}
|
|
307
308
|
onClick={() => (viewState.value.outlineVisible = false)}
|
|
308
|
-
onMouseenter={(e) => {
|
|
309
|
+
onMouseenter={(e: MouseEvent) => {
|
|
309
310
|
;(e.currentTarget as HTMLElement).style.backgroundColor =
|
|
310
311
|
'var(--crepe-color-hover)'
|
|
311
312
|
;(e.currentTarget as HTMLElement).style.color =
|
|
312
313
|
'var(--crepe-color-on-surface)'
|
|
313
314
|
}}
|
|
314
|
-
onMouseleave={(e) => {
|
|
315
|
+
onMouseleave={(e: MouseEvent) => {
|
|
315
316
|
;(e.currentTarget as HTMLElement).style.backgroundColor =
|
|
316
317
|
'transparent'
|
|
317
318
|
;(e.currentTarget as HTMLElement).style.color =
|
|
@@ -348,7 +349,7 @@ export const OutlinePanel = defineComponent({
|
|
|
348
349
|
暂无标题
|
|
349
350
|
</div>
|
|
350
351
|
) : null}
|
|
351
|
-
{visibleItems.value.map(({ item, hasChildren: hasKids }) => {
|
|
352
|
+
{visibleItems.value.map(({ item, hasChildren: hasKids }: any) => {
|
|
352
353
|
const isActive = activeId.value === item.id
|
|
353
354
|
const collapsed = collapsedIds.value.has(item.id)
|
|
354
355
|
return (
|
|
@@ -372,7 +373,7 @@ export const OutlinePanel = defineComponent({
|
|
|
372
373
|
overflow: 'hidden',
|
|
373
374
|
textOverflow: 'ellipsis',
|
|
374
375
|
}}
|
|
375
|
-
onMouseenter={(e) => {
|
|
376
|
+
onMouseenter={(e: MouseEvent) => {
|
|
376
377
|
;(e.currentTarget as HTMLElement).style.backgroundColor =
|
|
377
378
|
'var(--crepe-color-hover)'
|
|
378
379
|
if (!isActive) {
|
|
@@ -380,7 +381,7 @@ export const OutlinePanel = defineComponent({
|
|
|
380
381
|
'var(--crepe-color-on-surface)'
|
|
381
382
|
}
|
|
382
383
|
}}
|
|
383
|
-
onMouseleave={(e) => {
|
|
384
|
+
onMouseleave={(e: MouseEvent) => {
|
|
384
385
|
;(e.currentTarget as HTMLElement).style.backgroundColor =
|
|
385
386
|
'transparent'
|
|
386
387
|
if (!isActive) {
|
|
@@ -391,7 +392,7 @@ export const OutlinePanel = defineComponent({
|
|
|
391
392
|
>
|
|
392
393
|
{/* Toggle arrow */}
|
|
393
394
|
<span
|
|
394
|
-
onClick={(e) => {
|
|
395
|
+
onClick={(e: MouseEvent) => {
|
|
395
396
|
e.stopPropagation()
|
|
396
397
|
toggleCollapse(item.id)
|
|
397
398
|
}}
|
|
@@ -414,19 +415,19 @@ export const OutlinePanel = defineComponent({
|
|
|
414
415
|
? 'rotate(0deg)'
|
|
415
416
|
: 'rotate(-90deg)',
|
|
416
417
|
}}
|
|
417
|
-
onMouseenter={(e) => {
|
|
418
|
+
onMouseenter={(e: MouseEvent) => {
|
|
418
419
|
if (hasKids) {
|
|
419
420
|
;(
|
|
420
421
|
e.currentTarget as HTMLElement
|
|
421
422
|
).style.backgroundColor = 'var(--crepe-color-hover)'
|
|
422
423
|
}
|
|
423
424
|
}}
|
|
424
|
-
onMouseleave={(e) => {
|
|
425
|
+
onMouseleave={(e: MouseEvent) => {
|
|
425
426
|
;(e.currentTarget as HTMLElement).style.backgroundColor =
|
|
426
427
|
'transparent'
|
|
427
428
|
}}
|
|
428
429
|
>
|
|
429
|
-
|
|
430
|
+
�?{' '}
|
|
430
431
|
</span>
|
|
431
432
|
{/* Text - click to scroll */}
|
|
432
433
|
<span
|
|
@@ -459,13 +460,13 @@ export const OutlinePanel = defineComponent({
|
|
|
459
460
|
zIndex: 10,
|
|
460
461
|
opacity: isResizing.value ? 1 : 0,
|
|
461
462
|
}}
|
|
462
|
-
onMouseenter={(e) => {
|
|
463
|
+
onMouseenter={(e: MouseEvent) => {
|
|
463
464
|
if (!isResizing.value)
|
|
464
465
|
(e.currentTarget as HTMLElement).style.opacity = '0.5'
|
|
465
466
|
;(e.currentTarget as HTMLElement).style.backgroundColor =
|
|
466
467
|
'var(--crepe-color-primary)'
|
|
467
468
|
}}
|
|
468
|
-
onMouseleave={(e) => {
|
|
469
|
+
onMouseleave={(e: MouseEvent) => {
|
|
469
470
|
if (!isResizing.value)
|
|
470
471
|
(e.currentTarget as HTMLElement).style.opacity = '0'
|
|
471
472
|
;(e.currentTarget as HTMLElement).style.backgroundColor =
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Ctx } from '@jvs-milkdown/kit/ctx'
|
|
2
2
|
|
|
3
3
|
import { Icon } from '@jvs-milkdown/kit/component'
|
|
4
|
+
// @ts-ignore
|
|
4
5
|
import { defineComponent, type Ref, h, onMounted, onBeforeUnmount } from 'vue'
|
|
5
6
|
|
|
6
7
|
import type { CrepeTranslations } from '../../core/locale'
|
|
@@ -144,7 +145,7 @@ export const ShortcutHelpModal = defineComponent<ModalProps>({
|
|
|
144
145
|
ctx: { type: Object, required: true },
|
|
145
146
|
visible: { type: Object, required: true },
|
|
146
147
|
},
|
|
147
|
-
setup(props) {
|
|
148
|
+
setup(props: any) {
|
|
148
149
|
const close = () => {
|
|
149
150
|
props.visible.value = false
|
|
150
151
|
}
|
|
@@ -179,7 +180,7 @@ export const ShortcutHelpModal = defineComponent<ModalProps>({
|
|
|
179
180
|
boxShadow: '0 8px 32px rgba(0, 0, 0, 0.15)',
|
|
180
181
|
padding: '20px 24px',
|
|
181
182
|
}}
|
|
182
|
-
onClick={(e) => e.stopPropagation()}
|
|
183
|
+
onClick={(e: MouseEvent) => e.stopPropagation()}
|
|
183
184
|
>
|
|
184
185
|
<div
|
|
185
186
|
style={{
|
package/src/feature/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AttachmentFeatureConfig } from './attachment/config'
|
|
1
2
|
import type { BlockEditFeatureConfig } from './block-edit'
|
|
2
3
|
import type { CodeMirrorFeatureConfig } from './code-mirror'
|
|
3
4
|
import type { CursorFeatureConfig } from './cursor'
|
|
@@ -9,7 +10,6 @@ import type { ListItemFeatureConfig } from './list-item'
|
|
|
9
10
|
import type { PlaceholderFeatureConfig } from './placeholder'
|
|
10
11
|
import type { TableFeatureConfig } from './table'
|
|
11
12
|
import type { ToolbarFeatureConfig } from './toolbar'
|
|
12
|
-
import type { AttachmentFeatureConfig } from './attachment/config'
|
|
13
13
|
|
|
14
14
|
/// The crepe editor feature flags.
|
|
15
15
|
/// Every feature is enabled by default.
|
|
@@ -2,6 +2,7 @@ import type { Ctx } from '@jvs-milkdown/kit/ctx'
|
|
|
2
2
|
import type { EditorView } from '@jvs-milkdown/kit/prose/view'
|
|
3
3
|
|
|
4
4
|
import { Icon } from '@jvs-milkdown/kit/component'
|
|
5
|
+
// @ts-ignore
|
|
5
6
|
import {
|
|
6
7
|
defineComponent,
|
|
7
8
|
type ShallowRef,
|
|
@@ -44,8 +45,8 @@ export const LatexTooltip = defineComponent<LatexTooltipProps>({
|
|
|
44
45
|
required: true,
|
|
45
46
|
},
|
|
46
47
|
},
|
|
47
|
-
setup(props) {
|
|
48
|
-
const innerViewRef: VNodeRef = (el) => {
|
|
48
|
+
setup(props: any) {
|
|
49
|
+
const innerViewRef: VNodeRef = (el: any) => {
|
|
49
50
|
if (!el || !(el instanceof HTMLElement)) return
|
|
50
51
|
while (el.firstChild) {
|
|
51
52
|
el.removeChild(el.firstChild)
|
package/src/feature/loader.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Editor } from '@jvs-milkdown/kit/core'
|
|
2
2
|
|
|
3
|
+
import { attachment } from './attachment'
|
|
3
4
|
import { blockEdit } from './block-edit'
|
|
4
5
|
import { codeMirror } from './code-mirror'
|
|
5
6
|
import { cursor } from './cursor'
|
|
@@ -12,7 +13,6 @@ import { listItem } from './list-item'
|
|
|
12
13
|
import { placeholder } from './placeholder'
|
|
13
14
|
import { table } from './table'
|
|
14
15
|
import { toolbar } from './toolbar'
|
|
15
|
-
import { attachment } from './attachment'
|
|
16
16
|
|
|
17
17
|
export function loadFeature(
|
|
18
18
|
feature: CrepeFeature,
|
|
@@ -62,7 +62,8 @@ export const placeholderPlugin = $prose((ctx) => {
|
|
|
62
62
|
if (crepe.readonly) return DecorationSet.empty
|
|
63
63
|
|
|
64
64
|
const config = ctx.get(placeholderConfig.key)
|
|
65
|
-
if (config.mode === 'doc' && !isDocEmpty(state.doc))
|
|
65
|
+
if (config.mode === 'doc' && !isDocEmpty(state.doc))
|
|
66
|
+
return DecorationSet.empty
|
|
66
67
|
|
|
67
68
|
if (isInCodeBlock(state.selection) || isInList(state.selection))
|
|
68
69
|
return DecorationSet.empty
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Command } from '@jvs-milkdown/kit/prose/state'
|
|
1
2
|
|
|
2
3
|
import {
|
|
3
4
|
$command,
|
|
@@ -5,7 +6,6 @@ import {
|
|
|
5
6
|
$markSchema,
|
|
6
7
|
$remark,
|
|
7
8
|
} from '@jvs-milkdown/kit/utils'
|
|
8
|
-
import type { Command } from '@jvs-milkdown/kit/prose/state'
|
|
9
9
|
import { visit } from 'unist-util-visit'
|
|
10
10
|
|
|
11
11
|
export const remarkTextColorPlugin = $remark(
|
|
@@ -40,9 +40,11 @@ export const remarkTextColorPlugin = $remark(
|
|
|
40
40
|
parent &&
|
|
41
41
|
index != null
|
|
42
42
|
) {
|
|
43
|
-
const hasTextColor =
|
|
43
|
+
const hasTextColor =
|
|
44
|
+
node.value.includes('color:') &&
|
|
45
|
+
!node.value.match(/background-color:\s*([^"';>]+)/)
|
|
44
46
|
const hasBgColor = node.value.includes('background-color:')
|
|
45
|
-
|
|
47
|
+
|
|
46
48
|
if (!hasTextColor && !hasBgColor) return
|
|
47
49
|
|
|
48
50
|
let color = null
|
|
@@ -156,98 +158,100 @@ export const bgColorSchema = $markSchema('bgColor', (_ctx) => ({
|
|
|
156
158
|
|
|
157
159
|
export const toggleTextColorCommand = $command(
|
|
158
160
|
'ToggleTextColor',
|
|
159
|
-
(ctx) =>
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
(ctx) =>
|
|
162
|
+
(color?: string | null): Command => {
|
|
163
|
+
return (state, dispatch) => {
|
|
164
|
+
const markType = textColorSchema.type(ctx)
|
|
165
|
+
const { $cursor, ranges } = state.selection as any
|
|
163
166
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
if (dispatch) {
|
|
168
|
+
let tr = state.tr
|
|
169
|
+
if ($cursor) {
|
|
170
|
+
const marks = state.storedMarks || $cursor.marks()
|
|
171
|
+
const currentMark = markType.isInSet(marks)
|
|
172
|
+
|
|
173
|
+
if (currentMark && currentMark.attrs.color === color) {
|
|
174
|
+
tr = tr.removeStoredMark(markType)
|
|
175
|
+
} else {
|
|
176
|
+
tr = tr.removeStoredMark(markType)
|
|
177
|
+
if (color) tr = tr.addStoredMark(markType.create({ color }))
|
|
178
|
+
}
|
|
172
179
|
} else {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const mark = markType.isInSet(node.marks)
|
|
183
|
-
if (mark && mark.attrs.color === color) {
|
|
184
|
-
hasSameColor = true
|
|
180
|
+
let hasSameColor = false
|
|
181
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
182
|
+
let { $from, $to } = ranges[i]
|
|
183
|
+
state.doc.nodesBetween($from.pos, $to.pos, (node) => {
|
|
184
|
+
if (node.isText) {
|
|
185
|
+
const mark = markType.isInSet(node.marks)
|
|
186
|
+
if (mark && mark.attrs.color === color) {
|
|
187
|
+
hasSameColor = true
|
|
188
|
+
}
|
|
185
189
|
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
190
|
+
})
|
|
191
|
+
}
|
|
189
192
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
194
|
+
let { $from, $to } = ranges[i]
|
|
195
|
+
tr = tr.removeMark($from.pos, $to.pos, markType)
|
|
196
|
+
if (!hasSameColor && color) {
|
|
197
|
+
tr = tr.addMark($from.pos, $to.pos, markType.create({ color }))
|
|
198
|
+
}
|
|
195
199
|
}
|
|
196
200
|
}
|
|
201
|
+
dispatch(tr.scrollIntoView())
|
|
197
202
|
}
|
|
198
|
-
|
|
203
|
+
return true
|
|
199
204
|
}
|
|
200
|
-
return true
|
|
201
205
|
}
|
|
202
|
-
}
|
|
203
206
|
)
|
|
204
207
|
|
|
205
208
|
export const toggleBgColorCommand = $command(
|
|
206
209
|
'ToggleBgColor',
|
|
207
|
-
(ctx) =>
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
210
|
+
(ctx) =>
|
|
211
|
+
(color?: string | null): Command => {
|
|
212
|
+
return (state, dispatch) => {
|
|
213
|
+
const markType = bgColorSchema.type(ctx)
|
|
214
|
+
const { $cursor, ranges } = state.selection as any
|
|
215
|
+
|
|
216
|
+
if (dispatch) {
|
|
217
|
+
let tr = state.tr
|
|
218
|
+
if ($cursor) {
|
|
219
|
+
const marks = state.storedMarks || $cursor.marks()
|
|
220
|
+
const currentMark = markType.isInSet(marks)
|
|
211
221
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (currentMark && currentMark.attrs.color === color) {
|
|
219
|
-
tr = tr.removeStoredMark(markType)
|
|
222
|
+
if (currentMark && currentMark.attrs.color === color) {
|
|
223
|
+
tr = tr.removeStoredMark(markType)
|
|
224
|
+
} else {
|
|
225
|
+
tr = tr.removeStoredMark(markType)
|
|
226
|
+
if (color) tr = tr.addStoredMark(markType.create({ color }))
|
|
227
|
+
}
|
|
220
228
|
} else {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const mark = markType.isInSet(node.marks)
|
|
231
|
-
if (mark && mark.attrs.color === color) {
|
|
232
|
-
hasSameColor = true
|
|
229
|
+
let hasSameColor = false
|
|
230
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
231
|
+
let { $from, $to } = ranges[i]
|
|
232
|
+
state.doc.nodesBetween($from.pos, $to.pos, (node) => {
|
|
233
|
+
if (node.isText) {
|
|
234
|
+
const mark = markType.isInSet(node.marks)
|
|
235
|
+
if (mark && mark.attrs.color === color) {
|
|
236
|
+
hasSameColor = true
|
|
237
|
+
}
|
|
233
238
|
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
239
|
+
})
|
|
240
|
+
}
|
|
237
241
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
242
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
243
|
+
let { $from, $to } = ranges[i]
|
|
244
|
+
tr = tr.removeMark($from.pos, $to.pos, markType)
|
|
245
|
+
if (!hasSameColor && color) {
|
|
246
|
+
tr = tr.addMark($from.pos, $to.pos, markType.create({ color }))
|
|
247
|
+
}
|
|
243
248
|
}
|
|
244
249
|
}
|
|
250
|
+
dispatch(tr.scrollIntoView())
|
|
245
251
|
}
|
|
246
|
-
|
|
252
|
+
return true
|
|
247
253
|
}
|
|
248
|
-
return true
|
|
249
254
|
}
|
|
250
|
-
}
|
|
251
255
|
)
|
|
252
256
|
|
|
253
257
|
export const colorPlugins = [
|