@uniweb/core 0.1.11 → 0.1.12
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 +47 -47
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
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.9"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/block.js
CHANGED
|
@@ -26,9 +26,9 @@ export default class Block {
|
|
|
26
26
|
this.rawContent = blockData.content || {}
|
|
27
27
|
this.parsedContent = this.parseContent(blockData.content)
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.items = items
|
|
29
|
+
// Flat content structure - no more nested main/items
|
|
30
|
+
// parsedContent now has: title, pretitle, paragraphs, links, imgs, items, etc.
|
|
31
|
+
this.items = this.parsedContent.items || []
|
|
32
32
|
|
|
33
33
|
// Block configuration
|
|
34
34
|
const blockConfig = blockData.params || blockData.config || {}
|
|
@@ -81,11 +81,10 @@ export default class Block {
|
|
|
81
81
|
// Simple key-value content (PoC style) - pass through directly
|
|
82
82
|
// This allows components to receive content like { title, subtitle, items }
|
|
83
83
|
if (content && typeof content === 'object' && !Array.isArray(content)) {
|
|
84
|
+
// Mark as PoC format so runtime can detect and pass through
|
|
84
85
|
return {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// Store raw content for direct access
|
|
88
|
-
raw: content
|
|
86
|
+
_isPoc: true,
|
|
87
|
+
_pocContent: content
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
90
|
|
|
@@ -99,24 +98,15 @@ export default class Block {
|
|
|
99
98
|
/**
|
|
100
99
|
* Extract structured content from ProseMirror document
|
|
101
100
|
* Uses @uniweb/semantic-parser for intelligent content extraction
|
|
101
|
+
* Returns flat content structure
|
|
102
102
|
*/
|
|
103
103
|
extractFromProseMirror(doc) {
|
|
104
104
|
try {
|
|
105
|
-
// Parse with semantic-parser
|
|
106
|
-
const
|
|
105
|
+
// Parse with semantic-parser - returns flat structure
|
|
106
|
+
const parsed = parseSemanticContent(doc)
|
|
107
107
|
|
|
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
|
-
}
|
|
108
|
+
// Parsed content is now flat: { title, pretitle, paragraphs, links, items, sequence, ... }
|
|
109
|
+
return parsed
|
|
120
110
|
} catch (err) {
|
|
121
111
|
console.warn('[Block] Semantic parser error, using fallback:', err.message)
|
|
122
112
|
return this.extractFromProseMirrorFallback(doc)
|
|
@@ -125,29 +115,39 @@ export default class Block {
|
|
|
125
115
|
|
|
126
116
|
/**
|
|
127
117
|
* Fallback extraction when semantic-parser fails
|
|
118
|
+
* Returns flat content structure matching new parser output
|
|
128
119
|
*/
|
|
129
120
|
extractFromProseMirrorFallback(doc) {
|
|
130
|
-
const
|
|
131
|
-
|
|
121
|
+
const content = {
|
|
122
|
+
title: '',
|
|
123
|
+
pretitle: '',
|
|
124
|
+
subtitle: '',
|
|
125
|
+
paragraphs: [],
|
|
126
|
+
links: [],
|
|
127
|
+
imgs: [],
|
|
128
|
+
lists: [],
|
|
129
|
+
icons: [],
|
|
130
|
+
items: [],
|
|
131
|
+
sequence: []
|
|
132
|
+
}
|
|
132
133
|
|
|
133
|
-
if (!doc.content) return
|
|
134
|
+
if (!doc.content) return content
|
|
134
135
|
|
|
135
136
|
for (const node of doc.content) {
|
|
136
137
|
if (node.type === 'heading') {
|
|
137
138
|
const text = this.extractText(node)
|
|
138
139
|
if (node.attrs?.level === 1) {
|
|
139
|
-
|
|
140
|
+
content.title = text
|
|
140
141
|
} else if (node.attrs?.level === 2) {
|
|
141
|
-
|
|
142
|
+
content.subtitle = text
|
|
142
143
|
}
|
|
143
144
|
} else if (node.type === 'paragraph') {
|
|
144
145
|
const text = this.extractText(node)
|
|
145
|
-
|
|
146
|
-
main.body.paragraphs.push(text)
|
|
146
|
+
content.paragraphs.push(text)
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
return
|
|
150
|
+
return content
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
/**
|
|
@@ -193,26 +193,25 @@ export default class Block {
|
|
|
193
193
|
|
|
194
194
|
/**
|
|
195
195
|
* Get structured block content for components
|
|
196
|
+
* Returns flat content structure
|
|
196
197
|
*/
|
|
197
198
|
getBlockContent() {
|
|
198
|
-
const
|
|
199
|
-
const mainBody = this.main?.body || {}
|
|
200
|
-
const banner = this.main?.banner || null
|
|
199
|
+
const c = this.parsedContent || {}
|
|
201
200
|
|
|
202
201
|
return {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
202
|
+
pretitle: c.pretitle || '',
|
|
203
|
+
title: c.title || '',
|
|
204
|
+
subtitle: c.subtitle || '',
|
|
205
|
+
description: c.subtitle2 || '',
|
|
206
|
+
paragraphs: c.paragraphs || [],
|
|
207
|
+
images: c.imgs || [],
|
|
208
|
+
links: c.links || [],
|
|
209
|
+
icons: c.icons || [],
|
|
210
|
+
properties: c.propertyBlocks?.[0] || c.properties || {},
|
|
211
|
+
videos: c.videos || [],
|
|
212
|
+
lists: c.lists || [],
|
|
213
|
+
buttons: c.buttons || [],
|
|
214
|
+
items: c.items || []
|
|
216
215
|
}
|
|
217
216
|
}
|
|
218
217
|
|
|
@@ -237,14 +236,15 @@ export default class Block {
|
|
|
237
236
|
*/
|
|
238
237
|
getBlockLinks(options = {}) {
|
|
239
238
|
const website = globalThis.uniweb?.activeWebsite
|
|
239
|
+
const c = this.parsedContent || {}
|
|
240
240
|
|
|
241
241
|
if (options.nested) {
|
|
242
|
-
const lists =
|
|
242
|
+
const lists = c.lists || []
|
|
243
243
|
const links = lists[0]
|
|
244
244
|
return Block.parseNestedLinks(links, website)
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
const links =
|
|
247
|
+
const links = c.links || []
|
|
248
248
|
return links.map((link) => ({
|
|
249
249
|
route: website?.makeHref(link.href) || link.href,
|
|
250
250
|
label: link.label
|