@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.
- package/.jshintrc +3 -0
- package/base.js +41 -0
- package/core.js +1 -0
- package/data-tracker.js +351 -0
- package/events.js +602 -0
- package/main.js +1331 -0
- package/modules/ajax/ajax.js +514 -0
- package/modules/animation/animation.js +236 -0
- package/modules/animations/animation-controller.js +231 -0
- package/modules/animations/animation.js +64 -0
- package/modules/animations/attr-movement.js +66 -0
- package/modules/animations/css-movement.js +170 -0
- package/modules/animations/movement.js +131 -0
- package/modules/animations/value.js +187 -0
- package/modules/atom/atom.js +54 -0
- package/modules/component/component.js +230 -0
- package/modules/component/event-helper.js +119 -0
- package/modules/component/jot.js +144 -0
- package/modules/component/state-helper.js +262 -0
- package/modules/component/unit.js +551 -0
- package/modules/data/attrs.js +40 -0
- package/modules/data/basic-data.js +500 -0
- package/modules/data/data-utils.js +29 -0
- package/modules/data/data.js +3 -0
- package/modules/data/deep-data.js +541 -0
- package/modules/data/model-service.js +528 -0
- package/modules/data/model.js +133 -0
- package/modules/data/simple-data.js +33 -0
- package/modules/data-binder/connection-tracker.js +113 -0
- package/modules/data-binder/connection.js +16 -0
- package/modules/data-binder/data-binder.js +352 -0
- package/modules/data-binder/data-pub-sub.js +141 -0
- package/modules/data-binder/data-source.js +56 -0
- package/modules/data-binder/element-source.js +219 -0
- package/modules/data-binder/one-way-connection.js +46 -0
- package/modules/data-binder/one-way-source.js +43 -0
- package/modules/data-binder/source.js +36 -0
- package/modules/data-binder/two-way-connection.js +75 -0
- package/modules/data-binder/two-way-source.js +41 -0
- package/modules/date/date.js +544 -0
- package/modules/history/history.js +89 -0
- package/modules/html-builder/html-builder.js +434 -0
- package/modules/import/import.js +390 -0
- package/modules/layout/layout-builder.js +1269 -0
- package/modules/layout/layout-parser.js +134 -0
- package/modules/layout/watcher-helper.js +282 -0
- package/modules/mouse/mouse.js +114 -0
- package/modules/router/component-helper.js +163 -0
- package/modules/router/history-controller.js +216 -0
- package/modules/router/nav-link.js +124 -0
- package/modules/router/route.js +401 -0
- package/modules/router/router.js +789 -0
- package/modules/router/utils.js +31 -0
- package/modules/state/state-target.js +91 -0
- package/modules/state/state.js +171 -0
- package/package.json +23 -0
- package/shared/objects.js +99 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import {builder} from '../layout/layout-builder.js';
|
|
2
|
+
import {Jot} from "../component/jot.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This will track previously loaded scripts and styles.
|
|
6
|
+
*/
|
|
7
|
+
const loaded = [];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This will check if a script or style has been loaded.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} src
|
|
13
|
+
* @return {bool}
|
|
14
|
+
*/
|
|
15
|
+
const isLoaded = (src) => loaded.indexOf(src) !== -1;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This will create a script atom.
|
|
19
|
+
*
|
|
20
|
+
* @param {object} props
|
|
21
|
+
* @return {object}
|
|
22
|
+
*/
|
|
23
|
+
const Script = (props) => ({
|
|
24
|
+
tag: 'script',
|
|
25
|
+
src: props.src,
|
|
26
|
+
async: false,
|
|
27
|
+
load(e)
|
|
28
|
+
{
|
|
29
|
+
loaded.push(props.src);
|
|
30
|
+
|
|
31
|
+
const callBack = props.load;
|
|
32
|
+
if(callBack)
|
|
33
|
+
{
|
|
34
|
+
callBack();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* This will create a style atom.
|
|
41
|
+
*
|
|
42
|
+
* @param {object} props
|
|
43
|
+
* @return {object}
|
|
44
|
+
*/
|
|
45
|
+
const Style = (props) => ({
|
|
46
|
+
tag: 'link',
|
|
47
|
+
rel: 'stylesheet',
|
|
48
|
+
type: 'text/css',
|
|
49
|
+
href: props.src,
|
|
50
|
+
load(e)
|
|
51
|
+
{
|
|
52
|
+
loaded.push(props.src);
|
|
53
|
+
|
|
54
|
+
const callBack = props.load;
|
|
55
|
+
if(callBack)
|
|
56
|
+
{
|
|
57
|
+
callBack();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Group
|
|
64
|
+
*
|
|
65
|
+
* This will setup a depends group to load all
|
|
66
|
+
* dependencies before loaded the script.
|
|
67
|
+
*/
|
|
68
|
+
class Group
|
|
69
|
+
{
|
|
70
|
+
constructor(callBack)
|
|
71
|
+
{
|
|
72
|
+
this.percent = 0;
|
|
73
|
+
this.loaded = 0;
|
|
74
|
+
this.total = 0;
|
|
75
|
+
this.callBack = callBack || null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* This will add the resource to the document.
|
|
80
|
+
*
|
|
81
|
+
* @param {string} src
|
|
82
|
+
*/
|
|
83
|
+
add(src)
|
|
84
|
+
{
|
|
85
|
+
this.total++;
|
|
86
|
+
let atom;
|
|
87
|
+
|
|
88
|
+
const load = this.update.bind(this);
|
|
89
|
+
if(src.indexOf('.css') !== -1)
|
|
90
|
+
{
|
|
91
|
+
atom = Style({
|
|
92
|
+
load,
|
|
93
|
+
src
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
else
|
|
97
|
+
{
|
|
98
|
+
atom = Script({
|
|
99
|
+
load,
|
|
100
|
+
src
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
builder.build(atom, document.head);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* This will add the dependencies to the document.
|
|
109
|
+
*
|
|
110
|
+
* @param {array} files
|
|
111
|
+
*/
|
|
112
|
+
addFiles(files)
|
|
113
|
+
{
|
|
114
|
+
if(!files)
|
|
115
|
+
{
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
for(var i = 0, length = files.length; i < length; i++)
|
|
120
|
+
{
|
|
121
|
+
var src = files[i];
|
|
122
|
+
if(!isLoaded(src))
|
|
123
|
+
{
|
|
124
|
+
this.add(src);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
update()
|
|
130
|
+
{
|
|
131
|
+
const percent = this.updateProgress();
|
|
132
|
+
if(percent >= 100)
|
|
133
|
+
{
|
|
134
|
+
var callBack = this.callBack;
|
|
135
|
+
if(callBack)
|
|
136
|
+
{
|
|
137
|
+
callBack();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
updateProgress()
|
|
143
|
+
{
|
|
144
|
+
++this.loaded;
|
|
145
|
+
return (this.percent = Math.floor(this.loaded / this.total * 100));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* This will load the module.
|
|
151
|
+
*
|
|
152
|
+
* @param {string} src
|
|
153
|
+
* @param {function} callBack
|
|
154
|
+
* @return {object}
|
|
155
|
+
*/
|
|
156
|
+
const loadModule = (src, callBack) =>
|
|
157
|
+
{
|
|
158
|
+
import(src).then(module =>
|
|
159
|
+
{
|
|
160
|
+
if(callBack)
|
|
161
|
+
{
|
|
162
|
+
callBack(module);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* This will check if an object is a contructor.
|
|
169
|
+
*
|
|
170
|
+
* @param {object|function} object
|
|
171
|
+
* @returns {bool}
|
|
172
|
+
*/
|
|
173
|
+
const isConstructor = (object) =>
|
|
174
|
+
{
|
|
175
|
+
if(!object)
|
|
176
|
+
{
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return (typeof object?.prototype?.constructor === 'function');
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* This will render the module.
|
|
185
|
+
*
|
|
186
|
+
* @param {object} layout
|
|
187
|
+
* @param {object} ele
|
|
188
|
+
* @param {object} parent
|
|
189
|
+
* @param {function} callBack
|
|
190
|
+
* @return {object}
|
|
191
|
+
*/
|
|
192
|
+
const render = (layout, ele, parent) =>
|
|
193
|
+
{
|
|
194
|
+
const frag = builder.build(layout, null, parent);
|
|
195
|
+
const firstChild = frag.firstChild;
|
|
196
|
+
ele.after(frag);
|
|
197
|
+
return firstChild;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* This will create a comment.
|
|
202
|
+
*
|
|
203
|
+
* @param {object} props
|
|
204
|
+
* @returns {object}
|
|
205
|
+
*/
|
|
206
|
+
const Comment = (props) => ({
|
|
207
|
+
tag: 'comment',
|
|
208
|
+
text: 'import placeholder',
|
|
209
|
+
onCreated: props.onCreated
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* This will create an import wrapper component that
|
|
214
|
+
* will wrap the comment atom to pass route to the
|
|
215
|
+
* imported layout.
|
|
216
|
+
*
|
|
217
|
+
* @param {object} props
|
|
218
|
+
* @returns {object}
|
|
219
|
+
*/
|
|
220
|
+
const ImportWrapper = Jot(
|
|
221
|
+
{
|
|
222
|
+
render()
|
|
223
|
+
{
|
|
224
|
+
return Comment(
|
|
225
|
+
{
|
|
226
|
+
onCreated: (ele) =>
|
|
227
|
+
{
|
|
228
|
+
const src = this.src;
|
|
229
|
+
if(!src)
|
|
230
|
+
{
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* This will set up a resource group to load the
|
|
236
|
+
* depends before the module.
|
|
237
|
+
*/
|
|
238
|
+
if(this.depends)
|
|
239
|
+
{
|
|
240
|
+
const group = new Group(() =>
|
|
241
|
+
{
|
|
242
|
+
this.loadAndRender(ele);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
group.addFiles(this.depends);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
this.loadAndRender(ele);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
},
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* This will get the layout.
|
|
256
|
+
*
|
|
257
|
+
* @param {object} module
|
|
258
|
+
* @returns {object|null}
|
|
259
|
+
*/
|
|
260
|
+
getLayout(module)
|
|
261
|
+
{
|
|
262
|
+
let layout = module.default;
|
|
263
|
+
if(!layout)
|
|
264
|
+
{
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* This will check if the import is useing a custom
|
|
270
|
+
* callback to set up the module.
|
|
271
|
+
*/
|
|
272
|
+
const callBack = this.callBack;
|
|
273
|
+
if(callBack)
|
|
274
|
+
{
|
|
275
|
+
layout = callBack(layout);
|
|
276
|
+
}
|
|
277
|
+
else
|
|
278
|
+
{
|
|
279
|
+
if(isConstructor(layout))
|
|
280
|
+
{
|
|
281
|
+
/**
|
|
282
|
+
* This will set up the layout as a component and pass
|
|
283
|
+
* the import props like persist and route.
|
|
284
|
+
*/
|
|
285
|
+
layout = new layout();
|
|
286
|
+
layout.route = this.route;
|
|
287
|
+
|
|
288
|
+
if(this.persist)
|
|
289
|
+
{
|
|
290
|
+
layout.persist = true;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
else
|
|
294
|
+
{
|
|
295
|
+
/**
|
|
296
|
+
* This will set up the layout as a n atom.
|
|
297
|
+
*/
|
|
298
|
+
layout = layout();
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return (this.layout = layout);
|
|
303
|
+
},
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* This will load the module and render the layout.
|
|
307
|
+
*
|
|
308
|
+
* @param {object} ele
|
|
309
|
+
*/
|
|
310
|
+
loadAndRender(ele)
|
|
311
|
+
{
|
|
312
|
+
loadModule(this.src, (module) =>
|
|
313
|
+
{
|
|
314
|
+
this.loaded = true;
|
|
315
|
+
const layout = this.layout || this.getLayout(module);
|
|
316
|
+
this.layoutRoot = render(layout, ele, this.parent);
|
|
317
|
+
});
|
|
318
|
+
},
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* This will check if the layout should be updated.
|
|
322
|
+
*
|
|
323
|
+
* @param {object} layout
|
|
324
|
+
* @returns {bool}
|
|
325
|
+
*/
|
|
326
|
+
shouldUpdate(layout)
|
|
327
|
+
{
|
|
328
|
+
if(this.updateLayout === true)
|
|
329
|
+
{
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return (this.updateLayout = (layout && layout.isUnit && typeof layout.update === 'function'));
|
|
334
|
+
},
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* This will update the module layout.
|
|
338
|
+
*
|
|
339
|
+
* @param {object} params
|
|
340
|
+
*/
|
|
341
|
+
updateModuleLayout(params)
|
|
342
|
+
{
|
|
343
|
+
const layout = this.layout;
|
|
344
|
+
if(this.shouldUpdate(layout))
|
|
345
|
+
{
|
|
346
|
+
layout.update(params);
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* This will call if the import is added to a route. This will pass
|
|
352
|
+
* the update params to the imported layout.
|
|
353
|
+
*
|
|
354
|
+
* @param {object} params
|
|
355
|
+
*/
|
|
356
|
+
update(params)
|
|
357
|
+
{
|
|
358
|
+
if(this.loaded === true)
|
|
359
|
+
{
|
|
360
|
+
this.updateModuleLayout(params);
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* This will remove the imported layout when the
|
|
366
|
+
* comment is being removed.
|
|
367
|
+
*
|
|
368
|
+
* @returns {void}
|
|
369
|
+
*/
|
|
370
|
+
beforeDestroy()
|
|
371
|
+
{
|
|
372
|
+
if(!this.layoutRoot)
|
|
373
|
+
{
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
builder.removeElement(this.layoutRoot);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* This will import a module.
|
|
383
|
+
*
|
|
384
|
+
* @param {object} props
|
|
385
|
+
* @returns {object}
|
|
386
|
+
*/
|
|
387
|
+
export const Import = (props) =>
|
|
388
|
+
{
|
|
389
|
+
return new ImportWrapper(props);
|
|
390
|
+
};
|