@base-framework/base 2.6.1 → 2.6.2

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.
Files changed (248) hide show
  1. package/README.md +1 -0
  2. package/dist/base.js +1 -0
  3. package/package.json +9 -4
  4. package/.jshintrc +0 -3
  5. package/base.js +0 -41
  6. package/base.min.js +0 -1
  7. package/core.js +0 -1
  8. package/data-tracker.js +0 -351
  9. package/es5/base.js +0 -2968
  10. package/es5/modules/ajax.js +0 -663
  11. package/es5/modules/animation.js +0 -188
  12. package/es5/modules/animations.js +0 -1080
  13. package/es5/modules/atom.js +0 -65
  14. package/es5/modules/component.js +0 -1310
  15. package/es5/modules/data-binder.js +0 -1131
  16. package/es5/modules/data.js +0 -1808
  17. package/es5/modules/date.js +0 -525
  18. package/es5/modules/form-validator.js +0 -324
  19. package/es5/modules/history.js +0 -126
  20. package/es5/modules/html-builder.js +0 -461
  21. package/es5/modules/layout.js +0 -1679
  22. package/es5/modules/mouse.js +0 -124
  23. package/es5/modules/nav-link.js +0 -123
  24. package/es5/modules/olderversions/animations-ease.js +0 -1095
  25. package/es5/modules/olderversions/animations-update.js +0 -1048
  26. package/es5/modules/olderversions/base-animations.js +0 -636
  27. package/es5/modules/olderversions/base-component-class.js +0 -100
  28. package/es5/modules/olderversions/base-data-binder-1.js +0 -407
  29. package/es5/modules/olderversions/base-data-binder-class.js +0 -358
  30. package/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  31. package/es5/modules/olderversions/base-mode-1.js +0 -777
  32. package/es5/modules/olderversions/base-model-class.js +0 -585
  33. package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  34. package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  35. package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  36. package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  37. package/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  38. package/es5/modules/olderversions/data-tracker.js +0 -187
  39. package/es5/modules/olderversions/event-update.js +0 -666
  40. package/es5/modules/olderversions/nav-link.js +0 -119
  41. package/es5/modules/olderversions/router-with-templates-1.js +0 -785
  42. package/es5/modules/olderversions/router-with-templates.js +0 -701
  43. package/es5/modules/prototypes/ajax.js +0 -657
  44. package/es5/modules/prototypes/atom.js +0 -65
  45. package/es5/modules/prototypes/component.js +0 -972
  46. package/es5/modules/prototypes/data-binder.js +0 -1089
  47. package/es5/modules/prototypes/data.js +0 -1290
  48. package/es5/modules/prototypes/html-builder.js +0 -414
  49. package/es5/modules/prototypes/layout.js +0 -879
  50. package/es5/modules/router.js +0 -1680
  51. package/es5/modules/state.js +0 -274
  52. package/es6/.jshintrc +0 -3
  53. package/es6/base.js +0 -41
  54. package/es6/core.js +0 -1
  55. package/es6/data-tracker.js +0 -351
  56. package/es6/events.js +0 -602
  57. package/es6/legacy/es5/base.js +0 -2968
  58. package/es6/legacy/es5/modules/ajax.js +0 -663
  59. package/es6/legacy/es5/modules/animation.js +0 -188
  60. package/es6/legacy/es5/modules/animations.js +0 -1080
  61. package/es6/legacy/es5/modules/atom.js +0 -65
  62. package/es6/legacy/es5/modules/component.js +0 -1310
  63. package/es6/legacy/es5/modules/data-binder.js +0 -1131
  64. package/es6/legacy/es5/modules/data.js +0 -1808
  65. package/es6/legacy/es5/modules/date.js +0 -525
  66. package/es6/legacy/es5/modules/form-validator.js +0 -324
  67. package/es6/legacy/es5/modules/history.js +0 -126
  68. package/es6/legacy/es5/modules/html-builder.js +0 -461
  69. package/es6/legacy/es5/modules/layout.js +0 -1679
  70. package/es6/legacy/es5/modules/mouse.js +0 -124
  71. package/es6/legacy/es5/modules/nav-link.js +0 -123
  72. package/es6/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
  73. package/es6/legacy/es5/modules/olderversions/animations-update.js +0 -1048
  74. package/es6/legacy/es5/modules/olderversions/base-animations.js +0 -636
  75. package/es6/legacy/es5/modules/olderversions/base-component-class.js +0 -100
  76. package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
  77. package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
  78. package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  79. package/es6/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
  80. package/es6/legacy/es5/modules/olderversions/base-model-class.js +0 -585
  81. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  82. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  83. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  84. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  85. package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  86. package/es6/legacy/es5/modules/olderversions/data-tracker.js +0 -187
  87. package/es6/legacy/es5/modules/olderversions/event-update.js +0 -666
  88. package/es6/legacy/es5/modules/olderversions/nav-link.js +0 -119
  89. package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
  90. package/es6/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
  91. package/es6/legacy/es5/modules/prototypes/ajax.js +0 -657
  92. package/es6/legacy/es5/modules/prototypes/atom.js +0 -65
  93. package/es6/legacy/es5/modules/prototypes/component.js +0 -972
  94. package/es6/legacy/es5/modules/prototypes/data-binder.js +0 -1089
  95. package/es6/legacy/es5/modules/prototypes/data.js +0 -1290
  96. package/es6/legacy/es5/modules/prototypes/html-builder.js +0 -414
  97. package/es6/legacy/es5/modules/prototypes/layout.js +0 -879
  98. package/es6/legacy/es5/modules/router.js +0 -1680
  99. package/es6/legacy/es5/modules/state.js +0 -274
  100. package/es6/main.js +0 -1331
  101. package/es6/modules/ajax/ajax.js +0 -514
  102. package/es6/modules/animation/animation.js +0 -236
  103. package/es6/modules/animations/animation-controller.js +0 -231
  104. package/es6/modules/animations/animation.js +0 -64
  105. package/es6/modules/animations/attr-movement.js +0 -66
  106. package/es6/modules/animations/css-movement.js +0 -170
  107. package/es6/modules/animations/movement.js +0 -131
  108. package/es6/modules/animations/value.js +0 -187
  109. package/es6/modules/atom/atom.js +0 -54
  110. package/es6/modules/component/component.js +0 -230
  111. package/es6/modules/component/event-helper.js +0 -119
  112. package/es6/modules/component/jot.js +0 -144
  113. package/es6/modules/component/state-helper.js +0 -262
  114. package/es6/modules/component/unit.js +0 -551
  115. package/es6/modules/data/attrs.js +0 -40
  116. package/es6/modules/data/basic-data.js +0 -500
  117. package/es6/modules/data/data-utils.js +0 -29
  118. package/es6/modules/data/data.js +0 -3
  119. package/es6/modules/data/deep-data.js +0 -541
  120. package/es6/modules/data/model-service.js +0 -528
  121. package/es6/modules/data/model.js +0 -133
  122. package/es6/modules/data/simple-data.js +0 -33
  123. package/es6/modules/data-binder/connection-tracker.js +0 -113
  124. package/es6/modules/data-binder/connection.js +0 -16
  125. package/es6/modules/data-binder/data-binder.js +0 -352
  126. package/es6/modules/data-binder/data-pub-sub.js +0 -141
  127. package/es6/modules/data-binder/data-source.js +0 -56
  128. package/es6/modules/data-binder/element-source.js +0 -219
  129. package/es6/modules/data-binder/one-way-connection.js +0 -46
  130. package/es6/modules/data-binder/one-way-source.js +0 -43
  131. package/es6/modules/data-binder/source.js +0 -36
  132. package/es6/modules/data-binder/two-way-connection.js +0 -75
  133. package/es6/modules/data-binder/two-way-source.js +0 -41
  134. package/es6/modules/date/date.js +0 -544
  135. package/es6/modules/history/history.js +0 -89
  136. package/es6/modules/html-builder/html-builder.js +0 -434
  137. package/es6/modules/import/import.js +0 -390
  138. package/es6/modules/layout/layout-builder.js +0 -1269
  139. package/es6/modules/layout/layout-parser.js +0 -134
  140. package/es6/modules/layout/watcher-helper.js +0 -282
  141. package/es6/modules/mouse/mouse.js +0 -114
  142. package/es6/modules/router/component-helper.js +0 -163
  143. package/es6/modules/router/history-controller.js +0 -216
  144. package/es6/modules/router/nav-link.js +0 -124
  145. package/es6/modules/router/route.js +0 -401
  146. package/es6/modules/router/router.js +0 -789
  147. package/es6/modules/router/utils.js +0 -31
  148. package/es6/modules/state/state-target.js +0 -91
  149. package/es6/modules/state/state.js +0 -171
  150. package/es6/package-lock.json +0 -13
  151. package/es6/package.json +0 -28
  152. package/es6/shared/objects.js +0 -99
  153. package/events.js +0 -602
  154. package/legacy/es5/base.js +0 -2968
  155. package/legacy/es5/modules/ajax.js +0 -663
  156. package/legacy/es5/modules/animation.js +0 -188
  157. package/legacy/es5/modules/animations.js +0 -1080
  158. package/legacy/es5/modules/atom.js +0 -65
  159. package/legacy/es5/modules/component.js +0 -1310
  160. package/legacy/es5/modules/data-binder.js +0 -1131
  161. package/legacy/es5/modules/data.js +0 -1808
  162. package/legacy/es5/modules/date.js +0 -525
  163. package/legacy/es5/modules/form-validator.js +0 -324
  164. package/legacy/es5/modules/history.js +0 -126
  165. package/legacy/es5/modules/html-builder.js +0 -461
  166. package/legacy/es5/modules/layout.js +0 -1679
  167. package/legacy/es5/modules/mouse.js +0 -124
  168. package/legacy/es5/modules/nav-link.js +0 -123
  169. package/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
  170. package/legacy/es5/modules/olderversions/animations-update.js +0 -1048
  171. package/legacy/es5/modules/olderversions/base-animations.js +0 -636
  172. package/legacy/es5/modules/olderversions/base-component-class.js +0 -100
  173. package/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
  174. package/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
  175. package/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  176. package/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
  177. package/legacy/es5/modules/olderversions/base-model-class.js +0 -585
  178. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  179. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  180. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  181. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  182. package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  183. package/legacy/es5/modules/olderversions/data-tracker.js +0 -187
  184. package/legacy/es5/modules/olderversions/event-update.js +0 -666
  185. package/legacy/es5/modules/olderversions/nav-link.js +0 -119
  186. package/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
  187. package/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
  188. package/legacy/es5/modules/prototypes/ajax.js +0 -657
  189. package/legacy/es5/modules/prototypes/atom.js +0 -65
  190. package/legacy/es5/modules/prototypes/component.js +0 -972
  191. package/legacy/es5/modules/prototypes/data-binder.js +0 -1089
  192. package/legacy/es5/modules/prototypes/data.js +0 -1290
  193. package/legacy/es5/modules/prototypes/html-builder.js +0 -414
  194. package/legacy/es5/modules/prototypes/layout.js +0 -879
  195. package/legacy/es5/modules/router.js +0 -1680
  196. package/legacy/es5/modules/state.js +0 -274
  197. package/main.js +0 -1331
  198. package/modules/ajax/ajax.js +0 -514
  199. package/modules/animation/animation.js +0 -236
  200. package/modules/animations/animation-controller.js +0 -231
  201. package/modules/animations/animation.js +0 -64
  202. package/modules/animations/attr-movement.js +0 -66
  203. package/modules/animations/css-movement.js +0 -170
  204. package/modules/animations/movement.js +0 -131
  205. package/modules/animations/value.js +0 -187
  206. package/modules/atom/atom.js +0 -54
  207. package/modules/component/component.js +0 -230
  208. package/modules/component/event-helper.js +0 -119
  209. package/modules/component/jot.js +0 -144
  210. package/modules/component/state-helper.js +0 -262
  211. package/modules/component/unit.js +0 -551
  212. package/modules/data/attrs.js +0 -40
  213. package/modules/data/basic-data.js +0 -500
  214. package/modules/data/data-utils.js +0 -29
  215. package/modules/data/data.js +0 -3
  216. package/modules/data/deep-data.js +0 -541
  217. package/modules/data/model-service.js +0 -528
  218. package/modules/data/model.js +0 -133
  219. package/modules/data/simple-data.js +0 -33
  220. package/modules/data-binder/connection-tracker.js +0 -113
  221. package/modules/data-binder/connection.js +0 -16
  222. package/modules/data-binder/data-binder.js +0 -352
  223. package/modules/data-binder/data-pub-sub.js +0 -141
  224. package/modules/data-binder/data-source.js +0 -56
  225. package/modules/data-binder/element-source.js +0 -219
  226. package/modules/data-binder/one-way-connection.js +0 -46
  227. package/modules/data-binder/one-way-source.js +0 -43
  228. package/modules/data-binder/source.js +0 -36
  229. package/modules/data-binder/two-way-connection.js +0 -75
  230. package/modules/data-binder/two-way-source.js +0 -41
  231. package/modules/date/date.js +0 -544
  232. package/modules/history/history.js +0 -89
  233. package/modules/html-builder/html-builder.js +0 -434
  234. package/modules/import/import.js +0 -390
  235. package/modules/layout/layout-builder.js +0 -1269
  236. package/modules/layout/layout-parser.js +0 -134
  237. package/modules/layout/watcher-helper.js +0 -282
  238. package/modules/mouse/mouse.js +0 -114
  239. package/modules/router/component-helper.js +0 -163
  240. package/modules/router/history-controller.js +0 -216
  241. package/modules/router/nav-link.js +0 -124
  242. package/modules/router/route.js +0 -401
  243. package/modules/router/router.js +0 -789
  244. package/modules/router/utils.js +0 -31
  245. package/modules/state/state-target.js +0 -91
  246. package/modules/state/state.js +0 -171
  247. package/shared/objects.js +0 -99
  248. package/update +0 -16
@@ -1,216 +0,0 @@
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
- }
@@ -1,124 +0,0 @@
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
- }
@@ -1,401 +0,0 @@
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
- }