@symbo.ls/create 2.27.16 → 2.28.1
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/cjs/createDomql.js +20 -14
- package/dist/cjs/index.js +31 -10
- package/dist/cjs/initEmotion.js +1 -1
- package/dist/cjs/options.js +1 -1
- package/dist/cjs/prepare.js +24 -23
- package/dist/esm/createDomql.js +24 -13
- package/dist/esm/index.js +19 -7
- package/dist/esm/initEmotion.js +1 -1
- package/dist/esm/options.js +1 -1
- package/dist/esm/prepare.js +24 -23
- package/package.json +13 -13
- package/src/createDomql.js +26 -15
- package/src/index.js +57 -19
- package/src/initEmotion.js +7 -5
- package/src/options.js +1 -1
- package/src/prepare.js +28 -28
package/dist/cjs/createDomql.js
CHANGED
|
@@ -36,15 +36,18 @@ var import_domql = __toESM(require("domql"), 1);
|
|
|
36
36
|
var uikit = __toESM(require("@symbo.ls/uikit"), 1);
|
|
37
37
|
var import_utils = require("@domql/utils");
|
|
38
38
|
var import_event = require("@domql/event");
|
|
39
|
-
var import_define = require("./define");
|
|
40
|
-
var import_router = require("./router");
|
|
41
|
-
var import_syncExtend = require("./syncExtend");
|
|
42
|
-
var import_prepare = require("./prepare");
|
|
43
|
-
const prepareContext = (app, context = {}) => {
|
|
39
|
+
var import_define = require("./define.js");
|
|
40
|
+
var import_router = require("./router.js");
|
|
41
|
+
var import_syncExtend = require("./syncExtend.js");
|
|
42
|
+
var import_prepare = require("./prepare.js");
|
|
43
|
+
const prepareContext = async (app, context = {}) => {
|
|
44
44
|
const key = context.key = context.key || ((0, import_utils.isString)(app) ? app : "smblsapp");
|
|
45
45
|
context.define = context.define || import_define.defaultDefine;
|
|
46
46
|
context.window = (0, import_prepare.prepareWindow)(context);
|
|
47
|
-
const [scratcDesignSystem, emotion, registry] = (0, import_prepare.prepareDesignSystem)(
|
|
47
|
+
const [scratcDesignSystem, emotion, registry] = (0, import_prepare.prepareDesignSystem)(
|
|
48
|
+
key,
|
|
49
|
+
context
|
|
50
|
+
);
|
|
48
51
|
context.designSystem = scratcDesignSystem;
|
|
49
52
|
context.registry = registry;
|
|
50
53
|
context.emotion = emotion;
|
|
@@ -53,7 +56,7 @@ const prepareContext = (app, context = {}) => {
|
|
|
53
56
|
context.pages = (0, import_prepare.preparePages)(app, context);
|
|
54
57
|
context.components = (0, import_prepare.prepareComponents)(context);
|
|
55
58
|
context.utils = (0, import_prepare.prepareUtils)(context);
|
|
56
|
-
context.dependencies = (0, import_prepare.prepareDependencies)(context);
|
|
59
|
+
context.dependencies = await (0, import_prepare.prepareDependencies)(context);
|
|
57
60
|
context.methods = (0, import_prepare.prepareMethods)(context);
|
|
58
61
|
context.routerOptions = (0, import_router.initRouter)(app, context);
|
|
59
62
|
context.defaultExtends = [uikit.Box];
|
|
@@ -72,19 +75,22 @@ const createDomqlElement = async (app, ctx) => {
|
|
|
72
75
|
if (!(0, import_utils.isObject)(app)) {
|
|
73
76
|
app = {};
|
|
74
77
|
}
|
|
75
|
-
prepareContext(app, ctx);
|
|
78
|
+
await prepareContext(app, ctx);
|
|
76
79
|
app.extend = (0, import_syncExtend.initializeExtend)(app, ctx);
|
|
77
80
|
app.routes = ctx.pages;
|
|
78
81
|
app.state = ctx.state;
|
|
79
82
|
app.context = ctx;
|
|
80
83
|
app.data = app.data || {};
|
|
81
84
|
app.data.frameListeners = (0, import_event.initAnimationFrame)(ctx);
|
|
82
|
-
(0, import_prepare.prepareRequire)(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
await (0, import_prepare.prepareRequire)(
|
|
86
|
+
{
|
|
87
|
+
functions: ctx.functions,
|
|
88
|
+
utils: ctx.utils,
|
|
89
|
+
snippets: ctx.snippets,
|
|
90
|
+
...ctx.files
|
|
91
|
+
},
|
|
92
|
+
ctx
|
|
93
|
+
);
|
|
88
94
|
(0, import_syncExtend.initializeSync)(app, ctx);
|
|
89
95
|
(0, import_syncExtend.initializeInspect)(app, ctx);
|
|
90
96
|
(0, import_syncExtend.initializeNotifications)(app, ctx);
|
package/dist/cjs/index.js
CHANGED
|
@@ -36,36 +36,57 @@ __export(index_exports, {
|
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(index_exports);
|
|
38
38
|
var import_utils = require("@domql/utils");
|
|
39
|
-
var utils = __toESM(require("./utilImports"), 1);
|
|
40
|
-
var import_router = require("./router");
|
|
41
|
-
var import_ferchOnCreate = require("./ferchOnCreate");
|
|
42
|
-
var import_options = __toESM(require("./options"), 1);
|
|
39
|
+
var utils = __toESM(require("./utilImports.js"), 1);
|
|
40
|
+
var import_router = require("./router.js");
|
|
41
|
+
var import_ferchOnCreate = require("./ferchOnCreate.js");
|
|
42
|
+
var import_options = __toESM(require("./options.js"), 1);
|
|
43
43
|
var import_dynamic = __toESM(require("@symbo.ls/init/dynamic.json"), 1);
|
|
44
|
-
var import_createDomql = require("./createDomql");
|
|
44
|
+
var import_createDomql = require("./createDomql.js");
|
|
45
45
|
const mergeWithLocalFile = (options, optionsExternalFile) => (0, import_utils.deepMerge)(
|
|
46
46
|
options,
|
|
47
47
|
(0, import_utils.isObject)(optionsExternalFile) ? optionsExternalFile : import_dynamic.default || {}
|
|
48
48
|
);
|
|
49
49
|
const create = (App, options = import_options.default, optionsExternalFile) => {
|
|
50
|
-
const redefinedOptions = {
|
|
50
|
+
const redefinedOptions = {
|
|
51
|
+
...import_options.default,
|
|
52
|
+
...mergeWithLocalFile(options, optionsExternalFile)
|
|
53
|
+
};
|
|
51
54
|
const domqlApp = (0, import_createDomql.createDomqlElement)(App, redefinedOptions);
|
|
52
55
|
(0, import_router.popStateRouter)(domqlApp, redefinedOptions);
|
|
53
|
-
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
56
|
+
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
57
|
+
redefinedOptions.on.create(
|
|
58
|
+
domqlApp,
|
|
59
|
+
domqlApp.state,
|
|
60
|
+
domqlApp.context,
|
|
61
|
+
redefinedOptions
|
|
62
|
+
);
|
|
54
63
|
return domqlApp;
|
|
55
64
|
};
|
|
56
65
|
const createAsync = (App, options = import_options.default, optionsExternalFile) => {
|
|
57
66
|
const domqlApp = create(App, options, optionsExternalFile);
|
|
58
|
-
const redefinedOptions = {
|
|
67
|
+
const redefinedOptions = {
|
|
68
|
+
...import_options.default,
|
|
69
|
+
...mergeWithLocalFile(options, optionsExternalFile)
|
|
70
|
+
};
|
|
59
71
|
const key = redefinedOptions.key;
|
|
60
72
|
(0, import_ferchOnCreate.fetchAsync)(domqlApp, key, { utils, ...redefinedOptions });
|
|
61
73
|
return domqlApp;
|
|
62
74
|
};
|
|
63
75
|
const createSync = async (App, options = import_options.default, optionsExternalFile) => {
|
|
64
|
-
const redefinedOptions = {
|
|
76
|
+
const redefinedOptions = {
|
|
77
|
+
...import_options.default,
|
|
78
|
+
...mergeWithLocalFile(options, optionsExternalFile)
|
|
79
|
+
};
|
|
65
80
|
const key = options.key;
|
|
66
81
|
await (0, import_ferchOnCreate.fetchSync)(key, redefinedOptions);
|
|
67
82
|
const domqlApp = await (0, import_createDomql.createDomqlElement)(App, redefinedOptions);
|
|
68
|
-
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
83
|
+
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
84
|
+
await redefinedOptions.on.create(
|
|
85
|
+
domqlApp,
|
|
86
|
+
domqlApp.state,
|
|
87
|
+
domqlApp.context,
|
|
88
|
+
redefinedOptions
|
|
89
|
+
);
|
|
69
90
|
return domqlApp;
|
|
70
91
|
};
|
|
71
92
|
const createSkeleton = (App = {}, options = import_options.default, optionsExternalFile) => {
|
package/dist/cjs/initEmotion.js
CHANGED
|
@@ -25,7 +25,7 @@ var import_emotion = require("@domql/emotion");
|
|
|
25
25
|
var import_emotion2 = require("@symbo.ls/emotion");
|
|
26
26
|
var import_init = require("@symbo.ls/init");
|
|
27
27
|
var import_utils = require("@domql/utils");
|
|
28
|
-
var import_options = require("./options");
|
|
28
|
+
var import_options = require("./options.js");
|
|
29
29
|
var import_default_config = require("@symbo.ls/default-config");
|
|
30
30
|
const initEmotion = (key, options = {}) => {
|
|
31
31
|
var _a;
|
package/dist/cjs/options.js
CHANGED
|
@@ -23,7 +23,7 @@ __export(options_exports, {
|
|
|
23
23
|
default: () => options_default
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(options_exports);
|
|
26
|
-
var import_define = require("./define");
|
|
26
|
+
var import_define = require("./define.js");
|
|
27
27
|
const DESIGN_SYSTEM_OPTIONS = {
|
|
28
28
|
useReset: true,
|
|
29
29
|
useVariable: true,
|
package/dist/cjs/prepare.js
CHANGED
|
@@ -41,9 +41,9 @@ __export(prepare_exports, {
|
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(prepare_exports);
|
|
43
43
|
var import_utils = require("@domql/utils");
|
|
44
|
-
var import_initEmotion = require("./initEmotion");
|
|
44
|
+
var import_initEmotion = require("./initEmotion.js");
|
|
45
45
|
var uikit = __toESM(require("@symbo.ls/uikit"), 1);
|
|
46
|
-
var utils = __toESM(require("./utilImports"), 1);
|
|
46
|
+
var utils = __toESM(require("./utilImports.js"), 1);
|
|
47
47
|
var routerUtils = __toESM(require("@domql/router"), 1);
|
|
48
48
|
// @preserve-env
|
|
49
49
|
const prepareWindow = (context) => {
|
|
@@ -88,51 +88,47 @@ const prepareMethods = (context) => {
|
|
|
88
88
|
return {
|
|
89
89
|
...context.methods || {},
|
|
90
90
|
require: context.utils.require,
|
|
91
|
-
requireOnDemand: context.utils.requireOnDemand
|
|
92
|
-
call: function(fnKey, ...args) {
|
|
93
|
-
var _a;
|
|
94
|
-
return (_a = context.utils[fnKey] || context.functions[fnKey] || context.methods[fnKey] || context.snippets[fnKey]) == null ? void 0 : _a.call(this, ...args);
|
|
95
|
-
}
|
|
91
|
+
requireOnDemand: context.utils.requireOnDemand
|
|
96
92
|
};
|
|
97
93
|
};
|
|
98
94
|
const cachedDeps = {};
|
|
99
|
-
const prepareDependencies = ({
|
|
95
|
+
const prepareDependencies = async ({
|
|
100
96
|
dependencies,
|
|
101
97
|
dependenciesOnDemand,
|
|
102
|
-
document: document2
|
|
98
|
+
document: document2,
|
|
99
|
+
preventCaching = false
|
|
103
100
|
}) => {
|
|
104
101
|
if (!dependencies || Object.keys(dependencies).length === 0) {
|
|
105
102
|
return null;
|
|
106
103
|
}
|
|
107
104
|
for (const [dependency, version] of Object.entries(dependencies)) {
|
|
108
|
-
if (version === "loading" || version === "error") {
|
|
105
|
+
if (version === "loading" || version === "error" || dependenciesOnDemand && dependenciesOnDemand[dependency]) {
|
|
109
106
|
continue;
|
|
110
107
|
}
|
|
111
|
-
const random = (0, import_utils.isDevelopment)() ? `?${Math.random()}` : "";
|
|
108
|
+
const random = (0, import_utils.isDevelopment)() && preventCaching ? `?${Math.random()}` : "";
|
|
112
109
|
let url = `https://pkg.symbo.ls/${dependency}/${version}.js${random}`;
|
|
113
110
|
if (dependency.split("/").length > 2 || !onlyDotsAndNumbers(version)) {
|
|
114
111
|
url = `https://pkg.symbo.ls/${dependency}${random}`;
|
|
115
112
|
}
|
|
116
|
-
if (dependenciesOnDemand && dependenciesOnDemand[dependency]) continue;
|
|
117
113
|
try {
|
|
118
114
|
if (cachedDeps[dependency]) return;
|
|
119
115
|
cachedDeps[dependency] = true;
|
|
120
|
-
utils.
|
|
116
|
+
await utils.loadRemoteScript(url, { document: document2 });
|
|
121
117
|
} catch (e) {
|
|
122
118
|
console.error(`Failed to load ${dependency}:`, e);
|
|
123
119
|
}
|
|
124
120
|
}
|
|
125
121
|
return dependencies;
|
|
126
122
|
};
|
|
127
|
-
const prepareRequire = (packages, ctx) => {
|
|
123
|
+
const prepareRequire = async (packages, ctx) => {
|
|
128
124
|
const windowOpts = ctx.window || window;
|
|
129
|
-
const initRequire = (ctx2) => (key) => {
|
|
125
|
+
const initRequire = async (ctx2) => async (key) => {
|
|
130
126
|
const windowOpts2 = ctx2.window || window;
|
|
131
127
|
const pkg = windowOpts2.packages[key];
|
|
132
|
-
if (typeof pkg === "function") return pkg();
|
|
128
|
+
if (typeof pkg === "function") return await pkg();
|
|
133
129
|
return pkg;
|
|
134
130
|
};
|
|
135
|
-
const initRequireOnDemand = (ctx2) => (key) => {
|
|
131
|
+
const initRequireOnDemand = (ctx2) => async (key) => {
|
|
136
132
|
const { dependenciesOnDemand } = ctx2;
|
|
137
133
|
const documentOpts = ctx2.document || document;
|
|
138
134
|
const windowOpts2 = ctx2.window || window;
|
|
@@ -141,15 +137,20 @@ const prepareRequire = (packages, ctx) => {
|
|
|
141
137
|
if (dependenciesOnDemand && dependenciesOnDemand[key]) {
|
|
142
138
|
const version = dependenciesOnDemand[key];
|
|
143
139
|
const url = `https://pkg.symbo.ls/${key}/${version}.js${random}`;
|
|
144
|
-
ctx2.utils.
|
|
140
|
+
await ctx2.utils.loadRemoteScript(url, {
|
|
141
|
+
window: windowOpts2,
|
|
142
|
+
document: documentOpts
|
|
143
|
+
});
|
|
145
144
|
} else {
|
|
146
145
|
const url = `https://pkg.symbo.ls/${key}${random}`;
|
|
147
|
-
ctx2.utils.
|
|
148
|
-
windowOpts2
|
|
146
|
+
await ctx2.utils.loadRemoteScript(url, {
|
|
147
|
+
window: windowOpts2,
|
|
148
|
+
document: documentOpts
|
|
149
149
|
});
|
|
150
|
+
windowOpts2.packages[key] = "loadedOnDeman";
|
|
150
151
|
}
|
|
151
152
|
}
|
|
152
|
-
return windowOpts2.require(key);
|
|
153
|
+
return await windowOpts2.require(key);
|
|
153
154
|
};
|
|
154
155
|
if (windowOpts.packages) {
|
|
155
156
|
windowOpts.packages = (0, import_utils.merge)(windowOpts.packages, packages);
|
|
@@ -157,11 +158,11 @@ const prepareRequire = (packages, ctx) => {
|
|
|
157
158
|
windowOpts.packages = packages;
|
|
158
159
|
}
|
|
159
160
|
if (!windowOpts.require) {
|
|
160
|
-
ctx.utils.require = initRequire(ctx);
|
|
161
|
+
ctx.utils.require = await initRequire(ctx);
|
|
161
162
|
windowOpts.require = ctx.utils.require;
|
|
162
163
|
}
|
|
163
164
|
if (!windowOpts.requireOnDemand) {
|
|
164
|
-
ctx.utils.requireOnDemand = initRequireOnDemand(ctx);
|
|
165
|
+
ctx.utils.requireOnDemand = await initRequireOnDemand(ctx);
|
|
165
166
|
windowOpts.requireOnDemand = ctx.utils.requireOnDemand;
|
|
166
167
|
}
|
|
167
168
|
};
|
package/dist/esm/createDomql.js
CHANGED
|
@@ -18,9 +18,14 @@ import DOM from "domql";
|
|
|
18
18
|
import * as uikit from "@symbo.ls/uikit";
|
|
19
19
|
import { isString, isNode, isObject } from "@domql/utils";
|
|
20
20
|
import { initAnimationFrame } from "@domql/event";
|
|
21
|
-
import { defaultDefine } from "./define";
|
|
22
|
-
import { initRouter } from "./router";
|
|
23
|
-
import {
|
|
21
|
+
import { defaultDefine } from "./define.js";
|
|
22
|
+
import { initRouter } from "./router.js";
|
|
23
|
+
import {
|
|
24
|
+
initializeExtend,
|
|
25
|
+
initializeInspect,
|
|
26
|
+
initializeNotifications,
|
|
27
|
+
initializeSync
|
|
28
|
+
} from "./syncExtend.js";
|
|
24
29
|
import {
|
|
25
30
|
prepareComponents,
|
|
26
31
|
prepareDependencies,
|
|
@@ -31,12 +36,15 @@ import {
|
|
|
31
36
|
prepareState,
|
|
32
37
|
prepareUtils,
|
|
33
38
|
prepareMethods
|
|
34
|
-
} from "./prepare";
|
|
35
|
-
const prepareContext = (app, context = {}) => {
|
|
39
|
+
} from "./prepare.js";
|
|
40
|
+
const prepareContext = async (app, context = {}) => {
|
|
36
41
|
const key = context.key = context.key || (isString(app) ? app : "smblsapp");
|
|
37
42
|
context.define = context.define || defaultDefine;
|
|
38
43
|
context.window = prepareWindow(context);
|
|
39
|
-
const [scratcDesignSystem, emotion, registry] = prepareDesignSystem(
|
|
44
|
+
const [scratcDesignSystem, emotion, registry] = prepareDesignSystem(
|
|
45
|
+
key,
|
|
46
|
+
context
|
|
47
|
+
);
|
|
40
48
|
context.designSystem = scratcDesignSystem;
|
|
41
49
|
context.registry = registry;
|
|
42
50
|
context.emotion = emotion;
|
|
@@ -45,7 +53,7 @@ const prepareContext = (app, context = {}) => {
|
|
|
45
53
|
context.pages = preparePages(app, context);
|
|
46
54
|
context.components = prepareComponents(context);
|
|
47
55
|
context.utils = prepareUtils(context);
|
|
48
|
-
context.dependencies = prepareDependencies(context);
|
|
56
|
+
context.dependencies = await prepareDependencies(context);
|
|
49
57
|
context.methods = prepareMethods(context);
|
|
50
58
|
context.routerOptions = initRouter(app, context);
|
|
51
59
|
context.defaultExtends = [uikit.Box];
|
|
@@ -64,18 +72,21 @@ const createDomqlElement = async (app, ctx) => {
|
|
|
64
72
|
if (!isObject(app)) {
|
|
65
73
|
app = {};
|
|
66
74
|
}
|
|
67
|
-
prepareContext(app, ctx);
|
|
75
|
+
await prepareContext(app, ctx);
|
|
68
76
|
app.extend = initializeExtend(app, ctx);
|
|
69
77
|
app.routes = ctx.pages;
|
|
70
78
|
app.state = ctx.state;
|
|
71
79
|
app.context = ctx;
|
|
72
80
|
app.data = app.data || {};
|
|
73
81
|
app.data.frameListeners = initAnimationFrame(ctx);
|
|
74
|
-
prepareRequire(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
await prepareRequire(
|
|
83
|
+
__spreadValues({
|
|
84
|
+
functions: ctx.functions,
|
|
85
|
+
utils: ctx.utils,
|
|
86
|
+
snippets: ctx.snippets
|
|
87
|
+
}, ctx.files),
|
|
88
|
+
ctx
|
|
89
|
+
);
|
|
79
90
|
initializeSync(app, ctx);
|
|
80
91
|
initializeInspect(app, ctx);
|
|
81
92
|
initializeNotifications(app, ctx);
|
package/dist/esm/index.js
CHANGED
|
@@ -15,12 +15,12 @@ var __spreadValues = (a, b) => {
|
|
|
15
15
|
return a;
|
|
16
16
|
};
|
|
17
17
|
import { deepMerge, isObject, isUndefined } from "@domql/utils";
|
|
18
|
-
import * as utils from "./utilImports";
|
|
19
|
-
import { popStateRouter } from "./router";
|
|
20
|
-
import { fetchAsync, fetchSync } from "./ferchOnCreate";
|
|
21
|
-
import DEFAULT_CREATE_OPTIONS from "./options";
|
|
18
|
+
import * as utils from "./utilImports.js";
|
|
19
|
+
import { popStateRouter } from "./router.js";
|
|
20
|
+
import { fetchAsync, fetchSync } from "./ferchOnCreate.js";
|
|
21
|
+
import DEFAULT_CREATE_OPTIONS from "./options.js";
|
|
22
22
|
import DYNAMIC_JSON from "@symbo.ls/init/dynamic.json";
|
|
23
|
-
import { createDomqlElement } from "./createDomql";
|
|
23
|
+
import { createDomqlElement } from "./createDomql.js";
|
|
24
24
|
const mergeWithLocalFile = (options, optionsExternalFile) => deepMerge(
|
|
25
25
|
options,
|
|
26
26
|
isObject(optionsExternalFile) ? optionsExternalFile : DYNAMIC_JSON || {}
|
|
@@ -29,7 +29,13 @@ const create = (App, options = DEFAULT_CREATE_OPTIONS, optionsExternalFile) => {
|
|
|
29
29
|
const redefinedOptions = __spreadValues(__spreadValues({}, DEFAULT_CREATE_OPTIONS), mergeWithLocalFile(options, optionsExternalFile));
|
|
30
30
|
const domqlApp = createDomqlElement(App, redefinedOptions);
|
|
31
31
|
popStateRouter(domqlApp, redefinedOptions);
|
|
32
|
-
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
32
|
+
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
33
|
+
redefinedOptions.on.create(
|
|
34
|
+
domqlApp,
|
|
35
|
+
domqlApp.state,
|
|
36
|
+
domqlApp.context,
|
|
37
|
+
redefinedOptions
|
|
38
|
+
);
|
|
33
39
|
return domqlApp;
|
|
34
40
|
};
|
|
35
41
|
const createAsync = (App, options = DEFAULT_CREATE_OPTIONS, optionsExternalFile) => {
|
|
@@ -44,7 +50,13 @@ const createSync = async (App, options = DEFAULT_CREATE_OPTIONS, optionsExternal
|
|
|
44
50
|
const key = options.key;
|
|
45
51
|
await fetchSync(key, redefinedOptions);
|
|
46
52
|
const domqlApp = await createDomqlElement(App, redefinedOptions);
|
|
47
|
-
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
53
|
+
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
54
|
+
await redefinedOptions.on.create(
|
|
55
|
+
domqlApp,
|
|
56
|
+
domqlApp.state,
|
|
57
|
+
domqlApp.context,
|
|
58
|
+
redefinedOptions
|
|
59
|
+
);
|
|
48
60
|
return domqlApp;
|
|
49
61
|
};
|
|
50
62
|
const createSkeleton = (App = {}, options = DEFAULT_CREATE_OPTIONS, optionsExternalFile) => {
|
package/dist/esm/initEmotion.js
CHANGED
|
@@ -18,7 +18,7 @@ import { transformDOMQLEmotion } from "@domql/emotion";
|
|
|
18
18
|
import { emotion as defaultEmotion } from "@symbo.ls/emotion";
|
|
19
19
|
import { init } from "@symbo.ls/init";
|
|
20
20
|
import { deepClone, deepMerge } from "@domql/utils";
|
|
21
|
-
import { DESIGN_SYSTEM_OPTIONS } from "./options";
|
|
21
|
+
import { DESIGN_SYSTEM_OPTIONS } from "./options.js";
|
|
22
22
|
import { DEFAULT_CONFIG } from "@symbo.ls/default-config";
|
|
23
23
|
const initEmotion = (key, options = {}) => {
|
|
24
24
|
var _a;
|
package/dist/esm/options.js
CHANGED
package/dist/esm/prepare.js
CHANGED
|
@@ -25,9 +25,9 @@ import {
|
|
|
25
25
|
checkIfKeyIsComponent,
|
|
26
26
|
isDevelopment
|
|
27
27
|
} from "@domql/utils";
|
|
28
|
-
import { initEmotion } from "./initEmotion";
|
|
28
|
+
import { initEmotion } from "./initEmotion.js";
|
|
29
29
|
import * as uikit from "@symbo.ls/uikit";
|
|
30
|
-
import * as utils from "./utilImports";
|
|
30
|
+
import * as utils from "./utilImports.js";
|
|
31
31
|
import * as routerUtils from "@domql/router";
|
|
32
32
|
// @preserve-env
|
|
33
33
|
const prepareWindow = (context) => {
|
|
@@ -64,51 +64,47 @@ const prepareUtils = (context) => {
|
|
|
64
64
|
const prepareMethods = (context) => {
|
|
65
65
|
return __spreadProps(__spreadValues({}, context.methods || {}), {
|
|
66
66
|
require: context.utils.require,
|
|
67
|
-
requireOnDemand: context.utils.requireOnDemand
|
|
68
|
-
call: function(fnKey, ...args) {
|
|
69
|
-
var _a;
|
|
70
|
-
return (_a = context.utils[fnKey] || context.functions[fnKey] || context.methods[fnKey] || context.snippets[fnKey]) == null ? void 0 : _a.call(this, ...args);
|
|
71
|
-
}
|
|
67
|
+
requireOnDemand: context.utils.requireOnDemand
|
|
72
68
|
});
|
|
73
69
|
};
|
|
74
70
|
const cachedDeps = {};
|
|
75
|
-
const prepareDependencies = ({
|
|
71
|
+
const prepareDependencies = async ({
|
|
76
72
|
dependencies,
|
|
77
73
|
dependenciesOnDemand,
|
|
78
|
-
document: document2
|
|
74
|
+
document: document2,
|
|
75
|
+
preventCaching = false
|
|
79
76
|
}) => {
|
|
80
77
|
if (!dependencies || Object.keys(dependencies).length === 0) {
|
|
81
78
|
return null;
|
|
82
79
|
}
|
|
83
80
|
for (const [dependency, version] of Object.entries(dependencies)) {
|
|
84
|
-
if (version === "loading" || version === "error") {
|
|
81
|
+
if (version === "loading" || version === "error" || dependenciesOnDemand && dependenciesOnDemand[dependency]) {
|
|
85
82
|
continue;
|
|
86
83
|
}
|
|
87
|
-
const random = isDevelopment() ? `?${Math.random()}` : "";
|
|
84
|
+
const random = isDevelopment() && preventCaching ? `?${Math.random()}` : "";
|
|
88
85
|
let url = `https://pkg.symbo.ls/${dependency}/${version}.js${random}`;
|
|
89
86
|
if (dependency.split("/").length > 2 || !onlyDotsAndNumbers(version)) {
|
|
90
87
|
url = `https://pkg.symbo.ls/${dependency}${random}`;
|
|
91
88
|
}
|
|
92
|
-
if (dependenciesOnDemand && dependenciesOnDemand[dependency]) continue;
|
|
93
89
|
try {
|
|
94
90
|
if (cachedDeps[dependency]) return;
|
|
95
91
|
cachedDeps[dependency] = true;
|
|
96
|
-
utils.
|
|
92
|
+
await utils.loadRemoteScript(url, { document: document2 });
|
|
97
93
|
} catch (e) {
|
|
98
94
|
console.error(`Failed to load ${dependency}:`, e);
|
|
99
95
|
}
|
|
100
96
|
}
|
|
101
97
|
return dependencies;
|
|
102
98
|
};
|
|
103
|
-
const prepareRequire = (packages, ctx) => {
|
|
99
|
+
const prepareRequire = async (packages, ctx) => {
|
|
104
100
|
const windowOpts = ctx.window || window;
|
|
105
|
-
const initRequire = (ctx2) => (key) => {
|
|
101
|
+
const initRequire = async (ctx2) => async (key) => {
|
|
106
102
|
const windowOpts2 = ctx2.window || window;
|
|
107
103
|
const pkg = windowOpts2.packages[key];
|
|
108
|
-
if (typeof pkg === "function") return pkg();
|
|
104
|
+
if (typeof pkg === "function") return await pkg();
|
|
109
105
|
return pkg;
|
|
110
106
|
};
|
|
111
|
-
const initRequireOnDemand = (ctx2) => (key) => {
|
|
107
|
+
const initRequireOnDemand = (ctx2) => async (key) => {
|
|
112
108
|
const { dependenciesOnDemand } = ctx2;
|
|
113
109
|
const documentOpts = ctx2.document || document;
|
|
114
110
|
const windowOpts2 = ctx2.window || window;
|
|
@@ -117,15 +113,20 @@ const prepareRequire = (packages, ctx) => {
|
|
|
117
113
|
if (dependenciesOnDemand && dependenciesOnDemand[key]) {
|
|
118
114
|
const version = dependenciesOnDemand[key];
|
|
119
115
|
const url = `https://pkg.symbo.ls/${key}/${version}.js${random}`;
|
|
120
|
-
ctx2.utils.
|
|
116
|
+
await ctx2.utils.loadRemoteScript(url, {
|
|
117
|
+
window: windowOpts2,
|
|
118
|
+
document: documentOpts
|
|
119
|
+
});
|
|
121
120
|
} else {
|
|
122
121
|
const url = `https://pkg.symbo.ls/${key}${random}`;
|
|
123
|
-
ctx2.utils.
|
|
124
|
-
windowOpts2
|
|
122
|
+
await ctx2.utils.loadRemoteScript(url, {
|
|
123
|
+
window: windowOpts2,
|
|
124
|
+
document: documentOpts
|
|
125
125
|
});
|
|
126
|
+
windowOpts2.packages[key] = "loadedOnDeman";
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
|
-
return windowOpts2.require(key);
|
|
129
|
+
return await windowOpts2.require(key);
|
|
129
130
|
};
|
|
130
131
|
if (windowOpts.packages) {
|
|
131
132
|
windowOpts.packages = merge(windowOpts.packages, packages);
|
|
@@ -133,11 +134,11 @@ const prepareRequire = (packages, ctx) => {
|
|
|
133
134
|
windowOpts.packages = packages;
|
|
134
135
|
}
|
|
135
136
|
if (!windowOpts.require) {
|
|
136
|
-
ctx.utils.require = initRequire(ctx);
|
|
137
|
+
ctx.utils.require = await initRequire(ctx);
|
|
137
138
|
windowOpts.require = ctx.utils.require;
|
|
138
139
|
}
|
|
139
140
|
if (!windowOpts.requireOnDemand) {
|
|
140
|
-
ctx.utils.requireOnDemand = initRequireOnDemand(ctx);
|
|
141
|
+
ctx.utils.requireOnDemand = await initRequireOnDemand(ctx);
|
|
141
142
|
windowOpts.requireOnDemand = ctx.utils.requireOnDemand;
|
|
142
143
|
}
|
|
143
144
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/create",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.28.1",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"gitHead": "
|
|
5
|
+
"gitHead": "371cc070cdca345fcd7ea73558d336a03c847825",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"module": "src/index.js",
|
|
8
8
|
"main": "src/index.js",
|
|
@@ -29,17 +29,17 @@
|
|
|
29
29
|
"prepublish": "npm run build; npm run copy:package:cjs"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@domql/emotion": "^2.
|
|
33
|
-
"@domql/event": "^2.
|
|
34
|
-
"@domql/report": "^2.
|
|
35
|
-
"@domql/router": "^2.
|
|
36
|
-
"@symbo.ls/fetch": "^2.
|
|
37
|
-
"@symbo.ls/init": "^2.
|
|
38
|
-
"@symbo.ls/scratch": "^2.
|
|
39
|
-
"@symbo.ls/sync": "^2.
|
|
40
|
-
"@symbo.ls/uikit": "^2.
|
|
41
|
-
"@symbo.ls/utils": "^2.
|
|
42
|
-
"domql": "^2.
|
|
32
|
+
"@domql/emotion": "^2.28.1",
|
|
33
|
+
"@domql/event": "^2.28.1",
|
|
34
|
+
"@domql/report": "^2.28.1",
|
|
35
|
+
"@domql/router": "^2.28.1",
|
|
36
|
+
"@symbo.ls/fetch": "^2.28.1",
|
|
37
|
+
"@symbo.ls/init": "^2.28.1",
|
|
38
|
+
"@symbo.ls/scratch": "^2.28.1",
|
|
39
|
+
"@symbo.ls/sync": "^2.28.1",
|
|
40
|
+
"@symbo.ls/uikit": "^2.28.1",
|
|
41
|
+
"@symbo.ls/utils": "^2.28.1",
|
|
42
|
+
"domql": "^2.28.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@babel/core": "^7.26.0"
|
package/src/createDomql.js
CHANGED
|
@@ -5,9 +5,14 @@ import * as uikit from '@symbo.ls/uikit'
|
|
|
5
5
|
|
|
6
6
|
import { isString, isNode, isObject } from '@domql/utils'
|
|
7
7
|
import { initAnimationFrame } from '@domql/event'
|
|
8
|
-
import { defaultDefine } from './define'
|
|
9
|
-
import { initRouter } from './router'
|
|
10
|
-
import {
|
|
8
|
+
import { defaultDefine } from './define.js'
|
|
9
|
+
import { initRouter } from './router.js'
|
|
10
|
+
import {
|
|
11
|
+
initializeExtend,
|
|
12
|
+
initializeInspect,
|
|
13
|
+
initializeNotifications,
|
|
14
|
+
initializeSync
|
|
15
|
+
} from './syncExtend.js'
|
|
11
16
|
|
|
12
17
|
import {
|
|
13
18
|
prepareComponents,
|
|
@@ -19,14 +24,17 @@ import {
|
|
|
19
24
|
prepareState,
|
|
20
25
|
prepareUtils,
|
|
21
26
|
prepareMethods
|
|
22
|
-
} from './prepare'
|
|
27
|
+
} from './prepare.js'
|
|
23
28
|
|
|
24
|
-
export const prepareContext = (app, context = {}) => {
|
|
29
|
+
export const prepareContext = async (app, context = {}) => {
|
|
25
30
|
// const rcFileKey = process?.env?.SYMBOLS_KEY
|
|
26
|
-
const key = context.key = context.key || (isString(app) ? app : 'smblsapp')
|
|
31
|
+
const key = (context.key = context.key || (isString(app) ? app : 'smblsapp'))
|
|
27
32
|
context.define = context.define || defaultDefine
|
|
28
33
|
context.window = prepareWindow(context)
|
|
29
|
-
const [scratcDesignSystem, emotion, registry] = prepareDesignSystem(
|
|
34
|
+
const [scratcDesignSystem, emotion, registry] = prepareDesignSystem(
|
|
35
|
+
key,
|
|
36
|
+
context
|
|
37
|
+
)
|
|
30
38
|
context.designSystem = scratcDesignSystem
|
|
31
39
|
context.registry = registry
|
|
32
40
|
context.emotion = emotion
|
|
@@ -35,7 +43,7 @@ export const prepareContext = (app, context = {}) => {
|
|
|
35
43
|
context.pages = preparePages(app, context)
|
|
36
44
|
context.components = prepareComponents(context)
|
|
37
45
|
context.utils = prepareUtils(context)
|
|
38
|
-
context.dependencies = prepareDependencies(context)
|
|
46
|
+
context.dependencies = await prepareDependencies(context)
|
|
39
47
|
context.methods = prepareMethods(context)
|
|
40
48
|
context.routerOptions = initRouter(app, context)
|
|
41
49
|
context.defaultExtends = [uikit.Box]
|
|
@@ -56,7 +64,7 @@ export const createDomqlElement = async (app, ctx) => {
|
|
|
56
64
|
app = {}
|
|
57
65
|
}
|
|
58
66
|
|
|
59
|
-
prepareContext(app, ctx)
|
|
67
|
+
await prepareContext(app, ctx)
|
|
60
68
|
|
|
61
69
|
app.extend = initializeExtend(app, ctx)
|
|
62
70
|
app.routes = ctx.pages
|
|
@@ -65,12 +73,15 @@ export const createDomqlElement = async (app, ctx) => {
|
|
|
65
73
|
app.data = app.data || {}
|
|
66
74
|
app.data.frameListeners = initAnimationFrame(ctx)
|
|
67
75
|
|
|
68
|
-
prepareRequire(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
await prepareRequire(
|
|
77
|
+
{
|
|
78
|
+
functions: ctx.functions,
|
|
79
|
+
utils: ctx.utils,
|
|
80
|
+
snippets: ctx.snippets,
|
|
81
|
+
...ctx.files
|
|
82
|
+
},
|
|
83
|
+
ctx
|
|
84
|
+
)
|
|
74
85
|
|
|
75
86
|
initializeSync(app, ctx)
|
|
76
87
|
initializeInspect(app, ctx)
|
package/src/index.js
CHANGED
|
@@ -2,36 +2,57 @@
|
|
|
2
2
|
|
|
3
3
|
import { deepMerge, isObject, isUndefined } from '@domql/utils'
|
|
4
4
|
|
|
5
|
-
import * as utils from './utilImports'
|
|
5
|
+
import * as utils from './utilImports.js'
|
|
6
6
|
|
|
7
|
-
import { popStateRouter } from './router'
|
|
8
|
-
import { fetchAsync, fetchSync } from './ferchOnCreate'
|
|
7
|
+
import { popStateRouter } from './router.js'
|
|
8
|
+
import { fetchAsync, fetchSync } from './ferchOnCreate.js'
|
|
9
9
|
|
|
10
|
-
import DEFAULT_CREATE_OPTIONS from './options'
|
|
11
|
-
import DYNAMIC_JSON from '@symbo.ls/init/dynamic.json'
|
|
12
|
-
import { createDomqlElement } from './createDomql'
|
|
10
|
+
import DEFAULT_CREATE_OPTIONS from './options.js'
|
|
11
|
+
import DYNAMIC_JSON from '@symbo.ls/init/dynamic.json' with { type: 'json' }
|
|
12
|
+
import { createDomqlElement } from './createDomql.js'
|
|
13
13
|
|
|
14
|
-
const mergeWithLocalFile = (options, optionsExternalFile) =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
)
|
|
14
|
+
const mergeWithLocalFile = (options, optionsExternalFile) =>
|
|
15
|
+
deepMerge(
|
|
16
|
+
options,
|
|
17
|
+
isObject(optionsExternalFile) ? optionsExternalFile : DYNAMIC_JSON || {}
|
|
18
|
+
)
|
|
18
19
|
|
|
19
|
-
export const create = (
|
|
20
|
-
|
|
20
|
+
export const create = (
|
|
21
|
+
App,
|
|
22
|
+
options = DEFAULT_CREATE_OPTIONS,
|
|
23
|
+
optionsExternalFile
|
|
24
|
+
) => {
|
|
25
|
+
const redefinedOptions = {
|
|
26
|
+
...DEFAULT_CREATE_OPTIONS,
|
|
27
|
+
...mergeWithLocalFile(options, optionsExternalFile)
|
|
28
|
+
}
|
|
21
29
|
|
|
22
30
|
const domqlApp = createDomqlElement(App, redefinedOptions)
|
|
23
31
|
|
|
24
32
|
popStateRouter(domqlApp, redefinedOptions)
|
|
25
33
|
|
|
26
|
-
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
34
|
+
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
35
|
+
redefinedOptions.on.create(
|
|
36
|
+
domqlApp,
|
|
37
|
+
domqlApp.state,
|
|
38
|
+
domqlApp.context,
|
|
39
|
+
redefinedOptions
|
|
40
|
+
)
|
|
27
41
|
|
|
28
42
|
return domqlApp
|
|
29
43
|
}
|
|
30
44
|
|
|
31
|
-
export const createAsync = (
|
|
45
|
+
export const createAsync = (
|
|
46
|
+
App,
|
|
47
|
+
options = DEFAULT_CREATE_OPTIONS,
|
|
48
|
+
optionsExternalFile
|
|
49
|
+
) => {
|
|
32
50
|
const domqlApp = create(App, options, optionsExternalFile)
|
|
33
51
|
|
|
34
|
-
const redefinedOptions = {
|
|
52
|
+
const redefinedOptions = {
|
|
53
|
+
...DEFAULT_CREATE_OPTIONS,
|
|
54
|
+
...mergeWithLocalFile(options, optionsExternalFile)
|
|
55
|
+
}
|
|
35
56
|
// const SYMBOLS_KEY = process.env.SYMBOLS_KEY
|
|
36
57
|
const key = redefinedOptions.key
|
|
37
58
|
fetchAsync(domqlApp, key, { utils, ...redefinedOptions })
|
|
@@ -39,20 +60,37 @@ export const createAsync = (App, options = DEFAULT_CREATE_OPTIONS, optionsExtern
|
|
|
39
60
|
return domqlApp
|
|
40
61
|
}
|
|
41
62
|
|
|
42
|
-
export const createSync = async (
|
|
43
|
-
|
|
63
|
+
export const createSync = async (
|
|
64
|
+
App,
|
|
65
|
+
options = DEFAULT_CREATE_OPTIONS,
|
|
66
|
+
optionsExternalFile
|
|
67
|
+
) => {
|
|
68
|
+
const redefinedOptions = {
|
|
69
|
+
...DEFAULT_CREATE_OPTIONS,
|
|
70
|
+
...mergeWithLocalFile(options, optionsExternalFile)
|
|
71
|
+
}
|
|
44
72
|
|
|
45
73
|
// const SYMBOLS_KEY = process.env.SYMBOLS_KEY
|
|
46
74
|
const key = options.key
|
|
47
75
|
await fetchSync(key, redefinedOptions)
|
|
48
76
|
|
|
49
77
|
const domqlApp = await createDomqlElement(App, redefinedOptions)
|
|
50
|
-
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
78
|
+
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
79
|
+
await redefinedOptions.on.create(
|
|
80
|
+
domqlApp,
|
|
81
|
+
domqlApp.state,
|
|
82
|
+
domqlApp.context,
|
|
83
|
+
redefinedOptions
|
|
84
|
+
)
|
|
51
85
|
|
|
52
86
|
return domqlApp
|
|
53
87
|
}
|
|
54
88
|
|
|
55
|
-
export const createSkeleton = (
|
|
89
|
+
export const createSkeleton = (
|
|
90
|
+
App = {},
|
|
91
|
+
options = DEFAULT_CREATE_OPTIONS,
|
|
92
|
+
optionsExternalFile
|
|
93
|
+
) => {
|
|
56
94
|
return create(
|
|
57
95
|
{
|
|
58
96
|
deps: { isUndefined },
|
package/src/initEmotion.js
CHANGED
|
@@ -5,7 +5,7 @@ import { emotion as defaultEmotion } from '@symbo.ls/emotion'
|
|
|
5
5
|
import { init } from '@symbo.ls/init'
|
|
6
6
|
import { deepClone, deepMerge } from '@domql/utils'
|
|
7
7
|
|
|
8
|
-
import { DESIGN_SYSTEM_OPTIONS } from './options'
|
|
8
|
+
import { DESIGN_SYSTEM_OPTIONS } from './options.js'
|
|
9
9
|
import { DEFAULT_CONFIG } from '@symbo.ls/default-config'
|
|
10
10
|
|
|
11
11
|
export const initEmotion = (key, options = {}) => {
|
|
@@ -15,10 +15,12 @@ export const initEmotion = (key, options = {}) => {
|
|
|
15
15
|
|
|
16
16
|
if (!initOptions.emotion) initOptions.emotion = defaultEmotion
|
|
17
17
|
|
|
18
|
-
const registry =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const registry =
|
|
19
|
+
options.registry || transformDOMQLEmotion(initOptions.emotion, options)
|
|
20
|
+
const designSystem =
|
|
21
|
+
initOptions.useDefaultConfig || options.designSystem?.useDefaultConfig
|
|
22
|
+
? deepMerge(options.designSystem, deepClone(DEFAULT_CONFIG))
|
|
23
|
+
: options.designSystem || deepClone(DEFAULT_CONFIG)
|
|
22
24
|
|
|
23
25
|
const scratchSystem = init(designSystem, {
|
|
24
26
|
key,
|
package/src/options.js
CHANGED
package/src/prepare.js
CHANGED
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
checkIfKeyIsComponent,
|
|
9
9
|
isDevelopment
|
|
10
10
|
} from '@domql/utils'
|
|
11
|
-
import { initEmotion } from './initEmotion'
|
|
11
|
+
import { initEmotion } from './initEmotion.js'
|
|
12
12
|
|
|
13
13
|
import * as uikit from '@symbo.ls/uikit'
|
|
14
|
-
import * as utils from './utilImports'
|
|
14
|
+
import * as utils from './utilImports.js'
|
|
15
15
|
import * as routerUtils from '@domql/router'
|
|
16
16
|
|
|
17
17
|
// @preserve-env
|
|
@@ -65,46 +65,41 @@ export const prepareMethods = context => {
|
|
|
65
65
|
return {
|
|
66
66
|
...(context.methods || {}),
|
|
67
67
|
require: context.utils.require,
|
|
68
|
-
requireOnDemand: context.utils.requireOnDemand
|
|
69
|
-
call: function (fnKey, ...args) {
|
|
70
|
-
return (
|
|
71
|
-
context.utils[fnKey] ||
|
|
72
|
-
context.functions[fnKey] ||
|
|
73
|
-
context.methods[fnKey] ||
|
|
74
|
-
context.snippets[fnKey]
|
|
75
|
-
)?.call(this, ...args)
|
|
76
|
-
}
|
|
68
|
+
requireOnDemand: context.utils.requireOnDemand
|
|
77
69
|
}
|
|
78
70
|
}
|
|
79
71
|
|
|
80
72
|
const cachedDeps = {}
|
|
81
|
-
export const prepareDependencies = ({
|
|
73
|
+
export const prepareDependencies = async ({
|
|
82
74
|
dependencies,
|
|
83
75
|
dependenciesOnDemand,
|
|
84
|
-
document
|
|
76
|
+
document,
|
|
77
|
+
preventCaching = false
|
|
85
78
|
}) => {
|
|
86
79
|
if (!dependencies || Object.keys(dependencies).length === 0) {
|
|
87
80
|
return null
|
|
88
81
|
}
|
|
89
82
|
|
|
90
83
|
for (const [dependency, version] of Object.entries(dependencies)) {
|
|
91
|
-
if (
|
|
84
|
+
if (
|
|
85
|
+
version === 'loading' ||
|
|
86
|
+
version === 'error' ||
|
|
87
|
+
(dependenciesOnDemand && dependenciesOnDemand[dependency])
|
|
88
|
+
) {
|
|
92
89
|
continue
|
|
93
90
|
}
|
|
94
91
|
|
|
95
|
-
const random = isDevelopment() ? `?${Math.random()}` : ''
|
|
92
|
+
const random = isDevelopment() && preventCaching ? `?${Math.random()}` : ''
|
|
96
93
|
let url = `https://pkg.symbo.ls/${dependency}/${version}.js${random}`
|
|
97
94
|
|
|
98
95
|
if (dependency.split('/').length > 2 || !onlyDotsAndNumbers(version)) {
|
|
99
96
|
url = `https://pkg.symbo.ls/${dependency}${random}`
|
|
100
97
|
}
|
|
101
98
|
|
|
102
|
-
if (dependenciesOnDemand && dependenciesOnDemand[dependency]) continue
|
|
103
|
-
|
|
104
99
|
try {
|
|
105
100
|
if (cachedDeps[dependency]) return
|
|
106
101
|
cachedDeps[dependency] = true
|
|
107
|
-
utils.
|
|
102
|
+
await utils.loadRemoteScript(url, { document })
|
|
108
103
|
} catch (e) {
|
|
109
104
|
console.error(`Failed to load ${dependency}:`, e)
|
|
110
105
|
}
|
|
@@ -113,17 +108,17 @@ export const prepareDependencies = ({
|
|
|
113
108
|
return dependencies
|
|
114
109
|
}
|
|
115
110
|
|
|
116
|
-
export const prepareRequire = (packages, ctx) => {
|
|
111
|
+
export const prepareRequire = async (packages, ctx) => {
|
|
117
112
|
const windowOpts = ctx.window || window
|
|
118
113
|
|
|
119
|
-
const initRequire = ctx => key => {
|
|
114
|
+
const initRequire = async ctx => async key => {
|
|
120
115
|
const windowOpts = ctx.window || window
|
|
121
116
|
const pkg = windowOpts.packages[key]
|
|
122
|
-
if (typeof pkg === 'function') return pkg()
|
|
117
|
+
if (typeof pkg === 'function') return await pkg()
|
|
123
118
|
return pkg
|
|
124
119
|
}
|
|
125
120
|
|
|
126
|
-
const initRequireOnDemand = ctx => key => {
|
|
121
|
+
const initRequireOnDemand = ctx => async key => {
|
|
127
122
|
const { dependenciesOnDemand } = ctx
|
|
128
123
|
const documentOpts = ctx.document || document
|
|
129
124
|
const windowOpts = ctx.window || window
|
|
@@ -132,15 +127,20 @@ export const prepareRequire = (packages, ctx) => {
|
|
|
132
127
|
if (dependenciesOnDemand && dependenciesOnDemand[key]) {
|
|
133
128
|
const version = dependenciesOnDemand[key]
|
|
134
129
|
const url = `https://pkg.symbo.ls/${key}/${version}.js${random}`
|
|
135
|
-
ctx.utils.
|
|
130
|
+
await ctx.utils.loadRemoteScript(url, {
|
|
131
|
+
window: windowOpts,
|
|
132
|
+
document: documentOpts
|
|
133
|
+
})
|
|
136
134
|
} else {
|
|
137
135
|
const url = `https://pkg.symbo.ls/${key}${random}`
|
|
138
|
-
ctx.utils.
|
|
139
|
-
windowOpts
|
|
136
|
+
await ctx.utils.loadRemoteScript(url, {
|
|
137
|
+
window: windowOpts,
|
|
138
|
+
document: documentOpts
|
|
140
139
|
})
|
|
140
|
+
windowOpts.packages[key] = 'loadedOnDeman'
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
return windowOpts.require(key)
|
|
143
|
+
return await windowOpts.require(key)
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
if (windowOpts.packages) {
|
|
@@ -150,12 +150,12 @@ export const prepareRequire = (packages, ctx) => {
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
if (!windowOpts.require) {
|
|
153
|
-
ctx.utils.require = initRequire(ctx)
|
|
153
|
+
ctx.utils.require = await initRequire(ctx)
|
|
154
154
|
windowOpts.require = ctx.utils.require
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
if (!windowOpts.requireOnDemand) {
|
|
158
|
-
ctx.utils.requireOnDemand = initRequireOnDemand(ctx)
|
|
158
|
+
ctx.utils.requireOnDemand = await initRequireOnDemand(ctx)
|
|
159
159
|
windowOpts.requireOnDemand = ctx.utils.requireOnDemand
|
|
160
160
|
}
|
|
161
161
|
}
|