@uniweb/core 1.4.5 → 1.4.7

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": "1.4.5",
3
+ "version": "1.4.7",
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
@@ -13,6 +13,27 @@ import { normalizeTokenValue, isCssName, isCssValue } from '@uniweb/theming'
13
13
  import { sectionDomId } from './section-id.js'
14
14
  import { liftInsets } from './insets.js'
15
15
 
16
+ /**
17
+ * A video background's own fields, in its `video`: `video: <url>` is its `src`, and a `poster`,
18
+ * `sources`, `loop` or `muted` written beside it are the video's — the shorthand the reference
19
+ * documents. A video given only as `sources` takes the first one's as its `src`.
20
+ * ⛔ Until 2026-10-25 these passed through as written, while every renderer reads
21
+ * `background.video.src`: the documented `video: /videos/hero.mp4` beside a `poster:` drew nothing.
22
+ *
23
+ * @param {Object} raw - a background object whose mode is video
24
+ * @returns {Object}
25
+ */
26
+ function gatherVideoFields(raw) {
27
+ const { video, poster, sources, loop, muted, ...rest } = raw
28
+ const own = typeof video === 'string' ? { src: video } : { ...(video || {}) }
29
+ for (const [key, value] of Object.entries({ poster, sources, loop, muted })) {
30
+ if (value !== undefined && own[key] === undefined) own[key] = value
31
+ }
32
+ const first = !own.src && Array.isArray(own.sources) ? own.sources.find((s) => s?.src) : null
33
+ if (first) own.src = first.src
34
+ return { ...rest, video: own }
35
+ }
36
+
16
37
  export default class Block {
17
38
  constructor(blockData, id, page) {
18
39
  this.id = id
@@ -880,8 +901,8 @@ export default class Block {
880
901
  return { mode: 'color', color: normalizeTokenValue(raw) }
881
902
  }
882
903
 
883
- // Object with explicit mode — pass through
884
- if (raw.mode) return raw
904
+ // Object with explicit mode — pass through, a video's own fields gathered into it
905
+ if (raw.mode) return raw.mode === 'video' ? gatherVideoFields(raw) : raw
885
906
 
886
907
  // Normalize overlay shorthand: number → { enabled: true, type: 'dark', opacity }
887
908
  if (typeof raw.overlay === 'number') {
@@ -889,7 +910,7 @@ export default class Block {
889
910
  }
890
911
 
891
912
  // Infer mode from fields
892
- if (raw.video || raw.sources) return { mode: 'video', ...raw }
913
+ if (raw.video || raw.sources) return gatherVideoFields({ mode: 'video', ...raw })
893
914
  if (raw.image || raw.src) {
894
915
  // Support flat { src, position, size } shorthand
895
916
  if (raw.src) {
package/src/uniweb.js CHANGED
@@ -28,7 +28,7 @@ export default class Uniweb {
28
28
  * sites never pass this option.
29
29
  */
30
30
  constructor({ content = {}, foundation = null, extensions = [], defaultFetcher = null, transport = null, dev = false } = {}) {
31
- this.activeWebsite = new Website({ content, foundation, extensions, defaultFetcher, transport, dev })
31
+ this.activeWebsite = new Website({ content, foundation, extensions, defaultFetcher, transport, dev, uniweb: this })
32
32
 
33
33
  this.foundation = foundation
34
34
  this.foundationConfig = {}
package/src/website.js CHANGED
@@ -54,7 +54,7 @@ const SERVICE_RESOLVERS = {
54
54
  * swaps reassemble the dispatcher but preserve the DataStore and state so the
55
55
  * editor's live-edit path doesn't wipe either between keystrokes.
56
56
  *
57
- * new Website({ content, foundation?, extensions?, defaultFetcher?, dev? })
57
+ * new Website({ content, foundation?, extensions?, defaultFetcher?, dev?, uniweb? })
58
58
  */
59
59
  export default class Website {
60
60
  constructor({
@@ -64,6 +64,7 @@ export default class Website {
64
64
  defaultFetcher = null,
65
65
  transport = null,
66
66
  dev = false,
67
+ uniweb = null,
67
68
  } = {}) {
68
69
 
69
70
  // ─── Foundation / dispatcher state (not re-derived on rebuild) ───
@@ -74,6 +75,8 @@ export default class Website {
74
75
  // rebuild() reassembles the dispatcher with the same override in place.
75
76
  this._transport = transport
76
77
  this._dev = dev
78
+ // The Uniweb that made this Website, if one did — what `makeCurrent` points the global at.
79
+ this._uniweb = uniweb
77
80
 
78
81
  this.dataStore = new DataStore()
79
82
  this.fetcher = new FetcherDispatcher({
@@ -248,6 +251,37 @@ export default class Website {
248
251
  })
249
252
  }
250
253
 
254
+ /**
255
+ * Forget the answers this Website holds, and the parametric pages made from them.
256
+ *
257
+ * ⭐ For a caller that renders many pages or requests on one Website, so that each render
258
+ * starts from the answers its own page carries (`render(target, { fetchedData })` in
259
+ * `@uniweb/runtime/ssr`). ⛔ Emptying the store alone is not enough: a parametric page takes
260
+ * its title, description and not-found state from the store when it is first made, and is
261
+ * then kept by route (`_pageFor`), so it would go on showing what an earlier request found.
262
+ * The store is emptied in place, so every dispatcher built on it sees the same.
263
+ */
264
+ forgetData() {
265
+ this.dataStore.clear()
266
+ this._dynamicPageCache.clear()
267
+ }
268
+
269
+ /**
270
+ * Point `globalThis.uniweb` at the Uniweb that made this Website.
271
+ *
272
+ * ⭐ Code that reaches the site through the global reads THAT, not the Website it was handed:
273
+ * a block resolving its component (`Block#initComponent`, kept on the block), the props
274
+ * pipeline, this class's own foundation config, and kit in every foundation
275
+ * (`getUniweb().activeWebsite`). Every `createUniweb` points the global at the newest instance,
276
+ * so a caller holding several in one process (a host serving many sites, publishes or locales)
277
+ * must point it back before it uses another. The render door and the data step do
278
+ * (`@uniweb/runtime/ssr`). A Website built without a Uniweb has none to point at, and leaves
279
+ * the global as it is.
280
+ */
281
+ makeCurrent() {
282
+ if (this._uniweb) globalThis.uniweb = this._uniweb
283
+ }
284
+
251
285
  /**
252
286
  * Rebuild in place. Content-only rebuilds preserve the dispatcher and all
253
287
  * state (site and per-page). Passing `foundation` or `extensions` reassembles