AppFlowy/frontend/appflowy_flutter/lib/plugins/document/document.dart

129 lines
3.4 KiB
Dart
Raw Normal View History

2022-08-10 09:59:28 +00:00
library document_plugin;
2022-03-01 08:05:45 +00:00
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/document_page.dart';
import 'package:appflowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart';
import 'package:appflowy/plugins/document/presentation/more/more_button.dart';
import 'package:appflowy/plugins/document/presentation/share/share_button.dart';
import 'package:appflowy/plugins/util.dart';
import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
import 'package:appflowy/workspace/presentation/widgets/tab_bar_item.dart';
import 'package:appflowy/workspace/presentation/widgets/view_title_bar.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
2021-07-24 06:05:49 +00:00
import 'package:flutter/material.dart';
2022-11-28 10:02:05 +00:00
import 'package:flutter_bloc/flutter_bloc.dart';
2022-05-17 18:25:35 +00:00
2022-03-01 03:22:39 +00:00
class DocumentPluginBuilder extends PluginBuilder {
2022-02-28 14:38:53 +00:00
@override
Plugin build(dynamic data) {
2022-07-19 06:11:29 +00:00
if (data is ViewPB) {
2022-02-28 14:38:53 +00:00
return DocumentPlugin(pluginType: pluginType, view: data);
} else {
throw FlowyPluginException.invalidData;
}
}
@override
2022-05-17 18:25:35 +00:00
String get menuName => LocaleKeys.document_menuName.tr();
2022-02-28 14:38:53 +00:00
@override
FlowySvgData get icon => FlowySvgs.documents_s;
2022-02-28 14:38:53 +00:00
@override
PluginType get pluginType => PluginType.editor;
2022-02-28 14:38:53 +00:00
@override
ViewLayoutPB? get layoutType => ViewLayoutPB.Document;
2022-02-28 14:38:53 +00:00
}
class DocumentPlugin extends Plugin<int> {
2022-02-28 14:38:53 +00:00
late PluginType _pluginType;
2021-10-10 07:58:57 +00:00
@override
final ViewPluginNotifier notifier;
DocumentPlugin({
required PluginType pluginType,
required ViewPB view,
bool listenOnViewChanged = false,
Key? key,
}) : notifier = ViewPluginNotifier(view: view) {
_pluginType = pluginType;
}
@override
PluginWidgetBuilder get widgetBuilder {
return DocumentPluginWidgetBuilder(
notifier: notifier,
);
}
2021-10-10 07:58:57 +00:00
@override
PluginType get pluginType => _pluginType;
2022-02-28 14:38:53 +00:00
@override
PluginId get id => notifier.view.id;
2022-02-28 14:38:53 +00:00
}
class DocumentPluginWidgetBuilder extends PluginWidgetBuilder
with NavigationItem {
final ViewPluginNotifier notifier;
ViewPB get view => notifier.view;
int? deletedViewIndex;
2022-02-28 14:38:53 +00:00
DocumentPluginWidgetBuilder({
required this.notifier,
Key? key,
});
2021-10-10 07:58:57 +00:00
@override
EdgeInsets get contentPadding => EdgeInsets.zero;
2021-10-10 07:58:57 +00:00
@override
Widget buildWidget({PluginContext? context, required bool shrinkWrap}) {
notifier.isDeleted.addListener(() {
notifier.isDeleted.value.fold(() => null, (deletedView) {
if (deletedView.hasIndex()) {
deletedViewIndex = deletedView.index;
}
});
});
[feat] Allow user to select any Google Font (#2895) * chore: add label for font selection drop down * chore: add method to set font family * feat: add drop down to setting appearance view * feat: add fontFamily to document appearance cubit * feat: add bloc provider to root for document appearance style * feat: syncFont family from setting appearance dialog * feat: plumbing for font style in editor * fix: add blocprovider before pushing overlay * chore: add kv_keys * fix: use fontFamily in document appearance cubit * fix: remove bloc providers because bloc is supplied in ancestor * fix: remove unecessary bloc provider * chore: add constraints to popover * chore: add translation for search box * feat: add levenshtein for string sort * feat: add search bar view * refactor: levenshtein * chore: add tests for levenshtein algorithm * feat: add unit tests for appearance cubit * fix: analyzer warnings * feat: sort by ascending if query is empty * chore: add test for the font family setting widget * feat: make comparison case insensitive * feat: lazy load with listview.builder Co-authored-by: Yijing Huang <hyj891204@gmail.com> * fix: fonts loaded on open application * fix: checkmark doesn't show * fix: try catch before getFont * fix: clear text editing value on close * fix: remove autofocus for search text field * chore: add tests * feat: use sliver protocol Co-authored-by: Yijing Huang <hyj891204@gmail.com> * fix: avoid using intrinsic height Co-authored-by: Yijing Huang <hyj891204@gmail.com> * fix: extra paren caused build failure * feat: switch order of font family setting --------- Co-authored-by: Yijing Huang <hyj891204@gmail.com>
2023-07-04 21:30:38 +00:00
return BlocBuilder<DocumentAppearanceCubit, DocumentAppearance>(
builder: (_, state) {
return DocumentPage(
view: view,
onDeleted: () => context?.onDeleted(view, deletedViewIndex),
key: ValueKey(view.id),
);
},
);
}
@override
Widget get leftBarItem => ViewTitleBar(view: view);
@override
Widget tabBarItem(String pluginId) => ViewTabBarItem(view: notifier.view);
@override
Widget? get rightBarItem {
return Row(
children: [
2023-06-19 13:20:53 +00:00
DocumentShareButton(
key: ValueKey(view.id),
view: view,
),
const SizedBox(width: 10),
[feat] Allow user to select any Google Font (#2895) * chore: add label for font selection drop down * chore: add method to set font family * feat: add drop down to setting appearance view * feat: add fontFamily to document appearance cubit * feat: add bloc provider to root for document appearance style * feat: syncFont family from setting appearance dialog * feat: plumbing for font style in editor * fix: add blocprovider before pushing overlay * chore: add kv_keys * fix: use fontFamily in document appearance cubit * fix: remove bloc providers because bloc is supplied in ancestor * fix: remove unecessary bloc provider * chore: add constraints to popover * chore: add translation for search box * feat: add levenshtein for string sort * feat: add search bar view * refactor: levenshtein * chore: add tests for levenshtein algorithm * feat: add unit tests for appearance cubit * fix: analyzer warnings * feat: sort by ascending if query is empty * chore: add test for the font family setting widget * feat: make comparison case insensitive * feat: lazy load with listview.builder Co-authored-by: Yijing Huang <hyj891204@gmail.com> * fix: fonts loaded on open application * fix: checkmark doesn't show * fix: try catch before getFont * fix: clear text editing value on close * fix: remove autofocus for search text field * chore: add tests * feat: use sliver protocol Co-authored-by: Yijing Huang <hyj891204@gmail.com> * fix: avoid using intrinsic height Co-authored-by: Yijing Huang <hyj891204@gmail.com> * fix: extra paren caused build failure * feat: switch order of font family setting --------- Co-authored-by: Yijing Huang <hyj891204@gmail.com>
2023-07-04 21:30:38 +00:00
const DocumentMoreButton(),
],
);
}
2021-07-24 14:27:24 +00:00
@override
List<NavigationItem> get navigationItems => [this];
}