smbls 3.7.0 → 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.7.0",
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.7.0",
33
- "@symbo.ls/helmet": "^3.7.0",
34
- "@domql/report": "^3.7.0",
35
- "@domql/router": "^3.7.0",
36
- "@domql/utils": "^3.7.0",
37
- "@symbo.ls/cli": "^3.7.0",
38
- "@symbo.ls/default-config": "^3.7.0",
39
- "@symbo.ls/fetch": "^3.7.0",
40
- "@symbo.ls/scratch": "^3.7.0",
41
- "@symbo.ls/sync": "^3.7.0",
42
- "@symbo.ls/uikit": "^3.7.0",
43
- "@symbo.ls/smbls-utils": "^3.7.0",
44
- "attrs-in-props": "^3.7.0",
45
- "css-in-props": "^3.7.0",
46
- "domql": "^3.7.0"
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'