Skip to content

Commit

Permalink
Prepare 1.7.0 to pub
Browse files Browse the repository at this point in the history
  • Loading branch information
tneotia committed Mar 17, 2021
1 parent 69a6ded commit 47ce278
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 113 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [1.7.0] - 2021-03-17
* [BREAKING]:
* Refactored `height`, `autoAdjustHeight`, `decoration`, `showBottomToolbar`, and `darkMode` into new `HtmlEditorOptions` class - see README for how to migrate
* Removed 'Summernote Classes' plugin
* Sorry for all the breaking changes lately - I think I've finally figured out how I want to do the API design so there should be far less in future releases
* Added `onImageUpload` callback that fires when an image is inserted via `<input type="file">`
* Added `onImageLinkInsert` callback that fires when an image is inserted via URL
* Added `shouldEnsureVisible` that scrolls the editor into view when it is focused or text is typed, kind of like `TextField`s
* Added `adjustHeightForKeyboard` (default true) that adjusts the editor's height when the keyboard is active to ensure no content is cut off by the keyboard
* Added `filePath` which allows you to provide a completely custom HTML file to load
* If you plan on using any of the above, it is highly recommend looking at the README for more details and examples.
* Removed disabled scroll feature since it prevented the editor from scrolling even when the editor content was larger than the height
* Code cleanup

## [1.6.0] - 2021-03-13
* [BREAKING] removed `dispose()` method on controller
* The editor no longer uses a `Stream` to get text and therefore nothing needs to be disposed
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ More is on the way! File a feature request or contribute to the project if you'd

## Setup

Add `html_editor_enhanced: ^1.6.0` as dependency to your pubspec.yaml
Add `html_editor_enhanced: ^1.7.0` as dependency to your pubspec.yaml

Additional setup is required to allow the user to pick images via `<input type="file">`:

