@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,262 @@
1
+ import {state} from '../state/state.js';
2
+
3
+ /**
4
+ * StateHelper
5
+ *
6
+ * This is a helper to manage component states.
7
+ */
8
+ export class StateHelper
9
+ {
10
+ /**
11
+ * @constructor
12
+ * @param {object} state
13
+ * @param {object} states
14
+ */
15
+ constructor(state, states)
16
+ {
17
+ this.remoteStates = [];
18
+
19
+ let actions = this.convertStates(states);
20
+ this.addStatesToTarget(state, actions);
21
+ }
22
+
23
+ /**
24
+ * This will add states to a state.
25
+ *
26
+ * @param {object} state
27
+ * @param {object} states
28
+ */
29
+ addStates(state, states)
30
+ {
31
+ let actions = this.convertStates(states);
32
+ this.addStatesToTarget(state, actions);
33
+ }
34
+
35
+ /**
36
+ * This will create a state object.
37
+ *
38
+ * @param {string} action
39
+ * @param {*} state
40
+ * @param {function} callBack
41
+ * @param {string} [targetId]
42
+ * @return {object}
43
+ */
44
+ createState(action, state, callBack, targetId)
45
+ {
46
+ return {
47
+ action,
48
+ state,
49
+ callBack,
50
+ targetId,
51
+ token: null
52
+ };
53
+ }
54
+
55
+ /**
56
+ * This will convert an action object to a state array.
57
+ *
58
+ * @protected
59
+ * @param {object} action
60
+ * @return {array}
61
+ */
62
+ convertStates(action)
63
+ {
64
+ let actions = [];
65
+ for(var prop in action)
66
+ {
67
+ if(action.hasOwnProperty(prop) === false)
68
+ {
69
+ continue;
70
+ }
71
+ else if(prop === 'remotes')
72
+ {
73
+ this.setupRemoteStates(action[prop], actions);
74
+ continue;
75
+ }
76
+
77
+ var targetId = null,
78
+ callBack = null,
79
+ state = action[prop];
80
+ if(state && typeof state === 'object')
81
+ {
82
+ callBack = state.callBack;
83
+ targetId = state.id || state.targetId;
84
+ state = state.state;
85
+ }
86
+
87
+ actions.push(this.createState(
88
+ prop,
89
+ state,
90
+ callBack,
91
+ targetId
92
+ ));
93
+ }
94
+ return actions;
95
+ }
96
+
97
+ setupRemoteStates(remotes, actions)
98
+ {
99
+ let remote;
100
+ for(var i = 0, length = remotes.length; i < length; i++)
101
+ {
102
+ remote = remotes[i];
103
+ if(!remote)
104
+ {
105
+ continue;
106
+ }
107
+
108
+ for(var prop in remote)
109
+ {
110
+ if(remote.hasOwnProperty(prop) === false || prop === 'id')
111
+ {
112
+ continue;
113
+ }
114
+
115
+ var callBack = null,
116
+ value = remote[prop],
117
+ state = (value !== null)? value : undefined;
118
+ if(state && typeof state === 'object')
119
+ {
120
+ callBack = state.callBack;
121
+ state = state.state;
122
+ }
123
+
124
+ actions.push(this.createState(
125
+ prop,
126
+ state,
127
+ callBack,
128
+ remote.id
129
+ ));
130
+ }
131
+ }
132
+ }
133
+
134
+ /**
135
+ * This will remove remote states.
136
+ */
137
+ removeRemoteStates()
138
+ {
139
+ let remoteStates = this.remoteStates;
140
+ if(remoteStates)
141
+ {
142
+ this.removeActions(remoteStates);
143
+ }
144
+ }
145
+
146
+ /**
147
+ * This will remove the actions.
148
+ *
149
+ * @param {array} actions
150
+ */
151
+ removeActions(actions)
152
+ {
153
+ if(actions.length < 1)
154
+ {
155
+ return;
156
+ }
157
+
158
+ for(var i = 0, length = actions.length; i < length; i++)
159
+ {
160
+ var action = actions[i];
161
+ state.remove(action.targetId, action.action, action.token);
162
+ }
163
+ }
164
+
165
+ /**
166
+ * This will restore a state.
167
+ *
168
+ * @param {object} state
169
+ */
170
+ restore(state)
171
+ {
172
+ state.restore();
173
+
174
+ let remotes = this.remoteStates;
175
+ if(!remotes)
176
+ {
177
+ return;
178
+ }
179
+
180
+ for(var i = 0, length = remotes.length; i < length; i++)
181
+ {
182
+ var action = remotes[i];
183
+ action.token = this.bindRemoteState(state, action.action, action.targetId);
184
+ }
185
+ }
186
+
187
+ /**
188
+ * This will setup a two way bind to a remote state.
189
+ *
190
+ * @param {object} target
191
+ * @param {string} actionEvent
192
+ * @param {string} remoteTargetId
193
+ * @return {string}
194
+ */
195
+ bindRemoteState(target, actionEvent, remoteTargetId)
196
+ {
197
+ const remoteTarget = state.getTarget(remoteTargetId);
198
+
199
+ return target.link(remoteTarget, actionEvent);
200
+ }
201
+
202
+ /**
203
+ * This will add the states to the target.
204
+ *
205
+ * @protected
206
+ * @param {object} state
207
+ * @param {array} actions
208
+ */
209
+ addStatesToTarget(state, actions)
210
+ {
211
+ let remotes = this.remoteStates;
212
+
213
+ for(var i = 0, length = actions.length; i < length; i++)
214
+ {
215
+ var action = actions[i],
216
+ token = this.addAction(state, action);
217
+
218
+ if(action.targetId)
219
+ {
220
+ action.token = token;
221
+ remotes.push(action);
222
+ }
223
+ }
224
+
225
+ if(remotes.length < 1)
226
+ {
227
+ this.remoteStates = null;
228
+ }
229
+ }
230
+
231
+ /**
232
+ * This will add an action.
233
+ *
234
+ * @param {object} target
235
+ * @param {object} action
236
+ */
237
+ addAction(target, action)
238
+ {
239
+ let token,
240
+ actionEvent = action.action;
241
+
242
+ /* this will check to select the remote target if set */
243
+ let targetId = action.targetId;
244
+ if(targetId)
245
+ {
246
+ token = this.bindRemoteState(target, actionEvent, targetId);
247
+ }
248
+
249
+ if(typeof action.state !== 'undefined')
250
+ {
251
+ target.addAction(actionEvent, action.state);
252
+ }
253
+
254
+ let callBack = action.callBack;
255
+ if(typeof callBack === 'function')
256
+ {
257
+ target.on(actionEvent, callBack);
258
+ }
259
+
260
+ return token;
261
+ }
262
+ }