Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed May 6, 2024
1 parent 8e9a81a commit d63f82a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 41 deletions.
6 changes: 3 additions & 3 deletions notes/flutter_web/lib/routes/notes/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import 'package:you_flutter/state.dart';

/// [NoteLayoutBuilder]
@ToType(type: ToNote)
NoteResult layout(BuildContext context, NoteResult child) {
NoteMixin layout(BuildContext context, NoteMixin child) {
// ignore: unnecessary_type_check
assert(layout is NoteLayoutBuilder);
return NoteLayout(child: child);
}

/// 一个极简的笔记布局范例
/// 左边routes树,右边页面内容
final class NoteLayout extends StatelessWidget with NoteResult {
final NoteResult child;
final class NoteLayout extends StatelessWidget with NoteMixin {
final NoteMixin child;

const NoteLayout({super.key, required this.child});

Expand Down
2 changes: 1 addition & 1 deletion packages/you_flutter/lib/note.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
library note;

export 'src/note/note.dart' show ToNote, Cell, NoteBuilder,NoteResult, NoteLayoutBuilder, NoteSystem;
export 'src/note/note.dart' show ToNote, Cell, NoteBuilder,NoteMixin, NoteLayoutBuilder;

export 'src/note/contents/contents.dart' show contents, Contents;
export 'src/note/contents/mockup.dart' show MockupWindow;
Expand Down
30 changes: 7 additions & 23 deletions packages/you_flutter/lib/src/note/note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import 'package:you_flutter/src/note/conventions.dart';
import 'package:http/http.dart' as http;

typedef NoteBuilder = void Function(BuildContext context, Cell print);
typedef NoteLayoutBuilder = NoteResult Function(BuildContext context, NoteResult child);
typedef NoteLayoutBuilder = NoteMixin Function(BuildContext context, NoteMixin child);

mixin NoteResult on StatelessWidget {
mixin NoteMixin on StatelessWidget {
Cell get cell;
}

Expand All @@ -29,23 +29,23 @@ base class ToNote extends To {
}) : super(
page: page == null ? null : (context) => _build(context, page),
notFound: notFound == null ? null : (context) => _build(context, notFound),
layout: layout == null ? null : (context, child) => layout(context, child as NoteResult),
layout: layout == null ? null : (context, child) => layout(context, child as NoteMixin),
);

static NoteResult _build(BuildContext context, NoteBuilder page) {
static NoteMixin _build(BuildContext context, NoteBuilder page) {
Cell cell = Cell.empty();
page.call(context, cell);
return _DefaultNotePage(cell: cell);
return _DefaultNote(cell: cell);
}
}

/// 一个极简的笔记布局范例
/// 左边routes树,右边页面内容
final class _DefaultNotePage extends StatelessWidget with NoteResult {
final class _DefaultNote extends StatelessWidget with NoteMixin {
@override
final Cell cell;

const _DefaultNotePage({required this.cell});
const _DefaultNote({required this.cell});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -191,22 +191,6 @@ class NoteRoute {
String get confAssetPath => conventions.noteConfAssetPath(path);
}

class NoteSystem {
final To root;

NoteSystem({
required this.root,
});

static Future<NoteSystem> load({
required To root,
}) async {
return NoteSystem(
root: root,
);
}
}

base class Cell {
Cell(
Function(Cell print) callback, {
Expand Down
2 changes: 0 additions & 2 deletions packages/you_flutter/lib/src/note/note_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ const Widget _cellSplitBlock = SizedBox(height: 18);

@Deprecated("已被新router替代暂时保留,代码还没移植完")
class LayoutScreen extends StatefulWidget with Screen<void> {
final NoteSystem noteSystem;
final NoteRoute note = NoteRoute.root();
final Cell rootCell;
final NoteRoute rootNote = NoteRoute.root();

LayoutScreen({
super.key,
required this.noteSystem,
required this.rootCell,
});

Expand Down
24 changes: 12 additions & 12 deletions packages/you_flutter/lib/src/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ final class YouRouter with RouterMixin {
YouRouter get router => this;
}

enum RouteNodeType {
enum ToPartType {
/// static path : /settings
static,

Expand All @@ -140,7 +140,7 @@ enum RouteNodeType {
/// /file/a/b/c.txt -> path==a/b/c.txt
dynamicRest;

static RouteNodeType? parse(String name) {
static ToPartType? parse(String name) {
for (var i in values) {
if (i.name == name) {
return i;
Expand All @@ -161,7 +161,7 @@ base class To {
final String part;

late final String _name;
late final RouteNodeType _type;
late final ToPartType _type;

late To _parent = this;

Expand Down Expand Up @@ -286,14 +286,14 @@ base class To {

// 忽略后缀'/'
// next=="" 代表最后以 '/' 结尾,当前 segments==[""]
if (_type == RouteNodeType.static && next == "") {
if (_type == ToPartType.static && next == "") {
return RouteUri._(uri: uri, to: this, routeParameters: params);
}

To? matchChild({required String segment}) {
To? matched = children.where((e) => e._type == RouteNodeType.static).where((e) => segment == e._name).firstOrNull;
To? matched = children.where((e) => e._type == ToPartType.static).where((e) => segment == e._name).firstOrNull;
if (matched != null) return matched;
matched = children.where((e) => e._type == RouteNodeType.dynamic || e._type == RouteNodeType.dynamicRest).firstOrNull;
matched = children.where((e) => e._type == ToPartType.dynamic || e._type == ToPartType.dynamicRest).firstOrNull;
if (matched != null) return matched;
return null;
}
Expand All @@ -304,7 +304,7 @@ base class To {
throw NotFoundError(invalidValue: uri);
}

if (matchedNext._type == RouteNodeType.dynamicRest) {
if (matchedNext._type == ToPartType.dynamicRest) {
// /tree/[...file]
// /tree/x/y --> {"file":"x/y"}
// /tree/x/y/ --> {"file":"x/y/"}
Expand All @@ -315,7 +315,7 @@ base class To {
if (next == "") {
return RouteUri._(uri: uri, to: this, routeParameters: params);
}
if (matchedNext._type == RouteNodeType.dynamic) {
if (matchedNext._type == ToPartType.dynamic) {
params[matchedNext._name] = next;
}
}
Expand Down Expand Up @@ -358,11 +358,11 @@ base class To {
/// parse("user") --> (name:"user",type:ToNodeType.normal)
/// parse("[id]") --> (name:"id", type:ToNodeType.dynamic)
/// parse("[...path]") --> (name:"path",type:ToNodeType.dynamicAll)
static (String, RouteNodeType) _parse(String pattern) {
static (String, ToPartType) _parse(String pattern) {
assert(pattern.isNotEmpty);

if (pattern[0] != "[" || pattern[pattern.length - 1] != "]") {
return (pattern, RouteNodeType.static);
return (pattern, ToPartType.static);
}

assert(pattern != "[]");
Expand All @@ -373,9 +373,9 @@ base class To {
final removeBrackets = pattern.substring(1, pattern.length - 1);

if (removeBrackets.startsWith("...")) {
return (removeBrackets.substring(3), RouteNodeType.dynamicRest);
return (removeBrackets.substring(3), ToPartType.dynamicRest);
} else {
return (removeBrackets, RouteNodeType.dynamic);
return (removeBrackets, ToPartType.dynamic);
}
}

Expand Down

0 comments on commit d63f82a

Please sign in to comment.