@symbo.ls/create 2.10.162 → 2.10.165

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.
@@ -0,0 +1,26 @@
1
+ 'use strict'
2
+
3
+ import { fetchProject, fetchStateAsync } from "@symbo.ls/fetch"
4
+
5
+ export const fetchSync = async (key, options) => {
6
+ if (key && options.editor) {
7
+ try {
8
+ if (!options.async) await fetchProject(key, options)
9
+ } catch (e) {
10
+ console.error(e)
11
+ }
12
+ }
13
+ }
14
+
15
+ export const fetchAsync = (app, key, options, callback) => {
16
+ if (key && options.editor) {
17
+ try {
18
+ if (options.editor.async) fetchStateAsync(key, options, (data) => {
19
+ app.state.update(data)
20
+ })
21
+ } catch (e) {
22
+ console.error(e)
23
+ }
24
+ }
25
+ }
26
+
package/index.js CHANGED
@@ -1,24 +1,27 @@
1
1
  'use strict'
2
2
 
3
3
  import DOM from 'domql'
4
- import { transformDOMQLEmotion } from 'domql/packages/emotion'
5
- import { router } from 'domql/packages/router'
4
+ import { transformDOMQLEmotion } from '@domql/emotion'
5
+ import { router as defaultRouter } from '@domql/router'
6
6
 
7
7
  import * as utils from '@symbo.ls/utils'
8
8
  import * as domqlUtils from '@domql/utils'
9
9
 
10
10
  import * as uikit from '@symbo.ls/uikit'
11
- import { init } from '@symbo.ls/init'
12
- import { fetchStateAsync, fetchProject } from '@symbo.ls/fetch'
11
+ import { init, updateReset } from '@symbo.ls/init'
12
+ import { set } from '@symbo.ls/scratch'
13
13
 
14
14
  import { emotion as defaultEmotion, createEmotion } from '@symbo.ls/emotion'
15
15
  import { defaultDefine } from './define'
16
16
 
17
17
  import DYNAMIC_JSON from '@symbo.ls/init/dynamic.json'
18
+
18
19
  import { deepMerge, isObject } from '@domql/utils'
19
20
  import { initRouter } from './router'
21
+ import { fetchAsync, fetchSync } from './ferchOnCreate'
20
22
 
21
23
  const SYMBOLS_KEY = process.env.SYMBOLS_KEY
24
+ const smblsUtils = { init, set, updateReset }
22
25
 
23
26
  const defaultOptions = {
24
27
  editor: {
@@ -55,22 +58,16 @@ export const create = async (App, options = defaultOptions, RC_FILE) => {
55
58
  const key = options.key || SYMBOLS_KEY || (appIsKey ? App : '')
56
59
 
57
60
  if (appIsKey) App = {}
58
- if (key && options.editor) {
59
- try {
60
- if (!options.async) await fetchProject(key, options)
61
- } catch (e) {
62
- console.error(e)
63
- }
64
- }
61
+ await fetchSync(key, options)
65
62
 
66
63
  const initOptions = options.initOptions || {}
67
64
  const emotion = initOptions.emotion || defaultEmotion || createEmotion()
68
65
  if (!initOptions.emotion) initOptions.emotion = emotion
69
66
  const emotionDefine = options.registry || transformDOMQLEmotion(initOptions.emotion, options)
70
67
 
71
- const doc = options.parent || document
68
+ const doc = options.parent || options.document || document
72
69
 
73
- const designSystem = init(options.designSystem || {}, {
70
+ const scratchSystem = init(options.designSystem || {}, {
74
71
  key,
75
72
  emotion,
76
73
  verbose: options.verbose,
@@ -79,22 +76,31 @@ export const create = async (App, options = defaultOptions, RC_FILE) => {
79
76
  ...initOptions
80
77
  })
81
78
 
82
- if (options.router) initRouter(App, options.router)
79
+ initRouter(App, options.routerOptions)
80
+
81
+ const state = options.state || {}
82
+ const pages = options.pages || {}
83
+ const components = options.components ? { ...uikit, ...options.components } : uikit
84
+ const designSystem = scratchSystem || {}
85
+ const snippets = { ...utils, ...domqlUtils, ...smblsUtils, ...(options.snippets || {})}
86
+ const router = options.router || defaultRouter
87
+ const define = options.define || defaultDefine
83
88
 
84
89
  const domqlApp = DOM.create({
85
90
  extend: [App],
86
91
  routes: options.pages,
87
- state: options.state,
92
+ state,
88
93
  context: {
89
94
  key,
90
- components: options.components ? { ...uikit, ...options.components } : uikit,
91
- state: options.state || {},
92
- pages: options.pages || {},
93
- designSystem: designSystem || {},
94
- utils: { ...utils, ...domqlUtils },
95
- define: defaultDefine,
95
+ components,
96
+ state,
97
+ pages,
98
+ designSystem,
99
+ snippets,
100
+ utils: snippets,
101
+ define,
96
102
  registry: emotionDefine,
97
- router: options.router || router,
103
+ router,
98
104
  emotion,
99
105
  document: doc
100
106
  }
@@ -104,15 +110,7 @@ export const create = async (App, options = defaultOptions, RC_FILE) => {
104
110
  ...options.domqlOptions
105
111
  })
106
112
 
107
- if (key && options.editor) {
108
- try {
109
- if (options.editor.async) fetchStateAsync(key, options, (data) => {
110
- domqlApp.state.update(data)
111
- })
112
- } catch (e) {
113
- console.error(e)
114
- }
115
- }
113
+ fetchAsync(domqlApp)
116
114
 
117
115
  return domqlApp
118
116
  }
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@symbo.ls/create",
3
- "version": "2.10.162",
3
+ "version": "2.10.165",
4
4
  "license": "MIT",
5
- "gitHead": "bcb75a861d22f204893bc7f58a4432b1126f8e17",
5
+ "gitHead": "30fbc4dc26682e15d1d7eb2b6312bce6d9f07ec2",
6
6
  "source": "index.js",
7
7
  "main": "index.js",
8
8
  "dependencies": {
9
+ "@domql/emotion": "latest",
10
+ "@domql/router": "latest",
9
11
  "@domql/utils": "latest",
10
12
  "@symbo.ls/fetch": "latest",
11
13
  "@symbo.ls/init": "latest",
package/router.js CHANGED
@@ -18,10 +18,10 @@ export const initRouter = (root, options = DEFAULT_ROUTING_OPTIONS) => {
18
18
 
19
19
  if (options.initRouter) {
20
20
  if (root.on) {
21
- root.on.render = onRender
21
+ root.on.renderRouter = onRender
22
22
  } else {
23
23
  root.on = {
24
- render: onRender
24
+ renderRouter: onRender
25
25
  }
26
26
  }
27
27
  }