From 90e7873135fa9554b41b1700cde92b0effa3902c Mon Sep 17 00:00:00 2001 From: appflowy Date: Fri, 25 Mar 2022 15:02:43 +0800 Subject: [PATCH] chore: create field --- .../app_flowy/lib/startup/deps_resolver.dart | 222 ++++++++ .../lib/startup/home_deps_resolver.dart | 169 ------ frontend/app_flowy/lib/startup/startup.dart | 6 +- .../lib/startup/user_deps_resolver.dart | 29 -- .../lib/user/application/prelude.dart | 4 + .../lib/user/application/sign_in_bloc.dart | 4 +- .../lib/user/application/sign_up_bloc.dart | 12 +- .../app_flowy/lib/user/domain/auth_state.dart | 2 +- .../grid/cell_bloc/checkbox_cell_bloc.dart | 4 +- .../grid/cell_bloc/date_cell_bloc.dart | 4 +- .../grid/cell_bloc/number_cell_bloc.dart | 4 +- .../grid/cell_bloc/selection_cell_bloc.dart | 4 +- .../grid/cell_bloc/text_cell_bloc.dart | 4 +- .../grid/field/create_field_bloc.dart | 9 +- .../grid/field/edit_field_bloc.dart | 9 +- .../application/grid/field/field_service.dart | 21 +- .../grid/field/switch_field_type_bloc.dart | 61 +++ .../grid/field/type_option/date_bloc.dart | 39 ++ .../grid/field/type_option/number_bloc.dart | 39 ++ .../field/type_option/selection_bloc.dart | 39 ++ .../workspace/application/grid/grid_bloc.dart | 4 +- .../workspace/application/grid/prelude.dart | 10 + .../application/grid/row/row_bloc.dart | 2 +- .../src/widgets/content/cell_builder.dart | 2 +- .../widgets/header/create_field_pannel.dart | 24 +- .../grid/src/widgets/header/field_editor.dart | 12 +- .../src/widgets/header/field_name_input.dart | 2 +- .../widgets/header/field_tyep_switcher.dart | 199 +++++++- .../src/widgets/header/field_type_list.dart | 6 +- .../src/flowy_overlay/overlay_container.dart | 2 +- .../dart_event/flowy-grid/dart_event.dart | 12 +- .../flowy-grid-data-model/grid.pb.dart | 138 +++++ .../flowy-grid-data-model/grid.pbjson.dart | 23 + .../protobuf/flowy-grid/event_map.pbenum.dart | 4 +- .../protobuf/flowy-grid/event_map.pbjson.dart | 4 +- .../rust-lib/flowy-grid/src/event_handler.rs | 28 +- frontend/rust-lib/flowy-grid/src/event_map.rs | 6 +- .../src/protobuf/model/event_map.rs | 14 +- .../src/protobuf/proto/event_map.proto | 2 +- .../flowy-grid/src/services/grid_editor.rs | 5 +- .../src/entities/grid.rs | 21 + .../src/protobuf/model/grid.rs | 483 +++++++++++++++++- .../src/protobuf/proto/grid.proto | 9 + 43 files changed, 1371 insertions(+), 326 deletions(-) create mode 100644 frontend/app_flowy/lib/startup/deps_resolver.dart delete mode 100644 frontend/app_flowy/lib/startup/home_deps_resolver.dart delete mode 100644 frontend/app_flowy/lib/startup/user_deps_resolver.dart create mode 100644 frontend/app_flowy/lib/user/application/prelude.dart create mode 100644 frontend/app_flowy/lib/workspace/application/grid/field/switch_field_type_bloc.dart create mode 100644 frontend/app_flowy/lib/workspace/application/grid/field/type_option/date_bloc.dart create mode 100644 frontend/app_flowy/lib/workspace/application/grid/field/type_option/number_bloc.dart create mode 100644 frontend/app_flowy/lib/workspace/application/grid/field/type_option/selection_bloc.dart diff --git a/frontend/app_flowy/lib/startup/deps_resolver.dart b/frontend/app_flowy/lib/startup/deps_resolver.dart new file mode 100644 index 0000000000..56f115a22b --- /dev/null +++ b/frontend/app_flowy/lib/startup/deps_resolver.dart @@ -0,0 +1,222 @@ +import 'package:app_flowy/core/network_monitor.dart'; +import 'package:app_flowy/user/application/user_listener.dart'; +import 'package:app_flowy/user/application/user_service.dart'; +import 'package:app_flowy/workspace/application/app/prelude.dart'; +import 'package:app_flowy/workspace/application/doc/prelude.dart'; +import 'package:app_flowy/workspace/application/grid/prelude.dart'; +import 'package:app_flowy/workspace/application/grid/row/row_listener.dart'; +import 'package:app_flowy/workspace/application/trash/prelude.dart'; +import 'package:app_flowy/workspace/application/workspace/prelude.dart'; +import 'package:app_flowy/workspace/application/edit_pannel/edit_pannel_bloc.dart'; +import 'package:app_flowy/workspace/application/home/home_bloc.dart'; +import 'package:app_flowy/workspace/application/view/prelude.dart'; +import 'package:app_flowy/workspace/application/home/prelude.dart'; +import 'package:app_flowy/workspace/application/menu/prelude.dart'; +import 'package:app_flowy/user/application/prelude.dart'; +import 'package:app_flowy/user/presentation/router.dart'; +import 'package:app_flowy/workspace/presentation/home/home_stack.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; +import 'package:get_it/get_it.dart'; + +class DependencyResolver { + static Future resolve(GetIt getIt) async { + _resolveUserDeps(getIt); + + _resolveHomeDeps(getIt); + + _resolveFolderDeps(getIt); + + _resolveDocDeps(getIt); + + _resolveGridDeps(getIt); + } +} + +void _resolveUserDeps(GetIt getIt) { + getIt.registerFactory(() => AuthService()); + getIt.registerFactory(() => AuthRouter()); + + getIt.registerFactory(() => SignInBloc(getIt())); + getIt.registerFactory(() => SignUpBloc(getIt())); + + getIt.registerFactory(() => SplashRoute()); + getIt.registerFactory(() => HomeBloc()); + getIt.registerFactory(() => EditPannelBloc()); + getIt.registerFactory(() => SplashBloc()); + getIt.registerLazySingleton(() => NetworkListener()); +} + +void _resolveHomeDeps(GetIt getIt) { + getIt.registerFactoryParam( + (user, _) => UserListener(user: user), + ); + + getIt.registerFactoryParam( + (user, _) => HomeListenBloc(getIt(param1: user)), + ); + + // + getIt.registerLazySingleton(() => HomeStackManager()); + + getIt.registerFactoryParam( + (user, _) => WelcomeBloc( + userService: UserService(), + userListener: getIt(param1: user), + ), + ); + + // share + getIt.registerLazySingleton(() => ShareService()); + getIt.registerFactoryParam( + (view, _) => DocShareBloc(view: view, service: getIt())); +} + +void _resolveFolderDeps(GetIt getIt) { + //workspace + getIt.registerFactoryParam((user, workspaceId) => + WorkspaceListener(service: WorkspaceListenerService(user: user, workspaceId: workspaceId))); + + // View + getIt.registerFactoryParam( + (view, _) => ViewListener(view: view), + ); + + getIt.registerFactoryParam( + (view, _) => ViewBloc( + view: view, + service: ViewService(), + listener: getIt(param1: view), + ), + ); + + //Menu + getIt.registerFactoryParam( + (user, workspaceId) => MenuBloc( + workspaceId: workspaceId, + service: WorkspaceService(), + listener: getIt(param1: user, param2: workspaceId), + ), + ); + + getIt.registerFactoryParam( + (user, _) => MenuUserBloc( + user, + UserService(), + getIt(param1: user), + ), + ); + + // App + getIt.registerFactoryParam( + (app, _) => AppBloc( + app: app, + service: AppService(), + listener: AppListener(appId: app.id), + ), + ); + + // trash + getIt.registerLazySingleton(() => TrashService()); + getIt.registerLazySingleton(() => TrashListener()); + getIt.registerFactory( + () => TrashBloc( + service: getIt(), + listener: getIt(), + ), + ); +} + +void _resolveDocDeps(GetIt getIt) { +// Doc + getIt.registerFactoryParam( + (view, _) => DocumentBloc( + view: view, + service: DocumentService(), + listener: getIt(param1: view), + trashService: getIt(), + ), + ); +} + +void _resolveGridDeps(GetIt getIt) { + // Grid + getIt.registerFactoryParam( + (view, _) => GridBloc(view: view, service: GridService()), + ); + + getIt.registerFactoryParam( + (data, _) => RowBloc( + rowService: RowService(data), + listener: RowListener(rowId: data.rowId), + ), + ); + + getIt.registerFactoryParam>( + (gridId, fields) => GridHeaderBloc( + data: GridHeaderData(gridId: gridId, fields: fields), + service: FieldService(gridId: gridId), + ), + ); + + getIt.registerFactoryParam( + (data, _) => EditFieldBloc( + field: data.field, + service: FieldService(gridId: data.gridId), + ), + ); + + getIt.registerFactoryParam( + (gridId, _) => CreateFieldBloc( + service: FieldService(gridId: gridId), + ), + ); + + getIt.registerFactoryParam( + (context, _) => TextCellBloc( + service: CellService(context), + ), + ); + + getIt.registerFactoryParam( + (context, _) => SelectionCellBloc( + service: CellService(context), + ), + ); + + getIt.registerFactoryParam( + (context, _) => NumberCellBloc( + service: CellService(context), + ), + ); + + getIt.registerFactoryParam( + (context, _) => DateCellBloc( + service: CellService(context), + ), + ); + + getIt.registerFactoryParam( + (context, _) => CheckboxCellBloc( + service: CellService(context), + ), + ); + + getIt.registerFactoryParam( + (editContext, _) => SwitchFieldTypeBloc(editContext), + ); + + getIt.registerFactory( + () => SelectionTypeOptionBloc(), + ); + + getIt.registerFactory( + () => DateTypeOptionBloc(), + ); + + getIt.registerFactory( + () => NumberTypeOptionBloc(), + ); +} diff --git a/frontend/app_flowy/lib/startup/home_deps_resolver.dart b/frontend/app_flowy/lib/startup/home_deps_resolver.dart deleted file mode 100644 index 1702544a64..0000000000 --- a/frontend/app_flowy/lib/startup/home_deps_resolver.dart +++ /dev/null @@ -1,169 +0,0 @@ -import 'package:app_flowy/user/application/user_listener.dart'; -import 'package:app_flowy/user/application/user_service.dart'; -import 'package:app_flowy/workspace/application/app/prelude.dart'; -import 'package:app_flowy/workspace/application/doc/prelude.dart'; -import 'package:app_flowy/workspace/application/grid/prelude.dart'; -import 'package:app_flowy/workspace/application/grid/row/row_listener.dart'; -import 'package:app_flowy/workspace/application/trash/prelude.dart'; -import 'package:app_flowy/workspace/application/workspace/prelude.dart'; -import 'package:app_flowy/workspace/application/view/prelude.dart'; -import 'package:app_flowy/workspace/application/home/prelude.dart'; -import 'package:app_flowy/workspace/application/menu/prelude.dart'; - -import 'package:app_flowy/workspace/presentation/home/home_stack.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; -import 'package:get_it/get_it.dart'; - -class HomeDepsResolver { - static Future resolve(GetIt getIt) async { - getIt.registerFactoryParam( - (user, _) => UserListener(user: user), - ); - - getIt.registerFactoryParam( - (user, _) => HomeListenBloc(getIt(param1: user)), - ); - - // - getIt.registerLazySingleton(() => HomeStackManager()); - getIt.registerFactoryParam( - (user, _) => WelcomeBloc( - userService: UserService(), - userListener: getIt(param1: user), - ), - ); - - //workspace - getIt.registerFactoryParam((user, workspaceId) => - WorkspaceListener(service: WorkspaceListenerService(user: user, workspaceId: workspaceId))); - - // View - getIt.registerFactoryParam( - (view, _) => ViewListener(view: view), - ); - - getIt.registerFactoryParam( - (view, _) => ViewBloc( - view: view, - service: ViewService(), - listener: getIt(param1: view), - ), - ); - - //Menu Bloc - getIt.registerFactoryParam( - (user, workspaceId) => MenuBloc( - workspaceId: workspaceId, - service: WorkspaceService(), - listener: getIt(param1: user, param2: workspaceId), - ), - ); - - getIt.registerFactoryParam( - (user, _) => MenuUserBloc( - user, - UserService(), - getIt(param1: user), - ), - ); - - // App - getIt.registerFactoryParam( - (app, _) => AppBloc( - app: app, - service: AppService(), - listener: AppListener(appId: app.id), - ), - ); - - // Doc - getIt.registerFactoryParam( - (view, _) => DocumentBloc( - view: view, - service: DocumentService(), - listener: getIt(param1: view), - trashService: getIt(), - ), - ); - - // Grid - getIt.registerFactoryParam( - (view, _) => GridBloc(view: view, service: GridService()), - ); - - getIt.registerFactoryParam( - (data, _) => RowBloc( - rowService: RowService(data), - listener: RowListener(rowId: data.rowId), - ), - ); - - getIt.registerFactoryParam>( - (gridId, fields) => GridHeaderBloc( - data: GridHeaderData(gridId: gridId, fields: fields), - service: FieldService(gridId: gridId), - ), - ); - - getIt.registerFactoryParam( - (data, _) => EditFieldBloc( - field: data.field, - service: FieldService(gridId: data.gridId), - ), - ); - - getIt.registerFactoryParam( - (gridId, _) => CreateFieldBloc( - service: FieldService(gridId: gridId), - ), - ); - - getIt.registerFactoryParam( - (context, _) => TextCellBloc( - service: CellService(context), - ), - ); - - getIt.registerFactoryParam( - (context, _) => SelectionCellBloc( - service: CellService(context), - ), - ); - - getIt.registerFactoryParam( - (context, _) => NumberCellBloc( - service: CellService(context), - ), - ); - - getIt.registerFactoryParam( - (context, _) => DateCellBloc( - service: CellService(context), - ), - ); - - getIt.registerFactoryParam( - (context, _) => CheckboxCellBloc( - service: CellService(context), - ), - ); - - // trash - getIt.registerLazySingleton(() => TrashService()); - getIt.registerLazySingleton(() => TrashListener()); - getIt.registerFactory( - () => TrashBloc( - service: getIt(), - listener: getIt(), - ), - ); - - // share - getIt.registerLazySingleton(() => ShareService()); - getIt.registerFactoryParam( - (view, _) => DocShareBloc(view: view, service: getIt())); - } -} diff --git a/frontend/app_flowy/lib/startup/startup.dart b/frontend/app_flowy/lib/startup/startup.dart index 0335879f5a..38243afa56 100644 --- a/frontend/app_flowy/lib/startup/startup.dart +++ b/frontend/app_flowy/lib/startup/startup.dart @@ -2,8 +2,7 @@ import 'dart:io'; import 'package:app_flowy/plugin/plugin.dart'; import 'package:app_flowy/startup/tasks/prelude.dart'; -import 'package:app_flowy/startup/home_deps_resolver.dart'; -import 'package:app_flowy/startup/user_deps_resolver.dart'; +import 'package:app_flowy/startup/deps_resolver.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; @@ -62,8 +61,7 @@ Future initGetIt( getIt.registerLazySingleton(() => AppLauncher(env, getIt)); getIt.registerSingleton(PluginSandbox()); - await UserDepsResolver.resolve(getIt); - await HomeDepsResolver.resolve(getIt); + await DependencyResolver.resolve(getIt); } class LaunchContext { diff --git a/frontend/app_flowy/lib/startup/user_deps_resolver.dart b/frontend/app_flowy/lib/startup/user_deps_resolver.dart deleted file mode 100644 index daf67a071a..0000000000 --- a/frontend/app_flowy/lib/startup/user_deps_resolver.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:app_flowy/user/application/auth_service.dart'; -import 'package:app_flowy/user/application/sign_in_bloc.dart'; -import 'package:app_flowy/user/application/sign_up_bloc.dart'; -import 'package:app_flowy/user/application/splash_bloc.dart'; -import 'package:app_flowy/user/presentation/router.dart'; -import 'package:app_flowy/workspace/application/edit_pannel/edit_pannel_bloc.dart'; -import 'package:app_flowy/workspace/application/home/home_bloc.dart'; -import 'package:get_it/get_it.dart'; - -import '../core/network_monitor.dart'; - -class UserDepsResolver { - static Future resolve(GetIt getIt) async { - getIt.registerFactory(() => AuthService()); - - //Interface implementation - getIt.registerFactory(() => AuthRouter()); - - //Bloc - getIt.registerFactory(() => SignInBloc(getIt())); - getIt.registerFactory(() => SignUpBloc(getIt())); - - getIt.registerFactory(() => SplashRoute()); - getIt.registerFactory(() => HomeBloc()); - getIt.registerFactory(() => EditPannelBloc()); - getIt.registerFactory(() => SplashBloc()); - getIt.registerLazySingleton(() => NetworkListener()); - } -} diff --git a/frontend/app_flowy/lib/user/application/prelude.dart b/frontend/app_flowy/lib/user/application/prelude.dart new file mode 100644 index 0000000000..74b644808e --- /dev/null +++ b/frontend/app_flowy/lib/user/application/prelude.dart @@ -0,0 +1,4 @@ +export './auth_service.dart'; +export './sign_in_bloc.dart'; +export './sign_up_bloc.dart'; +export './splash_bloc.dart'; diff --git a/frontend/app_flowy/lib/user/application/sign_in_bloc.dart b/frontend/app_flowy/lib/user/application/sign_in_bloc.dart index 25aa66cc50..e0f5bed605 100644 --- a/frontend/app_flowy/lib/user/application/sign_in_bloc.dart +++ b/frontend/app_flowy/lib/user/application/sign_in_bloc.dart @@ -54,14 +54,14 @@ class SignInBloc extends Bloc { } @freezed -abstract class SignInEvent with _$SignInEvent { +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 { +class SignInState with _$SignInState { const factory SignInState({ String? email, String? password, diff --git a/frontend/app_flowy/lib/user/application/sign_up_bloc.dart b/frontend/app_flowy/lib/user/application/sign_up_bloc.dart index 11acd1d385..2efc82d3c7 100644 --- a/frontend/app_flowy/lib/user/application/sign_up_bloc.dart +++ b/frontend/app_flowy/lib/user/application/sign_up_bloc.dart @@ -15,11 +15,11 @@ class SignUpBloc extends Bloc { on((event, emit) async { await event.map(signUpWithUserEmailAndPassword: (e) async { await _performActionOnSignUp(emit); - }, emailChanged: (EmailChanged value) async { + }, emailChanged: (_EmailChanged value) async { emit(state.copyWith(email: value.email, emailError: none(), successOrFail: none())); - }, passwordChanged: (PasswordChanged value) async { + }, passwordChanged: (_PasswordChanged value) async { emit(state.copyWith(password: value.password, passwordError: none(), successOrFail: none())); - }, repeatPasswordChanged: (RepeatPasswordChanged value) async { + }, repeatPasswordChanged: (_RepeatPasswordChanged value) async { emit(state.copyWith(repeatedPassword: value.password, repeatPasswordError: none(), successOrFail: none())); }); }); @@ -104,9 +104,9 @@ class SignUpBloc extends Bloc { @freezed class SignUpEvent with _$SignUpEvent { const factory SignUpEvent.signUpWithUserEmailAndPassword() = SignUpWithUserEmailAndPassword; - const factory SignUpEvent.emailChanged(String email) = EmailChanged; - const factory SignUpEvent.passwordChanged(String password) = PasswordChanged; - const factory SignUpEvent.repeatPasswordChanged(String password) = RepeatPasswordChanged; + const factory SignUpEvent.emailChanged(String email) = _EmailChanged; + const factory SignUpEvent.passwordChanged(String password) = _PasswordChanged; + const factory SignUpEvent.repeatPasswordChanged(String password) = _RepeatPasswordChanged; } @freezed diff --git a/frontend/app_flowy/lib/user/domain/auth_state.dart b/frontend/app_flowy/lib/user/domain/auth_state.dart index b70383c0aa..96f2036e01 100644 --- a/frontend/app_flowy/lib/user/domain/auth_state.dart +++ b/frontend/app_flowy/lib/user/domain/auth_state.dart @@ -4,7 +4,7 @@ import 'package:freezed_annotation/freezed_annotation.dart'; part 'auth_state.freezed.dart'; @freezed -abstract class AuthState with _$AuthState { +class AuthState with _$AuthState { const factory AuthState.authenticated(UserProfile userProfile) = Authenticated; const factory AuthState.unauthenticated(FlowyError error) = Unauthenticated; const factory AuthState.initial() = _Initial; diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/checkbox_cell_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/checkbox_cell_bloc.dart index ab844448dc..2199d59562 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/checkbox_cell_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/checkbox_cell_bloc.dart @@ -28,12 +28,12 @@ class CheckboxCellBloc extends Bloc { } @freezed -abstract class CheckboxCellEvent with _$CheckboxCellEvent { +class CheckboxCellEvent with _$CheckboxCellEvent { const factory CheckboxCellEvent.initial() = _InitialCell; } @freezed -abstract class CheckboxCellState with _$CheckboxCellState { +class CheckboxCellState with _$CheckboxCellState { const factory CheckboxCellState({ required Cell? cell, }) = _CheckboxCellState; diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/date_cell_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/date_cell_bloc.dart index dcb0461165..071757fdeb 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/date_cell_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/date_cell_bloc.dart @@ -28,12 +28,12 @@ class DateCellBloc extends Bloc { } @freezed -abstract class DateCellEvent with _$DateCellEvent { +class DateCellEvent with _$DateCellEvent { const factory DateCellEvent.initial() = _InitialCell; } @freezed -abstract class DateCellState with _$DateCellState { +class DateCellState with _$DateCellState { const factory DateCellState({ required Cell? cell, }) = _DateCellState; diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/number_cell_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/number_cell_bloc.dart index caa91fa408..e368c32c35 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/number_cell_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/number_cell_bloc.dart @@ -28,12 +28,12 @@ class NumberCellBloc extends Bloc { } @freezed -abstract class NumberCellEvent with _$NumberCellEvent { +class NumberCellEvent with _$NumberCellEvent { const factory NumberCellEvent.initial() = _InitialCell; } @freezed -abstract class NumberCellState with _$NumberCellState { +class NumberCellState with _$NumberCellState { const factory NumberCellState({ required Cell? cell, }) = _NumberCellState; diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/selection_cell_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/selection_cell_bloc.dart index 7f21a84fff..1a94d4ce69 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/selection_cell_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/selection_cell_bloc.dart @@ -28,12 +28,12 @@ class SelectionCellBloc extends Bloc { } @freezed -abstract class SelectionCellEvent with _$SelectionCellEvent { +class SelectionCellEvent with _$SelectionCellEvent { const factory SelectionCellEvent.initial() = _InitialCell; } @freezed -abstract class SelectionCellState with _$SelectionCellState { +class SelectionCellState with _$SelectionCellState { const factory SelectionCellState({ required Cell? cell, }) = _SelectionCellState; diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/text_cell_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/text_cell_bloc.dart index 407cde3d2c..d999ea774d 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/text_cell_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/text_cell_bloc.dart @@ -31,13 +31,13 @@ class TextCellBloc extends Bloc { } @freezed -abstract class TextCellEvent with _$TextCellEvent { +class TextCellEvent with _$TextCellEvent { const factory TextCellEvent.initial() = _InitialCell; const factory TextCellEvent.updateText(String text) = _UpdateText; } @freezed -abstract class TextCellState with _$TextCellState { +class TextCellState with _$TextCellState { const factory TextCellState({ required String content, }) = _TextCellState; diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/create_field_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/create_field_bloc.dart index 9f70646415..aa0d47e5d6 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/create_field_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/create_field_bloc.dart @@ -1,5 +1,6 @@ import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid-data-model/meta.pb.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'dart:async'; @@ -16,9 +17,9 @@ class CreateFieldBloc extends Bloc { (event, emit) async { await event.map( initial: (_InitialField value) async { - final result = await service.getDefaultField(); + final result = await service.getEditFieldContext(FieldType.RichText); result.fold( - (field) => emit(state.copyWith(field: Some(field))), + (editContext) => emit(state.copyWith(editContext: Some(editContext))), (err) => Log.error(err), ); }, @@ -46,11 +47,11 @@ class CreateFieldEvent with _$CreateFieldEvent { class CreateFieldState with _$CreateFieldState { const factory CreateFieldState({ required String errorText, - required Option field, + required Option editContext, }) = _CreateFieldState; factory CreateFieldState.initial() => CreateFieldState( - field: none(), + editContext: none(), errorText: '', ); } diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/edit_field_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/edit_field_bloc.dart index 0944bdd1bb..75a0a7c9bc 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/edit_field_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/edit_field_bloc.dart @@ -9,7 +9,8 @@ part 'edit_field_bloc.freezed.dart'; class EditFieldBloc extends Bloc { final FieldService service; - EditFieldBloc({required Field field, required this.service}) : super(EditFieldState.initial(field)) { + EditFieldBloc({required Field field, required this.service}) + : super(EditFieldState.initial(EditFieldContext.create()..gridField = field)) { on( (event, emit) async { await event.map( @@ -43,12 +44,12 @@ class EditFieldEvent with _$EditFieldEvent { @freezed class EditFieldState with _$EditFieldState { const factory EditFieldState({ - required Field field, + required EditFieldContext editContext, required String errorText, }) = _EditFieldState; - factory EditFieldState.initial(Field field) => EditFieldState( - field: field, + factory EditFieldState.initial(EditFieldContext editContext) => EditFieldState( + editContext: editContext, errorText: '', ); } diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart b/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart index f63d8d5d5f..e3dfdf3ce9 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart @@ -5,6 +5,7 @@ import 'package:equatable/equatable.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid-data-model/meta.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/protobuf.dart'; class FieldService { @@ -12,9 +13,12 @@ class FieldService { FieldService({required this.gridId}); - Future> getDefaultField() { - final payload = GridId.create()..value = gridId; - return GridEventCreateDefaultField(payload).send(); + Future> getEditFieldContext(FieldType fieldType) { + final payload = CreateEditFieldContextParams.create() + ..gridId = gridId + ..fieldType = fieldType; + + return GridEventCreateEditFieldContext(payload).send(); } Future> createTextField( @@ -24,7 +28,7 @@ class FieldService { String? startFieldId, ) { final typeOptionData = typeOption.writeToBuffer(); - return createField(gridId, field, typeOptionData, startFieldId); + return createField(field, typeOptionData, startFieldId); } Future> createSingleSelectField( @@ -34,7 +38,7 @@ class FieldService { String? startFieldId, ) { final typeOptionData = typeOption.writeToBuffer(); - return createField(gridId, field, typeOptionData, startFieldId); + return createField(field, typeOptionData, startFieldId); } Future> createMultiSelectField( @@ -44,7 +48,7 @@ class FieldService { String? startFieldId, ) { final typeOptionData = typeOption.writeToBuffer(); - return createField(gridId, field, typeOptionData, startFieldId); + return createField(field, typeOptionData, startFieldId); } Future> createNumberField( @@ -54,7 +58,7 @@ class FieldService { String? startFieldId, ) { final typeOptionData = typeOption.writeToBuffer(); - return createField(gridId, field, typeOptionData, startFieldId); + return createField(field, typeOptionData, startFieldId); } Future> createDateField( @@ -64,11 +68,10 @@ class FieldService { String? startFieldId, ) { final typeOptionData = typeOption.writeToBuffer(); - return createField(gridId, field, typeOptionData, startFieldId); + return createField(field, typeOptionData, startFieldId); } Future> createField( - String gridId, Field field, Uint8List? typeOptionData, String? startFieldId, diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/switch_field_type_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/switch_field_type_bloc.dart new file mode 100644 index 0000000000..a6042c52e3 --- /dev/null +++ b/frontend/app_flowy/lib/workspace/application/grid/field/switch_field_type_bloc.dart @@ -0,0 +1,61 @@ +import 'dart:typed_data'; +import 'package:flowy_sdk/log.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid-data-model/meta.pb.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'dart:async'; +import 'field_service.dart'; + +part 'switch_field_type_bloc.freezed.dart'; + +class SwitchFieldTypeBloc extends Bloc { + SwitchFieldTypeBloc(EditFieldContext editContext) : super(SwitchFieldTypeState.initial(editContext)) { + on( + (event, emit) async { + await event.map( + toFieldType: (_ToFieldType value) async { + final fieldService = FieldService(gridId: state.gridId); + final result = await fieldService.getEditFieldContext(value.fieldType); + result.fold( + (newEditContext) { + emit( + state.copyWith( + field: newEditContext.gridField, + typeOptionData: Uint8List.fromList(newEditContext.typeOptionData), + ), + ); + }, + (err) => Log.error(err), + ); + }, + ); + }, + ); + } + + @override + Future close() async { + return super.close(); + } +} + +@freezed +class SwitchFieldTypeEvent with _$SwitchFieldTypeEvent { + const factory SwitchFieldTypeEvent.toFieldType(FieldType fieldType) = _ToFieldType; +} + +@freezed +class SwitchFieldTypeState with _$SwitchFieldTypeState { + const factory SwitchFieldTypeState({ + required String gridId, + required Field field, + required Uint8List typeOptionData, + }) = _SwitchFieldTypeState; + + factory SwitchFieldTypeState.initial(EditFieldContext editContext) => SwitchFieldTypeState( + gridId: editContext.gridId, + field: editContext.gridField, + typeOptionData: Uint8List.fromList(editContext.typeOptionData), + ); +} diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/type_option/date_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/date_bloc.dart new file mode 100644 index 0000000000..78b22b078b --- /dev/null +++ b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/date_bloc.dart @@ -0,0 +1,39 @@ +import 'dart:typed_data'; + +import 'package:flowy_sdk/log.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'dart:async'; +import 'package:dartz/dartz.dart'; + +part 'date_bloc.freezed.dart'; + +class DateTypeOptionBloc extends Bloc { + DateTypeOptionBloc() : super(DateTypeOptionState.initial()) { + on( + (event, emit) async { + await event.map( + initial: (_InitialField value) async {}, + ); + }, + ); + } + + @override + Future close() async { + return super.close(); + } +} + +@freezed +class DateTypeOptionEvent with _$DateTypeOptionEvent { + const factory DateTypeOptionEvent.initial(Uint8List? typeOptionData) = _InitialField; +} + +@freezed +class DateTypeOptionState with _$DateTypeOptionState { + const factory DateTypeOptionState() = _DateTypeOptionState; + + factory DateTypeOptionState.initial() => DateTypeOptionState(); +} diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/type_option/number_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/number_bloc.dart new file mode 100644 index 0000000000..21043f003b --- /dev/null +++ b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/number_bloc.dart @@ -0,0 +1,39 @@ +import 'dart:typed_data'; + +import 'package:flowy_sdk/log.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'dart:async'; +import 'package:dartz/dartz.dart'; + +part 'number_bloc.freezed.dart'; + +class NumberTypeOptionBloc extends Bloc { + NumberTypeOptionBloc() : super(NumberTypeOptionState.initial()) { + on( + (event, emit) async { + await event.map( + initial: (_InitialField value) async {}, + ); + }, + ); + } + + @override + Future close() async { + return super.close(); + } +} + +@freezed +class NumberTypeOptionEvent with _$NumberTypeOptionEvent { + const factory NumberTypeOptionEvent.initial(Uint8List? typeOptionData) = _InitialField; +} + +@freezed +class NumberTypeOptionState with _$NumberTypeOptionState { + const factory NumberTypeOptionState() = _NumberTypeOptionState; + + factory NumberTypeOptionState.initial() => NumberTypeOptionState(); +} diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/type_option/selection_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/selection_bloc.dart new file mode 100644 index 0000000000..ac6d3fb6d4 --- /dev/null +++ b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/selection_bloc.dart @@ -0,0 +1,39 @@ +import 'dart:typed_data'; + +import 'package:flowy_sdk/log.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'dart:async'; +import 'package:dartz/dartz.dart'; + +part 'selection_bloc.freezed.dart'; + +class SelectionTypeOptionBloc extends Bloc { + SelectionTypeOptionBloc() : super(SelectionTypeOptionState.initial()) { + on( + (event, emit) async { + await event.map( + initial: (_InitialField value) async {}, + ); + }, + ); + } + + @override + Future close() async { + return super.close(); + } +} + +@freezed +class SelectionTypeOptionEvent with _$SelectionTypeOptionEvent { + const factory SelectionTypeOptionEvent.initial(Uint8List? typeOptionData) = _InitialField; +} + +@freezed +class SelectionTypeOptionState with _$SelectionTypeOptionState { + const factory SelectionTypeOptionState() = _SelectionTypeOptionState; + + factory SelectionTypeOptionState.initial() => SelectionTypeOptionState(); +} diff --git a/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart index 63a2a19ec7..ea090a086a 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart @@ -124,7 +124,7 @@ class GridBloc extends Bloc { } @freezed -abstract class GridEvent with _$GridEvent { +class GridEvent with _$GridEvent { const factory GridEvent.initial() = InitialGrid; const factory GridEvent.rename(String gridId, String name) = _Rename; const factory GridEvent.updateDesc(String gridId, String desc) = _Desc; @@ -135,7 +135,7 @@ abstract class GridEvent with _$GridEvent { } @freezed -abstract class GridState with _$GridState { +class GridState with _$GridState { const factory GridState({ required GridLoadingState loadingState, required List fields, diff --git a/frontend/app_flowy/lib/workspace/application/grid/prelude.dart b/frontend/app_flowy/lib/workspace/application/grid/prelude.dart index a1c60d7efb..38135f75f6 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/prelude.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/prelude.dart @@ -3,10 +3,20 @@ export 'row/row_bloc.dart'; export 'row/row_service.dart'; export 'grid_service.dart'; export 'data.dart'; + +// Field export 'field/field_service.dart'; export 'field/grid_header_bloc.dart'; export 'field/edit_field_bloc.dart'; export 'field/create_field_bloc.dart'; +export 'field/switch_field_type_bloc.dart'; + +// Field Type Option +export 'field/type_option/date_bloc.dart'; +export 'field/type_option/number_bloc.dart'; +export 'field/type_option/selection_bloc.dart'; + +// Cell export 'cell_bloc/text_cell_bloc.dart'; export 'cell_bloc/number_cell_bloc.dart'; export 'cell_bloc/selection_cell_bloc.dart'; diff --git a/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart index a30bea39ee..b7e4f40c5d 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart @@ -88,7 +88,7 @@ class RowBloc extends Bloc { } @freezed -abstract class RowEvent with _$RowEvent { +class RowEvent with _$RowEvent { const factory RowEvent.initial() = _InitialRow; const factory RowEvent.createRow() = _CreateRow; const factory RowEvent.activeRow() = _ActiveRow; diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/content/cell_builder.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/content/cell_builder.dart index 7aa412589e..d612110ecb 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/content/cell_builder.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/content/cell_builder.dart @@ -22,7 +22,7 @@ Widget buildGridCell(GridCellData cellData) { case FieldType.SingleSelect: return SingleSelectCell(cellContext: cellData); default: - return const BlankCell(); + throw UnimplementedError; } } diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/create_field_pannel.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/create_field_pannel.dart index 0b8e2c3eac..8ac70b3741 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/create_field_pannel.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/create_field_pannel.dart @@ -37,8 +37,7 @@ class CreateFieldPannel extends FlowyOverlayDelegate { @override void didRemove() async { - await _createFieldBloc.close(); - // TODO: implement didRemove + _createFieldBloc.add(const CreateFieldEvent.done()); } } @@ -52,16 +51,16 @@ class _CreateFieldPannelWidget extends StatelessWidget { value: createFieldBloc, child: BlocBuilder( builder: (context, state) { - return state.field.fold( + return state.editContext.fold( () => const SizedBox(), - (field) => ListView( + (editContext) => ListView( shrinkWrap: true, children: [ const FlowyText.medium("Edit property", fontSize: 12), const VSpace(10), - _FieldNameTextField(field), + _FieldNameTextField(editContext.gridField), const VSpace(10), - _FieldTypeSwitcher(field), + _FieldTypeSwitcher(editContext), const VSpace(10), ], ), @@ -73,19 +72,12 @@ class _CreateFieldPannelWidget extends StatelessWidget { } class _FieldTypeSwitcher extends StatelessWidget { - final Field field; - const _FieldTypeSwitcher(this.field, {Key? key}) : super(key: key); + final EditFieldContext editContext; + const _FieldTypeSwitcher(this.editContext, {Key? key}) : super(key: key); @override Widget build(BuildContext context) { - return FieldTypeSwitcher( - field: field, - onSelectField: _switchToFieldType, - ); - } - - void _switchToFieldType(FieldType fieldType) { - throw UnimplementedError(); + return FieldTypeSwitcher(editContext: editContext); } } diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_editor.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_editor.dart index c199553cc6..ed26ecbd64 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_editor.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_editor.dart @@ -59,15 +59,11 @@ class _FieldTypeSwitcher extends StatelessWidget { Widget build(BuildContext context) { return BlocBuilder( builder: (context, state) { - final field = context.read().state.field; - return FieldTypeSwitcher(field: field, onSelectField: _switchToFieldType); + final editContext = context.read().state.editContext; + return FieldTypeSwitcher(editContext: editContext); }, ); } - - void _switchToFieldType(FieldType fieldType) { - throw UnimplementedError(); - } } class _FieldNameTextField extends StatelessWidget { @@ -76,10 +72,10 @@ class _FieldNameTextField extends StatelessWidget { @override Widget build(BuildContext context) { return BlocBuilder( - buildWhen: ((previous, current) => previous.field.name == current.field.name), + buildWhen: ((previous, current) => previous.editContext.gridField.name == current.editContext.gridField.name), builder: (context, state) { return FieldNameTextField( - name: state.field.name, + name: state.editContext.gridField.name, errorText: state.errorText, onNameChanged: (newName) { context.read().add(EditFieldEvent.updateFieldName(newName)); diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_name_input.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_name_input.dart index 49f0513099..80cb327379 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_name_input.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_name_input.dart @@ -19,7 +19,7 @@ class FieldNameTextField extends StatelessWidget { final theme = context.watch(); return RoundedInputField( height: 36, - style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w500), + style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w500), initialValue: name, normalBorderColor: theme.shader4, errorBorderColor: theme.red, diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_tyep_switcher.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_tyep_switcher.dart index 61b7c49b2d..df6ecf0d6a 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_tyep_switcher.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_tyep_switcher.dart @@ -1,3 +1,7 @@ +import 'dart:typed_data'; + +import 'package:app_flowy/startup/startup.dart'; +import 'package:app_flowy/workspace/application/grid/prelude.dart'; import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/header/field_type_list.dart'; import 'package:flowy_infra/image.dart'; import 'package:flowy_infra/theme.dart'; @@ -5,34 +9,217 @@ import 'package:flowy_infra_ui/style_widget/button.dart'; import 'package:flowy_infra_ui/style_widget/text.dart'; import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid-data-model/meta.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid/checkbox_type_option.pbserver.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid/date_type_option.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid/number_type_option.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid/selection_type_option.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid/text_type_option.pb.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; typedef SelectFieldCallback = void Function(FieldType); class FieldTypeSwitcher extends StatelessWidget { - final Field field; - final SelectFieldCallback onSelectField; + final EditFieldContext editContext; + const FieldTypeSwitcher({ - required this.field, - required this.onSelectField, + required this.editContext, Key? key, }) : super(key: key); @override Widget build(BuildContext context) { - final theme = context.watch(); + return BlocProvider( + create: (context) => getIt(param1: editContext), + child: BlocBuilder( + builder: (context, state) { + List children = [ + _switchFieldTypeButton(context, state.field), + ]; + final builder = _makeTypeOptionBuild( + state.field.fieldType, + state.typeOptionData, + ); + + final typeOptionWidget = builder.customWidget; + if (typeOptionWidget != null) { + children.add(typeOptionWidget); + } + + return ListView( + shrinkWrap: true, + children: children, + ); + }, + ), + ); + } + + Widget _switchFieldTypeButton(BuildContext context, Field field) { + final theme = context.watch(); return SizedBox( height: 36, child: FlowyButton( text: FlowyText.medium(field.fieldType.title(), fontSize: 12), padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2), hoverColor: theme.hover, - onTap: () => FieldTypeList.show(context, onSelectField), + onTap: () => FieldTypeList.show(context, (fieldType) { + context.read().add(SwitchFieldTypeEvent.toFieldType(fieldType)); + }), leftIcon: svg(field.fieldType.iconName(), color: theme.iconColor), rightIcon: svg("grid/more", color: theme.iconColor), ), ); } } + +abstract class TypeOptionBuilder { + Uint8List? get typeOptionData; + Widget? get customWidget; +} + +abstract class TypeOptionWidget extends StatelessWidget { + const TypeOptionWidget({Key? key}) : super(key: key); +} + +TypeOptionBuilder _makeTypeOptionBuild(FieldType fieldType, Uint8List typeOptionData) { + switch (fieldType) { + case FieldType.Checkbox: + return CheckboxTypeOptionBuilder(typeOptionData); + case FieldType.DateTime: + return DateTypeOptionBuilder(typeOptionData); + case FieldType.MultiSelect: + return MultiSelectTypeOptionBuilder(typeOptionData); + case FieldType.Number: + return NumberTypeOptionBuilder(typeOptionData); + case FieldType.RichText: + return RichTextTypeOptionBuilder(typeOptionData); + case FieldType.SingleSelect: + return SingleSelectTypeOptionBuilder(typeOptionData); + default: + throw UnimplementedError; + } +} + +class RichTextTypeOptionBuilder extends TypeOptionBuilder { + RichTextTypeOption typeOption; + + RichTextTypeOptionBuilder(Uint8List typeOptionData) : typeOption = RichTextTypeOption.fromBuffer(typeOptionData); + + @override + Uint8List? get typeOptionData => typeOption.writeToBuffer(); + + @override + Widget? get customWidget => null; +} + +class NumberTypeOptionBuilder extends TypeOptionBuilder { + NumberTypeOption typeOption; + + NumberTypeOptionBuilder(Uint8List typeOptionData) : typeOption = NumberTypeOption.fromBuffer(typeOptionData); + + @override + Uint8List? get typeOptionData => typeOption.writeToBuffer(); + + @override + Widget? get customWidget => const NumberTypeOptionWidget(); +} + +class NumberTypeOptionWidget extends TypeOptionWidget { + const NumberTypeOptionWidget({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => getIt(), + child: Container(), + ); + } +} + +class DateTypeOptionBuilder extends TypeOptionBuilder { + DateTypeOption typeOption; + + DateTypeOptionBuilder(Uint8List typeOptionData) : typeOption = DateTypeOption.fromBuffer(typeOptionData); + + @override + Uint8List? get typeOptionData => typeOption.writeToBuffer(); + + @override + Widget? get customWidget => const DateTypeOptionWidget(); +} + +class DateTypeOptionWidget extends TypeOptionWidget { + const DateTypeOptionWidget({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => getIt(), + child: Container(), + ); + } +} + +class CheckboxTypeOptionBuilder extends TypeOptionBuilder { + CheckboxTypeOption typeOption; + + CheckboxTypeOptionBuilder(Uint8List typeOptionData) : typeOption = CheckboxTypeOption.fromBuffer(typeOptionData); + + @override + Uint8List? get typeOptionData => throw UnimplementedError(); + + @override + Widget? get customWidget => null; +} + +class SingleSelectTypeOptionBuilder extends TypeOptionBuilder { + SingleSelectTypeOption typeOption; + + SingleSelectTypeOptionBuilder(Uint8List typeOptionData) + : typeOption = SingleSelectTypeOption.fromBuffer(typeOptionData); + + @override + Uint8List? get typeOptionData => typeOption.writeToBuffer(); + + @override + Widget? get customWidget => const SingleSelectTypeOptionWidget(); +} + +class SingleSelectTypeOptionWidget extends TypeOptionWidget { + const SingleSelectTypeOptionWidget({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => getIt(), + child: Container(), + ); + } +} + +class MultiSelectTypeOptionBuilder extends TypeOptionBuilder { + MultiSelectTypeOption typeOption; + + MultiSelectTypeOptionBuilder(Uint8List typeOptionData) + : typeOption = MultiSelectTypeOption.fromBuffer(typeOptionData); + + @override + Uint8List? get typeOptionData => typeOption.writeToBuffer(); + + @override + Widget? get customWidget => const MultiSelectTypeOptionWidget(); +} + +class MultiSelectTypeOptionWidget extends TypeOptionWidget { + const MultiSelectTypeOptionWidget({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => getIt(), + child: Container(), + ); + } +} diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_type_list.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_type_list.dart index 25ff77494d..25481fce09 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_type_list.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_type_list.dart @@ -104,8 +104,7 @@ extension FieldTypeListExtension on FieldType { case FieldType.SingleSelect: return "grid/field/single_select"; default: - assert(false, "Unsupport field type"); - return "grid/field/text"; + throw UnimplementedError; } } @@ -124,8 +123,7 @@ extension FieldTypeListExtension on FieldType { case FieldType.SingleSelect: return LocaleKeys.grid_field_singleSelectFieldName.tr(); default: - assert(false, "Unsupport field type"); - return LocaleKeys.grid_field_textFieldName.tr(); + throw UnimplementedError; } } } diff --git a/frontend/app_flowy/packages/flowy_infra_ui/lib/src/flowy_overlay/overlay_container.dart b/frontend/app_flowy/packages/flowy_infra_ui/lib/src/flowy_overlay/overlay_container.dart index bee123d248..b1f18b6695 100644 --- a/frontend/app_flowy/packages/flowy_infra_ui/lib/src/flowy_overlay/overlay_container.dart +++ b/frontend/app_flowy/packages/flowy_infra_ui/lib/src/flowy_overlay/overlay_container.dart @@ -21,7 +21,7 @@ class OverlayContainer extends StatelessWidget { type: MaterialType.transparency, child: Container( padding: padding, - decoration: FlowyDecoration.decoration(theme.surface, theme.shadowColor.withOpacity(0.1)), + decoration: FlowyDecoration.decoration(theme.surface, theme.shadowColor.withOpacity(0.15)), constraints: constraints, child: child, ), diff --git a/frontend/app_flowy/packages/flowy_sdk/lib/dispatch/dart_event/flowy-grid/dart_event.dart b/frontend/app_flowy/packages/flowy_sdk/lib/dispatch/dart_event/flowy-grid/dart_event.dart index c5f7002138..88f404d4f6 100644 --- a/frontend/app_flowy/packages/flowy_sdk/lib/dispatch/dart_event/flowy-grid/dart_event.dart +++ b/frontend/app_flowy/packages/flowy_sdk/lib/dispatch/dart_event/flowy-grid/dart_event.dart @@ -86,18 +86,18 @@ class GridEventCreateField { } } -class GridEventCreateDefaultField { - GridId request; - GridEventCreateDefaultField(this.request); +class GridEventCreateEditFieldContext { + CreateEditFieldContextParams request; + GridEventCreateEditFieldContext(this.request); - Future> send() { + Future> send() { final request = FFIRequest.create() - ..event = GridEvent.CreateDefaultField.toString() + ..event = GridEvent.CreateEditFieldContext.toString() ..payload = requestToBytes(this.request); return Dispatch.asyncRequest(request) .then((bytesResult) => bytesResult.fold( - (okBytes) => left(Field.fromBuffer(okBytes)), + (okBytes) => left(EditFieldContext.fromBuffer(okBytes)), (errBytes) => right(FlowyError.fromBuffer(errBytes)), )); } diff --git a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid-data-model/grid.pb.dart b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid-data-model/grid.pb.dart index ce247ef7d6..4ea447d729 100644 --- a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid-data-model/grid.pb.dart +++ b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid-data-model/grid.pb.dart @@ -252,6 +252,144 @@ class FieldOrder extends $pb.GeneratedMessage { void clearFieldId() => clearField(1); } +class CreateEditFieldContextParams extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'CreateEditFieldContextParams', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'gridId') + ..e<$0.FieldType>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'fieldType', $pb.PbFieldType.OE, defaultOrMaker: $0.FieldType.RichText, valueOf: $0.FieldType.valueOf, enumValues: $0.FieldType.values) + ..hasRequiredFields = false + ; + + CreateEditFieldContextParams._() : super(); + factory CreateEditFieldContextParams({ + $core.String? gridId, + $0.FieldType? fieldType, + }) { + final _result = create(); + if (gridId != null) { + _result.gridId = gridId; + } + if (fieldType != null) { + _result.fieldType = fieldType; + } + return _result; + } + factory CreateEditFieldContextParams.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory CreateEditFieldContextParams.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') + CreateEditFieldContextParams clone() => CreateEditFieldContextParams()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + CreateEditFieldContextParams copyWith(void Function(CreateEditFieldContextParams) updates) => super.copyWith((message) => updates(message as CreateEditFieldContextParams)) as CreateEditFieldContextParams; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static CreateEditFieldContextParams create() => CreateEditFieldContextParams._(); + CreateEditFieldContextParams createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static CreateEditFieldContextParams getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static CreateEditFieldContextParams? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get gridId => $_getSZ(0); + @$pb.TagNumber(1) + set gridId($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasGridId() => $_has(0); + @$pb.TagNumber(1) + void clearGridId() => clearField(1); + + @$pb.TagNumber(2) + $0.FieldType get fieldType => $_getN(1); + @$pb.TagNumber(2) + set fieldType($0.FieldType v) { setField(2, v); } + @$pb.TagNumber(2) + $core.bool hasFieldType() => $_has(1); + @$pb.TagNumber(2) + void clearFieldType() => clearField(2); +} + +class EditFieldContext extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'EditFieldContext', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'gridId') + ..aOM(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'gridField', subBuilder: Field.create) + ..a<$core.List<$core.int>>(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'typeOptionData', $pb.PbFieldType.OY) + ..hasRequiredFields = false + ; + + EditFieldContext._() : super(); + factory EditFieldContext({ + $core.String? gridId, + Field? gridField, + $core.List<$core.int>? typeOptionData, + }) { + final _result = create(); + if (gridId != null) { + _result.gridId = gridId; + } + if (gridField != null) { + _result.gridField = gridField; + } + if (typeOptionData != null) { + _result.typeOptionData = typeOptionData; + } + return _result; + } + factory EditFieldContext.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory EditFieldContext.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') + EditFieldContext clone() => EditFieldContext()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + EditFieldContext copyWith(void Function(EditFieldContext) updates) => super.copyWith((message) => updates(message as EditFieldContext)) as EditFieldContext; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static EditFieldContext create() => EditFieldContext._(); + EditFieldContext createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static EditFieldContext getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static EditFieldContext? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get gridId => $_getSZ(0); + @$pb.TagNumber(1) + set gridId($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasGridId() => $_has(0); + @$pb.TagNumber(1) + void clearGridId() => clearField(1); + + @$pb.TagNumber(2) + Field get gridField => $_getN(1); + @$pb.TagNumber(2) + set gridField(Field v) { setField(2, v); } + @$pb.TagNumber(2) + $core.bool hasGridField() => $_has(1); + @$pb.TagNumber(2) + void clearGridField() => clearField(2); + @$pb.TagNumber(2) + Field ensureGridField() => $_ensure(1); + + @$pb.TagNumber(3) + $core.List<$core.int> get typeOptionData => $_getN(2); + @$pb.TagNumber(3) + set typeOptionData($core.List<$core.int> v) { $_setBytes(2, v); } + @$pb.TagNumber(3) + $core.bool hasTypeOptionData() => $_has(2); + @$pb.TagNumber(3) + void clearTypeOptionData() => clearField(3); +} + class RepeatedField extends $pb.GeneratedMessage { static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'RepeatedField', createEmptyInstance: create) ..pc(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'items', $pb.PbFieldType.PM, subBuilder: Field.create) diff --git a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid-data-model/grid.pbjson.dart b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid-data-model/grid.pbjson.dart index adb25af959..a7dc3255c8 100644 --- a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid-data-model/grid.pbjson.dart +++ b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid-data-model/grid.pbjson.dart @@ -46,6 +46,29 @@ const FieldOrder$json = const { /// Descriptor for `FieldOrder`. Decode as a `google.protobuf.DescriptorProto`. final $typed_data.Uint8List fieldOrderDescriptor = $convert.base64Decode('CgpGaWVsZE9yZGVyEhkKCGZpZWxkX2lkGAEgASgJUgdmaWVsZElk'); +@$core.Deprecated('Use createEditFieldContextParamsDescriptor instead') +const CreateEditFieldContextParams$json = const { + '1': 'CreateEditFieldContextParams', + '2': const [ + const {'1': 'grid_id', '3': 1, '4': 1, '5': 9, '10': 'gridId'}, + const {'1': 'field_type', '3': 2, '4': 1, '5': 14, '6': '.FieldType', '10': 'fieldType'}, + ], +}; + +/// Descriptor for `CreateEditFieldContextParams`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List createEditFieldContextParamsDescriptor = $convert.base64Decode('ChxDcmVhdGVFZGl0RmllbGRDb250ZXh0UGFyYW1zEhcKB2dyaWRfaWQYASABKAlSBmdyaWRJZBIpCgpmaWVsZF90eXBlGAIgASgOMgouRmllbGRUeXBlUglmaWVsZFR5cGU='); +@$core.Deprecated('Use editFieldContextDescriptor instead') +const EditFieldContext$json = const { + '1': 'EditFieldContext', + '2': const [ + const {'1': 'grid_id', '3': 1, '4': 1, '5': 9, '10': 'gridId'}, + const {'1': 'grid_field', '3': 2, '4': 1, '5': 11, '6': '.Field', '10': 'gridField'}, + const {'1': 'type_option_data', '3': 3, '4': 1, '5': 12, '10': 'typeOptionData'}, + ], +}; + +/// Descriptor for `EditFieldContext`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List editFieldContextDescriptor = $convert.base64Decode('ChBFZGl0RmllbGRDb250ZXh0EhcKB2dyaWRfaWQYASABKAlSBmdyaWRJZBIlCgpncmlkX2ZpZWxkGAIgASgLMgYuRmllbGRSCWdyaWRGaWVsZBIoChB0eXBlX29wdGlvbl9kYXRhGAMgASgMUg50eXBlT3B0aW9uRGF0YQ=='); @$core.Deprecated('Use repeatedFieldDescriptor instead') const RepeatedField$json = const { '1': 'RepeatedField', diff --git a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/event_map.pbenum.dart b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/event_map.pbenum.dart index 7007f1f6c8..74cb74e42e 100644 --- a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/event_map.pbenum.dart +++ b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/event_map.pbenum.dart @@ -15,7 +15,7 @@ class GridEvent extends $pb.ProtobufEnum { static const GridEvent GetFields = GridEvent._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'GetFields'); static const GridEvent UpdateField = GridEvent._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UpdateField'); static const GridEvent CreateField = GridEvent._(12, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CreateField'); - static const GridEvent CreateDefaultField = GridEvent._(13, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CreateDefaultField'); + static const GridEvent CreateEditFieldContext = GridEvent._(13, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CreateEditFieldContext'); static const GridEvent CreateRow = GridEvent._(21, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CreateRow'); static const GridEvent GetRow = GridEvent._(22, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'GetRow'); static const GridEvent UpdateCell = GridEvent._(30, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UpdateCell'); @@ -26,7 +26,7 @@ class GridEvent extends $pb.ProtobufEnum { GetFields, UpdateField, CreateField, - CreateDefaultField, + CreateEditFieldContext, CreateRow, GetRow, UpdateCell, diff --git a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/event_map.pbjson.dart b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/event_map.pbjson.dart index 1d94f8227a..386cdd5bcb 100644 --- a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/event_map.pbjson.dart +++ b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/event_map.pbjson.dart @@ -17,7 +17,7 @@ const GridEvent$json = const { const {'1': 'GetFields', '2': 10}, const {'1': 'UpdateField', '2': 11}, const {'1': 'CreateField', '2': 12}, - const {'1': 'CreateDefaultField', '2': 13}, + const {'1': 'CreateEditFieldContext', '2': 13}, const {'1': 'CreateRow', '2': 21}, const {'1': 'GetRow', '2': 22}, const {'1': 'UpdateCell', '2': 30}, @@ -25,4 +25,4 @@ const GridEvent$json = const { }; /// Descriptor for `GridEvent`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List gridEventDescriptor = $convert.base64Decode('CglHcmlkRXZlbnQSDwoLR2V0R3JpZERhdGEQABIRCg1HZXRHcmlkQmxvY2tzEAESDQoJR2V0RmllbGRzEAoSDwoLVXBkYXRlRmllbGQQCxIPCgtDcmVhdGVGaWVsZBAMEhYKEkNyZWF0ZURlZmF1bHRGaWVsZBANEg0KCUNyZWF0ZVJvdxAVEgoKBkdldFJvdxAWEg4KClVwZGF0ZUNlbGwQHg=='); +final $typed_data.Uint8List gridEventDescriptor = $convert.base64Decode('CglHcmlkRXZlbnQSDwoLR2V0R3JpZERhdGEQABIRCg1HZXRHcmlkQmxvY2tzEAESDQoJR2V0RmllbGRzEAoSDwoLVXBkYXRlRmllbGQQCxIPCgtDcmVhdGVGaWVsZBAMEhoKFkNyZWF0ZUVkaXRGaWVsZENvbnRleHQQDRINCglDcmVhdGVSb3cQFRIKCgZHZXRSb3cQFhIOCgpVcGRhdGVDZWxsEB4='); diff --git a/frontend/rust-lib/flowy-grid/src/event_handler.rs b/frontend/rust-lib/flowy-grid/src/event_handler.rs index 39d6bf2e95..fb21efdd37 100644 --- a/frontend/rust-lib/flowy-grid/src/event_handler.rs +++ b/frontend/rust-lib/flowy-grid/src/event_handler.rs @@ -1,8 +1,9 @@ use crate::manager::GridManager; use flowy_error::FlowyError; use flowy_grid_data_model::entities::{ - CellMetaChangeset, CreateFieldPayload, CreateRowPayload, Field, FieldChangeset, Grid, GridId, QueryFieldPayload, - QueryGridBlocksPayload, QueryRowPayload, RepeatedField, RepeatedGridBlock, Row, + CellMetaChangeset, CreateEditFieldContextParams, CreateFieldPayload, CreateRowPayload, EditFieldContext, Field, + FieldChangeset, Grid, GridId, QueryFieldPayload, QueryGridBlocksPayload, QueryRowPayload, RepeatedField, + RepeatedGridBlock, Row, }; use flowy_grid_data_model::parser::{ CreateFieldParams, CreateRowParams, QueryFieldParams, QueryGridBlocksParams, QueryRowParams, @@ -72,14 +73,23 @@ pub(crate) async fn create_field_handler( } #[tracing::instrument(level = "debug", skip(data, manager), err)] -pub(crate) async fn create_default_field_handler( - data: Data, +pub(crate) async fn create_field_edit_context_handler( + data: Data, manager: AppData>, -) -> DataResult { - let grid_id: GridId = data.into_inner(); - let editor = manager.get_grid_editor(grid_id.as_ref())?; - let field = editor.make_default_field().await?; - data_result(field) +) -> DataResult { + let params: CreateEditFieldContextParams = data.into_inner(); + let editor = manager.get_grid_editor(¶ms.grid_id)?; + let field_meta = editor.make_field_meta_from_ty(¶ms.field_type).await?; + let type_option_data = field_meta.type_option.as_bytes().to_vec(); + let field: Field = field_meta.into(); + + let edit_context = EditFieldContext { + grid_id: params.grid_id, + grid_field: field, + type_option_data, + }; + + data_result(edit_context) } #[tracing::instrument(level = "debug", skip(data, manager), err)] diff --git a/frontend/rust-lib/flowy-grid/src/event_map.rs b/frontend/rust-lib/flowy-grid/src/event_map.rs index 8c08d547ff..b9fb842151 100644 --- a/frontend/rust-lib/flowy-grid/src/event_map.rs +++ b/frontend/rust-lib/flowy-grid/src/event_map.rs @@ -13,7 +13,7 @@ pub fn create(grid_manager: Arc) -> Module { .event(GridEvent::GetFields, get_fields_handler) .event(GridEvent::UpdateField, update_field_handler) .event(GridEvent::CreateField, create_field_handler) - .event(GridEvent::CreateDefaultField, create_default_field_handler) + .event(GridEvent::CreateEditFieldContext, create_field_edit_context_handler) .event(GridEvent::CreateRow, create_row_handler) .event(GridEvent::GetRow, get_row_handler) .event(GridEvent::UpdateCell, update_cell_handler); @@ -39,8 +39,8 @@ pub enum GridEvent { #[event(input = "CreateFieldPayload")] CreateField = 12, - #[event(input = "GridId", output = "Field")] - CreateDefaultField = 13, + #[event(input = "CreateEditFieldContextParams", output = "EditFieldContext")] + CreateEditFieldContext = 13, #[event(input = "CreateRowPayload", output = "Row")] CreateRow = 21, diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/model/event_map.rs b/frontend/rust-lib/flowy-grid/src/protobuf/model/event_map.rs index 4e0008c7a0..fb0e652790 100644 --- a/frontend/rust-lib/flowy-grid/src/protobuf/model/event_map.rs +++ b/frontend/rust-lib/flowy-grid/src/protobuf/model/event_map.rs @@ -30,7 +30,7 @@ pub enum GridEvent { GetFields = 10, UpdateField = 11, CreateField = 12, - CreateDefaultField = 13, + CreateEditFieldContext = 13, CreateRow = 21, GetRow = 22, UpdateCell = 30, @@ -48,7 +48,7 @@ impl ::protobuf::ProtobufEnum for GridEvent { 10 => ::std::option::Option::Some(GridEvent::GetFields), 11 => ::std::option::Option::Some(GridEvent::UpdateField), 12 => ::std::option::Option::Some(GridEvent::CreateField), - 13 => ::std::option::Option::Some(GridEvent::CreateDefaultField), + 13 => ::std::option::Option::Some(GridEvent::CreateEditFieldContext), 21 => ::std::option::Option::Some(GridEvent::CreateRow), 22 => ::std::option::Option::Some(GridEvent::GetRow), 30 => ::std::option::Option::Some(GridEvent::UpdateCell), @@ -63,7 +63,7 @@ impl ::protobuf::ProtobufEnum for GridEvent { GridEvent::GetFields, GridEvent::UpdateField, GridEvent::CreateField, - GridEvent::CreateDefaultField, + GridEvent::CreateEditFieldContext, GridEvent::CreateRow, GridEvent::GetRow, GridEvent::UpdateCell, @@ -95,11 +95,11 @@ impl ::protobuf::reflect::ProtobufValue for GridEvent { } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x0fevent_map.proto*\xa3\x01\n\tGridEvent\x12\x0f\n\x0bGetGridData\x10\ + \n\x0fevent_map.proto*\xa7\x01\n\tGridEvent\x12\x0f\n\x0bGetGridData\x10\ \0\x12\x11\n\rGetGridBlocks\x10\x01\x12\r\n\tGetFields\x10\n\x12\x0f\n\ - \x0bUpdateField\x10\x0b\x12\x0f\n\x0bCreateField\x10\x0c\x12\x16\n\x12Cr\ - eateDefaultField\x10\r\x12\r\n\tCreateRow\x10\x15\x12\n\n\x06GetRow\x10\ - \x16\x12\x0e\n\nUpdateCell\x10\x1eb\x06proto3\ + \x0bUpdateField\x10\x0b\x12\x0f\n\x0bCreateField\x10\x0c\x12\x1a\n\x16Cr\ + eateEditFieldContext\x10\r\x12\r\n\tCreateRow\x10\x15\x12\n\n\x06GetRow\ + \x10\x16\x12\x0e\n\nUpdateCell\x10\x1eb\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/proto/event_map.proto b/frontend/rust-lib/flowy-grid/src/protobuf/proto/event_map.proto index 894b2a111a..f6a07a0119 100644 --- a/frontend/rust-lib/flowy-grid/src/protobuf/proto/event_map.proto +++ b/frontend/rust-lib/flowy-grid/src/protobuf/proto/event_map.proto @@ -6,7 +6,7 @@ enum GridEvent { GetFields = 10; UpdateField = 11; CreateField = 12; - CreateDefaultField = 13; + CreateEditFieldContext = 13; CreateRow = 21; GetRow = 22; UpdateCell = 30; diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs index d81b96a1ad..3089836220 100644 --- a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs +++ b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs @@ -62,11 +62,10 @@ impl ClientGridEditor { Ok(()) } - pub async fn make_default_field(&self) -> FlowyResult { - let field_type = FieldType::default(); + pub async fn make_field_meta_from_ty(&self, field_type: &FieldType) -> FlowyResult { let name = format!("Property {}", self.pad.read().await.fields().len()); let field_meta = FieldBuilder::from_field_type(&field_type).name(&name).build(); - Ok(field_meta.into()) + Ok(field_meta) } pub async fn contain_field(&self, field_id: &str) -> bool { diff --git a/shared-lib/flowy-grid-data-model/src/entities/grid.rs b/shared-lib/flowy-grid-data-model/src/entities/grid.rs index c421dcac64..6d17fbca0f 100644 --- a/shared-lib/flowy-grid-data-model/src/entities/grid.rs +++ b/shared-lib/flowy-grid-data-model/src/entities/grid.rs @@ -67,6 +67,27 @@ impl std::convert::From for Field { } } +#[derive(Debug, Default, ProtoBuf)] +pub struct CreateEditFieldContextParams { + #[pb(index = 1)] + pub grid_id: String, + + #[pb(index = 2)] + pub field_type: FieldType, +} + +#[derive(Debug, Default, ProtoBuf)] +pub struct EditFieldContext { + #[pb(index = 1)] + pub grid_id: String, + + #[pb(index = 2)] + pub grid_field: Field, + + #[pb(index = 3)] + pub type_option_data: Vec, +} + #[derive(Debug, Default, ProtoBuf)] pub struct RepeatedField { #[pb(index = 1)] diff --git a/shared-lib/flowy-grid-data-model/src/protobuf/model/grid.rs b/shared-lib/flowy-grid-data-model/src/protobuf/model/grid.rs index 5a8dced09b..a6afa46d9a 100644 --- a/shared-lib/flowy-grid-data-model/src/protobuf/model/grid.rs +++ b/shared-lib/flowy-grid-data-model/src/protobuf/model/grid.rs @@ -818,6 +818,454 @@ impl ::protobuf::reflect::ProtobufValue for FieldOrder { } } +#[derive(PartialEq,Clone,Default)] +pub struct CreateEditFieldContextParams { + // message fields + pub grid_id: ::std::string::String, + pub field_type: super::meta::FieldType, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a CreateEditFieldContextParams { + fn default() -> &'a CreateEditFieldContextParams { + ::default_instance() + } +} + +impl CreateEditFieldContextParams { + pub fn new() -> CreateEditFieldContextParams { + ::std::default::Default::default() + } + + // string grid_id = 1; + + + pub fn get_grid_id(&self) -> &str { + &self.grid_id + } + pub fn clear_grid_id(&mut self) { + self.grid_id.clear(); + } + + // Param is passed by value, moved + pub fn set_grid_id(&mut self, v: ::std::string::String) { + self.grid_id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_grid_id(&mut self) -> &mut ::std::string::String { + &mut self.grid_id + } + + // Take field + pub fn take_grid_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.grid_id, ::std::string::String::new()) + } + + // .FieldType field_type = 2; + + + pub fn get_field_type(&self) -> super::meta::FieldType { + self.field_type + } + pub fn clear_field_type(&mut self) { + self.field_type = super::meta::FieldType::RichText; + } + + // Param is passed by value, moved + pub fn set_field_type(&mut self, v: super::meta::FieldType) { + self.field_type = v; + } +} + +impl ::protobuf::Message for CreateEditFieldContextParams { + 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.grid_id)?; + }, + 2 => { + ::protobuf::rt::read_proto3_enum_with_unknown_fields_into(wire_type, is, &mut self.field_type, 2, &mut self.unknown_fields)? + }, + _ => { + ::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.grid_id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.grid_id); + } + if self.field_type != super::meta::FieldType::RichText { + my_size += ::protobuf::rt::enum_size(2, self.field_type); + } + 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.grid_id.is_empty() { + os.write_string(1, &self.grid_id)?; + } + if self.field_type != super::meta::FieldType::RichText { + os.write_enum(2, ::protobuf::ProtobufEnum::value(&self.field_type))?; + } + 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() -> CreateEditFieldContextParams { + CreateEditFieldContextParams::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>( + "grid_id", + |m: &CreateEditFieldContextParams| { &m.grid_id }, + |m: &mut CreateEditFieldContextParams| { &mut m.grid_id }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( + "field_type", + |m: &CreateEditFieldContextParams| { &m.field_type }, + |m: &mut CreateEditFieldContextParams| { &mut m.field_type }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CreateEditFieldContextParams", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static CreateEditFieldContextParams { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CreateEditFieldContextParams::new) + } +} + +impl ::protobuf::Clear for CreateEditFieldContextParams { + fn clear(&mut self) { + self.grid_id.clear(); + self.field_type = super::meta::FieldType::RichText; + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for CreateEditFieldContextParams { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for CreateEditFieldContextParams { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct EditFieldContext { + // message fields + pub grid_id: ::std::string::String, + pub grid_field: ::protobuf::SingularPtrField, + pub type_option_data: ::std::vec::Vec, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a EditFieldContext { + fn default() -> &'a EditFieldContext { + ::default_instance() + } +} + +impl EditFieldContext { + pub fn new() -> EditFieldContext { + ::std::default::Default::default() + } + + // string grid_id = 1; + + + pub fn get_grid_id(&self) -> &str { + &self.grid_id + } + pub fn clear_grid_id(&mut self) { + self.grid_id.clear(); + } + + // Param is passed by value, moved + pub fn set_grid_id(&mut self, v: ::std::string::String) { + self.grid_id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_grid_id(&mut self) -> &mut ::std::string::String { + &mut self.grid_id + } + + // Take field + pub fn take_grid_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.grid_id, ::std::string::String::new()) + } + + // .Field grid_field = 2; + + + pub fn get_grid_field(&self) -> &Field { + self.grid_field.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_grid_field(&mut self) { + self.grid_field.clear(); + } + + pub fn has_grid_field(&self) -> bool { + self.grid_field.is_some() + } + + // Param is passed by value, moved + pub fn set_grid_field(&mut self, v: Field) { + self.grid_field = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_grid_field(&mut self) -> &mut Field { + if self.grid_field.is_none() { + self.grid_field.set_default(); + } + self.grid_field.as_mut().unwrap() + } + + // Take field + pub fn take_grid_field(&mut self) -> Field { + self.grid_field.take().unwrap_or_else(|| Field::new()) + } + + // bytes type_option_data = 3; + + + pub fn get_type_option_data(&self) -> &[u8] { + &self.type_option_data + } + pub fn clear_type_option_data(&mut self) { + self.type_option_data.clear(); + } + + // Param is passed by value, moved + pub fn set_type_option_data(&mut self, v: ::std::vec::Vec) { + self.type_option_data = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_type_option_data(&mut self) -> &mut ::std::vec::Vec { + &mut self.type_option_data + } + + // Take field + pub fn take_type_option_data(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.type_option_data, ::std::vec::Vec::new()) + } +} + +impl ::protobuf::Message for EditFieldContext { + fn is_initialized(&self) -> bool { + for v in &self.grid_field { + 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.grid_id)?; + }, + 2 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.grid_field)?; + }, + 3 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.type_option_data)?; + }, + _ => { + ::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.grid_id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.grid_id); + } + if let Some(ref v) = self.grid_field.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + if !self.type_option_data.is_empty() { + my_size += ::protobuf::rt::bytes_size(3, &self.type_option_data); + } + 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.grid_id.is_empty() { + os.write_string(1, &self.grid_id)?; + } + if let Some(ref v) = self.grid_field.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)?; + } + if !self.type_option_data.is_empty() { + os.write_bytes(3, &self.type_option_data)?; + } + 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() -> EditFieldContext { + EditFieldContext::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>( + "grid_id", + |m: &EditFieldContext| { &m.grid_id }, + |m: &mut EditFieldContext| { &mut m.grid_id }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "grid_field", + |m: &EditFieldContext| { &m.grid_field }, + |m: &mut EditFieldContext| { &mut m.grid_field }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "type_option_data", + |m: &EditFieldContext| { &m.type_option_data }, + |m: &mut EditFieldContext| { &mut m.type_option_data }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "EditFieldContext", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static EditFieldContext { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(EditFieldContext::new) + } +} + +impl ::protobuf::Clear for EditFieldContext { + fn clear(&mut self) { + self.grid_id.clear(); + self.grid_field.clear(); + self.type_option_data.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for EditFieldContext { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for EditFieldContext { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + #[derive(PartialEq,Clone,Default)] pub struct RepeatedField { // message fields @@ -4418,21 +4866,26 @@ static file_descriptor_proto_data: &'static [u8] = b"\ \x01(\x0e2\n.FieldTypeR\tfieldType\x12\x16\n\x06frozen\x18\x05\x20\x01(\ \x08R\x06frozen\x12\x1e\n\nvisibility\x18\x06\x20\x01(\x08R\nvisibility\ \x12\x14\n\x05width\x18\x07\x20\x01(\x05R\x05width\"'\n\nFieldOrder\x12\ - \x19\n\x08field_id\x18\x01\x20\x01(\tR\x07fieldId\"-\n\rRepeatedField\ - \x12\x1c\n\x05items\x18\x01\x20\x03(\x0b2\x06.FieldR\x05items\"7\n\x12Re\ - peatedFieldOrder\x12!\n\x05items\x18\x01\x20\x03(\x0b2\x0b.FieldOrderR\ - \x05items\"T\n\x08RowOrder\x12\x15\n\x06row_id\x18\x01\x20\x01(\tR\x05ro\ - wId\x12\x19\n\x08block_id\x18\x02\x20\x01(\tR\x07blockId\x12\x16\n\x06he\ - ight\x18\x03\x20\x01(\x05R\x06height\"\xb8\x01\n\x03Row\x12\x0e\n\x02id\ - \x18\x01\x20\x01(\tR\x02id\x12@\n\x10cell_by_field_id\x18\x02\x20\x03(\ - \x0b2\x17.Row.CellByFieldIdEntryR\rcellByFieldId\x12\x16\n\x06height\x18\ - \x03\x20\x01(\x05R\x06height\x1aG\n\x12CellByFieldIdEntry\x12\x10\n\x03k\ - ey\x18\x01\x20\x01(\tR\x03key\x12\x1b\n\x05value\x18\x02\x20\x01(\x0b2\ - \x05.CellR\x05value:\x028\x01\")\n\x0bRepeatedRow\x12\x1a\n\x05items\x18\ - \x01\x20\x03(\x0b2\x04.RowR\x05items\"5\n\x11RepeatedGridBlock\x12\x20\n\ - \x05items\x18\x01\x20\x03(\x0b2\n.GridBlockR\x05items\"+\n\x0eGridBlockO\ - rder\x12\x19\n\x08block_id\x18\x01\x20\x01(\tR\x07blockId\"E\n\tGridBloc\ - k\x12\x0e\n\x02id\x18\x01\x20\x01(\tR\x02id\x12(\n\nrow_orders\x18\x02\ + \x19\n\x08field_id\x18\x01\x20\x01(\tR\x07fieldId\"b\n\x1cCreateEditFiel\ + dContextParams\x12\x17\n\x07grid_id\x18\x01\x20\x01(\tR\x06gridId\x12)\n\ + \nfield_type\x18\x02\x20\x01(\x0e2\n.FieldTypeR\tfieldType\"|\n\x10EditF\ + ieldContext\x12\x17\n\x07grid_id\x18\x01\x20\x01(\tR\x06gridId\x12%\n\ng\ + rid_field\x18\x02\x20\x01(\x0b2\x06.FieldR\tgridField\x12(\n\x10type_opt\ + ion_data\x18\x03\x20\x01(\x0cR\x0etypeOptionData\"-\n\rRepeatedField\x12\ + \x1c\n\x05items\x18\x01\x20\x03(\x0b2\x06.FieldR\x05items\"7\n\x12Repeat\ + edFieldOrder\x12!\n\x05items\x18\x01\x20\x03(\x0b2\x0b.FieldOrderR\x05it\ + ems\"T\n\x08RowOrder\x12\x15\n\x06row_id\x18\x01\x20\x01(\tR\x05rowId\ + \x12\x19\n\x08block_id\x18\x02\x20\x01(\tR\x07blockId\x12\x16\n\x06heigh\ + t\x18\x03\x20\x01(\x05R\x06height\"\xb8\x01\n\x03Row\x12\x0e\n\x02id\x18\ + \x01\x20\x01(\tR\x02id\x12@\n\x10cell_by_field_id\x18\x02\x20\x03(\x0b2\ + \x17.Row.CellByFieldIdEntryR\rcellByFieldId\x12\x16\n\x06height\x18\x03\ + \x20\x01(\x05R\x06height\x1aG\n\x12CellByFieldIdEntry\x12\x10\n\x03key\ + \x18\x01\x20\x01(\tR\x03key\x12\x1b\n\x05value\x18\x02\x20\x01(\x0b2\x05\ + .CellR\x05value:\x028\x01\")\n\x0bRepeatedRow\x12\x1a\n\x05items\x18\x01\ + \x20\x03(\x0b2\x04.RowR\x05items\"5\n\x11RepeatedGridBlock\x12\x20\n\x05\ + items\x18\x01\x20\x03(\x0b2\n.GridBlockR\x05items\"+\n\x0eGridBlockOrder\ + \x12\x19\n\x08block_id\x18\x01\x20\x01(\tR\x07blockId\"E\n\tGridBlock\ + \x12\x0e\n\x02id\x18\x01\x20\x01(\tR\x02id\x12(\n\nrow_orders\x18\x02\ \x20\x03(\x0b2\t.RowOrderR\trowOrders\";\n\x04Cell\x12\x19\n\x08field_id\ \x18\x01\x20\x01(\tR\x07fieldId\x12\x18\n\x07content\x18\x02\x20\x01(\tR\ \x07content\"+\n\x0cRepeatedCell\x12\x1b\n\x05items\x18\x01\x20\x03(\x0b\ diff --git a/shared-lib/flowy-grid-data-model/src/protobuf/proto/grid.proto b/shared-lib/flowy-grid-data-model/src/protobuf/proto/grid.proto index b1252fc72e..ec109f580f 100644 --- a/shared-lib/flowy-grid-data-model/src/protobuf/proto/grid.proto +++ b/shared-lib/flowy-grid-data-model/src/protobuf/proto/grid.proto @@ -18,6 +18,15 @@ message Field { message FieldOrder { string field_id = 1; } +message CreateEditFieldContextParams { + string grid_id = 1; + FieldType field_type = 2; +} +message EditFieldContext { + string grid_id = 1; + Field grid_field = 2; + bytes type_option_data = 3; +} message RepeatedField { repeated Field items = 1; }