@uniweb/core 0.32.0 → 0.32.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.32.0",
3
+ "version": "0.32.2",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
@@ -15,6 +15,7 @@
15
15
  "./layout-name": "./src/layout-name.js",
16
16
  "./page-data": "./src/page-data.js",
17
17
  "./icon-corpus": "./src/icon-corpus.js",
18
+ "./insets": "./src/insets.js",
18
19
  "./locale-config": "./src/locale-config.js",
19
20
  "./route-match": "./src/route-match.js",
20
21
  "./section-id": "./src/section-id.js",
@@ -47,8 +48,8 @@
47
48
  "vitest": "^4.1.7"
48
49
  },
49
50
  "dependencies": {
50
- "@uniweb/theming": "^0.1.15",
51
- "@uniweb/semantic-parser": "^1.4.1"
51
+ "@uniweb/semantic-parser": "^1.4.1",
52
+ "@uniweb/theming": "^0.1.15"
52
53
  },
53
54
  "scripts": {
54
55
  "test": "vitest run"
package/src/block.js CHANGED
@@ -11,70 +11,7 @@ import {
11
11
  } from '@uniweb/semantic-parser'
12
12
  import { normalizeTokenValue } from '@uniweb/theming'
13
13
  import { sectionDomId } from './section-id.js'
14
-
15
- /**
16
- * Lift container fences out of a content document.
17
- *
18
- * A ` ```@Component{params} ` fence parses to an `inset_block` node carrying a
19
- * body of real block content. This rewrites each one to the `inset_placeholder`
20
- * a leaf inset leaves behind, so a container resolves through exactly the same
21
- * path: `getInset(refId)` → a Block → the foundation's component. Kit and the
22
- * SSR renderer already handle placeholders, so neither needs to know containers
23
- * exist.
24
- *
25
- * PURE with respect to the input. `blockData.content` is shared with the sync /
26
- * pull machinery, which must keep seeing `inset_block` — that is the canonical
27
- * stored shape. Nodes on the path to a container are cloned; everything else is
28
- * passed through by reference, so a document with no containers costs one array
29
- * walk and allocates nothing.
30
- *
31
- * Containers are NOT recursed into here. A container's body becomes its child
32
- * Block's content, and that Block's constructor lifts its own containers — so
33
- * nesting resolves one level at a time, each at the level that owns it.
34
- *
35
- * @param {Object} content - ProseMirror document (never mutated)
36
- * @returns {{ content: Object, refs: Array<{refId, type, params, content}> }}
37
- */
38
- function liftContainers(content) {
39
- if (!content || !Array.isArray(content.content)) return { content, refs: [] }
40
-
41
- const refs = []
42
-
43
- const visit = (nodes) => {
44
- let changed = false
45
- const out = nodes.map((node) => {
46
- if (!node) return node
47
-
48
- if (node.type === 'inset_block') {
49
- const { component, ...params } = node.attrs || {}
50
- const refId = `container_${refs.length}`
51
- refs.push({
52
- refId,
53
- type: component,
54
- params,
55
- content: { type: 'doc', content: node.content || [] },
56
- })
57
- changed = true
58
- return { type: 'inset_placeholder', attrs: { refId, embedKind: 'block' } }
59
- }
60
-
61
- if (Array.isArray(node.content)) {
62
- const inner = visit(node.content)
63
- if (inner !== node.content) {
64
- changed = true
65
- return { ...node, content: inner }
66
- }
67
- }
68
- return node
69
- })
70
- return changed ? out : nodes
71
- }
72
-
73
- const next = visit(content.content)
74
- return next === content.content
75
- ? { content, refs }
76
- : { content: { ...content, content: next }, refs }
77
- }
14
+ import { liftInsets } from './insets.js'
78
15
 
79
16
  export default class Block {
80
17
  constructor(blockData, id, page) {
@@ -91,14 +28,16 @@ export default class Block {
91
28
  // 2. Pre-parsed content with main/items structure
92
29
  // For now, store raw and parse on demand
93
30
  //
94
- // Container fences (```@Component around a body) arrive as `inset_block`
95
- // nodes and are lifted out HERE, into the same placeholder + refId shape
96
- // the build gives leaf insets. Doing it at render-graph construction
97
- // rather than at build time is deliberate: `inset_block` is the canonical
98
- // STORED shape, so the content that syncs and round-trips must keep
99
- // carrying it. `blockData.content` is left untouched — the lift produces a
100
- // new tree and only this Block's view of it changes.
101
- const lifted = liftContainers(blockData.content)
31
+ // Insets arrive as the author wrote them — `inset_ref` for a leaf, `inset_block`
32
+ // for a ```@Component fence — and are lifted out HERE into placeholders plus
33
+ // inset Blocks (`liftInsets`). Doing it at render-graph construction rather than
34
+ // at build time is deliberate: what the author wrote is the canonical STORED
35
+ // shape, so the content that syncs and round-trips keeps carrying it.
36
+ // `blockData.content` is left untouched — the lift produces a new tree and only
37
+ // this Block's view of it changes. Leaves are numbered after a stored `insets[]`
38
+ // (content from before the lift moved here), so the two cannot share a refId.
39
+ const storedInsets = Array.isArray(blockData.insets) ? blockData.insets : []
40
+ const lifted = liftInsets(blockData.content, storedInsets.length)
102
41
  this.rawContent = lifted.content || {}
103
42
  this.parsedContent = this.parseContent(lifted.content)
104
43
 
@@ -166,6 +105,16 @@ export default class Block {
166
105
  this.properties = { ...this.properties, theme: this.themeName }
167
106
  }
168
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
+
169
118
  // Extract background from params into standardOptions
170
119
  // Content authors set background in section frontmatter; the runtime
171
120
  // reads it from standardOptions to render the Background component.
@@ -182,26 +131,26 @@ export default class Block {
182
131
  ? blockData.subsections.map((block, i) => new Block(block, `${id}_${i}`, this.page))
183
132
  : []
184
133
 
185
- // Insets — inline @-referenced components positioned in content flow
134
+ // Insets — inline @-referenced components positioned in content flow: a stored
135
+ // `insets[]` first, then the leaves lifted from the content, in document order.
136
+ // Each receives its `[…]` text as `content.title` and its `{…}` as params.
186
137
  this.insets = []
187
- const insetData = blockData.insets
188
- if (insetData?.length > 0) {
189
- for (let i = 0; i < insetData.length; i++) {
190
- const ref = insetData[i]
191
- const title = ref.title || ''
192
- const child = new Block(
193
- {
194
- type: ref.type,
195
- params: ref.params || {},
196
- content: { title },
197
- stableId: ref.refId,
198
- refId: ref.refId,
199
- },
200
- `${id}_inset_${i}`,
201
- this.page
202
- )
203
- this.insets.push(child)
204
- }
138
+ const insetData = [...storedInsets, ...lifted.leaves]
139
+ for (let i = 0; i < insetData.length; i++) {
140
+ const ref = insetData[i]
141
+ const title = ref.title || ''
142
+ const child = new Block(
143
+ {
144
+ type: ref.type,
145
+ params: ref.params || {},
146
+ content: { title },
147
+ stableId: ref.refId,
148
+ refId: ref.refId,
149
+ },
150
+ `${id}_inset_${i}`,
151
+ this.page
152
+ )
153
+ this.insets.push(child)
205
154
  }
206
155
 
207
156
  // Containers, appended AFTER the leaf insets so `block.insets[0]` keeps
@@ -210,9 +159,9 @@ export default class Block {
210
159
  // content, so the foundation's component receives a fully parsed
211
160
  // `content` — title, paragraphs, items, sequence — exactly as a section
212
161
  // does. Nested containers resolve for free: the child Block runs this
213
- // same constructor over its own body.
214
- for (let i = 0; i < lifted.refs.length; i++) {
215
- const ref = lifted.refs[i]
162
+ // same constructor over its own body, leaf insets included.
163
+ for (let i = 0; i < lifted.containers.length; i++) {
164
+ const ref = lifted.containers[i]
216
165
  this.insets.push(
217
166
  new Block(
218
167
  {
@@ -232,6 +181,17 @@ export default class Block {
232
181
  // Supports local files (path) or remote URLs (url)
233
182
  this.fetch = blockData.fetch || null
234
183
 
184
+ // The layout the author chose for this section's child sections — the reserved
185
+ // `grid:` section key [Diego, 2026-09-27]: `3` (equal columns) or `'40/60'`
186
+ // (relative widths). Carried as written; kit's `ChildGrid` lays the children out
187
+ // from it (`@uniweb/schemas/grid`). A section key, never a param: a component
188
+ // declares the layouts it offers in `meta.js` `children.grid`, and does not see
189
+ // `grid` among its params (above).
190
+ // ⭐ It is read from the params, where it is stored and synced — no field of its
191
+ // own, so no store has to declare one. `blockData.grid` is `@uniweb/build@0.67.0`'s
192
+ // spelling, which carried it beside the params for a few hours on 2026-09-27.
193
+ this.grid = gridParam ?? blockData.grid ?? null
194
+
235
195
  // Data loading state — set by BlockRenderer when a runtime fetch is in progress
236
196
  // Components check this to show loading UI (spinners, skeletons)
237
197
  this.dataLoading = false
package/src/insets.js ADDED
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Insets — lifted out of a content document at render-graph construction.
3
+ *
4
+ * A leaf module so a tool can show exactly what a component receives without building
5
+ * a Block: `uniweb inspect` imports it. `Block`'s constructor is the one runtime caller.
6
+ */
7
+
8
+ /**
9
+ * Lift the insets out of a content document — both forms, as the author wrote them.
10
+ *
11
+ * - A LEAF inset — `![alt](@Component){params}`, `[text](@Component)`, and the
12
+ * `[@key]` / `[#id]` shorthands — parses to an `inset_ref` node. It becomes an
13
+ * `inset_placeholder` in place, inline where it was inline, and a leaf ref:
14
+ * the component, its params, and the `[…]` text as the inset's title.
15
+ * - A CONTAINER — a ` ```@Component{params} ` fence — parses to an `inset_block`
16
+ * node carrying a body of real block content. It becomes a placeholder too, and
17
+ * its body becomes the child Block's content.
18
+ *
19
+ * Both then resolve through one path: `getInset(refId)` → a Block → the
20
+ * foundation's component. Kit and the SSR renderer handle placeholders, so neither
21
+ * needs to know which form a placeholder came from.
22
+ *
23
+ * ⭐ Doing it HERE, at render-graph construction, is the point: what the author wrote
24
+ * is the stored shape. `blockData.content` is shared with the sync / pull machinery
25
+ * and an editor, which keep seeing `inset_ref` and `inset_block`, and a document that
26
+ * never went through a build — a record body, a free-form translation — resolves its
27
+ * insets the same way. ⛔ *Until 2026-09-27 only containers were lifted here; leaf
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.* A stored `insets[]` is
30
+ * still read (the constructor below), and `leafStart` numbers the lifted leaves after
31
+ * it so their refIds cannot collide.
32
+ *
33
+ * PURE with respect to the input: nodes on the path to an inset are cloned; everything
34
+ * else is passed through by reference, so a document with no insets costs one walk and
35
+ * allocates nothing.
36
+ *
37
+ * Containers are NOT recursed into here — neither for containers nor for leaves. A
38
+ * container's body becomes its child Block's content, and that Block's constructor
39
+ * lifts its own — so nesting resolves one level at a time, each at the level that owns
40
+ * it.
41
+ *
42
+ * @param {Object} content - ProseMirror document (never mutated)
43
+ * @param {number} [leafStart=0] - the first leaf refId number (`inset_<leafStart>`)
44
+ * @returns {{
45
+ * content: Object,
46
+ * leaves: Array<{refId, type, params, title, embedKind}>,
47
+ * containers: Array<{refId, type, params, content}>,
48
+ * }}
49
+ */
50
+ export function liftInsets(content, leafStart = 0) {
51
+ if (!content || !Array.isArray(content.content)) return { content, leaves: [], containers: [] }
52
+
53
+ const leaves = []
54
+ const containers = []
55
+
56
+ const visit = (nodes) => {
57
+ let changed = false
58
+ const out = nodes.map((node) => {
59
+ if (!node) return node
60
+
61
+ if (node.type === 'inset_ref') {
62
+ const { component, alt, embedKind, ...params } = node.attrs || {}
63
+ const refId = `inset_${leafStart + leaves.length}`
64
+ const kind = embedKind || 'visual'
65
+ leaves.push({ refId, type: component, params, title: alt || null, embedKind: kind })
66
+ changed = true
67
+ return { type: 'inset_placeholder', attrs: { refId, embedKind: kind } }
68
+ }
69
+
70
+ if (node.type === 'inset_block') {
71
+ const { component, ...params } = node.attrs || {}
72
+ const refId = `container_${containers.length}`
73
+ containers.push({
74
+ refId,
75
+ type: component,
76
+ params,
77
+ content: { type: 'doc', content: node.content || [] },
78
+ })
79
+ changed = true
80
+ return { type: 'inset_placeholder', attrs: { refId, embedKind: 'block' } }
81
+ }
82
+
83
+ if (Array.isArray(node.content)) {
84
+ const inner = visit(node.content)
85
+ if (inner !== node.content) {
86
+ changed = true
87
+ return { ...node, content: inner }
88
+ }
89
+ }
90
+ return node
91
+ })
92
+ return changed ? out : nodes
93
+ }
94
+
95
+ const next = visit(content.content)
96
+ return next === content.content
97
+ ? { content, leaves, containers }
98
+ : { content: { ...content, content: next }, leaves, containers }
99
+ }