Expand Down Expand Up @@ -248,7 +248,7 @@ Parameter | Type | Default | Description
------------ | ------------- | ------------- | -------------
**height** | `double` | 380 | Height of text editor (does not set the height in HTML yet, only the height of the WebView widget)
**autoAdjustHeight** | `bool` | `true` | Automatically adjust the height of the text editor by analyzing the HTML height once the editor is loaded. Recommended value: `true`. See [below](#autoadjustheight) for more details.
**adjustHeightForKeyboard** | `bool` | `true` | Adjust the height of the editor if the keyboard is active and it overlaps the editor to prevent the overlap. Recommended value: `true`. See [below](#adjustheightforkeyboard) for more details.
**adjustHeightForKeyboard** | `bool` | `true` | Adjust the height of the editor if the keyboard is active and it overlaps the editor to prevent the overlap. Recommended value: `true`, only works on mobile. See [below](#adjustheightforkeyboard) for more details.
**decoration** | `BoxDecoration` | | `BoxDecoration` that surrounds the widget
**showBottomToolbar** | `bool` | true | Show or hide bottom toolbar
**hint** | `String` | empty | Placeholder hint text
Expand Down Expand Up @@ -436,7 +436,7 @@ If this does not help your use case feel free to disable it, but the recommended

### `adjustHeightForKeyboard`

Default value: true
Default value: true, only considered on mobile

This option parameter changes the height of the editor if the keyboard is active and it overlaps with the editor.

Expand Down
28 changes: 14 additions & 14 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ class _HtmlEditorExampleState extends State<HtmlEditorExample> {
controller: controller,
hint: "Your text here...",
//initialText: "<p>text content initial, if any</p>",
options: HtmlEditorOptions(
height: 450,
shouldEnsureVisible: true
),
options:
HtmlEditorOptions(height: 450, shouldEnsureVisible: true),
callbacks: Callbacks(
onChange: (String? changed) {
print("content changed to $changed");
Expand Down Expand Up @@ -137,23 +135,25 @@ class _HtmlEditorExampleState extends State<HtmlEditorExample> {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextButton(
style:
TextButton.styleFrom(backgroundColor: Colors.blueGrey),
style: TextButton.styleFrom(
backgroundColor: Colors.blueGrey),
onPressed: () {
controller.undo();
},
child: Text("Undo", style: TextStyle(color: Colors.white)),
child:
Text("Undo", style: TextStyle(color: Colors.white)),
),
SizedBox(
width: 16,
),
TextButton(
style:
TextButton.styleFrom(backgroundColor: Colors.blueGrey),
style: TextButton.styleFrom(
backgroundColor: Colors.blueGrey),
onPressed: () {
controller.clear();
},
child: Text("Reset", style: TextStyle(color: Colors.white)),
child:
Text("Reset", style: TextStyle(color: Colors.white)),
),
SizedBox(
width: 16,
Expand Down Expand Up @@ -205,13 +205,13 @@ class _HtmlEditorExampleState extends State<HtmlEditorExample> {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextButton(
style:
TextButton.styleFrom(backgroundColor: Colors.blueGrey),
style: TextButton.styleFrom(
backgroundColor: Colors.blueGrey),
onPressed: () {
controller.disable();
},
child:
Text("Disable", style: TextStyle(color: Colors.white)),
child: Text("Disable",
style: TextStyle(color: Colors.white)),
),
SizedBox(
width: 16,
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.6.0"
version: "1.7.0"
js:
dependency: transitive
description:
Expand Down
4 changes: 3 additions & 1 deletion lib/src/html_editor_controller_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ class HtmlEditorController extends unsupported.HtmlEditorController {
/// accommodate the keyboard. This should only be used on mobile, and only
/// when [adjustHeightForKeyboard] is enabled.
void resetHeight() {
_evaluateJavascript(source: "console.log('_HtmlEditorWidgetMobileState().resetHeight();');");
_evaluateJavascript(
source:
"console.log('_HtmlEditorWidgetMobileState().resetHeight();');");
}

/// Reloads the IFrameElement, throws an exception on mobile
Expand Down
82 changes: 48 additions & 34 deletions lib/src/widgets/html_editor_widget_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
if (widget.options.filePath != null) {
filePath = widget.options.filePath!;
} else if (widget.plugins.isEmpty) {
filePath = 'packages/html_editor_enhanced/assets/summernote-no-plugins.html';
filePath =
'packages/html_editor_enhanced/assets/summernote-no-plugins.html';
} else {
filePath = 'packages/html_editor_enhanced/assets/summernote.html';
}
Expand All @@ -78,6 +79,7 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
super.dispose();
}

/// resets the height of the editor to the original height
void resetHeight() async {
setState(() {
if (docHeight != null) {
Expand All @@ -86,8 +88,8 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
actualHeight = widget.options.height + 125;
}
});
await controllerMap[widget.controller].evaluateJavascript(source:
"\$('div.note-editable').height(${widget.options.height});");
await controllerMap[widget.controller].evaluateJavascript(
source: "\$('div.note-editable').height(${widget.options.height});");
}

@override
Expand Down Expand Up @@ -116,8 +118,8 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
},
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
javaScriptEnabled: true,
transparentBackground: true,
javaScriptEnabled: true,
transparentBackground: true,
),
android: AndroidInAppWebViewOptions(
useHybridComposition: true,
Expand All @@ -129,14 +131,16 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
},
onConsoleMessage: (controller, message) {
print(message.message);
if (message.message == "_HtmlEditorWidgetMobileState().resetHeight();")
if (message.message ==
"_HtmlEditorWidgetMobileState().resetHeight();")
resetHeight();
},
onWindowFocus: (controller) async {
if (widget.options.shouldEnsureVisible && Scrollable.of(context) != null) {
if (widget.options.shouldEnsureVisible &&
Scrollable.of(context) != null) {
Scrollable.of(context)!.position.ensureVisible(
context.findRenderObject()!,
);
context.findRenderObject()!,
);
}
if (widget.options.adjustHeightForKeyboard) {
visibleStream.stream.drain();
Expand All @@ -145,10 +149,12 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
if (docHeight != null) {
newHeight = (docHeight! + 40) * visibleDecimal;
} else {
newHeight = (widget.options.height + 125) * visibleDecimal;
newHeight =
(widget.options.height + 125) * visibleDecimal;
}
await controller.evaluateJavascript(source:
"\$('div.note-editable').height(${max(widget.options.height - (actualHeight - newHeight) - 10, 30)});");
await controller.evaluateJavascript(
source:
"\$('div.note-editable').height(${max(widget.options.height - (actualHeight - newHeight) - 10, 30)});");
setState(() {
if (docHeight != null) {
actualHeight = newHeight;
Expand All @@ -158,7 +164,8 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
});
}
},
onLoadStop: (InAppWebViewController controller, Uri? uri) async {
onLoadStop:
(InAppWebViewController controller, Uri? uri) async {
String url = uri.toString();
if (url.contains(filePath)) {
String summernoteToolbar = "[\n";
Expand Down Expand Up @@ -190,11 +197,13 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
},
""";
if (p.onSelect != null) {
controllerMap[widget.controller].addJavaScriptHandler(
handlerName: 'onSelectMention',
callback: (value) {
p.onSelect!.call(value.first.toString());
});
controllerMap[widget.controller]
.addJavaScriptHandler(
handlerName: 'onSelectMention',
callback: (value) {
p.onSelect!
.call(value.first.toString());
});
}
}
if (p is SummernoteFile) {
Expand All @@ -212,27 +221,30 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
window.flutter_inappwebview.callHandler('onFileUpload', JSON.stringify(newObject));
},
""";
controllerMap[widget.controller].addJavaScriptHandler(
handlerName: 'onFileUpload',
callback: (files) {
FileUpload file =
fileUploadFromJson(files.first);
p.onFileUpload!.call(file);
});
controllerMap[widget.controller]
.addJavaScriptHandler(
handlerName: 'onFileUpload',
callback: (files) {
FileUpload file =
fileUploadFromJson(files.first);
p.onFileUpload!.call(file);
});
}
}
}
}
if (widget.callbacks != null) {
if (widget.callbacks!.onImageLinkInsert != null) {
summernoteCallbacks = summernoteCallbacks + """
summernoteCallbacks = summernoteCallbacks +
"""
onImageLinkInsert: function(url) {
window.flutter_inappwebview.callHandler('onImageLinkInsert', url);
},
""";
}
if (widget.callbacks!.onImageUpload != null) {
summernoteCallbacks = summernoteCallbacks + """
summernoteCallbacks = summernoteCallbacks +
"""
onImageUpload: function(files) {
var newObject = {
'lastModified': files[0].lastModified,
Expand Down Expand Up @@ -304,13 +316,16 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
controller.addJavaScriptHandler(
handlerName: 'onChange',
callback: (contents) {
if (widget.options.shouldEnsureVisible && Scrollable.of(context) != null) {
if (widget.options.shouldEnsureVisible &&
Scrollable.of(context) != null) {
Scrollable.of(context)!.position.ensureVisible(
context.findRenderObject()!,
);
context.findRenderObject()!,
);
}
if (widget.callbacks != null && widget.callbacks!.onChange != null) {
widget.callbacks!.onChange!.call(contents.first.toString());
if (widget.callbacks != null &&
widget.callbacks!.onChange != null) {
widget.callbacks!.onChange!
.call(contents.first.toString());
}
});
}
Expand Down Expand Up @@ -425,8 +440,7 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
controllerMap[widget.controller].addJavaScriptHandler(
handlerName: 'onImageUpload',
callback: (files) {
FileUpload file =
fileUploadFromJson(files.first);
FileUpload file = fileUploadFromJson(files.first);
c.onImageUpload!.call(file);
});
}
Expand Down
Loading

0 comments on commit 47ce278

Please sign in to comment.