Skip to content
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
20 changes: 7 additions & 13 deletions lib/html_editor.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
library html_editor;

export 'package:flutter_inappwebview/flutter_inappwebview.dart';
export 'package:html_editor_enhanced/src/html_editor.dart'
if (dart.library.html) 'package:html_editor_enhanced/src/html_editor_web.dart';
export 'package:html_editor_enhanced/src/html_editor_controller.dart'
if (dart.library.html) 'package:html_editor_enhanced/src/html_editor_controller_web.dart';
export 'package:html_editor_enhanced/src/widgets/toolbar_widget.dart';
export 'package:html_editor_enhanced/utils/callbacks.dart';
export 'package:html_editor_enhanced/utils/toolbar.dart';
export 'package:html_editor_enhanced/utils/plugins.dart';
export 'package:html_editor_enhanced/utils/file_upload_model.dart';
export 'package:html_editor_enhanced/utils/options.dart';
export 'package:html_editor_enhanced/utils/plugins.dart';
export 'package:html_editor_enhanced/utils/toolbar.dart';
export 'package:html_editor_enhanced/utils/utils.dart'
hide setState, intersperse, getRandString;

export 'package:html_editor_enhanced/src/html_editor_unsupported.dart'
if (dart.library.html) 'package:html_editor_enhanced/src/html_editor_web.dart'
if (dart.library.io) 'package:html_editor_enhanced/src/html_editor_mobile.dart';

export 'package:html_editor_enhanced/src/html_editor_controller_unsupported.dart'
if (dart.library.html) 'package:html_editor_enhanced/src/html_editor_controller_web.dart'
if (dart.library.io) 'package:html_editor_enhanced/src/html_editor_controller_mobile.dart';

export 'package:html_editor_enhanced/utils/shims/flutter_inappwebview_fake.dart'
if (dart.library.io) 'package:flutter_inappwebview/flutter_inappwebview.dart';

/// Defines the 3 different cases for file insertion failing
enum UploadError { unsupportedFile, exceededMaxSize, jsException }

Expand Down
8 changes: 4 additions & 4 deletions lib/src/html_editor_mobile.dart → lib/src/html_editor.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:html_editor_enhanced/html_editor.dart'
hide HtmlEditorController;
import 'package:html_editor_enhanced/src/html_editor_controller_mobile.dart';
import 'package:html_editor_enhanced/src/widgets/html_editor_widget_mobile.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:html_editor_enhanced/html_editor.dart'
hide HtmlEditorController;
import 'package:html_editor_enhanced/src/html_editor_controller.dart';
import 'package:html_editor_enhanced/src/widgets/html_editor_widget.dart';

