Skip to content

Commit

Permalink
Prepare 1.8.0 to pub
Browse files Browse the repository at this point in the history
  • Loading branch information
tneotia committed Apr 7, 2021
1 parent 7ad205e commit fb16e47
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 142 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## [1.8.0] - 2021-04-07
* Add support for `getSuggestionsMobile` (Summernote @ Mentions Plugin) - allows you to programatically return the list of mentions.
* Only supported on mobile.
* [BREAKING] renamed `mentions` to `mentionsWeb` as a result of this change
* Added support for the remainder of Summernote callbacks:
* `onBeforeCommand`
* `onChangeCodeview`
* `onDialogShown`
* `onImageUploadError`
* `onMouseDown`
* `onMouseUp`
* `onScroll`
* See the README for how these work.
* Added a few new functions:
* recalculateHeight(): recalculates the editor height and applies it
* addNotification(): adds a notification bar to the bottom of the editor in a specified style with specified text
* removeNotification(): removes the current notification from the bottom of the editor
* Fixed blank space at the bottom of the editor when `showBottomToolbar: false`
* Fixed 'Android resource linking failed' (bumped flutter_inappwebview to 5.3.1+1)

## [1.7.1] - 2021-03-26
* Fixed bug where initial text would not be inserted and default toolbar would be shown regardless of editor options
* Significantly improved keyboard height detection (detect when keyboard comes up and goes down)
Expand Down
126 changes: 58 additions & 68 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,27 @@ class _HtmlEditorExampleState extends State<HtmlEditorExample> {
//initialText: "<p>text content initial, if any</p>",
options:
HtmlEditorOptions(height: 450, shouldEnsureVisible: true),
callbacks: Callbacks(
onBeforeCommand: (String? currentHtml) {
print("html before change is $currentHtml");
},
onChange: (String? changed) {
print("content changed to $changed");
},
onChangeCodeview: (String? changed) {
print("code changed to $changed");
},
onDialogShown: () {
print("dialog shown");
},
onEnter: () {
print("enter/return pressed");
},
onFocus: () {
print("editor focused");
},
onBlur: () {
print("editor unfocused");
},
onBlurCodeview: () {
print("codeview either focused or unfocused");
},
onInit: () {
print("init");
},
//this is commented because it overrides the default Summernote handlers
/*onImageLinkInsert: (String? url) {
callbacks: Callbacks(onBeforeCommand: (String? currentHtml) {
print("html before change is $currentHtml");
}, onChange: (String? changed) {
print("content changed to $changed");
}, onChangeCodeview: (String? changed) {
print("code changed to $changed");
}, onDialogShown: () {
print("dialog shown");
}, onEnter: () {
print("enter/return pressed");
}, onFocus: () {
print("editor focused");
}, onBlur: () {
print("editor unfocused");
}, onBlurCodeview: () {
print("codeview either focused or unfocused");
}, onInit: () {
print("init");
},
//this is commented because it overrides the default Summernote handlers
/*onImageLinkInsert: (String? url) {
print(url ?? "unknown url");
},
onImageUpload: (FileUpload file) async {
Expand All @@ -110,35 +101,28 @@ class _HtmlEditorExampleState extends State<HtmlEditorExample> {
print(file.type);
print(file.base64);
},*/
onImageUploadError: (FileUpload? file, String? base64Str,
UploadError error) {
print(describeEnum(error));
print(base64Str ?? "");
if (file != null) {
print(file.name);
print(file.size);
print(file.type);
}
},
onKeyDown: (int? keyCode) {
print("$keyCode key downed");
},
onKeyUp: (int? keyCode) {
print("$keyCode key released");
},
onMouseDown: () {
print("mouse downed");
},
onMouseUp: () {
print("mouse released");
},
onPaste: () {
print("pasted into editor");
},
onScroll: () {
print("editor scrolled");
onImageUploadError: (FileUpload? file, String? base64Str,
UploadError error) {
print(describeEnum(error));
print(base64Str ?? "");
if (file != null) {
print(file.name);
print(file.size);
print(file.type);
}
),
}, onKeyDown: (int? keyCode) {
print("$keyCode key downed");
}, onKeyUp: (int? keyCode) {
print("$keyCode key released");
}, onMouseDown: () {
print("mouse downed");
}, onMouseUp: () {
print("mouse released");
}, onPaste: () {
print("pasted into editor");
}, onScroll: () {
print("editor scrolled");
}),
plugins: [
SummernoteEmoji(),
AdditionalTextTags(),
Expand All @@ -148,8 +132,9 @@ class _HtmlEditorExampleState extends State<HtmlEditorExample> {
SummernoteAtMention(
getSuggestionsMobile: (String value) {
List<String> mentions = ['test1', 'test2', 'test3'];
return mentions.where((element) =>
element.contains(value)).toList();
return mentions
.where((element) => element.contains(value))
.toList();
},
mentionsWeb: ['test1', 'test2', 'test3'],
onSelect: (String value) {
Expand Down Expand Up @@ -356,10 +341,11 @@ class _HtmlEditorExampleState extends State<HtmlEditorExample> {
style: TextButton.styleFrom(
backgroundColor: Colors.blueGrey),
onPressed: () {
controller.addNotification("Info notification", NotificationType.info);
controller.addNotification(
"Info notification", NotificationType.info);
},
child:
Text("Info", style: TextStyle(color: Colors.white)),
Text("Info", style: TextStyle(color: Colors.white)),
),
SizedBox(
width: 16,
Expand All @@ -368,10 +354,11 @@ class _HtmlEditorExampleState extends State<HtmlEditorExample> {
style: TextButton.styleFrom(
backgroundColor: Colors.blueGrey),
onPressed: () {
controller.addNotification("Warning notification", NotificationType.warning);
controller.addNotification(
"Warning notification", NotificationType.warning);
},
child:
Text("Warning", style: TextStyle(color: Colors.white)),
child: Text("Warning",
style: TextStyle(color: Colors.white)),
),
SizedBox(
width: 16,
Expand All @@ -380,7 +367,8 @@ class _HtmlEditorExampleState extends State<HtmlEditorExample> {
style: TextButton.styleFrom(
backgroundColor: Theme.of(context).accentColor),
onPressed: () async {
controller.addNotification("Success notification", NotificationType.success);
controller.addNotification(
"Success notification", NotificationType.success);
},
child: Text(
"Success",
Expand All @@ -394,7 +382,8 @@ class _HtmlEditorExampleState extends State<HtmlEditorExample> {
style: TextButton.styleFrom(
backgroundColor: Theme.of(context).accentColor),
onPressed: () {
controller.addNotification("Danger notification", NotificationType.danger);
controller.addNotification(
"Danger notification", NotificationType.danger);
},
child: Text(
"Danger",
Expand All @@ -414,7 +403,8 @@ class _HtmlEditorExampleState extends State<HtmlEditorExample> {
style: TextButton.styleFrom(
backgroundColor: Colors.blueGrey),
onPressed: () {
controller.addNotification("Plaintext notification", NotificationType.plaintext);
controller.addNotification("Plaintext notification",
NotificationType.plaintext);
},
child: Text("Plaintext",
style: TextStyle(color: Colors.white)),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.7.1"
version: "1.8.0"
js:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion lib/html_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Map<HtmlEditorController, dynamic> controllerMap = {};

/// Manages the notification type for a notification displayed at the bottom of
/// the editor
enum NotificationType {info, warning, success, danger, plaintext}
enum NotificationType { info, warning, success, danger, plaintext }
12 changes: 6 additions & 6 deletions lib/src/html_editor_controller_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,23 @@ class HtmlEditorController extends unsupported.HtmlEditorController {
/// when [adjustHeightForKeyboard] is enabled.
void resetHeight() {
_evaluateJavascript(
source: "window.flutter_inappwebview.callHandler('setHeight', 'reset');");
source:
"window.flutter_inappwebview.callHandler('setHeight', 'reset');");
}

/// Recalculates the height of the editor to remove any vertical scrolling.
/// This method will not do anything if [autoAdjustHeight] is turned off.
void recalculateHeight() {
_evaluateJavascript(
source: "var height = document.body.scrollHeight; window.flutter_inappwebview.callHandler('setHeight', height);");
source:
"var height = document.body.scrollHeight; window.flutter_inappwebview.callHandler('setHeight', height);");
}

/// Add a notification to the bottom of the editor. This is styled similar to
/// Bootstrap alerts. You can set the HTML to be displayed in the alert,
/// and the notificationType determines how the alert is displayed.
void addNotification(String html, NotificationType notificationType) async {
await _evaluateJavascript(
source: """
await _evaluateJavascript(source: """
\$('.note-status-output').html(
'<div class="alert alert-${describeEnum(notificationType)}">$html</div>'
);
Expand All @@ -182,8 +183,7 @@ class HtmlEditorController extends unsupported.HtmlEditorController {

/// Remove the current notification from the bottom of the editor
void removeNotification() async {
await _evaluateJavascript(
source: "\$('.note-status-output').empty();");
await _evaluateJavascript(source: "\$('.note-status-output').empty();");
recalculateHeight();
}

Expand Down
10 changes: 3 additions & 7 deletions lib/src/html_editor_controller_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,8 @@ class HtmlEditorController extends unsupported.HtmlEditorController {
/// and the notificationType determines how the alert is displayed.
void addNotification(String html, NotificationType notificationType) {
if (notificationType == NotificationType.plaintext)
_evaluateJavascriptWeb(data: {
"type": "toIframe: addNotification",
"html": html
});
_evaluateJavascriptWeb(
data: {"type": "toIframe: addNotification", "html": html});
else
_evaluateJavascriptWeb(data: {
"type": "toIframe: addNotification",
Expand All @@ -193,9 +191,7 @@ class HtmlEditorController extends unsupported.HtmlEditorController {

/// Remove the current notification from the bottom of the editor
void removeNotification() {
_evaluateJavascriptWeb(data: {
"type": "toIframe: removeNotification"
});
_evaluateJavascriptWeb(data: {"type": "toIframe: removeNotification"});
recalculateHeight();
}

Expand Down
Loading

0 comments on commit fb16e47

Please sign in to comment.