@symbo.ls/create 2.10.152 → 2.10.161

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.
Files changed (3) hide show
  1. package/index.js +11 -4
  2. package/package.json +2 -2
  3. package/router.js +36 -0
package/index.js CHANGED
@@ -16,6 +16,7 @@ import { defaultDefine } from './define'
16
16
 
17
17
  import DYNAMIC_JSON from '@symbo.ls/init/dynamic.json'
18
18
  import { deepMerge, isObject } from '@domql/utils'
19
+ import { initRouter } from './router'
19
20
 
20
21
  const SYMBOLS_KEY = process.env.SYMBOLS_KEY
21
22
 
@@ -25,7 +26,7 @@ const defaultOptions = {
25
26
  },
26
27
  state: {},
27
28
  pages: {},
28
- system: {
29
+ designSystem: {
29
30
  useReset: true,
30
31
  useVariable: true,
31
32
  useIconSprite: true,
@@ -36,6 +37,10 @@ const defaultOptions = {
36
37
  initOptions: {
37
38
  emotion: defaultEmotion
38
39
  },
40
+ router: {
41
+ initRouter: true,
42
+ injectRouterInLinkComponent: true
43
+ },
39
44
  define: defaultDefine
40
45
  }
41
46
 
@@ -65,15 +70,17 @@ export const create = async (App, options = defaultOptions, RC_FILE) => {
65
70
 
66
71
  const doc = options.parent || document
67
72
 
68
- const designSystem = init(options.system || {}, {
73
+ const designSystem = init(options.designSystem || {}, {
69
74
  key,
70
75
  emotion,
71
76
  verbose: options.verbose,
72
77
  document: doc,
73
- ...defaultOptions.system,
78
+ ...defaultOptions.designSystem,
74
79
  ...initOptions
75
80
  })
76
81
 
82
+ if (options.router) initRouter(App, options.router)
83
+
77
84
  const domqlApp = DOM.create({
78
85
  extend: [App],
79
86
  routes: options.pages,
@@ -83,7 +90,7 @@ export const create = async (App, options = defaultOptions, RC_FILE) => {
83
90
  components: options.components ? { ...uikit, ...options.components } : uikit,
84
91
  state: options.state || {},
85
92
  pages: options.pages || {},
86
- system: designSystem || {},
93
+ designSystem: designSystem || {},
87
94
  utils: { ...utils, ...domqlUtils },
88
95
  define: defaultDefine,
89
96
  registry: emotionDefine,
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@symbo.ls/create",
3
- "version": "2.10.152",
3
+ "version": "2.10.161",
4
4
  "license": "MIT",
5
- "gitHead": "2d292d25c681dbed822c339cdbc3d10aa97cfb50",
5
+ "gitHead": "f9ad1b5f9b5230f9219b31df4b6b4b451d5dfa8f",
6
6
  "source": "index.js",
7
7
  "main": "index.js",
8
8
  "dependencies": {
package/router.js ADDED
@@ -0,0 +1,36 @@
1
+ 'use strict'
2
+
3
+ import { router } from '@domql/router'
4
+ import { Link, RouterLink } from 'smbls'
5
+ import { deepMerge } from '@domql/utils'
6
+
7
+ const DEFAULT_ROUTING_OPTIONS = {
8
+ initRouter: true,
9
+ injectRouterInLinkComponent: true
10
+ }
11
+
12
+ export const initRouter = (root, options = DEFAULT_ROUTING_OPTIONS) => {
13
+ if (options === true) options = DEFAULT_ROUTING_OPTIONS
14
+
15
+ const onRender = (el, s) => {
16
+ router(el, window.location.pathname, {}, { updateState: false })
17
+ }
18
+
19
+ if (options.initRouter) {
20
+ if (root.on) {
21
+ root.on.render = onRender
22
+ } else {
23
+ root.on = {
24
+ render: onRender
25
+ }
26
+ }
27
+ }
28
+
29
+ if (options.injectRouterInLinkComponent) {
30
+ injectRouterInLinkComponent(options)
31
+ }
32
+ }
33
+
34
+ export const injectRouterInLinkComponent = () => {
35
+ return deepMerge(Link, RouterLink)
36
+ }