-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathFigure.js
44 lines (38 loc) · 1.05 KB
/
Figure.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
33
34
35
36
37
38
39
40
41
42
43
44
import { DocumentNode, CHILDREN } from 'substance'
import MetadataField from './MetadataField'
export default class Figure extends DocumentNode {
_initialize (...args) {
super._initialize(...args)
this.state = {
currentPanelIndex: 0
}
}
getCurrentPanelIndex () {
let currentPanelIndex = 0
if (this.state) {
currentPanelIndex = this.state.currentPanelIndex
}
return currentPanelIndex
}
getPanels () {
return this.resolve('panels')
}
// NOTE: we are using structure of active panel as template for new one,
// currently we are replicating the structure of metadata fields
getTemplateFromCurrentPanel () {
const currentIndex = this.getCurrentPanelIndex()
const firstPanel = this.getPanels()[currentIndex]
return {
metadata: firstPanel.resolve('metadata').map(metadataField => (
{ type: MetadataField.type, name: metadataField.name, value: '' }
))
}
}
static get refType () {
return 'fig'
}
}
Figure.schema = {
type: 'figure',
panels: CHILDREN('figure-panel')
}