@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
@@ -0,0 +1,230 @@
1
+ import {base} from '../../core.js';
2
+ import {Unit} from './unit.js';
3
+ import {state} from '../state/state.js';
4
+ import {EventHelper} from './event-helper.js';
5
+ import {StateHelper} from './state-helper.js';
6
+
7
+ export {Unit} from './unit.js';
8
+ export {Jot} from './jot.js';
9
+ export {Watch} from '../layout/layout-builder.js';
10
+
11
+ /**
12
+ * Component
13
+ *
14
+ * @class
15
+ * @augments Unit
16
+ *
17
+ * This will allow components to be extended
18
+ * from a single factory.
19
+ *
20
+ * @example
21
+ * class QuickFlashPanel extends base.Component
22
+ * {
23
+ * constructor(props)
24
+ * {
25
+ * // this will setup the component id
26
+ * super(props);
27
+ * },
28
+ *
29
+ * render()
30
+ * {
31
+ * return {
32
+ *
33
+ * };
34
+ * }
35
+ * }
36
+ */
37
+ export class Component extends Unit
38
+ {
39
+ /**
40
+ * @constructor
41
+ * @param {object} [props]
42
+ */
43
+ constructor(props)
44
+ {
45
+ super(props);
46
+
47
+ /**
48
+ * @param {bool} isComponent
49
+ */
50
+ this.isComponent = true;
51
+
52
+ /* this will allow the component to override the
53
+ state target id to add a custom id */
54
+ /**
55
+ * @member {string} [stateTargetId] // optional override of state id
56
+ */
57
+ this.stateTargetId = null;
58
+ }
59
+
60
+ /**
61
+ * This will initialize the component.
62
+ * @protected
63
+ */
64
+ initialize()
65
+ {
66
+ this.setupContext();
67
+ this.beforeSetup();
68
+ this.addStates();
69
+ this.buildLayout();
70
+ this.addEvents();
71
+ this.afterSetup();
72
+ }
73
+
74
+ /**
75
+ * This will setup the state target.
76
+ *
77
+ * @protected
78
+ * @param {string} [id]
79
+ */
80
+ setupStateTarget(id)
81
+ {
82
+ let targetId = id || this.stateTargetId || this.id;
83
+ this.state = state.getTarget(targetId);
84
+ }
85
+
86
+ /**
87
+ * Override this to setup the component states.
88
+ * @return {object}
89
+ */
90
+ setupStates()
91
+ {
92
+ /*
93
+ return {
94
+ action: 'state'
95
+ };
96
+
97
+ or
98
+
99
+ return {
100
+ action:
101
+ {
102
+ state: 'state',
103
+ callBack(state, prevState)
104
+ {
105
+
106
+ }
107
+ }
108
+ };*/
109
+
110
+ return {
111
+
112
+ };
113
+ }
114
+
115
+ /**
116
+ * This will add the states.
117
+ * @protected
118
+ */
119
+ addStates()
120
+ {
121
+ /* this will check to restore previous a previous state if the
122
+ component has been preserved. */
123
+ let state = this.state;
124
+ if(state)
125
+ {
126
+ this.stateHelper.restore(state);
127
+ return;
128
+ }
129
+
130
+ /* this will only setupa state manager if
131
+ we have states */
132
+ let states = this.setupStates();
133
+ if(base.isEmpty(states))
134
+ {
135
+ return;
136
+ }
137
+
138
+ this.setupStateTarget();
139
+ this.stateHelper = new StateHelper(this.state, states);
140
+ }
141
+
142
+ /**
143
+ * This will remove the states.
144
+ * @protected
145
+ */
146
+ removeStates()
147
+ {
148
+ let state = this.state;
149
+ if(!state)
150
+ {
151
+ return false;
152
+ }
153
+
154
+ this.stateHelper.removeRemoteStates();
155
+ state.remove();
156
+ }
157
+
158
+ /**
159
+ * This will setup the event helper.
160
+ *
161
+ * @protected
162
+ */
163
+ setupEventHelper()
164
+ {
165
+ if(!this.events)
166
+ {
167
+ this.events = new EventHelper();
168
+ }
169
+ }
170
+
171
+ /**
172
+ * This will setup the events.
173
+ *
174
+ * @protected
175
+ * @return {array}
176
+ */
177
+ setupEvents()
178
+ {
179
+ return [
180
+ //['action', element, function(e){}, false]
181
+ ];
182
+ }
183
+
184
+ /**
185
+ * This will add the events.
186
+ *
187
+ * @protected
188
+ */
189
+ addEvents()
190
+ {
191
+ let events = this.setupEvents();
192
+ if(events.length < 1)
193
+ {
194
+ return false;
195
+ }
196
+
197
+ this.setupEventHelper();
198
+ this.events.addEvents(events);
199
+ }
200
+
201
+ /**
202
+ * This will remove the events.
203
+ * @protected
204
+ */
205
+ removeEvents()
206
+ {
207
+ let events = this.events;
208
+ if(events)
209
+ {
210
+ events.reset();
211
+ }
212
+ }
213
+
214
+ /**
215
+ * This will prepare the component to be destroyed.
216
+ */
217
+ prepareDestroy()
218
+ {
219
+ this.rendered = false;
220
+ this.beforeDestroy();
221
+ this.removeEvents();
222
+ this.removeStates();
223
+ this.removeContext();
224
+
225
+ if(this.data && this.persist === false)
226
+ {
227
+ this.data.unlink();
228
+ }
229
+ }
230
+ }
@@ -0,0 +1,119 @@
1
+ import {base} from '../../core.js';
2
+
3
+ /**
4
+ * EventHelper
5
+ *
6
+ * This will create an event object to make
7
+ * adding and removing events easier.
8
+ * @class
9
+ */
10
+ export class EventHelper
11
+ {
12
+ /**
13
+ * @constructor
14
+ */
15
+ constructor()
16
+ {
17
+ this.events = [];
18
+ }
19
+
20
+ /**
21
+ * This will add an array of events.
22
+ *
23
+ * @param {array} events
24
+ */
25
+ addEvents(events)
26
+ {
27
+ let length = events.length;
28
+ if(length < 1)
29
+ {
30
+ return false;
31
+ }
32
+
33
+ let event;
34
+ for(var i = 0; i < length; i++)
35
+ {
36
+ event = events[i];
37
+ this.on(...event);
38
+ }
39
+ }
40
+
41
+ /**
42
+ * This will add an event.
43
+ *
44
+ * @param {string} event
45
+ * @param {object} obj
46
+ * @param {function} callBack
47
+ * @param {boolean} capture
48
+ */
49
+ on(event, obj, callBack, capture)
50
+ {
51
+ base.on(event, obj, callBack, capture);
52
+
53
+ this.events.push({
54
+ event,
55
+ obj,
56
+ callBack,
57
+ capture
58
+ });
59
+ }
60
+
61
+ /**
62
+ * This will remove an event.
63
+ *
64
+ * @param {string} event
65
+ * @param {object} obj
66
+ * @param {function} callBack
67
+ * @param {boolean} capture
68
+ */
69
+ off(event, obj, callBack, capture)
70
+ {
71
+ base.off(event, obj, callBack, capture);
72
+
73
+ let option,
74
+ events = this.events;
75
+ for(var i = 0, length = events.length; i < length; i++)
76
+ {
77
+ option = events[i];
78
+ if(option.event === event && option.obj === obj)
79
+ {
80
+ events.splice(i, 1);
81
+ break;
82
+ }
83
+ }
84
+ }
85
+
86
+ /**
87
+ * This will set all events.
88
+ */
89
+ set()
90
+ {
91
+ let event,
92
+ events = this.events;
93
+ for(var i = 0, length = events.length; i < length; i++)
94
+ {
95
+ event = events[i];
96
+ base.on(event.event, event.obj, event.callBack, event.capture);
97
+ }
98
+ }
99
+
100
+ unset()
101
+ {
102
+ let event,
103
+ events = this.events;
104
+ for(var i = 0, length = events.length; i < length; i++)
105
+ {
106
+ event = events[i];
107
+ base.off(event.event, event.obj, event.callBack, event.capture);
108
+ }
109
+ }
110
+
111
+ /**
112
+ * This will reset the events.
113
+ */
114
+ reset()
115
+ {
116
+ this.unset();
117
+ this.events = [];
118
+ }
119
+ }
@@ -0,0 +1,144 @@
1
+ import {Unit} from './unit.js';
2
+ import {Component} from './component.js';
3
+
4
+ /**
5
+ * This will store the jot shorthand method alaises.
6
+ */
7
+ const JOT_SHORTHAND_METHODS =
8
+ {
9
+ created: 'onCreated',
10
+ state: 'setupStates',
11
+ events: 'setupEevents',
12
+ before: 'beforeSetup',
13
+ render: 'render',
14
+ after: 'afterSetup',
15
+ destroy: 'beforeDestroy'
16
+ };
17
+
18
+ /**
19
+ * This will get the jot method by value. If the method is an
20
+ * object, it will be nested in a function.
21
+ *
22
+ * @param {object|function} value
23
+ * @returns {function}
24
+ */
25
+ const getJotShorthandMethod = (value) =>
26
+ {
27
+ const valueType = (typeof value);
28
+ return (valueType === 'function')? value : function()
29
+ {
30
+ return value;
31
+ };
32
+ };
33
+
34
+ /**
35
+ * This will create a jot component object that will be used
36
+ * to create the jot component.
37
+ *
38
+ * @param {object} settings
39
+ * @returns {object}
40
+ */
41
+ const JotComponent = (settings) =>
42
+ {
43
+ const component = {};
44
+ if(!settings)
45
+ {
46
+ return component;
47
+ }
48
+
49
+ for(var prop in settings)
50
+ {
51
+ if(settings.hasOwnProperty(prop) === false)
52
+ {
53
+ continue;
54
+ }
55
+
56
+ let value = settings[prop];
57
+ let alias = JOT_SHORTHAND_METHODS[prop];
58
+ if(alias)
59
+ {
60
+ component[alias] = getJotShorthandMethod(value);
61
+ continue;
62
+ }
63
+
64
+ component[prop] = value;
65
+ }
66
+
67
+ return component;
68
+ };
69
+
70
+ /**
71
+ * This will create a component class.
72
+ *
73
+ * @param {object} settings
74
+ * @returns {class}
75
+ */
76
+ const createComponentClass = (settings) =>
77
+ {
78
+ class Child extends Component
79
+ {
80
+
81
+ }
82
+
83
+ Object.assign(Child.prototype, settings);
84
+ return Child;
85
+ };
86
+
87
+ /**
88
+ * This will create a unit class.
89
+ *
90
+ * @param {object} settings
91
+ * @returns {class}
92
+ */
93
+ const createUnitClass = (settings) =>
94
+ {
95
+ class Child extends Unit
96
+ {
97
+
98
+ }
99
+
100
+ Object.assign(Child.prototype, settings);
101
+ return Child;
102
+ };
103
+
104
+ /**
105
+ * This will create a shorthand component.
106
+ *
107
+ * @param {object|function} layout
108
+ * @returns {function}
109
+ */
110
+ export const Jot = function(layout)
111
+ {
112
+ if(!layout)
113
+ {
114
+ return null;
115
+ }
116
+
117
+ let settings;
118
+ switch(typeof layout)
119
+ {
120
+ case 'object':
121
+ if(layout.render)
122
+ {
123
+ settings = JotComponent(layout);
124
+ return createComponentClass(settings);
125
+ }
126
+
127
+ settings = {
128
+ render: function()
129
+ {
130
+ return layout;
131
+ }
132
+ };
133
+
134
+ // this will create a stateless and dataless unit
135
+ return createUnitClass(settings);
136
+ case 'function':
137
+ settings = {
138
+ render: layout
139
+ };
140
+
141
+ // this will create a stateless and dataless unit
142
+ return createUnitClass(settings);
143
+ }
144
+ };