Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: adjust custom prompt UI (#7966)

Richard Shiue581a2b41a850
diff --git a/frontend/appflowy_flutter/lib/ai/service/ai_entities.dart b/frontend/appflowy_flutter/lib/ai/service/ai_entities.dart
index b5439cb558..e32cb3951c 100644
--- a/frontend/appflowy_flutter/lib/ai/service/ai_entities.dart
+++ b/frontend/appflowy_flutter/lib/ai/service/ai_entities.dart
@@ -1,8 +1,11 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/shared/easy_localiation_service.dart';
+import 'package:appflowy/startup/startup.dart';
import 'package:appflowy_backend/protobuf/flowy-ai/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
+import 'package:collection/collection.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
@@ -113,75 +116,55 @@ enum TextFormat {
}
enum AiPromptCategory {
- @JsonValue("other")
other,
- @JsonValue("development")
development,
- @JsonValue("writing")
writing,
- @JsonValue("healthAndFitness")
healthAndFitness,
- @JsonValue("business")
business,
- @JsonValue("marketing")
marketing,
- @JsonValue("travel")
travel,
- @JsonValue("contentSeo")
contentSeo,
- @JsonValue("emailMarketing")
emailMarketing,
- @JsonValue("paidAds")
paidAds,
- @JsonValue("prCommunication")
prCommunication,
- @JsonValue("recruiting")
recruiting,
- @JsonValue("sales")
sales,
- @JsonValue("socialMedia")
socialMedia,
- @JsonValue("strategy")
strategy,
- @JsonValue("caseStudies")
caseStudies,
- @JsonValue("salesCopy")
salesCopy,
- @JsonValue("education")
education,
- @JsonValue("work")
work,
- @JsonValue("podcastProduction")
podcastProduction,
- @JsonValue("copyWriting")
copyWriting,
- @JsonValue("customerSuccess")
customerSuccess;
- String get i18n {
+ String get i18n => token.tr();
+
+ String get token {
return switch (this) {
- other => LocaleKeys.ai_customPrompt_others.tr(),
- development => LocaleKeys.ai_customPrompt_development.tr(),
- writing => LocaleKeys.ai_customPrompt_writing.tr(),
- healthAndFitness => LocaleKeys.ai_customPrompt_healthAndFitness.tr(),
- business => LocaleKeys.ai_customPrompt_business.tr(),
- marketing => LocaleKeys.ai_customPrompt_marketing.tr(),
- travel => LocaleKeys.ai_customPrompt_travel.tr(),
- contentSeo => LocaleKeys.ai_customPrompt_contentSeo.tr(),
- emailMarketing => LocaleKeys.ai_customPrompt_emailMarketing.tr(),
- paidAds => LocaleKeys.ai_customPrompt_paidAds.tr(),
- prCommunication => LocaleKeys.ai_customPrompt_prCommunication.tr(),
- recruiting => LocaleKeys.ai_customPrompt_recruiting.tr(),
- sales => LocaleKeys.ai_customPrompt_sales.tr(),
- socialMedia => LocaleKeys.ai_customPrompt_socialMedia.tr(),
- strategy => LocaleKeys.ai_customPrompt_strategy.tr(),
- caseStudies => LocaleKeys.ai_customPrompt_caseStudies.tr(),
- salesCopy => LocaleKeys.ai_customPrompt_salesCopy.tr(),
- education => LocaleKeys.ai_customPrompt_education.tr(),
- work => LocaleKeys.ai_customPrompt_work.tr(),
- podcastProduction => LocaleKeys.ai_customPrompt_podcastProduction.tr(),
- copyWriting => LocaleKeys.ai_customPrompt_copyWriting.tr(),
- customerSuccess => LocaleKeys.ai_customPrompt_customerSuccess.tr(),
+ other => LocaleKeys.ai_customPrompt_others,
+ development => LocaleKeys.ai_customPrompt_development,
+ writing => LocaleKeys.ai_customPrompt_writing,
+ healthAndFitness => LocaleKeys.ai_customPrompt_healthAndFitness,
+ business => LocaleKeys.ai_customPrompt_business,
+ marketing => LocaleKeys.ai_customPrompt_marketing,
+ travel => LocaleKeys.ai_customPrompt_travel,
+ contentSeo => LocaleKeys.ai_customPrompt_contentSeo,
+ emailMarketing => LocaleKeys.ai_customPrompt_emailMarketing,
+ paidAds => LocaleKeys.ai_customPrompt_paidAds,
+ prCommunication => LocaleKeys.ai_customPrompt_prCommunication,
+ recruiting => LocaleKeys.ai_customPrompt_recruiting,
+ sales => LocaleKeys.ai_customPrompt_sales,
+ socialMedia => LocaleKeys.ai_customPrompt_socialMedia,
+ strategy => LocaleKeys.ai_customPrompt_strategy,
+ caseStudies => LocaleKeys.ai_customPrompt_caseStudies,
+ salesCopy => LocaleKeys.ai_customPrompt_salesCopy,
+ education => LocaleKeys.ai_customPrompt_education,
+ work => LocaleKeys.ai_customPrompt_work,
+ podcastProduction => LocaleKeys.ai_customPrompt_podcastProduction,
+ copyWriting => LocaleKeys.ai_customPrompt_copyWriting,
+ customerSuccess => LocaleKeys.ai_customPrompt_customerSuccess,
};
}
}
@@ -199,13 +182,28 @@ class AiPrompt extends Equatable {
});
factory AiPrompt.fromPB(CustomPromptPB pb) {
+ final map = _buildCategoryNameMap();
+ final categories = pb.category
+ .split(',')
+ .map((categoryName) => categoryName.trim())
+ .map(
+ (categoryName) {
+ final entry = map.entries.firstWhereOrNull(
+ (entry) =>
+ entry.value.$1 == categoryName ||
+ entry.value.$2 == categoryName,
+ );
+ return entry?.key ?? AiPromptCategory.other;
+ },
+ )
+ .toSet()
+ .toList();
+
return AiPrompt(
id: pb.id,
name: pb.name,
content: pb.content,
- category: AiPromptCategory.values.firstWhere(
- (e) => e.name == pb.category,
- ),
+ category: categories,
example: pb.example,
isFeatured: false,
isCustom: true,
@@ -220,11 +218,8 @@ class AiPrompt extends Equatable {
final String id;
final String name;
final String content;
- @JsonKey(
- unknownEnumValue: AiPromptCategory.other,
- defaultValue: AiPromptCategory.other,
- )
- final AiPromptCategory category;
+ @JsonKey(fromJson: _categoryFromJson)
+ final List<AiPromptCategory> category;
@JsonKey(defaultValue: "")
final String example;
@JsonKey(defaultValue: false)
@@ -235,8 +230,63 @@ class AiPrompt extends Equatable {
@override
List<Object?> get props =>
[id, name, content, category, example, isFeatured, isCustom];
+
+ static Map<AiPromptCategory, (String, String)> _buildCategoryNameMap() {
+ final service = getIt<EasyLocalizationService>();
+ return {
+ for (final category in AiPromptCategory.values)
+ category: (
+ service.getFallbackTranslation(category.token),
+ service.getFallbackTranslation(category.token),
+ ),
+ };
+ }
+
+ static List<AiPromptCategory> _categoryFromJson(dynamic json) {
+ if (json is String) {
+ return json
+ .split(',')
+ .map((categoryName) => categoryName.trim())
+ .map(
+ (categoryName) => $enumDecode(
+ _aiPromptCategoryEnumMap,
+ categoryName,
+ unknownValue: AiPromptCategory.other,
+ ),
+ )
+ .toSet()
+ .toList();
+ }
+
+ return [AiPromptCategory.other];
+ }
}
+const _aiPromptCategoryEnumMap = {
+ AiPromptCategory.other: 'other',
+ AiPromptCategory.development: 'development',
+ AiPromptCategory.writing: 'writing',
+ AiPromptCategory.healthAndFitness: 'healthAndFitness',
+ AiPromptCategory.business: 'business',
+ AiPromptCategory.marketing: 'marketing',
+ AiPromptCategory.travel: 'travel',
+ AiPromptCategory.contentSeo: 'contentSeo',
+ AiPromptCategory.emailMarketing: 'emailMarketing',
+ AiPromptCategory.paidAds: 'paidAds',
+ AiPromptCategory.prCommunication: 'prCommunication',
+ AiPromptCategory.recruiting: 'recruiting',
+ AiPromptCategory.sales: 'sales',
+ AiPromptCategory.socialMedia: 'socialMedia',
+ AiPromptCategory.strategy: 'strategy',
+ AiPromptCategory.caseStudies: 'caseStudies',
+ AiPromptCategory.salesCopy: 'salesCopy',
+ AiPromptCategory.education: 'education',
+ AiPromptCategory.work: 'work',
+ AiPromptCategory.podcastProduction: 'podcastProduction',
+ AiPromptCategory.copyWriting: 'copyWriting',
+ AiPromptCategory.customerSuccess: 'customerSuccess',
+};
+
class CustomPromptDatabaseConfig extends Equatable {
const CustomPromptDatabaseConfig({
required this.view,
diff --git a/frontend/appflowy_flutter/lib/ai/service/ai_prompt_selector_cubit.dart b/frontend/appflowy_flutter/lib/ai/service/ai_prompt_selector_cubit.dart
index 2679ad7598..e8275b686a 100644
--- a/frontend/appflowy_flutter/lib/ai/service/ai_prompt_selector_cubit.dart
+++ b/frontend/appflowy_flutter/lib/ai/service/ai_prompt_selector_cubit.dart
@@ -80,6 +80,11 @@ class AiPromptSelectorCubit extends Cubit<AiPromptSelectorState> {
);
}
}
+ } else {
+ final view = await getDatabaseView(configuration.view.id);
+ if (view != null) {
+ configuration = configuration.copyWith(view: view);
+ }
}
if (configuration == null) {
@@ -182,7 +187,8 @@ class AiPromptSelectorCubit extends Cubit<AiPromptSelectorState> {
ready: (readyState) {
final prompts = category == null
? availablePrompts
- : availablePrompts.where((prompt) => prompt.category == category);
+ : availablePrompts
+ .where((prompt) => prompt.category.contains(category));
final visiblePrompts = _getFilteredPrompts(prompts);
final selectedPromptId = _getVisibleSelectedPrompt(
@@ -333,7 +339,7 @@ class AiPromptSelectorCubit extends Cubit<AiPromptSelectorState> {
Iterable<AiPrompt> _getPromptsByCategory(_AiPromptSelectorReadyState state) {
return availablePrompts.where((prompt) {
if (state.selectedCategory != null) {
- return prompt.category == state.selectedCategory;
+ return prompt.category.contains(state.selectedCategory);
}
if (state.isFeaturedSectionSelected) {
return prompt.isFeatured;
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_category_list.dart b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_category_list.dart
index 56e5f51245..91bea332be 100644
--- a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_category_list.dart
+++ b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_category_list.dart
@@ -68,7 +68,10 @@ class _AiPromptCategoryListState extends State<AiPromptCategoryList> {
static Iterable<AiPromptCategory> get sortedCategories {
final categories = [...AiPromptCategory.values];
- categories.sort((a, b) => a.i18n.compareTo(b.i18n));
+ categories
+ ..sort((a, b) => a.i18n.compareTo(b.i18n))
+ ..remove(AiPromptCategory.other)
+ ..add(AiPromptCategory.other);
return categories;
}
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_database_modal.dart b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_database_modal.dart
index a878563cb7..de777b3c10 100644
--- a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_database_modal.dart
+++ b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_database_modal.dart
@@ -239,6 +239,7 @@ class _HeaderState extends State<_Header> {
),
boxShadow: theme.shadow.medium,
),
+ padding: EdgeInsets.zero,
anchor: AFAnchor(
childAlignment: Alignment.topCenter,
overlayAlignment: Alignment.bottomCenter,
@@ -356,11 +357,15 @@ class _Expanded extends StatelessWidget {
title: LocaleKeys.ai_customPrompt_title.tr(),
currentFieldId: selectedState.config.titleFieldId,
isDisabled: true,
+ fields: selectedState.fields,
onSelect: (id) {},
),
FieldSelector(
title: LocaleKeys.ai_customPrompt_content.tr(),
currentFieldId: selectedState.config.contentFieldId,
+ fields: selectedState.fields
+ .where((f) => f.fieldType == FieldType.RichText)
+ .toList(),
onSelect: (id) {
if (id != null) {
context
@@ -373,6 +378,9 @@ class _Expanded extends StatelessWidget {
title: LocaleKeys.ai_customPrompt_example.tr(),
currentFieldId: selectedState.config.exampleFieldId,
isOptional: true,
+ fields: selectedState.fields
+ .where((f) => f.fieldType == FieldType.RichText)
+ .toList(),
onSelect: (id) {
context
.read<AiPromptDatabaseSelectorCubit>()
@@ -383,6 +391,14 @@ class _Expanded extends StatelessWidget {
title: LocaleKeys.ai_customPrompt_category.tr(),
currentFieldId: selectedState.config.categoryFieldId,
isOptional: true,
+ fields: selectedState.fields
+ .where(
+ (f) =>
+ f.fieldType == FieldType.RichText ||
+ f.fieldType == FieldType.SingleSelect ||
+ f.fieldType == FieldType.MultiSelect,
+ )
+ .toList(),
onSelect: (id) {
context
.read<AiPromptDatabaseSelectorCubit>()
@@ -508,6 +524,7 @@ class FieldSelector extends StatefulWidget {
required this.currentFieldId,
this.isDisabled = false,
this.isOptional = false,
+ this.fields = const [],
required this.onSelect,
});
@@ -515,6 +532,7 @@ class FieldSelector extends StatefulWidget {
final String? currentFieldId;
final bool isDisabled;
final bool isOptional;
+ final List<FieldPB> fields;
final void Function(String? id)? onSelect;
@override
@@ -534,124 +552,114 @@ class _FieldSelectorState extends State<FieldSelector> {
Widget build(BuildContext context) {
final theme = AppFlowyTheme.of(context);
- return BlocBuilder<AiPromptDatabaseSelectorCubit,
- AiPromptDatabaseSelectorState>(
- builder: (context, state) {
- final fields = _getVisibleFields(state);
- final selectedField = fields.firstWhereOrNull(
- (field) => field.id == widget.currentFieldId,
- );
+ final selectedField = widget.fields.firstWhereOrNull(
+ (field) => field.id == widget.currentFieldId,
+ );
- return Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- widget.title,
- style: theme.textStyle.body.standard(
- color: theme.textColorScheme.secondary,
- ),
+ return Row(
+ spacing: theme.spacing.s,
+ children: [
+ Expanded(
+ child: Text(
+ widget.title,
+ style: theme.textStyle.body.standard(
+ color: theme.textColorScheme.secondary,
),
- AFPopover(
- controller: popoverController,
- decoration: BoxDecoration(
- color: theme.surfaceColorScheme.primary,
- borderRadius: BorderRadius.circular(theme.borderRadius.l),
- border: Border.all(
- color: theme.borderColorScheme.primary,
- ),
- boxShadow: theme.shadow.medium,
- ),
- anchor: AFAnchor(
- childAlignment: Alignment.topRight,
- overlayAlignment: Alignment.bottomRight,
- offset: Offset(0, theme.spacing.xs),
- ),
- popover: (context) {
- return ConstrainedBox(
- constraints: const BoxConstraints(maxWidth: 240),
- child: ListView.builder(
- itemCount: fields.length + (widget.isOptional ? 1 : 0),
- shrinkWrap: true,
- padding: EdgeInsets.all(theme.spacing.m),
- itemBuilder: (context, index) {
- if (widget.isOptional && index == 0) {
- return AFTextMenuItem(
- title: LocaleKeys.ai_customPrompt_selectField.tr(),
- onTap: () {
- widget.onSelect?.call(null);
- popoverController.hide();
- },
- trailing: selectedField == null
- ? FlowySvg(
- FlowySvgs.check_s,
- size: const Size.square(20),
- color: theme.fillColorScheme.themeThick,
- )
- : null,
- );
- }
- final field = fields[index - (widget.isOptional ? 1 : 0)];
- return AFTextMenuItem(
- title: field.name,
- trailing: field.id == selectedField?.id
- ? FlowySvg(
- FlowySvgs.check_s,
- size: const Size.square(20),
- color: theme.fillColorScheme.themeThick,
- )
- : null,
- onTap: () {
- widget.onSelect?.call(field.id);
- popoverController.hide();
- },
- );
+ ),
+ ),
+ AFPopover(
+ controller: popoverController,
+ decoration: BoxDecoration(
+ color: theme.surfaceColorScheme.primary,
+ borderRadius: BorderRadius.circular(theme.borderRadius.l),
+ border: Border.all(
+ color: theme.borderColorScheme.primary,
+ ),
+ boxShadow: theme.shadow.medium,
+ ),
+ padding: EdgeInsets.zero,
+ anchor: AFAnchor(
+ childAlignment: Alignment.topCenter,
+ overlayAlignment: Alignment.bottomCenter,
+ offset: Offset(0, theme.spacing.xs),
+ ),
+ popover: (context) {
+ return ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 200),
+ child: ListView.builder(
+ itemCount: widget.fields.length,
+ shrinkWrap: true,
+ padding: EdgeInsets.all(theme.spacing.m),
+ itemBuilder: (context, index) {
+ final field = widget.fields[index];
+ return AFTextMenuItem(
+ title: field.name,
+ trailing: field.id == selectedField?.id
+ ? FlowySvg(
+ FlowySvgs.check_s,
+ size: const Size.square(20),
+ color: theme.fillColorScheme.themeThick,
+ )
+ : null,
+ onTap: () {
+ widget.onSelect?.call(field.id);
+ popoverController.hide();
},
- ),
- );
- },
- child: AFOutlinedButton.normal(
- disabled: widget.isDisabled,
- builder: (context, isHovering, disabled) {
- return Row(
- children: [
- Text(
- selectedField?.name ??
- LocaleKeys.ai_customPrompt_selectField.tr(),
- style: theme.textStyle.body.enhanced(
- color: disabled
- ? theme.textColorScheme.tertiary
- : selectedField == null
- ? theme.textColorScheme.secondary
- : theme.textColorScheme.primary,
- ),
- ),
- HSpace(
- theme.spacing.s,
- ),
- FlowySvg(
- FlowySvgs.toolbar_arrow_down_m,
- size: Size(12, 20),
- ),
- ],
);
},
- onTap: () => popoverController.toggle(),
),
- ),
- ],
- );
- },
- );
- }
-
- List<FieldPB> _getVisibleFields(AiPromptDatabaseSelectorState state) {
- return state.maybeMap(
- orElse: () => [],
- selected: (value) {
- return value.fields
- .where((field) => field.fieldType == FieldType.RichText)
- .toList();
- },
+ );
+ },
+ child: AFOutlinedButton.normal(
+ disabled: widget.isDisabled,
+ builder: (context, isHovering, disabled) {
+ return Row(
+ children: [
+ Text(
+ selectedField?.name ??
+ LocaleKeys.ai_customPrompt_selectField.tr(),
+ style: theme.textStyle.body.enhanced(
+ color: disabled
+ ? theme.textColorScheme.tertiary
+ : selectedField == null
+ ? theme.textColorScheme.secondary
+ : theme.textColorScheme.primary,
+ ),
+ ),
+ HSpace(
+ theme.spacing.s,
+ ),
+ FlowySvg(
+ FlowySvgs.toolbar_arrow_down_m,
+ size: Size(12, 20),
+ ),
+ ],
+ );
+ },
+ onTap: () => popoverController.toggle(),
+ ),
+ ),
+ if (widget.isOptional)
+ AFGhostButton.normal(
+ onTap: () {
+ widget.onSelect?.call(null);
+ },
+ padding: EdgeInsets.all(theme.spacing.xs),
+ disabled: widget.currentFieldId == null ||
+ !widget.fields.map((f) => f.id).contains(widget.currentFieldId),
+ builder: (context, isHovering, disabled) {
+ return FlowySvg(
+ FlowySvgs.eraser_m,
+ size: const Size.square(20),
+ color: disabled
+ ? theme.iconColorScheme.tertiary
+ : theme.iconColorScheme.primary,
+ );
+ },
+ )
+ else
+ const SizedBox.square(dimension: 28),
+ ],
);
}
}
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_preview.dart b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_preview.dart
index dc024195c8..371d712d8a 100644
--- a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_preview.dart
+++ b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_preview.dart
@@ -106,7 +106,7 @@ class _PromptContent extends StatelessWidget {
return Container(
padding: EdgeInsets.all(theme.spacing.l),
decoration: BoxDecoration(
- color: theme.fillColorScheme.contentVisible,
+ color: theme.surfaceContainerColorScheme.layer01,
borderRadius: BorderRadius.circular(theme.borderRadius.m),
),
child: Text.rich(
@@ -176,7 +176,7 @@ class _PromptExample extends StatelessWidget {
return Container(
padding: EdgeInsets.all(theme.spacing.l),
decoration: BoxDecoration(
- color: theme.fillColorScheme.contentVisible,
+ color: theme.surfaceContainerColorScheme.layer01,
borderRadius: BorderRadius.circular(theme.borderRadius.m),
),
child: AIMarkdownText(
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_visible_list.dart b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_visible_list.dart
index b904e792fe..84f3674a73 100644
--- a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_visible_list.dart
+++ b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_visible_list.dart
@@ -211,10 +211,13 @@ class _AiPromptVisibleListState extends State<AiPromptVisibleList> {
.read<AiPromptSelectorCubit>()
.filterTextController
.clear(),
- child: FlowySvg(
- FlowySvgs.toast_close_s,
- color: theme.textColorScheme.secondary,
- size: const Size.square(20),
+ child: MouseRegion(
+ cursor: SystemMouseCursors.click,
+ child: FlowySvg(
+ FlowySvgs.search_clear_m,
+ color: theme.iconColorScheme.tertiary,
+ size: const Size.square(20),
+ ),
),
),
),
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/select_sources_bottom_sheet.dart b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/select_sources_bottom_sheet.dart
index cbfdf933e7..08aad06a09 100644
--- a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/select_sources_bottom_sheet.dart
+++ b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/select_sources_bottom_sheet.dart
@@ -11,6 +11,7 @@ import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
@@ -66,6 +67,8 @@ class _PromptInputMobileSelectSourcesButtonState
@override
Widget build(BuildContext context) {
+ final theme = AppFlowyTheme.of(context);
+
return BlocBuilder<UserWorkspaceBloc, UserWorkspaceState>(
builder: (context, state) {
final userProfile = context.read<UserWorkspaceBloc>().state.userProfile;
@@ -112,7 +115,7 @@ class _PromptInputMobileSelectSourcesButtonState
await showMobileBottomSheet<void>(
context,
- backgroundColor: Theme.of(context).colorScheme.surface,
+ backgroundColor: theme.surfaceColorScheme.primary,
maxChildSize: 0.98,
enableDraggableScrollable: true,
scrollableWidgetBuilder: (_, scrollController) {
@@ -163,7 +166,7 @@ class _MobileSelectSourcesSheetBody extends StatelessWidget {
pinned: true,
delegate: _Header(
child: ColoredBox(
- color: Theme.of(context).cardColor,
+ color: AppFlowyTheme.of(context).surfaceColorScheme.primary,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_markdown_text.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_markdown_text.dart
index 41d5846ed0..df92a94052 100644
--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_markdown_text.dart
+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_markdown_text.dart
@@ -162,6 +162,7 @@ class _AppFlowyEditorMarkdownState extends State<_AppFlowyEditorMarkdown>
// the editor is not editable in the chat
editable: false,
alwaysDistributeSimpleTableColumnWidths: UniversalPlatform.isDesktop,
+ customPadding: (node) => EdgeInsets.zero,
);
return IntrinsicHeight(
child: AppFlowyEditor(
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart
index 78b414462a..2f7a941836 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart
@@ -84,6 +84,7 @@ Map<String, BlockComponentBuilder> buildBlockComponentBuilders({
placeholderText: placeholderText,
alwaysDistributeSimpleTableColumnWidths:
alwaysDistributeSimpleTableColumnWidths,
+ customHeadingPadding: customPadding,
);
// customize the action builder. actually, we can customize them in their own builder. Put them here just for convenience.
@@ -297,7 +298,7 @@ Map<String, BlockComponentBuilder> _buildBlockComponentBuilderMap(
required EditorStyleCustomizer styleCustomizer,
ShowPlaceholder? showParagraphPlaceholder,
String Function(Node)? placeholderText,
- EdgeInsets? customHeadingPadding,
+ EdgeInsets Function(Node)? customHeadingPadding,
bool alwaysDistributeSimpleTableColumnWidths = false,
}) {
final customBlockComponentBuilderMap = {
@@ -641,7 +642,7 @@ HeadingBlockComponentBuilder _buildHeadingBlockComponentBuilder(
BuildContext context,
BlockComponentConfiguration configuration,
EditorStyleCustomizer styleCustomizer,
- EdgeInsets? customHeadingPadding,
+ EdgeInsets Function(Node)? customHeadingPadding,
) {
return HeadingBlockComponentBuilder(
configuration: configuration.copyWith(
@@ -653,7 +654,7 @@ HeadingBlockComponentBuilder _buildHeadingBlockComponentBuilder(
),
padding: (node) {
if (customHeadingPadding != null) {
- return customHeadingPadding;
+ return customHeadingPadding.call(node);
}
if (UniversalPlatform.isMobile) {
@@ -902,13 +903,13 @@ ToggleListBlockComponentBuilder _buildToggleListBlockComponentBuilder(
BuildContext context,
BlockComponentConfiguration configuration,
EditorStyleCustomizer styleCustomizer,
- EdgeInsets? customHeadingPadding,
+ EdgeInsets Function(Node)? customHeadingPadding,
) {
return ToggleListBlockComponentBuilder(
configuration: configuration.copyWith(
padding: (node) {
if (customHeadingPadding != null) {
- return customHeadingPadding;
+ return customHeadingPadding(node);
}
if (UniversalPlatform.isMobile) {
diff --git a/frontend/appflowy_flutter/lib/shared/easy_localiation_service.dart b/frontend/appflowy_flutter/lib/shared/easy_localiation_service.dart
new file mode 100644
index 0000000000..316863d342
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/shared/easy_localiation_service.dart
@@ -0,0 +1,26 @@
+import 'package:easy_localization/easy_localization.dart';
+// ignore: implementation_imports
+import 'package:easy_localization/src/easy_localization_controller.dart';
+import 'package:flutter/widgets.dart';
+
+class EasyLocalizationService {
+ EasyLocalizationService();
+
+ late EasyLocalizationController? controller;
+
+ String getFallbackTranslation(String token) {
+ final translations = controller?.fallbackTranslations;
+
+ return translations?.get(token).toString() ?? '';
+ }
+
+ String getTranslation(String token) {
+ final translations = controller?.translations;
+
+ return translations?.get(token).toString() ?? '';
+ }
+
+ void init(BuildContext context) {
+ controller = EasyLocalization.of(context)?.delegate.localizationController;
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/startup/deps_resolver.dart b/frontend/appflowy_flutter/lib/startup/deps_resolver.dart
index 57d0d4c9eb..631bed3a3b 100644
--- a/frontend/appflowy_flutter/lib/startup/deps_resolver.dart
+++ b/frontend/appflowy_flutter/lib/startup/deps_resolver.dart
@@ -8,6 +8,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_p
import 'package:appflowy/plugins/trash/application/prelude.dart';
import 'package:appflowy/shared/appflowy_cache_manager.dart';
import 'package:appflowy/shared/custom_image_cache_manager.dart';
+import 'package:appflowy/shared/easy_localiation_service.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/startup/tasks/appflowy_cloud_task.dart';
import 'package:appflowy/user/application/auth/af_cloud_auth_service.dart';
@@ -98,6 +99,8 @@ void _resolveCommonService(
..registerCache(CustomImageCacheManager())
..registerCache(FeatureFlagCache()),
);
+
+ getIt.registerSingleton<EasyLocalizationService>(EasyLocalizationService());
}
void _resolveUserDeps(GetIt getIt, IntegrationMode mode) {
diff --git a/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart b/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart
index dfd2419adc..e35bb29843 100644
--- a/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart
+++ b/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart
@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:appflowy/mobile/application/mobile_router.dart';
import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
import 'package:appflowy/shared/clipboard_state.dart';
+import 'package:appflowy/shared/easy_localiation_service.dart';
import 'package:appflowy/shared/feature_flags.dart';
import 'package:appflowy/shared/icon_emoji_picker/icon_picker.dart';
import 'package:appflowy/startup/startup.dart';
@@ -110,7 +111,12 @@ class InitAppWidgetTask extends LaunchTask {
path: 'assets/translations',
fallbackLocale: const Locale('en', 'US'),
useFallbackTranslations: true,
- child: app,
+ child: Builder(
+ builder: (context) {
+ getIt.get<EasyLocalizationService>().init(context);
+ return app;
+ },
+ ),
),
);
diff --git a/frontend/resources/flowy_icons/20x/eraser.svg b/frontend/resources/flowy_icons/20x/eraser.svg
new file mode 100644
index 0000000000..a3b8be73e2
--- /dev/null
+++ b/frontend/resources/flowy_icons/20x/eraser.svg
@@ -0,0 +1,3 @@
+<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M5.76636 8.46859L11.5315 14.2339M7 17H17M9.67528 16.0898L16.0898 9.67528C17.3034 8.46164 17.3034 6.49394 16.0898 5.2803L14.7197 3.91023C13.5061 2.69659 11.5384 2.69659 10.3247 3.91023L3.91023 10.3247C2.69659 11.5384 2.69659 13.5061 3.91023 14.7197L5.2803 16.0898C6.49394 17.3034 8.46164 17.3034 9.67528 16.0898Z" stroke="#21232A" stroke-linecap="round"/>
+</svg>
diff --git a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs
index 8e3b9dbf49..79c7fb01af 100644
--- a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs
@@ -1874,9 +1874,13 @@ impl DatabaseEditor {
.find(|field| field.id == *id && field.field_type == FieldType::RichText.value())
});
let category_field = config.category_field_id.as_ref().and_then(|id| {
- fields
- .iter()
- .find(|field| field.id == *id && field.field_type == FieldType::RichText.value())
+ fields.iter().find(|field| {
+ field.id == *id
+ && matches!(
+ FieldType::from(field.field_type),
+ FieldType::RichText | FieldType::SingleSelect | FieldType::MultiSelect
+ )
+ })
});
fn extract_cell_value(row: &Row, field: &Field) -> Option<String> {
@@ -1911,7 +1915,7 @@ impl DatabaseEditor {
let category = category_field
.and_then(|field| extract_cell_value(&row, field))
- .unwrap_or_else(|| "other".to_string());
+ .unwrap_or_default();
Some(CustomPromptPB {
id,
@@ -1959,7 +1963,13 @@ impl DatabaseEditor {
let category_field_id = fields
.iter()
- .find(|f| f.name.to_lowercase() == "category")
+ .find(|f| {
+ f.name.to_lowercase() == "category"
+ && matches!(
+ FieldType::from(f.field_type),
+ FieldType::RichText | FieldType::SingleSelect | FieldType::MultiSelect
+ )
+ })
.map(|f| f.id.clone());
let configuration = CustomPromptDatabaseConfigPB {