mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-23 06:25:41 -05:00
fix: layout group priority
This commit is contained in:
parent
442c2aa1fe
commit
e9293bb4bf
@ -215,10 +215,10 @@ plugins:
|
|||||||
- source: github:quartz-community/spacer
|
- source: github:quartz-community/spacer
|
||||||
enabled: true
|
enabled: true
|
||||||
options: {}
|
options: {}
|
||||||
order: 95
|
order: 25
|
||||||
layout:
|
layout:
|
||||||
position: left
|
position: left
|
||||||
priority: 95
|
priority: 25
|
||||||
display: mobile-only
|
display: mobile-only
|
||||||
- source: github:quartz-community/bases-page
|
- source: github:quartz-community/bases-page
|
||||||
enabled: true
|
enabled: true
|
||||||
@ -244,6 +244,7 @@ plugins:
|
|||||||
layout:
|
layout:
|
||||||
groups:
|
groups:
|
||||||
toolbar:
|
toolbar:
|
||||||
|
priority: 15
|
||||||
direction: row
|
direction: row
|
||||||
gap: 0.5rem
|
gap: 0.5rem
|
||||||
byPageType:
|
byPageType:
|
||||||
|
|||||||
@ -215,10 +215,10 @@ plugins:
|
|||||||
- source: github:quartz-community/spacer
|
- source: github:quartz-community/spacer
|
||||||
enabled: true
|
enabled: true
|
||||||
options: {}
|
options: {}
|
||||||
order: 95
|
order: 25
|
||||||
layout:
|
layout:
|
||||||
position: left
|
position: left
|
||||||
priority: 95
|
priority: 25
|
||||||
display: mobile-only
|
display: mobile-only
|
||||||
- source: github:quartz-community/bases-page
|
- source: github:quartz-community/bases-page
|
||||||
enabled: true
|
enabled: true
|
||||||
@ -244,6 +244,7 @@ plugins:
|
|||||||
layout:
|
layout:
|
||||||
groups:
|
groups:
|
||||||
toolbar:
|
toolbar:
|
||||||
|
priority: 15
|
||||||
direction: row
|
direction: row
|
||||||
gap: 0.5rem
|
gap: 0.5rem
|
||||||
byPageType:
|
byPageType:
|
||||||
|
|||||||
@ -704,57 +704,74 @@ function resolveGroups(
|
|||||||
}[],
|
}[],
|
||||||
groups: Record<string, FlexGroupConfig>,
|
groups: Record<string, FlexGroupConfig>,
|
||||||
): QuartzComponent[] {
|
): QuartzComponent[] {
|
||||||
const result: QuartzComponent[] = []
|
// Collect grouped components and track the effective priority for each group.
|
||||||
|
// Effective priority = explicit group config priority ?? first member's priority.
|
||||||
const groupedComponents = new Map<
|
const groupedComponents = new Map<
|
||||||
string,
|
string,
|
||||||
{ component: QuartzComponent; groupOptions?: PluginLayoutDeclaration["groupOptions"] }[]
|
{ component: QuartzComponent; groupOptions?: PluginLayoutDeclaration["groupOptions"] }[]
|
||||||
>()
|
>()
|
||||||
const groupInsertionOrder: { name: string; priority: number }[] = []
|
const groupPriority = new Map<string, number>()
|
||||||
|
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
if (item.group) {
|
if (item.group) {
|
||||||
if (!groupedComponents.has(item.group)) {
|
if (!groupedComponents.has(item.group)) {
|
||||||
groupedComponents.set(item.group, [])
|
groupedComponents.set(item.group, [])
|
||||||
groupInsertionOrder.push({ name: item.group, priority: item.priority })
|
// Use explicit group priority from config if set, otherwise fall back to first member's priority
|
||||||
|
const groupConfig = groups[item.group]
|
||||||
|
groupPriority.set(item.group, groupConfig?.priority ?? item.priority)
|
||||||
}
|
}
|
||||||
groupedComponents.get(item.group)!.push({
|
groupedComponents.get(item.group)!.push({
|
||||||
component: item.component,
|
component: item.component,
|
||||||
groupOptions: item.groupOptions,
|
groupOptions: item.groupOptions,
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
result.push(item.component)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert flex groups at the position of their first member
|
// Build a unified list of renderable entries (ungrouped components + flex groups),
|
||||||
for (const { name: groupName } of groupInsertionOrder) {
|
// each with a priority, so we can sort them together.
|
||||||
const members = groupedComponents.get(groupName)!
|
type RenderEntry = { priority: number; component: QuartzComponent }
|
||||||
const groupConfig = groups[groupName] ?? {}
|
const entries: RenderEntry[] = []
|
||||||
|
const processedGroups = new Set<string>()
|
||||||
|
|
||||||
const flexComponents = members.map((m) => ({
|
for (const item of items) {
|
||||||
Component: m.component,
|
if (item.group) {
|
||||||
grow: m.groupOptions?.grow,
|
// Only emit the flex group once (on first encounter)
|
||||||
shrink: m.groupOptions?.shrink,
|
if (processedGroups.has(item.group)) continue
|
||||||
basis: m.groupOptions?.basis,
|
processedGroups.add(item.group)
|
||||||
order: m.groupOptions?.order,
|
|
||||||
align: m.groupOptions?.align,
|
|
||||||
justify: m.groupOptions?.justify,
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Dynamically import Flex to avoid circular dependencies
|
const members = groupedComponents.get(item.group)!
|
||||||
const FlexModule = require("../../components/Flex")
|
const groupConfig = groups[item.group] ?? {}
|
||||||
const Flex = FlexModule.default as Function
|
|
||||||
const flexComponent = Flex({
|
|
||||||
components: flexComponents,
|
|
||||||
direction: groupConfig.direction ?? "row",
|
|
||||||
wrap: groupConfig.wrap,
|
|
||||||
gap: groupConfig.gap ?? "1rem",
|
|
||||||
}) as QuartzComponent
|
|
||||||
|
|
||||||
result.push(flexComponent)
|
const flexComponents = members.map((m) => ({
|
||||||
|
Component: m.component,
|
||||||
|
grow: m.groupOptions?.grow,
|
||||||
|
shrink: m.groupOptions?.shrink,
|
||||||
|
basis: m.groupOptions?.basis,
|
||||||
|
order: m.groupOptions?.order,
|
||||||
|
align: m.groupOptions?.align,
|
||||||
|
justify: m.groupOptions?.justify,
|
||||||
|
}))
|
||||||
|
|
||||||
|
// Dynamically import Flex to avoid circular dependencies
|
||||||
|
const FlexModule = require("../../components/Flex")
|
||||||
|
const Flex = FlexModule.default as Function
|
||||||
|
const flexComponent = Flex({
|
||||||
|
components: flexComponents,
|
||||||
|
direction: groupConfig.direction ?? "row",
|
||||||
|
wrap: groupConfig.wrap,
|
||||||
|
gap: groupConfig.gap ?? "1rem",
|
||||||
|
}) as QuartzComponent
|
||||||
|
|
||||||
|
entries.push({ priority: groupPriority.get(item.group)!, component: flexComponent })
|
||||||
|
} else {
|
||||||
|
entries.push({ priority: item.priority, component: item.component })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
// Stable sort by priority (items already arrive sorted, so equal priorities preserve order)
|
||||||
|
entries.sort((a, b) => a.priority - b.priority)
|
||||||
|
|
||||||
|
return entries.map((e) => e.component)
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyDisplayWrapper(
|
function applyDisplayWrapper(
|
||||||
|
|||||||
@ -148,6 +148,8 @@ export interface PluginJsonEntry {
|
|||||||
|
|
||||||
/** Flex group configuration in the top-level layout section */
|
/** Flex group configuration in the top-level layout section */
|
||||||
export interface FlexGroupConfig {
|
export interface FlexGroupConfig {
|
||||||
|
/** Explicit priority for the group. Overrides first-member priority. Lower = renders first. */
|
||||||
|
priority?: number
|
||||||
direction?: "row" | "row-reverse" | "column" | "column-reverse"
|
direction?: "row" | "row-reverse" | "column" | "column-reverse"
|
||||||
wrap?: "nowrap" | "wrap" | "wrap-reverse"
|
wrap?: "nowrap" | "wrap" | "wrap-reverse"
|
||||||
gap?: string
|
gap?: string
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user