@uniweb/core 0.32.2 → 0.34.0
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 +3 -3
- package/src/block.js +136 -62
- package/src/fetch-config.js +4 -1
- package/src/insets.js +2 -3
- package/src/page.js +16 -0
- package/src/uniweb.js +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"vitest": "^4.1.7"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@uniweb/
|
|
52
|
-
"@uniweb/
|
|
51
|
+
"@uniweb/theming": "^0.1.16",
|
|
52
|
+
"@uniweb/semantic-parser": "^1.4.1"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"test": "vitest run"
|
package/src/block.js
CHANGED
|
@@ -34,10 +34,11 @@ export default class Block {
|
|
|
34
34
|
// at build time is deliberate: what the author wrote is the canonical STORED
|
|
35
35
|
// shape, so the content that syncs and round-trips keeps carrying it.
|
|
36
36
|
// `blockData.content` is left untouched — the lift produces a new tree and only
|
|
37
|
-
// this Block's view of it changes.
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
// this Block's view of it changes. ⛔ A stored `insets[]` — what the build extracted
|
|
38
|
+
// before 2026-09-27 — is no longer read: no store serves one since the site-content
|
|
39
|
+
// Model dropped the field (2026-09-28), and a site pushed again carries its insets in
|
|
40
|
+
// its content.
|
|
41
|
+
const lifted = liftInsets(blockData.content)
|
|
41
42
|
this.rawContent = lifted.content || {}
|
|
42
43
|
this.parsedContent = this.parseContent(lifted.content)
|
|
43
44
|
|
|
@@ -68,74 +69,79 @@ export default class Block {
|
|
|
68
69
|
this.items = this.parsedContent.items || []
|
|
69
70
|
|
|
70
71
|
// Block configuration
|
|
72
|
+
// ⛔ No `block.preset`: a section's `preset:` was stored and never read, and neither the build
|
|
73
|
+
// nor a store keeps one any more (2026-09-28).
|
|
71
74
|
const blockConfig = blockData.params || blockData.config || {}
|
|
72
|
-
this.preset = blockData.preset
|
|
73
75
|
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
+
// ⭐ THE SECTION'S OWN SETTINGS — the names framework reserves in its params
|
|
77
|
+
// (`@uniweb/schemas/section`): `theme`, `background`, `grid`, `vars`, `fetch`. Framework applies
|
|
78
|
+
// each — the runtime paints the background and the color context around the component,
|
|
79
|
+
// the page stylesheet applies the section's theme and its component's variables, kit's
|
|
80
|
+
// `ChildGrid` lays out the child sections — so each is lifted onto the block, normalized
|
|
81
|
+
// once for every renderer, and a component NEVER receives one as a param [Diego,
|
|
82
|
+
// 2026-09-28]. It reads them from the block, or through kit. ⛔ Until then a component
|
|
83
|
+
// also received `theme` (the mode), `background` and `vars` as params, and nothing read
|
|
84
|
+
// them there. `standardOptions` and `properties` are the older editor envelopes.
|
|
85
|
+
const own = blockConfig.properties || blockConfig
|
|
86
|
+
const setting = (name) => (blockConfig[name] !== undefined ? blockConfig[name] : own[name])
|
|
87
|
+
const rawTheme = setting('theme')
|
|
88
|
+
const rawBg = setting('background')
|
|
89
|
+
const gridParam = setting('grid')
|
|
90
|
+
const varsParam = setting('vars')
|
|
91
|
+
const fetchParam = setting('fetch')
|
|
92
|
+
const standardOptions = blockConfig.standardOptions
|
|
93
|
+
const {
|
|
94
|
+
theme: _theme, background: _background, grid: _grid, vars: _vars, fetch: _fetch,
|
|
95
|
+
standardOptions: _standardOptions, properties: _properties,
|
|
96
|
+
...componentParams
|
|
97
|
+
} = own
|
|
98
|
+
this.properties = componentParams
|
|
99
|
+
|
|
100
|
+
// The section's theme: `theme.yml`'s own keys scoped to the section — `colors`,
|
|
101
|
+
// `contexts`, `vars` — plus `mode`, the color context it pins. `theme: dark` is the
|
|
102
|
+
// shorthand for `{ mode: dark }`, and a token written beside `mode` applies to the section
|
|
103
|
+
// in any context (`normalizeSectionTheme`). The page stylesheet applies the overrides
|
|
104
|
+
// (`buildSectionOverrides`, @uniweb/theming).
|
|
76
105
|
//
|
|
77
106
|
// themeName values:
|
|
78
|
-
// '' (empty) = Auto — section
|
|
107
|
+
// '' (empty) = Auto — the section follows the site's light/dark scheme
|
|
79
108
|
// 'light' = Pinned to light context
|
|
80
109
|
// 'medium' = Pinned to dim context
|
|
81
110
|
// 'dark' = Pinned to dark context
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
this.properties = { ...this.properties, theme: this.themeName }
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// `grid` rides in the section's params, as every key the author writes does — so it
|
|
109
|
-
// travels and round-trips with no field of its own — but the NAME is framework's:
|
|
110
|
-
// it is lifted to `block.grid` below and a component never receives it as a param.
|
|
111
|
-
let gridParam = null
|
|
112
|
-
if (Object.hasOwn(this.properties, 'grid')) {
|
|
113
|
-
const { grid, ...rest } = this.properties
|
|
114
|
-
gridParam = grid
|
|
115
|
-
this.properties = rest
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Extract background from params into standardOptions
|
|
119
|
-
// Content authors set background in section frontmatter; the runtime
|
|
120
|
-
// reads it from standardOptions to render the Background component.
|
|
121
|
-
const rawBg = blockConfig.background
|
|
122
|
-
if (rawBg && !this.standardOptions.background) {
|
|
123
|
-
this.standardOptions = {
|
|
124
|
-
...this.standardOptions,
|
|
125
|
-
background: Block.normalizeBackground(rawBg, this.parseOptions())
|
|
126
|
-
}
|
|
127
|
-
}
|
|
111
|
+
const theme = Block.normalizeSectionTheme(rawTheme)
|
|
112
|
+
this.themeName = theme.mode
|
|
113
|
+
this.themeOverrides = theme.overrides
|
|
114
|
+
// The tokens in effect whatever the scheme (`normalizeSectionTheme`): the renderers apply
|
|
115
|
+
// them inline on the section, and a neighbour reads them through `getBlockInfo()`.
|
|
116
|
+
this.contextOverrides = theme.effectiveTokens
|
|
117
|
+
|
|
118
|
+
// ⚠️ The older editor envelope: `colors` (a section palette, and tokens per context) and
|
|
119
|
+
// `foundationStyles`, read by the page stylesheet until an editor writes the section's
|
|
120
|
+
// `theme` instead (uwx-format.md § A page section's fields). Nothing else reads it.
|
|
121
|
+
this.standardOptions = standardOptions || {}
|
|
122
|
+
|
|
123
|
+
// What the runtime draws behind the section — normalized once (its shape, and store-held
|
|
124
|
+
// assets resolved to URLs) for every renderer, and for a component that draws it itself
|
|
125
|
+
// (`background: 'self'` in `meta.js`, with kit's `SectionBackground`). An editor's preview
|
|
126
|
+
// may still send it inside the older envelope, which wins while it does.
|
|
127
|
+
this.background =
|
|
128
|
+
this.standardOptions.background ||
|
|
129
|
+
(rawBg ? Block.normalizeBackground(rawBg, this.parseOptions()) : null)
|
|
130
|
+
|
|
131
|
+
// Values for the CSS variables the component declares in `meta.js` `vars:` — merged into
|
|
132
|
+
// `componentVars` when the component is known (`initComponent`).
|
|
133
|
+
this.sectionVars = varsParam && typeof varsParam === 'object' ? varsParam : null
|
|
128
134
|
|
|
129
135
|
// Child blocks (subsections)
|
|
130
136
|
this.childBlocks = blockData.subsections
|
|
131
137
|
? blockData.subsections.map((block, i) => new Block(block, `${id}_${i}`, this.page))
|
|
132
138
|
: []
|
|
133
139
|
|
|
134
|
-
// Insets — inline @-referenced components positioned in content flow:
|
|
135
|
-
//
|
|
136
|
-
//
|
|
140
|
+
// Insets — inline @-referenced components positioned in content flow: the leaves
|
|
141
|
+
// lifted from the content, in document order. Each receives its `[…]` text as
|
|
142
|
+
// `content.title` and its `{…}` as params.
|
|
137
143
|
this.insets = []
|
|
138
|
-
const insetData =
|
|
144
|
+
const insetData = lifted.leaves
|
|
139
145
|
for (let i = 0; i < insetData.length; i++) {
|
|
140
146
|
const ref = insetData[i]
|
|
141
147
|
const title = ref.title || ''
|
|
@@ -177,9 +183,10 @@ export default class Block {
|
|
|
177
183
|
)
|
|
178
184
|
}
|
|
179
185
|
|
|
180
|
-
//
|
|
181
|
-
//
|
|
182
|
-
|
|
186
|
+
// The section's own data — what its `query:` / `fetch:` declares. A stored section carries it
|
|
187
|
+
// in `params.fetch` [Diego, 2026-09-28], which wins when present; the `fetch` beside the params
|
|
188
|
+
// is framework's own build output, and a store's older field.
|
|
189
|
+
this.fetch = fetchParam || blockData.fetch || null
|
|
183
190
|
|
|
184
191
|
// The layout the author chose for this section's child sections — the reserved
|
|
185
192
|
// `grid:` section key [Diego, 2026-09-27]: `3` (equal columns) or `'40/60'`
|
|
@@ -511,7 +518,7 @@ export default class Block {
|
|
|
511
518
|
// Merge component-level CSS vars: meta.js defaults + frontmatter overrides
|
|
512
519
|
// Source: meta.js vars field (defaults), section frontmatter vars: key (overrides)
|
|
513
520
|
if (meta.vars) {
|
|
514
|
-
this.componentVars = Block.mergeComponentVars(meta.vars, this.
|
|
521
|
+
this.componentVars = Block.mergeComponentVars(meta.vars, this.sectionVars)
|
|
515
522
|
}
|
|
516
523
|
|
|
517
524
|
return this.Component
|
|
@@ -725,6 +732,73 @@ export default class Block {
|
|
|
725
732
|
* asset-URL pattern, used to resolve a store-held background.
|
|
726
733
|
* @returns {Object} Normalized background config with mode
|
|
727
734
|
*/
|
|
735
|
+
/**
|
|
736
|
+
* A section's theme, from its `theme:` — `theme.yml`'s own keys scoped to the section,
|
|
737
|
+
* plus `mode`, the color context it pins:
|
|
738
|
+
*
|
|
739
|
+
* theme: dark the shorthand for { mode: dark }
|
|
740
|
+
* theme:
|
|
741
|
+
* mode: dark light | medium | dark; left out, the section follows the site
|
|
742
|
+
* colors: { primary: '#0a6' } like theme.yml `colors` — a palette, shades generated
|
|
743
|
+
* contexts: { dark: { … } } like theme.yml `contexts` — tokens per color context
|
|
744
|
+
* vars: { header-height: 5rem } like theme.yml `vars` — the foundation's variables
|
|
745
|
+
* heading: primary-900 a token beside `mode` — the section's in any context
|
|
746
|
+
*
|
|
747
|
+
* Token values resolve bare palette references (`neutral-900` → `var(--neutral-900)`).
|
|
748
|
+
*
|
|
749
|
+
* @param {string|Object|null|undefined} raw
|
|
750
|
+
* @returns {{ mode: string, overrides: Object|null, effectiveTokens: Object|null }}
|
|
751
|
+
* `overrides` is `{ colors, contexts, vars, tokens }` (each null when unset) or null when
|
|
752
|
+
* the section overrides nothing; `effectiveTokens` are the tokens in effect whatever the
|
|
753
|
+
* scheme — a pinned section's context's own over those beside `mode`; for a section that
|
|
754
|
+
* follows the site, those beside `mode` it sets in no context — or null. The renderers
|
|
755
|
+
* apply them inline, so they reach the page even where a host places no page stylesheet.
|
|
756
|
+
*/
|
|
757
|
+
static normalizeSectionTheme(raw) {
|
|
758
|
+
if (raw === undefined || raw === null || raw === '') return { mode: '', overrides: null, effectiveTokens: null }
|
|
759
|
+
if (typeof raw !== 'object' || Array.isArray(raw)) return { mode: String(raw), overrides: null, effectiveTokens: null }
|
|
760
|
+
|
|
761
|
+
const { mode, colors, contexts, vars, ...tokens } = raw
|
|
762
|
+
const tokenMap = (map) => {
|
|
763
|
+
if (!map || typeof map !== 'object' || Array.isArray(map)) return null
|
|
764
|
+
const out = {}
|
|
765
|
+
for (const [name, value] of Object.entries(map)) {
|
|
766
|
+
if (value === undefined || value === null || value === '') continue
|
|
767
|
+
out[name] = normalizeTokenValue(value)
|
|
768
|
+
}
|
|
769
|
+
return Object.keys(out).length > 0 ? out : null
|
|
770
|
+
}
|
|
771
|
+
const nonEmpty = (map) =>
|
|
772
|
+
map && typeof map === 'object' && !Array.isArray(map) && Object.keys(map).length > 0 ? { ...map } : null
|
|
773
|
+
|
|
774
|
+
const byContext = {}
|
|
775
|
+
if (contexts && typeof contexts === 'object') {
|
|
776
|
+
for (const [context, map] of Object.entries(contexts)) {
|
|
777
|
+
const normalized = tokenMap(map)
|
|
778
|
+
if (normalized) byContext[context] = normalized
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
const overrides = {
|
|
782
|
+
colors: nonEmpty(colors),
|
|
783
|
+
contexts: Object.keys(byContext).length > 0 ? byContext : null,
|
|
784
|
+
vars: nonEmpty(vars),
|
|
785
|
+
tokens: tokenMap(tokens),
|
|
786
|
+
}
|
|
787
|
+
const pinned = typeof mode === 'string' ? mode : ''
|
|
788
|
+
// A context's own token beats one written beside `mode`, as in the page stylesheet. A
|
|
789
|
+
// section that follows the site has no context of its own, so a token it also sets per
|
|
790
|
+
// context is left to the stylesheet's per-scheme rules rather than applied here.
|
|
791
|
+
const perContext = new Set(Object.values(byContext).flatMap((map) => Object.keys(map)))
|
|
792
|
+
const effective = pinned
|
|
793
|
+
? { ...(overrides.tokens || {}), ...(byContext[pinned] || {}) }
|
|
794
|
+
: Object.fromEntries(Object.entries(overrides.tokens || {}).filter(([name]) => !perContext.has(name)))
|
|
795
|
+
return {
|
|
796
|
+
mode: pinned,
|
|
797
|
+
overrides: Object.values(overrides).some(Boolean) ? overrides : null,
|
|
798
|
+
effectiveTokens: Object.keys(effective).length > 0 ? effective : null,
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
728
802
|
static normalizeBackground(raw, options) {
|
|
729
803
|
return Block.resolveBackgroundMedia(Block.normalizeBackgroundShape(raw), options)
|
|
730
804
|
}
|
package/src/fetch-config.js
CHANGED
|
@@ -818,7 +818,10 @@ export function sectionFetches(sections) {
|
|
|
818
818
|
const walk = (list) => {
|
|
819
819
|
for (const s of list || []) {
|
|
820
820
|
if (!s || typeof s !== 'object') continue
|
|
821
|
-
|
|
821
|
+
// A stored section carries its fetch in `params.fetch` (2026-09-28); framework's own build
|
|
822
|
+
// output beside the params — the same order as the Block's.
|
|
823
|
+
const own = s.params?.fetch || s.fetch
|
|
824
|
+
if (own) out.push(own)
|
|
822
825
|
if (Array.isArray(s.subsections)) walk(s.subsections)
|
|
823
826
|
}
|
|
824
827
|
}
|
package/src/insets.js
CHANGED
|
@@ -26,9 +26,8 @@
|
|
|
26
26
|
* never went through a build — a record body, a free-form translation — resolves its
|
|
27
27
|
* insets the same way. ⛔ *Until 2026-09-27 only containers were lifted here; leaf
|
|
28
28
|
* insets were extracted by the site build into the section's `insets[]`, so any
|
|
29
|
-
* document the build did not extract rendered none of them.*
|
|
30
|
-
*
|
|
31
|
-
* it so their refIds cannot collide.
|
|
29
|
+
* document the build did not extract rendered none of them.* `leafStart` offsets the
|
|
30
|
+
* leaves' refIds for a caller that numbers other insets first.
|
|
32
31
|
*
|
|
33
32
|
* PURE with respect to the input: nodes on the path to an inset are cloned; everything
|
|
34
33
|
* else is passed through by reference, so a document with no insets costs one walk and
|
package/src/page.js
CHANGED
|
@@ -326,6 +326,22 @@ export default class Page {
|
|
|
326
326
|
return blocks
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
+
/**
|
|
330
|
+
* Every section block the page renders at its top level: its body, and each layout area it
|
|
331
|
+
* shows — header, footer, and any other area its layout declares, a sidebar included. A
|
|
332
|
+
* block's child sections are its own (`block.childBlocks`). What the page stylesheet covers
|
|
333
|
+
* (`buildSectionOverrides`, @uniweb/theming), where `getPageBlocks()` is the header · body ·
|
|
334
|
+
* footer order that neighbours count in.
|
|
335
|
+
* @returns {Block[]}
|
|
336
|
+
*/
|
|
337
|
+
getAllBlocks() {
|
|
338
|
+
const blocks = [...this.bodyBlocks]
|
|
339
|
+
for (const areaBlocks of Object.values(this.getLayoutAreas())) {
|
|
340
|
+
if (Array.isArray(areaBlocks)) blocks.push(...areaBlocks)
|
|
341
|
+
}
|
|
342
|
+
return blocks
|
|
343
|
+
}
|
|
344
|
+
|
|
329
345
|
/**
|
|
330
346
|
* Get body blocks
|
|
331
347
|
* @returns {Block[]}
|
package/src/uniweb.js
CHANGED
|
@@ -53,6 +53,10 @@ export default class Uniweb {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
this.childBlockRenderer = null
|
|
56
|
+
// The runtime's section-background renderer — the same one it draws behind every section —
|
|
57
|
+
// for kit's `SectionBackground`, which a component that paints its own background uses
|
|
58
|
+
// (`background: 'self'`). Filled by each boot path, like `childBlockRenderer`.
|
|
59
|
+
this.backgroundRenderer = null
|
|
56
60
|
this.routingComponents = {}
|
|
57
61
|
this.language = 'en'
|
|
58
62
|
|