-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
aurelia-loader-default.js
262 lines (207 loc) · 7.82 KB
/
aurelia-loader-default.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
import { TemplateRegistryEntry, Loader } from 'aurelia-loader';
import { DOM, PLATFORM } from 'aurelia-pal';
import { Origin } from 'aurelia-metadata';
export var TextTemplateLoader = function () {
function TextTemplateLoader() {
}
TextTemplateLoader.prototype.loadTemplate = function loadTemplate(loader, entry) {
return loader.loadText(entry.address).then(function (text) {
entry.template = DOM.createTemplateFromMarkup(text);
});
};
return TextTemplateLoader;
}();
function ensureOriginOnExports(executed, name) {
var target = executed;
var key = void 0;
var exportedValue = void 0;
if (target.__useDefault) {
target = target['default'];
}
Origin.set(target, new Origin(name, 'default'));
for (key in target) {
exportedValue = target[key];
if (typeof exportedValue === 'function') {
Origin.set(exportedValue, new Origin(name, key));
}
}
return executed;
}
export var DefaultLoader = function (_Loader) {
_inherits(DefaultLoader, _Loader);
function DefaultLoader() {
var _this = _possibleConstructorReturn(this, _Loader.call(this));
_this.textPluginName = 'text';
_this.moduleRegistry = Object.create(null);
_this.useTemplateLoader(new TextTemplateLoader());
var that = _this;
_this.addPlugin('template-registry-entry', {
'fetch': function fetch(address) {
var entry = that.getOrCreateTemplateRegistryEntry(address);
return entry.templateIsLoaded ? entry : that.templateLoader.loadTemplate(that, entry).then(function (x) {
return entry;
});
}
});
return _this;
}
DefaultLoader.prototype.useTemplateLoader = function useTemplateLoader(templateLoader) {
this.templateLoader = templateLoader;
};
DefaultLoader.prototype.loadAllModules = function loadAllModules(ids) {
var loads = [];
for (var i = 0, ii = ids.length; i < ii; ++i) {
loads.push(this.loadModule(ids[i]));
}
return Promise.all(loads);
};
DefaultLoader.prototype.loadTemplate = function loadTemplate(url) {
return this._import(this.applyPluginToUrl(url, 'template-registry-entry'));
};
DefaultLoader.prototype.loadText = function loadText(url) {
return this._import(this.applyPluginToUrl(url, this.textPluginName)).then(function (textOrModule) {
if (typeof textOrModule === 'string') {
return textOrModule;
}
return textOrModule['default'];
});
};
return DefaultLoader;
}(Loader);
PLATFORM.Loader = DefaultLoader;
if (!PLATFORM.global.System || !PLATFORM.global.System.import) {
if (PLATFORM.global.requirejs) {
var getDefined = void 0;
if (_typeof(PLATFORM.global.requirejs.s) === 'object') {
getDefined = function getDefined() {
return PLATFORM.global.requirejs.s.contexts._.defined;
};
} else if (_typeof(PLATFORM.global.requirejs.contexts) === 'object') {
getDefined = function getDefined() {
return PLATFORM.global.requirejs.contexts._.defined;
};
} else if (typeof PLATFORM.global.requirejs.definedValues === 'function') {
getDefined = function getDefined() {
return PLATFORM.global.requirejs.definedValues();
};
} else {
getDefined = function getDefined() {
return {};
};
}
PLATFORM.eachModule = function (callback) {
var defined = getDefined();
for (var key in defined) {
try {
if (callback(key, defined[key])) return;
} catch (e) {}
}
};
} else {
PLATFORM.eachModule = function (callback) {};
}
DefaultLoader.prototype._import = function (moduleId) {
return new Promise(function (resolve, reject) {
PLATFORM.global.require([moduleId], resolve, reject);
});
};
DefaultLoader.prototype.loadModule = function (id) {
var _this2 = this;
var existing = this.moduleRegistry[id];
if (existing !== undefined) {
return Promise.resolve(existing);
}
return new Promise(function (resolve, reject) {
PLATFORM.global.require([id], function (m) {
_this2.moduleRegistry[id] = m;
resolve(ensureOriginOnExports(m, id));
}, reject);
});
};
DefaultLoader.prototype.map = function (id, source) {};
DefaultLoader.prototype.normalize = function (moduleId, relativeTo) {
return Promise.resolve(moduleId);
};
DefaultLoader.prototype.normalizeSync = function (moduleId, relativeTo) {
return moduleId;
};
DefaultLoader.prototype.applyPluginToUrl = function (url, pluginName) {
return pluginName + '!' + url;
};
DefaultLoader.prototype.addPlugin = function (pluginName, implementation) {
var nonAnonDefine = define;
nonAnonDefine(pluginName, [], {
'load': function load(name, req, onload) {
var result = implementation.fetch(name);
Promise.resolve(result).then(onload);
}
});
};
} else {
PLATFORM.eachModule = function (callback) {
if (System.registry) {
var keys = Array.from(System.registry.keys());
for (var i = 0; i < keys.length; i++) {
try {
var key = keys[i];
if (callback(key, System.registry.get(key))) {
return;
}
} catch (e) {}
}
return;
}
var modules = System._loader.modules;
for (var _key in modules) {
try {
if (callback(_key, modules[_key].module)) return;
} catch (e) {}
}
};
DefaultLoader.prototype._import = function (moduleId) {
return System.import(moduleId);
};
DefaultLoader.prototype.loadModule = function (id) {
var _this3 = this;
return System.normalize(id).then(function (newId) {
var existing = _this3.moduleRegistry[newId];
if (existing !== undefined) {
return Promise.resolve(existing);
}
return System.import(newId).then(function (m) {
_this3.moduleRegistry[newId] = m;
return ensureOriginOnExports(m, newId);
});
});
};
DefaultLoader.prototype.map = function (id, source) {
var _map;
System.config({ map: (_map = {}, _map[id] = source, _map) });
};
DefaultLoader.prototype.normalizeSync = function (moduleId, relativeTo) {
return System.normalizeSync(moduleId, relativeTo);
};
DefaultLoader.prototype.normalize = function (moduleId, relativeTo) {
return System.normalize(moduleId, relativeTo);
};
DefaultLoader.prototype.applyPluginToUrl = function (url, pluginName) {
return url + '!' + pluginName;
};
DefaultLoader.prototype.addPlugin = function (pluginName, implementation) {
System.set(pluginName, System.newModule({
'fetch': function fetch(load, _fetch) {
var result = implementation.fetch(load.address);
return Promise.resolve(result).then(function (x) {
load.metadata.result = x;
return '';
});
},
'instantiate': function instantiate(load) {
return load.metadata.result;
}
}));
};
}