Skip to content

Commit

Permalink
note tree filter containsPage node
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed May 11, 2024
1 parent f0d1bdf commit 4d77a53
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 85 deletions.
82 changes: 41 additions & 41 deletions notes/flutter_web/lib/routes.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,47 +141,47 @@ mixin RoutesMixin {
]),
]),
]);
late final To routes_root = root.find('/')!;
late final To routes_notes = root.find('/notes')!;
late final To routes_notes_research_parameterized = root.find('/notes/research/parameterized')!;
late final To routes_notes_research_remote_view = root.find('/notes/research/remote_view')!;
late final To routes_notes_env_info = root.find('/notes/env_info')!;
late final To routes_notes_layout_constraints = root.find('/notes/layout/constraints')!;
late final To routes_notes_navigation = root.find('/notes/navigation')!;
late final To routes_notes_state = root.find('/notes/state')!;
late final To routes_notes_state_vanilla_state = root.find('/notes/state/1.vanilla_state')!;
late final To routes_notes_state_StatefulBuilder = root.find('/notes/state/StatefulBuilder')!;
late final To routes_notes_media_assets_file_file_desktop = root.find('/notes/media&assets&file/file_desktop')!;
late final To routes_notes_media_assets_file_file_web = root.find('/notes/media&assets&file/file_web')!;
late final To routes_notes_media_assets_file_assets = root.find('/notes/media&assets&file/assets')!;
late final To routes_notes_style_theming_material3 = root.find('/notes/style&theming/material3')!;
late final To routes_notes_pure_dart_dart3 = root.find('/notes/pure_dart/dart3')!;
late final To routes_notes_pure_dart_async = root.find('/notes/pure_dart/async')!;
late final To routes_notes_pure_dart_safe_interface = root.find('/notes/pure_dart/safe_interface')!;
late final To routes_notes_pure_dart_execption = root.find('/notes/pure_dart/execption')!;
late final To routes_notes_pure_dart_serialization_json = root.find('/notes/pure_dart/serialization_json')!;
late final To routes_notes_pure_dart_analyzer = root.find('/notes/pure_dart/analyzer')!;
late final To routes_notes_dev_host_mirror = root.find('/notes/dev/host_mirror')!;
late final To routes_notes_dev_macos_config = root.find('/notes/dev/macos_config')!;
late final To routes_notes_dev_devtool = root.find('/notes/dev/devtool')!;
late final To routes_notes_dev_devtool_vmservice = root.find('/notes/dev/devtool/vmservice')!;
late final To routes_notes_dev_debug = root.find('/notes/dev/debug')!;
late final To routes_notes_i18n = root.find('/notes/i18n')!;
late final To routes_notes_thinking_in_ui_readable_html_vs_dart = root.find('/notes/thinking_in_ui/readable_html_vs_dart')!;
late final To routes_notes_x_note_inside_how_note_work = root.find('/notes/x.note_inside/how_note_work')!;
late final To routes_notes_x_note_inside_mockup_content = root.find('/notes/x.note_inside/mockup_content')!;
late final To routes_notes_x_note_inside_welcome = root.find('/notes/x.note_inside/1.welcome')!;
late final To routes_notes_x_note_inside_note_test_self = root.find('/notes/x.note_inside/note_test_self')!;
late final To routes_notes_x_note_inside_note_test_self_nobody = root.find('/notes/x.note_inside/note_test_self/nobody')!;
late final To routes_notes_widgets_specific_widgets_button = root.find('/notes/widgets/specific_widgets/button')!;
late final To routes_notes_widgets_container_widgets_menu = root.find('/notes/widgets/container_widgets/menu')!;
late final To routes_notes_widgets_container_widgets_scrollable_Dismissible = root.find('/notes/widgets/container_widgets/scrollable/Dismissible')!;
late final To routes_notes_widgets_container_widgets_bar = root.find('/notes/widgets/container_widgets/bar')!;
late final To routes_notes_Improve_app = root.find('/notes/Improve_app')!;
late final To routes_notes_Improve_app_overview = root.find('/notes/Improve_app/1.overview')!;
late final To routes_notes_Improve_app_web_optimization = root.find('/notes/Improve_app/web_optimization')!;
late final To routes_notes_Improve_app_RepaintBoundary = root.find('/notes/Improve_app/RepaintBoundary')!;
late final To routes_notes_Improve_app_event_listener_lifeycle = root.find('/notes/Improve_app/event&listener&lifeycle')!;
late final To routes_root = (root.find('/')! as To);
late final ToNote routes_notes = (root.find('/notes')! as ToNote);
late final ToNote routes_notes_research_parameterized = (root.find('/notes/research/parameterized')! as ToNote);
late final ToNote routes_notes_research_remote_view = (root.find('/notes/research/remote_view')! as ToNote);
late final ToNote routes_notes_env_info = (root.find('/notes/env_info')! as ToNote);
late final ToNote routes_notes_layout_constraints = (root.find('/notes/layout/constraints')! as ToNote);
late final ToNote routes_notes_navigation = (root.find('/notes/navigation')! as ToNote);
late final ToNote routes_notes_state = (root.find('/notes/state')! as ToNote);
late final ToNote routes_notes_state_vanilla_state = (root.find('/notes/state/1.vanilla_state')! as ToNote);
late final ToNote routes_notes_state_StatefulBuilder = (root.find('/notes/state/StatefulBuilder')! as ToNote);
late final ToNote routes_notes_media_assets_file_file_desktop = (root.find('/notes/media&assets&file/file_desktop')! as ToNote);
late final ToNote routes_notes_media_assets_file_file_web = (root.find('/notes/media&assets&file/file_web')! as ToNote);
late final ToNote routes_notes_media_assets_file_assets = (root.find('/notes/media&assets&file/assets')! as ToNote);
late final ToNote routes_notes_style_theming_material3 = (root.find('/notes/style&theming/material3')! as ToNote);
late final ToNote routes_notes_pure_dart_dart3 = (root.find('/notes/pure_dart/dart3')! as ToNote);
late final ToNote routes_notes_pure_dart_async = (root.find('/notes/pure_dart/async')! as ToNote);
late final ToNote routes_notes_pure_dart_safe_interface = (root.find('/notes/pure_dart/safe_interface')! as ToNote);
late final ToNote routes_notes_pure_dart_execption = (root.find('/notes/pure_dart/execption')! as ToNote);
late final ToNote routes_notes_pure_dart_serialization_json = (root.find('/notes/pure_dart/serialization_json')! as ToNote);
late final ToNote routes_notes_pure_dart_analyzer = (root.find('/notes/pure_dart/analyzer')! as ToNote);
late final ToNote routes_notes_dev_host_mirror = (root.find('/notes/dev/host_mirror')! as ToNote);
late final ToNote routes_notes_dev_macos_config = (root.find('/notes/dev/macos_config')! as ToNote);
late final ToNote routes_notes_dev_devtool = (root.find('/notes/dev/devtool')! as ToNote);
late final ToNote routes_notes_dev_devtool_vmservice = (root.find('/notes/dev/devtool/vmservice')! as ToNote);
late final ToNote routes_notes_dev_debug = (root.find('/notes/dev/debug')! as ToNote);
late final ToNote routes_notes_i18n = (root.find('/notes/i18n')! as ToNote);
late final ToNote routes_notes_thinking_in_ui_readable_html_vs_dart = (root.find('/notes/thinking_in_ui/readable_html_vs_dart')! as ToNote);
late final ToNote routes_notes_x_note_inside_how_note_work = (root.find('/notes/x.note_inside/how_note_work')! as ToNote);
late final ToNote routes_notes_x_note_inside_mockup_content = (root.find('/notes/x.note_inside/mockup_content')! as ToNote);
late final ToNote routes_notes_x_note_inside_welcome = (root.find('/notes/x.note_inside/1.welcome')! as ToNote);
late final ToNote routes_notes_x_note_inside_note_test_self = (root.find('/notes/x.note_inside/note_test_self')! as ToNote);
late final ToNote routes_notes_x_note_inside_note_test_self_nobody = (root.find('/notes/x.note_inside/note_test_self/nobody')! as ToNote);
late final ToNote routes_notes_widgets_specific_widgets_button = (root.find('/notes/widgets/specific_widgets/button')! as ToNote);
late final ToNote routes_notes_widgets_container_widgets_menu = (root.find('/notes/widgets/container_widgets/menu')! as ToNote);
late final ToNote routes_notes_widgets_container_widgets_scrollable_Dismissible = (root.find('/notes/widgets/container_widgets/scrollable/Dismissible')! as ToNote);
late final ToNote routes_notes_widgets_container_widgets_bar = (root.find('/notes/widgets/container_widgets/bar')! as ToNote);
late final ToNote routes_notes_Improve_app = (root.find('/notes/Improve_app')! as ToNote);
late final ToNote routes_notes_Improve_app_overview = (root.find('/notes/Improve_app/1.overview')! as ToNote);
late final ToNote routes_notes_Improve_app_web_optimization = (root.find('/notes/Improve_app/web_optimization')! as ToNote);
late final ToNote routes_notes_Improve_app_RepaintBoundary = (root.find('/notes/Improve_app/RepaintBoundary')! as ToNote);
late final ToNote routes_notes_Improve_app_event_listener_lifeycle = (root.find('/notes/Improve_app/event&listener&lifeycle')! as ToNote);
}

