forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
144 lines (138 loc) · 2.99 KB
/
config.js
File metadata and controls
144 lines (138 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import copyIcon from '../../assets/pngicon/copy/2.png'
import newIcon from '../../assets/pngicon/paragraph/2.png'
import deleteIcon from '../../assets/pngicon/delete/2.png'
import turnIcon from '../../assets/pngicon/turninto/2.png'
import { isOsx } from '../../config'
import { quickInsertObj } from '../quickInsert/config'
const wholeSubMenu = Object.keys(quickInsertObj).reduce((acc, key) => {
const items = quickInsertObj[key]
return [...acc, ...items]
}, [])
const COMMAND_KEY = isOsx ? '⌘' : '⌃'
export const menu = [{
icon: copyIcon,
label: 'duplicate',
text: 'Duplicate',
shortCut: `⇧${COMMAND_KEY}P`
}, {
icon: turnIcon,
label: 'turnInto',
text: 'Turn Into'
}, {
icon: newIcon,
label: 'new',
text: 'New Paragraph',
shortCut: `⇧${COMMAND_KEY}N`
}, {
icon: deleteIcon,
label: 'delete',
text: 'Delete',
shortCut: `⇧${COMMAND_KEY}D`
}]
export const getLabel = block => {
const { type, functionType, listType } = block
let label = ''
switch (type) {
case 'p': {
label = 'paragraph'
break
}
case 'figure': {
if (functionType === 'table') {
label = 'table'
} else if (functionType === 'html') {
label = 'html'
} else if (functionType === 'multiplemath') {
label = 'mathblock'
}
break
}
case 'pre': {
if (functionType === 'fencecode' || functionType === 'indentcode') {
label = 'pre'
} else if (functionType === 'frontmatter') {
label = 'front-matter'
}
break
}
case 'ul': {
if (listType === 'task') {
label = 'ul-task'
} else {
label = 'ul-bullet'
}
break
}
case 'ol': {
label = 'ol-order'
break
}
case 'blockquote': {
label = 'blockquote'
break
}
case 'h1': {
label = 'heading 1'
break
}
case 'h2': {
label = 'heading 2'
break
}
case 'h3': {
label = 'heading 3'
break
}
case 'h4': {
label = 'heading 4'
break
}
case 'h5': {
label = 'heading 5'
break
}
case 'h6': {
label = 'heading 6'
break
}
case 'hr': {
label = 'hr'
break
}
default:
label = 'paragraph'
break
}
return label
}
export const getSubMenu = (block, startBlock, endBlock) => {
const { type } = block
switch (type) {
case 'p': {
return wholeSubMenu.filter(menuItem => {
const REG_EXP = startBlock.key === endBlock.key
? /front-matter|hr|table/
: /front-matter|hr|table|heading/
return !REG_EXP.test(menuItem.label)
})
}
case 'h1':
case 'h2':
case 'h3':
case 'h4':
case 'h5':
case 'h6': {
return wholeSubMenu.filter(menuItem => {
return /heading|paragraph/.test(menuItem.label)
})
}
case 'ul':
case 'ol': {
return wholeSubMenu.filter(menuItem => {
return /ul|ol/.test(menuItem.label)
})
}
default:
return []
}
}