From 6f14b469b1bbae19a4f03b9d7a437a3893789932 Mon Sep 17 00:00:00 2001 From: TheRealWelshCJ Date: Thu, 8 Aug 2019 19:01:50 +0100 Subject: [PATCH 1/6] Added custom attribute --- .vscode/launch.json | 14 ++++++++++++++ packages/notus/example/main.dart | 3 ++- .../notus/lib/src/document/attributes.dart | 18 ++++++++++++------ 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..2f9d5e5ca --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Notus", + "program": "packages/notus/example/main.dart", + "request": "launch", + "type": "dart" + } + ] +} \ No newline at end of file diff --git a/packages/notus/example/main.dart b/packages/notus/example/main.dart index cf17d8d9f..a31ebdba4 100644 --- a/packages/notus/example/main.dart +++ b/packages/notus/example/main.dart @@ -6,6 +6,7 @@ import 'package:notus/notus.dart'; void main() { final doc = new NotusDocument(); + // Modify this document with insert, delete and format operations doc.insert( 0, 'Notus package provides rich text document model for Zefyr editor'); @@ -24,4 +25,4 @@ void main() { // Dispose resources allocated by this document, e.g. closes "changes" stream. // After document is closed it cannot be modified. doc.close(); -} +} \ No newline at end of file diff --git a/packages/notus/lib/src/document/attributes.dart b/packages/notus/lib/src/document/attributes.dart index 8070a1fc9..70579d50b 100644 --- a/packages/notus/lib/src/document/attributes.dart +++ b/packages/notus/lib/src/document/attributes.dart @@ -93,7 +93,7 @@ class NotusAttribute implements NotusAttributeBuilder { // Line attributes /// Heading style attribute. - static const heading = const HeadingAttributeBuilder._(); + static const heading = const HeadingAttributeBuilder._(); /// Alias for [NotusAttribute.heading.level1]. static NotusAttribute get h1 => heading.level1; @@ -103,7 +103,7 @@ class NotusAttribute implements NotusAttributeBuilder { /// Alias for [NotusAttribute.heading.level3]. static NotusAttribute get h3 => heading.level3; - + /// Block attribute static const block = const BlockAttributeBuilder._(); @@ -130,6 +130,11 @@ class NotusAttribute implements NotusAttributeBuilder { return builder.withValue(value); } + // NotusAttribute.register(String key, NotusAttributeScope scope, dynamic value){ + // print ('trying to register [\'$key\']: $value'); + // ._(key, scope, value); + // } + const NotusAttribute._(this.key, this.scope, this.value); /// Unique key of this attribute. @@ -194,7 +199,7 @@ class NotusStyle { if (data == null) return new NotusStyle(); final result = data.map((String key, dynamic value) { - var attr = NotusAttribute._fromKeyValue(key, value); + var attr = NotusAttribute._fromKeyValue(key, value) ?? 'test'; return new MapEntry(key, attr); }); return new NotusStyle._(result); @@ -360,9 +365,10 @@ class HeadingAttributeBuilder extends NotusAttributeBuilder { /// [NotusAttribute.block] instead. class BlockAttributeBuilder extends NotusAttributeBuilder { static const _kBlock = 'block'; - const BlockAttributeBuilder._() : super._(_kBlock, NotusAttributeScope.line); + + const BlockAttributeBuilder._() : super._(_kBlock, NotusAttributeScope.inline); - /// Formats a block of lines as a bullet list. + /// Formats a block of lines as a bullet list. NotusAttribute get bulletList => new NotusAttribute._(key, scope, 'ul'); @@ -399,7 +405,7 @@ class EmbedAttributeBuilder /// Type of embedded content. enum EmbedType { horizontalRule, image } - +//TODO:Chris: make this a custom attribute class EmbedAttribute extends NotusAttribute> { static const _kValueEquality = const MapEquality(); static const _kEmbed = 'embed'; From 4bba21280a83987f2ee214259c0f7c370fe54234 Mon Sep 17 00:00:00 2001 From: TheRealWelshCJ Date: Thu, 8 Aug 2019 19:03:06 +0100 Subject: [PATCH 2/6] Added custom attribute --- packages/notus/example/main.dart | 1 + packages/notus/lib/src/document/attributes.dart | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/notus/example/main.dart b/packages/notus/example/main.dart index a31ebdba4..03f0e463c 100644 --- a/packages/notus/example/main.dart +++ b/packages/notus/example/main.dart @@ -12,6 +12,7 @@ void main() { 0, 'Notus package provides rich text document model for Zefyr editor'); doc.format(0, 5, NotusAttribute.bold); // Makes first word bold. doc.format(0, 0, NotusAttribute.h1); // Makes first line a heading. + doc.format(15, 23, NotusAttribute.custom.withValue('customAttribute')); doc.delete(23, 10); // Deletes "rich text " segment. // Collects style attributes at 1 character in this document. diff --git a/packages/notus/lib/src/document/attributes.dart b/packages/notus/lib/src/document/attributes.dart index 70579d50b..b138b7f1c 100644 --- a/packages/notus/lib/src/document/attributes.dart +++ b/packages/notus/lib/src/document/attributes.dart @@ -77,6 +77,7 @@ class NotusAttribute implements NotusAttributeBuilder { NotusAttribute.heading.key: NotusAttribute.heading, NotusAttribute.block.key: NotusAttribute.block, NotusAttribute.embed.key: NotusAttribute.embed, + NotusAttribute.custom.key: NotusAttribute.custom, }; // Inline attributes @@ -122,6 +123,9 @@ class NotusAttribute implements NotusAttributeBuilder { /// Embed style attribute. static const embed = const EmbedAttributeBuilder._(); + /// Custom attribute. + static final custom = CustomAttributeBuilder._(); + static NotusAttribute _fromKeyValue(String key, dynamic value) { if (!_registry.containsKey(key)) throw new ArgumentError.value( @@ -455,3 +459,16 @@ class EmbedAttribute extends NotusAttribute> { return hashObjects(objects); } } + +/// Builder for custom attributes that do not necessarily need styling. +/// +/// There is no need to use this class directly, consider using +/// [NotusAttribute.custom] instead. +class CustomAttributeBuilder extends NotusAttributeBuilder { + static const _kCustom = 'custom'; + + const CustomAttributeBuilder._() : super._(_kCustom, NotusAttributeScope.inline); + + NotusAttribute withValue(String value) => NotusAttribute._(key, scope, value); +} + From 5d11c94f720576a449406ce9b65bd2671c14783f Mon Sep 17 00:00:00 2001 From: TheRealWelshCJ Date: Thu, 8 Aug 2019 19:03:18 +0100 Subject: [PATCH 3/6] Revert "Added custom attribute" This reverts commit 6f14b469b1bbae19a4f03b9d7a437a3893789932. --- .vscode/launch.json | 14 -------------- packages/notus/example/main.dart | 3 +-- .../notus/lib/src/document/attributes.dart | 18 ++++++------------ 3 files changed, 7 insertions(+), 28 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 2f9d5e5ca..000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Notus", - "program": "packages/notus/example/main.dart", - "request": "launch", - "type": "dart" - } - ] -} \ No newline at end of file diff --git a/packages/notus/example/main.dart b/packages/notus/example/main.dart index 03f0e463c..0c09c843d 100644 --- a/packages/notus/example/main.dart +++ b/packages/notus/example/main.dart @@ -6,7 +6,6 @@ import 'package:notus/notus.dart'; void main() { final doc = new NotusDocument(); - // Modify this document with insert, delete and format operations doc.insert( 0, 'Notus package provides rich text document model for Zefyr editor'); @@ -26,4 +25,4 @@ void main() { // Dispose resources allocated by this document, e.g. closes "changes" stream. // After document is closed it cannot be modified. doc.close(); -} \ No newline at end of file +} diff --git a/packages/notus/lib/src/document/attributes.dart b/packages/notus/lib/src/document/attributes.dart index b138b7f1c..78c3a902b 100644 --- a/packages/notus/lib/src/document/attributes.dart +++ b/packages/notus/lib/src/document/attributes.dart @@ -94,7 +94,7 @@ class NotusAttribute implements NotusAttributeBuilder { // Line attributes /// Heading style attribute. - static const heading = const HeadingAttributeBuilder._(); + static const heading = const HeadingAttributeBuilder._(); /// Alias for [NotusAttribute.heading.level1]. static NotusAttribute get h1 => heading.level1; @@ -104,7 +104,7 @@ class NotusAttribute implements NotusAttributeBuilder { /// Alias for [NotusAttribute.heading.level3]. static NotusAttribute get h3 => heading.level3; - + /// Block attribute static const block = const BlockAttributeBuilder._(); @@ -134,11 +134,6 @@ class NotusAttribute implements NotusAttributeBuilder { return builder.withValue(value); } - // NotusAttribute.register(String key, NotusAttributeScope scope, dynamic value){ - // print ('trying to register [\'$key\']: $value'); - // ._(key, scope, value); - // } - const NotusAttribute._(this.key, this.scope, this.value); /// Unique key of this attribute. @@ -203,7 +198,7 @@ class NotusStyle { if (data == null) return new NotusStyle(); final result = data.map((String key, dynamic value) { - var attr = NotusAttribute._fromKeyValue(key, value) ?? 'test'; + var attr = NotusAttribute._fromKeyValue(key, value); return new MapEntry(key, attr); }); return new NotusStyle._(result); @@ -369,10 +364,9 @@ class HeadingAttributeBuilder extends NotusAttributeBuilder { /// [NotusAttribute.block] instead. class BlockAttributeBuilder extends NotusAttributeBuilder { static const _kBlock = 'block'; - - const BlockAttributeBuilder._() : super._(_kBlock, NotusAttributeScope.inline); + const BlockAttributeBuilder._() : super._(_kBlock, NotusAttributeScope.line); - /// Formats a block of lines as a bullet list. + /// Formats a block of lines as a bullet list. NotusAttribute get bulletList => new NotusAttribute._(key, scope, 'ul'); @@ -409,7 +403,7 @@ class EmbedAttributeBuilder /// Type of embedded content. enum EmbedType { horizontalRule, image } -//TODO:Chris: make this a custom attribute + class EmbedAttribute extends NotusAttribute> { static const _kValueEquality = const MapEquality(); static const _kEmbed = 'embed'; From 2078df6815aee6c554ddfbf243869b620c735bcd Mon Sep 17 00:00:00 2001 From: TheRealWelshCJ Date: Fri, 9 Aug 2019 10:27:46 +0100 Subject: [PATCH 4/6] Added additional comments and updated documentation. --- doc/attributes.md | 7 ++++++- packages/notus/example/main.dart | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/attributes.md b/doc/attributes.md index 0bb3aa581..a66933b9a 100644 --- a/doc/attributes.md +++ b/doc/attributes.md @@ -19,7 +19,8 @@ attribute can be either *inline-scoped* or *line-scoped*, but not both. A good example of an inline-scoped attribute is "bold" attribute. Bold style can be applied to any character within a line, but not to the line itself. Similarly "heading" style is line-scoped and has effect -only on the line as a whole. +only on the line as a whole. A custom *inline-scoped* attributes can be +added for tracking of non-UI based attributes. Below table summarizes information about all currently supported attributes in Zefyr: @@ -32,6 +33,7 @@ attributes in Zefyr: | Heading | `heading` | `line` | `int` | `1`, `2` and `3` | | Block | `block` | `line` | `String` | `"ul"`, `"ol"`, `"code"` and `"quote"` | | Embed | `embed` | `inline` | `Map` | `"hr"`, `"image"` | +| Custom | `custom` | `inline` | `String` | Non-empty string | Removing a specific style is as simple as setting corresponding attribute to `null`. @@ -68,6 +70,9 @@ void makeItPretty(NotusDocument document) { // Remove heading style from the first line. All attributes // have `unset` property which can be used the same way. document.format(0, 0, NotusAttribute.heading.unset); + + // Add a custom attribute that does not reflect in the UI + document.format(15, 23, NotusAttribute.custom.withValue('customAttribute')); } ``` diff --git a/packages/notus/example/main.dart b/packages/notus/example/main.dart index 0c09c843d..a01868100 100644 --- a/packages/notus/example/main.dart +++ b/packages/notus/example/main.dart @@ -11,7 +11,7 @@ void main() { 0, 'Notus package provides rich text document model for Zefyr editor'); doc.format(0, 5, NotusAttribute.bold); // Makes first word bold. doc.format(0, 0, NotusAttribute.h1); // Makes first line a heading. - doc.format(15, 23, NotusAttribute.custom.withValue('customAttribute')); + doc.format(15, 23, NotusAttribute.custom.withValue('customAttribute')); // Adds a non-UI custom attribute doc.delete(23, 10); // Deletes "rich text " segment. // Collects style attributes at 1 character in this document. From bf34d4d4d65722bf1e083b88da96dfd083aa4837 Mon Sep 17 00:00:00 2001 From: Chris O'Shea Date: Fri, 9 Aug 2019 17:32:09 +0100 Subject: [PATCH 5/6] Fixed issue with build due to fonts-droids not downloading --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1dac79aef..ea793170a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ addons: - ubuntu-toolchain-r-test packages: - libstdc++6 - - fonts-droid + - fonts-droid-fallback cache: directories: From 517a9f56ef5f1a64d03892cc36859a12350728ac Mon Sep 17 00:00:00 2001 From: TheRealWelshCJ Date: Tue, 15 Oct 2019 17:23:23 +0100 Subject: [PATCH 6/6] Update .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 62c893550..7708fc00a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea/ \ No newline at end of file +.idea/ +packages/zefyr/example/ios/Flutter/flutter_export_environment.sh