From fe1901575818b43cba8c36eba81f24021a99fb74 Mon Sep 17 00:00:00 2001 From: Mikhail Golovko Date: Wed, 27 Mar 2024 11:33:53 +0300 Subject: [PATCH] IOS-2557 Migrate --- Anytype.xcodeproj/project.pbxproj | 8 ++--- .../Sources/Models/BlockFields+Fields.swift | 11 ++++++ .../Assemblies/ModulesDI.swift | 4 --- .../Assemblies/ModulesDIProtocol.swift | 1 - .../EditorPageCoordinatorView.swift | 3 ++ .../EditorPageCoordinatorViewModel.swift | 5 +++ .../CodeLanguage/CodeLanguageListView.swift | 7 ++-- .../CodeLanguageListViewModel.swift | 35 ++++++++++++------- .../CodeLanguageModuleAssembly.swift | 30 ---------------- .../Page/EditorPageModuleAssembly.swift | 4 +-- .../Page/EditorPageModuleOutput.swift | 1 + .../Code/CodeBlockContentConfiguration.swift | 2 +- .../Blocks/Text/Code/CodeBlockViewModel.swift | 8 ++--- .../EditorPage/EditorPageViewModel.swift | 2 +- .../Models/BlockViewModelBuilder.swift | 18 ++++++---- .../Routing/Editor/EditorRouter.swift | 10 +----- .../Routing/Editor/EditorRouterProtocol.swift | 2 -- 17 files changed, 71 insertions(+), 80 deletions(-) create mode 100644 Anytype/Sources/Models/BlockFields+Fields.swift delete mode 100644 Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageModuleAssembly.swift diff --git a/Anytype.xcodeproj/project.pbxproj b/Anytype.xcodeproj/project.pbxproj index ca54e9315c..9a353d4913 100644 --- a/Anytype.xcodeproj/project.pbxproj +++ b/Anytype.xcodeproj/project.pbxproj @@ -384,6 +384,7 @@ 2A2C33212892BA36008BC326 /* RelationValueViewModelOutput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A2C33202892BA36008BC326 /* RelationValueViewModelOutput.swift */; }; 2A30734928ACEF58003673DF /* AlertOpener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A30734828ACEF58003673DF /* AlertOpener.swift */; }; 2A30735128AD04D7003673DF /* TopAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A30735028AD04D7003673DF /* TopAlertView.swift */; }; + 2A30B2022BB40E3400206806 /* BlockFields+Fields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A30B2012BB40E3400206806 /* BlockFields+Fields.swift */; }; 2A3425AC2A6A8EB3005E61F1 /* SmallImageIdPainter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A3425AB2A6A8EB3005E61F1 /* SmallImageIdPainter.swift */; }; 2A3425B32A6AD415005E61F1 /* AnytypeText+Mention.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A3425B22A6AD415005E61F1 /* AnytypeText+Mention.swift */; }; 2A35FF8E2AAF202E00D6006D /* CodeLanguageListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A35FF8D2AAF202E00D6006D /* CodeLanguageListView.swift */; }; @@ -670,7 +671,6 @@ 2AB7AAEB2AF51D0C00ED3E02 /* View+PresentationBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AB7AAEA2AF51D0C00ED3E02 /* View+PresentationBackground.swift */; }; 2AB7AAED2AF537AB00ED3E02 /* RemoteStorageSegmentInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AB7AAEC2AF537AB00ED3E02 /* RemoteStorageSegmentInfo.swift */; }; 2ABA0E07283BC420008369DC /* BlockObjectsSearchInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ABA0E06283BC420008369DC /* BlockObjectsSearchInteractor.swift */; }; - 2ABAF2BB2938E5FA003C4730 /* CodeLanguageModuleAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ABAF2BA2938E5FA003C4730 /* CodeLanguageModuleAssembly.swift */; }; 2ABAF2C1293DED8C003C4730 /* CreateObjectModuleAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ABAF2C0293DED8C003C4730 /* CreateObjectModuleAssembly.swift */; }; 2ABF214329B204BE00E872D9 /* UIUserInterfaceStyle+Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ABF214229B204BE00E872D9 /* UIUserInterfaceStyle+Settings.swift */; }; 2ABF214629B204F800E872D9 /* DashboardLogoutAlertModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ABF214529B204F800E872D9 /* DashboardLogoutAlertModel.swift */; }; @@ -2182,6 +2182,7 @@ 2A2C33202892BA36008BC326 /* RelationValueViewModelOutput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelationValueViewModelOutput.swift; sourceTree = ""; }; 2A30734828ACEF58003673DF /* AlertOpener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertOpener.swift; sourceTree = ""; }; 2A30735028AD04D7003673DF /* TopAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopAlertView.swift; sourceTree = ""; }; + 2A30B2012BB40E3400206806 /* BlockFields+Fields.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BlockFields+Fields.swift"; sourceTree = ""; }; 2A3425AB2A6A8EB3005E61F1 /* SmallImageIdPainter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmallImageIdPainter.swift; sourceTree = ""; }; 2A3425B22A6AD415005E61F1 /* AnytypeText+Mention.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AnytypeText+Mention.swift"; sourceTree = ""; }; 2A35FF8D2AAF202E00D6006D /* CodeLanguageListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeLanguageListView.swift; sourceTree = ""; }; @@ -2464,7 +2465,6 @@ 2AB7AAEA2AF51D0C00ED3E02 /* View+PresentationBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+PresentationBackground.swift"; sourceTree = ""; }; 2AB7AAEC2AF537AB00ED3E02 /* RemoteStorageSegmentInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteStorageSegmentInfo.swift; sourceTree = ""; }; 2ABA0E06283BC420008369DC /* BlockObjectsSearchInteractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlockObjectsSearchInteractor.swift; sourceTree = ""; }; - 2ABAF2BA2938E5FA003C4730 /* CodeLanguageModuleAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeLanguageModuleAssembly.swift; sourceTree = ""; }; 2ABAF2C0293DED8C003C4730 /* CreateObjectModuleAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateObjectModuleAssembly.swift; sourceTree = ""; }; 2ABF214229B204BE00E872D9 /* UIUserInterfaceStyle+Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIUserInterfaceStyle+Settings.swift"; sourceTree = ""; }; 2ABF214529B204F800E872D9 /* DashboardLogoutAlertModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardLogoutAlertModel.swift; sourceTree = ""; }; @@ -3851,6 +3851,7 @@ 038FB5C922D8F32F002B90B8 /* Models */ = { isa = PBXGroup; children = ( + 2A30B2012BB40E3400206806 /* BlockFields+Fields.swift */, 2AC5B3D02BA30070002584B8 /* ObjectPermissions */, 53D4089527ECCE9000495335 /* FieldConverters */, 5347854A2743C50C0097CA30 /* Relations */, @@ -6497,7 +6498,6 @@ 2ABAF2B72938E548003C4730 /* CodeLanguage */ = { isa = PBXGroup; children = ( - 2ABAF2BA2938E5FA003C4730 /* CodeLanguageModuleAssembly.swift */, 2A35FF8D2AAF202E00D6006D /* CodeLanguageListView.swift */, 2A35FF8F2AAF203C00D6006D /* CodeLanguageListViewModel.swift */, 2A35FF912AAF20FD00D6006D /* CodeLanguageRowModel.swift */, @@ -10713,7 +10713,6 @@ 2A2B332B2A7BAEBA004BD906 /* SpaceSwitchViewModel.swift in Sources */, EAADB1B32678EB52004B0AF2 /* MarkStyleModifier.swift in Sources */, 86C4B3782B246141003B8C51 /* SharingTipCoordinator.swift in Sources */, - 2ABAF2BB2938E5FA003C4730 /* CodeLanguageModuleAssembly.swift in Sources */, 2AA8108029A3D8E8007DD64B /* WidgetObjectListRowModel.swift in Sources */, 3D2F00292B6814CC009F3AA5 /* ObjectTypeSearchView.swift in Sources */, 2A4373722906808700A1C4D6 /* InlineMarkdownListener.swift in Sources */, @@ -11164,6 +11163,7 @@ 2AD6792C29812EE600339624 /* HomeBottomPanelModuleOutput.swift in Sources */, 2E7E50422B6D5C3A003867A3 /* ObjectRelationListModuleOutput.swift in Sources */, 3D1CEC4527F5F566000D36BA /* Clock.swift in Sources */, + 2A30B2022BB40E3400206806 /* BlockFields+Fields.swift in Sources */, 2AF205BC2ABD8E660027F3EA /* HomeBottomNavigationPanelView.swift in Sources */, 53FF7C4826F7562B00A5A592 /* AnytypeAudioPlayer.swift in Sources */, 2E22F9EC2B6167B7001EFCF3 /* SelectRelationListCoordinatorViewModel.swift in Sources */, diff --git a/Anytype/Sources/Models/BlockFields+Fields.swift b/Anytype/Sources/Models/BlockFields+Fields.swift new file mode 100644 index 0000000000..6c5cd49fc9 --- /dev/null +++ b/Anytype/Sources/Models/BlockFields+Fields.swift @@ -0,0 +1,11 @@ +import Foundation +import Services + +extension BlockFields { + + var codeLanguage: CodeLanguage { + CodeLanguage.create( + middleware: self[CodeBlockFields.FieldName.codeLanguage]?.stringValue + ) + } +} diff --git a/Anytype/Sources/PresentationLayer/Assemblies/ModulesDI.swift b/Anytype/Sources/PresentationLayer/Assemblies/ModulesDI.swift index 01108fde34..a96fe7e8ac 100644 --- a/Anytype/Sources/PresentationLayer/Assemblies/ModulesDI.swift +++ b/Anytype/Sources/PresentationLayer/Assemblies/ModulesDI.swift @@ -53,10 +53,6 @@ final class ModulesDI: ModulesDIProtocol { func createObject() -> CreateObjectModuleAssemblyProtocol { return CreateObjectModuleAssembly(serviceLocator: serviceLocator) } - - func codeLanguageList() -> CodeLanguageListModuleAssemblyProtocol { - return CodeLanguageListModuleAssembly(serviceLocator: serviceLocator) - } func newSearch() -> NewSearchModuleAssemblyProtocol { return NewSearchModuleAssembly(uiHelpersDI: uiHelpersDI, serviceLocator: serviceLocator) diff --git a/Anytype/Sources/PresentationLayer/Assemblies/ModulesDIProtocol.swift b/Anytype/Sources/PresentationLayer/Assemblies/ModulesDIProtocol.swift index 62bffbd159..05ec098771 100644 --- a/Anytype/Sources/PresentationLayer/Assemblies/ModulesDIProtocol.swift +++ b/Anytype/Sources/PresentationLayer/Assemblies/ModulesDIProtocol.swift @@ -11,7 +11,6 @@ protocol ModulesDIProtocol: AnyObject { func objectSetting() -> ObjectSettingModuleAssemblyProtocol func search() -> SearchModuleAssemblyProtocol func createObject() -> CreateObjectModuleAssemblyProtocol - func codeLanguageList() -> CodeLanguageListModuleAssemblyProtocol func newSearch() -> NewSearchModuleAssemblyProtocol func newRelation() -> NewRelationModuleAssemblyProtocol func homeWidgets() -> HomeWidgetsModuleAssemblyProtocol diff --git a/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorView.swift b/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorView.swift index 131a46365d..23de788bda 100644 --- a/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorView.swift +++ b/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorView.swift @@ -19,6 +19,9 @@ struct EditorPageCoordinatorView: View { .sheet(item: $model.relationValueData) { data in model.relationValueCoordinator(data: data) } + .sheet(item: $model.codeLanguageData) { + CodeLanguageListView(data: $0) + } .snackbar(toastBarData: $model.toastBarData) } } diff --git a/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorViewModel.swift b/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorViewModel.swift index 1588faac14..f2045155cf 100644 --- a/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorViewModel.swift @@ -18,6 +18,7 @@ final class EditorPageCoordinatorViewModel: ObservableObject, EditorPageModuleOu @Published var dismiss = false @Published var relationValueData: RelationValueData? @Published var toastBarData: ToastBarData = .empty + @Published var codeLanguageData: CodeLanguageListData? init( data: EditorPageObject, @@ -76,6 +77,10 @@ final class EditorPageCoordinatorViewModel: ObservableObject, EditorPageModuleOu ) } + func onSelectCodeLanguage(objectId: String, blockId: String) { + codeLanguageData = CodeLanguageListData(documentId: objectId, blockId: blockId) + } + private func handleRelationValue(relation: Relation, objectDetails: ObjectDetails) { let analyticsType = AnalyticsEventsRelationType.block if relationValueProcessingService.canOpenRelationInNewModule(relation) { diff --git a/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageListView.swift b/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageListView.swift index 90f0ae06e9..471272db43 100644 --- a/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageListView.swift +++ b/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageListView.swift @@ -3,11 +3,14 @@ import SwiftUI struct CodeLanguageListView: View { - @ObservedObject var model: CodeLanguageListViewModel - + @StateObject private var model: CodeLanguageListViewModel @State private var searchText: String = "" @Environment(\.dismiss) private var dismiss + init(data: CodeLanguageListData) { + self._model = StateObject(wrappedValue: CodeLanguageListViewModel(data: data)) + } + var body: some View { VStack(spacing: 0) { DragIndicator() diff --git a/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageListViewModel.swift b/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageListViewModel.swift index 0051d10e42..0bc506e0db 100644 --- a/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageListViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageListViewModel.swift @@ -1,25 +1,36 @@ import Foundation import Services +struct CodeLanguageListData: Identifiable, Hashable { + let documentId: String + let blockId: String + + var id: Int { hashValue } +} + final class CodeLanguageListViewModel: ObservableObject { // MARK: - DI + @Injected(\.blockService) + private var blockService: BlockServiceProtocol + @Injected(\.documentsProvider) + private var documentsProvider: DocumentsProviderProtocol - private let document: BaseDocumentProtocol - private let blockId: String - private let blockService: BlockServiceProtocol - private let selectedLanguage: CodeLanguage + private let data: CodeLanguageListData + private lazy var document: BaseDocumentProtocol = { + documentsProvider.document(objectId: data.documentId, forPreview: false) + }() + private var selectedLanguage: CodeLanguage? // MARK: - State @Published var rows: [CodeLanguageRowModel] = [] @Published var dismiss: Bool = false - init(document: BaseDocumentProtocol, blockId: String, selectedLanguage: CodeLanguage, blockService: BlockServiceProtocol) { - self.document = document - self.blockId = blockId - self.selectedLanguage = selectedLanguage - self.blockService = blockService + init(data: CodeLanguageListData) { + self.data = data + let info = document.infoContainer.get(id: data.blockId) + selectedLanguage = info?.fields.codeLanguage updateRows(searchText: "") } @@ -30,7 +41,7 @@ final class CodeLanguageListViewModel: ObservableObject { // MARK: - Private private func updateRows(searchText: String) { - + let languages = searchText.isEmpty ? CodeLanguage.allCases : CodeLanguage.allCases.filter { $0.title.lowercased().contains(searchText.lowercased()) } @@ -48,10 +59,10 @@ final class CodeLanguageListViewModel: ObservableObject { private func onTapCodeLanguage(_ language: CodeLanguage) { Task { @MainActor in - guard let info = document.infoContainer.get(id: blockId) else { return } + guard let info = document.infoContainer.get(id: data.blockId) else { return } let fields = CodeBlockFields(language: language) let newInfo = info.addFields(fields.asMiddleware()) - try await blockService.setFields(objectId: document.objectId, blockId: blockId, fields: newInfo.fields) + try await blockService.setFields(objectId: document.objectId, blockId: data.blockId, fields: newInfo.fields) dismiss.toggle() } } diff --git a/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageModuleAssembly.swift b/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageModuleAssembly.swift deleted file mode 100644 index b29806d189..0000000000 --- a/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageModuleAssembly.swift +++ /dev/null @@ -1,30 +0,0 @@ -import Foundation -import UIKit -import Services -import SwiftUI - -protocol CodeLanguageListModuleAssemblyProtocol { - func make(document: BaseDocumentProtocol, blockId: String, selectedLanguage: CodeLanguage) -> AnyView -} - -final class CodeLanguageListModuleAssembly: CodeLanguageListModuleAssemblyProtocol { - - private let serviceLocator: ServiceLocator - - init(serviceLocator: ServiceLocator) { - self.serviceLocator = serviceLocator - } - - // MARK: - CodeLanguageListModuleAssemblyProtocol - - func make(document: BaseDocumentProtocol, blockId: String, selectedLanguage: CodeLanguage) -> AnyView { - return CodeLanguageListView( - model: CodeLanguageListViewModel( - document: document, - blockId: blockId, - selectedLanguage: selectedLanguage, - blockService: serviceLocator.blockService() - ) - ).eraseToAnyView() - } -} diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleAssembly.swift b/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleAssembly.swift index 00eac183ba..c057bdcc3e 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleAssembly.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleAssembly.swift @@ -88,7 +88,6 @@ final class EditorPageModuleAssembly: EditorPageModuleAssemblyProtocol { objectSettingCoordinator: coordinatorsDI.objectSettings().make(), searchModuleAssembly: modulesDI.search(), toastPresenter: uiHelpersDI.toastPresenter(using: nil), - codeLanguageListModuleAssembly: modulesDI.codeLanguageList(), newSearchModuleAssembly: modulesDI.newSearch(), objectTypeSearchModuleAssembly: modulesDI.objectTypeSearch(), textIconPickerModuleAssembly: modulesDI.textIconPicker(), @@ -256,7 +255,8 @@ final class EditorPageModuleAssembly: EditorPageModuleAssemblyProtocol { linkToObjectCoordinator: coordinatorsDI.linkToObject().make(output: router), markupChanger: BlockMarkupChanger(), slashMenuActionHandler: slashMenuActionHandler, - editorPageBlocksStateManager: blocksStateManager + editorPageBlocksStateManager: blocksStateManager, + output: output ) blocksStateManager.blocksSelectionOverlayViewModel = blocksSelectionOverlayViewModel diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleOutput.swift b/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleOutput.swift index 6c810c0ca1..8a38c2608c 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleOutput.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleOutput.swift @@ -5,6 +5,7 @@ protocol EditorPageModuleOutput: AnyObject { func showEditorScreen(data: EditorScreenData) func replaceEditorScreen(data: EditorScreenData) func closeEditor() + func onSelectCodeLanguage(objectId: String, blockId: String) func showRelationValueEditingView(document: BaseDocumentProtocol, relation: Relation) // TODO: Refactoring templates. Delete it func setModuleInput(input: EditorPageModuleInput, objectId: String) diff --git a/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/Text/Code/CodeBlockContentConfiguration.swift b/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/Text/Code/CodeBlockContentConfiguration.swift index ed912072b3..845ea4b6c8 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/Text/Code/CodeBlockContentConfiguration.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/Text/Code/CodeBlockContentConfiguration.swift @@ -7,7 +7,7 @@ struct CodeBlockContentConfiguration: BlockConfiguration { struct Actions { let becomeFirstResponder: () -> () let textDidChange: (UITextView) -> () - let showCodeSelection: () -> () + let showCodeSelection: @MainActor () -> () } let content: BlockText diff --git a/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/Text/Code/CodeBlockViewModel.swift b/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/Text/Code/CodeBlockViewModel.swift index c3f0842b24..2b29c09373 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/Text/Code/CodeBlockViewModel.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/Text/Code/CodeBlockViewModel.swift @@ -12,7 +12,7 @@ struct CodeBlockViewModel: BlockViewModelProtocol { let becomeFirstResponder: (BlockInformation) -> () let handler: BlockActionHandlerProtocol let editorCollectionController: EditorBlockCollectionController - let showCodeSelection: (BlockInformation, CodeLanguage) -> () + let showCodeSelection: @MainActor (BlockInformation) -> () func makeContentConfiguration(maxWidth width: CGFloat) -> UIContentConfiguration { guard case let .text(content) = info.content else { @@ -20,9 +20,7 @@ struct CodeBlockViewModel: BlockViewModelProtocol { } let anytypeText = content.anytypeText(document: document) - let codeLanguage = CodeLanguage.create( - middleware: info.fields[CodeBlockFields.FieldName.codeLanguage]?.stringValue - ) + let codeLanguage = info.fields.codeLanguage return CodeBlockContentConfiguration( content: content, @@ -35,7 +33,7 @@ struct CodeBlockViewModel: BlockViewModelProtocol { handler.changeText(textView.attributedText, blockId: info.id) editorCollectionController.reconfigure(items: [.block(self)]) }, - showCodeSelection: { showCodeSelection(info, codeLanguage) } + showCodeSelection: { showCodeSelection(info) } ) ).cellBlockConfiguration( dragConfiguration: .init(id: info.id), diff --git a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageViewModel.swift b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageViewModel.swift index 06cea9f2e6..0634d89fd5 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageViewModel.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageViewModel.swift @@ -152,7 +152,7 @@ final class EditorPageViewModel: EditorPageViewModelProtocol, EditorBottomNaviga for blockId in blockIds { if blockViewModel.blockId == blockId { - guard let newViewModel = blockBuilder.build(id: blockId) else { + guard let newViewModel = blockBuilder.build(blockId: blockId) else { continue } diff --git a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Models/BlockViewModelBuilder.swift b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Models/BlockViewModelBuilder.swift index 1b9648a2d3..21cd458e2f 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Models/BlockViewModelBuilder.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Models/BlockViewModelBuilder.swift @@ -25,6 +25,7 @@ final class BlockViewModelBuilder { private let linkToObjectCoordinator: LinkToObjectCoordinatorProtocol private let markupChanger: BlockMarkupChangerProtocol private let slashMenuActionHandler: SlashMenuActionHandler + private weak var output: EditorPageModuleOutput? init( document: BaseDocumentProtocol, @@ -47,7 +48,8 @@ final class BlockViewModelBuilder { linkToObjectCoordinator: LinkToObjectCoordinatorProtocol, markupChanger: BlockMarkupChangerProtocol, slashMenuActionHandler: SlashMenuActionHandler, - editorPageBlocksStateManager: EditorPageBlocksStateManager + editorPageBlocksStateManager: EditorPageBlocksStateManager, + output: EditorPageModuleOutput? ) { self.document = document self.handler = handler @@ -70,6 +72,7 @@ final class BlockViewModelBuilder { self.markupChanger = markupChanger self.slashMenuActionHandler = slashMenuActionHandler self.editorPageBlocksStateManager = editorPageBlocksStateManager + self.output = output } func buildEditorItems(infos: [String]) -> [EditorItem] { @@ -96,20 +99,21 @@ final class BlockViewModelBuilder { private func build(_ ids: [String]) -> [BlockViewModelProtocol] { ids.compactMap { - let block = build(id: $0) + let block = build(blockId: $0) return block } } - func build(id: String) -> BlockViewModelProtocol? { - if let model = modelsHolder.blocksMapping[id] { + func build(blockId: String) -> BlockViewModelProtocol? { + if let model = modelsHolder.blocksMapping[blockId] { return model } - guard let info = infoContainer.get(id: id) else { + guard let info = infoContainer.get(id: blockId) else { return nil } + let documentId = document.objectId let blockInformationProvider = BlockModelInfomationProvider(infoContainer: infoContainer, info: info) switch info.content { @@ -122,8 +126,8 @@ final class BlockViewModelBuilder { becomeFirstResponder: { _ in }, handler: handler, editorCollectionController: blockCollectionController, - showCodeSelection: { [weak self] info, codeLanguage in - self?.router.showCodeLanguage(blockId: info.id, selectedLanguage: codeLanguage) + showCodeSelection: { [weak self] info in + self?.output?.onSelectCodeLanguage(objectId: documentId, blockId: blockId) } ) default: diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Routing/Editor/EditorRouter.swift b/Anytype/Sources/PresentationLayer/TextEditor/Routing/Editor/EditorRouter.swift index 21658a6e85..dbc5827e47 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Routing/Editor/EditorRouter.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Routing/Editor/EditorRouter.swift @@ -20,7 +20,6 @@ final class EditorRouter: NSObject, EditorRouterProtocol, ObjectSettingsCoordina private let objectSettingCoordinator: ObjectSettingsCoordinatorProtocol private let searchModuleAssembly: SearchModuleAssemblyProtocol private let toastPresenter: ToastPresenterProtocol - private let codeLanguageListModuleAssembly: CodeLanguageListModuleAssemblyProtocol private let newSearchModuleAssembly: NewSearchModuleAssemblyProtocol private let objectTypeSearchModuleAssembly: ObjectTypeSearchModuleAssemblyProtocol private let textIconPickerModuleAssembly: TextIconPickerModuleAssemblyProtocol @@ -41,7 +40,6 @@ final class EditorRouter: NSObject, EditorRouterProtocol, ObjectSettingsCoordina objectSettingCoordinator: ObjectSettingsCoordinatorProtocol, searchModuleAssembly: SearchModuleAssemblyProtocol, toastPresenter: ToastPresenterProtocol, - codeLanguageListModuleAssembly: CodeLanguageListModuleAssemblyProtocol, newSearchModuleAssembly: NewSearchModuleAssemblyProtocol, objectTypeSearchModuleAssembly: ObjectTypeSearchModuleAssemblyProtocol, textIconPickerModuleAssembly: TextIconPickerModuleAssemblyProtocol, @@ -62,7 +60,6 @@ final class EditorRouter: NSObject, EditorRouterProtocol, ObjectSettingsCoordina self.objectSettingCoordinator = objectSettingCoordinator self.searchModuleAssembly = searchModuleAssembly self.toastPresenter = toastPresenter - self.codeLanguageListModuleAssembly = codeLanguageListModuleAssembly self.newSearchModuleAssembly = newSearchModuleAssembly self.objectTypeSearchModuleAssembly = objectTypeSearchModuleAssembly self.textIconPickerModuleAssembly = textIconPickerModuleAssembly @@ -156,12 +153,7 @@ final class EditorRouter: NSObject, EditorRouterProtocol, ObjectSettingsCoordina func saveFile(fileURL: URL, type: FileContentType) { fileCoordinator.downloadFileAt(fileURL, withType: type) } - - func showCodeLanguage(blockId: String, selectedLanguage: CodeLanguage) { - let module = codeLanguageListModuleAssembly.make(document: document, blockId: blockId, selectedLanguage: selectedLanguage) - navigationContext.present(module) - } - + @MainActor func showStyleMenu( informations: [BlockInformation], diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Routing/Editor/EditorRouterProtocol.swift b/Anytype/Sources/PresentationLayer/TextEditor/Routing/Editor/EditorRouterProtocol.swift index f35bddf837..877da3c744 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Routing/Editor/EditorRouterProtocol.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Routing/Editor/EditorRouterProtocol.swift @@ -25,8 +25,6 @@ protocol EditorRouterProtocol: func saveFile(fileURL: URL, type: FileContentType) - func showCodeLanguage(blockId: String, selectedLanguage: CodeLanguage) - func showStyleMenu( informations: [BlockInformation], restrictions: BlockRestrictions,