(props: {
scrollRef: HTMLDivElement;
brandColorSwatches: OrganizationBrandColorSwatch[];
})
| 1615 | } |
| 1616 | |
| 1617 | function BackgroundConfig(props: { |
| 1618 | scrollRef: HTMLDivElement; |
| 1619 | brandColorSwatches: OrganizationBrandColorSwatch[]; |
| 1620 | }) { |
| 1621 | const { project, setProject, editorInstance, projectHistory } = |
| 1622 | useEditorContext(); |
| 1623 | const isNoneBackground = () => |
| 1624 | project.background.padding === 0 && project.background.rounding === 0; |
| 1625 | const initialCurrentDesktopBackgroundPath = () => { |
| 1626 | const source = project.background.source; |
| 1627 | if (source.type !== "wallpaper" || !source.path) return null; |
| 1628 | return isCurrentDesktopBackgroundPath(source.path) ? source.path : null; |
| 1629 | }; |
| 1630 | const [currentDesktopBackgroundPath, setCurrentDesktopBackgroundPath] = |
| 1631 | createSignal<string | null>(initialCurrentDesktopBackgroundPath()); |
| 1632 | |
| 1633 | const [backgroundTab, setBackgroundTab] = |
| 1634 | createSignal<keyof typeof BACKGROUND_THEMES>("macOS"); |
| 1635 | const projectBackgroundSourceTab = createMemo<BackgroundSourceTab>(() => { |
| 1636 | const source = project.background.source; |
| 1637 | if ( |
| 1638 | source.type === "wallpaper" && |
| 1639 | isCurrentDesktopBackgroundPath(source.path) |
| 1640 | ) { |
| 1641 | return "desktop"; |
| 1642 | } |
| 1643 | |
| 1644 | return source.type; |
| 1645 | }); |
| 1646 | const [backgroundSourceTab, setBackgroundSourceTab] = |
| 1647 | createSignal<BackgroundSourceTab>( |
| 1648 | isNoneBackground() ? "none" : projectBackgroundSourceTab(), |
| 1649 | ); |
| 1650 | |
| 1651 | // "None" is a sticky selection: nudging the padding/rounding sliders must not |
| 1652 | // swap the panel back to the underlying source tab (that reflow moves the very |
| 1653 | // slider being dragged), so only re-sync when the user isn't sitting on "None". |
| 1654 | createEffect( |
| 1655 | on(projectBackgroundSourceTab, (tab) => { |
| 1656 | if (backgroundSourceTab() !== "none") setBackgroundSourceTab(tab); |
| 1657 | }), |
| 1658 | ); |
| 1659 | |
| 1660 | const [wallpapers] = createResource(async () => { |
| 1661 | // Only load visible wallpapers initially |
| 1662 | const visibleWallpaperPaths = WALLPAPER_NAMES.map(async (id) => { |
| 1663 | try { |
| 1664 | const path = await resolveResource(`assets/backgrounds/${id}.jpg`); |
| 1665 | return { id, path }; |
| 1666 | } catch (_err) { |
| 1667 | return { id, path: null }; |
| 1668 | } |
| 1669 | }); |
| 1670 | |
| 1671 | // Load initial batch |
| 1672 | const initialPaths = await Promise.all(visibleWallpaperPaths); |
| 1673 | |
| 1674 | return initialPaths.flatMap(({ id, path }) => { |
nothing calls this directly
no test coverage detected