smbls 3.6.8 → 3.7.3

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smbls",
3
- "version": "3.6.8",
3
+ "version": "3.7.3",
4
4
  "license": "CC-BY-NC-4.0",
5
5
  "repository": "https://github.com/symbo-ls/smbls",
6
6
  "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
@@ -29,21 +29,22 @@
29
29
  "src"
30
30
  ],
31
31
  "dependencies": {
32
- "@symbo.ls/emotion": "^3.6.8",
33
- "@symbo.ls/helmet": "^3.6.8",
34
- "@domql/report": "^3.6.8",
35
- "@domql/router": "^3.6.8",
36
- "@domql/utils": "^3.6.8",
37
- "@symbo.ls/cli": "^3.6.8",
38
- "@symbo.ls/default-config": "^3.6.8",
39
- "@symbo.ls/fetch": "^3.6.8",
40
- "@symbo.ls/scratch": "^3.6.8",
41
- "@symbo.ls/sync": "^3.6.8",
42
- "@symbo.ls/uikit": "^3.6.8",
43
- "@symbo.ls/smbls-utils": "^3.6.8",
44
- "attrs-in-props": "^3.6.8",
45
- "css-in-props": "^3.6.8",
46
- "domql": "^3.6.8"
32
+ "@symbo.ls/emotion": "^3.7.3",
33
+ "@symbo.ls/helmet": "^3.7.3",
34
+ "@domql/report": "^3.7.3",
35
+ "@domql/router": "^3.7.3",
36
+ "@domql/utils": "^3.7.3",
37
+ "@symbo.ls/cli": "^3.7.3",
38
+ "@symbo.ls/default-config": "^3.7.3",
39
+ "@symbo.ls/fetch": "^3.7.3",
40
+ "@symbo.ls/polyglot": "^3.7.3",
41
+ "@symbo.ls/scratch": "^3.7.3",
42
+ "@symbo.ls/sync": "^3.7.3",
43
+ "@symbo.ls/uikit": "^3.7.3",
44
+ "@symbo.ls/smbls-utils": "^3.7.3",
45
+ "attrs-in-props": "^3.7.3",
46
+ "css-in-props": "^3.7.3",
47
+ "domql": "^3.7.3"
47
48
  },
