|
@@ -1,29 +1,19 @@
|
|
library document_plugin;
|
|
library document_plugin;
|
|
|
|
|
|
import 'package:app_flowy/generated/locale_keys.g.dart';
|
|
import 'package:app_flowy/generated/locale_keys.g.dart';
|
|
|
|
+import 'package:app_flowy/plugins/document/document_page.dart';
|
|
|
|
+import 'package:app_flowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart';
|
|
|
|
+import 'package:app_flowy/plugins/document/presentation/more/more_button.dart';
|
|
|
|
+import 'package:app_flowy/plugins/document/presentation/share/share_button.dart';
|
|
import 'package:app_flowy/plugins/util.dart';
|
|
import 'package:app_flowy/plugins/util.dart';
|
|
import 'package:app_flowy/startup/plugin/plugin.dart';
|
|
import 'package:app_flowy/startup/plugin/plugin.dart';
|
|
-import 'package:app_flowy/startup/startup.dart';
|
|
|
|
-import 'package:app_flowy/plugins/document/application/share_bloc.dart';
|
|
|
|
import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
|
|
import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
|
|
-import 'package:app_flowy/workspace/presentation/home/toast.dart';
|
|
|
|
import 'package:app_flowy/workspace/presentation/widgets/left_bar_item.dart';
|
|
import 'package:app_flowy/workspace/presentation/widgets/left_bar_item.dart';
|
|
-import 'package:app_flowy/workspace/presentation/widgets/dialogs.dart';
|
|
|
|
-import 'package:app_flowy/workspace/presentation/widgets/pop_up_action.dart';
|
|
|
|
-import 'package:appflowy_popover/appflowy_popover.dart';
|
|
|
|
-import 'package:clipboard/clipboard.dart';
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
-import 'package:file_picker/file_picker.dart';
|
|
|
|
-import 'package:flowy_infra_ui/widget/rounded_button.dart';
|
|
|
|
-import 'package:flowy_sdk/log.dart';
|
|
|
|
-import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
|
|
|
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
|
|
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
|
|
-import 'package:flowy_sdk/protobuf/flowy-document/entities.pb.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
|
-import 'document_page.dart';
|
|
|
|
-
|
|
|
|
class DocumentPluginBuilder extends PluginBuilder {
|
|
class DocumentPluginBuilder extends PluginBuilder {
|
|
@override
|
|
@override
|
|
Plugin build(dynamic data) {
|
|
Plugin build(dynamic data) {
|
|
@@ -49,6 +39,8 @@ class DocumentPluginBuilder extends PluginBuilder {
|
|
|
|
|
|
class DocumentPlugin extends Plugin<int> {
|
|
class DocumentPlugin extends Plugin<int> {
|
|
late PluginType _pluginType;
|
|
late PluginType _pluginType;
|
|
|
|
+ final DocumentAppearanceCubit _documentAppearanceCubit =
|
|
|
|
+ DocumentAppearanceCubit();
|
|
|
|
|
|
@override
|
|
@override
|
|
final ViewPluginNotifier notifier;
|
|
final ViewPluginNotifier notifier;
|
|
@@ -59,10 +51,22 @@ class DocumentPlugin extends Plugin<int> {
|
|
Key? key,
|
|
Key? key,
|
|
}) : notifier = ViewPluginNotifier(view: view) {
|
|
}) : notifier = ViewPluginNotifier(view: view) {
|
|
_pluginType = pluginType;
|
|
_pluginType = pluginType;
|
|
|
|
+ _documentAppearanceCubit.fetch();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ void dispose() {
|
|
|
|
+ _documentAppearanceCubit.close();
|
|
|
|
+ super.dispose();
|
|
}
|
|
}
|
|
|
|
|
|
@override
|
|
@override
|
|
- PluginDisplay get display => DocumentPluginDisplay(notifier: notifier);
|
|
|
|
|
|
+ PluginDisplay get display {
|
|
|
|
+ return DocumentPluginDisplay(
|
|
|
|
+ notifier: notifier,
|
|
|
|
+ documentAppearanceCubit: _documentAppearanceCubit,
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
|
|
@override
|
|
@override
|
|
PluginType get ty => _pluginType;
|
|
PluginType get ty => _pluginType;
|
|
@@ -75,8 +79,13 @@ class DocumentPluginDisplay extends PluginDisplay with NavigationItem {
|
|
final ViewPluginNotifier notifier;
|
|
final ViewPluginNotifier notifier;
|
|
ViewPB get view => notifier.view;
|
|
ViewPB get view => notifier.view;
|
|
int? deletedViewIndex;
|
|
int? deletedViewIndex;
|
|
|
|
+ DocumentAppearanceCubit documentAppearanceCubit;
|
|
|
|
|
|
- DocumentPluginDisplay({required this.notifier, Key? key});
|
|
|
|
|
|
+ DocumentPluginDisplay({
|
|
|
|
+ required this.notifier,
|
|
|
|
+ required this.documentAppearanceCubit,
|
|
|
|
+ Key? key,
|
|
|
|
+ });
|
|
|
|
|
|
@override
|
|
@override
|
|
Widget buildWidget(PluginContext context) {
|
|
Widget buildWidget(PluginContext context) {
|
|
@@ -88,144 +97,37 @@ class DocumentPluginDisplay extends PluginDisplay with NavigationItem {
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
- return DocumentPage(
|
|
|
|
- view: view,
|
|
|
|
- onDeleted: () => context.onDeleted(view, deletedViewIndex),
|
|
|
|
- key: ValueKey(view.id),
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- Widget get leftBarItem => ViewLeftBarItem(view: view);
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- Widget? get rightBarItem => DocumentShareButton(view: view);
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- List<NavigationItem> get navigationItems => [this];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-class DocumentShareButton extends StatelessWidget {
|
|
|
|
- final ViewPB view;
|
|
|
|
- DocumentShareButton({Key? key, required this.view})
|
|
|
|
- : super(key: ValueKey(view.hashCode));
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- Widget build(BuildContext context) {
|
|
|
|
- return BlocProvider(
|
|
|
|
- create: (context) => getIt<DocShareBloc>(param1: view),
|
|
|
|
- child: BlocListener<DocShareBloc, DocShareState>(
|
|
|
|
- listener: (context, state) {
|
|
|
|
- state.map(
|
|
|
|
- initial: (_) {},
|
|
|
|
- loading: (_) {},
|
|
|
|
- finish: (state) {
|
|
|
|
- state.successOrFail.fold(
|
|
|
|
- _handleExportData,
|
|
|
|
- _handleExportError,
|
|
|
|
- );
|
|
|
|
- },
|
|
|
|
|
|
+ return BlocProvider.value(
|
|
|
|
+ value: documentAppearanceCubit,
|
|
|
|
+ child: BlocBuilder<DocumentAppearanceCubit, DocumentAppearance>(
|
|
|
|
+ builder: (_, state) {
|
|
|
|
+ return DocumentPage(
|
|
|
|
+ view: view,
|
|
|
|
+ onDeleted: () => context.onDeleted(view, deletedViewIndex),
|
|
|
|
+ key: ValueKey(view.id),
|
|
);
|
|
);
|
|
},
|
|
},
|
|
- child: BlocBuilder<DocShareBloc, DocShareState>(
|
|
|
|
- builder: (context, state) => ConstrainedBox(
|
|
|
|
- constraints: const BoxConstraints.expand(
|
|
|
|
- height: 30,
|
|
|
|
- width: 100,
|
|
|
|
- ),
|
|
|
|
- child: ShareActionList(view: view),
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
),
|
|
),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- void _handleExportData(ExportDataPB exportData) {
|
|
|
|
- switch (exportData.exportType) {
|
|
|
|
- case ExportType.Link:
|
|
|
|
- break;
|
|
|
|
- case ExportType.Markdown:
|
|
|
|
- FlutterClipboard.copy(exportData.data)
|
|
|
|
- .then((value) => Log.info('copied to clipboard'));
|
|
|
|
- break;
|
|
|
|
- case ExportType.Text:
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- void _handleExportError(FlowyError error) {}
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-class ShareActionList extends StatelessWidget {
|
|
|
|
- const ShareActionList({
|
|
|
|
- Key? key,
|
|
|
|
- required this.view,
|
|
|
|
- }) : super(key: key);
|
|
|
|
-
|
|
|
|
- final ViewPB view;
|
|
|
|
|
|
+ @override
|
|
|
|
+ Widget get leftBarItem => ViewLeftBarItem(view: view);
|
|
|
|
|
|
@override
|
|
@override
|
|
- Widget build(BuildContext context) {
|
|
|
|
- final docShareBloc = context.read<DocShareBloc>();
|
|
|
|
- return PopoverActionList<ShareActionWrapper>(
|
|
|
|
- direction: PopoverDirection.bottomWithCenterAligned,
|
|
|
|
- actions: ShareAction.values
|
|
|
|
- .map((action) => ShareActionWrapper(action))
|
|
|
|
- .toList(),
|
|
|
|
- buildChild: (controller) {
|
|
|
|
- return RoundedTextButton(
|
|
|
|
- title: LocaleKeys.shareAction_buttonText.tr(),
|
|
|
|
- onPressed: () => controller.show(),
|
|
|
|
- );
|
|
|
|
- },
|
|
|
|
- onSelected: (action, controller) async {
|
|
|
|
- switch (action.inner) {
|
|
|
|
- case ShareAction.markdown:
|
|
|
|
- final exportPath = await FilePicker.platform.saveFile(
|
|
|
|
- dialogTitle: '',
|
|
|
|
- fileName: '${view.name}.md',
|
|
|
|
- );
|
|
|
|
- if (exportPath != null) {
|
|
|
|
- docShareBloc.add(DocShareEvent.shareMarkdown(exportPath));
|
|
|
|
- showMessageToast('Exported to: $exportPath');
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- case ShareAction.copyLink:
|
|
|
|
- NavigatorAlertDialog(
|
|
|
|
- title: LocaleKeys.shareAction_workInProgress.tr())
|
|
|
|
- .show(context);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- controller.close();
|
|
|
|
- },
|
|
|
|
|
|
+ Widget? get rightBarItem {
|
|
|
|
+ return Row(
|
|
|
|
+ children: [
|
|
|
|
+ DocumentShareButton(view: view),
|
|
|
|
+ const SizedBox(width: 10),
|
|
|
|
+ BlocProvider.value(
|
|
|
|
+ value: documentAppearanceCubit,
|
|
|
|
+ child: const DocumentMoreButton(),
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
);
|
|
);
|
|
}
|
|
}
|
|
-}
|
|
|
|
-
|
|
|
|
-enum ShareAction {
|
|
|
|
- markdown,
|
|
|
|
- copyLink,
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-class ShareActionWrapper extends ActionCell {
|
|
|
|
- final ShareAction inner;
|
|
|
|
-
|
|
|
|
- ShareActionWrapper(this.inner);
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- Widget? leftIcon(Color iconColor) => null;
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
- String get name => inner.name;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-extension QuestionBubbleExtension on ShareAction {
|
|
|
|
- String get name {
|
|
|
|
- switch (this) {
|
|
|
|
- case ShareAction.markdown:
|
|
|
|
- return LocaleKeys.shareAction_markdown.tr();
|
|
|
|
- case ShareAction.copyLink:
|
|
|
|
- return LocaleKeys.shareAction_copyLink.tr();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ List<NavigationItem> get navigationItems => [this];
|
|
}
|
|
}
|