@uniweb/core 0.4.0 → 0.4.2

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": "@uniweb/core",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
package/src/block.js CHANGED
@@ -432,6 +432,11 @@ export default class Block {
432
432
  // Object with explicit mode — pass through
433
433
  if (raw.mode) return raw
434
434
 
435
+ // Normalize overlay shorthand: number → { enabled: true, type: 'dark', opacity }
436
+ if (typeof raw.overlay === 'number') {
437
+ raw = { ...raw, overlay: { enabled: true, type: 'dark', opacity: raw.overlay } }
438
+ }
439
+
435
440
  // Infer mode from fields
436
441
  if (raw.video || raw.sources) return { mode: 'video', ...raw }
437
442
  if (raw.image || raw.src) {
@@ -440,6 +445,11 @@ export default class Block {
440
445
  const { src, position, size, lazy, ...rest } = raw
441
446
  return { mode: 'image', image: { src, position, size, lazy }, ...rest }
442
447
  }
448
+ // Support string shorthand: { image: "url" } → { image: { src: "url" } }
449
+ if (typeof raw.image === 'string') {
450
+ const { image, ...rest } = raw
451
+ return { mode: 'image', image: { src: image }, ...rest }
452
+ }
443
453
  return { mode: 'image', ...raw }
444
454
  }
445
455
  if (raw.gradient) return { mode: 'gradient', ...raw }
@@ -40,6 +40,27 @@ export default class EntityStore {
40
40
  return null
41
41
  }
42
42
 
43
+ /**
44
+ * Return a localized copy of a fetch config for collection data.
45
+ * For non-default locales, prepends /{locale} to /data/ paths so the
46
+ * client fetches the translated JSON (e.g. /fr/data/articles.json).
47
+ *
48
+ * @param {Object} cfg - Fetch config
49
+ * @param {import('./website.js').default|null} website
50
+ * @returns {Object} Localized config (or original if no change needed)
51
+ */
52
+ _localizeConfig(cfg, website) {
53
+ if (!cfg.path || !website) return cfg
54
+
55
+ const locale = website.getActiveLocale()
56
+ const defaultLocale = website.getDefaultLocale()
57
+ if (!locale || locale === defaultLocale) return cfg
58
+
59
+ if (!cfg.path.startsWith('/data/')) return cfg
60
+
61
+ return { ...cfg, path: `/${locale}${cfg.path}` }
62
+ }
63
+
43
64
  /**
44
65
  * Walk the hierarchy to find fetch configs for requested schemas.
45
66
  * Order: block.fetch → page.fetch → parent.fetch → site config.fetch
@@ -77,6 +98,8 @@ export default class EntityStore {
77
98
  sources.push(siteFetch)
78
99
  }
79
100
 
101
+ const website = block.website
102
+
80
103
  for (const source of sources) {
81
104
  // Normalize: single config or array of configs
82
105
  const configList = Array.isArray(source) ? source : [source]
@@ -86,7 +109,7 @@ export default class EntityStore {
86
109
  if (configs.has(cfg.schema)) continue // first match wins
87
110
 
88
111
  if (collectAll || requested.includes(cfg.schema)) {
89
- configs.set(cfg.schema, cfg)
112
+ configs.set(cfg.schema, this._localizeConfig(cfg, website))
90
113
  }
91
114
  }
92
115
  }