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

78 lines
1.7 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';
2022-03-01 08:05:45 +00:00
import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
2022-02-28 14:38:53 +00:00
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;
2022-03-01 08:05:45 +00:00
typedef PluginId = String;
2022-02-28 14:38:53 +00:00
abstract class Plugin {
2022-03-01 08:05:45 +00:00
PluginId get pluginId;
PluginDisplay get pluginDisplay;
2022-02-28 14:38:53 +00:00
PluginType get pluginType;
2022-03-01 08:05:45 +00:00
ChangeNotifier? get displayNotifier => null;
2022-02-28 14:38:53 +00:00
void dispose();
}
abstract class PluginBuilder {
Plugin build(dynamic data);
2022-03-01 08:05:45 +00:00
String get menuName;
2022-02-28 14:38:53 +00:00
PluginType get pluginType;
2022-03-01 02:25:21 +00:00
ViewDataType get dataType => ViewDataType.PlainText;
2022-02-28 14:38:53 +00:00
}
2022-03-01 03:22:39 +00:00
abstract class PluginConfig {
bool get creatable => true;
}
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();
}
2022-03-01 03:22:39 +00:00
void registerPlugin({required PluginBuilder builder, PluginConfig? config}) {
getIt<PluginSandbox>().registerPlugin(builder.pluginType, builder, config: config);
2022-02-28 14:38:53 +00:00
}
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;
}
2022-03-01 03:22:39 +00:00
List<PluginBuilder> pluginBuilders() {
final pluginBuilders = getIt<PluginSandbox>().builders;
final pluginConfigs = getIt<PluginSandbox>().pluginConfigs;
return pluginBuilders.where(
(builder) {
final config = pluginConfigs[builder.pluginType]?.creatable;
return config ?? true;
},
).toList();
}
2022-02-28 14:38:53 +00:00
enum FlowyPluginException {
invalidData,
}