Skip to content

Commit

Permalink
准备合并Print和Cell
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed Apr 23, 2024
1 parent fd77399 commit fbd175b
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 211 deletions.
20 changes: 9 additions & 11 deletions bin/notecli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:analyzer/dart/analysis/utilities.dart' as analyzer_util;
import 'package:watcher/watcher.dart';
import 'package:yaml_edit/yaml_edit.dart' show YamlEditor;

import 'package:you_note_dart/src/utils_core.dart';
import 'package:you_dart/src/core.dart';

const String _libRoot = "lib";
const String _notesRoot = "lib/notes";
Expand Down Expand Up @@ -124,15 +124,13 @@ class NotesGenerator {
// final NoteRoute dev_devtool = put("/dev/devtool", (context,print) async => await dev_devtool_.loadLibrary().then((value) => dev_devtool_.build(context,print)));
return """ final $noteVarNameWithPadding = put("${noteLib.noteKey}", (context,print) async => await ${noteLib.asVariableName}_.loadLibrary().then((value) => ${noteLib.asVariableName}_.build(context,print))); """;
}).join("\n");
Library importCode = Library(
(b) => b
..comments.addAll(["Generated by gen_maters.dart, please don't edit! ", "ignore_for_file: library_prefixes, non_constant_identifier_names"])
..directives.addAll(
noteLibs.map((lib) {
return code.Directive.importDeferredAs(lib.package, "${lib.asVariableName}_");
}),
)
);
Library importCode = Library((b) => b
..comments.addAll(["Generated by gen_maters.dart, please don't edit! ", "ignore_for_file: library_prefixes, non_constant_identifier_names"])
..directives.addAll(
noteLibs.map((lib) {
return code.Directive.importDeferredAs(lib.package, "${lib.asVariableName}_");
}),
));

String importCodeFmt = '${importCode.accept(DartEmitter(allocator: Allocator.none, orderDirectives: true, useNullSafetySyntax: true))}';
importCodeFmt = _fmt.format(importCodeFmt);
Expand Down Expand Up @@ -496,7 +494,7 @@ class NoteParseResult {
*/
Future<NoteParseResult> _gen(_NoteInfo source) async {
var cells = source.cells.map((e) {
var comment = e.cellStatements.map((e) => e.toString().replaceAll("\n", " ").safeSubstring(0, 30));
var comment = e.cellStatements.map((e) => strings.safeSubstring(e.toString().replaceAll("\n", " "), 0, 30));

var specialNodes = e.specialNodes.map((e) => """
(
Expand Down
24 changes: 17 additions & 7 deletions notes/flutter_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ dependencies:

analyzer: ^6.4.1

you_note_dart:
path: ../../packages/you_note_dart

note:
path: ../../

path: ^1.8.2
code_builder: ^4.4.0
file: ^7.0.0
Expand All @@ -38,7 +32,11 @@ dependencies:
source_map_stack_trace: ^2.1.1
http: ^1.2.1
source_maps: ^0.10.12

# you_*
you_dart: ^0.0.4
you_flutter: ^0.0.4
you_note_dart: ^0.0.4

dev_dependencies:

Expand Down Expand Up @@ -127,4 +125,16 @@ flutter:
# https://flutter.dev/assets-and-images/#from-packages

# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
# see https://flutter.dev/custom-fonts/#from-packages

dependency_overrides:
# dart CHANGELOG 3.0.0 2023-05-10
# - dart pub publish will no longer warn about dependency_overrides.
# Dependency overrides only take effect in the root package of a resolution.
# - ref: https://github.com/dart-lang/sdk/blob/main/CHANGELOG.md
you_dart:
path: ../../packages/you_dart
you_note_dart:
path: ../../packages/you_note_dart
you_flutter:
path: ../../packages/you_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:meta/meta.dart';
/// 基础包,不依赖其他业务代码
Types types = Types();
Strings strings = Strings();


@experimental
Expand Down Expand Up @@ -55,17 +56,6 @@ base mixin class Types {
}
}

extension type StringExt(String str) {
String safeSubstring(int start, [int? end]) {
end ??= str.length;
end = end <= str.length ? end : str.length;
try {
return str.substring(start, end);
} catch (e) {
throw Exception("$e, string $this");
}
}
}

/// 范型参数只有在类型内才能看见,比如Map Signal内的key, value类型外部是无法看见的,
/// 只能通过钩子传出来
Expand All @@ -87,6 +77,9 @@ final class TypeHook<T> {
bool isNullable() {
return null is T;
}
bool isNullableOf(T t) {
return null is T || t == null;
}

bool isTypeOf(obj) {
return obj is T;
Expand All @@ -106,3 +99,21 @@ class Unique {
String toString() => '[#$name:${shortHash(this)}]';

}

class Strings {
/// content only space、/r/n ...not useful text
bool isBlankText(String str) {
// \s: 匹配任何空白字符,包括空格、制表符、换行符等。
return str.contains(RegExp(r'^\s*$'));
}

String safeSubstring(String str, int start, [int? end]) {
end ??= str.length;
end = end <= str.length ? end : str.length;
try {
return str.substring(start, end);
} catch (e) {
throw Exception("$e, string $this");
}
}
}
2 changes: 1 addition & 1 deletion packages/you_dart/lib/src/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';

import 'package:meta/meta.dart';
import 'package:you_dart/src/_core.dart';
import 'package:you_dart/src/core.dart';

_defaultOnSignalDoNothing(Signal signal) {}

Expand Down
2 changes: 1 addition & 1 deletion packages/you_dart/lib/src/state_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:collection';
import 'dart:convert';

import 'package:meta/meta.dart';
import 'package:you_dart/src/_core.dart';
import 'package:you_dart/src/core.dart';
import 'package:you_dart/src/state.dart';

/// [Store] 的编解码器,为[Store]对象赋予json等的能力, 目前支持
Expand Down
2 changes: 1 addition & 1 deletion packages/you_dart/test/core_types_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:checks/checks.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:you_dart/src/_core.dart';
import 'package:you_dart/src/core.dart';

void main() {
group("types.isType", () {
Expand Down
5 changes: 0 additions & 5 deletions packages/you_note_dart/lib/core.dart

This file was deleted.

Loading

0 comments on commit fbd175b

Please sign in to comment.