fix:menu permissions

pr675
Hufe921 4 years ago
parent 193b9d7a41
commit 58849f763b

@ -262,6 +262,8 @@ export class CommandAdapt {
public superscript() {
const isReadonly = this.draw.isReadonly()
if (isReadonly) return
const activeControl = this.control.getActiveControl()
if (activeControl) return
const selection = this.range.getSelection()
if (!selection) return
const superscriptIndex = selection.findIndex(s => s.type === ElementType.SUPERSCRIPT)
@ -285,6 +287,8 @@ export class CommandAdapt {
public subscript() {
const isReadonly = this.draw.isReadonly()
if (isReadonly) return
const activeControl = this.control.getActiveControl()
if (activeControl) return
const selection = this.range.getSelection()
if (!selection) return
const subscriptIndex = selection.findIndex(s => s.type === ElementType.SUBSCRIPT)
@ -382,6 +386,8 @@ export class CommandAdapt {
public insertTable(row: number, col: number) {
const isReadonly = this.draw.isReadonly()
if (isReadonly) return
const activeControl = this.control.getActiveControl()
if (activeControl) return
const { startIndex, endIndex } = this.range.getRange()
if (!~startIndex && !~endIndex) return
const elementList = this.draw.getElementList()
@ -979,6 +985,8 @@ export class CommandAdapt {
public hyperlink(payload: IElement) {
const isReadonly = this.draw.isReadonly()
if (isReadonly) return
const activeControl = this.control.getActiveControl()
if (activeControl) return
const { startIndex, endIndex } = this.range.getRange()
if (!~startIndex && !~endIndex) return
const elementList = this.draw.getElementList()
@ -1005,6 +1013,8 @@ export class CommandAdapt {
public separator(payload: number[]) {
const isReadonly = this.draw.isReadonly()
if (isReadonly) return
const activeControl = this.control.getActiveControl()
if (activeControl) return
const { startIndex, endIndex } = this.range.getRange()
if (!~startIndex && !~endIndex) return
const elementList = this.draw.getElementList()
@ -1035,6 +1045,10 @@ export class CommandAdapt {
}
public pageBreak() {
const isReadonly = this.draw.isReadonly()
if (isReadonly) return
const activeControl = this.control.getActiveControl()
if (activeControl) return
this.insertElementList([{
type: ElementType.PAGE_BREAK,
value: WRAP
@ -1073,6 +1087,8 @@ export class CommandAdapt {
public image(payload: IDrawImagePayload) {
const isReadonly = this.draw.isReadonly()
if (isReadonly) return
const activeControl = this.control.getActiveControl()
if (activeControl) return
const { startIndex, endIndex } = this.range.getRange()
if (!~startIndex && !~endIndex) return
const elementList = this.draw.getElementList()
@ -1103,6 +1119,8 @@ export class CommandAdapt {
}
public replace(payload: string) {
const isReadonly = this.draw.isReadonly()
if (isReadonly) return
if (!payload || new RegExp(`${ZERO}`, 'g').test(payload)) return
const matchList = this.draw.getSearch().getSearchMatchList()
if (!matchList.length) return

@ -669,6 +669,25 @@ window.onload = function () {
document.querySelector<HTMLSpanElement>('.page-scale-percentage')!.innerText = `${Math.floor(payload * 10 * 10)}%`
}
instance.listener.controlChange = function (payload) {
const disableMenusInControlContext = [
'superscript',
'subscript',
'table',
'image',
'hyperlink',
'separator',
'codeblock',
'page-break',
'control'
]
// 菜单操作权限
disableMenusInControlContext.forEach(menu => {
const menuDom = document.querySelector<HTMLDivElement>(`.menu-item__${menu}`)!
payload ? menuDom.classList.add('disable') : menuDom.classList.remove('disable')
})
}
instance.listener.saved = function (payload) {
console.log('elementList: ', payload)
}

@ -172,6 +172,7 @@ ul {
color: #c0c4cc;
cursor: not-allowed;
opacity: 0.4;
pointer-events: none;
}
.menu-item__undo i {

Loading…
Cancel
Save