/// HtmlEditor class for mobile
class HtmlEditor extends StatelessWidget {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:html_editor_enhanced/html_editor.dart';
import 'package:html_editor_enhanced/src/html_editor_controller_unsupported.dart'
as unsupported;

/// Controller for mobile
/// Controller for desktop and mobile
class HtmlEditorController extends unsupported.HtmlEditorController {
HtmlEditorController({
this.processInputHtml = true,
Expand Down Expand Up @@ -58,9 +59,33 @@ class HtmlEditorController extends unsupported.HtmlEditorController {
/// A function to quickly call a document.execCommand function in a readable format
@override
void execCommand(String command, {String? argument}) {
_evaluateJavascript(
source:
"document.execCommand('$command', false${argument == null ? "" : ", '$argument'"});");
if (Platform.isMacOS || Platform.isWindows || Platform.isLinux) {
_evaluateJavascript(source: """
try {
var editor = \$('#summernote-2');
var context = editor.data('summernote');

if (context && context.invoke) {
// Try to restore the saved range first
try {
context.invoke('editor.restoreRange');
} catch (e) {
console.log('No saved range to restore');
}
}

// Apply bold formatting
document.execCommand('$command', false${argument == null ? "" : ", '$argument'"});
} catch (error) {
// Fallback to document.execCommand
document.execCommand('$command', false${argument == null ? "" : ", '$argument'"});
}
""");
} else {
_evaluateJavascript(source: """
document.execCommand('$command', false${argument == null ? "" : ", '$argument'"});
""");
}
}

/// Gets the text from the editor and returns it as a [String].
Expand Down
40 changes: 0 additions & 40 deletions lib/src/html_editor_unsupported.dart

This file was deleted.

4 changes: 2 additions & 2 deletions lib/src/html_editor_web.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:html_editor_enhanced/html_editor.dart';
import 'package:html_editor_enhanced/src/widgets/html_editor_widget_web.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:html_editor_enhanced/html_editor.dart';
import 'package:html_editor_enhanced/src/widgets/html_editor_widget_web.dart';

/// HtmlEditor class for web
class HtmlEditor extends StatelessWidget {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:collection';
import 'dart:math';

import 'package:flutter/foundation.dart';
Expand All @@ -13,7 +12,7 @@ import 'package:html_editor_enhanced/html_editor.dart'
import 'package:html_editor_enhanced/utils/utils.dart';
import 'package:visibility_detector/visibility_detector.dart';

/// The HTML Editor widget itself, for mobile (uses InAppWebView)
/// The HTML Editor widget itself (uses InAppWebView)
class HtmlEditorWidget extends StatefulWidget {
HtmlEditorWidget({
Key? key,
Expand All @@ -33,13 +32,13 @@ class HtmlEditorWidget extends StatefulWidget {
final OtherOptions otherOptions;

@override
_HtmlEditorWidgetMobileState createState() => _HtmlEditorWidgetMobileState();
_HtmlEditorWidgetState createState() => _HtmlEditorWidgetState();
}

/// State for the mobile Html editor widget
/// State for the desktop and mobile Html editor widget
///
/// A stateful widget is necessary here to allow the height to dynamically adjust.
class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
class _HtmlEditorWidgetState extends State<HtmlEditorWidget> {
/// Tracks whether the callbacks were initialized or not to prevent re-initializing them
bool callbacksInitialized = false;

Expand Down Expand Up @@ -147,15 +146,13 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
javaScriptEnabled: true,
transparentBackground: true,
useShouldOverrideUrlLoading: true,
useHybridComposition: widget.htmlEditorOptions
.androidUseHybridComposition,
useHybridComposition:
widget.htmlEditorOptions.androidUseHybridComposition,
loadWithOverviewMode: true,
),
initialUserScripts:
widget.htmlEditorOptions.mobileInitialScripts
as UnmodifiableListView<UserScript>?,
contextMenu: widget.htmlEditorOptions.mobileContextMenu
as ContextMenu?,
widget.htmlEditorOptions.mobileInitialScripts,
contextMenu: widget.htmlEditorOptions.mobileContextMenu,
gestureRecognizers: {
Factory<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer()),
Expand All @@ -167,8 +164,7 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
shouldOverrideUrlLoading: (controller, action) async {
if (!action.request.url.toString().contains(filePath)) {
return (await widget.callbacks?.onNavigationRequestMobile
?.call(action.request.url.toString()))
as NavigationActionPolicy? ??
?.call(action.request.url.toString())) ??
NavigationActionPolicy.ALLOW;
}
return NavigationActionPolicy.ALLOW;
Expand Down Expand Up @@ -213,7 +209,9 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
});
await setHeightJS();
}
var visibleDecimal = await visibleStream.stream.firstWhere((_) => !visibleStream.isClosed, orElse: () => 0);
var visibleDecimal = await visibleStream.stream
.firstWhere((_) => !visibleStream.isClosed,
orElse: () => 0);
var newHeight = widget.otherOptions.height;
if (visibleDecimal > 0.1) {
this.setState(() {
Expand Down Expand Up @@ -376,11 +374,11 @@ class _HtmlEditorWidgetMobileState extends State<HtmlEditorWidget> {
${widget.htmlEditorOptions.customOptions}
$summernoteCallbacks
});

\$('#summernote-2').on('summernote.change', function(_, contents, \$editable) {
window.flutter_inappwebview.callHandler('onChangeContent', contents);
});

function onSelectionChange() {
let {anchorNode, anchorOffset, focusNode, focusOffset} = document.getSelection();
var isBold = false;
Expand Down
Loading