@symbo.ls/create 2.11.444 → 2.11.447

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.
@@ -28,65 +28,73 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var createDomql_exports = {};
30
30
  __export(createDomql_exports, {
31
- createDomqlElement: () => createDomqlElement
31
+ createDomqlElement: () => createDomqlElement,
32
+ prepareContext: () => prepareContext
32
33
  });
33
34
  module.exports = __toCommonJS(createDomql_exports);
34
35
  var import_domql = __toESM(require("domql"), 1);
35
- var import_utils = require("@domql/utils");
36
36
  var uikit = __toESM(require("@symbo.ls/uikit"), 1);
37
+ var import_utils = require("@domql/utils");
37
38
  var import_define = require("./define");
38
39
  var import_router = require("./router");
39
40
  var import_syncExtend = require("./syncExtend");
40
41
  var import_prepare = require("./prepare");
41
42
  const SYMBOLS_KEY = process.env.SYMBOLS_KEY;
42
- const createDomqlElement = (App, options) => {
43
- const key = options.key || SYMBOLS_KEY || ((0, import_utils.isString)(App) ? App : "");
44
- const [scratcDesignSystem, emotion, registry] = (0, import_prepare.prepareDesignSystem)(options, key);
45
- if ((0, import_utils.isString)(App))
46
- App = {};
47
- const doc = (0, import_prepare.prepareDocument)(options);
48
- const state = (0, import_prepare.prepareState)(options, App);
49
- const pages = (0, import_prepare.preparePages)(options);
50
- const components = (0, import_prepare.prepareComponents)(options);
51
- const designSystem = scratcDesignSystem;
52
- const snippets = (0, import_prepare.prepareUtils)(options);
53
- const dependencies = (0, import_prepare.prepareDependencies)(options);
54
- (0, import_prepare.preparePackages)({ functions: snippets, utils: snippets, snippets, ...options.files }, options);
55
- const frameListeners = (0, import_prepare.prepareAnimationFrame)(options);
56
- const define = options.define || import_define.defaultDefine;
57
- const routerOptions = (0, import_router.initRouter)(App, options);
58
- const extend = (0, import_syncExtend.applySyncDebug)([App], options);
59
- return (import_domql.default.default && import_domql.default.default.create || import_domql.default.create)({
60
- extend,
61
- routes: options.pages,
62
- state,
63
- data: {
64
- frameListeners
65
- },
66
- context: {
67
- key,
68
- components,
69
- state,
70
- pages,
71
- designSystem,
72
- snippets,
73
- dependencies,
74
- functions: options.functions,
75
- files: options.files,
76
- utils: snippets,
77
- schema: options.schema,
78
- define,
79
- registry,
80
- emotion,
81
- routerOptions,
82
- socket: options.socket,
83
- editor: options.editor,
84
- window: options.window || window,
85
- document: doc
86
- }
87
- }, options.parent || doc.body, key, {
88
- extend: [uikit.Box],
89
- verbose: options.verbose,
90
- ...options.domqlOptions
43
+ const prepareContext = (app, context = {}) => {
44
+ const key = context.key = context.key || SYMBOLS_KEY || ((0, import_utils.isString)(app) ? app : "smblsapp");
45
+ context.define = context.define || import_define.defaultDefine;
46
+ context.window = (0, import_prepare.prepareWindow)(context);
47
+ const [scratcDesignSystem, emotion, registry] = (0, import_prepare.prepareDesignSystem)(key, context);
48
+ context.designSystem = scratcDesignSystem;
49
+ context.registry = registry;
50
+ context.emotion = emotion;
51
+ const state = (0, import_prepare.prepareState)(app, context);
52
+ context.state = state;
53
+ context.pages = (0, import_prepare.preparePages)(app, context);
54
+ context.components = (0, import_prepare.prepareComponents)(context);
55
+ context.utils = (0, import_prepare.prepareUtils)(context);
56
+ context.snippets = context.utils;
57
+ context.dependencies = (0, import_prepare.prepareDependencies)(context);
58
+ context.methods = (0, import_prepare.prepareMethods)(context);
59
+ context.routerOptions = (0, import_router.initRouter)(app, context);
60
+ context.defaultExtends = [uikit.Box];
61
+ return context;
62
+ };
63
+ const createDomqlElement = (app, ctx) => {
64
+ if (!(0, import_utils.isObject)(ctx))
65
+ ctx = {};
66
+ if ((0, import_utils.isNode)(app)) {
67
+ app = {};
68
+ ctx.parent = app;
69
+ }
70
+ if ((0, import_utils.isString)(app)) {
71
+ app = {};
72
+ ctx.key = app;
73
+ }
74
+ if (!(0, import_utils.isObject)(app)) {
75
+ app = {};
76
+ }
77
+ prepareContext(app, ctx);
78
+ app.extend = (0, import_syncExtend.initializeExtend)(app, ctx);
79
+ app.routes = ctx.pages;
80
+ app.state = ctx.state;
81
+ app.context = ctx;
82
+ app.data = app.data || {};
83
+ app.data.frameListeners = (0, import_prepare.initAnimationFrame)();
84
+ (0, import_prepare.prepareRequire)({
85
+ functions: ctx.snippets,
86
+ utils: ctx.snippets,
87
+ snippets: ctx.snippets,
88
+ ...ctx.files
89
+ }, ctx);
90
+ (0, import_syncExtend.initializeSync)(app, ctx);
91
+ (0, import_syncExtend.initializeInspect)(app, ctx);
92
+ (0, import_syncExtend.initializeNotifications)(app, ctx);
93
+ const parentNode = ctx.parent || ctx.document.body;
94
+ const domqlCreate = import_domql.default.default && import_domql.default.default.create || import_domql.default.create;
95
+ const smblsApp = domqlCreate(app, parentNode, ctx.key, {
96
+ verbose: ctx.verbose,
97
+ ...ctx.domqlOptions
91
98
  });
99
+ return smblsApp;
92
100
  };
package/dist/cjs/index.js CHANGED
@@ -39,7 +39,6 @@ var import_utils = require("@domql/utils");
39
39
  var utils = __toESM(require("./utilImports"), 1);
40
40
  var import_router = require("./router");
41
41
  var import_ferchOnCreate = require("./ferchOnCreate");
42
- var import_syncExtend = require("./syncExtend");
43
42
  var import_options = __toESM(require("./options"), 1);
44
43
  var import_dynamic = __toESM(require("@symbo.ls/init/dynamic.json"), 1);
45
44
  var import_createDomql = require("./createDomql");
@@ -51,7 +50,6 @@ const mergeWithLocalFile = (options, optionsExternalFile) => (0, import_utils.de
51
50
  const create = (App, options = import_options.default, optionsExternalFile) => {
52
51
  const redefinedOptions = { ...import_options.default, ...mergeWithLocalFile(options, optionsExternalFile) };
53
52
  const domqlApp = (0, import_createDomql.createDomqlElement)(App, redefinedOptions);
54
- (0, import_syncExtend.applyInspectListener)(domqlApp, redefinedOptions);
55
53
  (0, import_router.popStateRouter)(domqlApp, redefinedOptions);
56
54
  if (redefinedOptions.on && redefinedOptions.on.create)
57
55
  redefinedOptions.on.create(domqlApp, redefinedOptions);
@@ -29,25 +29,37 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var prepare_exports = {};
30
30
  __export(prepare_exports, {
31
31
  UIkitWithPrefix: () => UIkitWithPrefix,
32
- prepareAnimationFrame: () => prepareAnimationFrame,
32
+ initAnimationFrame: () => initAnimationFrame,
33
33
  prepareComponents: () => prepareComponents,
34
34
  prepareDependencies: () => prepareDependencies,
35
35
  prepareDesignSystem: () => prepareDesignSystem,
36
- prepareDocument: () => prepareDocument,
37
- preparePackages: () => preparePackages,
36
+ prepareMethods: () => prepareMethods,
38
37
  preparePages: () => preparePages,
38
+ prepareRequire: () => prepareRequire,
39
39
  prepareState: () => prepareState,
40
- prepareUtils: () => prepareUtils
40
+ prepareUtils: () => prepareUtils,
41
+ prepareWindow: () => prepareWindow
41
42
  });
42
43
  module.exports = __toCommonJS(prepare_exports);
43
44
  var import_utils = require("@domql/utils");
44
45
  var import_initEmotion = require("./initEmotion");
45
46
  var uikit = __toESM(require("@symbo.ls/uikit"), 1);
46
47
  var utils = __toESM(require("./utilImports"), 1);
48
+ const ENV = "development";
49
+ const prepareWindow = (context) => {
50
+ if (typeof window === "undefined")
51
+ window = globalThis || {};
52
+ if (typeof document === "undefined") {
53
+ if (!window.document)
54
+ window.document = globalThis.document || { body: {} };
55
+ document = window.document;
56
+ }
57
+ context.document = context.document || document;
58
+ return context.window = context.window || window;
59
+ };
47
60
  function onlyDotsAndNumbers(str) {
48
61
  return /^[0-9.]+$/.test(str) && str !== "";
49
62
  }
50
- const ENV = "development";
51
63
  const UIkitWithPrefix = () => {
52
64
  const newObj = {};
53
65
  for (const key in uikit) {
@@ -61,14 +73,28 @@ const UIkitWithPrefix = () => {
61
73
  }
62
74
  return newObj;
63
75
  };
64
- const prepareComponents = (options) => {
65
- return options.components ? { ...UIkitWithPrefix(), ...options.components } : UIkitWithPrefix();
76
+ const prepareComponents = (context) => {
77
+ return context.components ? { ...UIkitWithPrefix(), ...context.components } : UIkitWithPrefix();
66
78
  };
67
- const prepareUtils = (options) => {
68
- return { ...utils, ...utils.scratchUtils, ...options.snippets || options.utils || options.functions || {} };
79
+ const prepareUtils = (context) => {
80
+ return { ...utils, ...utils.scratchUtils, ...context.snippets || context.utils || context.functions || {} };
81
+ };
82
+ const prepareMethods = (context) => {
83
+ return {
84
+ ...context.methods || {},
85
+ require: context.utils.require,
86
+ requireOnDemand: context.utils.requireOnDemand,
87
+ call: function(fnKey, ...args) {
88
+ return (context.utils[fnKey] || context.methods[fnKey]).call(this, ...args);
89
+ }
90
+ };
69
91
  };
70
92
  const cachedDeps = {};
71
- const prepareDependencies = ({ packages: dependencies, dependenciesOnDemand, document: document2 }) => {
93
+ const prepareDependencies = ({
94
+ packages: dependencies,
95
+ dependenciesOnDemand,
96
+ document: document2
97
+ }) => {
72
98
  if (!dependencies || Object.keys(dependencies).length === 0) {
73
99
  return null;
74
100
  }
@@ -94,90 +120,82 @@ const prepareDependencies = ({ packages: dependencies, dependenciesOnDemand, doc
94
120
  }
95
121
  return dependencies;
96
122
  };
97
- const preparePackages = (packages, opts) => {
98
- const windowOpts = opts.window || window;
123
+ const prepareRequire = (packages, ctx) => {
124
+ const windowOpts = ctx.window || window;
125
+ const initRequire = (ctx2) => (key) => {
126
+ const windowOpts2 = ctx2.window || window;
127
+ const pkg = windowOpts2.packages[key];
128
+ if (typeof pkg === "function")
129
+ return pkg();
130
+ return pkg;
131
+ };
132
+ const initRequireOnDemand = (ctx2) => (key) => {
133
+ const { dependenciesOnDemand } = ctx2;
134
+ const documentOpts = ctx2.document || document;
135
+ const windowOpts2 = ctx2.window || window;
136
+ if (!windowOpts2.packages[key]) {
137
+ const random = ENV === "development" ? `?${Math.random()}` : "";
138
+ if (dependenciesOnDemand && dependenciesOnDemand[key]) {
139
+ const version = dependenciesOnDemand[key];
140
+ const url = `https://pkg.symbo.ls/${key}/${version}.js${random}`;
141
+ ctx2.utils.loadJavascriptFileEmbedSync(url, documentOpts);
142
+ } else {
143
+ const url = `https://pkg.symbo.ls/${key}${random}`;
144
+ ctx2.utils.loadJavascriptFileEmbedSync(url, documentOpts, (d) => {
145
+ windowOpts2.packages[key] = "loadedOnDeman";
146
+ console.log(d);
147
+ });
148
+ }
149
+ }
150
+ return windowOpts2.require(key);
151
+ };
99
152
  if (windowOpts.packages) {
100
153
  windowOpts.packages = (0, import_utils.merge)(windowOpts.packages, packages);
101
154
  } else {
102
155
  windowOpts.packages = packages;
103
156
  }
104
157
  if (!windowOpts.require) {
105
- windowOpts.require = (key) => {
106
- const pkg = windowOpts.packages[key];
107
- if (typeof pkg === "function")
108
- return pkg();
109
- return pkg;
110
- };
158
+ ctx.utils.require = initRequire(ctx);
159
+ windowOpts.require = ctx.utils.require;
111
160
  }
112
161
  if (!windowOpts.requireOnDemand) {
113
- windowOpts.requireOnDemand = (key) => {
114
- const { dependenciesOnDemand, document: document2 } = opts;
115
- if (!windowOpts.packages[key]) {
116
- const random = ENV === "development" ? `?${Math.random()}` : "";
117
- if (dependenciesOnDemand && dependenciesOnDemand[key]) {
118
- const version = dependenciesOnDemand[key];
119
- const url = `https://pkg.symbo.ls/${key}/${version}.js${random}`;
120
- utils.loadJavascriptFileEmbedSync(url, document2);
121
- } else {
122
- const url = `https://pkg.symbo.ls/${key}${random}`;
123
- utils.loadJavascriptFileEmbedSync(url, document2, (d) => {
124
- windowOpts.packages[key] = "loadedOnDeman";
125
- console.log(d);
126
- });
127
- }
128
- }
129
- return windowOpts.require(key);
130
- };
162
+ ctx.utils.requireOnDemand = initRequireOnDemand(ctx);
163
+ windowOpts.requireOnDemand = ctx.utils.requireOnDemand;
131
164
  }
132
165
  };
133
- const prepareDesignSystem = (options, key) => {
134
- const [scratcDesignhSystem, emotion, registry] = (0, import_initEmotion.initEmotion)(key, options);
166
+ const prepareDesignSystem = (key, context) => {
167
+ const [scratcDesignhSystem, emotion, registry] = (0, import_initEmotion.initEmotion)(key, context);
135
168
  return [scratcDesignhSystem, emotion, registry];
136
169
  };
137
- const prepareState = (options, App) => {
170
+ const prepareState = (app, context) => {
138
171
  const state = {};
139
- if (options.state)
140
- utils.deepMerge(state, options.state);
141
- if (App && App.state)
142
- (0, import_utils.deepMerge)(state, App.state);
172
+ if (context.state)
173
+ utils.deepMerge(state, context.state);
174
+ if (app && app.state)
175
+ (0, import_utils.deepMerge)(state, app.state);
143
176
  return (0, import_utils.deepCloneWithExtend)(state);
144
177
  };
145
- const preparePages = (options) => {
146
- const pages = options.pages;
147
- Object.keys(options.pages).filter((v) => !v.startsWith("/")).forEach((v) => {
148
- if (v === "main")
149
- pages["/"] = options.pages.main;
150
- else {
151
- pages["/" + v] = options.pages[v];
152
- }
153
- });
154
- options.pages = pages;
155
- return pages;
156
- };
157
- const prepareDocument = (options) => {
158
- if (typeof document === "undefined") {
159
- if (typeof window === "undefined")
160
- window = {};
161
- if (!window.document)
162
- window.document = { body: {} };
163
- document = window.document;
178
+ const preparePages = (app, context) => {
179
+ if ((0, import_utils.isObject)(app.routes) && (0, import_utils.isObject)(context.pages)) {
180
+ (0, import_utils.merge)(app.routes, context.pages);
164
181
  }
165
- if (!options.window)
166
- options.window = window;
167
- if (!options.document)
168
- options.document = document;
169
- return options.parent || options.document || document;
182
+ const pages = app.routes || context.pages || {};
183
+ return Object.keys(pages).filter((v) => !v.startsWith("/")).reduce((pages2, v) => {
184
+ const index = v === "index" ? "" : v;
185
+ pages2["/" + index] = pages2[v];
186
+ delete pages2[v];
187
+ return pages2;
188
+ }, pages);
170
189
  };
171
- const prepareAnimationFrame = (opts) => {
190
+ const initAnimationFrame = () => {
172
191
  const frameListeners = /* @__PURE__ */ new Set();
173
192
  function requestFrame() {
174
- var _a;
175
- for (const el of frameListeners) {
176
- if (!((_a = el.node) == null ? void 0 : _a.parentNode)) {
177
- frameListeners.delete(el);
193
+ for (const element of frameListeners) {
194
+ if (!document.body.contains(element.node)) {
195
+ frameListeners.delete(element);
178
196
  } else {
179
197
  try {
180
- (el.on.frame || el.props.onFrame)(el, el.state, el.context);
198
+ (element.on.frame || element.props.onFrame)(element, element.state, element.context);
181
199
  } catch (e) {
182
200
  console.warn(e);
183
201
  }
@@ -31,15 +31,15 @@ const DEFAULT_ROUTING_OPTIONS = {
31
31
  injectRouterInLinkComponent: true,
32
32
  popState: true
33
33
  };
34
- const initRouter = (element, options) => {
35
- if (options.router === false)
34
+ const initRouter = (element, context) => {
35
+ if (context.router === false)
36
36
  return;
37
- else if (options.router === true)
38
- options.router = DEFAULT_ROUTING_OPTIONS;
37
+ else if (context.router === true)
38
+ context.router = DEFAULT_ROUTING_OPTIONS;
39
39
  else
40
- (0, import_utils.merge)(options.router || {}, DEFAULT_ROUTING_OPTIONS);
41
- const routerOptions = options.router;
42
- const router = options.snippets && options.snippets.router ? options.snippets.router : import_router.router;
40
+ (0, import_utils.merge)(context.router || {}, DEFAULT_ROUTING_OPTIONS);
41
+ const routerOptions = context.router;
42
+ const router = context.snippets && context.snippets.router ? context.snippets.router : import_router.router;
43
43
  const onRouterRenderDefault = (el, s) => {
44
44
  const { pathname, search, hash } = import_utils.window.location;
45
45
  const url = pathname + search + hash;
@@ -60,14 +60,14 @@ const initRouter = (element, options) => {
60
60
  return routerOptions;
61
61
  };
62
62
  let popStateFired;
63
- const popStateRouter = (element, options) => {
63
+ const popStateRouter = (element, context) => {
64
64
  if (popStateFired)
65
65
  return;
66
66
  popStateFired = true;
67
- const routerOptions = options.router || DEFAULT_ROUTING_OPTIONS;
67
+ const routerOptions = context.router || DEFAULT_ROUTING_OPTIONS;
68
68
  if (!routerOptions.popState)
69
69
  return;
70
- const router = options.snippets && options.snippets.router ? options.snippets.router : import_router.router;
70
+ const router = context.snippets && context.snippets.router ? context.snippets.router : import_router.router;
71
71
  import_utils.window.onpopstate = (e) => {
72
72
  const { pathname, search, hash } = import_utils.window.location;
73
73
  const url = pathname + search + hash;
@@ -18,29 +18,40 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var syncExtend_exports = {};
20
20
  __export(syncExtend_exports, {
21
- applyInspectListener: () => applyInspectListener,
22
- applySyncDebug: () => applySyncDebug
21
+ initializeExtend: () => initializeExtend,
22
+ initializeInspect: () => initializeInspect,
23
+ initializeNotifications: () => initializeNotifications,
24
+ initializeSync: () => initializeSync
23
25
  });
24
26
  module.exports = __toCommonJS(syncExtend_exports);
25
- var import_socket_ui = require("@symbo.ls/socket-ui");
26
27
  var import_utils = require("@domql/utils");
27
- const applySyncDebug = (extend, options) => {
28
- const { editor } = options;
28
+ var import_sync = require("@symbo.ls/sync");
29
+ var import_Inspect = require("@symbo.ls/sync/Inspect");
30
+ var import_Notifications = require("@symbo.ls/sync/Notifications");
31
+ const initializeExtend = (app, ctx) => {
32
+ return (0, import_utils.isObjectLike)(app.extend) ? app.extend : {};
33
+ };
34
+ const initializeSync = (app, ctx) => {
35
+ const { editor } = ctx;
29
36
  if (!editor)
30
- return extend;
31
- const inspect = (0, import_utils.isUndefined)(editor.inspect) ? (0, import_utils.isDevelopment)() : editor.inspect;
32
- if (inspect)
33
- extend.push(import_socket_ui.DevFocus);
37
+ return;
34
38
  const liveSync = (0, import_utils.isUndefined)(editor.liveSync) ? (0, import_utils.isDevelopment)() : editor.liveSync;
35
39
  if (liveSync)
36
- extend.push(import_socket_ui.Sync);
37
- return extend;
40
+ app.extend.push(import_sync.SyncComponent);
38
41
  };
39
- const applyInspectListener = (root, options) => {
40
- const { editor } = options;
42
+ const initializeInspect = (app, ctx) => {
43
+ const { editor } = ctx;
41
44
  if (!editor)
42
45
  return;
43
46
  const inspect = (0, import_utils.isUndefined)(editor.inspect) ? (0, import_utils.isDevelopment)() : editor.inspect;
44
47
  if (inspect)
45
- (0, import_socket_ui.inspectOnKey)(root, options);
48
+ app.extend.push(import_Inspect.Inspect);
49
+ };
50
+ const initializeNotifications = (app, ctx) => {
51
+ const { editor } = ctx;
52
+ if (!editor)
53
+ return;
54
+ const verbose = (0, import_utils.isUndefined)(editor.verbose) ? (0, import_utils.isDevelopment)() || ctx.verbose : editor.verbose;
55
+ if (verbose)
56
+ app.extend.push(import_Notifications.Notifications);
46
57
  };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@symbo.ls/create",
3
- "version": "2.11.444",
3
+ "version": "2.11.447",
4
4
  "license": "MIT",
5
- "gitHead": "15341106596c691381dac4b475c44d53557786e8",
5
+ "gitHead": "e59d0443eec7f94e5737a916d49daf00d1ee9c47",
6
6
  "files": [
7
7
  "src",
8
8
  "dist"
@@ -31,16 +31,15 @@
31
31
  "prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
32
32
  },
33
33
  "dependencies": {
34
- "@domql/emotion": "latest",
35
- "@domql/report": "latest",
36
- "@domql/router": "latest",
37
- "@domql/utils": "latest",
38
- "@symbo.ls/fetch": "latest",
39
- "@symbo.ls/init": "latest",
40
- "@symbo.ls/scratch": "latest",
41
- "@symbo.ls/socket-ui": "latest",
42
- "@symbo.ls/uikit": "latest",
43
- "@symbo.ls/utils": "latest",
34
+ "@domql/emotion": "^2.5.0",
35
+ "@domql/report": "^2.5.0",
36
+ "@domql/router": "^2.5.0",
37
+ "@symbo.ls/fetch": "^2.11.446",
38
+ "@symbo.ls/init": "^2.11.446",
39
+ "@symbo.ls/scratch": "^2.11.446",
40
+ "@symbo.ls/sync": "^2.11.447",
41
+ "@symbo.ls/uikit": "^2.11.447",
42
+ "@symbo.ls/utils": "^2.11.446",
44
43
  "domql": "^2.5.0"
45
44
  },
46
45
  "devDependencies": {
@@ -1,79 +1,89 @@
1
1
  'use strict'
2
2
 
3
3
  import DOM from 'domql'
4
- import { isString } from '@domql/utils'
5
-
6
4
  import * as uikit from '@symbo.ls/uikit'
7
5
 
6
+ import { isString, isNode, isObject } from '@domql/utils'
8
7
  import { defaultDefine } from './define'
9
8
  import { initRouter } from './router'
10
- import { applySyncDebug } from './syncExtend'
9
+ import { initializeExtend, initializeInspect, initializeNotifications, initializeSync } from './syncExtend'
10
+
11
11
  import {
12
- prepareAnimationFrame,
12
+ initAnimationFrame,
13
13
  prepareComponents,
14
14
  prepareDependencies,
15
15
  prepareDesignSystem,
16
- prepareDocument,
17
- preparePackages,
16
+ prepareWindow,
17
+ prepareRequire,
18
18
  preparePages,
19
19
  prepareState,
20
- prepareUtils
20
+ prepareUtils,
21
+ prepareMethods
21
22
  } from './prepare'
22
23
 
23
24
  const SYMBOLS_KEY = process.env.SYMBOLS_KEY
24
25
 
25
- export const createDomqlElement = (App, options) => {
26
- const key = options.key || SYMBOLS_KEY || (isString(App) ? App : '')
27
- const [scratcDesignSystem, emotion, registry] = prepareDesignSystem(options, key)
28
- if (isString(App)) App = {}
26
+ export const prepareContext = (app, context = {}) => {
27
+ const key = context.key = context.key || SYMBOLS_KEY || (isString(app) ? app : 'smblsapp')
28
+ context.define = context.define || defaultDefine
29
+ context.window = prepareWindow(context)
30
+ const [scratcDesignSystem, emotion, registry] = prepareDesignSystem(key, context)
31
+ context.designSystem = scratcDesignSystem
32
+ context.registry = registry
33
+ context.emotion = emotion
34
+ const state = prepareState(app, context)
35
+ context.state = state
36
+ context.pages = preparePages(app, context)
37
+ context.components = prepareComponents(context)
38
+ context.utils = prepareUtils(context)
39
+ context.snippets = context.utils
40
+ context.dependencies = prepareDependencies(context)
41
+ context.methods = prepareMethods(context)
42
+ context.routerOptions = initRouter(app, context)
43
+ context.defaultExtends = [uikit.Box]
44
+ return context
45
+ }
29
46
 
30
- const doc = prepareDocument(options)
31
- const state = prepareState(options, App)
32
- const pages = preparePages(options)
33
- const components = prepareComponents(options)
34
- const designSystem = scratcDesignSystem
35
- const snippets = prepareUtils(options)
36
- const dependencies = prepareDependencies(options)
37
- preparePackages({ functions: snippets, utils: snippets, snippets, ...options.files }, options)
47
+ export const createDomqlElement = (app, ctx) => {
48
+ if (!isObject(ctx)) ctx = {}
49
+ if (isNode(app)) {
50
+ app = {}
51
+ ctx.parent = app
52
+ }
53
+ if (isString(app)) {
54
+ app = {}
55
+ ctx.key = app
56
+ }
57
+ if (!isObject(app)) {
58
+ app = {}
59
+ }
38
60
 
39
- const frameListeners = prepareAnimationFrame(options)
61
+ prepareContext(app, ctx)
40
62
 
41
- const define = options.define || defaultDefine
63
+ app.extend = initializeExtend(app, ctx)
64
+ app.routes = ctx.pages
65
+ app.state = ctx.state
66
+ app.context = ctx
67
+ app.data = app.data || {}
68
+ app.data.frameListeners = initAnimationFrame()
42
69
 
43
- const routerOptions = initRouter(App, options) // eslint-disable-line
44
- const extend = applySyncDebug([App], options)
70
+ prepareRequire({
71
+ functions: ctx.snippets,
72
+ utils: ctx.snippets,
73
+ snippets: ctx.snippets,
74
+ ...ctx.files
75
+ }, ctx)
45
76
 
46
- return ((DOM.default && DOM.default.create) || DOM.create)({
47
- extend,
48
- routes: options.pages,
49
- state,
50
- data: {
51
- frameListeners
52
- },
53
- context: {
54
- key,
55
- components,
56
- state,
57
- pages,
58
- designSystem,
59
- snippets,
60
- dependencies,
61
- functions: options.functions,
62
- files: options.files,
63
- utils: snippets,
64
- schema: options.schema,
65
- define,
66
- registry,
67
- emotion,
68
- routerOptions,
69
- socket: options.socket,
70
- editor: options.editor,
71
- window: options.window || window,
72
- document: doc
73
- }
74
- }, options.parent || doc.body, key, {
75
- extend: [uikit.Box],
76
- verbose: options.verbose,
77
- ...options.domqlOptions
77
+ initializeSync(app, ctx)
78
+ initializeInspect(app, ctx)
79
+ initializeNotifications(app, ctx)
80
+
81
+ const parentNode = ctx.parent || ctx.document.body
82
+ const domqlCreate = (DOM.default && DOM.default.create) || DOM.create
83
+ const smblsApp = domqlCreate(app, parentNode, ctx.key, {
84
+ verbose: ctx.verbose,
85
+ ...ctx.domqlOptions
78
86
  })
87
+
88
+ return smblsApp
79
89
  }
package/src/index.js CHANGED
@@ -6,7 +6,6 @@ import * as utils from './utilImports'
6
6
 
7
7
  import { popStateRouter } from './router'
8
8
  import { fetchAsync, fetchSync } from './ferchOnCreate'
9
- import { applyInspectListener } from './syncExtend'
10
9
 
11
10
  import DEFAULT_CREATE_OPTIONS from './options'
12
11
  import DYNAMIC_JSON from '@symbo.ls/init/dynamic.json'
@@ -24,7 +23,6 @@ export const create = (App, options = DEFAULT_CREATE_OPTIONS, optionsExternalFil
24
23
 
25
24
  const domqlApp = createDomqlElement(App, redefinedOptions)
26
25
 
27
- applyInspectListener(domqlApp, redefinedOptions)
28
26
  popStateRouter(domqlApp, redefinedOptions)
29
27
 
30
28
  if (redefinedOptions.on && redefinedOptions.on.create) redefinedOptions.on.create(domqlApp, redefinedOptions)