7onic 0.1.21 → 0.1.22
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/dist/index.js +22 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10405,6 +10405,22 @@ function flattenFragments(children: React.ReactNode): React.ReactNode[] {
|
|
|
10405
10405
|
)
|
|
10406
10406
|
}
|
|
10407
10407
|
|
|
10408
|
+
// Children passed from a Server Component arrive with lazy element types, so
|
|
10409
|
+
// \`node.type === BreadcrumbItem\` cannot tell them apart. When no child can be
|
|
10410
|
+
// identified, the list is read as the alternating item / separator order every
|
|
10411
|
+
// breadcrumb uses. Unidentified children next to identified separators (items
|
|
10412
|
+
// wrapped in the caller's own component) count as items.
|
|
10413
|
+
function classifyNodes(nodes: React.ReactNode[]): ('item' | 'separator')[] {
|
|
10414
|
+
const known = nodes.map((node) => {
|
|
10415
|
+
const type = React.isValidElement(node) ? node.type : null
|
|
10416
|
+
return type === BreadcrumbSeparator ? 'separator' : type === BreadcrumbItem ? 'item' : null
|
|
10417
|
+
})
|
|
10418
|
+
if (known.every((kind) => kind === null)) {
|
|
10419
|
+
return nodes.map((_, i) => (i % 2 === 0 ? 'item' : 'separator'))
|
|
10420
|
+
}
|
|
10421
|
+
return known.map((kind) => kind ?? 'item')
|
|
10422
|
+
}
|
|
10423
|
+
|
|
10408
10424
|
// Groups children into segments (the separator before an item + the item),
|
|
10409
10425
|
// then keeps the first \`before\` and last \`after\` segments around one ellipsis
|
|
10410
10426
|
// item. The user's own separators are reused, so custom separators survive.
|
|
@@ -10412,21 +10428,17 @@ function collapseItems(children: React.ReactNode, maxItems: number | undefined,
|
|
|
10412
10428
|
if (maxItems === undefined) return children
|
|
10413
10429
|
|
|
10414
10430
|
const nodes = flattenFragments(children)
|
|
10431
|
+
const kinds = classifyNodes(nodes)
|
|
10415
10432
|
const segments: { separator: React.ReactNode; nodes: React.ReactNode[] }[] = []
|
|
10416
10433
|
let pendingSeparator: React.ReactNode = null
|
|
10417
|
-
|
|
10418
|
-
|
|
10419
|
-
if (type === BreadcrumbSeparator) {
|
|
10434
|
+
nodes.forEach((node, i) => {
|
|
10435
|
+
if (kinds[i] === 'separator') {
|
|
10420
10436
|
pendingSeparator = node
|
|
10421
|
-
} else
|
|
10437
|
+
} else {
|
|
10422
10438
|
segments.push({ separator: pendingSeparator, nodes: [node] })
|
|
10423
10439
|
pendingSeparator = null
|
|
10424
|
-
} else if (segments.length > 0) {
|
|
10425
|
-
segments[segments.length - 1].nodes.push(node)
|
|
10426
|
-
} else {
|
|
10427
|
-
segments.push({ separator: null, nodes: [node] })
|
|
10428
10440
|
}
|
|
10429
|
-
}
|
|
10441
|
+
})
|
|
10430
10442
|
|
|
10431
10443
|
if (segments.length <= maxItems || before + after >= segments.length) return children
|
|
10432
10444
|
|
|
@@ -21897,7 +21909,7 @@ function showCompanionHints(names) {
|
|
|
21897
21909
|
|
|
21898
21910
|
// cli/src/index.ts
|
|
21899
21911
|
var import_picocolors4 = __toESM(require_picocolors());
|
|
21900
|
-
var VERSION = "0.1.
|
|
21912
|
+
var VERSION = "0.1.22";
|
|
21901
21913
|
var HELP = `
|
|
21902
21914
|
${import_picocolors4.default.bold("7onic")} \u2014 Add 7onic design system components to your project
|
|
21903
21915
|
|