diff --git a/PROMPT.md b/PROMPT.md index 63f2406..eecb873 100644 --- a/PROMPT.md +++ b/PROMPT.md @@ -1,4 +1,5 @@ # OpenAI Prompt * `make a new sequence that represent an OAuth2 classic flow` +* `make a new sequence that represent an OAuth2 classic flow with refresh token` diff --git a/PlantUML/PlantUML+OpenAI.swift b/PlantUML/PlantUML+OpenAI.swift index 7ab7cf1..2674e06 100644 --- a/PlantUML/PlantUML+OpenAI.swift +++ b/PlantUML/PlantUML+OpenAI.swift @@ -174,6 +174,7 @@ extension OpenAIView { var Input_Fragment: some View { ZStack(alignment: .bottomTrailing ) { + TextEditor(text: $instruction) .font(.title3.monospaced() ) .lineSpacing(15) @@ -189,12 +190,12 @@ extension OpenAIView { HStack(spacing: 10) { Spacer() - Button( action: onUndo, - label: { - Label( "Undo", systemImage: "arrow.uturn.backward") - .labelStyle(.titleAndIcon) - }) - .disabled( isEditing || service.clipboard.isEmpty ) +// Button( action: onUndo, +// label: { +// Label( "Undo", systemImage: "arrow.uturn.backward") +// .labelStyle(.titleAndIcon) +// }) +// .disabled( isEditing || service.clipboard.isEmpty ) Button( action: { @@ -203,7 +204,6 @@ extension OpenAIView { service.status = .Ready service.clipboard.push( result.isEmpty ? input : result ) service.prompt.push( instruction ) - result = res } } diff --git a/PlantUML/PlantUMLContentView.swift b/PlantUML/PlantUMLContentView.swift index 2658131..ed4a2cd 100644 --- a/PlantUML/PlantUMLContentView.swift +++ b/PlantUML/PlantUMLContentView.swift @@ -21,7 +21,7 @@ import LineEditor struct PlantUMLContentView: View { - typealias PlantUMLLineEditorView = StandardLineEditorView + typealias PlantUMLLineEditorView = StandardLineEditorView class ViewState : ObservableObject, Identifiable { @@ -50,28 +50,8 @@ struct PlantUMLContentView: View { @State private var fontSize = CGFloat(12) @State private var showLine:Bool = false @State private var saving = false - @State private var openAIResult:String = "" @State private var diagramImage:UIImage? - var OpenAIView_Fragment: some View { - - OpenAIView( service: openAIService, result: $openAIResult, input: document.text, - onUndo: { - if let text = openAIService.clipboard.pop() { - document.setText( text ) - saving = true - document.updateRequest.send() - } - } - ) - .onChange(of: openAIResult ) { result in - document.setText( result ) - saving = true - document.updateRequest.send() - } - - } - var body: some View { VStack { @@ -91,6 +71,16 @@ struct PlantUMLContentView: View { } } .id( viewState.id ) + .onChange(of: document.openAIResult ) { result in + document.setText( result ) + document.editorText = PlantUMLDocumentProxy.buildDocumentText(from: result) +// saving = true +// document.updateRequest.send() + } + .onChange(of: document.editorText ) { _ in + saving = true + document.updateRequest.send() + } .onReceive(document.updateRequest.publisher) { _ in withAnimation(.easeInOut(duration: 1.0)) { document.save() @@ -142,6 +132,28 @@ struct PlantUMLContentView: View { } } +// +// MARK: - OpenAI extension - +// +extension PlantUMLContentView { + + var OpenAIView_Fragment: some View { + + OpenAIView( service: openAIService, result: $document.openAIResult, input: document.text, + onUndo: { + if let text = openAIService.clipboard.pop() { + document.setText( text ) + saving = true + document.updateRequest.send() + } + } + ) + + } + + +} + // // MARK: - Editor extension - // @@ -149,17 +161,13 @@ extension PlantUMLContentView { var EditorView_Fragment: some View { - PlantUMLLineEditorView( items: $document.items, + PlantUMLLineEditorView( text: $document.editorText, fontSize: $fontSize, showLine: $showLine) { onHide, onPressSymbol in PlantUMLKeyboardView( selectedTab: $keyboardTab, onHide: onHide, onPressSymbol: onPressSymbol) } - .onChange(of: document.items ) { _ in - saving = true - document.updateRequest.send() - } } diff --git a/PlantUML/PlantUMLDocumentProxy.swift b/PlantUML/PlantUMLDocumentProxy.swift index b83f234..e410b5c 100644 --- a/PlantUML/PlantUMLDocumentProxy.swift +++ b/PlantUML/PlantUMLDocumentProxy.swift @@ -32,13 +32,17 @@ class DebounceRequest { class PlantUMLDocumentProxy : ObservableObject, CustomStringConvertible { @Binding var object: PlantUMLDocument - @Published var items:Array +// private var items:Array + @Published var editorText: String + @Published var openAIResult:String = "" + private(set) var text:String let updateRequest = DebounceRequest( debounceInSeconds: 0.5) var description: String { - self.items.map { $0.rawValue }.joined( separator: "\n" ) + self.editorText +// self.items.map { $0.rawValue }.joined( separator: "\n" ) } let presenter = PlantUMLBrowserPresenter( format: .imagePng ) @@ -46,20 +50,23 @@ class PlantUMLDocumentProxy : ObservableObject, CustomStringConvertible { private var textCancellable:AnyCancellable? init( document: Binding ) { - let contents = "@startuml\n\(document.wrappedValue.text)\n@enduml" self._object = document - self.text = contents - self.items = Self.buildSyntaxStructureItems( from: contents) + self.text = "@startuml\n\(document.wrappedValue.text)\n@enduml" + self.editorText = document.wrappedValue.text +// self.items = Self.buildSyntaxStructureItems( from: contents) + + } func setText( _ text: String ) { self.text = text - self.items = Self.buildSyntaxStructureItems( from: text ) + +// self.items = Self.buildSyntaxStructureItems( from: text ) } func buildURL() -> URL { - let script = PlantUMLScript( items: items ) + let script = PlantUMLScript( items: Self.buildSyntaxStructureItems( from: self.text ) ) return presenter.url( of: script ) } @@ -80,6 +87,15 @@ class PlantUMLDocumentProxy : ObservableObject, CustomStringConvertible { extension PlantUMLDocumentProxy { + public static func buildDocumentText( from text: String ) -> String { + return text + .split(whereSeparator: \.isNewline) + .filter { line in + line != "@startuml" && line != "@enduml" + } + .joined(separator: "\n") + } + private static func buildSyntaxStructureItems( from text: String ) -> Array { return text .split(whereSeparator: \.isNewline) diff --git a/PlantUML4iPad.xcworkspace/xcshareddata/swiftpm/Package.resolved b/PlantUML4iPad.xcworkspace/xcshareddata/swiftpm/Package.resolved index df33932..7f22bf4 100644 --- a/PlantUML4iPad.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/PlantUML4iPad.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -10,12 +10,12 @@ } }, { - "identity" : "plantuml4ipad", + "identity" : "swiftui-lineeditor", "kind" : "remoteSourceControl", - "location" : "https://github.com/bsorrentino/PlantUML4iPad.git", + "location" : "https://github.com/bsorrentino/SwiftUI-LineEditor.git", "state" : { - "branch" : "line_editor", - "revision" : "c32ca4eebd381f6030d1b0d3f09bfc7b08bdf0b0" + "branch" : "feature/issue1", + "revision" : "266e3603c2da9adac5f9e0ceaf3caef8b0a7580b" } } ], diff --git a/PlantUMLApp.xcodeproj/project.pbxproj b/PlantUMLApp.xcodeproj/project.pbxproj index 5cf2ce3..649f1ad 100644 --- a/PlantUMLApp.xcodeproj/project.pbxproj +++ b/PlantUMLApp.xcodeproj/project.pbxproj @@ -32,9 +32,7 @@ A0D3C65E28984A10000838D7 /* PlantUMLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0D3C65D28984A10000838D7 /* PlantUMLTests.swift */; }; A0D3C66828984A11000838D7 /* PlantUMLUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0D3C66728984A11000838D7 /* PlantUMLUITests.swift */; }; A0D3C66A28984A11000838D7 /* PlantUMLUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0D3C66928984A11000838D7 /* PlantUMLUITestsLaunchTests.swift */; }; - A0DC176429D345BB00CB70E6 /* OpenAIKit in Frameworks */ = {isa = PBXBuildFile; productRef = A0DC176329D345BB00CB70E6 /* OpenAIKit */; }; A0DC176629D345D600CB70E6 /* PlantUMLKeyboard in Frameworks */ = {isa = PBXBuildFile; productRef = A0DC176529D345D600CB70E6 /* PlantUMLKeyboard */; }; - A0DC176829D345DB00CB70E6 /* LineEditor in Frameworks */ = {isa = PBXBuildFile; productRef = A0DC176729D345DB00CB70E6 /* LineEditor */; }; A0F2B14229353C2D00A44481 /* SwiftUI+Rotate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0F2B14129353C2D00A44481 /* SwiftUI+Rotate.swift */; }; A0F2B14329353C2D00A44481 /* SwiftUI+Rotate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0F2B14129353C2D00A44481 /* SwiftUI+Rotate.swift */; }; A0FB8F9C295616BF00910896 /* View+UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = A08AA78329561170004DE329 /* View+UIImage.swift */; }; @@ -96,9 +94,7 @@ buildActionMask = 2147483647; files = ( A01A6FBC29D3464500C3A1F6 /* PlantUMLFramework in Frameworks */, - A0DC176829D345DB00CB70E6 /* LineEditor in Frameworks */, A0DC176629D345D600CB70E6 /* PlantUMLKeyboard in Frameworks */, - A0DC176429D345BB00CB70E6 /* OpenAIKit in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -220,9 +216,7 @@ ); name = PlantUMLApp; packageProductDependencies = ( - A0DC176329D345BB00CB70E6 /* OpenAIKit */, A0DC176529D345D600CB70E6 /* PlantUMLKeyboard */, - A0DC176729D345DB00CB70E6 /* LineEditor */, A01A6FBB29D3464500C3A1F6 /* PlantUMLFramework */, ); productName = PlantUML; @@ -298,8 +292,6 @@ ); mainGroup = A0D3C63D28984A0E000838D7; packageReferences = ( - A0F3291E2902AC5E00E0C47C /* XCRemoteSwiftPackageReference "PlantUML4iPad" */, - A0DC176229D345BB00CB70E6 /* XCRemoteSwiftPackageReference "OpenAIKit" */, ); productRefGroup = A0D3C64728984A0E000838D7 /* Products */; projectDirPath = ""; @@ -713,44 +705,15 @@ }; /* End XCConfigurationList section */ -/* Begin XCRemoteSwiftPackageReference section */ - A0DC176229D345BB00CB70E6 /* XCRemoteSwiftPackageReference "OpenAIKit" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/marcodotio/OpenAIKit.git"; - requirement = { - kind = upToNextMajorVersion; - minimumVersion = 1.2.0; - }; - }; - A0F3291E2902AC5E00E0C47C /* XCRemoteSwiftPackageReference "PlantUML4iPad" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/bsorrentino/PlantUML4iPad.git"; - requirement = { - branch = line_editor; - kind = branch; - }; - }; -/* End XCRemoteSwiftPackageReference section */ - /* Begin XCSwiftPackageProductDependency section */ A01A6FBB29D3464500C3A1F6 /* PlantUMLFramework */ = { isa = XCSwiftPackageProductDependency; productName = PlantUMLFramework; }; - A0DC176329D345BB00CB70E6 /* OpenAIKit */ = { - isa = XCSwiftPackageProductDependency; - package = A0DC176229D345BB00CB70E6 /* XCRemoteSwiftPackageReference "OpenAIKit" */; - productName = OpenAIKit; - }; A0DC176529D345D600CB70E6 /* PlantUMLKeyboard */ = { isa = XCSwiftPackageProductDependency; productName = PlantUMLKeyboard; }; - A0DC176729D345DB00CB70E6 /* LineEditor */ = { - isa = XCSwiftPackageProductDependency; - package = A0F3291E2902AC5E00E0C47C /* XCRemoteSwiftPackageReference "PlantUML4iPad" */; - productName = LineEditor; - }; /* End XCSwiftPackageProductDependency section */ }; rootObject = A0D3C63E28984A0E000838D7 /* Project object */; diff --git a/PlantUMLKeyboard/Package.swift b/PlantUMLKeyboard/Package.swift index 959cac7..a35db49 100644 --- a/PlantUMLKeyboard/Package.swift +++ b/PlantUMLKeyboard/Package.swift @@ -19,7 +19,7 @@ let package = Package( // .package(url: "https://github.com/siteline/SwiftUI-Introspect.git", branch: "master" ), .package(path: "../PlantUMLFramework" ), .package(url: "https://github.com/marcodotio/OpenAIKit.git", from: "1.2.0"), - .package(url: "https://github.com/bsorrentino/PlantUML4iPad.git", branch: "line_editor"), + .package(url: "https://github.com/bsorrentino/SwiftUI-LineEditor.git", branch: "feature/issue1"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. @@ -27,7 +27,7 @@ let package = Package( .target( name: "PlantUMLKeyboard", dependencies: [ - .product(name: "LineEditor", package: "PlantUML4iPad"), + .product(name: "LineEditor", package: "SwiftUI-LineEditor"), .product(name: "OpenAIKit", package: "OpenAIKit"), "PlantUMLFramework", ],