48
49
  "publishConfig": {
49
50
  "access": "public"
@@ -28,6 +28,11 @@ import {
28
28
  PACKAGE_MANAGER_TO_CDN
29
29
  } from './prepare.js'
30
30
 
31
+ import { polyglotPlugin } from '@symbo.ls/polyglot'
32
+ import { polyglotFunctions } from '@symbo.ls/polyglot/functions'
33
+ import { helmetPlugin } from '@symbo.ls/helmet'
34
+ import { fetchPlugin } from '@symbo.ls/fetch'
35
+
31
36
  export const prepareContext = async (app, context = {}) => {
32
37
  const key = (context.key = context.key || (isString(app) ? app : 'smblsapp'))
33
38
  context.define = context.define || defaultDefine
@@ -58,6 +63,26 @@ export const prepareContext = async (app, context = {}) => {
58
63
  context.defaultExtends = [uikit.Box]
59
64
  context.snippets = context.snippets || {}
60
65
  context.functions = context.functions || {}
66
+ context.plugins = context.plugins || []
67
+
68
+ // Auto-register plugins based on context config
69
+ const hasPlugin = (name) => context.plugins.some(p => p.name === name)
70
+
71
+ if (context.polyglot && !hasPlugin('polyglot')) {
72
+ context.plugins.push(polyglotPlugin)
73
+ for (const k in polyglotFunctions) {
74
+ if (!(k in context.functions)) context.functions[k] = polyglotFunctions[k]
75
+ }
76
+ }
77
+
78
+ if (!hasPlugin('helmet')) {
79
+ context.plugins.push(helmetPlugin)
80
+ }
81
+
82
+ if (context.fetch && !hasPlugin('fetch')) {
83
+ context.plugins.push(fetchPlugin)
84
+ }
85
+
61
86
  return context
62
87
  }
63
88
 
package/src/define.js CHANGED
@@ -3,35 +3,62 @@
3
3
  import { resolveMetadata, applyMetadata } from '@symbo.ls/helmet'
4
4
  import { executeFetch } from '@symbo.ls/fetch'
5
5
 
6
- export const defaultDefine = {
7
- routes: param => param,
6
+ const fetchHandler = (param, el, state, context) => {
7
+ if (!param) return
8
+ executeFetch(param, el, state, context)
9
+ }
8
10
 
9
- metadata: (param, el, state) => {
10
- if (!param) return
11
- const doc = el.context?.document || (typeof document !== 'undefined' && document)
12
- if (!doc) return
13
- const resolved = resolveMetadata(param, el, state)
14
- applyMetadata(resolved, doc)
15
- },
11
+ const metadataHandler = (param, el, state) => {
12
+ if (!param) return
13
+ const doc = el.context?.document || (typeof document !== 'undefined' && document)
14
+ if (!doc) return
15
+ const resolved = resolveMetadata(param, el, state)
16
+ applyMetadata(resolved, doc)
17
+ }
16
18
 
17
- fetch: (param, el, state, context) => {
18
- if (!param) return
19
- executeFetch(param, el, state, context)
20
- },
19
+ const routerHandler = async (param, el) => {
20
+ if (!param) return
21
21
 
22
- $router: async (param, el) => {
23
- if (!param) return
22
+ const obj = { tag: 'fragment', ...param }
24
23
 
25
- const obj = { tag: 'fragment', ...param }
24
+ const set = async () => {
25
+ await el.set(obj, { preventDefineUpdate: '$router' })
26
+ }
26
27
 
27
- const set = async () => {
28
- await el.set(obj, { preventDefineUpdate: '$router' })
29
- }
28
+ if (el.props && el.props.lazyLoad) {
29
+ window.requestAnimationFrame(set)
30
+ } else await set()
30
31
 
31
- if (el.props && el.props.lazyLoad) {
32
- window.requestAnimationFrame(set)
33
- } else await set()
32
+ return obj
33
+ }
34
34
 
35
- return obj
36
- }
35
+ export const defaultDefine = {
36
+ routes: param => param,
37
+ metadata: metadataHandler,
38
+ fetch: fetchHandler,
39
+ $router: routerHandler
40
+ }
41
+
42
+ /**
43
+ * Create a custom define object with optional features.
44
+ *
45
+ * @param {Object} opts
46
+ * @param {boolean} [opts.fetch=true] - Include fetch handler
47
+ * @param {boolean} [opts.metadata=true] - Include metadata/helmet handler
48
+ * @param {boolean} [opts.router=true] - Include router handler
49
+ * @returns {Object} define handlers
50
+ *
51
+ * @example
52
+ * // Disable fetch:
53
+ * context.define = createDefine({ fetch: false })
54
+ *
55
+ * // Only router:
56
+ * context.define = createDefine({ fetch: false, metadata: false })
57
+ */
58
+ export const createDefine = (opts = {}) => {
59
+ const define = { routes: param => param }
60
+ if (opts.metadata !== false) define.metadata = metadataHandler
61
+ if (opts.fetch !== false) define.fetch = fetchHandler
62
+ if (opts.router !== false) define.$router = routerHandler
63
+ return define
37
64
  }
package/src/index.js CHANGED
@@ -103,3 +103,8 @@ export default create
103
103
 
104
104
  export * from './init.js'
105
105
  export { DEFAULT_CONTEXT, DESIGN_SYSTEM_OPTIONS, ROUTER_OPTIONS } from './options.js'
106
+ export { defaultDefine, createDefine } from './define.js'
107
+
108
+ // Polyglot i18n plugin
109
+ export { polyglotPlugin, translate, setLang, getActiveLang, getLanguages, loadTranslations, upsertTranslation, initPolyglot, getLocalStateLang } from '@symbo.ls/polyglot'
110
+ export { polyglotFunctions } from '@symbo.ls/polyglot/functions'
package/src/init.js CHANGED
@@ -53,15 +53,15 @@ export const init = (config, options = SET_OPTIONS) => {
53
53
  { newConfig: options.newConfig }
54
54
  )
55
55
 
56
- const FontFace = getFontFaceString(conf.font || conf.FONT, conf.files)
56
+ const FontFace = getFontFaceString(conf.font, conf.files)
57
57
 
58
58
  const useReset = conf.useReset
59
59
  const useVariable = conf.useVariable
60
60
  const useFontImport = conf.useFontImport
61
61
  const useSvgSprite = conf.useSvgSprite
62
- const hasSvgs = config.svg || config.SVG
62
+ const hasSvgs = config.svg
63
63
  const useIconSprite = conf.useIconSprite
64
- const hasIcons = config.icons || config.ICONS
64
+ const hasIcons = config.icons
65
65
 
66
66
  if (useFontImport) emotion.injectGlobal(FontFace)
67
67
  if (useVariable) {
@@ -81,10 +81,10 @@ export const init = (config, options = SET_OPTIONS) => {
81
81
  emotion.injectGlobal(themeStyles)
82
82
  }
83
83
  }
84
- if (useReset) emotion.injectGlobal(conf.reset || conf.RESET)
84
+ if (useReset) emotion.injectGlobal(conf.reset)
85
85
 
86
86
  // Register all ANIMATION entries as global @keyframes
87
- const animations = conf.animation || conf.ANIMATION
87
+ const animations = conf.animation
88
88
  if (animations) {
89
89
  const keyframesCSS = {}
90
90
  for (const name in animations) {
@@ -94,10 +94,10 @@ export const init = (config, options = SET_OPTIONS) => {
94
94
  }
95
95
 
96
96
  if (hasSvgs || useSvgSprite)
97
- appendSVGSprite(conf.svg || conf.SVG, { document: options.document })
97
+ appendSVGSprite(conf.svg, { document: options.document })
98
98
 
99
99
  if (hasIcons || useIconSprite)
100
- appendSvgIconsSprite(conf.icons || conf.ICONS, { document: options.document })
100
+ appendSvgIconsSprite(conf.icons, { document: options.document })
101
101
 
102
102
  return conf
103
103
  }
@@ -126,7 +126,7 @@ export const reinit = (config, options = UPDATE_OPTIONS) => {
126
126
  }
127
127
  emotion.injectGlobal(themeStyles)
128
128
  }
129
- emotion.injectGlobal(conf.RESET)
129
+ emotion.injectGlobal(conf.reset)
130
130
  }
131
131
  return conf
132
132
  }