-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathInsertFootnoteCommand.js
32 lines (29 loc) · 1.07 KB
/
InsertFootnoteCommand.js
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
import { findParentByType } from '../shared/nodeHelpers'
import AddEntityCommand from './AddEntityCommand'
export default class InsertFootnoteCommand extends AddEntityCommand {
detectScope (params) {
const xpath = params.selectionState.xpath
return xpath.find(n => n.type === 'table-figure') ? 'table-figure' : 'default'
}
_getCollectionPath (params, context) {
const scope = this.detectScope(params)
if (scope === 'default') {
return ['article', 'footnotes']
} else {
const doc = params.editorSession.getDocument()
const nodeId = params.selection.getNodeId()
const node = doc.get(nodeId)
let tableNodeId = node.id
// check if we are already selected table-figure
if (node.type !== 'table-figure') {
const parentTable = findParentByType(node, 'table-figure')
tableNodeId = parentTable.id
}
return [tableNodeId, 'footnotes']
}
}
execute (params, context) {
let footnoteCollectionPath = this._getCollectionPath(params, context)
context.api.addFootnote(footnoteCollectionPath)
}
}