@symbo.ls/create 3.1.1 → 3.2.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.
@@ -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)(key, context);
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];
@@ -74,19 +77,22 @@ const createDomqlElement = async (app, ctx) => {
74
77
  if (!(0, import_utils.isObject)(app)) {
75
78
  app = {};
76
79
  }
77
- prepareContext(app, ctx);
80
+ await prepareContext(app, ctx);
78
81
  app.extends = (0, import_syncExtend.initializeExtend)(app, ctx);
79
82
  app.routes = ctx.pages;
80
83
  app.state = ctx.state;
81
84
  app.context = ctx;
82
85
  app.data = app.data || {};
83
86
  app.data.frameListeners = (0, import_event.initAnimationFrame)(ctx);
84
- (0, import_prepare.prepareRequire)({
85
- functions: ctx.functions,
86
- utils: ctx.utils,
87
- snippets: ctx.snippets,
88
- ...ctx.files
89
- }, ctx);
87
+ await (0, import_prepare.prepareRequire)(
88
+ {
89
+ functions: ctx.functions,
90
+ utils: ctx.utils,
91
+ snippets: ctx.snippets,
92
+ ...ctx.files
93
+ },
94
+ ctx
95
+ );
90
96
  (0, import_syncExtend.initializeSync)(app, ctx);
91
97
  (0, import_syncExtend.initializeInspect)(app, ctx);
92
98
  (0, import_syncExtend.initializeNotifications)(app, ctx);
package/dist/cjs/index.js CHANGED
@@ -36,12 +36,12 @@ __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 || {}
@@ -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;
@@ -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,
@@ -41,11 +41,11 @@ __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
- const ENV = "development";
48
+ // @preserve-env
49
49
  const prepareWindow = (context) => {
50
50
  if (typeof window === "undefined") window = globalThis || {};
51
51
  if (typeof document === "undefined") {
@@ -53,7 +53,8 @@ const prepareWindow = (context) => {
53
53
  document = window.document;
54
54
  }
55
55
  context.document = context.document || document;
56
- return context.window = context.window || window;
56
+ context.window = context.window || window;
57
+ return context.window;
57
58
  };
58
59
  function onlyDotsAndNumbers(str) {
59
60
  return /^[0-9.]+$/.test(str) && str !== "";
@@ -75,74 +76,82 @@ const prepareComponents = (context) => {
75
76
  return context.components ? { ...UIkitWithPrefix(), ...context.components } : UIkitWithPrefix();
76
77
  };
77
78
  const prepareUtils = (context) => {
78
- return { ...utils, ...routerUtils, ...utils.scratchUtils, ...context.utils, ...context.snippets, ...context.functions };
79
+ return {
80
+ ...utils,
81
+ ...routerUtils,
82
+ ...utils.scratchUtils,
83
+ ...context.utils,
84
+ ...context.snippets,
85
+ ...context.functions
86
+ };
79
87
  };
80
88
  const prepareMethods = (context) => {
81
89
  return {
82
90
  ...context.methods || {},
83
91
  require: context.utils.require,
84
- requireOnDemand: context.utils.requireOnDemand,
85
- call: function(fnKey, ...args) {
86
- var _a;
87
- return (_a = context.utils[fnKey] || context.functions[fnKey] || context.methods[fnKey] || context.snippets[fnKey]) == null ? void 0 : _a.call(this, ...args);
88
- }
92
+ requireOnDemand: context.utils.requireOnDemand
89
93
  };
90
94
  };
91
95
  const cachedDeps = {};
92
- const prepareDependencies = ({
96
+ const prepareDependencies = async ({
93
97
  dependencies,
94
98
  dependenciesOnDemand,
95
- document: document2
99
+ document: document2,
100
+ preventCaching = false
96
101
  }) => {
97
102
  if (!dependencies || Object.keys(dependencies).length === 0) {
98
103
  return null;
99
104
  }
100
105
  for (const [dependency, version] of Object.entries(dependencies)) {
101
- if (version === "loading" || version === "error") {
106
+ if (dependenciesOnDemand && dependenciesOnDemand[dependency]) {
102
107
  continue;
103
108
  }
104
- const random = ENV === "development" ? `?${Math.random()}` : "";
109
+ const random = (0, import_utils.isDevelopment)() && preventCaching ? `?${Math.random()}` : "";
105
110
  let url = `https://pkg.symbo.ls/${dependency}/${version}.js${random}`;
106
111
  if (dependency.split("/").length > 2 || !onlyDotsAndNumbers(version)) {
107
112
  url = `https://pkg.symbo.ls/${dependency}${random}`;
108
113
  }
109
- if (dependenciesOnDemand && dependenciesOnDemand[dependency]) continue;
110
114
  try {
111
115
  if (cachedDeps[dependency]) return;
112
116
  cachedDeps[dependency] = true;
113
- utils.loadJavascriptFileEmbedSync(url, document2);
117
+ await utils.loadRemoteScript(url, { document: document2 });
114
118
  } catch (e) {
115
119
  console.error(`Failed to load ${dependency}:`, e);
116
120
  }
117
121
  }
118
122
  return dependencies;
119
123
  };
120
- const prepareRequire = (packages, ctx) => {
124
+ const prepareRequire = async (packages, ctx) => {
121
125
  const windowOpts = ctx.window || window;
122
- const initRequire = (ctx2) => (key) => {
126
+ const initRequire = async (ctx2) => async (key) => {
123
127
  const windowOpts2 = ctx2.window || window;
124
128
  const pkg = windowOpts2.packages[key];
125
129
  if (typeof pkg === "function") return pkg();
126
130
  return pkg;
127
131
  };
128
- const initRequireOnDemand = (ctx2) => (key) => {
132
+ const initRequireOnDemand = async (ctx2) => async (key) => {
129
133
  const { dependenciesOnDemand } = ctx2;
130
134
  const documentOpts = ctx2.document || document;
131
135
  const windowOpts2 = ctx2.window || window;
132
136
  if (!windowOpts2.packages[key]) {
133
- const random = ENV === "development" ? `?${Math.random()}` : "";
137
+ const random = (0, import_utils.isDevelopment)() ? `?${Math.random()}` : "";
134
138
  if (dependenciesOnDemand && dependenciesOnDemand[key]) {
135
139
  const version = dependenciesOnDemand[key];
136
140
  const url = `https://pkg.symbo.ls/${key}/${version}.js${random}`;
137
- ctx2.utils.loadJavascriptFileEmbedSync(url, documentOpts);
141
+ await ctx2.utils.loadRemoteScript(url, {
142
+ window: windowOpts2,
143
+ document: documentOpts
144
+ });
138
145
  } else {
139
146
  const url = `https://pkg.symbo.ls/${key}${random}`;
140
- ctx2.utils.loadJavascriptFileEmbedSync(url, documentOpts, (d) => {
141
- windowOpts2.packages[key] = "loadedOnDeman";
147
+ await ctx2.utils.loadRemoteScript(url, {
148
+ window: windowOpts2,
149
+ document: documentOpts
142
150
  });
151
+ windowOpts2.packages[key] = "loadedOnDeman";
143
152
  }
144
153
  }
145
- return windowOpts2.require(key);
154
+ return await windowOpts2.require(key);
146
155
  };
147
156
  if (windowOpts.packages) {
148
157
  windowOpts.packages = (0, import_utils.merge)(windowOpts.packages, packages);
@@ -150,11 +159,11 @@ const prepareRequire = (packages, ctx) => {
150
159
  windowOpts.packages = packages;
151
160
  }
152
161
  if (!windowOpts.require) {
153
- ctx.utils.require = initRequire(ctx);
162
+ ctx.utils.require = await initRequire(ctx);
154
163
  windowOpts.require = ctx.utils.require;
155
164
  }
156
165
  if (!windowOpts.requireOnDemand) {
157
- ctx.utils.requireOnDemand = initRequireOnDemand(ctx);
166
+ ctx.utils.requireOnDemand = await initRequireOnDemand(ctx);
158
167
  windowOpts.requireOnDemand = ctx.utils.requireOnDemand;
159
168
  }
160
169
  };
@@ -25,6 +25,7 @@ __export(router_exports, {
25
25
  module.exports = __toCommonJS(router_exports);
26
26
  var import_router = require("@domql/router");
27
27
  var import_utils = require("@domql/utils");
28
+ var import_smbls = require("smbls");
28
29
  const DEFAULT_ROUTING_OPTIONS = {
29
30
  initRouter: true,
30
31
  injectRouterInLinkComponent: true,
@@ -61,15 +62,23 @@ const popStateRouter = (element, context) => {
61
62
  const routerOptions = context.router || DEFAULT_ROUTING_OPTIONS;
62
63
  if (!routerOptions.popState) return;
63
64
  const router = context.utils && context.utils.router ? context.utils.router : import_router.router;
64
- import_utils.window.onpopstate = (e) => {
65
+ import_utils.window.onpopstate = async (e) => {
65
66
  const { pathname, search, hash } = import_utils.window.location;
66
67
  const url = pathname + search + hash;
67
- router(url, element, {}, { pushState: false, scrollToTop: false, level: 0 });
68
+ await router(
69
+ url,
70
+ element,
71
+ {},
72
+ { pushState: false, scrollToTop: false, level: 0, event: e }
73
+ );
68
74
  };
69
75
  };
70
76
  const injectRouterInLinkComponent = (context, routerOptions) => {
71
- const { Link, RouterLink } = context.components;
77
+ const { components } = context;
72
78
  if (routerOptions && routerOptions.injectRouterInLinkComponent) {
73
- return (0, import_utils.deepMerge)(Link, RouterLink);
79
+ return (0, import_utils.deepMerge)(
80
+ components["Link"] || components["smbls.Link"],
81
+ components["RouterLink"] || components["smbls.RouterLink"]
82
+ );
74
83
  }
75
84
  };
@@ -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 { initializeExtend, initializeInspect, initializeNotifications, initializeSync } from "./syncExtend";
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(key, context);
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];
@@ -66,18 +74,21 @@ const createDomqlElement = async (app, ctx) => {
66
74
  if (!isObject(app)) {
67
75
  app = {};
68
76
  }
69
- prepareContext(app, ctx);
77
+ await prepareContext(app, ctx);
70
78
  app.extends = initializeExtend(app, ctx);
71
79
  app.routes = ctx.pages;
72
80
  app.state = ctx.state;
73
81
  app.context = ctx;
74
82
  app.data = app.data || {};
75
83
  app.data.frameListeners = initAnimationFrame(ctx);
76
- prepareRequire(__spreadValues({
77
- functions: ctx.functions,
78
- utils: ctx.utils,
79
- snippets: ctx.snippets
80
- }, ctx.files), ctx);
84
+ await prepareRequire(
85
+ __spreadValues({
86
+ functions: ctx.functions,
87
+ utils: ctx.utils,
88
+ snippets: ctx.snippets
89
+ }, ctx.files),
90
+ ctx
91
+ );
81
92
  initializeSync(app, ctx);
82
93
  initializeInspect(app, ctx);
83
94
  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 || {}
@@ -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;
@@ -1,4 +1,4 @@
1
- import { defaultDefine } from "./define";
1
+ import { defaultDefine } from "./define.js";
2
2
  const DESIGN_SYSTEM_OPTIONS = {
3
3
  useReset: true,
4
4
  useVariable: true,
@@ -22,13 +22,14 @@ import {
22
22
  deepMerge,
23
23
  deepClone,
24
24
  merge,
25
+ isDevelopment,
25
26
  matchesComponentNaming
26
27
  } from "@domql/utils";
27
- import { initEmotion } from "./initEmotion";
28
+ import { initEmotion } from "./initEmotion.js";
28
29
  import * as uikit from "@symbo.ls/uikit";
29
- import * as utils from "./utilImports";
30
+ import * as utils from "./utilImports.js";
30
31
  import * as routerUtils from "@domql/router";
31
- const ENV = "development";
32
+ // @preserve-env
32
33
  const prepareWindow = (context) => {
33
34
  if (typeof window === "undefined") window = globalThis || {};
34
35
  if (typeof document === "undefined") {
@@ -36,7 +37,8 @@ const prepareWindow = (context) => {
36
37
  document = window.document;
37
38
  }
38
39
  context.document = context.document || document;
39
- return context.window = context.window || window;
40
+ context.window = context.window || window;
41
+ return context.window;
40
42
  };
41
43
  function onlyDotsAndNumbers(str) {
42
44
  return /^[0-9.]+$/.test(str) && str !== "";
@@ -63,68 +65,69 @@ const prepareUtils = (context) => {
63
65
  const prepareMethods = (context) => {
64
66
  return __spreadProps(__spreadValues({}, context.methods || {}), {
65
67
  require: context.utils.require,
66
- requireOnDemand: context.utils.requireOnDemand,
67
- call: function(fnKey, ...args) {
68
- var _a;
69
- return (_a = context.utils[fnKey] || context.functions[fnKey] || context.methods[fnKey] || context.snippets[fnKey]) == null ? void 0 : _a.call(this, ...args);
70
- }
68
+ requireOnDemand: context.utils.requireOnDemand
71
69
  });
72
70
  };
73
71
  const cachedDeps = {};
74
- const prepareDependencies = ({
72
+ const prepareDependencies = async ({
75
73
  dependencies,
76
74
  dependenciesOnDemand,
77
- document: document2
75
+ document: document2,
76
+ preventCaching = false
78
77
  }) => {
79
78
  if (!dependencies || Object.keys(dependencies).length === 0) {
80
79
  return null;
81
80
  }
82
81
  for (const [dependency, version] of Object.entries(dependencies)) {
83
- if (version === "loading" || version === "error") {
82
+ if (dependenciesOnDemand && dependenciesOnDemand[dependency]) {
84
83
  continue;
85
84
  }
86
- const random = ENV === "development" ? `?${Math.random()}` : "";
85
+ const random = isDevelopment() && preventCaching ? `?${Math.random()}` : "";
87
86
  let url = `https://pkg.symbo.ls/${dependency}/${version}.js${random}`;
88
87
  if (dependency.split("/").length > 2 || !onlyDotsAndNumbers(version)) {
89
88
  url = `https://pkg.symbo.ls/${dependency}${random}`;
90
89
  }
91
- if (dependenciesOnDemand && dependenciesOnDemand[dependency]) continue;
92
90
  try {
93
91
  if (cachedDeps[dependency]) return;
94
92
  cachedDeps[dependency] = true;
95
- utils.loadJavascriptFileEmbedSync(url, document2);
93
+ await utils.loadRemoteScript(url, { document: document2 });
96
94
  } catch (e) {
97
95
  console.error(`Failed to load ${dependency}:`, e);
98
96
  }
99
97
  }
100
98
  return dependencies;
101
99
  };
102
- const prepareRequire = (packages, ctx) => {
100
+ const prepareRequire = async (packages, ctx) => {
103
101
  const windowOpts = ctx.window || window;
104
- const initRequire = (ctx2) => (key) => {
102
+ const initRequire = async (ctx2) => async (key) => {
105
103
  const windowOpts2 = ctx2.window || window;
106
104
  const pkg = windowOpts2.packages[key];
107
105
  if (typeof pkg === "function") return pkg();
108
106
  return pkg;
109
107
  };
110
- const initRequireOnDemand = (ctx2) => (key) => {
108
+ const initRequireOnDemand = async (ctx2) => async (key) => {
111
109
  const { dependenciesOnDemand } = ctx2;
112
110
  const documentOpts = ctx2.document || document;
113
111
  const windowOpts2 = ctx2.window || window;
114
112
  if (!windowOpts2.packages[key]) {
115
- const random = ENV === "development" ? `?${Math.random()}` : "";
113
+ const random = isDevelopment() ? `?${Math.random()}` : "";
116
114
  if (dependenciesOnDemand && dependenciesOnDemand[key]) {
117
115
  const version = dependenciesOnDemand[key];
118
116
  const url = `https://pkg.symbo.ls/${key}/${version}.js${random}`;
119
- ctx2.utils.loadJavascriptFileEmbedSync(url, documentOpts);
117
+ await ctx2.utils.loadRemoteScript(url, {
118
+ window: windowOpts2,
119
+ document: documentOpts
120
+ });
120
121
  } else {
121
122
  const url = `https://pkg.symbo.ls/${key}${random}`;
122
- ctx2.utils.loadJavascriptFileEmbedSync(url, documentOpts, (d) => {
123
- windowOpts2.packages[key] = "loadedOnDeman";
123
+ await ctx2.utils.loadRemoteScript(url, {
124
+ window: windowOpts2,
125
+ document: documentOpts
124
126
  });
127
+ windowOpts2.packages[key] = "loadedOnDeman";
125
128
  }
126
129
  }
127
- return windowOpts2.require(key);
130
+ return await windowOpts2.require(key);
128
131
  };
129
132
  if (windowOpts.packages) {
130
133
  windowOpts.packages = merge(windowOpts.packages, packages);
@@ -132,11 +135,11 @@ const prepareRequire = (packages, ctx) => {
132
135
  windowOpts.packages = packages;
133
136
  }
134
137
  if (!windowOpts.require) {
135
- ctx.utils.require = initRequire(ctx);
138
+ ctx.utils.require = await initRequire(ctx);
136
139
  windowOpts.require = ctx.utils.require;
137
140
  }
138
141
  if (!windowOpts.requireOnDemand) {
139
- ctx.utils.requireOnDemand = initRequireOnDemand(ctx);
142
+ ctx.utils.requireOnDemand = await initRequireOnDemand(ctx);
140
143
  windowOpts.requireOnDemand = ctx.utils.requireOnDemand;
141
144
  }
142
145
  };
@@ -1,5 +1,6 @@
1
1
  import { router as defaultRouter } from "@domql/router";
2
2
  import { window, deepMerge, merge, isUndefined } from "@domql/utils";
3
+ import { Link } from "smbls";
3
4
  const DEFAULT_ROUTING_OPTIONS = {
4
5
  initRouter: true,
5
6
  injectRouterInLinkComponent: true,
@@ -36,16 +37,24 @@ const popStateRouter = (element, context) => {
36
37
  const routerOptions = context.router || DEFAULT_ROUTING_OPTIONS;
37
38
  if (!routerOptions.popState) return;
38
39
  const router = context.utils && context.utils.router ? context.utils.router : defaultRouter;
39
- window.onpopstate = (e) => {
40
+ window.onpopstate = async (e) => {
40
41
  const { pathname, search, hash } = window.location;
41
42
  const url = pathname + search + hash;
42
- router(url, element, {}, { pushState: false, scrollToTop: false, level: 0 });
43
+ await router(
44
+ url,
45
+ element,
46
+ {},
47
+ { pushState: false, scrollToTop: false, level: 0, event: e }
48
+ );
43
49
  };
44
50
  };
45
51
  const injectRouterInLinkComponent = (context, routerOptions) => {
46
- const { Link, RouterLink } = context.components;
52
+ const { components } = context;
47
53
  if (routerOptions && routerOptions.injectRouterInLinkComponent) {
48
- return deepMerge(Link, RouterLink);
54
+ return deepMerge(
55
+ components["Link"] || components["smbls.Link"],
56
+ components["RouterLink"] || components["smbls.RouterLink"]
57
+ );
49
58
  }
50
59
  };
51
60
  export {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@symbo.ls/create",
3
- "version": "3.1.1",
3
+ "version": "3.2.3",
4
4
  "license": "MIT",
5
- "gitHead": "39fb7a8c07355468ccce79e2f787ca3fa0715692",
5
+ "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
6
6
  "type": "module",
7
7
  "module": "src/index.js",
8
8
  "main": "src/index.js",
@@ -10,9 +10,9 @@
10
10
  "jsdelivr": "dist/iife/index.js",
11
11
  "exports": {
12
12
  ".": {
13
- "default": "./dist/esm/index.js",
14
13
  "import": "./dist/esm/index.js",
15
- "require": "./dist/cjs/index.js"
14
+ "require": "./dist/cjs/index.js",
15
+ "default": "./dist/esm/index.js"
16
16
  }
17
17
  },
18
18
  "source": "src/index.js",
@@ -22,24 +22,24 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
25
- "build:esm": "npx esbuild src/*.js --target=es2017 --format=esm --outdir=dist/esm",
26
- "build:cjs": "npx esbuild src/*.js --target=node16 --format=cjs --outdir=dist/cjs",
27
- "build:iife": "npx esbuild src/*.js --target=node16 --format=iife --outdir=dist/iife",
25
+ "build:esm": "npx cross-env NODE_ENV=$NODE_ENV npx esbuild src/*.js --target=es2017 --format=esm --outdir=dist/esm",
26
+ "build:cjs": "npx cross-env NODE_ENV=$NODE_ENV npx esbuild src/*.js --target=node16 --format=cjs --outdir=dist/cjs",
27
+ "build:iife": "npx cross-env NODE_ENV=$NODE_ENV npx esbuild src/*.js --target=node16 --format=iife --outdir=dist/iife",
28
28
  "build": "rimraf -I dist; npm run build:cjs; npm run build:esm",
29
29
  "prepublish": "npm run build; npm run copy:package:cjs"
30
30
  },
31
31
  "dependencies": {
32
- "@domql/emotion": "^3.1.1",
33
- "@domql/event": "^3.1.1",
34
- "@domql/report": "^3.1.1",
35
- "@domql/router": "^3.1.1",
36
- "@symbo.ls/fetch": "^3.1.1",
37
- "@symbo.ls/init": "^3.1.1",
38
- "@symbo.ls/scratch": "^3.1.1",
39
- "@symbo.ls/sync": "^3.1.1",
40
- "@symbo.ls/uikit": "^3.1.1",
41
- "@symbo.ls/utils": "^3.1.1",
42
- "domql": "^3.1.1"
32
+ "@domql/emotion": "^3.2.3",
33
+ "@domql/event": "^3.2.3",
34
+ "@domql/report": "^3.2.3",
35
+ "@domql/router": "^3.2.3",
36
+ "@symbo.ls/fetch": "^3.2.3",
37
+ "@symbo.ls/init": "^3.2.3",
38
+ "@symbo.ls/scratch": "^3.2.3",
39
+ "@symbo.ls/sync": "^3.2.3",
40
+ "@symbo.ls/uikit": "^3.2.3",
41
+ "@symbo.ls/utils": "^3.2.3",
42
+ "domql": "^3.2.3"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@babel/core": "^7.26.0"
@@ -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 { initializeExtend, initializeInspect, initializeNotifications, initializeSync } from './syncExtend'
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(key, context)
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]
@@ -58,7 +66,7 @@ export const createDomqlElement = async (app, ctx) => {
58
66
  app = {}
59
67
  }
60
68
 
61
- prepareContext(app, ctx)
69
+ await prepareContext(app, ctx)
62
70
 
63
71
  app.extends = initializeExtend(app, ctx)
64
72
  app.routes = ctx.pages
@@ -67,12 +75,15 @@ export const createDomqlElement = async (app, ctx) => {
67
75
  app.data = app.data || {}
68
76
  app.data.frameListeners = initAnimationFrame(ctx)
69
77
 
70
- prepareRequire({
71
- functions: ctx.functions,
72
- utils: ctx.utils,
73
- snippets: ctx.snippets,
74
- ...ctx.files
75
- }, ctx)
78
+ await prepareRequire(
79
+ {
80
+ functions: ctx.functions,
81
+ utils: ctx.utils,
82
+ snippets: ctx.snippets,
83
+ ...ctx.files
84
+ },
85
+ ctx
86
+ )
76
87
 
77
88
  initializeSync(app, ctx)
78
89
  initializeInspect(app, ctx)
package/src/index.js CHANGED
@@ -2,14 +2,14 @@
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
14
  const mergeWithLocalFile = (options, optionsExternalFile) =>
15
15
  deepMerge(
@@ -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 = options.registry || transformDOMQLEmotion(initOptions.emotion, options)
19
- const designSystem = (initOptions.useDefaultConfig || options.designSystem?.useDefaultConfig)
20
- ? deepMerge(options.designSystem, deepClone(DEFAULT_CONFIG))
21
- : options.designSystem || deepClone(DEFAULT_CONFIG)
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
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { defaultDefine } from './define'
3
+ import { defaultDefine } from './define.js'
4
4
 
5
5
  export const DESIGN_SYSTEM_OPTIONS = {
6
6
  useReset: true,
package/src/prepare.js CHANGED
@@ -5,24 +5,26 @@ import {
5
5
  deepMerge,
6
6
  deepClone,
7
7
  merge,
8
+ isDevelopment,
8
9
  matchesComponentNaming
9
10
  } from '@domql/utils'
10
- import { initEmotion } from './initEmotion'
11
+ import { initEmotion } from './initEmotion.js'
11
12
 
12
13
  import * as uikit from '@symbo.ls/uikit'
13
- import * as utils from './utilImports'
14
+ import * as utils from './utilImports.js'
14
15
  import * as routerUtils from '@domql/router'
15
16
 
16
- const ENV = process.env.NODE_ENV
17
+ // @preserve-env
17
18
 
18
- export const prepareWindow = (context) => {
19
- if (typeof (window) === 'undefined') window = globalThis || {} // eslint-disable-line
20
- if (typeof (document) === 'undefined') {
19
+ export const prepareWindow = context => {
20
+ if (typeof window === 'undefined') window = globalThis || {} // eslint-disable-line
21
+ if (typeof document === 'undefined') {
21
22
  if (!window.document) window.document = globalThis.document || { body: {} }
22
23
  document = window.document // eslint-disable-line
23
24
  }
24
25
  context.document = context.document || document
25
- return (context.window = context.window || window)
26
+ context.window = context.window || window
27
+ return context.window
26
28
  }
27
29
 
28
30
  function onlyDotsAndNumbers (str) {
@@ -44,52 +46,57 @@ export const UIkitWithPrefix = () => {
44
46
  }
45
47
 
46
48
  export const prepareComponents = context => {
47
- return context.components ? { ...UIkitWithPrefix(), ...context.components } : UIkitWithPrefix()
49
+ return context.components
50
+ ? { ...UIkitWithPrefix(), ...context.components }
51
+ : UIkitWithPrefix()
48
52
  }
49
53
 
50
54
  export const prepareUtils = context => {
51
- return { ...utils, ...routerUtils, ...utils.scratchUtils, ...context.utils, ...context.snippets, ...context.functions }
55
+ return {
56
+ ...utils,
57
+ ...routerUtils,
58
+ ...utils.scratchUtils,
59
+ ...context.utils,
60
+ ...context.snippets,
61
+ ...context.functions
62
+ }
52
63
  }
53
64
 
54
- export const prepareMethods = (context) => {
65
+ export const prepareMethods = context => {
55
66
  return {
56
67
  ...(context.methods || {}),
57
68
  require: context.utils.require,
58
- requireOnDemand: context.utils.requireOnDemand,
59
- call: function (fnKey, ...args) {
60
- return (context.utils[fnKey] || context.functions[fnKey] || context.methods[fnKey] || context.snippets[fnKey])?.call(this, ...args)
61
- }
69
+ requireOnDemand: context.utils.requireOnDemand
62
70
  }
63
71
  }
64
72
 
65
73
  const cachedDeps = {}
66
- export const prepareDependencies = ({
74
+ export const prepareDependencies = async ({
67
75
  dependencies,
68
76
  dependenciesOnDemand,
69
- document
77
+ document,
78
+ preventCaching = false
70
79
  }) => {
71
80
  if (!dependencies || Object.keys(dependencies).length === 0) {
72
81
  return null
73
82
  }
74
83
 
75
84
  for (const [dependency, version] of Object.entries(dependencies)) {
76
- if (version === 'loading' || version === 'error') {
85
+ if (dependenciesOnDemand && dependenciesOnDemand[dependency]) {
77
86
  continue
78
87
  }
79
88
 
80
- const random = ENV === 'development' ? `?${Math.random()}` : ''
89
+ const random = isDevelopment() && preventCaching ? `?${Math.random()}` : ''
81
90
  let url = `https://pkg.symbo.ls/${dependency}/${version}.js${random}`
82
91
 
83
92
  if (dependency.split('/').length > 2 || !onlyDotsAndNumbers(version)) {
84
93
  url = `https://pkg.symbo.ls/${dependency}${random}`
85
94
  }
86
95
 
87
- if (dependenciesOnDemand && dependenciesOnDemand[dependency]) continue
88
-
89
96
  try {
90
97
  if (cachedDeps[dependency]) return
91
98
  cachedDeps[dependency] = true
92
- utils.loadJavascriptFileEmbedSync(url, document)
99
+ await utils.loadRemoteScript(url, { document })
93
100
  } catch (e) {
94
101
  console.error(`Failed to load ${dependency}:`, e)
95
102
  }
@@ -98,34 +105,39 @@ export const prepareDependencies = ({
98
105
  return dependencies
99
106
  }
100
107
 
101
- export const prepareRequire = (packages, ctx) => {
108
+ export const prepareRequire = async (packages, ctx) => {
102
109
  const windowOpts = ctx.window || window
103
110
 
104
- const initRequire = ctx => key => {
111
+ const initRequire = async ctx => async key => {
105
112
  const windowOpts = ctx.window || window
106
113
  const pkg = windowOpts.packages[key]
107
114
  if (typeof pkg === 'function') return pkg()
108
115
  return pkg
109
116
  }
110
117
 
111
- const initRequireOnDemand = ctx => key => {
118
+ const initRequireOnDemand = async ctx => async key => {
112
119
  const { dependenciesOnDemand } = ctx
113
120
  const documentOpts = ctx.document || document
114
121
  const windowOpts = ctx.window || window
115
122
  if (!windowOpts.packages[key]) {
116
- const random = ENV === 'development' ? `?${Math.random()}` : ''
123
+ const random = isDevelopment() ? `?${Math.random()}` : ''
117
124
  if (dependenciesOnDemand && dependenciesOnDemand[key]) {
118
125
  const version = dependenciesOnDemand[key]
119
126
  const url = `https://pkg.symbo.ls/${key}/${version}.js${random}`
120
- ctx.utils.loadJavascriptFileEmbedSync(url, documentOpts)
127
+ await ctx.utils.loadRemoteScript(url, {
128
+ window: windowOpts,
129
+ document: documentOpts
130
+ })
121
131
  } else {
122
132
  const url = `https://pkg.symbo.ls/${key}${random}`
123
- ctx.utils.loadJavascriptFileEmbedSync(url, documentOpts, d => {
124
- windowOpts.packages[key] = 'loadedOnDeman'
133
+ await ctx.utils.loadRemoteScript(url, {
134
+ window: windowOpts,
135
+ document: documentOpts
125
136
  })
137
+ windowOpts.packages[key] = 'loadedOnDeman'
126
138
  }
127
139
  }
128
- return windowOpts.require(key)
140
+ return await windowOpts.require(key)
129
141
  }
130
142
 
131
143
  if (windowOpts.packages) {
@@ -135,12 +147,12 @@ export const prepareRequire = (packages, ctx) => {
135
147
  }
136
148
 
137
149
  if (!windowOpts.require) {
138
- ctx.utils.require = initRequire(ctx)
150
+ ctx.utils.require = await initRequire(ctx)
139
151
  windowOpts.require = ctx.utils.require
140
152
  }
141
153
 
142
154
  if (!windowOpts.requireOnDemand) {
143
- ctx.utils.requireOnDemand = initRequireOnDemand(ctx)
155
+ ctx.utils.requireOnDemand = await initRequireOnDemand(ctx)
144
156
  windowOpts.requireOnDemand = ctx.utils.requireOnDemand
145
157
  }
146
158
  }
package/src/router.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { router as defaultRouter } from '@domql/router'
4
4
  import { window, deepMerge, merge, isUndefined } from '@domql/utils'
5
+ import { Link } from 'smbls'
5
6
 
6
7
  const DEFAULT_ROUTING_OPTIONS = {
7
8
  initRouter: true,
@@ -50,16 +51,24 @@ export const popStateRouter = (element, context) => {
50
51
  if (!routerOptions.popState) return
51
52
  const router =
52
53
  context.utils && context.utils.router ? context.utils.router : defaultRouter
53
- window.onpopstate = e => {
54
+ window.onpopstate = async e => {
54
55
  const { pathname, search, hash } = window.location
55
56
  const url = pathname + search + hash
56
- router(url, element, {}, { pushState: false, scrollToTop: false, level: 0 })
57
+ await router(
58
+ url,
59
+ element,
60
+ {},
61
+ { pushState: false, scrollToTop: false, level: 0, event: e }
62
+ )
57
63
  }
58
64
  }
59
65
 
60
66
  export const injectRouterInLinkComponent = (context, routerOptions) => {
61
- const { Link, RouterLink } = context.components
67
+ const { components } = context
62
68
  if (routerOptions && routerOptions.injectRouterInLinkComponent) {
63
- return deepMerge(Link, RouterLink)
69
+ return deepMerge(
70
+ components['Link'] || components['smbls.Link'],
71
+ components['RouterLink'] || components['smbls.RouterLink']
72
+ )
64
73
  }
65
74
  }