board_cell.dart 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import 'package:app_flowy/plugins/grid/application/prelude.dart';
  2. import 'package:flowy_infra/notifier.dart';
  3. abstract class FocusableBoardCell {
  4. set becomeFocus(bool isFocus);
  5. }
  6. class EditableCellNotifier {
  7. final Notifier becomeFirstResponder = Notifier();
  8. final Notifier resignFirstResponder = Notifier();
  9. EditableCellNotifier();
  10. }
  11. class EditableRowNotifier {
  12. Map<EditableCellId, EditableCellNotifier> cells = {};
  13. void insertCell(
  14. GridCellIdentifier cellIdentifier,
  15. EditableCellNotifier notifier,
  16. ) {
  17. cells[EditableCellId.from(cellIdentifier)] = notifier;
  18. }
  19. void becomeFirstResponder() {
  20. for (final notifier in cells.values) {
  21. notifier.becomeFirstResponder.notify();
  22. }
  23. }
  24. void resignFirstResponder() {
  25. for (final notifier in cells.values) {
  26. notifier.resignFirstResponder.notify();
  27. }
  28. }
  29. void dispose() {
  30. for (final notifier in cells.values) {
  31. notifier.resignFirstResponder.notify();
  32. }
  33. cells.clear();
  34. }
  35. }
  36. abstract class EditableCell {
  37. EditableCellNotifier? get editableNotifier;
  38. }
  39. class EditableCellId {
  40. String fieldId;
  41. String rowId;
  42. EditableCellId(this.rowId, this.fieldId);
  43. factory EditableCellId.from(GridCellIdentifier cellIdentifier) =>
  44. EditableCellId(
  45. cellIdentifier.rowId,
  46. cellIdentifier.fieldId,
  47. );
  48. }