@uniweb/core 0.1.6 → 0.1.8

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.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
package/src/uniweb.js CHANGED
@@ -40,13 +40,8 @@ export default class Uniweb {
40
40
  return undefined
41
41
  }
42
42
 
43
- // Use foundation's getComponent interface
44
- if (typeof this.foundation.getComponent === 'function') {
45
- return this.foundation.getComponent(name)
46
- }
47
-
48
- // Fallback: direct component access
49
- return this.foundation[name]
43
+ // Look in components object first, then direct access (named export)
44
+ return this.foundation.components?.[name] || this.foundation[name]
50
45
  }
51
46
 
52
47
  /**
@@ -56,28 +51,14 @@ export default class Uniweb {
56
51
  listComponents() {
57
52
  if (!this.foundation) return []
58
53
 
59
- if (typeof this.foundation.listComponents === 'function') {
60
- return this.foundation.listComponents()
54
+ // Use components object if available
55
+ if (this.foundation.components) {
56
+ return Object.keys(this.foundation.components)
61
57
  }
62
58
 
63
59
  return []
64
60
  }
65
61
 
66
- /**
67
- * Get component schema
68
- * @param {string} name - Component name
69
- * @returns {Object|undefined}
70
- */
71
- getSchema(name) {
72
- if (!this.foundation) return undefined
73
-
74
- if (typeof this.foundation.getSchema === 'function') {
75
- return this.foundation.getSchema(name)
76
- }
77
-
78
- return undefined
79
- }
80
-
81
62
  /**
82
63
  * Set foundation configuration
83
64
  * @param {Object} config
@@ -85,23 +66,4 @@ export default class Uniweb {
85
66
  setFoundationConfig(config) {
86
67
  this.foundationConfig = config
87
68
  }
88
-
89
- // Legacy compatibility - maps to new method names
90
- getRemoteComponent(name) {
91
- return this.getComponent(name)
92
- }
93
-
94
- setRemoteComponents(components) {
95
- // Legacy: components was an object map
96
- // Convert to foundation-like interface
97
- this.foundation = {
98
- getComponent: (name) => components[name],
99
- listComponents: () => Object.keys(components),
100
- components
101
- }
102
- }
103
-
104
- setRemoteConfig(config) {
105
- this.setFoundationConfig(config)
106
- }
107
69
  }
package/src/website.js CHANGED
@@ -49,6 +49,9 @@ export default class Website {
49
49
  new Page(page, index, this, this.headerPage, this.footerPage, this.leftPage, this.rightPage)
50
50
  )
51
51
 
52
+ // Build parent-child relationships based on route structure
53
+ this.buildPageHierarchy()
54
+
52
55
  this.activePage =
53
56
  this.pages.find((page) => page.route === '/' || page.route === '/index') ||
54
57
  this.pages[0]
@@ -98,6 +101,53 @@ export default class Website {
98
101
  }))
99
102
  }
100
103
 
104
+ /**
105
+ * Build parent-child relationships between pages based on route structure
106
+ * E.g., /getting-started/installation is a child of /getting-started
107
+ * @private
108
+ */
109
+ buildPageHierarchy() {
110
+ // Sort pages by route depth (parents before children)
111
+ const sortedPages = [...this.pages].sort((a, b) => {
112
+ const depthA = (a.route.match(/\//g) || []).length
113
+ const depthB = (b.route.match(/\//g) || []).length
114
+ return depthA - depthB
115
+ })
116
+
117
+ // Build a map of route to page for quick lookup
118
+ const pageMap = new Map()
119
+ for (const page of sortedPages) {
120
+ pageMap.set(page.route, page)
121
+ }
122
+
123
+ // For each page, find its parent and add it as a child
124
+ for (const page of sortedPages) {
125
+ const route = page.route
126
+ if (route === '/' || route === '') continue
127
+
128
+ // Find parent route by removing the last segment
129
+ // /getting-started/installation -> /getting-started
130
+ const segments = route.split('/').filter(Boolean)
131
+ if (segments.length <= 1) continue // Root-level pages have no parent
132
+
133
+ // Build parent route
134
+ const parentRoute = '/' + segments.slice(0, -1).join('/')
135
+ const parent = pageMap.get(parentRoute)
136
+
137
+ if (parent) {
138
+ parent.children.push(page)
139
+ page.parent = parent
140
+ }
141
+ }
142
+
143
+ // Sort children by order
144
+ for (const page of this.pages) {
145
+ if (page.children.length > 0) {
146
+ page.children.sort((a, b) => (a.order || 0) - (b.order || 0))
147
+ }
148
+ }
149
+ }
150
+
101
151
  /**
102
152
  * Get page by route
103
153
  * @param {string} route
@@ -391,7 +441,7 @@ export default class Website {
391
441
  } = options
392
442
 
393
443
  // Filter pages based on navigation type and visibility
394
- let filteredPages = this.pages.filter(page => {
444
+ const isPageVisible = (page) => {
395
445
  // Always exclude special pages (header/footer are already separated)
396
446
  if (page.route.startsWith('/@')) return false
397
447
 
@@ -406,7 +456,15 @@ export default class Website {
406
456
  if (customFilter && !customFilter(page)) return false
407
457
 
408
458
  return true
409
- })
459
+ }
460
+
461
+ let filteredPages = this.pages.filter(isPageVisible)
462
+
463
+ // When nested, only include root-level pages at top level
464
+ // (children will be nested inside their parents)
465
+ if (nested) {
466
+ filteredPages = filteredPages.filter(page => !page.parent)
467
+ }
410
468
 
411
469
  // Apply custom sort or default to order
412
470
  if (customSort) {
@@ -424,7 +482,7 @@ export default class Website {
424
482
  order: page.order,
425
483
  hasContent: page.getBodyBlocks().length > 0,
426
484
  children: nested && page.hasChildren()
427
- ? page.children.map(buildPageInfo)
485
+ ? page.children.filter(isPageVisible).map(buildPageInfo)
428
486
  : []
429
487
  })
430
488