-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
two-cell-anchor-xform.js
62 lines (51 loc) · 1.63 KB
/
two-cell-anchor-xform.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const BaseCellAnchorXform = require('./base-cell-anchor-xform');
const StaticXform = require('../static-xform');
const CellPositionXform = require('./cell-position-xform');
const PicXform = require('./pic-xform');
class TwoCellAnchorXform extends BaseCellAnchorXform {
constructor() {
super();
this.map = {
'xdr:from': new CellPositionXform({tag: 'xdr:from'}),
'xdr:to': new CellPositionXform({tag: 'xdr:to'}),
'xdr:pic': new PicXform(),
'xdr:clientData': new StaticXform({tag: 'xdr:clientData'}),
};
}
get tag() {
return 'xdr:twoCellAnchor';
}
prepare(model, options) {
this.map['xdr:pic'].prepare(model.picture, options);
}
render(xmlStream, model) {
xmlStream.openNode(this.tag, {editAs: model.range.editAs || 'oneCell'});
this.map['xdr:from'].render(xmlStream, model.range.tl);
this.map['xdr:to'].render(xmlStream, model.range.br);
this.map['xdr:pic'].render(xmlStream, model.picture);
this.map['xdr:clientData'].render(xmlStream, {});
xmlStream.closeNode();
}
parseClose(name) {
if (this.parser) {
if (!this.parser.parseClose(name)) {
this.parser = undefined;
}
return true;
}
switch (name) {
case this.tag:
this.model.range.tl = this.map['xdr:from'].model;
this.model.range.br = this.map['xdr:to'].model;
this.model.picture = this.map['xdr:pic'].model;
return false;
default:
// could be some unrecognised tags
return true;
}
}
reconcile(model, options) {
model.medium = this.reconcilePicture(model.picture, options);
}
}
module.exports = TwoCellAnchorXform;