@base-framework/base 2.6.1 → 2.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/base.js +1 -0
- package/package.json +30 -26
- package/.jshintrc +0 -3
- package/base.js +0 -41
- package/base.min.js +0 -1
- package/core.js +0 -1
- package/data-tracker.js +0 -351
- package/es5/base.js +0 -2968
- package/es5/modules/ajax.js +0 -663
- package/es5/modules/animation.js +0 -188
- package/es5/modules/animations.js +0 -1080
- package/es5/modules/atom.js +0 -65
- package/es5/modules/component.js +0 -1310
- package/es5/modules/data-binder.js +0 -1131
- package/es5/modules/data.js +0 -1808
- package/es5/modules/date.js +0 -525
- package/es5/modules/form-validator.js +0 -324
- package/es5/modules/history.js +0 -126
- package/es5/modules/html-builder.js +0 -461
- package/es5/modules/layout.js +0 -1679
- package/es5/modules/mouse.js +0 -124
- package/es5/modules/nav-link.js +0 -123
- package/es5/modules/olderversions/animations-ease.js +0 -1095
- package/es5/modules/olderversions/animations-update.js +0 -1048
- package/es5/modules/olderversions/base-animations.js +0 -636
- package/es5/modules/olderversions/base-component-class.js +0 -100
- package/es5/modules/olderversions/base-data-binder-1.js +0 -407
- package/es5/modules/olderversions/base-data-binder-class.js +0 -358
- package/es5/modules/olderversions/base-layout-parser-class.js +0 -172
- package/es5/modules/olderversions/base-mode-1.js +0 -777
- package/es5/modules/olderversions/base-model-class.js +0 -585
- package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
- package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
- package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
- package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
- package/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
- package/es5/modules/olderversions/data-tracker.js +0 -187
- package/es5/modules/olderversions/event-update.js +0 -666
- package/es5/modules/olderversions/nav-link.js +0 -119
- package/es5/modules/olderversions/router-with-templates-1.js +0 -785
- package/es5/modules/olderversions/router-with-templates.js +0 -701
- package/es5/modules/prototypes/ajax.js +0 -657
- package/es5/modules/prototypes/atom.js +0 -65
- package/es5/modules/prototypes/component.js +0 -972
- package/es5/modules/prototypes/data-binder.js +0 -1089
- package/es5/modules/prototypes/data.js +0 -1290
- package/es5/modules/prototypes/html-builder.js +0 -414
- package/es5/modules/prototypes/layout.js +0 -879
- package/es5/modules/router.js +0 -1680
- package/es5/modules/state.js +0 -274
- package/es6/.jshintrc +0 -3
- package/es6/base.js +0 -41
- package/es6/core.js +0 -1
- package/es6/data-tracker.js +0 -351
- package/es6/events.js +0 -602
- package/es6/legacy/es5/base.js +0 -2968
- package/es6/legacy/es5/modules/ajax.js +0 -663
- package/es6/legacy/es5/modules/animation.js +0 -188
- package/es6/legacy/es5/modules/animations.js +0 -1080
- package/es6/legacy/es5/modules/atom.js +0 -65
- package/es6/legacy/es5/modules/component.js +0 -1310
- package/es6/legacy/es5/modules/data-binder.js +0 -1131
- package/es6/legacy/es5/modules/data.js +0 -1808
- package/es6/legacy/es5/modules/date.js +0 -525
- package/es6/legacy/es5/modules/form-validator.js +0 -324
- package/es6/legacy/es5/modules/history.js +0 -126
- package/es6/legacy/es5/modules/html-builder.js +0 -461
- package/es6/legacy/es5/modules/layout.js +0 -1679
- package/es6/legacy/es5/modules/mouse.js +0 -124
- package/es6/legacy/es5/modules/nav-link.js +0 -123
- package/es6/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
- package/es6/legacy/es5/modules/olderversions/animations-update.js +0 -1048
- package/es6/legacy/es5/modules/olderversions/base-animations.js +0 -636
- package/es6/legacy/es5/modules/olderversions/base-component-class.js +0 -100
- package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
- package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
- package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
- package/es6/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
- package/es6/legacy/es5/modules/olderversions/base-model-class.js +0 -585
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
- package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
- package/es6/legacy/es5/modules/olderversions/data-tracker.js +0 -187
- package/es6/legacy/es5/modules/olderversions/event-update.js +0 -666
- package/es6/legacy/es5/modules/olderversions/nav-link.js +0 -119
- package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
- package/es6/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
- package/es6/legacy/es5/modules/prototypes/ajax.js +0 -657
- package/es6/legacy/es5/modules/prototypes/atom.js +0 -65
- package/es6/legacy/es5/modules/prototypes/component.js +0 -972
- package/es6/legacy/es5/modules/prototypes/data-binder.js +0 -1089
- package/es6/legacy/es5/modules/prototypes/data.js +0 -1290
- package/es6/legacy/es5/modules/prototypes/html-builder.js +0 -414
- package/es6/legacy/es5/modules/prototypes/layout.js +0 -879
- package/es6/legacy/es5/modules/router.js +0 -1680
- package/es6/legacy/es5/modules/state.js +0 -274
- package/es6/main.js +0 -1331
- package/es6/modules/ajax/ajax.js +0 -514
- package/es6/modules/animation/animation.js +0 -236
- package/es6/modules/animations/animation-controller.js +0 -231
- package/es6/modules/animations/animation.js +0 -64
- package/es6/modules/animations/attr-movement.js +0 -66
- package/es6/modules/animations/css-movement.js +0 -170
- package/es6/modules/animations/movement.js +0 -131
- package/es6/modules/animations/value.js +0 -187
- package/es6/modules/atom/atom.js +0 -54
- package/es6/modules/component/component.js +0 -230
- package/es6/modules/component/event-helper.js +0 -119
- package/es6/modules/component/jot.js +0 -144
- package/es6/modules/component/state-helper.js +0 -262
- package/es6/modules/component/unit.js +0 -551
- package/es6/modules/data/attrs.js +0 -40
- package/es6/modules/data/basic-data.js +0 -500
- package/es6/modules/data/data-utils.js +0 -29
- package/es6/modules/data/data.js +0 -3
- package/es6/modules/data/deep-data.js +0 -541
- package/es6/modules/data/model-service.js +0 -528
- package/es6/modules/data/model.js +0 -133
- package/es6/modules/data/simple-data.js +0 -33
- package/es6/modules/data-binder/connection-tracker.js +0 -113
- package/es6/modules/data-binder/connection.js +0 -16
- package/es6/modules/data-binder/data-binder.js +0 -352
- package/es6/modules/data-binder/data-pub-sub.js +0 -141
- package/es6/modules/data-binder/data-source.js +0 -56
- package/es6/modules/data-binder/element-source.js +0 -219
- package/es6/modules/data-binder/one-way-connection.js +0 -46
- package/es6/modules/data-binder/one-way-source.js +0 -43
- package/es6/modules/data-binder/source.js +0 -36
- package/es6/modules/data-binder/two-way-connection.js +0 -75
- package/es6/modules/data-binder/two-way-source.js +0 -41
- package/es6/modules/date/date.js +0 -544
- package/es6/modules/history/history.js +0 -89
- package/es6/modules/html-builder/html-builder.js +0 -434
- package/es6/modules/import/import.js +0 -390
- package/es6/modules/layout/layout-builder.js +0 -1269
- package/es6/modules/layout/layout-parser.js +0 -134
- package/es6/modules/layout/watcher-helper.js +0 -282
- package/es6/modules/mouse/mouse.js +0 -114
- package/es6/modules/router/component-helper.js +0 -163
- package/es6/modules/router/history-controller.js +0 -216
- package/es6/modules/router/nav-link.js +0 -124
- package/es6/modules/router/route.js +0 -401
- package/es6/modules/router/router.js +0 -789
- package/es6/modules/router/utils.js +0 -31
- package/es6/modules/state/state-target.js +0 -91
- package/es6/modules/state/state.js +0 -171
- package/es6/package-lock.json +0 -13
- package/es6/package.json +0 -28
- package/es6/shared/objects.js +0 -99
- package/events.js +0 -602
- package/legacy/es5/base.js +0 -2968
- package/legacy/es5/modules/ajax.js +0 -663
- package/legacy/es5/modules/animation.js +0 -188
- package/legacy/es5/modules/animations.js +0 -1080
- package/legacy/es5/modules/atom.js +0 -65
- package/legacy/es5/modules/component.js +0 -1310
- package/legacy/es5/modules/data-binder.js +0 -1131
- package/legacy/es5/modules/data.js +0 -1808
- package/legacy/es5/modules/date.js +0 -525
- package/legacy/es5/modules/form-validator.js +0 -324
- package/legacy/es5/modules/history.js +0 -126
- package/legacy/es5/modules/html-builder.js +0 -461
- package/legacy/es5/modules/layout.js +0 -1679
- package/legacy/es5/modules/mouse.js +0 -124
- package/legacy/es5/modules/nav-link.js +0 -123
- package/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
- package/legacy/es5/modules/olderversions/animations-update.js +0 -1048
- package/legacy/es5/modules/olderversions/base-animations.js +0 -636
- package/legacy/es5/modules/olderversions/base-component-class.js +0 -100
- package/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
- package/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
- package/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
- package/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
- package/legacy/es5/modules/olderversions/base-model-class.js +0 -585
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
- package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
- package/legacy/es5/modules/olderversions/data-tracker.js +0 -187
- package/legacy/es5/modules/olderversions/event-update.js +0 -666
- package/legacy/es5/modules/olderversions/nav-link.js +0 -119
- package/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
- package/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
- package/legacy/es5/modules/prototypes/ajax.js +0 -657
- package/legacy/es5/modules/prototypes/atom.js +0 -65
- package/legacy/es5/modules/prototypes/component.js +0 -972
- package/legacy/es5/modules/prototypes/data-binder.js +0 -1089
- package/legacy/es5/modules/prototypes/data.js +0 -1290
- package/legacy/es5/modules/prototypes/html-builder.js +0 -414
- package/legacy/es5/modules/prototypes/layout.js +0 -879
- package/legacy/es5/modules/router.js +0 -1680
- package/legacy/es5/modules/state.js +0 -274
- package/main.js +0 -1331
- package/modules/ajax/ajax.js +0 -514
- package/modules/animation/animation.js +0 -236
- package/modules/animations/animation-controller.js +0 -231
- package/modules/animations/animation.js +0 -64
- package/modules/animations/attr-movement.js +0 -66
- package/modules/animations/css-movement.js +0 -170
- package/modules/animations/movement.js +0 -131
- package/modules/animations/value.js +0 -187
- package/modules/atom/atom.js +0 -54
- package/modules/component/component.js +0 -230
- package/modules/component/event-helper.js +0 -119
- package/modules/component/jot.js +0 -144
- package/modules/component/state-helper.js +0 -262
- package/modules/component/unit.js +0 -551
- package/modules/data/attrs.js +0 -40
- package/modules/data/basic-data.js +0 -500
- package/modules/data/data-utils.js +0 -29
- package/modules/data/data.js +0 -3
- package/modules/data/deep-data.js +0 -541
- package/modules/data/model-service.js +0 -528
- package/modules/data/model.js +0 -133
- package/modules/data/simple-data.js +0 -33
- package/modules/data-binder/connection-tracker.js +0 -113
- package/modules/data-binder/connection.js +0 -16
- package/modules/data-binder/data-binder.js +0 -352
- package/modules/data-binder/data-pub-sub.js +0 -141
- package/modules/data-binder/data-source.js +0 -56
- package/modules/data-binder/element-source.js +0 -219
- package/modules/data-binder/one-way-connection.js +0 -46
- package/modules/data-binder/one-way-source.js +0 -43
- package/modules/data-binder/source.js +0 -36
- package/modules/data-binder/two-way-connection.js +0 -75
- package/modules/data-binder/two-way-source.js +0 -41
- package/modules/date/date.js +0 -544
- package/modules/history/history.js +0 -89
- package/modules/html-builder/html-builder.js +0 -434
- package/modules/import/import.js +0 -390
- package/modules/layout/layout-builder.js +0 -1269
- package/modules/layout/layout-parser.js +0 -134
- package/modules/layout/watcher-helper.js +0 -282
- package/modules/mouse/mouse.js +0 -114
- package/modules/router/component-helper.js +0 -163
- package/modules/router/history-controller.js +0 -216
- package/modules/router/nav-link.js +0 -124
- package/modules/router/route.js +0 -401
- package/modules/router/router.js +0 -789
- package/modules/router/utils.js +0 -31
- package/modules/state/state-target.js +0 -91
- package/modules/state/state.js +0 -171
- package/shared/objects.js +0 -99
- package/update +0 -16
|
@@ -1,1269 +0,0 @@
|
|
|
1
|
-
import {base} from '../../core.js';
|
|
2
|
-
import {LayoutParser} from './layout-parser.js';
|
|
3
|
-
import {dataBinder} from '../data-binder/data-binder.js';
|
|
4
|
-
import {htmlBuilder, normalizeAttr, removeEventPrefix} from '../html-builder/html-builder.js';
|
|
5
|
-
import {WatcherHelper} from './watcher-helper.js';
|
|
6
|
-
import {Jot} from "../component/jot.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* This will create a watch element.
|
|
10
|
-
*
|
|
11
|
-
* @param {object} data
|
|
12
|
-
* @param {string} prop
|
|
13
|
-
* @returns {function}
|
|
14
|
-
*/
|
|
15
|
-
export const Watch = function(data, prop)
|
|
16
|
-
{
|
|
17
|
-
return function(callBack)
|
|
18
|
-
{
|
|
19
|
-
return {
|
|
20
|
-
onSet: [data, prop, (ele, value) =>
|
|
21
|
-
{
|
|
22
|
-
return callBack(value);
|
|
23
|
-
}]
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* This will track the context from an atom to remove
|
|
30
|
-
* it when the element is removed.
|
|
31
|
-
*/
|
|
32
|
-
base.dataTracker.addType('context', function(data)
|
|
33
|
-
{
|
|
34
|
-
if(!data)
|
|
35
|
-
{
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
data.parent.removeContextBranch(data.branch);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const parser = new LayoutParser();
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* LayoutBuilder
|
|
46
|
-
*
|
|
47
|
-
* This will build JSON layouts.
|
|
48
|
-
*
|
|
49
|
-
* @class
|
|
50
|
-
* @augments htmlBuilder
|
|
51
|
-
*/
|
|
52
|
-
export class LayoutBuilder extends htmlBuilder
|
|
53
|
-
{
|
|
54
|
-
/**
|
|
55
|
-
* This will create a new element.
|
|
56
|
-
*
|
|
57
|
-
* @override
|
|
58
|
-
* @param {string} nodeName The node name.
|
|
59
|
-
* @param {object} attrObject The node attributes.
|
|
60
|
-
* @param {object} container The node container.
|
|
61
|
-
* @param {object} parent
|
|
62
|
-
* @return {object} The new element.
|
|
63
|
-
*/
|
|
64
|
-
create(nodeName, attrObject, container, parent)
|
|
65
|
-
{
|
|
66
|
-
let obj = document.createElement(nodeName);
|
|
67
|
-
this._addElementAttrs(obj, attrObject, parent);
|
|
68
|
-
this.append(container, obj);
|
|
69
|
-
return obj;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* This will add the element attributes.
|
|
74
|
-
*
|
|
75
|
-
* @protected
|
|
76
|
-
* @param {object} obj
|
|
77
|
-
* @param {object} attrObject
|
|
78
|
-
* @param {object} parent
|
|
79
|
-
*/
|
|
80
|
-
_addElementAttrs(obj, attrObject, parent)
|
|
81
|
-
{
|
|
82
|
-
/* we want to check if we have attrributes to add */
|
|
83
|
-
if(!attrObject || typeof attrObject !== 'object')
|
|
84
|
-
{
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/* we need to add the type if set to stop ie
|
|
89
|
-
from removing the value if set after the value is
|
|
90
|
-
added */
|
|
91
|
-
let type = attrObject.type;
|
|
92
|
-
if(typeof type !== 'undefined')
|
|
93
|
-
{
|
|
94
|
-
base.setAttr(obj, 'type', type);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/* we want to add each attr to the obj */
|
|
98
|
-
for(var prop in attrObject)
|
|
99
|
-
{
|
|
100
|
-
/* we have already added the type so we need to
|
|
101
|
-
skip if the prop is type */
|
|
102
|
-
if(attrObject.hasOwnProperty(prop) === false || prop === 'type')
|
|
103
|
-
{
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
var attrPropValue = attrObject[prop];
|
|
108
|
-
|
|
109
|
-
/* we want to check to add the attr settings
|
|
110
|
-
by property name */
|
|
111
|
-
if(prop === 'innerHTML')
|
|
112
|
-
{
|
|
113
|
-
obj.innerHTML = attrPropValue;
|
|
114
|
-
}
|
|
115
|
-
else if(prop.indexOf('-') !== -1)
|
|
116
|
-
{
|
|
117
|
-
// this will handle data and aria attributes
|
|
118
|
-
base.setAttr(obj, prop, attrPropValue);
|
|
119
|
-
}
|
|
120
|
-
else
|
|
121
|
-
{
|
|
122
|
-
this.addAttr(obj, prop, attrPropValue, parent);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* This will add an element attribute.
|
|
129
|
-
*
|
|
130
|
-
* @param {object} obj
|
|
131
|
-
* @param {object} attr
|
|
132
|
-
* @param {string} value
|
|
133
|
-
*/
|
|
134
|
-
addAttr(obj, attr, value, parent)
|
|
135
|
-
{
|
|
136
|
-
if(value === '' || !attr)
|
|
137
|
-
{
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/* we want to check to add a value or an event listener */
|
|
142
|
-
let type = typeof value;
|
|
143
|
-
if(type === 'function')
|
|
144
|
-
{
|
|
145
|
-
/* this will add the event using the base events
|
|
146
|
-
so the event is tracked */
|
|
147
|
-
attr = removeEventPrefix(attr);
|
|
148
|
-
base.addListener(attr, obj, function(e)
|
|
149
|
-
{
|
|
150
|
-
value.call(this, e, parent);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
else
|
|
154
|
-
{
|
|
155
|
-
let attrName = normalizeAttr(attr);
|
|
156
|
-
obj[attrName] = value;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* This will render a function/Unit/Component.
|
|
162
|
-
*
|
|
163
|
-
* @param {object|function} layout
|
|
164
|
-
* @param {object} container
|
|
165
|
-
* @param {object} [parent]
|
|
166
|
-
* @returns {object} The layout Unit or Component
|
|
167
|
-
*/
|
|
168
|
-
render(layout, container, parent)
|
|
169
|
-
{
|
|
170
|
-
if(!layout)
|
|
171
|
-
{
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
switch(typeof layout)
|
|
176
|
-
{
|
|
177
|
-
case 'object':
|
|
178
|
-
if(layout.isUnit === true)
|
|
179
|
-
{
|
|
180
|
-
this.createComponent(layout, container, parent);
|
|
181
|
-
return layout;
|
|
182
|
-
}
|
|
183
|
-
default:
|
|
184
|
-
let component = Jot(layout);
|
|
185
|
-
let jot = new component();
|
|
186
|
-
this.createComponent(jot, container, parent);
|
|
187
|
-
return jot;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* This will build a JSON layout.
|
|
193
|
-
*
|
|
194
|
-
* @param {object} obj The JSON layout.
|
|
195
|
-
* @param {object} [container] The parent receiving the layout.
|
|
196
|
-
* @param {object} [parent] The component adding the layout.
|
|
197
|
-
* @return {object} The doc Frag element.
|
|
198
|
-
*/
|
|
199
|
-
build(obj, container, parent)
|
|
200
|
-
{
|
|
201
|
-
let fragment = this.createDocFragment();
|
|
202
|
-
|
|
203
|
-
if (Array.isArray(obj))
|
|
204
|
-
{
|
|
205
|
-
let item;
|
|
206
|
-
for (var i = 0, length = obj.length; i < length; i++)
|
|
207
|
-
{
|
|
208
|
-
item = obj[i];
|
|
209
|
-
this.buildElement(item, fragment, parent);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
else
|
|
213
|
-
{
|
|
214
|
-
this.buildElement(obj, fragment, parent);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if(container && typeof container === 'object')
|
|
218
|
-
{
|
|
219
|
-
container.appendChild(fragment);
|
|
220
|
-
}
|
|
221
|
-
return fragment;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* This will build an element or component.
|
|
226
|
-
*
|
|
227
|
-
* @param {object} obj
|
|
228
|
-
* @param {object} container
|
|
229
|
-
* @param {object} [parent] The component adding the layout.
|
|
230
|
-
*/
|
|
231
|
-
buildElement(obj, container, parent)
|
|
232
|
-
{
|
|
233
|
-
if(!obj)
|
|
234
|
-
{
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if(obj.component || obj.isUnit === true)
|
|
239
|
-
{
|
|
240
|
-
this.createComponent(obj, container, parent);
|
|
241
|
-
}
|
|
242
|
-
else
|
|
243
|
-
{
|
|
244
|
-
this.createElement(obj, container, parent);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* This will append a child element to a parent.
|
|
250
|
-
*
|
|
251
|
-
* @override
|
|
252
|
-
* @param {object} parent
|
|
253
|
-
* @param {object} child
|
|
254
|
-
*/
|
|
255
|
-
append(parent, child)
|
|
256
|
-
{
|
|
257
|
-
parent.appendChild(child);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* This will create an element.
|
|
262
|
-
*
|
|
263
|
-
* @protected
|
|
264
|
-
* @param {object} obj
|
|
265
|
-
* @param {object} container
|
|
266
|
-
* @param {object} [parent] The component adding the layout.
|
|
267
|
-
*/
|
|
268
|
-
createElement(obj, container, parent)
|
|
269
|
-
{
|
|
270
|
-
let settings = parser.parseElement(obj),
|
|
271
|
-
ele = this.createNode(settings, container, parent);
|
|
272
|
-
|
|
273
|
-
const propName = obj.cache;
|
|
274
|
-
if(parent && propName)
|
|
275
|
-
{
|
|
276
|
-
parent[propName] = ele;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/* we want to recursively add the children to
|
|
280
|
-
the new element */
|
|
281
|
-
let children = settings.children;
|
|
282
|
-
if (children.length > 0)
|
|
283
|
-
{
|
|
284
|
-
let child;
|
|
285
|
-
for (var i = 0, length = children.length; i < length; i++)
|
|
286
|
-
{
|
|
287
|
-
child = children[i];
|
|
288
|
-
if(child === null)
|
|
289
|
-
{
|
|
290
|
-
continue;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
this.buildElement(child, ele, parent);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
this.addElementDirectives(ele, obj, parent);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* This will add the element directives.
|
|
302
|
-
*
|
|
303
|
-
* @param {object} ele
|
|
304
|
-
* @param {object} obj
|
|
305
|
-
* @param {object} [parent]
|
|
306
|
-
*/
|
|
307
|
-
addElementDirectives(ele, obj, parent)
|
|
308
|
-
{
|
|
309
|
-
if(typeof obj.onCreated === 'function')
|
|
310
|
-
{
|
|
311
|
-
obj.onCreated(ele, parent);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/* this will check to bind the element to
|
|
315
|
-
the prop of a data */
|
|
316
|
-
let bind = obj.bind;
|
|
317
|
-
if(bind)
|
|
318
|
-
{
|
|
319
|
-
this.bindElement(ele, bind, parent);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if(obj.route)
|
|
323
|
-
{
|
|
324
|
-
this.addRoute(ele, obj.route, parent);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if(obj.switch)
|
|
328
|
-
{
|
|
329
|
-
this.addSwitch(ele, obj.switch, parent);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if(obj.html)
|
|
333
|
-
{
|
|
334
|
-
this.addHtml(ele, obj.html);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
if(obj.useContext)
|
|
338
|
-
{
|
|
339
|
-
this.useContext(ele, obj.useContext, parent);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if(obj.addContext)
|
|
343
|
-
{
|
|
344
|
-
this.addContext(ele, obj.addContext, parent);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
if(obj.context)
|
|
348
|
-
{
|
|
349
|
-
this.context(ele, obj.context, parent);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
if(obj.role)
|
|
353
|
-
{
|
|
354
|
-
this.addRole(ele, obj.role, parent);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
if(obj.aria)
|
|
358
|
-
{
|
|
359
|
-
this.addAria(ele, obj.aria, parent);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
if(parent)
|
|
363
|
-
{
|
|
364
|
-
let onState = obj.onState;
|
|
365
|
-
if(onState && onState.length)
|
|
366
|
-
{
|
|
367
|
-
this.onState(ele, onState, parent);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
let onSet = obj.onSet;
|
|
371
|
-
if(onSet && onSet.length)
|
|
372
|
-
{
|
|
373
|
-
this.onSet(ele, onSet, parent);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
let map = obj.map;
|
|
377
|
-
if(map && map.length)
|
|
378
|
-
{
|
|
379
|
-
this.map(ele, map, parent);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
let forBind = obj.for;
|
|
383
|
-
if(forBind && forBind.length)
|
|
384
|
-
{
|
|
385
|
-
this.for(ele, forBind, parent);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
let useParent = obj.useParent;
|
|
389
|
-
if(useParent)
|
|
390
|
-
{
|
|
391
|
-
this.useParent(ele, useParent, parent);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
let useData = obj.useData;
|
|
395
|
-
if(useData)
|
|
396
|
-
{
|
|
397
|
-
this.useData(ele, useData, parent);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
let useState = obj.useState;
|
|
401
|
-
if(useState)
|
|
402
|
-
{
|
|
403
|
-
this.useState(ele, useState, parent);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
let addState = obj.addState;
|
|
407
|
-
if(addState)
|
|
408
|
-
{
|
|
409
|
-
this.addState(ele, addState, parent);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if(obj.watch)
|
|
414
|
-
{
|
|
415
|
-
this.watch(ele, obj.watch, parent);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* This will get the data source from the parent component.
|
|
421
|
-
*
|
|
422
|
-
* @protected
|
|
423
|
-
* @param {object} [parent]
|
|
424
|
-
* @return {(object|boolean)}
|
|
425
|
-
*/
|
|
426
|
-
_getDataSource(parent)
|
|
427
|
-
{
|
|
428
|
-
if(!parent)
|
|
429
|
-
{
|
|
430
|
-
return false;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
if(parent.data)
|
|
434
|
-
{
|
|
435
|
-
return parent.data;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
if(parent.context && parent.context.data)
|
|
439
|
-
{
|
|
440
|
-
return parent.context.data;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
if(parent.state)
|
|
444
|
-
{
|
|
445
|
-
return parent.state;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
return false;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* This will bind an element to data.
|
|
453
|
-
*
|
|
454
|
-
* @protected
|
|
455
|
-
* @param {object} ele
|
|
456
|
-
* @param {(string|array)} bind
|
|
457
|
-
* @param {*} parent
|
|
458
|
-
*/
|
|
459
|
-
bindElement(ele, bind, parent)
|
|
460
|
-
{
|
|
461
|
-
let data, prop, filter;
|
|
462
|
-
|
|
463
|
-
if(typeof bind === 'string')
|
|
464
|
-
{
|
|
465
|
-
data = this._getDataSource(parent);
|
|
466
|
-
if(!data)
|
|
467
|
-
{
|
|
468
|
-
return false;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
prop = bind;
|
|
472
|
-
}
|
|
473
|
-
else if(Array.isArray(bind))
|
|
474
|
-
{
|
|
475
|
-
if((typeof bind[0] !== 'object'))
|
|
476
|
-
{
|
|
477
|
-
let dataSource = this._getDataSource(parent);
|
|
478
|
-
if(!dataSource)
|
|
479
|
-
{
|
|
480
|
-
return false;
|
|
481
|
-
}
|
|
482
|
-
else
|
|
483
|
-
{
|
|
484
|
-
bind.unshift(dataSource);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
[data, prop, filter] = bind;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
dataBinder.bind(ele, data, prop, filter);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
/**
|
|
495
|
-
* This will add a route.
|
|
496
|
-
*
|
|
497
|
-
* @protected
|
|
498
|
-
* @param {object} ele
|
|
499
|
-
* @param {(object|array)} route
|
|
500
|
-
* @param {object} parent
|
|
501
|
-
*/
|
|
502
|
-
addRoute(ele, route, parent)
|
|
503
|
-
{
|
|
504
|
-
if(!route)
|
|
505
|
-
{
|
|
506
|
-
return false;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
if(base.isArray(route))
|
|
510
|
-
{
|
|
511
|
-
for(var i = 0, length = route.length; i < length; i++)
|
|
512
|
-
{
|
|
513
|
-
this.setupRoute(ele, route[i], parent);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
else
|
|
517
|
-
{
|
|
518
|
-
this.setupRoute(ele, route, parent);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* This will setup a route.
|
|
524
|
-
*
|
|
525
|
-
* @protected
|
|
526
|
-
* @param {object} ele
|
|
527
|
-
* @param {object} route
|
|
528
|
-
* @param {object} parent
|
|
529
|
-
*/
|
|
530
|
-
setupRoute(ele, route, parent)
|
|
531
|
-
{
|
|
532
|
-
// this will check to resume route
|
|
533
|
-
// if(this.checkResume(route))
|
|
534
|
-
// {
|
|
535
|
-
// this.resumeRoute(ele, route.component.route);
|
|
536
|
-
// return;
|
|
537
|
-
// }
|
|
538
|
-
|
|
539
|
-
route.container = ele;
|
|
540
|
-
route.parent = parent;
|
|
541
|
-
let newRoute = base.router.add(route);
|
|
542
|
-
|
|
543
|
-
this.trackRoute(ele, newRoute);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* This will check to resume route.
|
|
548
|
-
*
|
|
549
|
-
* @param {object} route
|
|
550
|
-
*/
|
|
551
|
-
checkResume(route)
|
|
552
|
-
{
|
|
553
|
-
return (route && route.component && route.component.route);
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
/**
|
|
557
|
-
* This will resume a route.
|
|
558
|
-
*
|
|
559
|
-
* @param {object} ele
|
|
560
|
-
* @param {object} route
|
|
561
|
-
*/
|
|
562
|
-
resumeRoute(ele, route)
|
|
563
|
-
{
|
|
564
|
-
base.router.resume(route, ele);
|
|
565
|
-
|
|
566
|
-
this.trackRoute(ele, route);
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
/**
|
|
570
|
-
* This will track a route.
|
|
571
|
-
*
|
|
572
|
-
* @param {object} ele
|
|
573
|
-
* @param {object} route
|
|
574
|
-
*/
|
|
575
|
-
trackRoute(ele, route)
|
|
576
|
-
{
|
|
577
|
-
base.dataTracker.add(ele, 'routes',
|
|
578
|
-
{
|
|
579
|
-
route
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
/**
|
|
584
|
-
* This will add a switch.
|
|
585
|
-
*
|
|
586
|
-
* @protected
|
|
587
|
-
* @param {object} ele
|
|
588
|
-
* @param {array} group
|
|
589
|
-
* @param {object} parent
|
|
590
|
-
*/
|
|
591
|
-
addSwitch(ele, group, parent)
|
|
592
|
-
{
|
|
593
|
-
let route = group[0];
|
|
594
|
-
// this will check to resume switch
|
|
595
|
-
// if(this.checkResume(route))
|
|
596
|
-
// {
|
|
597
|
-
// this.resumeSwitch(ele, group);
|
|
598
|
-
// return;
|
|
599
|
-
// }
|
|
600
|
-
|
|
601
|
-
for(var i = 0, length = group.length; i < length; i++)
|
|
602
|
-
{
|
|
603
|
-
route = group[i];
|
|
604
|
-
route.container = ele;
|
|
605
|
-
route.parent = parent;
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
let id = base.router.addSwitch(group);
|
|
609
|
-
this.trackSwitch(ele, id);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
resumeSwitch(ele, group)
|
|
613
|
-
{
|
|
614
|
-
let id = base.router.resumeSwitch(group, ele);
|
|
615
|
-
this.trackSwitch(ele, id);
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
/**
|
|
619
|
-
* This will track a switch.
|
|
620
|
-
*
|
|
621
|
-
* @param {object} ele
|
|
622
|
-
* @param {int} id
|
|
623
|
-
*/
|
|
624
|
-
trackSwitch(ele, id)
|
|
625
|
-
{
|
|
626
|
-
base.dataTracker.add(ele, 'switch',
|
|
627
|
-
{
|
|
628
|
-
id
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
/**
|
|
633
|
-
* This will add aria attributes.
|
|
634
|
-
*
|
|
635
|
-
* @protected
|
|
636
|
-
* @param {object} ele
|
|
637
|
-
* @param {array} role
|
|
638
|
-
* @param {object} parent
|
|
639
|
-
*/
|
|
640
|
-
addRole(ele, role, parent)
|
|
641
|
-
{
|
|
642
|
-
if(!role)
|
|
643
|
-
{
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
if(role)
|
|
648
|
-
{
|
|
649
|
-
base.setAttr(ele, 'role', role);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
/**
|
|
654
|
-
* This will add aria attributes.
|
|
655
|
-
*
|
|
656
|
-
* @protected
|
|
657
|
-
* @param {object} ele
|
|
658
|
-
* @param {array} attributes
|
|
659
|
-
* @param {object} parent
|
|
660
|
-
*/
|
|
661
|
-
addAria(ele, attributes, parent)
|
|
662
|
-
{
|
|
663
|
-
if(!attributes)
|
|
664
|
-
{
|
|
665
|
-
return;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
let role = attributes.role;
|
|
669
|
-
if(role)
|
|
670
|
-
{
|
|
671
|
-
base.setAttr(ele, 'role', role);
|
|
672
|
-
attributes.role = null;
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
/**
|
|
676
|
-
* This will setup the onSet callBack.
|
|
677
|
-
*
|
|
678
|
-
* @param {string} attr
|
|
679
|
-
* @return {function}
|
|
680
|
-
*/
|
|
681
|
-
const onSetCallBack = (attr) =>
|
|
682
|
-
{
|
|
683
|
-
return (ele, val) =>
|
|
684
|
-
{
|
|
685
|
-
var text = (val)? "true" : "false";
|
|
686
|
-
base.setAttr(ele, attr, text);
|
|
687
|
-
};
|
|
688
|
-
};
|
|
689
|
-
|
|
690
|
-
for(var prop in attributes)
|
|
691
|
-
{
|
|
692
|
-
if(attributes.hasOwnProperty(prop) === false || attributes[prop] === null)
|
|
693
|
-
{
|
|
694
|
-
continue;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
var value = attributes[prop];
|
|
698
|
-
var attr = 'aria-' + prop;
|
|
699
|
-
|
|
700
|
-
/* this will setup an onSet to change the attr value
|
|
701
|
-
when the data chnages. */
|
|
702
|
-
if(Array.isArray(value))
|
|
703
|
-
{
|
|
704
|
-
value.push(onSetCallBack(attr));
|
|
705
|
-
this.onSet(ele, value, parent);
|
|
706
|
-
}
|
|
707
|
-
else
|
|
708
|
-
{
|
|
709
|
-
base.setAttr(ele, attr, value);
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
/**
|
|
715
|
-
* This will get the parent context.
|
|
716
|
-
*
|
|
717
|
-
* @param {object|null} parent
|
|
718
|
-
* @returns {object|null}
|
|
719
|
-
*/
|
|
720
|
-
getParentContext(parent)
|
|
721
|
-
{
|
|
722
|
-
return (!parent)? null : parent.getContext();
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
/**
|
|
726
|
-
* This will set the context attributes.
|
|
727
|
-
*
|
|
728
|
-
* @protected
|
|
729
|
-
* @param {object} ele
|
|
730
|
-
* @param {function} context
|
|
731
|
-
* @param {object} [parent]
|
|
732
|
-
*/
|
|
733
|
-
context(ele, context, parent)
|
|
734
|
-
{
|
|
735
|
-
if(typeof context !== 'function')
|
|
736
|
-
{
|
|
737
|
-
return;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
let parentContext = this.getParentContext(parent);
|
|
741
|
-
let attributes = context(parentContext);
|
|
742
|
-
if(!attributes)
|
|
743
|
-
{
|
|
744
|
-
return;
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
this._addElementAttrs(ele, attributes, parent);
|
|
748
|
-
this.addElementDirectives(ele, attributes, parent);
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
/**
|
|
752
|
-
* This will use the parent context.
|
|
753
|
-
*
|
|
754
|
-
* @param {object} ele
|
|
755
|
-
* @param {function} callBack
|
|
756
|
-
* @param {object} [parent]
|
|
757
|
-
* @returns {void}
|
|
758
|
-
*/
|
|
759
|
-
useContext(ele, callBack, parent)
|
|
760
|
-
{
|
|
761
|
-
if(typeof callBack !== 'function')
|
|
762
|
-
{
|
|
763
|
-
return;
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
let parentContext = this.getParentContext(parent);
|
|
767
|
-
callBack(parentContext);
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
* This will add context the parent context.
|
|
772
|
-
*
|
|
773
|
-
* @param {object} ele
|
|
774
|
-
* @param {array} callBack
|
|
775
|
-
* @param {object} [parent]
|
|
776
|
-
* @returns {void}
|
|
777
|
-
*/
|
|
778
|
-
addContext(ele, callBack, parent)
|
|
779
|
-
{
|
|
780
|
-
if(typeof callBack !== 'function' || !parent)
|
|
781
|
-
{
|
|
782
|
-
return;
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
let parentContext = this.getParentContext(parent);
|
|
786
|
-
let childContext = callBack(parentContext);
|
|
787
|
-
if(!childContext)
|
|
788
|
-
{
|
|
789
|
-
return;
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
parent.addContextBranch(childContext[0], childContext[1]);
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
/**
|
|
796
|
-
* This will track the child context on the element.
|
|
797
|
-
*
|
|
798
|
-
* @param {object} ele
|
|
799
|
-
* @param {string} branchName
|
|
800
|
-
* @param {object} parent
|
|
801
|
-
*/
|
|
802
|
-
trackContext(ele, branchName, parent)
|
|
803
|
-
{
|
|
804
|
-
base.dataTracker.add(ele, 'context',
|
|
805
|
-
{
|
|
806
|
-
branch: branchName,
|
|
807
|
-
parent: parent
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
/**
|
|
812
|
-
* This will add a watcher.
|
|
813
|
-
*
|
|
814
|
-
* @protected
|
|
815
|
-
* @param {object} ele
|
|
816
|
-
* @param {(array|object)} watcher
|
|
817
|
-
* @param {object} [parent]
|
|
818
|
-
*/
|
|
819
|
-
watch(ele, watcher, parent)
|
|
820
|
-
{
|
|
821
|
-
if(!watcher)
|
|
822
|
-
{
|
|
823
|
-
return false;
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
if(Array.isArray(watcher) && typeof watcher[0] !== 'string')
|
|
827
|
-
{
|
|
828
|
-
for(var i = 0, length = watcher.length; i < length; i++)
|
|
829
|
-
{
|
|
830
|
-
WatcherHelper.setup(ele, watcher[i], parent);
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
else
|
|
834
|
-
{
|
|
835
|
-
WatcherHelper.setup(ele, watcher, parent);
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
/**
|
|
840
|
-
* This will pass the parent state to the callBack.
|
|
841
|
-
*
|
|
842
|
-
* @param {object} ele
|
|
843
|
-
* @param {function} callBack
|
|
844
|
-
* @param {object} parent
|
|
845
|
-
*/
|
|
846
|
-
useParent(ele, callBack, parent)
|
|
847
|
-
{
|
|
848
|
-
if(!callBack || !parent)
|
|
849
|
-
{
|
|
850
|
-
return false;
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
callBack(parent, ele);
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
/**
|
|
857
|
-
* This will pass the parent state to the callBack.
|
|
858
|
-
*
|
|
859
|
-
* @param {object} ele
|
|
860
|
-
* @param {function} callBack
|
|
861
|
-
* @param {object} parent
|
|
862
|
-
*/
|
|
863
|
-
useData(ele, callBack, parent)
|
|
864
|
-
{
|
|
865
|
-
if(!callBack || !parent)
|
|
866
|
-
{
|
|
867
|
-
return false;
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
callBack(parent.data, ele);
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
/**
|
|
874
|
-
* This will pass the parent state to the callBack.
|
|
875
|
-
*
|
|
876
|
-
* @param {object} ele
|
|
877
|
-
* @param {function} callBack
|
|
878
|
-
* @param {object} parent
|
|
879
|
-
*/
|
|
880
|
-
useState(ele, callBack, parent)
|
|
881
|
-
{
|
|
882
|
-
if(!callBack || !parent)
|
|
883
|
-
{
|
|
884
|
-
return false;
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
callBack(parent.state, ele);
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
/**
|
|
891
|
-
* This will pass the parent state to the callBack.
|
|
892
|
-
*
|
|
893
|
-
* @param {object} ele
|
|
894
|
-
* @param {function} callBack
|
|
895
|
-
* @param {object} parent
|
|
896
|
-
*/
|
|
897
|
-
addState(ele, callBack, parent)
|
|
898
|
-
{
|
|
899
|
-
if(!callBack || !parent)
|
|
900
|
-
{
|
|
901
|
-
return false;
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
if(parent.stateHelper)
|
|
905
|
-
{
|
|
906
|
-
let state = parent.state;
|
|
907
|
-
let states = callBack(state);
|
|
908
|
-
parent.stateHelper.addStates(states);
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
/**
|
|
913
|
-
* This will map children to the element.
|
|
914
|
-
*
|
|
915
|
-
* @param {object} ele
|
|
916
|
-
* @param {array} settings
|
|
917
|
-
* @param {object} parent
|
|
918
|
-
*/
|
|
919
|
-
map(ele, settings, parent)
|
|
920
|
-
{
|
|
921
|
-
let items = settings[0];
|
|
922
|
-
if(!items || items.length < 1)
|
|
923
|
-
{
|
|
924
|
-
return;
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
let item = settings[1];
|
|
928
|
-
let children = [];
|
|
929
|
-
for(var i = 0, length = items.length; i < length; i++)
|
|
930
|
-
{
|
|
931
|
-
var row = items[i];
|
|
932
|
-
if(!row)
|
|
933
|
-
{
|
|
934
|
-
continue;
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
var layout = item(row, i);
|
|
938
|
-
if(layout === null)
|
|
939
|
-
{
|
|
940
|
-
continue;
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
children.push(layout);
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
return this.build(children, ele, parent);
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
/**
|
|
950
|
-
* This will watch a data attr and update the
|
|
951
|
-
* children to the element when the attr value is updated.
|
|
952
|
-
*
|
|
953
|
-
* @param {object} ele
|
|
954
|
-
* @param {array} settings
|
|
955
|
-
* @param {object} parent
|
|
956
|
-
*/
|
|
957
|
-
for(ele, settings, parent)
|
|
958
|
-
{
|
|
959
|
-
let data, prop, item, scope;
|
|
960
|
-
|
|
961
|
-
if(settings.length < 3)
|
|
962
|
-
{
|
|
963
|
-
const parentData = this.getParentSetData(parent);
|
|
964
|
-
if(!parentData)
|
|
965
|
-
{
|
|
966
|
-
return;
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
data = parentData;
|
|
970
|
-
prop = settings[0];
|
|
971
|
-
item = settings[1];
|
|
972
|
-
scope = settings[2];
|
|
973
|
-
}
|
|
974
|
-
else
|
|
975
|
-
{
|
|
976
|
-
data = settings[0];
|
|
977
|
-
prop = settings[1];
|
|
978
|
-
item = settings[2];
|
|
979
|
-
scope = settings[3];
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
let scopeData = (scope !== false);
|
|
983
|
-
dataBinder.watch(ele, data, prop, (items) =>
|
|
984
|
-
{
|
|
985
|
-
this.removeAll(ele);
|
|
986
|
-
if(!items || items.length < 1)
|
|
987
|
-
{
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
let children = [];
|
|
992
|
-
for(var i = 0, length = items.length; i < length; i++)
|
|
993
|
-
{
|
|
994
|
-
var scoped = (scopeData)? data.scope(prop + '[' + i + ']') : null;
|
|
995
|
-
var layout = item(items[i], i, scoped);
|
|
996
|
-
if(layout === null)
|
|
997
|
-
{
|
|
998
|
-
continue;
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
children.push(layout);
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
return this.build(children, ele, parent);
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
/**
|
|
1009
|
-
* This will add an onState watcher.
|
|
1010
|
-
*
|
|
1011
|
-
* @param {object} ele
|
|
1012
|
-
* @param {array} onState
|
|
1013
|
-
* @param {object} parent
|
|
1014
|
-
*/
|
|
1015
|
-
onState(ele, onState, parent)
|
|
1016
|
-
{
|
|
1017
|
-
this.onUpdate(ele, parent.state, onState, parent);
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
/**
|
|
1021
|
-
* This will get the parent set data.
|
|
1022
|
-
*
|
|
1023
|
-
* @param {object} parent
|
|
1024
|
-
* @returns {object|null}
|
|
1025
|
-
*/
|
|
1026
|
-
getParentSetData(parent)
|
|
1027
|
-
{
|
|
1028
|
-
if(parent.data)
|
|
1029
|
-
{
|
|
1030
|
-
return parent.data;
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
if(parent.context && parent.context.data)
|
|
1034
|
-
{
|
|
1035
|
-
return parent.context.data;
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
return null;
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
/**
|
|
1042
|
-
* This will add an onSet watcher.
|
|
1043
|
-
*
|
|
1044
|
-
* @param {object} ele
|
|
1045
|
-
* @param {array} onSet
|
|
1046
|
-
* @param {object} parent
|
|
1047
|
-
*/
|
|
1048
|
-
onSet(ele, onSet, parent)
|
|
1049
|
-
{
|
|
1050
|
-
const data = this.getParentSetData(parent);
|
|
1051
|
-
this.onUpdate(ele, data, onSet, parent);
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
/**
|
|
1055
|
-
* This will setup a data watcher.
|
|
1056
|
-
*
|
|
1057
|
-
* @param {object} ele
|
|
1058
|
-
* @param {object} data
|
|
1059
|
-
* @param {string} prop
|
|
1060
|
-
* @param {(function|object)} callBack
|
|
1061
|
-
* @param {string} parent
|
|
1062
|
-
*/
|
|
1063
|
-
onUpdate(ele, data, settings, parent)
|
|
1064
|
-
{
|
|
1065
|
-
let prop,
|
|
1066
|
-
callBack,
|
|
1067
|
-
update;
|
|
1068
|
-
|
|
1069
|
-
if(base.isArray(settings[0]))
|
|
1070
|
-
{
|
|
1071
|
-
for(var i = 0, maxLength = settings.length; i < maxLength; i++)
|
|
1072
|
-
{
|
|
1073
|
-
var itemSettings = settings[i];
|
|
1074
|
-
if(!itemSettings)
|
|
1075
|
-
{
|
|
1076
|
-
continue;
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
this.onUpdate(ele, data, itemSettings, parent);
|
|
1080
|
-
}
|
|
1081
|
-
return;
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
if(settings.length < 3)
|
|
1085
|
-
{
|
|
1086
|
-
[prop, callBack] = settings;
|
|
1087
|
-
}
|
|
1088
|
-
else
|
|
1089
|
-
{
|
|
1090
|
-
[data, prop, callBack] = settings;
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
if(!data || !prop)
|
|
1094
|
-
{
|
|
1095
|
-
return false;
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
switch(typeof callBack)
|
|
1099
|
-
{
|
|
1100
|
-
case 'object':
|
|
1101
|
-
update = (value) =>
|
|
1102
|
-
{
|
|
1103
|
-
this.addClass(ele, callBack, value);
|
|
1104
|
-
};
|
|
1105
|
-
break;
|
|
1106
|
-
case 'function':
|
|
1107
|
-
update = (value) =>
|
|
1108
|
-
{
|
|
1109
|
-
this.updateElement(ele, callBack, prop, value, parent);
|
|
1110
|
-
};
|
|
1111
|
-
break;
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
dataBinder.watch(ele, data, prop, update);
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
/**
|
|
1118
|
-
* This will setup a data watcher.
|
|
1119
|
-
*
|
|
1120
|
-
* @private
|
|
1121
|
-
* @param {object} ele
|
|
1122
|
-
* @param {function} callBack
|
|
1123
|
-
* @param {string} value
|
|
1124
|
-
* @param {string} parent
|
|
1125
|
-
*/
|
|
1126
|
-
updateElement(ele, callBack, prop, value, parent)
|
|
1127
|
-
{
|
|
1128
|
-
let result = callBack(ele, value, parent);
|
|
1129
|
-
switch(typeof result)
|
|
1130
|
-
{
|
|
1131
|
-
case 'object':
|
|
1132
|
-
if(parent && result && result.isUnit === true && parent.persist === true && parent.state)
|
|
1133
|
-
{
|
|
1134
|
-
let key = prop + ':' + value,
|
|
1135
|
-
state = parent.state,
|
|
1136
|
-
previousResult = state.get(key);
|
|
1137
|
-
if(typeof previousResult !== 'undefined')
|
|
1138
|
-
{
|
|
1139
|
-
result = previousResult;
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
state.set(key, result);
|
|
1143
|
-
}
|
|
1144
|
-
this.rebuild(ele, result, parent);
|
|
1145
|
-
break;
|
|
1146
|
-
case 'string':
|
|
1147
|
-
this.addHtml(ele, result);
|
|
1148
|
-
break;
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
/**
|
|
1153
|
-
* This will add or remove a class from an element.
|
|
1154
|
-
*
|
|
1155
|
-
* @param {object} ele
|
|
1156
|
-
* @param {object} stateStyles
|
|
1157
|
-
* @param {*} newValue
|
|
1158
|
-
*/
|
|
1159
|
-
addClass(ele, stateStyles, newValue)
|
|
1160
|
-
{
|
|
1161
|
-
for(var prop in stateStyles)
|
|
1162
|
-
{
|
|
1163
|
-
if(!stateStyles.hasOwnProperty(prop) || !prop)
|
|
1164
|
-
{
|
|
1165
|
-
continue;
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
if(stateStyles[prop] === newValue)
|
|
1169
|
-
{
|
|
1170
|
-
base.addClass(ele, prop);
|
|
1171
|
-
}
|
|
1172
|
-
else
|
|
1173
|
-
{
|
|
1174
|
-
base.removeClass(ele, prop);
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
|
|
1179
|
-
/**
|
|
1180
|
-
* This will reset an element innerHTML and rebuild.
|
|
1181
|
-
*
|
|
1182
|
-
* @private
|
|
1183
|
-
* @param {object} ele
|
|
1184
|
-
* @param {object} layout
|
|
1185
|
-
* @param {object} parent
|
|
1186
|
-
*/
|
|
1187
|
-
rebuild(ele, layout, parent)
|
|
1188
|
-
{
|
|
1189
|
-
this.removeAll(ele);
|
|
1190
|
-
this.build(layout, ele, parent);
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
/**
|
|
1194
|
-
* This will create a component.
|
|
1195
|
-
*
|
|
1196
|
-
* @protected
|
|
1197
|
-
* @param {object} obj
|
|
1198
|
-
* @param {object} container
|
|
1199
|
-
* @param {object} parent
|
|
1200
|
-
*/
|
|
1201
|
-
createComponent(obj, container, parent)
|
|
1202
|
-
{
|
|
1203
|
-
// this will allow both cached components or native components
|
|
1204
|
-
const component = obj.component || obj;
|
|
1205
|
-
component.parent = parent;
|
|
1206
|
-
|
|
1207
|
-
if(parent && parent.persist === true && component.persist !== false)
|
|
1208
|
-
{
|
|
1209
|
-
component.persist = true;
|
|
1210
|
-
}
|
|
1211
|
-
|
|
1212
|
-
if(component.cacheable && parent)
|
|
1213
|
-
{
|
|
1214
|
-
parent[component.cacheable] = component;
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
component.setup(container);
|
|
1218
|
-
|
|
1219
|
-
if(obj.component && typeof obj.onCreated === 'function')
|
|
1220
|
-
{
|
|
1221
|
-
obj.onCreated(component);
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
/**
|
|
1226
|
-
* This will create a node.
|
|
1227
|
-
*
|
|
1228
|
-
* @param {object} settings
|
|
1229
|
-
* @param {object} container
|
|
1230
|
-
* @param {object} parent
|
|
1231
|
-
* @return {object}
|
|
1232
|
-
*/
|
|
1233
|
-
createNode(settings, container, parent)
|
|
1234
|
-
{
|
|
1235
|
-
let tag = settings.tag;
|
|
1236
|
-
if(tag === 'text')
|
|
1237
|
-
{
|
|
1238
|
-
let attr = settings.attr;
|
|
1239
|
-
let text = attr.textContent || attr.text;
|
|
1240
|
-
return this.createTextNode(text, container);
|
|
1241
|
-
}
|
|
1242
|
-
else if(tag === 'comment')
|
|
1243
|
-
{
|
|
1244
|
-
let attr = settings.attr;
|
|
1245
|
-
let text = attr.text;
|
|
1246
|
-
return this.createCommentNode(text, container);
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
return this.create(tag, settings.attr, container, parent);
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
export const builder = new LayoutBuilder();
|
|
1254
|
-
|
|
1255
|
-
base.augment(
|
|
1256
|
-
{
|
|
1257
|
-
/**
|
|
1258
|
-
* This will build a JSON layout.
|
|
1259
|
-
*
|
|
1260
|
-
* @param {object} obj
|
|
1261
|
-
* @param {object} [container]
|
|
1262
|
-
* @param {object} [parent]
|
|
1263
|
-
* @return {object}
|
|
1264
|
-
*/
|
|
1265
|
-
buildLayout(obj, container, parent)
|
|
1266
|
-
{
|
|
1267
|
-
builder.build(obj, container, parent);
|
|
1268
|
-
}
|
|
1269
|
-
});
|