class Routes with RoutesMixin {}
Expand Down
2 changes: 1 addition & 1 deletion notes/flutter_web/lib/routes/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class _NoteTreeState extends State<_NoteTree> {
routes.routes_root.expandTree(true, level: 2);
return Watch((context) {
final notes = routes.routes_notes.toList(includeThis: false).cast<ToNote>().where((e) {
return e.parent.expand && (includeDraft.value || e.containsPublishNode);
return e.containsPage() && e.parent.expand && (includeDraft.value || e.containsPublishNode(includeThis: true));
});

return Column(
Expand Down
10 changes: 5 additions & 5 deletions packages/you_cli/bin/cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Cmd_gen_routes_g_dart extends Command {
[literalString(node.dir.basename)],
{
if (node.file_page_dart.existsSync()) "page": refer(YouCli.pageFunctionName, node.pagePackageUrl),
if (node.pageAnno!=null) "pageAnno": refer("_Pages").property(node.flatName),
if (node.pageAnno != null) "pageAnno": refer("_Pages").property(node.flatName),
if (node.file_layout_dart.existsSync()) "layout": refer(YouCli.layoutFunctionName, node.layoutPackageUrl),
if (node.children.isNotEmpty) "children": literalList(node.children.map((e) => _genRootRouteExpression(e))),
},
Expand Down Expand Up @@ -171,9 +171,9 @@ class Cmd_gen_routes_g_dart extends Command {
(routeDir) => Field((f) => f
..modifier = FieldModifier.final$
..late = true
..type = YouCli.toType
..type = routeDir.findToType()
..name = "routes_${routeDir.flatName}"
..assignment = refer("root.find").call([literalString(routeDir.routePath)]).nullChecked.code),
..assignment = refer("root.find").call([literalString(routeDir.routePath)]).nullChecked.asA(routeDir.findToType()).code),
),
),
),
Expand All @@ -191,8 +191,8 @@ class Cmd_gen_routes_g_dart extends Command {
rootRoute.toList(includeThis: true).where((e) => e.pageAnno != null).map((e) {
return Field((b) => b
..name = e.flatName
..static=true
..modifier=FieldModifier.constant
..static = true
..modifier = FieldModifier.constant
..assignment = Code(e.pageAnno!.toSource.substring(1) /*跳过第一个@字符:@PageAnnotation(label: "笔记", toType: ToNote)*/));
}),
),
Expand Down
2 changes: 2 additions & 0 deletions packages/you_cli/lib/src/cli_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class RouteNode {
);
}

get hasPage => page != null;

int get level => isRoot ? 0 : _parent.level + 1;

RouteNode get root => isRoot ? this : _parent.root;
Expand Down
8 changes: 5 additions & 3 deletions packages/you_flutter/lib/src/note/note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ base class ToNote extends To {
String get label => pageAnno == null ? part : pageAnno!.label;

@nonVirtual
bool get containsPublishNode {
if (isPublish) return true;
bool containsPublishNode({bool includeThis = true}) {
if(includeThis){
if (isPublish) return true;
}
for (var c in children) {
if (c.containsPublishNode) return true;
if (c.containsPublishNode()) return true;
}
return false;
}
Expand Down
43 changes: 8 additions & 35 deletions packages/you_flutter/lib/src/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ base class To {
/// /[user]/[repository]
/// - /dart-lang/sdk => {"user":"dart-lang","repository":"sdk"}
/// - /flutter/flutter => {"user":"flutter","repository":"flutter"}
@nonVirtual
final String part;

late final String _name;
Expand All @@ -207,63 +206,43 @@ base class To {
final PageBodyBuilder? _notFound;
final PageLayoutBuilder? _layout;

@nonVirtual
To get parent => _parent;

@nonVirtual
bool get isRoot => _parent == this;

@nonVirtual
bool get isLeaf {
return children.isEmpty;
}

bool get isValid {
if (isPage) return true;
return isChildrenValid;
}

bool get isLeafPage {
return isValid && !isChildrenValid;
return hasPage && !containsPage(includeThis: false);
}

bool get isChildrenValid {
bool containsPage({bool includeThis = true}) {
if (includeThis) {
if (hasPage) return true;
}
for (var c in children) {
if (c.isValid) return true;
if (c.containsPage()) return true;
}
return false;
}

@nonVirtual
bool get isNonLeaf => !isLeaf;

@nonVirtual
To get root => isRoot ? this : _parent.root;

@nonVirtual
int get level => isRoot ? 0 : _parent.level + 1;

@nonVirtual
bool get isPage => _page != null;
bool get hasPage => _page != null;

@nonVirtual
bool get hasNotFound => _notFound != null;

@nonVirtual
bool get hasLayout => _layout != null;

// 对于page目录树:
// - / -> uriTemplate: /
// - users -> uriTemplate: /users
// - [user] -> uriTemplate: /users/[user]
@nonVirtual
String get templatePath => isRoot ? "/" : path_.join(_parent.templatePath, part);

@nonVirtual
List<To> get ancestors => isRoot ? [] : [_parent, ..._parent.ancestors];

/// return Strictly equal ancestors of type
@nonVirtual
Iterable<T> findAncestorsOfSameType<T>() sync* {
for (var a in ancestors) {
if (a.runtimeType == runtimeType) {
Expand All @@ -272,14 +251,12 @@ base class To {
}
}

@nonVirtual
Uri toUri({Map<String, String> routeParameters = const {}, Map<String, List<String>> queryParameters = const {}}) {
// TODO 临时实现,需要增加模版参数
return Uri.parse(templatePath);
}

/// framework invoke this method if [isPage]
@nonVirtual
/// framework invoke this method if [hasPage]
Widget _buildBody(BuildContext context) {
return _build(context, _page!);
}
Expand All @@ -290,7 +267,6 @@ base class To {

/// framework invoke this method if [hasLayout]
/// downstream results warp to => new result
@nonVirtual
Widget _warpLayout(BuildContext context, Widget child) {
return _layout!(context, child);
}
Expand Down Expand Up @@ -354,7 +330,6 @@ base class To {
///
/// a.toList(includeThis:true)
/// => [/a,/a/1,/a/2]
@nonVirtual
List<To> toList({
bool includeThis = true,
bool Function(To path)? where,
Expand Down Expand Up @@ -399,7 +374,6 @@ base class To {
}
}

@nonVirtual
To? find(String templatePath) {
return _findBySegments(Uri.parse(templatePath).pathSegments.where((e) => e.isNotEmpty).toList());
}
Expand Down Expand Up @@ -435,7 +409,6 @@ base class To {
);
}

@nonVirtual
Widget _buildPage(BuildContext context, ToUri uri) {
var result = _buildBody(context);
final List<To> chain = [this, ...ancestors];
Expand Down

0 comments on commit 4d77a53

Please sign in to comment.