Skip to content
This repository was archived by the owner on Sep 10, 2026. It is now read-only.

Commit 1441b79

Browse files
committed
feat: customizing portation and export structured quill delta
* Support customizing portation actions by overriding callback. * `BBCodePortationButtonClickedCallback`. * Support export quill delta as `List<Map<String, dynamic>>`. * `toQuillDeltaJson`.
1 parent 300ebed commit 1441b79

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

lib/flutter_bbcode_editor.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export 'src/editor.dart'
77
BBCodeEditorToolbar,
88
BBCodeExt,
99
BBCodeUrlPicker,
10+
BBCodePortationButtonClickedCallback,
1011
PickColorResult,
1112
PickUrlResult,
1213
buildBBCodeEditorController;

lib/src/editor.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:convert';
23
import 'dart:io';
34

lib/src/editor_controller.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
part of 'editor.dart';
22

3+
/// Function as portation button clicked callback.
4+
typedef BBCodePortationButtonClickedCallback =
5+
FutureOr<void> Function(BuildContext context, BBCodeEditorController controller);
6+
37
/// Alias type.
48
typedef BBCodeEditorController = QuillController;
59

@@ -99,6 +103,21 @@ extension BBCodeExt on BBCodeEditorController {
99103
return ret;
100104
}
101105

106+
/// Convert current document to quill delta json object.
107+
List<Map<String, dynamic>> toQuillDeltaJson({bool trimCR = true}) {
108+
if (!trimCR) {
109+
return document.toDelta().toJson();
110+
}
111+
112+
return document
113+
.toDelta()
114+
.operations
115+
.map(
116+
(op) => jsonDecode(jsonEncode(op.toJson()).replaceAll('\r', '')) as Map<String, dynamic>,
117+
)
118+
.toList();
119+
}
120+
102121
/// Convert current document to quill delta.
103122
String toQuillDelta({bool trimCR = true}) {
104123
final data = jsonEncode(document.toDelta().toJson());

lib/src/editor_tool_bar.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class BBCodeEditorToolbar extends StatefulWidget {
6060
BBCodeUrlPicker? urlPicker,
6161
BBCodeImagePicker? imagePicker,
6262
BBCodeUsernamePicker? usernamePicker,
63+
BBCodePortationButtonClickedCallback? onPortationButtonClicked,
6364
String? host,
6465
this.showUndo = true,
6566
this.showRedo = true,
@@ -101,6 +102,7 @@ class BBCodeEditorToolbar extends StatefulWidget {
101102
_urlPicker = urlPicker,
102103
_imagePicker = imagePicker,
103104
_usernamePicker = usernamePicker,
105+
_onPortationButtonClicked = onPortationButtonClicked,
104106
_host = host;
105107

106108
final BBCodeEditorController _controller;
@@ -112,6 +114,7 @@ class BBCodeEditorToolbar extends StatefulWidget {
112114
final BBCodeUrlPicker? _urlPicker;
113115
final BBCodeImagePicker? _imagePicker;
114116
final BBCodeUsernamePicker? _usernamePicker;
117+
final BBCodePortationButtonClickedCallback? _onPortationButtonClicked;
115118

116119
/// The focus node shared with editor.
117120
final FocusNode? focusNode;
@@ -565,7 +568,10 @@ class _BBCodeEditorToolbarState extends State<BBCodeEditorToolbar> {
565568
controller: controller,
566569
options: BBCodePortationButtonOptions(
567570
tooltip: context.bbcodeL10n.portationTitle,
568-
onPressed: () async => openPortationModalBottomSheet(context, widget._controller),
571+
onPressed:
572+
widget._onPortationButtonClicked != null
573+
? () async => widget._onPortationButtonClicked!(context, widget._controller)
574+
: () async => openPortationModalBottomSheet(context, widget._controller),
569575
),
570576
baseOptions: baseOptions,
571577
),

0 commit comments

Comments
 (0)