@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.
- package/package.json +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.
|
|
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.
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
86
|
-
|
|
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
|
|
122
|
+
// Parse with semantic-parser - returns flat structure
|
|
123
|
+
const parsed = parseSemanticContent(doc)
|
|
107
124
|
|
|
108
|
-
//
|
|
109
|
-
|
|
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
|
|
131
|
-
|
|
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
|
|
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
|
-
|
|
157
|
+
content.title = text
|
|
140
158
|
} else if (node.attrs?.level === 2) {
|
|
141
|
-
|
|
159
|
+
content.subtitle = text
|
|
142
160
|
}
|
|
143
161
|
} else if (node.type === 'paragraph') {
|
|
144
162
|
const text = this.extractText(node)
|
|
145
|
-
|
|
146
|
-
main.body.paragraphs.push(text)
|
|
163
|
+
content.paragraphs.push(text)
|
|
147
164
|
}
|
|
148
165
|
}
|
|
149
166
|
|
|
150
|
-
return
|
|
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
|
|
199
|
-
const mainBody = this.main?.body || {}
|
|
200
|
-
const banner = this.main?.banner || null
|
|
216
|
+
const c = this.parsedContent || {}
|
|
201
217
|
|
|
202
218
|
return {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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 =
|
|
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 =
|
|
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
|