@base-framework/base 2.6.0

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 (57) hide show
  1. package/.jshintrc +3 -0
  2. package/base.js +41 -0
  3. package/core.js +1 -0
  4. package/data-tracker.js +351 -0
  5. package/events.js +602 -0
  6. package/main.js +1331 -0
  7. package/modules/ajax/ajax.js +514 -0
  8. package/modules/animation/animation.js +236 -0
  9. package/modules/animations/animation-controller.js +231 -0
  10. package/modules/animations/animation.js +64 -0
  11. package/modules/animations/attr-movement.js +66 -0
  12. package/modules/animations/css-movement.js +170 -0
  13. package/modules/animations/movement.js +131 -0
  14. package/modules/animations/value.js +187 -0
  15. package/modules/atom/atom.js +54 -0
  16. package/modules/component/component.js +230 -0
  17. package/modules/component/event-helper.js +119 -0
  18. package/modules/component/jot.js +144 -0
  19. package/modules/component/state-helper.js +262 -0
  20. package/modules/component/unit.js +551 -0
  21. package/modules/data/attrs.js +40 -0
  22. package/modules/data/basic-data.js +500 -0
  23. package/modules/data/data-utils.js +29 -0
  24. package/modules/data/data.js +3 -0
  25. package/modules/data/deep-data.js +541 -0
  26. package/modules/data/model-service.js +528 -0
  27. package/modules/data/model.js +133 -0
  28. package/modules/data/simple-data.js +33 -0
  29. package/modules/data-binder/connection-tracker.js +113 -0
  30. package/modules/data-binder/connection.js +16 -0
  31. package/modules/data-binder/data-binder.js +352 -0
  32. package/modules/data-binder/data-pub-sub.js +141 -0
  33. package/modules/data-binder/data-source.js +56 -0
  34. package/modules/data-binder/element-source.js +219 -0
  35. package/modules/data-binder/one-way-connection.js +46 -0
  36. package/modules/data-binder/one-way-source.js +43 -0
  37. package/modules/data-binder/source.js +36 -0
  38. package/modules/data-binder/two-way-connection.js +75 -0
  39. package/modules/data-binder/two-way-source.js +41 -0
  40. package/modules/date/date.js +544 -0
  41. package/modules/history/history.js +89 -0
  42. package/modules/html-builder/html-builder.js +434 -0
  43. package/modules/import/import.js +390 -0
  44. package/modules/layout/layout-builder.js +1269 -0
  45. package/modules/layout/layout-parser.js +134 -0
  46. package/modules/layout/watcher-helper.js +282 -0
  47. package/modules/mouse/mouse.js +114 -0
  48. package/modules/router/component-helper.js +163 -0
  49. package/modules/router/history-controller.js +216 -0
  50. package/modules/router/nav-link.js +124 -0
  51. package/modules/router/route.js +401 -0
  52. package/modules/router/router.js +789 -0
  53. package/modules/router/utils.js +31 -0
  54. package/modules/state/state-target.js +91 -0
  55. package/modules/state/state.js +171 -0
  56. package/package.json +23 -0
  57. package/shared/objects.js +99 -0
