smbls 3.1.2 → 3.2.7
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/bin/smbls.js +2 -0
- package/dist/cjs/index.js +2 -3
- package/dist/cjs/src/createDomql.js +110 -0
- package/dist/cjs/src/define.js +38 -0
- package/dist/cjs/src/fetchOnCreate.js +54 -0
- package/dist/cjs/src/index.js +109 -0
- package/dist/cjs/src/init.js +127 -0
- package/dist/cjs/src/options.js +57 -0
- package/dist/cjs/src/prepare.js +296 -0
- package/dist/cjs/src/router.js +84 -0
- package/dist/cjs/src/syncExtend.js +70 -0
- package/dist/cjs/src/utilImports.js +35 -0
- package/dist/esm/index.js +2 -3
- package/dist/esm/src/createDomql.js +96 -0
- package/dist/esm/src/define.js +18 -0
- package/dist/esm/src/fetchOnCreate.js +34 -0
- package/dist/esm/src/index.js +78 -0
- package/dist/esm/src/init.js +103 -0
- package/dist/esm/src/options.js +37 -0
- package/dist/esm/src/prepare.js +273 -0
- package/dist/esm/src/router.js +64 -0
- package/dist/esm/src/syncExtend.js +50 -0
- package/dist/esm/src/utilImports.js +14 -0
- package/dist/iife/index.js +740 -0
- package/index.js +2 -6
- package/package.json +37 -26
- package/src/createDomql.js +107 -0
- package/src/define.js +22 -0
- package/src/fetchOnCreate.js +34 -0
- package/src/index.js +106 -0
- package/src/init.js +121 -0
- package/src/options.js +37 -0
- package/src/prepare.js +307 -0
- package/src/router.js +73 -0
- package/src/syncExtend.js +50 -0
- package/src/utilImports.js +10 -0
- package/dist/cjs/package.json +0 -4
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { deepMerge, isObject, isUndefined } from "@domql/utils";
|
|
2
|
+
import * as utils from "./utilImports.js";
|
|
3
|
+
import { onpopstateRouter } from "./router.js";
|
|
4
|
+
import { fetchAsync, fetchSync } from "./fetchOnCreate.js";
|
|
5
|
+
import DEFAULT_CREATE_OPTIONS from "./options.js";
|
|
6
|
+
import DYNAMIC_JSON from "../dynamic.json";
|
|
7
|
+
import { createDomqlElement } from "./createDomql.js";
|
|
8
|
+
const mergeWithLocalFile = (options, optionsExternalFile) => deepMerge(
|
|
9
|
+
options,
|
|
10
|
+
isObject(optionsExternalFile) ? optionsExternalFile : DYNAMIC_JSON || {}
|
|
11
|
+
);
|
|
12
|
+
const create = (App, options = DEFAULT_CREATE_OPTIONS, optionsExternalFile) => {
|
|
13
|
+
const redefinedOptions = {
|
|
14
|
+
...DEFAULT_CREATE_OPTIONS,
|
|
15
|
+
...mergeWithLocalFile(options, optionsExternalFile)
|
|
16
|
+
};
|
|
17
|
+
const domqlApp = createDomqlElement(App, redefinedOptions).then((App2) => {
|
|
18
|
+
onpopstateRouter(App2, redefinedOptions);
|
|
19
|
+
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
20
|
+
redefinedOptions.on.create(
|
|
21
|
+
domqlApp,
|
|
22
|
+
domqlApp.state,
|
|
23
|
+
domqlApp.context,
|
|
24
|
+
redefinedOptions
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
return domqlApp;
|
|
28
|
+
};
|
|
29
|
+
const createAsync = (App, options = DEFAULT_CREATE_OPTIONS, optionsExternalFile) => {
|
|
30
|
+
const domqlApp = create(App, options, optionsExternalFile);
|
|
31
|
+
const redefinedOptions = {
|
|
32
|
+
...DEFAULT_CREATE_OPTIONS,
|
|
33
|
+
...mergeWithLocalFile(options, optionsExternalFile)
|
|
34
|
+
};
|
|
35
|
+
const key = redefinedOptions.key;
|
|
36
|
+
fetchAsync(domqlApp, key, { utils, ...redefinedOptions });
|
|
37
|
+
return domqlApp;
|
|
38
|
+
};
|
|
39
|
+
const createSync = async (App, options = DEFAULT_CREATE_OPTIONS, optionsExternalFile) => {
|
|
40
|
+
const redefinedOptions = {
|
|
41
|
+
...DEFAULT_CREATE_OPTIONS,
|
|
42
|
+
...mergeWithLocalFile(options, optionsExternalFile)
|
|
43
|
+
};
|
|
44
|
+
const key = options.key;
|
|
45
|
+
await fetchSync(key, redefinedOptions);
|
|
46
|
+
const domqlApp = await createDomqlElement(App, redefinedOptions);
|
|
47
|
+
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
48
|
+
await redefinedOptions.on.create(
|
|
49
|
+
domqlApp,
|
|
50
|
+
domqlApp.state,
|
|
51
|
+
domqlApp.context,
|
|
52
|
+
redefinedOptions
|
|
53
|
+
);
|
|
54
|
+
return domqlApp;
|
|
55
|
+
};
|
|
56
|
+
const createSkeleton = (App = {}, options = DEFAULT_CREATE_OPTIONS, optionsExternalFile) => {
|
|
57
|
+
return create(
|
|
58
|
+
{
|
|
59
|
+
deps: { isUndefined },
|
|
60
|
+
...App
|
|
61
|
+
},
|
|
62
|
+
deepMerge({ domqlOptions: { onlyResolveExtends: true } }, options),
|
|
63
|
+
optionsExternalFile
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
var src_default = create;
|
|
67
|
+
export * from "./init.js";
|
|
68
|
+
import { DEFAULT_CONTEXT, DESIGN_SYSTEM_OPTIONS, ROUTER_OPTIONS } from "./options.js";
|
|
69
|
+
export {
|
|
70
|
+
DEFAULT_CONTEXT,
|
|
71
|
+
DESIGN_SYSTEM_OPTIONS,
|
|
72
|
+
ROUTER_OPTIONS,
|
|
73
|
+
create,
|
|
74
|
+
createAsync,
|
|
75
|
+
createSkeleton,
|
|
76
|
+
createSync,
|
|
77
|
+
src_default as default
|
|
78
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {
|
|
2
|
+
set,
|
|
3
|
+
getActiveConfig,
|
|
4
|
+
getFontFaceString,
|
|
5
|
+
appendSVGSprite,
|
|
6
|
+
appendSvgIconsSprite
|
|
7
|
+
} from "@symbo.ls/scratch";
|
|
8
|
+
import { isObject, deepMerge, deepClone } from "@domql/utils";
|
|
9
|
+
import { emotion as defaultEmotion } from "@symbo.ls/emotion";
|
|
10
|
+
import DYNAMIC_JSON from "../dynamic.json";
|
|
11
|
+
const CONFIG = getActiveConfig();
|
|
12
|
+
const mergeWithLocalFile = (config = CONFIG, options) => {
|
|
13
|
+
const rcfile = isObject(options.localFile) ? options.localFile : DYNAMIC_JSON || {};
|
|
14
|
+
const clonedFile = deepClone(rcfile.designSystem || {});
|
|
15
|
+
return deepMerge(config, clonedFile);
|
|
16
|
+
};
|
|
17
|
+
const SET_OPTIONS = {
|
|
18
|
+
emotion: defaultEmotion,
|
|
19
|
+
useVariable: true,
|
|
20
|
+
useReset: true,
|
|
21
|
+
useFontImport: true,
|
|
22
|
+
useIconSprite: true,
|
|
23
|
+
useDocumentTheme: true,
|
|
24
|
+
useSvgSprite: true
|
|
25
|
+
};
|
|
26
|
+
const init = (config, options = SET_OPTIONS) => {
|
|
27
|
+
const emotion = options.emotion || defaultEmotion;
|
|
28
|
+
const resultConfig = mergeWithLocalFile(config || {}, options);
|
|
29
|
+
const conf = set(
|
|
30
|
+
{
|
|
31
|
+
verbose: options.verbose,
|
|
32
|
+
useReset: options.useReset,
|
|
33
|
+
useFontImport: options.useFontImport,
|
|
34
|
+
useVariable: options.useVariable,
|
|
35
|
+
useSvgSprite: options.useSvgSprite,
|
|
36
|
+
useDocumentTheme: options.useDocumentTheme,
|
|
37
|
+
useIconSprite: options.useIconSprite,
|
|
38
|
+
useDefaultConfig: options.useDefaultConfig,
|
|
39
|
+
globalTheme: options.globalTheme,
|
|
40
|
+
...resultConfig
|
|
41
|
+
},
|
|
42
|
+
{ newConfig: options.newConfig }
|
|
43
|
+
);
|
|
44
|
+
const FontFace = getFontFaceString(conf.FONT);
|
|
45
|
+
const useReset = conf.useReset;
|
|
46
|
+
const useVariable = conf.useVariable;
|
|
47
|
+
const useFontImport = conf.useFontImport;
|
|
48
|
+
const useSvgSprite = conf.useSvgSprite;
|
|
49
|
+
const hasSvgs = config.svg || config.SVG;
|
|
50
|
+
const useIconSprite = conf.useIconSprite;
|
|
51
|
+
const hasIcons = config.icons || config.ICONS;
|
|
52
|
+
if (useFontImport) emotion.injectGlobal(FontFace);
|
|
53
|
+
if (useVariable) emotion.injectGlobal({ ":root": conf.CSS_VARS });
|
|
54
|
+
if (useReset) emotion.injectGlobal(conf.RESET);
|
|
55
|
+
if (conf.ANIMATION) {
|
|
56
|
+
const keyframesCSS = {};
|
|
57
|
+
for (const name in conf.ANIMATION) {
|
|
58
|
+
keyframesCSS[`@keyframes ${name}`] = conf.ANIMATION[name];
|
|
59
|
+
}
|
|
60
|
+
emotion.injectGlobal(keyframesCSS);
|
|
61
|
+
}
|
|
62
|
+
if (hasSvgs) appendSVGSprite(hasSvgs, { document: options.document });
|
|
63
|
+
else if (useSvgSprite)
|
|
64
|
+
appendSVGSprite(conf.SVG, { document: options.document });
|
|
65
|
+
if (hasIcons) appendSvgIconsSprite(hasIcons, { document: options.document });
|
|
66
|
+
else if (useIconSprite)
|
|
67
|
+
appendSvgIconsSprite(conf.ICONS, { document: options.document });
|
|
68
|
+
return conf;
|
|
69
|
+
};
|
|
70
|
+
const UPDATE_OPTIONS = {
|
|
71
|
+
emotion: defaultEmotion
|
|
72
|
+
};
|
|
73
|
+
const reinit = (config, options = UPDATE_OPTIONS) => {
|
|
74
|
+
const emotion = options.emotion || defaultEmotion;
|
|
75
|
+
const resultConfig = mergeWithLocalFile(config || {}, options);
|
|
76
|
+
const conf = set({
|
|
77
|
+
verbose: false,
|
|
78
|
+
...resultConfig
|
|
79
|
+
});
|
|
80
|
+
if (!options.preventInject) {
|
|
81
|
+
emotion.injectGlobal({ ":root": conf.CSS_VARS });
|
|
82
|
+
emotion.injectGlobal(conf.RESET);
|
|
83
|
+
}
|
|
84
|
+
return conf;
|
|
85
|
+
};
|
|
86
|
+
const applyCSS = (styles, options = UPDATE_OPTIONS) => {
|
|
87
|
+
const emotion = options.emotion || defaultEmotion;
|
|
88
|
+
emotion.injectGlobal(styles);
|
|
89
|
+
};
|
|
90
|
+
const updateVars = (config, options = UPDATE_OPTIONS) => {
|
|
91
|
+
const emotion = options.emotion || defaultEmotion;
|
|
92
|
+
emotion.injectGlobal({ ":root": config.CSS_VARS });
|
|
93
|
+
};
|
|
94
|
+
const setClass = (props, options = UPDATE_OPTIONS) => {
|
|
95
|
+
};
|
|
96
|
+
export {
|
|
97
|
+
DYNAMIC_JSON,
|
|
98
|
+
applyCSS,
|
|
99
|
+
init,
|
|
100
|
+
reinit,
|
|
101
|
+
setClass,
|
|
102
|
+
updateVars
|
|
103
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defaultDefine } from "./define.js";
|
|
2
|
+
import { version } from "../package.json";
|
|
3
|
+
const DESIGN_SYSTEM_OPTIONS = {
|
|
4
|
+
useReset: true,
|
|
5
|
+
useVariable: true,
|
|
6
|
+
useIconSprite: true,
|
|
7
|
+
useSvgSprite: true,
|
|
8
|
+
useDocumentTheme: true,
|
|
9
|
+
useDefaultIcons: true,
|
|
10
|
+
useFontImport: true,
|
|
11
|
+
useDefaultConfig: true
|
|
12
|
+
};
|
|
13
|
+
const ROUTER_OPTIONS = {
|
|
14
|
+
initRouter: true,
|
|
15
|
+
popState: true,
|
|
16
|
+
injectRouterInLinkComponent: true
|
|
17
|
+
};
|
|
18
|
+
const DEFAULT_CONTEXT = {
|
|
19
|
+
...DESIGN_SYSTEM_OPTIONS,
|
|
20
|
+
router: ROUTER_OPTIONS,
|
|
21
|
+
version
|
|
22
|
+
};
|
|
23
|
+
const CREATE_OPTIONS = {
|
|
24
|
+
state: {},
|
|
25
|
+
pages: {},
|
|
26
|
+
components: {},
|
|
27
|
+
router: ROUTER_OPTIONS,
|
|
28
|
+
define: defaultDefine
|
|
29
|
+
};
|
|
30
|
+
var options_default = CREATE_OPTIONS;
|
|
31
|
+
export {
|
|
32
|
+
CREATE_OPTIONS,
|
|
33
|
+
DEFAULT_CONTEXT,
|
|
34
|
+
DESIGN_SYSTEM_OPTIONS,
|
|
35
|
+
ROUTER_OPTIONS,
|
|
36
|
+
options_default as default
|
|
37
|
+
};
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isObject,
|
|
3
|
+
deepMerge,
|
|
4
|
+
deepClone,
|
|
5
|
+
merge,
|
|
6
|
+
isDevelopment,
|
|
7
|
+
matchesComponentNaming
|
|
8
|
+
} from "@domql/utils";
|
|
9
|
+
import { initEmotion } from "@symbo.ls/emotion";
|
|
10
|
+
import * as uikit from "@symbo.ls/uikit";
|
|
11
|
+
import * as utils from "./utilImports.js";
|
|
12
|
+
import * as routerUtils from "@domql/router";
|
|
13
|
+
// @preserve-env
|
|
14
|
+
const prepareWindow = (context) => {
|
|
15
|
+
if (typeof window === "undefined") window = globalThis || {};
|
|
16
|
+
if (typeof document === "undefined") {
|
|
17
|
+
if (!window.document) window.document = globalThis.document || { body: {} };
|
|
18
|
+
document = window.document;
|
|
19
|
+
}
|
|
20
|
+
context.document = context.document || document;
|
|
21
|
+
context.window = context.window || window;
|
|
22
|
+
return context.window;
|
|
23
|
+
};
|
|
24
|
+
function onlyDotsAndNumbers(str) {
|
|
25
|
+
return /^[0-9.]+$/.test(str) && str !== "";
|
|
26
|
+
}
|
|
27
|
+
const CDN_PROVIDERS = {
|
|
28
|
+
skypack: {
|
|
29
|
+
url: "https://cdn.skypack.dev",
|
|
30
|
+
formatUrl: (pkg, version) => `${CDN_PROVIDERS.skypack.url}/${pkg}${version !== "latest" ? `@${version}` : ""}`
|
|
31
|
+
},
|
|
32
|
+
esmsh: {
|
|
33
|
+
url: "https://esm.sh",
|
|
34
|
+
formatUrl: (pkg, version) => `${CDN_PROVIDERS.esmsh.url}/${pkg}${version !== "latest" ? `@${version}` : ""}`
|
|
35
|
+
},
|
|
36
|
+
unpkg: {
|
|
37
|
+
url: "https://unpkg.com",
|
|
38
|
+
formatUrl: (pkg, version) => `${CDN_PROVIDERS.unpkg.url}/${pkg}${version !== "latest" ? `@${version}` : ""}?module`
|
|
39
|
+
},
|
|
40
|
+
jsdelivr: {
|
|
41
|
+
url: "https://cdn.jsdelivr.net/npm",
|
|
42
|
+
formatUrl: (pkg, version) => `${CDN_PROVIDERS.jsdelivr.url}/${pkg}${version !== "latest" ? `@${version}` : ""}/+esm`
|
|
43
|
+
},
|
|
44
|
+
symbols: {
|
|
45
|
+
url: "https://pkg.symbo.ls",
|
|
46
|
+
formatUrl: (pkg, version) => {
|
|
47
|
+
if (pkg.split("/").length > 2 || !onlyDotsAndNumbers(version)) {
|
|
48
|
+
return `${CDN_PROVIDERS.symbols.url}/${pkg}`;
|
|
49
|
+
}
|
|
50
|
+
return `${CDN_PROVIDERS.symbols.url}/${pkg}/${version}.js`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const PACKAGE_MANAGER_TO_CDN = {
|
|
55
|
+
"esm.sh": "esmsh",
|
|
56
|
+
"unpkg": "unpkg",
|
|
57
|
+
"skypack": "skypack",
|
|
58
|
+
"jsdelivr": "jsdelivr",
|
|
59
|
+
"pkg.symbo.ls": "symbols"
|
|
60
|
+
};
|
|
61
|
+
const getCdnProviderFromConfig = (symbolsConfig = {}) => {
|
|
62
|
+
const { packageManager } = symbolsConfig;
|
|
63
|
+
return PACKAGE_MANAGER_TO_CDN[packageManager] || null;
|
|
64
|
+
};
|
|
65
|
+
const getCDNUrl = (packageName, version = "latest", provider = "esmsh") => {
|
|
66
|
+
const cdnConfig = CDN_PROVIDERS[provider] || CDN_PROVIDERS.esmsh;
|
|
67
|
+
return cdnConfig.formatUrl(packageName, version);
|
|
68
|
+
};
|
|
69
|
+
const UIkitWithPrefix = (prefix = "smbls") => {
|
|
70
|
+
const newObj = {};
|
|
71
|
+
for (const key in uikit) {
|
|
72
|
+
if (Object.prototype.hasOwnProperty.call(uikit, key)) {
|
|
73
|
+
if (matchesComponentNaming(key)) {
|
|
74
|
+
newObj[`smbls.${key}`] = uikit[key];
|
|
75
|
+
} else {
|
|
76
|
+
newObj[key] = uikit[key];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return newObj;
|
|
81
|
+
};
|
|
82
|
+
const prepareComponents = (context) => {
|
|
83
|
+
return context.components ? { ...UIkitWithPrefix(), ...context.components } : UIkitWithPrefix();
|
|
84
|
+
};
|
|
85
|
+
const prepareUtils = (context) => {
|
|
86
|
+
return {
|
|
87
|
+
...utils,
|
|
88
|
+
...routerUtils,
|
|
89
|
+
...utils.scratchUtils,
|
|
90
|
+
...context.utils,
|
|
91
|
+
...context.snippets,
|
|
92
|
+
...context.functions
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
const prepareMethods = (context) => {
|
|
96
|
+
return {
|
|
97
|
+
...context.methods || {},
|
|
98
|
+
require: context.utils.require,
|
|
99
|
+
requireOnDemand: context.utils.requireOnDemand,
|
|
100
|
+
router: context.utils.router
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
const cachedDeps = {};
|
|
104
|
+
const prepareDependencies = async ({
|
|
105
|
+
dependencies,
|
|
106
|
+
dependenciesOnDemand,
|
|
107
|
+
document: document2,
|
|
108
|
+
preventCaching = false,
|
|
109
|
+
cdnProvider,
|
|
110
|
+
packageManager,
|
|
111
|
+
symbolsConfig
|
|
112
|
+
}) => {
|
|
113
|
+
if (!cdnProvider) {
|
|
114
|
+
cdnProvider = PACKAGE_MANAGER_TO_CDN[packageManager] || getCdnProviderFromConfig(symbolsConfig) || "esmsh";
|
|
115
|
+
}
|
|
116
|
+
if (!dependencies) return null;
|
|
117
|
+
let hasAny = false;
|
|
118
|
+
for (const _k in dependencies) {
|
|
119
|
+
hasAny = true;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
if (!hasAny) return null;
|
|
123
|
+
for (const dependency in dependencies) {
|
|
124
|
+
const version = dependencies[dependency];
|
|
125
|
+
if (dependenciesOnDemand && dependenciesOnDemand[dependency]) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const random = isDevelopment() && preventCaching ? `?${Math.random()}` : "";
|
|
129
|
+
const url = getCDNUrl(dependency, version, cdnProvider) + random;
|
|
130
|
+
try {
|
|
131
|
+
if (cachedDeps[dependency]) return;
|
|
132
|
+
cachedDeps[dependency] = true;
|
|
133
|
+
await utils.loadRemoteScript(url, { document: document2, type: "module" });
|
|
134
|
+
} catch (e) {
|
|
135
|
+
console.error(`Failed to load ${dependency} from ${cdnProvider}:`, e);
|
|
136
|
+
if (cdnProvider !== "symbols") {
|
|
137
|
+
try {
|
|
138
|
+
const fallbackUrl = getCDNUrl(dependency, version, "symbols") + random;
|
|
139
|
+
await utils.loadRemoteScript(fallbackUrl, { document: document2 });
|
|
140
|
+
console.log(
|
|
141
|
+
`Successfully loaded ${dependency} from fallback (symbols.ls)`
|
|
142
|
+
);
|
|
143
|
+
} catch (fallbackError) {
|
|
144
|
+
console.error(
|
|
145
|
+
`Failed to load ${dependency} from fallback:`,
|
|
146
|
+
fallbackError
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return dependencies;
|
|
153
|
+
};
|
|
154
|
+
const prepareRequire = async (packages, ctx) => {
|
|
155
|
+
const windowOpts = ctx.window || window;
|
|
156
|
+
const defaultProvider = ctx.cdnProvider || getCdnProviderFromConfig(ctx.symbolsConfig) || "esmsh";
|
|
157
|
+
const initRequire = async (ctx2) => async (key, provider) => {
|
|
158
|
+
const windowOpts2 = ctx2.window || window;
|
|
159
|
+
const pkg = windowOpts2.packages[key];
|
|
160
|
+
if (typeof pkg === "function") return pkg();
|
|
161
|
+
return pkg;
|
|
162
|
+
};
|
|
163
|
+
const initRequireOnDemand = async (ctx2) => async (key, provider = defaultProvider) => {
|
|
164
|
+
const { dependenciesOnDemand } = ctx2;
|
|
165
|
+
const documentOpts = ctx2.document || document;
|
|
166
|
+
const windowOpts2 = ctx2.window || window;
|
|
167
|
+
if (!windowOpts2.packages[key]) {
|
|
168
|
+
const random = isDevelopment() ? `?${Math.random()}` : "";
|
|
169
|
+
if (dependenciesOnDemand && dependenciesOnDemand[key]) {
|
|
170
|
+
const version = dependenciesOnDemand[key];
|
|
171
|
+
const url = getCDNUrl(key, version, provider) + random;
|
|
172
|
+
try {
|
|
173
|
+
await ctx2.utils.loadRemoteScript(url, {
|
|
174
|
+
window: windowOpts2,
|
|
175
|
+
document: documentOpts
|
|
176
|
+
});
|
|
177
|
+
} catch (e) {
|
|
178
|
+
console.error(`Failed to load ${key} from ${provider}:`, e);
|
|
179
|
+
if (provider !== "symbols") {
|
|
180
|
+
const fallbackUrl = getCDNUrl(key, version, "symbols") + random;
|
|
181
|
+
await ctx2.utils.loadRemoteScript(fallbackUrl, {
|
|
182
|
+
window: windowOpts2,
|
|
183
|
+
document: documentOpts
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
} else {
|
|
188
|
+
const url = getCDNUrl(key, "latest", provider) + random;
|
|
189
|
+
try {
|
|
190
|
+
await ctx2.utils.loadRemoteScript(url, {
|
|
191
|
+
window: windowOpts2,
|
|
192
|
+
document: documentOpts
|
|
193
|
+
});
|
|
194
|
+
} catch (e) {
|
|
195
|
+
console.error(`Failed to load ${key} from ${provider}:`, e);
|
|
196
|
+
if (provider !== "symbols") {
|
|
197
|
+
const fallbackUrl = getCDNUrl(key, "latest", "symbols") + random;
|
|
198
|
+
await ctx2.utils.loadRemoteScript(fallbackUrl, {
|
|
199
|
+
window: windowOpts2,
|
|
200
|
+
document: documentOpts
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
windowOpts2.packages[key] = "loadedOnDeman";
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return await windowOpts2.require(key, provider);
|
|
208
|
+
};
|
|
209
|
+
if (windowOpts.packages) {
|
|
210
|
+
windowOpts.packages = merge(windowOpts.packages, packages);
|
|
211
|
+
} else {
|
|
212
|
+
windowOpts.packages = packages;
|
|
213
|
+
}
|
|
214
|
+
if (!windowOpts.require) {
|
|
215
|
+
ctx.utils.require = await initRequire(ctx);
|
|
216
|
+
windowOpts.require = ctx.utils.require;
|
|
217
|
+
}
|
|
218
|
+
if (!windowOpts.requireOnDemand) {
|
|
219
|
+
ctx.utils.requireOnDemand = await initRequireOnDemand(ctx);
|
|
220
|
+
windowOpts.requireOnDemand = ctx.utils.requireOnDemand;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
const prepareDesignSystem = (key, context) => {
|
|
224
|
+
const [scratcDesignhSystem, emotion, registry] = initEmotion(key, context);
|
|
225
|
+
return [scratcDesignhSystem, emotion, registry];
|
|
226
|
+
};
|
|
227
|
+
const prepareState = (app, context) => {
|
|
228
|
+
const state = {};
|
|
229
|
+
if (context.state) utils.deepMerge(state, context.state);
|
|
230
|
+
if (app && app.state) deepMerge(state, app.state);
|
|
231
|
+
state.isRootState = true;
|
|
232
|
+
return deepClone(state);
|
|
233
|
+
};
|
|
234
|
+
const preparePages = (app, context) => {
|
|
235
|
+
if (isObject(app.routes) && isObject(context.pages)) {
|
|
236
|
+
merge(app.routes, context.pages);
|
|
237
|
+
}
|
|
238
|
+
const pages = app.routes || context.pages || {};
|
|
239
|
+
for (const v in pages) {
|
|
240
|
+
if (v.charCodeAt(0) === 47) continue;
|
|
241
|
+
const index = v === "index" ? "" : v;
|
|
242
|
+
pages["/" + index] = pages[v];
|
|
243
|
+
delete pages[v];
|
|
244
|
+
}
|
|
245
|
+
return pages;
|
|
246
|
+
};
|
|
247
|
+
const prepareSharedLibs = (context) => {
|
|
248
|
+
const sharedLibraries = context.sharedLibraries;
|
|
249
|
+
for (let i = 0; i < sharedLibraries.length; i++) {
|
|
250
|
+
const sharedLib = sharedLibraries[i];
|
|
251
|
+
if (context.type === "template") {
|
|
252
|
+
overwriteShallow(context.designSystem, sharedLib.designSystem);
|
|
253
|
+
deepMerge(context, sharedLib, ["designSystem"], 1);
|
|
254
|
+
} else {
|
|
255
|
+
deepMerge(context, sharedLib, [], 1);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
export {
|
|
260
|
+
PACKAGE_MANAGER_TO_CDN,
|
|
261
|
+
getCDNUrl,
|
|
262
|
+
getCdnProviderFromConfig,
|
|
263
|
+
prepareComponents,
|
|
264
|
+
prepareDependencies,
|
|
265
|
+
prepareDesignSystem,
|
|
266
|
+
prepareMethods,
|
|
267
|
+
preparePages,
|
|
268
|
+
prepareRequire,
|
|
269
|
+
prepareSharedLibs,
|
|
270
|
+
prepareState,
|
|
271
|
+
prepareUtils,
|
|
272
|
+
prepareWindow
|
|
273
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { window, deepMerge, merge, isUndefined } from "@domql/utils";
|
|
2
|
+
import { router as defaultRouter } from "@domql/router";
|
|
3
|
+
import { Link } from "smbls";
|
|
4
|
+
const DEFAULT_ROUTING_OPTIONS = {
|
|
5
|
+
initRouter: true,
|
|
6
|
+
injectRouterInLinkComponent: true,
|
|
7
|
+
popState: true
|
|
8
|
+
};
|
|
9
|
+
const initRouter = (element, context) => {
|
|
10
|
+
if (context.router === false) return;
|
|
11
|
+
else if (context.router === true) context.router = DEFAULT_ROUTING_OPTIONS;
|
|
12
|
+
else context.router = merge(context.router || {}, DEFAULT_ROUTING_OPTIONS);
|
|
13
|
+
const routerOptions = context.router;
|
|
14
|
+
const onRouterRenderDefault = async (el, s) => {
|
|
15
|
+
const { pathname, search, hash } = window.location;
|
|
16
|
+
const url = pathname + search + hash;
|
|
17
|
+
if (el.routes) await defaultRouter(url, el, {}, { initialRender: true });
|
|
18
|
+
};
|
|
19
|
+
const hasRenderRouter = element.on && !isUndefined(element.on.renderRouter) || !isUndefined(element.onRenderRouter);
|
|
20
|
+
if (routerOptions && routerOptions.initRouter && !hasRenderRouter) {
|
|
21
|
+
if (element.on) {
|
|
22
|
+
element.on.renderRouter = onRouterRenderDefault;
|
|
23
|
+
} else {
|
|
24
|
+
element.on = {
|
|
25
|
+
renderRouter: onRouterRenderDefault
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
injectRouterInLinkComponent(context, routerOptions);
|
|
30
|
+
return routerOptions;
|
|
31
|
+
};
|
|
32
|
+
let popStateFired;
|
|
33
|
+
const onpopstateRouter = (element, context) => {
|
|
34
|
+
if (popStateFired) return;
|
|
35
|
+
popStateFired = true;
|
|
36
|
+
const routerOptions = context.router || DEFAULT_ROUTING_OPTIONS;
|
|
37
|
+
if (!routerOptions.popState) return;
|
|
38
|
+
const router = context.utils && context.utils.router ? context.utils.router : defaultRouter;
|
|
39
|
+
window.onpopstate = async (e) => {
|
|
40
|
+
const { pathname, search, hash } = window.location;
|
|
41
|
+
const url = pathname + search + hash;
|
|
42
|
+
await element.call(
|
|
43
|
+
"router",
|
|
44
|
+
url,
|
|
45
|
+
element,
|
|
46
|
+
{},
|
|
47
|
+
{ pushState: false, scrollToTop: false, level: 0, event: e }
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const injectRouterInLinkComponent = (context, routerOptions) => {
|
|
52
|
+
const { components } = context;
|
|
53
|
+
if (routerOptions && routerOptions.injectRouterInLinkComponent) {
|
|
54
|
+
return deepMerge(
|
|
55
|
+
components["Link"] || components["smbls.Link"],
|
|
56
|
+
components["RouterLink"] || components["smbls.RouterLink"]
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
export {
|
|
61
|
+
initRouter,
|
|
62
|
+
injectRouterInLinkComponent,
|
|
63
|
+
onpopstateRouter
|
|
64
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isObjectLike, isUndefined, isDevelopment, isArray } from "@domql/utils";
|
|
2
|
+
import { SyncComponent, Inspect, Notifications } from "@symbo.ls/sync";
|
|
3
|
+
const initializeExtend = (app, ctx) => {
|
|
4
|
+
return isObjectLike(app.extends) ? app.extends : [];
|
|
5
|
+
};
|
|
6
|
+
const initializeSync = (app, ctx) => {
|
|
7
|
+
const { editor } = ctx;
|
|
8
|
+
if (!editor) return;
|
|
9
|
+
const liveSync = isUndefined(editor.liveSync) ? isDevelopment() : editor.liveSync;
|
|
10
|
+
if (liveSync) {
|
|
11
|
+
if (isArray(app.extends)) app.extends.push(SyncComponent);
|
|
12
|
+
else if (app.extends) {
|
|
13
|
+
app.extends = [app.extends, SyncComponent];
|
|
14
|
+
} else {
|
|
15
|
+
app.extends = [SyncComponent];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const initializeInspect = (app, ctx) => {
|
|
20
|
+
const { editor } = ctx;
|
|
21
|
+
if (!editor) return;
|
|
22
|
+
const inspect = isUndefined(editor.inspect) ? isDevelopment() : editor.inspect;
|
|
23
|
+
if (inspect) {
|
|
24
|
+
if (isArray(app.extends)) app.extends.push(Inspect);
|
|
25
|
+
else if (app.extends) {
|
|
26
|
+
app.extends = [app.extends, Inspect];
|
|
27
|
+
} else {
|
|
28
|
+
app.extends = [Inspect];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const initializeNotifications = (app, ctx) => {
|
|
33
|
+
const { editor } = ctx;
|
|
34
|
+
if (!editor) return;
|
|
35
|
+
const verbose = isUndefined(editor.verbose) ? isDevelopment() || ctx.verbose : editor.verbose;
|
|
36
|
+
if (verbose) {
|
|
37
|
+
if (isArray(app.extends)) app.extends.push(Notifications);
|
|
38
|
+
else if (app.extends) {
|
|
39
|
+
app.extends = [app.extends, Notifications];
|
|
40
|
+
} else {
|
|
41
|
+
app.extends = [Notifications];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
initializeExtend,
|
|
47
|
+
initializeInspect,
|
|
48
|
+
initializeNotifications,
|
|
49
|
+
initializeSync
|
|
50
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { scratchUtils, scratchSystem, set } from "@symbo.ls/scratch";
|
|
2
|
+
export * from "@domql/utils";
|
|
3
|
+
export * from "@symbo.ls/smbls-utils";
|
|
4
|
+
import { init, reinit, applyCSS } from "./init.js";
|
|
5
|
+
export * from "@domql/report";
|
|
6
|
+
export * from "@domql/router";
|
|
7
|
+
export {
|
|
8
|
+
applyCSS,
|
|
9
|
+
init,
|
|
10
|
+
reinit,
|
|
11
|
+
scratchSystem,
|
|
12
|
+
scratchUtils,
|
|
13
|
+
set
|
|
14
|
+
};
|