chore: add toolbar id

This commit is contained in:
Lucas.Xu 2024-08-06 18:02:04 +08:00
commit 4536488faf
13 changed files with 33 additions and 8 deletions

View file

@ -74,7 +74,7 @@ class _DesktopEditorState extends State<DesktopEditor> {
...textDirectionItems, ...textDirectionItems,
...alignmentItems, ...alignmentItems,
], ],
tooltipBuilder: (context, message, child) { tooltipBuilder: (context, _, message, child) {
return Tooltip( return Tooltip(
message: message, message: message,
preferBelow: false, preferBelow: false,

View file

@ -12,6 +12,7 @@ const floatingToolbarItemPrefixKey = 'appflowy_editor_floating_toolbar_item';
typedef ToolbarTooltipBuilder = Widget Function( typedef ToolbarTooltipBuilder = Widget Function(
BuildContext context, BuildContext context,
String id,
String message, String message,
Widget child, Widget child,
); );

View file

@ -60,6 +60,7 @@ class _AlignmentToolbarItem extends ToolbarItem {
if (tooltipBuilder != null) { if (tooltipBuilder != null) {
return tooltipBuilder( return tooltipBuilder(
context, context,
id,
getTooltipText(id), getTooltipText(id),
child, child,
); );

View file

@ -1,7 +1,9 @@
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
const _kBulletedListItemId = 'editor.bulleted_list';
final ToolbarItem bulletedListItem = ToolbarItem( final ToolbarItem bulletedListItem = ToolbarItem(
id: 'editor.bulleted_list', id: _kBulletedListItemId,
group: 3, group: 3,
isActive: onlyShowInSingleSelectionAndTextType, isActive: onlyShowInSingleSelectionAndTextType,
builder: (context, editorState, highlightColor, iconColor, tooltipBuilder) { builder: (context, editorState, highlightColor, iconColor, tooltipBuilder) {
@ -24,6 +26,7 @@ final ToolbarItem bulletedListItem = ToolbarItem(
if (tooltipBuilder != null) { if (tooltipBuilder != null) {
return tooltipBuilder( return tooltipBuilder(
context, context,
_kBulletedListItemId,
AppFlowyEditorL10n.current.bulletedList, AppFlowyEditorL10n.current.bulletedList,
child, child,
); );

View file

@ -1,8 +1,10 @@
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
const _kHighlightColorItemId = 'editor.highlightColor';
ToolbarItem buildHighlightColorItem({List<ColorOption>? colorOptions}) { ToolbarItem buildHighlightColorItem({List<ColorOption>? colorOptions}) {
return ToolbarItem( return ToolbarItem(
id: 'editor.highlightColor', id: _kHighlightColorItemId,
group: 4, group: 4,
isActive: onlyShowInTextType, isActive: onlyShowInTextType,
builder: (context, editorState, highlightColor, iconColor, tooltipBuilder) { builder: (context, editorState, highlightColor, iconColor, tooltipBuilder) {
@ -51,6 +53,7 @@ ToolbarItem buildHighlightColorItem({List<ColorOption>? colorOptions}) {
if (tooltipBuilder != null) { if (tooltipBuilder != null) {
return tooltipBuilder( return tooltipBuilder(
context, context,
_kHighlightColorItemId,
AppFlowyEditorL10n.current.highlightColor, AppFlowyEditorL10n.current.highlightColor,
child, child,
); );

View file

@ -1,10 +1,12 @@
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
const _kTextColorItemId = 'editor.textColor';
ToolbarItem buildTextColorItem({ ToolbarItem buildTextColorItem({
List<ColorOption>? colorOptions, List<ColorOption>? colorOptions,
}) { }) {
return ToolbarItem( return ToolbarItem(
id: 'editor.textColor', id: _kTextColorItemId,
group: 4, group: 4,
isActive: onlyShowInTextType, isActive: onlyShowInTextType,
builder: (context, editorState, highlightColor, iconColor, tooltipBuilder) { builder: (context, editorState, highlightColor, iconColor, tooltipBuilder) {
@ -55,6 +57,7 @@ ToolbarItem buildTextColorItem({
if (tooltipBuilder != null) { if (tooltipBuilder != null) {
return tooltipBuilder( return tooltipBuilder(
context, context,
_kTextColorItemId,
AppFlowyEditorL10n.current.textColor, AppFlowyEditorL10n.current.textColor,
child, child,
); );

View file

@ -58,6 +58,7 @@ class _FormatToolbarItem extends ToolbarItem {
if (tooltipBuilder != null) { if (tooltipBuilder != null) {
return tooltipBuilder( return tooltipBuilder(
context, context,
id,
getTooltipText(id), getTooltipText(id),
child, child,
); );

View file

@ -50,6 +50,7 @@ class _HeadingToolbarItem extends ToolbarItem {
if (tooltipBuilder != null) { if (tooltipBuilder != null) {
return tooltipBuilder( return tooltipBuilder(
context, context,
'editor.h$level',
levelToTooltips(level), levelToTooltips(level),
child, child,
); );

View file

@ -6,9 +6,10 @@ import 'package:string_validator/string_validator.dart';
const _menuWidth = 300; const _menuWidth = 300;
const _hasTextHeight = 244; const _hasTextHeight = 244;
const _noTextHeight = 150; const _noTextHeight = 150;
const _kLinkItemId = 'editor.link';
final linkItem = ToolbarItem( final linkItem = ToolbarItem(
id: 'editor.link', id: _kLinkItemId,
group: 4, group: 4,
isActive: onlyShowInSingleSelectionAndTextType, isActive: onlyShowInSingleSelectionAndTextType,
builder: (context, editorState, highlightColor, iconColor, tooltipBuilder) { builder: (context, editorState, highlightColor, iconColor, tooltipBuilder) {
@ -33,6 +34,7 @@ final linkItem = ToolbarItem(
if (tooltipBuilder != null) { if (tooltipBuilder != null) {
return tooltipBuilder( return tooltipBuilder(
context, context,
_kLinkItemId,
AppFlowyEditorL10n.current.link, AppFlowyEditorL10n.current.link,
child, child,
); );

View file

@ -1,7 +1,9 @@
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
const _kNumberedListItemId = 'editor.numbered_list';
final ToolbarItem numberedListItem = ToolbarItem( final ToolbarItem numberedListItem = ToolbarItem(
id: 'editor.numbered_list', id: _kNumberedListItemId,
group: 3, group: 3,
isActive: onlyShowInSingleSelectionAndTextType, isActive: onlyShowInSingleSelectionAndTextType,
builder: (context, editorState, highlightColor, iconColor, tooltipBuilder) { builder: (context, editorState, highlightColor, iconColor, tooltipBuilder) {
@ -24,6 +26,7 @@ final ToolbarItem numberedListItem = ToolbarItem(
if (tooltipBuilder != null) { if (tooltipBuilder != null) {
return tooltipBuilder( return tooltipBuilder(
context, context,
_kNumberedListItemId,
AppFlowyEditorL10n.current.numberedList, AppFlowyEditorL10n.current.numberedList,
child, child,
); );

View file

@ -1,7 +1,9 @@
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
const _kParagraphItemId = 'editor.paragraph';
final ToolbarItem paragraphItem = ToolbarItem( final ToolbarItem paragraphItem = ToolbarItem(
id: 'editor.paragraph', id: _kParagraphItemId,
group: 1, group: 1,
isActive: onlyShowInSingleSelectionAndTextType, isActive: onlyShowInSingleSelectionAndTextType,
builder: (context, editorState, highlightColor, iconColor, tooltipBuilder) { builder: (context, editorState, highlightColor, iconColor, tooltipBuilder) {
@ -32,6 +34,7 @@ final ToolbarItem paragraphItem = ToolbarItem(
if (tooltipBuilder != null) { if (tooltipBuilder != null) {
return tooltipBuilder( return tooltipBuilder(
context, context,
_kParagraphItemId,
AppFlowyEditorL10n.current.text, AppFlowyEditorL10n.current.text,
child, child,
); );

View file

@ -1,7 +1,9 @@
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
const _kQuoteItemId = 'editor.quote';
final ToolbarItem quoteItem = ToolbarItem( final ToolbarItem quoteItem = ToolbarItem(
id: 'editor.quote', id: _kQuoteItemId,
group: 3, group: 3,
isActive: onlyShowInSingleSelectionAndTextType, isActive: onlyShowInSingleSelectionAndTextType,
builder: (context, editorState, highlightColor, iconColor, tooltipBuilder) { builder: (context, editorState, highlightColor, iconColor, tooltipBuilder) {
@ -24,6 +26,7 @@ final ToolbarItem quoteItem = ToolbarItem(
if (tooltipBuilder != null) { if (tooltipBuilder != null) {
return tooltipBuilder( return tooltipBuilder(
context, context,
_kQuoteItemId,
AppFlowyEditorL10n.current.quote, AppFlowyEditorL10n.current.quote,
child, child,
); );

View file

@ -59,6 +59,7 @@ class _TextDirectionToolbarItem extends ToolbarItem {
if (tooltipBuilder != null) { if (tooltipBuilder != null) {
return tooltipBuilder( return tooltipBuilder(
context, context,
id,
getTooltipText(id), getTooltipText(id),
child, child,
); );