Skip to content

Commit

Permalink
fix(wasm): avoid using quill_controller_web_stub.dart for web which w…
Browse files Browse the repository at this point in the history
…ill throw exception
  • Loading branch information
EchoEllet committed Sep 27, 2024
1 parent 1ec13c5 commit e04dd87
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 43 deletions.
13 changes: 1 addition & 12 deletions lib/src/controller/quill_controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:math' as math;

import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/services.dart' show ClipboardData, Clipboard;
import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart' show experimental;
Expand All @@ -21,9 +20,6 @@ import '../toolbar/config/simple_toolbar_configurations.dart';
import 'quill_controller_configurations.dart';
import 'quill_controller_rich_paste.dart';

import 'web/quill_controller_web_stub.dart'
if (dart.library.html) 'web/quill_controller_web_real.dart';

typedef ReplaceTextCallback = bool Function(int index, int len, Object? data);
typedef DeleteCallback = void Function(int cursorPosition, bool forward);

Expand All @@ -40,11 +36,7 @@ class QuillController extends ChangeNotifier {
this.readOnly = false,
this.editorFocusNode,
}) : _document = document,
_selection = selection {
if (kIsWeb) {
initializeWebPasteEvent();
}
}
_selection = selection;

factory QuillController.basic(
{QuillControllerConfigurations configurations =
Expand Down Expand Up @@ -476,9 +468,6 @@ class QuillController extends ChangeNotifier {
}

_isDisposed = true;
if (kIsWeb) {
cancelWebPasteEvent();
}
super.dispose();
}

Expand Down
64 changes: 33 additions & 31 deletions lib/src/controller/web/quill_controller_web_real.dart
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
// TODO: This might be removed from here or moved to quill_native_bridge

// This file should not be exported as the APIs in it are meant for internal usage only

import 'dart:async' show StreamSubscription;
// import 'dart:async' show StreamSubscription;

import 'package:web/web.dart';
// import 'package:web/web.dart';

import '../quill_controller.dart';
// ignore: unused_import
import '../quill_controller_rich_paste.dart';
// import '../quill_controller.dart';
// // ignore: unused_import
// import '../quill_controller_rich_paste.dart';

/// Paste event for the web.
///
/// Will be `null` when [QuillControllerWeb.initializeWebPasteEvent] was not called
/// or the subscription was canceled due to calling [QuillControllerWeb.cancelWebPasteEvent]
///
/// See: https://developer.mozilla.org/en-US/docs/Web/API/Element/paste_event
StreamSubscription? _webPasteEventSubscription;
// /// Paste event for the web.
// ///
// /// Will be `null` when [QuillControllerWeb.initializeWebPasteEvent] was not called
// /// or the subscription was canceled due to calling [QuillControllerWeb.cancelWebPasteEvent]
// ///
// /// See: https://developer.mozilla.org/en-US/docs/Web/API/Element/paste_event
// StreamSubscription? _webPasteEventSubscription;

extension QuillControllerWeb on QuillController {
void initializeWebPasteEvent() {
_webPasteEventSubscription =
EventStreamProviders.pasteEvent.forTarget(window.document).listen((e) {
// TODO: See if we can support markdown paste
final html = e.clipboardData?.getData('text/html');
if (html == null) {
return;
}
// TODO: Temporarily disable the rich text pasting feature as a workaround
// due to issue https://github.com/singerdmx/flutter-quill/issues/2220
// pasteHTML(html: html);
});
}
// extension QuillControllerWeb on QuillController {
// void initializeWebPasteEvent() {
// _webPasteEventSubscription =
// EventStreamProviders.pasteEvent.forTarget(window.document).listen((e) {
// // TODO: See if we can support markdown paste
// final html = e.clipboardData?.getData('text/html');
// if (html == null) {
// return;
// }
// // TODO: Temporarily disable the rich text pasting feature as a workaround
// // due to issue https://github.com/singerdmx/flutter-quill/issues/2220
// // pasteHTML(html: html);
// });
// }

void cancelWebPasteEvent() {
_webPasteEventSubscription?.cancel();
_webPasteEventSubscription = null;
}
}
// void cancelWebPasteEvent() {
// _webPasteEventSubscription?.cancel();
// _webPasteEventSubscription = null;
// }
// }

0 comments on commit e04dd87

Please sign in to comment.