mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
aec7bc847e
* chore: ai type * chore: use patch to fix version issue * chore: update * chore: update * chore: integrate client api * chore: add schema * chore: setup event * chore: add event test * chore: add test * chore: update test * chore: load chat message * chore: load chat message * chore: chat ui * chore: disable create chat * chore: update client api * chore: disable chat * chore: ui theme * chore: ui theme * chore: copy message * chore: fix test * chore: show error * chore: update bloc * chore: update test * chore: lint * chore: icon * chore: hover * chore: show unsupported page * chore: adjust mobile ui * chore: adjust view title bar * chore: return related question * chore: error page * chore: error page * chore: code format * chore: prompt * chore: fix test * chore: ui adjust * chore: disable create chat * chore: add loading page * chore: fix test * chore: disable chat action * chore: add maximum text limit
119 lines
2.9 KiB
Dart
119 lines
2.9 KiB
Dart
library flowy_plugin;
|
|
|
|
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
|
import 'package:appflowy/startup/plugin/plugin.dart';
|
|
import 'package:appflowy/startup/startup.dart';
|
|
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
|
|
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
|
|
|
export "./src/sandbox.dart";
|
|
|
|
enum PluginType {
|
|
document,
|
|
blank,
|
|
trash,
|
|
grid,
|
|
board,
|
|
calendar,
|
|
databaseDocument,
|
|
chat,
|
|
}
|
|
|
|
typedef PluginId = String;
|
|
|
|
abstract class Plugin {
|
|
PluginId get id;
|
|
|
|
PluginWidgetBuilder get widgetBuilder;
|
|
|
|
PluginNotifier? get notifier => null;
|
|
|
|
PluginType get pluginType;
|
|
|
|
void init() {}
|
|
|
|
void dispose() {
|
|
notifier?.dispose();
|
|
}
|
|
}
|
|
|
|
abstract class PluginNotifier<T> {
|
|
/// Notify if the plugin get deleted
|
|
ValueNotifier<T> get isDeleted;
|
|
|
|
void dispose() {}
|
|
}
|
|
|
|
abstract class PluginBuilder {
|
|
Plugin build(dynamic data);
|
|
|
|
String get menuName;
|
|
|
|
FlowySvgData get icon;
|
|
|
|
/// The type of this [Plugin]. Each [Plugin] should have a unique [PluginType]
|
|
PluginType get pluginType;
|
|
|
|
/// The layoutType is used in the backend to determine the layout of the view.
|
|
/// Currently, AppFlowy supports 4 layout types: Document, Grid, Board, Calendar.
|
|
ViewLayoutPB? get layoutType;
|
|
}
|
|
|
|
abstract class PluginConfig {
|
|
// Return false will disable the user to create it. For example, a trash plugin shouldn't be created by the user,
|
|
bool get creatable => true;
|
|
}
|
|
|
|
abstract class PluginWidgetBuilder with NavigationItem {
|
|
List<NavigationItem> get navigationItems;
|
|
|
|
EdgeInsets get contentPadding =>
|
|
const EdgeInsets.symmetric(horizontal: 40, vertical: 28);
|
|
|
|
Widget buildWidget({
|
|
required PluginContext context,
|
|
required bool shrinkWrap,
|
|
});
|
|
}
|
|
|
|
class PluginContext {
|
|
PluginContext({
|
|
this.userProfile,
|
|
this.onDeleted,
|
|
});
|
|
|
|
// calls when widget of the plugin get deleted
|
|
final Function(ViewPB, int?)? onDeleted;
|
|
final UserProfilePB? userProfile;
|
|
}
|
|
|
|
void registerPlugin({required PluginBuilder builder, PluginConfig? config}) {
|
|
getIt<PluginSandbox>()
|
|
.registerPlugin(builder.pluginType, builder, config: config);
|
|
}
|
|
|
|
/// Make the correct plugin from the [pluginType] and [data]. If the plugin
|
|
/// is not registered, it will return a blank plugin.
|
|
Plugin makePlugin({required PluginType pluginType, dynamic data}) {
|
|
final plugin = getIt<PluginSandbox>().buildPlugin(pluginType, data);
|
|
return plugin;
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
enum FlowyPluginException {
|
|
invalidData,
|
|
}
|