lilact 0.31.2 → 0.31.3
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/dist/lilact.development.js +4 -5
- package/dist/lilact.development.js.map +2 -2
- package/dist/lilact.development.min.js +8 -8
- package/dist/lilact.development.min.js.map +2 -2
- package/dist/lilact.production.min.js +8 -8
- package/docs/functions/run.lazy.html +1 -1
- package/docs/functions/run.runScripts.html +1 -1
- package/docs/static/index.html +1 -1
- package/docs/static/lilact.development.js +4 -5
- package/docs/static/lilact.development.js.map +2 -2
- package/docs/static/lilact.development.min.js +8 -8
- package/docs/static/lilact.development.min.js.map +2 -2
- package/docs/static/lilact.production.min.js +8 -8
- package/examples/index.html +1 -1
- package/examples/lilact.development.js +4 -5
- package/examples/lilact.development.js.map +2 -2
- package/examples/lilact.development.min.js +8 -8
- package/examples/lilact.development.min.js.map +2 -2
- package/examples/lilact.production.min.js +8 -8
- package/package.json +1 -1
- package/src/run.jsx +92 -93
package/src/run.jsx
CHANGED
|
@@ -134,113 +134,113 @@ function createModule(path, {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
function loadModule(path, options = {}) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
if (Lilact.importObjectPaths?.[path]) {
|
|
138
|
+
return Lilact.importObjectPaths[path];
|
|
139
|
+
}
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
if (options.requirer?.path) {
|
|
142
|
+
path = joinPaths(options.requirer.path, path);
|
|
143
|
+
}
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
const loadAsync =
|
|
146
|
+
Boolean(Lilact[LAZY]) ||
|
|
147
|
+
Boolean(options.isLazy);
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
const module = getOrCreateModule(path, {});
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
if (module.loaded && !options.forceReload) {
|
|
152
|
+
return module.exports;
|
|
153
|
+
}
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
if (path.startsWith("#")) {
|
|
156
|
+
const element = document.getElementById(path.slice(1));
|
|
157
157
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
158
|
+
if (!element) {
|
|
159
|
+
throw report(
|
|
160
|
+
new Error(`Required element not found (${path})`),
|
|
161
|
+
path
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
164
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
165
|
+
return run(
|
|
166
|
+
element.textContent || "",
|
|
167
|
+
path,
|
|
168
|
+
{forceReload: options.forceReload}
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
if (loadAsync) {
|
|
173
|
+
Lilact[LAZY] = false;
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
if (module.request && !options.forceReload) {
|
|
176
|
+
return module.request;
|
|
177
|
+
}
|
|
178
178
|
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
return loadAsyncResource(path, module, options);
|
|
180
|
+
}
|
|
181
181
|
|
|
182
|
-
|
|
182
|
+
const resolved = Lilact.resolver?.(path);
|
|
183
183
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
184
|
+
if (resolved != null) {
|
|
185
|
+
if (path.endsWith(".css")) {
|
|
186
|
+
injectGlobal(String(resolved));
|
|
187
|
+
module.code = String(resolved);
|
|
188
|
+
module.loaded = true;
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
191
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
192
|
+
return run(
|
|
193
|
+
String(resolved),
|
|
194
|
+
path,
|
|
195
|
+
{forceReload: options.forceReload}
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
const request = new XMLHttpRequest();
|
|
200
200
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
201
|
+
try {
|
|
202
|
+
request.open("GET", path, false);
|
|
203
|
+
request.send(null);
|
|
204
|
+
} catch (value) {
|
|
205
|
+
throw report(value, path);
|
|
206
|
+
}
|
|
207
207
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
208
|
+
if (request.status >= 200 && request.status < 300) {
|
|
209
|
+
if (path.endsWith(".css")) {
|
|
210
|
+
module.code = request.responseText;
|
|
211
|
+
injectGlobal(module.code);
|
|
212
|
+
module.loaded = true;
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
215
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
216
|
+
return run(
|
|
217
|
+
request.responseText,
|
|
218
|
+
path,
|
|
219
|
+
{forceReload: true}
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
222
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
223
|
+
throw report(
|
|
224
|
+
new Error(
|
|
225
|
+
`Unable to load ${path}: HTTP ${request.status || 0}`
|
|
226
|
+
),
|
|
227
|
+
path
|
|
228
|
+
);
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
export function require(path)
|
|
232
232
|
{
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
233
|
+
let options = {};
|
|
234
|
+
|
|
235
|
+
if (
|
|
236
|
+
arguments.length === 2 &&
|
|
237
|
+
arguments[1] &&
|
|
238
|
+
typeof arguments[1] === "object"
|
|
239
|
+
) {
|
|
240
|
+
options = arguments[1];
|
|
241
|
+
}
|
|
242
242
|
|
|
243
|
-
|
|
243
|
+
return loadModule(path, options);
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
|
|
@@ -473,8 +473,8 @@ function loadAsyncResource(path, module, options = {})
|
|
|
473
473
|
return request;
|
|
474
474
|
}
|
|
475
475
|
|
|
476
|
-
|
|
477
|
-
|
|
476
|
+
export function lazy(factory)
|
|
477
|
+
{
|
|
478
478
|
let status = "pending";
|
|
479
479
|
let result;
|
|
480
480
|
|
|
@@ -485,6 +485,8 @@ export function lazy(factory) {
|
|
|
485
485
|
} catch (error) {
|
|
486
486
|
status = "error";
|
|
487
487
|
result = error;
|
|
488
|
+
} finally {
|
|
489
|
+
Lilact[LAZY] = false;
|
|
488
490
|
}
|
|
489
491
|
|
|
490
492
|
if (Lilact.isThenable(result)) {
|
|
@@ -503,22 +505,19 @@ export function lazy(factory) {
|
|
|
503
505
|
}
|
|
504
506
|
|
|
505
507
|
function LazyComponent(props) {
|
|
506
|
-
if (status === "pending") {
|
|
508
|
+
if (status === "pending" || status === "error") {
|
|
507
509
|
throw result;
|
|
508
510
|
}
|
|
509
511
|
|
|
510
|
-
|
|
511
|
-
throw result;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
const Component = result;
|
|
512
|
+
const Component = result?.default ?? result;
|
|
515
513
|
return <Component {...props} />;
|
|
516
514
|
}
|
|
517
515
|
|
|
518
516
|
return LazyComponent;
|
|
519
517
|
}
|
|
520
518
|
|
|
521
|
-
function scriptTags()
|
|
519
|
+
function scriptTags()
|
|
520
|
+
{
|
|
522
521
|
return Array.from(
|
|
523
522
|
document.querySelectorAll('script[type="text/jsx"]')
|
|
524
523
|
).map(element => ({
|