package/.jshintrc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "esversion": 6
3
+ }
package/base.js ADDED
@@ -0,0 +1,41 @@
1
+ import {base} from './core.js';
2
+ import {ajax} from './modules/ajax/ajax.js';
3
+ import {dataBinder} from './modules/data-binder/data-binder.js';
4
+ import {Data, SimpleData, Model} from './modules/data/data.js';
5
+ import {state} from './modules/state/state.js';
6
+ import {router, NavLink} from './modules/router/router.js';
7
+ import {builder} from './modules/layout/layout-builder.js';
8
+ import {Unit, Component, Jot, Watch} from './modules/component/component.js';
9
+ import {Atom} from './modules/atom/atom.js';
10
+
11
+ base.augment(
12
+ {
13
+ ajax,
14
+ dataBinder,
15
+ Data,
16
+ SimpleData,
17
+ Model,
18
+ state,
19
+ builder,
20
+ router,
21
+ Component
22
+ });
23
+
24
+ export {
25
+ base,
26
+ ajax,
27
+ dataBinder,
28
+ Data,
29
+ SimpleData,
30
+ Model,
31
+ state,
32
+ builder,
33
+ router,
34
+ Unit,
35
+ Component,
36
+ Jot,
37
+ Watch,
38
+ NavLink,
39
+ Atom
40
+ };
41
+
package/core.js ADDED
@@ -0,0 +1 @@
1
+ export {base} from './events.js';
@@ -0,0 +1,351 @@
1
+ /**
2
+ * TrackerTypes
3
+ *
4
+ * This will add and remove tracker types to the data tracker.
5
+ *
6
+ */
7
+ const TrackerTypes =
8
+ {
9
+ /**
10
+ * @member {object} The Type and callBack that is called
11
+ * when the type is removed from the object.
12
+ */
13
+ types: {},
14
+
15
+ /**
16
+ * This will add a type.
17
+ * @param {string} type
18
+ * @param {function} callBack The function to call when an object
19
+ * is having the type removed.
20
+ */
21
+ add(type, callBack)
22
+ {
23
+ this.types[type] = callBack;
24
+ },
25
+
26
+ /**
27
+ * This will get a type or return false.
28
+ * @param {string} type
29
+ * @return {(function|boolean)} The callBack or false.
30
+ */
31
+ get(type)
32
+ {
33
+ return this.types[type] || false;
34
+ },
35
+
36
+ /**
37
+ * This will remove a type.
38
+ * @param {string} type
39
+ */
40
+ remove(type)
41
+ {
42
+ delete this.types[type];
43
+ }
44
+ };
45
+
46
+ /**
47
+ * Tracker
48
+ *
49
+ * This will create a tracker for an object that will
50
+ * store each type added and the data stored to
51
+ * each type.
52
+ *
53
+ * @class
54
+ */
55
+ class Tracker
56
+ {
57
+ /**
58
+ * @constructor
59
+ */
60
+ constructor()
61
+ {
62
+ /**
63
+ * @member {object} types
64
+ */
65
+ this.types = {};
66
+ }
67
+
68
+ /**
69
+ * This will add data to a type.
70
+ *
71
+ * @public
72
+ * @param {string} addingType The type of data.
73
+ * @param {*} data The data to store
74
+ */
75
+ add(addingType, data)
76
+ {
77
+ let type = this.types[addingType] || (this.types[addingType] = []);
78
+ type.push(data);
79
+ }
80
+
81
+ /**
82
+ * This will get all the data stored to a data type.
83
+ * @param {string} type
84
+ * @return {*|boolean} the data or false.
85
+ */
86
+ get(type)
87
+ {
88
+ return this.types[type] || false;
89
+ }
90
+
91
+ /**
92
+ * This will call the callBack with the data.
93
+ *
94
+ * @private
95
+ * @param {function} callBack
96
+ * @param {*} data
97
+ */
98
+ removeByCallBack(callBack, data)
99
+ {
100
+ if(typeof callBack === 'function')
101
+ {
102
+ callBack(data);
103
+ }
104
+ }
105
+
106
+ /**
107
+ * This will remove the data by type.
108
+ *
109
+ * @private
110
+ * @param {string} removingType
111
+ */
112
+ removeType(removingType)
113
+ {
114
+ let types = this.types;
115
+ if(types)
116
+ {
117
+ let type = types[removingType];
118
+ if(type.length)
119
+ {
120
+ let data,
121
+ callBack = TrackerTypes.get(removingType);
122
+ for(var i = 0, length = type.length; i < length; i++)
123
+ {
124
+ data = type[i];
125
+ if(data)
126
+ {
127
+ // this will stop any circular referrences
128
+ type[i] = null;
129
+
130
+ this.removeByCallBack(callBack, data);
131
+ }
132
+ }
133
+ delete types[type];
134
+ }
135
+ }
136
+ }
137
+
138
+ /**
139
+ * This will remove the data by type or all if no type is
140
+ * set.
141
+ *
142
+ * @public
143
+ * @param {string} [type]
144
+ */
145
+ remove(type)
146
+ {
147
+ if(type)
148
+ {
149
+ this.removeType(type);
150
+ }
151
+ else
152
+ {
153
+ let types = this.types;
154
+ for(var prop in types)
155
+ {
156
+ if(types.hasOwnProperty(prop))
157
+ {
158
+ type = types[prop];
159
+ if(!type)
160
+ {
161
+ continue;
162
+ }
163
+
164
+ this.removeType(prop);
165
+ }
166
+ }
167
+
168
+ delete this.types;
169
+ }
170
+ }
171
+ }
172
+
173
+ /**
174
+ * DataTracker
175
+ *
176
+ * This will add data tracking for objects. The DataTracker is
177
+ * a single point where any data can be tracked to an object
178
+ * or element. Modules can register types to store their own
179
+ * data that can allow the data to be removed when the element
180
+ * is removed.
181
+ *
182
+ * @class
183
+ */
184
+ export class DataTracker
185
+ {
186
+ /**
187
+ * @constructor
188
+ */
189
+ constructor()
190
+ {
191
+ /**
192
+ * @private
193
+ * @member trackers This is an object that stores all tracker
194
+ * objects by tracking id.
195
+ */
196
+ this.trackers = {};
197
+
198
+ /**
199
+ * @private
200
+ * @member {int} trackingCount
201
+ */
202
+ this.trackingCount = 0;
203
+ }
204
+
205
+ /**
206
+ * This will add a new type to the data tracker.
207
+ *
208
+ * @public
209
+ * @param {string} type The new type.
210
+ * @param {function} callBack The callBack to help clean
211
+ * up data when removed.
212
+ */
213
+ addType(type, callBack)
214
+ {
215
+ TrackerTypes.add(type, callBack);
216
+ }
217
+
218
+ /**
219
+ * This will remove a type from the data tracker.
220
+ * @param {string} type
221
+ */
222
+ removeType(type)
223
+ {
224
+ TrackerTypes.remove(type);
225
+ }
226
+
227
+ /**
228
+ * This will get the object tracking id or set it if
229
+ * not set.
230
+ *
231
+ * @param {object} obj
232
+ * @return {string}
233
+ */
234
+ getTrackingId(obj)
235
+ {
236
+ return obj.trackingId || (obj.trackingId = 'dt' + this.trackingCount++);
237
+ }
238
+
239
+ /**
240
+ * This will add data to an object.
241
+ *
242
+ * @param {object} obj
243
+ * @param {string} type The type name.
244
+ * @param {*} data The data to track.
245
+ */
246
+ add(obj, type, data)
247
+ {
248
+ const id = this.getTrackingId(obj),
249
+ tracker = this.find(id);
250
+
251
+ tracker.add(type, data);
252
+ }
253
+
254
+ /**
255
+ * This will get the data from a type or the tracker object
256
+ * if type is not set.
257
+ *
258
+ * @param {object} obj
259
+ * @param {string} [type]
260
+ * @return {*}
261
+ */
262
+ get(obj, type)
263
+ {
264
+ const id = obj.trackingId;
265
+ let tracker = this.trackers[id];
266
+ if(!tracker)
267
+ {
268
+ return false;
269
+ }
270
+
271
+ return (type)? tracker.get(type) : tracker;
272
+ }
273
+
274
+ /**
275
+ * This will get the tracker or create a new tracker
276
+ * if no tracker is set.
277
+ *
278
+ * @param {string} id
279
+ * @return {object} The tracker.
280
+ */
281
+ find(id)
282
+ {
283
+ let trackers = this.trackers;
284
+ return (trackers[id] || (trackers[id] = new Tracker()));
285
+ }
286
+
287
+ /**
288
+ * This will check if an object is empty.
289
+ *
290
+ * @param {object} obj
291
+ * @return {boolean}
292
+ */
293
+ isEmpty(obj)
294
+ {
295
+ if(!obj || typeof obj !== 'object')
296
+ {
297
+ return true;
298
+ }
299
+
300
+ /* we want to loop through each property and
301
+ check if it belongs to the object directly */
302
+ for(var key in obj)
303
+ {
304
+ if(obj.hasOwnProperty(key))
305
+ {
306
+ return false;
307
+ }
308
+ }
309
+ return true;
310
+ }
311
+
312
+ /**
313
+ * This will remove a type or all data for an object if
314
+ * no type is set.
315
+ *
316
+ * @param {object} obj
317
+ * @param {stirng} [type]
318
+ */
319
+ remove(obj, type)
320
+ {
321
+ const id = obj.trackingId;
322
+ if(!id)
323
+ {
324
+ return true;
325
+ }
326
+
327
+ let tracker = this.trackers[id];
328
+ if(!tracker)
329
+ {
330
+ return false;
331
+ }
332
+
333
+ if(type)
334
+ {
335
+ tracker.remove(type);
336
+
337
+ /* this will remove the msg from the elements
338
+ if no elements are listed under the msg */
339
+ if(this.isEmpty(tracker.types))
340
+ {
341
+ delete this.trackers[id];
342
+ }
343
+ }
344
+ else
345
+ {
346
+ tracker.remove();
347
+
348
+ delete this.trackers[id];
349
+ }
350
+ }
351
+ }