diff --git a/app_flowy/analysis_options.yaml b/app_flowy/analysis_options.yaml index e9def11a1c..eb5b057c3c 100644 --- a/app_flowy/analysis_options.yaml +++ b/app_flowy/analysis_options.yaml @@ -15,6 +15,7 @@ analyzer: - "**/*.g.dart" - "**/*.freezed.dart" - "packages/flowy_editor/**" + - "packages/flowy_infra_ui/**" linter: # The lint rules applied to this project can be customized in the diff --git a/app_flowy/ios/Flutter/AppFrameworkInfo.plist b/app_flowy/ios/Flutter/AppFrameworkInfo.plist index 9367d483e4..8d4492f977 100644 --- a/app_flowy/ios/Flutter/AppFrameworkInfo.plist +++ b/app_flowy/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 8.0 + 9.0 diff --git a/app_flowy/lib/home/application/edit_pannel/edit_pannel_event.dart b/app_flowy/lib/home/application/edit_pannel/edit_pannel_event.dart deleted file mode 100644 index 718e916e6d..0000000000 --- a/app_flowy/lib/home/application/edit_pannel/edit_pannel_event.dart +++ /dev/null @@ -1,9 +0,0 @@ -part of 'edit_pannel_bloc.dart'; - -@freezed -abstract class EditPannelEvent with _$EditPannelEvent { - const factory EditPannelEvent.startEdit(EditPannelContext context) = - _StartEdit; - - const factory EditPannelEvent.endEdit(EditPannelContext context) = _EndEdit; -} diff --git a/app_flowy/lib/home/application/edit_pannel/edit_pannel_state.dart b/app_flowy/lib/home/application/edit_pannel/edit_pannel_state.dart deleted file mode 100644 index 3cca9a2b0a..0000000000 --- a/app_flowy/lib/home/application/edit_pannel/edit_pannel_state.dart +++ /dev/null @@ -1,14 +0,0 @@ -part of 'edit_pannel_bloc.dart'; - -@freezed -abstract class EditPannelState implements _$EditPannelState { - const factory EditPannelState({ - required bool isEditing, - required Option editContext, - }) = _EditPannelState; - - factory EditPannelState.initial() => EditPannelState( - isEditing: false, - editContext: none(), - ); -} diff --git a/app_flowy/lib/home/application/home_bloc.dart b/app_flowy/lib/home/application/home_bloc.dart deleted file mode 100644 index 259abc3bb6..0000000000 --- a/app_flowy/lib/home/application/home_bloc.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'package:app_flowy/home/domain/edit_context.dart'; -import 'package:app_flowy/home/domain/page_context.dart'; -import 'package:app_flowy/home/presentation/widgets/blank_page.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:dartz/dartz.dart'; - -part 'home_event.dart'; -part 'home_state.dart'; -part 'home_bloc.freezed.dart'; - -class HomeBloc extends Bloc { - HomeBloc() : super(HomeState.initial()); - - @override - Stream mapEventToState( - HomeEvent event, - ) async* { - yield* event.map( - setPage: (e) async* { - yield state.copyWith(pageContext: e.context); - }, - showLoading: (e) async* { - yield state.copyWith(isLoading: e.isLoading); - }, - setEditPannel: (e) async* { - yield state.copyWith(editContext: some(e.editContext)); - }, - dismissEditPannel: (value) async* { - yield state.copyWith(editContext: none()); - }, - showMenu: (e) async* { - yield state.copyWith(showMenu: e.isShow); - }, - ); - } - - @override - Future close() { - return super.close(); - } -} diff --git a/app_flowy/lib/home/application/home_event.dart b/app_flowy/lib/home/application/home_event.dart deleted file mode 100644 index ec4d0a457b..0000000000 --- a/app_flowy/lib/home/application/home_event.dart +++ /dev/null @@ -1,15 +0,0 @@ -part of 'home_bloc.dart'; - -@freezed -abstract class HomeEvent with _$HomeEvent { - const factory HomeEvent.showLoading(bool isLoading) = _ShowLoading; - const factory HomeEvent.showMenu(bool isShow) = _ShowMenu; - - //page - const factory HomeEvent.setPage(PageContext context) = SetCurrentPage; - - //edit pannel - const factory HomeEvent.setEditPannel(EditPannelContext editContext) = - _ShowEditPannel; - const factory HomeEvent.dismissEditPannel() = _DismissEditPannel; -} diff --git a/app_flowy/lib/home/application/home_state.dart b/app_flowy/lib/home/application/home_state.dart deleted file mode 100644 index ce0be0f38e..0000000000 --- a/app_flowy/lib/home/application/home_state.dart +++ /dev/null @@ -1,18 +0,0 @@ -part of 'home_bloc.dart'; - -@freezed -abstract class HomeState implements _$HomeState { - const factory HomeState({ - required bool isLoading, - required bool showMenu, - required PageContext pageContext, - required Option editContext, - }) = _HomeState; - - factory HomeState.initial() => HomeState( - isLoading: false, - showMenu: true, - pageContext: const BlankPageContext(), - editContext: none(), - ); -} diff --git a/app_flowy/lib/home/application/menu/menu_bloc.dart b/app_flowy/lib/home/application/menu/menu_bloc.dart deleted file mode 100644 index dd5790b458..0000000000 --- a/app_flowy/lib/home/application/menu/menu_bloc.dart +++ /dev/null @@ -1,44 +0,0 @@ -import 'dart:async'; -import 'package:app_flowy/home/domain/page_context.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -part 'menu_event.dart'; -part 'menu_state.dart'; -part 'menu_bloc.freezed.dart'; - -class MenuBloc extends Bloc { - MenuBloc() : super(MenuState.initial()); - - @override - Stream mapEventToState( - MenuEvent event, - ) async* { - yield* event.map( - collapse: (e) async* { - final isCollapse = state.isCollapse; - yield state.copyWith(isCollapse: !isCollapse); - }, - openPage: (e) async* { - yield* _performActionOnOpenPage(e); - }, - createApp: (e) async* { - yield* _performActionOnCreateApp(e); - }, - ); - } - - Stream _performActionOnOpenPage(_OpenPage e) async* { - yield state.copyWith(pageContext: some(e.context)); - } - - Stream _performActionOnCreateApp(_CreateApp e) async* { - yield state; - } - - @override - Future close() { - return super.close(); - } -} diff --git a/app_flowy/lib/home/application/menu/menu_bloc.freezed.dart b/app_flowy/lib/home/application/menu/menu_bloc.freezed.dart deleted file mode 100644 index 38b4cb1fd0..0000000000 --- a/app_flowy/lib/home/application/menu/menu_bloc.freezed.dart +++ /dev/null @@ -1,525 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides - -part of 'menu_bloc.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); - -/// @nodoc -class _$MenuEventTearOff { - const _$MenuEventTearOff(); - - Collapse collapse() { - return const Collapse(); - } - - _OpenPage openPage(PageContext context) { - return _OpenPage( - context, - ); - } - - _CreateApp createApp() { - return const _CreateApp(); - } -} - -/// @nodoc -const $MenuEvent = _$MenuEventTearOff(); - -/// @nodoc -mixin _$MenuEvent { - @optionalTypeArgs - TResult when({ - required TResult Function() collapse, - required TResult Function(PageContext context) openPage, - required TResult Function() createApp, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? collapse, - TResult Function(PageContext context)? openPage, - TResult Function()? createApp, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(Collapse value) collapse, - required TResult Function(_OpenPage value) openPage, - required TResult Function(_CreateApp value) createApp, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(Collapse value)? collapse, - TResult Function(_OpenPage value)? openPage, - TResult Function(_CreateApp value)? createApp, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $MenuEventCopyWith<$Res> { - factory $MenuEventCopyWith(MenuEvent value, $Res Function(MenuEvent) then) = - _$MenuEventCopyWithImpl<$Res>; -} - -/// @nodoc -class _$MenuEventCopyWithImpl<$Res> implements $MenuEventCopyWith<$Res> { - _$MenuEventCopyWithImpl(this._value, this._then); - - final MenuEvent _value; - // ignore: unused_field - final $Res Function(MenuEvent) _then; -} - -/// @nodoc -abstract class $CollapseCopyWith<$Res> { - factory $CollapseCopyWith(Collapse value, $Res Function(Collapse) then) = - _$CollapseCopyWithImpl<$Res>; -} - -/// @nodoc -class _$CollapseCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> - implements $CollapseCopyWith<$Res> { - _$CollapseCopyWithImpl(Collapse _value, $Res Function(Collapse) _then) - : super(_value, (v) => _then(v as Collapse)); - - @override - Collapse get _value => super._value as Collapse; -} - -/// @nodoc - -class _$Collapse implements Collapse { - const _$Collapse(); - - @override - String toString() { - return 'MenuEvent.collapse()'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || (other is Collapse); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() collapse, - required TResult Function(PageContext context) openPage, - required TResult Function() createApp, - }) { - return collapse(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? collapse, - TResult Function(PageContext context)? openPage, - TResult Function()? createApp, - required TResult orElse(), - }) { - if (collapse != null) { - return collapse(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(Collapse value) collapse, - required TResult Function(_OpenPage value) openPage, - required TResult Function(_CreateApp value) createApp, - }) { - return collapse(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(Collapse value)? collapse, - TResult Function(_OpenPage value)? openPage, - TResult Function(_CreateApp value)? createApp, - required TResult orElse(), - }) { - if (collapse != null) { - return collapse(this); - } - return orElse(); - } -} - -abstract class Collapse implements MenuEvent { - const factory Collapse() = _$Collapse; -} - -/// @nodoc -abstract class _$OpenPageCopyWith<$Res> { - factory _$OpenPageCopyWith(_OpenPage value, $Res Function(_OpenPage) then) = - __$OpenPageCopyWithImpl<$Res>; - $Res call({PageContext context}); -} - -/// @nodoc -class __$OpenPageCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> - implements _$OpenPageCopyWith<$Res> { - __$OpenPageCopyWithImpl(_OpenPage _value, $Res Function(_OpenPage) _then) - : super(_value, (v) => _then(v as _OpenPage)); - - @override - _OpenPage get _value => super._value as _OpenPage; - - @override - $Res call({ - Object? context = freezed, - }) { - return _then(_OpenPage( - context == freezed - ? _value.context - : context // ignore: cast_nullable_to_non_nullable - as PageContext, - )); - } -} - -/// @nodoc - -class _$_OpenPage implements _OpenPage { - const _$_OpenPage(this.context); - - @override - final PageContext context; - - @override - String toString() { - return 'MenuEvent.openPage(context: $context)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other is _OpenPage && - (identical(other.context, context) || - const DeepCollectionEquality().equals(other.context, context))); - } - - @override - int get hashCode => - runtimeType.hashCode ^ const DeepCollectionEquality().hash(context); - - @JsonKey(ignore: true) - @override - _$OpenPageCopyWith<_OpenPage> get copyWith => - __$OpenPageCopyWithImpl<_OpenPage>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() collapse, - required TResult Function(PageContext context) openPage, - required TResult Function() createApp, - }) { - return openPage(context); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? collapse, - TResult Function(PageContext context)? openPage, - TResult Function()? createApp, - required TResult orElse(), - }) { - if (openPage != null) { - return openPage(context); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(Collapse value) collapse, - required TResult Function(_OpenPage value) openPage, - required TResult Function(_CreateApp value) createApp, - }) { - return openPage(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(Collapse value)? collapse, - TResult Function(_OpenPage value)? openPage, - TResult Function(_CreateApp value)? createApp, - required TResult orElse(), - }) { - if (openPage != null) { - return openPage(this); - } - return orElse(); - } -} - -abstract class _OpenPage implements MenuEvent { - const factory _OpenPage(PageContext context) = _$_OpenPage; - - PageContext get context => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - _$OpenPageCopyWith<_OpenPage> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$CreateAppCopyWith<$Res> { - factory _$CreateAppCopyWith( - _CreateApp value, $Res Function(_CreateApp) then) = - __$CreateAppCopyWithImpl<$Res>; -} - -/// @nodoc -class __$CreateAppCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> - implements _$CreateAppCopyWith<$Res> { - __$CreateAppCopyWithImpl(_CreateApp _value, $Res Function(_CreateApp) _then) - : super(_value, (v) => _then(v as _CreateApp)); - - @override - _CreateApp get _value => super._value as _CreateApp; -} - -/// @nodoc - -class _$_CreateApp implements _CreateApp { - const _$_CreateApp(); - - @override - String toString() { - return 'MenuEvent.createApp()'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || (other is _CreateApp); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() collapse, - required TResult Function(PageContext context) openPage, - required TResult Function() createApp, - }) { - return createApp(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? collapse, - TResult Function(PageContext context)? openPage, - TResult Function()? createApp, - required TResult orElse(), - }) { - if (createApp != null) { - return createApp(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(Collapse value) collapse, - required TResult Function(_OpenPage value) openPage, - required TResult Function(_CreateApp value) createApp, - }) { - return createApp(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(Collapse value)? collapse, - TResult Function(_OpenPage value)? openPage, - TResult Function(_CreateApp value)? createApp, - required TResult orElse(), - }) { - if (createApp != null) { - return createApp(this); - } - return orElse(); - } -} - -abstract class _CreateApp implements MenuEvent { - const factory _CreateApp() = _$_CreateApp; -} - -/// @nodoc -class _$MenuStateTearOff { - const _$MenuStateTearOff(); - - _MenuState call( - {required bool isCollapse, required Option pageContext}) { - return _MenuState( - isCollapse: isCollapse, - pageContext: pageContext, - ); - } -} - -/// @nodoc -const $MenuState = _$MenuStateTearOff(); - -/// @nodoc -mixin _$MenuState { - bool get isCollapse => throw _privateConstructorUsedError; - Option get pageContext => throw _privateConstructorUsedError; - - @JsonKey(ignore: true) - $MenuStateCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $MenuStateCopyWith<$Res> { - factory $MenuStateCopyWith(MenuState value, $Res Function(MenuState) then) = - _$MenuStateCopyWithImpl<$Res>; - $Res call({bool isCollapse, Option pageContext}); -} - -/// @nodoc -class _$MenuStateCopyWithImpl<$Res> implements $MenuStateCopyWith<$Res> { - _$MenuStateCopyWithImpl(this._value, this._then); - - final MenuState _value; - // ignore: unused_field - final $Res Function(MenuState) _then; - - @override - $Res call({ - Object? isCollapse = freezed, - Object? pageContext = freezed, - }) { - return _then(_value.copyWith( - isCollapse: isCollapse == freezed - ? _value.isCollapse - : isCollapse // ignore: cast_nullable_to_non_nullable - as bool, - pageContext: pageContext == freezed - ? _value.pageContext - : pageContext // ignore: cast_nullable_to_non_nullable - as Option, - )); - } -} - -/// @nodoc -abstract class _$MenuStateCopyWith<$Res> implements $MenuStateCopyWith<$Res> { - factory _$MenuStateCopyWith( - _MenuState value, $Res Function(_MenuState) then) = - __$MenuStateCopyWithImpl<$Res>; - @override - $Res call({bool isCollapse, Option pageContext}); -} - -/// @nodoc -class __$MenuStateCopyWithImpl<$Res> extends _$MenuStateCopyWithImpl<$Res> - implements _$MenuStateCopyWith<$Res> { - __$MenuStateCopyWithImpl(_MenuState _value, $Res Function(_MenuState) _then) - : super(_value, (v) => _then(v as _MenuState)); - - @override - _MenuState get _value => super._value as _MenuState; - - @override - $Res call({ - Object? isCollapse = freezed, - Object? pageContext = freezed, - }) { - return _then(_MenuState( - isCollapse: isCollapse == freezed - ? _value.isCollapse - : isCollapse // ignore: cast_nullable_to_non_nullable - as bool, - pageContext: pageContext == freezed - ? _value.pageContext - : pageContext // ignore: cast_nullable_to_non_nullable - as Option, - )); - } -} - -/// @nodoc - -class _$_MenuState implements _MenuState { - const _$_MenuState({required this.isCollapse, required this.pageContext}); - - @override - final bool isCollapse; - @override - final Option pageContext; - - @override - String toString() { - return 'MenuState(isCollapse: $isCollapse, pageContext: $pageContext)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other is _MenuState && - (identical(other.isCollapse, isCollapse) || - const DeepCollectionEquality() - .equals(other.isCollapse, isCollapse)) && - (identical(other.pageContext, pageContext) || - const DeepCollectionEquality() - .equals(other.pageContext, pageContext))); - } - - @override - int get hashCode => - runtimeType.hashCode ^ - const DeepCollectionEquality().hash(isCollapse) ^ - const DeepCollectionEquality().hash(pageContext); - - @JsonKey(ignore: true) - @override - _$MenuStateCopyWith<_MenuState> get copyWith => - __$MenuStateCopyWithImpl<_MenuState>(this, _$identity); -} - -abstract class _MenuState implements MenuState { - const factory _MenuState( - {required bool isCollapse, - required Option pageContext}) = _$_MenuState; - - @override - bool get isCollapse => throw _privateConstructorUsedError; - @override - Option get pageContext => throw _privateConstructorUsedError; - @override - @JsonKey(ignore: true) - _$MenuStateCopyWith<_MenuState> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/app_flowy/lib/home/application/menu/menu_event.dart b/app_flowy/lib/home/application/menu/menu_event.dart deleted file mode 100644 index a187022b9a..0000000000 --- a/app_flowy/lib/home/application/menu/menu_event.dart +++ /dev/null @@ -1,8 +0,0 @@ -part of 'menu_bloc.dart'; - -@freezed -abstract class MenuEvent with _$MenuEvent { - const factory MenuEvent.collapse() = Collapse; - const factory MenuEvent.openPage(PageContext context) = _OpenPage; - const factory MenuEvent.createApp() = _CreateApp; -} diff --git a/app_flowy/lib/home/application/menu/menu_state.dart b/app_flowy/lib/home/application/menu/menu_state.dart deleted file mode 100644 index 548459be0d..0000000000 --- a/app_flowy/lib/home/application/menu/menu_state.dart +++ /dev/null @@ -1,14 +0,0 @@ -part of 'menu_bloc.dart'; - -@freezed -abstract class MenuState implements _$MenuState { - const factory MenuState({ - required bool isCollapse, - required Option pageContext, - }) = _MenuState; - - factory MenuState.initial() => MenuState( - isCollapse: false, - pageContext: none(), - ); -} diff --git a/app_flowy/lib/home/application/watcher/home_watcher_event.dart b/app_flowy/lib/home/application/watcher/home_watcher_event.dart deleted file mode 100644 index 0bae7a735c..0000000000 --- a/app_flowy/lib/home/application/watcher/home_watcher_event.dart +++ /dev/null @@ -1,7 +0,0 @@ -part of 'home_watcher_bloc.dart'; - -@freezed -abstract class HomeWatcherEvent with _$HomeWatcherEvent { - const factory HomeWatcherEvent.started(String workspaceId) = _Started; - const factory HomeWatcherEvent.stop(String workspaceId) = _Stop; -} diff --git a/app_flowy/lib/home/application/watcher/home_watcher_state.dart b/app_flowy/lib/home/application/watcher/home_watcher_state.dart deleted file mode 100644 index 5081f94af0..0000000000 --- a/app_flowy/lib/home/application/watcher/home_watcher_state.dart +++ /dev/null @@ -1,7 +0,0 @@ -part of 'home_watcher_bloc.dart'; - -@freezed -abstract class HomeWatcherState with _$HomeWatcherState { - const factory HomeWatcherState.initial() = _Initial; - const factory HomeWatcherState.loading() = _Loading; -} diff --git a/app_flowy/lib/home/domain/page_context.dart b/app_flowy/lib/home/domain/page_context.dart deleted file mode 100644 index a787bd927f..0000000000 --- a/app_flowy/lib/home/domain/page_context.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:equatable/equatable.dart'; -import 'package:flutter/material.dart'; - -abstract class HomeStackPage extends StatefulWidget { - final PageContext pageContext; - const HomeStackPage({Key? key, required this.pageContext}) : super(key: key); -} - -enum PageType { - blank, -} - -List pages = PageType.values.toList(); - -abstract class PageContext extends Equatable { - final PageType pageType; - final String pageTitle; - const PageContext(this.pageType, {required this.pageTitle}); -} diff --git a/app_flowy/lib/home/presentation/widgets/menu/home_menu.dart b/app_flowy/lib/home/presentation/widgets/menu/home_menu.dart deleted file mode 100644 index b233128131..0000000000 --- a/app_flowy/lib/home/presentation/widgets/menu/home_menu.dart +++ /dev/null @@ -1,121 +0,0 @@ -import 'package:app_flowy/home/application/menu/menu_bloc.dart'; -import 'package:app_flowy/home/domain/page_context.dart'; -import 'package:app_flowy/startup/startup.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flowy_infra/size.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import '../../home_sizes.dart'; -import 'package:styled_widget/styled_widget.dart'; - -class HomeMenu extends StatelessWidget { - final Function(Option) pageContextChanged; - final Function(bool) isCollapseChanged; - - const HomeMenu( - {Key? key, - required this.pageContextChanged, - required this.isCollapseChanged}) - : super(key: key); - - @override - Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider(create: (context) => getIt()), - ], - child: MultiBlocListener( - listeners: bind(), - child: Container( - color: Theme.of(context).colorScheme.primaryVariant, - child: Padding( - padding: EdgeInsets.symmetric(horizontal: Insets.sm), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - const MenuTopBar(), - Container(), - const NewAppButton(), - ], - ), - ), - ), - )); - } - - // bind the function passed by ooutter with the bloc listener - List> bind() { - return [ - BlocListener( - listenWhen: (p, c) => p.pageContext != c.pageContext, - listener: (context, state) => pageContextChanged(state.pageContext), - ), - BlocListener( - listenWhen: (p, c) => p.isCollapse != c.isCollapse, - listener: (context, state) => isCollapseChanged(state.isCollapse), - ) - ]; - } -} - -class MenuTopBar extends StatelessWidget { - const MenuTopBar({Key? key}) : super(key: key); - @override - Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return SizedBox( - height: HomeSizes.menuTopBarHeight, - child: Row( - children: [ - const Text( - 'AppFlowy', - style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20), - ).constrained(minWidth: 100), - const Spacer(), - IconButton( - icon: const Icon(Icons.arrow_left), - onPressed: () => - context.read().add(const MenuEvent.collapse()), - ), - ], - ), - ); - }, - ); - } -} - -class NewAppButton extends StatelessWidget { - const NewAppButton({Key? key}) : super(key: key); - @override - Widget build(BuildContext context) { - return SizedBox( - height: HomeSizes.menuAddButtonHeight, - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - const Icon(Icons.add), - const SizedBox( - width: 10, - ), - TextButton( - onPressed: () async { - // Dialogs.show(OkCancelDialog( - // title: "No Connection", - // message: - // "It appears your device is offline. Please check your connection and try again.", - // onOkPressed: () => AppGlobals.nav.pop(), - // )); - }, - child: const Text('New App', - style: TextStyle( - color: Colors.black, - fontWeight: FontWeight.bold, - fontSize: 20)), - ) - ], - ), - ); - } -} diff --git a/app_flowy/lib/home/presentation/widgets/menu/prelude.dart b/app_flowy/lib/home/presentation/widgets/menu/prelude.dart deleted file mode 100644 index d3156898d5..0000000000 --- a/app_flowy/lib/home/presentation/widgets/menu/prelude.dart +++ /dev/null @@ -1,2 +0,0 @@ -export 'home_menu.dart'; -export 'hom_menu_size.dart'; diff --git a/app_flowy/lib/main.dart b/app_flowy/lib/main.dart index 76aa42d13f..6a7201968a 100644 --- a/app_flowy/lib/main.dart +++ b/app_flowy/lib/main.dart @@ -10,5 +10,5 @@ class FlowyAppFactory implements AppFactory { } void main() { - App.run(FlowyAppFactory()); + Application.run(FlowyAppFactory()); } diff --git a/app_flowy/lib/startup/deps_inject/prelude.dart b/app_flowy/lib/startup/deps_inject/prelude.dart index 3811e93bd0..8727cba4a2 100644 --- a/app_flowy/lib/startup/deps_inject/prelude.dart +++ b/app_flowy/lib/startup/deps_inject/prelude.dart @@ -1,7 +1,8 @@ +import 'package:app_flowy/workspace/infrastructure/deps_resolver.dart'; import 'package:app_flowy/startup/launch.dart'; import 'package:app_flowy/startup/startup.dart'; -import 'package:app_flowy/user/infrastructure/interface_impl.dart'; -import 'package:app_flowy/welcome/infrastructure/interface_impl.dart'; +import 'package:app_flowy/user/infrastructure/deps_resolver.dart'; +import 'package:app_flowy/welcome/infrastructure/deps_resolver.dart'; import 'package:flowy_sdk/flowy_sdk.dart'; import 'package:get_it/get_it.dart'; @@ -16,4 +17,5 @@ Future initGetIt( await WelcomeDepsResolver.resolve(getIt); await UserDepsResolver.resolve(getIt); + await HomeDepsResolver.resolve(getIt); } diff --git a/app_flowy/lib/startup/startup.dart b/app_flowy/lib/startup/startup.dart index 31a75755a9..96588ff06c 100644 --- a/app_flowy/lib/startup/startup.dart +++ b/app_flowy/lib/startup/startup.dart @@ -14,7 +14,7 @@ abstract class AppFactory { Widget create(); } -class App { +class Application { static void run(AppFactory f) { // Specify the evn const env = IntegrationEnv.dev; diff --git a/app_flowy/lib/startup/tasks/app_widget_task.dart b/app_flowy/lib/startup/tasks/application_task.dart similarity index 90% rename from app_flowy/lib/startup/tasks/app_widget_task.dart rename to app_flowy/lib/startup/tasks/application_task.dart index e18ef9a0a8..416310e470 100644 --- a/app_flowy/lib/startup/tasks/app_widget_task.dart +++ b/app_flowy/lib/startup/tasks/application_task.dart @@ -12,16 +12,16 @@ class AppWidgetTask extends LaunchTask { @override Future initialize(LaunchContext context) { final widget = context.getIt().create(); - final app = AppWidget(child: widget); + final app = ApplicationWidget(child: widget); runApp(app); return Future(() => {}); } } -class AppWidget extends StatelessWidget { +class ApplicationWidget extends StatelessWidget { final Widget child; - const AppWidget({ + const ApplicationWidget({ Key? key, required this.child, }) : super(key: key); diff --git a/app_flowy/lib/startup/tasks/prelude.dart b/app_flowy/lib/startup/tasks/prelude.dart index d4474f0342..2e82179a7b 100644 --- a/app_flowy/lib/startup/tasks/prelude.dart +++ b/app_flowy/lib/startup/tasks/prelude.dart @@ -1,2 +1,2 @@ -export 'app_widget_task.dart'; +export 'application_task.dart'; export 'rust_sdk_init_task.dart'; diff --git a/app_flowy/lib/startup/tasks/rust_sdk_init_task.dart b/app_flowy/lib/startup/tasks/rust_sdk_init_task.dart index 4f57190761..c5067b2cc9 100644 --- a/app_flowy/lib/startup/tasks/rust_sdk_init_task.dart +++ b/app_flowy/lib/startup/tasks/rust_sdk_init_task.dart @@ -38,8 +38,9 @@ class RustSDKInitTask extends LaunchTask { class ApplicationBlocObserver extends BlocObserver { @override + // ignore: unnecessary_overrides void onTransition(Bloc bloc, Transition transition) { - Log.debug(transition); + // Log.debug(transition); super.onTransition(bloc, transition); } diff --git a/app_flowy/lib/user/application/sign_in/sign_in_bloc.dart b/app_flowy/lib/user/application/sign_in/sign_in_bloc.dart index 08d8d71aac..8bb9a87ff8 100644 --- a/app_flowy/lib/user/application/sign_in/sign_in_bloc.dart +++ b/app_flowy/lib/user/application/sign_in/sign_in_bloc.dart @@ -1,12 +1,10 @@ -import 'package:app_flowy/user/domain/interface.dart'; +import 'package:app_flowy/user/domain/i_auth.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; // ignore: import_of_legacy_library_into_null_safe import 'package:flutter_bloc/flutter_bloc.dart'; -part 'sign_in_event.dart'; -part 'sign_in_state.dart'; part 'sign_in_bloc.freezed.dart'; class SignInBloc extends Bloc { @@ -43,3 +41,27 @@ class SignInBloc extends Bloc { ); } } + +@freezed +abstract class SignInEvent with _$SignInEvent { + const factory SignInEvent.signedInWithUserEmailAndPassword() = + SignedInWithUserEmailAndPassword; + + const factory SignInEvent.emailChanged(String email) = EmailChanged; + const factory SignInEvent.passwordChanged(String password) = PasswordChanged; +} + +@freezed +abstract class SignInState with _$SignInState { + const factory SignInState({ + String? email, + String? password, + required bool isSubmitting, + required Option> signInFailure, + }) = _SignInState; + + factory SignInState.initial() => SignInState( + isSubmitting: false, + signInFailure: none(), + ); +} diff --git a/app_flowy/lib/user/application/sign_in/sign_in_event.dart b/app_flowy/lib/user/application/sign_in/sign_in_event.dart deleted file mode 100644 index 702afea0bc..0000000000 --- a/app_flowy/lib/user/application/sign_in/sign_in_event.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'sign_in_bloc.dart'; - -@freezed -abstract class SignInEvent with _$SignInEvent { - const factory SignInEvent.signedInWithUserEmailAndPassword() = - SignedInWithUserEmailAndPassword; - - const factory SignInEvent.emailChanged(String email) = EmailChanged; - const factory SignInEvent.passwordChanged(String password) = PasswordChanged; -} diff --git a/app_flowy/lib/user/application/sign_in/sign_in_state.dart b/app_flowy/lib/user/application/sign_in/sign_in_state.dart deleted file mode 100644 index 76555cb38b..0000000000 --- a/app_flowy/lib/user/application/sign_in/sign_in_state.dart +++ /dev/null @@ -1,16 +0,0 @@ -part of 'sign_in_bloc.dart'; - -@freezed -abstract class SignInState with _$SignInState { - const factory SignInState({ - String? email, - String? password, - required bool isSubmitting, - required Option> signInFailure, - }) = _SignInState; - - factory SignInState.initial() => SignInState( - isSubmitting: false, - signInFailure: none(), - ); -} diff --git a/app_flowy/lib/user/domain/interface.dart b/app_flowy/lib/user/domain/i_auth.dart similarity index 100% rename from app_flowy/lib/user/domain/interface.dart rename to app_flowy/lib/user/domain/i_auth.dart diff --git a/app_flowy/lib/user/infrastructure/deps_resolver.dart b/app_flowy/lib/user/infrastructure/deps_resolver.dart new file mode 100644 index 0000000000..92df6eef03 --- /dev/null +++ b/app_flowy/lib/user/infrastructure/deps_resolver.dart @@ -0,0 +1,17 @@ +import 'package:app_flowy/user/application/sign_in/sign_in_bloc.dart'; +import 'package:app_flowy/user/domain/i_auth.dart'; +import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart'; +import 'package:app_flowy/user/infrastructure/i_auth_impl.dart'; +import 'package:get_it/get_it.dart'; + +class UserDepsResolver { + static Future resolve(GetIt getIt) async { + getIt.registerLazySingleton(() => AuthRepository()); + + //Interface implementation + getIt.registerFactory(() => AuthImpl(repo: getIt())); + + //Bloc + getIt.registerFactory(() => SignInBloc(getIt())); + } +} diff --git a/app_flowy/lib/user/infrastructure/interface_impl.dart b/app_flowy/lib/user/infrastructure/i_auth_impl.dart similarity index 52% rename from app_flowy/lib/user/infrastructure/interface_impl.dart rename to app_flowy/lib/user/infrastructure/i_auth_impl.dart index f7ddd74da4..580637cdcf 100644 --- a/app_flowy/lib/user/infrastructure/interface_impl.dart +++ b/app_flowy/lib/user/infrastructure/i_auth_impl.dart @@ -1,22 +1,7 @@ -import 'package:app_flowy/user/application/sign_in/sign_in_bloc.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart'; -import 'package:get_it/get_it.dart'; - -import 'package:app_flowy/user/domain/interface.dart'; -import 'package:app_flowy/user/infrastructure/auth_repo.dart'; - -class UserDepsResolver { - static Future resolve(GetIt getIt) async { - getIt.registerLazySingleton(() => AuthRepository()); - - //Interface implementation - getIt.registerFactory(() => AuthImpl(repo: getIt())); - - //Bloc - getIt.registerFactory(() => SignInBloc(getIt())); - } -} +import 'package:app_flowy/user/domain/i_auth.dart'; +import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart'; class AuthImpl extends IAuth { AuthRepository repo; diff --git a/app_flowy/lib/user/infrastructure/auth_repo.dart b/app_flowy/lib/user/infrastructure/repos/auth_repo.dart similarity index 100% rename from app_flowy/lib/user/infrastructure/auth_repo.dart rename to app_flowy/lib/user/infrastructure/repos/auth_repo.dart diff --git a/app_flowy/lib/user/presentation/sign_in/widgets/body.dart b/app_flowy/lib/user/presentation/sign_in/widgets/body.dart index 7021dd740b..be49b3f7b9 100644 --- a/app_flowy/lib/user/presentation/sign_in/widgets/body.dart +++ b/app_flowy/lib/user/presentation/sign_in/widgets/body.dart @@ -1,7 +1,7 @@ -import 'package:app_flowy/home/presentation/home_screen.dart'; import 'package:app_flowy/startup/startup.dart'; import 'package:app_flowy/user/application/sign_in/sign_in_bloc.dart'; import 'package:app_flowy/user/presentation/sign_in/widgets/background.dart'; +import 'package:app_flowy/workspace/presentation/home/home_screen.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_infra_ui/widget/rounded_button.dart'; import 'package:flowy_infra_ui/widget/rounded_input_field.dart'; diff --git a/app_flowy/lib/welcome/application/welcome_bloc.dart b/app_flowy/lib/welcome/application/welcome_bloc.dart index b8bfe9efb8..6595029a4a 100644 --- a/app_flowy/lib/welcome/application/welcome_bloc.dart +++ b/app_flowy/lib/welcome/application/welcome_bloc.dart @@ -1,10 +1,8 @@ import 'package:app_flowy/welcome/domain/auth_state.dart'; -import 'package:app_flowy/welcome/domain/interface.dart'; +import 'package:app_flowy/welcome/domain/i_welcome.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -part 'welcome_event.dart'; -part 'welcome_state.dart'; part 'welcome_bloc.freezed.dart'; class WelcomeBloc extends Bloc { @@ -21,3 +19,19 @@ class WelcomeBloc extends Bloc { ); } } + +@freezed +abstract class WelcomeEvent with _$WelcomeEvent { + const factory WelcomeEvent.getUser() = _GetUser; +} + +@freezed +abstract class WelcomeState implements _$WelcomeState { + const factory WelcomeState({ + required AuthState auth, + }) = _WelcomeState; + + factory WelcomeState.initial() => const WelcomeState( + auth: AuthState.initial(), + ); +} diff --git a/app_flowy/lib/welcome/application/welcome_event.dart b/app_flowy/lib/welcome/application/welcome_event.dart deleted file mode 100644 index 0ade68c9df..0000000000 --- a/app_flowy/lib/welcome/application/welcome_event.dart +++ /dev/null @@ -1,6 +0,0 @@ -part of 'welcome_bloc.dart'; - -@freezed -abstract class WelcomeEvent with _$WelcomeEvent { - const factory WelcomeEvent.getUser() = _GetUser; -} diff --git a/app_flowy/lib/welcome/application/welcome_state.dart b/app_flowy/lib/welcome/application/welcome_state.dart deleted file mode 100644 index 04ba534244..0000000000 --- a/app_flowy/lib/welcome/application/welcome_state.dart +++ /dev/null @@ -1,12 +0,0 @@ -part of 'welcome_bloc.dart'; - -@freezed -abstract class WelcomeState implements _$WelcomeState { - const factory WelcomeState({ - required AuthState auth, - }) = _WelcomeState; - - factory WelcomeState.initial() => const WelcomeState( - auth: AuthState.initial(), - ); -} diff --git a/app_flowy/lib/welcome/domain/interface.dart b/app_flowy/lib/welcome/domain/i_welcome.dart similarity index 100% rename from app_flowy/lib/welcome/domain/interface.dart rename to app_flowy/lib/welcome/domain/i_welcome.dart diff --git a/app_flowy/lib/welcome/infrastructure/deps_resolver.dart b/app_flowy/lib/welcome/infrastructure/deps_resolver.dart new file mode 100644 index 0000000000..18024e9038 --- /dev/null +++ b/app_flowy/lib/welcome/infrastructure/deps_resolver.dart @@ -0,0 +1,19 @@ +import 'package:app_flowy/workspace/application/edit_pannel/edit_pannel_bloc.dart'; +import 'package:app_flowy/welcome/application/welcome_bloc.dart'; +import 'package:app_flowy/welcome/infrastructure/i_welcome_impl.dart'; +import 'package:app_flowy/workspace/application/home/home_bloc.dart'; +import 'package:app_flowy/workspace/application/home/home_watcher_bloc.dart'; +import 'package:get_it/get_it.dart'; + +class WelcomeDepsResolver { + static Future resolve(GetIt getIt) async { + getIt.registerFactory(() => WelcomeAuthImpl()); + getIt.registerFactory(() => WelcomeRoute()); + getIt.registerFactory(() => HomeBloc()); + getIt.registerFactory(() => HomeWatcherBloc()); + getIt.registerFactory(() => EditPannelBloc()); + + getIt + .registerFactory(() => WelcomeBloc(getIt())); + } +} diff --git a/app_flowy/lib/welcome/infrastructure/i_welcome_impl.dart b/app_flowy/lib/welcome/infrastructure/i_welcome_impl.dart new file mode 100644 index 0000000000..671c8427f6 --- /dev/null +++ b/app_flowy/lib/welcome/infrastructure/i_welcome_impl.dart @@ -0,0 +1,39 @@ +import 'package:app_flowy/user/presentation/sign_in/sign_in_screen.dart'; +import 'package:app_flowy/welcome/domain/auth_state.dart'; +import 'package:app_flowy/welcome/domain/i_welcome.dart'; +import 'package:app_flowy/workspace/presentation/home/home_screen.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; + +export 'package:app_flowy/welcome/domain/i_welcome.dart'; + +class WelcomeAuthImpl implements IWelcomeAuth { + @override + Future currentUserState() { + final result = UserEventGetStatus().send(); + return result.then((result) { + return result.fold( + (userDetail) { + return AuthState.authenticated(userDetail); + }, + (userError) { + return AuthState.unauthenticated(userError); + }, + ); + }); + } +} + +class WelcomeRoute implements IWelcomeRoute { + @override + Widget pushHomeScreen(UserDetail user) { + return HomeScreen(user); + } + + @override + Widget pushSignInScreen() { + return const SignInScreen(); + } +} diff --git a/app_flowy/lib/welcome/infrastructure/interface_impl.dart b/app_flowy/lib/welcome/infrastructure/interface_impl.dart deleted file mode 100644 index d060aff1e1..0000000000 --- a/app_flowy/lib/welcome/infrastructure/interface_impl.dart +++ /dev/null @@ -1,58 +0,0 @@ -import 'package:app_flowy/home/application/edit_pannel/edit_pannel_bloc.dart'; -import 'package:app_flowy/home/application/home_bloc.dart'; -import 'package:app_flowy/home/application/menu/menu_bloc.dart'; -import 'package:app_flowy/home/application/watcher/home_watcher_bloc.dart'; -import 'package:app_flowy/home/presentation/home_screen.dart'; -import 'package:app_flowy/user/presentation/sign_in/sign_in_screen.dart'; -import 'package:app_flowy/welcome/application/welcome_bloc.dart'; -import 'package:app_flowy/welcome/domain/auth_state.dart'; -import 'package:app_flowy/welcome/domain/interface.dart'; -import 'package:flowy_sdk/dispatch/dispatch.dart'; -import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; -import 'package:get_it/get_it.dart'; - -class WelcomeDepsResolver { - static Future resolve(GetIt getIt) async { - getIt.registerFactory(() => WelcomeAuthImpl()); - getIt.registerFactory(() => WelcomeRoute()); - getIt.registerFactory(() => HomeBloc()); - getIt.registerFactory(() => HomeWatcherBloc()); - getIt.registerFactory(() => EditPannelBloc()); - - getIt.registerFactory(() => MenuBloc()); - - getIt - .registerFactory(() => WelcomeBloc(getIt())); - } -} - -class WelcomeAuthImpl implements IWelcomeAuth { - @override - Future currentUserState() { - final result = UserEventGetStatus().send(); - return result.then((result) { - return result.fold( - (userDetail) { - return AuthState.authenticated(userDetail); - }, - (userError) { - return AuthState.unauthenticated(userError); - }, - ); - }); - } -} - -class WelcomeRoute implements IWelcomeRoute { - @override - Widget pushHomeScreen(UserDetail user) { - return HomeScreen(user); - } - - @override - Widget pushSignInScreen() { - return const SignInScreen(); - } -} diff --git a/app_flowy/lib/welcome/presentation/welcome_screen.dart b/app_flowy/lib/welcome/presentation/welcome_screen.dart index b4ef56cf4d..82fc4cfcfa 100644 --- a/app_flowy/lib/welcome/presentation/welcome_screen.dart +++ b/app_flowy/lib/welcome/presentation/welcome_screen.dart @@ -1,4 +1,4 @@ -import 'package:app_flowy/welcome/domain/interface.dart'; +import 'package:app_flowy/welcome/domain/i_welcome.dart'; import 'package:app_flowy/welcome/domain/auth_state.dart'; import 'package:app_flowy/startup/startup.dart'; import 'package:app_flowy/welcome/application/welcome_bloc.dart'; diff --git a/app_flowy/lib/workspace/application/app/app_bloc.dart b/app_flowy/lib/workspace/application/app/app_bloc.dart new file mode 100644 index 0000000000..45200aa8d3 --- /dev/null +++ b/app_flowy/lib/workspace/application/app/app_bloc.dart @@ -0,0 +1,58 @@ +import 'package:app_flowy/workspace/domain/i_app.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:dartz/dartz.dart'; + +part 'app_bloc.freezed.dart'; + +class AppBloc extends Bloc { + final IApp iAppImpl; + AppBloc(this.iAppImpl) : super(AppState.initial()); + + @override + Stream mapEventToState( + AppEvent event, + ) async* { + yield* event.map( + initial: (e) async* { + yield* _fetchViews(); + }, + createView: (CreateView value) async* { + iAppImpl.createView( + name: value.name, desc: value.desc, viewType: value.viewType); + }, + ); + } + + Stream _fetchViews() async* { + final viewsOrFailed = await iAppImpl.getViews(); + yield viewsOrFailed.fold( + (apps) => state.copyWith(views: some(apps)), + (error) => state.copyWith(successOrFailure: right(error)), + ); + } +} + +@freezed +abstract class AppEvent with _$AppEvent { + const factory AppEvent.initial() = Initial; + const factory AppEvent.createView( + String name, String desc, ViewType viewType) = CreateView; +} + +@freezed +abstract class AppState implements _$AppState { + const factory AppState({ + required bool isLoading, + required Option> views, + required Either successOrFailure, + }) = _AppState; + + factory AppState.initial() => AppState( + isLoading: false, + views: none(), + successOrFailure: left(unit), + ); +} diff --git a/app_flowy/lib/workspace/application/app/app_bloc.freezed.dart b/app_flowy/lib/workspace/application/app/app_bloc.freezed.dart new file mode 100644 index 0000000000..eb75305a1b --- /dev/null +++ b/app_flowy/lib/workspace/application/app/app_bloc.freezed.dart @@ -0,0 +1,484 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'app_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$AppEventTearOff { + const _$AppEventTearOff(); + + Initial initial() { + return const Initial(); + } + + CreateView createView(String name, String desc, ViewType viewType) { + return CreateView( + name, + desc, + viewType, + ); + } +} + +/// @nodoc +const $AppEvent = _$AppEventTearOff(); + +/// @nodoc +mixin _$AppEvent { + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(String name, String desc, ViewType viewType) + createView, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(String name, String desc, ViewType viewType)? createView, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(Initial value) initial, + required TResult Function(CreateView value) createView, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Initial value)? initial, + TResult Function(CreateView value)? createView, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $AppEventCopyWith<$Res> { + factory $AppEventCopyWith(AppEvent value, $Res Function(AppEvent) then) = + _$AppEventCopyWithImpl<$Res>; +} + +/// @nodoc +class _$AppEventCopyWithImpl<$Res> implements $AppEventCopyWith<$Res> { + _$AppEventCopyWithImpl(this._value, this._then); + + final AppEvent _value; + // ignore: unused_field + final $Res Function(AppEvent) _then; +} + +/// @nodoc +abstract class $InitialCopyWith<$Res> { + factory $InitialCopyWith(Initial value, $Res Function(Initial) then) = + _$InitialCopyWithImpl<$Res>; +} + +/// @nodoc +class _$InitialCopyWithImpl<$Res> extends _$AppEventCopyWithImpl<$Res> + implements $InitialCopyWith<$Res> { + _$InitialCopyWithImpl(Initial _value, $Res Function(Initial) _then) + : super(_value, (v) => _then(v as Initial)); + + @override + Initial get _value => super._value as Initial; +} + +/// @nodoc + +class _$Initial implements Initial { + const _$Initial(); + + @override + String toString() { + return 'AppEvent.initial()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is Initial); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(String name, String desc, ViewType viewType) + createView, + }) { + return initial(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(String name, String desc, ViewType viewType)? createView, + required TResult orElse(), + }) { + if (initial != null) { + return initial(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Initial value) initial, + required TResult Function(CreateView value) createView, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Initial value)? initial, + TResult Function(CreateView value)? createView, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class Initial implements AppEvent { + const factory Initial() = _$Initial; +} + +/// @nodoc +abstract class $CreateViewCopyWith<$Res> { + factory $CreateViewCopyWith( + CreateView value, $Res Function(CreateView) then) = + _$CreateViewCopyWithImpl<$Res>; + $Res call({String name, String desc, ViewType viewType}); +} + +/// @nodoc +class _$CreateViewCopyWithImpl<$Res> extends _$AppEventCopyWithImpl<$Res> + implements $CreateViewCopyWith<$Res> { + _$CreateViewCopyWithImpl(CreateView _value, $Res Function(CreateView) _then) + : super(_value, (v) => _then(v as CreateView)); + + @override + CreateView get _value => super._value as CreateView; + + @override + $Res call({ + Object? name = freezed, + Object? desc = freezed, + Object? viewType = freezed, + }) { + return _then(CreateView( + name == freezed + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + desc == freezed + ? _value.desc + : desc // ignore: cast_nullable_to_non_nullable + as String, + viewType == freezed + ? _value.viewType + : viewType // ignore: cast_nullable_to_non_nullable + as ViewType, + )); + } +} + +/// @nodoc + +class _$CreateView implements CreateView { + const _$CreateView(this.name, this.desc, this.viewType); + + @override + final String name; + @override + final String desc; + @override + final ViewType viewType; + + @override + String toString() { + return 'AppEvent.createView(name: $name, desc: $desc, viewType: $viewType)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is CreateView && + (identical(other.name, name) || + const DeepCollectionEquality().equals(other.name, name)) && + (identical(other.desc, desc) || + const DeepCollectionEquality().equals(other.desc, desc)) && + (identical(other.viewType, viewType) || + const DeepCollectionEquality() + .equals(other.viewType, viewType))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(name) ^ + const DeepCollectionEquality().hash(desc) ^ + const DeepCollectionEquality().hash(viewType); + + @JsonKey(ignore: true) + @override + $CreateViewCopyWith get copyWith => + _$CreateViewCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(String name, String desc, ViewType viewType) + createView, + }) { + return createView(name, desc, viewType); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(String name, String desc, ViewType viewType)? createView, + required TResult orElse(), + }) { + if (createView != null) { + return createView(name, desc, viewType); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Initial value) initial, + required TResult Function(CreateView value) createView, + }) { + return createView(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Initial value)? initial, + TResult Function(CreateView value)? createView, + required TResult orElse(), + }) { + if (createView != null) { + return createView(this); + } + return orElse(); + } +} + +abstract class CreateView implements AppEvent { + const factory CreateView(String name, String desc, ViewType viewType) = + _$CreateView; + + String get name => throw _privateConstructorUsedError; + String get desc => throw _privateConstructorUsedError; + ViewType get viewType => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $CreateViewCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +class _$AppStateTearOff { + const _$AppStateTearOff(); + + _AppState call( + {required bool isLoading, + required Option> views, + required Either successOrFailure}) { + return _AppState( + isLoading: isLoading, + views: views, + successOrFailure: successOrFailure, + ); + } +} + +/// @nodoc +const $AppState = _$AppStateTearOff(); + +/// @nodoc +mixin _$AppState { + bool get isLoading => throw _privateConstructorUsedError; + Option> get views => throw _privateConstructorUsedError; + Either get successOrFailure => + throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $AppStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $AppStateCopyWith<$Res> { + factory $AppStateCopyWith(AppState value, $Res Function(AppState) then) = + _$AppStateCopyWithImpl<$Res>; + $Res call( + {bool isLoading, + Option> views, + Either successOrFailure}); +} + +/// @nodoc +class _$AppStateCopyWithImpl<$Res> implements $AppStateCopyWith<$Res> { + _$AppStateCopyWithImpl(this._value, this._then); + + final AppState _value; + // ignore: unused_field + final $Res Function(AppState) _then; + + @override + $Res call({ + Object? isLoading = freezed, + Object? views = freezed, + Object? successOrFailure = freezed, + }) { + return _then(_value.copyWith( + isLoading: isLoading == freezed + ? _value.isLoading + : isLoading // ignore: cast_nullable_to_non_nullable + as bool, + views: views == freezed + ? _value.views + : views // ignore: cast_nullable_to_non_nullable + as Option>, + successOrFailure: successOrFailure == freezed + ? _value.successOrFailure + : successOrFailure // ignore: cast_nullable_to_non_nullable + as Either, + )); + } +} + +/// @nodoc +abstract class _$AppStateCopyWith<$Res> implements $AppStateCopyWith<$Res> { + factory _$AppStateCopyWith(_AppState value, $Res Function(_AppState) then) = + __$AppStateCopyWithImpl<$Res>; + @override + $Res call( + {bool isLoading, + Option> views, + Either successOrFailure}); +} + +/// @nodoc +class __$AppStateCopyWithImpl<$Res> extends _$AppStateCopyWithImpl<$Res> + implements _$AppStateCopyWith<$Res> { + __$AppStateCopyWithImpl(_AppState _value, $Res Function(_AppState) _then) + : super(_value, (v) => _then(v as _AppState)); + + @override + _AppState get _value => super._value as _AppState; + + @override + $Res call({ + Object? isLoading = freezed, + Object? views = freezed, + Object? successOrFailure = freezed, + }) { + return _then(_AppState( + isLoading: isLoading == freezed + ? _value.isLoading + : isLoading // ignore: cast_nullable_to_non_nullable + as bool, + views: views == freezed + ? _value.views + : views // ignore: cast_nullable_to_non_nullable + as Option>, + successOrFailure: successOrFailure == freezed + ? _value.successOrFailure + : successOrFailure // ignore: cast_nullable_to_non_nullable + as Either, + )); + } +} + +/// @nodoc + +class _$_AppState implements _AppState { + const _$_AppState( + {required this.isLoading, + required this.views, + required this.successOrFailure}); + + @override + final bool isLoading; + @override + final Option> views; + @override + final Either successOrFailure; + + @override + String toString() { + return 'AppState(isLoading: $isLoading, views: $views, successOrFailure: $successOrFailure)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _AppState && + (identical(other.isLoading, isLoading) || + const DeepCollectionEquality() + .equals(other.isLoading, isLoading)) && + (identical(other.views, views) || + const DeepCollectionEquality().equals(other.views, views)) && + (identical(other.successOrFailure, successOrFailure) || + const DeepCollectionEquality() + .equals(other.successOrFailure, successOrFailure))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(isLoading) ^ + const DeepCollectionEquality().hash(views) ^ + const DeepCollectionEquality().hash(successOrFailure); + + @JsonKey(ignore: true) + @override + _$AppStateCopyWith<_AppState> get copyWith => + __$AppStateCopyWithImpl<_AppState>(this, _$identity); +} + +abstract class _AppState implements AppState { + const factory _AppState( + {required bool isLoading, + required Option> views, + required Either successOrFailure}) = _$_AppState; + + @override + bool get isLoading => throw _privateConstructorUsedError; + @override + Option> get views => throw _privateConstructorUsedError; + @override + Either get successOrFailure => + throw _privateConstructorUsedError; + @override + @JsonKey(ignore: true) + _$AppStateCopyWith<_AppState> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/app_flowy/lib/workspace/application/app/app_watch_bloc.dart b/app_flowy/lib/workspace/application/app/app_watch_bloc.dart new file mode 100644 index 0000000000..4cabff5a96 --- /dev/null +++ b/app_flowy/lib/workspace/application/app/app_watch_bloc.dart @@ -0,0 +1,56 @@ +import 'package:app_flowy/workspace/domain/i_app.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:dartz/dartz.dart'; + +part 'app_watch_bloc.freezed.dart'; + +class AppWatchBloc extends Bloc { + final IAppWatch watcher; + AppWatchBloc(this.watcher) : super(const AppWatchState.initial()); + + @override + Stream mapEventToState( + AppWatchEvent event, + ) async* { + yield* event.map(started: (_) async* { + watcher.startWatching( + addViewCallback: (viewsOrFail) => _handleViewsOrFail(viewsOrFail), + ); + }, viewsReceived: (ViewsReceived value) async* { + yield value.viewsOrFail.fold( + (views) => AppWatchState.loadViews(views), + (error) => AppWatchState.loadFail(error), + ); + }); + } + + void _handleViewsOrFail(Either, WorkspaceError> viewsOrFail) { + viewsOrFail.fold( + (views) => add(AppWatchEvent.viewsReceived(left(views))), + (error) => add(AppWatchEvent.viewsReceived(right(error))), + ); + } +} + +@freezed +abstract class AppWatchEvent with _$AppWatchEvent { + const factory AppWatchEvent.started() = _Started; + const factory AppWatchEvent.viewsReceived( + Either, WorkspaceError> viewsOrFail) = ViewsReceived; +} + +@freezed +abstract class AppWatchState implements _$AppWatchState { + const factory AppWatchState.initial() = _Initial; + + const factory AppWatchState.loadViews( + List views, + ) = _LoadViews; + + const factory AppWatchState.loadFail( + WorkspaceError error, + ) = _LoadFail; +} diff --git a/app_flowy/lib/workspace/application/app/app_watch_bloc.freezed.dart b/app_flowy/lib/workspace/application/app/app_watch_bloc.freezed.dart new file mode 100644 index 0000000000..e3dc21be5c --- /dev/null +++ b/app_flowy/lib/workspace/application/app/app_watch_bloc.freezed.dart @@ -0,0 +1,683 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'app_watch_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$AppWatchEventTearOff { + const _$AppWatchEventTearOff(); + + _Started started() { + return const _Started(); + } + + ViewsReceived viewsReceived(Either, WorkspaceError> viewsOrFail) { + return ViewsReceived( + viewsOrFail, + ); + } +} + +/// @nodoc +const $AppWatchEvent = _$AppWatchEventTearOff(); + +/// @nodoc +mixin _$AppWatchEvent { + @optionalTypeArgs + TResult when({ + required TResult Function() started, + required TResult Function(Either, WorkspaceError> viewsOrFail) + viewsReceived, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? started, + TResult Function(Either, WorkspaceError> viewsOrFail)? + viewsReceived, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_Started value) started, + required TResult Function(ViewsReceived value) viewsReceived, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Started value)? started, + TResult Function(ViewsReceived value)? viewsReceived, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $AppWatchEventCopyWith<$Res> { + factory $AppWatchEventCopyWith( + AppWatchEvent value, $Res Function(AppWatchEvent) then) = + _$AppWatchEventCopyWithImpl<$Res>; +} + +/// @nodoc +class _$AppWatchEventCopyWithImpl<$Res> + implements $AppWatchEventCopyWith<$Res> { + _$AppWatchEventCopyWithImpl(this._value, this._then); + + final AppWatchEvent _value; + // ignore: unused_field + final $Res Function(AppWatchEvent) _then; +} + +/// @nodoc +abstract class _$StartedCopyWith<$Res> { + factory _$StartedCopyWith(_Started value, $Res Function(_Started) then) = + __$StartedCopyWithImpl<$Res>; +} + +/// @nodoc +class __$StartedCopyWithImpl<$Res> extends _$AppWatchEventCopyWithImpl<$Res> + implements _$StartedCopyWith<$Res> { + __$StartedCopyWithImpl(_Started _value, $Res Function(_Started) _then) + : super(_value, (v) => _then(v as _Started)); + + @override + _Started get _value => super._value as _Started; +} + +/// @nodoc + +class _$_Started implements _Started { + const _$_Started(); + + @override + String toString() { + return 'AppWatchEvent.started()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _Started); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() started, + required TResult Function(Either, WorkspaceError> viewsOrFail) + viewsReceived, + }) { + return started(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? started, + TResult Function(Either, WorkspaceError> viewsOrFail)? + viewsReceived, + required TResult orElse(), + }) { + if (started != null) { + return started(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Started value) started, + required TResult Function(ViewsReceived value) viewsReceived, + }) { + return started(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Started value)? started, + TResult Function(ViewsReceived value)? viewsReceived, + required TResult orElse(), + }) { + if (started != null) { + return started(this); + } + return orElse(); + } +} + +abstract class _Started implements AppWatchEvent { + const factory _Started() = _$_Started; +} + +/// @nodoc +abstract class $ViewsReceivedCopyWith<$Res> { + factory $ViewsReceivedCopyWith( + ViewsReceived value, $Res Function(ViewsReceived) then) = + _$ViewsReceivedCopyWithImpl<$Res>; + $Res call({Either, WorkspaceError> viewsOrFail}); +} + +/// @nodoc +class _$ViewsReceivedCopyWithImpl<$Res> + extends _$AppWatchEventCopyWithImpl<$Res> + implements $ViewsReceivedCopyWith<$Res> { + _$ViewsReceivedCopyWithImpl( + ViewsReceived _value, $Res Function(ViewsReceived) _then) + : super(_value, (v) => _then(v as ViewsReceived)); + + @override + ViewsReceived get _value => super._value as ViewsReceived; + + @override + $Res call({ + Object? viewsOrFail = freezed, + }) { + return _then(ViewsReceived( + viewsOrFail == freezed + ? _value.viewsOrFail + : viewsOrFail // ignore: cast_nullable_to_non_nullable + as Either, WorkspaceError>, + )); + } +} + +/// @nodoc + +class _$ViewsReceived implements ViewsReceived { + const _$ViewsReceived(this.viewsOrFail); + + @override + final Either, WorkspaceError> viewsOrFail; + + @override + String toString() { + return 'AppWatchEvent.viewsReceived(viewsOrFail: $viewsOrFail)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is ViewsReceived && + (identical(other.viewsOrFail, viewsOrFail) || + const DeepCollectionEquality() + .equals(other.viewsOrFail, viewsOrFail))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(viewsOrFail); + + @JsonKey(ignore: true) + @override + $ViewsReceivedCopyWith get copyWith => + _$ViewsReceivedCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() started, + required TResult Function(Either, WorkspaceError> viewsOrFail) + viewsReceived, + }) { + return viewsReceived(viewsOrFail); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? started, + TResult Function(Either, WorkspaceError> viewsOrFail)? + viewsReceived, + required TResult orElse(), + }) { + if (viewsReceived != null) { + return viewsReceived(viewsOrFail); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Started value) started, + required TResult Function(ViewsReceived value) viewsReceived, + }) { + return viewsReceived(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Started value)? started, + TResult Function(ViewsReceived value)? viewsReceived, + required TResult orElse(), + }) { + if (viewsReceived != null) { + return viewsReceived(this); + } + return orElse(); + } +} + +abstract class ViewsReceived implements AppWatchEvent { + const factory ViewsReceived(Either, WorkspaceError> viewsOrFail) = + _$ViewsReceived; + + Either, WorkspaceError> get viewsOrFail => + throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $ViewsReceivedCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +class _$AppWatchStateTearOff { + const _$AppWatchStateTearOff(); + + _Initial initial() { + return const _Initial(); + } + + _LoadViews loadViews(List views) { + return _LoadViews( + views, + ); + } + + _LoadFail loadFail(WorkspaceError error) { + return _LoadFail( + error, + ); + } +} + +/// @nodoc +const $AppWatchState = _$AppWatchStateTearOff(); + +/// @nodoc +mixin _$AppWatchState { + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(List views) loadViews, + required TResult Function(WorkspaceError error) loadFail, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(List views)? loadViews, + TResult Function(WorkspaceError error)? loadFail, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_LoadViews value) loadViews, + required TResult Function(_LoadFail value) loadFail, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_LoadViews value)? loadViews, + TResult Function(_LoadFail value)? loadFail, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $AppWatchStateCopyWith<$Res> { + factory $AppWatchStateCopyWith( + AppWatchState value, $Res Function(AppWatchState) then) = + _$AppWatchStateCopyWithImpl<$Res>; +} + +/// @nodoc +class _$AppWatchStateCopyWithImpl<$Res> + implements $AppWatchStateCopyWith<$Res> { + _$AppWatchStateCopyWithImpl(this._value, this._then); + + final AppWatchState _value; + // ignore: unused_field + final $Res Function(AppWatchState) _then; +} + +/// @nodoc +abstract class _$InitialCopyWith<$Res> { + factory _$InitialCopyWith(_Initial value, $Res Function(_Initial) then) = + __$InitialCopyWithImpl<$Res>; +} + +/// @nodoc +class __$InitialCopyWithImpl<$Res> extends _$AppWatchStateCopyWithImpl<$Res> + implements _$InitialCopyWith<$Res> { + __$InitialCopyWithImpl(_Initial _value, $Res Function(_Initial) _then) + : super(_value, (v) => _then(v as _Initial)); + + @override + _Initial get _value => super._value as _Initial; +} + +/// @nodoc + +class _$_Initial implements _Initial { + const _$_Initial(); + + @override + String toString() { + return 'AppWatchState.initial()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _Initial); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(List views) loadViews, + required TResult Function(WorkspaceError error) loadFail, + }) { + return initial(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(List views)? loadViews, + TResult Function(WorkspaceError error)? loadFail, + required TResult orElse(), + }) { + if (initial != null) { + return initial(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_LoadViews value) loadViews, + required TResult Function(_LoadFail value) loadFail, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_LoadViews value)? loadViews, + TResult Function(_LoadFail value)? loadFail, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class _Initial implements AppWatchState { + const factory _Initial() = _$_Initial; +} + +/// @nodoc +abstract class _$LoadViewsCopyWith<$Res> { + factory _$LoadViewsCopyWith( + _LoadViews value, $Res Function(_LoadViews) then) = + __$LoadViewsCopyWithImpl<$Res>; + $Res call({List views}); +} + +/// @nodoc +class __$LoadViewsCopyWithImpl<$Res> extends _$AppWatchStateCopyWithImpl<$Res> + implements _$LoadViewsCopyWith<$Res> { + __$LoadViewsCopyWithImpl(_LoadViews _value, $Res Function(_LoadViews) _then) + : super(_value, (v) => _then(v as _LoadViews)); + + @override + _LoadViews get _value => super._value as _LoadViews; + + @override + $Res call({ + Object? views = freezed, + }) { + return _then(_LoadViews( + views == freezed + ? _value.views + : views // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc + +class _$_LoadViews implements _LoadViews { + const _$_LoadViews(this.views); + + @override + final List views; + + @override + String toString() { + return 'AppWatchState.loadViews(views: $views)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _LoadViews && + (identical(other.views, views) || + const DeepCollectionEquality().equals(other.views, views))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(views); + + @JsonKey(ignore: true) + @override + _$LoadViewsCopyWith<_LoadViews> get copyWith => + __$LoadViewsCopyWithImpl<_LoadViews>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(List views) loadViews, + required TResult Function(WorkspaceError error) loadFail, + }) { + return loadViews(views); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(List views)? loadViews, + TResult Function(WorkspaceError error)? loadFail, + required TResult orElse(), + }) { + if (loadViews != null) { + return loadViews(views); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_LoadViews value) loadViews, + required TResult Function(_LoadFail value) loadFail, + }) { + return loadViews(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_LoadViews value)? loadViews, + TResult Function(_LoadFail value)? loadFail, + required TResult orElse(), + }) { + if (loadViews != null) { + return loadViews(this); + } + return orElse(); + } +} + +abstract class _LoadViews implements AppWatchState { + const factory _LoadViews(List views) = _$_LoadViews; + + List get views => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$LoadViewsCopyWith<_LoadViews> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$LoadFailCopyWith<$Res> { + factory _$LoadFailCopyWith(_LoadFail value, $Res Function(_LoadFail) then) = + __$LoadFailCopyWithImpl<$Res>; + $Res call({WorkspaceError error}); +} + +/// @nodoc +class __$LoadFailCopyWithImpl<$Res> extends _$AppWatchStateCopyWithImpl<$Res> + implements _$LoadFailCopyWith<$Res> { + __$LoadFailCopyWithImpl(_LoadFail _value, $Res Function(_LoadFail) _then) + : super(_value, (v) => _then(v as _LoadFail)); + + @override + _LoadFail get _value => super._value as _LoadFail; + + @override + $Res call({ + Object? error = freezed, + }) { + return _then(_LoadFail( + error == freezed + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as WorkspaceError, + )); + } +} + +/// @nodoc + +class _$_LoadFail implements _LoadFail { + const _$_LoadFail(this.error); + + @override + final WorkspaceError error; + + @override + String toString() { + return 'AppWatchState.loadFail(error: $error)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _LoadFail && + (identical(other.error, error) || + const DeepCollectionEquality().equals(other.error, error))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(error); + + @JsonKey(ignore: true) + @override + _$LoadFailCopyWith<_LoadFail> get copyWith => + __$LoadFailCopyWithImpl<_LoadFail>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(List views) loadViews, + required TResult Function(WorkspaceError error) loadFail, + }) { + return loadFail(error); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(List views)? loadViews, + TResult Function(WorkspaceError error)? loadFail, + required TResult orElse(), + }) { + if (loadFail != null) { + return loadFail(error); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_LoadViews value) loadViews, + required TResult Function(_LoadFail value) loadFail, + }) { + return loadFail(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_LoadViews value)? loadViews, + TResult Function(_LoadFail value)? loadFail, + required TResult orElse(), + }) { + if (loadFail != null) { + return loadFail(this); + } + return orElse(); + } +} + +abstract class _LoadFail implements AppWatchState { + const factory _LoadFail(WorkspaceError error) = _$_LoadFail; + + WorkspaceError get error => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$LoadFailCopyWith<_LoadFail> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/app_flowy/lib/workspace/application/doc/doc_bloc.dart b/app_flowy/lib/workspace/application/doc/doc_bloc.dart new file mode 100644 index 0000000000..27f3b0f5a0 --- /dev/null +++ b/app_flowy/lib/workspace/application/doc/doc_bloc.dart @@ -0,0 +1,39 @@ +import 'package:app_flowy/workspace/domain/i_doc.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:dartz/dartz.dart'; + +part 'doc_bloc.freezed.dart'; + +class DocBloc extends Bloc { + final IDoc iDocImpl; + + DocBloc(this.iDocImpl) : super(DocState.initial()); + + @override + Stream mapEventToState(DocEvent event) async* { + yield* event.map( + initial: (e) async* {}, + save: (Save value) async* {}, + close: (Close value) async* {}, + ); + } +} + +@freezed +abstract class DocEvent with _$DocEvent { + const factory DocEvent.initial() = Initial; + const factory DocEvent.save(String jsonStr) = Save; + const factory DocEvent.close() = Close; +} + +@freezed +abstract class DocState implements _$DocState { + const factory DocState({ + required bool isSaving, + }) = _DocState; + + factory DocState.initial() => const DocState( + isSaving: false, + ); +} diff --git a/app_flowy/lib/workspace/application/doc/doc_bloc.freezed.dart b/app_flowy/lib/workspace/application/doc/doc_bloc.freezed.dart new file mode 100644 index 0000000000..1e74f06c09 --- /dev/null +++ b/app_flowy/lib/workspace/application/doc/doc_bloc.freezed.dart @@ -0,0 +1,498 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'doc_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$DocEventTearOff { + const _$DocEventTearOff(); + + Initial initial() { + return const Initial(); + } + + Save save(String jsonStr) { + return Save( + jsonStr, + ); + } + + Close close() { + return const Close(); + } +} + +/// @nodoc +const $DocEvent = _$DocEventTearOff(); + +/// @nodoc +mixin _$DocEvent { + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(String jsonStr) save, + required TResult Function() close, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(String jsonStr)? save, + TResult Function()? close, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(Initial value) initial, + required TResult Function(Save value) save, + required TResult Function(Close value) close, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Initial value)? initial, + TResult Function(Save value)? save, + TResult Function(Close value)? close, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $DocEventCopyWith<$Res> { + factory $DocEventCopyWith(DocEvent value, $Res Function(DocEvent) then) = + _$DocEventCopyWithImpl<$Res>; +} + +/// @nodoc +class _$DocEventCopyWithImpl<$Res> implements $DocEventCopyWith<$Res> { + _$DocEventCopyWithImpl(this._value, this._then); + + final DocEvent _value; + // ignore: unused_field + final $Res Function(DocEvent) _then; +} + +/// @nodoc +abstract class $InitialCopyWith<$Res> { + factory $InitialCopyWith(Initial value, $Res Function(Initial) then) = + _$InitialCopyWithImpl<$Res>; +} + +/// @nodoc +class _$InitialCopyWithImpl<$Res> extends _$DocEventCopyWithImpl<$Res> + implements $InitialCopyWith<$Res> { + _$InitialCopyWithImpl(Initial _value, $Res Function(Initial) _then) + : super(_value, (v) => _then(v as Initial)); + + @override + Initial get _value => super._value as Initial; +} + +/// @nodoc + +class _$Initial implements Initial { + const _$Initial(); + + @override + String toString() { + return 'DocEvent.initial()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is Initial); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(String jsonStr) save, + required TResult Function() close, + }) { + return initial(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(String jsonStr)? save, + TResult Function()? close, + required TResult orElse(), + }) { + if (initial != null) { + return initial(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Initial value) initial, + required TResult Function(Save value) save, + required TResult Function(Close value) close, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Initial value)? initial, + TResult Function(Save value)? save, + TResult Function(Close value)? close, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class Initial implements DocEvent { + const factory Initial() = _$Initial; +} + +/// @nodoc +abstract class $SaveCopyWith<$Res> { + factory $SaveCopyWith(Save value, $Res Function(Save) then) = + _$SaveCopyWithImpl<$Res>; + $Res call({String jsonStr}); +} + +/// @nodoc +class _$SaveCopyWithImpl<$Res> extends _$DocEventCopyWithImpl<$Res> + implements $SaveCopyWith<$Res> { + _$SaveCopyWithImpl(Save _value, $Res Function(Save) _then) + : super(_value, (v) => _then(v as Save)); + + @override + Save get _value => super._value as Save; + + @override + $Res call({ + Object? jsonStr = freezed, + }) { + return _then(Save( + jsonStr == freezed + ? _value.jsonStr + : jsonStr // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$Save implements Save { + const _$Save(this.jsonStr); + + @override + final String jsonStr; + + @override + String toString() { + return 'DocEvent.save(jsonStr: $jsonStr)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is Save && + (identical(other.jsonStr, jsonStr) || + const DeepCollectionEquality().equals(other.jsonStr, jsonStr))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(jsonStr); + + @JsonKey(ignore: true) + @override + $SaveCopyWith get copyWith => + _$SaveCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(String jsonStr) save, + required TResult Function() close, + }) { + return save(jsonStr); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(String jsonStr)? save, + TResult Function()? close, + required TResult orElse(), + }) { + if (save != null) { + return save(jsonStr); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Initial value) initial, + required TResult Function(Save value) save, + required TResult Function(Close value) close, + }) { + return save(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Initial value)? initial, + TResult Function(Save value)? save, + TResult Function(Close value)? close, + required TResult orElse(), + }) { + if (save != null) { + return save(this); + } + return orElse(); + } +} + +abstract class Save implements DocEvent { + const factory Save(String jsonStr) = _$Save; + + String get jsonStr => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $SaveCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $CloseCopyWith<$Res> { + factory $CloseCopyWith(Close value, $Res Function(Close) then) = + _$CloseCopyWithImpl<$Res>; +} + +/// @nodoc +class _$CloseCopyWithImpl<$Res> extends _$DocEventCopyWithImpl<$Res> + implements $CloseCopyWith<$Res> { + _$CloseCopyWithImpl(Close _value, $Res Function(Close) _then) + : super(_value, (v) => _then(v as Close)); + + @override + Close get _value => super._value as Close; +} + +/// @nodoc + +class _$Close implements Close { + const _$Close(); + + @override + String toString() { + return 'DocEvent.close()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is Close); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(String jsonStr) save, + required TResult Function() close, + }) { + return close(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(String jsonStr)? save, + TResult Function()? close, + required TResult orElse(), + }) { + if (close != null) { + return close(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Initial value) initial, + required TResult Function(Save value) save, + required TResult Function(Close value) close, + }) { + return close(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Initial value)? initial, + TResult Function(Save value)? save, + TResult Function(Close value)? close, + required TResult orElse(), + }) { + if (close != null) { + return close(this); + } + return orElse(); + } +} + +abstract class Close implements DocEvent { + const factory Close() = _$Close; +} + +/// @nodoc +class _$DocStateTearOff { + const _$DocStateTearOff(); + + _DocState call({required bool isSaving}) { + return _DocState( + isSaving: isSaving, + ); + } +} + +/// @nodoc +const $DocState = _$DocStateTearOff(); + +/// @nodoc +mixin _$DocState { + bool get isSaving => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $DocStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $DocStateCopyWith<$Res> { + factory $DocStateCopyWith(DocState value, $Res Function(DocState) then) = + _$DocStateCopyWithImpl<$Res>; + $Res call({bool isSaving}); +} + +/// @nodoc +class _$DocStateCopyWithImpl<$Res> implements $DocStateCopyWith<$Res> { + _$DocStateCopyWithImpl(this._value, this._then); + + final DocState _value; + // ignore: unused_field + final $Res Function(DocState) _then; + + @override + $Res call({ + Object? isSaving = freezed, + }) { + return _then(_value.copyWith( + isSaving: isSaving == freezed + ? _value.isSaving + : isSaving // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc +abstract class _$DocStateCopyWith<$Res> implements $DocStateCopyWith<$Res> { + factory _$DocStateCopyWith(_DocState value, $Res Function(_DocState) then) = + __$DocStateCopyWithImpl<$Res>; + @override + $Res call({bool isSaving}); +} + +/// @nodoc +class __$DocStateCopyWithImpl<$Res> extends _$DocStateCopyWithImpl<$Res> + implements _$DocStateCopyWith<$Res> { + __$DocStateCopyWithImpl(_DocState _value, $Res Function(_DocState) _then) + : super(_value, (v) => _then(v as _DocState)); + + @override + _DocState get _value => super._value as _DocState; + + @override + $Res call({ + Object? isSaving = freezed, + }) { + return _then(_DocState( + isSaving: isSaving == freezed + ? _value.isSaving + : isSaving // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc + +class _$_DocState implements _DocState { + const _$_DocState({required this.isSaving}); + + @override + final bool isSaving; + + @override + String toString() { + return 'DocState(isSaving: $isSaving)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _DocState && + (identical(other.isSaving, isSaving) || + const DeepCollectionEquality() + .equals(other.isSaving, isSaving))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(isSaving); + + @JsonKey(ignore: true) + @override + _$DocStateCopyWith<_DocState> get copyWith => + __$DocStateCopyWithImpl<_DocState>(this, _$identity); +} + +abstract class _DocState implements DocState { + const factory _DocState({required bool isSaving}) = _$_DocState; + + @override + bool get isSaving => throw _privateConstructorUsedError; + @override + @JsonKey(ignore: true) + _$DocStateCopyWith<_DocState> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/app_flowy/lib/home/application/edit_pannel/edit_pannel_bloc.dart b/app_flowy/lib/workspace/application/edit_pannel/edit_pannel_bloc.dart similarity index 54% rename from app_flowy/lib/home/application/edit_pannel/edit_pannel_bloc.dart rename to app_flowy/lib/workspace/application/edit_pannel/edit_pannel_bloc.dart index addb06a3ad..ecaf26bc63 100644 --- a/app_flowy/lib/home/application/edit_pannel/edit_pannel_bloc.dart +++ b/app_flowy/lib/workspace/application/edit_pannel/edit_pannel_bloc.dart @@ -1,12 +1,10 @@ -import 'package:app_flowy/home/domain/edit_context.dart'; +import 'package:app_flowy/workspace/domain/edit_context.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; // ignore: import_of_legacy_library_into_null_safe import 'package:flutter_bloc/flutter_bloc.dart'; -part 'edit_pannel_event.dart'; -part 'edit_pannel_state.dart'; part 'edit_pannel_bloc.freezed.dart'; class EditPannelBloc extends Bloc { @@ -26,3 +24,24 @@ class EditPannelBloc extends Bloc { ); } } + +@freezed +abstract class EditPannelEvent with _$EditPannelEvent { + const factory EditPannelEvent.startEdit(EditPannelContext context) = + _StartEdit; + + const factory EditPannelEvent.endEdit(EditPannelContext context) = _EndEdit; +} + +@freezed +abstract class EditPannelState implements _$EditPannelState { + const factory EditPannelState({ + required bool isEditing, + required Option editContext, + }) = _EditPannelState; + + factory EditPannelState.initial() => EditPannelState( + isEditing: false, + editContext: none(), + ); +} diff --git a/app_flowy/lib/home/application/edit_pannel/edit_pannel_bloc.freezed.dart b/app_flowy/lib/workspace/application/edit_pannel/edit_pannel_bloc.freezed.dart similarity index 100% rename from app_flowy/lib/home/application/edit_pannel/edit_pannel_bloc.freezed.dart rename to app_flowy/lib/workspace/application/edit_pannel/edit_pannel_bloc.freezed.dart diff --git a/app_flowy/lib/workspace/application/home/home_bloc.dart b/app_flowy/lib/workspace/application/home/home_bloc.dart new file mode 100644 index 0000000000..df985d9261 --- /dev/null +++ b/app_flowy/lib/workspace/application/home/home_bloc.dart @@ -0,0 +1,58 @@ +import 'package:app_flowy/workspace/domain/edit_context.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:dartz/dartz.dart'; +part 'home_bloc.freezed.dart'; + +class HomeBloc extends Bloc { + HomeBloc() : super(HomeState.initial()); + + @override + Stream mapEventToState( + HomeEvent event, + ) async* { + yield* event.map( + showLoading: (e) async* { + yield state.copyWith(isLoading: e.isLoading); + }, + setEditPannel: (e) async* { + yield state.copyWith(editContext: some(e.editContext)); + }, + dismissEditPannel: (value) async* { + yield state.copyWith(editContext: none()); + }, + forceCollapse: (e) async* { + yield state.copyWith(forceCollapse: e.forceCollapse); + }, + ); + } + + @override + Future close() { + return super.close(); + } +} + +@freezed +abstract class HomeEvent with _$HomeEvent { + const factory HomeEvent.showLoading(bool isLoading) = _ShowLoading; + const factory HomeEvent.forceCollapse(bool forceCollapse) = _ForceCollapse; + const factory HomeEvent.setEditPannel(EditPannelContext editContext) = + _ShowEditPannel; + const factory HomeEvent.dismissEditPannel() = _DismissEditPannel; +} + +@freezed +abstract class HomeState implements _$HomeState { + const factory HomeState({ + required bool isLoading, + required bool forceCollapse, + required Option editContext, + }) = _HomeState; + + factory HomeState.initial() => HomeState( + isLoading: false, + forceCollapse: false, + editContext: none(), + ); +} diff --git a/app_flowy/lib/home/application/home_bloc.freezed.dart b/app_flowy/lib/workspace/application/home/home_bloc.freezed.dart similarity index 66% rename from app_flowy/lib/home/application/home_bloc.freezed.dart rename to app_flowy/lib/workspace/application/home/home_bloc.freezed.dart index 16ed6f5120..10787b8ac6 100644 --- a/app_flowy/lib/home/application/home_bloc.freezed.dart +++ b/app_flowy/lib/workspace/application/home/home_bloc.freezed.dart @@ -22,15 +22,9 @@ class _$HomeEventTearOff { ); } - _ShowMenu showMenu(bool isShow) { - return _ShowMenu( - isShow, - ); - } - - SetCurrentPage setPage(PageContext context) { - return SetCurrentPage( - context, + _ForceCollapse forceCollapse(bool forceCollapse) { + return _ForceCollapse( + forceCollapse, ); } @@ -53,8 +47,7 @@ mixin _$HomeEvent { @optionalTypeArgs TResult when({ required TResult Function(bool isLoading) showLoading, - required TResult Function(bool isShow) showMenu, - required TResult Function(PageContext context) setPage, + required TResult Function(bool forceCollapse) forceCollapse, required TResult Function(EditPannelContext editContext) setEditPannel, required TResult Function() dismissEditPannel, }) => @@ -62,8 +55,7 @@ mixin _$HomeEvent { @optionalTypeArgs TResult maybeWhen({ TResult Function(bool isLoading)? showLoading, - TResult Function(bool isShow)? showMenu, - TResult Function(PageContext context)? setPage, + TResult Function(bool forceCollapse)? forceCollapse, TResult Function(EditPannelContext editContext)? setEditPannel, TResult Function()? dismissEditPannel, required TResult orElse(), @@ -72,8 +64,7 @@ mixin _$HomeEvent { @optionalTypeArgs TResult map({ required TResult Function(_ShowLoading value) showLoading, - required TResult Function(_ShowMenu value) showMenu, - required TResult Function(SetCurrentPage value) setPage, + required TResult Function(_ForceCollapse value) forceCollapse, required TResult Function(_ShowEditPannel value) setEditPannel, required TResult Function(_DismissEditPannel value) dismissEditPannel, }) => @@ -81,8 +72,7 @@ mixin _$HomeEvent { @optionalTypeArgs TResult maybeMap({ TResult Function(_ShowLoading value)? showLoading, - TResult Function(_ShowMenu value)? showMenu, - TResult Function(SetCurrentPage value)? setPage, + TResult Function(_ForceCollapse value)? forceCollapse, TResult Function(_ShowEditPannel value)? setEditPannel, TResult Function(_DismissEditPannel value)? dismissEditPannel, required TResult orElse(), @@ -171,8 +161,7 @@ class _$_ShowLoading implements _ShowLoading { @optionalTypeArgs TResult when({ required TResult Function(bool isLoading) showLoading, - required TResult Function(bool isShow) showMenu, - required TResult Function(PageContext context) setPage, + required TResult Function(bool forceCollapse) forceCollapse, required TResult Function(EditPannelContext editContext) setEditPannel, required TResult Function() dismissEditPannel, }) { @@ -183,8 +172,7 @@ class _$_ShowLoading implements _ShowLoading { @optionalTypeArgs TResult maybeWhen({ TResult Function(bool isLoading)? showLoading, - TResult Function(bool isShow)? showMenu, - TResult Function(PageContext context)? setPage, + TResult Function(bool forceCollapse)? forceCollapse, TResult Function(EditPannelContext editContext)? setEditPannel, TResult Function()? dismissEditPannel, required TResult orElse(), @@ -199,8 +187,7 @@ class _$_ShowLoading implements _ShowLoading { @optionalTypeArgs TResult map({ required TResult Function(_ShowLoading value) showLoading, - required TResult Function(_ShowMenu value) showMenu, - required TResult Function(SetCurrentPage value) setPage, + required TResult Function(_ForceCollapse value) forceCollapse, required TResult Function(_ShowEditPannel value) setEditPannel, required TResult Function(_DismissEditPannel value) dismissEditPannel, }) { @@ -211,8 +198,7 @@ class _$_ShowLoading implements _ShowLoading { @optionalTypeArgs TResult maybeMap({ TResult Function(_ShowLoading value)? showLoading, - TResult Function(_ShowMenu value)? showMenu, - TResult Function(SetCurrentPage value)? setPage, + TResult Function(_ForceCollapse value)? forceCollapse, TResult Function(_ShowEditPannel value)? setEditPannel, TResult Function(_DismissEditPannel value)? dismissEditPannel, required TResult orElse(), @@ -234,29 +220,31 @@ abstract class _ShowLoading implements HomeEvent { } /// @nodoc -abstract class _$ShowMenuCopyWith<$Res> { - factory _$ShowMenuCopyWith(_ShowMenu value, $Res Function(_ShowMenu) then) = - __$ShowMenuCopyWithImpl<$Res>; - $Res call({bool isShow}); +abstract class _$ForceCollapseCopyWith<$Res> { + factory _$ForceCollapseCopyWith( + _ForceCollapse value, $Res Function(_ForceCollapse) then) = + __$ForceCollapseCopyWithImpl<$Res>; + $Res call({bool forceCollapse}); } /// @nodoc -class __$ShowMenuCopyWithImpl<$Res> extends _$HomeEventCopyWithImpl<$Res> - implements _$ShowMenuCopyWith<$Res> { - __$ShowMenuCopyWithImpl(_ShowMenu _value, $Res Function(_ShowMenu) _then) - : super(_value, (v) => _then(v as _ShowMenu)); +class __$ForceCollapseCopyWithImpl<$Res> extends _$HomeEventCopyWithImpl<$Res> + implements _$ForceCollapseCopyWith<$Res> { + __$ForceCollapseCopyWithImpl( + _ForceCollapse _value, $Res Function(_ForceCollapse) _then) + : super(_value, (v) => _then(v as _ForceCollapse)); @override - _ShowMenu get _value => super._value as _ShowMenu; + _ForceCollapse get _value => super._value as _ForceCollapse; @override $Res call({ - Object? isShow = freezed, + Object? forceCollapse = freezed, }) { - return _then(_ShowMenu( - isShow == freezed - ? _value.isShow - : isShow // ignore: cast_nullable_to_non_nullable + return _then(_ForceCollapse( + forceCollapse == freezed + ? _value.forceCollapse + : forceCollapse // ignore: cast_nullable_to_non_nullable as bool, )); } @@ -264,58 +252,57 @@ class __$ShowMenuCopyWithImpl<$Res> extends _$HomeEventCopyWithImpl<$Res> /// @nodoc -class _$_ShowMenu implements _ShowMenu { - const _$_ShowMenu(this.isShow); +class _$_ForceCollapse implements _ForceCollapse { + const _$_ForceCollapse(this.forceCollapse); @override - final bool isShow; + final bool forceCollapse; @override String toString() { - return 'HomeEvent.showMenu(isShow: $isShow)'; + return 'HomeEvent.forceCollapse(forceCollapse: $forceCollapse)'; } @override bool operator ==(dynamic other) { return identical(this, other) || - (other is _ShowMenu && - (identical(other.isShow, isShow) || - const DeepCollectionEquality().equals(other.isShow, isShow))); + (other is _ForceCollapse && + (identical(other.forceCollapse, forceCollapse) || + const DeepCollectionEquality() + .equals(other.forceCollapse, forceCollapse))); } @override int get hashCode => - runtimeType.hashCode ^ const DeepCollectionEquality().hash(isShow); + runtimeType.hashCode ^ const DeepCollectionEquality().hash(forceCollapse); @JsonKey(ignore: true) @override - _$ShowMenuCopyWith<_ShowMenu> get copyWith => - __$ShowMenuCopyWithImpl<_ShowMenu>(this, _$identity); + _$ForceCollapseCopyWith<_ForceCollapse> get copyWith => + __$ForceCollapseCopyWithImpl<_ForceCollapse>(this, _$identity); @override @optionalTypeArgs TResult when({ required TResult Function(bool isLoading) showLoading, - required TResult Function(bool isShow) showMenu, - required TResult Function(PageContext context) setPage, + required TResult Function(bool forceCollapse) forceCollapse, required TResult Function(EditPannelContext editContext) setEditPannel, required TResult Function() dismissEditPannel, }) { - return showMenu(isShow); + return forceCollapse(this.forceCollapse); } @override @optionalTypeArgs TResult maybeWhen({ TResult Function(bool isLoading)? showLoading, - TResult Function(bool isShow)? showMenu, - TResult Function(PageContext context)? setPage, + TResult Function(bool forceCollapse)? forceCollapse, TResult Function(EditPannelContext editContext)? setEditPannel, TResult Function()? dismissEditPannel, required TResult orElse(), }) { - if (showMenu != null) { - return showMenu(isShow); + if (forceCollapse != null) { + return forceCollapse(this.forceCollapse); } return orElse(); } @@ -324,164 +311,35 @@ class _$_ShowMenu implements _ShowMenu { @optionalTypeArgs TResult map({ required TResult Function(_ShowLoading value) showLoading, - required TResult Function(_ShowMenu value) showMenu, - required TResult Function(SetCurrentPage value) setPage, + required TResult Function(_ForceCollapse value) forceCollapse, required TResult Function(_ShowEditPannel value) setEditPannel, required TResult Function(_DismissEditPannel value) dismissEditPannel, }) { - return showMenu(this); + return forceCollapse(this); } @override @optionalTypeArgs TResult maybeMap({ TResult Function(_ShowLoading value)? showLoading, - TResult Function(_ShowMenu value)? showMenu, - TResult Function(SetCurrentPage value)? setPage, + TResult Function(_ForceCollapse value)? forceCollapse, TResult Function(_ShowEditPannel value)? setEditPannel, TResult Function(_DismissEditPannel value)? dismissEditPannel, required TResult orElse(), }) { - if (showMenu != null) { - return showMenu(this); + if (forceCollapse != null) { + return forceCollapse(this); } return orElse(); } } -abstract class _ShowMenu implements HomeEvent { - const factory _ShowMenu(bool isShow) = _$_ShowMenu; +abstract class _ForceCollapse implements HomeEvent { + const factory _ForceCollapse(bool forceCollapse) = _$_ForceCollapse; - bool get isShow => throw _privateConstructorUsedError; + bool get forceCollapse => throw _privateConstructorUsedError; @JsonKey(ignore: true) - _$ShowMenuCopyWith<_ShowMenu> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $SetCurrentPageCopyWith<$Res> { - factory $SetCurrentPageCopyWith( - SetCurrentPage value, $Res Function(SetCurrentPage) then) = - _$SetCurrentPageCopyWithImpl<$Res>; - $Res call({PageContext context}); -} - -/// @nodoc -class _$SetCurrentPageCopyWithImpl<$Res> extends _$HomeEventCopyWithImpl<$Res> - implements $SetCurrentPageCopyWith<$Res> { - _$SetCurrentPageCopyWithImpl( - SetCurrentPage _value, $Res Function(SetCurrentPage) _then) - : super(_value, (v) => _then(v as SetCurrentPage)); - - @override - SetCurrentPage get _value => super._value as SetCurrentPage; - - @override - $Res call({ - Object? context = freezed, - }) { - return _then(SetCurrentPage( - context == freezed - ? _value.context - : context // ignore: cast_nullable_to_non_nullable - as PageContext, - )); - } -} - -/// @nodoc - -class _$SetCurrentPage implements SetCurrentPage { - const _$SetCurrentPage(this.context); - - @override - final PageContext context; - - @override - String toString() { - return 'HomeEvent.setPage(context: $context)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other is SetCurrentPage && - (identical(other.context, context) || - const DeepCollectionEquality().equals(other.context, context))); - } - - @override - int get hashCode => - runtimeType.hashCode ^ const DeepCollectionEquality().hash(context); - - @JsonKey(ignore: true) - @override - $SetCurrentPageCopyWith get copyWith => - _$SetCurrentPageCopyWithImpl(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(bool isLoading) showLoading, - required TResult Function(bool isShow) showMenu, - required TResult Function(PageContext context) setPage, - required TResult Function(EditPannelContext editContext) setEditPannel, - required TResult Function() dismissEditPannel, - }) { - return setPage(context); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(bool isLoading)? showLoading, - TResult Function(bool isShow)? showMenu, - TResult Function(PageContext context)? setPage, - TResult Function(EditPannelContext editContext)? setEditPannel, - TResult Function()? dismissEditPannel, - required TResult orElse(), - }) { - if (setPage != null) { - return setPage(context); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_ShowLoading value) showLoading, - required TResult Function(_ShowMenu value) showMenu, - required TResult Function(SetCurrentPage value) setPage, - required TResult Function(_ShowEditPannel value) setEditPannel, - required TResult Function(_DismissEditPannel value) dismissEditPannel, - }) { - return setPage(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_ShowLoading value)? showLoading, - TResult Function(_ShowMenu value)? showMenu, - TResult Function(SetCurrentPage value)? setPage, - TResult Function(_ShowEditPannel value)? setEditPannel, - TResult Function(_DismissEditPannel value)? dismissEditPannel, - required TResult orElse(), - }) { - if (setPage != null) { - return setPage(this); - } - return orElse(); - } -} - -abstract class SetCurrentPage implements HomeEvent { - const factory SetCurrentPage(PageContext context) = _$SetCurrentPage; - - PageContext get context => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $SetCurrentPageCopyWith get copyWith => + _$ForceCollapseCopyWith<_ForceCollapse> get copyWith => throw _privateConstructorUsedError; } @@ -551,8 +409,7 @@ class _$_ShowEditPannel implements _ShowEditPannel { @optionalTypeArgs TResult when({ required TResult Function(bool isLoading) showLoading, - required TResult Function(bool isShow) showMenu, - required TResult Function(PageContext context) setPage, + required TResult Function(bool forceCollapse) forceCollapse, required TResult Function(EditPannelContext editContext) setEditPannel, required TResult Function() dismissEditPannel, }) { @@ -563,8 +420,7 @@ class _$_ShowEditPannel implements _ShowEditPannel { @optionalTypeArgs TResult maybeWhen({ TResult Function(bool isLoading)? showLoading, - TResult Function(bool isShow)? showMenu, - TResult Function(PageContext context)? setPage, + TResult Function(bool forceCollapse)? forceCollapse, TResult Function(EditPannelContext editContext)? setEditPannel, TResult Function()? dismissEditPannel, required TResult orElse(), @@ -579,8 +435,7 @@ class _$_ShowEditPannel implements _ShowEditPannel { @optionalTypeArgs TResult map({ required TResult Function(_ShowLoading value) showLoading, - required TResult Function(_ShowMenu value) showMenu, - required TResult Function(SetCurrentPage value) setPage, + required TResult Function(_ForceCollapse value) forceCollapse, required TResult Function(_ShowEditPannel value) setEditPannel, required TResult Function(_DismissEditPannel value) dismissEditPannel, }) { @@ -591,8 +446,7 @@ class _$_ShowEditPannel implements _ShowEditPannel { @optionalTypeArgs TResult maybeMap({ TResult Function(_ShowLoading value)? showLoading, - TResult Function(_ShowMenu value)? showMenu, - TResult Function(SetCurrentPage value)? setPage, + TResult Function(_ForceCollapse value)? forceCollapse, TResult Function(_ShowEditPannel value)? setEditPannel, TResult Function(_DismissEditPannel value)? dismissEditPannel, required TResult orElse(), @@ -655,8 +509,7 @@ class _$_DismissEditPannel implements _DismissEditPannel { @optionalTypeArgs TResult when({ required TResult Function(bool isLoading) showLoading, - required TResult Function(bool isShow) showMenu, - required TResult Function(PageContext context) setPage, + required TResult Function(bool forceCollapse) forceCollapse, required TResult Function(EditPannelContext editContext) setEditPannel, required TResult Function() dismissEditPannel, }) { @@ -667,8 +520,7 @@ class _$_DismissEditPannel implements _DismissEditPannel { @optionalTypeArgs TResult maybeWhen({ TResult Function(bool isLoading)? showLoading, - TResult Function(bool isShow)? showMenu, - TResult Function(PageContext context)? setPage, + TResult Function(bool forceCollapse)? forceCollapse, TResult Function(EditPannelContext editContext)? setEditPannel, TResult Function()? dismissEditPannel, required TResult orElse(), @@ -683,8 +535,7 @@ class _$_DismissEditPannel implements _DismissEditPannel { @optionalTypeArgs TResult map({ required TResult Function(_ShowLoading value) showLoading, - required TResult Function(_ShowMenu value) showMenu, - required TResult Function(SetCurrentPage value) setPage, + required TResult Function(_ForceCollapse value) forceCollapse, required TResult Function(_ShowEditPannel value) setEditPannel, required TResult Function(_DismissEditPannel value) dismissEditPannel, }) { @@ -695,8 +546,7 @@ class _$_DismissEditPannel implements _DismissEditPannel { @optionalTypeArgs TResult maybeMap({ TResult Function(_ShowLoading value)? showLoading, - TResult Function(_ShowMenu value)? showMenu, - TResult Function(SetCurrentPage value)? setPage, + TResult Function(_ForceCollapse value)? forceCollapse, TResult Function(_ShowEditPannel value)? setEditPannel, TResult Function(_DismissEditPannel value)? dismissEditPannel, required TResult orElse(), @@ -718,13 +568,11 @@ class _$HomeStateTearOff { _HomeState call( {required bool isLoading, - required bool showMenu, - required PageContext pageContext, + required bool forceCollapse, required Option editContext}) { return _HomeState( isLoading: isLoading, - showMenu: showMenu, - pageContext: pageContext, + forceCollapse: forceCollapse, editContext: editContext, ); } @@ -736,8 +584,7 @@ const $HomeState = _$HomeStateTearOff(); /// @nodoc mixin _$HomeState { bool get isLoading => throw _privateConstructorUsedError; - bool get showMenu => throw _privateConstructorUsedError; - PageContext get pageContext => throw _privateConstructorUsedError; + bool get forceCollapse => throw _privateConstructorUsedError; Option get editContext => throw _privateConstructorUsedError; @@ -752,8 +599,7 @@ abstract class $HomeStateCopyWith<$Res> { _$HomeStateCopyWithImpl<$Res>; $Res call( {bool isLoading, - bool showMenu, - PageContext pageContext, + bool forceCollapse, Option editContext}); } @@ -768,8 +614,7 @@ class _$HomeStateCopyWithImpl<$Res> implements $HomeStateCopyWith<$Res> { @override $Res call({ Object? isLoading = freezed, - Object? showMenu = freezed, - Object? pageContext = freezed, + Object? forceCollapse = freezed, Object? editContext = freezed, }) { return _then(_value.copyWith( @@ -777,14 +622,10 @@ class _$HomeStateCopyWithImpl<$Res> implements $HomeStateCopyWith<$Res> { ? _value.isLoading : isLoading // ignore: cast_nullable_to_non_nullable as bool, - showMenu: showMenu == freezed - ? _value.showMenu - : showMenu // ignore: cast_nullable_to_non_nullable + forceCollapse: forceCollapse == freezed + ? _value.forceCollapse + : forceCollapse // ignore: cast_nullable_to_non_nullable as bool, - pageContext: pageContext == freezed - ? _value.pageContext - : pageContext // ignore: cast_nullable_to_non_nullable - as PageContext, editContext: editContext == freezed ? _value.editContext : editContext // ignore: cast_nullable_to_non_nullable @@ -801,8 +642,7 @@ abstract class _$HomeStateCopyWith<$Res> implements $HomeStateCopyWith<$Res> { @override $Res call( {bool isLoading, - bool showMenu, - PageContext pageContext, + bool forceCollapse, Option editContext}); } @@ -818,8 +658,7 @@ class __$HomeStateCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res> @override $Res call({ Object? isLoading = freezed, - Object? showMenu = freezed, - Object? pageContext = freezed, + Object? forceCollapse = freezed, Object? editContext = freezed, }) { return _then(_HomeState( @@ -827,14 +666,10 @@ class __$HomeStateCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res> ? _value.isLoading : isLoading // ignore: cast_nullable_to_non_nullable as bool, - showMenu: showMenu == freezed - ? _value.showMenu - : showMenu // ignore: cast_nullable_to_non_nullable + forceCollapse: forceCollapse == freezed + ? _value.forceCollapse + : forceCollapse // ignore: cast_nullable_to_non_nullable as bool, - pageContext: pageContext == freezed - ? _value.pageContext - : pageContext // ignore: cast_nullable_to_non_nullable - as PageContext, editContext: editContext == freezed ? _value.editContext : editContext // ignore: cast_nullable_to_non_nullable @@ -848,22 +683,19 @@ class __$HomeStateCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res> class _$_HomeState implements _HomeState { const _$_HomeState( {required this.isLoading, - required this.showMenu, - required this.pageContext, + required this.forceCollapse, required this.editContext}); @override final bool isLoading; @override - final bool showMenu; - @override - final PageContext pageContext; + final bool forceCollapse; @override final Option editContext; @override String toString() { - return 'HomeState(isLoading: $isLoading, showMenu: $showMenu, pageContext: $pageContext, editContext: $editContext)'; + return 'HomeState(isLoading: $isLoading, forceCollapse: $forceCollapse, editContext: $editContext)'; } @override @@ -873,12 +705,9 @@ class _$_HomeState implements _HomeState { (identical(other.isLoading, isLoading) || const DeepCollectionEquality() .equals(other.isLoading, isLoading)) && - (identical(other.showMenu, showMenu) || + (identical(other.forceCollapse, forceCollapse) || const DeepCollectionEquality() - .equals(other.showMenu, showMenu)) && - (identical(other.pageContext, pageContext) || - const DeepCollectionEquality() - .equals(other.pageContext, pageContext)) && + .equals(other.forceCollapse, forceCollapse)) && (identical(other.editContext, editContext) || const DeepCollectionEquality() .equals(other.editContext, editContext))); @@ -888,8 +717,7 @@ class _$_HomeState implements _HomeState { int get hashCode => runtimeType.hashCode ^ const DeepCollectionEquality().hash(isLoading) ^ - const DeepCollectionEquality().hash(showMenu) ^ - const DeepCollectionEquality().hash(pageContext) ^ + const DeepCollectionEquality().hash(forceCollapse) ^ const DeepCollectionEquality().hash(editContext); @JsonKey(ignore: true) @@ -901,16 +729,13 @@ class _$_HomeState implements _HomeState { abstract class _HomeState implements HomeState { const factory _HomeState( {required bool isLoading, - required bool showMenu, - required PageContext pageContext, + required bool forceCollapse, required Option editContext}) = _$_HomeState; @override bool get isLoading => throw _privateConstructorUsedError; @override - bool get showMenu => throw _privateConstructorUsedError; - @override - PageContext get pageContext => throw _privateConstructorUsedError; + bool get forceCollapse => throw _privateConstructorUsedError; @override Option get editContext => throw _privateConstructorUsedError; diff --git a/app_flowy/lib/home/application/watcher/home_watcher_bloc.dart b/app_flowy/lib/workspace/application/home/home_watcher_bloc.dart similarity index 53% rename from app_flowy/lib/home/application/watcher/home_watcher_bloc.dart rename to app_flowy/lib/workspace/application/home/home_watcher_bloc.dart index afb787e980..d6d86c59de 100644 --- a/app_flowy/lib/home/application/watcher/home_watcher_bloc.dart +++ b/app_flowy/lib/workspace/application/home/home_watcher_bloc.dart @@ -1,10 +1,7 @@ import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -// ignore: import_of_legacy_library_into_null_safe import 'package:flutter_bloc/flutter_bloc.dart'; -part 'home_watcher_event.dart'; -part 'home_watcher_state.dart'; part 'home_watcher_bloc.freezed.dart'; class HomeWatcherBloc extends Bloc { @@ -17,3 +14,15 @@ class HomeWatcherBloc extends Bloc { yield state; } } + +@freezed +abstract class HomeWatcherEvent with _$HomeWatcherEvent { + const factory HomeWatcherEvent.started(String workspaceId) = _Started; + const factory HomeWatcherEvent.stop(String workspaceId) = _Stop; +} + +@freezed +abstract class HomeWatcherState with _$HomeWatcherState { + const factory HomeWatcherState.initial() = _Initial; + const factory HomeWatcherState.loading() = _Loading; +} diff --git a/app_flowy/lib/home/application/watcher/home_watcher_bloc.freezed.dart b/app_flowy/lib/workspace/application/home/home_watcher_bloc.freezed.dart similarity index 100% rename from app_flowy/lib/home/application/watcher/home_watcher_bloc.freezed.dart rename to app_flowy/lib/workspace/application/home/home_watcher_bloc.freezed.dart diff --git a/app_flowy/lib/workspace/application/menu/menu_bloc.dart b/app_flowy/lib/workspace/application/menu/menu_bloc.dart new file mode 100644 index 0000000000..39e2e09c2b --- /dev/null +++ b/app_flowy/lib/workspace/application/menu/menu_bloc.dart @@ -0,0 +1,86 @@ +import 'dart:async'; +import 'package:app_flowy/workspace/domain/i_workspace.dart'; +import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:flutter/material.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +part 'menu_bloc.freezed.dart'; + +class MenuBloc extends Bloc { + final IWorkspace iWorkspaceImpl; + MenuBloc(this.iWorkspaceImpl) : super(MenuState.initial()); + + @override + Stream mapEventToState( + MenuEvent event, + ) async* { + yield* event.map( + initial: (value) async* { + yield* _fetchApps(); + }, + collapse: (e) async* { + final isCollapse = state.isCollapse; + yield state.copyWith(isCollapse: !isCollapse); + }, + openPage: (OpenPage e) async* { + yield* _performActionOnOpenPage(e); + }, + createApp: (CreateApp event) async* { + yield* _performActionOnCreateApp(event); + }, + ); + } + + Stream _performActionOnOpenPage(OpenPage e) async* { + yield state.copyWith(stackView: e.stackView); + } + + Stream _performActionOnCreateApp(CreateApp event) async* { + await iWorkspaceImpl + .createApp(name: event.name, desc: event.desc) + .then((result) async* { + result.fold( + (app) => {}, + (error) async* { + yield state.copyWith(successOrFailure: right(error)); + }, + ); + }); + } + + Stream _fetchApps() async* { + final appsOrFail = await iWorkspaceImpl.getApps(); + yield appsOrFail.fold( + (apps) => state.copyWith(apps: some(apps)), + (error) => state.copyWith(successOrFailure: right(error)), + ); + } +} + +@freezed +abstract class MenuEvent with _$MenuEvent { + const factory MenuEvent.initial() = _Initial; + const factory MenuEvent.collapse() = Collapse; + const factory MenuEvent.openPage(HomeStackView stackView) = OpenPage; + const factory MenuEvent.createApp(String name, {String? desc}) = CreateApp; +} + +@freezed +abstract class MenuState implements _$MenuState { + const factory MenuState({ + required bool isCollapse, + required Option> apps, + required Either successOrFailure, + HomeStackView? stackView, + }) = _MenuState; + + factory MenuState.initial() => MenuState( + isCollapse: false, + apps: none(), + successOrFailure: left(unit), + ); +} diff --git a/app_flowy/lib/workspace/application/menu/menu_bloc.freezed.dart b/app_flowy/lib/workspace/application/menu/menu_bloc.freezed.dart new file mode 100644 index 0000000000..fda402a807 --- /dev/null +++ b/app_flowy/lib/workspace/application/menu/menu_bloc.freezed.dart @@ -0,0 +1,739 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'menu_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$MenuEventTearOff { + const _$MenuEventTearOff(); + + _Initial initial() { + return const _Initial(); + } + + Collapse collapse() { + return const Collapse(); + } + + OpenPage openPage(HomeStackView stackView) { + return OpenPage( + stackView, + ); + } + + CreateApp createApp(String name, {String? desc}) { + return CreateApp( + name, + desc: desc, + ); + } +} + +/// @nodoc +const $MenuEvent = _$MenuEventTearOff(); + +/// @nodoc +mixin _$MenuEvent { + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() collapse, + required TResult Function(HomeStackView stackView) openPage, + required TResult Function(String name, String? desc) createApp, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? collapse, + TResult Function(HomeStackView stackView)? openPage, + TResult Function(String name, String? desc)? createApp, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(Collapse value) collapse, + required TResult Function(OpenPage value) openPage, + required TResult Function(CreateApp value) createApp, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(Collapse value)? collapse, + TResult Function(OpenPage value)? openPage, + TResult Function(CreateApp value)? createApp, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MenuEventCopyWith<$Res> { + factory $MenuEventCopyWith(MenuEvent value, $Res Function(MenuEvent) then) = + _$MenuEventCopyWithImpl<$Res>; +} + +/// @nodoc +class _$MenuEventCopyWithImpl<$Res> implements $MenuEventCopyWith<$Res> { + _$MenuEventCopyWithImpl(this._value, this._then); + + final MenuEvent _value; + // ignore: unused_field + final $Res Function(MenuEvent) _then; +} + +/// @nodoc +abstract class _$InitialCopyWith<$Res> { + factory _$InitialCopyWith(_Initial value, $Res Function(_Initial) then) = + __$InitialCopyWithImpl<$Res>; +} + +/// @nodoc +class __$InitialCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> + implements _$InitialCopyWith<$Res> { + __$InitialCopyWithImpl(_Initial _value, $Res Function(_Initial) _then) + : super(_value, (v) => _then(v as _Initial)); + + @override + _Initial get _value => super._value as _Initial; +} + +/// @nodoc + +class _$_Initial implements _Initial { + const _$_Initial(); + + @override + String toString() { + return 'MenuEvent.initial()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _Initial); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() collapse, + required TResult Function(HomeStackView stackView) openPage, + required TResult Function(String name, String? desc) createApp, + }) { + return initial(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? collapse, + TResult Function(HomeStackView stackView)? openPage, + TResult Function(String name, String? desc)? createApp, + required TResult orElse(), + }) { + if (initial != null) { + return initial(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(Collapse value) collapse, + required TResult Function(OpenPage value) openPage, + required TResult Function(CreateApp value) createApp, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(Collapse value)? collapse, + TResult Function(OpenPage value)? openPage, + TResult Function(CreateApp value)? createApp, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class _Initial implements MenuEvent { + const factory _Initial() = _$_Initial; +} + +/// @nodoc +abstract class $CollapseCopyWith<$Res> { + factory $CollapseCopyWith(Collapse value, $Res Function(Collapse) then) = + _$CollapseCopyWithImpl<$Res>; +} + +/// @nodoc +class _$CollapseCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> + implements $CollapseCopyWith<$Res> { + _$CollapseCopyWithImpl(Collapse _value, $Res Function(Collapse) _then) + : super(_value, (v) => _then(v as Collapse)); + + @override + Collapse get _value => super._value as Collapse; +} + +/// @nodoc + +class _$Collapse implements Collapse { + const _$Collapse(); + + @override + String toString() { + return 'MenuEvent.collapse()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is Collapse); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() collapse, + required TResult Function(HomeStackView stackView) openPage, + required TResult Function(String name, String? desc) createApp, + }) { + return collapse(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? collapse, + TResult Function(HomeStackView stackView)? openPage, + TResult Function(String name, String? desc)? createApp, + required TResult orElse(), + }) { + if (collapse != null) { + return collapse(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(Collapse value) collapse, + required TResult Function(OpenPage value) openPage, + required TResult Function(CreateApp value) createApp, + }) { + return collapse(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(Collapse value)? collapse, + TResult Function(OpenPage value)? openPage, + TResult Function(CreateApp value)? createApp, + required TResult orElse(), + }) { + if (collapse != null) { + return collapse(this); + } + return orElse(); + } +} + +abstract class Collapse implements MenuEvent { + const factory Collapse() = _$Collapse; +} + +/// @nodoc +abstract class $OpenPageCopyWith<$Res> { + factory $OpenPageCopyWith(OpenPage value, $Res Function(OpenPage) then) = + _$OpenPageCopyWithImpl<$Res>; + $Res call({HomeStackView stackView}); +} + +/// @nodoc +class _$OpenPageCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> + implements $OpenPageCopyWith<$Res> { + _$OpenPageCopyWithImpl(OpenPage _value, $Res Function(OpenPage) _then) + : super(_value, (v) => _then(v as OpenPage)); + + @override + OpenPage get _value => super._value as OpenPage; + + @override + $Res call({ + Object? stackView = freezed, + }) { + return _then(OpenPage( + stackView == freezed + ? _value.stackView + : stackView // ignore: cast_nullable_to_non_nullable + as HomeStackView, + )); + } +} + +/// @nodoc + +class _$OpenPage implements OpenPage { + const _$OpenPage(this.stackView); + + @override + final HomeStackView stackView; + + @override + String toString() { + return 'MenuEvent.openPage(stackView: $stackView)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is OpenPage && + (identical(other.stackView, stackView) || + const DeepCollectionEquality() + .equals(other.stackView, stackView))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(stackView); + + @JsonKey(ignore: true) + @override + $OpenPageCopyWith get copyWith => + _$OpenPageCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() collapse, + required TResult Function(HomeStackView stackView) openPage, + required TResult Function(String name, String? desc) createApp, + }) { + return openPage(stackView); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? collapse, + TResult Function(HomeStackView stackView)? openPage, + TResult Function(String name, String? desc)? createApp, + required TResult orElse(), + }) { + if (openPage != null) { + return openPage(stackView); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(Collapse value) collapse, + required TResult Function(OpenPage value) openPage, + required TResult Function(CreateApp value) createApp, + }) { + return openPage(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(Collapse value)? collapse, + TResult Function(OpenPage value)? openPage, + TResult Function(CreateApp value)? createApp, + required TResult orElse(), + }) { + if (openPage != null) { + return openPage(this); + } + return orElse(); + } +} + +abstract class OpenPage implements MenuEvent { + const factory OpenPage(HomeStackView stackView) = _$OpenPage; + + HomeStackView get stackView => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $OpenPageCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $CreateAppCopyWith<$Res> { + factory $CreateAppCopyWith(CreateApp value, $Res Function(CreateApp) then) = + _$CreateAppCopyWithImpl<$Res>; + $Res call({String name, String? desc}); +} + +/// @nodoc +class _$CreateAppCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> + implements $CreateAppCopyWith<$Res> { + _$CreateAppCopyWithImpl(CreateApp _value, $Res Function(CreateApp) _then) + : super(_value, (v) => _then(v as CreateApp)); + + @override + CreateApp get _value => super._value as CreateApp; + + @override + $Res call({ + Object? name = freezed, + Object? desc = freezed, + }) { + return _then(CreateApp( + name == freezed + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + desc: desc == freezed + ? _value.desc + : desc // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +class _$CreateApp implements CreateApp { + const _$CreateApp(this.name, {this.desc}); + + @override + final String name; + @override + final String? desc; + + @override + String toString() { + return 'MenuEvent.createApp(name: $name, desc: $desc)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is CreateApp && + (identical(other.name, name) || + const DeepCollectionEquality().equals(other.name, name)) && + (identical(other.desc, desc) || + const DeepCollectionEquality().equals(other.desc, desc))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(name) ^ + const DeepCollectionEquality().hash(desc); + + @JsonKey(ignore: true) + @override + $CreateAppCopyWith get copyWith => + _$CreateAppCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() collapse, + required TResult Function(HomeStackView stackView) openPage, + required TResult Function(String name, String? desc) createApp, + }) { + return createApp(name, desc); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? collapse, + TResult Function(HomeStackView stackView)? openPage, + TResult Function(String name, String? desc)? createApp, + required TResult orElse(), + }) { + if (createApp != null) { + return createApp(name, desc); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(Collapse value) collapse, + required TResult Function(OpenPage value) openPage, + required TResult Function(CreateApp value) createApp, + }) { + return createApp(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(Collapse value)? collapse, + TResult Function(OpenPage value)? openPage, + TResult Function(CreateApp value)? createApp, + required TResult orElse(), + }) { + if (createApp != null) { + return createApp(this); + } + return orElse(); + } +} + +abstract class CreateApp implements MenuEvent { + const factory CreateApp(String name, {String? desc}) = _$CreateApp; + + String get name => throw _privateConstructorUsedError; + String? get desc => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $CreateAppCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +class _$MenuStateTearOff { + const _$MenuStateTearOff(); + + _MenuState call( + {required bool isCollapse, + required Option> apps, + required Either successOrFailure, + HomeStackView? stackView}) { + return _MenuState( + isCollapse: isCollapse, + apps: apps, + successOrFailure: successOrFailure, + stackView: stackView, + ); + } +} + +/// @nodoc +const $MenuState = _$MenuStateTearOff(); + +/// @nodoc +mixin _$MenuState { + bool get isCollapse => throw _privateConstructorUsedError; + Option> get apps => throw _privateConstructorUsedError; + Either get successOrFailure => + throw _privateConstructorUsedError; + HomeStackView? get stackView => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $MenuStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MenuStateCopyWith<$Res> { + factory $MenuStateCopyWith(MenuState value, $Res Function(MenuState) then) = + _$MenuStateCopyWithImpl<$Res>; + $Res call( + {bool isCollapse, + Option> apps, + Either successOrFailure, + HomeStackView? stackView}); +} + +/// @nodoc +class _$MenuStateCopyWithImpl<$Res> implements $MenuStateCopyWith<$Res> { + _$MenuStateCopyWithImpl(this._value, this._then); + + final MenuState _value; + // ignore: unused_field + final $Res Function(MenuState) _then; + + @override + $Res call({ + Object? isCollapse = freezed, + Object? apps = freezed, + Object? successOrFailure = freezed, + Object? stackView = freezed, + }) { + return _then(_value.copyWith( + isCollapse: isCollapse == freezed + ? _value.isCollapse + : isCollapse // ignore: cast_nullable_to_non_nullable + as bool, + apps: apps == freezed + ? _value.apps + : apps // ignore: cast_nullable_to_non_nullable + as Option>, + successOrFailure: successOrFailure == freezed + ? _value.successOrFailure + : successOrFailure // ignore: cast_nullable_to_non_nullable + as Either, + stackView: stackView == freezed + ? _value.stackView + : stackView // ignore: cast_nullable_to_non_nullable + as HomeStackView?, + )); + } +} + +/// @nodoc +abstract class _$MenuStateCopyWith<$Res> implements $MenuStateCopyWith<$Res> { + factory _$MenuStateCopyWith( + _MenuState value, $Res Function(_MenuState) then) = + __$MenuStateCopyWithImpl<$Res>; + @override + $Res call( + {bool isCollapse, + Option> apps, + Either successOrFailure, + HomeStackView? stackView}); +} + +/// @nodoc +class __$MenuStateCopyWithImpl<$Res> extends _$MenuStateCopyWithImpl<$Res> + implements _$MenuStateCopyWith<$Res> { + __$MenuStateCopyWithImpl(_MenuState _value, $Res Function(_MenuState) _then) + : super(_value, (v) => _then(v as _MenuState)); + + @override + _MenuState get _value => super._value as _MenuState; + + @override + $Res call({ + Object? isCollapse = freezed, + Object? apps = freezed, + Object? successOrFailure = freezed, + Object? stackView = freezed, + }) { + return _then(_MenuState( + isCollapse: isCollapse == freezed + ? _value.isCollapse + : isCollapse // ignore: cast_nullable_to_non_nullable + as bool, + apps: apps == freezed + ? _value.apps + : apps // ignore: cast_nullable_to_non_nullable + as Option>, + successOrFailure: successOrFailure == freezed + ? _value.successOrFailure + : successOrFailure // ignore: cast_nullable_to_non_nullable + as Either, + stackView: stackView == freezed + ? _value.stackView + : stackView // ignore: cast_nullable_to_non_nullable + as HomeStackView?, + )); + } +} + +/// @nodoc + +class _$_MenuState implements _MenuState { + const _$_MenuState( + {required this.isCollapse, + required this.apps, + required this.successOrFailure, + this.stackView}); + + @override + final bool isCollapse; + @override + final Option> apps; + @override + final Either successOrFailure; + @override + final HomeStackView? stackView; + + @override + String toString() { + return 'MenuState(isCollapse: $isCollapse, apps: $apps, successOrFailure: $successOrFailure, stackView: $stackView)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _MenuState && + (identical(other.isCollapse, isCollapse) || + const DeepCollectionEquality() + .equals(other.isCollapse, isCollapse)) && + (identical(other.apps, apps) || + const DeepCollectionEquality().equals(other.apps, apps)) && + (identical(other.successOrFailure, successOrFailure) || + const DeepCollectionEquality() + .equals(other.successOrFailure, successOrFailure)) && + (identical(other.stackView, stackView) || + const DeepCollectionEquality() + .equals(other.stackView, stackView))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(isCollapse) ^ + const DeepCollectionEquality().hash(apps) ^ + const DeepCollectionEquality().hash(successOrFailure) ^ + const DeepCollectionEquality().hash(stackView); + + @JsonKey(ignore: true) + @override + _$MenuStateCopyWith<_MenuState> get copyWith => + __$MenuStateCopyWithImpl<_MenuState>(this, _$identity); +} + +abstract class _MenuState implements MenuState { + const factory _MenuState( + {required bool isCollapse, + required Option> apps, + required Either successOrFailure, + HomeStackView? stackView}) = _$_MenuState; + + @override + bool get isCollapse => throw _privateConstructorUsedError; + @override + Option> get apps => throw _privateConstructorUsedError; + @override + Either get successOrFailure => + throw _privateConstructorUsedError; + @override + HomeStackView? get stackView => throw _privateConstructorUsedError; + @override + @JsonKey(ignore: true) + _$MenuStateCopyWith<_MenuState> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/app_flowy/lib/workspace/application/menu/menu_watch.dart b/app_flowy/lib/workspace/application/menu/menu_watch.dart new file mode 100644 index 0000000000..2e0f5f2f93 --- /dev/null +++ b/app_flowy/lib/workspace/application/menu/menu_watch.dart @@ -0,0 +1,64 @@ +import 'package:app_flowy/workspace/domain/i_workspace.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:flutter/material.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:dartz/dartz.dart'; + +part 'menu_watch.freezed.dart'; + +class MenuWatchBloc extends Bloc { + final IWorkspaceWatch watcher; + MenuWatchBloc(this.watcher) : super(const MenuWatchState.initial()); + + @override + Stream mapEventToState(MenuWatchEvent event) async* { + yield* event.map( + started: (_) async* { + watcher.startWatching( + addAppCallback: (appsOrFail) => _handleAppsOrFail(appsOrFail), + ); + }, + appsReceived: (e) async* { + yield e.appsOrFail.fold( + (apps) => MenuWatchState.loadApps(apps), + (error) => MenuWatchState.loadFail(error), + ); + }, + ); + } + + @override + Future close() async { + await watcher.stopWatching(); + return super.close(); + } + + void _handleAppsOrFail(Either, WorkspaceError> appsOrFail) { + appsOrFail.fold( + (apps) => add(MenuWatchEvent.appsReceived(left(apps))), + (error) => add(MenuWatchEvent.appsReceived(right(error))), + ); + } +} + +@freezed +abstract class MenuWatchEvent with _$MenuWatchEvent { + const factory MenuWatchEvent.started() = _Started; + const factory MenuWatchEvent.appsReceived( + Either, WorkspaceError> appsOrFail) = AppsReceived; +} + +@freezed +abstract class MenuWatchState with _$MenuWatchState { + const factory MenuWatchState.initial() = _Initial; + + const factory MenuWatchState.loadApps( + List apps, + ) = _LoadApps; + + const factory MenuWatchState.loadFail( + WorkspaceError error, + ) = _LoadFail; +} diff --git a/app_flowy/lib/workspace/application/menu/menu_watch.freezed.dart b/app_flowy/lib/workspace/application/menu/menu_watch.freezed.dart new file mode 100644 index 0000000000..31d0ed42a0 --- /dev/null +++ b/app_flowy/lib/workspace/application/menu/menu_watch.freezed.dart @@ -0,0 +1,682 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'menu_watch.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$MenuWatchEventTearOff { + const _$MenuWatchEventTearOff(); + + _Started started() { + return const _Started(); + } + + AppsReceived appsReceived(Either, WorkspaceError> appsOrFail) { + return AppsReceived( + appsOrFail, + ); + } +} + +/// @nodoc +const $MenuWatchEvent = _$MenuWatchEventTearOff(); + +/// @nodoc +mixin _$MenuWatchEvent { + @optionalTypeArgs + TResult when({ + required TResult Function() started, + required TResult Function(Either, WorkspaceError> appsOrFail) + appsReceived, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? started, + TResult Function(Either, WorkspaceError> appsOrFail)? + appsReceived, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_Started value) started, + required TResult Function(AppsReceived value) appsReceived, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Started value)? started, + TResult Function(AppsReceived value)? appsReceived, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MenuWatchEventCopyWith<$Res> { + factory $MenuWatchEventCopyWith( + MenuWatchEvent value, $Res Function(MenuWatchEvent) then) = + _$MenuWatchEventCopyWithImpl<$Res>; +} + +/// @nodoc +class _$MenuWatchEventCopyWithImpl<$Res> + implements $MenuWatchEventCopyWith<$Res> { + _$MenuWatchEventCopyWithImpl(this._value, this._then); + + final MenuWatchEvent _value; + // ignore: unused_field + final $Res Function(MenuWatchEvent) _then; +} + +/// @nodoc +abstract class _$StartedCopyWith<$Res> { + factory _$StartedCopyWith(_Started value, $Res Function(_Started) then) = + __$StartedCopyWithImpl<$Res>; +} + +/// @nodoc +class __$StartedCopyWithImpl<$Res> extends _$MenuWatchEventCopyWithImpl<$Res> + implements _$StartedCopyWith<$Res> { + __$StartedCopyWithImpl(_Started _value, $Res Function(_Started) _then) + : super(_value, (v) => _then(v as _Started)); + + @override + _Started get _value => super._value as _Started; +} + +/// @nodoc + +class _$_Started implements _Started { + const _$_Started(); + + @override + String toString() { + return 'MenuWatchEvent.started()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _Started); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() started, + required TResult Function(Either, WorkspaceError> appsOrFail) + appsReceived, + }) { + return started(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? started, + TResult Function(Either, WorkspaceError> appsOrFail)? + appsReceived, + required TResult orElse(), + }) { + if (started != null) { + return started(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Started value) started, + required TResult Function(AppsReceived value) appsReceived, + }) { + return started(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Started value)? started, + TResult Function(AppsReceived value)? appsReceived, + required TResult orElse(), + }) { + if (started != null) { + return started(this); + } + return orElse(); + } +} + +abstract class _Started implements MenuWatchEvent { + const factory _Started() = _$_Started; +} + +/// @nodoc +abstract class $AppsReceivedCopyWith<$Res> { + factory $AppsReceivedCopyWith( + AppsReceived value, $Res Function(AppsReceived) then) = + _$AppsReceivedCopyWithImpl<$Res>; + $Res call({Either, WorkspaceError> appsOrFail}); +} + +/// @nodoc +class _$AppsReceivedCopyWithImpl<$Res> + extends _$MenuWatchEventCopyWithImpl<$Res> + implements $AppsReceivedCopyWith<$Res> { + _$AppsReceivedCopyWithImpl( + AppsReceived _value, $Res Function(AppsReceived) _then) + : super(_value, (v) => _then(v as AppsReceived)); + + @override + AppsReceived get _value => super._value as AppsReceived; + + @override + $Res call({ + Object? appsOrFail = freezed, + }) { + return _then(AppsReceived( + appsOrFail == freezed + ? _value.appsOrFail + : appsOrFail // ignore: cast_nullable_to_non_nullable + as Either, WorkspaceError>, + )); + } +} + +/// @nodoc + +class _$AppsReceived implements AppsReceived { + const _$AppsReceived(this.appsOrFail); + + @override + final Either, WorkspaceError> appsOrFail; + + @override + String toString() { + return 'MenuWatchEvent.appsReceived(appsOrFail: $appsOrFail)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is AppsReceived && + (identical(other.appsOrFail, appsOrFail) || + const DeepCollectionEquality() + .equals(other.appsOrFail, appsOrFail))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(appsOrFail); + + @JsonKey(ignore: true) + @override + $AppsReceivedCopyWith get copyWith => + _$AppsReceivedCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() started, + required TResult Function(Either, WorkspaceError> appsOrFail) + appsReceived, + }) { + return appsReceived(appsOrFail); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? started, + TResult Function(Either, WorkspaceError> appsOrFail)? + appsReceived, + required TResult orElse(), + }) { + if (appsReceived != null) { + return appsReceived(appsOrFail); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Started value) started, + required TResult Function(AppsReceived value) appsReceived, + }) { + return appsReceived(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Started value)? started, + TResult Function(AppsReceived value)? appsReceived, + required TResult orElse(), + }) { + if (appsReceived != null) { + return appsReceived(this); + } + return orElse(); + } +} + +abstract class AppsReceived implements MenuWatchEvent { + const factory AppsReceived(Either, WorkspaceError> appsOrFail) = + _$AppsReceived; + + Either, WorkspaceError> get appsOrFail => + throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $AppsReceivedCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +class _$MenuWatchStateTearOff { + const _$MenuWatchStateTearOff(); + + _Initial initial() { + return const _Initial(); + } + + _LoadApps loadApps(List apps) { + return _LoadApps( + apps, + ); + } + + _LoadFail loadFail(WorkspaceError error) { + return _LoadFail( + error, + ); + } +} + +/// @nodoc +const $MenuWatchState = _$MenuWatchStateTearOff(); + +/// @nodoc +mixin _$MenuWatchState { + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(List apps) loadApps, + required TResult Function(WorkspaceError error) loadFail, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(List apps)? loadApps, + TResult Function(WorkspaceError error)? loadFail, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_LoadApps value) loadApps, + required TResult Function(_LoadFail value) loadFail, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_LoadApps value)? loadApps, + TResult Function(_LoadFail value)? loadFail, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MenuWatchStateCopyWith<$Res> { + factory $MenuWatchStateCopyWith( + MenuWatchState value, $Res Function(MenuWatchState) then) = + _$MenuWatchStateCopyWithImpl<$Res>; +} + +/// @nodoc +class _$MenuWatchStateCopyWithImpl<$Res> + implements $MenuWatchStateCopyWith<$Res> { + _$MenuWatchStateCopyWithImpl(this._value, this._then); + + final MenuWatchState _value; + // ignore: unused_field + final $Res Function(MenuWatchState) _then; +} + +/// @nodoc +abstract class _$InitialCopyWith<$Res> { + factory _$InitialCopyWith(_Initial value, $Res Function(_Initial) then) = + __$InitialCopyWithImpl<$Res>; +} + +/// @nodoc +class __$InitialCopyWithImpl<$Res> extends _$MenuWatchStateCopyWithImpl<$Res> + implements _$InitialCopyWith<$Res> { + __$InitialCopyWithImpl(_Initial _value, $Res Function(_Initial) _then) + : super(_value, (v) => _then(v as _Initial)); + + @override + _Initial get _value => super._value as _Initial; +} + +/// @nodoc + +class _$_Initial implements _Initial { + const _$_Initial(); + + @override + String toString() { + return 'MenuWatchState.initial()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _Initial); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(List apps) loadApps, + required TResult Function(WorkspaceError error) loadFail, + }) { + return initial(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(List apps)? loadApps, + TResult Function(WorkspaceError error)? loadFail, + required TResult orElse(), + }) { + if (initial != null) { + return initial(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_LoadApps value) loadApps, + required TResult Function(_LoadFail value) loadFail, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_LoadApps value)? loadApps, + TResult Function(_LoadFail value)? loadFail, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class _Initial implements MenuWatchState { + const factory _Initial() = _$_Initial; +} + +/// @nodoc +abstract class _$LoadAppsCopyWith<$Res> { + factory _$LoadAppsCopyWith(_LoadApps value, $Res Function(_LoadApps) then) = + __$LoadAppsCopyWithImpl<$Res>; + $Res call({List apps}); +} + +/// @nodoc +class __$LoadAppsCopyWithImpl<$Res> extends _$MenuWatchStateCopyWithImpl<$Res> + implements _$LoadAppsCopyWith<$Res> { + __$LoadAppsCopyWithImpl(_LoadApps _value, $Res Function(_LoadApps) _then) + : super(_value, (v) => _then(v as _LoadApps)); + + @override + _LoadApps get _value => super._value as _LoadApps; + + @override + $Res call({ + Object? apps = freezed, + }) { + return _then(_LoadApps( + apps == freezed + ? _value.apps + : apps // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc + +class _$_LoadApps implements _LoadApps { + const _$_LoadApps(this.apps); + + @override + final List apps; + + @override + String toString() { + return 'MenuWatchState.loadApps(apps: $apps)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _LoadApps && + (identical(other.apps, apps) || + const DeepCollectionEquality().equals(other.apps, apps))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(apps); + + @JsonKey(ignore: true) + @override + _$LoadAppsCopyWith<_LoadApps> get copyWith => + __$LoadAppsCopyWithImpl<_LoadApps>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(List apps) loadApps, + required TResult Function(WorkspaceError error) loadFail, + }) { + return loadApps(apps); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(List apps)? loadApps, + TResult Function(WorkspaceError error)? loadFail, + required TResult orElse(), + }) { + if (loadApps != null) { + return loadApps(apps); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_LoadApps value) loadApps, + required TResult Function(_LoadFail value) loadFail, + }) { + return loadApps(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_LoadApps value)? loadApps, + TResult Function(_LoadFail value)? loadFail, + required TResult orElse(), + }) { + if (loadApps != null) { + return loadApps(this); + } + return orElse(); + } +} + +abstract class _LoadApps implements MenuWatchState { + const factory _LoadApps(List apps) = _$_LoadApps; + + List get apps => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$LoadAppsCopyWith<_LoadApps> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$LoadFailCopyWith<$Res> { + factory _$LoadFailCopyWith(_LoadFail value, $Res Function(_LoadFail) then) = + __$LoadFailCopyWithImpl<$Res>; + $Res call({WorkspaceError error}); +} + +/// @nodoc +class __$LoadFailCopyWithImpl<$Res> extends _$MenuWatchStateCopyWithImpl<$Res> + implements _$LoadFailCopyWith<$Res> { + __$LoadFailCopyWithImpl(_LoadFail _value, $Res Function(_LoadFail) _then) + : super(_value, (v) => _then(v as _LoadFail)); + + @override + _LoadFail get _value => super._value as _LoadFail; + + @override + $Res call({ + Object? error = freezed, + }) { + return _then(_LoadFail( + error == freezed + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as WorkspaceError, + )); + } +} + +/// @nodoc + +class _$_LoadFail implements _LoadFail { + const _$_LoadFail(this.error); + + @override + final WorkspaceError error; + + @override + String toString() { + return 'MenuWatchState.loadFail(error: $error)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _LoadFail && + (identical(other.error, error) || + const DeepCollectionEquality().equals(other.error, error))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(error); + + @JsonKey(ignore: true) + @override + _$LoadFailCopyWith<_LoadFail> get copyWith => + __$LoadFailCopyWithImpl<_LoadFail>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(List apps) loadApps, + required TResult Function(WorkspaceError error) loadFail, + }) { + return loadFail(error); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(List apps)? loadApps, + TResult Function(WorkspaceError error)? loadFail, + required TResult orElse(), + }) { + if (loadFail != null) { + return loadFail(error); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_LoadApps value) loadApps, + required TResult Function(_LoadFail value) loadFail, + }) { + return loadFail(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_LoadApps value)? loadApps, + TResult Function(_LoadFail value)? loadFail, + required TResult orElse(), + }) { + if (loadFail != null) { + return loadFail(this); + } + return orElse(); + } +} + +abstract class _LoadFail implements MenuWatchState { + const factory _LoadFail(WorkspaceError error) = _$_LoadFail; + + WorkspaceError get error => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$LoadFailCopyWith<_LoadFail> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/app_flowy/lib/workspace/application/view/doc_watch_bloc.dart b/app_flowy/lib/workspace/application/view/doc_watch_bloc.dart new file mode 100644 index 0000000000..e5268e49df --- /dev/null +++ b/app_flowy/lib/workspace/application/view/doc_watch_bloc.dart @@ -0,0 +1,42 @@ +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:app_flowy/workspace/domain/i_doc.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:flowy_sdk/protobuf/flowy-editor/errors.pb.dart'; +part 'doc_watch_bloc.freezed.dart'; + +class DocWatchBloc extends Bloc { + final IDoc iDocImpl; + + DocWatchBloc({ + required this.iDocImpl, + }) : super(const DocWatchState.loading()); + + @override + Stream mapEventToState(DocWatchEvent event) async* { + yield* event.map( + started: (_) async* { + yield* _readDoc(); + }, + ); + } + + Stream _readDoc() async* { + final docOrFail = await iDocImpl.readDoc(); + yield docOrFail.fold( + (doc) => DocWatchState.loadDoc(doc), + (error) => DocWatchState.loadFail(error), + ); + } +} + +@freezed +class DocWatchEvent with _$DocWatchEvent { + const factory DocWatchEvent.started() = Started; +} + +@freezed +class DocWatchState with _$DocWatchState { + const factory DocWatchState.loading() = Loading; + const factory DocWatchState.loadDoc(Doc doc) = LoadDoc; + const factory DocWatchState.loadFail(EditorError error) = LoadFail; +} diff --git a/app_flowy/lib/workspace/application/view/doc_watch_bloc.freezed.dart b/app_flowy/lib/workspace/application/view/doc_watch_bloc.freezed.dart new file mode 100644 index 0000000000..c1a1669cdb --- /dev/null +++ b/app_flowy/lib/workspace/application/view/doc_watch_bloc.freezed.dart @@ -0,0 +1,542 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'doc_watch_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$DocWatchEventTearOff { + const _$DocWatchEventTearOff(); + + Started started() { + return const Started(); + } +} + +/// @nodoc +const $DocWatchEvent = _$DocWatchEventTearOff(); + +/// @nodoc +mixin _$DocWatchEvent { + @optionalTypeArgs + TResult when({ + required TResult Function() started, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? started, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(Started value) started, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Started value)? started, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $DocWatchEventCopyWith<$Res> { + factory $DocWatchEventCopyWith( + DocWatchEvent value, $Res Function(DocWatchEvent) then) = + _$DocWatchEventCopyWithImpl<$Res>; +} + +/// @nodoc +class _$DocWatchEventCopyWithImpl<$Res> + implements $DocWatchEventCopyWith<$Res> { + _$DocWatchEventCopyWithImpl(this._value, this._then); + + final DocWatchEvent _value; + // ignore: unused_field + final $Res Function(DocWatchEvent) _then; +} + +/// @nodoc +abstract class $StartedCopyWith<$Res> { + factory $StartedCopyWith(Started value, $Res Function(Started) then) = + _$StartedCopyWithImpl<$Res>; +} + +/// @nodoc +class _$StartedCopyWithImpl<$Res> extends _$DocWatchEventCopyWithImpl<$Res> + implements $StartedCopyWith<$Res> { + _$StartedCopyWithImpl(Started _value, $Res Function(Started) _then) + : super(_value, (v) => _then(v as Started)); + + @override + Started get _value => super._value as Started; +} + +/// @nodoc + +class _$Started implements Started { + const _$Started(); + + @override + String toString() { + return 'DocWatchEvent.started()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is Started); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() started, + }) { + return started(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? started, + required TResult orElse(), + }) { + if (started != null) { + return started(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Started value) started, + }) { + return started(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Started value)? started, + required TResult orElse(), + }) { + if (started != null) { + return started(this); + } + return orElse(); + } +} + +abstract class Started implements DocWatchEvent { + const factory Started() = _$Started; +} + +/// @nodoc +class _$DocWatchStateTearOff { + const _$DocWatchStateTearOff(); + + Loading loading() { + return const Loading(); + } + + LoadDoc loadDoc(Doc doc) { + return LoadDoc( + doc, + ); + } + + LoadFail loadFail(EditorError error) { + return LoadFail( + error, + ); + } +} + +/// @nodoc +const $DocWatchState = _$DocWatchStateTearOff(); + +/// @nodoc +mixin _$DocWatchState { + @optionalTypeArgs + TResult when({ + required TResult Function() loading, + required TResult Function(Doc doc) loadDoc, + required TResult Function(EditorError error) loadFail, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loading, + TResult Function(Doc doc)? loadDoc, + TResult Function(EditorError error)? loadFail, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(Loading value) loading, + required TResult Function(LoadDoc value) loadDoc, + required TResult Function(LoadFail value) loadFail, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Loading value)? loading, + TResult Function(LoadDoc value)? loadDoc, + TResult Function(LoadFail value)? loadFail, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $DocWatchStateCopyWith<$Res> { + factory $DocWatchStateCopyWith( + DocWatchState value, $Res Function(DocWatchState) then) = + _$DocWatchStateCopyWithImpl<$Res>; +} + +/// @nodoc +class _$DocWatchStateCopyWithImpl<$Res> + implements $DocWatchStateCopyWith<$Res> { + _$DocWatchStateCopyWithImpl(this._value, this._then); + + final DocWatchState _value; + // ignore: unused_field + final $Res Function(DocWatchState) _then; +} + +/// @nodoc +abstract class $LoadingCopyWith<$Res> { + factory $LoadingCopyWith(Loading value, $Res Function(Loading) then) = + _$LoadingCopyWithImpl<$Res>; +} + +/// @nodoc +class _$LoadingCopyWithImpl<$Res> extends _$DocWatchStateCopyWithImpl<$Res> + implements $LoadingCopyWith<$Res> { + _$LoadingCopyWithImpl(Loading _value, $Res Function(Loading) _then) + : super(_value, (v) => _then(v as Loading)); + + @override + Loading get _value => super._value as Loading; +} + +/// @nodoc + +class _$Loading implements Loading { + const _$Loading(); + + @override + String toString() { + return 'DocWatchState.loading()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is Loading); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loading, + required TResult Function(Doc doc) loadDoc, + required TResult Function(EditorError error) loadFail, + }) { + return loading(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loading, + TResult Function(Doc doc)? loadDoc, + TResult Function(EditorError error)? loadFail, + required TResult orElse(), + }) { + if (loading != null) { + return loading(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Loading value) loading, + required TResult Function(LoadDoc value) loadDoc, + required TResult Function(LoadFail value) loadFail, + }) { + return loading(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Loading value)? loading, + TResult Function(LoadDoc value)? loadDoc, + TResult Function(LoadFail value)? loadFail, + required TResult orElse(), + }) { + if (loading != null) { + return loading(this); + } + return orElse(); + } +} + +abstract class Loading implements DocWatchState { + const factory Loading() = _$Loading; +} + +/// @nodoc +abstract class $LoadDocCopyWith<$Res> { + factory $LoadDocCopyWith(LoadDoc value, $Res Function(LoadDoc) then) = + _$LoadDocCopyWithImpl<$Res>; + $Res call({Doc doc}); +} + +/// @nodoc +class _$LoadDocCopyWithImpl<$Res> extends _$DocWatchStateCopyWithImpl<$Res> + implements $LoadDocCopyWith<$Res> { + _$LoadDocCopyWithImpl(LoadDoc _value, $Res Function(LoadDoc) _then) + : super(_value, (v) => _then(v as LoadDoc)); + + @override + LoadDoc get _value => super._value as LoadDoc; + + @override + $Res call({ + Object? doc = freezed, + }) { + return _then(LoadDoc( + doc == freezed + ? _value.doc + : doc // ignore: cast_nullable_to_non_nullable + as Doc, + )); + } +} + +/// @nodoc + +class _$LoadDoc implements LoadDoc { + const _$LoadDoc(this.doc); + + @override + final Doc doc; + + @override + String toString() { + return 'DocWatchState.loadDoc(doc: $doc)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is LoadDoc && + (identical(other.doc, doc) || + const DeepCollectionEquality().equals(other.doc, doc))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(doc); + + @JsonKey(ignore: true) + @override + $LoadDocCopyWith get copyWith => + _$LoadDocCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loading, + required TResult Function(Doc doc) loadDoc, + required TResult Function(EditorError error) loadFail, + }) { + return loadDoc(doc); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loading, + TResult Function(Doc doc)? loadDoc, + TResult Function(EditorError error)? loadFail, + required TResult orElse(), + }) { + if (loadDoc != null) { + return loadDoc(doc); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Loading value) loading, + required TResult Function(LoadDoc value) loadDoc, + required TResult Function(LoadFail value) loadFail, + }) { + return loadDoc(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Loading value)? loading, + TResult Function(LoadDoc value)? loadDoc, + TResult Function(LoadFail value)? loadFail, + required TResult orElse(), + }) { + if (loadDoc != null) { + return loadDoc(this); + } + return orElse(); + } +} + +abstract class LoadDoc implements DocWatchState { + const factory LoadDoc(Doc doc) = _$LoadDoc; + + Doc get doc => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $LoadDocCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $LoadFailCopyWith<$Res> { + factory $LoadFailCopyWith(LoadFail value, $Res Function(LoadFail) then) = + _$LoadFailCopyWithImpl<$Res>; + $Res call({EditorError error}); +} + +/// @nodoc +class _$LoadFailCopyWithImpl<$Res> extends _$DocWatchStateCopyWithImpl<$Res> + implements $LoadFailCopyWith<$Res> { + _$LoadFailCopyWithImpl(LoadFail _value, $Res Function(LoadFail) _then) + : super(_value, (v) => _then(v as LoadFail)); + + @override + LoadFail get _value => super._value as LoadFail; + + @override + $Res call({ + Object? error = freezed, + }) { + return _then(LoadFail( + error == freezed + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as EditorError, + )); + } +} + +/// @nodoc + +class _$LoadFail implements LoadFail { + const _$LoadFail(this.error); + + @override + final EditorError error; + + @override + String toString() { + return 'DocWatchState.loadFail(error: $error)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is LoadFail && + (identical(other.error, error) || + const DeepCollectionEquality().equals(other.error, error))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(error); + + @JsonKey(ignore: true) + @override + $LoadFailCopyWith get copyWith => + _$LoadFailCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loading, + required TResult Function(Doc doc) loadDoc, + required TResult Function(EditorError error) loadFail, + }) { + return loadFail(error); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loading, + TResult Function(Doc doc)? loadDoc, + TResult Function(EditorError error)? loadFail, + required TResult orElse(), + }) { + if (loadFail != null) { + return loadFail(error); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Loading value) loading, + required TResult Function(LoadDoc value) loadDoc, + required TResult Function(LoadFail value) loadFail, + }) { + return loadFail(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Loading value)? loading, + TResult Function(LoadDoc value)? loadDoc, + TResult Function(LoadFail value)? loadFail, + required TResult orElse(), + }) { + if (loadFail != null) { + return loadFail(this); + } + return orElse(); + } +} + +abstract class LoadFail implements DocWatchState { + const factory LoadFail(EditorError error) = _$LoadFail; + + EditorError get error => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $LoadFailCopyWith get copyWith => + throw _privateConstructorUsedError; +} diff --git a/app_flowy/lib/workspace/application/view/view_bloc.dart b/app_flowy/lib/workspace/application/view/view_bloc.dart new file mode 100644 index 0000000000..0de85a0d51 --- /dev/null +++ b/app_flowy/lib/workspace/application/view/view_bloc.dart @@ -0,0 +1,44 @@ +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +import 'package:app_flowy/workspace/domain/i_view.dart'; + +part 'view_bloc.freezed.dart'; + +class ViewBloc extends Bloc { + final IView iViewImpl; + + ViewBloc({ + required this.iViewImpl, + }) : super(ViewState.initial()); + + @override + Stream mapEventToState(ViewEvent event) async* { + yield* event.map(initial: (_) async* { + yield state; + }); + } +} + +@freezed +abstract class ViewEvent with _$ViewEvent { + const factory ViewEvent.initial() = Initial; +} + +@freezed +abstract class ViewState implements _$ViewState { + const factory ViewState({ + required bool isLoading, + required Option view, + required Either successOrFailure, + }) = _ViewState; + + factory ViewState.initial() => ViewState( + isLoading: false, + view: none(), + successOrFailure: left(unit), + ); +} diff --git a/app_flowy/lib/workspace/application/view/view_bloc.freezed.dart b/app_flowy/lib/workspace/application/view/view_bloc.freezed.dart new file mode 100644 index 0000000000..72e82121e5 --- /dev/null +++ b/app_flowy/lib/workspace/application/view/view_bloc.freezed.dart @@ -0,0 +1,327 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'view_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$ViewEventTearOff { + const _$ViewEventTearOff(); + + Initial initial() { + return const Initial(); + } +} + +/// @nodoc +const $ViewEvent = _$ViewEventTearOff(); + +/// @nodoc +mixin _$ViewEvent { + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(Initial value) initial, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Initial value)? initial, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ViewEventCopyWith<$Res> { + factory $ViewEventCopyWith(ViewEvent value, $Res Function(ViewEvent) then) = + _$ViewEventCopyWithImpl<$Res>; +} + +/// @nodoc +class _$ViewEventCopyWithImpl<$Res> implements $ViewEventCopyWith<$Res> { + _$ViewEventCopyWithImpl(this._value, this._then); + + final ViewEvent _value; + // ignore: unused_field + final $Res Function(ViewEvent) _then; +} + +/// @nodoc +abstract class $InitialCopyWith<$Res> { + factory $InitialCopyWith(Initial value, $Res Function(Initial) then) = + _$InitialCopyWithImpl<$Res>; +} + +/// @nodoc +class _$InitialCopyWithImpl<$Res> extends _$ViewEventCopyWithImpl<$Res> + implements $InitialCopyWith<$Res> { + _$InitialCopyWithImpl(Initial _value, $Res Function(Initial) _then) + : super(_value, (v) => _then(v as Initial)); + + @override + Initial get _value => super._value as Initial; +} + +/// @nodoc + +class _$Initial implements Initial { + const _$Initial(); + + @override + String toString() { + return 'ViewEvent.initial()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is Initial); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + }) { + return initial(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + required TResult orElse(), + }) { + if (initial != null) { + return initial(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Initial value) initial, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Initial value)? initial, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class Initial implements ViewEvent { + const factory Initial() = _$Initial; +} + +/// @nodoc +class _$ViewStateTearOff { + const _$ViewStateTearOff(); + + _ViewState call( + {required bool isLoading, + required Option view, + required Either successOrFailure}) { + return _ViewState( + isLoading: isLoading, + view: view, + successOrFailure: successOrFailure, + ); + } +} + +/// @nodoc +const $ViewState = _$ViewStateTearOff(); + +/// @nodoc +mixin _$ViewState { + bool get isLoading => throw _privateConstructorUsedError; + Option get view => throw _privateConstructorUsedError; + Either get successOrFailure => + throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $ViewStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ViewStateCopyWith<$Res> { + factory $ViewStateCopyWith(ViewState value, $Res Function(ViewState) then) = + _$ViewStateCopyWithImpl<$Res>; + $Res call( + {bool isLoading, + Option view, + Either successOrFailure}); +} + +/// @nodoc +class _$ViewStateCopyWithImpl<$Res> implements $ViewStateCopyWith<$Res> { + _$ViewStateCopyWithImpl(this._value, this._then); + + final ViewState _value; + // ignore: unused_field + final $Res Function(ViewState) _then; + + @override + $Res call({ + Object? isLoading = freezed, + Object? view = freezed, + Object? successOrFailure = freezed, + }) { + return _then(_value.copyWith( + isLoading: isLoading == freezed + ? _value.isLoading + : isLoading // ignore: cast_nullable_to_non_nullable + as bool, + view: view == freezed + ? _value.view + : view // ignore: cast_nullable_to_non_nullable + as Option, + successOrFailure: successOrFailure == freezed + ? _value.successOrFailure + : successOrFailure // ignore: cast_nullable_to_non_nullable + as Either, + )); + } +} + +/// @nodoc +abstract class _$ViewStateCopyWith<$Res> implements $ViewStateCopyWith<$Res> { + factory _$ViewStateCopyWith( + _ViewState value, $Res Function(_ViewState) then) = + __$ViewStateCopyWithImpl<$Res>; + @override + $Res call( + {bool isLoading, + Option view, + Either successOrFailure}); +} + +/// @nodoc +class __$ViewStateCopyWithImpl<$Res> extends _$ViewStateCopyWithImpl<$Res> + implements _$ViewStateCopyWith<$Res> { + __$ViewStateCopyWithImpl(_ViewState _value, $Res Function(_ViewState) _then) + : super(_value, (v) => _then(v as _ViewState)); + + @override + _ViewState get _value => super._value as _ViewState; + + @override + $Res call({ + Object? isLoading = freezed, + Object? view = freezed, + Object? successOrFailure = freezed, + }) { + return _then(_ViewState( + isLoading: isLoading == freezed + ? _value.isLoading + : isLoading // ignore: cast_nullable_to_non_nullable + as bool, + view: view == freezed + ? _value.view + : view // ignore: cast_nullable_to_non_nullable + as Option, + successOrFailure: successOrFailure == freezed + ? _value.successOrFailure + : successOrFailure // ignore: cast_nullable_to_non_nullable + as Either, + )); + } +} + +/// @nodoc + +class _$_ViewState implements _ViewState { + const _$_ViewState( + {required this.isLoading, + required this.view, + required this.successOrFailure}); + + @override + final bool isLoading; + @override + final Option view; + @override + final Either successOrFailure; + + @override + String toString() { + return 'ViewState(isLoading: $isLoading, view: $view, successOrFailure: $successOrFailure)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _ViewState && + (identical(other.isLoading, isLoading) || + const DeepCollectionEquality() + .equals(other.isLoading, isLoading)) && + (identical(other.view, view) || + const DeepCollectionEquality().equals(other.view, view)) && + (identical(other.successOrFailure, successOrFailure) || + const DeepCollectionEquality() + .equals(other.successOrFailure, successOrFailure))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(isLoading) ^ + const DeepCollectionEquality().hash(view) ^ + const DeepCollectionEquality().hash(successOrFailure); + + @JsonKey(ignore: true) + @override + _$ViewStateCopyWith<_ViewState> get copyWith => + __$ViewStateCopyWithImpl<_ViewState>(this, _$identity); +} + +abstract class _ViewState implements ViewState { + const factory _ViewState( + {required bool isLoading, + required Option view, + required Either successOrFailure}) = _$_ViewState; + + @override + bool get isLoading => throw _privateConstructorUsedError; + @override + Option get view => throw _privateConstructorUsedError; + @override + Either get successOrFailure => + throw _privateConstructorUsedError; + @override + @JsonKey(ignore: true) + _$ViewStateCopyWith<_ViewState> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/app_flowy/lib/home/domain/edit_context.dart b/app_flowy/lib/workspace/domain/edit_context.dart similarity index 100% rename from app_flowy/lib/home/domain/edit_context.dart rename to app_flowy/lib/workspace/domain/edit_context.dart diff --git a/app_flowy/lib/workspace/domain/i_app.dart b/app_flowy/lib/workspace/domain/i_app.dart new file mode 100644 index 0000000000..3114cd3f0b --- /dev/null +++ b/app_flowy/lib/workspace/domain/i_app.dart @@ -0,0 +1,21 @@ +import 'package:flowy_sdk/protobuf/flowy-workspace/protobuf.dart'; +import 'package:dartz/dartz.dart'; + +typedef AppUpdatedCallback = void Function(String name, String desc); +typedef AppAddViewCallback = void Function( + Either, WorkspaceError> viewsOrFailed); + +abstract class IApp { + Future, WorkspaceError>> getViews(); + + Future> createView( + {required String name, String? desc, required ViewType viewType}); +} + +abstract class IAppWatch { + void startWatching( + {AppAddViewCallback? addViewCallback, + AppUpdatedCallback? updatedCallback}); + + Future stopWatching(); +} diff --git a/app_flowy/lib/workspace/domain/i_doc.dart b/app_flowy/lib/workspace/domain/i_doc.dart new file mode 100644 index 0000000000..ece8d529bc --- /dev/null +++ b/app_flowy/lib/workspace/domain/i_doc.dart @@ -0,0 +1,18 @@ +import 'package:flowy_editor/flowy_editor.dart'; +import 'package:flowy_sdk/protobuf/flowy-editor/doc_create.pb.dart'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/protobuf/flowy-editor/errors.pb.dart'; + +class Doc { + final DocInfo info; + final Document data; + + Doc({required this.info, required this.data}); +} + +abstract class IDoc { + Future> readDoc(); + Future> updateDoc( + {String? name, String? desc, String? text}); + Future> closeDoc(); +} diff --git a/app_flowy/lib/workspace/domain/i_view.dart b/app_flowy/lib/workspace/domain/i_view.dart new file mode 100644 index 0000000000..2334b65e57 --- /dev/null +++ b/app_flowy/lib/workspace/domain/i_view.dart @@ -0,0 +1,15 @@ +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; +import 'package:dartz/dartz.dart'; + +typedef ViewUpdatedCallback = void Function(View view); + +abstract class IView { + Future> readView(); +} + +abstract class IViewWatch { + void startWatching({ViewUpdatedCallback? updatedCallback}); + + Future stopWatching(); +} diff --git a/app_flowy/lib/workspace/domain/i_workspace.dart b/app_flowy/lib/workspace/domain/i_workspace.dart new file mode 100644 index 0000000000..5656ee5b98 --- /dev/null +++ b/app_flowy/lib/workspace/domain/i_workspace.dart @@ -0,0 +1,21 @@ +import 'package:flowy_sdk/protobuf/flowy-workspace/protobuf.dart'; +import 'package:dartz/dartz.dart'; + +typedef WorkspaceAddAppCallback = void Function( + Either, WorkspaceError> appsOrFail); +typedef WorkspaceUpdatedCallback = void Function(String name, String desc); + +abstract class IWorkspace { + Future> createApp( + {required String name, String? desc}); + + Future, WorkspaceError>> getApps(); +} + +abstract class IWorkspaceWatch { + void startWatching( + {WorkspaceAddAppCallback? addAppCallback, + WorkspaceUpdatedCallback? updatedCallback}); + + Future stopWatching(); +} diff --git a/app_flowy/lib/workspace/domain/page_stack/page_stack.dart b/app_flowy/lib/workspace/domain/page_stack/page_stack.dart new file mode 100644 index 0000000000..bf5572f4e8 --- /dev/null +++ b/app_flowy/lib/workspace/domain/page_stack/page_stack.dart @@ -0,0 +1,90 @@ +import 'package:app_flowy/workspace/domain/page_stack/page_stack_bloc.dart'; +import 'package:app_flowy/workspace/presentation/doc/doc_page.dart'; +import 'package:equatable/equatable.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; +import 'package:flutter/material.dart'; +import 'package:app_flowy/workspace/presentation/widgets/blank_page.dart'; +import 'package:app_flowy/workspace/presentation/widgets/fading_index_stack.dart'; +import 'package:app_flowy/workspace/presentation/widgets/prelude.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +abstract class HomeStackView extends Equatable { + final ViewType type; + final String title; + const HomeStackView({required this.type, required this.title}); +} + +class HomePageStack { + final PageStackBloc _bloc = PageStackBloc(); + HomePageStack(); + + String title() { + return _bloc.state.stackView.title; + } + + void setStackView(HomeStackView? stackView) { + _bloc.add(PageStackEvent.setStackView(stackView ?? const BlankStackView())); + } + + Widget stackTopBar() { + return BlocProvider( + create: (context) => _bloc, + child: BlocBuilder( + builder: (context, state) { + return HomeTopBar( + title: state.stackView.title, + ); + }, + ), + ); + } + + Widget stackWidget() { + return BlocProvider( + create: (context) => _bloc, + child: BlocBuilder( + builder: (context, state) { + return FadingIndexedStack( + index: pages.indexOf(state.stackView.type), + children: _buildStackWidget(state.stackView), + ); + }, + ), + ); + } +} + +List pages = ViewType.values.toList(); + +List _buildStackWidget(HomeStackView stackView) { + return ViewType.values.map((viewType) { + if (viewType == stackView.type) { + switch (stackView.type) { + case ViewType.Blank: + return BlankPage(stackView: stackView as BlankStackView); + case ViewType.Doc: + return DocPage(stackView: stackView as DocPageStackView); + default: + return BlankPage(stackView: stackView as BlankStackView); + } + } else { + return const BlankPage(stackView: BlankStackView()); + } + }).toList(); +} + +HomeStackView stackViewFromView(View view) { + switch (view.viewType) { + case ViewType.Blank: + return const BlankStackView(); + case ViewType.Doc: + return DocPageStackView(view); + default: + return const BlankStackView(); + } +} + +abstract class HomeStackWidget extends StatefulWidget { + final HomeStackView stackView; + const HomeStackWidget({Key? key, required this.stackView}) : super(key: key); +} diff --git a/app_flowy/lib/workspace/domain/page_stack/page_stack_bloc.dart b/app_flowy/lib/workspace/domain/page_stack/page_stack_bloc.dart new file mode 100644 index 0000000000..9d43af2d05 --- /dev/null +++ b/app_flowy/lib/workspace/domain/page_stack/page_stack_bloc.dart @@ -0,0 +1,35 @@ +import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; +import 'package:app_flowy/workspace/presentation/widgets/blank_page.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +part 'page_stack_bloc.freezed.dart'; + +class PageStackBloc extends Bloc { + PageStackBloc() : super(PageStackState.initial()); + + @override + Stream mapEventToState( + PageStackEvent event, + ) async* { + yield* event.map(setStackView: (NewPageContext value) async* { + yield state.copyWith(stackView: value.newStackView); + }); + } +} + +@freezed +abstract class PageStackEvent with _$PageStackEvent { + const factory PageStackEvent.setStackView(HomeStackView newStackView) = + NewPageContext; +} + +@freezed +abstract class PageStackState implements _$PageStackState { + const factory PageStackState({ + required HomeStackView stackView, + }) = _PageStackState; + + factory PageStackState.initial() => const PageStackState( + stackView: BlankStackView(), + ); +} diff --git a/app_flowy/lib/workspace/domain/page_stack/page_stack_bloc.freezed.dart b/app_flowy/lib/workspace/domain/page_stack/page_stack_bloc.freezed.dart new file mode 100644 index 0000000000..2a7a0345d2 --- /dev/null +++ b/app_flowy/lib/workspace/domain/page_stack/page_stack_bloc.freezed.dart @@ -0,0 +1,337 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'page_stack_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$PageStackEventTearOff { + const _$PageStackEventTearOff(); + + NewPageContext setStackView(HomeStackView newStackView) { + return NewPageContext( + newStackView, + ); + } +} + +/// @nodoc +const $PageStackEvent = _$PageStackEventTearOff(); + +/// @nodoc +mixin _$PageStackEvent { + HomeStackView get newStackView => throw _privateConstructorUsedError; + + @optionalTypeArgs + TResult when({ + required TResult Function(HomeStackView newStackView) setStackView, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(HomeStackView newStackView)? setStackView, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(NewPageContext value) setStackView, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(NewPageContext value)? setStackView, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $PageStackEventCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PageStackEventCopyWith<$Res> { + factory $PageStackEventCopyWith( + PageStackEvent value, $Res Function(PageStackEvent) then) = + _$PageStackEventCopyWithImpl<$Res>; + $Res call({HomeStackView newStackView}); +} + +/// @nodoc +class _$PageStackEventCopyWithImpl<$Res> + implements $PageStackEventCopyWith<$Res> { + _$PageStackEventCopyWithImpl(this._value, this._then); + + final PageStackEvent _value; + // ignore: unused_field + final $Res Function(PageStackEvent) _then; + + @override + $Res call({ + Object? newStackView = freezed, + }) { + return _then(_value.copyWith( + newStackView: newStackView == freezed + ? _value.newStackView + : newStackView // ignore: cast_nullable_to_non_nullable + as HomeStackView, + )); + } +} + +/// @nodoc +abstract class $NewPageContextCopyWith<$Res> + implements $PageStackEventCopyWith<$Res> { + factory $NewPageContextCopyWith( + NewPageContext value, $Res Function(NewPageContext) then) = + _$NewPageContextCopyWithImpl<$Res>; + @override + $Res call({HomeStackView newStackView}); +} + +/// @nodoc +class _$NewPageContextCopyWithImpl<$Res> + extends _$PageStackEventCopyWithImpl<$Res> + implements $NewPageContextCopyWith<$Res> { + _$NewPageContextCopyWithImpl( + NewPageContext _value, $Res Function(NewPageContext) _then) + : super(_value, (v) => _then(v as NewPageContext)); + + @override + NewPageContext get _value => super._value as NewPageContext; + + @override + $Res call({ + Object? newStackView = freezed, + }) { + return _then(NewPageContext( + newStackView == freezed + ? _value.newStackView + : newStackView // ignore: cast_nullable_to_non_nullable + as HomeStackView, + )); + } +} + +/// @nodoc + +class _$NewPageContext implements NewPageContext { + const _$NewPageContext(this.newStackView); + + @override + final HomeStackView newStackView; + + @override + String toString() { + return 'PageStackEvent.setStackView(newStackView: $newStackView)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is NewPageContext && + (identical(other.newStackView, newStackView) || + const DeepCollectionEquality() + .equals(other.newStackView, newStackView))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(newStackView); + + @JsonKey(ignore: true) + @override + $NewPageContextCopyWith get copyWith => + _$NewPageContextCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(HomeStackView newStackView) setStackView, + }) { + return setStackView(newStackView); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(HomeStackView newStackView)? setStackView, + required TResult orElse(), + }) { + if (setStackView != null) { + return setStackView(newStackView); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(NewPageContext value) setStackView, + }) { + return setStackView(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(NewPageContext value)? setStackView, + required TResult orElse(), + }) { + if (setStackView != null) { + return setStackView(this); + } + return orElse(); + } +} + +abstract class NewPageContext implements PageStackEvent { + const factory NewPageContext(HomeStackView newStackView) = _$NewPageContext; + + @override + HomeStackView get newStackView => throw _privateConstructorUsedError; + @override + @JsonKey(ignore: true) + $NewPageContextCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +class _$PageStackStateTearOff { + const _$PageStackStateTearOff(); + + _PageStackState call({required HomeStackView stackView}) { + return _PageStackState( + stackView: stackView, + ); + } +} + +/// @nodoc +const $PageStackState = _$PageStackStateTearOff(); + +/// @nodoc +mixin _$PageStackState { + HomeStackView get stackView => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $PageStackStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PageStackStateCopyWith<$Res> { + factory $PageStackStateCopyWith( + PageStackState value, $Res Function(PageStackState) then) = + _$PageStackStateCopyWithImpl<$Res>; + $Res call({HomeStackView stackView}); +} + +/// @nodoc +class _$PageStackStateCopyWithImpl<$Res> + implements $PageStackStateCopyWith<$Res> { + _$PageStackStateCopyWithImpl(this._value, this._then); + + final PageStackState _value; + // ignore: unused_field + final $Res Function(PageStackState) _then; + + @override + $Res call({ + Object? stackView = freezed, + }) { + return _then(_value.copyWith( + stackView: stackView == freezed + ? _value.stackView + : stackView // ignore: cast_nullable_to_non_nullable + as HomeStackView, + )); + } +} + +/// @nodoc +abstract class _$PageStackStateCopyWith<$Res> + implements $PageStackStateCopyWith<$Res> { + factory _$PageStackStateCopyWith( + _PageStackState value, $Res Function(_PageStackState) then) = + __$PageStackStateCopyWithImpl<$Res>; + @override + $Res call({HomeStackView stackView}); +} + +/// @nodoc +class __$PageStackStateCopyWithImpl<$Res> + extends _$PageStackStateCopyWithImpl<$Res> + implements _$PageStackStateCopyWith<$Res> { + __$PageStackStateCopyWithImpl( + _PageStackState _value, $Res Function(_PageStackState) _then) + : super(_value, (v) => _then(v as _PageStackState)); + + @override + _PageStackState get _value => super._value as _PageStackState; + + @override + $Res call({ + Object? stackView = freezed, + }) { + return _then(_PageStackState( + stackView: stackView == freezed + ? _value.stackView + : stackView // ignore: cast_nullable_to_non_nullable + as HomeStackView, + )); + } +} + +/// @nodoc + +class _$_PageStackState implements _PageStackState { + const _$_PageStackState({required this.stackView}); + + @override + final HomeStackView stackView; + + @override + String toString() { + return 'PageStackState(stackView: $stackView)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _PageStackState && + (identical(other.stackView, stackView) || + const DeepCollectionEquality() + .equals(other.stackView, stackView))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(stackView); + + @JsonKey(ignore: true) + @override + _$PageStackStateCopyWith<_PageStackState> get copyWith => + __$PageStackStateCopyWithImpl<_PageStackState>(this, _$identity); +} + +abstract class _PageStackState implements PageStackState { + const factory _PageStackState({required HomeStackView stackView}) = + _$_PageStackState; + + @override + HomeStackView get stackView => throw _privateConstructorUsedError; + @override + @JsonKey(ignore: true) + _$PageStackStateCopyWith<_PageStackState> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/app_flowy/lib/workspace/infrastructure/deps_resolver.dart new file mode 100644 index 0000000000..a01ec4ea24 --- /dev/null +++ b/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -0,0 +1,72 @@ +import 'package:app_flowy/workspace/application/app/app_bloc.dart'; +import 'package:app_flowy/workspace/application/app/app_watch_bloc.dart'; +import 'package:app_flowy/workspace/application/doc/doc_bloc.dart'; +import 'package:app_flowy/workspace/application/menu/menu_bloc.dart'; +import 'package:app_flowy/workspace/application/menu/menu_watch.dart'; +import 'package:app_flowy/workspace/application/view/doc_watch_bloc.dart'; +import 'package:app_flowy/workspace/application/view/view_bloc.dart'; +import 'package:app_flowy/workspace/domain/i_doc.dart'; +import 'package:app_flowy/workspace/domain/i_view.dart'; +import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; +import 'package:app_flowy/workspace/infrastructure/i_app_impl.dart'; +import 'package:app_flowy/workspace/infrastructure/i_doc_impl.dart'; +import 'package:app_flowy/workspace/infrastructure/i_workspace_impl.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart'; +import 'package:get_it/get_it.dart'; + +import 'i_view_impl.dart'; + +class HomeDepsResolver { + static Future resolve(GetIt getIt) async { + // + getIt.registerLazySingleton(() => HomePageStack()); + + //App + getIt.registerFactoryParam( + (appId, _) => IAppImpl(repo: AppRepository(appId: appId))); + getIt.registerFactoryParam( + (appId, _) => IAppWatchImpl(repo: AppWatchRepository(appId: appId))); + + //workspace + getIt.registerFactoryParam((workspaceId, _) => + IWorkspaceImpl(repo: WorkspaceRepo(workspaceId: workspaceId))); + getIt.registerFactoryParam((workspacId, _) => + IWorkspaceWatchImpl(repo: WorkspaceWatchRepo(workspaceId: workspacId))); + + // View + getIt.registerFactoryParam( + (viewId, _) => IViewImpl(repo: ViewRepository(viewId: viewId))); + getIt.registerFactoryParam((viewId, _) => + IViewWatchImpl(repo: ViewWatchRepository(viewId: viewId))); + + // Doc + getIt.registerFactoryParam( + (docId, _) => IDocImpl(repo: DocRepository(docId: docId))); + + //Bloc + getIt.registerFactoryParam( + (workspaceId, _) => MenuBloc(getIt(param1: workspaceId))); + getIt.registerFactoryParam((workspaceId, _) => + MenuWatchBloc(getIt(param1: workspaceId))); + + getIt.registerFactoryParam( + (appId, _) => AppBloc(getIt(param1: appId))); + getIt.registerFactoryParam( + (appId, _) => AppWatchBloc(getIt(param1: appId))); + + getIt.registerFactoryParam( + (viewId, _) => ViewBloc(iViewImpl: getIt(param1: viewId))); + + getIt.registerFactoryParam( + (docId, _) => DocWatchBloc(iDocImpl: getIt(param1: docId))); + + getIt.registerFactoryParam( + (docId, _) => DocBloc(getIt(param1: docId))); + + // getIt.registerFactoryParam( + // (viewId, _) => ViewBloc(iViewImpl: getIt(param1: viewId))); + } +} diff --git a/app_flowy/lib/workspace/infrastructure/i_app_impl.dart b/app_flowy/lib/workspace/infrastructure/i_app_impl.dart new file mode 100644 index 0000000000..ac19453819 --- /dev/null +++ b/app_flowy/lib/workspace/infrastructure/i_app_impl.dart @@ -0,0 +1,65 @@ +import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:app_flowy/workspace/domain/i_app.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; +export 'package:app_flowy/workspace/domain/i_app.dart'; + +class IAppImpl extends IApp { + AppRepository repo; + IAppImpl({ + required this.repo, + }); + + @override + Future, WorkspaceError>> getViews() { + return repo.getViews(); + } + + @override + Future> createView( + {required String name, String? desc, required ViewType viewType}) { + return repo.createView(name, desc ?? "", viewType).then((result) { + return result.fold( + (view) => _createDoc(view), + (r) => right(r), + ); + }); + } + + Future> _createDoc(View view) async { + switch (view.viewType) { + case ViewType.Doc: + final docRepo = DocRepository(docId: view.id); + final result = await docRepo.createDoc( + name: view.name, desc: "", text: "[{\"insert\":\"\\n\"}]"); + return result.fold((l) => left(view), (r) { + return right( + WorkspaceError(code: WorkspaceErrorCode.Unknown, msg: r.msg)); + }); + default: + return left(view); + } + } +} + +class IAppWatchImpl extends IAppWatch { + AppWatchRepository repo; + IAppWatchImpl({ + required this.repo, + }); + + @override + void startWatching( + {AppAddViewCallback? addViewCallback, + AppUpdatedCallback? updatedCallback}) { + repo.startWatching( + addViewCallback: addViewCallback, updatedCallback: updatedCallback); + } + + @override + Future stopWatching() async { + await repo.close(); + } +} diff --git a/app_flowy/lib/workspace/infrastructure/i_doc_impl.dart b/app_flowy/lib/workspace/infrastructure/i_doc_impl.dart new file mode 100644 index 0000000000..2669f03ae0 --- /dev/null +++ b/app_flowy/lib/workspace/infrastructure/i_doc_impl.dart @@ -0,0 +1,51 @@ +import 'dart:convert'; + +import 'package:app_flowy/workspace/domain/i_doc.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart'; +import 'package:flowy_editor/flowy_editor.dart'; +import 'package:flowy_sdk/protobuf/flowy-editor/errors.pb.dart'; +import 'package:dartz/dartz.dart'; + +class IDocImpl extends IDoc { + DocRepository repo; + + IDocImpl({required this.repo}); + + @override + Future> closeDoc() { + return repo.closeDoc(); + } + + @override + Future> readDoc() async { + final docInfoOrFail = await repo.readDoc(); + return docInfoOrFail.fold( + (info) => _loadDocument(info.path).then((result) => result.fold( + (document) => left(Doc(info: info, data: document)), + (error) => right(error))), + (error) => right(error), + ); + } + + @override + Future> updateDoc( + {String? name, String? desc, String? text}) { + final json = jsonEncode(text ?? ""); + return repo.updateDoc(name: name, desc: desc, text: json); + } + + Future> _loadDocument(String path) { + return repo.readDocData(path).then((docDataOrFail) { + return docDataOrFail.fold( + (docData) => left(_decodeToDocument(docData.text)), + (error) => right(error), + ); + }); + } + + Document _decodeToDocument(String text) { + final json = jsonDecode(text); + final document = Document.fromJson(json); + return document; + } +} diff --git a/app_flowy/lib/workspace/infrastructure/i_view_impl.dart b/app_flowy/lib/workspace/infrastructure/i_view_impl.dart new file mode 100644 index 0000000000..a4aff46ba3 --- /dev/null +++ b/app_flowy/lib/workspace/infrastructure/i_view_impl.dart @@ -0,0 +1,33 @@ +import 'package:app_flowy/workspace/domain/i_view.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:dartz/dartz.dart'; + +class IViewImpl extends IView { + ViewRepository repo; + + IViewImpl({required this.repo}); + + @override + Future> readView() { + return repo.readView(); + } +} + +class IViewWatchImpl extends IViewWatch { + final ViewWatchRepository repo; + IViewWatchImpl({ + required this.repo, + }); + + @override + void startWatching({ViewUpdatedCallback? updatedCallback}) { + repo.startWatching(updatedCallback: updatedCallback); + } + + @override + Future stopWatching() async { + await repo.close(); + } +} diff --git a/app_flowy/lib/workspace/infrastructure/i_workspace_impl.dart b/app_flowy/lib/workspace/infrastructure/i_workspace_impl.dart new file mode 100644 index 0000000000..748ae3538d --- /dev/null +++ b/app_flowy/lib/workspace/infrastructure/i_workspace_impl.dart @@ -0,0 +1,50 @@ +import 'package:app_flowy/workspace/domain/i_workspace.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; + +export 'package:app_flowy/workspace/domain/i_workspace.dart'; + +class IWorkspaceImpl extends IWorkspace { + WorkspaceRepo repo; + IWorkspaceImpl({ + required this.repo, + }); + + @override + Future> createApp( + {required String name, String? desc}) { + return repo.createApp(name, desc ?? ""); + } + + @override + Future, WorkspaceError>> getApps() { + return repo.getWorkspace(readApps: true).then((result) { + return result.fold( + (workspace) => left(workspace.apps.items), + (error) => right(error), + ); + }); + } +} + +class IWorkspaceWatchImpl extends IWorkspaceWatch { + WorkspaceWatchRepo repo; + IWorkspaceWatchImpl({ + required this.repo, + }); + + @override + void startWatching( + {WorkspaceAddAppCallback? addAppCallback, + WorkspaceUpdatedCallback? updatedCallback}) { + repo.startWatching( + addAppCallback: addAppCallback, updatedCallback: updatedCallback); + } + + @override + Future stopWatching() async { + await repo.close(); + } +} diff --git a/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart b/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart new file mode 100644 index 0000000000..5457c5e9ce --- /dev/null +++ b/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart @@ -0,0 +1,115 @@ +import 'dart:async'; +import 'package:app_flowy/workspace/domain/i_app.dart'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_infra/flowy_logger.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-observable/subject.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/app_query.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/observable.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pbenum.dart'; +import 'package:flowy_sdk/rust_stream.dart'; + +class AppRepository { + String appId; + AppRepository({ + required this.appId, + }); + + Future> getAppDesc() { + final request = QueryAppRequest.create() + ..appId = appId + ..readViews = false; + + return WorkspaceEventGetApp(request).send(); + } + + Future> createView( + String name, String desc, ViewType viewType) { + final request = CreateViewRequest.create() + ..appId = appId + ..name = name + ..desc = desc + ..viewType = viewType; + + return WorkspaceEventCreateView(request).send(); + } + + Future, WorkspaceError>> getViews() { + final request = QueryAppRequest.create() + ..appId = appId + ..readViews = true; + + return WorkspaceEventGetApp(request).send().then((result) { + return result.fold( + (app) => left(app.views.items), + (error) => right(error), + ); + }); + } +} + +class AppWatchRepository { + StreamSubscription? _subscription; + AppAddViewCallback? _addViewCallback; + AppUpdatedCallback? _updatedCallback; + String appId; + late AppRepository _repo; + AppWatchRepository({ + required this.appId, + }) { + _repo = AppRepository(appId: appId); + } + + void startWatching( + {AppAddViewCallback? addViewCallback, + AppUpdatedCallback? updatedCallback}) { + _addViewCallback = addViewCallback; + _updatedCallback = updatedCallback; + _subscription = RustStreamReceiver.listen((observable) { + if (observable.subjectId != appId) { + return; + } + + final ty = WorkspaceObservable.valueOf(observable.ty); + if (ty != null) { + _handleObservableType(ty); + } + }); + } + + void _handleObservableType(WorkspaceObservable ty) { + switch (ty) { + case WorkspaceObservable.AppAddView: + if (_addViewCallback == null) { + return; + } + _repo.getViews().then((result) { + result.fold( + (views) => _addViewCallback!(left(views)), + (error) => _addViewCallback!(right(error)), + ); + }); + break; + case WorkspaceObservable.AppUpdateDesc: + if (_updatedCallback == null) { + return; + } + _repo.getAppDesc().then((result) { + result.fold( + (app) => _updatedCallback!(app.name, app.desc), + (error) => Log.error(error), + ); + }); + break; + default: + break; + } + } + + Future close() async { + await _subscription?.cancel(); + } +} diff --git a/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart b/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart new file mode 100644 index 0000000000..1e1a6c0e32 --- /dev/null +++ b/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart @@ -0,0 +1,45 @@ +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-editor/doc_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-editor/doc_modify.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-editor/doc_query.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-editor/errors.pb.dart'; + +class DocRepository { + final String docId; + DocRepository({ + required this.docId, + }); + + Future> createDoc( + {required String name, String? desc, String? text}) { + final request = + CreateDocRequest(id: docId, name: name, desc: desc, text: text); + + return EditorEventCreateDoc(request).send(); + } + + Future> readDoc() { + final request = QueryDocRequest.create()..docId = docId; + return EditorEventReadDocInfo(request).send(); + } + + Future> readDocData(String path) { + final request = QueryDocDataRequest.create() + ..docId = docId + ..path = path; + return EditorEventReadDocData(request).send(); + } + + Future> updateDoc( + {String? name, String? desc, String? text}) { + final request = UpdateDocRequest(id: docId, name: name, text: text); + + return EditorEventUpdateDoc(request).send(); + } + + Future> closeDoc( + {String? name, String? desc, String? text}) { + throw UnimplementedError(); + } +} diff --git a/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart b/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart new file mode 100644 index 0000000000..3a3bf78140 --- /dev/null +++ b/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart @@ -0,0 +1,75 @@ +import 'dart:async'; + +import 'package:dartz/dartz.dart'; +import 'package:flowy_infra/flowy_logger.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-observable/subject.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/observable.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_query.pb.dart'; +import 'package:flowy_sdk/rust_stream.dart'; + +import 'package:app_flowy/workspace/domain/i_view.dart'; + +class ViewRepository { + String viewId; + ViewRepository({ + required this.viewId, + }); + + Future> readView() { + final request = QueryViewRequest.create()..viewId = viewId; + return WorkspaceEventReadView(request).send(); + } +} + +class ViewWatchRepository { + StreamSubscription? _subscription; + ViewUpdatedCallback? _updatedCallback; + String viewId; + late ViewRepository _repo; + ViewWatchRepository({ + required this.viewId, + }) { + _repo = ViewRepository(viewId: viewId); + } + + void startWatching({ + ViewUpdatedCallback? updatedCallback, + }) { + _updatedCallback = updatedCallback; + _subscription = RustStreamReceiver.listen((observable) { + if (observable.subjectId != viewId) { + return; + } + + final ty = WorkspaceObservable.valueOf(observable.ty); + if (ty != null) { + _handleObservableType(ty); + } + }); + } + + void _handleObservableType(WorkspaceObservable ty) { + switch (ty) { + case WorkspaceObservable.ViewUpdateDesc: + if (_updatedCallback == null) { + return; + } + _repo.readView().then((result) { + result.fold( + (view) => _updatedCallback!(view), + (error) => Log.error(error), + ); + }); + break; + default: + break; + } + } + + Future close() async { + await _subscription?.cancel(); + } +} diff --git a/app_flowy/lib/workspace/infrastructure/repos/workspace_repo.dart b/app_flowy/lib/workspace/infrastructure/repos/workspace_repo.dart new file mode 100644 index 0000000000..6484108870 --- /dev/null +++ b/app_flowy/lib/workspace/infrastructure/repos/workspace_repo.dart @@ -0,0 +1,116 @@ +import 'dart:async'; + +import 'package:app_flowy/workspace/domain/i_workspace.dart'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_infra/flowy_logger.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-observable/subject.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/observable.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/workspace_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/workspace_query.pb.dart'; +import 'package:flowy_sdk/rust_stream.dart'; + +class WorkspaceRepo { + String workspaceId; + WorkspaceRepo({ + required this.workspaceId, + }); + + Future> createApp(String appName, String desc) { + return WorkspaceEventGetCurWorkspace().send().then((result) { + return result.fold( + (workspace) { + final request = CreateAppRequest.create() + ..name = appName + ..workspaceId = workspace.id + ..desc = desc; + return WorkspaceEventCreateApp(request).send(); + }, + (error) { + return right(error); + }, + ); + }); + } + + Future> getWorkspace( + {bool readApps = false}) { + final request = QueryWorkspaceRequest.create() + ..workspaceId = workspaceId + ..readApps = readApps; + + return WorkspaceEventGetWorkspace(request).send().then((result) { + return result.fold( + (workspace) => left(workspace), + (error) => right(error), + ); + }); + } +} + +class WorkspaceWatchRepo { + StreamSubscription? _subscription; + WorkspaceAddAppCallback? _addAppCallback; + WorkspaceUpdatedCallback? _updatedCallback; + final String workspaceId; + late WorkspaceRepo _repo; + + WorkspaceWatchRepo({ + required this.workspaceId, + }) { + _repo = WorkspaceRepo(workspaceId: workspaceId); + } + + void startWatching( + {WorkspaceAddAppCallback? addAppCallback, + WorkspaceUpdatedCallback? updatedCallback}) { + _addAppCallback = addAppCallback; + _updatedCallback = updatedCallback; + + _subscription = RustStreamReceiver.listen((observable) { + if (observable.subjectId != workspaceId) { + return; + } + + final ty = WorkspaceObservable.valueOf(observable.ty); + if (ty != null) { + _handleObservableType(ty); + } + }); + } + + void _handleObservableType(WorkspaceObservable ty) { + switch (ty) { + case WorkspaceObservable.WorkspaceUpdateDesc: + if (_updatedCallback == null) { + return; + } + _repo.getWorkspace().then((result) { + result.fold( + (workspace) => _updatedCallback!(workspace.name, workspace.desc), + (error) => Log.error(error), + ); + }); + break; + case WorkspaceObservable.WorkspaceAddApp: + if (_addAppCallback == null) { + return; + } + _repo.getWorkspace(readApps: true).then((result) { + result.fold( + (workspace) => _addAppCallback!(left(workspace.apps.items)), + (error) => _addAppCallback!(right(error)), + ); + }); + break; + default: + break; + } + } + + Future close() async { + await _subscription?.cancel(); + } +} diff --git a/app_flowy/lib/workspace/presentation/app/app_widget.dart b/app_flowy/lib/workspace/presentation/app/app_widget.dart new file mode 100644 index 0000000000..cadf15b5a9 --- /dev/null +++ b/app_flowy/lib/workspace/presentation/app/app_widget.dart @@ -0,0 +1,149 @@ +import 'package:app_flowy/workspace/application/app/app_bloc.dart'; +import 'package:app_flowy/workspace/application/app/app_watch_bloc.dart'; +import 'package:app_flowy/workspace/presentation/app/view_list.dart'; +import 'package:app_flowy/workspace/presentation/widgets/menu/menu_size.dart'; +import 'package:app_flowy/startup/startup.dart'; +import 'package:expandable/expandable.dart'; +import 'package:flowy_infra/size.dart'; +import 'package:flowy_infra_ui/widget/error_page.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:dartz/dartz.dart'; + +class AppWidget extends StatelessWidget { + final App app; + const AppWidget(this.app, {Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MultiBlocProvider( + providers: [ + BlocProvider(create: (context) { + final appBloc = getIt(param1: app.id); + appBloc.add(const AppEvent.initial()); + return appBloc; + }), + BlocProvider(create: (context) { + final watchBloc = getIt(param1: app.id); + watchBloc.add(const AppWatchEvent.started()); + return watchBloc; + }), + ], + child: BlocBuilder( + builder: (context, state) { + final child = state.map( + initial: (_) => BlocBuilder( + builder: (context, state) { + return ViewList(state.views); + }, + ), + loadViews: (s) => ViewList(some(s.views)), + loadFail: (s) => FlowyErrorPage(s.error.toString()), + ); + + return expandableWrapper(context, child); + }, + ), + ); + } + + ExpandableNotifier expandableWrapper(BuildContext context, Widget child) { + return ExpandableNotifier( + child: ScrollOnExpand( + scrollOnExpand: true, + scrollOnCollapse: false, + child: Card( + clipBehavior: Clip.antiAlias, + child: Column( + children: [ + ExpandablePanel( + theme: const ExpandableThemeData( + headerAlignment: ExpandablePanelHeaderAlignment.center, + tapBodyToExpand: false, + tapBodyToCollapse: false, + iconPadding: EdgeInsets.zero, + hasIcon: false, + ), + header: AppHeader(app), + expanded: Padding( + padding: EdgeInsets.only(left: Sizes.iconMed), + child: child, + ), + collapsed: const SizedBox(), + ), + ], + ), + ), + ), + ); + } +} + +class AppHeader extends StatelessWidget { + final App app; + const AppHeader( + this.app, { + Key? key, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + color: Colors.white, + child: Padding( + padding: EdgeInsets.symmetric(vertical: Insets.m), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + ExpandableIcon( + theme: ExpandableThemeData( + expandIcon: Icons.arrow_right, + collapseIcon: Icons.arrow_drop_down, + iconColor: Colors.black, + iconSize: HomeMenuSize.collapseIconSize, + iconPadding: EdgeInsets.zero, + hasIcon: false, + ), + ), + Expanded( + child: Text(app.name), + ), + SizedBox( + height: HomeMenuSize.createViewButtonSize, + child: createViewPopupMenu(context), + ), + ], + ), + ), + ); + } + + Widget createViewPopupMenu(BuildContext context) { + return PopupMenuButton( + iconSize: 24, + tooltip: 'create new view', + icon: const Icon(Icons.add), + padding: EdgeInsets.zero, + onSelected: (viewType) => _createView(viewType as ViewType, context), + itemBuilder: (context) => menuItemBuilder()); + } + + List menuItemBuilder() { + return ViewType.values + .where((element) => element != ViewType.Blank) + .map((ty) { + return PopupMenuItem( + value: ty, + child: Row( + children: [Text(ty.name)], + )); + }).toList(); + } + + void _createView(ViewType viewType, BuildContext context) { + context.read().add(AppEvent.createView("New view", "", viewType)); + } +} diff --git a/app_flowy/lib/workspace/presentation/app/new_app.dart b/app_flowy/lib/workspace/presentation/app/new_app.dart new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app_flowy/lib/workspace/presentation/app/view_list.dart b/app_flowy/lib/workspace/presentation/app/view_list.dart new file mode 100644 index 0000000000..d4dde80159 --- /dev/null +++ b/app_flowy/lib/workspace/presentation/app/view_list.dart @@ -0,0 +1,45 @@ +import 'package:app_flowy/workspace/presentation/view/view_widget.dart'; +import 'package:flowy_infra/flowy_logger.dart'; +import 'package:flowy_infra/size.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:dartz/dartz.dart'; +import 'package:styled_widget/styled_widget.dart'; + +class ViewList extends StatelessWidget { + final Option> views; + const ViewList(this.views, {Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + Log.info('ViewList build'); + return views.fold( + () => const SizedBox( + height: 10, + ), + (views) { + return Column( + children: buildViewWidgets(views), + ).padding(vertical: Insets.sm); + }, + ); + } + + List buildViewWidgets(List views) { + var targetViews = views.map((view) { + return ViewWidget( + icon: const Icon(Icons.file_copy), + view: view, + ); + }).toList(growable: true); + return targetViews; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + views.fold(() => {}, + (views) => properties.add(IterableProperty('views', views))); + } +} diff --git a/app_flowy/lib/workspace/presentation/doc/doc_page.dart b/app_flowy/lib/workspace/presentation/doc/doc_page.dart new file mode 100644 index 0000000000..cd8c8edb59 --- /dev/null +++ b/app_flowy/lib/workspace/presentation/doc/doc_page.dart @@ -0,0 +1,51 @@ +import 'package:app_flowy/startup/startup.dart'; +import 'package:app_flowy/workspace/application/view/doc_watch_bloc.dart'; +import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; +import 'package:app_flowy/workspace/presentation/doc/editor_widget.dart'; +import 'package:flowy_infra_ui/widget/error_page.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +class DocPage extends HomeStackWidget { + const DocPage({Key? key, required DocPageStackView stackView}) + : super(key: key, stackView: stackView); + + @override + _DocPageState createState() => _DocPageState(); +} + +class _DocPageState extends State { + @override + Widget build(BuildContext context) { + final stackView = widget.stackView as DocPageStackView; + return MultiBlocProvider( + providers: [ + BlocProvider( + create: (context) => getIt(param1: stackView.view.id) + ..add(const DocWatchEvent.started())), + ], + child: + BlocBuilder(builder: (context, state) { + assert(widget.stackView is DocPageStackView); + return state.map( + loading: (_) => const CircularProgressIndicator.adaptive(), + loadDoc: (s) => EditorWdiget(doc: s.doc), + loadFail: (s) => FlowyErrorPage(s.error.toString()), + ); + }), + ); + } +} + +class DocPageStackView extends HomeStackView { + final View view; + DocPageStackView(this.view) + : super( + type: view.viewType, + title: view.name, + ); + + @override + List get props => [view.id, type]; +} diff --git a/app_flowy/lib/workspace/presentation/doc/editor_widget.dart b/app_flowy/lib/workspace/presentation/doc/editor_widget.dart new file mode 100644 index 0000000000..9d46a7b71f --- /dev/null +++ b/app_flowy/lib/workspace/presentation/doc/editor_widget.dart @@ -0,0 +1,61 @@ +import 'dart:io'; + +import 'package:app_flowy/startup/startup.dart'; +import 'package:app_flowy/workspace/application/doc/doc_bloc.dart'; +import 'package:app_flowy/workspace/domain/i_doc.dart'; +import 'package:flowy_editor/flowy_editor.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +class EditorWdiget extends StatelessWidget { + final FocusNode _focusNode = FocusNode(); + late EditorController controller; + final Doc doc; + + EditorWdiget({Key? key, required this.doc}) : super(key: key) { + controller = EditorController( + document: doc.data, + selection: const TextSelection.collapsed(offset: 0), + ); + } + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => getIt(param1: doc.info.id), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + _renderEditor(controller), + _renderToolbar(controller), + ], + ), + ); + } + + Widget _renderEditor(EditorController controller) { + final editor = FlowyEditor( + controller: controller, + focusNode: _focusNode, + scrollable: true, + autoFocus: false, + expands: false, + padding: const EdgeInsets.symmetric(horizontal: 8.0), + readOnly: false, + scrollBottomInset: 0, + scrollController: ScrollController(), + ); + return Expanded(child: editor); + } + + Widget _renderToolbar(EditorController controller) { + return FlowyToolbar.basic( + controller: controller, + onImageSelectCallback: _onImageSelection, + ); + } + + Future _onImageSelection(File file) { + throw UnimplementedError(); + } +} diff --git a/app_flowy/lib/home/presentation/home_layout.dart b/app_flowy/lib/workspace/presentation/home/home_layout.dart similarity index 78% rename from app_flowy/lib/home/presentation/home_layout.dart rename to app_flowy/lib/workspace/presentation/home/home_layout.dart index 567d212dcc..5b72593c9b 100644 --- a/app_flowy/lib/home/presentation/home_layout.dart +++ b/app_flowy/lib/workspace/presentation/home/home_layout.dart @@ -1,4 +1,4 @@ -import 'package:app_flowy/home/application/home_bloc.dart'; +import 'package:app_flowy/workspace/application/home/home_bloc.dart'; import 'package:flowy_infra/size.dart'; import 'package:flowy_infra/time/duration.dart'; import 'package:flutter/material.dart'; @@ -17,7 +17,8 @@ class HomeLayout { late double homePageROffset; late Duration animDuration; - HomeLayout(BuildContext context, BoxConstraints homeScreenConstraint) { + HomeLayout(BuildContext context, BoxConstraints homeScreenConstraint, + bool forceCollapse) { final homeBlocState = context.read().state; showEditPannel = homeBlocState.editContext.isSome(); @@ -27,12 +28,11 @@ class HomeLayout { menuWidth = Sizes.sideBarLg; } - // if (menuBlocState.isCollapse) { - // showMenu = false; - // } else { - // showMenu = context.widthPx > PageBreaks.TabletPortrait; - // } - showMenu = context.widthPx > PageBreaks.tabletPortrait; + if (forceCollapse) { + showMenu = false; + } else { + showMenu = context.widthPx > PageBreaks.tabletPortrait; + } homePageLOffset = showMenu ? menuWidth : 0.0; animDuration = .35.seconds; diff --git a/app_flowy/lib/home/presentation/home_screen.dart b/app_flowy/lib/workspace/presentation/home/home_screen.dart similarity index 67% rename from app_flowy/lib/home/presentation/home_screen.dart rename to app_flowy/lib/workspace/presentation/home/home_screen.dart index b31ce4a174..39dfc4e90a 100644 --- a/app_flowy/lib/home/presentation/home_screen.dart +++ b/app_flowy/lib/workspace/presentation/home/home_screen.dart @@ -1,7 +1,7 @@ -import 'package:app_flowy/home/application/home_bloc.dart'; -import 'package:app_flowy/home/application/watcher/home_watcher_bloc.dart'; -import 'package:app_flowy/home/domain/page_context.dart'; -import 'package:app_flowy/home/presentation/widgets/prelude.dart'; +import 'package:app_flowy/workspace/application/home/home_bloc.dart'; +import 'package:app_flowy/workspace/application/home/home_watcher_bloc.dart'; +import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; +import 'package:app_flowy/workspace/presentation/widgets/prelude.dart'; import 'package:app_flowy/startup/startup.dart'; import 'package:flowy_infra/flowy_logger.dart'; import 'package:flowy_infra_ui/style_widget/styled_container.dart'; @@ -11,7 +11,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:styled_widget/styled_widget.dart'; import 'home_layout.dart'; -import 'widgets/fading_index_stack.dart'; class HomeScreen extends StatelessWidget { static GlobalKey scaffoldKey = GlobalKey(); @@ -29,10 +28,12 @@ class HomeScreen extends StatelessWidget { child: Scaffold( key: HomeScreen.scaffoldKey, body: BlocBuilder( + buildWhen: (previous, current) => previous != current, builder: (context, state) { return StyledContainer( Theme.of(context).colorScheme.background, - child: _buildBody(state), + child: _buildBody( + state, context.read().state.forceCollapse), ); }, ), @@ -40,10 +41,10 @@ class HomeScreen extends StatelessWidget { ); } - Widget _buildBody(HomeState state) { + Widget _buildBody(HomeState state, bool forceCollapse) { return LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { - final layout = HomeLayout(context, constraints); + final layout = HomeLayout(context, constraints, forceCollapse); const homePage = HomePage(); final menu = _buildHomeMenu( layout: layout, @@ -68,16 +69,12 @@ class HomeScreen extends StatelessWidget { final homeBloc = context.read(); Widget homeMenu = HomeMenu( pageContextChanged: (pageContext) { - pageContext.fold( - () => homeBloc.add(const HomeEvent.setPage(BlankPageContext())), - (pageContext) { - homeBloc.add(HomeEvent.setPage(pageContext)); - }, - ); + getIt().setStackView(pageContext); }, isCollapseChanged: (isCollapse) { - homeBloc.add(HomeEvent.showMenu(!isCollapse)); + homeBloc.add(HomeEvent.forceCollapse(isCollapse)); }, + workspaceId: userDetail.workspace, ); homeMenu = RepaintBoundary(child: homeMenu); homeMenu = FocusTraversalGroup(child: homeMenu); @@ -139,25 +136,6 @@ class HomeScreen extends StatelessWidget { } } -extension PageTypeExtension on PageType { - HomeStackPage builder(PageContext context) { - switch (this) { - case PageType.blank: - return BlankPage(context: context); - } - } -} - -List buildPagesWidget(PageContext pageContext) { - return PageType.values.map((pageType) { - if (pageType == pageContext.pageType) { - return pageType.builder(pageContext); - } else { - return const BlankPage(context: BlankPageContext()); - } - }).toList(); -} - class HomePage extends StatelessWidget { static GlobalKey scaffoldKey = GlobalKey(); // final Size size; @@ -168,40 +146,44 @@ class HomePage extends StatelessWidget { Log.info('HomePage build'); return Column( mainAxisAlignment: MainAxisAlignment.start, - children: const [ - HomeTopBar(), - HomeIndexStack(), + children: [ + getIt().stackTopBar(), + Expanded( + child: Container( + color: Colors.white, + child: FocusTraversalGroup( + child: getIt().stackWidget(), + ), + ), + ), ], ); } } -class HomeIndexStack extends StatelessWidget { - const HomeIndexStack({Key? key}) : super(key: key); - @override - Widget build(BuildContext context) { - return BlocBuilder( - buildWhen: (p, c) { - if (p.pageContext != c.pageContext) { - Log.info( - 'PageContext switch from ${p.pageContext.pageType} to ${c.pageContext.pageType}'); - } - return p.pageContext != c.pageContext; - }, - builder: (context, state) { - final pageContext = context.read().state.pageContext; - return Expanded( - child: Container( - color: Colors.white, - child: FocusTraversalGroup( - child: FadingIndexedStack( - index: pages.indexOf(pageContext.pageType), - children: buildPagesWidget(pageContext), - ), - ), - ), - ); - }, - ); - } -} +// class HomeIndexStack extends StatelessWidget { +// const HomeIndexStack({Key? key}) : super(key: key); +// @override +// Widget build(BuildContext context) { +// return BlocBuilder( +// buildWhen: (p, c) { +// if (p.pageContext != c.pageContext) { +// Log.info( +// 'PageContext switch from ${p.pageContext.pageType} to ${c.pageContext.pageType}'); +// } +// return p.pageContext != c.pageContext; +// }, +// builder: (context, state) { +// final pageContext = context.read().state.pageContext; +// return Expanded( +// child: Container( +// color: Colors.white, +// child: FocusTraversalGroup( +// child: getIt().indexStack(pageContext), +// ), +// ), +// ); +// }, +// ); +// } +// } diff --git a/app_flowy/lib/home/presentation/home_sizes.dart b/app_flowy/lib/workspace/presentation/home/home_sizes.dart similarity index 100% rename from app_flowy/lib/home/presentation/home_sizes.dart rename to app_flowy/lib/workspace/presentation/home/home_sizes.dart diff --git a/app_flowy/lib/workspace/presentation/view/view_widget.dart b/app_flowy/lib/workspace/presentation/view/view_widget.dart new file mode 100644 index 0000000000..5e70770038 --- /dev/null +++ b/app_flowy/lib/workspace/presentation/view/view_widget.dart @@ -0,0 +1,39 @@ +import 'package:app_flowy/startup/startup.dart'; +import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; +import 'package:flutter/material.dart'; + +class ViewWidget extends StatelessWidget { + final View view; + final Widget icon; + const ViewWidget({Key? key, required this.view, required this.icon}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return InkWell(onTap: _openView(context), child: buildContent()); + } + + Row buildContent() { + return Row( + children: [ + icon, + const SizedBox( + width: 4, + ), + Text( + view.name, + textAlign: TextAlign.start, + style: const TextStyle(fontSize: 15), + ) + ], + ); + } + + Function() _openView(BuildContext context) { + return () { + final stackView = stackViewFromView(view); + getIt().setStackView(stackView); + }; + } +} diff --git a/app_flowy/lib/home/presentation/widgets/blank_page.dart b/app_flowy/lib/workspace/presentation/widgets/blank_page.dart similarity index 54% rename from app_flowy/lib/home/presentation/widgets/blank_page.dart rename to app_flowy/lib/workspace/presentation/widgets/blank_page.dart index da6a4bf03b..e59df39502 100644 --- a/app_flowy/lib/home/presentation/widgets/blank_page.dart +++ b/app_flowy/lib/workspace/presentation/widgets/blank_page.dart @@ -1,16 +1,17 @@ -import 'package:app_flowy/home/domain/page_context.dart'; +import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; import 'package:flutter/material.dart'; -class BlankPageContext extends PageContext { - const BlankPageContext() : super(PageType.blank, pageTitle: 'Blank'); +class BlankStackView extends HomeStackView { + const BlankStackView() : super(type: ViewType.Blank, title: 'Blank'); @override List get props => []; } -class BlankPage extends HomeStackPage { - const BlankPage({Key? key, required PageContext context}) - : super(key: key, pageContext: context); +class BlankPage extends HomeStackWidget { + const BlankPage({Key? key, required BlankStackView stackView}) + : super(key: key, stackView: stackView); @override State createState() => _BlankPageState(); diff --git a/app_flowy/lib/home/presentation/widgets/edit_pannel/edit_pannel.dart b/app_flowy/lib/workspace/presentation/widgets/edit_pannel/edit_pannel.dart similarity index 89% rename from app_flowy/lib/home/presentation/widgets/edit_pannel/edit_pannel.dart rename to app_flowy/lib/workspace/presentation/widgets/edit_pannel/edit_pannel.dart index 0d561151fc..3b7b40ee7b 100644 --- a/app_flowy/lib/home/presentation/widgets/edit_pannel/edit_pannel.dart +++ b/app_flowy/lib/workspace/presentation/widgets/edit_pannel/edit_pannel.dart @@ -1,12 +1,12 @@ -import 'package:app_flowy/home/application/edit_pannel/edit_pannel_bloc.dart'; -import 'package:app_flowy/home/domain/edit_context.dart'; +import 'package:app_flowy/workspace/application/edit_pannel/edit_pannel_bloc.dart'; +import 'package:app_flowy/workspace/domain/edit_context.dart'; import 'package:app_flowy/startup/startup.dart'; +import 'package:app_flowy/workspace/presentation/home/home_sizes.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_infra_ui/style_widget/styled_bar_title.dart'; import 'package:flowy_infra_ui/style_widget/styled_close_button.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import '../../home_sizes.dart'; class EditPannel extends StatelessWidget { late final EditPannelContext editContext; diff --git a/app_flowy/lib/home/presentation/widgets/edit_pannel/pannel_animation.dart b/app_flowy/lib/workspace/presentation/widgets/edit_pannel/pannel_animation.dart similarity index 100% rename from app_flowy/lib/home/presentation/widgets/edit_pannel/pannel_animation.dart rename to app_flowy/lib/workspace/presentation/widgets/edit_pannel/pannel_animation.dart diff --git a/app_flowy/lib/home/presentation/widgets/fading_index_stack.dart b/app_flowy/lib/workspace/presentation/widgets/fading_index_stack.dart similarity index 100% rename from app_flowy/lib/home/presentation/widgets/fading_index_stack.dart rename to app_flowy/lib/workspace/presentation/widgets/fading_index_stack.dart diff --git a/app_flowy/lib/home/presentation/widgets/home_stack_page.dart b/app_flowy/lib/workspace/presentation/widgets/home_stack_page.dart similarity index 62% rename from app_flowy/lib/home/presentation/widgets/home_stack_page.dart rename to app_flowy/lib/workspace/presentation/widgets/home_stack_page.dart index 98ac0615c4..e474c01a20 100644 --- a/app_flowy/lib/home/presentation/widgets/home_stack_page.dart +++ b/app_flowy/lib/workspace/presentation/widgets/home_stack_page.dart @@ -1,7 +1,7 @@ -import 'package:app_flowy/home/domain/page_context.dart'; +import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:flutter/material.dart'; abstract class HomeStackPage extends StatefulWidget { - final PageContext pageContext; + final HomeStackView pageContext; const HomeStackPage({Key? key, required this.pageContext}) : super(key: key); } diff --git a/app_flowy/lib/home/presentation/widgets/home_top_bar.dart b/app_flowy/lib/workspace/presentation/widgets/home_top_bar.dart similarity index 76% rename from app_flowy/lib/home/presentation/widgets/home_top_bar.dart rename to app_flowy/lib/workspace/presentation/widgets/home_top_bar.dart index 646e5cfc0b..6c9d91a4e5 100644 --- a/app_flowy/lib/home/presentation/widgets/home_top_bar.dart +++ b/app_flowy/lib/workspace/presentation/widgets/home_top_bar.dart @@ -1,11 +1,9 @@ -import 'package:app_flowy/home/application/home_bloc.dart'; +import 'package:app_flowy/workspace/presentation/home/home_sizes.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -import '../home_sizes.dart'; class HomeTopBar extends StatelessWidget { - const HomeTopBar({Key? key}) : super(key: key); + final String title; + const HomeTopBar({Key? key, required this.title}) : super(key: key); @override Widget build(BuildContext context) { @@ -15,7 +13,7 @@ class HomeTopBar extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ - HomeTitle(), + HomeTitle(title: title), ], ), ); @@ -23,18 +21,19 @@ class HomeTopBar extends StatelessWidget { } class HomeTitle extends StatelessWidget { + final String title; final _editingController = TextEditingController( text: '', ); HomeTitle({ Key? key, + required this.title, }) : super(key: key); @override Widget build(BuildContext context) { - _editingController.text = - context.read().state.pageContext.pageTitle; + _editingController.text = title; return Expanded( child: TextField( diff --git a/app_flowy/lib/workspace/presentation/widgets/menu/app_list.dart b/app_flowy/lib/workspace/presentation/widgets/menu/app_list.dart new file mode 100644 index 0000000000..ddb50cb832 --- /dev/null +++ b/app_flowy/lib/workspace/presentation/widgets/menu/app_list.dart @@ -0,0 +1,29 @@ +import 'package:app_flowy/workspace/presentation/app/app_widget.dart'; +import 'package:expandable/expandable.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart'; +import 'package:flutter/material.dart'; +import 'package:dartz/dartz.dart'; + +class AppList extends StatelessWidget { + final Option> apps; + const AppList({required this.apps, Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return apps.fold(() { + return const Expanded(child: Text('You have no apps, create one?')); + }, (apps) { + return ExpandableTheme( + data: const ExpandableThemeData( + iconColor: Colors.blue, + useInkWell: true, + ), + child: Expanded( + child: ListView( + physics: const BouncingScrollPhysics(), + children: apps.map((app) => AppWidget(app)).toList(), + ), + )); + }); + } +} diff --git a/app_flowy/lib/workspace/presentation/widgets/menu/menu.dart b/app_flowy/lib/workspace/presentation/widgets/menu/menu.dart new file mode 100644 index 0000000000..6b211a968c --- /dev/null +++ b/app_flowy/lib/workspace/presentation/widgets/menu/menu.dart @@ -0,0 +1,221 @@ +import 'package:app_flowy/workspace/application/menu/menu_bloc.dart'; +import 'package:app_flowy/workspace/application/menu/menu_watch.dart'; +import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; +import 'package:app_flowy/startup/startup.dart'; +import 'package:app_flowy/startup/tasks/application_task.dart'; +import 'package:app_flowy/workspace/presentation/home/home_sizes.dart'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_infra/size.dart'; +import 'package:flowy_infra/text_style.dart'; +import 'package:flowy_infra/theme.dart'; +import 'package:flowy_infra_ui/style_widget/styled_text_input.dart'; +import 'package:flowy_infra_ui/widget/buttons/ok_cancel_button.dart'; +import 'package:flowy_infra_ui/widget/dialog/styled_dialogs.dart'; +import 'package:flowy_infra_ui/widget/error_page.dart'; +import 'package:flowy_infra_ui/widget/spacing.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:styled_widget/styled_widget.dart'; +import 'package:textstyle_extensions/textstyle_extensions.dart'; +import 'app_list.dart'; + +class HomeMenu extends StatelessWidget { + final Function(HomeStackView?) pageContextChanged; + final Function(bool) isCollapseChanged; + final String workspaceId; + + const HomeMenu( + {Key? key, + required this.pageContextChanged, + required this.isCollapseChanged, + required this.workspaceId}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return MultiBlocProvider( + providers: [ + BlocProvider( + create: (context) => getIt(param1: workspaceId) + ..add(const MenuEvent.initial())), + BlocProvider( + create: (context) => getIt(param1: workspaceId) + ..add(const MenuWatchEvent.started())), + ], + child: MultiBlocListener( + listeners: [ + BlocListener( + listenWhen: (p, c) => p.stackView != c.stackView, + listener: (context, state) => pageContextChanged(state.stackView), + ), + BlocListener( + listenWhen: (p, c) => p.isCollapse != c.isCollapse, + listener: (context, state) => isCollapseChanged(state.isCollapse), + ) + ], + child: BlocBuilder( + builder: (context, state) => _renderBody(context), + ), + ), + ); + } + + Widget _renderBody(BuildContext context) { + return Container( + color: Theme.of(context).colorScheme.primaryVariant, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const MenuTopBar(), + _renderAppList(context), + _renderNewButton(context), + ], + ).padding(horizontal: Insets.sm), + ); + } + + Widget _renderAppList(BuildContext context) { + return BlocBuilder( + builder: (context, state) => state.map( + initial: (_) => BlocBuilder( + builder: (context, state) { + return AppList(apps: state.apps); + }, + ), + loadApps: (s) => AppList(apps: some(s.apps)), + loadFail: (s) => FlowyErrorPage(s.error.toString()), + ), + ); + } + + Widget _renderNewButton(BuildContext context) { + return NewAppButton( + createAppCallback: (appName) => + context.read().add(MenuEvent.createApp(appName, desc: "")), + ); + } +} + +class MenuTopBar extends StatelessWidget { + const MenuTopBar({Key? key}) : super(key: key); + @override + Widget build(BuildContext context) { + return BlocBuilder( + builder: (context, state) { + return SizedBox( + height: HomeSizes.menuTopBarHeight, + child: Row( + children: [ + const Text( + 'AppFlowy', + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20), + ).constrained(minWidth: 100), + const Spacer(), + IconButton( + icon: const Icon(Icons.arrow_left), + onPressed: () => + context.read().add(const MenuEvent.collapse()), + ), + ], + ), + ); + }, + ); + } +} + +class NewAppButton extends StatelessWidget { + final Function(String)? createAppCallback; + + const NewAppButton({this.createAppCallback, Key? key}) : super(key: key); + @override + Widget build(BuildContext context) { + return SizedBox( + height: HomeSizes.menuAddButtonHeight, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const Icon(Icons.add), + const SizedBox( + width: 10, + ), + TextButton( + onPressed: () async => await _showCreateAppDialog(context), + child: _buttonTitle(), + ) + ], + ), + ); + } + + Widget _buttonTitle() { + return const Text('New App', + style: TextStyle( + color: Colors.black, + fontWeight: FontWeight.bold, + fontSize: 20, + )); + } + + Future _showCreateAppDialog(BuildContext context) async { + await Dialogs.showWithContext(CreateAppDialogContext( + confirm: (appName) { + if (appName.isNotEmpty && createAppCallback != null) { + createAppCallback!(appName); + } + }, + ), context); + } +} + +//ignore: must_be_immutable +class CreateAppDialogContext extends DialogContext { + String appName; + final Function(String)? confirm; + + CreateAppDialogContext({this.appName = "", this.confirm}) + : super(identifier: 'CreateAppDialogContext'); + + @override + Widget buildWiget(BuildContext context) { + final theme = context.watch(); + return StyledDialog( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ...[ + Text('Create App'.toUpperCase(), + style: TextStyles.T1.textColor(theme.accent1Darker)), + VSpace(Insets.sm * 1.5), + // Container(color: theme.greyWeak.withOpacity(.35), height: 1), + VSpace(Insets.m * 1.5), + ], + StyledFormTextInput( + hintText: "App name", + onChanged: (text) { + appName = text; + }, + ), + SizedBox(height: Insets.l), + OkCancelButton( + onOkPressed: () { + if (confirm != null) { + confirm!(appName); + AppGlobals.nav.pop(); + } + }, + onCancelPressed: () { + AppGlobals.nav.pop(); + }, + ) + ], + ), + ); + } + + @override + List get props => [identifier]; + + @override + bool get barrierDismissable => false; +} diff --git a/app_flowy/lib/home/presentation/widgets/menu/hom_menu_size.dart b/app_flowy/lib/workspace/presentation/widgets/menu/menu_size.dart similarity index 100% rename from app_flowy/lib/home/presentation/widgets/menu/hom_menu_size.dart rename to app_flowy/lib/workspace/presentation/widgets/menu/menu_size.dart diff --git a/app_flowy/lib/workspace/presentation/widgets/menu/prelude.dart b/app_flowy/lib/workspace/presentation/widgets/menu/prelude.dart new file mode 100644 index 0000000000..c541cb3e36 --- /dev/null +++ b/app_flowy/lib/workspace/presentation/widgets/menu/prelude.dart @@ -0,0 +1,2 @@ +export 'menu.dart'; +export 'menu_size.dart'; diff --git a/app_flowy/lib/home/presentation/widgets/prelude.dart b/app_flowy/lib/workspace/presentation/widgets/prelude.dart similarity index 81% rename from app_flowy/lib/home/presentation/widgets/prelude.dart rename to app_flowy/lib/workspace/presentation/widgets/prelude.dart index e2f412551a..8a9f575646 100644 --- a/app_flowy/lib/home/presentation/widgets/prelude.dart +++ b/app_flowy/lib/workspace/presentation/widgets/prelude.dart @@ -2,4 +2,4 @@ export './blank_page.dart'; export './edit_pannel/edit_pannel.dart'; export './edit_pannel/pannel_animation.dart'; export './home_top_bar.dart'; -export './menu/home_menu.dart'; +export 'menu/menu.dart'; diff --git a/app_flowy/macos/Podfile.lock b/app_flowy/macos/Podfile.lock index 54e66df1b4..9fd7f54a99 100644 --- a/app_flowy/macos/Podfile.lock +++ b/app_flowy/macos/Podfile.lock @@ -49,4 +49,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c -COCOAPODS: 1.10.1 +COCOAPODS: 1.9.3 diff --git a/app_flowy/packages/flowy_editor/lib/src/service/controller.dart b/app_flowy/packages/flowy_editor/lib/src/service/controller.dart index 7ad7983349..7bfab52372 100644 --- a/app_flowy/packages/flowy_editor/lib/src/service/controller.dart +++ b/app_flowy/packages/flowy_editor/lib/src/service/controller.dart @@ -38,8 +38,7 @@ class EditorController extends ChangeNotifier { ); Style getSelectionStyle() => - document.collectStyle(selection.start, selection.end - selection.start) - ..mergeAll(toggledStyle); + document.collectStyle(selection.start, selection.end - selection.start)..mergeAll(toggledStyle); bool get hasUndo => document.hasUndo; @@ -59,6 +58,12 @@ class EditorController extends ChangeNotifier { } } + Future save() async { + document.toDelta().toJson(); + // TODO: vedon - Save document to database + return true; + } + @override void dispose() { document.close(); @@ -75,9 +80,7 @@ class EditorController extends ChangeNotifier { } void formatText(int index, int length, Attribute? attribute) { - if (length == 0 && - attribute!.isInline && - attribute.key != Attribute.link.key) { + if (length == 0 && attribute!.isInline && attribute.key != Attribute.link.key) { toggledStyle = toggledStyle.put(attribute); } @@ -92,24 +95,16 @@ class EditorController extends ChangeNotifier { notifyListeners(); } - void replaceText( - int index, int length, Object? data, TextSelection? textSelection) { + void replaceText(int index, int length, Object? data, TextSelection? textSelection) { assert(data is String || data is Embeddable); Delta? delta; if (length > 0 || data is! String || data.isNotEmpty) { delta = document.replace(index, length, data); - var shouldRetainDelta = toggledStyle.isNotEmpty && - delta.isNotEmpty && - delta.length <= 2 && - delta.last.isInsert; - if (shouldRetainDelta && - toggledStyle.isNotEmpty && - delta.length == 2 && - delta.last.data == '\n') { + var shouldRetainDelta = toggledStyle.isNotEmpty && delta.isNotEmpty && delta.length <= 2 && delta.last.isInsert; + if (shouldRetainDelta && toggledStyle.isNotEmpty && delta.length == 2 && delta.last.data == '\n') { // if all attributes are inline, shouldRetainDelta should be false - final anyAttributeNotInline = - toggledStyle.values.any((attr) => !attr.isInline); + final anyAttributeNotInline = toggledStyle.values.any((attr) => !attr.isInline); shouldRetainDelta &= anyAttributeNotInline; } if (shouldRetainDelta) { @@ -151,8 +146,7 @@ class EditorController extends ChangeNotifier { textSelection = selection.copyWith( baseOffset: delta.transformPosition(selection.baseOffset, force: false), - extentOffset: - delta.transformPosition(selection.extentOffset, force: false), + extentOffset: delta.transformPosition(selection.extentOffset, force: false), ); if (selection != textSelection) { _updateSelection(textSelection, source); diff --git a/app_flowy/packages/flowy_editor/lib/src/service/keyboard.dart b/app_flowy/packages/flowy_editor/lib/src/service/keyboard.dart index 937fb5fbbe..e3e4993b88 100644 --- a/app_flowy/packages/flowy_editor/lib/src/service/keyboard.dart +++ b/app_flowy/packages/flowy_editor/lib/src/service/keyboard.dart @@ -8,6 +8,7 @@ enum InputShortcut { COPY, PASTE, SELECT_ALL, + SAVE, } typedef CursorMoveCallback = void Function( @@ -46,6 +47,7 @@ class KeyboardListener { LogicalKeyboardKey.keyC, LogicalKeyboardKey.keyV, LogicalKeyboardKey.keyX, + LogicalKeyboardKey.keyS, LogicalKeyboardKey.delete, LogicalKeyboardKey.backspace, }; @@ -78,6 +80,7 @@ class KeyboardListener { LogicalKeyboardKey.keyC: InputShortcut.COPY, LogicalKeyboardKey.keyV: InputShortcut.PASTE, LogicalKeyboardKey.keyA: InputShortcut.SELECT_ALL, + LogicalKeyboardKey.keyS: InputShortcut.SAVE, }; bool handleRawKeyEvent(RawKeyEvent event) { @@ -89,8 +92,7 @@ class KeyboardListener { return false; } - final keysPressed = - LogicalKeyboardKey.collapseSynonyms(RawKeyboard.instance.keysPressed); + final keysPressed = LogicalKeyboardKey.collapseSynonyms(RawKeyboard.instance.keysPressed); final key = event.logicalKey; final isMacOS = event.data is RawKeyEventDataMacOs; final modifierKeys = isMacOS ? _osxModifierKeys : _winModifierKeys; diff --git a/app_flowy/packages/flowy_editor/lib/src/widget/raw_editor.dart b/app_flowy/packages/flowy_editor/lib/src/widget/raw_editor.dart index 324b45c1e5..a2d634a224 100644 --- a/app_flowy/packages/flowy_editor/lib/src/widget/raw_editor.dart +++ b/app_flowy/packages/flowy_editor/lib/src/widget/raw_editor.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:math' as math; +import 'dart:developer'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; @@ -59,8 +60,7 @@ class RawEditor extends StatefulWidget { this.embedBuilder, ) : assert(maxHeight == null || maxHeight > 0, 'maxHeight cannot be null'), assert(minHeight == null || minHeight >= 0, 'minHeight cannot be null'), - assert( - maxHeight == null || minHeight == null || maxHeight >= minHeight), + assert(maxHeight == null || minHeight == null || maxHeight >= minHeight), showCursor = showCursor ?? true, super(key: key); @@ -111,10 +111,7 @@ abstract class EditorState extends State { } class _RawEditorState extends EditorState - with - AutomaticKeepAliveClientMixin, - WidgetsBindingObserver, - TickerProviderStateMixin + with AutomaticKeepAliveClientMixin, WidgetsBindingObserver, TickerProviderStateMixin implements TextSelectionDelegate, TextInputClient { final GlobalKey _editorKey = GlobalKey(); final List _sentRemoteValues = []; @@ -132,8 +129,7 @@ class _RawEditorState extends EditorState bool _didAutoFocus = false; bool _keyboardVisible = false; DefaultStyles? _styles; - final ClipboardStatusNotifier? _clipboardStatus = - kIsWeb ? null : ClipboardStatusNotifier(); + final ClipboardStatusNotifier? _clipboardStatus = kIsWeb ? null : ClipboardStatusNotifier(); final LayerLink _toolbarLayerLink = LayerLink(); final LayerLink _startHandleLayerLink = LayerLink(); final LayerLink _endHandleLayerLink = LayerLink(); @@ -181,78 +177,57 @@ class _RawEditorState extends EditorState downKey = key == LogicalKeyboardKey.arrowDown; if ((rightKey || leftKey) && !(rightKey && leftKey)) { - newSelection = _jumpToBeginOrEndOfWord(newSelection, wordModifier, - leftKey, rightKey, plainText, lineModifier, shift); + newSelection = + _jumpToBeginOrEndOfWord(newSelection, wordModifier, leftKey, rightKey, plainText, lineModifier, shift); } if (downKey || upKey) { - newSelection = _handleMovingCursorVertically( - upKey, downKey, shift, selection, newSelection, plainText); + newSelection = _handleMovingCursorVertically(upKey, downKey, shift, selection, newSelection, plainText); } if (!shift) { - newSelection = - _placeCollapsedSelection(selection, newSelection, leftKey, rightKey); + newSelection = _placeCollapsedSelection(selection, newSelection, leftKey, rightKey); } widget.controller.updateSelection(newSelection, ChangeSource.LOCAL); } - TextSelection _placeCollapsedSelection(TextSelection selection, - TextSelection newSelection, bool leftKey, bool rightKey) { + TextSelection _placeCollapsedSelection( + TextSelection selection, TextSelection newSelection, bool leftKey, bool rightKey) { var newOffset = newSelection.extentOffset; if (!selection.isCollapsed) { if (leftKey) { - newOffset = newSelection.baseOffset < newSelection.extentOffset - ? newSelection.baseOffset - : newSelection.extentOffset; + newOffset = + newSelection.baseOffset < newSelection.extentOffset ? newSelection.baseOffset : newSelection.extentOffset; } else if (rightKey) { - newOffset = newSelection.baseOffset > newSelection.extentOffset - ? newSelection.baseOffset - : newSelection.extentOffset; + newOffset = + newSelection.baseOffset > newSelection.extentOffset ? newSelection.baseOffset : newSelection.extentOffset; } } return TextSelection.fromPosition(TextPosition(offset: newOffset)); } TextSelection _handleMovingCursorVertically( - bool upKey, - bool downKey, - bool shift, - TextSelection selection, - TextSelection newSelection, - String plainText) { - final originPosition = TextPosition( - offset: upKey ? selection.baseOffset : selection.extentOffset); + bool upKey, bool downKey, bool shift, TextSelection selection, TextSelection newSelection, String plainText) { + final originPosition = TextPosition(offset: upKey ? selection.baseOffset : selection.extentOffset); final child = getRenderEditor()!.childAtPosition(originPosition); - final localPosition = TextPosition( - offset: originPosition.offset - child.container.documentOffset); + final localPosition = TextPosition(offset: originPosition.offset - child.container.documentOffset); - var position = upKey - ? child.getPositionAbove(localPosition) - : child.getPositionBelow(localPosition); + var position = upKey ? child.getPositionAbove(localPosition) : child.getPositionBelow(localPosition); if (position == null) { - final sibling = upKey - ? getRenderEditor()!.childBefore(child) - : getRenderEditor()!.childAfter(child); + final sibling = upKey ? getRenderEditor()!.childBefore(child) : getRenderEditor()!.childAfter(child); if (sibling == null) { position = TextPosition(offset: upKey ? 0 : plainText.length - 1); } else { - final finalOffset = Offset( - child.getOffsetForCaret(localPosition).dx, - sibling - .getOffsetForCaret(TextPosition( - offset: upKey ? sibling.container.length - 1 : 0)) - .dy); + final finalOffset = Offset(child.getOffsetForCaret(localPosition).dx, + sibling.getOffsetForCaret(TextPosition(offset: upKey ? sibling.container.length - 1 : 0)).dy); final siblingPosition = sibling.getPositionForOffset(finalOffset); - position = TextPosition( - offset: sibling.container.documentOffset + siblingPosition.offset); + position = TextPosition(offset: sibling.container.documentOffset + siblingPosition.offset); } } else { - position = TextPosition( - offset: child.container.documentOffset + position.offset); + position = TextPosition(offset: child.container.documentOffset + position.offset); } if (position.offset == newSelection.extentOffset) { @@ -275,47 +250,33 @@ class _RawEditorState extends EditorState return newSelection; } - TextSelection _jumpToBeginOrEndOfWord( - TextSelection newSelection, - bool wordModifier, - bool leftKey, - bool rightKey, - String plainText, - bool lineModifier, - bool shift) { + TextSelection _jumpToBeginOrEndOfWord(TextSelection newSelection, bool wordModifier, bool leftKey, bool rightKey, + String plainText, bool lineModifier, bool shift) { if (wordModifier) { if (leftKey) { final textSelection = getRenderEditor()!.selectWordAtPosition( - TextPosition( - offset: _previousCharacter( - newSelection.extentOffset, plainText, false))); + TextPosition(offset: _previousCharacter(newSelection.extentOffset, plainText, false))); return newSelection.copyWith(extentOffset: textSelection.baseOffset); } - final textSelection = getRenderEditor()!.selectWordAtPosition( - TextPosition( - offset: - _nextCharacter(newSelection.extentOffset, plainText, false))); + final textSelection = getRenderEditor()! + .selectWordAtPosition(TextPosition(offset: _nextCharacter(newSelection.extentOffset, plainText, false))); return newSelection.copyWith(extentOffset: textSelection.extentOffset); } else if (lineModifier) { if (leftKey) { final textSelection = getRenderEditor()!.selectLineAtPosition( - TextPosition( - offset: _previousCharacter( - newSelection.extentOffset, plainText, false))); + TextPosition(offset: _previousCharacter(newSelection.extentOffset, plainText, false))); return newSelection.copyWith(extentOffset: textSelection.baseOffset); } final startPoint = newSelection.extentOffset; if (startPoint < plainText.length) { - final textSelection = getRenderEditor()! - .selectLineAtPosition(TextPosition(offset: startPoint)); + final textSelection = getRenderEditor()!.selectLineAtPosition(TextPosition(offset: startPoint)); return newSelection.copyWith(extentOffset: textSelection.extentOffset); } return newSelection; } if (rightKey && newSelection.extentOffset < plainText.length) { - final nextExtent = - _nextCharacter(newSelection.extentOffset, plainText, true); + final nextExtent = _nextCharacter(newSelection.extentOffset, plainText, true); final distance = nextExtent - newSelection.extentOffset; newSelection = newSelection.copyWith(extentOffset: nextExtent); if (shift) { @@ -325,8 +286,7 @@ class _RawEditorState extends EditorState } if (leftKey && newSelection.extentOffset > 0) { - final previousExtent = - _previousCharacter(newSelection.extentOffset, plainText, true); + final previousExtent = _previousCharacter(newSelection.extentOffset, plainText, true); final distance = newSelection.extentOffset - previousExtent; newSelection = newSelection.copyWith(extentOffset: previousExtent); if (shift) { @@ -366,9 +326,7 @@ class _RawEditorState extends EditorState var count = 0; int? lastNonWhitespace; for (final currentString in string.characters) { - if (!includeWhitespace && - !WHITE_SPACE.contains( - currentString.characters.first.toString().codeUnitAt(0))) { + if (!includeWhitespace && !WHITE_SPACE.contains(currentString.characters.first.toString().codeUnitAt(0))) { lastNonWhitespace = count; } if (count + currentString.length >= index) { @@ -379,8 +337,7 @@ class _RawEditorState extends EditorState return 0; } - bool get hasConnection => - _textInputConnection != null && _textInputConnection!.attached; + bool get hasConnection => _textInputConnection != null && _textInputConnection!.attached; void openConnectionIfNeeded() { if (!shouldCreateInputConnection) { @@ -431,8 +388,7 @@ class _RawEditorState extends EditorState return; } - final shouldRemember = - textEditingValue.text != _lastKnownRemoteTextEditingValue!.text; + final shouldRemember = textEditingValue.text != _lastKnownRemoteTextEditingValue!.text; _lastKnownRemoteTextEditingValue = actualValue; _textInputConnection!.setEditingState(actualValue); if (shouldRemember) { @@ -441,8 +397,7 @@ class _RawEditorState extends EditorState } @override - TextEditingValue? get currentTextEditingValue => - _lastKnownRemoteTextEditingValue; + TextEditingValue? get currentTextEditingValue => _lastKnownRemoteTextEditingValue; @override AutofillScope? get currentAutofillScope => null; @@ -474,8 +429,7 @@ class _RawEditorState extends EditorState final text = value.text; final cursorPosition = value.selection.extentOffset; final diff = getDiff(oldText, text, cursorPosition); - widget.controller.replaceText( - diff.start, diff.deleted.length, diff.inserted, value.selection); + widget.controller.replaceText(diff.start, diff.deleted.length, diff.inserted, value.selection); } @override @@ -525,11 +479,8 @@ class _RawEditorState extends EditorState super.build(context); var _doc = widget.controller.document; - if (_doc.isEmpty() && - !widget.focusNode.hasFocus && - widget.placeholder != null) { - _doc = Document.fromJson(jsonDecode( - '[{"attributes":{"placeholder":true},"insert":"${widget.placeholder}\\n"}]')); + if (_doc.isEmpty() && !widget.focusNode.hasFocus && widget.placeholder != null) { + _doc = Document.fromJson(jsonDecode('[{"attributes":{"placeholder":true},"insert":"${widget.placeholder}\\n"}]')); } Widget child = CompositedTransformTarget( @@ -552,8 +503,7 @@ class _RawEditorState extends EditorState ); if (widget.scrollable) { - final baselinePadding = - EdgeInsets.only(top: _styles!.paragraph!.verticalSpacing.item1); + final baselinePadding = EdgeInsets.only(top: _styles!.paragraph!.verticalSpacing.item1); child = BaselineProxy( textStyle: _styles!.paragraph!.style, padding: baselinePadding, @@ -584,8 +534,7 @@ class _RawEditorState extends EditorState ); } - void _handleSelectionChanged( - TextSelection selection, SelectionChangedCause cause) { + void _handleSelectionChanged(TextSelection selection, SelectionChangedCause cause) { widget.controller.updateSelection(selection, ChangeSource.LOCAL); _selectionOverlay?.handlesVisible = _shouldShowSelectionHandles(); @@ -614,9 +563,7 @@ class _RawEditorState extends EditorState _styles, widget.enableInteractiveSelection, _hasFocus, - attrs.containsKey(Attribute.codeBlock.key) - ? const EdgeInsets.all(16) - : null, + attrs.containsKey(Attribute.codeBlock.key) ? const EdgeInsets.all(16) : null, widget.embedBuilder, _cursorController, indentLevelCounts); @@ -628,8 +575,7 @@ class _RawEditorState extends EditorState return result; } - EditableTextLine _getEditableTextLineFromNode( - Line node, BuildContext context) { + EditableTextLine _getEditableTextLineFromNode(Line node, BuildContext context) { final textLine = TextLine( line: node, textDirection: _textDirection, @@ -652,8 +598,7 @@ class _RawEditorState extends EditorState return editableTextLine; } - Tuple2 _getVerticalSpacingForLine( - Line line, DefaultStyles? defaultStyles) { + Tuple2 _getVerticalSpacingForLine(Line line, DefaultStyles? defaultStyles) { final attrs = line.style.attributes; if (attrs.containsKey(Attribute.header.key)) { final int? level = attrs[Attribute.header.key]!.value; @@ -678,8 +623,7 @@ class _RawEditorState extends EditorState return defaultStyles!.paragraph!.verticalSpacing; } - Tuple2 _getVerticalSpacingForBlock( - Block node, DefaultStyles? defaultStyles) { + Tuple2 _getVerticalSpacingForBlock(Block node, DefaultStyles? defaultStyles) { final attrs = node.style.attributes; if (attrs.containsKey(Attribute.quoteBlock.key)) { return defaultStyles!.quote!.verticalSpacing; @@ -722,8 +666,7 @@ class _RawEditorState extends EditorState } else { _keyboardVisibilityController = KeyboardVisibilityController(); _keyboardVisible = _keyboardVisibilityController!.isVisible; - _keyboardVisibilitySubscription = - _keyboardVisibilityController?.onChange.listen((visible) { + _keyboardVisibilitySubscription = _keyboardVisibilityController?.onChange.listen((visible) { _keyboardVisible = visible; if (visible) { _onChangeTextEditingValue(); @@ -746,9 +689,7 @@ class _RawEditorState extends EditorState super.didChangeDependencies(); final parentStyles = EditorStyles.getStyles(context, true); final defaultStyles = DefaultStyles.getInstance(context); - _styles = (parentStyles != null) - ? defaultStyles.merge(parentStyles) - : defaultStyles; + _styles = (parentStyles != null) ? defaultStyles.merge(parentStyles) : defaultStyles; if (widget.customStyles != null) { _styles = _styles!.merge(widget.customStyles!); @@ -808,8 +749,7 @@ class _RawEditorState extends EditorState } bool _shouldShowSelectionHandles() { - return widget.showSelectionHandles && - !widget.controller.selection.isCollapsed; + return widget.showSelectionHandles && !widget.controller.selection.isCollapsed; } void handleDelete(bool forward) { @@ -820,8 +760,7 @@ class _RawEditorState extends EditorState var textAfter = selection.textAfter(plainText); if (selection.isCollapsed) { if (!forward && textBefore.isNotEmpty) { - final characterBoundary = - _previousCharacter(textBefore.length, textBefore, true); + final characterBoundary = _previousCharacter(textBefore.length, textBefore, true); textBefore = textBefore.substring(0, characterBoundary); cursorPosition = characterBoundary; } @@ -844,10 +783,16 @@ class _RawEditorState extends EditorState Future handleShortcut(InputShortcut? shortcut) async { final selection = widget.controller.selection; final plainText = textEditingValue.text; + if (shortcut == InputShortcut.SAVE) { + bool saved = await widget.controller.save(); + if (!saved) { + log('Unabled to save document.'); + } + return; + } if (shortcut == InputShortcut.COPY) { if (!selection.isCollapsed) { - await Clipboard.setData( - ClipboardData(text: selection.textInside(plainText))); + await Clipboard.setData(ClipboardData(text: selection.textInside(plainText))); } return; } @@ -864,8 +809,7 @@ class _RawEditorState extends EditorState ); textEditingValue = TextEditingValue( - text: - selection.textBefore(plainText) + selection.textAfter(plainText), + text: selection.textBefore(plainText) + selection.textAfter(plainText), selection: TextSelection.collapsed(offset: selection.start), ); } @@ -883,8 +827,7 @@ class _RawEditorState extends EditorState } return; } - if (shortcut == InputShortcut.SELECT_ALL && - widget.enableInteractiveSelection) { + if (shortcut == InputShortcut.SELECT_ALL && widget.enableInteractiveSelection) { widget.controller.updateSelection( selection.copyWith( baseOffset: 0, @@ -938,16 +881,14 @@ class _RawEditorState extends EditorState void _onChangeTextEditingValue() { _showCaretOnScreen(); updateRemoteValueIfNeeded(); - _cursorController.startOrStopCursorTimerIfNeeded( - _hasFocus, widget.controller.selection); + _cursorController.startOrStopCursorTimerIfNeeded(_hasFocus, widget.controller.selection); if (hasConnection) { _cursorController ..stopCursorTimer(resetCharTicks: false) ..startCursorTimer(); } - SchedulerBinding.instance!.addPostFrameCallback( - (_) => _updateOrDisposeSelectionOverlayIfNeeded()); + SchedulerBinding.instance!.addPostFrameCallback((_) => _updateOrDisposeSelectionOverlayIfNeeded()); if (mounted) { setState(() { // Use widget.controller.value in build() @@ -990,8 +931,7 @@ class _RawEditorState extends EditorState void _handleFocusChanged() { openOrCloseConnection(); - _cursorController.startOrStopCursorTimerIfNeeded( - _hasFocus, widget.controller.selection); + _cursorController.startOrStopCursorTimerIfNeeded(_hasFocus, widget.controller.selection); _updateOrDisposeSelectionOverlayIfNeeded(); if (_hasFocus) { WidgetsBinding.instance!.addObserver(this); @@ -1022,8 +962,7 @@ class _RawEditorState extends EditorState _showCaretOnScreenScheduled = false; final viewport = RenderAbstractViewport.of(getRenderEditor())!; - final editorOffset = getRenderEditor()! - .localToGlobal(const Offset(0, 0), ancestor: viewport); + final editorOffset = getRenderEditor()!.localToGlobal(const Offset(0, 0), ancestor: viewport); final offsetInViewport = _scrollController!.offset + editorOffset.dy; final offset = getRenderEditor()!.getOffsetToRevealCursor( @@ -1106,8 +1045,7 @@ class _RawEditorState extends EditorState final value = textEditingValue; final data = await Clipboard.getData(Clipboard.kTextPlain); if (data != null) { - final length = - textEditingValue.selection.end - textEditingValue.selection.start; + final length = textEditingValue.selection.end - textEditingValue.selection.start; widget.controller.replaceText( value.selection.start, length, @@ -1116,9 +1054,7 @@ class _RawEditorState extends EditorState ); // move cursor to the end of pasted text selection widget.controller.updateSelection( - TextSelection.collapsed( - offset: value.selection.start + data.text!.length), - ChangeSource.LOCAL); + TextSelection.collapsed(offset: value.selection.start + data.text!.length), ChangeSource.LOCAL); } } } @@ -1128,8 +1064,7 @@ class _RawEditorState extends EditorState if (data == null) { return false; } - return textEditingValue.text.length - value.text.length == - data.text!.length; + return textEditingValue.text.length - value.text.length == data.text!.length; } @override @@ -1162,8 +1097,7 @@ class _RawEditorState extends EditorState } @override - void userUpdateTextEditingValue( - TextEditingValue value, SelectionChangedCause cause) { + void userUpdateTextEditingValue(TextEditingValue value, SelectionChangedCause cause) { // TODO: implement userUpdateTextEditingValue } } @@ -1213,8 +1147,7 @@ class _Editor extends MultiChildRenderObjectWidget { } @override - void updateRenderObject( - BuildContext context, covariant RenderEditor renderObject) { + void updateRenderObject(BuildContext context, covariant RenderEditor renderObject) { renderObject ..document = document ..container = document.root diff --git a/app_flowy/packages/flowy_infra/pubspec.lock b/app_flowy/packages/flowy_infra/pubspec.lock index c043549f48..9bbcf33e9e 100644 --- a/app_flowy/packages/flowy_infra/pubspec.lock +++ b/app_flowy/packages/flowy_infra/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.7.0" + version: "2.6.1" boolean_selector: dependency: transitive description: @@ -28,7 +28,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.3.1" + version: "1.2.0" clock: dependency: transitive description: @@ -101,7 +101,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.4.0" + version: "1.3.0" path: dependency: transitive description: @@ -155,7 +155,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.1" + version: "0.3.0" textstyle_extensions: dependency: "direct main" description: diff --git a/app_flowy/packages/flowy_infra_ui/example/pubspec.lock b/app_flowy/packages/flowy_infra_ui/example/pubspec.lock index c2685ea99f..76f4d31c6c 100644 --- a/app_flowy/packages/flowy_infra_ui/example/pubspec.lock +++ b/app_flowy/packages/flowy_infra_ui/example/pubspec.lock @@ -14,7 +14,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.7.0" boolean_selector: dependency: transitive description: @@ -35,7 +35,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -176,7 +176,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" nested: dependency: transitive description: @@ -258,7 +258,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.1" textstyle_extensions: dependency: transitive description: diff --git a/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_platform_interface/test/flowy_infra_ui_platform_interface_test.dart b/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_platform_interface/test/flowy_infra_ui_platform_interface_test.dart index b351001e1a..ab73b3a234 100644 --- a/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_platform_interface/test/flowy_infra_ui_platform_interface_test.dart +++ b/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_platform_interface/test/flowy_infra_ui_platform_interface_test.dart @@ -1,5 +1 @@ -import 'package:flutter_test/flutter_test.dart'; - -import 'package:flowy_infra_ui_platform_interface/flowy_infra_ui_platform_interface.dart'; - void main() {} diff --git a/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_web/test/flowy_infra_ui_web_test.dart b/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_web/test/flowy_infra_ui_web_test.dart index a9de9b8be5..ab73b3a234 100644 --- a/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_web/test/flowy_infra_ui_web_test.dart +++ b/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_web/test/flowy_infra_ui_web_test.dart @@ -1,5 +1 @@ -import 'package:flutter_test/flutter_test.dart'; - -import 'package:flowy_infra_ui_web/flowy_infra_ui_web.dart'; - void main() {} diff --git a/app_flowy/packages/flowy_infra_ui/lib/widget/error_page.dart b/app_flowy/packages/flowy_infra_ui/lib/widget/error_page.dart new file mode 100644 index 0000000000..f315c7d6d0 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/lib/widget/error_page.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +class FlowyErrorPage extends StatelessWidget { + final String error; + const FlowyErrorPage(this.error, {Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + child: Text(error), + ); + } +} diff --git a/app_flowy/packages/flowy_infra_ui/pubspec.lock b/app_flowy/packages/flowy_infra_ui/pubspec.lock index 98f80cfe2a..e05bfcbe05 100644 --- a/app_flowy/packages/flowy_infra_ui/pubspec.lock +++ b/app_flowy/packages/flowy_infra_ui/pubspec.lock @@ -14,7 +14,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.7.0" boolean_selector: dependency: transitive description: @@ -35,7 +35,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -162,7 +162,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" nested: dependency: transitive description: @@ -244,7 +244,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.1" textstyle_extensions: dependency: "direct main" description: diff --git a/app_flowy/packages/flowy_infra_ui/test/flowy_infra_ui_test.dart b/app_flowy/packages/flowy_infra_ui/test/flowy_infra_ui_test.dart index c7e2a4cf99..ee0b1ea9aa 100644 --- a/app_flowy/packages/flowy_infra_ui/test/flowy_infra_ui_test.dart +++ b/app_flowy/packages/flowy_infra_ui/test/flowy_infra_ui_test.dart @@ -1,6 +1,5 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:flowy_infra_ui/flowy_infra_ui.dart'; void main() { const MethodChannel channel = MethodChannel('flowy_infra_ui'); @@ -16,8 +15,4 @@ void main() { tearDown(() { channel.setMockMethodCallHandler(null); }); - - test('getPlatformVersion', () async { - expect(await FlowyInfraUi.platformVersion, '42'); - }); } diff --git a/app_flowy/packages/flowy_sdk/example/pubspec.lock b/app_flowy/packages/flowy_sdk/example/pubspec.lock index f4b55f1d50..b1bb8d395a 100644 --- a/app_flowy/packages/flowy_sdk/example/pubspec.lock +++ b/app_flowy/packages/flowy_sdk/example/pubspec.lock @@ -14,7 +14,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.7.0" + version: "2.6.1" boolean_selector: dependency: transitive description: @@ -35,7 +35,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.3.1" + version: "1.2.0" clock: dependency: transitive description: @@ -91,7 +91,7 @@ packages: name: file url: "https://pub.dartlang.org" source: hosted - version: "6.1.2" + version: "6.1.1" fixnum: dependency: transitive description: @@ -193,7 +193,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.4.0" + version: "1.3.0" path: dependency: transitive description: @@ -275,7 +275,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.1" + version: "0.3.0" textstyle_extensions: dependency: transitive description: @@ -317,7 +317,7 @@ packages: name: vm_service url: "https://pub.dartlang.org" source: hosted - version: "7.1.0" + version: "6.2.0" webdriver: dependency: transitive description: diff --git a/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart b/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart index 799493ba24..2b9d2036e7 100644 --- a/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart +++ b/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart @@ -2,6 +2,207 @@ /// Auto gen code from rust ast, do not edit part of 'dispatch.dart'; +class EditorEventCreateDoc { + CreateDocRequest request; + EditorEventCreateDoc(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = EditorEvent.CreateDoc.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (okBytes) => left(DocInfo.fromBuffer(okBytes)), + (errBytes) => right(EditorError.fromBuffer(errBytes)), + )); + } +} + +class EditorEventUpdateDoc { + UpdateDocRequest request; + EditorEventUpdateDoc(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = EditorEvent.UpdateDoc.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (bytes) => left(unit), + (errBytes) => right(EditorError.fromBuffer(errBytes)), + )); + } +} + +class EditorEventReadDocInfo { + QueryDocRequest request; + EditorEventReadDocInfo(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = EditorEvent.ReadDocInfo.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (okBytes) => left(DocInfo.fromBuffer(okBytes)), + (errBytes) => right(EditorError.fromBuffer(errBytes)), + )); + } +} + +class EditorEventReadDocData { + QueryDocDataRequest request; + EditorEventReadDocData(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = EditorEvent.ReadDocData.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (okBytes) => left(DocData.fromBuffer(okBytes)), + (errBytes) => right(EditorError.fromBuffer(errBytes)), + )); + } +} + +class WorkspaceEventCreateWorkspace { + CreateWorkspaceRequest request; + WorkspaceEventCreateWorkspace(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = WorkspaceEvent.CreateWorkspace.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (okBytes) => left(Workspace.fromBuffer(okBytes)), + (errBytes) => right(WorkspaceError.fromBuffer(errBytes)), + )); + } +} + +class WorkspaceEventGetCurWorkspace { + WorkspaceEventGetCurWorkspace(); + + Future> send() { + final request = FFIRequest.create() + ..event = WorkspaceEvent.GetCurWorkspace.toString(); + + return Dispatch.asyncRequest(request).then((bytesResult) => bytesResult.fold( + (okBytes) => left(Workspace.fromBuffer(okBytes)), + (errBytes) => right(WorkspaceError.fromBuffer(errBytes)), + )); + } +} + +class WorkspaceEventGetWorkspace { + QueryWorkspaceRequest request; + WorkspaceEventGetWorkspace(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = WorkspaceEvent.GetWorkspace.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (okBytes) => left(Workspace.fromBuffer(okBytes)), + (errBytes) => right(WorkspaceError.fromBuffer(errBytes)), + )); + } +} + +class WorkspaceEventCreateApp { + CreateAppRequest request; + WorkspaceEventCreateApp(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = WorkspaceEvent.CreateApp.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (okBytes) => left(App.fromBuffer(okBytes)), + (errBytes) => right(WorkspaceError.fromBuffer(errBytes)), + )); + } +} + +class WorkspaceEventGetApp { + QueryAppRequest request; + WorkspaceEventGetApp(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = WorkspaceEvent.GetApp.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (okBytes) => left(App.fromBuffer(okBytes)), + (errBytes) => right(WorkspaceError.fromBuffer(errBytes)), + )); + } +} + +class WorkspaceEventCreateView { + CreateViewRequest request; + WorkspaceEventCreateView(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = WorkspaceEvent.CreateView.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (okBytes) => left(View.fromBuffer(okBytes)), + (errBytes) => right(WorkspaceError.fromBuffer(errBytes)), + )); + } +} + +class WorkspaceEventReadView { + QueryViewRequest request; + WorkspaceEventReadView(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = WorkspaceEvent.ReadView.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (okBytes) => left(View.fromBuffer(okBytes)), + (errBytes) => right(WorkspaceError.fromBuffer(errBytes)), + )); + } +} + +class WorkspaceEventUpdateView { + UpdateViewRequest request; + WorkspaceEventUpdateView(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = WorkspaceEvent.UpdateView.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (bytes) => left(unit), + (errBytes) => right(WorkspaceError.fromBuffer(errBytes)), + )); + } +} + class UserEventGetStatus { UserEventGetStatus(); @@ -27,8 +228,8 @@ class UserEventSignIn { return Dispatch.asyncRequest(request) .then((bytesResult) => bytesResult.fold( - (okBytes) => left(UserDetail.fromBuffer(okBytes)), - (errBytes) => right(UserError.fromBuffer(errBytes)), + (okBytes) => left(UserDetail.fromBuffer(okBytes)), + (errBytes) => right(UserError.fromBuffer(errBytes)), )); } } @@ -44,8 +245,8 @@ class UserEventSignUp { return Dispatch.asyncRequest(request) .then((bytesResult) => bytesResult.fold( - (okBytes) => left(UserDetail.fromBuffer(okBytes)), - (errBytes) => right(UserError.fromBuffer(errBytes)), + (okBytes) => left(UserDetail.fromBuffer(okBytes)), + (errBytes) => right(UserError.fromBuffer(errBytes)), )); } } @@ -64,3 +265,20 @@ class UserEventSignOut { } } +class UserEventUpdateUser { + UpdateUserRequest request; + UserEventUpdateUser(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = UserEvent.UpdateUser.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (okBytes) => left(UserDetail.fromBuffer(okBytes)), + (errBytes) => right(UserError.fromBuffer(errBytes)), + )); + } +} + diff --git a/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart b/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart index f3e68e120f..5e6bbff243 100644 --- a/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart +++ b/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart @@ -12,6 +12,8 @@ import 'dart:typed_data'; import 'package:flowy_sdk/ffi.dart' as ffi; import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart'; import 'package:flowy_sdk/protobuf/dart-ffi/protobuf.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/protobuf.dart'; +import 'package:flowy_sdk/protobuf/flowy-editor/protobuf.dart'; // ignore: unused_import import 'package:flowy_sdk/protobuf/flowy-infra/protobuf.dart'; import 'package:protobuf/protobuf.dart'; diff --git a/app_flowy/packages/flowy_sdk/lib/ffi.dart b/app_flowy/packages/flowy_sdk/lib/ffi.dart index df3ff0de61..f794b4202c 100644 --- a/app_flowy/packages/flowy_sdk/lib/ffi.dart +++ b/app_flowy/packages/flowy_sdk/lib/ffi.dart @@ -80,6 +80,22 @@ typedef _init_sdk_Dart = int Function( Pointer path, ); + +/// C function `init_stream`. +int set_stream_port(int port) { + return _set_stream_port(port); +} + +final _set_stream_port_Dart _set_stream_port = +_dl.lookupFunction<_set_stream_port_C, _set_stream_port_Dart>('set_stream_port'); + +typedef _set_stream_port_C = Int32 Function( + Int64 port, + ); +typedef _set_stream_port_Dart = int Function( + int port, + ); + /// C function `link_me_please`. void link_me_please() { _link_me_please(); diff --git a/app_flowy/packages/flowy_sdk/lib/flowy_sdk.dart b/app_flowy/packages/flowy_sdk/lib/flowy_sdk.dart index 5ea973daa9..ff386f2bf7 100644 --- a/app_flowy/packages/flowy_sdk/lib/flowy_sdk.dart +++ b/app_flowy/packages/flowy_sdk/lib/flowy_sdk.dart @@ -1,6 +1,7 @@ export 'package:async/async.dart'; import 'dart:io'; import 'dart:async'; +import 'package:flowy_sdk/rust_stream.dart'; import 'package:flutter/services.dart'; import 'dart:ffi'; import 'ffi.dart' as ffi; @@ -18,6 +19,9 @@ class FlowySDK { void dispose() {} Future init(Directory sdkDir) async { + final port = RustStreamReceiver.shared.port; + ffi.set_stream_port(port); + ffi.store_dart_post_cobject(NativeApi.postCObject); ffi.init_sdk(sdkDir.path.toNativeUtf8()); } diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pb.dart new file mode 100644 index 0000000000..8421e9ae6f --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pb.dart @@ -0,0 +1,236 @@ +/// +// Generated code. Do not modify. +// source: doc_create.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +class CreateDocRequest extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'CreateDocRequest', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id') + ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') + ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc') + ..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'text') + ..hasRequiredFields = false + ; + + CreateDocRequest._() : super(); + factory CreateDocRequest({ + $core.String? id, + $core.String? name, + $core.String? desc, + $core.String? text, + }) { + final _result = create(); + if (id != null) { + _result.id = id; + } + if (name != null) { + _result.name = name; + } + if (desc != null) { + _result.desc = desc; + } + if (text != null) { + _result.text = text; + } + return _result; + } + factory CreateDocRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory CreateDocRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + CreateDocRequest clone() => CreateDocRequest()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + CreateDocRequest copyWith(void Function(CreateDocRequest) updates) => super.copyWith((message) => updates(message as CreateDocRequest)) as CreateDocRequest; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static CreateDocRequest create() => CreateDocRequest._(); + CreateDocRequest createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static CreateDocRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static CreateDocRequest? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get id => $_getSZ(0); + @$pb.TagNumber(1) + set id($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasId() => $_has(0); + @$pb.TagNumber(1) + void clearId() => clearField(1); + + @$pb.TagNumber(2) + $core.String get name => $_getSZ(1); + @$pb.TagNumber(2) + set name($core.String v) { $_setString(1, v); } + @$pb.TagNumber(2) + $core.bool hasName() => $_has(1); + @$pb.TagNumber(2) + void clearName() => clearField(2); + + @$pb.TagNumber(3) + $core.String get desc => $_getSZ(2); + @$pb.TagNumber(3) + set desc($core.String v) { $_setString(2, v); } + @$pb.TagNumber(3) + $core.bool hasDesc() => $_has(2); + @$pb.TagNumber(3) + void clearDesc() => clearField(3); + + @$pb.TagNumber(4) + $core.String get text => $_getSZ(3); + @$pb.TagNumber(4) + set text($core.String v) { $_setString(3, v); } + @$pb.TagNumber(4) + $core.bool hasText() => $_has(3); + @$pb.TagNumber(4) + void clearText() => clearField(4); +} + +class DocInfo extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'DocInfo', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id') + ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') + ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc') + ..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'path') + ..hasRequiredFields = false + ; + + DocInfo._() : super(); + factory DocInfo({ + $core.String? id, + $core.String? name, + $core.String? desc, + $core.String? path, + }) { + final _result = create(); + if (id != null) { + _result.id = id; + } + if (name != null) { + _result.name = name; + } + if (desc != null) { + _result.desc = desc; + } + if (path != null) { + _result.path = path; + } + return _result; + } + factory DocInfo.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory DocInfo.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + DocInfo clone() => DocInfo()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + DocInfo copyWith(void Function(DocInfo) updates) => super.copyWith((message) => updates(message as DocInfo)) as DocInfo; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static DocInfo create() => DocInfo._(); + DocInfo createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static DocInfo getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static DocInfo? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get id => $_getSZ(0); + @$pb.TagNumber(1) + set id($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasId() => $_has(0); + @$pb.TagNumber(1) + void clearId() => clearField(1); + + @$pb.TagNumber(2) + $core.String get name => $_getSZ(1); + @$pb.TagNumber(2) + set name($core.String v) { $_setString(1, v); } + @$pb.TagNumber(2) + $core.bool hasName() => $_has(1); + @$pb.TagNumber(2) + void clearName() => clearField(2); + + @$pb.TagNumber(3) + $core.String get desc => $_getSZ(2); + @$pb.TagNumber(3) + set desc($core.String v) { $_setString(2, v); } + @$pb.TagNumber(3) + $core.bool hasDesc() => $_has(2); + @$pb.TagNumber(3) + void clearDesc() => clearField(3); + + @$pb.TagNumber(4) + $core.String get path => $_getSZ(3); + @$pb.TagNumber(4) + set path($core.String v) { $_setString(3, v); } + @$pb.TagNumber(4) + $core.bool hasPath() => $_has(3); + @$pb.TagNumber(4) + void clearPath() => clearField(4); +} + +class DocData extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'DocData', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'text') + ..hasRequiredFields = false + ; + + DocData._() : super(); + factory DocData({ + $core.String? text, + }) { + final _result = create(); + if (text != null) { + _result.text = text; + } + return _result; + } + factory DocData.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory DocData.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + DocData clone() => DocData()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + DocData copyWith(void Function(DocData) updates) => super.copyWith((message) => updates(message as DocData)) as DocData; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static DocData create() => DocData._(); + DocData createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static DocData getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static DocData? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get text => $_getSZ(0); + @$pb.TagNumber(1) + set text($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasText() => $_has(0); + @$pb.TagNumber(1) + void clearText() => clearField(1); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbenum.dart new file mode 100644 index 0000000000..5a18459933 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbenum.dart @@ -0,0 +1,7 @@ +/// +// Generated code. Do not modify. +// source: doc_create.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbjson.dart new file mode 100644 index 0000000000..82b7365445 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbjson.dart @@ -0,0 +1,46 @@ +/// +// Generated code. Do not modify. +// source: doc_create.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +import 'dart:core' as $core; +import 'dart:convert' as $convert; +import 'dart:typed_data' as $typed_data; +@$core.Deprecated('Use createDocRequestDescriptor instead') +const CreateDocRequest$json = const { + '1': 'CreateDocRequest', + '2': const [ + const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'}, + const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'}, + const {'1': 'desc', '3': 3, '4': 1, '5': 9, '10': 'desc'}, + const {'1': 'text', '3': 4, '4': 1, '5': 9, '10': 'text'}, + ], +}; + +/// Descriptor for `CreateDocRequest`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List createDocRequestDescriptor = $convert.base64Decode('ChBDcmVhdGVEb2NSZXF1ZXN0Eg4KAmlkGAEgASgJUgJpZBISCgRuYW1lGAIgASgJUgRuYW1lEhIKBGRlc2MYAyABKAlSBGRlc2MSEgoEdGV4dBgEIAEoCVIEdGV4dA=='); +@$core.Deprecated('Use docInfoDescriptor instead') +const DocInfo$json = const { + '1': 'DocInfo', + '2': const [ + const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'}, + const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'}, + const {'1': 'desc', '3': 3, '4': 1, '5': 9, '10': 'desc'}, + const {'1': 'path', '3': 4, '4': 1, '5': 9, '10': 'path'}, + ], +}; + +/// Descriptor for `DocInfo`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List docInfoDescriptor = $convert.base64Decode('CgdEb2NJbmZvEg4KAmlkGAEgASgJUgJpZBISCgRuYW1lGAIgASgJUgRuYW1lEhIKBGRlc2MYAyABKAlSBGRlc2MSEgoEcGF0aBgEIAEoCVIEcGF0aA=='); +@$core.Deprecated('Use docDataDescriptor instead') +const DocData$json = const { + '1': 'DocData', + '2': const [ + const {'1': 'text', '3': 1, '4': 1, '5': 9, '10': 'text'}, + ], +}; + +/// Descriptor for `DocData`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List docDataDescriptor = $convert.base64Decode('CgdEb2NEYXRhEhIKBHRleHQYASABKAlSBHRleHQ='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbserver.dart new file mode 100644 index 0000000000..04a394275c --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: doc_create.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +export 'doc_create.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pb.dart new file mode 100644 index 0000000000..65a548358d --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pb.dart @@ -0,0 +1,139 @@ +/// +// Generated code. Do not modify. +// source: doc_modify.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +enum UpdateDocRequest_OneOfName { + name, + notSet +} + +enum UpdateDocRequest_OneOfDesc { + desc, + notSet +} + +enum UpdateDocRequest_OneOfText { + text, + notSet +} + +class UpdateDocRequest extends $pb.GeneratedMessage { + static const $core.Map<$core.int, UpdateDocRequest_OneOfName> _UpdateDocRequest_OneOfNameByTag = { + 2 : UpdateDocRequest_OneOfName.name, + 0 : UpdateDocRequest_OneOfName.notSet + }; + static const $core.Map<$core.int, UpdateDocRequest_OneOfDesc> _UpdateDocRequest_OneOfDescByTag = { + 3 : UpdateDocRequest_OneOfDesc.desc, + 0 : UpdateDocRequest_OneOfDesc.notSet + }; + static const $core.Map<$core.int, UpdateDocRequest_OneOfText> _UpdateDocRequest_OneOfTextByTag = { + 4 : UpdateDocRequest_OneOfText.text, + 0 : UpdateDocRequest_OneOfText.notSet + }; + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UpdateDocRequest', createEmptyInstance: create) + ..oo(0, [2]) + ..oo(1, [3]) + ..oo(2, [4]) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id') + ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') + ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc') + ..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'text') + ..hasRequiredFields = false + ; + + UpdateDocRequest._() : super(); + factory UpdateDocRequest({ + $core.String? id, + $core.String? name, + $core.String? desc, + $core.String? text, + }) { + final _result = create(); + if (id != null) { + _result.id = id; + } + if (name != null) { + _result.name = name; + } + if (desc != null) { + _result.desc = desc; + } + if (text != null) { + _result.text = text; + } + return _result; + } + factory UpdateDocRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory UpdateDocRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + UpdateDocRequest clone() => UpdateDocRequest()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + UpdateDocRequest copyWith(void Function(UpdateDocRequest) updates) => super.copyWith((message) => updates(message as UpdateDocRequest)) as UpdateDocRequest; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static UpdateDocRequest create() => UpdateDocRequest._(); + UpdateDocRequest createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static UpdateDocRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static UpdateDocRequest? _defaultInstance; + + UpdateDocRequest_OneOfName whichOneOfName() => _UpdateDocRequest_OneOfNameByTag[$_whichOneof(0)]!; + void clearOneOfName() => clearField($_whichOneof(0)); + + UpdateDocRequest_OneOfDesc whichOneOfDesc() => _UpdateDocRequest_OneOfDescByTag[$_whichOneof(1)]!; + void clearOneOfDesc() => clearField($_whichOneof(1)); + + UpdateDocRequest_OneOfText whichOneOfText() => _UpdateDocRequest_OneOfTextByTag[$_whichOneof(2)]!; + void clearOneOfText() => clearField($_whichOneof(2)); + + @$pb.TagNumber(1) + $core.String get id => $_getSZ(0); + @$pb.TagNumber(1) + set id($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasId() => $_has(0); + @$pb.TagNumber(1) + void clearId() => clearField(1); + + @$pb.TagNumber(2) + $core.String get name => $_getSZ(1); + @$pb.TagNumber(2) + set name($core.String v) { $_setString(1, v); } + @$pb.TagNumber(2) + $core.bool hasName() => $_has(1); + @$pb.TagNumber(2) + void clearName() => clearField(2); + + @$pb.TagNumber(3) + $core.String get desc => $_getSZ(2); + @$pb.TagNumber(3) + set desc($core.String v) { $_setString(2, v); } + @$pb.TagNumber(3) + $core.bool hasDesc() => $_has(2); + @$pb.TagNumber(3) + void clearDesc() => clearField(3); + + @$pb.TagNumber(4) + $core.String get text => $_getSZ(3); + @$pb.TagNumber(4) + set text($core.String v) { $_setString(3, v); } + @$pb.TagNumber(4) + $core.bool hasText() => $_has(3); + @$pb.TagNumber(4) + void clearText() => clearField(4); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbenum.dart new file mode 100644 index 0000000000..7bad4b5b81 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbenum.dart @@ -0,0 +1,7 @@ +/// +// Generated code. Do not modify. +// source: doc_modify.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbjson.dart new file mode 100644 index 0000000000..edee7b3ef4 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbjson.dart @@ -0,0 +1,28 @@ +/// +// Generated code. Do not modify. +// source: doc_modify.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +import 'dart:core' as $core; +import 'dart:convert' as $convert; +import 'dart:typed_data' as $typed_data; +@$core.Deprecated('Use updateDocRequestDescriptor instead') +const UpdateDocRequest$json = const { + '1': 'UpdateDocRequest', + '2': const [ + const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'}, + const {'1': 'name', '3': 2, '4': 1, '5': 9, '9': 0, '10': 'name'}, + const {'1': 'desc', '3': 3, '4': 1, '5': 9, '9': 1, '10': 'desc'}, + const {'1': 'text', '3': 4, '4': 1, '5': 9, '9': 2, '10': 'text'}, + ], + '8': const [ + const {'1': 'one_of_name'}, + const {'1': 'one_of_desc'}, + const {'1': 'one_of_text'}, + ], +}; + +/// Descriptor for `UpdateDocRequest`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List updateDocRequestDescriptor = $convert.base64Decode('ChBVcGRhdGVEb2NSZXF1ZXN0Eg4KAmlkGAEgASgJUgJpZBIUCgRuYW1lGAIgASgJSABSBG5hbWUSFAoEZGVzYxgDIAEoCUgBUgRkZXNjEhQKBHRleHQYBCABKAlIAlIEdGV4dEINCgtvbmVfb2ZfbmFtZUINCgtvbmVfb2ZfZGVzY0INCgtvbmVfb2ZfdGV4dA=='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbserver.dart new file mode 100644 index 0000000000..928cad7186 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: doc_modify.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +export 'doc_modify.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pb.dart new file mode 100644 index 0000000000..7fddbd972f --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pb.dart @@ -0,0 +1,119 @@ +/// +// Generated code. Do not modify. +// source: doc_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +class QueryDocRequest extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'QueryDocRequest', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'docId') + ..hasRequiredFields = false + ; + + QueryDocRequest._() : super(); + factory QueryDocRequest({ + $core.String? docId, + }) { + final _result = create(); + if (docId != null) { + _result.docId = docId; + } + return _result; + } + factory QueryDocRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory QueryDocRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + QueryDocRequest clone() => QueryDocRequest()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + QueryDocRequest copyWith(void Function(QueryDocRequest) updates) => super.copyWith((message) => updates(message as QueryDocRequest)) as QueryDocRequest; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static QueryDocRequest create() => QueryDocRequest._(); + QueryDocRequest createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static QueryDocRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static QueryDocRequest? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get docId => $_getSZ(0); + @$pb.TagNumber(1) + set docId($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasDocId() => $_has(0); + @$pb.TagNumber(1) + void clearDocId() => clearField(1); +} + +class QueryDocDataRequest extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'QueryDocDataRequest', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'docId') + ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'path') + ..hasRequiredFields = false + ; + + QueryDocDataRequest._() : super(); + factory QueryDocDataRequest({ + $core.String? docId, + $core.String? path, + }) { + final _result = create(); + if (docId != null) { + _result.docId = docId; + } + if (path != null) { + _result.path = path; + } + return _result; + } + factory QueryDocDataRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory QueryDocDataRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + QueryDocDataRequest clone() => QueryDocDataRequest()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + QueryDocDataRequest copyWith(void Function(QueryDocDataRequest) updates) => super.copyWith((message) => updates(message as QueryDocDataRequest)) as QueryDocDataRequest; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static QueryDocDataRequest create() => QueryDocDataRequest._(); + QueryDocDataRequest createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static QueryDocDataRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static QueryDocDataRequest? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get docId => $_getSZ(0); + @$pb.TagNumber(1) + set docId($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasDocId() => $_has(0); + @$pb.TagNumber(1) + void clearDocId() => clearField(1); + + @$pb.TagNumber(2) + $core.String get path => $_getSZ(1); + @$pb.TagNumber(2) + set path($core.String v) { $_setString(1, v); } + @$pb.TagNumber(2) + $core.bool hasPath() => $_has(1); + @$pb.TagNumber(2) + void clearPath() => clearField(2); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbenum.dart new file mode 100644 index 0000000000..03194a6330 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbenum.dart @@ -0,0 +1,7 @@ +/// +// Generated code. Do not modify. +// source: doc_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbjson.dart new file mode 100644 index 0000000000..47e13a3b3e --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbjson.dart @@ -0,0 +1,31 @@ +/// +// Generated code. Do not modify. +// source: doc_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +import 'dart:core' as $core; +import 'dart:convert' as $convert; +import 'dart:typed_data' as $typed_data; +@$core.Deprecated('Use queryDocRequestDescriptor instead') +const QueryDocRequest$json = const { + '1': 'QueryDocRequest', + '2': const [ + const {'1': 'doc_id', '3': 1, '4': 1, '5': 9, '10': 'docId'}, + ], +}; + +/// Descriptor for `QueryDocRequest`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List queryDocRequestDescriptor = $convert.base64Decode('Cg9RdWVyeURvY1JlcXVlc3QSFQoGZG9jX2lkGAEgASgJUgVkb2NJZA=='); +@$core.Deprecated('Use queryDocDataRequestDescriptor instead') +const QueryDocDataRequest$json = const { + '1': 'QueryDocDataRequest', + '2': const [ + const {'1': 'doc_id', '3': 1, '4': 1, '5': 9, '10': 'docId'}, + const {'1': 'path', '3': 2, '4': 1, '5': 9, '10': 'path'}, + ], +}; + +/// Descriptor for `QueryDocDataRequest`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List queryDocDataRequestDescriptor = $convert.base64Decode('ChNRdWVyeURvY0RhdGFSZXF1ZXN0EhUKBmRvY19pZBgBIAEoCVIFZG9jSWQSEgoEcGF0aBgCIAEoCVIEcGF0aA=='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbserver.dart new file mode 100644 index 0000000000..6058e23a7d --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: doc_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +export 'doc_query.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pb.dart new file mode 100644 index 0000000000..bffe2ef3c6 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pb.dart @@ -0,0 +1,76 @@ +/// +// Generated code. Do not modify. +// source: errors.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +import 'errors.pbenum.dart'; + +export 'errors.pbenum.dart'; + +class EditorError extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'EditorError', createEmptyInstance: create) + ..e(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'code', $pb.PbFieldType.OE, defaultOrMaker: EditorErrorCode.Unknown, valueOf: EditorErrorCode.valueOf, enumValues: EditorErrorCode.values) + ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'msg') + ..hasRequiredFields = false + ; + + EditorError._() : super(); + factory EditorError({ + EditorErrorCode? code, + $core.String? msg, + }) { + final _result = create(); + if (code != null) { + _result.code = code; + } + if (msg != null) { + _result.msg = msg; + } + return _result; + } + factory EditorError.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory EditorError.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + EditorError clone() => EditorError()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + EditorError copyWith(void Function(EditorError) updates) => super.copyWith((message) => updates(message as EditorError)) as EditorError; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static EditorError create() => EditorError._(); + EditorError createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static EditorError getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static EditorError? _defaultInstance; + + @$pb.TagNumber(1) + EditorErrorCode get code => $_getN(0); + @$pb.TagNumber(1) + set code(EditorErrorCode v) { setField(1, v); } + @$pb.TagNumber(1) + $core.bool hasCode() => $_has(0); + @$pb.TagNumber(1) + void clearCode() => clearField(1); + + @$pb.TagNumber(2) + $core.String get msg => $_getSZ(1); + @$pb.TagNumber(2) + set msg($core.String v) { $_setString(1, v); } + @$pb.TagNumber(2) + $core.bool hasMsg() => $_has(1); + @$pb.TagNumber(2) + void clearMsg() => clearField(2); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbenum.dart new file mode 100644 index 0000000000..96ad5b534c --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbenum.dart @@ -0,0 +1,40 @@ +/// +// Generated code. Do not modify. +// source: errors.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +// ignore_for_file: UNDEFINED_SHOWN_NAME +import 'dart:core' as $core; +import 'package:protobuf/protobuf.dart' as $pb; + +class EditorErrorCode extends $pb.ProtobufEnum { + static const EditorErrorCode Unknown = EditorErrorCode._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown'); + static const EditorErrorCode EditorDBInternalError = EditorErrorCode._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EditorDBInternalError'); + static const EditorErrorCode EditorDBConnFailed = EditorErrorCode._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EditorDBConnFailed'); + static const EditorErrorCode DocNameInvalid = EditorErrorCode._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocNameInvalid'); + static const EditorErrorCode DocViewIdInvalid = EditorErrorCode._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocViewIdInvalid'); + static const EditorErrorCode DocDescTooLong = EditorErrorCode._(12, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocDescTooLong'); + static const EditorErrorCode DocOpenFileError = EditorErrorCode._(13, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocOpenFileError'); + static const EditorErrorCode DocFilePathInvalid = EditorErrorCode._(14, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocFilePathInvalid'); + static const EditorErrorCode EditorUserNotLoginYet = EditorErrorCode._(100, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EditorUserNotLoginYet'); + + static const $core.List values = [ + Unknown, + EditorDBInternalError, + EditorDBConnFailed, + DocNameInvalid, + DocViewIdInvalid, + DocDescTooLong, + DocOpenFileError, + DocFilePathInvalid, + EditorUserNotLoginYet, + ]; + + static final $core.Map<$core.int, EditorErrorCode> _byValue = $pb.ProtobufEnum.initByValue(values); + static EditorErrorCode? valueOf($core.int value) => _byValue[value]; + + const EditorErrorCode._($core.int v, $core.String n) : super(v, n); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbjson.dart new file mode 100644 index 0000000000..2e92891638 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbjson.dart @@ -0,0 +1,39 @@ +/// +// Generated code. Do not modify. +// source: errors.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +import 'dart:core' as $core; +import 'dart:convert' as $convert; +import 'dart:typed_data' as $typed_data; +@$core.Deprecated('Use editorErrorCodeDescriptor instead') +const EditorErrorCode$json = const { + '1': 'EditorErrorCode', + '2': const [ + const {'1': 'Unknown', '2': 0}, + const {'1': 'EditorDBInternalError', '2': 1}, + const {'1': 'EditorDBConnFailed', '2': 2}, + const {'1': 'DocNameInvalid', '2': 10}, + const {'1': 'DocViewIdInvalid', '2': 11}, + const {'1': 'DocDescTooLong', '2': 12}, + const {'1': 'DocOpenFileError', '2': 13}, + const {'1': 'DocFilePathInvalid', '2': 14}, + const {'1': 'EditorUserNotLoginYet', '2': 100}, + ], +}; + +/// Descriptor for `EditorErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`. +final $typed_data.Uint8List editorErrorCodeDescriptor = $convert.base64Decode('Cg9FZGl0b3JFcnJvckNvZGUSCwoHVW5rbm93bhAAEhkKFUVkaXRvckRCSW50ZXJuYWxFcnJvchABEhYKEkVkaXRvckRCQ29ubkZhaWxlZBACEhIKDkRvY05hbWVJbnZhbGlkEAoSFAoQRG9jVmlld0lkSW52YWxpZBALEhIKDkRvY0Rlc2NUb29Mb25nEAwSFAoQRG9jT3BlbkZpbGVFcnJvchANEhYKEkRvY0ZpbGVQYXRoSW52YWxpZBAOEhkKFUVkaXRvclVzZXJOb3RMb2dpbllldBBk'); +@$core.Deprecated('Use editorErrorDescriptor instead') +const EditorError$json = const { + '1': 'EditorError', + '2': const [ + const {'1': 'code', '3': 1, '4': 1, '5': 14, '6': '.EditorErrorCode', '10': 'code'}, + const {'1': 'msg', '3': 2, '4': 1, '5': 9, '10': 'msg'}, + ], +}; + +/// Descriptor for `EditorError`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List editorErrorDescriptor = $convert.base64Decode('CgtFZGl0b3JFcnJvchIkCgRjb2RlGAEgASgOMhAuRWRpdG9yRXJyb3JDb2RlUgRjb2RlEhAKA21zZxgCIAEoCVIDbXNn'); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbserver.dart new file mode 100644 index 0000000000..18b02b9216 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: errors.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +export 'errors.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pb.dart new file mode 100644 index 0000000000..e8db14dba5 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pb.dart @@ -0,0 +1,11 @@ +/// +// Generated code. Do not modify. +// source: event.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +import 'dart:core' as $core; + +export 'event.pbenum.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbenum.dart new file mode 100644 index 0000000000..30f14ebb7f --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbenum.dart @@ -0,0 +1,30 @@ +/// +// Generated code. Do not modify. +// source: event.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +// ignore_for_file: UNDEFINED_SHOWN_NAME +import 'dart:core' as $core; +import 'package:protobuf/protobuf.dart' as $pb; + +class EditorEvent extends $pb.ProtobufEnum { + static const EditorEvent CreateDoc = EditorEvent._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CreateDoc'); + static const EditorEvent UpdateDoc = EditorEvent._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UpdateDoc'); + static const EditorEvent ReadDocInfo = EditorEvent._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ReadDocInfo'); + static const EditorEvent ReadDocData = EditorEvent._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ReadDocData'); + + static const $core.List values = [ + CreateDoc, + UpdateDoc, + ReadDocInfo, + ReadDocData, + ]; + + static final $core.Map<$core.int, EditorEvent> _byValue = $pb.ProtobufEnum.initByValue(values); + static EditorEvent? valueOf($core.int value) => _byValue[value]; + + const EditorEvent._($core.int v, $core.String n) : super(v, n); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbjson.dart new file mode 100644 index 0000000000..a5157d6f8f --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbjson.dart @@ -0,0 +1,23 @@ +/// +// Generated code. Do not modify. +// source: event.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +import 'dart:core' as $core; +import 'dart:convert' as $convert; +import 'dart:typed_data' as $typed_data; +@$core.Deprecated('Use editorEventDescriptor instead') +const EditorEvent$json = const { + '1': 'EditorEvent', + '2': const [ + const {'1': 'CreateDoc', '2': 0}, + const {'1': 'UpdateDoc', '2': 1}, + const {'1': 'ReadDocInfo', '2': 2}, + const {'1': 'ReadDocData', '2': 3}, + ], +}; + +/// Descriptor for `EditorEvent`. Decode as a `google.protobuf.EnumDescriptorProto`. +final $typed_data.Uint8List editorEventDescriptor = $convert.base64Decode('CgtFZGl0b3JFdmVudBINCglDcmVhdGVEb2MQABINCglVcGRhdGVEb2MQARIPCgtSZWFkRG9jSW5mbxACEg8KC1JlYWREb2NEYXRhEAM='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbserver.dart new file mode 100644 index 0000000000..534f858805 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: event.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +export 'event.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/protobuf.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/protobuf.dart new file mode 100644 index 0000000000..5b72739393 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/protobuf.dart @@ -0,0 +1,6 @@ +// Auto-generated, do not edit +export './doc_modify.pb.dart'; +export './doc_create.pb.dart'; +export './errors.pb.dart'; +export './event.pb.dart'; +export './doc_query.pb.dart'; diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/protobuf.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/protobuf.dart new file mode 100644 index 0000000000..6f21b675f3 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/protobuf.dart @@ -0,0 +1,2 @@ +// Auto-generated, do not edit +export './subject.pb.dart'; diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/subject.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/subject.pb.dart new file mode 100644 index 0000000000..fee3f5e319 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/subject.pb.dart @@ -0,0 +1,113 @@ +/// +// Generated code. Do not modify. +// source: subject.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +enum ObservableSubject_OneOfSubjectPayload { + subjectPayload, + notSet +} + +class ObservableSubject extends $pb.GeneratedMessage { + static const $core.Map<$core.int, ObservableSubject_OneOfSubjectPayload> _ObservableSubject_OneOfSubjectPayloadByTag = { + 4 : ObservableSubject_OneOfSubjectPayload.subjectPayload, + 0 : ObservableSubject_OneOfSubjectPayload.notSet + }; + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'ObservableSubject', createEmptyInstance: create) + ..oo(0, [4]) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'category') + ..a<$core.int>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'ty', $pb.PbFieldType.O3) + ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'subjectId') + ..a<$core.List<$core.int>>(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'subjectPayload', $pb.PbFieldType.OY) + ..hasRequiredFields = false + ; + + ObservableSubject._() : super(); + factory ObservableSubject({ + $core.String? category, + $core.int? ty, + $core.String? subjectId, + $core.List<$core.int>? subjectPayload, + }) { + final _result = create(); + if (category != null) { + _result.category = category; + } + if (ty != null) { + _result.ty = ty; + } + if (subjectId != null) { + _result.subjectId = subjectId; + } + if (subjectPayload != null) { + _result.subjectPayload = subjectPayload; + } + return _result; + } + factory ObservableSubject.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory ObservableSubject.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + ObservableSubject clone() => ObservableSubject()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + ObservableSubject copyWith(void Function(ObservableSubject) updates) => super.copyWith((message) => updates(message as ObservableSubject)) as ObservableSubject; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static ObservableSubject create() => ObservableSubject._(); + ObservableSubject createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static ObservableSubject getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static ObservableSubject? _defaultInstance; + + ObservableSubject_OneOfSubjectPayload whichOneOfSubjectPayload() => _ObservableSubject_OneOfSubjectPayloadByTag[$_whichOneof(0)]!; + void clearOneOfSubjectPayload() => clearField($_whichOneof(0)); + + @$pb.TagNumber(1) + $core.String get category => $_getSZ(0); + @$pb.TagNumber(1) + set category($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasCategory() => $_has(0); + @$pb.TagNumber(1) + void clearCategory() => clearField(1); + + @$pb.TagNumber(2) + $core.int get ty => $_getIZ(1); + @$pb.TagNumber(2) + set ty($core.int v) { $_setSignedInt32(1, v); } + @$pb.TagNumber(2) + $core.bool hasTy() => $_has(1); + @$pb.TagNumber(2) + void clearTy() => clearField(2); + + @$pb.TagNumber(3) + $core.String get subjectId => $_getSZ(2); + @$pb.TagNumber(3) + set subjectId($core.String v) { $_setString(2, v); } + @$pb.TagNumber(3) + $core.bool hasSubjectId() => $_has(2); + @$pb.TagNumber(3) + void clearSubjectId() => clearField(3); + + @$pb.TagNumber(4) + $core.List<$core.int> get subjectPayload => $_getN(3); + @$pb.TagNumber(4) + set subjectPayload($core.List<$core.int> v) { $_setBytes(3, v); } + @$pb.TagNumber(4) + $core.bool hasSubjectPayload() => $_has(3); + @$pb.TagNumber(4) + void clearSubjectPayload() => clearField(4); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/subject.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/subject.pbenum.dart new file mode 100644 index 0000000000..7ae7ff12c2 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/subject.pbenum.dart @@ -0,0 +1,7 @@ +/// +// Generated code. Do not modify. +// source: subject.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/subject.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/subject.pbjson.dart new file mode 100644 index 0000000000..d81e160f35 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/subject.pbjson.dart @@ -0,0 +1,26 @@ +/// +// Generated code. Do not modify. +// source: subject.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +import 'dart:core' as $core; +import 'dart:convert' as $convert; +import 'dart:typed_data' as $typed_data; +@$core.Deprecated('Use observableSubjectDescriptor instead') +const ObservableSubject$json = const { + '1': 'ObservableSubject', + '2': const [ + const {'1': 'category', '3': 1, '4': 1, '5': 9, '10': 'category'}, + const {'1': 'ty', '3': 2, '4': 1, '5': 5, '10': 'ty'}, + const {'1': 'subject_id', '3': 3, '4': 1, '5': 9, '10': 'subjectId'}, + const {'1': 'subject_payload', '3': 4, '4': 1, '5': 12, '9': 0, '10': 'subjectPayload'}, + ], + '8': const [ + const {'1': 'one_of_subject_payload'}, + ], +}; + +/// Descriptor for `ObservableSubject`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List observableSubjectDescriptor = $convert.base64Decode('ChFPYnNlcnZhYmxlU3ViamVjdBIaCghjYXRlZ29yeRgBIAEoCVIIY2F0ZWdvcnkSDgoCdHkYAiABKAVSAnR5Eh0KCnN1YmplY3RfaWQYAyABKAlSCXN1YmplY3RJZBIpCg9zdWJqZWN0X3BheWxvYWQYBCABKAxIAFIOc3ViamVjdFBheWxvYWRCGAoWb25lX29mX3N1YmplY3RfcGF5bG9hZA=='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/subject.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/subject.pbserver.dart new file mode 100644 index 0000000000..1e092ab75a --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-observable/subject.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: subject.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +export 'subject.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart index 28205f8984..791039fce8 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart @@ -16,6 +16,7 @@ class UserErrorCode extends $pb.ProtobufEnum { static const UserErrorCode UserDatabaseReadLocked = UserErrorCode._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserDatabaseReadLocked'); static const UserErrorCode UserDatabaseDidNotMatch = UserErrorCode._(4, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserDatabaseDidNotMatch'); static const UserErrorCode UserDatabaseInternalError = UserErrorCode._(5, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserDatabaseInternalError'); + static const UserErrorCode SqlInternalError = UserErrorCode._(6, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'SqlInternalError'); static const UserErrorCode UserNotLoginYet = UserErrorCode._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserNotLoginYet'); static const UserErrorCode ReadCurrentIdFailed = UserErrorCode._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ReadCurrentIdFailed'); static const UserErrorCode WriteCurrentIdFailed = UserErrorCode._(12, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WriteCurrentIdFailed'); @@ -25,6 +26,7 @@ class UserErrorCode extends $pb.ProtobufEnum { static const UserErrorCode UserWorkspaceInvalid = UserErrorCode._(23, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserWorkspaceInvalid'); static const UserErrorCode UserIdInvalid = UserErrorCode._(24, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserIdInvalid'); static const UserErrorCode CreateDefaultWorkspaceFailed = UserErrorCode._(25, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CreateDefaultWorkspaceFailed'); + static const UserErrorCode DefaultWorkspaceAlreadyExist = UserErrorCode._(26, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DefaultWorkspaceAlreadyExist'); static const $core.List values = [ Unknown, @@ -33,6 +35,7 @@ class UserErrorCode extends $pb.ProtobufEnum { UserDatabaseReadLocked, UserDatabaseDidNotMatch, UserDatabaseInternalError, + SqlInternalError, UserNotLoginYet, ReadCurrentIdFailed, WriteCurrentIdFailed, @@ -42,6 +45,7 @@ class UserErrorCode extends $pb.ProtobufEnum { UserWorkspaceInvalid, UserIdInvalid, CreateDefaultWorkspaceFailed, + DefaultWorkspaceAlreadyExist, ]; static final $core.Map<$core.int, UserErrorCode> _byValue = $pb.ProtobufEnum.initByValue(values); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart index 70e80819c6..9625ae9cff 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart @@ -18,6 +18,7 @@ const UserErrorCode$json = const { const {'1': 'UserDatabaseReadLocked', '2': 3}, const {'1': 'UserDatabaseDidNotMatch', '2': 4}, const {'1': 'UserDatabaseInternalError', '2': 5}, + const {'1': 'SqlInternalError', '2': 6}, const {'1': 'UserNotLoginYet', '2': 10}, const {'1': 'ReadCurrentIdFailed', '2': 11}, const {'1': 'WriteCurrentIdFailed', '2': 12}, @@ -27,11 +28,12 @@ const UserErrorCode$json = const { const {'1': 'UserWorkspaceInvalid', '2': 23}, const {'1': 'UserIdInvalid', '2': 24}, const {'1': 'CreateDefaultWorkspaceFailed', '2': 25}, + const {'1': 'DefaultWorkspaceAlreadyExist', '2': 26}, ], }; /// Descriptor for `UserErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List userErrorCodeDescriptor = $convert.base64Decode('Cg1Vc2VyRXJyb3JDb2RlEgsKB1Vua25vd24QABIaChZVc2VyRGF0YWJhc2VJbml0RmFpbGVkEAESGwoXVXNlckRhdGFiYXNlV3JpdGVMb2NrZWQQAhIaChZVc2VyRGF0YWJhc2VSZWFkTG9ja2VkEAMSGwoXVXNlckRhdGFiYXNlRGlkTm90TWF0Y2gQBBIdChlVc2VyRGF0YWJhc2VJbnRlcm5hbEVycm9yEAUSEwoPVXNlck5vdExvZ2luWWV0EAoSFwoTUmVhZEN1cnJlbnRJZEZhaWxlZBALEhgKFFdyaXRlQ3VycmVudElkRmFpbGVkEAwSEAoMRW1haWxJbnZhbGlkEBQSEwoPUGFzc3dvcmRJbnZhbGlkEBUSEwoPVXNlck5hbWVJbnZhbGlkEBYSGAoUVXNlcldvcmtzcGFjZUludmFsaWQQFxIRCg1Vc2VySWRJbnZhbGlkEBgSIAocQ3JlYXRlRGVmYXVsdFdvcmtzcGFjZUZhaWxlZBAZ'); +final $typed_data.Uint8List userErrorCodeDescriptor = $convert.base64Decode('Cg1Vc2VyRXJyb3JDb2RlEgsKB1Vua25vd24QABIaChZVc2VyRGF0YWJhc2VJbml0RmFpbGVkEAESGwoXVXNlckRhdGFiYXNlV3JpdGVMb2NrZWQQAhIaChZVc2VyRGF0YWJhc2VSZWFkTG9ja2VkEAMSGwoXVXNlckRhdGFiYXNlRGlkTm90TWF0Y2gQBBIdChlVc2VyRGF0YWJhc2VJbnRlcm5hbEVycm9yEAUSFAoQU3FsSW50ZXJuYWxFcnJvchAGEhMKD1VzZXJOb3RMb2dpbllldBAKEhcKE1JlYWRDdXJyZW50SWRGYWlsZWQQCxIYChRXcml0ZUN1cnJlbnRJZEZhaWxlZBAMEhAKDEVtYWlsSW52YWxpZBAUEhMKD1Bhc3N3b3JkSW52YWxpZBAVEhMKD1VzZXJOYW1lSW52YWxpZBAWEhgKFFVzZXJXb3Jrc3BhY2VJbnZhbGlkEBcSEQoNVXNlcklkSW52YWxpZBAYEiAKHENyZWF0ZURlZmF1bHRXb3Jrc3BhY2VGYWlsZWQQGRIgChxEZWZhdWx0V29ya3NwYWNlQWxyZWFkeUV4aXN0EBo='); @$core.Deprecated('Use userErrorDescriptor instead') const UserError$json = const { '1': 'UserError', diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pb.dart index fdb1ac1482..2788f32ed6 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pb.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pb.dart @@ -9,6 +9,8 @@ import 'dart:core' as $core; import 'package:protobuf/protobuf.dart' as $pb; +import 'view_create.pb.dart' as $0; + class CreateAppRequest extends $pb.GeneratedMessage { static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'CreateAppRequest', createEmptyInstance: create) ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'workspaceId') @@ -153,6 +155,7 @@ class App extends $pb.GeneratedMessage { ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'workspaceId') ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') ..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc') + ..aOM<$0.RepeatedView>(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'views', subBuilder: $0.RepeatedView.create) ..hasRequiredFields = false ; @@ -162,6 +165,7 @@ class App extends $pb.GeneratedMessage { $core.String? workspaceId, $core.String? name, $core.String? desc, + $0.RepeatedView? views, }) { final _result = create(); if (id != null) { @@ -176,6 +180,9 @@ class App extends $pb.GeneratedMessage { if (desc != null) { _result.desc = desc; } + if (views != null) { + _result.views = views; + } return _result; } factory App.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); @@ -234,5 +241,57 @@ class App extends $pb.GeneratedMessage { $core.bool hasDesc() => $_has(3); @$pb.TagNumber(4) void clearDesc() => clearField(4); + + @$pb.TagNumber(5) + $0.RepeatedView get views => $_getN(4); + @$pb.TagNumber(5) + set views($0.RepeatedView v) { setField(5, v); } + @$pb.TagNumber(5) + $core.bool hasViews() => $_has(4); + @$pb.TagNumber(5) + void clearViews() => clearField(5); + @$pb.TagNumber(5) + $0.RepeatedView ensureViews() => $_ensure(4); +} + +class RepeatedApp extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'RepeatedApp', createEmptyInstance: create) + ..pc(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'items', $pb.PbFieldType.PM, subBuilder: App.create) + ..hasRequiredFields = false + ; + + RepeatedApp._() : super(); + factory RepeatedApp({ + $core.Iterable? items, + }) { + final _result = create(); + if (items != null) { + _result.items.addAll(items); + } + return _result; + } + factory RepeatedApp.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory RepeatedApp.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + RepeatedApp clone() => RepeatedApp()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + RepeatedApp copyWith(void Function(RepeatedApp) updates) => super.copyWith((message) => updates(message as RepeatedApp)) as RepeatedApp; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static RepeatedApp create() => RepeatedApp._(); + RepeatedApp createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static RepeatedApp getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static RepeatedApp? _defaultInstance; + + @$pb.TagNumber(1) + $core.List get items => $_getList(0); } diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbjson.dart index 46e4b0b849..41fbce779a 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbjson.dart @@ -39,8 +39,19 @@ const App$json = const { const {'1': 'workspace_id', '3': 2, '4': 1, '5': 9, '10': 'workspaceId'}, const {'1': 'name', '3': 3, '4': 1, '5': 9, '10': 'name'}, const {'1': 'desc', '3': 4, '4': 1, '5': 9, '10': 'desc'}, + const {'1': 'views', '3': 5, '4': 1, '5': 11, '6': '.RepeatedView', '10': 'views'}, ], }; /// Descriptor for `App`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List appDescriptor = $convert.base64Decode('CgNBcHASDgoCaWQYASABKAlSAmlkEiEKDHdvcmtzcGFjZV9pZBgCIAEoCVILd29ya3NwYWNlSWQSEgoEbmFtZRgDIAEoCVIEbmFtZRISCgRkZXNjGAQgASgJUgRkZXNj'); +final $typed_data.Uint8List appDescriptor = $convert.base64Decode('CgNBcHASDgoCaWQYASABKAlSAmlkEiEKDHdvcmtzcGFjZV9pZBgCIAEoCVILd29ya3NwYWNlSWQSEgoEbmFtZRgDIAEoCVIEbmFtZRISCgRkZXNjGAQgASgJUgRkZXNjEiMKBXZpZXdzGAUgASgLMg0uUmVwZWF0ZWRWaWV3UgV2aWV3cw=='); +@$core.Deprecated('Use repeatedAppDescriptor instead') +const RepeatedApp$json = const { + '1': 'RepeatedApp', + '2': const [ + const {'1': 'items', '3': 1, '4': 3, '5': 11, '6': '.App', '10': 'items'}, + ], +}; + +/// Descriptor for `RepeatedApp`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List repeatedAppDescriptor = $convert.base64Decode('CgtSZXBlYXRlZEFwcBIaCgVpdGVtcxgBIAMoCzIELkFwcFIFaXRlbXM='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_query.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_query.pb.dart new file mode 100644 index 0000000000..dbe560351b --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_query.pb.dart @@ -0,0 +1,72 @@ +/// +// Generated code. Do not modify. +// source: app_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +class QueryAppRequest extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'QueryAppRequest', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'appId') + ..aOB(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'readViews') + ..hasRequiredFields = false + ; + + QueryAppRequest._() : super(); + factory QueryAppRequest({ + $core.String? appId, + $core.bool? readViews, + }) { + final _result = create(); + if (appId != null) { + _result.appId = appId; + } + if (readViews != null) { + _result.readViews = readViews; + } + return _result; + } + factory QueryAppRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory QueryAppRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + QueryAppRequest clone() => QueryAppRequest()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + QueryAppRequest copyWith(void Function(QueryAppRequest) updates) => super.copyWith((message) => updates(message as QueryAppRequest)) as QueryAppRequest; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static QueryAppRequest create() => QueryAppRequest._(); + QueryAppRequest createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static QueryAppRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static QueryAppRequest? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get appId => $_getSZ(0); + @$pb.TagNumber(1) + set appId($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasAppId() => $_has(0); + @$pb.TagNumber(1) + void clearAppId() => clearField(1); + + @$pb.TagNumber(2) + $core.bool get readViews => $_getBF(1); + @$pb.TagNumber(2) + set readViews($core.bool v) { $_setBool(1, v); } + @$pb.TagNumber(2) + $core.bool hasReadViews() => $_has(1); + @$pb.TagNumber(2) + void clearReadViews() => clearField(2); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_query.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_query.pbenum.dart new file mode 100644 index 0000000000..b22bc4dbed --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_query.pbenum.dart @@ -0,0 +1,7 @@ +/// +// Generated code. Do not modify. +// source: app_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_query.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_query.pbjson.dart new file mode 100644 index 0000000000..8fd192ea59 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_query.pbjson.dart @@ -0,0 +1,21 @@ +/// +// Generated code. Do not modify. +// source: app_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +import 'dart:core' as $core; +import 'dart:convert' as $convert; +import 'dart:typed_data' as $typed_data; +@$core.Deprecated('Use queryAppRequestDescriptor instead') +const QueryAppRequest$json = const { + '1': 'QueryAppRequest', + '2': const [ + const {'1': 'app_id', '3': 1, '4': 1, '5': 9, '10': 'appId'}, + const {'1': 'read_views', '3': 2, '4': 1, '5': 8, '10': 'readViews'}, + ], +}; + +/// Descriptor for `QueryAppRequest`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List queryAppRequestDescriptor = $convert.base64Decode('Cg9RdWVyeUFwcFJlcXVlc3QSFQoGYXBwX2lkGAEgASgJUgVhcHBJZBIdCgpyZWFkX3ZpZXdzGAIgASgIUglyZWFkVmlld3M='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_query.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_query.pbserver.dart new file mode 100644 index 0000000000..37a06ce563 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_query.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: app_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +export 'app_query.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbenum.dart index ede6d2aa55..156f16249b 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbenum.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbenum.dart @@ -17,7 +17,9 @@ class WorkspaceErrorCode extends $pb.ProtobufEnum { static const WorkspaceErrorCode AppIdInvalid = WorkspaceErrorCode._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppIdInvalid'); static const WorkspaceErrorCode AppNameInvalid = WorkspaceErrorCode._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppNameInvalid'); static const WorkspaceErrorCode ViewNameInvalid = WorkspaceErrorCode._(20, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewNameInvalid'); - static const WorkspaceErrorCode ViewThumbnailName = WorkspaceErrorCode._(21, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewThumbnailName'); + static const WorkspaceErrorCode ViewThumbnailInvalid = WorkspaceErrorCode._(21, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewThumbnailInvalid'); + static const WorkspaceErrorCode ViewIdInvalid = WorkspaceErrorCode._(22, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewIdInvalid'); + static const WorkspaceErrorCode ViewDescInvalid = WorkspaceErrorCode._(23, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewDescInvalid'); static const WorkspaceErrorCode DatabaseConnectionFail = WorkspaceErrorCode._(100, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DatabaseConnectionFail'); static const WorkspaceErrorCode WorkspaceDatabaseError = WorkspaceErrorCode._(101, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceDatabaseError'); static const WorkspaceErrorCode UserInternalError = WorkspaceErrorCode._(102, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserInternalError'); @@ -31,7 +33,9 @@ class WorkspaceErrorCode extends $pb.ProtobufEnum { AppIdInvalid, AppNameInvalid, ViewNameInvalid, - ViewThumbnailName, + ViewThumbnailInvalid, + ViewIdInvalid, + ViewDescInvalid, DatabaseConnectionFail, WorkspaceDatabaseError, UserInternalError, diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbjson.dart index 1dd3186d24..54591696e9 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbjson.dart @@ -19,7 +19,9 @@ const WorkspaceErrorCode$json = const { const {'1': 'AppIdInvalid', '2': 10}, const {'1': 'AppNameInvalid', '2': 11}, const {'1': 'ViewNameInvalid', '2': 20}, - const {'1': 'ViewThumbnailName', '2': 21}, + const {'1': 'ViewThumbnailInvalid', '2': 21}, + const {'1': 'ViewIdInvalid', '2': 22}, + const {'1': 'ViewDescInvalid', '2': 23}, const {'1': 'DatabaseConnectionFail', '2': 100}, const {'1': 'WorkspaceDatabaseError', '2': 101}, const {'1': 'UserInternalError', '2': 102}, @@ -28,7 +30,7 @@ const WorkspaceErrorCode$json = const { }; /// Descriptor for `WorkspaceErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List workspaceErrorCodeDescriptor = $convert.base64Decode('ChJXb3Jrc3BhY2VFcnJvckNvZGUSCwoHVW5rbm93bhAAEhgKFFdvcmtzcGFjZU5hbWVJbnZhbGlkEAESFgoSV29ya3NwYWNlSWRJbnZhbGlkEAISGAoUQXBwQ29sb3JTdHlsZUludmFsaWQQAxIQCgxBcHBJZEludmFsaWQQChISCg5BcHBOYW1lSW52YWxpZBALEhMKD1ZpZXdOYW1lSW52YWxpZBAUEhUKEVZpZXdUaHVtYm5haWxOYW1lEBUSGgoWRGF0YWJhc2VDb25uZWN0aW9uRmFpbBBkEhoKFldvcmtzcGFjZURhdGFiYXNlRXJyb3IQZRIVChFVc2VySW50ZXJuYWxFcnJvchBmEhMKD1VzZXJOb3RMb2dpbllldBBn'); +final $typed_data.Uint8List workspaceErrorCodeDescriptor = $convert.base64Decode('ChJXb3Jrc3BhY2VFcnJvckNvZGUSCwoHVW5rbm93bhAAEhgKFFdvcmtzcGFjZU5hbWVJbnZhbGlkEAESFgoSV29ya3NwYWNlSWRJbnZhbGlkEAISGAoUQXBwQ29sb3JTdHlsZUludmFsaWQQAxIQCgxBcHBJZEludmFsaWQQChISCg5BcHBOYW1lSW52YWxpZBALEhMKD1ZpZXdOYW1lSW52YWxpZBAUEhgKFFZpZXdUaHVtYm5haWxJbnZhbGlkEBUSEQoNVmlld0lkSW52YWxpZBAWEhMKD1ZpZXdEZXNjSW52YWxpZBAXEhoKFkRhdGFiYXNlQ29ubmVjdGlvbkZhaWwQZBIaChZXb3Jrc3BhY2VEYXRhYmFzZUVycm9yEGUSFQoRVXNlckludGVybmFsRXJyb3IQZhITCg9Vc2VyTm90TG9naW5ZZXQQZw=='); @$core.Deprecated('Use workspaceErrorDescriptor instead') const WorkspaceError$json = const { '1': 'WorkspaceError', diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/event.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/event.pbenum.dart index 08cec09e19..d76368c696 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/event.pbenum.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/event.pbenum.dart @@ -11,15 +11,23 @@ import 'package:protobuf/protobuf.dart' as $pb; class WorkspaceEvent extends $pb.ProtobufEnum { static const WorkspaceEvent CreateWorkspace = WorkspaceEvent._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CreateWorkspace'); - static const WorkspaceEvent GetWorkspaceDetail = WorkspaceEvent._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'GetWorkspaceDetail'); + static const WorkspaceEvent GetCurWorkspace = WorkspaceEvent._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'GetCurWorkspace'); + static const WorkspaceEvent GetWorkspace = WorkspaceEvent._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'GetWorkspace'); static const WorkspaceEvent CreateApp = WorkspaceEvent._(101, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CreateApp'); + static const WorkspaceEvent GetApp = WorkspaceEvent._(102, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'GetApp'); static const WorkspaceEvent CreateView = WorkspaceEvent._(201, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CreateView'); + static const WorkspaceEvent ReadView = WorkspaceEvent._(202, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ReadView'); + static const WorkspaceEvent UpdateView = WorkspaceEvent._(203, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UpdateView'); static const $core.List values = [ CreateWorkspace, - GetWorkspaceDetail, + GetCurWorkspace, + GetWorkspace, CreateApp, + GetApp, CreateView, + ReadView, + UpdateView, ]; static final $core.Map<$core.int, WorkspaceEvent> _byValue = $pb.ProtobufEnum.initByValue(values); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/event.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/event.pbjson.dart index b7cdc7c7d0..e03a64e771 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/event.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/event.pbjson.dart @@ -13,11 +13,15 @@ const WorkspaceEvent$json = const { '1': 'WorkspaceEvent', '2': const [ const {'1': 'CreateWorkspace', '2': 0}, - const {'1': 'GetWorkspaceDetail', '2': 1}, + const {'1': 'GetCurWorkspace', '2': 1}, + const {'1': 'GetWorkspace', '2': 2}, const {'1': 'CreateApp', '2': 101}, + const {'1': 'GetApp', '2': 102}, const {'1': 'CreateView', '2': 201}, + const {'1': 'ReadView', '2': 202}, + const {'1': 'UpdateView', '2': 203}, ], }; /// Descriptor for `WorkspaceEvent`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List workspaceEventDescriptor = $convert.base64Decode('Cg5Xb3Jrc3BhY2VFdmVudBITCg9DcmVhdGVXb3Jrc3BhY2UQABIWChJHZXRXb3Jrc3BhY2VEZXRhaWwQARINCglDcmVhdGVBcHAQZRIPCgpDcmVhdGVWaWV3EMkB'); +final $typed_data.Uint8List workspaceEventDescriptor = $convert.base64Decode('Cg5Xb3Jrc3BhY2VFdmVudBITCg9DcmVhdGVXb3Jrc3BhY2UQABITCg9HZXRDdXJXb3Jrc3BhY2UQARIQCgxHZXRXb3Jrc3BhY2UQAhINCglDcmVhdGVBcHAQZRIKCgZHZXRBcHAQZhIPCgpDcmVhdGVWaWV3EMkBEg0KCFJlYWRWaWV3EMoBEg8KClVwZGF0ZVZpZXcQywE='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pb.dart new file mode 100644 index 0000000000..f1a6d9fcdb --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pb.dart @@ -0,0 +1,11 @@ +/// +// Generated code. Do not modify. +// source: observable.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +import 'dart:core' as $core; + +export 'observable.pbenum.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbenum.dart new file mode 100644 index 0000000000..5a73da2f00 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbenum.dart @@ -0,0 +1,34 @@ +/// +// Generated code. Do not modify. +// source: observable.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +// ignore_for_file: UNDEFINED_SHOWN_NAME +import 'dart:core' as $core; +import 'package:protobuf/protobuf.dart' as $pb; + +class WorkspaceObservable extends $pb.ProtobufEnum { + static const WorkspaceObservable Unknown = WorkspaceObservable._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown'); + static const WorkspaceObservable WorkspaceUpdateDesc = WorkspaceObservable._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceUpdateDesc'); + static const WorkspaceObservable WorkspaceAddApp = WorkspaceObservable._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceAddApp'); + static const WorkspaceObservable AppUpdateDesc = WorkspaceObservable._(20, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppUpdateDesc'); + static const WorkspaceObservable AppAddView = WorkspaceObservable._(21, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppAddView'); + static const WorkspaceObservable ViewUpdateDesc = WorkspaceObservable._(30, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewUpdateDesc'); + + static const $core.List values = [ + Unknown, + WorkspaceUpdateDesc, + WorkspaceAddApp, + AppUpdateDesc, + AppAddView, + ViewUpdateDesc, + ]; + + static final $core.Map<$core.int, WorkspaceObservable> _byValue = $pb.ProtobufEnum.initByValue(values); + static WorkspaceObservable? valueOf($core.int value) => _byValue[value]; + + const WorkspaceObservable._($core.int v, $core.String n) : super(v, n); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbjson.dart new file mode 100644 index 0000000000..d9d9cc02a8 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbjson.dart @@ -0,0 +1,25 @@ +/// +// Generated code. Do not modify. +// source: observable.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +import 'dart:core' as $core; +import 'dart:convert' as $convert; +import 'dart:typed_data' as $typed_data; +@$core.Deprecated('Use workspaceObservableDescriptor instead') +const WorkspaceObservable$json = const { + '1': 'WorkspaceObservable', + '2': const [ + const {'1': 'Unknown', '2': 0}, + const {'1': 'WorkspaceUpdateDesc', '2': 10}, + const {'1': 'WorkspaceAddApp', '2': 11}, + const {'1': 'AppUpdateDesc', '2': 20}, + const {'1': 'AppAddView', '2': 21}, + const {'1': 'ViewUpdateDesc', '2': 30}, + ], +}; + +/// Descriptor for `WorkspaceObservable`. Decode as a `google.protobuf.EnumDescriptorProto`. +final $typed_data.Uint8List workspaceObservableDescriptor = $convert.base64Decode('ChNXb3Jrc3BhY2VPYnNlcnZhYmxlEgsKB1Vua25vd24QABIXChNXb3Jrc3BhY2VVcGRhdGVEZXNjEAoSEwoPV29ya3NwYWNlQWRkQXBwEAsSEQoNQXBwVXBkYXRlRGVzYxAUEg4KCkFwcEFkZFZpZXcQFRISCg5WaWV3VXBkYXRlRGVzYxAe'); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbserver.dart new file mode 100644 index 0000000000..d0e7d97b5d --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: observable.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +export 'observable.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/protobuf.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/protobuf.dart index cf45ec07ad..c033d8a24a 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/protobuf.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/protobuf.dart @@ -1,9 +1,14 @@ // Auto-generated, do not edit +export './view_update.pb.dart'; +export './app_query.pb.dart'; +export './observable.pb.dart'; export './errors.pb.dart'; export './workspace_update.pb.dart'; export './app_create.pb.dart'; +export './workspace_query.pb.dart'; export './event.pb.dart'; export './view_create.pb.dart'; export './workspace_user_detail.pb.dart'; export './workspace_create.pb.dart'; export './app_update.pb.dart'; +export './view_query.pb.dart'; diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_create.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_create.pb.dart index 82f7d3a17d..208da2c0b4 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_create.pb.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_create.pb.dart @@ -29,7 +29,7 @@ class CreateViewRequest extends $pb.GeneratedMessage { ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc') ..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'thumbnail') - ..e(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'viewType', $pb.PbFieldType.OE, defaultOrMaker: ViewTypeIdentifier.Docs, valueOf: ViewTypeIdentifier.valueOf, enumValues: ViewTypeIdentifier.values) + ..e(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'viewType', $pb.PbFieldType.OE, defaultOrMaker: ViewType.Blank, valueOf: ViewType.valueOf, enumValues: ViewType.values) ..hasRequiredFields = false ; @@ -39,7 +39,7 @@ class CreateViewRequest extends $pb.GeneratedMessage { $core.String? name, $core.String? desc, $core.String? thumbnail, - ViewTypeIdentifier? viewType, + ViewType? viewType, }) { final _result = create(); if (appId != null) { @@ -120,9 +120,9 @@ class CreateViewRequest extends $pb.GeneratedMessage { void clearThumbnail() => clearField(4); @$pb.TagNumber(5) - ViewTypeIdentifier get viewType => $_getN(4); + ViewType get viewType => $_getN(4); @$pb.TagNumber(5) - set viewType(ViewTypeIdentifier v) { setField(5, v); } + set viewType(ViewType v) { setField(5, v); } @$pb.TagNumber(5) $core.bool hasViewType() => $_has(4); @$pb.TagNumber(5) @@ -135,7 +135,7 @@ class View extends $pb.GeneratedMessage { ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'appId') ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') ..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc') - ..e(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'viewType', $pb.PbFieldType.OE, defaultOrMaker: ViewTypeIdentifier.Docs, valueOf: ViewTypeIdentifier.valueOf, enumValues: ViewTypeIdentifier.values) + ..e(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'viewType', $pb.PbFieldType.OE, defaultOrMaker: ViewType.Blank, valueOf: ViewType.valueOf, enumValues: ViewType.values) ..hasRequiredFields = false ; @@ -145,7 +145,7 @@ class View extends $pb.GeneratedMessage { $core.String? appId, $core.String? name, $core.String? desc, - ViewTypeIdentifier? viewType, + ViewType? viewType, }) { final _result = create(); if (id != null) { @@ -223,12 +223,53 @@ class View extends $pb.GeneratedMessage { void clearDesc() => clearField(4); @$pb.TagNumber(5) - ViewTypeIdentifier get viewType => $_getN(4); + ViewType get viewType => $_getN(4); @$pb.TagNumber(5) - set viewType(ViewTypeIdentifier v) { setField(5, v); } + set viewType(ViewType v) { setField(5, v); } @$pb.TagNumber(5) $core.bool hasViewType() => $_has(4); @$pb.TagNumber(5) void clearViewType() => clearField(5); } +class RepeatedView extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'RepeatedView', createEmptyInstance: create) + ..pc(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'items', $pb.PbFieldType.PM, subBuilder: View.create) + ..hasRequiredFields = false + ; + + RepeatedView._() : super(); + factory RepeatedView({ + $core.Iterable? items, + }) { + final _result = create(); + if (items != null) { + _result.items.addAll(items); + } + return _result; + } + factory RepeatedView.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory RepeatedView.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + RepeatedView clone() => RepeatedView()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + RepeatedView copyWith(void Function(RepeatedView) updates) => super.copyWith((message) => updates(message as RepeatedView)) as RepeatedView; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static RepeatedView create() => RepeatedView._(); + RepeatedView createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static RepeatedView getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static RepeatedView? _defaultInstance; + + @$pb.TagNumber(1) + $core.List get items => $_getList(0); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_create.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_create.pbenum.dart index a685816a29..790a0bd3d1 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_create.pbenum.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_create.pbenum.dart @@ -9,16 +9,18 @@ import 'dart:core' as $core; import 'package:protobuf/protobuf.dart' as $pb; -class ViewTypeIdentifier extends $pb.ProtobufEnum { - static const ViewTypeIdentifier Docs = ViewTypeIdentifier._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Docs'); +class ViewType extends $pb.ProtobufEnum { + static const ViewType Blank = ViewType._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Blank'); + static const ViewType Doc = ViewType._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Doc'); - static const $core.List values = [ - Docs, + static const $core.List values = [ + Blank, + Doc, ]; - static final $core.Map<$core.int, ViewTypeIdentifier> _byValue = $pb.ProtobufEnum.initByValue(values); - static ViewTypeIdentifier? valueOf($core.int value) => _byValue[value]; + static final $core.Map<$core.int, ViewType> _byValue = $pb.ProtobufEnum.initByValue(values); + static ViewType? valueOf($core.int value) => _byValue[value]; - const ViewTypeIdentifier._($core.int v, $core.String n) : super(v, n); + const ViewType._($core.int v, $core.String n) : super(v, n); } diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_create.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_create.pbjson.dart index c17dd1699e..acb1a48392 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_create.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_create.pbjson.dart @@ -8,16 +8,17 @@ import 'dart:core' as $core; import 'dart:convert' as $convert; import 'dart:typed_data' as $typed_data; -@$core.Deprecated('Use viewTypeIdentifierDescriptor instead') -const ViewTypeIdentifier$json = const { - '1': 'ViewTypeIdentifier', +@$core.Deprecated('Use viewTypeDescriptor instead') +const ViewType$json = const { + '1': 'ViewType', '2': const [ - const {'1': 'Docs', '2': 0}, + const {'1': 'Blank', '2': 0}, + const {'1': 'Doc', '2': 1}, ], }; -/// Descriptor for `ViewTypeIdentifier`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List viewTypeIdentifierDescriptor = $convert.base64Decode('ChJWaWV3VHlwZUlkZW50aWZpZXISCAoERG9jcxAA'); +/// Descriptor for `ViewType`. Decode as a `google.protobuf.EnumDescriptorProto`. +final $typed_data.Uint8List viewTypeDescriptor = $convert.base64Decode('CghWaWV3VHlwZRIJCgVCbGFuaxAAEgcKA0RvYxAB'); @$core.Deprecated('Use createViewRequestDescriptor instead') const CreateViewRequest$json = const { '1': 'CreateViewRequest', @@ -26,7 +27,7 @@ const CreateViewRequest$json = const { const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'}, const {'1': 'desc', '3': 3, '4': 1, '5': 9, '10': 'desc'}, const {'1': 'thumbnail', '3': 4, '4': 1, '5': 9, '9': 0, '10': 'thumbnail'}, - const {'1': 'view_type', '3': 5, '4': 1, '5': 14, '6': '.ViewTypeIdentifier', '10': 'viewType'}, + const {'1': 'view_type', '3': 5, '4': 1, '5': 14, '6': '.ViewType', '10': 'viewType'}, ], '8': const [ const {'1': 'one_of_thumbnail'}, @@ -34,7 +35,7 @@ const CreateViewRequest$json = const { }; /// Descriptor for `CreateViewRequest`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List createViewRequestDescriptor = $convert.base64Decode('ChFDcmVhdGVWaWV3UmVxdWVzdBIVCgZhcHBfaWQYASABKAlSBWFwcElkEhIKBG5hbWUYAiABKAlSBG5hbWUSEgoEZGVzYxgDIAEoCVIEZGVzYxIeCgl0aHVtYm5haWwYBCABKAlIAFIJdGh1bWJuYWlsEjAKCXZpZXdfdHlwZRgFIAEoDjITLlZpZXdUeXBlSWRlbnRpZmllclIIdmlld1R5cGVCEgoQb25lX29mX3RodW1ibmFpbA=='); +final $typed_data.Uint8List createViewRequestDescriptor = $convert.base64Decode('ChFDcmVhdGVWaWV3UmVxdWVzdBIVCgZhcHBfaWQYASABKAlSBWFwcElkEhIKBG5hbWUYAiABKAlSBG5hbWUSEgoEZGVzYxgDIAEoCVIEZGVzYxIeCgl0aHVtYm5haWwYBCABKAlIAFIJdGh1bWJuYWlsEiYKCXZpZXdfdHlwZRgFIAEoDjIJLlZpZXdUeXBlUgh2aWV3VHlwZUISChBvbmVfb2ZfdGh1bWJuYWls'); @$core.Deprecated('Use viewDescriptor instead') const View$json = const { '1': 'View', @@ -43,9 +44,19 @@ const View$json = const { const {'1': 'app_id', '3': 2, '4': 1, '5': 9, '10': 'appId'}, const {'1': 'name', '3': 3, '4': 1, '5': 9, '10': 'name'}, const {'1': 'desc', '3': 4, '4': 1, '5': 9, '10': 'desc'}, - const {'1': 'view_type', '3': 5, '4': 1, '5': 14, '6': '.ViewTypeIdentifier', '10': 'viewType'}, + const {'1': 'view_type', '3': 5, '4': 1, '5': 14, '6': '.ViewType', '10': 'viewType'}, ], }; /// Descriptor for `View`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List viewDescriptor = $convert.base64Decode('CgRWaWV3Eg4KAmlkGAEgASgJUgJpZBIVCgZhcHBfaWQYAiABKAlSBWFwcElkEhIKBG5hbWUYAyABKAlSBG5hbWUSEgoEZGVzYxgEIAEoCVIEZGVzYxIwCgl2aWV3X3R5cGUYBSABKA4yEy5WaWV3VHlwZUlkZW50aWZpZXJSCHZpZXdUeXBl'); +final $typed_data.Uint8List viewDescriptor = $convert.base64Decode('CgRWaWV3Eg4KAmlkGAEgASgJUgJpZBIVCgZhcHBfaWQYAiABKAlSBWFwcElkEhIKBG5hbWUYAyABKAlSBG5hbWUSEgoEZGVzYxgEIAEoCVIEZGVzYxImCgl2aWV3X3R5cGUYBSABKA4yCS5WaWV3VHlwZVIIdmlld1R5cGU='); +@$core.Deprecated('Use repeatedViewDescriptor instead') +const RepeatedView$json = const { + '1': 'RepeatedView', + '2': const [ + const {'1': 'items', '3': 1, '4': 3, '5': 11, '6': '.View', '10': 'items'}, + ], +}; + +/// Descriptor for `RepeatedView`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List repeatedViewDescriptor = $convert.base64Decode('CgxSZXBlYXRlZFZpZXcSGwoFaXRlbXMYASADKAsyBS5WaWV3UgVpdGVtcw=='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_query.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_query.pb.dart new file mode 100644 index 0000000000..63c576064c --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_query.pb.dart @@ -0,0 +1,58 @@ +/// +// Generated code. Do not modify. +// source: view_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +class QueryViewRequest extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'QueryViewRequest', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'viewId') + ..hasRequiredFields = false + ; + + QueryViewRequest._() : super(); + factory QueryViewRequest({ + $core.String? viewId, + }) { + final _result = create(); + if (viewId != null) { + _result.viewId = viewId; + } + return _result; + } + factory QueryViewRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory QueryViewRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + QueryViewRequest clone() => QueryViewRequest()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + QueryViewRequest copyWith(void Function(QueryViewRequest) updates) => super.copyWith((message) => updates(message as QueryViewRequest)) as QueryViewRequest; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static QueryViewRequest create() => QueryViewRequest._(); + QueryViewRequest createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static QueryViewRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static QueryViewRequest? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get viewId => $_getSZ(0); + @$pb.TagNumber(1) + set viewId($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasViewId() => $_has(0); + @$pb.TagNumber(1) + void clearViewId() => clearField(1); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_query.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_query.pbenum.dart new file mode 100644 index 0000000000..4cb16cfd45 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_query.pbenum.dart @@ -0,0 +1,7 @@ +/// +// Generated code. Do not modify. +// source: view_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_query.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_query.pbjson.dart new file mode 100644 index 0000000000..7dcc47e03b --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_query.pbjson.dart @@ -0,0 +1,20 @@ +/// +// Generated code. Do not modify. +// source: view_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +import 'dart:core' as $core; +import 'dart:convert' as $convert; +import 'dart:typed_data' as $typed_data; +@$core.Deprecated('Use queryViewRequestDescriptor instead') +const QueryViewRequest$json = const { + '1': 'QueryViewRequest', + '2': const [ + const {'1': 'view_id', '3': 1, '4': 1, '5': 9, '10': 'viewId'}, + ], +}; + +/// Descriptor for `QueryViewRequest`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List queryViewRequestDescriptor = $convert.base64Decode('ChBRdWVyeVZpZXdSZXF1ZXN0EhcKB3ZpZXdfaWQYASABKAlSBnZpZXdJZA=='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_query.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_query.pbserver.dart new file mode 100644 index 0000000000..e57b4ae5ce --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_query.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: view_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +export 'view_query.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_update.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_update.pb.dart new file mode 100644 index 0000000000..5ce9d627eb --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_update.pb.dart @@ -0,0 +1,139 @@ +/// +// Generated code. Do not modify. +// source: view_update.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +enum UpdateViewRequest_OneOfName { + name, + notSet +} + +enum UpdateViewRequest_OneOfDesc { + desc, + notSet +} + +enum UpdateViewRequest_OneOfThumbnail { + thumbnail, + notSet +} + +class UpdateViewRequest extends $pb.GeneratedMessage { + static const $core.Map<$core.int, UpdateViewRequest_OneOfName> _UpdateViewRequest_OneOfNameByTag = { + 2 : UpdateViewRequest_OneOfName.name, + 0 : UpdateViewRequest_OneOfName.notSet + }; + static const $core.Map<$core.int, UpdateViewRequest_OneOfDesc> _UpdateViewRequest_OneOfDescByTag = { + 3 : UpdateViewRequest_OneOfDesc.desc, + 0 : UpdateViewRequest_OneOfDesc.notSet + }; + static const $core.Map<$core.int, UpdateViewRequest_OneOfThumbnail> _UpdateViewRequest_OneOfThumbnailByTag = { + 4 : UpdateViewRequest_OneOfThumbnail.thumbnail, + 0 : UpdateViewRequest_OneOfThumbnail.notSet + }; + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UpdateViewRequest', createEmptyInstance: create) + ..oo(0, [2]) + ..oo(1, [3]) + ..oo(2, [4]) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'viewId') + ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') + ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc') + ..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'thumbnail') + ..hasRequiredFields = false + ; + + UpdateViewRequest._() : super(); + factory UpdateViewRequest({ + $core.String? viewId, + $core.String? name, + $core.String? desc, + $core.String? thumbnail, + }) { + final _result = create(); + if (viewId != null) { + _result.viewId = viewId; + } + if (name != null) { + _result.name = name; + } + if (desc != null) { + _result.desc = desc; + } + if (thumbnail != null) { + _result.thumbnail = thumbnail; + } + return _result; + } + factory UpdateViewRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory UpdateViewRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + UpdateViewRequest clone() => UpdateViewRequest()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + UpdateViewRequest copyWith(void Function(UpdateViewRequest) updates) => super.copyWith((message) => updates(message as UpdateViewRequest)) as UpdateViewRequest; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static UpdateViewRequest create() => UpdateViewRequest._(); + UpdateViewRequest createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static UpdateViewRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static UpdateViewRequest? _defaultInstance; + + UpdateViewRequest_OneOfName whichOneOfName() => _UpdateViewRequest_OneOfNameByTag[$_whichOneof(0)]!; + void clearOneOfName() => clearField($_whichOneof(0)); + + UpdateViewRequest_OneOfDesc whichOneOfDesc() => _UpdateViewRequest_OneOfDescByTag[$_whichOneof(1)]!; + void clearOneOfDesc() => clearField($_whichOneof(1)); + + UpdateViewRequest_OneOfThumbnail whichOneOfThumbnail() => _UpdateViewRequest_OneOfThumbnailByTag[$_whichOneof(2)]!; + void clearOneOfThumbnail() => clearField($_whichOneof(2)); + + @$pb.TagNumber(1) + $core.String get viewId => $_getSZ(0); + @$pb.TagNumber(1) + set viewId($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasViewId() => $_has(0); + @$pb.TagNumber(1) + void clearViewId() => clearField(1); + + @$pb.TagNumber(2) + $core.String get name => $_getSZ(1); + @$pb.TagNumber(2) + set name($core.String v) { $_setString(1, v); } + @$pb.TagNumber(2) + $core.bool hasName() => $_has(1); + @$pb.TagNumber(2) + void clearName() => clearField(2); + + @$pb.TagNumber(3) + $core.String get desc => $_getSZ(2); + @$pb.TagNumber(3) + set desc($core.String v) { $_setString(2, v); } + @$pb.TagNumber(3) + $core.bool hasDesc() => $_has(2); + @$pb.TagNumber(3) + void clearDesc() => clearField(3); + + @$pb.TagNumber(4) + $core.String get thumbnail => $_getSZ(3); + @$pb.TagNumber(4) + set thumbnail($core.String v) { $_setString(3, v); } + @$pb.TagNumber(4) + $core.bool hasThumbnail() => $_has(3); + @$pb.TagNumber(4) + void clearThumbnail() => clearField(4); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_update.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_update.pbenum.dart new file mode 100644 index 0000000000..490fe8aa67 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_update.pbenum.dart @@ -0,0 +1,7 @@ +/// +// Generated code. Do not modify. +// source: view_update.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_update.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_update.pbjson.dart new file mode 100644 index 0000000000..6a9db1bb06 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_update.pbjson.dart @@ -0,0 +1,28 @@ +/// +// Generated code. Do not modify. +// source: view_update.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +import 'dart:core' as $core; +import 'dart:convert' as $convert; +import 'dart:typed_data' as $typed_data; +@$core.Deprecated('Use updateViewRequestDescriptor instead') +const UpdateViewRequest$json = const { + '1': 'UpdateViewRequest', + '2': const [ + const {'1': 'view_id', '3': 1, '4': 1, '5': 9, '10': 'viewId'}, + const {'1': 'name', '3': 2, '4': 1, '5': 9, '9': 0, '10': 'name'}, + const {'1': 'desc', '3': 3, '4': 1, '5': 9, '9': 1, '10': 'desc'}, + const {'1': 'thumbnail', '3': 4, '4': 1, '5': 9, '9': 2, '10': 'thumbnail'}, + ], + '8': const [ + const {'1': 'one_of_name'}, + const {'1': 'one_of_desc'}, + const {'1': 'one_of_thumbnail'}, + ], +}; + +/// Descriptor for `UpdateViewRequest`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List updateViewRequestDescriptor = $convert.base64Decode('ChFVcGRhdGVWaWV3UmVxdWVzdBIXCgd2aWV3X2lkGAEgASgJUgZ2aWV3SWQSFAoEbmFtZRgCIAEoCUgAUgRuYW1lEhQKBGRlc2MYAyABKAlIAVIEZGVzYxIeCgl0aHVtYm5haWwYBCABKAlIAlIJdGh1bWJuYWlsQg0KC29uZV9vZl9uYW1lQg0KC29uZV9vZl9kZXNjQhIKEG9uZV9vZl90aHVtYm5haWw='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_update.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_update.pbserver.dart new file mode 100644 index 0000000000..61e753e6f9 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/view_update.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: view_update.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +export 'view_update.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pb.dart index e14b1f4382..6b7884bbfc 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pb.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pb.dart @@ -9,6 +9,8 @@ import 'dart:core' as $core; import 'package:protobuf/protobuf.dart' as $pb; +import 'app_create.pb.dart' as $0; + class CreateWorkspaceRequest extends $pb.GeneratedMessage { static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'CreateWorkspaceRequest', createEmptyInstance: create) ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') @@ -75,6 +77,7 @@ class Workspace extends $pb.GeneratedMessage { ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id') ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc') + ..aOM<$0.RepeatedApp>(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'apps', subBuilder: $0.RepeatedApp.create) ..hasRequiredFields = false ; @@ -83,6 +86,7 @@ class Workspace extends $pb.GeneratedMessage { $core.String? id, $core.String? name, $core.String? desc, + $0.RepeatedApp? apps, }) { final _result = create(); if (id != null) { @@ -94,6 +98,9 @@ class Workspace extends $pb.GeneratedMessage { if (desc != null) { _result.desc = desc; } + if (apps != null) { + _result.apps = apps; + } return _result; } factory Workspace.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); @@ -143,5 +150,16 @@ class Workspace extends $pb.GeneratedMessage { $core.bool hasDesc() => $_has(2); @$pb.TagNumber(3) void clearDesc() => clearField(3); + + @$pb.TagNumber(4) + $0.RepeatedApp get apps => $_getN(3); + @$pb.TagNumber(4) + set apps($0.RepeatedApp v) { setField(4, v); } + @$pb.TagNumber(4) + $core.bool hasApps() => $_has(3); + @$pb.TagNumber(4) + void clearApps() => clearField(4); + @$pb.TagNumber(4) + $0.RepeatedApp ensureApps() => $_ensure(3); } diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbjson.dart index 89729f1fc4..1f266f0eb1 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbjson.dart @@ -26,8 +26,9 @@ const Workspace$json = const { const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'}, const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'}, const {'1': 'desc', '3': 3, '4': 1, '5': 9, '10': 'desc'}, + const {'1': 'apps', '3': 4, '4': 1, '5': 11, '6': '.RepeatedApp', '10': 'apps'}, ], }; /// Descriptor for `Workspace`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List workspaceDescriptor = $convert.base64Decode('CglXb3Jrc3BhY2USDgoCaWQYASABKAlSAmlkEhIKBG5hbWUYAiABKAlSBG5hbWUSEgoEZGVzYxgDIAEoCVIEZGVzYw=='); +final $typed_data.Uint8List workspaceDescriptor = $convert.base64Decode('CglXb3Jrc3BhY2USDgoCaWQYASABKAlSAmlkEhIKBG5hbWUYAiABKAlSBG5hbWUSEgoEZGVzYxgDIAEoCVIEZGVzYxIgCgRhcHBzGAQgASgLMgwuUmVwZWF0ZWRBcHBSBGFwcHM='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_query.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_query.pb.dart new file mode 100644 index 0000000000..bb0a78d416 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_query.pb.dart @@ -0,0 +1,72 @@ +/// +// Generated code. Do not modify. +// source: workspace_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +class QueryWorkspaceRequest extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'QueryWorkspaceRequest', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'workspaceId') + ..aOB(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'readApps') + ..hasRequiredFields = false + ; + + QueryWorkspaceRequest._() : super(); + factory QueryWorkspaceRequest({ + $core.String? workspaceId, + $core.bool? readApps, + }) { + final _result = create(); + if (workspaceId != null) { + _result.workspaceId = workspaceId; + } + if (readApps != null) { + _result.readApps = readApps; + } + return _result; + } + factory QueryWorkspaceRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory QueryWorkspaceRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + QueryWorkspaceRequest clone() => QueryWorkspaceRequest()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + QueryWorkspaceRequest copyWith(void Function(QueryWorkspaceRequest) updates) => super.copyWith((message) => updates(message as QueryWorkspaceRequest)) as QueryWorkspaceRequest; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static QueryWorkspaceRequest create() => QueryWorkspaceRequest._(); + QueryWorkspaceRequest createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static QueryWorkspaceRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static QueryWorkspaceRequest? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get workspaceId => $_getSZ(0); + @$pb.TagNumber(1) + set workspaceId($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasWorkspaceId() => $_has(0); + @$pb.TagNumber(1) + void clearWorkspaceId() => clearField(1); + + @$pb.TagNumber(2) + $core.bool get readApps => $_getBF(1); + @$pb.TagNumber(2) + set readApps($core.bool v) { $_setBool(1, v); } + @$pb.TagNumber(2) + $core.bool hasReadApps() => $_has(1); + @$pb.TagNumber(2) + void clearReadApps() => clearField(2); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_query.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_query.pbenum.dart new file mode 100644 index 0000000000..a14731fc1f --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_query.pbenum.dart @@ -0,0 +1,7 @@ +/// +// Generated code. Do not modify. +// source: workspace_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_query.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_query.pbjson.dart new file mode 100644 index 0000000000..570d4191e7 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_query.pbjson.dart @@ -0,0 +1,21 @@ +/// +// Generated code. Do not modify. +// source: workspace_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +import 'dart:core' as $core; +import 'dart:convert' as $convert; +import 'dart:typed_data' as $typed_data; +@$core.Deprecated('Use queryWorkspaceRequestDescriptor instead') +const QueryWorkspaceRequest$json = const { + '1': 'QueryWorkspaceRequest', + '2': const [ + const {'1': 'workspace_id', '3': 1, '4': 1, '5': 9, '10': 'workspaceId'}, + const {'1': 'read_apps', '3': 2, '4': 1, '5': 8, '10': 'readApps'}, + ], +}; + +/// Descriptor for `QueryWorkspaceRequest`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List queryWorkspaceRequestDescriptor = $convert.base64Decode('ChVRdWVyeVdvcmtzcGFjZVJlcXVlc3QSIQoMd29ya3NwYWNlX2lkGAEgASgJUgt3b3Jrc3BhY2VJZBIbCglyZWFkX2FwcHMYAiABKAhSCHJlYWRBcHBz'); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_query.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_query.pbserver.dart new file mode 100644 index 0000000000..e79a538647 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_query.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: workspace_query.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +export 'workspace_query.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_user_detail.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_user_detail.pb.dart index 553d431dd9..798624e8d0 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_user_detail.pb.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_user_detail.pb.dart @@ -9,17 +9,15 @@ import 'dart:core' as $core; import 'package:protobuf/protobuf.dart' as $pb; -import 'workspace_create.pb.dart' as $0; - -class UserWorkspace extends $pb.GeneratedMessage { - static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UserWorkspace', createEmptyInstance: create) +class CurrentWorkspace extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'CurrentWorkspace', createEmptyInstance: create) ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'owner') ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'workspaceId') ..hasRequiredFields = false ; - UserWorkspace._() : super(); - factory UserWorkspace({ + CurrentWorkspace._() : super(); + factory CurrentWorkspace({ $core.String? owner, $core.String? workspaceId, }) { @@ -32,26 +30,26 @@ class UserWorkspace extends $pb.GeneratedMessage { } return _result; } - factory UserWorkspace.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); - factory UserWorkspace.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + factory CurrentWorkspace.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory CurrentWorkspace.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - UserWorkspace clone() => UserWorkspace()..mergeFromMessage(this); + CurrentWorkspace clone() => CurrentWorkspace()..mergeFromMessage(this); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') - UserWorkspace copyWith(void Function(UserWorkspace) updates) => super.copyWith((message) => updates(message as UserWorkspace)) as UserWorkspace; // ignore: deprecated_member_use + CurrentWorkspace copyWith(void Function(CurrentWorkspace) updates) => super.copyWith((message) => updates(message as CurrentWorkspace)) as CurrentWorkspace; // ignore: deprecated_member_use $pb.BuilderInfo get info_ => _i; @$core.pragma('dart2js:noInline') - static UserWorkspace create() => UserWorkspace._(); - UserWorkspace createEmptyInstance() => create(); - static $pb.PbList createRepeated() => $pb.PbList(); + static CurrentWorkspace create() => CurrentWorkspace._(); + CurrentWorkspace createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); @$core.pragma('dart2js:noInline') - static UserWorkspace getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); - static UserWorkspace? _defaultInstance; + static CurrentWorkspace getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static CurrentWorkspace? _defaultInstance; @$pb.TagNumber(1) $core.String get owner => $_getSZ(0); @@ -72,66 +70,3 @@ class UserWorkspace extends $pb.GeneratedMessage { void clearWorkspaceId() => clearField(2); } -class UserWorkspaceDetail extends $pb.GeneratedMessage { - static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UserWorkspaceDetail', createEmptyInstance: create) - ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'owner') - ..aOM<$0.Workspace>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'workspace', subBuilder: $0.Workspace.create) - ..hasRequiredFields = false - ; - - UserWorkspaceDetail._() : super(); - factory UserWorkspaceDetail({ - $core.String? owner, - $0.Workspace? workspace, - }) { - final _result = create(); - if (owner != null) { - _result.owner = owner; - } - if (workspace != null) { - _result.workspace = workspace; - } - return _result; - } - factory UserWorkspaceDetail.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); - factory UserWorkspaceDetail.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); - @$core.Deprecated( - 'Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - UserWorkspaceDetail clone() => UserWorkspaceDetail()..mergeFromMessage(this); - @$core.Deprecated( - 'Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - UserWorkspaceDetail copyWith(void Function(UserWorkspaceDetail) updates) => super.copyWith((message) => updates(message as UserWorkspaceDetail)) as UserWorkspaceDetail; // ignore: deprecated_member_use - $pb.BuilderInfo get info_ => _i; - @$core.pragma('dart2js:noInline') - static UserWorkspaceDetail create() => UserWorkspaceDetail._(); - UserWorkspaceDetail createEmptyInstance() => create(); - static $pb.PbList createRepeated() => $pb.PbList(); - @$core.pragma('dart2js:noInline') - static UserWorkspaceDetail getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); - static UserWorkspaceDetail? _defaultInstance; - - @$pb.TagNumber(1) - $core.String get owner => $_getSZ(0); - @$pb.TagNumber(1) - set owner($core.String v) { $_setString(0, v); } - @$pb.TagNumber(1) - $core.bool hasOwner() => $_has(0); - @$pb.TagNumber(1) - void clearOwner() => clearField(1); - - @$pb.TagNumber(2) - $0.Workspace get workspace => $_getN(1); - @$pb.TagNumber(2) - set workspace($0.Workspace v) { setField(2, v); } - @$pb.TagNumber(2) - $core.bool hasWorkspace() => $_has(1); - @$pb.TagNumber(2) - void clearWorkspace() => clearField(2); - @$pb.TagNumber(2) - $0.Workspace ensureWorkspace() => $_ensure(1); -} - diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_user_detail.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_user_detail.pbjson.dart index b267e42d5b..bdce8c7542 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_user_detail.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_user_detail.pbjson.dart @@ -8,25 +8,14 @@ import 'dart:core' as $core; import 'dart:convert' as $convert; import 'dart:typed_data' as $typed_data; -@$core.Deprecated('Use userWorkspaceDescriptor instead') -const UserWorkspace$json = const { - '1': 'UserWorkspace', +@$core.Deprecated('Use currentWorkspaceDescriptor instead') +const CurrentWorkspace$json = const { + '1': 'CurrentWorkspace', '2': const [ const {'1': 'owner', '3': 1, '4': 1, '5': 9, '10': 'owner'}, const {'1': 'workspace_id', '3': 2, '4': 1, '5': 9, '10': 'workspaceId'}, ], }; -/// Descriptor for `UserWorkspace`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List userWorkspaceDescriptor = $convert.base64Decode('Cg1Vc2VyV29ya3NwYWNlEhQKBW93bmVyGAEgASgJUgVvd25lchIhCgx3b3Jrc3BhY2VfaWQYAiABKAlSC3dvcmtzcGFjZUlk'); -@$core.Deprecated('Use userWorkspaceDetailDescriptor instead') -const UserWorkspaceDetail$json = const { - '1': 'UserWorkspaceDetail', - '2': const [ - const {'1': 'owner', '3': 1, '4': 1, '5': 9, '10': 'owner'}, - const {'1': 'workspace', '3': 2, '4': 1, '5': 11, '6': '.Workspace', '10': 'workspace'}, - ], -}; - -/// Descriptor for `UserWorkspaceDetail`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List userWorkspaceDetailDescriptor = $convert.base64Decode('ChNVc2VyV29ya3NwYWNlRGV0YWlsEhQKBW93bmVyGAEgASgJUgVvd25lchIoCgl3b3Jrc3BhY2UYAiABKAsyCi5Xb3Jrc3BhY2VSCXdvcmtzcGFjZQ=='); +/// Descriptor for `CurrentWorkspace`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List currentWorkspaceDescriptor = $convert.base64Decode('ChBDdXJyZW50V29ya3NwYWNlEhQKBW93bmVyGAEgASgJUgVvd25lchIhCgx3b3Jrc3BhY2VfaWQYAiABKAlSC3dvcmtzcGFjZUlk'); diff --git a/app_flowy/packages/flowy_sdk/lib/rust_stream.dart b/app_flowy/packages/flowy_sdk/lib/rust_stream.dart new file mode 100644 index 0000000000..b812c59497 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/rust_stream.dart @@ -0,0 +1,54 @@ +import 'dart:isolate'; +import 'dart:async'; +import 'dart:typed_data'; +import 'dart:ffi'; +import 'package:flowy_infra/flowy_logger.dart'; +import 'protobuf/flowy-observable/subject.pb.dart'; + +typedef ObserverCallback = void Function(ObservableSubject observable); + +class RustStreamReceiver { + static RustStreamReceiver shared = RustStreamReceiver._internal(); + late RawReceivePort _ffiPort; + late StreamController _streamController; + late StreamController _observableController; + late StreamSubscription _ffiSubscription; + + int get port => _ffiPort.sendPort.nativePort; + StreamController get observable => _observableController; + + RustStreamReceiver._internal() { + _ffiPort = RawReceivePort(); + _streamController = StreamController(); + _observableController = StreamController.broadcast(); + + _ffiPort.handler = _streamController.add; + _ffiSubscription = _streamController.stream.listen(streamCallback); + } + + factory RustStreamReceiver() { + return shared; + } + + static listen(void Function(ObservableSubject subject) callback) { + RustStreamReceiver.shared.observable.stream.listen(callback); + } + + void streamCallback(Uint8List bytes) { + try { + final observable = ObservableSubject.fromBuffer(bytes); + _observableController.add(observable); + } catch (e, s) { + Log.error('RustStreamReceiver ObservableSubject deserialize error: ${e.runtimeType}'); + Log.error('Stack trace \n $s'); + rethrow; + } + } + + Future dispose() async { + await _ffiSubscription.cancel(); + await _streamController.close(); + await _observableController.close(); + _ffiPort.close(); + } +} diff --git a/app_flowy/packages/flowy_sdk/macos/Classes/binding.h b/app_flowy/packages/flowy_sdk/macos/Classes/binding.h index 0455d23a96..036d56aa2a 100644 --- a/app_flowy/packages/flowy_sdk/macos/Classes/binding.h +++ b/app_flowy/packages/flowy_sdk/macos/Classes/binding.h @@ -10,4 +10,6 @@ void async_command(int64_t port, const uint8_t *input, uintptr_t len); const uint8_t *sync_command(const uint8_t *input, uintptr_t len); +int32_t set_stream_port(int64_t port); + void link_me_please(void); \ No newline at end of file diff --git a/app_flowy/packages/flowy_sdk/pubspec.lock b/app_flowy/packages/flowy_sdk/pubspec.lock index 0293ed6db5..1219f95aeb 100644 --- a/app_flowy/packages/flowy_sdk/pubspec.lock +++ b/app_flowy/packages/flowy_sdk/pubspec.lock @@ -28,7 +28,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.7.0" + version: "2.6.1" boolean_selector: dependency: transitive description: @@ -105,7 +105,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.3.1" + version: "1.2.0" checked_yaml: dependency: transitive description: @@ -318,7 +318,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.4.0" + version: "1.3.0" mime: dependency: transitive description: @@ -442,7 +442,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.1" + version: "0.3.0" textstyle_extensions: dependency: transitive description: diff --git a/app_flowy/pubspec.lock b/app_flowy/pubspec.lock index 58a8783ca8..5fa4e5d72f 100644 --- a/app_flowy/pubspec.lock +++ b/app_flowy/pubspec.lock @@ -14,7 +14,7 @@ packages: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "1.7.2" + version: "1.7.1" animations: dependency: transitive description: @@ -35,7 +35,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.7.0" + version: "2.6.1" bloc: dependency: transitive description: @@ -56,7 +56,7 @@ packages: name: build url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.0.3" build_config: dependency: transitive description: @@ -77,21 +77,21 @@ packages: name: build_resolvers url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.4" build_runner: dependency: "direct dev" description: name: build_runner url: "https://pub.dartlang.org" source: hosted - version: "2.0.4" + version: "2.0.6" build_runner_core: dependency: transitive description: name: build_runner_core url: "https://pub.dartlang.org" source: hosted - version: "7.0.0" + version: "7.0.1" built_collection: dependency: transitive description: @@ -105,7 +105,7 @@ packages: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "8.1.0" + version: "8.1.1" characters: dependency: transitive description: @@ -119,7 +119,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.3.1" + version: "1.2.0" checked_yaml: dependency: transitive description: @@ -133,7 +133,7 @@ packages: name: cli_util url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.3.3" clock: dependency: transitive description: @@ -161,7 +161,7 @@ packages: name: convert url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.0.1" crypto: dependency: transitive description: @@ -182,7 +182,7 @@ packages: name: dart_style url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.2" dartz: dependency: transitive description: @@ -203,7 +203,7 @@ packages: name: expandable url: "https://pub.dartlang.org" source: hosted - version: "4.1.4" + version: "5.0.1" fake_async: dependency: transitive description: @@ -320,7 +320,7 @@ packages: name: flutter_lints url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.4" flutter_test: dependency: "direct dev" description: flutter @@ -358,7 +358,7 @@ packages: name: get_it url: "https://pub.dartlang.org" source: hosted - version: "7.1.3" + version: "7.2.0" glob: dependency: transitive description: @@ -393,7 +393,7 @@ packages: name: io url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.0.3" isolates: dependency: transitive description: @@ -456,7 +456,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.4.0" + version: "1.3.0" mime: dependency: transitive description: @@ -549,7 +549,7 @@ packages: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" pool: dependency: transitive description: @@ -612,7 +612,7 @@ packages: name: shelf url: "https://pub.dartlang.org" source: hosted - version: "1.1.4" + version: "1.2.0" shelf_web_socket: dependency: transitive description: @@ -638,7 +638,7 @@ packages: name: source_gen url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "1.0.3" source_span: dependency: transitive description: @@ -701,7 +701,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.1" + version: "0.3.0" textstyle_extensions: dependency: transitive description: @@ -820,7 +820,7 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.2.5" window_size: dependency: "direct main" description: diff --git a/app_flowy/pubspec.yaml b/app_flowy/pubspec.yaml index 1b89074a0a..9a3afb20c1 100644 --- a/app_flowy/pubspec.yaml +++ b/app_flowy/pubspec.yaml @@ -52,7 +52,7 @@ dependencies: ref: e48abe7c3e9ebfe0b81622167c5201d4e783bb81 sized_context: ^1.0.0+1 styled_widget: '>=0.3.1' - expandable: ^4.1.4 + expandable: ^5.0.1 # The following adds the Cupertino Icons font to your application. diff --git a/rust-lib/Cargo.toml b/rust-lib/Cargo.toml index 4085f5c52b..87a8758ff7 100644 --- a/rust-lib/Cargo.toml +++ b/rust-lib/Cargo.toml @@ -12,6 +12,8 @@ members = [ "flowy-database", "flowy-infra", "flowy-workspace", + "flowy-observable", + "flowy-editor", ] [profile.dev] diff --git a/rust-lib/dart-ffi/Cargo.toml b/rust-lib/dart-ffi/Cargo.toml index 7373739538..fc345df327 100644 --- a/rust-lib/dart-ffi/Cargo.toml +++ b/rust-lib/dart-ffi/Cargo.toml @@ -28,6 +28,7 @@ serde_json = {version = "1.0"} flowy-dispatch = {path = "../flowy-dispatch"} flowy-sdk = {path = "../flowy-sdk"} flowy-derive = {path = "../flowy-derive"} +flowy-observable = {path = "../flowy-observable", features = ["dart"]} #[features] diff --git a/rust-lib/dart-ffi/binding.h b/rust-lib/dart-ffi/binding.h index 0455d23a96..036d56aa2a 100644 --- a/rust-lib/dart-ffi/binding.h +++ b/rust-lib/dart-ffi/binding.h @@ -10,4 +10,6 @@ void async_command(int64_t port, const uint8_t *input, uintptr_t len); const uint8_t *sync_command(const uint8_t *input, uintptr_t len); +int32_t set_stream_port(int64_t port); + void link_me_please(void); \ No newline at end of file diff --git a/rust-lib/dart-ffi/src/lib.rs b/rust-lib/dart-ffi/src/lib.rs index 5c7f0b28c0..aaaba4d12a 100644 --- a/rust-lib/dart-ffi/src/lib.rs +++ b/rust-lib/dart-ffi/src/lib.rs @@ -12,14 +12,6 @@ use flowy_sdk::*; use lazy_static::lazy_static; use std::{ffi::CStr, os::raw::c_char}; -lazy_static! { - pub static ref FFI_RUNTIME: tokio::runtime::Runtime = - tokio::runtime::Builder::new_current_thread() - .thread_name("flowy-dart-ffi") - .build() - .unwrap(); -} - #[no_mangle] pub extern "C" fn init_sdk(path: *mut c_char) -> i64 { let c_str: &CStr = unsafe { CStr::from_ptr(path) }; @@ -58,6 +50,12 @@ pub extern "C" fn sync_command(input: *const u8, len: usize) -> *const u8 { forget_rust(result) } +#[no_mangle] +pub extern "C" fn set_stream_port(port: i64) -> i32 { + flowy_observable::dart::RustStreamSender::set_port(port); + return 0; +} + #[inline(never)] #[no_mangle] pub extern "C" fn link_me_please() {} diff --git a/rust-lib/dart-ffi/src/model/ffi_response.rs b/rust-lib/dart-ffi/src/model/ffi_response.rs index 09f2b988e3..29c7c01065 100644 --- a/rust-lib/dart-ffi/src/model/ffi_response.rs +++ b/rust-lib/dart-ffi/src/model/ffi_response.rs @@ -1,5 +1,5 @@ use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; -use flowy_dispatch::prelude::{EventResponse, Payload, StatusCode}; +use flowy_dispatch::prelude::{DispatchError, EventResponse, Payload, StatusCode}; #[derive(ProtoBuf_Enum, Clone, Copy)] pub enum FFIStatusCode { @@ -33,6 +33,11 @@ impl std::convert::From for FFIResponse { StatusCode::Err => FFIStatusCode::Err, }; + // let msg = match resp.error { + // None => "".to_owned(), + // Some(e) => format!("{:?}", e), + // }; + FFIResponse { payload, code } } } diff --git a/rust-lib/flowy-ast/src/ast.rs b/rust-lib/flowy-ast/src/ast.rs index 3990e123a2..b1973598c2 100644 --- a/rust-lib/flowy-ast/src/ast.rs +++ b/rust-lib/flowy-ast/src/ast.rs @@ -29,7 +29,7 @@ impl<'a> ASTContainer<'a> { }, syn::Data::Enum(data) => { // https://docs.rs/syn/1.0.48/syn/struct.DataEnum.html - ASTData::Enum(enum_from_ast(cx, &data.variants, &ast.attrs)) + ASTData::Enum(enum_from_ast(cx, &ast.ident, &data.variants, &ast.attrs)) }, }; @@ -208,14 +208,14 @@ pub fn struct_from_ast<'a>(cx: &Ctxt, fields: &'a syn::Fields) -> (ASTStyle, Vec pub fn enum_from_ast<'a>( cx: &Ctxt, + ident: &syn::Ident, variants: &'a Punctuated, enum_attrs: &Vec, ) -> Vec> { variants .iter() .flat_map(|variant| { - let attrs = attr::ASTEnumAttrVariant::from_ast(cx, variant, enum_attrs); - + let attrs = attr::ASTEnumAttrVariant::from_ast(cx, ident, variant, enum_attrs); let (style, fields) = struct_from_ast(cx, &variant.fields); Some(ASTEnumVariant { ident: variant.ident.clone(), diff --git a/rust-lib/flowy-ast/src/attr.rs b/rust-lib/flowy-ast/src/attr.rs index 9e60a92533..f121792eff 100644 --- a/rust-lib/flowy-ast/src/attr.rs +++ b/rust-lib/flowy-ast/src/attr.rs @@ -266,14 +266,21 @@ pub struct EventAttrs { #[derive(Debug, Clone)] pub struct ASTEnumAttrVariant { - pub name: String, + pub enum_name: String, + pub enum_item_name: String, pub value: String, pub event_attrs: EventAttrs, } impl ASTEnumAttrVariant { - pub fn from_ast(ctxt: &Ctxt, variant: &syn::Variant, enum_attrs: &Vec) -> Self { - let name = variant.ident.to_string(); + pub fn from_ast( + ctxt: &Ctxt, + ident: &syn::Ident, + variant: &syn::Variant, + enum_attrs: &Vec, + ) -> Self { + let enum_item_name = variant.ident.to_string(); + let enum_name = ident.to_string(); let mut value = String::new(); if variant.discriminant.is_some() { match variant.discriminant.as_ref().unwrap().1 { @@ -290,7 +297,8 @@ impl ASTEnumAttrVariant { } let event_attrs = get_event_attrs_from(ctxt, &variant.attrs, enum_attrs); ASTEnumAttrVariant { - name, + enum_name, + enum_item_name, value, event_attrs, } diff --git a/rust-lib/flowy-ast/src/event_ast.rs b/rust-lib/flowy-ast/src/event_ast.rs index d4a1f79c44..5b9434e535 100644 --- a/rust-lib/flowy-ast/src/event_ast.rs +++ b/rust-lib/flowy-ast/src/event_ast.rs @@ -11,15 +11,15 @@ pub struct EventASTContext { impl EventASTContext { pub fn from(variant: &ASTEnumAttrVariant) -> EventASTContext { - let command_name = variant.name.clone(); + let command_name = variant.enum_item_name.clone(); if command_name.is_empty() { - panic!("Invalid command name: {}", variant.name); + panic!("Invalid command name: {}", variant.enum_item_name); } let event = format_ident!("{}", &command_name); let splits = command_name.split("_").collect::>(); - let event_ty = format_ident!("UserEvent"); + let event_ty = format_ident!("{}", variant.enum_name); let event_request_struct = format_ident!("{}Event", &splits.join("")); let event_input = variant.event_input(); diff --git a/rust-lib/flowy-database/migrations/2021-07-09-063045_flowy-user/up.sql b/rust-lib/flowy-database/migrations/2021-07-09-063045_flowy-user/up.sql index 570b6c4e4b..7de8a8614d 100644 --- a/rust-lib/flowy-database/migrations/2021-07-09-063045_flowy-user/up.sql +++ b/rust-lib/flowy-database/migrations/2021-07-09-063045_flowy-user/up.sql @@ -1,42 +1,42 @@ -- Your SQL goes here CREATE TABLE user_table ( - id TEXT NOT NULL PRIMARY KEY, - name TEXT NOT NULL DEFAULT '', - password TEXT NOT NULL DEFAULT '', - email TEXT NOT NULL DEFAULT '' + id TEXT NOT NULL PRIMARY KEY, + name TEXT NOT NULL DEFAULT '', + password TEXT NOT NULL DEFAULT '', + email TEXT NOT NULL DEFAULT '' ); CREATE TABLE workspace_table ( - id TEXT NOT NULL PRIMARY KEY, - name TEXT NOT NULL DEFAULT '', - desc TEXT NOT NULL DEFAULT '', - modified_time BIGINT NOT NULL DEFAULT 0, - create_time BIGINT NOT NULL DEFAULT 0, - user_id TEXT NOT NULL DEFAULT '', - version BIGINT NOT NULL DEFAULT 0 + id TEXT NOT NULL PRIMARY KEY, + name TEXT NOT NULL DEFAULT '', + desc TEXT NOT NULL DEFAULT '', + modified_time BIGINT NOT NULL DEFAULT 0, + create_time BIGINT NOT NULL DEFAULT 0, + user_id TEXT NOT NULL DEFAULT '', + version BIGINT NOT NULL DEFAULT 0 ); CREATE TABLE app_table ( - id TEXT NOT NULL PRIMARY KEY, - workspace_id TEXT NOT NULL DEFAULT '', - name TEXT NOT NULL DEFAULT '', - desc TEXT NOT NULL DEFAULT '', - color_style BLOB NOT NULL DEFAULT (x''), - last_view_id TEXT DEFAULT '', - modified_time BIGINT NOT NULL DEFAULT 0, - create_time BIGINT NOT NULL DEFAULT 0, - version BIGINT NOT NULL DEFAULT 0 + id TEXT NOT NULL PRIMARY KEY, + workspace_id TEXT NOT NULL DEFAULT '', + name TEXT NOT NULL DEFAULT '', + desc TEXT NOT NULL DEFAULT '', + color_style BLOB NOT NULL DEFAULT (x''), + last_view_id TEXT DEFAULT '', + modified_time BIGINT NOT NULL DEFAULT 0, + create_time BIGINT NOT NULL DEFAULT 0, + version BIGINT NOT NULL DEFAULT 0 ); CREATE TABLE view_table ( - id TEXT NOT NULL PRIMARY KEY, - app_id TEXT NOT NULL DEFAULT '', - name TEXT NOT NULL DEFAULT '', - desc TEXT NOT NULL DEFAULT '', - modified_time BIGINT NOT NULL DEFAULT 0, - create_time BIGINT NOT NULL DEFAULT 0, - thumbnail TEXT NOT NULL DEFAULT '', - view_type INTEGER NOT NULL DEFAULT 0, - version BIGINT NOT NULL DEFAULT 0 + id TEXT NOT NULL PRIMARY KEY, + app_id TEXT NOT NULL DEFAULT '', + name TEXT NOT NULL DEFAULT '', + desc TEXT NOT NULL DEFAULT '', + modified_time BIGINT NOT NULL DEFAULT 0, + create_time BIGINT NOT NULL DEFAULT 0, + thumbnail TEXT NOT NULL DEFAULT '', + view_type INTEGER NOT NULL DEFAULT 0, + version BIGINT NOT NULL DEFAULT 0 ); diff --git a/rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/down.sql b/rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/down.sql new file mode 100644 index 0000000000..41dd39b71f --- /dev/null +++ b/rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +DROP TABLE doc_table; \ No newline at end of file diff --git a/rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/up.sql b/rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/up.sql new file mode 100644 index 0000000000..e1c8064271 --- /dev/null +++ b/rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/up.sql @@ -0,0 +1,10 @@ +-- Your SQL goes here +CREATE TABLE doc_table ( + id TEXT NOT NULL PRIMARY KEY, + name TEXT NOT NULL DEFAULT '', + desc TEXT NOT NULL DEFAULT '', + path TEXT NOT NULL DEFAULT '', + modified_time BIGINT NOT NULL DEFAULT 0, + create_time BIGINT NOT NULL DEFAULT 0, + version BIGINT NOT NULL DEFAULT 0 +); \ No newline at end of file diff --git a/rust-lib/flowy-database/src/lib.rs b/rust-lib/flowy-database/src/lib.rs index c107aa23ad..d3049f89d5 100644 --- a/rust-lib/flowy-database/src/lib.rs +++ b/rust-lib/flowy-database/src/lib.rs @@ -22,7 +22,7 @@ use std::{fmt::Debug, io, path::Path}; pub mod prelude { pub use super::UserDatabaseConnection; - pub use diesel::{query_dsl::*, ExpressionMethods, RunQueryDsl}; + pub use diesel::{query_dsl::*, BelongingToDsl, ExpressionMethods, RunQueryDsl}; } embed_migrations!("../flowy-database/migrations/"); diff --git a/rust-lib/flowy-database/src/macros.rs b/rust-lib/flowy-database/src/macros.rs index 08ca0e85b8..456d1f2699 100644 --- a/rust-lib/flowy-database/src/macros.rs +++ b/rust-lib/flowy-database/src/macros.rs @@ -10,6 +10,6 @@ macro_rules! diesel_update_table { let affected_row = diesel::update(filter) .set($changeset) .execute(&*$connection)?; - debug_assert_eq!(affected_row, 1); + // debug_assert_eq!(affected_row, 1); }; } diff --git a/rust-lib/flowy-database/src/schema.rs b/rust-lib/flowy-database/src/schema.rs index a7034dbe1c..7a70976026 100644 --- a/rust-lib/flowy-database/src/schema.rs +++ b/rust-lib/flowy-database/src/schema.rs @@ -12,6 +12,18 @@ table! { } } +table! { + doc_table (id) { + id -> Text, + name -> Text, + desc -> Text, + path -> Text, + modified_time -> BigInt, + create_time -> BigInt, + version -> BigInt, + } +} + table! { user_table (id) { id -> Text, @@ -50,6 +62,7 @@ table! { allow_tables_to_appear_in_same_query!( app_table, + doc_table, user_table, view_table, workspace_table, diff --git a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs index f9ff418873..9829f4f522 100644 --- a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs +++ b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs @@ -15,18 +15,31 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { "HashMap" => TypeCategory::Map, "u8" => TypeCategory::Bytes, "String" => TypeCategory::Str, - "KeyValue" + "ObservableSubject" + | "KeyValue" + | "CreateDocRequest" + | "DocInfo" + | "DocData" + | "QueryDocRequest" + | "QueryDocDataRequest" + | "UpdateDocRequest" + | "EditorError" + | "QueryAppRequest" | "CreateAppRequest" | "ColorStyle" | "App" + | "RepeatedApp" | "UpdateAppRequest" | "UpdateWorkspaceRequest" | "CreateWorkspaceRequest" | "Workspace" - | "UserWorkspace" - | "UserWorkspaceDetail" + | "QueryWorkspaceRequest" + | "CurrentWorkspace" + | "UpdateViewRequest" + | "QueryViewRequest" | "CreateViewRequest" | "View" + | "RepeatedView" | "WorkspaceError" | "FFIRequest" | "FFIResponse" @@ -39,9 +52,12 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { | "SignInParams" | "UserError" => TypeCategory::Protobuf, - "ViewTypeIdentifier" + "EditorEvent" + | "EditorErrorCode" + | "ViewType" | "WorkspaceEvent" | "WorkspaceErrorCode" + | "WorkspaceObservable" | "FFIStatusCode" | "UserStatus" | "UserEvent" diff --git a/rust-lib/flowy-derive/src/proto_buf/deserialize.rs b/rust-lib/flowy-derive/src/proto_buf/deserialize.rs index 15cb2db2f6..9a40b30cd7 100644 --- a/rust-lib/flowy-derive/src/proto_buf/deserialize.rs +++ b/rust-lib/flowy-derive/src/proto_buf/deserialize.rs @@ -86,6 +86,14 @@ fn token_stream_for_one_of(ctxt: &Ctxt, field: &ASTField) -> Option } }) }, + TypeCategory::Array => { + let take_func = format_ident!("take_{}", ident.to_string()); + Some(quote! { + if pb.#has_func() { + o.#member=Some(pb.#take_func()); + } + }) + }, _ => { let take_func = format_ident!("take_{}", ident.to_string()); let ty = bracketed_ty_info.unwrap().ty; diff --git a/rust-lib/flowy-derive/src/proto_buf/serialize.rs b/rust-lib/flowy-derive/src/proto_buf/serialize.rs index 50d94e9d33..6ebba93212 100644 --- a/rust-lib/flowy-derive/src/proto_buf/serialize.rs +++ b/rust-lib/flowy-derive/src/proto_buf/serialize.rs @@ -129,7 +129,7 @@ fn token_stream_for_vec(ctxt: &Ctxt, member: &syn::Member, ty: &syn::Type) -> Op TypeCategory::Protobuf => Some(quote! { pb.#member = ::protobuf::RepeatedField::from_vec( self.#member - .iter() + .into_iter() .map(|m| m.try_into().unwrap()) .collect()); }), diff --git a/rust-lib/flowy-dispatch/src/data.rs b/rust-lib/flowy-dispatch/src/data.rs index 0aaa94d41c..6539a52769 100644 --- a/rust-lib/flowy-dispatch/src/data.rs +++ b/rust-lib/flowy-dispatch/src/data.rs @@ -36,7 +36,7 @@ where Payload::None => ready(Err(unexpected_none_payload(req))), Payload::Bytes(bytes) => match T::parse_from_bytes(bytes) { Ok(data) => ready(Ok(Data(data))), - Err(e) => ready(Err(InternalError::new(format!("{:?}", e)).into())), + Err(e) => ready(Err(InternalError::new(format!("{}", e)).into())), }, } } @@ -50,7 +50,7 @@ where match self.into_inner().into_bytes() { Ok(bytes) => ResponseBuilder::Ok().data(bytes.to_vec()).build(), Err(e) => { - let system_err: DispatchError = InternalError::new(format!("{:?}", e)).into(); + let system_err: DispatchError = InternalError::new(format!("{}", e)).into(); system_err.into() }, } diff --git a/rust-lib/flowy-dispatch/src/dispatch.rs b/rust-lib/flowy-dispatch/src/dispatch.rs index aac9c410a7..e8badd4b9c 100644 --- a/rust-lib/flowy-dispatch/src/dispatch.rs +++ b/rust-lib/flowy-dispatch/src/dispatch.rs @@ -155,6 +155,7 @@ impl Service for DispatchService { Box::pin(async move { let result = { + // print_module_map_info(&module_map); match module_map.get(&request.event) { Some(module) => { let fut = module.new_service(()); @@ -163,7 +164,7 @@ impl Service for DispatchService { }, None => { let msg = format!("Can not find the event handler. {:?}", request); - log::trace!("{}", msg); + log::error!("{}", msg); Err(InternalError::new(msg).into()) }, } @@ -180,6 +181,7 @@ impl Service for DispatchService { } } +#[allow(dead_code)] fn module_info(modules: &Vec) -> String { let mut info = format!("{} modules loaded\n", modules.len()); for module in modules { @@ -187,3 +189,10 @@ fn module_info(modules: &Vec) -> String { } info } + +#[allow(dead_code)] +fn print_module_map_info(module_map: &ModuleMap) { + module_map.iter().for_each(|(k, v)| { + log::info!("Event: {:?} module: {:?}", k, v.name); + }) +} diff --git a/rust-lib/flowy-dispatch/src/errors/errors.rs b/rust-lib/flowy-dispatch/src/errors/errors.rs index 344807b6b2..ae7b1e6ff9 100644 --- a/rust-lib/flowy-dispatch/src/errors/errors.rs +++ b/rust-lib/flowy-dispatch/src/errors/errors.rs @@ -1,4 +1,5 @@ use crate::{ + byte_trait::FromBytes, request::EventRequest, response::{EventResponse, ResponseBuilder, StatusCode}, }; @@ -8,7 +9,7 @@ use std::{fmt, option::NoneError}; use tokio::sync::mpsc::error::SendError; pub trait Error: fmt::Debug + DynClone + Send + Sync { - fn as_response(&self) -> EventResponse { EventResponse::new(StatusCode::Err) } + fn as_response(&self) -> EventResponse; } dyn_clone::clone_trait_object!(Error); @@ -66,6 +67,13 @@ impl From for DispatchError { fn from(s: String) -> Self { InternalError { inner: s }.into() } } +impl FromBytes for DispatchError { + fn parse_from_bytes(bytes: &Vec) -> Result { + let s = String::from_utf8(bytes.to_vec()).unwrap(); + Ok(InternalError { inner: s }.into()) + } +} + impl From for EventResponse { fn from(err: DispatchError) -> Self { err.inner_error().as_response() } } @@ -98,12 +106,8 @@ where T: fmt::Debug + fmt::Display + 'static + Clone + Send + Sync, { fn as_response(&self) -> EventResponse { - let error = InternalError { - inner: format!("{}", self.inner), - } - .into(); - - ResponseBuilder::Err().error(error).build() + let error = format!("{}", self.inner).into_bytes(); + ResponseBuilder::Err().data(error).build() } } diff --git a/rust-lib/flowy-dispatch/src/module/data.rs b/rust-lib/flowy-dispatch/src/module/data.rs index 552decc122..368126cd28 100644 --- a/rust-lib/flowy-dispatch/src/module/data.rs +++ b/rust-lib/flowy-dispatch/src/module/data.rs @@ -5,18 +5,18 @@ use crate::{ }; use std::{any::type_name, ops::Deref, sync::Arc}; -pub struct ModuleData(Arc); +pub struct Unit(Arc); -impl ModuleData +impl Unit where T: Send + Sync, { - pub fn new(data: T) -> Self { ModuleData(Arc::new(data)) } + pub fn new(data: T) -> Self { Unit(Arc::new(data)) } pub fn get_ref(&self) -> &T { self.0.as_ref() } } -impl Deref for ModuleData +impl Deref for Unit where T: ?Sized + Send + Sync, { @@ -25,21 +25,21 @@ where fn deref(&self) -> &Arc { &self.0 } } -impl Clone for ModuleData +impl Clone for Unit where T: ?Sized + Send + Sync, { - fn clone(&self) -> ModuleData { ModuleData(self.0.clone()) } + fn clone(&self) -> Unit { Unit(self.0.clone()) } } -impl From> for ModuleData +impl From> for Unit where T: ?Sized + Send + Sync, { - fn from(arc: Arc) -> Self { ModuleData(arc) } + fn from(arc: Arc) -> Self { Unit(arc) } } -impl FromRequest for ModuleData +impl FromRequest for Unit where T: ?Sized + Send + Sync + 'static, { @@ -48,7 +48,7 @@ where #[inline] fn from_request(req: &EventRequest, _: &mut Payload) -> Self::Future { - if let Some(data) = req.module_data::>() { + if let Some(data) = req.module_data::>() { ready(Ok(data.clone())) } else { let msg = format!( diff --git a/rust-lib/flowy-dispatch/src/module/module.rs b/rust-lib/flowy-dispatch/src/module/module.rs index a715e93b53..ffe79c11bf 100644 --- a/rust-lib/flowy-dispatch/src/module/module.rs +++ b/rust-lib/flowy-dispatch/src/module/module.rs @@ -13,7 +13,7 @@ use pin_project::pin_project; use crate::{ errors::{DispatchError, InternalError}, - module::{container::ModuleDataMap, ModuleData}, + module::{container::ModuleDataMap, Unit}, request::{payload::Payload, EventRequest, FromRequest}, response::{EventResponse, Responder}, service::{ @@ -77,7 +77,7 @@ impl Module { pub fn data(mut self, data: D) -> Self { Arc::get_mut(&mut self.module_data) .unwrap() - .insert(ModuleData::new(data)); + .insert(Unit::new(data)); self } diff --git a/rust-lib/flowy-dispatch/src/response/builder.rs b/rust-lib/flowy-dispatch/src/response/builder.rs index abfe55184a..2d56db4205 100644 --- a/rust-lib/flowy-dispatch/src/response/builder.rs +++ b/rust-lib/flowy-dispatch/src/response/builder.rs @@ -14,7 +14,6 @@ macro_rules! static_response { pub struct ResponseBuilder { pub payload: T, pub status: StatusCode, - pub error: Option, } impl ResponseBuilder { @@ -22,7 +21,6 @@ impl ResponseBuilder { ResponseBuilder { payload: Payload::None, status, - error: None, } } @@ -31,16 +29,10 @@ impl ResponseBuilder { self } - pub fn error(mut self, error: DispatchError) -> Self { - self.error = Some(error); - self - } - pub fn build(self) -> EventResponse { EventResponse { payload: self.payload, status_code: self.status, - error: self.error, } } diff --git a/rust-lib/flowy-dispatch/src/response/response.rs b/rust-lib/flowy-dispatch/src/response/response.rs index f0ed7c3fb6..593a3b4d3a 100644 --- a/rust-lib/flowy-dispatch/src/response/response.rs +++ b/rust-lib/flowy-dispatch/src/response/response.rs @@ -20,7 +20,6 @@ pub struct EventResponse { #[derivative(Debug = "ignore")] pub payload: Payload, pub status_code: StatusCode, - pub error: Option, } impl EventResponse { @@ -28,7 +27,6 @@ impl EventResponse { EventResponse { payload: Payload::None, status_code, - error: None, } } @@ -59,10 +57,6 @@ impl std::fmt::Display for EventResponse { Payload::Bytes(b) => f.write_fmt(format_args!("Data: {} bytes", b.len()))?, Payload::None => f.write_fmt(format_args!("Data: Empty"))?, } - match &self.error { - Some(e) => f.write_fmt(format_args!("Error: {:?}", e))?, - None => {}, - } Ok(()) } diff --git a/rust-lib/flowy-editor/Cargo.toml b/rust-lib/flowy-editor/Cargo.toml new file mode 100644 index 0000000000..d62fce0b3f --- /dev/null +++ b/rust-lib/flowy-editor/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "flowy-editor" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +derive_more = {version = "0.99", features = ["display"]} +flowy-dispatch = { path = "../flowy-dispatch" } +flowy-log = { path = "../flowy-log" } +flowy-derive = { path = "../flowy-derive" } +flowy-database = { path = "../flowy-database" } +flowy-infra = { path = "../flowy-infra" } +diesel = {version = "1.4.7", features = ["sqlite"]} +diesel_derives = {version = "1.4.1", features = ["sqlite"]} +protobuf = {version = "2.18.0"} +unicode-segmentation = "1.7.1" +lazy_static = "1.4.0" +log = "0.4.14" +tokio = {version = "1.6.0", features = ["sync"]} +tracing = { version = "0.1", features = ["log"] } + +[dev-dependencies] +flowy-test = { path = "../flowy-test" } \ No newline at end of file diff --git a/rust-lib/flowy-editor/Flowy.toml b/rust-lib/flowy-editor/Flowy.toml new file mode 100644 index 0000000000..728e5eb776 --- /dev/null +++ b/rust-lib/flowy-editor/Flowy.toml @@ -0,0 +1,3 @@ + +proto_crates = ["src/entities", "src/event.rs", "src/errors.rs"] +event_files = ["src/event.rs"] \ No newline at end of file diff --git a/rust-lib/flowy-editor/src/entities/doc/doc_create.rs b/rust-lib/flowy-editor/src/entities/doc/doc_create.rs new file mode 100644 index 0000000000..c160c8293b --- /dev/null +++ b/rust-lib/flowy-editor/src/entities/doc/doc_create.rs @@ -0,0 +1,78 @@ +use crate::{ + entities::doc::parser::*, + errors::{ErrorBuilder, *}, +}; +use flowy_derive::ProtoBuf; +use std::convert::TryInto; + +#[derive(ProtoBuf, Default)] +pub struct CreateDocRequest { + #[pb(index = 1)] + pub id: String, + + #[pb(index = 2)] + pub name: String, + + #[pb(index = 3)] + pub desc: String, + + #[pb(index = 4)] + pub text: String, +} + +pub struct CreateDocParams { + pub id: String, + pub name: String, + pub desc: String, + pub text: String, +} + +impl TryInto for CreateDocRequest { + type Error = EditorError; + + fn try_into(self) -> Result { + let name = DocName::parse(self.name) + .map_err(|e| { + ErrorBuilder::new(EditorErrorCode::DocNameInvalid) + .msg(e) + .build() + })? + .0; + + let id = DocViewId::parse(self.id) + .map_err(|e| { + ErrorBuilder::new(EditorErrorCode::DocViewIdInvalid) + .msg(e) + .build() + })? + .0; + + Ok(CreateDocParams { + id, + name, + desc: self.desc, + text: self.text, + }) + } +} + +#[derive(ProtoBuf, Default, Debug)] +pub struct DocInfo { + #[pb(index = 1)] + pub id: String, + + #[pb(index = 2)] + pub name: String, + + #[pb(index = 3)] + pub desc: String, + + #[pb(index = 4)] + pub path: String, +} + +#[derive(ProtoBuf, Default, Debug)] +pub struct DocData { + #[pb(index = 1)] + pub text: String, +} diff --git a/rust-lib/flowy-editor/src/entities/doc/doc_modify.rs b/rust-lib/flowy-editor/src/entities/doc/doc_modify.rs new file mode 100644 index 0000000000..7980bbc89c --- /dev/null +++ b/rust-lib/flowy-editor/src/entities/doc/doc_modify.rs @@ -0,0 +1,72 @@ +use crate::{entities::doc::parser::*, errors::*}; +use flowy_derive::ProtoBuf; +use std::convert::TryInto; + +#[derive(ProtoBuf, Default)] +pub struct UpdateDocRequest { + #[pb(index = 1)] + pub id: String, + + #[pb(index = 2, one_of)] + pub name: Option, + + #[pb(index = 3, one_of)] + pub desc: Option, + + #[pb(index = 4, one_of)] + pub text: Option, +} + +pub(crate) struct UpdateDocParams { + pub(crate) id: String, + pub(crate) name: Option, + pub(crate) desc: Option, + pub(crate) text: Option, +} + +impl TryInto for UpdateDocRequest { + type Error = EditorError; + + fn try_into(self) -> Result { + let id = DocId::parse(self.id) + .map_err(|e| { + ErrorBuilder::new(EditorErrorCode::DocViewIdInvalid) + .msg(e) + .build() + })? + .0; + + let name = match self.name { + None => None, + Some(name) => Some( + DocName::parse(name) + .map_err(|e| { + ErrorBuilder::new(EditorErrorCode::DocNameInvalid) + .msg(e) + .build() + })? + .0, + ), + }; + + let desc = match self.desc { + None => None, + Some(desc) => Some( + DocDesc::parse(desc) + .map_err(|e| { + ErrorBuilder::new(EditorErrorCode::DocDescTooLong) + .msg(e) + .build() + })? + .0, + ), + }; + + Ok(UpdateDocParams { + id, + name, + desc, + text: self.text, + }) + } +} diff --git a/rust-lib/flowy-editor/src/entities/doc/doc_query.rs b/rust-lib/flowy-editor/src/entities/doc/doc_query.rs new file mode 100644 index 0000000000..ea1573fe7d --- /dev/null +++ b/rust-lib/flowy-editor/src/entities/doc/doc_query.rs @@ -0,0 +1,70 @@ +use crate::{ + entities::doc::parser::{DocId, DocPath}, + errors::*, +}; +use flowy_derive::ProtoBuf; +use std::convert::TryInto; + +#[derive(Default, ProtoBuf)] +pub struct QueryDocRequest { + #[pb(index = 1)] + pub doc_id: String, +} + +pub(crate) struct QueryDocParams { + pub doc_id: String, +} + +impl TryInto for QueryDocRequest { + type Error = EditorError; + + fn try_into(self) -> Result { + let doc_id = DocId::parse(self.doc_id) + .map_err(|e| { + ErrorBuilder::new(EditorErrorCode::DocViewIdInvalid) + .msg(e) + .build() + })? + .0; + + Ok(QueryDocParams { doc_id }) + } +} + +#[derive(Default, ProtoBuf)] +pub struct QueryDocDataRequest { + #[pb(index = 1)] + pub doc_id: String, + + #[pb(index = 2)] + pub path: String, +} + +pub(crate) struct QueryDocDataParams { + pub doc_id: String, + pub path: String, +} + +impl TryInto for QueryDocDataRequest { + type Error = EditorError; + + fn try_into(self) -> Result { + let doc_id = DocId::parse(self.doc_id) + .map_err(|e| { + ErrorBuilder::new(EditorErrorCode::DocViewIdInvalid) + .msg(e) + .build() + })? + .0; + + let path = DocPath::parse(self.path) + .map_err(|e| { + ErrorBuilder::new(EditorErrorCode::DocFilePathInvalid) + .msg(e) + .build() + })? + .0; + + Ok(QueryDocDataParams { doc_id, path }) + } +} diff --git a/rust-lib/flowy-editor/src/entities/doc/mod.rs b/rust-lib/flowy-editor/src/entities/doc/mod.rs new file mode 100644 index 0000000000..a12126ac61 --- /dev/null +++ b/rust-lib/flowy-editor/src/entities/doc/mod.rs @@ -0,0 +1,8 @@ +mod doc_create; +mod doc_modify; +mod doc_query; +mod parser; + +pub use doc_create::*; +pub use doc_modify::*; +pub use doc_query::*; diff --git a/rust-lib/flowy-editor/src/entities/doc/parser/doc_desc.rs b/rust-lib/flowy-editor/src/entities/doc/parser/doc_desc.rs new file mode 100644 index 0000000000..0249bd4f12 --- /dev/null +++ b/rust-lib/flowy-editor/src/entities/doc/parser/doc_desc.rs @@ -0,0 +1,14 @@ +use unicode_segmentation::UnicodeSegmentation; + +#[derive(Debug)] +pub struct DocDesc(pub String); + +impl DocDesc { + pub fn parse(s: String) -> Result { + if s.graphemes(true).count() > 1000 { + return Err(format!("Doc desc too long")); + } + + Ok(Self(s)) + } +} diff --git a/rust-lib/flowy-editor/src/entities/doc/parser/doc_id.rs b/rust-lib/flowy-editor/src/entities/doc/parser/doc_id.rs new file mode 100644 index 0000000000..fbdfc0fa56 --- /dev/null +++ b/rust-lib/flowy-editor/src/entities/doc/parser/doc_id.rs @@ -0,0 +1,12 @@ +#[derive(Debug)] +pub struct DocId(pub String); + +impl DocId { + pub fn parse(s: String) -> Result { + if s.trim().is_empty() { + return Err(format!("Doc id can not be empty or whitespace")); + } + + Ok(Self(s)) + } +} diff --git a/rust-lib/flowy-editor/src/entities/doc/parser/doc_name.rs b/rust-lib/flowy-editor/src/entities/doc/parser/doc_name.rs new file mode 100644 index 0000000000..3138acaaf6 --- /dev/null +++ b/rust-lib/flowy-editor/src/entities/doc/parser/doc_name.rs @@ -0,0 +1,12 @@ +#[derive(Debug)] +pub struct DocName(pub String); + +impl DocName { + pub fn parse(s: String) -> Result { + if s.trim().is_empty() { + return Err(format!("Doc name can not be empty or whitespace")); + } + + Ok(Self(s)) + } +} diff --git a/rust-lib/flowy-editor/src/entities/doc/parser/doc_path.rs b/rust-lib/flowy-editor/src/entities/doc/parser/doc_path.rs new file mode 100644 index 0000000000..ac69879818 --- /dev/null +++ b/rust-lib/flowy-editor/src/entities/doc/parser/doc_path.rs @@ -0,0 +1,12 @@ +#[derive(Debug)] +pub struct DocPath(pub String); + +impl DocPath { + pub fn parse(s: String) -> Result { + if s.trim().is_empty() { + return Err(format!("Doc path can not be empty or whitespace")); + } + + Ok(Self(s)) + } +} diff --git a/rust-lib/flowy-editor/src/entities/doc/parser/doc_view_id.rs b/rust-lib/flowy-editor/src/entities/doc/parser/doc_view_id.rs new file mode 100644 index 0000000000..6dea4f0fb0 --- /dev/null +++ b/rust-lib/flowy-editor/src/entities/doc/parser/doc_view_id.rs @@ -0,0 +1,12 @@ +#[derive(Debug)] +pub struct DocViewId(pub String); + +impl DocViewId { + pub fn parse(s: String) -> Result { + if s.trim().is_empty() { + return Err(format!("Doc view id can not be empty or whitespace")); + } + + Ok(Self(s)) + } +} diff --git a/rust-lib/flowy-editor/src/entities/doc/parser/mod.rs b/rust-lib/flowy-editor/src/entities/doc/parser/mod.rs new file mode 100644 index 0000000000..10865b9880 --- /dev/null +++ b/rust-lib/flowy-editor/src/entities/doc/parser/mod.rs @@ -0,0 +1,11 @@ +mod doc_desc; +mod doc_id; +mod doc_name; +mod doc_path; +mod doc_view_id; + +pub use doc_desc::*; +pub use doc_id::*; +pub use doc_name::*; +pub use doc_path::*; +pub use doc_view_id::*; diff --git a/rust-lib/flowy-editor/src/entities/mod.rs b/rust-lib/flowy-editor/src/entities/mod.rs new file mode 100644 index 0000000000..dc16bd593b --- /dev/null +++ b/rust-lib/flowy-editor/src/entities/mod.rs @@ -0,0 +1 @@ +pub mod doc; diff --git a/rust-lib/flowy-editor/src/errors.rs b/rust-lib/flowy-editor/src/errors.rs new file mode 100644 index 0000000000..ad15db1f88 --- /dev/null +++ b/rust-lib/flowy-editor/src/errors.rs @@ -0,0 +1,109 @@ +use crate::services::file_manager::FileError; +use derive_more::Display; +use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; +use flowy_dispatch::prelude::{EventResponse, ResponseBuilder}; +use std::convert::TryInto; + +#[derive(Debug, Default, Clone, ProtoBuf)] +pub struct EditorError { + #[pb(index = 1)] + pub code: EditorErrorCode, + + #[pb(index = 2)] + pub msg: String, +} + +impl EditorError { + fn new(code: EditorErrorCode, msg: &str) -> Self { + Self { + code, + msg: msg.to_owned(), + } + } +} + +#[derive(Debug, Clone, ProtoBuf_Enum, Display, PartialEq, Eq)] +pub enum EditorErrorCode { + #[display(fmt = "Unknown")] + Unknown = 0, + + #[display(fmt = "EditorDBInternalError")] + EditorDBInternalError = 1, + + #[display(fmt = "EditorDBConnFailed")] + EditorDBConnFailed = 2, + + #[display(fmt = "DocNameInvalid")] + DocNameInvalid = 10, + + #[display(fmt = "DocViewIdInvalid")] + DocViewIdInvalid = 11, + + #[display(fmt = "DocDescTooLong")] + DocDescTooLong = 12, + + #[display(fmt = "DocOpenFileError")] + DocOpenFileError = 13, + + #[display(fmt = "DocFilePathInvalid")] + DocFilePathInvalid = 14, + + #[display(fmt = "EditorUserNotLoginYet")] + EditorUserNotLoginYet = 100, +} + +impl std::default::Default for EditorErrorCode { + fn default() -> Self { EditorErrorCode::Unknown } +} + +impl std::convert::From for EditorError { + fn from(error: flowy_database::result::Error) -> Self { + ErrorBuilder::new(EditorErrorCode::EditorDBInternalError) + .error(error) + .build() + } +} + +impl std::convert::From for EditorError { + fn from(error: FileError) -> Self { + ErrorBuilder::new(EditorErrorCode::DocOpenFileError) + .error(error) + .build() + } +} + +impl flowy_dispatch::Error for EditorError { + fn as_response(&self) -> EventResponse { + let bytes: Vec = self.clone().try_into().unwrap(); + ResponseBuilder::Err().data(bytes).build() + } +} + +pub struct ErrorBuilder { + pub code: EditorErrorCode, + pub msg: Option, +} + +impl ErrorBuilder { + pub fn new(code: EditorErrorCode) -> Self { ErrorBuilder { code, msg: None } } + + pub fn msg(mut self, msg: T) -> Self + where + T: Into, + { + self.msg = Some(msg.into()); + self + } + + pub fn error(mut self, msg: T) -> Self + where + T: std::fmt::Debug, + { + self.msg = Some(format!("{:?}", msg)); + self + } + + pub fn build(mut self) -> EditorError { + EditorError::new(self.code, &self.msg.take().unwrap_or("".to_owned())) + } +} diff --git a/rust-lib/flowy-editor/src/event.rs b/rust-lib/flowy-editor/src/event.rs new file mode 100644 index 0000000000..358f863a93 --- /dev/null +++ b/rust-lib/flowy-editor/src/event.rs @@ -0,0 +1,22 @@ +use derive_more::Display; +use flowy_derive::{Flowy_Event, ProtoBuf_Enum}; + +#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)] +#[event_err = "EditorError"] +pub enum EditorEvent { + #[display(fmt = "CreateDoc")] + #[event(input = "CreateDocRequest", output = "DocInfo")] + CreateDoc = 0, + + #[display(fmt = "UpdateDoc")] + #[event(input = "UpdateDocRequest")] + UpdateDoc = 1, + + #[display(fmt = "ReadDocInfo")] + #[event(input = "QueryDocRequest", output = "DocInfo")] + ReadDocInfo = 2, + + #[display(fmt = "ReadDocData")] + #[event(input = "QueryDocDataRequest", output = "DocData")] + ReadDocData = 3, +} diff --git a/rust-lib/flowy-editor/src/handlers/doc_handler.rs b/rust-lib/flowy-editor/src/handlers/doc_handler.rs new file mode 100644 index 0000000000..13ea1d641c --- /dev/null +++ b/rust-lib/flowy-editor/src/handlers/doc_handler.rs @@ -0,0 +1,78 @@ +use crate::{ + entities::doc::*, + errors::EditorError, + services::{doc_controller::DocController, file_manager::FileManager}, +}; +use flowy_dispatch::prelude::*; +use std::{convert::TryInto, path::Path, sync::Arc}; +use tokio::sync::RwLock; + +#[tracing::instrument(name = "create_doc", skip(data, controller, manager))] +pub async fn create_doc( + data: Data, + controller: Unit, + manager: Unit>, +) -> ResponseResult { + let params: CreateDocParams = data.into_inner().try_into()?; + let dir = manager.read().await.user.user_doc_dir()?; + let path = manager + .write() + .await + .create_file(¶ms.id, &dir, ¶ms.text)?; + let doc_desc = controller + .create_doc(params, path.to_str().unwrap()) + .await?; + response_ok(doc_desc) +} + +#[tracing::instrument(name = "read_doc", skip(data, controller, manager))] +pub async fn read_doc( + data: Data, + controller: Unit, + manager: Unit>, +) -> ResponseResult { + let params: QueryDocParams = data.into_inner().try_into()?; + let doc_info = controller.read_doc(¶ms.doc_id).await?; + let _ = manager + .write() + .await + .open(Path::new(&doc_info.path), doc_info.id.clone())?; + + response_ok(doc_info) +} + +#[tracing::instrument(name = "read_doc_data", skip(data, manager))] +pub async fn read_doc_data( + data: Data, + manager: Unit>, +) -> ResponseResult { + let params: QueryDocDataParams = data.into_inner().try_into()?; + let text = manager + .write() + .await + .open(Path::new(¶ms.path), params.doc_id)?; + + response_ok(DocData { text }) +} + +pub async fn update_doc( + data: Data, + controller: Unit, + manager: Unit>, +) -> Result<(), EditorError> { + let mut params: UpdateDocParams = data.into_inner().try_into()?; + + if let Some(s) = params.text.take() { + let doc_desc = controller.read_doc(¶ms.id).await?; + manager + .write() + .await + .save(Path::new(&doc_desc.path), &s, params.id.clone()); + } + + if params.name.is_some() || params.desc.is_some() { + let _ = controller.update_doc(params).await?; + } + + Ok(()) +} diff --git a/rust-lib/flowy-editor/src/handlers/mod.rs b/rust-lib/flowy-editor/src/handlers/mod.rs new file mode 100644 index 0000000000..04640ecc56 --- /dev/null +++ b/rust-lib/flowy-editor/src/handlers/mod.rs @@ -0,0 +1,3 @@ +mod doc_handler; + +pub use doc_handler::*; diff --git a/rust-lib/flowy-editor/src/lib.rs b/rust-lib/flowy-editor/src/lib.rs new file mode 100644 index 0000000000..9782f9f922 --- /dev/null +++ b/rust-lib/flowy-editor/src/lib.rs @@ -0,0 +1,15 @@ +pub mod entities; +pub mod errors; +pub mod event; +mod handlers; +pub mod module; +mod protobuf; +mod services; +mod sql_tables; + +#[macro_use] +extern crate flowy_database; + +pub mod prelude { + pub use crate::module::*; +} diff --git a/rust-lib/flowy-editor/src/module.rs b/rust-lib/flowy-editor/src/module.rs new file mode 100644 index 0000000000..e3b64fcd94 --- /dev/null +++ b/rust-lib/flowy-editor/src/module.rs @@ -0,0 +1,35 @@ +use crate::{ + errors::EditorError, + event::EditorEvent, + handlers::*, + services::{ + doc_controller::DocController, + file_manager::{create_dir_if_not_exist, FileManager}, + }, +}; +use flowy_database::DBConnection; +use flowy_dispatch::prelude::*; +use std::sync::Arc; +use tokio::sync::RwLock; + +pub trait EditorDatabase: Send + Sync { + fn db_connection(&self) -> Result; +} + +pub trait EditorUser: Send + Sync { + fn user_doc_dir(&self) -> Result; +} + +pub fn create(database: Arc, user: Arc) -> Module { + let file_manager = RwLock::new(FileManager::new(user.clone())); + let doc_controller = DocController::new(database); + + Module::new() + .name("Flowy-Editor") + .data(file_manager) + .data(doc_controller) + .event(EditorEvent::CreateDoc, create_doc) + .event(EditorEvent::UpdateDoc, update_doc) + .event(EditorEvent::ReadDocInfo, read_doc) + .event(EditorEvent::ReadDocData, read_doc_data) +} diff --git a/rust-lib/flowy-editor/src/protobuf/mod.rs b/rust-lib/flowy-editor/src/protobuf/mod.rs new file mode 100644 index 0000000000..2480f62fbe --- /dev/null +++ b/rust-lib/flowy-editor/src/protobuf/mod.rs @@ -0,0 +1,4 @@ + +mod model; +pub use model::*; + \ No newline at end of file diff --git a/rust-lib/flowy-editor/src/protobuf/model/doc_create.rs b/rust-lib/flowy-editor/src/protobuf/model/doc_create.rs new file mode 100644 index 0000000000..e2cef4e81e --- /dev/null +++ b/rust-lib/flowy-editor/src/protobuf/model/doc_create.rs @@ -0,0 +1,804 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `doc_create.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct CreateDocRequest { + // message fields + pub id: ::std::string::String, + pub name: ::std::string::String, + pub desc: ::std::string::String, + pub text: ::std::string::String, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a CreateDocRequest { + fn default() -> &'a CreateDocRequest { + ::default_instance() + } +} + +impl CreateDocRequest { + pub fn new() -> CreateDocRequest { + ::std::default::Default::default() + } + + // string id = 1; + + + pub fn get_id(&self) -> &str { + &self.id + } + pub fn clear_id(&mut self) { + self.id.clear(); + } + + // Param is passed by value, moved + pub fn set_id(&mut self, v: ::std::string::String) { + self.id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_id(&mut self) -> &mut ::std::string::String { + &mut self.id + } + + // Take field + pub fn take_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.id, ::std::string::String::new()) + } + + // string name = 2; + + + pub fn get_name(&self) -> &str { + &self.name + } + pub fn clear_name(&mut self) { + self.name.clear(); + } + + // Param is passed by value, moved + pub fn set_name(&mut self, v: ::std::string::String) { + self.name = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_name(&mut self) -> &mut ::std::string::String { + &mut self.name + } + + // Take field + pub fn take_name(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.name, ::std::string::String::new()) + } + + // string desc = 3; + + + pub fn get_desc(&self) -> &str { + &self.desc + } + pub fn clear_desc(&mut self) { + self.desc.clear(); + } + + // Param is passed by value, moved + pub fn set_desc(&mut self, v: ::std::string::String) { + self.desc = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_desc(&mut self) -> &mut ::std::string::String { + &mut self.desc + } + + // Take field + pub fn take_desc(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.desc, ::std::string::String::new()) + } + + // string text = 4; + + + pub fn get_text(&self) -> &str { + &self.text + } + pub fn clear_text(&mut self) { + self.text.clear(); + } + + // Param is passed by value, moved + pub fn set_text(&mut self, v: ::std::string::String) { + self.text = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_text(&mut self) -> &mut ::std::string::String { + &mut self.text + } + + // Take field + pub fn take_text(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.text, ::std::string::String::new()) + } +} + +impl ::protobuf::Message for CreateDocRequest { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.id)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?; + }, + 3 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.desc)?; + }, + 4 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.text)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.id); + } + if !self.name.is_empty() { + my_size += ::protobuf::rt::string_size(2, &self.name); + } + if !self.desc.is_empty() { + my_size += ::protobuf::rt::string_size(3, &self.desc); + } + if !self.text.is_empty() { + my_size += ::protobuf::rt::string_size(4, &self.text); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.id.is_empty() { + os.write_string(1, &self.id)?; + } + if !self.name.is_empty() { + os.write_string(2, &self.name)?; + } + if !self.desc.is_empty() { + os.write_string(3, &self.desc)?; + } + if !self.text.is_empty() { + os.write_string(4, &self.text)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> CreateDocRequest { + CreateDocRequest::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "id", + |m: &CreateDocRequest| { &m.id }, + |m: &mut CreateDocRequest| { &mut m.id }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "name", + |m: &CreateDocRequest| { &m.name }, + |m: &mut CreateDocRequest| { &mut m.name }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "desc", + |m: &CreateDocRequest| { &m.desc }, + |m: &mut CreateDocRequest| { &mut m.desc }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "text", + |m: &CreateDocRequest| { &m.text }, + |m: &mut CreateDocRequest| { &mut m.text }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CreateDocRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static CreateDocRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CreateDocRequest::new) + } +} + +impl ::protobuf::Clear for CreateDocRequest { + fn clear(&mut self) { + self.id.clear(); + self.name.clear(); + self.desc.clear(); + self.text.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for CreateDocRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for CreateDocRequest { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct DocInfo { + // message fields + pub id: ::std::string::String, + pub name: ::std::string::String, + pub desc: ::std::string::String, + pub path: ::std::string::String, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a DocInfo { + fn default() -> &'a DocInfo { + ::default_instance() + } +} + +impl DocInfo { + pub fn new() -> DocInfo { + ::std::default::Default::default() + } + + // string id = 1; + + + pub fn get_id(&self) -> &str { + &self.id + } + pub fn clear_id(&mut self) { + self.id.clear(); + } + + // Param is passed by value, moved + pub fn set_id(&mut self, v: ::std::string::String) { + self.id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_id(&mut self) -> &mut ::std::string::String { + &mut self.id + } + + // Take field + pub fn take_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.id, ::std::string::String::new()) + } + + // string name = 2; + + + pub fn get_name(&self) -> &str { + &self.name + } + pub fn clear_name(&mut self) { + self.name.clear(); + } + + // Param is passed by value, moved + pub fn set_name(&mut self, v: ::std::string::String) { + self.name = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_name(&mut self) -> &mut ::std::string::String { + &mut self.name + } + + // Take field + pub fn take_name(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.name, ::std::string::String::new()) + } + + // string desc = 3; + + + pub fn get_desc(&self) -> &str { + &self.desc + } + pub fn clear_desc(&mut self) { + self.desc.clear(); + } + + // Param is passed by value, moved + pub fn set_desc(&mut self, v: ::std::string::String) { + self.desc = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_desc(&mut self) -> &mut ::std::string::String { + &mut self.desc + } + + // Take field + pub fn take_desc(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.desc, ::std::string::String::new()) + } + + // string path = 4; + + + pub fn get_path(&self) -> &str { + &self.path + } + pub fn clear_path(&mut self) { + self.path.clear(); + } + + // Param is passed by value, moved + pub fn set_path(&mut self, v: ::std::string::String) { + self.path = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_path(&mut self) -> &mut ::std::string::String { + &mut self.path + } + + // Take field + pub fn take_path(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.path, ::std::string::String::new()) + } +} + +impl ::protobuf::Message for DocInfo { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.id)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?; + }, + 3 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.desc)?; + }, + 4 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.path)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.id); + } + if !self.name.is_empty() { + my_size += ::protobuf::rt::string_size(2, &self.name); + } + if !self.desc.is_empty() { + my_size += ::protobuf::rt::string_size(3, &self.desc); + } + if !self.path.is_empty() { + my_size += ::protobuf::rt::string_size(4, &self.path); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.id.is_empty() { + os.write_string(1, &self.id)?; + } + if !self.name.is_empty() { + os.write_string(2, &self.name)?; + } + if !self.desc.is_empty() { + os.write_string(3, &self.desc)?; + } + if !self.path.is_empty() { + os.write_string(4, &self.path)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> DocInfo { + DocInfo::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "id", + |m: &DocInfo| { &m.id }, + |m: &mut DocInfo| { &mut m.id }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "name", + |m: &DocInfo| { &m.name }, + |m: &mut DocInfo| { &mut m.name }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "desc", + |m: &DocInfo| { &m.desc }, + |m: &mut DocInfo| { &mut m.desc }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "path", + |m: &DocInfo| { &m.path }, + |m: &mut DocInfo| { &mut m.path }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "DocInfo", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static DocInfo { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(DocInfo::new) + } +} + +impl ::protobuf::Clear for DocInfo { + fn clear(&mut self) { + self.id.clear(); + self.name.clear(); + self.desc.clear(); + self.path.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for DocInfo { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for DocInfo { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct DocData { + // message fields + pub text: ::std::string::String, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a DocData { + fn default() -> &'a DocData { + ::default_instance() + } +} + +impl DocData { + pub fn new() -> DocData { + ::std::default::Default::default() + } + + // string text = 1; + + + pub fn get_text(&self) -> &str { + &self.text + } + pub fn clear_text(&mut self) { + self.text.clear(); + } + + // Param is passed by value, moved + pub fn set_text(&mut self, v: ::std::string::String) { + self.text = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_text(&mut self) -> &mut ::std::string::String { + &mut self.text + } + + // Take field + pub fn take_text(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.text, ::std::string::String::new()) + } +} + +impl ::protobuf::Message for DocData { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.text)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.text.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.text); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.text.is_empty() { + os.write_string(1, &self.text)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> DocData { + DocData::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "text", + |m: &DocData| { &m.text }, + |m: &mut DocData| { &mut m.text }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "DocData", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static DocData { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(DocData::new) + } +} + +impl ::protobuf::Clear for DocData { + fn clear(&mut self) { + self.text.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for DocData { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for DocData { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x10doc_create.proto\"^\n\x10CreateDocRequest\x12\x0e\n\x02id\x18\x01\ + \x20\x01(\tR\x02id\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\x12\ + \n\x04desc\x18\x03\x20\x01(\tR\x04desc\x12\x12\n\x04text\x18\x04\x20\x01\ + (\tR\x04text\"U\n\x07DocInfo\x12\x0e\n\x02id\x18\x01\x20\x01(\tR\x02id\ + \x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\x12\n\x04desc\x18\x03\ + \x20\x01(\tR\x04desc\x12\x12\n\x04path\x18\x04\x20\x01(\tR\x04path\"\x1d\ + \n\x07DocData\x12\x12\n\x04text\x18\x01\x20\x01(\tR\x04textJ\xc9\x04\n\ + \x06\x12\x04\0\0\x10\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\ + \x12\x04\x02\0\x07\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x18\n\x0b\n\ + \x04\x04\0\x02\0\x12\x03\x03\x04\x12\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\ + \x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\r\n\x0c\n\x05\x04\ + \0\x02\0\x03\x12\x03\x03\x10\x11\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\ + \x04\x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\ + \0\x02\x01\x01\x12\x03\x04\x0b\x0f\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\ + \x04\x12\x13\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x04\x14\n\x0c\n\x05\ + \x04\0\x02\x02\x05\x12\x03\x05\x04\n\n\x0c\n\x05\x04\0\x02\x02\x01\x12\ + \x03\x05\x0b\x0f\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x12\x13\n\x0b\ + \n\x04\x04\0\x02\x03\x12\x03\x06\x04\x14\n\x0c\n\x05\x04\0\x02\x03\x05\ + \x12\x03\x06\x04\n\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06\x0b\x0f\n\ + \x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x06\x12\x13\n\n\n\x02\x04\x01\x12\ + \x04\x08\0\r\x01\n\n\n\x03\x04\x01\x01\x12\x03\x08\x08\x0f\n\x0b\n\x04\ + \x04\x01\x02\0\x12\x03\t\x04\x12\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\t\ + \x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\t\x0b\r\n\x0c\n\x05\x04\x01\ + \x02\0\x03\x12\x03\t\x10\x11\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\n\x04\ + \x14\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\n\x04\n\n\x0c\n\x05\x04\x01\ + \x02\x01\x01\x12\x03\n\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\n\ + \x12\x13\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\x0b\x04\x14\n\x0c\n\x05\x04\ + \x01\x02\x02\x05\x12\x03\x0b\x04\n\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\ + \x03\x0b\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\x0b\x12\x13\n\ + \x0b\n\x04\x04\x01\x02\x03\x12\x03\x0c\x04\x14\n\x0c\n\x05\x04\x01\x02\ + \x03\x05\x12\x03\x0c\x04\n\n\x0c\n\x05\x04\x01\x02\x03\x01\x12\x03\x0c\ + \x0b\x0f\n\x0c\n\x05\x04\x01\x02\x03\x03\x12\x03\x0c\x12\x13\n\n\n\x02\ + \x04\x02\x12\x04\x0e\0\x10\x01\n\n\n\x03\x04\x02\x01\x12\x03\x0e\x08\x0f\ + \n\x0b\n\x04\x04\x02\x02\0\x12\x03\x0f\x04\x14\n\x0c\n\x05\x04\x02\x02\0\ + \x05\x12\x03\x0f\x04\n\n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03\x0f\x0b\x0f\ + \n\x0c\n\x05\x04\x02\x02\0\x03\x12\x03\x0f\x12\x13b\x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-editor/src/protobuf/model/doc_modify.rs b/rust-lib/flowy-editor/src/protobuf/model/doc_modify.rs new file mode 100644 index 0000000000..ac288b1b27 --- /dev/null +++ b/rust-lib/flowy-editor/src/protobuf/model/doc_modify.rs @@ -0,0 +1,463 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `doc_modify.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct UpdateDocRequest { + // message fields + pub id: ::std::string::String, + // message oneof groups + pub one_of_name: ::std::option::Option, + pub one_of_desc: ::std::option::Option, + pub one_of_text: ::std::option::Option, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a UpdateDocRequest { + fn default() -> &'a UpdateDocRequest { + ::default_instance() + } +} + +#[derive(Clone,PartialEq,Debug)] +pub enum UpdateDocRequest_oneof_one_of_name { + name(::std::string::String), +} + +#[derive(Clone,PartialEq,Debug)] +pub enum UpdateDocRequest_oneof_one_of_desc { + desc(::std::string::String), +} + +#[derive(Clone,PartialEq,Debug)] +pub enum UpdateDocRequest_oneof_one_of_text { + text(::std::string::String), +} + +impl UpdateDocRequest { + pub fn new() -> UpdateDocRequest { + ::std::default::Default::default() + } + + // string id = 1; + + + pub fn get_id(&self) -> &str { + &self.id + } + pub fn clear_id(&mut self) { + self.id.clear(); + } + + // Param is passed by value, moved + pub fn set_id(&mut self, v: ::std::string::String) { + self.id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_id(&mut self) -> &mut ::std::string::String { + &mut self.id + } + + // Take field + pub fn take_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.id, ::std::string::String::new()) + } + + // string name = 2; + + + pub fn get_name(&self) -> &str { + match self.one_of_name { + ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_name::name(ref v)) => v, + _ => "", + } + } + pub fn clear_name(&mut self) { + self.one_of_name = ::std::option::Option::None; + } + + pub fn has_name(&self) -> bool { + match self.one_of_name { + ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_name::name(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_name(&mut self, v: ::std::string::String) { + self.one_of_name = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_name::name(v)) + } + + // Mutable pointer to the field. + pub fn mut_name(&mut self) -> &mut ::std::string::String { + if let ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_name::name(_)) = self.one_of_name { + } else { + self.one_of_name = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_name::name(::std::string::String::new())); + } + match self.one_of_name { + ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_name::name(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_name(&mut self) -> ::std::string::String { + if self.has_name() { + match self.one_of_name.take() { + ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_name::name(v)) => v, + _ => panic!(), + } + } else { + ::std::string::String::new() + } + } + + // string desc = 3; + + + pub fn get_desc(&self) -> &str { + match self.one_of_desc { + ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_desc::desc(ref v)) => v, + _ => "", + } + } + pub fn clear_desc(&mut self) { + self.one_of_desc = ::std::option::Option::None; + } + + pub fn has_desc(&self) -> bool { + match self.one_of_desc { + ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_desc::desc(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_desc(&mut self, v: ::std::string::String) { + self.one_of_desc = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_desc::desc(v)) + } + + // Mutable pointer to the field. + pub fn mut_desc(&mut self) -> &mut ::std::string::String { + if let ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_desc::desc(_)) = self.one_of_desc { + } else { + self.one_of_desc = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_desc::desc(::std::string::String::new())); + } + match self.one_of_desc { + ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_desc::desc(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_desc(&mut self) -> ::std::string::String { + if self.has_desc() { + match self.one_of_desc.take() { + ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_desc::desc(v)) => v, + _ => panic!(), + } + } else { + ::std::string::String::new() + } + } + + // string text = 4; + + + pub fn get_text(&self) -> &str { + match self.one_of_text { + ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(ref v)) => v, + _ => "", + } + } + pub fn clear_text(&mut self) { + self.one_of_text = ::std::option::Option::None; + } + + pub fn has_text(&self) -> bool { + match self.one_of_text { + ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_text(&mut self, v: ::std::string::String) { + self.one_of_text = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(v)) + } + + // Mutable pointer to the field. + pub fn mut_text(&mut self) -> &mut ::std::string::String { + if let ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(_)) = self.one_of_text { + } else { + self.one_of_text = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(::std::string::String::new())); + } + match self.one_of_text { + ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_text(&mut self) -> ::std::string::String { + if self.has_text() { + match self.one_of_text.take() { + ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(v)) => v, + _ => panic!(), + } + } else { + ::std::string::String::new() + } + } +} + +impl ::protobuf::Message for UpdateDocRequest { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.id)?; + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.one_of_name = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_name::name(is.read_string()?)); + }, + 3 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.one_of_desc = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_desc::desc(is.read_string()?)); + }, + 4 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.one_of_text = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(is.read_string()?)); + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.id); + } + if let ::std::option::Option::Some(ref v) = self.one_of_name { + match v { + &UpdateDocRequest_oneof_one_of_name::name(ref v) => { + my_size += ::protobuf::rt::string_size(2, &v); + }, + }; + } + if let ::std::option::Option::Some(ref v) = self.one_of_desc { + match v { + &UpdateDocRequest_oneof_one_of_desc::desc(ref v) => { + my_size += ::protobuf::rt::string_size(3, &v); + }, + }; + } + if let ::std::option::Option::Some(ref v) = self.one_of_text { + match v { + &UpdateDocRequest_oneof_one_of_text::text(ref v) => { + my_size += ::protobuf::rt::string_size(4, &v); + }, + }; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.id.is_empty() { + os.write_string(1, &self.id)?; + } + if let ::std::option::Option::Some(ref v) = self.one_of_name { + match v { + &UpdateDocRequest_oneof_one_of_name::name(ref v) => { + os.write_string(2, v)?; + }, + }; + } + if let ::std::option::Option::Some(ref v) = self.one_of_desc { + match v { + &UpdateDocRequest_oneof_one_of_desc::desc(ref v) => { + os.write_string(3, v)?; + }, + }; + } + if let ::std::option::Option::Some(ref v) = self.one_of_text { + match v { + &UpdateDocRequest_oneof_one_of_text::text(ref v) => { + os.write_string(4, v)?; + }, + }; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> UpdateDocRequest { + UpdateDocRequest::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "id", + |m: &UpdateDocRequest| { &m.id }, + |m: &mut UpdateDocRequest| { &mut m.id }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_string_accessor::<_>( + "name", + UpdateDocRequest::has_name, + UpdateDocRequest::get_name, + )); + fields.push(::protobuf::reflect::accessor::make_singular_string_accessor::<_>( + "desc", + UpdateDocRequest::has_desc, + UpdateDocRequest::get_desc, + )); + fields.push(::protobuf::reflect::accessor::make_singular_string_accessor::<_>( + "text", + UpdateDocRequest::has_text, + UpdateDocRequest::get_text, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "UpdateDocRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static UpdateDocRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(UpdateDocRequest::new) + } +} + +impl ::protobuf::Clear for UpdateDocRequest { + fn clear(&mut self) { + self.id.clear(); + self.one_of_name = ::std::option::Option::None; + self.one_of_desc = ::std::option::Option::None; + self.one_of_text = ::std::option::Option::None; + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for UpdateDocRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for UpdateDocRequest { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x10doc_modify.proto\"\x91\x01\n\x10UpdateDocRequest\x12\x0e\n\x02id\ + \x18\x01\x20\x01(\tR\x02id\x12\x14\n\x04name\x18\x02\x20\x01(\tH\0R\x04n\ + ame\x12\x14\n\x04desc\x18\x03\x20\x01(\tH\x01R\x04desc\x12\x14\n\x04text\ + \x18\x04\x20\x01(\tH\x02R\x04textB\r\n\x0bone_of_nameB\r\n\x0bone_of_des\ + cB\r\n\x0bone_of_textJ\xd7\x02\n\x06\x12\x04\0\0\x07\x01\n\x08\n\x01\x0c\ + \x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x07\x01\n\n\n\x03\x04\0\ + \x01\x12\x03\x02\x08\x18\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x12\n\ + \x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\ + \x12\x03\x03\x0b\r\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x10\x11\n\x0b\ + \n\x04\x04\0\x08\0\x12\x03\x04\x04*\n\x0c\n\x05\x04\0\x08\0\x01\x12\x03\ + \x04\n\x15\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x18(\n\x0c\n\x05\x04\0\ + \x02\x01\x05\x12\x03\x04\x18\x1e\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\ + \x04\x1f#\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04&'\n\x0b\n\x04\x04\0\ + \x08\x01\x12\x03\x05\x04*\n\x0c\n\x05\x04\0\x08\x01\x01\x12\x03\x05\n\ + \x15\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x18(\n\x0c\n\x05\x04\0\x02\ + \x02\x05\x12\x03\x05\x18\x1e\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x05\ + \x1f#\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05&'\n\x0b\n\x04\x04\0\x08\ + \x02\x12\x03\x06\x04*\n\x0c\n\x05\x04\0\x08\x02\x01\x12\x03\x06\n\x15\n\ + \x0b\n\x04\x04\0\x02\x03\x12\x03\x06\x18(\n\x0c\n\x05\x04\0\x02\x03\x05\ + \x12\x03\x06\x18\x1e\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06\x1f#\n\ + \x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x06&'b\x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-editor/src/protobuf/model/doc_query.rs b/rust-lib/flowy-editor/src/protobuf/model/doc_query.rs new file mode 100644 index 0000000000..1c9f44d181 --- /dev/null +++ b/rust-lib/flowy-editor/src/protobuf/model/doc_query.rs @@ -0,0 +1,414 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `doc_query.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct QueryDocRequest { + // message fields + pub doc_id: ::std::string::String, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a QueryDocRequest { + fn default() -> &'a QueryDocRequest { + ::default_instance() + } +} + +impl QueryDocRequest { + pub fn new() -> QueryDocRequest { + ::std::default::Default::default() + } + + // string doc_id = 1; + + + pub fn get_doc_id(&self) -> &str { + &self.doc_id + } + pub fn clear_doc_id(&mut self) { + self.doc_id.clear(); + } + + // Param is passed by value, moved + pub fn set_doc_id(&mut self, v: ::std::string::String) { + self.doc_id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_doc_id(&mut self) -> &mut ::std::string::String { + &mut self.doc_id + } + + // Take field + pub fn take_doc_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.doc_id, ::std::string::String::new()) + } +} + +impl ::protobuf::Message for QueryDocRequest { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.doc_id)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.doc_id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.doc_id); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.doc_id.is_empty() { + os.write_string(1, &self.doc_id)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> QueryDocRequest { + QueryDocRequest::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "doc_id", + |m: &QueryDocRequest| { &m.doc_id }, + |m: &mut QueryDocRequest| { &mut m.doc_id }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "QueryDocRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static QueryDocRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(QueryDocRequest::new) + } +} + +impl ::protobuf::Clear for QueryDocRequest { + fn clear(&mut self) { + self.doc_id.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for QueryDocRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for QueryDocRequest { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct QueryDocDataRequest { + // message fields + pub doc_id: ::std::string::String, + pub path: ::std::string::String, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a QueryDocDataRequest { + fn default() -> &'a QueryDocDataRequest { + ::default_instance() + } +} + +impl QueryDocDataRequest { + pub fn new() -> QueryDocDataRequest { + ::std::default::Default::default() + } + + // string doc_id = 1; + + + pub fn get_doc_id(&self) -> &str { + &self.doc_id + } + pub fn clear_doc_id(&mut self) { + self.doc_id.clear(); + } + + // Param is passed by value, moved + pub fn set_doc_id(&mut self, v: ::std::string::String) { + self.doc_id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_doc_id(&mut self) -> &mut ::std::string::String { + &mut self.doc_id + } + + // Take field + pub fn take_doc_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.doc_id, ::std::string::String::new()) + } + + // string path = 2; + + + pub fn get_path(&self) -> &str { + &self.path + } + pub fn clear_path(&mut self) { + self.path.clear(); + } + + // Param is passed by value, moved + pub fn set_path(&mut self, v: ::std::string::String) { + self.path = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_path(&mut self) -> &mut ::std::string::String { + &mut self.path + } + + // Take field + pub fn take_path(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.path, ::std::string::String::new()) + } +} + +impl ::protobuf::Message for QueryDocDataRequest { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.doc_id)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.path)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.doc_id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.doc_id); + } + if !self.path.is_empty() { + my_size += ::protobuf::rt::string_size(2, &self.path); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.doc_id.is_empty() { + os.write_string(1, &self.doc_id)?; + } + if !self.path.is_empty() { + os.write_string(2, &self.path)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> QueryDocDataRequest { + QueryDocDataRequest::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "doc_id", + |m: &QueryDocDataRequest| { &m.doc_id }, + |m: &mut QueryDocDataRequest| { &mut m.doc_id }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "path", + |m: &QueryDocDataRequest| { &m.path }, + |m: &mut QueryDocDataRequest| { &mut m.path }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "QueryDocDataRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static QueryDocDataRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(QueryDocDataRequest::new) + } +} + +impl ::protobuf::Clear for QueryDocDataRequest { + fn clear(&mut self) { + self.doc_id.clear(); + self.path.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for QueryDocDataRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for QueryDocDataRequest { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x0fdoc_query.proto\"(\n\x0fQueryDocRequest\x12\x15\n\x06doc_id\x18\ + \x01\x20\x01(\tR\x05docId\"@\n\x13QueryDocDataRequest\x12\x15\n\x06doc_i\ + d\x18\x01\x20\x01(\tR\x05docId\x12\x12\n\x04path\x18\x02\x20\x01(\tR\x04\ + pathJ\xe7\x01\n\x06\x12\x04\0\0\x08\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\ + \n\n\n\x02\x04\0\x12\x04\x02\0\x04\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\ + \x08\x17\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x16\n\x0c\n\x05\x04\0\ + \x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\ + \x11\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x14\x15\n\n\n\x02\x04\x01\ + \x12\x04\x05\0\x08\x01\n\n\n\x03\x04\x01\x01\x12\x03\x05\x08\x1b\n\x0b\n\ + \x04\x04\x01\x02\0\x12\x03\x06\x04\x16\n\x0c\n\x05\x04\x01\x02\0\x05\x12\ + \x03\x06\x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\x06\x0b\x11\n\x0c\n\ + \x05\x04\x01\x02\0\x03\x12\x03\x06\x14\x15\n\x0b\n\x04\x04\x01\x02\x01\ + \x12\x03\x07\x04\x14\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\x07\x04\n\n\ + \x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x07\x0b\x0f\n\x0c\n\x05\x04\x01\ + \x02\x01\x03\x12\x03\x07\x12\x13b\x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-editor/src/protobuf/model/errors.rs b/rust-lib/flowy-editor/src/protobuf/model/errors.rs new file mode 100644 index 0000000000..9cd328d33a --- /dev/null +++ b/rust-lib/flowy-editor/src/protobuf/model/errors.rs @@ -0,0 +1,334 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `errors.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct EditorError { + // message fields + pub code: EditorErrorCode, + pub msg: ::std::string::String, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a EditorError { + fn default() -> &'a EditorError { + ::default_instance() + } +} + +impl EditorError { + pub fn new() -> EditorError { + ::std::default::Default::default() + } + + // .EditorErrorCode code = 1; + + + pub fn get_code(&self) -> EditorErrorCode { + self.code + } + pub fn clear_code(&mut self) { + self.code = EditorErrorCode::Unknown; + } + + // Param is passed by value, moved + pub fn set_code(&mut self, v: EditorErrorCode) { + self.code = v; + } + + // string msg = 2; + + + pub fn get_msg(&self) -> &str { + &self.msg + } + pub fn clear_msg(&mut self) { + self.msg.clear(); + } + + // Param is passed by value, moved + pub fn set_msg(&mut self, v: ::std::string::String) { + self.msg = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_msg(&mut self) -> &mut ::std::string::String { + &mut self.msg + } + + // Take field + pub fn take_msg(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.msg, ::std::string::String::new()) + } +} + +impl ::protobuf::Message for EditorError { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_proto3_enum_with_unknown_fields_into(wire_type, is, &mut self.code, 1, &mut self.unknown_fields)? + }, + 2 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.msg)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if self.code != EditorErrorCode::Unknown { + my_size += ::protobuf::rt::enum_size(1, self.code); + } + if !self.msg.is_empty() { + my_size += ::protobuf::rt::string_size(2, &self.msg); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if self.code != EditorErrorCode::Unknown { + os.write_enum(1, ::protobuf::ProtobufEnum::value(&self.code))?; + } + if !self.msg.is_empty() { + os.write_string(2, &self.msg)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> EditorError { + EditorError::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( + "code", + |m: &EditorError| { &m.code }, + |m: &mut EditorError| { &mut m.code }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "msg", + |m: &EditorError| { &m.msg }, + |m: &mut EditorError| { &mut m.msg }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "EditorError", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static EditorError { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(EditorError::new) + } +} + +impl ::protobuf::Clear for EditorError { + fn clear(&mut self) { + self.code = EditorErrorCode::Unknown; + self.msg.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for EditorError { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for EditorError { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(Clone,PartialEq,Eq,Debug,Hash)] +pub enum EditorErrorCode { + Unknown = 0, + EditorDBInternalError = 1, + EditorDBConnFailed = 2, + DocNameInvalid = 10, + DocViewIdInvalid = 11, + DocDescTooLong = 12, + DocOpenFileError = 13, + DocFilePathInvalid = 14, + EditorUserNotLoginYet = 100, +} + +impl ::protobuf::ProtobufEnum for EditorErrorCode { + fn value(&self) -> i32 { + *self as i32 + } + + fn from_i32(value: i32) -> ::std::option::Option { + match value { + 0 => ::std::option::Option::Some(EditorErrorCode::Unknown), + 1 => ::std::option::Option::Some(EditorErrorCode::EditorDBInternalError), + 2 => ::std::option::Option::Some(EditorErrorCode::EditorDBConnFailed), + 10 => ::std::option::Option::Some(EditorErrorCode::DocNameInvalid), + 11 => ::std::option::Option::Some(EditorErrorCode::DocViewIdInvalid), + 12 => ::std::option::Option::Some(EditorErrorCode::DocDescTooLong), + 13 => ::std::option::Option::Some(EditorErrorCode::DocOpenFileError), + 14 => ::std::option::Option::Some(EditorErrorCode::DocFilePathInvalid), + 100 => ::std::option::Option::Some(EditorErrorCode::EditorUserNotLoginYet), + _ => ::std::option::Option::None + } + } + + fn values() -> &'static [Self] { + static values: &'static [EditorErrorCode] = &[ + EditorErrorCode::Unknown, + EditorErrorCode::EditorDBInternalError, + EditorErrorCode::EditorDBConnFailed, + EditorErrorCode::DocNameInvalid, + EditorErrorCode::DocViewIdInvalid, + EditorErrorCode::DocDescTooLong, + EditorErrorCode::DocOpenFileError, + EditorErrorCode::DocFilePathInvalid, + EditorErrorCode::EditorUserNotLoginYet, + ]; + values + } + + fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::EnumDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + ::protobuf::reflect::EnumDescriptor::new_pb_name::("EditorErrorCode", file_descriptor_proto()) + }) + } +} + +impl ::std::marker::Copy for EditorErrorCode { +} + +impl ::std::default::Default for EditorErrorCode { + fn default() -> Self { + EditorErrorCode::Unknown + } +} + +impl ::protobuf::reflect::ProtobufValue for EditorErrorCode { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Enum(::protobuf::ProtobufEnum::descriptor(self)) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x0cerrors.proto\"E\n\x0bEditorError\x12$\n\x04code\x18\x01\x20\x01(\ + \x0e2\x10.EditorErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\tR\ + \x03msg*\xd8\x01\n\x0fEditorErrorCode\x12\x0b\n\x07Unknown\x10\0\x12\x19\ + \n\x15EditorDBInternalError\x10\x01\x12\x16\n\x12EditorDBConnFailed\x10\ + \x02\x12\x12\n\x0eDocNameInvalid\x10\n\x12\x14\n\x10DocViewIdInvalid\x10\ + \x0b\x12\x12\n\x0eDocDescTooLong\x10\x0c\x12\x14\n\x10DocOpenFileError\ + \x10\r\x12\x16\n\x12DocFilePathInvalid\x10\x0e\x12\x19\n\x15EditorUserNo\ + tLoginYet\x10dJ\xa1\x04\n\x06\x12\x04\0\0\x10\x01\n\x08\n\x01\x0c\x12\ + \x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\ + \x12\x03\x02\x08\x13\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x1d\n\x0c\n\ + \x05\x04\0\x02\0\x06\x12\x03\x03\x04\x13\n\x0c\n\x05\x04\0\x02\0\x01\x12\ + \x03\x03\x14\x18\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x1b\x1c\n\x0b\n\ + \x04\x04\0\x02\x01\x12\x03\x04\x04\x13\n\x0c\n\x05\x04\0\x02\x01\x05\x12\ + \x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0e\n\x0c\n\ + \x05\x04\0\x02\x01\x03\x12\x03\x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\ + \x10\x01\n\n\n\x03\x05\0\x01\x12\x03\x06\x05\x14\n\x0b\n\x04\x05\0\x02\0\ + \x12\x03\x07\x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x07\x04\x0b\n\ + \x0c\n\x05\x05\0\x02\0\x02\x12\x03\x07\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\ + \x12\x03\x08\x04\x1e\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x08\x04\x19\n\ + \x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x08\x1c\x1d\n\x0b\n\x04\x05\0\x02\ + \x02\x12\x03\t\x04\x1b\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\t\x04\x16\n\ + \x0c\n\x05\x05\0\x02\x02\x02\x12\x03\t\x19\x1a\n\x0b\n\x04\x05\0\x02\x03\ + \x12\x03\n\x04\x18\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\n\x04\x12\n\x0c\ + \n\x05\x05\0\x02\x03\x02\x12\x03\n\x15\x17\n\x0b\n\x04\x05\0\x02\x04\x12\ + \x03\x0b\x04\x1a\n\x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x0b\x04\x14\n\x0c\ + \n\x05\x05\0\x02\x04\x02\x12\x03\x0b\x17\x19\n\x0b\n\x04\x05\0\x02\x05\ + \x12\x03\x0c\x04\x18\n\x0c\n\x05\x05\0\x02\x05\x01\x12\x03\x0c\x04\x12\n\ + \x0c\n\x05\x05\0\x02\x05\x02\x12\x03\x0c\x15\x17\n\x0b\n\x04\x05\0\x02\ + \x06\x12\x03\r\x04\x1a\n\x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\x04\x14\n\ + \x0c\n\x05\x05\0\x02\x06\x02\x12\x03\r\x17\x19\n\x0b\n\x04\x05\0\x02\x07\ + \x12\x03\x0e\x04\x1c\n\x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x16\n\ + \x0c\n\x05\x05\0\x02\x07\x02\x12\x03\x0e\x19\x1b\n\x0b\n\x04\x05\0\x02\ + \x08\x12\x03\x0f\x04\x20\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0f\x04\ + \x19\n\x0c\n\x05\x05\0\x02\x08\x02\x12\x03\x0f\x1c\x1fb\x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-editor/src/protobuf/model/event.rs b/rust-lib/flowy-editor/src/protobuf/model/event.rs new file mode 100644 index 0000000000..fe3c902008 --- /dev/null +++ b/rust-lib/flowy-editor/src/protobuf/model/event.rs @@ -0,0 +1,108 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `event.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(Clone,PartialEq,Eq,Debug,Hash)] +pub enum EditorEvent { + CreateDoc = 0, + UpdateDoc = 1, + ReadDocInfo = 2, + ReadDocData = 3, +} + +impl ::protobuf::ProtobufEnum for EditorEvent { + fn value(&self) -> i32 { + *self as i32 + } + + fn from_i32(value: i32) -> ::std::option::Option { + match value { + 0 => ::std::option::Option::Some(EditorEvent::CreateDoc), + 1 => ::std::option::Option::Some(EditorEvent::UpdateDoc), + 2 => ::std::option::Option::Some(EditorEvent::ReadDocInfo), + 3 => ::std::option::Option::Some(EditorEvent::ReadDocData), + _ => ::std::option::Option::None + } + } + + fn values() -> &'static [Self] { + static values: &'static [EditorEvent] = &[ + EditorEvent::CreateDoc, + EditorEvent::UpdateDoc, + EditorEvent::ReadDocInfo, + EditorEvent::ReadDocData, + ]; + values + } + + fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::EnumDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + ::protobuf::reflect::EnumDescriptor::new_pb_name::("EditorEvent", file_descriptor_proto()) + }) + } +} + +impl ::std::marker::Copy for EditorEvent { +} + +impl ::std::default::Default for EditorEvent { + fn default() -> Self { + EditorEvent::CreateDoc + } +} + +impl ::protobuf::reflect::ProtobufValue for EditorEvent { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Enum(::protobuf::ProtobufEnum::descriptor(self)) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x0bevent.proto*M\n\x0bEditorEvent\x12\r\n\tCreateDoc\x10\0\x12\r\n\tU\ + pdateDoc\x10\x01\x12\x0f\n\x0bReadDocInfo\x10\x02\x12\x0f\n\x0bReadDocDa\ + ta\x10\x03J\xce\x01\n\x06\x12\x04\0\0\x07\x01\n\x08\n\x01\x0c\x12\x03\0\ + \0\x12\n\n\n\x02\x05\0\x12\x04\x02\0\x07\x01\n\n\n\x03\x05\0\x01\x12\x03\ + \x02\x05\x10\n\x0b\n\x04\x05\0\x02\0\x12\x03\x03\x04\x12\n\x0c\n\x05\x05\ + \0\x02\0\x01\x12\x03\x03\x04\r\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x03\ + \x10\x11\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x04\x04\x12\n\x0c\n\x05\x05\0\ + \x02\x01\x01\x12\x03\x04\x04\r\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x04\ + \x10\x11\n\x0b\n\x04\x05\0\x02\x02\x12\x03\x05\x04\x14\n\x0c\n\x05\x05\0\ + \x02\x02\x01\x12\x03\x05\x04\x0f\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\ + \x05\x12\x13\n\x0b\n\x04\x05\0\x02\x03\x12\x03\x06\x04\x14\n\x0c\n\x05\ + \x05\0\x02\x03\x01\x12\x03\x06\x04\x0f\n\x0c\n\x05\x05\0\x02\x03\x02\x12\ + \x03\x06\x12\x13b\x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-editor/src/protobuf/model/mod.rs b/rust-lib/flowy-editor/src/protobuf/model/mod.rs new file mode 100644 index 0000000000..4bea143a13 --- /dev/null +++ b/rust-lib/flowy-editor/src/protobuf/model/mod.rs @@ -0,0 +1,16 @@ +// Auto-generated, do not edit + +mod doc_modify; +pub use doc_modify::*; + +mod doc_create; +pub use doc_create::*; + +mod errors; +pub use errors::*; + +mod event; +pub use event::*; + +mod doc_query; +pub use doc_query::*; diff --git a/rust-lib/flowy-editor/src/protobuf/proto/doc_create.proto b/rust-lib/flowy-editor/src/protobuf/proto/doc_create.proto new file mode 100644 index 0000000000..463f22022e --- /dev/null +++ b/rust-lib/flowy-editor/src/protobuf/proto/doc_create.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +message CreateDocRequest { + string id = 1; + string name = 2; + string desc = 3; + string text = 4; +} +message DocInfo { + string id = 1; + string name = 2; + string desc = 3; + string path = 4; +} +message DocData { + string text = 1; +} diff --git a/rust-lib/flowy-editor/src/protobuf/proto/doc_modify.proto b/rust-lib/flowy-editor/src/protobuf/proto/doc_modify.proto new file mode 100644 index 0000000000..a92b4ef23c --- /dev/null +++ b/rust-lib/flowy-editor/src/protobuf/proto/doc_modify.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +message UpdateDocRequest { + string id = 1; + oneof one_of_name { string name = 2; }; + oneof one_of_desc { string desc = 3; }; + oneof one_of_text { string text = 4; }; +} diff --git a/rust-lib/flowy-editor/src/protobuf/proto/doc_query.proto b/rust-lib/flowy-editor/src/protobuf/proto/doc_query.proto new file mode 100644 index 0000000000..e4b827e3a7 --- /dev/null +++ b/rust-lib/flowy-editor/src/protobuf/proto/doc_query.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +message QueryDocRequest { + string doc_id = 1; +} +message QueryDocDataRequest { + string doc_id = 1; + string path = 2; +} diff --git a/rust-lib/flowy-editor/src/protobuf/proto/errors.proto b/rust-lib/flowy-editor/src/protobuf/proto/errors.proto new file mode 100644 index 0000000000..a63ee113ac --- /dev/null +++ b/rust-lib/flowy-editor/src/protobuf/proto/errors.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +message EditorError { + EditorErrorCode code = 1; + string msg = 2; +} +enum EditorErrorCode { + Unknown = 0; + EditorDBInternalError = 1; + EditorDBConnFailed = 2; + DocNameInvalid = 10; + DocViewIdInvalid = 11; + DocDescTooLong = 12; + DocOpenFileError = 13; + DocFilePathInvalid = 14; + EditorUserNotLoginYet = 100; +} diff --git a/rust-lib/flowy-editor/src/protobuf/proto/event.proto b/rust-lib/flowy-editor/src/protobuf/proto/event.proto new file mode 100644 index 0000000000..f4cb158adc --- /dev/null +++ b/rust-lib/flowy-editor/src/protobuf/proto/event.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +enum EditorEvent { + CreateDoc = 0; + UpdateDoc = 1; + ReadDocInfo = 2; + ReadDocData = 3; +} diff --git a/rust-lib/flowy-editor/src/services/doc_controller.rs b/rust-lib/flowy-editor/src/services/doc_controller.rs new file mode 100644 index 0000000000..995063fe11 --- /dev/null +++ b/rust-lib/flowy-editor/src/services/doc_controller.rs @@ -0,0 +1,42 @@ +use crate::{ + entities::doc::{CreateDocParams, DocData, DocInfo, QueryDocParams, UpdateDocParams}, + errors::EditorError, + module::EditorDatabase, + sql_tables::doc::{DocTable, DocTableChangeset, DocTableSql}, +}; +use std::sync::Arc; + +pub struct DocController { + sql: Arc, +} + +impl DocController { + pub(crate) fn new(database: Arc) -> Self { + let sql = Arc::new(DocTableSql { database }); + Self { sql } + } + + pub(crate) async fn create_doc( + &self, + params: CreateDocParams, + path: &str, + ) -> Result { + let doc_table = DocTable::new(params, path); + let doc: DocInfo = doc_table.clone().into(); + let _ = self.sql.create_doc_table(doc_table)?; + + Ok(doc) + } + + pub(crate) async fn update_doc(&self, params: UpdateDocParams) -> Result<(), EditorError> { + let changeset = DocTableChangeset::new(params); + let _ = self.sql.update_doc_table(changeset)?; + Ok(()) + } + + pub(crate) async fn read_doc(&self, doc_id: &str) -> Result { + let doc_table = self.sql.read_doc_table(doc_id)?; + let doc_desc: DocInfo = doc_table.into(); + Ok(doc_desc) + } +} diff --git a/rust-lib/flowy-editor/src/services/file_manager/file.rs b/rust-lib/flowy-editor/src/services/file_manager/file.rs new file mode 100644 index 0000000000..610963f9cd --- /dev/null +++ b/rust-lib/flowy-editor/src/services/file_manager/file.rs @@ -0,0 +1,130 @@ +use std::{ + ffi::OsString, + fs, + fs::File, + io, + io::{Read, Write}, + path::{Path, PathBuf}, + str, + sync::atomic::{AtomicUsize, Ordering}, + time::SystemTime, +}; + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct FileId(pub(crate) String); + +impl std::convert::From for FileId { + fn from(s: String) -> Self { FileId(s) } +} + +#[derive(Debug, Clone, Copy)] +pub enum CharacterEncoding { + Utf8, + Utf8WithBom, +} + +const UTF8_BOM: &str = "\u{feff}"; +impl CharacterEncoding { + pub(crate) fn guess(s: &[u8]) -> Self { + if s.starts_with(UTF8_BOM.as_bytes()) { + CharacterEncoding::Utf8WithBom + } else { + CharacterEncoding::Utf8 + } + } +} + +#[derive(Debug)] +pub enum FileError { + Io(io::Error, PathBuf), + UnknownEncoding(PathBuf), + HasChanged(PathBuf), +} + +#[derive(Clone, Debug)] +pub struct FileInfo { + pub path: PathBuf, + pub modified_time: Option, + pub has_changed: bool, + pub encoding: CharacterEncoding, +} + +pub(crate) fn try_load_file

(path: P) -> Result<(String, FileInfo), FileError> +where + P: AsRef, +{ + let mut f = + File::open(path.as_ref()).map_err(|e| FileError::Io(e, path.as_ref().to_owned()))?; + let mut bytes = Vec::new(); + f.read_to_end(&mut bytes) + .map_err(|e| FileError::Io(e, path.as_ref().to_owned()))?; + + let encoding = CharacterEncoding::guess(&bytes); + let s = try_decode(bytes, encoding, path.as_ref())?; + let info = FileInfo { + encoding, + path: path.as_ref().to_owned(), + modified_time: get_modified_time(&path), + has_changed: false, + }; + Ok((s, info)) +} + +pub(crate) fn try_save( + path: &Path, + text: &str, + encoding: CharacterEncoding, + _file_info: Option<&FileInfo>, +) -> io::Result<()> { + let tmp_extension = path.extension().map_or_else( + || OsString::from("swp"), + |ext| { + let mut ext = ext.to_os_string(); + ext.push(".swp"); + ext + }, + ); + let tmp_path = &path.with_extension(tmp_extension); + + let mut f = File::create(tmp_path)?; + match encoding { + CharacterEncoding::Utf8WithBom => f.write_all(UTF8_BOM.as_bytes())?, + CharacterEncoding::Utf8 => (), + } + + f.write_all(text.as_bytes())?; + fs::rename(tmp_path, path)?; + + Ok(()) +} + +pub(crate) fn try_decode( + bytes: Vec, + encoding: CharacterEncoding, + path: &Path, +) -> Result { + match encoding { + CharacterEncoding::Utf8 => { + Ok(String::from(str::from_utf8(&bytes).map_err(|_e| { + FileError::UnknownEncoding(path.to_owned()) + })?)) + }, + CharacterEncoding::Utf8WithBom => { + let s = String::from_utf8(bytes) + .map_err(|_e| FileError::UnknownEncoding(path.to_owned()))?; + Ok(String::from(&s[UTF8_BOM.len()..])) + }, + } +} + +pub(crate) fn create_dir_if_not_exist(dir: &str) -> Result<(), io::Error> { + let _ = fs::create_dir_all(dir)?; + Ok(()) +} + +pub(crate) fn get_modified_time>(path: P) -> Option { + File::open(path) + .and_then(|f| f.metadata()) + .and_then(|meta| meta.modified()) + .ok() +} diff --git a/rust-lib/flowy-editor/src/services/file_manager/manager.rs b/rust-lib/flowy-editor/src/services/file_manager/manager.rs new file mode 100644 index 0000000000..b963c9a152 --- /dev/null +++ b/rust-lib/flowy-editor/src/services/file_manager/manager.rs @@ -0,0 +1,120 @@ +use crate::{module::EditorUser, services::file_manager::*}; +use std::{ + collections::HashMap, + io, + path::{Path, PathBuf}, + sync::{Arc, PoisonError, RwLock, RwLockReadGuard}, +}; + +pub struct FileManager { + pub user: Arc, + open_files: HashMap, + file_info: HashMap, +} + +impl FileManager { + pub(crate) fn new(user: Arc) -> Self { + Self { + user, + open_files: HashMap::new(), + file_info: HashMap::new(), + } + } + + pub(crate) fn open(&mut self, path: &Path, id: T) -> Result + where + T: Into, + { + if !path.exists() { + return Ok("".to_string()); + } + let file_id = id.into(); + let (s, info) = try_load_file(path)?; + self.open_files.insert(path.to_owned(), file_id.clone()); + self.file_info.insert(file_id, info); + + Ok(s) + } + + pub(crate) fn save(&mut self, path: &Path, text: &String, id: T) -> Result<(), FileError> + where + T: Into, + { + let file_id = id.into(); + let is_existing = self.file_info.contains_key(&file_id); + if is_existing { + self.save_existing(path, text, &file_id) + } else { + self.save_new(path, text, &file_id) + } + } + + pub(crate) fn close(&mut self, id: T) + where + T: Into, + { + if let Some(file_info) = self.file_info.remove(&id.into()) { + self.open_files.remove(&file_info.path); + } + } + + pub(crate) fn create_file( + &mut self, + id: &str, + dir: &str, + text: &str, + ) -> Result { + let path = PathBuf::from(format!("{}/{}", dir, id)); + let file_id: FileId = id.to_owned().into(); + log::info!("Create doc at: {:?}", path); + let _ = self.save_new(&path, text, &file_id)?; + Ok(path) + } + + pub(crate) fn get_info(&self, id: &FileId) -> Option<&FileInfo> { self.file_info.get(id) } + + pub(crate) fn get_file_id(&self, path: &Path) -> Option { + self.open_files.get(path).cloned() + } + + pub fn check_file(&mut self, path: &Path, id: &FileId) -> bool { + if let Some(info) = self.file_info.get_mut(&id) { + let modified_time = get_modified_time(path); + if modified_time != info.modified_time { + info.has_changed = true + } + return info.has_changed; + } + false + } + + fn save_new(&mut self, path: &Path, text: &str, id: &FileId) -> Result<(), FileError> { + try_save(path, text, CharacterEncoding::Utf8, self.get_info(id)) + .map_err(|e| FileError::Io(e, path.to_owned()))?; + let info = FileInfo { + encoding: CharacterEncoding::Utf8, + path: path.to_owned(), + modified_time: get_modified_time(path), + has_changed: false, + }; + self.open_files.insert(path.to_owned(), id.clone()); + self.file_info.insert(id.clone(), info); + Ok(()) + } + + fn save_existing(&mut self, path: &Path, text: &String, id: &FileId) -> Result<(), FileError> { + let prev_path = self.file_info[id].path.clone(); + if prev_path != path { + self.save_new(path, text, id)?; + self.open_files.remove(&prev_path); + } else if self.file_info[&id].has_changed { + return Err(FileError::HasChanged(path.to_owned())); + } else { + let encoding = self.file_info[&id].encoding; + try_save(path, text, encoding, self.get_info(id)) + .map_err(|e| FileError::Io(e, path.to_owned()))?; + self.file_info.get_mut(&id).unwrap().modified_time = get_modified_time(path); + } + Ok(()) + } +} diff --git a/rust-lib/flowy-editor/src/services/file_manager/mod.rs b/rust-lib/flowy-editor/src/services/file_manager/mod.rs new file mode 100644 index 0000000000..1840588f96 --- /dev/null +++ b/rust-lib/flowy-editor/src/services/file_manager/mod.rs @@ -0,0 +1,5 @@ +mod file; +mod manager; + +pub use file::*; +pub use manager::*; diff --git a/rust-lib/flowy-editor/src/services/mod.rs b/rust-lib/flowy-editor/src/services/mod.rs new file mode 100644 index 0000000000..9da8a27c59 --- /dev/null +++ b/rust-lib/flowy-editor/src/services/mod.rs @@ -0,0 +1,2 @@ +pub mod doc_controller; +pub mod file_manager; diff --git a/rust-lib/flowy-editor/src/sql_tables/doc/doc_sql.rs b/rust-lib/flowy-editor/src/sql_tables/doc/doc_sql.rs new file mode 100644 index 0000000000..04c41005cf --- /dev/null +++ b/rust-lib/flowy-editor/src/sql_tables/doc/doc_sql.rs @@ -0,0 +1,40 @@ +use crate::{ + errors::EditorError, + module::EditorDatabase, + sql_tables::doc::{DocTable, DocTableChangeset}, +}; +use flowy_database::{ + prelude::*, + schema::{doc_table, doc_table::dsl}, +}; +use std::sync::Arc; + +pub struct DocTableSql { + pub database: Arc, +} + +impl DocTableSql { + pub(crate) fn create_doc_table(&self, doc_table: DocTable) -> Result<(), EditorError> { + let conn = self.database.db_connection()?; + let _ = diesel::insert_into(doc_table::table) + .values(doc_table) + .execute(&*conn)?; + Ok(()) + } + + pub(crate) fn update_doc_table(&self, changeset: DocTableChangeset) -> Result<(), EditorError> { + let conn = self.database.db_connection()?; + diesel_update_table!(doc_table, changeset, conn); + Ok(()) + } + + pub(crate) fn read_doc_table(&self, doc_id: &str) -> Result { + let doc_table = dsl::doc_table + .filter(doc_table::id.eq(doc_id)) + .first::(&*(self.database.db_connection()?))?; + + Ok(doc_table) + } + + pub(crate) fn delete_doc(&self, view_id: &str) -> Result<(), EditorError> { unimplemented!() } +} diff --git a/rust-lib/flowy-editor/src/sql_tables/doc/doc_table.rs b/rust-lib/flowy-editor/src/sql_tables/doc/doc_table.rs new file mode 100644 index 0000000000..f1bf3dc5e3 --- /dev/null +++ b/rust-lib/flowy-editor/src/sql_tables/doc/doc_table.rs @@ -0,0 +1,60 @@ +use crate::entities::doc::{CreateDocParams, DocInfo, UpdateDocParams}; +use flowy_database::schema::doc_table; +use flowy_infra::{timestamp, uuid}; +use std::convert::TryInto; + +#[derive(PartialEq, Clone, Debug, Queryable, Identifiable, Insertable, Associations)] +#[table_name = "doc_table"] +pub(crate) struct DocTable { + pub id: String, + pub name: String, + pub desc: String, + pub path: String, + pub modified_time: i64, + pub create_time: i64, + pub version: i64, +} + +impl DocTable { + pub fn new(params: CreateDocParams, path: &str) -> Self { + let time = timestamp(); + Self { + id: params.id, + name: params.name, + desc: params.desc, + path: path.to_owned(), + modified_time: time, + create_time: time, + version: 0, + } + } +} + +#[derive(AsChangeset, Identifiable, Default, Debug)] +#[table_name = "doc_table"] +pub(crate) struct DocTableChangeset { + pub id: String, + pub name: Option, + pub desc: Option, +} + +impl DocTableChangeset { + pub(crate) fn new(params: UpdateDocParams) -> Self { + Self { + id: params.id, + name: params.name, + desc: params.desc, + } + } +} + +impl std::convert::Into for DocTable { + fn into(self) -> DocInfo { + DocInfo { + id: self.id, + name: self.name, + desc: self.desc, + path: self.path, + } + } +} diff --git a/rust-lib/flowy-editor/src/sql_tables/doc/mod.rs b/rust-lib/flowy-editor/src/sql_tables/doc/mod.rs new file mode 100644 index 0000000000..0425e372d4 --- /dev/null +++ b/rust-lib/flowy-editor/src/sql_tables/doc/mod.rs @@ -0,0 +1,5 @@ +mod doc_sql; +mod doc_table; + +pub use doc_sql::*; +pub use doc_table::*; diff --git a/rust-lib/flowy-editor/src/sql_tables/mod.rs b/rust-lib/flowy-editor/src/sql_tables/mod.rs new file mode 100644 index 0000000000..dc16bd593b --- /dev/null +++ b/rust-lib/flowy-editor/src/sql_tables/mod.rs @@ -0,0 +1 @@ +pub mod doc; diff --git a/rust-lib/flowy-editor/tests/editor/doc_test.rs b/rust-lib/flowy-editor/tests/editor/doc_test.rs new file mode 100644 index 0000000000..5c57364fba --- /dev/null +++ b/rust-lib/flowy-editor/tests/editor/doc_test.rs @@ -0,0 +1,22 @@ +use crate::helper::*; + +#[test] +fn file_create_test() { + let doc_desc = create_doc("hello world", "flutter ❤️ rust", "123"); + dbg!(&doc_desc); + + let doc = read_doc_data(&doc_desc.id, &doc_desc.path); + assert_eq!(doc.text, "123".to_owned()); +} + +#[test] +fn file_update_text_test() { + let doc_desc = create_doc("hello world", "flutter ❤️ rust", ""); + dbg!(&doc_desc); + + let content = "😁😁😁😁😁😁😁😁😁😁".to_owned(); + save_doc(&doc_desc, &content); + + let doc = read_doc_data(&doc_desc.id, &doc_desc.path); + assert_eq!(doc.text, content); +} diff --git a/rust-lib/flowy-editor/tests/editor/helper.rs b/rust-lib/flowy-editor/tests/editor/helper.rs new file mode 100644 index 0000000000..d68f156870 --- /dev/null +++ b/rust-lib/flowy-editor/tests/editor/helper.rs @@ -0,0 +1,64 @@ +use flowy_test::builder::SingleUserTestBuilder; + +use flowy_editor::{entities::doc::*, event::EditorEvent::*}; +use flowy_infra::uuid; + +pub fn create_doc(name: &str, desc: &str, text: &str) -> DocInfo { + let request = CreateDocRequest { + id: uuid(), + name: name.to_owned(), + desc: desc.to_owned(), + text: text.to_owned(), + }; + + let doc_desc = SingleUserTestBuilder::new() + .event(CreateDoc) + .request(request) + .sync_send() + .parse::(); + + doc_desc +} + +pub fn save_doc(desc: &DocInfo, content: &str) { + let request = UpdateDocRequest { + id: desc.id.clone(), + name: Some(desc.name.clone()), + desc: Some(desc.desc.clone()), + text: Some(content.to_owned()), + }; + + let _ = SingleUserTestBuilder::new() + .event(UpdateDoc) + .request(request) + .sync_send(); +} + +pub fn read_doc(doc_id: &str) -> DocInfo { + let request = QueryDocRequest { + doc_id: doc_id.to_string(), + }; + + let doc = SingleUserTestBuilder::new() + .event(ReadDocInfo) + .request(request) + .sync_send() + .parse::(); + + doc +} + +pub fn read_doc_data(doc_id: &str, path: &str) -> DocData { + let request = QueryDocDataRequest { + doc_id: doc_id.to_string(), + path: path.to_string(), + }; + + let doc = SingleUserTestBuilder::new() + .event(ReadDocData) + .request(request) + .sync_send() + .parse::(); + + doc +} diff --git a/rust-lib/flowy-editor/tests/editor/main.rs b/rust-lib/flowy-editor/tests/editor/main.rs new file mode 100644 index 0000000000..cc684a69bf --- /dev/null +++ b/rust-lib/flowy-editor/tests/editor/main.rs @@ -0,0 +1,2 @@ +mod doc_test; +mod helper; diff --git a/rust-lib/flowy-infra/src/kv/kv.rs b/rust-lib/flowy-infra/src/kv/kv.rs index 36bc30ecc1..115de44165 100644 --- a/rust-lib/flowy-infra/src/kv/kv.rs +++ b/rust-lib/flowy-infra/src/kv/kv.rs @@ -8,7 +8,7 @@ use std::{path::Path, sync::RwLock}; const DB_NAME: &str = "kv.db"; lazy_static! { - pub static ref KV_HOLDER: RwLock = RwLock::new(KVStore::new()); + static ref KV_HOLDER: RwLock = RwLock::new(KVStore::new()); } pub struct KVStore { diff --git a/rust-lib/flowy-observable/Cargo.toml b/rust-lib/flowy-observable/Cargo.toml new file mode 100644 index 0000000000..0fca6d8391 --- /dev/null +++ b/rust-lib/flowy-observable/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "flowy-observable" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +lazy_static = {version = "1.4.0"} +protobuf = {version = "2.20.0"} +allo-isolate = {version = "^0.1", features = ["catch-unwind",]} +log = "0.4.14" + +flowy-derive = {path = "../flowy-derive"} + +[features] +dart = [] \ No newline at end of file diff --git a/rust-lib/flowy-observable/Flowy.toml b/rust-lib/flowy-observable/Flowy.toml new file mode 100644 index 0000000000..33b1c193f2 --- /dev/null +++ b/rust-lib/flowy-observable/Flowy.toml @@ -0,0 +1,3 @@ + +proto_crates = ["src/entities"] +event_files = [] \ No newline at end of file diff --git a/rust-lib/flowy-observable/src/dart/mod.rs b/rust-lib/flowy-observable/src/dart/mod.rs new file mode 100644 index 0000000000..b58f792ae6 --- /dev/null +++ b/rust-lib/flowy-observable/src/dart/mod.rs @@ -0,0 +1,3 @@ +mod stream_sender; + +pub use stream_sender::*; diff --git a/rust-lib/flowy-observable/src/dart/stream_sender.rs b/rust-lib/flowy-observable/src/dart/stream_sender.rs new file mode 100644 index 0000000000..7f7f77ecb1 --- /dev/null +++ b/rust-lib/flowy-observable/src/dart/stream_sender.rs @@ -0,0 +1,52 @@ +use crate::entities::ObservableSubject; +use lazy_static::lazy_static; +use std::{convert::TryInto, sync::RwLock}; + +lazy_static! { + static ref R2F_STREAM_SENDER: RwLock = RwLock::new(RustStreamSender::new()); +} + +pub struct RustStreamSender { + isolate: Option, +} + +impl RustStreamSender { + fn new() -> Self { Self { isolate: None } } + + fn inner_set_port(&mut self, port: i64) { + log::info!("Setup rust to flutter stream with port {}", port); + self.isolate = Some(allo_isolate::Isolate::new(port)); + } + + fn inner_post(&self, observable_subject: ObservableSubject) -> Result<(), String> { + match self.isolate { + Some(ref isolate) => { + let bytes: Vec = observable_subject.try_into().unwrap(); + isolate.post(bytes); + Ok(()) + }, + None => Err("Isolate is not set".to_owned()), + } + } + + pub fn set_port(port: i64) { + match R2F_STREAM_SENDER.write() { + Ok(mut stream) => stream.inner_set_port(port), + Err(e) => { + let msg = format!("Get rust to flutter stream lock fail. {:?}", e); + log::error!("{:?}", msg); + }, + } + } + + pub fn post(observable_subject: ObservableSubject) -> Result<(), String> { + #[cfg(feature = "dart")] + match R2F_STREAM_SENDER.read() { + Ok(stream) => stream.inner_post(observable_subject), + Err(e) => Err(format!("Get rust to flutter stream lock fail. {:?}", e)), + } + + #[cfg(not(feature = "dart"))] + Ok(()) + } +} diff --git a/rust-lib/flowy-observable/src/entities/mod.rs b/rust-lib/flowy-observable/src/entities/mod.rs new file mode 100644 index 0000000000..c4512b93f5 --- /dev/null +++ b/rust-lib/flowy-observable/src/entities/mod.rs @@ -0,0 +1,3 @@ +mod subject; + +pub use subject::*; diff --git a/rust-lib/flowy-observable/src/entities/subject.rs b/rust-lib/flowy-observable/src/entities/subject.rs new file mode 100644 index 0000000000..c1a2b6d67c --- /dev/null +++ b/rust-lib/flowy-observable/src/entities/subject.rs @@ -0,0 +1,24 @@ +use flowy_derive::ProtoBuf; + +#[derive(Debug, Clone, ProtoBuf)] +pub struct ObservableSubject { + #[pb(index = 1)] + pub category: String, + + #[pb(index = 2)] + pub ty: i32, + + #[pb(index = 3)] + pub subject_id: String, + + #[pb(index = 4, one_of)] + pub subject_payload: Option>, +} + +impl std::default::Default for ObservableSubject { + fn default() -> Self { + Self { + ..Default::default() + } + } +} diff --git a/rust-lib/flowy-observable/src/lib.rs b/rust-lib/flowy-observable/src/lib.rs new file mode 100644 index 0000000000..f6ea0af380 --- /dev/null +++ b/rust-lib/flowy-observable/src/lib.rs @@ -0,0 +1,11 @@ +pub mod dart; +pub mod entities; +mod protobuf; + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/rust-lib/flowy-observable/src/protobuf/mod.rs b/rust-lib/flowy-observable/src/protobuf/mod.rs new file mode 100644 index 0000000000..2480f62fbe --- /dev/null +++ b/rust-lib/flowy-observable/src/protobuf/mod.rs @@ -0,0 +1,4 @@ + +mod model; +pub use model::*; + \ No newline at end of file diff --git a/rust-lib/flowy-observable/src/protobuf/model/mod.rs b/rust-lib/flowy-observable/src/protobuf/model/mod.rs new file mode 100644 index 0000000000..ce50dd797d --- /dev/null +++ b/rust-lib/flowy-observable/src/protobuf/model/mod.rs @@ -0,0 +1,4 @@ +// Auto-generated, do not edit + +mod subject; +pub use subject::*; diff --git a/rust-lib/flowy-observable/src/protobuf/model/subject.rs b/rust-lib/flowy-observable/src/protobuf/model/subject.rs new file mode 100644 index 0000000000..7497b4001b --- /dev/null +++ b/rust-lib/flowy-observable/src/protobuf/model/subject.rs @@ -0,0 +1,376 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `subject.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct ObservableSubject { + // message fields + pub category: ::std::string::String, + pub ty: i32, + pub subject_id: ::std::string::String, + // message oneof groups + pub one_of_subject_payload: ::std::option::Option, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a ObservableSubject { + fn default() -> &'a ObservableSubject { + ::default_instance() + } +} + +#[derive(Clone,PartialEq,Debug)] +pub enum ObservableSubject_oneof_one_of_subject_payload { + subject_payload(::std::vec::Vec), +} + +impl ObservableSubject { + pub fn new() -> ObservableSubject { + ::std::default::Default::default() + } + + // string category = 1; + + + pub fn get_category(&self) -> &str { + &self.category + } + pub fn clear_category(&mut self) { + self.category.clear(); + } + + // Param is passed by value, moved + pub fn set_category(&mut self, v: ::std::string::String) { + self.category = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_category(&mut self) -> &mut ::std::string::String { + &mut self.category + } + + // Take field + pub fn take_category(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.category, ::std::string::String::new()) + } + + // int32 ty = 2; + + + pub fn get_ty(&self) -> i32 { + self.ty + } + pub fn clear_ty(&mut self) { + self.ty = 0; + } + + // Param is passed by value, moved + pub fn set_ty(&mut self, v: i32) { + self.ty = v; + } + + // string subject_id = 3; + + + pub fn get_subject_id(&self) -> &str { + &self.subject_id + } + pub fn clear_subject_id(&mut self) { + self.subject_id.clear(); + } + + // Param is passed by value, moved + pub fn set_subject_id(&mut self, v: ::std::string::String) { + self.subject_id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_subject_id(&mut self) -> &mut ::std::string::String { + &mut self.subject_id + } + + // Take field + pub fn take_subject_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.subject_id, ::std::string::String::new()) + } + + // bytes subject_payload = 4; + + + pub fn get_subject_payload(&self) -> &[u8] { + match self.one_of_subject_payload { + ::std::option::Option::Some(ObservableSubject_oneof_one_of_subject_payload::subject_payload(ref v)) => v, + _ => &[], + } + } + pub fn clear_subject_payload(&mut self) { + self.one_of_subject_payload = ::std::option::Option::None; + } + + pub fn has_subject_payload(&self) -> bool { + match self.one_of_subject_payload { + ::std::option::Option::Some(ObservableSubject_oneof_one_of_subject_payload::subject_payload(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_subject_payload(&mut self, v: ::std::vec::Vec) { + self.one_of_subject_payload = ::std::option::Option::Some(ObservableSubject_oneof_one_of_subject_payload::subject_payload(v)) + } + + // Mutable pointer to the field. + pub fn mut_subject_payload(&mut self) -> &mut ::std::vec::Vec { + if let ::std::option::Option::Some(ObservableSubject_oneof_one_of_subject_payload::subject_payload(_)) = self.one_of_subject_payload { + } else { + self.one_of_subject_payload = ::std::option::Option::Some(ObservableSubject_oneof_one_of_subject_payload::subject_payload(::std::vec::Vec::new())); + } + match self.one_of_subject_payload { + ::std::option::Option::Some(ObservableSubject_oneof_one_of_subject_payload::subject_payload(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_subject_payload(&mut self) -> ::std::vec::Vec { + if self.has_subject_payload() { + match self.one_of_subject_payload.take() { + ::std::option::Option::Some(ObservableSubject_oneof_one_of_subject_payload::subject_payload(v)) => v, + _ => panic!(), + } + } else { + ::std::vec::Vec::new() + } + } +} + +impl ::protobuf::Message for ObservableSubject { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.category)?; + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_int32()?; + self.ty = tmp; + }, + 3 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.subject_id)?; + }, + 4 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.one_of_subject_payload = ::std::option::Option::Some(ObservableSubject_oneof_one_of_subject_payload::subject_payload(is.read_bytes()?)); + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.category.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.category); + } + if self.ty != 0 { + my_size += ::protobuf::rt::value_size(2, self.ty, ::protobuf::wire_format::WireTypeVarint); + } + if !self.subject_id.is_empty() { + my_size += ::protobuf::rt::string_size(3, &self.subject_id); + } + if let ::std::option::Option::Some(ref v) = self.one_of_subject_payload { + match v { + &ObservableSubject_oneof_one_of_subject_payload::subject_payload(ref v) => { + my_size += ::protobuf::rt::bytes_size(4, &v); + }, + }; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.category.is_empty() { + os.write_string(1, &self.category)?; + } + if self.ty != 0 { + os.write_int32(2, self.ty)?; + } + if !self.subject_id.is_empty() { + os.write_string(3, &self.subject_id)?; + } + if let ::std::option::Option::Some(ref v) = self.one_of_subject_payload { + match v { + &ObservableSubject_oneof_one_of_subject_payload::subject_payload(ref v) => { + os.write_bytes(4, v)?; + }, + }; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> ObservableSubject { + ObservableSubject::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "category", + |m: &ObservableSubject| { &m.category }, + |m: &mut ObservableSubject| { &mut m.category }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeInt32>( + "ty", + |m: &ObservableSubject| { &m.ty }, + |m: &mut ObservableSubject| { &mut m.ty }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "subject_id", + |m: &ObservableSubject| { &m.subject_id }, + |m: &mut ObservableSubject| { &mut m.subject_id }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_bytes_accessor::<_>( + "subject_payload", + ObservableSubject::has_subject_payload, + ObservableSubject::get_subject_payload, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "ObservableSubject", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static ObservableSubject { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(ObservableSubject::new) + } +} + +impl ::protobuf::Clear for ObservableSubject { + fn clear(&mut self) { + self.category.clear(); + self.ty = 0; + self.subject_id.clear(); + self.one_of_subject_payload = ::std::option::Option::None; + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for ObservableSubject { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for ObservableSubject { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\rsubject.proto\"\xa3\x01\n\x11ObservableSubject\x12\x1a\n\x08category\ + \x18\x01\x20\x01(\tR\x08category\x12\x0e\n\x02ty\x18\x02\x20\x01(\x05R\ + \x02ty\x12\x1d\n\nsubject_id\x18\x03\x20\x01(\tR\tsubjectId\x12)\n\x0fsu\ + bject_payload\x18\x04\x20\x01(\x0cH\0R\x0esubjectPayloadB\x18\n\x16one_o\ + f_subject_payloadJ\xa1\x02\n\x06\x12\x04\0\0\x07\x01\n\x08\n\x01\x0c\x12\ + \x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x07\x01\n\n\n\x03\x04\0\x01\ + \x12\x03\x02\x08\x19\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x18\n\x0c\n\ + \x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\ + \x03\x03\x0b\x13\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x16\x17\n\x0b\n\ + \x04\x04\0\x02\x01\x12\x03\x04\x04\x11\n\x0c\n\x05\x04\0\x02\x01\x05\x12\ + \x03\x04\x04\t\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\n\x0c\n\x0c\n\ + \x05\x04\0\x02\x01\x03\x12\x03\x04\x0f\x10\n\x0b\n\x04\x04\0\x02\x02\x12\ + \x03\x05\x04\x1a\n\x0c\n\x05\x04\0\x02\x02\x05\x12\x03\x05\x04\n\n\x0c\n\ + \x05\x04\0\x02\x02\x01\x12\x03\x05\x0b\x15\n\x0c\n\x05\x04\0\x02\x02\x03\ + \x12\x03\x05\x18\x19\n\x0b\n\x04\x04\0\x08\0\x12\x03\x06\x04?\n\x0c\n\ + \x05\x04\0\x08\0\x01\x12\x03\x06\n\x20\n\x0b\n\x04\x04\0\x02\x03\x12\x03\ + \x06#=\n\x0c\n\x05\x04\0\x02\x03\x05\x12\x03\x06#(\n\x0c\n\x05\x04\0\x02\ + \x03\x01\x12\x03\x06)8\n\x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x06; = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-observable/src/protobuf/proto/subject.proto b/rust-lib/flowy-observable/src/protobuf/proto/subject.proto new file mode 100644 index 0000000000..97efe0d9c2 --- /dev/null +++ b/rust-lib/flowy-observable/src/protobuf/proto/subject.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +message ObservableSubject { + string category = 1; + int32 ty = 2; + string subject_id = 3; + oneof one_of_subject_payload { bytes subject_payload = 4; }; +} diff --git a/rust-lib/flowy-sdk/Cargo.toml b/rust-lib/flowy-sdk/Cargo.toml index 6150dd01a3..ad24d84cfc 100644 --- a/rust-lib/flowy-sdk/Cargo.toml +++ b/rust-lib/flowy-sdk/Cargo.toml @@ -7,12 +7,13 @@ edition = "2018" [dependencies] flowy-dispatch = { path = "../flowy-dispatch", features = ["use_tracing"]} -flowy-log = { path = "../flowy-log" } -#flowy-log = { path = "../flowy-log", features = ["use_bunyan"] } +#flowy-log = { path = "../flowy-log" } +flowy-log = { path = "../flowy-log", features = ["use_bunyan"] } flowy-user = { path = "../flowy-user" } flowy-infra = { path = "../flowy-infra" } flowy-workspace = { path = "../flowy-workspace" } flowy-database = { path = "../flowy-database" } +flowy-editor = { path = "../flowy-editor" } tracing = { version = "0.1" } log = "0.4.14" futures-core = { version = "0.3", default-features = false } diff --git a/rust-lib/flowy-sdk/src/deps_resolve/editor_deps_impl.rs b/rust-lib/flowy-sdk/src/deps_resolve/editor_deps_impl.rs new file mode 100644 index 0000000000..b2dfae9887 --- /dev/null +++ b/rust-lib/flowy-sdk/src/deps_resolve/editor_deps_impl.rs @@ -0,0 +1,42 @@ +use flowy_database::DBConnection; +use flowy_editor::{ + errors::{EditorError, EditorErrorCode, ErrorBuilder}, + module::{EditorDatabase, EditorUser}, +}; +use flowy_user::prelude::UserSession; +use std::{path::Path, sync::Arc}; + +pub struct EditorDatabaseImpl { + pub(crate) user_session: Arc, +} + +impl EditorDatabase for EditorDatabaseImpl { + fn db_connection(&self) -> Result { + self.user_session.get_db_connection().map_err(|e| { + ErrorBuilder::new(EditorErrorCode::EditorDBConnFailed) + .error(e) + .build() + }) + } +} + +pub struct EditorUserImpl { + pub(crate) user_session: Arc, +} + +impl EditorUser for EditorUserImpl { + fn user_doc_dir(&self) -> Result { + let dir = self.user_session.get_user_dir().map_err(|e| { + ErrorBuilder::new(EditorErrorCode::EditorUserNotLoginYet) + .error(e) + .build() + })?; + + let doc_dir = format!("{}/doc", dir); + if !Path::new(&doc_dir).exists() { + // TODO: Make sure to unwrap? 😁 + std::fs::create_dir_all(&doc_dir).unwrap(); + } + Ok(doc_dir) + } +} diff --git a/rust-lib/flowy-sdk/src/deps_resolve/mod.rs b/rust-lib/flowy-sdk/src/deps_resolve/mod.rs index a49be3ee06..379f23f2fc 100644 --- a/rust-lib/flowy-sdk/src/deps_resolve/mod.rs +++ b/rust-lib/flowy-sdk/src/deps_resolve/mod.rs @@ -1,3 +1,5 @@ -mod workspace_user_impl; +mod editor_deps_impl; +mod workspace_deps_impl; -pub use workspace_user_impl::*; +pub use editor_deps_impl::*; +pub use workspace_deps_impl::*; diff --git a/rust-lib/flowy-sdk/src/deps_resolve/workspace_user_impl.rs b/rust-lib/flowy-sdk/src/deps_resolve/workspace_deps_impl.rs similarity index 82% rename from rust-lib/flowy-sdk/src/deps_resolve/workspace_user_impl.rs rename to rust-lib/flowy-sdk/src/deps_resolve/workspace_deps_impl.rs index df069a33a5..67666078c7 100644 --- a/rust-lib/flowy-sdk/src/deps_resolve/workspace_user_impl.rs +++ b/rust-lib/flowy-sdk/src/deps_resolve/workspace_deps_impl.rs @@ -2,9 +2,9 @@ use flowy_database::DBConnection; use flowy_dispatch::prelude::DispatchFuture; use flowy_user::prelude::UserSession; use flowy_workspace::{ - entities::workspace::UserWorkspace, + entities::workspace::CurrentWorkspace, errors::{ErrorBuilder, WorkspaceError, WorkspaceErrorCode}, - module::WorkspaceUser, + module::{WorkspaceDatabase, WorkspaceUser}, }; use std::sync::Arc; @@ -28,14 +28,13 @@ impl WorkspaceUser for WorkspaceUserImpl { ErrorBuilder::new(WorkspaceErrorCode::UserInternalError) .error(e) .build() - }); - + })?; Ok(()) }), } } - fn get_cur_workspace(&self) -> DispatchFuture> { + fn get_cur_workspace(&self) -> DispatchFuture> { let user_session = self.user_session.clone(); DispatchFuture { fut: Box::pin(async move { @@ -45,14 +44,20 @@ impl WorkspaceUser for WorkspaceUserImpl { .build() })?; - Ok(UserWorkspace { + Ok(CurrentWorkspace { owner: user_detail.email, workspace_id: user_detail.workspace, }) }), } } +} +pub struct WorkspaceDatabaseImpl { + pub(crate) user_session: Arc, +} + +impl WorkspaceDatabase for WorkspaceDatabaseImpl { fn db_connection(&self) -> Result { self.user_session.get_db_connection().map_err(|e| { ErrorBuilder::new(WorkspaceErrorCode::DatabaseConnectionFail) diff --git a/rust-lib/flowy-sdk/src/flowy_server.rs b/rust-lib/flowy-sdk/src/flowy_server.rs index 08d5a8ea84..3e3a2de9c8 100644 --- a/rust-lib/flowy-sdk/src/flowy_server.rs +++ b/rust-lib/flowy-sdk/src/flowy_server.rs @@ -1,4 +1,10 @@ -use flowy_dispatch::prelude::{DispatchFuture, EventDispatch, ModuleRequest, ToBytes}; +use flowy_dispatch::prelude::{ + DispatchError, + DispatchFuture, + EventDispatch, + ModuleRequest, + ToBytes, +}; use flowy_user::{ entities::{SignInParams, SignUpParams, UserDetail}, errors::{ErrorBuilder, UserError, UserErrorCode}, @@ -53,7 +59,8 @@ impl UserServer for FlowyServerMocker { name: &str, desc: &str, _user_id: &str, - ) -> DispatchFuture> { + ) -> DispatchFuture> { + log::info!("Create user workspace: {:?}", name); let payload: Vec = CreateWorkspaceRequest { name: name.to_string(), desc: desc.to_string(), @@ -64,15 +71,21 @@ impl UserServer for FlowyServerMocker { let request = ModuleRequest::new(CreateWorkspace).payload(payload); DispatchFuture { fut: Box::pin(async move { - let _ = EventDispatch::async_send(request) + let result = EventDispatch::async_send(request) .await - .parse::() + .parse::() .map_err(|e| { ErrorBuilder::new(UserErrorCode::CreateDefaultWorkspaceFailed) .error(e) .build() })?; - Ok(()) + + let workspace = result.map_err(|e| { + ErrorBuilder::new(UserErrorCode::CreateDefaultWorkspaceFailed) + .error(e) + .build() + })?; + Ok(workspace.id) }), } } diff --git a/rust-lib/flowy-sdk/src/module.rs b/rust-lib/flowy-sdk/src/module.rs index bdc712005f..a04878c8e9 100644 --- a/rust-lib/flowy-sdk/src/module.rs +++ b/rust-lib/flowy-sdk/src/module.rs @@ -1,9 +1,14 @@ use crate::flowy_server::{ArcFlowyServer, FlowyServerMocker}; use flowy_dispatch::prelude::Module; +use flowy_editor::prelude::*; use flowy_user::prelude::*; -use flowy_workspace::prelude::*; -use crate::deps_resolve::WorkspaceUserImpl; +use crate::deps_resolve::{ + EditorDatabaseImpl, + EditorUserImpl, + WorkspaceDatabaseImpl, + WorkspaceUserImpl, +}; use std::sync::Arc; pub struct ModuleConfig { @@ -21,8 +26,20 @@ pub fn build_modules(config: ModuleConfig, _server: ArcFlowyServer) -> Vec>; -impl WorkspaceTestBuilder { +pub type SingleUserTestBuilder = TestBuilder>; +impl SingleUserTestBuilder { pub fn new() -> Self { let mut builder = Self { tester: Box::new(FixedUserTester::::new()), @@ -38,7 +38,7 @@ impl UserTestBuilder { builder } - pub fn reset(mut self) -> Self { self.login() } + pub fn reset(self) -> Self { self.login() } } pub struct TestBuilder { diff --git a/rust-lib/flowy-test/src/tester.rs b/rust-lib/flowy-test/src/tester.rs index 5330ffc92e..c788d77516 100644 --- a/rust-lib/flowy-test/src/tester.rs +++ b/rust-lib/flowy-test/src/tester.rs @@ -122,7 +122,7 @@ pub trait TesterTrait { .unwrap() { Ok(user_detail) => user_detail, - Err(e) => self.login(), + Err(_e) => self.login(), } } diff --git a/rust-lib/flowy-user/Cargo.toml b/rust-lib/flowy-user/Cargo.toml index db0be3480b..0d3d1d5199 100644 --- a/rust-lib/flowy-user/Cargo.toml +++ b/rust-lib/flowy-user/Cargo.toml @@ -31,6 +31,7 @@ thread-id = "3.3.0" once_cell = "1.7.2" parking_lot = "0.11" + [dev-dependencies] quickcheck = "0.9.2" quickcheck_macros = "0.9.1" diff --git a/rust-lib/flowy-user/src/errors.rs b/rust-lib/flowy-user/src/errors.rs index 384793468f..a1ff441cc3 100644 --- a/rust-lib/flowy-user/src/errors.rs +++ b/rust-lib/flowy-user/src/errors.rs @@ -36,6 +36,9 @@ pub enum UserErrorCode { #[display(fmt = "Database internal error")] UserDatabaseInternalError = 5, + #[display(fmt = "Sql internal error")] + SqlInternalError = 6, + #[display(fmt = "User not login yet")] UserNotLoginYet = 10, #[display(fmt = "Get current id read lock failed")] @@ -55,6 +58,9 @@ pub enum UserErrorCode { UserIdInvalid = 24, #[display(fmt = "Create user default workspace failed")] CreateDefaultWorkspaceFailed = 25, + + #[display(fmt = "User default workspace already exists")] + DefaultWorkspaceAlreadyExist = 26, } impl std::default::Default for UserErrorCode { @@ -68,7 +74,8 @@ impl std::convert::From for UserError { .build() } } -use diesel::result::DatabaseErrorKind; +// use diesel::result::{Error, DatabaseErrorKind}; +// use flowy_sqlite::ErrorKind; impl std::convert::From for UserError { fn from(error: flowy_sqlite::Error) -> Self { // match error.kind() { @@ -84,7 +91,6 @@ impl std::convert::From for UserError { // } // _ => {} // } - // // }, // Error::NotFound => {}, // Error::QueryBuilderError(_) => {}, @@ -100,7 +106,7 @@ impl std::convert::From for UserError { // ErrorKind::__Nonexhaustive { .. } => {}, // } - ErrorBuilder::new(UserErrorCode::UserDatabaseInternalError) + ErrorBuilder::new(UserErrorCode::SqlInternalError) .error(error) .build() } diff --git a/rust-lib/flowy-user/src/handlers/auth_handler.rs b/rust-lib/flowy-user/src/handlers/auth_handler.rs index 601d8b6f09..97073f4096 100644 --- a/rust-lib/flowy-user/src/handlers/auth_handler.rs +++ b/rust-lib/flowy-user/src/handlers/auth_handler.rs @@ -3,16 +3,10 @@ use flowy_dispatch::prelude::*; use std::{convert::TryInto, sync::Arc}; // tracing instrument 👉🏻 https://docs.rs/tracing/0.1.26/tracing/attr.instrument.html -#[tracing::instrument( - name = "user_sign_in", - skip(data, session), - fields( - email = %data.email, - ) -)] +#[tracing::instrument(name = "user_sign_in", skip(data, session), fields(email = %data.email))] pub async fn user_sign_in_handler( data: Data, - session: ModuleData>, + session: Unit>, ) -> ResponseResult { let params: SignInParams = data.into_inner().try_into()?; let user = session.sign_in(params).await?; @@ -30,7 +24,7 @@ pub async fn user_sign_in_handler( )] pub async fn user_sign_up_handler( data: Data, - session: ModuleData>, + session: Unit>, ) -> ResponseResult { let params: SignUpParams = data.into_inner().try_into()?; let user = session.sign_up(params).await?; diff --git a/rust-lib/flowy-user/src/handlers/user_handler.rs b/rust-lib/flowy-user/src/handlers/user_handler.rs index 7cb31b3d88..7922efd03e 100644 --- a/rust-lib/flowy-user/src/handlers/user_handler.rs +++ b/rust-lib/flowy-user/src/handlers/user_handler.rs @@ -3,20 +3,20 @@ use flowy_dispatch::prelude::*; use std::{convert::TryInto, sync::Arc}; pub async fn user_get_status_handler( - session: ModuleData>, + session: Unit>, ) -> ResponseResult { let user_detail = session.user_detail()?; response_ok(user_detail) } -pub async fn sign_out_handler(session: ModuleData>) -> Result<(), UserError> { +pub async fn sign_out_handler(session: Unit>) -> Result<(), UserError> { let _ = session.sign_out()?; Ok(()) } pub async fn update_user_handler( data: Data, - session: ModuleData>, + session: Unit>, ) -> ResponseResult { let params: UpdateUserParams = data.into_inner().try_into()?; let user_detail = session.update_user(params)?; diff --git a/rust-lib/flowy-user/src/protobuf/model/errors.rs b/rust-lib/flowy-user/src/protobuf/model/errors.rs index 5c5e9468e0..657a1837a7 100644 --- a/rust-lib/flowy-user/src/protobuf/model/errors.rs +++ b/rust-lib/flowy-user/src/protobuf/model/errors.rs @@ -221,6 +221,7 @@ pub enum UserErrorCode { UserDatabaseReadLocked = 3, UserDatabaseDidNotMatch = 4, UserDatabaseInternalError = 5, + SqlInternalError = 6, UserNotLoginYet = 10, ReadCurrentIdFailed = 11, WriteCurrentIdFailed = 12, @@ -230,6 +231,7 @@ pub enum UserErrorCode { UserWorkspaceInvalid = 23, UserIdInvalid = 24, CreateDefaultWorkspaceFailed = 25, + DefaultWorkspaceAlreadyExist = 26, } impl ::protobuf::ProtobufEnum for UserErrorCode { @@ -245,6 +247,7 @@ impl ::protobuf::ProtobufEnum for UserErrorCode { 3 => ::std::option::Option::Some(UserErrorCode::UserDatabaseReadLocked), 4 => ::std::option::Option::Some(UserErrorCode::UserDatabaseDidNotMatch), 5 => ::std::option::Option::Some(UserErrorCode::UserDatabaseInternalError), + 6 => ::std::option::Option::Some(UserErrorCode::SqlInternalError), 10 => ::std::option::Option::Some(UserErrorCode::UserNotLoginYet), 11 => ::std::option::Option::Some(UserErrorCode::ReadCurrentIdFailed), 12 => ::std::option::Option::Some(UserErrorCode::WriteCurrentIdFailed), @@ -254,6 +257,7 @@ impl ::protobuf::ProtobufEnum for UserErrorCode { 23 => ::std::option::Option::Some(UserErrorCode::UserWorkspaceInvalid), 24 => ::std::option::Option::Some(UserErrorCode::UserIdInvalid), 25 => ::std::option::Option::Some(UserErrorCode::CreateDefaultWorkspaceFailed), + 26 => ::std::option::Option::Some(UserErrorCode::DefaultWorkspaceAlreadyExist), _ => ::std::option::Option::None } } @@ -266,6 +270,7 @@ impl ::protobuf::ProtobufEnum for UserErrorCode { UserErrorCode::UserDatabaseReadLocked, UserErrorCode::UserDatabaseDidNotMatch, UserErrorCode::UserDatabaseInternalError, + UserErrorCode::SqlInternalError, UserErrorCode::UserNotLoginYet, UserErrorCode::ReadCurrentIdFailed, UserErrorCode::WriteCurrentIdFailed, @@ -275,6 +280,7 @@ impl ::protobuf::ProtobufEnum for UserErrorCode { UserErrorCode::UserWorkspaceInvalid, UserErrorCode::UserIdInvalid, UserErrorCode::CreateDefaultWorkspaceFailed, + UserErrorCode::DefaultWorkspaceAlreadyExist, ]; values } @@ -305,54 +311,59 @@ impl ::protobuf::reflect::ProtobufValue for UserErrorCode { static file_descriptor_proto_data: &'static [u8] = b"\ \n\x0cerrors.proto\"A\n\tUserError\x12\"\n\x04code\x18\x01\x20\x01(\x0e2\ \x0e.UserErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\tR\x03msg*\ - \x80\x03\n\rUserErrorCode\x12\x0b\n\x07Unknown\x10\0\x12\x1a\n\x16UserDa\ + \xb8\x03\n\rUserErrorCode\x12\x0b\n\x07Unknown\x10\0\x12\x1a\n\x16UserDa\ tabaseInitFailed\x10\x01\x12\x1b\n\x17UserDatabaseWriteLocked\x10\x02\ \x12\x1a\n\x16UserDatabaseReadLocked\x10\x03\x12\x1b\n\x17UserDatabaseDi\ - dNotMatch\x10\x04\x12\x1d\n\x19UserDatabaseInternalError\x10\x05\x12\x13\ - \n\x0fUserNotLoginYet\x10\n\x12\x17\n\x13ReadCurrentIdFailed\x10\x0b\x12\ - \x18\n\x14WriteCurrentIdFailed\x10\x0c\x12\x10\n\x0cEmailInvalid\x10\x14\ - \x12\x13\n\x0fPasswordInvalid\x10\x15\x12\x13\n\x0fUserNameInvalid\x10\ - \x16\x12\x18\n\x14UserWorkspaceInvalid\x10\x17\x12\x11\n\rUserIdInvalid\ - \x10\x18\x12\x20\n\x1cCreateDefaultWorkspaceFailed\x10\x19J\x97\x06\n\ - \x06\x12\x04\0\0\x16\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\ - \x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x11\n\x0b\n\ - \x04\x04\0\x02\0\x12\x03\x03\x04\x1b\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\ - \x03\x04\x11\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x12\x16\n\x0c\n\x05\ - \x04\0\x02\0\x03\x12\x03\x03\x19\x1a\n\x0b\n\x04\x04\0\x02\x01\x12\x03\ - \x04\x04\x13\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\ - \x04\0\x02\x01\x01\x12\x03\x04\x0b\x0e\n\x0c\n\x05\x04\0\x02\x01\x03\x12\ - \x03\x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\x16\x01\n\n\n\x03\x05\0\ - \x01\x12\x03\x06\x05\x12\n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\x04\x10\n\ - \x0c\n\x05\x05\0\x02\0\x01\x12\x03\x07\x04\x0b\n\x0c\n\x05\x05\0\x02\0\ - \x02\x12\x03\x07\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x08\x04\x1f\n\ - \x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x08\x04\x1a\n\x0c\n\x05\x05\0\x02\ - \x01\x02\x12\x03\x08\x1d\x1e\n\x0b\n\x04\x05\0\x02\x02\x12\x03\t\x04\x20\ - \n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\t\x04\x1b\n\x0c\n\x05\x05\0\x02\ - \x02\x02\x12\x03\t\x1e\x1f\n\x0b\n\x04\x05\0\x02\x03\x12\x03\n\x04\x1f\n\ - \x0c\n\x05\x05\0\x02\x03\x01\x12\x03\n\x04\x1a\n\x0c\n\x05\x05\0\x02\x03\ - \x02\x12\x03\n\x1d\x1e\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x0b\x04\x20\n\ - \x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x0b\x04\x1b\n\x0c\n\x05\x05\0\x02\ - \x04\x02\x12\x03\x0b\x1e\x1f\n\x0b\n\x04\x05\0\x02\x05\x12\x03\x0c\x04\"\ - \n\x0c\n\x05\x05\0\x02\x05\x01\x12\x03\x0c\x04\x1d\n\x0c\n\x05\x05\0\x02\ - \x05\x02\x12\x03\x0c\x20!\n\x0b\n\x04\x05\0\x02\x06\x12\x03\r\x04\x19\n\ - \x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\x04\x13\n\x0c\n\x05\x05\0\x02\x06\ - \x02\x12\x03\r\x16\x18\n\x0b\n\x04\x05\0\x02\x07\x12\x03\x0e\x04\x1d\n\ - \x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x17\n\x0c\n\x05\x05\0\x02\ - \x07\x02\x12\x03\x0e\x1a\x1c\n\x0b\n\x04\x05\0\x02\x08\x12\x03\x0f\x04\ - \x1e\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0f\x04\x18\n\x0c\n\x05\x05\0\ - \x02\x08\x02\x12\x03\x0f\x1b\x1d\n\x0b\n\x04\x05\0\x02\t\x12\x03\x10\x04\ - \x16\n\x0c\n\x05\x05\0\x02\t\x01\x12\x03\x10\x04\x10\n\x0c\n\x05\x05\0\ - \x02\t\x02\x12\x03\x10\x13\x15\n\x0b\n\x04\x05\0\x02\n\x12\x03\x11\x04\ - \x19\n\x0c\n\x05\x05\0\x02\n\x01\x12\x03\x11\x04\x13\n\x0c\n\x05\x05\0\ - \x02\n\x02\x12\x03\x11\x16\x18\n\x0b\n\x04\x05\0\x02\x0b\x12\x03\x12\x04\ - \x19\n\x0c\n\x05\x05\0\x02\x0b\x01\x12\x03\x12\x04\x13\n\x0c\n\x05\x05\0\ - \x02\x0b\x02\x12\x03\x12\x16\x18\n\x0b\n\x04\x05\0\x02\x0c\x12\x03\x13\ - \x04\x1e\n\x0c\n\x05\x05\0\x02\x0c\x01\x12\x03\x13\x04\x18\n\x0c\n\x05\ - \x05\0\x02\x0c\x02\x12\x03\x13\x1b\x1d\n\x0b\n\x04\x05\0\x02\r\x12\x03\ - \x14\x04\x17\n\x0c\n\x05\x05\0\x02\r\x01\x12\x03\x14\x04\x11\n\x0c\n\x05\ - \x05\0\x02\r\x02\x12\x03\x14\x14\x16\n\x0b\n\x04\x05\0\x02\x0e\x12\x03\ - \x15\x04&\n\x0c\n\x05\x05\0\x02\x0e\x01\x12\x03\x15\x04\x20\n\x0c\n\x05\ - \x05\0\x02\x0e\x02\x12\x03\x15#%b\x06proto3\ + dNotMatch\x10\x04\x12\x1d\n\x19UserDatabaseInternalError\x10\x05\x12\x14\ + \n\x10SqlInternalError\x10\x06\x12\x13\n\x0fUserNotLoginYet\x10\n\x12\ + \x17\n\x13ReadCurrentIdFailed\x10\x0b\x12\x18\n\x14WriteCurrentIdFailed\ + \x10\x0c\x12\x10\n\x0cEmailInvalid\x10\x14\x12\x13\n\x0fPasswordInvalid\ + \x10\x15\x12\x13\n\x0fUserNameInvalid\x10\x16\x12\x18\n\x14UserWorkspace\ + Invalid\x10\x17\x12\x11\n\rUserIdInvalid\x10\x18\x12\x20\n\x1cCreateDefa\ + ultWorkspaceFailed\x10\x19\x12\x20\n\x1cDefaultWorkspaceAlreadyExist\x10\ + \x1aJ\xe9\x06\n\x06\x12\x04\0\0\x18\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\ + \n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\ + \x08\x11\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x1b\n\x0c\n\x05\x04\0\ + \x02\0\x06\x12\x03\x03\x04\x11\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\ + \x12\x16\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x19\x1a\n\x0b\n\x04\x04\ + \0\x02\x01\x12\x03\x04\x04\x13\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\ + \x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0e\n\x0c\n\x05\x04\ + \0\x02\x01\x03\x12\x03\x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\x18\x01\ + \n\n\n\x03\x05\0\x01\x12\x03\x06\x05\x12\n\x0b\n\x04\x05\0\x02\0\x12\x03\ + \x07\x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x07\x04\x0b\n\x0c\n\x05\ + \x05\0\x02\0\x02\x12\x03\x07\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\x12\x03\ + \x08\x04\x1f\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x08\x04\x1a\n\x0c\n\ + \x05\x05\0\x02\x01\x02\x12\x03\x08\x1d\x1e\n\x0b\n\x04\x05\0\x02\x02\x12\ + \x03\t\x04\x20\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\t\x04\x1b\n\x0c\n\ + \x05\x05\0\x02\x02\x02\x12\x03\t\x1e\x1f\n\x0b\n\x04\x05\0\x02\x03\x12\ + \x03\n\x04\x1f\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\n\x04\x1a\n\x0c\n\ + \x05\x05\0\x02\x03\x02\x12\x03\n\x1d\x1e\n\x0b\n\x04\x05\0\x02\x04\x12\ + \x03\x0b\x04\x20\n\x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x0b\x04\x1b\n\x0c\ + \n\x05\x05\0\x02\x04\x02\x12\x03\x0b\x1e\x1f\n\x0b\n\x04\x05\0\x02\x05\ + \x12\x03\x0c\x04\"\n\x0c\n\x05\x05\0\x02\x05\x01\x12\x03\x0c\x04\x1d\n\ + \x0c\n\x05\x05\0\x02\x05\x02\x12\x03\x0c\x20!\n\x0b\n\x04\x05\0\x02\x06\ + \x12\x03\r\x04\x19\n\x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\x04\x14\n\x0c\ + \n\x05\x05\0\x02\x06\x02\x12\x03\r\x17\x18\n\x0b\n\x04\x05\0\x02\x07\x12\ + \x03\x0e\x04\x19\n\x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x13\n\x0c\ + \n\x05\x05\0\x02\x07\x02\x12\x03\x0e\x16\x18\n\x0b\n\x04\x05\0\x02\x08\ + \x12\x03\x0f\x04\x1d\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0f\x04\x17\n\ + \x0c\n\x05\x05\0\x02\x08\x02\x12\x03\x0f\x1a\x1c\n\x0b\n\x04\x05\0\x02\t\ + \x12\x03\x10\x04\x1e\n\x0c\n\x05\x05\0\x02\t\x01\x12\x03\x10\x04\x18\n\ + \x0c\n\x05\x05\0\x02\t\x02\x12\x03\x10\x1b\x1d\n\x0b\n\x04\x05\0\x02\n\ + \x12\x03\x11\x04\x16\n\x0c\n\x05\x05\0\x02\n\x01\x12\x03\x11\x04\x10\n\ + \x0c\n\x05\x05\0\x02\n\x02\x12\x03\x11\x13\x15\n\x0b\n\x04\x05\0\x02\x0b\ + \x12\x03\x12\x04\x19\n\x0c\n\x05\x05\0\x02\x0b\x01\x12\x03\x12\x04\x13\n\ + \x0c\n\x05\x05\0\x02\x0b\x02\x12\x03\x12\x16\x18\n\x0b\n\x04\x05\0\x02\ + \x0c\x12\x03\x13\x04\x19\n\x0c\n\x05\x05\0\x02\x0c\x01\x12\x03\x13\x04\ + \x13\n\x0c\n\x05\x05\0\x02\x0c\x02\x12\x03\x13\x16\x18\n\x0b\n\x04\x05\0\ + \x02\r\x12\x03\x14\x04\x1e\n\x0c\n\x05\x05\0\x02\r\x01\x12\x03\x14\x04\ + \x18\n\x0c\n\x05\x05\0\x02\r\x02\x12\x03\x14\x1b\x1d\n\x0b\n\x04\x05\0\ + \x02\x0e\x12\x03\x15\x04\x17\n\x0c\n\x05\x05\0\x02\x0e\x01\x12\x03\x15\ + \x04\x11\n\x0c\n\x05\x05\0\x02\x0e\x02\x12\x03\x15\x14\x16\n\x0b\n\x04\ + \x05\0\x02\x0f\x12\x03\x16\x04&\n\x0c\n\x05\x05\0\x02\x0f\x01\x12\x03\ + \x16\x04\x20\n\x0c\n\x05\x05\0\x02\x0f\x02\x12\x03\x16#%\n\x0b\n\x04\x05\ + \0\x02\x10\x12\x03\x17\x04&\n\x0c\n\x05\x05\0\x02\x10\x01\x12\x03\x17\ + \x04\x20\n\x0c\n\x05\x05\0\x02\x10\x02\x12\x03\x17#%b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-user/src/protobuf/proto/errors.proto b/rust-lib/flowy-user/src/protobuf/proto/errors.proto index 1e644873fa..881ae87c12 100644 --- a/rust-lib/flowy-user/src/protobuf/proto/errors.proto +++ b/rust-lib/flowy-user/src/protobuf/proto/errors.proto @@ -11,6 +11,7 @@ enum UserErrorCode { UserDatabaseReadLocked = 3; UserDatabaseDidNotMatch = 4; UserDatabaseInternalError = 5; + SqlInternalError = 6; UserNotLoginYet = 10; ReadCurrentIdFailed = 11; WriteCurrentIdFailed = 12; @@ -20,4 +21,5 @@ enum UserErrorCode { UserWorkspaceInvalid = 23; UserIdInvalid = 24; CreateDefaultWorkspaceFailed = 25; + DefaultWorkspaceAlreadyExist = 26; } diff --git a/rust-lib/flowy-user/src/services/user_session/user_server.rs b/rust-lib/flowy-user/src/services/user_session/user_server.rs index ab9085b535..868b8d2b34 100644 --- a/rust-lib/flowy-user/src/services/user_session/user_server.rs +++ b/rust-lib/flowy-user/src/services/user_session/user_server.rs @@ -19,5 +19,5 @@ pub trait UserServer { name: &str, desc: &str, user_id: &str, - ) -> DispatchFuture>; + ) -> DispatchFuture>; } diff --git a/rust-lib/flowy-user/src/services/user_session/user_session.rs b/rust-lib/flowy-user/src/services/user_session/user_session.rs index a226a3d279..b1715214d4 100644 --- a/rust-lib/flowy-user/src/services/user_session/user_session.rs +++ b/rust-lib/flowy-user/src/services/user_session/user_session.rs @@ -63,21 +63,16 @@ impl UserSession { pub async fn sign_in(&self, params: SignInParams) -> Result { let user = self.server.sign_in(params)?; let _ = self.set_user_id(Some(user.id.clone()))?; + let user_table = self.save_user(user).await?; - let user_table = self.save_user(user)?; - let _ = self - .create_default_workspace_if_need(&user_table.id) - .await?; Ok(user_table) } pub async fn sign_up(&self, params: SignUpParams) -> Result { let user = self.server.sign_up(params)?; let _ = self.set_user_id(Some(user.id.clone()))?; - let user_table = self.save_user(user)?; - let _ = self - .create_default_workspace_if_need(&user_table.id) - .await?; + let user_table = self.save_user(user).await?; + Ok(user_table) } @@ -96,7 +91,13 @@ impl UserSession { Ok(()) } - fn save_user(&self, user: UserTable) -> Result { + async fn save_user(&self, mut user: UserTable) -> Result { + if user.workspace.is_empty() { + log::info!("Try to create user default workspace"); + let workspace_id = self.create_default_workspace_if_need(&user.id).await?; + user.workspace = workspace_id; + } + let conn = self.get_db_connection()?; let _ = diesel::insert_into(user_table::table) .values(user.clone()) @@ -109,7 +110,6 @@ impl UserSession { let changeset = UserTableChangeset::new(params); let conn = self.get_db_connection()?; diesel_update_table!(user_table, changeset, conn); - let user_detail = self.user_detail()?; Ok(user_detail) } @@ -146,6 +146,11 @@ impl UserSession { } } + pub fn get_user_dir(&self) -> Result { + let user_id = self.get_user_id()?; + Ok(format!("{}/{}", self.config.root_dir, user_id)) + } + pub fn get_user_id(&self) -> Result { let mut user_id = { let read_guard = self.user_id.read().map_err(|e| { @@ -183,19 +188,18 @@ impl UserSession { Ok(()) } - async fn create_default_workspace_if_need(&self, user_id: &str) -> Result<(), UserError> { + async fn create_default_workspace_if_need(&self, user_id: &str) -> Result { let key = format!("{}{}", user_id, DEFAULT_WORKSPACE); if KVStore::get_bool(&key).unwrap_or(false) { - return Ok(()); + return Err(ErrorBuilder::new(UserErrorCode::DefaultWorkspaceAlreadyExist).build()); } - KVStore::set_bool(&key, true); log::debug!("Create user:{} default workspace", user_id); - let _ = self + let workspace_id = self .server .create_workspace(DEFAULT_WORKSPACE_NAME, DEFAULT_WORKSPACE_DESC, user_id) .await?; - Ok(()) + Ok(workspace_id) } } diff --git a/rust-lib/flowy-user/tests/event/user_status_test.rs b/rust-lib/flowy-user/tests/event/user_status_test.rs index 391a325acd..ba0d657d3b 100644 --- a/rust-lib/flowy-user/tests/event/user_status_test.rs +++ b/rust-lib/flowy-user/tests/event/user_status_test.rs @@ -5,7 +5,7 @@ use serial_test::*; #[test] #[serial] fn user_status_get_failed_before_login() { - let a = UserTestBuilder::new() + let _a = UserTestBuilder::new() .logout() .event(GetStatus) .assert_error() diff --git a/rust-lib/flowy-workspace/Cargo.toml b/rust-lib/flowy-workspace/Cargo.toml index 3ec792721b..e548bb000f 100644 --- a/rust-lib/flowy-workspace/Cargo.toml +++ b/rust-lib/flowy-workspace/Cargo.toml @@ -12,6 +12,7 @@ flowy-derive = { path = "../flowy-derive" } flowy-database = { path = "../flowy-database" } flowy-sqlite = { path = "../flowy-sqlite" } flowy-infra = { path = "../flowy-infra" } +flowy-observable = { path = "../flowy-observable" } protobuf = {version = "2.18.0"} log = "0.4.14" diesel = {version = "1.4.7", features = ["sqlite"]} @@ -24,6 +25,8 @@ serde = { version = "1.0", features = ["derive"] } derive_more = {version = "0.99", features = ["display"]} bincode = { version = "1.3"} unicode-segmentation = "1.7.1" +tracing = { version = "0.1", features = ["log"] } [dev-dependencies] -flowy-test = { path = "../flowy-test" } \ No newline at end of file +flowy-test = { path = "../flowy-test" } +serial_test = "0.5.1" \ No newline at end of file diff --git a/rust-lib/flowy-workspace/Flowy.toml b/rust-lib/flowy-workspace/Flowy.toml index 728e5eb776..f66326779a 100644 --- a/rust-lib/flowy-workspace/Flowy.toml +++ b/rust-lib/flowy-workspace/Flowy.toml @@ -1,3 +1,3 @@ -proto_crates = ["src/entities", "src/event.rs", "src/errors.rs"] +proto_crates = ["src/entities", "src/event.rs", "src/errors.rs", "src/observable"] event_files = ["src/event.rs"] \ No newline at end of file diff --git a/rust-lib/flowy-workspace/src/entities/app/app_create.rs b/rust-lib/flowy-workspace/src/entities/app/app_create.rs index e4bbba81b2..a7cfe093df 100644 --- a/rust-lib/flowy-workspace/src/entities/app/app_create.rs +++ b/rust-lib/flowy-workspace/src/entities/app/app_create.rs @@ -1,9 +1,11 @@ use crate::{ entities::{ app::parser::{AppColorStyle, AppName}, + view::RepeatedView, workspace::parser::WorkspaceId, }, errors::*, + impl_def_and_def_mut, }; use flowy_derive::ProtoBuf; use std::convert::TryInto; @@ -67,7 +69,7 @@ impl TryInto for CreateAppRequest { } } -#[derive(ProtoBuf, Default, Debug)] +#[derive(PartialEq, ProtoBuf, Default, Debug)] pub struct App { #[pb(index = 1)] pub id: String, @@ -80,4 +82,15 @@ pub struct App { #[pb(index = 4)] pub desc: String, + + #[pb(index = 5)] + pub views: RepeatedView, } + +#[derive(Debug, Default, ProtoBuf)] +pub struct RepeatedApp { + #[pb(index = 1)] + pub items: Vec, +} + +impl_def_and_def_mut!(RepeatedApp, App); diff --git a/rust-lib/flowy-workspace/src/entities/app/app_query.rs b/rust-lib/flowy-workspace/src/entities/app/app_query.rs new file mode 100644 index 0000000000..317e3e25f9 --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/app/app_query.rs @@ -0,0 +1,36 @@ +use crate::{entities::app::parser::AppId, errors::*}; +use flowy_derive::ProtoBuf; +use std::convert::TryInto; + +#[derive(Default, ProtoBuf)] +pub struct QueryAppRequest { + #[pb(index = 1)] + pub app_id: String, + + #[pb(index = 2)] + pub read_views: bool, +} + +pub struct QueryAppParams { + pub app_id: String, + pub read_views: bool, +} + +impl TryInto for QueryAppRequest { + type Error = WorkspaceError; + + fn try_into(self) -> Result { + let app_id = AppId::parse(self.app_id) + .map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::AppIdInvalid) + .msg(e) + .build() + })? + .0; + + Ok(QueryAppParams { + app_id, + read_views: self.read_views, + }) + } +} diff --git a/rust-lib/flowy-workspace/src/entities/app/mod.rs b/rust-lib/flowy-workspace/src/entities/app/mod.rs index 3f23b6b562..8c51f2be1a 100644 --- a/rust-lib/flowy-workspace/src/entities/app/mod.rs +++ b/rust-lib/flowy-workspace/src/entities/app/mod.rs @@ -2,5 +2,8 @@ pub use app_create::*; pub use app_update::*; mod app_create; +mod app_query; mod app_update; pub mod parser; + +pub use app_query::*; diff --git a/rust-lib/flowy-workspace/src/entities/view/mod.rs b/rust-lib/flowy-workspace/src/entities/view/mod.rs index f9768ab8f2..a3cd566712 100644 --- a/rust-lib/flowy-workspace/src/entities/view/mod.rs +++ b/rust-lib/flowy-workspace/src/entities/view/mod.rs @@ -1,4 +1,8 @@ mod parser; mod view_create; +mod view_query; +mod view_update; pub use view_create::*; +pub use view_query::*; +pub use view_update::*; diff --git a/rust-lib/flowy-workspace/src/entities/view/parser/mod.rs b/rust-lib/flowy-workspace/src/entities/view/parser/mod.rs index 088fdf8144..b1419ab961 100644 --- a/rust-lib/flowy-workspace/src/entities/view/parser/mod.rs +++ b/rust-lib/flowy-workspace/src/entities/view/parser/mod.rs @@ -1,9 +1,11 @@ mod view_desc; +mod view_id; mod view_name; mod view_thumbnail; mod view_type; pub use view_desc::*; +pub use view_id::*; pub use view_name::*; pub use view_thumbnail::*; pub use view_type::*; diff --git a/rust-lib/flowy-workspace/src/entities/view/parser/view_id.rs b/rust-lib/flowy-workspace/src/entities/view/parser/view_id.rs new file mode 100644 index 0000000000..ef8844a049 --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/view/parser/view_id.rs @@ -0,0 +1,12 @@ +#[derive(Debug)] +pub struct ViewId(pub String); + +impl ViewId { + pub fn parse(s: String) -> Result { + if s.trim().is_empty() { + return Err(format!("View id can not be empty or whitespace")); + } + + Ok(Self(s)) + } +} diff --git a/rust-lib/flowy-workspace/src/entities/view/parser/view_thumbnail.rs b/rust-lib/flowy-workspace/src/entities/view/parser/view_thumbnail.rs index 6fe1aba136..303a2020a2 100644 --- a/rust-lib/flowy-workspace/src/entities/view/parser/view_thumbnail.rs +++ b/rust-lib/flowy-workspace/src/entities/view/parser/view_thumbnail.rs @@ -1,5 +1,3 @@ -use unicode_segmentation::UnicodeSegmentation; - #[derive(Debug)] pub struct ViewThumbnail(pub String); diff --git a/rust-lib/flowy-workspace/src/entities/view/parser/view_type.rs b/rust-lib/flowy-workspace/src/entities/view/parser/view_type.rs index 7486a6bdb5..286d7d8c17 100644 --- a/rust-lib/flowy-workspace/src/entities/view/parser/view_type.rs +++ b/rust-lib/flowy-workspace/src/entities/view/parser/view_type.rs @@ -1,13 +1,15 @@ -use crate::{entities::view::ViewTypeIdentifier, sql_tables::view::ViewType}; -use unicode_segmentation::UnicodeSegmentation; +use crate::{entities::view::ViewType, sql_tables::view::ViewTableType}; #[derive(Debug)] -pub struct ViewTypeCheck(pub ViewType); +pub struct ViewTypeCheck(pub ViewTableType); impl ViewTypeCheck { - pub fn parse(s: ViewTypeIdentifier) -> Result { + pub fn parse(s: ViewType) -> Result { match s { - ViewTypeIdentifier::Docs => Ok(Self(ViewType::Docs)), + ViewType::Blank => { + Err("Impossible to here, because you can create blank view".to_owned()) + }, + ViewType::Doc => Ok(Self(ViewTableType::Docs)), } } } diff --git a/rust-lib/flowy-workspace/src/entities/view/view_create.rs b/rust-lib/flowy-workspace/src/entities/view/view_create.rs index 10b81491b8..a52d713e67 100644 --- a/rust-lib/flowy-workspace/src/entities/view/view_create.rs +++ b/rust-lib/flowy-workspace/src/entities/view/view_create.rs @@ -1,18 +1,20 @@ use crate::{ entities::{app::parser::AppId, view::parser::*}, errors::{ErrorBuilder, WorkspaceError, WorkspaceErrorCode}, - sql_tables::view::ViewType, + impl_def_and_def_mut, + sql_tables::view::ViewTableType, }; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use std::convert::TryInto; -#[derive(Debug, ProtoBuf_Enum)] -pub enum ViewTypeIdentifier { - Docs = 0, +#[derive(PartialEq, Debug, ProtoBuf_Enum)] +pub enum ViewType { + Blank = 0, + Doc = 1, } -impl std::default::Default for ViewTypeIdentifier { - fn default() -> Self { ViewTypeIdentifier::Docs } +impl std::default::Default for ViewType { + fn default() -> Self { ViewType::Blank } } #[derive(Default, ProtoBuf)] @@ -30,7 +32,7 @@ pub struct CreateViewRequest { pub thumbnail: Option, #[pb(index = 5)] - pub view_type: ViewTypeIdentifier, + pub view_type: ViewType, } pub struct CreateViewParams { @@ -38,7 +40,7 @@ pub struct CreateViewParams { pub name: String, pub desc: String, pub thumbnail: String, - pub view_type: ViewType, + pub view_type: ViewTableType, } impl TryInto for CreateViewRequest { @@ -66,7 +68,7 @@ impl TryInto for CreateViewRequest { Some(thumbnail) => { ViewThumbnail::parse(thumbnail) .map_err(|e| { - ErrorBuilder::new(WorkspaceErrorCode::ViewThumbnailName) + ErrorBuilder::new(WorkspaceErrorCode::ViewThumbnailInvalid) .msg(e) .build() })? @@ -85,7 +87,7 @@ impl TryInto for CreateViewRequest { } } -#[derive(ProtoBuf, Default, Debug)] +#[derive(PartialEq, ProtoBuf, Default, Debug)] pub struct View { #[pb(index = 1)] pub id: String, @@ -100,5 +102,13 @@ pub struct View { pub desc: String, #[pb(index = 5)] - pub view_type: ViewTypeIdentifier, + pub view_type: ViewType, } + +#[derive(PartialEq, Debug, Default, ProtoBuf)] +pub struct RepeatedView { + #[pb(index = 1)] + pub items: Vec, +} + +impl_def_and_def_mut!(RepeatedView, View); diff --git a/rust-lib/flowy-workspace/src/entities/view/view_query.rs b/rust-lib/flowy-workspace/src/entities/view/view_query.rs new file mode 100644 index 0000000000..0e99b53e72 --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/view/view_query.rs @@ -0,0 +1,32 @@ +use crate::{ + entities::view::parser::ViewId, + errors::{ErrorBuilder, WorkspaceError, WorkspaceErrorCode}, +}; +use flowy_derive::ProtoBuf; +use std::convert::TryInto; + +#[derive(Default, ProtoBuf)] +pub struct QueryViewRequest { + #[pb(index = 1)] + pub view_id: String, +} + +pub struct QueryViewParams { + pub view_id: String, +} + +impl TryInto for QueryViewRequest { + type Error = WorkspaceError; + + fn try_into(self) -> Result { + let view_id = ViewId::parse(self.view_id) + .map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::ViewIdInvalid) + .msg(e) + .build() + })? + .0; + + Ok(QueryViewParams { view_id }) + } +} diff --git a/rust-lib/flowy-workspace/src/entities/view/view_update.rs b/rust-lib/flowy-workspace/src/entities/view/view_update.rs new file mode 100644 index 0000000000..07719f83bc --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/view/view_update.rs @@ -0,0 +1,88 @@ +use crate::{ + entities::view::parser::{ViewId, *}, + errors::{ErrorBuilder, WorkspaceError, WorkspaceErrorCode}, +}; +use flowy_derive::ProtoBuf; +use std::convert::TryInto; + +#[derive(Default, ProtoBuf)] +pub struct UpdateViewRequest { + #[pb(index = 1)] + pub view_id: String, + + #[pb(index = 2, one_of)] + pub name: Option, + + #[pb(index = 3, one_of)] + pub desc: Option, + + #[pb(index = 4, one_of)] + pub thumbnail: Option, +} + +pub struct UpdateViewParams { + pub view_id: String, + pub name: Option, + pub desc: Option, + pub thumbnail: Option, +} + +impl TryInto for UpdateViewRequest { + type Error = WorkspaceError; + + fn try_into(self) -> Result { + let view_id = ViewId::parse(self.view_id) + .map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::ViewIdInvalid) + .msg(e) + .build() + })? + .0; + + let name = match self.name { + None => None, + Some(name) => Some( + ViewName::parse(name) + .map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::ViewNameInvalid) + .msg(e) + .build() + })? + .0, + ), + }; + + let desc = match self.desc { + None => None, + Some(desc) => Some( + ViewDesc::parse(desc) + .map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::ViewDescInvalid) + .msg(e) + .build() + })? + .0, + ), + }; + + let thumbnail = match self.thumbnail { + None => None, + Some(thumbnail) => Some( + ViewThumbnail::parse(thumbnail) + .map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::ViewThumbnailInvalid) + .msg(e) + .build() + })? + .0, + ), + }; + + Ok(UpdateViewParams { + view_id, + name, + desc, + thumbnail, + }) + } +} diff --git a/rust-lib/flowy-workspace/src/entities/workspace/workspace_create.rs b/rust-lib/flowy-workspace/src/entities/workspace/workspace_create.rs index 6a1b4656b7..b20240754d 100644 --- a/rust-lib/flowy-workspace/src/entities/workspace/workspace_create.rs +++ b/rust-lib/flowy-workspace/src/entities/workspace/workspace_create.rs @@ -1,4 +1,10 @@ -use crate::{entities::workspace::parser::*, errors::*}; +use crate::{ + entities::{ + app::{App, RepeatedApp}, + workspace::parser::*, + }, + errors::*, +}; use flowy_derive::ProtoBuf; use std::convert::TryInto; @@ -43,4 +49,7 @@ pub struct Workspace { #[pb(index = 3)] pub desc: String, + + #[pb(index = 4)] + pub apps: RepeatedApp, } diff --git a/rust-lib/flowy-workspace/src/entities/workspace/workspace_query.rs b/rust-lib/flowy-workspace/src/entities/workspace/workspace_query.rs index 8f63e65520..f801713ab5 100644 --- a/rust-lib/flowy-workspace/src/entities/workspace/workspace_query.rs +++ b/rust-lib/flowy-workspace/src/entities/workspace/workspace_query.rs @@ -1,51 +1,36 @@ -// use crate::sql_tables::workspace::Workspace; -// -// #[derive(Default, Debug, ProtoBuf)] -// pub struct WorkspaceDetail { -// #[pb(index = 1)] -// pub workspace: Workspace, -// -// #[pb(index = 2)] -// pub apps: Vec, -// } +use crate::{entities::workspace::parser::*, errors::*}; +use flowy_derive::ProtoBuf; +use std::convert::TryInto; -// use crate::entities::{RepeatedApp, Workspace}; -// use flowy_derive::ProtoBuf; -// use flowy_traits::cqrs::Identifiable; -// -// #[derive(ProtoBuf, Default, Debug)] -// pub struct WorkspaceQuery { -// #[pb(index = 1)] -// pub workspace_id: String, -// -// #[pb(index = 2)] -// pub read_apps: bool, -// } -// -// impl WorkspaceQuery { -// pub fn read_workspace(workspace_id: &str) -> Self { -// WorkspaceQuery { -// workspace_id: workspace_id.to_string(), -// read_apps: false, -// } -// } -// -// pub fn read_apps(workspace_id: &str) -> Self { -// WorkspaceQuery { -// workspace_id: workspace_id.to_string(), -// read_apps: true, -// } -// } -// } -// -// #[derive(Default, Debug, ProtoBuf)] -// pub struct WorkspaceQueryResult { -// #[pb(index = 1, oneof)] -// pub workspace: Option, -// -// #[pb(index = 2, oneof)] -// pub apps: Option, -// -// #[pb(index = 100)] -// pub error: String, -// } +#[derive(Default, ProtoBuf)] +pub struct QueryWorkspaceRequest { + #[pb(index = 1)] + pub workspace_id: String, + + #[pb(index = 2)] + pub read_apps: bool, +} + +pub struct QueryWorkspaceParams { + pub workspace_id: String, + pub read_apps: bool, +} + +impl TryInto for QueryWorkspaceRequest { + type Error = WorkspaceError; + + fn try_into(self) -> Result { + let workspace_id = WorkspaceId::parse(self.workspace_id) + .map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::WorkspaceIdInvalid) + .msg(e) + .build() + })? + .0; + + Ok(QueryWorkspaceParams { + workspace_id, + read_apps: self.read_apps, + }) + } +} diff --git a/rust-lib/flowy-workspace/src/entities/workspace/workspace_user_detail.rs b/rust-lib/flowy-workspace/src/entities/workspace/workspace_user_detail.rs index 5db0639f39..757b7a1859 100644 --- a/rust-lib/flowy-workspace/src/entities/workspace/workspace_user_detail.rs +++ b/rust-lib/flowy-workspace/src/entities/workspace/workspace_user_detail.rs @@ -1,20 +1,10 @@ -use crate::entities::workspace::Workspace; use flowy_derive::ProtoBuf; #[derive(ProtoBuf, Default, Debug)] -pub struct UserWorkspace { +pub struct CurrentWorkspace { #[pb(index = 1)] pub owner: String, #[pb(index = 2)] pub workspace_id: String, } - -#[derive(ProtoBuf, Default, Debug)] -pub struct UserWorkspaceDetail { - #[pb(index = 1)] - pub owner: String, - - #[pb(index = 2)] - pub workspace: Workspace, -} diff --git a/rust-lib/flowy-workspace/src/errors.rs b/rust-lib/flowy-workspace/src/errors.rs index ec8380c2eb..c97ce14c53 100644 --- a/rust-lib/flowy-workspace/src/errors.rs +++ b/rust-lib/flowy-workspace/src/errors.rs @@ -32,20 +32,26 @@ pub enum WorkspaceErrorCode { #[display(fmt = "Workspace id is invalid")] WorkspaceIdInvalid = 2, - #[display(fmt = "App color style format error")] + #[display(fmt = "Color style of the App is invalid")] AppColorStyleInvalid = 3, - #[display(fmt = "App id is invalid")] + #[display(fmt = "Id of the App is invalid")] AppIdInvalid = 10, - #[display(fmt = "App name is invalid")] + #[display(fmt = "Name of the App is invalid")] AppNameInvalid = 11, - #[display(fmt = "View name is invalid")] + #[display(fmt = "Name of the View is invalid")] ViewNameInvalid = 20, #[display(fmt = "Thumbnail of the view is invalid")] - ViewThumbnailName = 21, + ViewThumbnailInvalid = 21, + + #[display(fmt = "Id of the View is invalid")] + ViewIdInvalid = 22, + + #[display(fmt = "Description of the View is invalid")] + ViewDescInvalid = 23, #[display(fmt = "Get database connection failed")] DatabaseConnectionFail = 100, diff --git a/rust-lib/flowy-workspace/src/event.rs b/rust-lib/flowy-workspace/src/event.rs index fd707f9995..d4bfe12cb1 100644 --- a/rust-lib/flowy-workspace/src/event.rs +++ b/rust-lib/flowy-workspace/src/event.rs @@ -4,19 +4,35 @@ use flowy_derive::{Flowy_Event, ProtoBuf_Enum}; #[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)] #[event_err = "WorkspaceError"] pub enum WorkspaceEvent { - #[display(fmt = "Create workspace")] - #[event(input = "CreateSpaceRequest", output = "WorkspaceDetail")] - CreateWorkspace = 0, + #[display(fmt = "CreateWorkspace")] + #[event(input = "CreateWorkspaceRequest", output = "Workspace")] + CreateWorkspace = 0, - #[display(fmt = "Get user's workspace detail")] - #[event(output = "UserWorkspaceDetail")] - GetWorkspaceDetail = 1, + #[display(fmt = "GetCurWorkspace")] + #[event(output = "Workspace")] + GetCurWorkspace = 1, - #[display(fmt = "Create app")] + #[display(fmt = "GetWorkspace")] + #[event(input = "QueryWorkspaceRequest", output = "Workspace")] + GetWorkspace = 2, + + #[display(fmt = "CreateApp")] #[event(input = "CreateAppRequest", output = "App")] - CreateApp = 101, + CreateApp = 101, - #[display(fmt = "Create view")] + #[display(fmt = "GetApp")] + #[event(input = "QueryAppRequest", output = "App")] + GetApp = 102, + + #[display(fmt = "CreateView")] #[event(input = "CreateViewRequest", output = "View")] - CreateView = 201, + CreateView = 201, + + #[display(fmt = "ReadView")] + #[event(input = "QueryViewRequest", output = "View")] + ReadView = 202, + + #[display(fmt = "UpdateView")] + #[event(input = "UpdateViewRequest")] + UpdateView = 203, } diff --git a/rust-lib/flowy-workspace/src/handlers/app_handler.rs b/rust-lib/flowy-workspace/src/handlers/app_handler.rs index 0100bffceb..77e0cb9707 100644 --- a/rust-lib/flowy-workspace/src/handlers/app_handler.rs +++ b/rust-lib/flowy-workspace/src/handlers/app_handler.rs @@ -1,16 +1,35 @@ use crate::{ - entities::app::{App, CreateAppParams, CreateAppRequest}, + entities::{ + app::{App, CreateAppParams, CreateAppRequest, QueryAppParams, QueryAppRequest}, + view::RepeatedView, + }, errors::WorkspaceError, services::AppController, }; -use flowy_dispatch::prelude::{response_ok, Data, ModuleData, ResponseResult}; +use flowy_dispatch::prelude::{response_ok, Data, ResponseResult, Unit}; use std::{convert::TryInto, sync::Arc}; +#[tracing::instrument(name = "create_app", skip(data, controller))] pub async fn create_app( data: Data, - controller: ModuleData>, + controller: Unit>, ) -> ResponseResult { let params: CreateAppParams = data.into_inner().try_into()?; - let detail = controller.save_app(params)?; + let detail = controller.create_app(params)?; response_ok(detail) } + +#[tracing::instrument(name = "get_app", skip(data, controller))] +pub async fn get_app( + data: Data, + controller: Unit>, +) -> ResponseResult { + let params: QueryAppParams = data.into_inner().try_into()?; + let mut app = controller.read_app(¶ms.app_id).await?; + if params.read_views { + let views = controller.read_views(¶ms.app_id).await?; + app.views = RepeatedView { items: views }; + } + + response_ok(app) +} diff --git a/rust-lib/flowy-workspace/src/handlers/view_handler.rs b/rust-lib/flowy-workspace/src/handlers/view_handler.rs index 45510b708b..9dbb7ecacb 100644 --- a/rust-lib/flowy-workspace/src/handlers/view_handler.rs +++ b/rust-lib/flowy-workspace/src/handlers/view_handler.rs @@ -1,16 +1,44 @@ use crate::{ - entities::view::{CreateViewParams, CreateViewRequest, View}, + entities::view::{ + CreateViewParams, + CreateViewRequest, + QueryViewParams, + QueryViewRequest, + UpdateViewParams, + UpdateViewRequest, + View, + }, errors::WorkspaceError, services::ViewController, }; -use flowy_dispatch::prelude::{response_ok, Data, ModuleData, ResponseResult}; +use flowy_dispatch::prelude::{response_ok, Data, ResponseResult, Unit}; use std::{convert::TryInto, sync::Arc}; pub async fn create_view( data: Data, - controller: ModuleData>, + controller: Unit>, ) -> ResponseResult { let params: CreateViewParams = data.into_inner().try_into()?; - let view = controller.save_view(params).await?; + let view = controller.create_view(params).await?; response_ok(view) } + +pub async fn read_view( + data: Data, + controller: Unit>, +) -> ResponseResult { + let params: QueryViewParams = data.into_inner().try_into()?; + let view = controller.read_view(¶ms.view_id).await?; + + response_ok(view) +} + +pub async fn update_view( + data: Data, + controller: Unit>, +) -> Result<(), WorkspaceError> { + let params: UpdateViewParams = data.into_inner().try_into()?; + let _ = controller.update_view(params).await?; + + Ok(()) +} diff --git a/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs b/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs index ff73d58abf..04ce81c674 100644 --- a/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs +++ b/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs @@ -1,30 +1,42 @@ use crate::{ - entities::workspace::{ - CreateWorkspaceParams, - CreateWorkspaceRequest, - UserWorkspace, - UserWorkspaceDetail, - Workspace, - }, + entities::{app::RepeatedApp, workspace::*}, errors::WorkspaceError, services::WorkspaceController, }; -use flowy_dispatch::prelude::{response_ok, Data, ModuleData, ResponseResult}; +use flowy_dispatch::prelude::{response_ok, Data, ResponseResult, Unit}; use std::{convert::TryInto, sync::Arc}; +#[tracing::instrument(name = "create_workspace", skip(data, controller))] pub async fn create_workspace( data: Data, - controller: ModuleData>, + controller: Unit>, ) -> ResponseResult { let controller = controller.get_ref().clone(); let params: CreateWorkspaceParams = data.into_inner().try_into()?; - let detail = controller.save_workspace(params).await?; + let detail = controller.create_workspace(params).await?; response_ok(detail) } -pub async fn get_workspace_detail( - controller: ModuleData>, -) -> ResponseResult { - let user_workspace = controller.get_user_workspace_detail().await?; - response_ok(user_workspace) +#[tracing::instrument(name = "get_cur_workspace", skip(controller))] +pub async fn get_cur_workspace( + controller: Unit>, +) -> ResponseResult { + let workspace = controller.read_cur_workspace().await?; + response_ok(workspace) +} + +#[tracing::instrument(name = "get_workspace", skip(data, controller))] +pub async fn get_workspace( + data: Data, + controller: Unit>, +) -> ResponseResult { + let params: QueryWorkspaceParams = data.into_inner().try_into()?; + let mut workspace = controller.read_workspace(¶ms.workspace_id).await?; + + if params.read_apps { + let apps = controller.read_apps(¶ms.workspace_id).await?; + workspace.apps = RepeatedApp { items: apps }; + } + + response_ok(workspace) } diff --git a/rust-lib/flowy-workspace/src/lib.rs b/rust-lib/flowy-workspace/src/lib.rs index 111c190399..c24d413009 100644 --- a/rust-lib/flowy-workspace/src/lib.rs +++ b/rust-lib/flowy-workspace/src/lib.rs @@ -7,6 +7,7 @@ mod sql_tables; #[macro_use] mod macros; +mod observable; mod protobuf; mod services; diff --git a/rust-lib/flowy-workspace/src/macros.rs b/rust-lib/flowy-workspace/src/macros.rs index 76431defce..2e7e16e347 100644 --- a/rust-lib/flowy-workspace/src/macros.rs +++ b/rust-lib/flowy-workspace/src/macros.rs @@ -80,3 +80,46 @@ macro_rules! impl_sql_integer_expression { } }; } +// #[macro_export] +// macro_rules! impl_save_func { +// ($func_name:ident, $target:ident, $table_name:expr, $conn:ident) => { +// fn $func_name(object: $target) -> Result<(), WorkspaceError> { +// let _ = diesel::insert_into($table_name) +// .values($target) +// .execute(&*($conn))?; +// } +// }; +// } + +#[macro_export] +macro_rules! impl_def_and_def_mut { + ($target:ident, $item: ident) => { + impl std::ops::Deref for $target { + type Target = Vec<$item>; + + fn deref(&self) -> &Self::Target { &self.items } + } + impl std::ops::DerefMut for $target { + fn deref_mut(&mut self) -> &mut Self::Target { &mut self.items } + } + + impl $target { + #[allow(dead_code)] + pub fn take_items(&mut self) -> Vec<$item> { + ::std::mem::replace(&mut self.items, vec![]) + } + + #[allow(dead_code)] + pub fn push(&mut self, item: $item) { + if self.items.contains(&item) { + log::error!("add duplicate item: {:?}", item); + return; + } + + self.items.push(item); + } + + pub fn first_or_crash(&self) -> &$item { self.items.first().unwrap() } + } + }; +} diff --git a/rust-lib/flowy-workspace/src/module.rs b/rust-lib/flowy-workspace/src/module.rs index 7d5f7f540e..d6df59bad3 100644 --- a/rust-lib/flowy-workspace/src/module.rs +++ b/rust-lib/flowy-workspace/src/module.rs @@ -7,19 +7,34 @@ use crate::{ }; use flowy_database::DBConnection; -use crate::{entities::workspace::UserWorkspace, handlers::*, services::ViewController}; +use crate::{entities::workspace::CurrentWorkspace, handlers::*, services::ViewController}; use std::sync::Arc; +pub trait WorkspaceDeps: WorkspaceUser + WorkspaceDatabase {} + pub trait WorkspaceUser: Send + Sync { fn set_cur_workspace_id(&self, id: &str) -> DispatchFuture>; - fn get_cur_workspace(&self) -> DispatchFuture>; + fn get_cur_workspace(&self) -> DispatchFuture>; +} + +pub trait WorkspaceDatabase: Send + Sync { fn db_connection(&self) -> Result; } -pub fn create(user: Arc) -> Module { - let workspace_controller = Arc::new(WorkspaceController::new(user.clone())); - let app_controller = Arc::new(AppController::new(user.clone())); - let view_controller = Arc::new(ViewController::new(user.clone())); +pub fn create(user: Arc, database: Arc) -> Module { + let view_controller = Arc::new(ViewController::new(database.clone())); + + let app_controller = Arc::new(AppController::new( + user.clone(), + database.clone(), + view_controller.clone(), + )); + + let workspace_controller = Arc::new(WorkspaceController::new( + user.clone(), + database.clone(), + app_controller.clone(), + )); Module::new() .name("Flowy-Workspace") @@ -27,7 +42,11 @@ pub fn create(user: Arc) -> Module { .data(app_controller) .data(view_controller) .event(WorkspaceEvent::CreateWorkspace, create_workspace) - .event(WorkspaceEvent::GetWorkspaceDetail, get_workspace_detail) + .event(WorkspaceEvent::GetCurWorkspace, get_cur_workspace) + .event(WorkspaceEvent::GetWorkspace, get_workspace) .event(WorkspaceEvent::CreateApp, create_app) + .event(WorkspaceEvent::GetApp, get_app) .event(WorkspaceEvent::CreateView, create_view) + .event(WorkspaceEvent::ReadView, read_view) + .event(WorkspaceEvent::UpdateView, update_view) } diff --git a/rust-lib/flowy-workspace/src/observable/mod.rs b/rust-lib/flowy-workspace/src/observable/mod.rs new file mode 100644 index 0000000000..66a2058d79 --- /dev/null +++ b/rust-lib/flowy-workspace/src/observable/mod.rs @@ -0,0 +1,3 @@ +mod observable; + +pub use observable::*; diff --git a/rust-lib/flowy-workspace/src/observable/observable.rs b/rust-lib/flowy-workspace/src/observable/observable.rs new file mode 100644 index 0000000000..0533de73c8 --- /dev/null +++ b/rust-lib/flowy-workspace/src/observable/observable.rs @@ -0,0 +1,76 @@ +use flowy_derive::ProtoBuf_Enum; +use flowy_dispatch::prelude::ToBytes; +use flowy_observable::{dart::RustStreamSender, entities::ObservableSubject}; +const OBSERVABLE_CATEGORY: &'static str = "Workspace"; + +#[derive(ProtoBuf_Enum, Debug)] +pub(crate) enum WorkspaceObservable { + Unknown = 0, + + WorkspaceUpdateDesc = 10, + WorkspaceAddApp = 11, + + AppUpdateDesc = 20, + AppAddView = 21, + + ViewUpdateDesc = 30, +} + +impl std::default::Default for WorkspaceObservable { + fn default() -> Self { WorkspaceObservable::Unknown } +} + +pub(crate) struct ObservableSender { + ty: WorkspaceObservable, + subject_id: String, + payload: Option>, +} + +impl ObservableSender { + pub(crate) fn new(subject_id: &str, ty: WorkspaceObservable) -> Self { + Self { + subject_id: subject_id.to_owned(), + ty, + payload: None, + } + } + + pub(crate) fn payload(mut self, payload: T) -> Self + where + T: ToBytes, + { + let bytes = payload.into_bytes().unwrap(); + self.payload = Some(bytes); + self + } + + pub(crate) fn send(self) { + log::debug!( + "Workspace observable id: {}, ty: {:?}", + self.subject_id, + self.ty + ); + + let subject = ObservableSubject { + category: OBSERVABLE_CATEGORY.to_string(), + ty: self.ty as i32, + subject_id: self.subject_id, + subject_payload: self.payload, + }; + match RustStreamSender::post(subject) { + Ok(_) => {}, + Err(error) => log::error!("Send observable subject failed: {}", error), + } + } +} + +pub(crate) fn send_observable(id: &str, ty: WorkspaceObservable) { + ObservableSender::new(id, ty).send(); +} + +pub(crate) fn send_observable_with_payload(id: &str, ty: WorkspaceObservable, payload: T) +where + T: ToBytes, +{ + ObservableSender::new(id, ty).payload(payload).send(); +} diff --git a/rust-lib/flowy-workspace/src/protobuf/model/app_create.rs b/rust-lib/flowy-workspace/src/protobuf/model/app_create.rs index d2dd5814d0..efe0ac25b8 100644 --- a/rust-lib/flowy-workspace/src/protobuf/model/app_create.rs +++ b/rust-lib/flowy-workspace/src/protobuf/model/app_create.rs @@ -489,6 +489,7 @@ pub struct App { pub workspace_id: ::std::string::String, pub name: ::std::string::String, pub desc: ::std::string::String, + pub views: ::protobuf::SingularPtrField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -608,10 +609,48 @@ impl App { pub fn take_desc(&mut self) -> ::std::string::String { ::std::mem::replace(&mut self.desc, ::std::string::String::new()) } + + // .RepeatedView views = 5; + + + pub fn get_views(&self) -> &super::view_create::RepeatedView { + self.views.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_views(&mut self) { + self.views.clear(); + } + + pub fn has_views(&self) -> bool { + self.views.is_some() + } + + // Param is passed by value, moved + pub fn set_views(&mut self, v: super::view_create::RepeatedView) { + self.views = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_views(&mut self) -> &mut super::view_create::RepeatedView { + if self.views.is_none() { + self.views.set_default(); + } + self.views.as_mut().unwrap() + } + + // Take field + pub fn take_views(&mut self) -> super::view_create::RepeatedView { + self.views.take().unwrap_or_else(|| super::view_create::RepeatedView::new()) + } } impl ::protobuf::Message for App { fn is_initialized(&self) -> bool { + for v in &self.views { + if !v.is_initialized() { + return false; + } + }; true } @@ -631,6 +670,9 @@ impl ::protobuf::Message for App { 4 => { ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.desc)?; }, + 5 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.views)?; + }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; }, @@ -655,6 +697,10 @@ impl ::protobuf::Message for App { if !self.desc.is_empty() { my_size += ::protobuf::rt::string_size(4, &self.desc); } + if let Some(ref v) = self.views.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); my_size @@ -673,6 +719,11 @@ impl ::protobuf::Message for App { if !self.desc.is_empty() { os.write_string(4, &self.desc)?; } + if let Some(ref v) = self.views.as_ref() { + os.write_tag(5, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -731,6 +782,11 @@ impl ::protobuf::Message for App { |m: &App| { &m.desc }, |m: &mut App| { &mut m.desc }, )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "views", + |m: &App| { &m.views }, + |m: &mut App| { &mut m.views }, + )); ::protobuf::reflect::MessageDescriptor::new_pb_name::( "App", fields, @@ -751,6 +807,7 @@ impl ::protobuf::Clear for App { self.workspace_id.clear(); self.name.clear(); self.desc.clear(); + self.views.clear(); self.unknown_fields.clear(); } } @@ -767,44 +824,221 @@ impl ::protobuf::reflect::ProtobufValue for App { } } +#[derive(PartialEq,Clone,Default)] +pub struct RepeatedApp { + // message fields + pub items: ::protobuf::RepeatedField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a RepeatedApp { + fn default() -> &'a RepeatedApp { + ::default_instance() + } +} + +impl RepeatedApp { + pub fn new() -> RepeatedApp { + ::std::default::Default::default() + } + + // repeated .App items = 1; + + + pub fn get_items(&self) -> &[App] { + &self.items + } + pub fn clear_items(&mut self) { + self.items.clear(); + } + + // Param is passed by value, moved + pub fn set_items(&mut self, v: ::protobuf::RepeatedField) { + self.items = v; + } + + // Mutable pointer to the field. + pub fn mut_items(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.items + } + + // Take field + pub fn take_items(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.items, ::protobuf::RepeatedField::new()) + } +} + +impl ::protobuf::Message for RepeatedApp { + fn is_initialized(&self) -> bool { + for v in &self.items { + if !v.is_initialized() { + return false; + } + }; + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.items)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + for value in &self.items { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + for v in &self.items { + os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }; + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> RepeatedApp { + RepeatedApp::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "items", + |m: &RepeatedApp| { &m.items }, + |m: &mut RepeatedApp| { &mut m.items }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "RepeatedApp", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static RepeatedApp { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(RepeatedApp::new) + } +} + +impl ::protobuf::Clear for RepeatedApp { + fn clear(&mut self) { + self.items.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for RepeatedApp { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for RepeatedApp { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x10app_create.proto\"\x8b\x01\n\x10CreateAppRequest\x12!\n\x0cworkspa\ - ce_id\x18\x01\x20\x01(\tR\x0bworkspaceId\x12\x12\n\x04name\x18\x02\x20\ - \x01(\tR\x04name\x12\x12\n\x04desc\x18\x03\x20\x01(\tR\x04desc\x12,\n\ - \x0bcolor_style\x18\x04\x20\x01(\x0b2\x0b.ColorStyleR\ncolorStyle\"-\n\n\ - ColorStyle\x12\x1f\n\x0btheme_color\x18\x01\x20\x01(\tR\nthemeColor\"`\n\ - \x03App\x12\x0e\n\x02id\x18\x01\x20\x01(\tR\x02id\x12!\n\x0cworkspace_id\ - \x18\x02\x20\x01(\tR\x0bworkspaceId\x12\x12\n\x04name\x18\x03\x20\x01(\t\ - R\x04name\x12\x12\n\x04desc\x18\x04\x20\x01(\tR\x04descJ\xc9\x04\n\x06\ - \x12\x04\0\0\x10\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\ - \x04\x02\0\x07\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x18\n\x0b\n\x04\ - \x04\0\x02\0\x12\x03\x03\x04\x1c\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\ - \x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\x17\n\x0c\n\x05\x04\0\ - \x02\0\x03\x12\x03\x03\x1a\x1b\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\ - \x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\ - \x02\x01\x01\x12\x03\x04\x0b\x0f\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\ - \x04\x12\x13\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x04\x14\n\x0c\n\x05\ - \x04\0\x02\x02\x05\x12\x03\x05\x04\n\n\x0c\n\x05\x04\0\x02\x02\x01\x12\ - \x03\x05\x0b\x0f\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x12\x13\n\x0b\ - \n\x04\x04\0\x02\x03\x12\x03\x06\x04\x1f\n\x0c\n\x05\x04\0\x02\x03\x06\ - \x12\x03\x06\x04\x0e\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06\x0f\x1a\n\ - \x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x06\x1d\x1e\n\n\n\x02\x04\x01\x12\ - \x04\x08\0\n\x01\n\n\n\x03\x04\x01\x01\x12\x03\x08\x08\x12\n\x0b\n\x04\ - \x04\x01\x02\0\x12\x03\t\x04\x1b\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\t\ - \x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\t\x0b\x16\n\x0c\n\x05\x04\ - \x01\x02\0\x03\x12\x03\t\x19\x1a\n\n\n\x02\x04\x02\x12\x04\x0b\0\x10\x01\ - \n\n\n\x03\x04\x02\x01\x12\x03\x0b\x08\x0b\n\x0b\n\x04\x04\x02\x02\0\x12\ - \x03\x0c\x04\x12\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\x0c\x04\n\n\x0c\n\ - \x05\x04\x02\x02\0\x01\x12\x03\x0c\x0b\r\n\x0c\n\x05\x04\x02\x02\0\x03\ - \x12\x03\x0c\x10\x11\n\x0b\n\x04\x04\x02\x02\x01\x12\x03\r\x04\x1c\n\x0c\ - \n\x05\x04\x02\x02\x01\x05\x12\x03\r\x04\n\n\x0c\n\x05\x04\x02\x02\x01\ - \x01\x12\x03\r\x0b\x17\n\x0c\n\x05\x04\x02\x02\x01\x03\x12\x03\r\x1a\x1b\ - \n\x0b\n\x04\x04\x02\x02\x02\x12\x03\x0e\x04\x14\n\x0c\n\x05\x04\x02\x02\ - \x02\x05\x12\x03\x0e\x04\n\n\x0c\n\x05\x04\x02\x02\x02\x01\x12\x03\x0e\ - \x0b\x0f\n\x0c\n\x05\x04\x02\x02\x02\x03\x12\x03\x0e\x12\x13\n\x0b\n\x04\ - \x04\x02\x02\x03\x12\x03\x0f\x04\x14\n\x0c\n\x05\x04\x02\x02\x03\x05\x12\ - \x03\x0f\x04\n\n\x0c\n\x05\x04\x02\x02\x03\x01\x12\x03\x0f\x0b\x0f\n\x0c\ - \n\x05\x04\x02\x02\x03\x03\x12\x03\x0f\x12\x13b\x06proto3\ + \n\x10app_create.proto\x1a\x11view_create.proto\"\x8b\x01\n\x10CreateApp\ + Request\x12!\n\x0cworkspace_id\x18\x01\x20\x01(\tR\x0bworkspaceId\x12\ + \x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\x12\n\x04desc\x18\x03\x20\ + \x01(\tR\x04desc\x12,\n\x0bcolor_style\x18\x04\x20\x01(\x0b2\x0b.ColorSt\ + yleR\ncolorStyle\"-\n\nColorStyle\x12\x1f\n\x0btheme_color\x18\x01\x20\ + \x01(\tR\nthemeColor\"\x85\x01\n\x03App\x12\x0e\n\x02id\x18\x01\x20\x01(\ + \tR\x02id\x12!\n\x0cworkspace_id\x18\x02\x20\x01(\tR\x0bworkspaceId\x12\ + \x12\n\x04name\x18\x03\x20\x01(\tR\x04name\x12\x12\n\x04desc\x18\x04\x20\ + \x01(\tR\x04desc\x12#\n\x05views\x18\x05\x20\x01(\x0b2\r.RepeatedViewR\ + \x05views\")\n\x0bRepeatedApp\x12\x1a\n\x05items\x18\x01\x20\x03(\x0b2\ + \x04.AppR\x05itemsJ\xe8\x05\n\x06\x12\x04\0\0\x15\x01\n\x08\n\x01\x0c\ + \x12\x03\0\0\x12\n\t\n\x02\x03\0\x12\x03\x01\0\x1b\n\n\n\x02\x04\0\x12\ + \x04\x03\0\x08\x01\n\n\n\x03\x04\0\x01\x12\x03\x03\x08\x18\n\x0b\n\x04\ + \x04\0\x02\0\x12\x03\x04\x04\x1c\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x04\ + \x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x04\x0b\x17\n\x0c\n\x05\x04\0\ + \x02\0\x03\x12\x03\x04\x1a\x1b\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x05\x04\ + \x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x05\x04\n\n\x0c\n\x05\x04\0\ + \x02\x01\x01\x12\x03\x05\x0b\x0f\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\ + \x05\x12\x13\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x06\x04\x14\n\x0c\n\x05\ + \x04\0\x02\x02\x05\x12\x03\x06\x04\n\n\x0c\n\x05\x04\0\x02\x02\x01\x12\ + \x03\x06\x0b\x0f\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x06\x12\x13\n\x0b\ + \n\x04\x04\0\x02\x03\x12\x03\x07\x04\x1f\n\x0c\n\x05\x04\0\x02\x03\x06\ + \x12\x03\x07\x04\x0e\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x07\x0f\x1a\n\ + \x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x07\x1d\x1e\n\n\n\x02\x04\x01\x12\ + \x04\t\0\x0b\x01\n\n\n\x03\x04\x01\x01\x12\x03\t\x08\x12\n\x0b\n\x04\x04\ + \x01\x02\0\x12\x03\n\x04\x1b\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\n\x04\ + \n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\n\x0b\x16\n\x0c\n\x05\x04\x01\ + \x02\0\x03\x12\x03\n\x19\x1a\n\n\n\x02\x04\x02\x12\x04\x0c\0\x12\x01\n\n\ + \n\x03\x04\x02\x01\x12\x03\x0c\x08\x0b\n\x0b\n\x04\x04\x02\x02\0\x12\x03\ + \r\x04\x12\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\r\x04\n\n\x0c\n\x05\x04\ + \x02\x02\0\x01\x12\x03\r\x0b\r\n\x0c\n\x05\x04\x02\x02\0\x03\x12\x03\r\ + \x10\x11\n\x0b\n\x04\x04\x02\x02\x01\x12\x03\x0e\x04\x1c\n\x0c\n\x05\x04\ + \x02\x02\x01\x05\x12\x03\x0e\x04\n\n\x0c\n\x05\x04\x02\x02\x01\x01\x12\ + \x03\x0e\x0b\x17\n\x0c\n\x05\x04\x02\x02\x01\x03\x12\x03\x0e\x1a\x1b\n\ + \x0b\n\x04\x04\x02\x02\x02\x12\x03\x0f\x04\x14\n\x0c\n\x05\x04\x02\x02\ + \x02\x05\x12\x03\x0f\x04\n\n\x0c\n\x05\x04\x02\x02\x02\x01\x12\x03\x0f\ + \x0b\x0f\n\x0c\n\x05\x04\x02\x02\x02\x03\x12\x03\x0f\x12\x13\n\x0b\n\x04\ + \x04\x02\x02\x03\x12\x03\x10\x04\x14\n\x0c\n\x05\x04\x02\x02\x03\x05\x12\ + \x03\x10\x04\n\n\x0c\n\x05\x04\x02\x02\x03\x01\x12\x03\x10\x0b\x0f\n\x0c\ + \n\x05\x04\x02\x02\x03\x03\x12\x03\x10\x12\x13\n\x0b\n\x04\x04\x02\x02\ + \x04\x12\x03\x11\x04\x1b\n\x0c\n\x05\x04\x02\x02\x04\x06\x12\x03\x11\x04\ + \x10\n\x0c\n\x05\x04\x02\x02\x04\x01\x12\x03\x11\x11\x16\n\x0c\n\x05\x04\ + \x02\x02\x04\x03\x12\x03\x11\x19\x1a\n\n\n\x02\x04\x03\x12\x04\x13\0\x15\ + \x01\n\n\n\x03\x04\x03\x01\x12\x03\x13\x08\x13\n\x0b\n\x04\x04\x03\x02\0\ + \x12\x03\x14\x04\x1b\n\x0c\n\x05\x04\x03\x02\0\x04\x12\x03\x14\x04\x0c\n\ + \x0c\n\x05\x04\x03\x02\0\x06\x12\x03\x14\r\x10\n\x0c\n\x05\x04\x03\x02\0\ + \x01\x12\x03\x14\x11\x16\n\x0c\n\x05\x04\x03\x02\0\x03\x12\x03\x14\x19\ + \x1ab\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-workspace/src/protobuf/model/app_query.rs b/rust-lib/flowy-workspace/src/protobuf/model/app_query.rs new file mode 100644 index 0000000000..8540c4f1d2 --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/model/app_query.rs @@ -0,0 +1,243 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `app_query.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct QueryAppRequest { + // message fields + pub app_id: ::std::string::String, + pub read_views: bool, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a QueryAppRequest { + fn default() -> &'a QueryAppRequest { + ::default_instance() + } +} + +impl QueryAppRequest { + pub fn new() -> QueryAppRequest { + ::std::default::Default::default() + } + + // string app_id = 1; + + + pub fn get_app_id(&self) -> &str { + &self.app_id + } + pub fn clear_app_id(&mut self) { + self.app_id.clear(); + } + + // Param is passed by value, moved + pub fn set_app_id(&mut self, v: ::std::string::String) { + self.app_id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_app_id(&mut self) -> &mut ::std::string::String { + &mut self.app_id + } + + // Take field + pub fn take_app_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.app_id, ::std::string::String::new()) + } + + // bool read_views = 2; + + + pub fn get_read_views(&self) -> bool { + self.read_views + } + pub fn clear_read_views(&mut self) { + self.read_views = false; + } + + // Param is passed by value, moved + pub fn set_read_views(&mut self, v: bool) { + self.read_views = v; + } +} + +impl ::protobuf::Message for QueryAppRequest { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.app_id)?; + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_bool()?; + self.read_views = tmp; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.app_id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.app_id); + } + if self.read_views != false { + my_size += 2; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.app_id.is_empty() { + os.write_string(1, &self.app_id)?; + } + if self.read_views != false { + os.write_bool(2, self.read_views)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> QueryAppRequest { + QueryAppRequest::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "app_id", + |m: &QueryAppRequest| { &m.app_id }, + |m: &mut QueryAppRequest| { &mut m.app_id }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>( + "read_views", + |m: &QueryAppRequest| { &m.read_views }, + |m: &mut QueryAppRequest| { &mut m.read_views }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "QueryAppRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static QueryAppRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(QueryAppRequest::new) + } +} + +impl ::protobuf::Clear for QueryAppRequest { + fn clear(&mut self) { + self.app_id.clear(); + self.read_views = false; + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for QueryAppRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for QueryAppRequest { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x0fapp_query.proto\"G\n\x0fQueryAppRequest\x12\x15\n\x06app_id\x18\ + \x01\x20\x01(\tR\x05appId\x12\x1d\n\nread_views\x18\x02\x20\x01(\x08R\tr\ + eadViewsJ\x98\x01\n\x06\x12\x04\0\0\x05\x01\n\x08\n\x01\x0c\x12\x03\0\0\ + \x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\ + \x02\x08\x17\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x16\n\x0c\n\x05\x04\ + \0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\ + \x0b\x11\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x14\x15\n\x0b\n\x04\x04\ + \0\x02\x01\x12\x03\x04\x04\x18\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\ + \x04\x08\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\t\x13\n\x0c\n\x05\x04\ + \0\x02\x01\x03\x12\x03\x04\x16\x17b\x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-workspace/src/protobuf/model/errors.rs b/rust-lib/flowy-workspace/src/protobuf/model/errors.rs index 8e9695898d..aa3aa6a631 100644 --- a/rust-lib/flowy-workspace/src/protobuf/model/errors.rs +++ b/rust-lib/flowy-workspace/src/protobuf/model/errors.rs @@ -222,7 +222,9 @@ pub enum WorkspaceErrorCode { AppIdInvalid = 10, AppNameInvalid = 11, ViewNameInvalid = 20, - ViewThumbnailName = 21, + ViewThumbnailInvalid = 21, + ViewIdInvalid = 22, + ViewDescInvalid = 23, DatabaseConnectionFail = 100, WorkspaceDatabaseError = 101, UserInternalError = 102, @@ -243,7 +245,9 @@ impl ::protobuf::ProtobufEnum for WorkspaceErrorCode { 10 => ::std::option::Option::Some(WorkspaceErrorCode::AppIdInvalid), 11 => ::std::option::Option::Some(WorkspaceErrorCode::AppNameInvalid), 20 => ::std::option::Option::Some(WorkspaceErrorCode::ViewNameInvalid), - 21 => ::std::option::Option::Some(WorkspaceErrorCode::ViewThumbnailName), + 21 => ::std::option::Option::Some(WorkspaceErrorCode::ViewThumbnailInvalid), + 22 => ::std::option::Option::Some(WorkspaceErrorCode::ViewIdInvalid), + 23 => ::std::option::Option::Some(WorkspaceErrorCode::ViewDescInvalid), 100 => ::std::option::Option::Some(WorkspaceErrorCode::DatabaseConnectionFail), 101 => ::std::option::Option::Some(WorkspaceErrorCode::WorkspaceDatabaseError), 102 => ::std::option::Option::Some(WorkspaceErrorCode::UserInternalError), @@ -261,7 +265,9 @@ impl ::protobuf::ProtobufEnum for WorkspaceErrorCode { WorkspaceErrorCode::AppIdInvalid, WorkspaceErrorCode::AppNameInvalid, WorkspaceErrorCode::ViewNameInvalid, - WorkspaceErrorCode::ViewThumbnailName, + WorkspaceErrorCode::ViewThumbnailInvalid, + WorkspaceErrorCode::ViewIdInvalid, + WorkspaceErrorCode::ViewDescInvalid, WorkspaceErrorCode::DatabaseConnectionFail, WorkspaceErrorCode::WorkspaceDatabaseError, WorkspaceErrorCode::UserInternalError, @@ -296,21 +302,22 @@ impl ::protobuf::reflect::ProtobufValue for WorkspaceErrorCode { static file_descriptor_proto_data: &'static [u8] = b"\ \n\x0cerrors.proto\"K\n\x0eWorkspaceError\x12'\n\x04code\x18\x01\x20\x01\ (\x0e2\x13.WorkspaceErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\ - \tR\x03msg*\xa3\x02\n\x12WorkspaceErrorCode\x12\x0b\n\x07Unknown\x10\0\ + \tR\x03msg*\xce\x02\n\x12WorkspaceErrorCode\x12\x0b\n\x07Unknown\x10\0\ \x12\x18\n\x14WorkspaceNameInvalid\x10\x01\x12\x16\n\x12WorkspaceIdInval\ id\x10\x02\x12\x18\n\x14AppColorStyleInvalid\x10\x03\x12\x10\n\x0cAppIdI\ nvalid\x10\n\x12\x12\n\x0eAppNameInvalid\x10\x0b\x12\x13\n\x0fViewNameIn\ - valid\x10\x14\x12\x15\n\x11ViewThumbnailName\x10\x15\x12\x1a\n\x16Databa\ - seConnectionFail\x10d\x12\x1a\n\x16WorkspaceDatabaseError\x10e\x12\x15\n\ - \x11UserInternalError\x10f\x12\x13\n\x0fUserNotLoginYet\x10gJ\x9c\x05\n\ - \x06\x12\x04\0\0\x13\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\ - \x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x16\n\x0b\n\ + valid\x10\x14\x12\x18\n\x14ViewThumbnailInvalid\x10\x15\x12\x11\n\rViewI\ + dInvalid\x10\x16\x12\x13\n\x0fViewDescInvalid\x10\x17\x12\x1a\n\x16Datab\ + aseConnectionFail\x10d\x12\x1a\n\x16WorkspaceDatabaseError\x10e\x12\x15\ + \n\x11UserInternalError\x10f\x12\x13\n\x0fUserNotLoginYet\x10gJ\xee\x05\ + \n\x06\x12\x04\0\0\x15\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\ + \0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x16\n\x0b\n\ \x04\x04\0\x02\0\x12\x03\x03\x04\x20\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\ \x03\x04\x16\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x17\x1b\n\x0c\n\x05\ \x04\0\x02\0\x03\x12\x03\x03\x1e\x1f\n\x0b\n\x04\x04\0\x02\x01\x12\x03\ \x04\x04\x13\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\ \x04\0\x02\x01\x01\x12\x03\x04\x0b\x0e\n\x0c\n\x05\x04\0\x02\x01\x03\x12\ - \x03\x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\x13\x01\n\n\n\x03\x05\0\ + \x03\x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\x15\x01\n\n\n\x03\x05\0\ \x01\x12\x03\x06\x05\x17\n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\x04\x10\n\ \x0c\n\x05\x05\0\x02\0\x01\x12\x03\x07\x04\x0b\n\x0c\n\x05\x05\0\x02\0\ \x02\x12\x03\x07\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x08\x04\x1d\n\ @@ -326,16 +333,20 @@ static file_descriptor_proto_data: &'static [u8] = b"\ \x02\x05\x02\x12\x03\x0c\x15\x17\n\x0b\n\x04\x05\0\x02\x06\x12\x03\r\x04\ \x19\n\x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\x04\x13\n\x0c\n\x05\x05\0\ \x02\x06\x02\x12\x03\r\x16\x18\n\x0b\n\x04\x05\0\x02\x07\x12\x03\x0e\x04\ - \x1b\n\x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x15\n\x0c\n\x05\x05\0\ - \x02\x07\x02\x12\x03\x0e\x18\x1a\n\x0b\n\x04\x05\0\x02\x08\x12\x03\x0f\ - \x04!\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0f\x04\x1a\n\x0c\n\x05\x05\ - \0\x02\x08\x02\x12\x03\x0f\x1d\x20\n\x0b\n\x04\x05\0\x02\t\x12\x03\x10\ - \x04!\n\x0c\n\x05\x05\0\x02\t\x01\x12\x03\x10\x04\x1a\n\x0c\n\x05\x05\0\ - \x02\t\x02\x12\x03\x10\x1d\x20\n\x0b\n\x04\x05\0\x02\n\x12\x03\x11\x04\ - \x1c\n\x0c\n\x05\x05\0\x02\n\x01\x12\x03\x11\x04\x15\n\x0c\n\x05\x05\0\ - \x02\n\x02\x12\x03\x11\x18\x1b\n\x0b\n\x04\x05\0\x02\x0b\x12\x03\x12\x04\ - \x1a\n\x0c\n\x05\x05\0\x02\x0b\x01\x12\x03\x12\x04\x13\n\x0c\n\x05\x05\0\ - \x02\x0b\x02\x12\x03\x12\x16\x19b\x06proto3\ + \x1e\n\x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x18\n\x0c\n\x05\x05\0\ + \x02\x07\x02\x12\x03\x0e\x1b\x1d\n\x0b\n\x04\x05\0\x02\x08\x12\x03\x0f\ + \x04\x17\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0f\x04\x11\n\x0c\n\x05\ + \x05\0\x02\x08\x02\x12\x03\x0f\x14\x16\n\x0b\n\x04\x05\0\x02\t\x12\x03\ + \x10\x04\x19\n\x0c\n\x05\x05\0\x02\t\x01\x12\x03\x10\x04\x13\n\x0c\n\x05\ + \x05\0\x02\t\x02\x12\x03\x10\x16\x18\n\x0b\n\x04\x05\0\x02\n\x12\x03\x11\ + \x04!\n\x0c\n\x05\x05\0\x02\n\x01\x12\x03\x11\x04\x1a\n\x0c\n\x05\x05\0\ + \x02\n\x02\x12\x03\x11\x1d\x20\n\x0b\n\x04\x05\0\x02\x0b\x12\x03\x12\x04\ + !\n\x0c\n\x05\x05\0\x02\x0b\x01\x12\x03\x12\x04\x1a\n\x0c\n\x05\x05\0\ + \x02\x0b\x02\x12\x03\x12\x1d\x20\n\x0b\n\x04\x05\0\x02\x0c\x12\x03\x13\ + \x04\x1c\n\x0c\n\x05\x05\0\x02\x0c\x01\x12\x03\x13\x04\x15\n\x0c\n\x05\ + \x05\0\x02\x0c\x02\x12\x03\x13\x18\x1b\n\x0b\n\x04\x05\0\x02\r\x12\x03\ + \x14\x04\x1a\n\x0c\n\x05\x05\0\x02\r\x01\x12\x03\x14\x04\x13\n\x0c\n\x05\ + \x05\0\x02\r\x02\x12\x03\x14\x16\x19b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-workspace/src/protobuf/model/event.rs b/rust-lib/flowy-workspace/src/protobuf/model/event.rs index efc2005564..2d5cbb97c6 100644 --- a/rust-lib/flowy-workspace/src/protobuf/model/event.rs +++ b/rust-lib/flowy-workspace/src/protobuf/model/event.rs @@ -26,9 +26,13 @@ #[derive(Clone,PartialEq,Eq,Debug,Hash)] pub enum WorkspaceEvent { CreateWorkspace = 0, - GetWorkspaceDetail = 1, + GetCurWorkspace = 1, + GetWorkspace = 2, CreateApp = 101, + GetApp = 102, CreateView = 201, + ReadView = 202, + UpdateView = 203, } impl ::protobuf::ProtobufEnum for WorkspaceEvent { @@ -39,9 +43,13 @@ impl ::protobuf::ProtobufEnum for WorkspaceEvent { fn from_i32(value: i32) -> ::std::option::Option { match value { 0 => ::std::option::Option::Some(WorkspaceEvent::CreateWorkspace), - 1 => ::std::option::Option::Some(WorkspaceEvent::GetWorkspaceDetail), + 1 => ::std::option::Option::Some(WorkspaceEvent::GetCurWorkspace), + 2 => ::std::option::Option::Some(WorkspaceEvent::GetWorkspace), 101 => ::std::option::Option::Some(WorkspaceEvent::CreateApp), + 102 => ::std::option::Option::Some(WorkspaceEvent::GetApp), 201 => ::std::option::Option::Some(WorkspaceEvent::CreateView), + 202 => ::std::option::Option::Some(WorkspaceEvent::ReadView), + 203 => ::std::option::Option::Some(WorkspaceEvent::UpdateView), _ => ::std::option::Option::None } } @@ -49,9 +57,13 @@ impl ::protobuf::ProtobufEnum for WorkspaceEvent { fn values() -> &'static [Self] { static values: &'static [WorkspaceEvent] = &[ WorkspaceEvent::CreateWorkspace, - WorkspaceEvent::GetWorkspaceDetail, + WorkspaceEvent::GetCurWorkspace, + WorkspaceEvent::GetWorkspace, WorkspaceEvent::CreateApp, + WorkspaceEvent::GetApp, WorkspaceEvent::CreateView, + WorkspaceEvent::ReadView, + WorkspaceEvent::UpdateView, ]; values } @@ -80,19 +92,29 @@ impl ::protobuf::reflect::ProtobufValue for WorkspaceEvent { } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x0bevent.proto*]\n\x0eWorkspaceEvent\x12\x13\n\x0fCreateWorkspace\x10\ - \0\x12\x16\n\x12GetWorkspaceDetail\x10\x01\x12\r\n\tCreateApp\x10e\x12\ - \x0f\n\nCreateView\x10\xc9\x01J\xce\x01\n\x06\x12\x04\0\0\x07\x01\n\x08\ - \n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x05\0\x12\x04\x02\0\x07\x01\n\n\n\ - \x03\x05\0\x01\x12\x03\x02\x05\x13\n\x0b\n\x04\x05\0\x02\0\x12\x03\x03\ - \x04\x18\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x03\x04\x13\n\x0c\n\x05\x05\ - \0\x02\0\x02\x12\x03\x03\x16\x17\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x04\ - \x04\x1b\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x04\x04\x16\n\x0c\n\x05\ - \x05\0\x02\x01\x02\x12\x03\x04\x19\x1a\n\x0b\n\x04\x05\0\x02\x02\x12\x03\ - \x05\x04\x14\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\x05\x04\r\n\x0c\n\x05\ - \x05\0\x02\x02\x02\x12\x03\x05\x10\x13\n\x0b\n\x04\x05\0\x02\x03\x12\x03\ - \x06\x04\x15\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\x06\x04\x0e\n\x0c\n\ - \x05\x05\0\x02\x03\x02\x12\x03\x06\x11\x14b\x06proto3\ + \n\x0bevent.proto*\x98\x01\n\x0eWorkspaceEvent\x12\x13\n\x0fCreateWorksp\ + ace\x10\0\x12\x13\n\x0fGetCurWorkspace\x10\x01\x12\x10\n\x0cGetWorkspace\ + \x10\x02\x12\r\n\tCreateApp\x10e\x12\n\n\x06GetApp\x10f\x12\x0f\n\nCreat\ + eView\x10\xc9\x01\x12\r\n\x08ReadView\x10\xca\x01\x12\x0f\n\nUpdateView\ + \x10\xcb\x01J\xf2\x02\n\x06\x12\x04\0\0\x0b\x01\n\x08\n\x01\x0c\x12\x03\ + \0\0\x12\n\n\n\x02\x05\0\x12\x04\x02\0\x0b\x01\n\n\n\x03\x05\0\x01\x12\ + \x03\x02\x05\x13\n\x0b\n\x04\x05\0\x02\0\x12\x03\x03\x04\x18\n\x0c\n\x05\ + \x05\0\x02\0\x01\x12\x03\x03\x04\x13\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\ + \x03\x16\x17\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x04\x04\x18\n\x0c\n\x05\ + \x05\0\x02\x01\x01\x12\x03\x04\x04\x13\n\x0c\n\x05\x05\0\x02\x01\x02\x12\ + \x03\x04\x16\x17\n\x0b\n\x04\x05\0\x02\x02\x12\x03\x05\x04\x15\n\x0c\n\ + \x05\x05\0\x02\x02\x01\x12\x03\x05\x04\x10\n\x0c\n\x05\x05\0\x02\x02\x02\ + \x12\x03\x05\x13\x14\n\x0b\n\x04\x05\0\x02\x03\x12\x03\x06\x04\x14\n\x0c\ + \n\x05\x05\0\x02\x03\x01\x12\x03\x06\x04\r\n\x0c\n\x05\x05\0\x02\x03\x02\ + \x12\x03\x06\x10\x13\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x07\x04\x11\n\x0c\ + \n\x05\x05\0\x02\x04\x01\x12\x03\x07\x04\n\n\x0c\n\x05\x05\0\x02\x04\x02\ + \x12\x03\x07\r\x10\n\x0b\n\x04\x05\0\x02\x05\x12\x03\x08\x04\x15\n\x0c\n\ + \x05\x05\0\x02\x05\x01\x12\x03\x08\x04\x0e\n\x0c\n\x05\x05\0\x02\x05\x02\ + \x12\x03\x08\x11\x14\n\x0b\n\x04\x05\0\x02\x06\x12\x03\t\x04\x13\n\x0c\n\ + \x05\x05\0\x02\x06\x01\x12\x03\t\x04\x0c\n\x0c\n\x05\x05\0\x02\x06\x02\ + \x12\x03\t\x0f\x12\n\x0b\n\x04\x05\0\x02\x07\x12\x03\n\x04\x15\n\x0c\n\ + \x05\x05\0\x02\x07\x01\x12\x03\n\x04\x0e\n\x0c\n\x05\x05\0\x02\x07\x02\ + \x12\x03\n\x11\x14b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-workspace/src/protobuf/model/mod.rs b/rust-lib/flowy-workspace/src/protobuf/model/mod.rs index 27e3001c33..5fad5177ca 100644 --- a/rust-lib/flowy-workspace/src/protobuf/model/mod.rs +++ b/rust-lib/flowy-workspace/src/protobuf/model/mod.rs @@ -1,5 +1,14 @@ // Auto-generated, do not edit +mod view_update; +pub use view_update::*; + +mod app_query; +pub use app_query::*; + +mod observable; +pub use observable::*; + mod errors; pub use errors::*; @@ -9,6 +18,9 @@ pub use workspace_update::*; mod app_create; pub use app_create::*; +mod workspace_query; +pub use workspace_query::*; + mod event; pub use event::*; @@ -23,3 +35,6 @@ pub use workspace_create::*; mod app_update; pub use app_update::*; + +mod view_query; +pub use view_query::*; diff --git a/rust-lib/flowy-workspace/src/protobuf/model/observable.rs b/rust-lib/flowy-workspace/src/protobuf/model/observable.rs new file mode 100644 index 0000000000..946760d6a1 --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/model/observable.rs @@ -0,0 +1,120 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `observable.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(Clone,PartialEq,Eq,Debug,Hash)] +pub enum WorkspaceObservable { + Unknown = 0, + WorkspaceUpdateDesc = 10, + WorkspaceAddApp = 11, + AppUpdateDesc = 20, + AppAddView = 21, + ViewUpdateDesc = 30, +} + +impl ::protobuf::ProtobufEnum for WorkspaceObservable { + fn value(&self) -> i32 { + *self as i32 + } + + fn from_i32(value: i32) -> ::std::option::Option { + match value { + 0 => ::std::option::Option::Some(WorkspaceObservable::Unknown), + 10 => ::std::option::Option::Some(WorkspaceObservable::WorkspaceUpdateDesc), + 11 => ::std::option::Option::Some(WorkspaceObservable::WorkspaceAddApp), + 20 => ::std::option::Option::Some(WorkspaceObservable::AppUpdateDesc), + 21 => ::std::option::Option::Some(WorkspaceObservable::AppAddView), + 30 => ::std::option::Option::Some(WorkspaceObservable::ViewUpdateDesc), + _ => ::std::option::Option::None + } + } + + fn values() -> &'static [Self] { + static values: &'static [WorkspaceObservable] = &[ + WorkspaceObservable::Unknown, + WorkspaceObservable::WorkspaceUpdateDesc, + WorkspaceObservable::WorkspaceAddApp, + WorkspaceObservable::AppUpdateDesc, + WorkspaceObservable::AppAddView, + WorkspaceObservable::ViewUpdateDesc, + ]; + values + } + + fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::EnumDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + ::protobuf::reflect::EnumDescriptor::new_pb_name::("WorkspaceObservable", file_descriptor_proto()) + }) + } +} + +impl ::std::marker::Copy for WorkspaceObservable { +} + +impl ::std::default::Default for WorkspaceObservable { + fn default() -> Self { + WorkspaceObservable::Unknown + } +} + +impl ::protobuf::reflect::ProtobufValue for WorkspaceObservable { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Enum(::protobuf::ProtobufEnum::descriptor(self)) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x10observable.proto*\x87\x01\n\x13WorkspaceObservable\x12\x0b\n\x07Un\ + known\x10\0\x12\x17\n\x13WorkspaceUpdateDesc\x10\n\x12\x13\n\x0fWorkspac\ + eAddApp\x10\x0b\x12\x11\n\rAppUpdateDesc\x10\x14\x12\x0e\n\nAppAddView\ + \x10\x15\x12\x12\n\x0eViewUpdateDesc\x10\x1eJ\xa0\x02\n\x06\x12\x04\0\0\ + \t\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x05\0\x12\x04\x02\0\t\ + \x01\n\n\n\x03\x05\0\x01\x12\x03\x02\x05\x18\n\x0b\n\x04\x05\0\x02\0\x12\ + \x03\x03\x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x03\x04\x0b\n\x0c\n\ + \x05\x05\0\x02\0\x02\x12\x03\x03\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\x12\ + \x03\x04\x04\x1d\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x04\x04\x17\n\x0c\ + \n\x05\x05\0\x02\x01\x02\x12\x03\x04\x1a\x1c\n\x0b\n\x04\x05\0\x02\x02\ + \x12\x03\x05\x04\x19\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\x05\x04\x13\n\ + \x0c\n\x05\x05\0\x02\x02\x02\x12\x03\x05\x16\x18\n\x0b\n\x04\x05\0\x02\ + \x03\x12\x03\x06\x04\x17\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\x06\x04\ + \x11\n\x0c\n\x05\x05\0\x02\x03\x02\x12\x03\x06\x14\x16\n\x0b\n\x04\x05\0\ + \x02\x04\x12\x03\x07\x04\x14\n\x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x07\ + \x04\x0e\n\x0c\n\x05\x05\0\x02\x04\x02\x12\x03\x07\x11\x13\n\x0b\n\x04\ + \x05\0\x02\x05\x12\x03\x08\x04\x18\n\x0c\n\x05\x05\0\x02\x05\x01\x12\x03\ + \x08\x04\x12\n\x0c\n\x05\x05\0\x02\x05\x02\x12\x03\x08\x15\x17b\x06proto\ + 3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-workspace/src/protobuf/model/view_create.rs b/rust-lib/flowy-workspace/src/protobuf/model/view_create.rs index 48a0c8f5e8..b11518212d 100644 --- a/rust-lib/flowy-workspace/src/protobuf/model/view_create.rs +++ b/rust-lib/flowy-workspace/src/protobuf/model/view_create.rs @@ -29,7 +29,7 @@ pub struct CreateViewRequest { pub app_id: ::std::string::String, pub name: ::std::string::String, pub desc: ::std::string::String, - pub view_type: ViewTypeIdentifier, + pub view_type: ViewType, // message oneof groups pub one_of_thumbnail: ::std::option::Option, // special fields @@ -180,18 +180,18 @@ impl CreateViewRequest { } } - // .ViewTypeIdentifier view_type = 5; + // .ViewType view_type = 5; - pub fn get_view_type(&self) -> ViewTypeIdentifier { + pub fn get_view_type(&self) -> ViewType { self.view_type } pub fn clear_view_type(&mut self) { - self.view_type = ViewTypeIdentifier::Docs; + self.view_type = ViewType::Blank; } // Param is passed by value, moved - pub fn set_view_type(&mut self, v: ViewTypeIdentifier) { + pub fn set_view_type(&mut self, v: ViewType) { self.view_type = v; } } @@ -244,7 +244,7 @@ impl ::protobuf::Message for CreateViewRequest { if !self.desc.is_empty() { my_size += ::protobuf::rt::string_size(3, &self.desc); } - if self.view_type != ViewTypeIdentifier::Docs { + if self.view_type != ViewType::Blank { my_size += ::protobuf::rt::enum_size(5, self.view_type); } if let ::std::option::Option::Some(ref v) = self.one_of_thumbnail { @@ -269,7 +269,7 @@ impl ::protobuf::Message for CreateViewRequest { if !self.desc.is_empty() { os.write_string(3, &self.desc)?; } - if self.view_type != ViewTypeIdentifier::Docs { + if self.view_type != ViewType::Blank { os.write_enum(5, ::protobuf::ProtobufEnum::value(&self.view_type))?; } if let ::std::option::Option::Some(ref v) = self.one_of_thumbnail { @@ -337,7 +337,7 @@ impl ::protobuf::Message for CreateViewRequest { CreateViewRequest::has_thumbnail, CreateViewRequest::get_thumbnail, )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( "view_type", |m: &CreateViewRequest| { &m.view_type }, |m: &mut CreateViewRequest| { &mut m.view_type }, @@ -362,7 +362,7 @@ impl ::protobuf::Clear for CreateViewRequest { self.name.clear(); self.desc.clear(); self.one_of_thumbnail = ::std::option::Option::None; - self.view_type = ViewTypeIdentifier::Docs; + self.view_type = ViewType::Blank; self.unknown_fields.clear(); } } @@ -386,7 +386,7 @@ pub struct View { pub app_id: ::std::string::String, pub name: ::std::string::String, pub desc: ::std::string::String, - pub view_type: ViewTypeIdentifier, + pub view_type: ViewType, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -507,18 +507,18 @@ impl View { ::std::mem::replace(&mut self.desc, ::std::string::String::new()) } - // .ViewTypeIdentifier view_type = 5; + // .ViewType view_type = 5; - pub fn get_view_type(&self) -> ViewTypeIdentifier { + pub fn get_view_type(&self) -> ViewType { self.view_type } pub fn clear_view_type(&mut self) { - self.view_type = ViewTypeIdentifier::Docs; + self.view_type = ViewType::Blank; } // Param is passed by value, moved - pub fn set_view_type(&mut self, v: ViewTypeIdentifier) { + pub fn set_view_type(&mut self, v: ViewType) { self.view_type = v; } } @@ -571,7 +571,7 @@ impl ::protobuf::Message for View { if !self.desc.is_empty() { my_size += ::protobuf::rt::string_size(4, &self.desc); } - if self.view_type != ViewTypeIdentifier::Docs { + if self.view_type != ViewType::Blank { my_size += ::protobuf::rt::enum_size(5, self.view_type); } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); @@ -592,7 +592,7 @@ impl ::protobuf::Message for View { if !self.desc.is_empty() { os.write_string(4, &self.desc)?; } - if self.view_type != ViewTypeIdentifier::Docs { + if self.view_type != ViewType::Blank { os.write_enum(5, ::protobuf::ProtobufEnum::value(&self.view_type))?; } os.write_unknown_fields(self.get_unknown_fields())?; @@ -653,7 +653,7 @@ impl ::protobuf::Message for View { |m: &View| { &m.desc }, |m: &mut View| { &mut m.desc }, )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( "view_type", |m: &View| { &m.view_type }, |m: &mut View| { &mut m.view_type }, @@ -678,7 +678,7 @@ impl ::protobuf::Clear for View { self.app_id.clear(); self.name.clear(); self.desc.clear(); - self.view_type = ViewTypeIdentifier::Docs; + self.view_type = ViewType::Blank; self.unknown_fields.clear(); } } @@ -695,26 +695,195 @@ impl ::protobuf::reflect::ProtobufValue for View { } } -#[derive(Clone,PartialEq,Eq,Debug,Hash)] -pub enum ViewTypeIdentifier { - Docs = 0, +#[derive(PartialEq,Clone,Default)] +pub struct RepeatedView { + // message fields + pub items: ::protobuf::RepeatedField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, } -impl ::protobuf::ProtobufEnum for ViewTypeIdentifier { +impl<'a> ::std::default::Default for &'a RepeatedView { + fn default() -> &'a RepeatedView { + ::default_instance() + } +} + +impl RepeatedView { + pub fn new() -> RepeatedView { + ::std::default::Default::default() + } + + // repeated .View items = 1; + + + pub fn get_items(&self) -> &[View] { + &self.items + } + pub fn clear_items(&mut self) { + self.items.clear(); + } + + // Param is passed by value, moved + pub fn set_items(&mut self, v: ::protobuf::RepeatedField) { + self.items = v; + } + + // Mutable pointer to the field. + pub fn mut_items(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.items + } + + // Take field + pub fn take_items(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.items, ::protobuf::RepeatedField::new()) + } +} + +impl ::protobuf::Message for RepeatedView { + fn is_initialized(&self) -> bool { + for v in &self.items { + if !v.is_initialized() { + return false; + } + }; + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.items)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + for value in &self.items { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + for v in &self.items { + os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }; + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> RepeatedView { + RepeatedView::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "items", + |m: &RepeatedView| { &m.items }, + |m: &mut RepeatedView| { &mut m.items }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "RepeatedView", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static RepeatedView { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(RepeatedView::new) + } +} + +impl ::protobuf::Clear for RepeatedView { + fn clear(&mut self) { + self.items.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for RepeatedView { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for RepeatedView { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(Clone,PartialEq,Eq,Debug,Hash)] +pub enum ViewType { + Blank = 0, + Doc = 1, +} + +impl ::protobuf::ProtobufEnum for ViewType { fn value(&self) -> i32 { *self as i32 } - fn from_i32(value: i32) -> ::std::option::Option { + fn from_i32(value: i32) -> ::std::option::Option { match value { - 0 => ::std::option::Option::Some(ViewTypeIdentifier::Docs), + 0 => ::std::option::Option::Some(ViewType::Blank), + 1 => ::std::option::Option::Some(ViewType::Doc), _ => ::std::option::Option::None } } fn values() -> &'static [Self] { - static values: &'static [ViewTypeIdentifier] = &[ - ViewTypeIdentifier::Docs, + static values: &'static [ViewType] = &[ + ViewType::Blank, + ViewType::Doc, ]; values } @@ -722,72 +891,79 @@ impl ::protobuf::ProtobufEnum for ViewTypeIdentifier { fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::EnumDescriptor> = ::protobuf::rt::LazyV2::INIT; descriptor.get(|| { - ::protobuf::reflect::EnumDescriptor::new_pb_name::("ViewTypeIdentifier", file_descriptor_proto()) + ::protobuf::reflect::EnumDescriptor::new_pb_name::("ViewType", file_descriptor_proto()) }) } } -impl ::std::marker::Copy for ViewTypeIdentifier { +impl ::std::marker::Copy for ViewType { } -impl ::std::default::Default for ViewTypeIdentifier { +impl ::std::default::Default for ViewType { fn default() -> Self { - ViewTypeIdentifier::Docs + ViewType::Blank } } -impl ::protobuf::reflect::ProtobufValue for ViewTypeIdentifier { +impl ::protobuf::reflect::ProtobufValue for ViewType { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Enum(::protobuf::ProtobufEnum::descriptor(self)) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x11view_create.proto\"\xb8\x01\n\x11CreateViewRequest\x12\x15\n\x06ap\ + \n\x11view_create.proto\"\xae\x01\n\x11CreateViewRequest\x12\x15\n\x06ap\ p_id\x18\x01\x20\x01(\tR\x05appId\x12\x12\n\x04name\x18\x02\x20\x01(\tR\ \x04name\x12\x12\n\x04desc\x18\x03\x20\x01(\tR\x04desc\x12\x1e\n\tthumbn\ - ail\x18\x04\x20\x01(\tH\0R\tthumbnail\x120\n\tview_type\x18\x05\x20\x01(\ - \x0e2\x13.ViewTypeIdentifierR\x08viewTypeB\x12\n\x10one_of_thumbnail\"\ - \x87\x01\n\x04View\x12\x0e\n\x02id\x18\x01\x20\x01(\tR\x02id\x12\x15\n\ - \x06app_id\x18\x02\x20\x01(\tR\x05appId\x12\x12\n\x04name\x18\x03\x20\ - \x01(\tR\x04name\x12\x12\n\x04desc\x18\x04\x20\x01(\tR\x04desc\x120\n\tv\ - iew_type\x18\x05\x20\x01(\x0e2\x13.ViewTypeIdentifierR\x08viewType*\x1e\ - \n\x12ViewTypeIdentifier\x12\x08\n\x04Docs\x10\0J\xc4\x05\n\x06\x12\x04\ - \0\0\x12\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\ - \0\x08\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x19\n\x0b\n\x04\x04\0\x02\ - \0\x12\x03\x03\x04\x16\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\ - \x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\x11\n\x0c\n\x05\x04\0\x02\0\ - \x03\x12\x03\x03\x14\x15\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x14\n\ - \x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\ - \x01\x12\x03\x04\x0b\x0f\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x12\ - \x13\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x04\x14\n\x0c\n\x05\x04\0\x02\ - \x02\x05\x12\x03\x05\x04\n\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x05\x0b\ - \x0f\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x12\x13\n\x0b\n\x04\x04\0\ - \x08\0\x12\x03\x06\x044\n\x0c\n\x05\x04\0\x08\0\x01\x12\x03\x06\n\x1a\n\ - \x0b\n\x04\x04\0\x02\x03\x12\x03\x06\x1d2\n\x0c\n\x05\x04\0\x02\x03\x05\ - \x12\x03\x06\x1d#\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06$-\n\x0c\n\ - \x05\x04\0\x02\x03\x03\x12\x03\x0601\n\x0b\n\x04\x04\0\x02\x04\x12\x03\ - \x07\x04%\n\x0c\n\x05\x04\0\x02\x04\x06\x12\x03\x07\x04\x16\n\x0c\n\x05\ - \x04\0\x02\x04\x01\x12\x03\x07\x17\x20\n\x0c\n\x05\x04\0\x02\x04\x03\x12\ - \x03\x07#$\n\n\n\x02\x04\x01\x12\x04\t\0\x0f\x01\n\n\n\x03\x04\x01\x01\ - \x12\x03\t\x08\x0c\n\x0b\n\x04\x04\x01\x02\0\x12\x03\n\x04\x12\n\x0c\n\ - \x05\x04\x01\x02\0\x05\x12\x03\n\x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\ - \x03\n\x0b\r\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\n\x10\x11\n\x0b\n\x04\ - \x04\x01\x02\x01\x12\x03\x0b\x04\x16\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\ - \x03\x0b\x04\n\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x0b\x0b\x11\n\x0c\ - \n\x05\x04\x01\x02\x01\x03\x12\x03\x0b\x14\x15\n\x0b\n\x04\x04\x01\x02\ - \x02\x12\x03\x0c\x04\x14\n\x0c\n\x05\x04\x01\x02\x02\x05\x12\x03\x0c\x04\ - \n\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\x0c\x0b\x0f\n\x0c\n\x05\x04\ - \x01\x02\x02\x03\x12\x03\x0c\x12\x13\n\x0b\n\x04\x04\x01\x02\x03\x12\x03\ - \r\x04\x14\n\x0c\n\x05\x04\x01\x02\x03\x05\x12\x03\r\x04\n\n\x0c\n\x05\ - \x04\x01\x02\x03\x01\x12\x03\r\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x03\x03\ - \x12\x03\r\x12\x13\n\x0b\n\x04\x04\x01\x02\x04\x12\x03\x0e\x04%\n\x0c\n\ - \x05\x04\x01\x02\x04\x06\x12\x03\x0e\x04\x16\n\x0c\n\x05\x04\x01\x02\x04\ - \x01\x12\x03\x0e\x17\x20\n\x0c\n\x05\x04\x01\x02\x04\x03\x12\x03\x0e#$\n\ - \n\n\x02\x05\0\x12\x04\x10\0\x12\x01\n\n\n\x03\x05\0\x01\x12\x03\x10\x05\ - \x17\n\x0b\n\x04\x05\0\x02\0\x12\x03\x11\x04\r\n\x0c\n\x05\x05\0\x02\0\ - \x01\x12\x03\x11\x04\x08\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x11\x0b\x0c\ - b\x06proto3\ + ail\x18\x04\x20\x01(\tH\0R\tthumbnail\x12&\n\tview_type\x18\x05\x20\x01(\ + \x0e2\t.ViewTypeR\x08viewTypeB\x12\n\x10one_of_thumbnail\"}\n\x04View\ + \x12\x0e\n\x02id\x18\x01\x20\x01(\tR\x02id\x12\x15\n\x06app_id\x18\x02\ + \x20\x01(\tR\x05appId\x12\x12\n\x04name\x18\x03\x20\x01(\tR\x04name\x12\ + \x12\n\x04desc\x18\x04\x20\x01(\tR\x04desc\x12&\n\tview_type\x18\x05\x20\ + \x01(\x0e2\t.ViewTypeR\x08viewType\"+\n\x0cRepeatedView\x12\x1b\n\x05ite\ + ms\x18\x01\x20\x03(\x0b2\x05.ViewR\x05items*\x1e\n\x08ViewType\x12\t\n\ + \x05Blank\x10\0\x12\x07\n\x03Doc\x10\x01J\xca\x06\n\x06\x12\x04\0\0\x16\ + \x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x08\ + \x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x19\n\x0b\n\x04\x04\0\x02\0\x12\ + \x03\x03\x04\x16\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\ + \x05\x04\0\x02\0\x01\x12\x03\x03\x0b\x11\n\x0c\n\x05\x04\0\x02\0\x03\x12\ + \x03\x03\x14\x15\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x14\n\x0c\n\ + \x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\ + \x12\x03\x04\x0b\x0f\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x12\x13\n\ + \x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x04\x14\n\x0c\n\x05\x04\0\x02\x02\ + \x05\x12\x03\x05\x04\n\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x05\x0b\x0f\ + \n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x12\x13\n\x0b\n\x04\x04\0\x08\ + \0\x12\x03\x06\x044\n\x0c\n\x05\x04\0\x08\0\x01\x12\x03\x06\n\x1a\n\x0b\ + \n\x04\x04\0\x02\x03\x12\x03\x06\x1d2\n\x0c\n\x05\x04\0\x02\x03\x05\x12\ + \x03\x06\x1d#\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06$-\n\x0c\n\x05\ + \x04\0\x02\x03\x03\x12\x03\x0601\n\x0b\n\x04\x04\0\x02\x04\x12\x03\x07\ + \x04\x1b\n\x0c\n\x05\x04\0\x02\x04\x06\x12\x03\x07\x04\x0c\n\x0c\n\x05\ + \x04\0\x02\x04\x01\x12\x03\x07\r\x16\n\x0c\n\x05\x04\0\x02\x04\x03\x12\ + \x03\x07\x19\x1a\n\n\n\x02\x04\x01\x12\x04\t\0\x0f\x01\n\n\n\x03\x04\x01\ + \x01\x12\x03\t\x08\x0c\n\x0b\n\x04\x04\x01\x02\0\x12\x03\n\x04\x12\n\x0c\ + \n\x05\x04\x01\x02\0\x05\x12\x03\n\x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\ + \x12\x03\n\x0b\r\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\n\x10\x11\n\x0b\n\ + \x04\x04\x01\x02\x01\x12\x03\x0b\x04\x16\n\x0c\n\x05\x04\x01\x02\x01\x05\ + \x12\x03\x0b\x04\n\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x0b\x0b\x11\n\ + \x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\x0b\x14\x15\n\x0b\n\x04\x04\x01\ + \x02\x02\x12\x03\x0c\x04\x14\n\x0c\n\x05\x04\x01\x02\x02\x05\x12\x03\x0c\ + \x04\n\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\x0c\x0b\x0f\n\x0c\n\x05\ + \x04\x01\x02\x02\x03\x12\x03\x0c\x12\x13\n\x0b\n\x04\x04\x01\x02\x03\x12\ + \x03\r\x04\x14\n\x0c\n\x05\x04\x01\x02\x03\x05\x12\x03\r\x04\n\n\x0c\n\ + \x05\x04\x01\x02\x03\x01\x12\x03\r\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x03\ + \x03\x12\x03\r\x12\x13\n\x0b\n\x04\x04\x01\x02\x04\x12\x03\x0e\x04\x1b\n\ + \x0c\n\x05\x04\x01\x02\x04\x06\x12\x03\x0e\x04\x0c\n\x0c\n\x05\x04\x01\ + \x02\x04\x01\x12\x03\x0e\r\x16\n\x0c\n\x05\x04\x01\x02\x04\x03\x12\x03\ + \x0e\x19\x1a\n\n\n\x02\x04\x02\x12\x04\x10\0\x12\x01\n\n\n\x03\x04\x02\ + \x01\x12\x03\x10\x08\x14\n\x0b\n\x04\x04\x02\x02\0\x12\x03\x11\x04\x1c\n\ + \x0c\n\x05\x04\x02\x02\0\x04\x12\x03\x11\x04\x0c\n\x0c\n\x05\x04\x02\x02\ + \0\x06\x12\x03\x11\r\x11\n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03\x11\x12\ + \x17\n\x0c\n\x05\x04\x02\x02\0\x03\x12\x03\x11\x1a\x1b\n\n\n\x02\x05\0\ + \x12\x04\x13\0\x16\x01\n\n\n\x03\x05\0\x01\x12\x03\x13\x05\r\n\x0b\n\x04\ + \x05\0\x02\0\x12\x03\x14\x04\x0e\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x14\ + \x04\t\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x14\x0c\r\n\x0b\n\x04\x05\0\ + \x02\x01\x12\x03\x15\x04\x0c\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x15\ + \x04\x07\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x15\n\x0bb\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-workspace/src/protobuf/model/view_query.rs b/rust-lib/flowy-workspace/src/protobuf/model/view_query.rs new file mode 100644 index 0000000000..ff42d7db5a --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/model/view_query.rs @@ -0,0 +1,205 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `view_query.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct QueryViewRequest { + // message fields + pub view_id: ::std::string::String, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a QueryViewRequest { + fn default() -> &'a QueryViewRequest { + ::default_instance() + } +} + +impl QueryViewRequest { + pub fn new() -> QueryViewRequest { + ::std::default::Default::default() + } + + // string view_id = 1; + + + pub fn get_view_id(&self) -> &str { + &self.view_id + } + pub fn clear_view_id(&mut self) { + self.view_id.clear(); + } + + // Param is passed by value, moved + pub fn set_view_id(&mut self, v: ::std::string::String) { + self.view_id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_view_id(&mut self) -> &mut ::std::string::String { + &mut self.view_id + } + + // Take field + pub fn take_view_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.view_id, ::std::string::String::new()) + } +} + +impl ::protobuf::Message for QueryViewRequest { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.view_id)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.view_id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.view_id); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.view_id.is_empty() { + os.write_string(1, &self.view_id)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> QueryViewRequest { + QueryViewRequest::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "view_id", + |m: &QueryViewRequest| { &m.view_id }, + |m: &mut QueryViewRequest| { &mut m.view_id }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "QueryViewRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static QueryViewRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(QueryViewRequest::new) + } +} + +impl ::protobuf::Clear for QueryViewRequest { + fn clear(&mut self) { + self.view_id.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for QueryViewRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for QueryViewRequest { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x10view_query.proto\"+\n\x10QueryViewRequest\x12\x17\n\x07view_id\x18\ + \x01\x20\x01(\tR\x06viewIdJa\n\x06\x12\x04\0\0\x04\x01\n\x08\n\x01\x0c\ + \x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x04\x01\n\n\n\x03\x04\0\ + \x01\x12\x03\x02\x08\x18\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x17\n\ + \x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\ + \x12\x03\x03\x0b\x12\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x15\x16b\ + \x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-workspace/src/protobuf/model/view_update.rs b/rust-lib/flowy-workspace/src/protobuf/model/view_update.rs new file mode 100644 index 0000000000..77ec831c47 --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/model/view_update.rs @@ -0,0 +1,463 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `view_update.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct UpdateViewRequest { + // message fields + pub view_id: ::std::string::String, + // message oneof groups + pub one_of_name: ::std::option::Option, + pub one_of_desc: ::std::option::Option, + pub one_of_thumbnail: ::std::option::Option, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a UpdateViewRequest { + fn default() -> &'a UpdateViewRequest { + ::default_instance() + } +} + +#[derive(Clone,PartialEq,Debug)] +pub enum UpdateViewRequest_oneof_one_of_name { + name(::std::string::String), +} + +#[derive(Clone,PartialEq,Debug)] +pub enum UpdateViewRequest_oneof_one_of_desc { + desc(::std::string::String), +} + +#[derive(Clone,PartialEq,Debug)] +pub enum UpdateViewRequest_oneof_one_of_thumbnail { + thumbnail(::std::string::String), +} + +impl UpdateViewRequest { + pub fn new() -> UpdateViewRequest { + ::std::default::Default::default() + } + + // string view_id = 1; + + + pub fn get_view_id(&self) -> &str { + &self.view_id + } + pub fn clear_view_id(&mut self) { + self.view_id.clear(); + } + + // Param is passed by value, moved + pub fn set_view_id(&mut self, v: ::std::string::String) { + self.view_id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_view_id(&mut self) -> &mut ::std::string::String { + &mut self.view_id + } + + // Take field + pub fn take_view_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.view_id, ::std::string::String::new()) + } + + // string name = 2; + + + pub fn get_name(&self) -> &str { + match self.one_of_name { + ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_name::name(ref v)) => v, + _ => "", + } + } + pub fn clear_name(&mut self) { + self.one_of_name = ::std::option::Option::None; + } + + pub fn has_name(&self) -> bool { + match self.one_of_name { + ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_name::name(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_name(&mut self, v: ::std::string::String) { + self.one_of_name = ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_name::name(v)) + } + + // Mutable pointer to the field. + pub fn mut_name(&mut self) -> &mut ::std::string::String { + if let ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_name::name(_)) = self.one_of_name { + } else { + self.one_of_name = ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_name::name(::std::string::String::new())); + } + match self.one_of_name { + ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_name::name(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_name(&mut self) -> ::std::string::String { + if self.has_name() { + match self.one_of_name.take() { + ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_name::name(v)) => v, + _ => panic!(), + } + } else { + ::std::string::String::new() + } + } + + // string desc = 3; + + + pub fn get_desc(&self) -> &str { + match self.one_of_desc { + ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_desc::desc(ref v)) => v, + _ => "", + } + } + pub fn clear_desc(&mut self) { + self.one_of_desc = ::std::option::Option::None; + } + + pub fn has_desc(&self) -> bool { + match self.one_of_desc { + ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_desc::desc(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_desc(&mut self, v: ::std::string::String) { + self.one_of_desc = ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_desc::desc(v)) + } + + // Mutable pointer to the field. + pub fn mut_desc(&mut self) -> &mut ::std::string::String { + if let ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_desc::desc(_)) = self.one_of_desc { + } else { + self.one_of_desc = ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_desc::desc(::std::string::String::new())); + } + match self.one_of_desc { + ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_desc::desc(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_desc(&mut self) -> ::std::string::String { + if self.has_desc() { + match self.one_of_desc.take() { + ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_desc::desc(v)) => v, + _ => panic!(), + } + } else { + ::std::string::String::new() + } + } + + // string thumbnail = 4; + + + pub fn get_thumbnail(&self) -> &str { + match self.one_of_thumbnail { + ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_thumbnail::thumbnail(ref v)) => v, + _ => "", + } + } + pub fn clear_thumbnail(&mut self) { + self.one_of_thumbnail = ::std::option::Option::None; + } + + pub fn has_thumbnail(&self) -> bool { + match self.one_of_thumbnail { + ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_thumbnail::thumbnail(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_thumbnail(&mut self, v: ::std::string::String) { + self.one_of_thumbnail = ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_thumbnail::thumbnail(v)) + } + + // Mutable pointer to the field. + pub fn mut_thumbnail(&mut self) -> &mut ::std::string::String { + if let ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_thumbnail::thumbnail(_)) = self.one_of_thumbnail { + } else { + self.one_of_thumbnail = ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_thumbnail::thumbnail(::std::string::String::new())); + } + match self.one_of_thumbnail { + ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_thumbnail::thumbnail(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_thumbnail(&mut self) -> ::std::string::String { + if self.has_thumbnail() { + match self.one_of_thumbnail.take() { + ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_thumbnail::thumbnail(v)) => v, + _ => panic!(), + } + } else { + ::std::string::String::new() + } + } +} + +impl ::protobuf::Message for UpdateViewRequest { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.view_id)?; + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.one_of_name = ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_name::name(is.read_string()?)); + }, + 3 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.one_of_desc = ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_desc::desc(is.read_string()?)); + }, + 4 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.one_of_thumbnail = ::std::option::Option::Some(UpdateViewRequest_oneof_one_of_thumbnail::thumbnail(is.read_string()?)); + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.view_id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.view_id); + } + if let ::std::option::Option::Some(ref v) = self.one_of_name { + match v { + &UpdateViewRequest_oneof_one_of_name::name(ref v) => { + my_size += ::protobuf::rt::string_size(2, &v); + }, + }; + } + if let ::std::option::Option::Some(ref v) = self.one_of_desc { + match v { + &UpdateViewRequest_oneof_one_of_desc::desc(ref v) => { + my_size += ::protobuf::rt::string_size(3, &v); + }, + }; + } + if let ::std::option::Option::Some(ref v) = self.one_of_thumbnail { + match v { + &UpdateViewRequest_oneof_one_of_thumbnail::thumbnail(ref v) => { + my_size += ::protobuf::rt::string_size(4, &v); + }, + }; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.view_id.is_empty() { + os.write_string(1, &self.view_id)?; + } + if let ::std::option::Option::Some(ref v) = self.one_of_name { + match v { + &UpdateViewRequest_oneof_one_of_name::name(ref v) => { + os.write_string(2, v)?; + }, + }; + } + if let ::std::option::Option::Some(ref v) = self.one_of_desc { + match v { + &UpdateViewRequest_oneof_one_of_desc::desc(ref v) => { + os.write_string(3, v)?; + }, + }; + } + if let ::std::option::Option::Some(ref v) = self.one_of_thumbnail { + match v { + &UpdateViewRequest_oneof_one_of_thumbnail::thumbnail(ref v) => { + os.write_string(4, v)?; + }, + }; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> UpdateViewRequest { + UpdateViewRequest::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "view_id", + |m: &UpdateViewRequest| { &m.view_id }, + |m: &mut UpdateViewRequest| { &mut m.view_id }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_string_accessor::<_>( + "name", + UpdateViewRequest::has_name, + UpdateViewRequest::get_name, + )); + fields.push(::protobuf::reflect::accessor::make_singular_string_accessor::<_>( + "desc", + UpdateViewRequest::has_desc, + UpdateViewRequest::get_desc, + )); + fields.push(::protobuf::reflect::accessor::make_singular_string_accessor::<_>( + "thumbnail", + UpdateViewRequest::has_thumbnail, + UpdateViewRequest::get_thumbnail, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "UpdateViewRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static UpdateViewRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(UpdateViewRequest::new) + } +} + +impl ::protobuf::Clear for UpdateViewRequest { + fn clear(&mut self) { + self.view_id.clear(); + self.one_of_name = ::std::option::Option::None; + self.one_of_desc = ::std::option::Option::None; + self.one_of_thumbnail = ::std::option::Option::None; + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for UpdateViewRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for UpdateViewRequest { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x11view_update.proto\"\xaa\x01\n\x11UpdateViewRequest\x12\x17\n\x07vi\ + ew_id\x18\x01\x20\x01(\tR\x06viewId\x12\x14\n\x04name\x18\x02\x20\x01(\t\ + H\0R\x04name\x12\x14\n\x04desc\x18\x03\x20\x01(\tH\x01R\x04desc\x12\x1e\ + \n\tthumbnail\x18\x04\x20\x01(\tH\x02R\tthumbnailB\r\n\x0bone_of_nameB\r\ + \n\x0bone_of_descB\x12\n\x10one_of_thumbnailJ\xd7\x02\n\x06\x12\x04\0\0\ + \x07\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\ + \x07\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x19\n\x0b\n\x04\x04\0\x02\0\ + \x12\x03\x03\x04\x17\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\ + \n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\x12\n\x0c\n\x05\x04\0\x02\0\x03\ + \x12\x03\x03\x15\x16\n\x0b\n\x04\x04\0\x08\0\x12\x03\x04\x04*\n\x0c\n\ + \x05\x04\0\x08\0\x01\x12\x03\x04\n\x15\n\x0b\n\x04\x04\0\x02\x01\x12\x03\ + \x04\x18(\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x18\x1e\n\x0c\n\x05\ + \x04\0\x02\x01\x01\x12\x03\x04\x1f#\n\x0c\n\x05\x04\0\x02\x01\x03\x12\ + \x03\x04&'\n\x0b\n\x04\x04\0\x08\x01\x12\x03\x05\x04*\n\x0c\n\x05\x04\0\ + \x08\x01\x01\x12\x03\x05\n\x15\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x18\ + (\n\x0c\n\x05\x04\0\x02\x02\x05\x12\x03\x05\x18\x1e\n\x0c\n\x05\x04\0\ + \x02\x02\x01\x12\x03\x05\x1f#\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05&\ + '\n\x0b\n\x04\x04\0\x08\x02\x12\x03\x06\x044\n\x0c\n\x05\x04\0\x08\x02\ + \x01\x12\x03\x06\n\x1a\n\x0b\n\x04\x04\0\x02\x03\x12\x03\x06\x1d2\n\x0c\ + \n\x05\x04\0\x02\x03\x05\x12\x03\x06\x1d#\n\x0c\n\x05\x04\0\x02\x03\x01\ + \x12\x03\x06$-\n\x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x0601b\x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-workspace/src/protobuf/model/workspace_create.rs b/rust-lib/flowy-workspace/src/protobuf/model/workspace_create.rs index 1022d2eabf..3ffcac8b23 100644 --- a/rust-lib/flowy-workspace/src/protobuf/model/workspace_create.rs +++ b/rust-lib/flowy-workspace/src/protobuf/model/workspace_create.rs @@ -230,6 +230,7 @@ pub struct Workspace { pub id: ::std::string::String, pub name: ::std::string::String, pub desc: ::std::string::String, + pub apps: ::protobuf::SingularPtrField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -323,10 +324,48 @@ impl Workspace { pub fn take_desc(&mut self) -> ::std::string::String { ::std::mem::replace(&mut self.desc, ::std::string::String::new()) } + + // .RepeatedApp apps = 4; + + + pub fn get_apps(&self) -> &super::app_create::RepeatedApp { + self.apps.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_apps(&mut self) { + self.apps.clear(); + } + + pub fn has_apps(&self) -> bool { + self.apps.is_some() + } + + // Param is passed by value, moved + pub fn set_apps(&mut self, v: super::app_create::RepeatedApp) { + self.apps = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_apps(&mut self) -> &mut super::app_create::RepeatedApp { + if self.apps.is_none() { + self.apps.set_default(); + } + self.apps.as_mut().unwrap() + } + + // Take field + pub fn take_apps(&mut self) -> super::app_create::RepeatedApp { + self.apps.take().unwrap_or_else(|| super::app_create::RepeatedApp::new()) + } } impl ::protobuf::Message for Workspace { fn is_initialized(&self) -> bool { + for v in &self.apps { + if !v.is_initialized() { + return false; + } + }; true } @@ -343,6 +382,9 @@ impl ::protobuf::Message for Workspace { 3 => { ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.desc)?; }, + 4 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.apps)?; + }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; }, @@ -364,6 +406,10 @@ impl ::protobuf::Message for Workspace { if !self.desc.is_empty() { my_size += ::protobuf::rt::string_size(3, &self.desc); } + if let Some(ref v) = self.apps.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); my_size @@ -379,6 +425,11 @@ impl ::protobuf::Message for Workspace { if !self.desc.is_empty() { os.write_string(3, &self.desc)?; } + if let Some(ref v) = self.apps.as_ref() { + os.write_tag(4, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -432,6 +483,11 @@ impl ::protobuf::Message for Workspace { |m: &Workspace| { &m.desc }, |m: &mut Workspace| { &mut m.desc }, )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "apps", + |m: &Workspace| { &m.apps }, + |m: &mut Workspace| { &mut m.apps }, + )); ::protobuf::reflect::MessageDescriptor::new_pb_name::( "Workspace", fields, @@ -451,6 +507,7 @@ impl ::protobuf::Clear for Workspace { self.id.clear(); self.name.clear(); self.desc.clear(); + self.apps.clear(); self.unknown_fields.clear(); } } @@ -468,28 +525,32 @@ impl ::protobuf::reflect::ProtobufValue for Workspace { } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x16workspace_create.proto\"@\n\x16CreateWorkspaceRequest\x12\x12\n\ - \x04name\x18\x01\x20\x01(\tR\x04name\x12\x12\n\x04desc\x18\x02\x20\x01(\ - \tR\x04desc\"C\n\tWorkspace\x12\x0e\n\x02id\x18\x01\x20\x01(\tR\x02id\ - \x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\x12\n\x04desc\x18\x03\ - \x20\x01(\tR\x04descJ\xd5\x02\n\x06\x12\x04\0\0\n\x01\n\x08\n\x01\x0c\ - \x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\ - \x01\x12\x03\x02\x08\x1e\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x14\n\ - \x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\ - \x12\x03\x03\x0b\x0f\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x12\x13\n\ - \x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x14\n\x0c\n\x05\x04\0\x02\x01\ - \x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0f\ - \n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x12\x13\n\n\n\x02\x04\x01\x12\ - \x04\x06\0\n\x01\n\n\n\x03\x04\x01\x01\x12\x03\x06\x08\x11\n\x0b\n\x04\ - \x04\x01\x02\0\x12\x03\x07\x04\x12\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\ - \x07\x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\x07\x0b\r\n\x0c\n\x05\ - \x04\x01\x02\0\x03\x12\x03\x07\x10\x11\n\x0b\n\x04\x04\x01\x02\x01\x12\ - \x03\x08\x04\x14\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\x08\x04\n\n\x0c\ - \n\x05\x04\x01\x02\x01\x01\x12\x03\x08\x0b\x0f\n\x0c\n\x05\x04\x01\x02\ - \x01\x03\x12\x03\x08\x12\x13\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\t\x04\ - \x14\n\x0c\n\x05\x04\x01\x02\x02\x05\x12\x03\t\x04\n\n\x0c\n\x05\x04\x01\ - \x02\x02\x01\x12\x03\t\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\t\ - \x12\x13b\x06proto3\ + \n\x16workspace_create.proto\x1a\x10app_create.proto\"@\n\x16CreateWorks\ + paceRequest\x12\x12\n\x04name\x18\x01\x20\x01(\tR\x04name\x12\x12\n\x04d\ + esc\x18\x02\x20\x01(\tR\x04desc\"e\n\tWorkspace\x12\x0e\n\x02id\x18\x01\ + \x20\x01(\tR\x02id\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\x12\ + \n\x04desc\x18\x03\x20\x01(\tR\x04desc\x12\x20\n\x04apps\x18\x04\x20\x01\ + (\x0b2\x0c.RepeatedAppR\x04appsJ\x97\x03\n\x06\x12\x04\0\0\x0c\x01\n\x08\ + \n\x01\x0c\x12\x03\0\0\x12\n\t\n\x02\x03\0\x12\x03\x01\0\x1a\n\n\n\x02\ + \x04\0\x12\x04\x03\0\x06\x01\n\n\n\x03\x04\0\x01\x12\x03\x03\x08\x1e\n\ + \x0b\n\x04\x04\0\x02\0\x12\x03\x04\x04\x14\n\x0c\n\x05\x04\0\x02\0\x05\ + \x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x04\x0b\x0f\n\x0c\ + \n\x05\x04\0\x02\0\x03\x12\x03\x04\x12\x13\n\x0b\n\x04\x04\0\x02\x01\x12\ + \x03\x05\x04\x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x05\x04\n\n\x0c\n\ + \x05\x04\0\x02\x01\x01\x12\x03\x05\x0b\x0f\n\x0c\n\x05\x04\0\x02\x01\x03\ + \x12\x03\x05\x12\x13\n\n\n\x02\x04\x01\x12\x04\x07\0\x0c\x01\n\n\n\x03\ + \x04\x01\x01\x12\x03\x07\x08\x11\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x08\ + \x04\x12\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\x08\x04\n\n\x0c\n\x05\x04\ + \x01\x02\0\x01\x12\x03\x08\x0b\r\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\ + \x08\x10\x11\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\t\x04\x14\n\x0c\n\x05\ + \x04\x01\x02\x01\x05\x12\x03\t\x04\n\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\ + \x03\t\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\t\x12\x13\n\x0b\n\ + \x04\x04\x01\x02\x02\x12\x03\n\x04\x14\n\x0c\n\x05\x04\x01\x02\x02\x05\ + \x12\x03\n\x04\n\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\n\x0b\x0f\n\x0c\ + \n\x05\x04\x01\x02\x02\x03\x12\x03\n\x12\x13\n\x0b\n\x04\x04\x01\x02\x03\ + \x12\x03\x0b\x04\x19\n\x0c\n\x05\x04\x01\x02\x03\x06\x12\x03\x0b\x04\x0f\ + \n\x0c\n\x05\x04\x01\x02\x03\x01\x12\x03\x0b\x10\x14\n\x0c\n\x05\x04\x01\ + \x02\x03\x03\x12\x03\x0b\x17\x18b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-workspace/src/protobuf/model/workspace_query.rs b/rust-lib/flowy-workspace/src/protobuf/model/workspace_query.rs new file mode 100644 index 0000000000..c5d990bb62 --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/model/workspace_query.rs @@ -0,0 +1,243 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `workspace_query.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct QueryWorkspaceRequest { + // message fields + pub workspace_id: ::std::string::String, + pub read_apps: bool, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a QueryWorkspaceRequest { + fn default() -> &'a QueryWorkspaceRequest { + ::default_instance() + } +} + +impl QueryWorkspaceRequest { + pub fn new() -> QueryWorkspaceRequest { + ::std::default::Default::default() + } + + // string workspace_id = 1; + + + pub fn get_workspace_id(&self) -> &str { + &self.workspace_id + } + pub fn clear_workspace_id(&mut self) { + self.workspace_id.clear(); + } + + // Param is passed by value, moved + pub fn set_workspace_id(&mut self, v: ::std::string::String) { + self.workspace_id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_workspace_id(&mut self) -> &mut ::std::string::String { + &mut self.workspace_id + } + + // Take field + pub fn take_workspace_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.workspace_id, ::std::string::String::new()) + } + + // bool read_apps = 2; + + + pub fn get_read_apps(&self) -> bool { + self.read_apps + } + pub fn clear_read_apps(&mut self) { + self.read_apps = false; + } + + // Param is passed by value, moved + pub fn set_read_apps(&mut self, v: bool) { + self.read_apps = v; + } +} + +impl ::protobuf::Message for QueryWorkspaceRequest { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.workspace_id)?; + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_bool()?; + self.read_apps = tmp; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.workspace_id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.workspace_id); + } + if self.read_apps != false { + my_size += 2; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.workspace_id.is_empty() { + os.write_string(1, &self.workspace_id)?; + } + if self.read_apps != false { + os.write_bool(2, self.read_apps)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> QueryWorkspaceRequest { + QueryWorkspaceRequest::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "workspace_id", + |m: &QueryWorkspaceRequest| { &m.workspace_id }, + |m: &mut QueryWorkspaceRequest| { &mut m.workspace_id }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>( + "read_apps", + |m: &QueryWorkspaceRequest| { &m.read_apps }, + |m: &mut QueryWorkspaceRequest| { &mut m.read_apps }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "QueryWorkspaceRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static QueryWorkspaceRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(QueryWorkspaceRequest::new) + } +} + +impl ::protobuf::Clear for QueryWorkspaceRequest { + fn clear(&mut self) { + self.workspace_id.clear(); + self.read_apps = false; + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for QueryWorkspaceRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for QueryWorkspaceRequest { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x15workspace_query.proto\"W\n\x15QueryWorkspaceRequest\x12!\n\x0cwork\ + space_id\x18\x01\x20\x01(\tR\x0bworkspaceId\x12\x1b\n\tread_apps\x18\x02\ + \x20\x01(\x08R\x08readAppsJ\x98\x01\n\x06\x12\x04\0\0\x05\x01\n\x08\n\ + \x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\ + \x04\0\x01\x12\x03\x02\x08\x1d\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\ + \x1c\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\ + \0\x01\x12\x03\x03\x0b\x17\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x1a\ + \x1b\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x17\n\x0c\n\x05\x04\0\x02\ + \x01\x05\x12\x03\x04\x04\x08\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\t\ + \x12\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x15\x16b\x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-workspace/src/protobuf/model/workspace_user_detail.rs b/rust-lib/flowy-workspace/src/protobuf/model/workspace_user_detail.rs index ca06200372..df1bb61951 100644 --- a/rust-lib/flowy-workspace/src/protobuf/model/workspace_user_detail.rs +++ b/rust-lib/flowy-workspace/src/protobuf/model/workspace_user_detail.rs @@ -24,7 +24,7 @@ // const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; #[derive(PartialEq,Clone,Default)] -pub struct UserWorkspace { +pub struct CurrentWorkspace { // message fields pub owner: ::std::string::String, pub workspace_id: ::std::string::String, @@ -33,14 +33,14 @@ pub struct UserWorkspace { pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a UserWorkspace { - fn default() -> &'a UserWorkspace { - ::default_instance() +impl<'a> ::std::default::Default for &'a CurrentWorkspace { + fn default() -> &'a CurrentWorkspace { + ::default_instance() } } -impl UserWorkspace { - pub fn new() -> UserWorkspace { +impl CurrentWorkspace { + pub fn new() -> CurrentWorkspace { ::std::default::Default::default() } @@ -97,7 +97,7 @@ impl UserWorkspace { } } -impl ::protobuf::Message for UserWorkspace { +impl ::protobuf::Message for CurrentWorkspace { fn is_initialized(&self) -> bool { true } @@ -172,8 +172,8 @@ impl ::protobuf::Message for UserWorkspace { Self::descriptor_static() } - fn new() -> UserWorkspace { - UserWorkspace::new() + fn new() -> CurrentWorkspace { + CurrentWorkspace::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { @@ -182,29 +182,29 @@ impl ::protobuf::Message for UserWorkspace { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "owner", - |m: &UserWorkspace| { &m.owner }, - |m: &mut UserWorkspace| { &mut m.owner }, + |m: &CurrentWorkspace| { &m.owner }, + |m: &mut CurrentWorkspace| { &mut m.owner }, )); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "workspace_id", - |m: &UserWorkspace| { &m.workspace_id }, - |m: &mut UserWorkspace| { &mut m.workspace_id }, + |m: &CurrentWorkspace| { &m.workspace_id }, + |m: &mut CurrentWorkspace| { &mut m.workspace_id }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "UserWorkspace", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CurrentWorkspace", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static UserWorkspace { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(UserWorkspace::new) + fn default_instance() -> &'static CurrentWorkspace { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CurrentWorkspace::new) } } -impl ::protobuf::Clear for UserWorkspace { +impl ::protobuf::Clear for CurrentWorkspace { fn clear(&mut self) { self.owner.clear(); self.workspace_id.clear(); @@ -212,255 +212,29 @@ impl ::protobuf::Clear for UserWorkspace { } } -impl ::std::fmt::Debug for UserWorkspace { +impl ::std::fmt::Debug for CurrentWorkspace { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for UserWorkspace { - fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { - ::protobuf::reflect::ReflectValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct UserWorkspaceDetail { - // message fields - pub owner: ::std::string::String, - pub workspace: ::protobuf::SingularPtrField, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a UserWorkspaceDetail { - fn default() -> &'a UserWorkspaceDetail { - ::default_instance() - } -} - -impl UserWorkspaceDetail { - pub fn new() -> UserWorkspaceDetail { - ::std::default::Default::default() - } - - // string owner = 1; - - - pub fn get_owner(&self) -> &str { - &self.owner - } - pub fn clear_owner(&mut self) { - self.owner.clear(); - } - - // Param is passed by value, moved - pub fn set_owner(&mut self, v: ::std::string::String) { - self.owner = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_owner(&mut self) -> &mut ::std::string::String { - &mut self.owner - } - - // Take field - pub fn take_owner(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.owner, ::std::string::String::new()) - } - - // .Workspace workspace = 2; - - - pub fn get_workspace(&self) -> &super::workspace_create::Workspace { - self.workspace.as_ref().unwrap_or_else(|| ::default_instance()) - } - pub fn clear_workspace(&mut self) { - self.workspace.clear(); - } - - pub fn has_workspace(&self) -> bool { - self.workspace.is_some() - } - - // Param is passed by value, moved - pub fn set_workspace(&mut self, v: super::workspace_create::Workspace) { - self.workspace = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_workspace(&mut self) -> &mut super::workspace_create::Workspace { - if self.workspace.is_none() { - self.workspace.set_default(); - } - self.workspace.as_mut().unwrap() - } - - // Take field - pub fn take_workspace(&mut self) -> super::workspace_create::Workspace { - self.workspace.take().unwrap_or_else(|| super::workspace_create::Workspace::new()) - } -} - -impl ::protobuf::Message for UserWorkspaceDetail { - fn is_initialized(&self) -> bool { - for v in &self.workspace { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.owner)?; - }, - 2 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.workspace)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.owner.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.owner); - } - if let Some(ref v) = self.workspace.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.owner.is_empty() { - os.write_string(1, &self.owner)?; - } - if let Some(ref v) = self.workspace.as_ref() { - os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> UserWorkspaceDetail { - UserWorkspaceDetail::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "owner", - |m: &UserWorkspaceDetail| { &m.owner }, - |m: &mut UserWorkspaceDetail| { &mut m.owner }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "workspace", - |m: &UserWorkspaceDetail| { &m.workspace }, - |m: &mut UserWorkspaceDetail| { &mut m.workspace }, - )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "UserWorkspaceDetail", - fields, - file_descriptor_proto() - ) - }) - } - - fn default_instance() -> &'static UserWorkspaceDetail { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(UserWorkspaceDetail::new) - } -} - -impl ::protobuf::Clear for UserWorkspaceDetail { - fn clear(&mut self) { - self.owner.clear(); - self.workspace.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for UserWorkspaceDetail { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for UserWorkspaceDetail { +impl ::protobuf::reflect::ProtobufValue for CurrentWorkspace { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x1bworkspace_user_detail.proto\x1a\x16workspace_create.proto\"H\n\rUs\ - erWorkspace\x12\x14\n\x05owner\x18\x01\x20\x01(\tR\x05owner\x12!\n\x0cwo\ - rkspace_id\x18\x02\x20\x01(\tR\x0bworkspaceId\"U\n\x13UserWorkspaceDetai\ - l\x12\x14\n\x05owner\x18\x01\x20\x01(\tR\x05owner\x12(\n\tworkspace\x18\ - \x02\x20\x01(\x0b2\n.WorkspaceR\tworkspaceJ\xa9\x02\n\x06\x12\x04\0\0\n\ - \x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\t\n\x02\x03\0\x12\x03\x01\0\x20\n\ - \n\n\x02\x04\0\x12\x04\x03\0\x06\x01\n\n\n\x03\x04\0\x01\x12\x03\x03\x08\ - \x15\n\x0b\n\x04\x04\0\x02\0\x12\x03\x04\x04\x15\n\x0c\n\x05\x04\0\x02\0\ - \x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x04\x0b\x10\n\ - \x0c\n\x05\x04\0\x02\0\x03\x12\x03\x04\x13\x14\n\x0b\n\x04\x04\0\x02\x01\ - \x12\x03\x05\x04\x1c\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x05\x04\n\n\ - \x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x05\x0b\x17\n\x0c\n\x05\x04\0\x02\ - \x01\x03\x12\x03\x05\x1a\x1b\n\n\n\x02\x04\x01\x12\x04\x07\0\n\x01\n\n\n\ - \x03\x04\x01\x01\x12\x03\x07\x08\x1b\n\x0b\n\x04\x04\x01\x02\0\x12\x03\ - \x08\x04\x15\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\x08\x04\n\n\x0c\n\x05\ - \x04\x01\x02\0\x01\x12\x03\x08\x0b\x10\n\x0c\n\x05\x04\x01\x02\0\x03\x12\ - \x03\x08\x13\x14\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\t\x04\x1c\n\x0c\n\ - \x05\x04\x01\x02\x01\x06\x12\x03\t\x04\r\n\x0c\n\x05\x04\x01\x02\x01\x01\ - \x12\x03\t\x0e\x17\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\t\x1a\x1bb\ - \x06proto3\ + \n\x1bworkspace_user_detail.proto\"K\n\x10CurrentWorkspace\x12\x14\n\x05\ + owner\x18\x01\x20\x01(\tR\x05owner\x12!\n\x0cworkspace_id\x18\x02\x20\ + \x01(\tR\x0bworkspaceIdJ\x98\x01\n\x06\x12\x04\0\0\x05\x01\n\x08\n\x01\ + \x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\ + \0\x01\x12\x03\x02\x08\x18\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x15\n\ + \x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\ + \x12\x03\x03\x0b\x10\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x13\x14\n\ + \x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x1c\n\x0c\n\x05\x04\0\x02\x01\ + \x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x17\ + \n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x1a\x1bb\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/app_create.proto b/rust-lib/flowy-workspace/src/protobuf/proto/app_create.proto index 10c585b344..e0bbca568e 100644 --- a/rust-lib/flowy-workspace/src/protobuf/proto/app_create.proto +++ b/rust-lib/flowy-workspace/src/protobuf/proto/app_create.proto @@ -1,4 +1,5 @@ syntax = "proto3"; +import "view_create.proto"; message CreateAppRequest { string workspace_id = 1; @@ -14,4 +15,8 @@ message App { string workspace_id = 2; string name = 3; string desc = 4; + RepeatedView views = 5; +} +message RepeatedApp { + repeated App items = 1; } diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/app_query.proto b/rust-lib/flowy-workspace/src/protobuf/proto/app_query.proto new file mode 100644 index 0000000000..8962befbec --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/proto/app_query.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; + +message QueryAppRequest { + string app_id = 1; + bool read_views = 2; +} diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/errors.proto b/rust-lib/flowy-workspace/src/protobuf/proto/errors.proto index 32ed650635..1103916f3b 100644 --- a/rust-lib/flowy-workspace/src/protobuf/proto/errors.proto +++ b/rust-lib/flowy-workspace/src/protobuf/proto/errors.proto @@ -12,7 +12,9 @@ enum WorkspaceErrorCode { AppIdInvalid = 10; AppNameInvalid = 11; ViewNameInvalid = 20; - ViewThumbnailName = 21; + ViewThumbnailInvalid = 21; + ViewIdInvalid = 22; + ViewDescInvalid = 23; DatabaseConnectionFail = 100; WorkspaceDatabaseError = 101; UserInternalError = 102; diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/event.proto b/rust-lib/flowy-workspace/src/protobuf/proto/event.proto index 42274c9a32..aaf252e84c 100644 --- a/rust-lib/flowy-workspace/src/protobuf/proto/event.proto +++ b/rust-lib/flowy-workspace/src/protobuf/proto/event.proto @@ -2,7 +2,11 @@ syntax = "proto3"; enum WorkspaceEvent { CreateWorkspace = 0; - GetWorkspaceDetail = 1; + GetCurWorkspace = 1; + GetWorkspace = 2; CreateApp = 101; + GetApp = 102; CreateView = 201; + ReadView = 202; + UpdateView = 203; } diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/observable.proto b/rust-lib/flowy-workspace/src/protobuf/proto/observable.proto new file mode 100644 index 0000000000..1d6367dcf7 --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/proto/observable.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +enum WorkspaceObservable { + Unknown = 0; + WorkspaceUpdateDesc = 10; + WorkspaceAddApp = 11; + AppUpdateDesc = 20; + AppAddView = 21; + ViewUpdateDesc = 30; +} diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/view_create.proto b/rust-lib/flowy-workspace/src/protobuf/proto/view_create.proto index 00d2868e63..d57cb2bfa7 100644 --- a/rust-lib/flowy-workspace/src/protobuf/proto/view_create.proto +++ b/rust-lib/flowy-workspace/src/protobuf/proto/view_create.proto @@ -5,15 +5,19 @@ message CreateViewRequest { string name = 2; string desc = 3; oneof one_of_thumbnail { string thumbnail = 4; }; - ViewTypeIdentifier view_type = 5; + ViewType view_type = 5; } message View { string id = 1; string app_id = 2; string name = 3; string desc = 4; - ViewTypeIdentifier view_type = 5; + ViewType view_type = 5; } -enum ViewTypeIdentifier { - Docs = 0; +message RepeatedView { + repeated View items = 1; +} +enum ViewType { + Blank = 0; + Doc = 1; } diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/view_query.proto b/rust-lib/flowy-workspace/src/protobuf/proto/view_query.proto new file mode 100644 index 0000000000..b3ddc861ae --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/proto/view_query.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +message QueryViewRequest { + string view_id = 1; +} diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/view_update.proto b/rust-lib/flowy-workspace/src/protobuf/proto/view_update.proto new file mode 100644 index 0000000000..389c22110b --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/proto/view_update.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +message UpdateViewRequest { + string view_id = 1; + oneof one_of_name { string name = 2; }; + oneof one_of_desc { string desc = 3; }; + oneof one_of_thumbnail { string thumbnail = 4; }; +} diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/workspace_create.proto b/rust-lib/flowy-workspace/src/protobuf/proto/workspace_create.proto index 0712daf539..bfac719c57 100644 --- a/rust-lib/flowy-workspace/src/protobuf/proto/workspace_create.proto +++ b/rust-lib/flowy-workspace/src/protobuf/proto/workspace_create.proto @@ -1,4 +1,5 @@ syntax = "proto3"; +import "app_create.proto"; message CreateWorkspaceRequest { string name = 1; @@ -8,4 +9,5 @@ message Workspace { string id = 1; string name = 2; string desc = 3; + RepeatedApp apps = 4; } diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/workspace_query.proto b/rust-lib/flowy-workspace/src/protobuf/proto/workspace_query.proto new file mode 100644 index 0000000000..de1803271d --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/proto/workspace_query.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; + +message QueryWorkspaceRequest { + string workspace_id = 1; + bool read_apps = 2; +} diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/workspace_user_detail.proto b/rust-lib/flowy-workspace/src/protobuf/proto/workspace_user_detail.proto index c43aed0503..2607d00694 100644 --- a/rust-lib/flowy-workspace/src/protobuf/proto/workspace_user_detail.proto +++ b/rust-lib/flowy-workspace/src/protobuf/proto/workspace_user_detail.proto @@ -1,11 +1,6 @@ syntax = "proto3"; -import "workspace_create.proto"; -message UserWorkspace { +message CurrentWorkspace { string owner = 1; string workspace_id = 2; } -message UserWorkspaceDetail { - string owner = 1; - Workspace workspace = 2; -} diff --git a/rust-lib/flowy-workspace/src/services/app_controller.rs b/rust-lib/flowy-workspace/src/services/app_controller.rs index 16a2526e92..4c50295f99 100644 --- a/rust-lib/flowy-workspace/src/services/app_controller.rs +++ b/rust-lib/flowy-workspace/src/services/app_controller.rs @@ -1,34 +1,78 @@ use crate::{ - entities::app::{App, CreateAppParams, *}, + entities::{ + app::{App, CreateAppParams, *}, + view::View, + }, errors::*, - module::WorkspaceUser, - sql_tables::app::*, + module::{WorkspaceDatabase, WorkspaceUser}, + observable::*, + services::ViewController, + sql_tables::app::{AppTable, AppTableChangeset, AppTableSql}, }; -use flowy_database::{prelude::*, schema::app_table}; +use flowy_dispatch::prelude::DispatchFuture; use std::sync::Arc; pub struct AppController { user: Arc, + sql: Arc, + view_controller: Arc, } impl AppController { - pub fn new(user: Arc) -> Self { Self { user } } + pub fn new( + user: Arc, + database: Arc, + view_controller: Arc, + ) -> Self { + let sql = Arc::new(AppTableSql { database }); + Self { + user, + sql, + view_controller, + } + } - pub fn save_app(&self, params: CreateAppParams) -> Result { + pub fn create_app(&self, params: CreateAppParams) -> Result { let app_table = AppTable::new(params); - let conn = self.user.db_connection()?; - let app: App = app_table.clone().into(); - let _ = diesel::insert_into(app_table::table) - .values(app_table) - .execute(&*conn)?; + let _ = self.sql.create_app(app_table)?; + send_observable(&app.workspace_id, WorkspaceObservable::WorkspaceAddApp); Ok(app) } + pub async fn read_app(&self, app_id: &str) -> Result { + let app_table = self.async_read_app(&app_id).await?; + Ok(app_table.into()) + } + pub fn update_app(&self, params: UpdateAppParams) -> Result<(), WorkspaceError> { let changeset = AppTableChangeset::new(params); - let conn = self.user.db_connection()?; - diesel_update_table!(app_table, changeset, conn); + let app_id = changeset.id.clone(); + let _ = self.sql.update_app(changeset)?; + send_observable(&app_id, WorkspaceObservable::AppUpdateDesc); Ok(()) } + + pub async fn read_views(&self, app_id: &str) -> Result, WorkspaceError> { + let views = self + .sql + .read_views_belong_to_app(app_id)? + .into_iter() + .map(|view_table| view_table.into()) + .collect::>(); + + Ok(views) + } + + fn async_read_app(&self, app_id: &str) -> DispatchFuture> { + let sql = self.sql.clone(); + let app_id = app_id.to_owned(); + DispatchFuture { + fut: Box::pin(async move { + let app_table = sql.read_app(&app_id)?; + // TODO: fetch app from remote server + Ok(app_table) + }), + } + } } diff --git a/rust-lib/flowy-workspace/src/services/mod.rs b/rust-lib/flowy-workspace/src/services/mod.rs index 35c19c299e..d043703c3d 100644 --- a/rust-lib/flowy-workspace/src/services/mod.rs +++ b/rust-lib/flowy-workspace/src/services/mod.rs @@ -1,9 +1,9 @@ +pub use app_controller::*; +pub use view_controller::*; +pub use workspace_controller::*; + mod app_controller; mod database; mod helper; mod view_controller; mod workspace_controller; - -pub use app_controller::*; -pub use view_controller::*; -pub use workspace_controller::*; diff --git a/rust-lib/flowy-workspace/src/services/view_controller.rs b/rust-lib/flowy-workspace/src/services/view_controller.rs index 2c0507a04e..87cb69d691 100644 --- a/rust-lib/flowy-workspace/src/services/view_controller.rs +++ b/rust-lib/flowy-workspace/src/services/view_controller.rs @@ -1,28 +1,43 @@ use crate::{ - entities::view::{CreateViewParams, View}, + entities::view::{CreateViewParams, UpdateViewParams, View}, errors::WorkspaceError, - module::WorkspaceUser, - sql_tables::view::ViewTable, + module::WorkspaceDatabase, + observable::{send_observable, WorkspaceObservable}, + sql_tables::view::{ViewTable, ViewTableChangeset, ViewTableSql}, }; -use flowy_database::{prelude::*, schema::view_table}; use std::sync::Arc; pub struct ViewController { - user: Arc, + sql: Arc, } impl ViewController { - pub fn new(user: Arc) -> Self { Self { user } } + pub fn new(database: Arc) -> Self { + let sql = Arc::new(ViewTableSql { database }); + Self { sql } + } - pub async fn save_view(&self, params: CreateViewParams) -> Result { + pub async fn create_view(&self, params: CreateViewParams) -> Result { let view_table = ViewTable::new(params); - let conn = self.user.db_connection()?; let view: View = view_table.clone().into(); + let _ = self.sql.create_view(view_table)?; - let _ = diesel::insert_into(view_table::table) - .values(view_table) - .execute(&*conn)?; - + send_observable(&view.app_id, WorkspaceObservable::AppAddView); Ok(view) } + + pub async fn read_view(&self, view_id: &str) -> Result { + let view_table = self.sql.read_view(view_id)?; + let view: View = view_table.into(); + Ok(view) + } + + pub async fn update_view(&self, params: UpdateViewParams) -> Result<(), WorkspaceError> { + let changeset = ViewTableChangeset::new(params); + let view_id = changeset.id.clone(); + let _ = self.sql.update_view(changeset)?; + send_observable(&view_id, WorkspaceObservable::ViewUpdateDesc); + + Ok(()) + } } diff --git a/rust-lib/flowy-workspace/src/services/workspace_controller.rs b/rust-lib/flowy-workspace/src/services/workspace_controller.rs index 0356cea43b..d98a9dfec7 100644 --- a/rust-lib/flowy-workspace/src/services/workspace_controller.rs +++ b/rust-lib/flowy-workspace/src/services/workspace_controller.rs @@ -1,66 +1,97 @@ -use crate::{entities::workspace::*, errors::*, module::WorkspaceUser, sql_tables::workspace::*}; -use flowy_database::{prelude::*, schema::workspace_table}; - -use flowy_database::schema::workspace_table::dsl; +use crate::{ + entities::{app::App, workspace::*}, + errors::*, + module::{WorkspaceDatabase, WorkspaceUser}, + observable::{send_observable, WorkspaceObservable}, + services::AppController, + sql_tables::workspace::{WorkspaceSql, WorkspaceTable, WorkspaceTableChangeset}, +}; use flowy_dispatch::prelude::DispatchFuture; use std::sync::Arc; pub struct WorkspaceController { pub user: Arc, + pub sql: Arc, + pub app_controller: Arc, } impl WorkspaceController { - pub fn new(user: Arc) -> Self { Self { user } } + pub fn new( + user: Arc, + database: Arc, + app_controller: Arc, + ) -> Self { + let sql = Arc::new(WorkspaceSql { database }); + Self { + user, + sql, + app_controller, + } + } - pub async fn save_workspace( + pub async fn create_workspace( &self, params: CreateWorkspaceParams, ) -> Result { let workspace_table = WorkspaceTable::new(params); let detail: Workspace = workspace_table.clone().into(); - - let _ = diesel::insert_into(workspace_table::table) - .values(workspace_table) - .execute(&*(self.user.db_connection()?))?; - - let _ = self.user.set_cur_workspace_id(&detail.id).await?; - + let _ = self.sql.create_workspace(workspace_table)?; Ok(detail) } - pub fn get_workspace( + pub fn update_workspace(&self, params: UpdateWorkspaceParams) -> Result<(), WorkspaceError> { + let changeset = WorkspaceTableChangeset::new(params); + let workspace_id = changeset.id.clone(); + let _ = self.sql.update_workspace(changeset)?; + + send_observable(&workspace_id, WorkspaceObservable::WorkspaceUpdateDesc); + Ok(()) + } + + pub fn delete_workspace(&self, workspace_id: &str) -> Result<(), WorkspaceError> { + unimplemented!() + } + + pub async fn read_cur_workspace(&self) -> Result { + let user_workspace = self.user.get_cur_workspace().await?; + let workspace = self.read_workspace(&user_workspace.workspace_id).await?; + Ok(workspace) + } + + pub async fn read_cur_apps(&self) -> Result, WorkspaceError> { + let user_workspace = self.user.get_cur_workspace().await?; + let apps = self.read_apps(&user_workspace.workspace_id).await?; + Ok(apps) + } + + pub async fn read_workspace(&self, workspace_id: &str) -> Result { + let workspace_table = self.read_workspace_table(workspace_id).await?; + Ok(workspace_table.into()) + } + + pub async fn read_apps(&self, workspace_id: &str) -> Result, WorkspaceError> { + let apps = self + .sql + .read_apps_belong_to_workspace(workspace_id)? + .into_iter() + .map(|app_table| app_table.into()) + .collect::>(); + + Ok(apps) + } + + fn read_workspace_table( &self, workspace_id: &str, ) -> DispatchFuture> { - let user = self.user.clone(); + let sql = self.sql.clone(); let workspace_id = workspace_id.to_owned(); DispatchFuture { fut: Box::pin(async move { - let workspace = dsl::workspace_table - .filter(workspace_table::id.eq(&workspace_id)) - .first::(&*(user.db_connection()?))?; - + let workspace = sql.read_workspace(&workspace_id)?; // TODO: fetch workspace from remote server Ok(workspace) }), } } - - pub fn update_workspace(&self, params: UpdateWorkspaceParams) -> Result<(), WorkspaceError> { - let changeset = WorkspaceTableChangeset::new(params); - let conn = self.user.db_connection()?; - diesel_update_table!(workspace_table, changeset, conn); - - Ok(()) - } - - pub async fn get_user_workspace_detail(&self) -> Result { - let user_workspace = self.user.get_cur_workspace().await?; - let workspace = self.get_workspace(&user_workspace.workspace_id).await?; - - Ok(UserWorkspaceDetail { - owner: user_workspace.owner, - workspace: workspace.into(), - }) - } } diff --git a/rust-lib/flowy-workspace/src/sql_tables/app/app_sql.rs b/rust-lib/flowy-workspace/src/sql_tables/app/app_sql.rs new file mode 100644 index 0000000000..2386d36fcf --- /dev/null +++ b/rust-lib/flowy-workspace/src/sql_tables/app/app_sql.rs @@ -0,0 +1,61 @@ +use crate::{ + errors::WorkspaceError, + module::WorkspaceDatabase, + sql_tables::{ + app::{AppTable, AppTableChangeset}, + view::ViewTable, + workspace::WorkspaceTable, + }, +}; +use flowy_database::{ + prelude::*, + schema::{app_table, app_table::dsl}, +}; +use std::sync::Arc; + +pub struct AppTableSql { + pub database: Arc, +} + +impl AppTableSql { + pub(crate) fn create_app(&self, app_table: AppTable) -> Result<(), WorkspaceError> { + let conn = self.database.db_connection()?; + let _ = diesel::insert_into(app_table::table) + .values(app_table) + .execute(&*conn)?; + Ok(()) + } + + pub(crate) fn update_app(&self, changeset: AppTableChangeset) -> Result<(), WorkspaceError> { + let conn = self.database.db_connection()?; + diesel_update_table!(app_table, changeset, conn); + Ok(()) + } + + pub(crate) fn read_app(&self, app_id: &str) -> Result { + let app_table = dsl::app_table + .filter(app_table::id.eq(app_id)) + .first::(&*(self.database.db_connection()?))?; + + Ok(app_table) + } + + pub(crate) fn delete_app(&self, app_id: &str) -> Result<(), WorkspaceError> { unimplemented!() } + + pub(crate) fn read_views_belong_to_app( + &self, + app_id: &str, + ) -> Result, WorkspaceError> { + let conn = self.database.db_connection()?; + + let views = conn.immediate_transaction::<_, WorkspaceError, _>(|| { + let app_table: AppTable = dsl::app_table + .filter(app_table::id.eq(app_id)) + .first::(&*(conn))?; + let views = ViewTable::belonging_to(&app_table).load::(&*conn)?; + Ok(views) + })?; + + Ok(views) + } +} diff --git a/rust-lib/flowy-workspace/src/sql_tables/app/app.rs b/rust-lib/flowy-workspace/src/sql_tables/app/app_table.rs similarity index 94% rename from rust-lib/flowy-workspace/src/sql_tables/app/app.rs rename to rust-lib/flowy-workspace/src/sql_tables/app/app_table.rs index ea5f4080d7..2975775d2d 100644 --- a/rust-lib/flowy-workspace/src/sql_tables/app/app.rs +++ b/rust-lib/flowy-workspace/src/sql_tables/app/app_table.rs @@ -1,5 +1,8 @@ use crate::{ - entities::app::{App, ColorStyle, CreateAppParams, UpdateAppParams}, + entities::{ + app::{App, ColorStyle, CreateAppParams, UpdateAppParams}, + view::RepeatedView, + }, impl_sql_binary_expression, sql_tables::workspace::WorkspaceTable, }; @@ -101,6 +104,7 @@ impl std::convert::Into for AppTable { workspace_id: self.workspace_id, name: self.name, desc: self.desc, + views: RepeatedView::default(), } } } diff --git a/rust-lib/flowy-workspace/src/sql_tables/app/mod.rs b/rust-lib/flowy-workspace/src/sql_tables/app/mod.rs index 732903754f..2ae56b4950 100644 --- a/rust-lib/flowy-workspace/src/sql_tables/app/mod.rs +++ b/rust-lib/flowy-workspace/src/sql_tables/app/mod.rs @@ -1,3 +1,5 @@ -mod app; +mod app_sql; +mod app_table; -pub use app::*; +pub use app_sql::*; +pub use app_table::*; diff --git a/rust-lib/flowy-workspace/src/sql_tables/view/mod.rs b/rust-lib/flowy-workspace/src/sql_tables/view/mod.rs index 034f450e71..b2730abed2 100644 --- a/rust-lib/flowy-workspace/src/sql_tables/view/mod.rs +++ b/rust-lib/flowy-workspace/src/sql_tables/view/mod.rs @@ -1,3 +1,5 @@ -mod view; +mod view_sql; +mod view_table; -pub use view::*; +pub use view_sql::*; +pub use view_table::*; diff --git a/rust-lib/flowy-workspace/src/sql_tables/view/view_sql.rs b/rust-lib/flowy-workspace/src/sql_tables/view/view_sql.rs new file mode 100644 index 0000000000..95aad2ab47 --- /dev/null +++ b/rust-lib/flowy-workspace/src/sql_tables/view/view_sql.rs @@ -0,0 +1,40 @@ +use crate::{ + errors::WorkspaceError, + module::WorkspaceDatabase, + sql_tables::view::{ViewTable, ViewTableChangeset}, +}; +use flowy_database::{ + prelude::*, + schema::{view_table, view_table::dsl}, +}; +use std::sync::Arc; + +pub struct ViewTableSql { + pub database: Arc, +} + +impl ViewTableSql { + pub(crate) fn create_view(&self, view_table: ViewTable) -> Result<(), WorkspaceError> { + let conn = self.database.db_connection()?; + let _ = diesel::insert_into(view_table::table) + .values(view_table) + .execute(&*conn)?; + Ok(()) + } + + pub(crate) fn read_view(&self, view_id: &str) -> Result { + let view_table = dsl::view_table + .filter(view_table::id.eq(view_id)) + .first::(&*(self.database.db_connection()?))?; + + Ok(view_table) + } + + pub(crate) fn update_view(&self, changeset: ViewTableChangeset) -> Result<(), WorkspaceError> { + let conn = self.database.db_connection()?; + diesel_update_table!(view_table, changeset, conn); + Ok(()) + } + + pub fn delete_view(&self, view_id: &str) -> Result<(), WorkspaceError> { unimplemented!() } +} diff --git a/rust-lib/flowy-workspace/src/sql_tables/view/view.rs b/rust-lib/flowy-workspace/src/sql_tables/view/view_table.rs similarity index 73% rename from rust-lib/flowy-workspace/src/sql_tables/view/view.rs rename to rust-lib/flowy-workspace/src/sql_tables/view/view_table.rs index 0557fe884b..cce138c3c3 100644 --- a/rust-lib/flowy-workspace/src/sql_tables/view/view.rs +++ b/rust-lib/flowy-workspace/src/sql_tables/view/view_table.rs @@ -1,10 +1,10 @@ use crate::{ - entities::view::{CreateViewParams, View, ViewTypeIdentifier}, + entities::view::{CreateViewParams, UpdateViewParams, View, ViewType}, impl_sql_integer_expression, sql_tables::app::AppTable, }; use diesel::sql_types::Integer; -use flowy_database::schema::{view_table, view_table::dsl}; +use flowy_database::schema::view_table; use flowy_infra::{timestamp, uuid}; #[derive(PartialEq, Clone, Debug, Queryable, Identifiable, Insertable, Associations)] @@ -18,7 +18,7 @@ pub(crate) struct ViewTable { pub modified_time: i64, pub create_time: i64, pub thumbnail: String, - pub view_type: ViewType, + pub view_type: ViewTableType, pub version: i64, } @@ -43,7 +43,7 @@ impl ViewTable { impl std::convert::Into for ViewTable { fn into(self) -> View { let view_type = match self.view_type { - ViewType::Docs => ViewTypeIdentifier::Docs, + ViewTableType::Docs => ViewType::Doc, }; View { @@ -62,15 +62,17 @@ pub struct ViewTableChangeset { pub id: String, pub name: Option, pub desc: Option, + pub thumbnail: Option, pub modified_time: i64, } impl ViewTableChangeset { - pub fn new(id: &str) -> Self { + pub fn new(params: UpdateViewParams) -> Self { ViewTableChangeset { - id: id.to_string(), - name: None, - desc: None, + id: params.view_id, + name: params.name, + desc: params.desc, + thumbnail: params.thumbnail, modified_time: timestamp(), } } @@ -79,28 +81,28 @@ impl ViewTableChangeset { #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, FromSqlRow, AsExpression)] #[repr(i32)] #[sql_type = "Integer"] -pub enum ViewType { +pub enum ViewTableType { Docs = 0, } -impl std::default::Default for ViewType { - fn default() -> Self { ViewType::Docs } +impl std::default::Default for ViewTableType { + fn default() -> Self { ViewTableType::Docs } } -impl std::convert::From for ViewType { +impl std::convert::From for ViewTableType { fn from(value: i32) -> Self { match value { - 0 => ViewType::Docs, + 0 => ViewTableType::Docs, o => { log::error!("Unsupported view type {}, fallback to ViewType::Docs", o); - ViewType::Docs + ViewTableType::Docs }, } } } -impl ViewType { +impl ViewTableType { pub fn value(&self) -> i32 { *self as i32 } } -impl_sql_integer_expression!(ViewType); +impl_sql_integer_expression!(ViewTableType); diff --git a/rust-lib/flowy-workspace/src/sql_tables/workspace/mod.rs b/rust-lib/flowy-workspace/src/sql_tables/workspace/mod.rs index c1f22fe9d7..2c8735b267 100644 --- a/rust-lib/flowy-workspace/src/sql_tables/workspace/mod.rs +++ b/rust-lib/flowy-workspace/src/sql_tables/workspace/mod.rs @@ -1,3 +1,5 @@ -mod workspace; +mod workspace_sql; +mod workspace_table; -pub use workspace::*; +pub use workspace_sql::*; +pub use workspace_table::*; diff --git a/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace_sql.rs b/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace_sql.rs new file mode 100644 index 0000000000..e612f61a4e --- /dev/null +++ b/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace_sql.rs @@ -0,0 +1,64 @@ +use crate::{ + errors::WorkspaceError, + module::WorkspaceDatabase, + sql_tables::{ + app::AppTable, + workspace::{WorkspaceTable, WorkspaceTableChangeset}, + }, +}; +use flowy_database::{ + prelude::*, + schema::{workspace_table, workspace_table::dsl}, +}; +use std::sync::Arc; + +pub struct WorkspaceSql { + pub database: Arc, +} + +impl WorkspaceSql { + pub fn create_workspace(&self, workspace_table: WorkspaceTable) -> Result<(), WorkspaceError> { + let _ = diesel::insert_into(workspace_table::table) + .values(workspace_table) + .execute(&*(self.database.db_connection()?))?; + Ok(()) + } + + pub fn read_workspace(&self, workspace_id: &str) -> Result { + let workspace = dsl::workspace_table + .filter(workspace_table::id.eq(&workspace_id)) + .first::(&*(self.database.db_connection()?))?; + + Ok(workspace) + } + + pub fn update_workspace( + &self, + changeset: WorkspaceTableChangeset, + ) -> Result<(), WorkspaceError> { + let conn = self.database.db_connection()?; + diesel_update_table!(workspace_table, changeset, conn); + Ok(()) + } + + pub fn delete_workspace(&self, workspace_id: &str) -> Result<(), WorkspaceError> { + unimplemented!() + } + + pub(crate) fn read_apps_belong_to_workspace( + &self, + workspace_id: &str, + ) -> Result, WorkspaceError> { + let conn = self.database.db_connection()?; + + let apps = conn.immediate_transaction::<_, WorkspaceError, _>(|| { + let workspace_table: WorkspaceTable = dsl::workspace_table + .filter(workspace_table::id.eq(workspace_id)) + .first::(&*(conn))?; + let apps = AppTable::belonging_to(&workspace_table).load::(&*conn)?; + Ok(apps) + })?; + + Ok(apps) + } +} diff --git a/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs b/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace_table.rs similarity index 91% rename from rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs rename to rust-lib/flowy-workspace/src/sql_tables/workspace/workspace_table.rs index 5fb3e20ec8..e8d8d69e4e 100644 --- a/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs +++ b/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace_table.rs @@ -1,4 +1,7 @@ -use crate::entities::workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, Workspace}; +use crate::entities::{ + app::RepeatedApp, + workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, Workspace}, +}; use flowy_database::schema::workspace_table; use flowy_infra::{timestamp, uuid}; @@ -63,6 +66,7 @@ impl std::convert::Into for WorkspaceTable { id: self.id, name: self.name, desc: self.desc, + apps: RepeatedApp::default(), } } } diff --git a/rust-lib/flowy-workspace/tests/event/app_test.rs b/rust-lib/flowy-workspace/tests/event/app_test.rs index 90b2574376..526ae6fa06 100644 --- a/rust-lib/flowy-workspace/tests/event/app_test.rs +++ b/rust-lib/flowy-workspace/tests/event/app_test.rs @@ -1,33 +1,64 @@ -use flowy_test::builder::WorkspaceTestBuilder; +use crate::helper::*; +use flowy_test::builder::SingleUserTestBuilder; use flowy_workspace::{ entities::{ - app::{App, CreateAppRequest}, - workspace::UserWorkspaceDetail, + app::{App, CreateAppRequest, QueryAppRequest}, + view::*, + workspace::Workspace, }, - event::WorkspaceEvent::{CreateApp, GetWorkspaceDetail}, + event::WorkspaceEvent::{CreateApp, GetCurWorkspace}, }; #[test] fn app_create_success() { - let user_workspace = WorkspaceTestBuilder::new() - .event(GetWorkspaceDetail) - .sync_send() - .parse::(); + let workspace = create_workspace("Workspace", ""); + let app = create_app("App A", "AppFlowy Github Project", &workspace.id); + dbg!(&app); +} - let request = CreateAppRequest { - workspace_id: user_workspace.workspace.id, - name: "Github".to_owned(), - desc: "AppFlowy Github Project".to_owned(), - color_style: Default::default(), +#[test] +fn app_create_and_then_get_success() { + let workspace = create_workspace("Workspace", ""); + let app = create_app("App A", "AppFlowy Github Project", &workspace.id); + let request = QueryAppRequest { + app_id: app.id.clone(), + read_views: false, + }; + let app_from_db = get_app(request); + assert_eq!(app_from_db, app); +} + +#[test] +fn app_create_with_view_and_then_get_success() { + let workspace = create_workspace("Workspace", ""); + let app = create_app("App A", "AppFlowy Github Project", &workspace.id); + let request_a = CreateViewRequest { + app_id: app.id.clone(), + name: "View A".to_string(), + desc: "".to_string(), + thumbnail: None, + view_type: ViewType::Doc, }; - let app_detail = WorkspaceTestBuilder::new() - .event(CreateApp) - .request(request) - .sync_send() - .parse::(); + let request_b = CreateViewRequest { + app_id: app.id.clone(), + name: "View B".to_string(), + desc: "".to_string(), + thumbnail: None, + view_type: ViewType::Doc, + }; - dbg!(&app_detail); + let view_a = create_view(request_a); + let view_b = create_view(request_b); + + let query = QueryAppRequest { + app_id: app.id.clone(), + read_views: true, + }; + let view_from_db = get_app(query); + + assert_eq!(view_from_db.views[0], view_a); + assert_eq!(view_from_db.views[1], view_b); } // TODO 1) test update app 2) delete app diff --git a/rust-lib/flowy-workspace/tests/event/helper.rs b/rust-lib/flowy-workspace/tests/event/helper.rs index 9631890bfa..a5aac63f44 100644 --- a/rust-lib/flowy-workspace/tests/event/helper.rs +++ b/rust-lib/flowy-workspace/tests/event/helper.rs @@ -1,4 +1,8 @@ -pub use flowy_test::builder::WorkspaceTestBuilder; +pub use flowy_test::builder::SingleUserTestBuilder; +use flowy_workspace::{ + entities::{app::*, view::*, workspace::*}, + event::WorkspaceEvent::*, +}; pub(crate) fn invalid_workspace_name_test_case() -> Vec { vec!["", "1234".repeat(100).as_str()] @@ -6,3 +10,64 @@ pub(crate) fn invalid_workspace_name_test_case() -> Vec { .map(|s| s.to_string()) .collect::>() } + +pub fn create_workspace(name: &str, desc: &str) -> Workspace { + let request = CreateWorkspaceRequest { + name: name.to_owned(), + desc: desc.to_owned(), + }; + + let workspace = SingleUserTestBuilder::new() + .event(CreateWorkspace) + .request(request) + .sync_send() + .parse::(); + + workspace +} + +pub fn create_app(name: &str, desc: &str, workspace_id: &str) -> App { + let create_app_request = CreateAppRequest { + workspace_id: workspace_id.to_string(), + name: name.to_string(), + desc: desc.to_string(), + color_style: Default::default(), + }; + + let app = SingleUserTestBuilder::new() + .event(CreateApp) + .request(create_app_request) + .sync_send() + .parse::(); + app +} + +pub fn get_workspace(request: QueryWorkspaceRequest) -> Workspace { + let workspace = SingleUserTestBuilder::new() + .event(GetWorkspace) + .request(request) + .sync_send() + .parse::(); + + workspace +} + +pub fn get_app(request: QueryAppRequest) -> App { + let app = SingleUserTestBuilder::new() + .event(GetApp) + .request(request) + .sync_send() + .parse::(); + + app +} + +pub fn create_view(request: CreateViewRequest) -> View { + let view = SingleUserTestBuilder::new() + .event(CreateView) + .request(request) + .sync_send() + .parse::(); + + view +} diff --git a/rust-lib/flowy-workspace/tests/event/main.rs b/rust-lib/flowy-workspace/tests/event/main.rs index bb71ee613f..38f399180d 100644 --- a/rust-lib/flowy-workspace/tests/event/main.rs +++ b/rust-lib/flowy-workspace/tests/event/main.rs @@ -1,3 +1,4 @@ mod app_test; mod helper; +mod view_test; mod workspace_test; diff --git a/rust-lib/flowy-workspace/tests/event/view_test.rs b/rust-lib/flowy-workspace/tests/event/view_test.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/rust-lib/flowy-workspace/tests/event/workspace_test.rs b/rust-lib/flowy-workspace/tests/event/workspace_test.rs index 8158ee9913..7c1bc0ab71 100644 --- a/rust-lib/flowy-workspace/tests/event/workspace_test.rs +++ b/rust-lib/flowy-workspace/tests/event/workspace_test.rs @@ -1,54 +1,54 @@ use crate::helper::*; use flowy_workspace::{ - entities::workspace::{CreateWorkspaceRequest, UserWorkspaceDetail, Workspace}, + entities::{ + app::{App, CreateAppRequest}, + workspace::{CreateWorkspaceRequest, QueryWorkspaceRequest, Workspace}, + }, event::WorkspaceEvent::*, prelude::*, }; +use serial_test::*; #[test] -fn workspace_create_success() { - let request = CreateWorkspaceRequest { - name: "123".to_owned(), - desc: "".to_owned(), - }; - - let response = WorkspaceTestBuilder::new() - .event(CreateWorkspace) - .request(request) - .sync_send() - .parse::(); - dbg!(&response); -} +fn workspace_create_success() { let _ = create_workspace("First workspace", ""); } #[test] -fn workspace_get_detail_success() { - let user_workspace = WorkspaceTestBuilder::new() - .event(GetWorkspaceDetail) - .sync_send() - .parse::(); - - dbg!(&user_workspace); -} - -#[test] -fn workspace_create_and_then_get_detail_success() { - let request = CreateWorkspaceRequest { - name: "Team A".to_owned(), - desc: "Team A Description".to_owned(), - }; - - let workspace = WorkspaceTestBuilder::new() - .event(CreateWorkspace) - .request(request) +fn workspace_get_success() { + let workspace = SingleUserTestBuilder::new() + .event(GetCurWorkspace) .sync_send() .parse::(); - let user_workspace = WorkspaceTestBuilder::new() - .event(GetWorkspaceDetail) - .sync_send() - .parse::(); + dbg!(&workspace); +} - assert_eq!(workspace.name, user_workspace.workspace.name); +#[test] +fn workspace_create_and_then_get_workspace_success() { + let workspace = create_workspace( + "Workspace A", + "workspace_create_and_then_get_workspace_success", + ); + let request = QueryWorkspaceRequest { + workspace_id: workspace.id.clone(), + read_apps: false, + }; + + let workspace_from_db = get_workspace(request); + assert_eq!(workspace.name, workspace_from_db.name); +} + +#[test] +fn workspace_create_with_apps_success() { + let workspace = create_workspace("Workspace B", ""); + let app = create_app("App A", "", &workspace.id); + + let query_workspace_request = QueryWorkspaceRequest { + workspace_id: workspace.id.clone(), + read_apps: true, + }; + + let workspace_from_db = get_workspace(query_workspace_request); + assert_eq!(&app, workspace_from_db.apps.first_or_crash()); } #[test] @@ -60,7 +60,7 @@ fn workspace_create_with_invalid_name_test() { }; assert_eq!( - WorkspaceTestBuilder::new() + SingleUserTestBuilder::new() .event(CreateWorkspace) .request(request) .sync_send() @@ -80,7 +80,7 @@ fn workspace_update_with_invalid_name_test() { }; assert_eq!( - WorkspaceTestBuilder::new() + SingleUserTestBuilder::new() .event(CreateWorkspace) .request(request) .sync_send() diff --git a/scripts/flowy-tool/src/dart_event/dart_event.rs b/scripts/flowy-tool/src/dart_event/dart_event.rs index 64ea6509bb..855ee83525 100644 --- a/scripts/flowy-tool/src/dart_event/dart_event.rs +++ b/scripts/flowy-tool/src/dart_event/dart_event.rs @@ -79,8 +79,12 @@ pub fn parse_event_crate(event_crate: &DartEventCrate) -> Vec { .map(|item| match item { Item::Enum(item_enum) => { let ctxt = Ctxt::new(); - let attrs = - flowy_ast::enum_from_ast(&ctxt, &item_enum.variants, &item_enum.attrs); + let attrs = flowy_ast::enum_from_ast( + &ctxt, + &item_enum.ident, + &item_enum.variants, + &item_enum.attrs, + ); ctxt.check().unwrap(); attrs .iter() @@ -110,6 +114,10 @@ pub fn ast_to_event_render_ctx(ast: &Vec) -> Vec Some(event_output.get_ident().unwrap().to_string()), None => None, }; + // eprintln!( + // "😁 {:?} / {:?}", + // event_ast.event_input, event_ast.event_output + // ); return EventRenderContext { input_deserializer, diff --git a/scripts/flowy-tool/src/dart_event/event_template.rs b/scripts/flowy-tool/src/dart_event/event_template.rs index 3ba4baefe3..6099fc59f9 100644 --- a/scripts/flowy-tool/src/dart_event/event_template.rs +++ b/scripts/flowy-tool/src/dart_event/event_template.rs @@ -44,8 +44,14 @@ impl EventTemplate { Some(ref input) => self.tera_context.insert("input_deserializer", input), } - self.tera_context - .insert("has_output", &ctx.output_deserializer.is_some()); + // eprintln!( + // "😁 {:?} / {:?}", + // &ctx.input_deserializer, &ctx.output_deserializer + // ); + + let has_output = ctx.output_deserializer.is_some(); + self.tera_context.insert("has_output", &has_output); + match ctx.output_deserializer { None => self.tera_context.insert("output_deserializer", "Unit"), Some(ref output) => self.tera_context.insert("output_deserializer", output), diff --git a/scripts/flowy-tool/src/dart_event/event_template.tera b/scripts/flowy-tool/src/dart_event/event_template.tera index 9f155c8790..aac3012fb6 100644 --- a/scripts/flowy-tool/src/dart_event/event_template.tera +++ b/scripts/flowy-tool/src/dart_event/event_template.tera @@ -19,8 +19,13 @@ class {{ event_class }} { return Dispatch.asyncRequest(request) .then((bytesResult) => bytesResult.fold( - (okBytes) => left({{ output_deserializer }}.fromBuffer(okBytes)), - (errBytes) => right({{ error_deserializer }}.fromBuffer(errBytes)), + + {%- if has_output %} + (okBytes) => left({{ output_deserializer }}.fromBuffer(okBytes)), + {%- else %} + (bytes) => left(unit), + {%- endif %} + (errBytes) => right({{ error_deserializer }}.fromBuffer(errBytes)), )); {%- else %} diff --git a/scripts/flowy-tool/src/proto/ast.rs b/scripts/flowy-tool/src/proto/ast.rs index ab4722897f..e6b096c5d3 100644 --- a/scripts/flowy-tool/src/proto/ast.rs +++ b/scripts/flowy-tool/src/proto/ast.rs @@ -130,14 +130,20 @@ pub fn get_ast_structs(ast: &syn::File) -> Vec { pub fn get_ast_enums(ast: &syn::File) -> Vec { let mut flowy_enums: Vec = vec![]; let ctxt = Ctxt::new(); - let enum_attrs = &ast.attrs; + ast.items.iter().for_each(|item| { // https://docs.rs/syn/1.0.54/syn/enum.Item.html match item { Item::Enum(item_enum) => { + let attrs = flowy_ast::enum_from_ast( + &ctxt, + &item_enum.ident, + &item_enum.variants, + &ast.attrs, + ); flowy_enums.push(FlowyEnum { name: item_enum.ident.to_string(), - attrs: flowy_ast::enum_from_ast(&ctxt, &item_enum.variants, enum_attrs), + attrs, }); } _ => {} diff --git a/scripts/flowy-tool/src/proto/template/proto_file/enum_template.rs b/scripts/flowy-tool/src/proto/template/proto_file/enum_template.rs index ac039b8ca2..07eefb84f7 100644 --- a/scripts/flowy-tool/src/proto/template/proto_file/enum_template.rs +++ b/scripts/flowy-tool/src/proto/template/proto_file/enum_template.rs @@ -19,8 +19,10 @@ impl EnumTemplate { pub fn set_message_enum(&mut self, flowy_enum: &FlowyEnum) { self.context.insert("enum_name", &flowy_enum.name); flowy_enum.attrs.iter().for_each(|item| { - self.items - .push(format!("{} = {};", item.attrs.name, item.attrs.value)) + self.items.push(format!( + "{} = {};", + item.attrs.enum_item_name, item.attrs.value + )) }) } diff --git a/scripts/flowy-tool/src/proto/template/proto_file/struct_template.rs b/scripts/flowy-tool/src/proto/template/proto_file/struct_template.rs index 9037ff0b38..1d06a16a51 100644 --- a/scripts/flowy-tool/src/proto/template/proto_file/struct_template.rs +++ b/scripts/flowy-tool/src/proto/template/proto_file/struct_template.rs @@ -1,6 +1,7 @@ use crate::util::get_tera; use flowy_ast::*; use phf::phf_map; +use syn::__private::quote::__private::Ident; use tera::Context; // Protobuf data type : https://developers.google.com/protocol-buffers/docs/proto3 @@ -47,10 +48,24 @@ impl StructTemplate { match field.bracket_category { Some(ref category) => match category { - BracketCategory::Opt => self.fields.push(format!( - "oneof one_of_{} {{ {} {} = {}; }};", - name, mapped_ty, name, index - )), + BracketCategory::Opt => match &field.bracket_inner_ty { + None => {} + Some(inner_ty) => match inner_ty.to_string().as_str() { + //TODO: support hashmap or something else wrapped by Option + "Vec" => { + self.fields.push(format!( + "oneof one_of_{} {{ bytes {} = {}; }};", + name, name, index + )); + } + _ => { + self.fields.push(format!( + "oneof one_of_{} {{ {} {} = {}; }};", + name, mapped_ty, name, index + )); + } + }, + }, BracketCategory::Map((k, v)) => { let key: &str = k; let value: &str = v; @@ -65,6 +80,7 @@ impl StructTemplate { } BracketCategory::Vec => { let bracket_ty: &str = &field.bracket_ty.as_ref().unwrap().to_string(); + // Vec if mapped_ty == "u8" && bracket_ty == "Vec" { self.fields.push(format!("bytes {} = {};", name, index)) } else { diff --git a/scripts/makefile/desktop.toml b/scripts/makefile/desktop.toml index 47210ddb8f..5c9aea45e9 100644 --- a/scripts/makefile/desktop.toml +++ b/scripts/makefile/desktop.toml @@ -34,7 +34,7 @@ condition = { platforms = ["mac"] } dependencies = ["restore-crate-type"] script = [ """ - echo ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY} + echo "🚀 🚀 🚀 Flowy-SDK build success" cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/x86_64-apple-darwin/${LIB_OUT_DIR}/lib${CARGO_MAKE_CRATE_FS_NAME}.dylib \ ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/packages/flowy_sdk/macos/lib${CARGO_MAKE_CRATE_FS_NAME}.dylib """, @@ -63,9 +63,8 @@ condition = { platforms = ["mac"] } script = [ """ target_path = set ${TMPDIR}/appflowy_client/lib${CARGO_MAKE_CRATE_FS_NAME}.dylib - echo "remove old dylib" rm ${target_path} - echo "copy new dylib to system" +# echo "🚀 🚀 🚀 Copy Flowy-SDK to system" cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/x86_64-apple-darwin/${LIB_OUT_DIR}/lib${CARGO_MAKE_CRATE_FS_NAME}.dylib ${target_path} """, ]