|
|
|
|
@ -7,6 +7,7 @@ import { formatPrismToken } from './utils/prism'
|
|
|
|
|
import { Signature } from './components/signature/Signature'
|
|
|
|
|
|
|
|
|
|
window.onload = function () {
|
|
|
|
|
const isApple = typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent)
|
|
|
|
|
|
|
|
|
|
// 1. 初始化编辑器
|
|
|
|
|
const container = document.querySelector<HTMLDivElement>('.editor')!
|
|
|
|
|
@ -17,12 +18,14 @@ window.onload = function () {
|
|
|
|
|
|
|
|
|
|
// 2. | 撤销 | 重做 | 格式刷 | 清除格式 |
|
|
|
|
|
const undoDom = document.querySelector<HTMLDivElement>('.menu-item__undo')!
|
|
|
|
|
undoDom.title = `撤销(${isApple ? '⌘' : 'Ctrl'}+Z)`
|
|
|
|
|
undoDom.onclick = function () {
|
|
|
|
|
console.log('undo')
|
|
|
|
|
instance.command.executeUndo()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const redoDom = document.querySelector<HTMLDivElement>('.menu-item__redo')!
|
|
|
|
|
redoDom.title = `重做(${isApple ? '⌘' : 'Ctrl'}+Y)`
|
|
|
|
|
redoDom.onclick = function () {
|
|
|
|
|
console.log('redo')
|
|
|
|
|
instance.command.executeRedo()
|
|
|
|
|
@ -60,29 +63,36 @@ window.onload = function () {
|
|
|
|
|
instance.command.executeFont(li.dataset.family!)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.querySelector<HTMLDivElement>('.menu-item__size-add')!.onclick = function () {
|
|
|
|
|
const sizeAddDom = document.querySelector<HTMLDivElement>('.menu-item__size-add')!
|
|
|
|
|
sizeAddDom.title = `增大字号(${isApple ? '⌘' : 'Ctrl'}+[)`
|
|
|
|
|
sizeAddDom.onclick = function () {
|
|
|
|
|
console.log('size-add')
|
|
|
|
|
instance.command.executeSizeAdd()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.querySelector<HTMLDivElement>('.menu-item__size-minus')!.onclick = function () {
|
|
|
|
|
const sizeMinusDom = document.querySelector<HTMLDivElement>('.menu-item__size-minus')!
|
|
|
|
|
sizeMinusDom.title = `减小字号(${isApple ? '⌘' : 'Ctrl'}+])`
|
|
|
|
|
sizeMinusDom.onclick = function () {
|
|
|
|
|
console.log('size-minus')
|
|
|
|
|
instance.command.executeSizeMinus()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const boldDom = document.querySelector<HTMLDivElement>('.menu-item__bold')!
|
|
|
|
|
boldDom.title = `加粗(${isApple ? '⌘' : 'Ctrl'}+B)`
|
|
|
|
|
boldDom.onclick = function () {
|
|
|
|
|
console.log('bold')
|
|
|
|
|
instance.command.executeBold()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const italicDom = document.querySelector<HTMLDivElement>('.menu-item__italic')!
|
|
|
|
|
italicDom.title = `斜体(${isApple ? '⌘' : 'Ctrl'}+I)`
|
|
|
|
|
italicDom.onclick = function () {
|
|
|
|
|
console.log('italic')
|
|
|
|
|
instance.command.executeItalic()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const underlineDom = document.querySelector<HTMLDivElement>('.menu-item__underline')!
|
|
|
|
|
underlineDom.title = `下划线(${isApple ? '⌘' : 'Ctrl'}+U)`
|
|
|
|
|
underlineDom.onclick = function () {
|
|
|
|
|
console.log('underline')
|
|
|
|
|
instance.command.executeUnderline()
|
|
|
|
|
@ -95,12 +105,14 @@ window.onload = function () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const superscriptDom = document.querySelector<HTMLDivElement>('.menu-item__superscript')!
|
|
|
|
|
superscriptDom.title = `上标(${isApple ? '⌘' : 'Ctrl'}+Shift+,)`
|
|
|
|
|
superscriptDom.onclick = function () {
|
|
|
|
|
console.log('superscript')
|
|
|
|
|
instance.command.executeSuperscript()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const subscriptDom = document.querySelector<HTMLDivElement>('.menu-item__subscript')!
|
|
|
|
|
subscriptDom.title = `下标(${isApple ? '⌘' : 'Ctrl'}+Shift+.)`
|
|
|
|
|
subscriptDom.onclick = function () {
|
|
|
|
|
console.log('subscript')
|
|
|
|
|
instance.command.executeSubscript()
|
|
|
|
|
@ -129,24 +141,28 @@ window.onload = function () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const leftDom = document.querySelector<HTMLDivElement>('.menu-item__left')!
|
|
|
|
|
leftDom.title = `左对齐(${isApple ? '⌘' : 'Ctrl'}+L)`
|
|
|
|
|
leftDom.onclick = function () {
|
|
|
|
|
console.log('left')
|
|
|
|
|
instance.command.executeLeft()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const centerDom = document.querySelector<HTMLDivElement>('.menu-item__center')!
|
|
|
|
|
centerDom.title = `居中对齐(${isApple ? '⌘' : 'Ctrl'}+E)`
|
|
|
|
|
centerDom.onclick = function () {
|
|
|
|
|
console.log('center')
|
|
|
|
|
instance.command.executeCenter()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const rightDom = document.querySelector<HTMLDivElement>('.menu-item__right')!
|
|
|
|
|
rightDom.title = `右对齐(${isApple ? '⌘' : 'Ctrl'}+R)`
|
|
|
|
|
rightDom.onclick = function () {
|
|
|
|
|
console.log('right')
|
|
|
|
|
instance.command.executeRight()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const alignmentDom = document.querySelector<HTMLDivElement>('.menu-item__alignment')!
|
|
|
|
|
alignmentDom.title = `两端对齐(${isApple ? '⌘' : 'Ctrl'}+J)`
|
|
|
|
|
alignmentDom.onclick = function () {
|
|
|
|
|
console.log('alignment')
|
|
|
|
|
instance.command.executeAlignment()
|
|
|
|
|
@ -697,6 +713,7 @@ window.onload = function () {
|
|
|
|
|
const searchInputDom = document.querySelector<HTMLInputElement>('.menu-item__search__collapse__search input')!
|
|
|
|
|
const replaceInputDom = document.querySelector<HTMLInputElement>('.menu-item__search__collapse__replace input')!
|
|
|
|
|
const searchDom = document.querySelector<HTMLDivElement>('.menu-item__search')!
|
|
|
|
|
searchDom.title = `搜索与替换(${isApple ? '⌘' : 'Ctrl'}+F)`
|
|
|
|
|
const searchResultDom = searchCollapseDom.querySelector<HTMLLabelElement>('.search-result')!
|
|
|
|
|
function setSearchResult() {
|
|
|
|
|
const result = instance.command.getSearchNavigateInfo()
|
|
|
|
|
@ -754,7 +771,9 @@ window.onload = function () {
|
|
|
|
|
setSearchResult()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.querySelector<HTMLDivElement>('.menu-item__print')!.onclick = function () {
|
|
|
|
|
const printDom = document.querySelector<HTMLDivElement>('.menu-item__print')!
|
|
|
|
|
printDom.title = `打印(${isApple ? '⌘' : 'Ctrl'}+P)`
|
|
|
|
|
printDom.onclick = function () {
|
|
|
|
|
console.log('print')
|
|
|
|
|
instance.command.executePrint()
|
|
|
|
|
}
|
|
|
|
|
@ -1062,7 +1081,7 @@ window.onload = function () {
|
|
|
|
|
instance.register.shortcutList([
|
|
|
|
|
{
|
|
|
|
|
key: KeyMap.P,
|
|
|
|
|
ctrl: true,
|
|
|
|
|
mod: true,
|
|
|
|
|
isGlobal: true,
|
|
|
|
|
callback: (command: Command) => {
|
|
|
|
|
command.executePrint()
|
|
|
|
|
@ -1070,7 +1089,7 @@ window.onload = function () {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: KeyMap.F,
|
|
|
|
|
ctrl: true,
|
|
|
|
|
mod: true,
|
|
|
|
|
isGlobal: true,
|
|
|
|
|
callback: (command: Command) => {
|
|
|
|
|
const text = command.getRangeText()
|
|
|
|
|
|