@base-framework/base 2.6.0 → 2.6.1
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/base.min.js +1 -0
- package/es5/base.js +2968 -0
- package/es5/modules/ajax.js +663 -0
- package/es5/modules/animation.js +188 -0
- package/es5/modules/animations.js +1080 -0
- package/es5/modules/atom.js +65 -0
- package/es5/modules/component.js +1310 -0
- package/es5/modules/data-binder.js +1131 -0
- package/es5/modules/data.js +1808 -0
- package/es5/modules/date.js +525 -0
- package/es5/modules/form-validator.js +324 -0
- package/es5/modules/history.js +126 -0
- package/es5/modules/html-builder.js +461 -0
- package/es5/modules/layout.js +1679 -0
- package/es5/modules/mouse.js +124 -0
- package/es5/modules/nav-link.js +123 -0
- package/es5/modules/olderversions/animations-ease.js +1095 -0
- package/es5/modules/olderversions/animations-update.js +1048 -0
- package/es5/modules/olderversions/base-animations.js +636 -0
- package/es5/modules/olderversions/base-component-class.js +100 -0
- package/es5/modules/olderversions/base-data-binder-1.js +407 -0
- package/es5/modules/olderversions/base-data-binder-class.js +358 -0
- package/es5/modules/olderversions/base-layout-parser-class.js +172 -0
- package/es5/modules/olderversions/base-mode-1.js +777 -0
- package/es5/modules/olderversions/base-model-class.js +585 -0
- package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
- package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
- package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
- package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
- package/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
- package/es5/modules/olderversions/data-tracker.js +187 -0
- package/es5/modules/olderversions/event-update.js +666 -0
- package/es5/modules/olderversions/nav-link.js +119 -0
- package/es5/modules/olderversions/router-with-templates-1.js +785 -0
- package/es5/modules/olderversions/router-with-templates.js +701 -0
- package/es5/modules/prototypes/ajax.js +657 -0
- package/es5/modules/prototypes/atom.js +65 -0
- package/es5/modules/prototypes/component.js +972 -0
- package/es5/modules/prototypes/data-binder.js +1089 -0
- package/es5/modules/prototypes/data.js +1290 -0
- package/es5/modules/prototypes/html-builder.js +414 -0
- package/es5/modules/prototypes/layout.js +879 -0
- package/es5/modules/router.js +1680 -0
- package/es5/modules/state.js +274 -0
- package/es6/.jshintrc +3 -0
- package/es6/base.js +41 -0
- package/es6/core.js +1 -0
- package/es6/data-tracker.js +351 -0
- package/es6/events.js +602 -0
- package/es6/legacy/es5/base.js +2968 -0
- package/es6/legacy/es5/modules/ajax.js +663 -0
- package/es6/legacy/es5/modules/animation.js +188 -0
- package/es6/legacy/es5/modules/animations.js +1080 -0
- package/es6/legacy/es5/modules/atom.js +65 -0
- package/es6/legacy/es5/modules/component.js +1310 -0
- package/es6/legacy/es5/modules/data-binder.js +1131 -0
- package/es6/legacy/es5/modules/data.js +1808 -0
- package/es6/legacy/es5/modules/date.js +525 -0
- package/es6/legacy/es5/modules/form-validator.js +324 -0
- package/es6/legacy/es5/modules/history.js +126 -0
- package/es6/legacy/es5/modules/html-builder.js +461 -0
- package/es6/legacy/es5/modules/layout.js +1679 -0
- package/es6/legacy/es5/modules/mouse.js +124 -0
- package/es6/legacy/es5/modules/nav-link.js +123 -0
- package/es6/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
- package/es6/legacy/es5/modules/olderversions/animations-update.js +1048 -0
- package/es6/legacy/es5/modules/olderversions/base-animations.js +636 -0
- package/es6/legacy/es5/modules/olderversions/base-component-class.js +100 -0
- package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
- package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
- package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
- package/es6/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
- package/es6/legacy/es5/modules/olderversions/base-model-class.js +585 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
- package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
- package/es6/legacy/es5/modules/olderversions/data-tracker.js +187 -0
- package/es6/legacy/es5/modules/olderversions/event-update.js +666 -0
- package/es6/legacy/es5/modules/olderversions/nav-link.js +119 -0
- package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
- package/es6/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
- package/es6/legacy/es5/modules/prototypes/ajax.js +657 -0
- package/es6/legacy/es5/modules/prototypes/atom.js +65 -0
- package/es6/legacy/es5/modules/prototypes/component.js +972 -0
- package/es6/legacy/es5/modules/prototypes/data-binder.js +1089 -0
- package/es6/legacy/es5/modules/prototypes/data.js +1290 -0
- package/es6/legacy/es5/modules/prototypes/html-builder.js +414 -0
- package/es6/legacy/es5/modules/prototypes/layout.js +879 -0
- package/es6/legacy/es5/modules/router.js +1680 -0
- package/es6/legacy/es5/modules/state.js +274 -0
- package/es6/main.js +1331 -0
- package/es6/modules/ajax/ajax.js +514 -0
- package/es6/modules/animation/animation.js +236 -0
- package/es6/modules/animations/animation-controller.js +231 -0
- package/es6/modules/animations/animation.js +64 -0
- package/es6/modules/animations/attr-movement.js +66 -0
- package/es6/modules/animations/css-movement.js +170 -0
- package/es6/modules/animations/movement.js +131 -0
- package/es6/modules/animations/value.js +187 -0
- package/es6/modules/atom/atom.js +54 -0
- package/es6/modules/component/component.js +230 -0
- package/es6/modules/component/event-helper.js +119 -0
- package/es6/modules/component/jot.js +144 -0
- package/es6/modules/component/state-helper.js +262 -0
- package/es6/modules/component/unit.js +551 -0
- package/es6/modules/data/attrs.js +40 -0
- package/es6/modules/data/basic-data.js +500 -0
- package/es6/modules/data/data-utils.js +29 -0
- package/es6/modules/data/data.js +3 -0
- package/es6/modules/data/deep-data.js +541 -0
- package/es6/modules/data/model-service.js +528 -0
- package/es6/modules/data/model.js +133 -0
- package/es6/modules/data/simple-data.js +33 -0
- package/es6/modules/data-binder/connection-tracker.js +113 -0
- package/es6/modules/data-binder/connection.js +16 -0
- package/es6/modules/data-binder/data-binder.js +352 -0
- package/es6/modules/data-binder/data-pub-sub.js +141 -0
- package/es6/modules/data-binder/data-source.js +56 -0
- package/es6/modules/data-binder/element-source.js +219 -0
- package/es6/modules/data-binder/one-way-connection.js +46 -0
- package/es6/modules/data-binder/one-way-source.js +43 -0
- package/es6/modules/data-binder/source.js +36 -0
- package/es6/modules/data-binder/two-way-connection.js +75 -0
- package/es6/modules/data-binder/two-way-source.js +41 -0
- package/es6/modules/date/date.js +544 -0
- package/es6/modules/history/history.js +89 -0
- package/es6/modules/html-builder/html-builder.js +434 -0
- package/es6/modules/import/import.js +390 -0
- package/es6/modules/layout/layout-builder.js +1269 -0
- package/es6/modules/layout/layout-parser.js +134 -0
- package/es6/modules/layout/watcher-helper.js +282 -0
- package/es6/modules/mouse/mouse.js +114 -0
- package/es6/modules/router/component-helper.js +163 -0
- package/es6/modules/router/history-controller.js +216 -0
- package/es6/modules/router/nav-link.js +124 -0
- package/es6/modules/router/route.js +401 -0
- package/es6/modules/router/router.js +789 -0
- package/es6/modules/router/utils.js +31 -0
- package/es6/modules/state/state-target.js +91 -0
- package/es6/modules/state/state.js +171 -0
- package/es6/package-lock.json +13 -0
- package/es6/package.json +28 -0
- package/es6/shared/objects.js +99 -0
- package/legacy/es5/base.js +2968 -0
- package/legacy/es5/modules/ajax.js +663 -0
- package/legacy/es5/modules/animation.js +188 -0
- package/legacy/es5/modules/animations.js +1080 -0
- package/legacy/es5/modules/atom.js +65 -0
- package/legacy/es5/modules/component.js +1310 -0
- package/legacy/es5/modules/data-binder.js +1131 -0
- package/legacy/es5/modules/data.js +1808 -0
- package/legacy/es5/modules/date.js +525 -0
- package/legacy/es5/modules/form-validator.js +324 -0
- package/legacy/es5/modules/history.js +126 -0
- package/legacy/es5/modules/html-builder.js +461 -0
- package/legacy/es5/modules/layout.js +1679 -0
- package/legacy/es5/modules/mouse.js +124 -0
- package/legacy/es5/modules/nav-link.js +123 -0
- package/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
- package/legacy/es5/modules/olderversions/animations-update.js +1048 -0
- package/legacy/es5/modules/olderversions/base-animations.js +636 -0
- package/legacy/es5/modules/olderversions/base-component-class.js +100 -0
- package/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
- package/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
- package/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
- package/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
- package/legacy/es5/modules/olderversions/base-model-class.js +585 -0
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
- package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
- package/legacy/es5/modules/olderversions/data-tracker.js +187 -0
- package/legacy/es5/modules/olderversions/event-update.js +666 -0
- package/legacy/es5/modules/olderversions/nav-link.js +119 -0
- package/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
- package/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
- package/legacy/es5/modules/prototypes/ajax.js +657 -0
- package/legacy/es5/modules/prototypes/atom.js +65 -0
- package/legacy/es5/modules/prototypes/component.js +972 -0
- package/legacy/es5/modules/prototypes/data-binder.js +1089 -0
- package/legacy/es5/modules/prototypes/data.js +1290 -0
- package/legacy/es5/modules/prototypes/html-builder.js +414 -0
- package/legacy/es5/modules/prototypes/layout.js +879 -0
- package/legacy/es5/modules/router.js +1680 -0
- package/legacy/es5/modules/state.js +274 -0
- package/package.json +8 -3
- package/update +16 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import {base} from '../../core.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* History
|
|
5
|
+
*
|
|
6
|
+
* This will setup the history controller.
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
export class HistoryController
|
|
10
|
+
{
|
|
11
|
+
/**
|
|
12
|
+
* This will check if browser based navigation is supported
|
|
13
|
+
*
|
|
14
|
+
* @returns boolean
|
|
15
|
+
*/
|
|
16
|
+
static browserIsSupported()
|
|
17
|
+
{
|
|
18
|
+
return ('history' in window && 'pushState' in window.history);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* This will create a History Object based on navigation support
|
|
23
|
+
*
|
|
24
|
+
* @param {Router} router
|
|
25
|
+
* @returns History
|
|
26
|
+
*/
|
|
27
|
+
static setup(router)
|
|
28
|
+
{
|
|
29
|
+
if(HistoryController.browserIsSupported())
|
|
30
|
+
{
|
|
31
|
+
return new BrowserHistory(router).setup();
|
|
32
|
+
}
|
|
33
|
+
return new HashHistory(router).setup();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let routerNumber = 0;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* History
|
|
41
|
+
*
|
|
42
|
+
* This will setup the history controller.
|
|
43
|
+
* @class
|
|
44
|
+
*/
|
|
45
|
+
class History
|
|
46
|
+
{
|
|
47
|
+
/**
|
|
48
|
+
* @constructor
|
|
49
|
+
* @param {object} router
|
|
50
|
+
*/
|
|
51
|
+
constructor(router)
|
|
52
|
+
{
|
|
53
|
+
this.router = router;
|
|
54
|
+
this.locationId = 'base-app-router-' + routerNumber++;
|
|
55
|
+
this.callBack = this.check.bind(this);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* This will check if the history api is supported
|
|
60
|
+
* and add events.
|
|
61
|
+
*
|
|
62
|
+
* @return {object} a reference to the object.
|
|
63
|
+
*/
|
|
64
|
+
setup()
|
|
65
|
+
{
|
|
66
|
+
this.addEvent();
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
class BrowserHistory extends History
|
|
72
|
+
{
|
|
73
|
+
/**
|
|
74
|
+
* This will add the events.
|
|
75
|
+
*
|
|
76
|
+
* @return {object} a reference to the object.
|
|
77
|
+
*/
|
|
78
|
+
addEvent()
|
|
79
|
+
{
|
|
80
|
+
base.on('popstate', window, this.callBack);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* This will remove the events.
|
|
86
|
+
*
|
|
87
|
+
* @return {object} a reference to the object.
|
|
88
|
+
*/
|
|
89
|
+
removeEvent()
|
|
90
|
+
{
|
|
91
|
+
base.off('popstate', window, this.callBack);
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* This will check to activate the router.
|
|
97
|
+
*
|
|
98
|
+
* @param {object} evt
|
|
99
|
+
*/
|
|
100
|
+
check(evt)
|
|
101
|
+
{
|
|
102
|
+
/* we want to check if the event has a state and if the
|
|
103
|
+
state location is from the background */
|
|
104
|
+
let state = evt.state;
|
|
105
|
+
if(!state || state.location !== this.locationId)
|
|
106
|
+
{
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
evt.preventDefault();
|
|
111
|
+
evt.stopPropagation();
|
|
112
|
+
|
|
113
|
+
this.router.checkActiveRoutes(state.uri);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* This will create a state object.
|
|
118
|
+
*
|
|
119
|
+
* @param {string} uri
|
|
120
|
+
* @param {*} data
|
|
121
|
+
* @return {object}
|
|
122
|
+
*/
|
|
123
|
+
createState(uri, data)
|
|
124
|
+
{
|
|
125
|
+
let stateObj = {
|
|
126
|
+
location: this.locationId,
|
|
127
|
+
uri: uri
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
if(data && typeof data === 'object')
|
|
131
|
+
{
|
|
132
|
+
stateObj = Object.assign(stateObj, data);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return stateObj;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* This will add a state to the history.
|
|
140
|
+
*
|
|
141
|
+
* @param {string} uri
|
|
142
|
+
* @param {object} data
|
|
143
|
+
* @param {boolean} replace
|
|
144
|
+
* @return {object} a reference to the object.
|
|
145
|
+
*/
|
|
146
|
+
addState(uri, data, replace)
|
|
147
|
+
{
|
|
148
|
+
let history = window.history,
|
|
149
|
+
lastState = history.state;
|
|
150
|
+
|
|
151
|
+
if(lastState && lastState.uri === uri)
|
|
152
|
+
{
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let stateObj = this.createState(uri, data);
|
|
157
|
+
|
|
158
|
+
/* this will check to push state or
|
|
159
|
+
replace state */
|
|
160
|
+
replace = (replace === true);
|
|
161
|
+
let method = (replace === false)? 'pushState' : 'replaceState';
|
|
162
|
+
history[method](stateObj, null, uri);
|
|
163
|
+
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
class HashHistory extends History
|
|
169
|
+
{
|
|
170
|
+
/**
|
|
171
|
+
* This will add the events.
|
|
172
|
+
*
|
|
173
|
+
* @return {object} a reference to the object.
|
|
174
|
+
*/
|
|
175
|
+
addEvent()
|
|
176
|
+
{
|
|
177
|
+
base.on('hashchange', window, this.callBack);
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* This will remove the events.
|
|
183
|
+
*
|
|
184
|
+
* @return {object} a reference to the object.
|
|
185
|
+
*/
|
|
186
|
+
removeEvent()
|
|
187
|
+
{
|
|
188
|
+
base.off('hashchange', window, this.callBack);
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* This will check to activate the router.
|
|
194
|
+
*
|
|
195
|
+
* @param {object} evt
|
|
196
|
+
*/
|
|
197
|
+
check(evt)
|
|
198
|
+
{
|
|
199
|
+
this.router.checkActiveRoutes(evt.newURL);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* This will add a state to the history.
|
|
204
|
+
*
|
|
205
|
+
* @param {string} uri
|
|
206
|
+
* @param {object} data
|
|
207
|
+
* @param {boolean} replace
|
|
208
|
+
* @return {object} a reference to the object.
|
|
209
|
+
*/
|
|
210
|
+
addState(uri, data, replace)
|
|
211
|
+
{
|
|
212
|
+
window.location.hash = uri;
|
|
213
|
+
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {router} from './router.js';
|
|
2
|
+
import {Component} from '../component/component.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* NavLink
|
|
6
|
+
*
|
|
7
|
+
* This will create a nav link that will add an active
|
|
8
|
+
* class when the browser route path matches the link
|
|
9
|
+
* href.
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
*/
|
|
13
|
+
export class NavLink extends Component
|
|
14
|
+
{
|
|
15
|
+
/**
|
|
16
|
+
* This will configure the link active class.
|
|
17
|
+
*
|
|
18
|
+
* @protected
|
|
19
|
+
*/
|
|
20
|
+
beforeSetup()
|
|
21
|
+
{
|
|
22
|
+
this.selectedClass = this.activeClass || 'active';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* This will render the component.
|
|
27
|
+
*
|
|
28
|
+
* @return {object}
|
|
29
|
+
*/
|
|
30
|
+
render()
|
|
31
|
+
{
|
|
32
|
+
let href = this.href,
|
|
33
|
+
text = this.text,
|
|
34
|
+
watchers = this.setupWatchers(href, text);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
tag: 'a',
|
|
38
|
+
className: this.className || null,
|
|
39
|
+
onState: ['selected', {
|
|
40
|
+
[this.selectedClass]: true
|
|
41
|
+
}],
|
|
42
|
+
href: this.getString(href),
|
|
43
|
+
text: this.getString(text),
|
|
44
|
+
children: this.children,
|
|
45
|
+
watch: watchers
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* This will get string.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} string
|
|
53
|
+
* @return {(string|null)}
|
|
54
|
+
*/
|
|
55
|
+
getString(string)
|
|
56
|
+
{
|
|
57
|
+
let type = typeof string;
|
|
58
|
+
return (type !== 'object' && type !== 'undefined')? string : null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* This will setup the watchers.
|
|
63
|
+
*
|
|
64
|
+
* @protected
|
|
65
|
+
* @param {string} href
|
|
66
|
+
* @param {string} text
|
|
67
|
+
* @return {array}
|
|
68
|
+
*/
|
|
69
|
+
setupWatchers(href, text)
|
|
70
|
+
{
|
|
71
|
+
let exact = (this.exact !== false),
|
|
72
|
+
data = router.data;
|
|
73
|
+
|
|
74
|
+
let watchers = [];
|
|
75
|
+
|
|
76
|
+
if(href && typeof href === 'object')
|
|
77
|
+
{
|
|
78
|
+
watchers.push(
|
|
79
|
+
{
|
|
80
|
+
attr: 'href',
|
|
81
|
+
value: href
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if(text && typeof text === 'object')
|
|
86
|
+
{
|
|
87
|
+
watchers.push(
|
|
88
|
+
{
|
|
89
|
+
attr: 'text',
|
|
90
|
+
value: text
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
watchers.push({
|
|
95
|
+
value: ['[[path]]', data],
|
|
96
|
+
callBack: (ele, value) =>
|
|
97
|
+
{
|
|
98
|
+
let path = ele.pathname + ele.hash;
|
|
99
|
+
let selected = exact? (value === path) : (new RegExp('^' + ele.pathname + '($|#|\/|\\.).*').test(value));
|
|
100
|
+
this.update(ele, selected);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return watchers;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
setupStates()
|
|
108
|
+
{
|
|
109
|
+
return {
|
|
110
|
+
selected: false
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* This will update the class on the element.
|
|
116
|
+
*
|
|
117
|
+
* @param {object} ele
|
|
118
|
+
* @param {bool} selected
|
|
119
|
+
*/
|
|
120
|
+
update(ele, selected)
|
|
121
|
+
{
|
|
122
|
+
this.state.set('selected', selected);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import {ComponentHelper} from './component-helper.js';
|
|
2
|
+
import {SimpleData} from '../data/data.js';
|
|
3
|
+
import {Import} from '../import/import.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This will setup a route uri pattern.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} uri
|
|
9
|
+
* @return {string}
|
|
10
|
+
*/
|
|
11
|
+
const routePattern = (uri) =>
|
|
12
|
+
{
|
|
13
|
+
let uriQuery = "";
|
|
14
|
+
if(uri)
|
|
15
|
+
{
|
|
16
|
+
let filter = /\//g;
|
|
17
|
+
uriQuery = uri.replace(filter, "\/");
|
|
18
|
+
|
|
19
|
+
/* this will setup for optional slashes before the optional params */
|
|
20
|
+
let optionalSlash = /(\/):[^\/(]*?\?/g;
|
|
21
|
+
uriQuery = uriQuery.replace(optionalSlash, (str) =>
|
|
22
|
+
{
|
|
23
|
+
let pattern = /\//g;
|
|
24
|
+
return str.replace(pattern, '(?:$|\/)');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/* this will setup for optional params and params
|
|
28
|
+
and stop at the last slash or query start */
|
|
29
|
+
let param = /(:[^\/?&($]+)/g;
|
|
30
|
+
let optionalParams = /(\?\/+\*?)/g;
|
|
31
|
+
uriQuery = uriQuery.replace(optionalParams, '?\/*');
|
|
32
|
+
uriQuery = uriQuery.replace(param, (str) =>
|
|
33
|
+
{
|
|
34
|
+
return (str.indexOf('.') < 0)? '([^\/|?]+)' : '([^\/|?]+.*)';
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/* we want to setup the wild card and param
|
|
38
|
+
checks to be modified to the route uri string */
|
|
39
|
+
let allowAll = /(\*)/g;
|
|
40
|
+
uriQuery = uriQuery.replace(allowAll, '.*');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* we want to set and string end if the wild card is not set */
|
|
44
|
+
uriQuery += (uri[uri.length - 1] === '*')? '' : '$';
|
|
45
|
+
return uriQuery;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* This will get the default route params.
|
|
50
|
+
*
|
|
51
|
+
* @param {array} params
|
|
52
|
+
* @return {(object|null)}
|
|
53
|
+
*/
|
|
54
|
+
const getParamDefaults = (params) =>
|
|
55
|
+
{
|
|
56
|
+
if(params.length)
|
|
57
|
+
{
|
|
58
|
+
let defaults = {};
|
|
59
|
+
for(var i = 0, length = params.length; i < length; i++)
|
|
60
|
+
{
|
|
61
|
+
defaults[params[i]] = null;
|
|
62
|
+
}
|
|
63
|
+
return defaults;
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* This will get the param keys from the uri.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} uri
|
|
72
|
+
* @return {array}
|
|
73
|
+
*/
|
|
74
|
+
const paramPattern = (uri) =>
|
|
75
|
+
{
|
|
76
|
+
let params = [];
|
|
77
|
+
if(!uri)
|
|
78
|
+
{
|
|
79
|
+
return params;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let filter = /[\*?]/g;
|
|
83
|
+
uri = uri.replace(filter, '');
|
|
84
|
+
|
|
85
|
+
let pattern = /:(.[^.\/?&($]+)\?*/g,
|
|
86
|
+
matches = uri.match(pattern);
|
|
87
|
+
if(matches === null)
|
|
88
|
+
{
|
|
89
|
+
return params;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
for(var i = 0, maxLength = matches.length; i < maxLength; i++)
|
|
93
|
+
{
|
|
94
|
+
var param = matches[i];
|
|
95
|
+
if(param)
|
|
96
|
+
{
|
|
97
|
+
param = param.replace(':', '');
|
|
98
|
+
params.push(param);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return params;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
let routeCount = 0;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Route
|
|
108
|
+
*
|
|
109
|
+
* This will create a route.
|
|
110
|
+
* @class
|
|
111
|
+
* @augments SimpleData
|
|
112
|
+
*/
|
|
113
|
+
export class Route extends SimpleData
|
|
114
|
+
{
|
|
115
|
+
/**
|
|
116
|
+
* @constructor
|
|
117
|
+
* @param {object} settings
|
|
118
|
+
*/
|
|
119
|
+
constructor(settings)
|
|
120
|
+
{
|
|
121
|
+
let uri = settings.baseUri;
|
|
122
|
+
|
|
123
|
+
const paramKeys = paramPattern(uri);
|
|
124
|
+
let params = getParamDefaults(paramKeys);
|
|
125
|
+
super(params);
|
|
126
|
+
|
|
127
|
+
this.uri = uri;
|
|
128
|
+
this.paramKeys = paramKeys;
|
|
129
|
+
|
|
130
|
+
this.setupRoute(settings);
|
|
131
|
+
this.set('active', false);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* This will setup the route settings.
|
|
136
|
+
*
|
|
137
|
+
* @protected
|
|
138
|
+
* @param {object} settings
|
|
139
|
+
*/
|
|
140
|
+
setupRoute(settings)
|
|
141
|
+
{
|
|
142
|
+
this.id = settings.id || 'bs-rte-' + routeCount++;
|
|
143
|
+
|
|
144
|
+
this.path = null;
|
|
145
|
+
this.referralPath = null;
|
|
146
|
+
|
|
147
|
+
/* route reg ex */
|
|
148
|
+
let uriMatch = routePattern(this.uri);
|
|
149
|
+
this.uriQuery = new RegExp('^' + uriMatch);
|
|
150
|
+
|
|
151
|
+
/* params */
|
|
152
|
+
this.params = null;
|
|
153
|
+
|
|
154
|
+
/* this will setup the template and route component
|
|
155
|
+
if one has been set */
|
|
156
|
+
this.setupComponentHelper(settings);
|
|
157
|
+
|
|
158
|
+
this.callBack = settings.callBack;
|
|
159
|
+
this.title = settings.title;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* This will update the route title.
|
|
164
|
+
*
|
|
165
|
+
* @param {string|function} title
|
|
166
|
+
*/
|
|
167
|
+
setTitle(title)
|
|
168
|
+
{
|
|
169
|
+
base.router.updateTitle({
|
|
170
|
+
title: title,
|
|
171
|
+
stage: this.stage
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* This will deactivate the route.
|
|
177
|
+
*/
|
|
178
|
+
deactivate()
|
|
179
|
+
{
|
|
180
|
+
this.set('active', false);
|
|
181
|
+
|
|
182
|
+
let controller = this.controller;
|
|
183
|
+
if(controller)
|
|
184
|
+
{
|
|
185
|
+
controller.remove();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* This will get the route layout.
|
|
191
|
+
*
|
|
192
|
+
* @param {object} settings
|
|
193
|
+
* @returns {object|null}
|
|
194
|
+
*/
|
|
195
|
+
getLayout(settings)
|
|
196
|
+
{
|
|
197
|
+
if(settings.component)
|
|
198
|
+
{
|
|
199
|
+
return settings.component;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
let imported = settings.import;
|
|
203
|
+
if(!imported)
|
|
204
|
+
{
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if(typeof imported === 'string')
|
|
209
|
+
{
|
|
210
|
+
imported = {
|
|
211
|
+
src: imported
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return Import(imported);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* This will setup the route layout.
|
|
220
|
+
*
|
|
221
|
+
* @protected
|
|
222
|
+
* @param {object} settings
|
|
223
|
+
*/
|
|
224
|
+
setupComponentHelper(settings)
|
|
225
|
+
{
|
|
226
|
+
const component = this.getLayout(settings);
|
|
227
|
+
if(component)
|
|
228
|
+
{
|
|
229
|
+
let {container, persist = false, parent} = settings;
|
|
230
|
+
|
|
231
|
+
const helperSettings =
|
|
232
|
+
{
|
|
233
|
+
component,
|
|
234
|
+
container,
|
|
235
|
+
persist,
|
|
236
|
+
parent
|
|
237
|
+
};
|
|
238
|
+
this.controller = new ComponentHelper(this, helperSettings);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* This will resume the route.
|
|
244
|
+
*
|
|
245
|
+
* @param {object} container
|
|
246
|
+
*/
|
|
247
|
+
resume(container)
|
|
248
|
+
{
|
|
249
|
+
let controller = this.controller;
|
|
250
|
+
if(controller)
|
|
251
|
+
{
|
|
252
|
+
controller.container = container;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* This will set the route path.
|
|
258
|
+
*
|
|
259
|
+
* @param {string} path
|
|
260
|
+
* @param {string} referralPath
|
|
261
|
+
*/
|
|
262
|
+
setPath(path, referralPath)
|
|
263
|
+
{
|
|
264
|
+
this.path = path;
|
|
265
|
+
this.referralPath = referralPath;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* This will select the route.
|
|
270
|
+
*/
|
|
271
|
+
select()
|
|
272
|
+
{
|
|
273
|
+
this.set('active', true);
|
|
274
|
+
|
|
275
|
+
let params = this.stage,
|
|
276
|
+
callBack = this.callBack;
|
|
277
|
+
if(typeof callBack === 'function')
|
|
278
|
+
{
|
|
279
|
+
callBack(params);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
let controller = this.controller;
|
|
283
|
+
if(controller)
|
|
284
|
+
{
|
|
285
|
+
controller.focus(params);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
let path = this.path;
|
|
289
|
+
if(!path)
|
|
290
|
+
{
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
let hash = path.split('#')[1];
|
|
295
|
+
if(!hash)
|
|
296
|
+
{
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
this.scrollToId(hash);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* This will scroll to the element by id.
|
|
305
|
+
*
|
|
306
|
+
* @param {string} hash
|
|
307
|
+
* @returns void
|
|
308
|
+
*/
|
|
309
|
+
scrollToId(hash)
|
|
310
|
+
{
|
|
311
|
+
if(!hash)
|
|
312
|
+
{
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
let ele = document.getElementById(hash);
|
|
317
|
+
if(!ele)
|
|
318
|
+
{
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
ele.scrollIntoView(true);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* This will check if a route matches the path.
|
|
327
|
+
*
|
|
328
|
+
* @param {string} path
|
|
329
|
+
* @return {(object|boolean)}
|
|
330
|
+
*/
|
|
331
|
+
match(path)
|
|
332
|
+
{
|
|
333
|
+
let matched = false;
|
|
334
|
+
|
|
335
|
+
/* we want to check to use the supplied uri or get the
|
|
336
|
+
current uri if not setup */
|
|
337
|
+
let result = path.match(this.uriQuery);
|
|
338
|
+
if(result === null)
|
|
339
|
+
{
|
|
340
|
+
this.resetParams();
|
|
341
|
+
return matched;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if(result && typeof result === 'object')
|
|
345
|
+
{
|
|
346
|
+
/* this will remove the first match from the
|
|
347
|
+
the params */
|
|
348
|
+
result.shift();
|
|
349
|
+
matched = result;
|
|
350
|
+
/* this will get the uri params of the route
|
|
351
|
+
and if set will save them to the route */
|
|
352
|
+
this.setParams(result);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return matched;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* This will reset the params.
|
|
360
|
+
*/
|
|
361
|
+
resetParams()
|
|
362
|
+
{
|
|
363
|
+
this.stage = {};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* This will set the params.
|
|
368
|
+
*
|
|
369
|
+
* @param {object} values
|
|
370
|
+
*/
|
|
371
|
+
setParams(values)
|
|
372
|
+
{
|
|
373
|
+
if(values && typeof values === 'object')
|
|
374
|
+
{
|
|
375
|
+
let keys = this.paramKeys;
|
|
376
|
+
if(keys)
|
|
377
|
+
{
|
|
378
|
+
let params = {};
|
|
379
|
+
for(var i = 0, maxL = keys.length; i < maxL; i++)
|
|
380
|
+
{
|
|
381
|
+
var key = keys[i];
|
|
382
|
+
if(typeof key !== 'undefined')
|
|
383
|
+
{
|
|
384
|
+
params[key] = values[i];
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
this.set(params);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* This will get the params.
|
|
394
|
+
*
|
|
395
|
+
* @return {object}
|
|
396
|
+
*/
|
|
397
|
+
getParams()
|
|
398
|
+
{
|
|
399
|
+
return this.stage;
|
|
400
|
+
}
|
|
401
|
+
}
|