-
Notifications
You must be signed in to change notification settings - Fork 0
/
HFlex.js
72 lines (68 loc) · 2.05 KB
/
HFlex.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
63
64
65
66
67
68
69
70
71
72
var compose = require('ksf/utils/compose');
var _Destroyable = require('ksf/base/_Destroyable');
var delegateGetSet = require('./utils/delegateGetSet');
var defaults = require('lodash/object/defaults')
var Flex = require('./layout/Flex');
var Full = require('./layout/Full');
var FullMax = require('./layout/FullMax');
var ZFlat = require('./layout/ZFlat');
var Container = require('./Container');
function getCmp (arg) {
return Array.isArray(arg) ? arg[0] : arg;
}
/**
Impose la hauteur à tous les enfants
Demande la largeur aux enfants fixes
Impose la largeur aux enfants flex
*/
module.exports = compose(_Destroyable, function(content, opts) {
opts = defaults({}, opts, {
autoHeight: false,
})
this._container = new Container(content.map(getCmp));
this._horizontalLayouter = this._own(new Flex('horizontal', content.map(function(arg) {
if (Array.isArray(arg)) {
if (typeof arg[1] === 'number') {
return {
cmp: arg[0],
type: 'flex',
weight: arg[1],
};
} else {
return {
cmp: arg[0],
type: arg[1],
};
}
} else {
return {
cmp: arg,
type: 'flex',
weight: 1,
};
}
})));
var cmpsAsDict = content.reduce(function(acc, arg, index) {
acc[index] = getCmp(arg);
return acc;
}, {});
if (opts.autoHeight) {
this._verticalLayouter = new FullMax('vertical').content(cmpsAsDict);
} else {
this._verticalLayouter = new Full('vertical').content(cmpsAsDict);
}
this._zLayouter = new ZFlat().content(cmpsAsDict);
}, {
width: delegateGetSet('_horizontalLayouter', 'size'),
height: delegateGetSet('_verticalLayouter', 'size'),
onHeight: function(cb) {
this._verticalLayouter.onSize && this._verticalLayouter.onSize(cb)
},
depth: delegateGetSet('_zLayouter', 'size'),
left: delegateGetSet('_horizontalLayouter', 'position'),
top: delegateGetSet('_verticalLayouter', 'position'),
zIndex: delegateGetSet('_zLayouter', 'position'),
parentNode: delegateGetSet('_container', 'parentNode'),
visible: delegateGetSet('_container', 'visible'),
containerVisible: delegateGetSet('_container', 'containerVisible'),
});