smbls 0.15.33 → 0.15.34

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "UI Library built on Scratch and DOMQL",
4
4
  "private": false,
5
5
  "author": "symbo.ls",
6
- "version": "0.15.33",
6
+ "version": "0.15.34",
7
7
  "repository": "https://github.com/symbo-ls/smbls",
8
8
  "main": "src/index.js",
9
9
  "files": [
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  import { merge, isArray } from '@domql/utils'
4
+ import { getSystemTheme } from './Theme'
4
5
 
5
6
  const keySetters = {
6
7
  '@': (key, props, result, element, isSubtree) => applyMediaProps(key, props, isSubtree ? result : result.media, element),
@@ -16,7 +17,11 @@ const execClass = (key, props, result, element) => {
16
17
 
17
18
  if (typeof classnameExec !== 'function') return
18
19
 
19
- let classExec = classnameExec({ props, context: element.context })
20
+ let classExec = classnameExec({
21
+ props,
22
+ context: element.context,
23
+ state: element.state
24
+ })
20
25
  if (isArray(classExec)) {
21
26
  classExec = classExec.reduce((a, c) => merge(a, c), {})
22
27
  }
@@ -46,9 +51,9 @@ const convertPropsToClass = (props, result, element) => {
46
51
 
47
52
  const applyMediaProps = (key, props, result, element) => {
48
53
  const { context } = element
49
- console.log(context, element)
50
54
  if (!context.SYSTEM || !context.SYSTEM.MEDIA) return
51
- const { globalTheme, MEDIA } = context.SYSTEM
55
+ const globalTheme = getSystemTheme(element)
56
+ const { MEDIA } = context.SYSTEM
52
57
  const mediaName = MEDIA[key.slice(1)]
53
58
  const generatedClass = convertPropsToClass(props, result, element)
54
59
 
@@ -113,7 +118,8 @@ const beforeClassAssign = (element, s) => {
113
118
  }
114
119
 
115
120
  export const initUpdate = element => {
116
- const { props, context, class: className } = element
121
+ const { props, class: className } = element
122
+ const globalTheme = getSystemTheme(element)
117
123
 
118
124
  const parentProps = element.parent.props
119
125
  if (parentProps && parentProps.spacingRatio && parentProps.inheritSpacingRatio) {
@@ -126,8 +132,6 @@ export const initUpdate = element => {
126
132
  })
127
133
  }
128
134
 
129
- const { globalTheme } = context.SYSTEM
130
-
131
135
  if (globalTheme) {
132
136
  const CLASS_NAMES = {
133
137
  media: {},
@@ -36,34 +36,60 @@ const transformShadow = shadows => shadows.split('|').map(shadow => {
36
36
  }).join(' ')
37
37
  }).join(',')
38
38
 
39
- const transformBackgroundImage = (backgroundImage, ctx) => ({
39
+ const transformBackgroundImage = (backgroundImage, ctx, globalTheme) => ({
40
40
  backgroundImage: backgroundImage.split(', ').map(v => {
41
41
  if (v.includes('url') || v.includes('gradient')) return v
42
42
  else if (ctx.SYSTEM.GRADIENT[backgroundImage]) {
43
- return getMediaColor(backgroundImage, 'backgroundImage')
43
+ return getMediaColor(backgroundImage, 'backgroundImage', globalTheme)
44
44
  }
45
45
  return `url(${v})`
46
46
  }).join(' ')
47
47
  })
48
48
 
49
+ export const getSystemTheme = (element, state) => {
50
+ const { context } = element
51
+ const rootState = element.__root ? element.__root.state : element.state
52
+ return rootState.globalTheme || context.SYSTEM.globalTheme
53
+ }
54
+
49
55
  export const Theme = {
50
56
  class: {
51
57
  depth: ({ props }) => depth[props.depth],
52
58
 
53
- theme: ({ props, context }) => {
59
+ theme: (element) => {
60
+ const { props } = element
61
+ const globalTheme = getSystemTheme(element)
54
62
  if (!props.theme) return
55
- return getMediaTheme(props.theme, props.themeModifier || context.SYSTEM.globalTheme)
63
+ return getMediaTheme(props.theme, props.themeModifier || globalTheme)
64
+ },
65
+
66
+ color: (element) => {
67
+ const { props } = element
68
+ const globalTheme = getSystemTheme(element)
69
+ if (!props.color) return
70
+ return getMediaColor(props.color, 'color', globalTheme)
56
71
  },
57
72
 
58
- color: ({ props, context }) => props.color && (
59
- getMediaColor(props.color, 'color', context.SYSTEM.globalTheme)
60
- ),
61
- background: ({ props, context }) => {
73
+ background: (element) => {
74
+ const { props } = element
75
+ const globalTheme = getSystemTheme(element)
62
76
  if (!props.background) return
63
- return getMediaColor(props.background, 'background', context.SYSTEM.globalTheme)
77
+ return getMediaColor(props.background, 'background', globalTheme)
78
+ },
79
+
80
+ backgroundColor: (element) => {
81
+ const { props } = element
82
+ const globalTheme = getSystemTheme(element)
83
+ if (!props.backgroundColor) return
84
+ return getMediaColor(props.backgroundColor, 'backgroundColor', globalTheme)
85
+ },
86
+
87
+ backgroundImage: (element) => {
88
+ const { props, context } = element
89
+ const globalTheme = getSystemTheme(element)
90
+ if (!props.backgroundImage) return
91
+ return transformBackgroundImage(props.backgroundImage, context, globalTheme)
64
92
  },
65
- backgroundColor: ({ props, context }) => (props.backgroundColor) && getMediaColor(props.backgroundColor, 'backgroundColor', context.SYSTEM.globalTheme),
66
- backgroundImage: ({ props, context }) => (props.backgroundImage) && transformBackgroundImage(props.backgroundImage, context),
67
93
  backgroundSize: ({ props }) => props.backgroundSize ? ({ backgroundSize: props.backgroundSize }) : null,
68
94
  backgroundPosition: ({ props }) => props.backgroundPosition ? ({ backgroundPosition: props.backgroundPosition }) : null,
69
95