AppFlowy/frontend/app_flowy/lib/plugin/plugin.dart

61 lines
1.2 KiB
Dart
Raw Normal View History

2022-02-28 14:38:53 +00:00
library flowy_plugin;
import 'package:app_flowy/plugin/plugin.dart';
import 'package:app_flowy/startup/startup.dart';
import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart';
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart';
import 'package:flutter/widgets.dart';
export "./src/sandbox.dart";
2022-03-01 02:25:21 +00:00
typedef PluginType = int;
2022-02-28 14:38:53 +00:00
typedef PluginDataType = ViewDataType;
abstract class Plugin {
PluginType get pluginType;
String get pluginId;
bool get enable;
void dispose();
PluginDisplay get display;
}
abstract class PluginBuilder {
Plugin build(dynamic data);
String get pluginName;
PluginType get pluginType;
2022-03-01 02:25:21 +00:00
ViewDataType get dataType => ViewDataType.PlainText;
2022-02-28 14:38:53 +00:00
}
abstract class PluginDisplay with NavigationItem {
@override
Widget get leftBarItem;
@override
Widget? get rightBarItem;
List<NavigationItem> get navigationItems;
Widget buildWidget();
}
void registerPlugin({required PluginBuilder builder}) {
getIt<PluginSandbox>().registerPlugin(builder.pluginType, builder);
}
2022-03-01 02:25:21 +00:00
Plugin makePlugin({required PluginType pluginType, dynamic data}) {
2022-02-28 14:38:53 +00:00
final plugin = getIt<PluginSandbox>().buildPlugin(pluginType, data);
return plugin;
}
enum FlowyPluginException {
invalidData,
}