Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom script option #128

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
30 changes: 30 additions & 0 deletions example/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "e1e47221e86272429674bec4f1bd36acc4fc7b77"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
base_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
- platform: web
create_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
base_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
9 changes: 9 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ class _MyAppState extends State<MyApp> {
debugPrint('Editor resized $height'),
onSelectionChanged: (sel) =>
debugPrint('index ${sel.index}, range ${sel.length}'),
customModuleConfig: """
blotFormatter: {},
""",
customQuillRegister: """
Quill.register('modules/blotFormatter', QuillBlotFormatter.default);
""",
customScriptTag: """
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/quill-blot-formatter.min.js"></script>
""",
),
),
],
Expand Down
66 changes: 33 additions & 33 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.17.2"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -69,10 +69,10 @@ packages:
dependency: transitive
description:
name: file_picker
sha256: b1729fc96627dd44012d0a901558177418818d6bd428df59dcfeb594e5f66432
sha256: "21145c9c268d54b1f771d8380c195d2d6f655e0567dc1ca2f9c134c02c819e0a"
url: "https://pub.dev"
source: hosted
version: "5.3.2"
version: "5.3.3"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -120,14 +120,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.2"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
lints:
dependency: transitive
description:
Expand All @@ -140,18 +132,18 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -180,17 +172,17 @@ packages:
dependency: transitive
description:
name: pointer_interceptor
sha256: "6aa680b30d96dccef496933d00208ad25f07e047f644dc98ce03ec6141633a9a"
sha256: "7626e034489820fd599380d2bb4d3f4a0a5e3529370b62bfce53ab736b91adb2"
url: "https://pub.dev"
source: hosted
version: "0.9.3+4"
version: "0.9.3+6"
quill_html_editor:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "2.2.4"
version: "2.2.5"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -200,10 +192,10 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -240,10 +232,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.6.0"
typed_data:
dependency: transitive
description:
Expand All @@ -268,38 +260,46 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
webview_flutter:
dependency: transitive
description:
name: webview_flutter
sha256: "789d52bd789373cc1e100fb634af2127e86c99cf9abde09499743270c5de8d00"
sha256: "82f6787d5df55907aa01e49bd9644f4ed1cc82af7a8257dd9947815959d2e755"
url: "https://pub.dev"
source: hosted
version: "4.2.2"
version: "4.2.4"
webview_flutter_android:
dependency: transitive
description:
name: webview_flutter_android
sha256: d936a09fbfd08cb78f7329e0bbacf6158fbdfe24ffc908b22444c07d295eb193
sha256: "9427774649fd3c8b7ff53523051395d13aed2ca355822b822e6493d79f5fc05a"
url: "https://pub.dev"
source: hosted
version: "3.9.2"
version: "3.10.0"
webview_flutter_platform_interface:
dependency: transitive
description:
name: webview_flutter_platform_interface
sha256: "564ef378cafc1a0e29f1d76ce175ef517a0a6115875dff7b43fccbef2b0aeb30"
sha256: "6d9213c65f1060116757a7c473247c60f3f7f332cac33dc417c9e362a9a13e4f"
url: "https://pub.dev"
source: hosted
version: "2.4.0"
version: "2.6.0"
webview_flutter_wkwebview:
dependency: transitive
description:
name: webview_flutter_wkwebview
sha256: "5fa098f28b606f699e8ca52d9e4e11edbbfef65189f5f77ae92703ba5408fd25"
sha256: d2f7241849582da80b79acb03bb936422412ce5c0c79fb5f6a1de5421a5aecc4
url: "https://pub.dev"
source: hosted
version: "3.7.2"
version: "3.7.4"
win32:
dependency: transitive
description:
Expand All @@ -309,5 +309,5 @@ packages:
source: hosted
version: "5.0.3"
sdks:
dart: ">=3.0.0 <4.0.0"
flutter: ">=3.3.0"
dart: ">=3.1.0 <4.0.0"
flutter: ">=3.13.0"
81 changes: 80 additions & 1 deletion lib/src/quill_editor_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class QuillHtmlEditor extends StatefulWidget {
color: Colors.black87,
fontWeight: FontWeight.normal,
),
this.customScriptTag,
this.customQuillRegister,
this.customModuleConfig,
}) : super(key: controller._editorKey);

