@symbo.ls/create 2.10.171 → 2.10.173

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/ferchOnCreate.js CHANGED
@@ -15,9 +15,8 @@ export const fetchSync = async (key, options) => {
15
15
  export const fetchAsync = (app, key, options, callback) => {
16
16
  if (key && options.editor) {
17
17
  try {
18
- if (options.editor.async) fetchStateAsync(key, options, (data) => {
19
- app.state.update(data)
20
- })
18
+ const defaultCallback = (data) => app.state.update(data)
19
+ if (options.editor.async) fetchStateAsync(key, options, callback || defaultCallback)
21
20
  } catch (e) {
22
21
  console.error(e)
23
22
  }
package/index.js CHANGED
@@ -7,43 +7,46 @@ import * as utils from './utilImports'
7
7
  import * as uikit from '@symbo.ls/uikit'
8
8
 
9
9
  import { defaultDefine } from './define'
10
- import { initRouter } from './router'
10
+ import { initRouter, popStateRouter } from './router'
11
11
  import { fetchAsync, fetchSync } from './ferchOnCreate'
12
12
  import { initEmotion } from './initEmotion'
13
+ import { applyKeyDebugListener, applySyncDebug } from './syncExtend'
13
14
 
14
- import { DEFAULT_CREATE_OPTIONS } from './options'
15
+ import DEFAULT_CREATE_OPTIONS from './options'
15
16
  import DYNAMIC_JSON from '@symbo.ls/init/dynamic.json'
16
17
 
17
18
  const SYMBOLS_KEY = process.env.SYMBOLS_KEY
18
19
 
19
- const mergeWithLocalFile = (options, RC_FILE) => {
20
- const rcfile = isObject(RC_FILE) ? RC_FILE : DYNAMIC_JSON || {}
20
+ const mergeWithLocalFile = (options, optionsExternalFile) => {
21
+ const rcfile = isObject(optionsExternalFile) ? optionsExternalFile : DYNAMIC_JSON || {}
21
22
  return deepMerge(options, rcfile)
22
23
  }
23
24
 
24
- export const create = async (App, options = DEFAULT_CREATE_OPTIONS, RC_FILE) => {
25
+ export const create = async (App, options = DEFAULT_CREATE_OPTIONS, optionsExternalFile) => {
25
26
  const appIsKey = isString(App)
26
- options = mergeWithLocalFile(options, RC_FILE)
27
+ options = mergeWithLocalFile(options, optionsExternalFile)
28
+
27
29
  const key = options.key || SYMBOLS_KEY || (appIsKey ? App : '')
28
30
 
29
31
  if (appIsKey) App = {}
30
32
  await fetchSync(key, options)
31
33
 
32
34
  const doc = options.parent || options.document || document
33
-
34
35
  const [scratchSystem, emotion, registry] = initEmotion(key, options)
35
36
 
36
- initRouter(App, options.routerOptions)
37
+ const router = initRouter(App, options)
37
38
 
38
39
  const state = options.state || {}
39
- const pages = options.pages || {}
40
+ const pages = options.pages || {}
40
41
  const components = options.components ? { ...uikit, ...options.components } : uikit
41
42
  const designSystem = scratchSystem || {}
42
- const snippets = { ...utils, ...(options.snippets || {})}
43
+ const snippets = { ...utils, ...(options.snippets || {}) }
43
44
  const define = options.define || defaultDefine
44
45
 
46
+ const extend = applySyncDebug([App], options)
47
+
45
48
  const domqlApp = DOM.create({
46
- extend: [App],
49
+ extend,
47
50
  routes: options.pages,
48
51
  state,
49
52
  context: {
@@ -65,7 +68,10 @@ export const create = async (App, options = DEFAULT_CREATE_OPTIONS, RC_FILE) =>
65
68
  ...options.domqlOptions
66
69
  })
67
70
 
68
- fetchAsync(domqlApp)
71
+ applyKeyDebugListener(domqlApp, options)
72
+ popStateRouter(domqlApp, options)
73
+
74
+ fetchAsync(domqlApp, key, options)
69
75
 
70
76
  return domqlApp
71
77
  }
package/initEmotion.js CHANGED
@@ -3,7 +3,8 @@
3
3
  import { transformDOMQLEmotion } from '@domql/emotion'
4
4
  import { emotion as defaultEmotion } from '@symbo.ls/emotion'
5
5
  import { init } from '@symbo.ls/init'
6
- import { DEFAULT_CREATE_OPTIONS } from './options'
6
+
7
+ import DEFAULT_CREATE_OPTIONS from './options'
7
8
 
8
9
  export const initEmotion = (key, options = DEFAULT_CREATE_OPTIONS) => {
9
10
  const doc = options.parent || options.document || document
package/options.js CHANGED
@@ -3,10 +3,8 @@
3
3
  import { defaultDefine } from './define'
4
4
  import { emotion as defaultEmotion } from '@symbo.ls/emotion'
5
5
 
6
- export const DEFAULT_CREATE_OPTIONS = {
7
- editor: {
8
- endpoint: 'api.symbols.app'
9
- },
6
+ export default {
7
+ editor: {},
10
8
  state: {},
11
9
  pages: {},
12
10
  designSystem: {
@@ -18,7 +16,7 @@ export const DEFAULT_CREATE_OPTIONS = {
18
16
  },
19
17
  components: {},
20
18
  initOptions: {
21
- emotion: defaultEmotion
19
+ emotion: defaultEmotion,
22
20
  },
23
21
  router: {
24
22
  initRouter: true,
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@symbo.ls/create",
3
- "version": "2.10.171",
3
+ "version": "2.10.173",
4
4
  "license": "MIT",
5
- "gitHead": "6be38bfad2d2bbcaf279e2b4fc81d8b5bbda30be",
5
+ "gitHead": "0238c5e3c0e34f4effa4e94031e549e7526e5f48",
6
6
  "source": "index.js",
7
7
  "main": "index.js",
8
8
  "dependencies": {
9
9
  "@domql/cookie": "latest",
10
10
  "@domql/emotion": "latest",
11
+ "@domql/env": "latest",
11
12
  "@domql/report": "latest",
12
13
  "@domql/router": "latest",
13
14
  "@domql/utils": "latest",
package/router.js CHANGED
@@ -1,23 +1,28 @@
1
1
  'use strict'
2
2
 
3
- import { router } from '@domql/router'
4
- import { Link, RouterLink } from 'smbls'
3
+ import { router as defaultRouter } from '@domql/router'
4
+ import { Link, RouterLink } from '@symbo.ls/uikit'
5
5
  import { deepMerge } from '@domql/utils'
6
6
 
7
7
  const DEFAULT_ROUTING_OPTIONS = {
8
8
  initRouter: true,
9
- injectRouterInLinkComponent: true
9
+ injectRouterInLinkComponent: true,
10
+ popState: true
10
11
  }
11
12
 
12
- export const initRouter = (root, options = DEFAULT_ROUTING_OPTIONS) => {
13
- if (options === false) return
14
- if (options === true) options = DEFAULT_ROUTING_OPTIONS
13
+ export const initRouter = (root, options) => {
14
+ const routerOptions = options.routerOptions || DEFAULT_ROUTING_OPTIONS
15
+
16
+ if (routerOptions === false) return
17
+ if (routerOptions === true) routerOptions = DEFAULT_ROUTING_OPTIONS
18
+
19
+ const router = options.snippets && options.snippets.router || defaultRouter
15
20
 
16
21
  const onRender = (el, s) => {
17
22
  if (el.routes) router(el, window.location.pathname, {})
18
23
  }
19
24
 
20
- if (options.initRouter) {
25
+ if (routerOptions.initRouter) {
21
26
  if (root.on) {
22
27
  root.on.renderRouter = onRender
23
28
  } else {
@@ -27,11 +32,19 @@ export const initRouter = (root, options = DEFAULT_ROUTING_OPTIONS) => {
27
32
  }
28
33
  }
29
34
 
30
- if (options.injectRouterInLinkComponent) {
31
- injectRouterInLinkComponent(options)
32
- }
35
+ injectRouterInLinkComponent(routerOptions)
36
+
37
+ return router
38
+ }
39
+
40
+ export const popStateRouter = (root, options) => {
41
+ const routerOptions = options.routerOptions || DEFAULT_ROUTING_OPTIONS
42
+ if (!routerOptions.popState) return
43
+ const router = options.snippets && options.snippets.router || defaultRouter
44
+ window.onpopstate = e => router(root, window.location.pathname, {}, 0, false)
33
45
  }
34
46
 
35
- export const injectRouterInLinkComponent = () => {
36
- return deepMerge(Link, RouterLink)
47
+ export const injectRouterInLinkComponent = (routerOptions) => {
48
+ if (routerOptions.injectRouterInLinkComponent)
49
+ return deepMerge(Link, RouterLink)
37
50
  }
package/syncExtend.js ADDED
@@ -0,0 +1,18 @@
1
+ 'use strict'
2
+
3
+ import { Sync, DevFocus, inspectOnKey } from '@symbo.ls/socket-ui'
4
+ import { isProduction, isTest } from '@domql/env'
5
+
6
+ const { NODE_ENV } = process.env
7
+
8
+ export const applySyncDebug = (extend, options) => {
9
+ if (options.debug) extend.push[DevFocus]
10
+ if (options.socket) extend.push[Sync]
11
+ return extend
12
+ }
13
+
14
+ export const applyKeyDebugListener = (root, options) => {
15
+ if (options.debug) inspectOnKey(root)
16
+ }
17
+
18
+ const extend = isProduction(NODE_ENV) || isTest(NODE_ENV) [Sync, DevFocus]