@@ -78,6 +78,7 @@ export class Command {
|
|||||||
private static setPaperMargin: CommandAdapt['setPaperMargin']
|
private static setPaperMargin: CommandAdapt['setPaperMargin']
|
||||||
private static insertElementList: CommandAdapt['insertElementList']
|
private static insertElementList: CommandAdapt['insertElementList']
|
||||||
private static removeControl: CommandAdapt['removeControl']
|
private static removeControl: CommandAdapt['removeControl']
|
||||||
|
private static setLocale: CommandAdapt['setLocale']
|
||||||
|
|
||||||
constructor(adapt: CommandAdapt) {
|
constructor(adapt: CommandAdapt) {
|
||||||
Command.mode = adapt.mode.bind(adapt)
|
Command.mode = adapt.mode.bind(adapt)
|
||||||
@@ -149,6 +150,7 @@ export class Command {
|
|||||||
Command.setPaperMargin = adapt.setPaperMargin.bind(adapt)
|
Command.setPaperMargin = adapt.setPaperMargin.bind(adapt)
|
||||||
Command.insertElementList = adapt.insertElementList.bind(adapt)
|
Command.insertElementList = adapt.insertElementList.bind(adapt)
|
||||||
Command.removeControl = adapt.removeControl.bind(adapt)
|
Command.removeControl = adapt.removeControl.bind(adapt)
|
||||||
|
Command.setLocale = adapt.setLocale.bind(adapt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 全局命令
|
// 全局命令
|
||||||
@@ -433,4 +435,8 @@ export class Command {
|
|||||||
return Command.removeControl()
|
return Command.removeControl()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public executeSetLocale(payload: string) {
|
||||||
|
return Command.setLocale(payload)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,7 @@ import { INavigateInfo, Search } from '../draw/interactive/Search'
|
|||||||
import { TableTool } from '../draw/particle/table/TableTool'
|
import { TableTool } from '../draw/particle/table/TableTool'
|
||||||
import { CanvasEvent } from '../event/CanvasEvent'
|
import { CanvasEvent } from '../event/CanvasEvent'
|
||||||
import { HistoryManager } from '../history/HistoryManager'
|
import { HistoryManager } from '../history/HistoryManager'
|
||||||
|
import { I18n } from '../i18n/I18n'
|
||||||
import { Position } from '../position/Position'
|
import { Position } from '../position/Position'
|
||||||
import { RangeManager } from '../range/RangeManager'
|
import { RangeManager } from '../range/RangeManager'
|
||||||
import { WorkerManager } from '../worker/WorkerManager'
|
import { WorkerManager } from '../worker/WorkerManager'
|
||||||
@@ -42,6 +43,7 @@ export class CommandAdapt {
|
|||||||
private control: Control
|
private control: Control
|
||||||
private workerManager: WorkerManager
|
private workerManager: WorkerManager
|
||||||
private searchManager: Search
|
private searchManager: Search
|
||||||
|
private i18n: I18n
|
||||||
|
|
||||||
constructor(draw: Draw) {
|
constructor(draw: Draw) {
|
||||||
this.draw = draw
|
this.draw = draw
|
||||||
@@ -54,6 +56,7 @@ export class CommandAdapt {
|
|||||||
this.control = draw.getControl()
|
this.control = draw.getControl()
|
||||||
this.workerManager = draw.getWorkerManager()
|
this.workerManager = draw.getWorkerManager()
|
||||||
this.searchManager = draw.getSearch()
|
this.searchManager = draw.getSearch()
|
||||||
|
this.i18n = draw.getI18n()
|
||||||
}
|
}
|
||||||
|
|
||||||
public mode(payload: EditorMode) {
|
public mode(payload: EditorMode) {
|
||||||
@@ -1468,4 +1471,8 @@ export class CommandAdapt {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setLocale(payload: string) {
|
||||||
|
this.i18n.setLocale(payload)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import { IContextMenuContext, IRegisterContextMenu } from '../../interface/conte
|
|||||||
import { findParent } from '../../utils'
|
import { findParent } from '../../utils'
|
||||||
import { Command } from '../command/Command'
|
import { Command } from '../command/Command'
|
||||||
import { Draw } from '../draw/Draw'
|
import { Draw } from '../draw/Draw'
|
||||||
|
import { I18n } from '../i18n/I18n'
|
||||||
import { Position } from '../position/Position'
|
import { Position } from '../position/Position'
|
||||||
import { RangeManager } from '../range/RangeManager'
|
import { RangeManager } from '../range/RangeManager'
|
||||||
import { controlMenus } from './menus/controlMenus'
|
import { controlMenus } from './menus/controlMenus'
|
||||||
@@ -26,6 +27,7 @@ export class ContextMenu {
|
|||||||
private command: Command
|
private command: Command
|
||||||
private range: RangeManager
|
private range: RangeManager
|
||||||
private position: Position
|
private position: Position
|
||||||
|
private i18n: I18n
|
||||||
private container: HTMLDivElement
|
private container: HTMLDivElement
|
||||||
private contextMenuList: IRegisterContextMenu[]
|
private contextMenuList: IRegisterContextMenu[]
|
||||||
private contextMenuContainerList: HTMLDivElement[]
|
private contextMenuContainerList: HTMLDivElement[]
|
||||||
@@ -37,6 +39,7 @@ export class ContextMenu {
|
|||||||
this.command = command
|
this.command = command
|
||||||
this.range = draw.getRange()
|
this.range = draw.getRange()
|
||||||
this.position = draw.getPosition()
|
this.position = draw.getPosition()
|
||||||
|
this.i18n = draw.getI18n()
|
||||||
this.container = draw.getContainer()
|
this.container = draw.getContainer()
|
||||||
this.context = null
|
this.context = null
|
||||||
// 内部菜单
|
// 内部菜单
|
||||||
@@ -212,7 +215,9 @@ export class ContextMenu {
|
|||||||
}
|
}
|
||||||
// 文本
|
// 文本
|
||||||
const span = document.createElement('span')
|
const span = document.createElement('span')
|
||||||
const name = this._formatName(menu.name!)
|
const name = menu.i18nPath
|
||||||
|
? this._formatName(this.i18n.t(menu.i18nPath))
|
||||||
|
: this._formatName(menu.name || '')
|
||||||
span.append(document.createTextNode(name))
|
span.append(document.createTextNode(name))
|
||||||
menuItem.append(span)
|
menuItem.append(span)
|
||||||
// 快捷方式提示
|
// 快捷方式提示
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Command } from '../../command/Command'
|
|||||||
|
|
||||||
export const controlMenus: IRegisterContextMenu[] = [
|
export const controlMenus: IRegisterContextMenu[] = [
|
||||||
{
|
{
|
||||||
name: '删除控件',
|
i18nPath: 'contextmenu.control.delete',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return !payload.editorHasSelection && payload.startElement?.type === ElementType.CONTROL
|
return !payload.editorHasSelection && payload.startElement?.type === ElementType.CONTROL
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Command } from '../../command/Command'
|
|||||||
|
|
||||||
export const globalMenus: IRegisterContextMenu[] = [
|
export const globalMenus: IRegisterContextMenu[] = [
|
||||||
{
|
{
|
||||||
name: '剪切',
|
i18nPath: 'contextmenu.global.cut',
|
||||||
shortCut: 'Ctrl + X',
|
shortCut: 'Ctrl + X',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return !payload.isReadonly
|
return !payload.isReadonly
|
||||||
@@ -13,7 +13,7 @@ export const globalMenus: IRegisterContextMenu[] = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '复制',
|
i18nPath: 'contextmenu.global.copy',
|
||||||
shortCut: 'Ctrl + C',
|
shortCut: 'Ctrl + C',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return payload.editorHasSelection
|
return payload.editorHasSelection
|
||||||
@@ -23,7 +23,7 @@ export const globalMenus: IRegisterContextMenu[] = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '粘贴',
|
i18nPath: 'contextmenu.global.paste',
|
||||||
shortCut: 'Ctrl + V',
|
shortCut: 'Ctrl + V',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return !payload.isReadonly && payload.editorTextFocus
|
return !payload.isReadonly && payload.editorTextFocus
|
||||||
@@ -33,7 +33,7 @@ export const globalMenus: IRegisterContextMenu[] = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '全选',
|
i18nPath: 'contextmenu.global.selectAll',
|
||||||
shortCut: 'Ctrl + A',
|
shortCut: 'Ctrl + A',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return payload.editorTextFocus
|
return payload.editorTextFocus
|
||||||
@@ -46,8 +46,8 @@ export const globalMenus: IRegisterContextMenu[] = [
|
|||||||
isDivider: true
|
isDivider: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
i18nPath: 'contextmenu.global.print',
|
||||||
icon: 'print',
|
icon: 'print',
|
||||||
name: '打印',
|
|
||||||
when: () => true,
|
when: () => true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
command.executePrint()
|
command.executePrint()
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Command } from '../../command/Command'
|
|||||||
|
|
||||||
export const hyperlinkMenus: IRegisterContextMenu[] = [
|
export const hyperlinkMenus: IRegisterContextMenu[] = [
|
||||||
{
|
{
|
||||||
name: '删除链接',
|
i18nPath: 'contextmenu.hyperlink.delete',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return payload.startElement?.type === ElementType.HYPERLINK
|
return payload.startElement?.type === ElementType.HYPERLINK
|
||||||
},
|
},
|
||||||
@@ -13,7 +13,7 @@ export const hyperlinkMenus: IRegisterContextMenu[] = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '取消链接',
|
i18nPath: 'contextmenu.hyperlink.cancel',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return payload.startElement?.type === ElementType.HYPERLINK
|
return payload.startElement?.type === ElementType.HYPERLINK
|
||||||
},
|
},
|
||||||
@@ -22,7 +22,7 @@ export const hyperlinkMenus: IRegisterContextMenu[] = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '编辑链接',
|
i18nPath: 'contextmenu.hyperlink.edit',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return payload.startElement?.type === ElementType.HYPERLINK
|
return payload.startElement?.type === ElementType.HYPERLINK
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Command } from '../../command/Command'
|
|||||||
|
|
||||||
export const imageMenus: IRegisterContextMenu[] = [
|
export const imageMenus: IRegisterContextMenu[] = [
|
||||||
{
|
{
|
||||||
name: '更改图片',
|
i18nPath: 'contextmenu.image.change',
|
||||||
icon: 'image-change',
|
icon: 'image-change',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return !payload.editorHasSelection && payload.startElement?.type === ElementType.IMAGE
|
return !payload.editorHasSelection && payload.startElement?.type === ElementType.IMAGE
|
||||||
@@ -29,7 +29,7 @@ export const imageMenus: IRegisterContextMenu[] = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '另存为图片',
|
i18nPath: 'contextmenu.image.saveAs',
|
||||||
icon: 'image',
|
icon: 'image',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return !payload.editorHasSelection && payload.startElement?.type === ElementType.IMAGE
|
return !payload.editorHasSelection && payload.startElement?.type === ElementType.IMAGE
|
||||||
@@ -39,20 +39,20 @@ export const imageMenus: IRegisterContextMenu[] = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '文字环绕',
|
i18nPath: 'contextmenu.image.textWrap',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return !payload.editorHasSelection && payload.startElement?.type === ElementType.IMAGE
|
return !payload.editorHasSelection && payload.startElement?.type === ElementType.IMAGE
|
||||||
},
|
},
|
||||||
childMenus: [
|
childMenus: [
|
||||||
{
|
{
|
||||||
name: '嵌入型',
|
i18nPath: 'contextmenu.image.textWrapType.embed',
|
||||||
when: () => true,
|
when: () => true,
|
||||||
callback: (command: Command, context: IContextMenuContext) => {
|
callback: (command: Command, context: IContextMenuContext) => {
|
||||||
command.executeChangeImageDisplay(context.startElement!, ImageDisplay.BLOCK)
|
command.executeChangeImageDisplay(context.startElement!, ImageDisplay.BLOCK)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '上下型环绕',
|
i18nPath: 'contextmenu.image.textWrapType.upDown',
|
||||||
when: () => true,
|
when: () => true,
|
||||||
callback: (command: Command, context: IContextMenuContext) => {
|
callback: (command: Command, context: IContextMenuContext) => {
|
||||||
command.executeChangeImageDisplay(context.startElement!, ImageDisplay.INLINE)
|
command.executeChangeImageDisplay(context.startElement!, ImageDisplay.INLINE)
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ export const tableMenus: IRegisterContextMenu[] = [
|
|||||||
isDivider: true
|
isDivider: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '插入行列',
|
i18nPath: 'contextmenu.table.insertRowCol',
|
||||||
icon: 'insert-row-col',
|
icon: 'insert-row-col',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return !payload.isReadonly && payload.isInTable
|
return !payload.isReadonly && payload.isInTable
|
||||||
},
|
},
|
||||||
childMenus: [
|
childMenus: [
|
||||||
{
|
{
|
||||||
name: '上方插入1行',
|
i18nPath: 'contextmenu.table.insertTopRow',
|
||||||
icon: 'insert-top-row',
|
icon: 'insert-top-row',
|
||||||
when: () => true,
|
when: () => true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
@@ -21,7 +21,7 @@ export const tableMenus: IRegisterContextMenu[] = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '下方插入1行',
|
i18nPath: 'contextmenu.table.insertBottomRow',
|
||||||
icon: 'insert-bottom-row',
|
icon: 'insert-bottom-row',
|
||||||
when: () => true,
|
when: () => true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
@@ -29,7 +29,7 @@ export const tableMenus: IRegisterContextMenu[] = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '左侧插入1列',
|
i18nPath: 'contextmenu.table.insertLeftCol',
|
||||||
icon: 'insert-left-col',
|
icon: 'insert-left-col',
|
||||||
when: () => true,
|
when: () => true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
@@ -37,7 +37,7 @@ export const tableMenus: IRegisterContextMenu[] = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '右侧插入1列',
|
i18nPath: 'contextmenu.table.insertRightCol',
|
||||||
icon: 'insert-right-col',
|
icon: 'insert-right-col',
|
||||||
when: () => true,
|
when: () => true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
@@ -47,14 +47,14 @@ export const tableMenus: IRegisterContextMenu[] = [
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '删除行列',
|
i18nPath: 'contextmenu.table.deleteRowCol',
|
||||||
icon: 'delete-row-col',
|
icon: 'delete-row-col',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return !payload.isReadonly && payload.isInTable
|
return !payload.isReadonly && payload.isInTable
|
||||||
},
|
},
|
||||||
childMenus: [
|
childMenus: [
|
||||||
{
|
{
|
||||||
name: '删除1行',
|
i18nPath: 'contextmenu.table.deleteRow',
|
||||||
icon: 'delete-row',
|
icon: 'delete-row',
|
||||||
when: () => true,
|
when: () => true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
@@ -62,7 +62,7 @@ export const tableMenus: IRegisterContextMenu[] = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '删除一列',
|
i18nPath: 'contextmenu.table.deleteCol',
|
||||||
icon: 'delete-col',
|
icon: 'delete-col',
|
||||||
when: () => true,
|
when: () => true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
@@ -70,7 +70,7 @@ export const tableMenus: IRegisterContextMenu[] = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '删除整个表格',
|
i18nPath: 'contextmenu.table.deleteTable',
|
||||||
icon: 'delete-table',
|
icon: 'delete-table',
|
||||||
when: () => true,
|
when: () => true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
@@ -80,7 +80,7 @@ export const tableMenus: IRegisterContextMenu[] = [
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '合并单元格',
|
i18nPath: 'contextmenu.table.mergeCell',
|
||||||
icon: 'merge-cell',
|
icon: 'merge-cell',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return !payload.isReadonly && payload.isCrossRowCol
|
return !payload.isReadonly && payload.isCrossRowCol
|
||||||
@@ -90,7 +90,7 @@ export const tableMenus: IRegisterContextMenu[] = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '取消合并',
|
i18nPath: 'contextmenu.table.mergeCancelCell',
|
||||||
icon: 'merge-cancel-cell',
|
icon: 'merge-cancel-cell',
|
||||||
when: (payload) => {
|
when: (payload) => {
|
||||||
return !payload.isReadonly && payload.isInTable
|
return !payload.isReadonly && payload.isInTable
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import { DateParticle } from './particle/date/DateParticle'
|
|||||||
import { IMargin } from '../../interface/Margin'
|
import { IMargin } from '../../interface/Margin'
|
||||||
import { BlockParticle } from './particle/block/BlockParticle'
|
import { BlockParticle } from './particle/block/BlockParticle'
|
||||||
import { EDITOR_COMPONENT, EDITOR_PREFIX } from '../../dataset/constant/Editor'
|
import { EDITOR_COMPONENT, EDITOR_PREFIX } from '../../dataset/constant/Editor'
|
||||||
|
import { I18n } from '../i18n/I18n'
|
||||||
|
|
||||||
export class Draw {
|
export class Draw {
|
||||||
|
|
||||||
@@ -62,6 +63,7 @@ export class Draw {
|
|||||||
private elementList: IElement[]
|
private elementList: IElement[]
|
||||||
private listener: Listener
|
private listener: Listener
|
||||||
|
|
||||||
|
private i18n: I18n
|
||||||
private canvasEvent: CanvasEvent
|
private canvasEvent: CanvasEvent
|
||||||
private globalEvent: GlobalEvent
|
private globalEvent: GlobalEvent
|
||||||
private cursor: Cursor
|
private cursor: Cursor
|
||||||
@@ -120,6 +122,7 @@ export class Draw {
|
|||||||
this.pageContainer = this._createPageContainer()
|
this.pageContainer = this._createPageContainer()
|
||||||
this._createPage(0)
|
this._createPage(0)
|
||||||
|
|
||||||
|
this.i18n = new I18n()
|
||||||
this.historyManager = new HistoryManager()
|
this.historyManager = new HistoryManager()
|
||||||
this.position = new Position(this)
|
this.position = new Position(this)
|
||||||
this.range = new RangeManager(this)
|
this.range = new RangeManager(this)
|
||||||
@@ -399,6 +402,10 @@ export class Draw {
|
|||||||
return this.workerManager
|
return this.workerManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getI18n(): I18n {
|
||||||
|
return this.i18n
|
||||||
|
}
|
||||||
|
|
||||||
public getRowCount(): number {
|
public getRowCount(): number {
|
||||||
return this.rowList.length
|
return this.rowList.length
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,31 @@ export class DateParticle {
|
|||||||
constructor(draw: Draw) {
|
constructor(draw: Draw) {
|
||||||
this.draw = draw
|
this.draw = draw
|
||||||
this.range = draw.getRange()
|
this.range = draw.getRange()
|
||||||
|
const i18n = draw.getI18n()
|
||||||
|
const t = i18n.t.bind(i18n)
|
||||||
this.datePicker = new DatePicker({
|
this.datePicker = new DatePicker({
|
||||||
mountDom: draw.getContainer(),
|
mountDom: draw.getContainer(),
|
||||||
onSubmit: this._setValue.bind(this)
|
onSubmit: this._setValue.bind(this),
|
||||||
|
getLang: () => ({
|
||||||
|
now: t('datePicker.now'),
|
||||||
|
confirm: t('datePicker.confirm'),
|
||||||
|
return: t('datePicker.return'),
|
||||||
|
timeSelect: t('datePicker.timeSelect'),
|
||||||
|
weeks: {
|
||||||
|
sun: t('datePicker.weeks.sun'),
|
||||||
|
mon: t('datePicker.weeks.mon'),
|
||||||
|
tue: t('datePicker.weeks.tue'),
|
||||||
|
wed: t('datePicker.weeks.wed'),
|
||||||
|
thu: t('datePicker.weeks.thu'),
|
||||||
|
fri: t('datePicker.weeks.fri'),
|
||||||
|
sat: t('datePicker.weeks.sat'),
|
||||||
|
},
|
||||||
|
year: t('datePicker.year'),
|
||||||
|
month: t('datePicker.month'),
|
||||||
|
hour: t('datePicker.hour'),
|
||||||
|
minute: t('datePicker.minute'),
|
||||||
|
second: t('datePicker.second')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,38 @@
|
|||||||
import { EDITOR_PREFIX } from '../../../../dataset/constant/Editor'
|
import { EDITOR_PREFIX } from '../../../../dataset/constant/Editor'
|
||||||
import { IElement, IElementPosition } from '../../../../interface/Element'
|
import { IElement, IElementPosition } from '../../../../interface/Element'
|
||||||
|
import { datePicker } from '../../../i18n/lang/zh-CN.json'
|
||||||
|
|
||||||
|
export interface IDatePickerLang {
|
||||||
|
now: string;
|
||||||
|
confirm: string;
|
||||||
|
return: string;
|
||||||
|
timeSelect: string;
|
||||||
|
weeks: {
|
||||||
|
sun: string;
|
||||||
|
mon: string;
|
||||||
|
tue: string;
|
||||||
|
wed: string;
|
||||||
|
thu: string;
|
||||||
|
fri: string;
|
||||||
|
sat: string;
|
||||||
|
};
|
||||||
|
year: string;
|
||||||
|
month: string;
|
||||||
|
hour: string;
|
||||||
|
minute: string;
|
||||||
|
second: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IDatePickerOption {
|
export interface IDatePickerOption {
|
||||||
mountDom?: HTMLElement;
|
mountDom?: HTMLElement;
|
||||||
onSubmit?: (date: string) => any;
|
onSubmit?: (date: string) => any;
|
||||||
|
getLang?: () => IDatePickerLang
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IDatePickerDom {
|
interface IDatePickerDom {
|
||||||
container: HTMLDivElement;
|
container: HTMLDivElement;
|
||||||
dateWrap: HTMLDivElement;
|
dateWrap: HTMLDivElement;
|
||||||
|
datePickerWeek: HTMLDivElement;
|
||||||
timeWrap: HTMLUListElement;
|
timeWrap: HTMLUListElement;
|
||||||
title: {
|
title: {
|
||||||
preYear: HTMLSpanElement;
|
preYear: HTMLSpanElement;
|
||||||
@@ -45,12 +69,14 @@ export class DatePicker {
|
|||||||
private renderOptions: IRenderOption | null
|
private renderOptions: IRenderOption | null
|
||||||
private isDatePicker: boolean
|
private isDatePicker: boolean
|
||||||
private pickDate: Date | null
|
private pickDate: Date | null
|
||||||
|
private lang: IDatePickerLang
|
||||||
|
|
||||||
constructor(options: IDatePickerOption = {}) {
|
constructor(options: IDatePickerOption = {}) {
|
||||||
this.options = {
|
this.options = {
|
||||||
mountDom: document.body,
|
mountDom: document.body,
|
||||||
...options
|
...options
|
||||||
}
|
}
|
||||||
|
this.lang = datePicker
|
||||||
this.now = new Date()
|
this.now = new Date()
|
||||||
this.dom = this._createDom()
|
this.dom = this._createDom()
|
||||||
this.renderOptions = null
|
this.renderOptions = null
|
||||||
@@ -89,7 +115,8 @@ export class DatePicker {
|
|||||||
// week-星期显示
|
// week-星期显示
|
||||||
const datePickerWeek = document.createElement('div')
|
const datePickerWeek = document.createElement('div')
|
||||||
datePickerWeek.classList.add(`${EDITOR_PREFIX}-date-week`)
|
datePickerWeek.classList.add(`${EDITOR_PREFIX}-date-week`)
|
||||||
const weekList = ['日', '一', '二', '三', '四', '五', '六']
|
const { weeks: { sun, mon, tue, wed, thu, fri, sat } } = this.lang
|
||||||
|
const weekList = [sun, mon, tue, wed, thu, fri, sat]
|
||||||
weekList.forEach(week => {
|
weekList.forEach(week => {
|
||||||
const weekDom = document.createElement('span')
|
const weekDom = document.createElement('span')
|
||||||
weekDom.innerText = `${week}`
|
weekDom.innerText = `${week}`
|
||||||
@@ -108,7 +135,7 @@ export class DatePicker {
|
|||||||
let hourTime: HTMLOListElement
|
let hourTime: HTMLOListElement
|
||||||
let minuteTime: HTMLOListElement
|
let minuteTime: HTMLOListElement
|
||||||
let secondTime: HTMLOListElement
|
let secondTime: HTMLOListElement
|
||||||
const timeList = ['时', '分', '秒']
|
const timeList = [this.lang.hour, this.lang.minute, this.lang.second]
|
||||||
timeList.forEach((t, i) => {
|
timeList.forEach((t, i) => {
|
||||||
const li = document.createElement('li')
|
const li = document.createElement('li')
|
||||||
const timeText = document.createElement('span')
|
const timeText = document.createElement('span')
|
||||||
@@ -139,13 +166,13 @@ export class DatePicker {
|
|||||||
datePickerMenu.classList.add(`${EDITOR_PREFIX}-date-menu`)
|
datePickerMenu.classList.add(`${EDITOR_PREFIX}-date-menu`)
|
||||||
const timeMenu = document.createElement('button')
|
const timeMenu = document.createElement('button')
|
||||||
timeMenu.classList.add(`${EDITOR_PREFIX}-date-menu__time`)
|
timeMenu.classList.add(`${EDITOR_PREFIX}-date-menu__time`)
|
||||||
timeMenu.innerText = '时间选择'
|
timeMenu.innerText = this.lang.timeSelect
|
||||||
const nowMenu = document.createElement('button')
|
const nowMenu = document.createElement('button')
|
||||||
nowMenu.classList.add(`${EDITOR_PREFIX}-date-menu__now`)
|
nowMenu.classList.add(`${EDITOR_PREFIX}-date-menu__now`)
|
||||||
nowMenu.innerText = '此刻'
|
nowMenu.innerText = this.lang.now
|
||||||
const submitMenu = document.createElement('button')
|
const submitMenu = document.createElement('button')
|
||||||
submitMenu.classList.add(`${EDITOR_PREFIX}-date-menu__submit`)
|
submitMenu.classList.add(`${EDITOR_PREFIX}-date-menu__submit`)
|
||||||
submitMenu.innerText = '确定'
|
submitMenu.innerText = this.lang.confirm
|
||||||
datePickerMenu.append(timeMenu)
|
datePickerMenu.append(timeMenu)
|
||||||
datePickerMenu.append(nowMenu)
|
datePickerMenu.append(nowMenu)
|
||||||
datePickerMenu.append(submitMenu)
|
datePickerMenu.append(submitMenu)
|
||||||
@@ -157,6 +184,7 @@ export class DatePicker {
|
|||||||
return {
|
return {
|
||||||
container: datePickerContainer,
|
container: datePickerContainer,
|
||||||
dateWrap,
|
dateWrap,
|
||||||
|
datePickerWeek,
|
||||||
timeWrap,
|
timeWrap,
|
||||||
title: {
|
title: {
|
||||||
preYear: preYearTitle,
|
preYear: preYearTitle,
|
||||||
@@ -261,6 +289,23 @@ export class DatePicker {
|
|||||||
this.pickDate = new Date(this.now)
|
this.pickDate = new Date(this.now)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _setLang() {
|
||||||
|
this.dom.menu.time.innerText = this.lang.timeSelect
|
||||||
|
this.dom.menu.now.innerText = this.lang.now
|
||||||
|
this.dom.menu.submit.innerText = this.lang.confirm
|
||||||
|
const { weeks: { sun, mon, tue, wed, thu, fri, sat } } = this.lang
|
||||||
|
const weekList = [sun, mon, tue, wed, thu, fri, sat]
|
||||||
|
this.dom.datePickerWeek.childNodes.forEach((child, i) => {
|
||||||
|
(<HTMLSpanElement>child).innerText = weekList[i]
|
||||||
|
})
|
||||||
|
const hourTitle = (<HTMLSpanElement>this.dom.time.hour.previousElementSibling)
|
||||||
|
hourTitle.innerText = this.lang.hour
|
||||||
|
const minuteTitle = (<HTMLSpanElement>this.dom.time.minute.previousElementSibling)
|
||||||
|
minuteTitle.innerText = this.lang.minute
|
||||||
|
const secondTitle = (<HTMLSpanElement>this.dom.time.second.previousElementSibling)
|
||||||
|
secondTitle.innerText = this.lang.second
|
||||||
|
}
|
||||||
|
|
||||||
private _update() {
|
private _update() {
|
||||||
// 本地年月日
|
// 本地年月日
|
||||||
const localDate = new Date()
|
const localDate = new Date()
|
||||||
@@ -279,7 +324,7 @@ export class DatePicker {
|
|||||||
// 当前年月日
|
// 当前年月日
|
||||||
const year = this.now.getFullYear()
|
const year = this.now.getFullYear()
|
||||||
const month = this.now.getMonth() + 1
|
const month = this.now.getMonth() + 1
|
||||||
this.dom.title.now.innerText = `${year}年 ${String(month).padStart(2, '0')}月`
|
this.dom.title.now.innerText = `${year}${this.lang.year} ${String(month).padStart(2, '0')}${this.lang.month}`
|
||||||
// 日期补差
|
// 日期补差
|
||||||
const curDate = new Date(year, month, 0) // 当月日期
|
const curDate = new Date(year, month, 0) // 当月日期
|
||||||
const curDay = curDate.getDate() // 当月总天数
|
const curDay = curDate.getDate() // 当月总天数
|
||||||
@@ -338,11 +383,11 @@ export class DatePicker {
|
|||||||
if (this.isDatePicker) {
|
if (this.isDatePicker) {
|
||||||
this.dom.dateWrap.classList.add('active')
|
this.dom.dateWrap.classList.add('active')
|
||||||
this.dom.timeWrap.classList.remove('active')
|
this.dom.timeWrap.classList.remove('active')
|
||||||
this.dom.menu.time.innerText = `时间选择`
|
this.dom.menu.time.innerText = this.lang.timeSelect
|
||||||
} else {
|
} else {
|
||||||
this.dom.dateWrap.classList.remove('active')
|
this.dom.dateWrap.classList.remove('active')
|
||||||
this.dom.timeWrap.classList.add('active')
|
this.dom.timeWrap.classList.add('active')
|
||||||
this.dom.menu.time.innerText = `返回日期`
|
this.dom.menu.time.innerText = this.lang.return
|
||||||
// 设置时分秒选择
|
// 设置时分秒选择
|
||||||
this._setTimePick()
|
this._setTimePick()
|
||||||
}
|
}
|
||||||
@@ -467,6 +512,10 @@ export class DatePicker {
|
|||||||
|
|
||||||
public render(option: IRenderOption) {
|
public render(option: IRenderOption) {
|
||||||
this.renderOptions = option
|
this.renderOptions = option
|
||||||
|
if (this.options.getLang) {
|
||||||
|
this.lang = this.options.getLang()
|
||||||
|
this._setLang()
|
||||||
|
}
|
||||||
this._setValue()
|
this._setValue()
|
||||||
this._update()
|
this._update()
|
||||||
this._setPosition()
|
this._setPosition()
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { ILang } from '../../interface/i18n/I18n'
|
||||||
|
import zhCN from './lang/zh-CN.json'
|
||||||
|
import en from './lang/en.json'
|
||||||
|
|
||||||
|
export class I18n {
|
||||||
|
|
||||||
|
private langMap: Map<string, ILang> = new Map([
|
||||||
|
['zhCN', zhCN],
|
||||||
|
['en', en]
|
||||||
|
])
|
||||||
|
|
||||||
|
private currentLocale = 'zhCN'
|
||||||
|
|
||||||
|
public registerLangMap(locale: string, lang: ILang) {
|
||||||
|
this.langMap.set(locale, lang)
|
||||||
|
}
|
||||||
|
|
||||||
|
public setLocale(locale: string) {
|
||||||
|
this.currentLocale = locale
|
||||||
|
}
|
||||||
|
|
||||||
|
public getLang(): ILang {
|
||||||
|
return this.langMap.get(this.currentLocale) || zhCN
|
||||||
|
}
|
||||||
|
|
||||||
|
public t(path: string): string {
|
||||||
|
const keyList = path.split('.')
|
||||||
|
let value = ''
|
||||||
|
let item = this.getLang()
|
||||||
|
for (let k = 0; k < keyList.length; k++) {
|
||||||
|
const key = keyList[k]
|
||||||
|
const currentValue = Reflect.get(item, key)
|
||||||
|
if (currentValue) {
|
||||||
|
value = item = currentValue
|
||||||
|
} else {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"contextmenu": {
|
||||||
|
"global": {
|
||||||
|
"cut": "Cut",
|
||||||
|
"copy": "Copy",
|
||||||
|
"paste": "Paste",
|
||||||
|
"selectAll": "Select all",
|
||||||
|
"print": "Print"
|
||||||
|
},
|
||||||
|
"control": {
|
||||||
|
"delete": "Delete control"
|
||||||
|
},
|
||||||
|
"hyperlink": {
|
||||||
|
"delete": "Delete hyperlink",
|
||||||
|
"cancel": "Cancel hyperlink",
|
||||||
|
"edit": "Edit hyperlink"
|
||||||
|
},
|
||||||
|
"image": {
|
||||||
|
"change": "Change image",
|
||||||
|
"saveAs": "Save as image",
|
||||||
|
"textWrap": "Text wrap",
|
||||||
|
"textWrapType": {
|
||||||
|
"embed": "Embed",
|
||||||
|
"upDown": "Up down"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"table": {
|
||||||
|
"insertRowCol": "Insert row col",
|
||||||
|
"insertTopRow": "Insert top 1 row",
|
||||||
|
"insertBottomRow": "Insert bottom 1 row",
|
||||||
|
"insertLeftCol": "Insert left 1 col",
|
||||||
|
"insertRightCol": "Insert right 1 col",
|
||||||
|
"deleteRowCol": "Delete row col",
|
||||||
|
"deleteRow": "Delete 1 row",
|
||||||
|
"deleteCol": "Delete 1 col",
|
||||||
|
"deleteTable": "Delete table",
|
||||||
|
"mergeCell": "Merge cell",
|
||||||
|
"mergeCancelCell": "Cancel merge cell"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"datePicker": {
|
||||||
|
"now": "Now",
|
||||||
|
"confirm": "Confirm",
|
||||||
|
"return": "Return",
|
||||||
|
"timeSelect": "Time select",
|
||||||
|
"weeks": {
|
||||||
|
"sun": "Sun",
|
||||||
|
"mon": "Mon",
|
||||||
|
"tue": "Tue",
|
||||||
|
"wed": "Wed",
|
||||||
|
"thu": "Thu",
|
||||||
|
"fri": "Fri",
|
||||||
|
"sat": "Sat"
|
||||||
|
},
|
||||||
|
"year": " ",
|
||||||
|
"month": " ",
|
||||||
|
"hour": "Hour",
|
||||||
|
"minute": "Minute",
|
||||||
|
"second": "Second"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"contextmenu": {
|
||||||
|
"global": {
|
||||||
|
"cut": "剪切",
|
||||||
|
"copy": "复制",
|
||||||
|
"paste": "粘贴",
|
||||||
|
"selectAll": "全选",
|
||||||
|
"print": "打印"
|
||||||
|
},
|
||||||
|
"control": {
|
||||||
|
"delete": "删除控件"
|
||||||
|
},
|
||||||
|
"hyperlink": {
|
||||||
|
"delete": "删除链接",
|
||||||
|
"cancel": "取消链接",
|
||||||
|
"edit": "编辑链接"
|
||||||
|
},
|
||||||
|
"image": {
|
||||||
|
"change": "更改图片",
|
||||||
|
"saveAs": "另存为图片",
|
||||||
|
"textWrap": "文字环绕",
|
||||||
|
"textWrapType": {
|
||||||
|
"embed": "嵌入型",
|
||||||
|
"upDown": "上下型环绕"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"table": {
|
||||||
|
"insertRowCol": "插入行列",
|
||||||
|
"insertTopRow": "上方插入1行",
|
||||||
|
"insertBottomRow": "下方插入1行",
|
||||||
|
"insertLeftCol": "左侧插入1列",
|
||||||
|
"insertRightCol": "右侧插入1列",
|
||||||
|
"deleteRowCol": "删除行列",
|
||||||
|
"deleteRow": "删除1行",
|
||||||
|
"deleteCol": "删除1列",
|
||||||
|
"deleteTable": "删除整个表格",
|
||||||
|
"mergeCell": "合并单元格",
|
||||||
|
"mergeCancelCell": "取消合并"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"datePicker": {
|
||||||
|
"now": "此刻",
|
||||||
|
"confirm": "确定",
|
||||||
|
"return": "返回日期",
|
||||||
|
"timeSelect": "时间选择",
|
||||||
|
"weeks": {
|
||||||
|
"sun": "日",
|
||||||
|
"mon": "一",
|
||||||
|
"tue": "二",
|
||||||
|
"wed": "三",
|
||||||
|
"thu": "四",
|
||||||
|
"fri": "五",
|
||||||
|
"sat": "六"
|
||||||
|
},
|
||||||
|
"year": "年",
|
||||||
|
"month": "月",
|
||||||
|
"hour": "时",
|
||||||
|
"minute": "分",
|
||||||
|
"second": "秒"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,21 +2,26 @@ import { IRegisterContextMenu } from '../../interface/contextmenu/ContextMenu'
|
|||||||
import { IRegisterShortcut } from '../../interface/shortcut/Shortcut'
|
import { IRegisterShortcut } from '../../interface/shortcut/Shortcut'
|
||||||
import { ContextMenu } from '../contextmenu/ContextMenu'
|
import { ContextMenu } from '../contextmenu/ContextMenu'
|
||||||
import { Shortcut } from '../shortcut/Shortcut'
|
import { Shortcut } from '../shortcut/Shortcut'
|
||||||
|
import { I18n } from '../i18n/I18n'
|
||||||
|
import { ILang } from '../../interface/i18n/I18n'
|
||||||
|
|
||||||
interface IRegisterPayload {
|
interface IRegisterPayload {
|
||||||
contextMenu: ContextMenu;
|
contextMenu: ContextMenu;
|
||||||
shortcut: Shortcut;
|
shortcut: Shortcut;
|
||||||
|
i18n: I18n;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Register {
|
export class Register {
|
||||||
|
|
||||||
public contextMenuList: (payload: IRegisterContextMenu[]) => void
|
public contextMenuList: (payload: IRegisterContextMenu[]) => void
|
||||||
public shortcutList: (payload: IRegisterShortcut[]) => void
|
public shortcutList: (payload: IRegisterShortcut[]) => void
|
||||||
|
public langMap: (locale: string, lang: ILang) => void
|
||||||
|
|
||||||
constructor(payload: IRegisterPayload) {
|
constructor(payload: IRegisterPayload) {
|
||||||
const { contextMenu, shortcut } = payload
|
const { contextMenu, shortcut, i18n } = payload
|
||||||
this.contextMenuList = contextMenu.registerContextMenuList.bind(contextMenu)
|
this.contextMenuList = contextMenu.registerContextMenuList.bind(contextMenu)
|
||||||
this.shortcutList = shortcut.registerShortcutList.bind(shortcut)
|
this.shortcutList = shortcut.registerShortcutList.bind(shortcut)
|
||||||
|
this.langMap = i18n.registerLangMap.bind(i18n)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+5
-2
@@ -28,6 +28,7 @@ import { Shortcut } from './core/shortcut/Shortcut'
|
|||||||
import { KeyMap } from './dataset/enum/KeyMap'
|
import { KeyMap } from './dataset/enum/KeyMap'
|
||||||
import { BlockType } from './dataset/enum/Block'
|
import { BlockType } from './dataset/enum/Block'
|
||||||
import { IBlock } from './interface/Block'
|
import { IBlock } from './interface/Block'
|
||||||
|
import { ILang } from './interface/i18n/I18n'
|
||||||
|
|
||||||
export default class Editor {
|
export default class Editor {
|
||||||
|
|
||||||
@@ -110,7 +111,8 @@ export default class Editor {
|
|||||||
// 注册
|
// 注册
|
||||||
this.register = new Register({
|
this.register = new Register({
|
||||||
contextMenu,
|
contextMenu,
|
||||||
shortcut
|
shortcut,
|
||||||
|
i18n: draw.getI18n()
|
||||||
})
|
})
|
||||||
// 注册销毁方法
|
// 注册销毁方法
|
||||||
this.destroy = () => {
|
this.destroy = () => {
|
||||||
@@ -147,5 +149,6 @@ export type {
|
|||||||
IRegisterContextMenu,
|
IRegisterContextMenu,
|
||||||
IWatermark,
|
IWatermark,
|
||||||
INavigateInfo,
|
INavigateInfo,
|
||||||
IBlock
|
IBlock,
|
||||||
|
ILang
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ export interface IContextMenuContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IRegisterContextMenu {
|
export interface IRegisterContextMenu {
|
||||||
|
i18nPath?: string;
|
||||||
isDivider?: boolean;
|
isDivider?: boolean;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
@@ -20,3 +21,43 @@ export interface IRegisterContextMenu {
|
|||||||
callback?: (command: Command, context: IContextMenuContext) => any;
|
callback?: (command: Command, context: IContextMenuContext) => any;
|
||||||
childMenus?: IRegisterContextMenu[];
|
childMenus?: IRegisterContextMenu[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IContextmenuLang {
|
||||||
|
global: {
|
||||||
|
cut: string;
|
||||||
|
copy: string;
|
||||||
|
paste: string;
|
||||||
|
selectAll: string;
|
||||||
|
print: string;
|
||||||
|
};
|
||||||
|
control: {
|
||||||
|
delete: string;
|
||||||
|
};
|
||||||
|
hyperlink: {
|
||||||
|
delete: string;
|
||||||
|
cancel: string;
|
||||||
|
edit: string;
|
||||||
|
};
|
||||||
|
image: {
|
||||||
|
change: string;
|
||||||
|
saveAs: string;
|
||||||
|
textWrap: string;
|
||||||
|
textWrapType: {
|
||||||
|
embed: string;
|
||||||
|
upDown: string;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
table: {
|
||||||
|
insertRowCol: string;
|
||||||
|
insertTopRow: string;
|
||||||
|
insertBottomRow: string;
|
||||||
|
insertLeftCol: string;
|
||||||
|
insertRightCol: string;
|
||||||
|
deleteRowCol: string;
|
||||||
|
deleteRow: string;
|
||||||
|
deleteCol: string;
|
||||||
|
deleteTable: string;
|
||||||
|
mergeCell: string;
|
||||||
|
mergeCancelCell: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { IDatePickerLang } from '../../core/draw/particle/date/DatePicker'
|
||||||
|
import { IContextmenuLang } from '../contextmenu/ContextMenu'
|
||||||
|
|
||||||
|
export interface ILang {
|
||||||
|
contextmenu: IContextmenuLang;
|
||||||
|
datePicker: IDatePickerLang;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user