feat(workspace): add workflow navigation and resizable desktop panels

This commit is contained in:
lingjhf committed 2026-10-09 19:23:49 +08:00
1 parent 02413383d8
commit 1acfe4a005
17 files changed
+2008 -277

No files matched your search

@@ -1,6 +1,6 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
enum DesktopContent { workspace, library, resourceLibrary, settings }
enum DesktopContent { workspace, library, resourceLibrary, workflow, settings }
typedef DesktopContentSelection = ({
DesktopContent surface,
+93 -74
View File
@@ -17,9 +17,9 @@ class DesktopWindowFrame extends StatelessWidget {
this.projectTabs,
this.headerTrailing = const SizedBox.shrink(),
this.settingsSelected = false,
this.resourceLibrarySelected = false,
this.onResourceLibraryPressed,
this.workflowSelected = false,
required this.onHomePressed,
required this.onWorkflowPressed,
required this.onSettingsPressed,
required this.child,
});
@@ -35,9 +35,9 @@ class DesktopWindowFrame extends StatelessWidget {
final Widget? projectTabs;
final Widget headerTrailing;
final bool settingsSelected;
final bool resourceLibrarySelected;
final VoidCallback? onResourceLibraryPressed;
final bool workflowSelected;
final VoidCallback onHomePressed;
final VoidCallback onWorkflowPressed;
final VoidCallback onSettingsPressed;
final Widget child;
@@ -119,90 +119,109 @@ class DesktopWindowFrame extends StatelessWidget {
Expanded(
child: Row(
children: [
if (projectTabs == null)
SizedBox(
key: const Key('desktop-navigation-rail'),
width: railWidth,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Column(
children: [
for (final section in [0, 2])
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: IconButton.filledTonal(
key: ValueKey(switch (section) {
0 => 'desktop-rail-home',
_ => 'desktop-rail-resources',
}),
tooltip: switch (section) {
0 => context.l10n.navigationHome,
_ => context.l10n.navigationLibrary,
},
isSelected:
!settingsSelected &&
(section == 2
? resourceLibrarySelected
: !resourceLibrarySelected),
style: IconButton.styleFrom(
fixedSize: const Size.square(railButtonSize),
minimumSize: const Size.square(railButtonSize),
maximumSize: const Size.square(railButtonSize),
padding: EdgeInsets.zero,
iconSize: railIconSize,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
backgroundColor:
!settingsSelected &&
(section == 2
? resourceLibrarySelected
: !resourceLibrarySelected)
? null
: Colors.transparent,
SizedBox(
key: const Key('desktop-navigation-rail'),
width: railWidth,
child: LayoutBuilder(
builder: (context, constraints) => SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraints.maxHeight,
),
child: IntrinsicHeight(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Column(
children: [
IconButton.filledTonal(
key: const ValueKey('desktop-rail-home'),
tooltip: context.l10n.navigationHome,
isSelected:
!settingsSelected && !workflowSelected,
style: IconButton.styleFrom(
fixedSize: const Size.square(railButtonSize),
minimumSize: const Size.square(
railButtonSize,
),
maximumSize: const Size.square(
railButtonSize,
),
padding: EdgeInsets.zero,
iconSize: railIconSize,
tapTargetSize:
MaterialTapTargetSize.shrinkWrap,
backgroundColor:
settingsSelected || workflowSelected
? Colors.transparent
: null,
),
onPressed: onHomePressed,
icon: const Icon(AppIcons.home),
),
onPressed: switch (section) {
0 => onHomePressed,
_ => onResourceLibraryPressed,
},
icon: Icon(switch (section) {
0 => AppIcons.home,
_ => AppIcons.folder,
}),
),
const SizedBox(height: 8),
IconButton.filledTonal(
key: const ValueKey('desktop-rail-workflow'),
tooltip: context.l10n.workflow,
isSelected: workflowSelected,
style: IconButton.styleFrom(
fixedSize: const Size.square(railButtonSize),
minimumSize: const Size.square(
railButtonSize,
),
maximumSize: const Size.square(
railButtonSize,
),
padding: EdgeInsets.zero,
iconSize: railIconSize,
tapTargetSize:
MaterialTapTargetSize.shrinkWrap,
backgroundColor: workflowSelected
? null
: Colors.transparent,
),
onPressed: onWorkflowPressed,
icon: const Icon(AppIcons.timeline),
),
const Spacer(),
IconButton(
key: const Key('desktop-rail-settings'),
tooltip: context.l10n.settings,
isSelected: settingsSelected,
onPressed: onSettingsPressed,
style: IconButton.styleFrom(
fixedSize: const Size.square(railButtonSize),
minimumSize: const Size.square(
railButtonSize,
),
maximumSize: const Size.square(
railButtonSize,
),
padding: EdgeInsets.zero,
iconSize: railIconSize,
tapTargetSize:
MaterialTapTargetSize.shrinkWrap,
),
icon: const Icon(AppIcons.settings),
),
],
),
const Spacer(),
IconButton(
key: const Key('project-settings-button'),
tooltip: context.l10n.settings,
isSelected: settingsSelected,
onPressed: onSettingsPressed,
style: IconButton.styleFrom(
fixedSize: const Size.square(railButtonSize),
minimumSize: const Size.square(railButtonSize),
maximumSize: const Size.square(railButtonSize),
padding: EdgeInsets.zero,
iconSize: railIconSize,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
icon: const Icon(AppIcons.settings),
),
],
),
),
),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.only(
left: projectTabs == null ? 0 : contentInset,
padding: const EdgeInsets.only(
left: contentInset,
right: contentInset,
bottom: contentInset,
),
child: SizedBox(
key: const Key('desktop-content-container'),
child: WindowHeaderPane(
offset: Offset(
projectTabs == null ? railWidth : contentInset,
headerHeight,
),
offset: const Offset(railWidth + contentInset, headerHeight),
child: LayoutBuilder(
builder: (context, constraints) =>
constraints.maxWidth < 200
+121 -9
View File
@@ -32,6 +32,11 @@ class DesktopWorkspaceShell extends StatefulWidget {
required this.scaffoldKey,
required this.navigationDrawer,
this.projectTabsLayout = false,
this.timelineHeight,
this.onTimelineHeightChanged,
this.onJunctionResizeEnd,
this.onSidebarResizeEnd,
this.sidebarCanExpand = true,
});
static const gutterWidth = WorkspaceLayoutMetrics.desktopSpacing;
@@ -47,12 +52,53 @@ class DesktopWorkspaceShell extends StatefulWidget {
final GlobalKey<ScaffoldState> scaffoldKey;
final Widget navigationDrawer;
final bool projectTabsLayout;
final double? timelineHeight;
final ValueChanged<double>? onTimelineHeightChanged;
final VoidCallback? onJunctionResizeEnd;
final VoidCallback? onSidebarResizeEnd;
final bool sidebarCanExpand;
@override
State<DesktopWorkspaceShell> createState() => _DesktopWorkspaceShellState();
}
class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
double? _sidebarRestoreWidth;
bool _sidebarJunctionDragging = false;
void _startSidebarResize(double width, {bool junction = false}) {
_sidebarRestoreWidth = width;
if (junction) setState(() => _sidebarJunctionDragging = true);
}
void _resizeSidebar(double requestedWidth, double maximum) {
if (!widget.sidebarCanExpand || widget.controller.agentFloating) return;
if (requestedWidth < WorkspaceLayoutMetrics.sidebarSnapThreshold) {
if (!widget.sidebarCollapsed) {
final restoreWidth = _sidebarRestoreWidth;
if (restoreWidth != null && widget.sidebarWidth != restoreWidth) {
widget.onSidebarWidthChanged(restoreWidth);
}
widget.onSidebarCollapsedChanged(true);
}
return;
}
if (widget.sidebarCollapsed) widget.onSidebarCollapsedChanged(false);
widget.onSidebarWidthChanged(
requestedWidth.clamp(WorkspaceLayoutMetrics.sidebarMinimumWidth, maximum),
);
}
void _finishSidebarResize() {
_sidebarRestoreWidth = null;
if (_sidebarJunctionDragging) {
setState(() => _sidebarJunctionDragging = false);
widget.onJunctionResizeEnd?.call();
} else {
widget.onSidebarResizeEnd?.call();
}
}
@override
void initState() {
super.initState();
@@ -64,6 +110,11 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
@override
void didUpdateWidget(covariant DesktopWorkspaceShell oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.controller.agentFloating ||
!widget.sidebarCanExpand ||
widget.onTimelineHeightChanged == null) {
_sidebarJunctionDragging = false;
}
if (oldWidget.controller != widget.controller) {
oldWidget.controller.removeListener(_changed);
widget.controller.addListener(_changed);
@@ -85,6 +136,9 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
required ValueChanged<double> onResize,
double direction = 1,
VoidCallback? onEnd,
VoidCallback? onStart,
Set<WorkspaceResizeBoundary> highlightTargets = const {},
Offset highlightOffset = Offset.zero,
}) => SizedBox(
width: WorkspaceLayoutMetrics.desktopResizeHitExtent,
height: double.infinity,
@@ -95,11 +149,17 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
direction: direction,
onResize: onResize,
onEnd: onEnd,
onStart: onStart,
highlightTargets: highlightTargets,
highlightOffset: highlightOffset,
),
);
@override
Widget build(BuildContext context) => widget.projectTabsLayout
Widget build(BuildContext context) =>
WorkspaceResizeHighlightScope(child: _workspace(context));
Widget _workspace(BuildContext context) => widget.projectTabsLayout
? _projectWorkspace(context)
: LayoutBuilder(
builder: (context, constraints) {
@@ -164,6 +224,7 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
return Scaffold(
key: widget.scaffoldKey,
drawerEnableOpenDragGesture: false,
backgroundColor: Colors.transparent,
drawer: Drawer(
width: 320,
@@ -317,6 +378,12 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
.toDouble();
final floating = widget.controller.agentFloating;
final collapsed = widget.sidebarCollapsed || floating;
double resolveTimelineHeight(double? height) =>
WorkspaceLayoutMetrics.resolveTimelineHeight(
constraints.maxHeight,
height,
);
final timelineHeight = resolveTimelineHeight(widget.timelineHeight);
final geometry = DesktopWorkspaceGeometry(
sidebarWidth: sidebarWidth,
agentWidth: 0,
@@ -324,6 +391,7 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
);
return Scaffold(
key: widget.scaffoldKey,
drawerEnableOpenDragGesture: false,
backgroundColor: Colors.transparent,
drawer: Drawer(
width: 320,
@@ -356,20 +424,64 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
),
],
),
if (!collapsed)
if (!floating &&
widget.sidebarCanExpand &&
WorkspaceLayoutPolicy.desktopNavigationFits(width))
Positioned(
left: sidebarWidth - WorkspaceLayoutMetrics.desktopResizeSlop,
left: collapsed
? 0
: sidebarWidth - WorkspaceLayoutMetrics.desktopResizeSlop,
top: 0,
bottom: 0,
child: _gutter(
name: 'project-sidebar',
initialWidth: sidebarWidth,
onResize: (value) => widget.onSidebarWidthChanged(
value.clamp(
WorkspaceLayoutMetrics.sidebarMinimumWidth,
maximum,
),
highlightTargets: const {WorkspaceResizeBoundary.sidebar},
highlightOffset: collapsed
? const Offset(
-WorkspaceLayoutMetrics.desktopResizeHitExtent / 2,
0,
)
: Offset.zero,
initialWidth: collapsed ? 0 : sidebarWidth,
onStart: () => _startSidebarResize(sidebarWidth),
onResize: (value) => _resizeSidebar(value, maximum),
onEnd: _finishSidebarResize,
),
),
if (!floating &&
widget.sidebarCanExpand &&
WorkspaceLayoutPolicy.desktopNavigationFits(width) &&
widget.onTimelineHeightChanged != null)
Positioned(
left: collapsed
? 0
: sidebarWidth - WorkspaceLayoutMetrics.desktopResizeSlop,
bottom:
timelineHeight - WorkspaceLayoutMetrics.desktopResizeSlop,
width: WorkspaceLayoutMetrics.desktopResizeHitExtent,
height: WorkspaceLayoutMetrics.desktopResizeHitExtent,
child: WorkspaceResizeHandle.junction(
key: const Key('desktop-chat-timeline-junction'),
highlightOffset: collapsed
? const Offset(
-WorkspaceLayoutMetrics.desktopResizeHitExtent / 2,
0,
)
: Offset.zero,
highlightTargets: const {
WorkspaceResizeBoundary.sidebar,
WorkspaceResizeBoundary.timeline,
},
initialWidth: collapsed ? 0 : sidebarWidth,
initialHeight: timelineHeight,
verticalDirection: -1,
onStart: () =>
_startSidebarResize(sidebarWidth, junction: true),
onWidthChanged: (value) => _resizeSidebar(value, maximum),
onHeightChanged: (value) => widget.onTimelineHeightChanged!(
resolveTimelineHeight(value),
),
onEnd: _finishSidebarResize,
),
),
if (floating)