@uniweb/core 0.1.11 → 0.1.13

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/block.js +64 -47
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/core",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
@@ -27,6 +27,6 @@
27
27
  "node": ">=20.19"
28
28
  },
29
29
  "dependencies": {
30
- "@uniweb/semantic-parser": "1.0.8"
30
+ "@uniweb/semantic-parser": "1.0.12"
31
31
  }
32
32
  }
package/src/block.js CHANGED
@@ -26,9 +26,18 @@ export default class Block {
26
26
  this.rawContent = blockData.content || {}
27
27
  this.parsedContent = this.parseContent(blockData.content)
28
28
 
29
- const { main, items } = this.parsedContent
30
- this.main = main
31
- this.items = items
29
+ // Merge fetched data from prerender (if present)
30
+ // Prerender stores fetched data in blockData.parsedContent.data
31
+ if (blockData.parsedContent?.data) {
32
+ this.parsedContent.data = {
33
+ ...(this.parsedContent.data || {}),
34
+ ...blockData.parsedContent.data,
35
+ }
36
+ }
37
+
38
+ // Flat content structure - no more nested main/items
39
+ // parsedContent now has: title, pretitle, paragraphs, links, imgs, items, etc.
40
+ this.items = this.parsedContent.items || []
32
41
 
33
42
  // Block configuration
34
43
  const blockConfig = blockData.params || blockData.config || {}
@@ -45,6 +54,14 @@ export default class Block {
45
54
  // Input data
46
55
  this.input = blockData.input || null
47
56
 
57
+ // Fetch configuration (from section frontmatter)
58
+ // Supports local files (path) or remote URLs (url)
59
+ this.fetch = blockData.fetch || null
60
+
61
+ // Cascaded data from page/site level fetches
62
+ // Populated during render for components with inheritData
63
+ this.cascadedData = blockData.cascadedData || {}
64
+
48
65
  // State management (dynamic, can change at runtime)
49
66
  this.startState = null
50
67
  this.state = null
@@ -81,11 +98,10 @@ export default class Block {
81
98
  // Simple key-value content (PoC style) - pass through directly
82
99
  // This allows components to receive content like { title, subtitle, items }
83
100
  if (content && typeof content === 'object' && !Array.isArray(content)) {
101
+ // Mark as PoC format so runtime can detect and pass through
84
102
  return {
85
- main: { header: {}, body: {} },
86
- items: [],
87
- // Store raw content for direct access
88
- raw: content
103
+ _isPoc: true,
104
+ _pocContent: content
89
105
  }
90
106
  }
91
107
 
@@ -99,24 +115,15 @@ export default class Block {
99
115
  /**
100
116
  * Extract structured content from ProseMirror document
101
117
  * Uses @uniweb/semantic-parser for intelligent content extraction
118
+ * Returns flat content structure
102
119
  */
103
120
  extractFromProseMirror(doc) {
104
121
  try {
105
- // Parse with semantic-parser
106
- const { groups, sequence, byType } = parseSemanticContent(doc)
122
+ // Parse with semantic-parser - returns flat structure
123
+ const parsed = parseSemanticContent(doc)
107
124
 
108
- // Transform groups structure to match expected format
109
- const main = groups.main || { header: {}, body: {} }
110
- const items = groups.items || []
111
-
112
- return {
113
- main,
114
- items,
115
- // Include additional data for advanced use cases
116
- sequence,
117
- byType,
118
- metadata: groups.metadata
119
- }
125
+ // Parsed content is now flat: { title, pretitle, paragraphs, links, items, sequence, ... }
126
+ return parsed
120
127
  } catch (err) {
121
128
  console.warn('[Block] Semantic parser error, using fallback:', err.message)
122
129
  return this.extractFromProseMirrorFallback(doc)
@@ -125,29 +132,39 @@ export default class Block {
125
132
 
126
133
  /**
127
134
  * Fallback extraction when semantic-parser fails
135
+ * Returns flat content structure matching new parser output
128
136
  */
129
137
  extractFromProseMirrorFallback(doc) {
130
- const main = { header: {}, body: {} }
131
- const items = []
138
+ const content = {
139
+ title: '',
140
+ pretitle: '',
141
+ subtitle: '',
142
+ paragraphs: [],
143
+ links: [],
144
+ imgs: [],
145
+ lists: [],
146
+ icons: [],
147
+ items: [],
148
+ sequence: []
149
+ }
132
150
 
133
- if (!doc.content) return { main, items }
151
+ if (!doc.content) return content
134
152
 
135
153
  for (const node of doc.content) {
136
154
  if (node.type === 'heading') {
137
155
  const text = this.extractText(node)
138
156
  if (node.attrs?.level === 1) {
139
- main.header.title = text
157
+ content.title = text
140
158
  } else if (node.attrs?.level === 2) {
141
- main.header.subtitle = text
159
+ content.subtitle = text
142
160
  }
143
161
  } else if (node.type === 'paragraph') {
144
162
  const text = this.extractText(node)
145
- if (!main.body.paragraphs) main.body.paragraphs = []
146
- main.body.paragraphs.push(text)
163
+ content.paragraphs.push(text)
147
164
  }
148
165
  }
149
166
 
150
- return { main, items }
167
+ return content
151
168
  }
152
169
 
153
170
  /**
@@ -193,26 +210,25 @@ export default class Block {
193
210
 
194
211
  /**
195
212
  * Get structured block content for components
213
+ * Returns flat content structure
196
214
  */
197
215
  getBlockContent() {
198
- const mainHeader = this.main?.header || {}
199
- const mainBody = this.main?.body || {}
200
- const banner = this.main?.banner || null
216
+ const c = this.parsedContent || {}
201
217
 
202
218
  return {
203
- banner,
204
- pretitle: mainHeader.pretitle || '',
205
- title: mainHeader.title || '',
206
- subtitle: mainHeader.subtitle || '',
207
- description: mainHeader.description || '',
208
- paragraphs: mainBody.paragraphs || [],
209
- images: mainBody.imgs || mainBody.images || [],
210
- links: mainBody.links || [],
211
- icons: mainBody.icons || [],
212
- properties: mainBody.propertyBlocks?.[0] || {},
213
- videos: mainBody.videos || [],
214
- lists: mainBody.lists || [],
215
- buttons: mainBody.buttons || []
219
+ pretitle: c.pretitle || '',
220
+ title: c.title || '',
221
+ subtitle: c.subtitle || '',
222
+ description: c.subtitle2 || '',
223
+ paragraphs: c.paragraphs || [],
224
+ images: c.imgs || [],
225
+ links: c.links || [],
226
+ icons: c.icons || [],
227
+ properties: c.propertyBlocks?.[0] || c.properties || {},
228
+ videos: c.videos || [],
229
+ lists: c.lists || [],
230
+ buttons: c.buttons || [],
231
+ items: c.items || []
216
232
  }
217
233
  }
218
234
 
@@ -237,14 +253,15 @@ export default class Block {
237
253
  */
238
254
  getBlockLinks(options = {}) {
239
255
  const website = globalThis.uniweb?.activeWebsite
256
+ const c = this.parsedContent || {}
240
257
 
241
258
  if (options.nested) {
242
- const lists = this.main?.body?.lists || []
259
+ const lists = c.lists || []
243
260
  const links = lists[0]
244
261
  return Block.parseNestedLinks(links, website)
245
262
  }
246
263
 
247
- const links = this.main?.body?.links || []
264
+ const links = c.links || []
248
265
  return links.map((link) => ({
249
266
  route: website?.makeHref(link.href) || link.href,
250
267
  label: link.label