/// [text] to set initial text to the editor, please use text
Expand Down Expand Up @@ -153,6 +156,78 @@ class QuillHtmlEditor extends StatefulWidget {
/// **Note** due to limitations of flutter webview at the moment, focus doesn't launch the keyboard in mobile, however, it will set the cursor at the end on focus.
final bool? autoFocus;

/// # Use for custom libraries
/// <br>
/// [customScriptTag]<br>
/// [customQuillRegister]<br>
/// [customQuillRegister]<br>
/// <br>
/// [customScriptTag] to set custom script tag for custom libraries
///
/// Ex:
/// For Quill Blot Formatter library https://github.com/Fandom-OSS/quill-blot-formatter
/// <br/>
/// `<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/quill-blot-formatter.min.js"></script>`
///
/// Use in flutter like:
/// ```
/// customScriptTag: """
/// <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/quill-blot-formatter.min.js"></script>
/// """
/// ```
/// You can use multiple libraries
///
final String? customScriptTag;

/// # Use for custom libraries
/// <br>
/// [customScriptTag]<br>
/// [customQuillRegister]<br>
/// [customQuillRegister]<br>
/// <br>
/// [customQuillRegister] to resister custom libraries
///
/// Ex:
/// For Quill Blot Formatter library https://github.com/Fandom-OSS/quill-blot-formatter
/// <br/>
/// `Quill.register('modules/blotFormatter', QuillBlotFormatter.default);`
///
/// Use in flutter like:
/// ```
/// customQuillRegister: """
/// Quill.register('modules/blotFormatter', QuillBlotFormatter.default);
/// """
/// ```
/// You can use multiple libraries
///
final String? customQuillRegister;

/// # Use for custom libraries
/// <br>
/// [customScriptTag]<br>
/// [customQuillRegister]<br>
/// [customQuillRegister]<br>
/// <br>
/// [customQuillRegister] to config the custom module
///
/// Ex:
/// For Quill Blot Formatter library https://github.com/Fandom-OSS/quill-blot-formatter
/// <br/>
/// ```
/// blotFormatter: {
/// },
/// ```
/// Use in flutter like:
/// ```
/// customModuleConfig: """
/// blotFormatter: {
/// },
/// """
/// ```
/// You can use multiple libraries
///
final String? customModuleConfig;

@override
QuillHtmlEditorState createState() => QuillHtmlEditorState();
}
Expand Down Expand Up @@ -570,6 +645,7 @@ class QuillHtmlEditorState extends State<QuillHtmlEditor> {
<script>
$_quillJsScript
</script>
${widget.customScriptTag ?? ""}
<style>
/*!
* Quill Editor v2.0.0-dev.3
Expand Down Expand Up @@ -970,6 +1046,8 @@ class QuillHtmlEditorState extends State<QuillHtmlEditor> {
}
Quill.register(Breaker);

${widget.customQuillRegister ?? ""}

var quilleditor = new Quill('#editor', {
modules: {
toolbar: '#toolbar-container',
Expand All @@ -979,7 +1057,8 @@ class QuillHtmlEditorState extends State<QuillHtmlEditor> {
delay: 2000,
maxStack: 500,
userOnly: false
}
},
${widget.customModuleConfig ?? ""}
},
theme: 'snow',
scrollingContainer: '#scrolling-container',
Expand Down
14 changes: 7 additions & 7 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ dependencies:
flutter_web_plugins:
sdk: flutter
##### For image picker widget
file_picker: ^5.3.2
file_picker: 5.3.3
##### For webveiwx widget
http: ^1.0.0
path: ^1.8.2
pointer_interceptor: ^0.9.3+4
uuid: ^3.0.7
webview_flutter: ^4.2.2
webview_flutter_android: ^3.9.2
webview_flutter_platform_interface: ^2.4.0
webview_flutter_wkwebview: ^3.7.2
pointer_interceptor: ^0.9.3+6
uuid: 3.0.7
webview_flutter: ^4.2.4
webview_flutter_android: ^3.10.0
webview_flutter_platform_interface: ^2.6.0
webview_flutter_wkwebview: ^3.7.4

dev_dependencies:
flutter_test:
Expand Down