Rich text editor for Flutter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.6 KiB

import 'package:flutter/material.dart';
import '../../../../flutter_quill.dart';
/// The [T] is the options for the button
/// The [E] is the extra options for the button
Fix block multi-line selection style (#1876) * toggle_style_button : calls to options.afterButtonPressed replaced by call to class function afterButtonPressed to allow default call to base button settings quill_icon_button: L26 build for isSelected updated to call afterButtonPressed = same as if not selected QuillController _updateSelection removed param=source because not used; added new param insertNewline when true set tog to style of preceding char (last entered); updated replaceText to call _updateSelection for NL document collectStyle: Selecting the start of a line, user expects the style to be the visible style of the line including inline styles * color_button calls afterButtonPressed insert at start of line uses style for line * Remove comments * Fix formatting issue * Fix FontFamily and Size button actions * Fix FontFamily and Size button actions * Value setting Stateful toolbar buttons derive from base class * Rename base class as QuillToolbarBaseValueButton * Fixes for before_push script * Removed deprecated functions * Move clipboard actions to QuillController * Fix: collectAllIndividualStylesAndEmbed for result span * Add: Clipboard toolbar buttons * export: Clipboard toolbar buttons * Fix: Dividers not shown in toolbar when multiRowsDisplay. Fix: Toolbar drop buttons clipped when !multiRowsDisplay * Add: test for QuillController clipboard Dart Formatted * Localizations updated * QuillControllerConfigurations and clipboard paste * Fix: CheckList action * Fix: Multiline selection and refactor toolbar buttons * Add tests: Multiline selection --------- Co-authored-by: Douglas Ward <dward@scied.com>
11 months ago
abstract class QuillToolbarBaseButton<
T extends QuillToolbarBaseButtonOptions<T, E>,
E extends QuillToolbarBaseButtonExtraOptions> extends StatefulWidget {
Fix block multi-line selection style (#1876) * toggle_style_button : calls to options.afterButtonPressed replaced by call to class function afterButtonPressed to allow default call to base button settings quill_icon_button: L26 build for isSelected updated to call afterButtonPressed = same as if not selected QuillController _updateSelection removed param=source because not used; added new param insertNewline when true set tog to style of preceding char (last entered); updated replaceText to call _updateSelection for NL document collectStyle: Selecting the start of a line, user expects the style to be the visible style of the line including inline styles * color_button calls afterButtonPressed insert at start of line uses style for line * Remove comments * Fix formatting issue * Fix FontFamily and Size button actions * Fix FontFamily and Size button actions * Value setting Stateful toolbar buttons derive from base class * Rename base class as QuillToolbarBaseValueButton * Fixes for before_push script * Removed deprecated functions * Move clipboard actions to QuillController * Fix: collectAllIndividualStylesAndEmbed for result span * Add: Clipboard toolbar buttons * export: Clipboard toolbar buttons * Fix: Dividers not shown in toolbar when multiRowsDisplay. Fix: Toolbar drop buttons clipped when !multiRowsDisplay * Add: test for QuillController clipboard Dart Formatted * Localizations updated * QuillControllerConfigurations and clipboard paste * Fix: CheckList action * Fix: Multiline selection and refactor toolbar buttons * Add tests: Multiline selection --------- Co-authored-by: Douglas Ward <dward@scied.com>
11 months ago
const QuillToolbarBaseButton(
{required this.controller, required this.options, super.key});
final T options;
final QuillController controller;
}
/// The [W] is the widget that creates this State
Fix block multi-line selection style (#1876) * toggle_style_button : calls to options.afterButtonPressed replaced by call to class function afterButtonPressed to allow default call to base button settings quill_icon_button: L26 build for isSelected updated to call afterButtonPressed = same as if not selected QuillController _updateSelection removed param=source because not used; added new param insertNewline when true set tog to style of preceding char (last entered); updated replaceText to call _updateSelection for NL document collectStyle: Selecting the start of a line, user expects the style to be the visible style of the line including inline styles * color_button calls afterButtonPressed insert at start of line uses style for line * Remove comments * Fix formatting issue * Fix FontFamily and Size button actions * Fix FontFamily and Size button actions * Value setting Stateful toolbar buttons derive from base class * Rename base class as QuillToolbarBaseValueButton * Fixes for before_push script * Removed deprecated functions * Move clipboard actions to QuillController * Fix: collectAllIndividualStylesAndEmbed for result span * Add: Clipboard toolbar buttons * export: Clipboard toolbar buttons * Fix: Dividers not shown in toolbar when multiRowsDisplay. Fix: Toolbar drop buttons clipped when !multiRowsDisplay * Add: test for QuillController clipboard Dart Formatted * Localizations updated * QuillControllerConfigurations and clipboard paste * Fix: CheckList action * Fix: Multiline selection and refactor toolbar buttons * Add tests: Multiline selection --------- Co-authored-by: Douglas Ward <dward@scied.com>
11 months ago
abstract class QuillToolbarCommonButtonState<
W extends QuillToolbarBaseButton<T, E>,
T extends QuillToolbarBaseButtonOptions<T, E>,
Fix block multi-line selection style (#1876) * toggle_style_button : calls to options.afterButtonPressed replaced by call to class function afterButtonPressed to allow default call to base button settings quill_icon_button: L26 build for isSelected updated to call afterButtonPressed = same as if not selected QuillController _updateSelection removed param=source because not used; added new param insertNewline when true set tog to style of preceding char (last entered); updated replaceText to call _updateSelection for NL document collectStyle: Selecting the start of a line, user expects the style to be the visible style of the line including inline styles * color_button calls afterButtonPressed insert at start of line uses style for line * Remove comments * Fix formatting issue * Fix FontFamily and Size button actions * Fix FontFamily and Size button actions * Value setting Stateful toolbar buttons derive from base class * Rename base class as QuillToolbarBaseValueButton * Fixes for before_push script * Removed deprecated functions * Move clipboard actions to QuillController * Fix: collectAllIndividualStylesAndEmbed for result span * Add: Clipboard toolbar buttons * export: Clipboard toolbar buttons * Fix: Dividers not shown in toolbar when multiRowsDisplay. Fix: Toolbar drop buttons clipped when !multiRowsDisplay * Add: test for QuillController clipboard Dart Formatted * Localizations updated * QuillControllerConfigurations and clipboard paste * Fix: CheckList action * Fix: Multiline selection and refactor toolbar buttons * Add tests: Multiline selection --------- Co-authored-by: Douglas Ward <dward@scied.com>
11 months ago
E extends QuillToolbarBaseButtonExtraOptions> extends State<W> {
T get options => widget.options;
QuillController get controller => widget.controller;
Fix block multi-line selection style (#1876) * toggle_style_button : calls to options.afterButtonPressed replaced by call to class function afterButtonPressed to allow default call to base button settings quill_icon_button: L26 build for isSelected updated to call afterButtonPressed = same as if not selected QuillController _updateSelection removed param=source because not used; added new param insertNewline when true set tog to style of preceding char (last entered); updated replaceText to call _updateSelection for NL document collectStyle: Selecting the start of a line, user expects the style to be the visible style of the line including inline styles * color_button calls afterButtonPressed insert at start of line uses style for line * Remove comments * Fix formatting issue * Fix FontFamily and Size button actions * Fix FontFamily and Size button actions * Value setting Stateful toolbar buttons derive from base class * Rename base class as QuillToolbarBaseValueButton * Fixes for before_push script * Removed deprecated functions * Move clipboard actions to QuillController * Fix: collectAllIndividualStylesAndEmbed for result span * Add: Clipboard toolbar buttons * export: Clipboard toolbar buttons * Fix: Dividers not shown in toolbar when multiRowsDisplay. Fix: Toolbar drop buttons clipped when !multiRowsDisplay * Add: test for QuillController clipboard Dart Formatted * Localizations updated * QuillControllerConfigurations and clipboard paste * Fix: CheckList action * Fix: Multiline selection and refactor toolbar buttons * Add tests: Multiline selection --------- Co-authored-by: Douglas Ward <dward@scied.com>
11 months ago
QuillToolbarBaseButtonOptions? get baseButtonExtraOptions =>
context.quillToolbarBaseButtonOptions;
String get defaultTooltip;
String get tooltip =>
options.tooltip ?? baseButtonExtraOptions?.tooltip ?? defaultTooltip;
double get iconSize =>
options.iconSize ?? baseButtonExtraOptions?.iconSize ?? kDefaultIconSize;
double get iconButtonFactor =>
options.iconButtonFactor ??
baseButtonExtraOptions?.iconButtonFactor ??
kDefaultIconButtonFactor;
QuillIconTheme? get iconTheme =>
options.iconTheme ?? baseButtonExtraOptions?.iconTheme;
VoidCallback? get afterButtonPressed =>
options.afterButtonPressed ??
baseButtonExtraOptions?.afterButtonPressed ??
() => controller.editorFocusNode?.requestFocus();
}
/// The [W] is the widget that creates this State
/// The [V] is the type of the currentValue
abstract class QuillToolbarBaseButtonState<
W extends QuillToolbarBaseButton<T, E>,
T extends QuillToolbarBaseButtonOptions<T, E>,
E extends QuillToolbarBaseButtonExtraOptions,
V> extends QuillToolbarCommonButtonState<W, T, E> {
V? _currentValue;
V get currentValue => _currentValue!;
set currentValue(V value) => _currentValue = value;
/// Callback to query the widget's state for the value to be assigned to currentState
V get currentStateValue;
@override
void initState() {
super.initState();
controller.addListener(didChangeEditingValue);
addExtraListener();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
currentValue = currentStateValue;
}
void didChangeEditingValue() {
setState(() => currentValue = currentStateValue);
}
@override
void dispose() {
controller.removeListener(didChangeEditingValue);
removeExtraListener(widget);
super.dispose();
}
@override
void didUpdateWidget(covariant W oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.controller != controller) {
oldWidget.controller.removeListener(didChangeEditingValue);
removeExtraListener(oldWidget);
controller.addListener(didChangeEditingValue);
addExtraListener();
currentValue = currentStateValue;
}
}
/// Extra listeners allow a subclass to listen to an external event that can affect its currentValue
void addExtraListener() {}
void removeExtraListener(covariant W oldWidget) {}
}
Fix block multi-line selection style (#1876) * toggle_style_button : calls to options.afterButtonPressed replaced by call to class function afterButtonPressed to allow default call to base button settings quill_icon_button: L26 build for isSelected updated to call afterButtonPressed = same as if not selected QuillController _updateSelection removed param=source because not used; added new param insertNewline when true set tog to style of preceding char (last entered); updated replaceText to call _updateSelection for NL document collectStyle: Selecting the start of a line, user expects the style to be the visible style of the line including inline styles * color_button calls afterButtonPressed insert at start of line uses style for line * Remove comments * Fix formatting issue * Fix FontFamily and Size button actions * Fix FontFamily and Size button actions * Value setting Stateful toolbar buttons derive from base class * Rename base class as QuillToolbarBaseValueButton * Fixes for before_push script * Removed deprecated functions * Move clipboard actions to QuillController * Fix: collectAllIndividualStylesAndEmbed for result span * Add: Clipboard toolbar buttons * export: Clipboard toolbar buttons * Fix: Dividers not shown in toolbar when multiRowsDisplay. Fix: Toolbar drop buttons clipped when !multiRowsDisplay * Add: test for QuillController clipboard Dart Formatted * Localizations updated * QuillControllerConfigurations and clipboard paste * Fix: CheckList action * Fix: Multiline selection and refactor toolbar buttons * Add tests: Multiline selection --------- Co-authored-by: Douglas Ward <dward@scied.com>
11 months ago
typedef QuillToolbarToggleStyleBaseButton = QuillToolbarBaseButton<
QuillToolbarToggleStyleButtonOptions,
QuillToolbarToggleStyleButtonExtraOptions>;
typedef QuillToolbarToggleStyleBaseButtonState<
W extends QuillToolbarToggleStyleBaseButton>
Fix block multi-line selection style (#1876) * toggle_style_button : calls to options.afterButtonPressed replaced by call to class function afterButtonPressed to allow default call to base button settings quill_icon_button: L26 build for isSelected updated to call afterButtonPressed = same as if not selected QuillController _updateSelection removed param=source because not used; added new param insertNewline when true set tog to style of preceding char (last entered); updated replaceText to call _updateSelection for NL document collectStyle: Selecting the start of a line, user expects the style to be the visible style of the line including inline styles * color_button calls afterButtonPressed insert at start of line uses style for line * Remove comments * Fix formatting issue * Fix FontFamily and Size button actions * Fix FontFamily and Size button actions * Value setting Stateful toolbar buttons derive from base class * Rename base class as QuillToolbarBaseValueButton * Fixes for before_push script * Removed deprecated functions * Move clipboard actions to QuillController * Fix: collectAllIndividualStylesAndEmbed for result span * Add: Clipboard toolbar buttons * export: Clipboard toolbar buttons * Fix: Dividers not shown in toolbar when multiRowsDisplay. Fix: Toolbar drop buttons clipped when !multiRowsDisplay * Add: test for QuillController clipboard Dart Formatted * Localizations updated * QuillControllerConfigurations and clipboard paste * Fix: CheckList action * Fix: Multiline selection and refactor toolbar buttons * Add tests: Multiline selection --------- Co-authored-by: Douglas Ward <dward@scied.com>
11 months ago
= QuillToolbarBaseButtonState<W, QuillToolbarToggleStyleButtonOptions,
QuillToolbarToggleStyleButtonExtraOptions, bool>;