Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added text color attribute #352

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions packages/notus/lib/src/document/attributes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,20 @@ abstract class NotusAttributeBuilder<T> implements NotusAttributeKey<T> {
///
/// * [NotusAttribute.bold]
/// * [NotusAttribute.italic]
/// * [NotusAttribute.strikethrough]
/// * [NotusAttribute.link]
/// * [NotusAttribute.heading]
/// * [NotusAttribute.block]
class NotusAttribute<T> implements NotusAttributeBuilder<T> {
static final Map<String, NotusAttributeBuilder> _registry = {
NotusAttribute.bold.key: NotusAttribute.bold,
NotusAttribute.italic.key: NotusAttribute.italic,
NotusAttribute.strikethrough.key: NotusAttribute.strikethrough,
NotusAttribute.link.key: NotusAttribute.link,
NotusAttribute.heading.key: NotusAttribute.heading,
NotusAttribute.block.key: NotusAttribute.block,
NotusAttribute.embed.key: NotusAttribute.embed,
NotusAttribute.color.key: NotusAttribute.color,
};

// Inline attributes
Expand All @@ -88,10 +91,46 @@ class NotusAttribute<T> implements NotusAttributeBuilder<T> {
/// Italic style attribute.
static const italic = _ItalicAttribute();

/// Italic style attribute.
static const strikethrough = _StrikeThroughAttribute();

/// Link style attribute.
// ignore: const_eval_throws_exception
static const link = LinkAttributeBuilder._();

//color style attribute
static const color = ColorAttributeBuilder._();

/// Aliases for [NotusAttribute.color.<color_foo>].
static NotusAttribute<String> get cPink => color.pink;
static NotusAttribute<String> get cNeonPink => color.neonPink;
static NotusAttribute<String> get cMaroonRed => color.maroonRed;
static NotusAttribute<String> get cCherryRed => color.cherryRed;
static NotusAttribute<String> get cCoralRed => color.coralRed;
static NotusAttribute<String> get cMahogany => color.mahogany;

static NotusAttribute<String> get cOrange => color.orange;

static NotusAttribute<String> get cYellow => color.yellow;
static NotusAttribute<String> get cNeonYellow => color.neonYellow;

static NotusAttribute<String> get cForestGreen => color.forestGreen;
static NotusAttribute<String> get cAppleGreen => color.appleGreen;
static NotusAttribute<String> get cTeaGreen => color.teaGreen;
static NotusAttribute<String> get cNeonGreen => color.neonGreen;
static NotusAttribute<String> get cTealGreen => color.tealGreen;

static NotusAttribute<String> get cLBlue => color.lightBlue;
static NotusAttribute<String> get cOceanBlue => color.oceanBlue;
static NotusAttribute<String> get cLilBlue => color.lilBlue;
static NotusAttribute<String> get cNavyBlue => color.navyBlue;

static NotusAttribute<String> get cPlum => color.plum;
static NotusAttribute<String> get cNeonPurple => color.neonPurple;
static NotusAttribute<String> get cSuedePurple => color.suedePurple;
static NotusAttribute<String> get cOrchidPurple => color.orchidPurple;


// Line attributes

/// Heading style attribute.
Expand Down Expand Up @@ -332,6 +371,11 @@ class _ItalicAttribute extends NotusAttribute<bool> {
const _ItalicAttribute() : super._('i', NotusAttributeScope.inline, true);
}

/// Applies strikethrough style to a text segment.
class _StrikeThroughAttribute extends NotusAttribute<bool> {
const _StrikeThroughAttribute() : super._('st', NotusAttributeScope.inline, true);
}

/// Builder for link attribute values.
///
/// There is no need to use this class directly, consider using
Expand Down Expand Up @@ -364,6 +408,43 @@ class HeadingAttributeBuilder extends NotusAttributeBuilder<int> {
NotusAttribute<int> get level3 => NotusAttribute<int>._(key, scope, 3);
}

/// Builder for color attribute styles.

class ColorAttributeBuilder extends NotusAttributeBuilder<String> {
static const _kColor = 'color';
const ColorAttributeBuilder._()
: super._(_kColor, NotusAttributeScope.inline);

NotusAttribute<String> get pink => NotusAttribute<String>._(key, scope, "ffbcbc");
NotusAttribute<String> get neonPink => NotusAttribute<String>._(key, scope, "ff3796");
NotusAttribute<String> get maroonRed => NotusAttribute<String>._(key, scope, "751011");
NotusAttribute<String> get cherryRed => NotusAttribute<String>._(key, scope, "e43f5a");
NotusAttribute<String> get coralRed => NotusAttribute<String>._(key, scope, "f47c7c");
NotusAttribute<String> get mahogany => NotusAttribute<String>._(key, scope, "B64003");

NotusAttribute<String> get orange => NotusAttribute<String>._(key, scope, "FE8C03");

NotusAttribute<String> get yellow => NotusAttribute<String>._(key, scope, "f7f48b");
NotusAttribute<String> get neonYellow => NotusAttribute<String>._(key, scope, "fdff38");

NotusAttribute<String> get forestGreen => NotusAttribute<String>._(key, scope, "004a18");
NotusAttribute<String> get appleGreen => NotusAttribute<String>._(key, scope, "a1de93");
NotusAttribute<String> get teaGreen => NotusAttribute<String>._(key, scope, "acecd5");
NotusAttribute<String> get neonGreen => NotusAttribute<String>._(key, scope, "00faac");
NotusAttribute<String> get tealGreen => NotusAttribute<String>._(key, scope, "048481");

NotusAttribute<String> get lightBlue => NotusAttribute<String>._(key, scope, "beebe9");
NotusAttribute<String> get oceanBlue => NotusAttribute<String>._(key, scope, "2ECFFF");
NotusAttribute<String> get lilBlue => NotusAttribute<String>._(key, scope, "70a1d7");
NotusAttribute<String> get navyBlue => NotusAttribute<String>._(key, scope, "162447");

NotusAttribute<String> get plum => NotusAttribute<String>._(key, scope, "d7aefc");
NotusAttribute<String> get neonPurple => NotusAttribute<String>._(key, scope, "dc2ade");
NotusAttribute<String> get suedePurple => NotusAttribute<String>._(key, scope, "834c69");
NotusAttribute<String> get orchidPurple => NotusAttribute<String>._(key, scope, "543864");

}

/// Builder for block attribute styles (number/bullet lists, code and quote).
///
/// There is no need to use this class directly, consider using
Expand Down
10 changes: 5 additions & 5 deletions packages/zefyr/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'package:flutter/services.dart';

import 'src/form.dart';
import 'src/full_page.dart';
import 'src/view.dart';
import 'src/text_field_page.dart';
import 'src/view.dart';

void main() {
runApp(ZefyrApp());
Expand Down Expand Up @@ -35,10 +35,10 @@ class ZefyrApp extends StatelessWidget {
title: 'Zefyr Editor',
home: HomePage(),
routes: {
"/fullPage": buildFullPage,
"/form": buildFormPage,
"/view": buildViewPage,
"/textinput": buildTextFieldPage,
'/fullPage': buildFullPage,
'/form': buildFormPage,
'/view': buildViewPage,
'/textinput': buildTextFieldPage,
},
);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/zefyr/example/lib/quick_start.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class QuickStartApp extends StatelessWidget {
title: 'Quick Start',
home: HomePage(),
routes: {
"/editor": (context) => EditorPage(),
'/editor': (context) => EditorPage(),
},
);
}
Expand All @@ -27,11 +27,11 @@ class HomePage extends StatelessWidget {
Widget build(BuildContext context) {
final navigator = Navigator.of(context);
return Scaffold(
appBar: AppBar(title: Text("Quick Start")),
appBar: AppBar(title: Text('Quick Start')),
body: Center(
child: FlatButton(
child: Text("Open editor"),
onPressed: () => navigator.pushNamed("/editor"),
child: Text('Open editor'),
onPressed: () => navigator.pushNamed('/editor'),
),
),
);
Expand Down
12 changes: 6 additions & 6 deletions packages/zefyr/example/lib/src/editor_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EditorPageState extends State<EditorPage> {

@override
Widget build(BuildContext context) {
final Widget body = (_controller == null)
final body = (_controller == null)
? Center(child: CircularProgressIndicator())
: ZefyrScaffold(
child: ZefyrEditor(
Expand All @@ -42,7 +42,7 @@ class EditorPageState extends State<EditorPage> {

return Scaffold(
appBar: AppBar(
title: Text("Editor page"),
title: Text('Editor page'),
actions: <Widget>[
Builder(
builder: (context) => IconButton(
Expand All @@ -59,14 +59,14 @@ class EditorPageState extends State<EditorPage> {
/// Loads the document asynchronously from a file if it exists, otherwise
/// returns default document.
Future<NotusDocument> _loadDocument() async {
final file = File(Directory.systemTemp.path + "/quick_start.json");
final file = File(Directory.systemTemp.path + '/quick_start.json');
if (await file.exists()) {
final contents = await file
.readAsString()
.then((data) => Future.delayed(Duration(seconds: 1), () => data));
return NotusDocument.fromJson(jsonDecode(contents));
}
final Delta delta = Delta()..insert("Zefyr Quick Start\n");
final delta = Delta()..insert('Zefyr Quick Start\n');
return NotusDocument.fromDelta(delta);
}

Expand All @@ -75,10 +75,10 @@ class EditorPageState extends State<EditorPage> {
// `jsonEncode` directly:
final contents = jsonEncode(_controller.document);
// For this example we save our document to a temporary file.
final file = File(Directory.systemTemp.path + "/quick_start.json");
final file = File(Directory.systemTemp.path + '/quick_start.json');
// And show a snack bar on success.
file.writeAsString(contents).then((_) {
Scaffold.of(context).showSnackBar(SnackBar(content: Text("Saved.")));
Scaffold.of(context).showSnackBar(SnackBar(content: Text('Saved.')));
});
}
}
7 changes: 5 additions & 2 deletions packages/zefyr/example/lib/src/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class _FormEmbeddedScreenState extends State<FormEmbeddedScreen> {
children: <Widget>[
TextField(decoration: InputDecoration(labelText: 'Name')),
buildEditor(),
TextField(decoration: InputDecoration(labelText: 'Email')),
TextField(
decoration: InputDecoration(labelText: 'Details'),
maxLines: 3,
),
],
);

Expand Down Expand Up @@ -81,7 +84,7 @@ class _FormEmbeddedScreenState extends State<FormEmbeddedScreen> {
return [
CheckedPopupMenuItem(
value: _Options.darkTheme,
child: Text("Dark theme"),
child: Text('Dark theme'),
checked: _darkTheme,
),
];
Expand Down
2 changes: 1 addition & 1 deletion packages/zefyr/example/lib/src/full_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class _FullPageEditorScreenState extends State<FullPageEditorScreen> {
return [
CheckedPopupMenuItem(
value: _Options.darkTheme,
child: Text("Dark theme"),
child: Text('Dark theme'),
checked: _darkTheme,
),
];
Expand Down
5 changes: 3 additions & 2 deletions packages/zefyr/example/lib/src/images.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class CustomImageDelegate implements ZefyrImageDelegate<ImageSource> {

@override
Future<String> pickImage(ImageSource source) async {
final file = await ImagePicker.pickImage(source: source);
final picker = ImagePicker();
final file = await picker.getImage(source: source);
if (file == null) return null;
return file.uri.toString();
return file.path;
}

@override
Expand Down
2 changes: 1 addition & 1 deletion packages/zefyr/example/lib/src/text_field_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class _TextFieldScreenState extends State<TextFieldScreen> {
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: _singleTextFieldcontroller,
maxLines: 1000,
maxLines: 10,
),
),
],
Expand Down
2 changes: 1 addition & 1 deletion packages/zefyr/example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: d8ba9b3e9e93c62c74a660b46c6fcb09f03991a7

COCOAPODS: 1.8.4
COCOAPODS: 1.9.3
Loading