@symbo.ls/create 2.10.169 → 2.10.172

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
@@ -6,68 +6,48 @@ import { deepMerge, isObject, isString } from '@domql/utils'
6
6
  import * as utils from './utilImports'
7
7
  import * as uikit from '@symbo.ls/uikit'
8
8
 
9
- import { emotion as defaultEmotion } from '@symbo.ls/emotion'
10
-
9
+ import { inspectOnKey } from '@symbo.ls/socket-ui'
11
10
  import { defaultDefine } from './define'
12
- import { initRouter } from './router'
11
+ import { initRouter, popStateRouter } from './router'
13
12
  import { fetchAsync, fetchSync } from './ferchOnCreate'
14
13
  import { initEmotion } from './initEmotion'
14
+ import { applySyncDebug } from './syncExtend'
15
15
 
16
+ import DEFAULT_CREATE_OPTIONS from './options'
16
17
  import DYNAMIC_JSON from '@symbo.ls/init/dynamic.json'
17
- const SYMBOLS_KEY = process.env.SYMBOLS_KEY
18
18
 
19
- export const DEFAULT_CREATE_OPTIONS = {
20
- editor: {
21
- endpoint: 'api.symbols.app'
22
- },
23
- state: {},
24
- pages: {},
25
- designSystem: {
26
- useReset: true,
27
- useVariable: true,
28
- useIconSprite: true,
29
- useSvgSprite: true,
30
- useFontImport: true
31
- },
32
- components: {},
33
- initOptions: {
34
- emotion: defaultEmotion
35
- },
36
- router: {
37
- initRouter: true,
38
- injectRouterInLinkComponent: true
39
- },
40
- define: defaultDefine
41
- }
19
+ const SYMBOLS_KEY = process.env.SYMBOLS_KEY
42
20
 
43
- const mergeWithLocalFile = (options, RC_FILE) => {
44
- const rcfile = isObject(RC_FILE) ? RC_FILE : DYNAMIC_JSON || {}
21
+ const mergeWithLocalFile = (options, optionsExternalFile) => {
22
+ const rcfile = isObject(optionsExternalFile) ? optionsExternalFile : DYNAMIC_JSON || {}
45
23
  return deepMerge(options, rcfile)
46
24
  }
47
25
 
48
- export const create = async (App, options = DEFAULT_CREATE_OPTIONS, RC_FILE) => {
26
+ export const create = async (App, options = DEFAULT_CREATE_OPTIONS, optionsExternalFile) => {
49
27
  const appIsKey = isString(App)
50
- options = mergeWithLocalFile(options, RC_FILE)
28
+ options = mergeWithLocalFile(options, optionsExternalFile)
29
+
51
30
  const key = options.key || SYMBOLS_KEY || (appIsKey ? App : '')
52
31
 
53
32
  if (appIsKey) App = {}
54
33
  await fetchSync(key, options)
55
34
 
56
35
  const doc = options.parent || options.document || document
57
-
58
36
  const [scratchSystem, emotion, registry] = initEmotion(key, options)
59
37
 
60
- initRouter(App, options.routerOptions)
38
+ const router = initRouter(App, options)
61
39
 
62
40
  const state = options.state || {}
63
- const pages = options.pages || {}
41
+ const pages = options.pages || {}
64
42
  const components = options.components ? { ...uikit, ...options.components } : uikit
65
43
  const designSystem = scratchSystem || {}
66
- const snippets = { ...utils, ...(options.snippets || {})}
44
+ const snippets = { ...utils, ...(options.snippets || {}) }
67
45
  const define = options.define || defaultDefine
68
46
 
47
+ const extend = applySyncDebug([App], options)
48
+
69
49
  const domqlApp = DOM.create({
70
- extend: [App],
50
+ extend,
71
51
  routes: options.pages,
72
52
  state,
73
53
  context: {
@@ -89,7 +69,10 @@ export const create = async (App, options = DEFAULT_CREATE_OPTIONS, RC_FILE) =>
89
69
  ...options.domqlOptions
90
70
  })
91
71
 
92
- fetchAsync(domqlApp)
72
+ applyKeyDebugListener(domqlApp, options)
73
+ popStateRouter(domqlApp, options)
74
+
75
+ fetchAsync(domqlApp, key, options)
93
76
 
94
77
  return domqlApp
95
78
  }
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 '.'
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 ADDED
@@ -0,0 +1,26 @@
1
+ 'use strict'
2
+
3
+ import { defaultDefine } from './define'
4
+ import { emotion as defaultEmotion } from '@symbo.ls/emotion'
5
+
6
+ export default {
7
+ editor: {},
8
+ state: {},
9
+ pages: {},
10
+ designSystem: {
11
+ useReset: true,
12
+ useVariable: true,
13
+ useIconSprite: true,
14
+ useSvgSprite: true,
15
+ useFontImport: true
16
+ },
17
+ components: {},
18
+ initOptions: {
19
+ emotion: defaultEmotion,
20
+ },
21
+ router: {
22
+ initRouter: true,
23
+ injectRouterInLinkComponent: true
24
+ },
25
+ define: defaultDefine
26
+ }
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@symbo.ls/create",
3
- "version": "2.10.169",
3
+ "version": "2.10.172",
4
4
  "license": "MIT",
5
- "gitHead": "f22d3cd31dd7c4521890a8ca730f8a3bee42bfc0",
5
+ "gitHead": "c5542d156c687366e76194813bf2d5f0227e8396",
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]