From 3262d009c57e3c46a3dcbcf5ef353063e969ea6d Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Thu, 1 Feb 2024 15:15:21 +0000 Subject: [PATCH 01/18] - --- end-to-end-tests/src/main/scala/tests/StdComponents.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/end-to-end-tests/src/main/scala/tests/StdComponents.scala b/end-to-end-tests/src/main/scala/tests/StdComponents.scala index 67c870ea..5b3ce3ca 100644 --- a/end-to-end-tests/src/main/scala/tests/StdComponents.scala +++ b/end-to-end-tests/src/main/scala/tests/StdComponents.scala @@ -14,7 +14,7 @@ import org.terminal21.client.components.std.* output.withText(newValue).renderChanges() Seq( - Header1(text = "Welcome to the std components demo/test"), + Header1(text = "header1 test"), Paragraph(text = "Hello World!").withChildren( NewLine(), Span(text = "Some more text"), From 642140d6bf97c40f78c2b6b8ecbe0cdec8c2b257 Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Thu, 1 Feb 2024 15:21:39 +0000 Subject: [PATCH 02/18] - --- .../src/main/scala/tests/StdComponents.scala | 5 ++++ .../client/components/std/StdElement.scala | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/end-to-end-tests/src/main/scala/tests/StdComponents.scala b/end-to-end-tests/src/main/scala/tests/StdComponents.scala index 5b3ce3ca..a822856f 100644 --- a/end-to-end-tests/src/main/scala/tests/StdComponents.scala +++ b/end-to-end-tests/src/main/scala/tests/StdComponents.scala @@ -15,6 +15,11 @@ import org.terminal21.client.components.std.* Seq( Header1(text = "header1 test"), + Header2(text = "header2 test"), + Header3(text = "header3 test"), + Header4(text = "header4 test"), + Header5(text = "header5 test"), + Header6(text = "header6 test"), Paragraph(text = "Hello World!").withChildren( NewLine(), Span(text = "Some more text"), diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/std/StdElement.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/std/StdElement.scala index b1384c30..8ee72beb 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/std/StdElement.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/std/StdElement.scala @@ -26,6 +26,31 @@ case class Header1(key: String = Keys.nextKey, text: String, style: Map[String, def withKey(v: String) = copy(key = v) def withText(v: String) = copy(text = v) +case class Header2(key: String = Keys.nextKey, text: String, style: Map[String, Any] = Map.empty) extends StdElement[Header2]: + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withKey(v: String) = copy(key = v) + def withText(v: String) = copy(text = v) + +case class Header3(key: String = Keys.nextKey, text: String, style: Map[String, Any] = Map.empty) extends StdElement[Header3]: + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withKey(v: String) = copy(key = v) + def withText(v: String) = copy(text = v) + +case class Header4(key: String = Keys.nextKey, text: String, style: Map[String, Any] = Map.empty) extends StdElement[Header4]: + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withKey(v: String) = copy(key = v) + def withText(v: String) = copy(text = v) + +case class Header5(key: String = Keys.nextKey, text: String, style: Map[String, Any] = Map.empty) extends StdElement[Header5]: + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withKey(v: String) = copy(key = v) + def withText(v: String) = copy(text = v) + +case class Header6(key: String = Keys.nextKey, text: String, style: Map[String, Any] = Map.empty) extends StdElement[Header6]: + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withKey(v: String) = copy(key = v) + def withText(v: String) = copy(text = v) + case class Paragraph( key: String = Keys.nextKey, text: String = "", From 459fd0c62613ae59fda3384740678d09748f4c5a Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Thu, 1 Feb 2024 15:41:39 +0000 Subject: [PATCH 03/18] - --- .../main/scala/tests/chakra/DataDisplay.scala | 11 +++++++++++ .../client/components/chakra/ChakraElement.scala | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/end-to-end-tests/src/main/scala/tests/chakra/DataDisplay.scala b/end-to-end-tests/src/main/scala/tests/chakra/DataDisplay.scala index 320e493d..e91586d7 100644 --- a/end-to-end-tests/src/main/scala/tests/chakra/DataDisplay.scala +++ b/end-to-end-tests/src/main/scala/tests/chakra/DataDisplay.scala @@ -3,6 +3,7 @@ package tests.chakra import org.terminal21.client.ConnectedSession import org.terminal21.client.components.UiElement import org.terminal21.client.components.chakra.* +import org.terminal21.client.components.std.NewLine import tests.chakra.Common.* object DataDisplay: @@ -67,5 +68,15 @@ object DataDisplay: headAndFoot ) ) + ), + VStack().withChildren( + Code(text = """ + |code-0001 + |""".stripMargin), + Code(colorScheme = Some("red")).withChildren( + Text(text = "val a=1"), + NewLine(), + Text(text = "println(a)") + ) ) ) diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala index 128deac6..30ed8b9d 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -1647,7 +1647,7 @@ case class Image( */ case class Text( key: String = Keys.nextKey, - text: String = "text.text is empty. Did you accidentally assigned the text to the `key` field?", + text: String = "text.text is empty. Did you accidentally assigned the text to the `key` field? Do Text(text=...)", fontSize: Option[String] = None, noOfLines: Option[Int] = None, color: Option[String] = None, @@ -1667,3 +1667,17 @@ case class Text( def withAlign(v: Option[String]) = copy(align = v) def withCasing(v: Option[String]) = copy(casing = v) def withDecoration(v: Option[String]) = copy(decoration = v) + +case class Code( + key: String = Keys.nextKey, + text: String = "", + colorScheme: Option[String] = None, + style: Map[String, Any] = Map.empty, + children: Seq[UiElement] = Nil +) extends ChakraElement[Code] + with HasChildren[Code]: + override def withChildren(cn: UiElement*) = copy(children = cn) + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withKey(v: String) = copy(key = v) + def withText(v: String) = copy(text = v) + def withColorScheme(v: Option[String]) = copy(colorScheme = v) From da52ca2392aeb5e9ca5ed38342002b4a95413ba0 Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Thu, 1 Feb 2024 15:47:26 +0000 Subject: [PATCH 04/18] - --- Readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Readme.md b/Readme.md index 63e636eb..fc7d216c 100644 --- a/Readme.md +++ b/Readme.md @@ -158,6 +158,10 @@ all changes that may have occurred at the browser and all the changes we did on Please use the [discussions](https://github.com/kostaskougios/terminal21-restapi/discussions) of the project to post any questions, comments or ideas. # Changelog +## Version 0.21 + +- more std and chakra components + ## Version 0.20 - immutable components From 19b466b08f9c6fda09e7d445fae9f8d39b6f1573 Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Thu, 1 Feb 2024 16:16:54 +0000 Subject: [PATCH 05/18] - --- .../main/scala/tests/chakra/DataDisplay.scala | 4 ++++ .../components/chakra/ChakraElement.scala | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/end-to-end-tests/src/main/scala/tests/chakra/DataDisplay.scala b/end-to-end-tests/src/main/scala/tests/chakra/DataDisplay.scala index e91586d7..69ba275d 100644 --- a/end-to-end-tests/src/main/scala/tests/chakra/DataDisplay.scala +++ b/end-to-end-tests/src/main/scala/tests/chakra/DataDisplay.scala @@ -78,5 +78,9 @@ object DataDisplay: NewLine(), Text(text = "println(a)") ) + ), + UnorderedList().withChildren( + ListItem(text = "unordered-list-list-item1"), + ListItem(text = "unordered-list-list-item2") ) ) diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala index 30ed8b9d..060a6d3d 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -1681,3 +1681,24 @@ case class Code( def withKey(v: String) = copy(key = v) def withText(v: String) = copy(text = v) def withColorScheme(v: Option[String]) = copy(colorScheme = v) + +case class UnorderedList( + key: String = Keys.nextKey, + style: Map[String, Any] = Map.empty, + children: Seq[UiElement] = Nil +) extends ChakraElement[UnorderedList] + with HasChildren[UnorderedList]: + override def withChildren(cn: UiElement*) = copy(children = cn) + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withKey(v: String) = copy(key = v) + +case class ListItem( + key: String = Keys.nextKey, + text: String = "", + style: Map[String, Any] = Map.empty, + children: Seq[UiElement] = Nil +) extends ChakraElement[ListItem] + with HasChildren[ListItem]: + override def withChildren(cn: UiElement*) = copy(children = cn) + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withKey(v: String) = copy(key = v) From 5aa7eec98422d5a1a3c2c1bb17bd63598122c68b Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Thu, 1 Feb 2024 16:21:39 +0000 Subject: [PATCH 06/18] - --- .../src/main/scala/tests/chakra/DataDisplay.scala | 4 ++++ .../client/components/chakra/ChakraElement.scala | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/end-to-end-tests/src/main/scala/tests/chakra/DataDisplay.scala b/end-to-end-tests/src/main/scala/tests/chakra/DataDisplay.scala index 69ba275d..6954315c 100644 --- a/end-to-end-tests/src/main/scala/tests/chakra/DataDisplay.scala +++ b/end-to-end-tests/src/main/scala/tests/chakra/DataDisplay.scala @@ -82,5 +82,9 @@ object DataDisplay: UnorderedList().withChildren( ListItem(text = "unordered-list-list-item1"), ListItem(text = "unordered-list-list-item2") + ), + OrderedList().withChildren( + ListItem(text = "Ordered-list-list-item1"), + ListItem(text = "Ordered-list-list-item2") ) ) diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala index 060a6d3d..777e8dcb 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -1692,6 +1692,16 @@ case class UnorderedList( override def withStyle(v: Map[String, Any]) = copy(style = v) def withKey(v: String) = copy(key = v) +case class OrderedList( + key: String = Keys.nextKey, + style: Map[String, Any] = Map.empty, + children: Seq[UiElement] = Nil +) extends ChakraElement[OrderedList] + with HasChildren[OrderedList]: + override def withChildren(cn: UiElement*) = copy(children = cn) + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withKey(v: String) = copy(key = v) + case class ListItem( key: String = Keys.nextKey, text: String = "", @@ -1699,6 +1709,7 @@ case class ListItem( children: Seq[UiElement] = Nil ) extends ChakraElement[ListItem] with HasChildren[ListItem]: + def withText(v: String) = copy(text = v) override def withChildren(cn: UiElement*) = copy(children = cn) override def withStyle(v: Map[String, Any]) = copy(style = v) def withKey(v: String) = copy(key = v) From 0439e039b98501a33e961728f19f343f8f8eb3eb Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Thu, 1 Feb 2024 16:26:29 +0000 Subject: [PATCH 07/18] - --- .../terminal21/client/components/chakra/ChakraElement.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala index 777e8dcb..f312d375 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -1684,6 +1684,7 @@ case class Code( case class UnorderedList( key: String = Keys.nextKey, + spacing: Option[String] = None, style: Map[String, Any] = Map.empty, children: Seq[UiElement] = Nil ) extends ChakraElement[UnorderedList] @@ -1691,9 +1692,11 @@ case class UnorderedList( override def withChildren(cn: UiElement*) = copy(children = cn) override def withStyle(v: Map[String, Any]) = copy(style = v) def withKey(v: String) = copy(key = v) + def withSpacing(v: Option[String]) = copy(spacing = v) case class OrderedList( key: String = Keys.nextKey, + spacing: Option[String] = None, style: Map[String, Any] = Map.empty, children: Seq[UiElement] = Nil ) extends ChakraElement[OrderedList] @@ -1701,6 +1704,7 @@ case class OrderedList( override def withChildren(cn: UiElement*) = copy(children = cn) override def withStyle(v: Map[String, Any]) = copy(style = v) def withKey(v: String) = copy(key = v) + def withSpacing(v: Option[String]) = copy(spacing = v) case class ListItem( key: String = Keys.nextKey, From 5f6b4bfb11ebe28ae0c599f0e2803daf5f459266 Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Thu, 1 Feb 2024 16:33:35 +0000 Subject: [PATCH 08/18] - --- example-scripts/csv-editor.sc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/example-scripts/csv-editor.sc b/example-scripts/csv-editor.sc index 79a01e0e..139e5b8e 100755 --- a/example-scripts/csv-editor.sc +++ b/example-scripts/csv-editor.sc @@ -55,7 +55,7 @@ def saveCsvMap() = .mkString("\n") FileUtils.writeStringToFile(file, s, "UTF-8") - // this will be countDown to 0 when we have to exit + // this will be set to true when we have to exit val exitFlag = new AtomicBoolean(false) Sessions.withNewSession(s"csv-editor-$fileName", s"CsvEdit: $fileName"): session => @@ -107,4 +107,3 @@ Sessions.withNewSession(s"csv-editor-$fileName", s"CsvEdit: $fileName"): session println(s"Now open ${session.uiUrl} to view the UI") // wait for one of the save/exit buttons to be pressed. session.waitTillUserClosesSessionOr(exitFlag.get()) - From 739bc59175c6966d1e3f0b986ec80af6ac564eb0 Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Thu, 1 Feb 2024 21:54:14 +0000 Subject: [PATCH 09/18] - --- .../main/scala/tests/ChakraComponents.scala | 2 +- .../main/scala/tests/chakra/Feedback.scala | 18 +++++++++ .../components/chakra/ChakraElement.scala | 37 +++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala diff --git a/end-to-end-tests/src/main/scala/tests/ChakraComponents.scala b/end-to-end-tests/src/main/scala/tests/ChakraComponents.scala index 6bdebe53..b08486f9 100644 --- a/end-to-end-tests/src/main/scala/tests/ChakraComponents.scala +++ b/end-to-end-tests/src/main/scala/tests/ChakraComponents.scala @@ -27,7 +27,7 @@ import java.util.concurrent.atomic.AtomicBoolean (Overlay.components ++ Forms.components ++ Editables.components ++ Stacks.components ++ Grids.components ++ Buttons.components( latch - ) ++ Etc.components ++ MediaAndIcons.components ++ DataDisplay.components ++ Typography.components ++ Seq(krButton)) + ) ++ Etc.components ++ MediaAndIcons.components ++ DataDisplay.components ++ Typography.components ++ Feedback.components ++ Seq(krButton)) .render() println("Waiting for button to be pressed for 1 hour") diff --git a/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala b/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala new file mode 100644 index 00000000..6a7ce75e --- /dev/null +++ b/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala @@ -0,0 +1,18 @@ +package tests.chakra + +import org.terminal21.client.ConnectedSession +import org.terminal21.client.components.UiElement +import org.terminal21.client.components.chakra.* +import tests.chakra.Common.commonBox + +object Feedback: + def components(using session: ConnectedSession): Seq[UiElement] = + Seq( + commonBox(text = "Alerts"), + VStack().withChildren( + Alert(status = "error").withChildren(AlertIcon(), AlertTitle(text = "Alert:error"), AlertDescription(text = "alert-error-text-01")), + Alert(status = "success").withChildren(AlertIcon(), AlertTitle(text = "Alert:success"), AlertDescription(text = "alert-success-text-01")), + Alert(status = "warning").withChildren(AlertIcon(), AlertTitle(text = "Alert:warning"), AlertDescription(text = "alert-warning-text-01")), + Alert(status = "info").withChildren(AlertIcon(), AlertTitle(text = "Alert:info"), AlertDescription(text = "alert-info-text-01")) + ) + ) diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala index f312d375..ddbbb909 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -1717,3 +1717,40 @@ case class ListItem( override def withChildren(cn: UiElement*) = copy(children = cn) override def withStyle(v: Map[String, Any]) = copy(style = v) def withKey(v: String) = copy(key = v) + +case class Alert( + key: String = Keys.nextKey, + status: String = "error", // error, success, warning, info + style: Map[String, Any] = Map.empty, + children: Seq[UiElement] = Nil +) extends ChakraElement[Alert] + with HasChildren[Alert]: + override def withChildren(cn: UiElement*) = copy(children = cn) + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withKey(v: String) = copy(key = v) + def withStatus(v: String) = copy(status = v) + +case class AlertIcon( + key: String = Keys.nextKey, + style: Map[String, Any] = Map.empty +) extends ChakraElement[AlertIcon]: + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withKey(v: String) = copy(key = v) + +case class AlertTitle( + key: String = Keys.nextKey, + text: String = "Alert!", + style: Map[String, Any] = Map.empty +) extends ChakraElement[AlertTitle]: + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withKey(v: String) = copy(key = v) + def withText(v: String) = copy(text = v) + +case class AlertDescription( + key: String = Keys.nextKey, + text: String = "Something happened!", + style: Map[String, Any] = Map.empty +) extends ChakraElement[AlertDescription]: + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withKey(v: String) = copy(key = v) + def withText(v: String) = copy(text = v) From 72c7784de435e490bca8fb0f4e792e897608c8a1 Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Fri, 2 Feb 2024 13:51:13 +0000 Subject: [PATCH 10/18] - --- .../src/main/scala/tests/chakra/Feedback.scala | 6 +++++- .../components/chakra/ChakraElement.scala | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala b/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala index 6a7ce75e..d1a2eaae 100644 --- a/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala +++ b/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala @@ -14,5 +14,9 @@ object Feedback: Alert(status = "success").withChildren(AlertIcon(), AlertTitle(text = "Alert:success"), AlertDescription(text = "alert-success-text-01")), Alert(status = "warning").withChildren(AlertIcon(), AlertTitle(text = "Alert:warning"), AlertDescription(text = "alert-warning-text-01")), Alert(status = "info").withChildren(AlertIcon(), AlertTitle(text = "Alert:info"), AlertDescription(text = "alert-info-text-01")) - ) + ), + commonBox(text = "Progress"), + Progress(value = 10), + Progress(value = 20, hasStripe = Some(true)), + Progress(value = 30, isIndeterminate = Some(true)) ) diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala index ddbbb909..175bee8f 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -1754,3 +1754,20 @@ case class AlertDescription( override def withStyle(v: Map[String, Any]) = copy(style = v) def withKey(v: String) = copy(key = v) def withText(v: String) = copy(text = v) + +case class Progress( + key: String = Keys.nextKey, + value: Int = 50, + colorScheme: Option[String] = None, + size: Option[String] = None, + hasStripe: Option[Boolean] = None, + isIndeterminate: Option[Boolean] = None, + style: Map[String, Any] = Map.empty +) extends ChakraElement[Progress]: + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withKey(v: String) = copy(key = v) + def withColorScheme(v: Option[String]) = copy(colorScheme = v) + def withSize(v: Option[String]) = copy(size = v) + def withValue(v: Int) = copy(value = v) + def withHasStripe(v: Option[Boolean]) = copy(hasStripe = v) + def withIsIndeterminate(v: Option[Boolean]) = copy(isIndeterminate = v) From 13d840c3f106ba4a4eefadfbd33b5d6c3e4b662f Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Fri, 2 Feb 2024 14:41:26 +0000 Subject: [PATCH 11/18] - --- .../main/scala/tests/chakra/Feedback.scala | 3 ++- .../components/chakra/ChakraElement.scala | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala b/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala index d1a2eaae..6fe6aab9 100644 --- a/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala +++ b/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala @@ -18,5 +18,6 @@ object Feedback: commonBox(text = "Progress"), Progress(value = 10), Progress(value = 20, hasStripe = Some(true)), - Progress(value = 30, isIndeterminate = Some(true)) + Progress(value = 30, isIndeterminate = Some(true)), + Tooltip(label = "A help message", child = Text(text = "hover me!")) ) diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala index 175bee8f..11f65d99 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -1771,3 +1771,25 @@ case class Progress( def withValue(v: Int) = copy(value = v) def withHasStripe(v: Option[Boolean]) = copy(hasStripe = v) def withIsIndeterminate(v: Option[Boolean]) = copy(isIndeterminate = v) + +case class Tooltip( + key: String = Keys.nextKey, + label: String = "tooltip.label", + bg: Option[String] = None, + color: Option[String] = None, + hasArrow: Option[Boolean] = None, + fontSize: Option[String] = None, + style: Map[String, Any] = Map.empty, + child: UiElement = Text("tooltip.child") +) extends ChakraElement[Tooltip] + with HasChildren[Tooltip]: + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withChild(cn: UiElement) = copy(child = cn) + def withKey(v: String) = copy(key = v) + def withBg(v: Option[String]) = copy(bg = v) + def withColor(v: Option[String]) = copy(color = v) + def withHasArrow(v: Option[Boolean]) = copy(hasArrow = v) + def withFontSize(v: Option[String]) = copy(fontSize = v) + override def children: Seq[UiElement] = Seq(child) + override def withChildren(cn: UiElement*): Tooltip = + if cn.size != 1 then throw new IllegalArgumentException("tooltip takes 1 only child") else withChild(cn.head) From 60ee633aa03e70f8caf3cb705552e2e111b8114d Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Fri, 2 Feb 2024 14:51:09 +0000 Subject: [PATCH 12/18] - --- .../src/main/scala/tests/chakra/Feedback.scala | 2 +- .../scala/org/terminal21/client/ConnectedSession.scala | 2 +- .../org/terminal21/client/components/UiElement.scala | 1 + .../client/components/chakra/ChakraElement.scala | 8 ++++---- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala b/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala index 6fe6aab9..72fd6f7f 100644 --- a/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala +++ b/end-to-end-tests/src/main/scala/tests/chakra/Feedback.scala @@ -19,5 +19,5 @@ object Feedback: Progress(value = 10), Progress(value = 20, hasStripe = Some(true)), Progress(value = 30, isIndeterminate = Some(true)), - Tooltip(label = "A help message", child = Text(text = "hover me!")) + Tooltip(label = "A help message").withContent(Text(text = "hover me!")) ) diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/ConnectedSession.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/ConnectedSession.scala index dbeb26d0..e693d5c5 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/ConnectedSession.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/ConnectedSession.scala @@ -95,7 +95,7 @@ class ConnectedSession(val session: Session, encoding: UiElementEncoding, val se el.key, el match case e: UiComponent => encoding.uiElementEncoder(e).deepDropNullValues - case e: HasChildren[_] => encoding.uiElementEncoder(e.withChildren()).deepDropNullValues + case e: HasChildren[_] => encoding.uiElementEncoder(e.noChildren).deepDropNullValues case e => encoding.uiElementEncoder(e).deepDropNullValues ) .toMap, diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/UiElement.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/UiElement.scala index 049acba6..00bb95b0 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/UiElement.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/UiElement.scala @@ -30,6 +30,7 @@ object UiElement: def children: Seq[UiElement] override def flat: Seq[UiElement] = Seq(this) ++ children.flatMap(_.flat) def withChildren(cn: UiElement*): A + def noChildren: A = withChildren() def addChildren(cn: UiElement*): A = withChildren(children ++ cn: _*) trait HasEventHandler: diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala index 11f65d99..f84f1060 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -1780,16 +1780,16 @@ case class Tooltip( hasArrow: Option[Boolean] = None, fontSize: Option[String] = None, style: Map[String, Any] = Map.empty, - child: UiElement = Text("tooltip.child") + children: Seq[UiElement] = Seq(Text("use tooltip.withContent() to set this")) ) extends ChakraElement[Tooltip] with HasChildren[Tooltip]: override def withStyle(v: Map[String, Any]) = copy(style = v) - def withChild(cn: UiElement) = copy(child = cn) + def withContent(cn: UiElement) = withChildren(cn) def withKey(v: String) = copy(key = v) def withBg(v: Option[String]) = copy(bg = v) def withColor(v: Option[String]) = copy(color = v) def withHasArrow(v: Option[Boolean]) = copy(hasArrow = v) def withFontSize(v: Option[String]) = copy(fontSize = v) - override def children: Seq[UiElement] = Seq(child) + override def noChildren = copy(children = Nil) override def withChildren(cn: UiElement*): Tooltip = - if cn.size != 1 then throw new IllegalArgumentException("tooltip takes 1 only child") else withChild(cn.head) + if cn.size != 1 then throw new IllegalArgumentException("tooltip takes 1 only child") else copy(children = cn) From e7677429ea9b1bd351b39b86520dcbde51cfa9d7 Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Fri, 2 Feb 2024 15:46:07 +0000 Subject: [PATCH 13/18] - --- .../main/scala/tests/ChakraComponents.scala | 4 +- .../main/scala/tests/chakra/Disclosure.scala | 31 +++++++ .../components/chakra/ChakraElement.scala | 81 +++++++++++++++++++ .../client/components/std/StdElement.scala | 2 +- 4 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 end-to-end-tests/src/main/scala/tests/chakra/Disclosure.scala diff --git a/end-to-end-tests/src/main/scala/tests/ChakraComponents.scala b/end-to-end-tests/src/main/scala/tests/ChakraComponents.scala index b08486f9..c7ec1db5 100644 --- a/end-to-end-tests/src/main/scala/tests/ChakraComponents.scala +++ b/end-to-end-tests/src/main/scala/tests/ChakraComponents.scala @@ -27,7 +27,9 @@ import java.util.concurrent.atomic.AtomicBoolean (Overlay.components ++ Forms.components ++ Editables.components ++ Stacks.components ++ Grids.components ++ Buttons.components( latch - ) ++ Etc.components ++ MediaAndIcons.components ++ DataDisplay.components ++ Typography.components ++ Feedback.components ++ Seq(krButton)) + ) ++ Etc.components ++ MediaAndIcons.components ++ DataDisplay.components ++ Typography.components ++ Feedback.components ++ Disclosure.components ++ Seq( + krButton + )) .render() println("Waiting for button to be pressed for 1 hour") diff --git a/end-to-end-tests/src/main/scala/tests/chakra/Disclosure.scala b/end-to-end-tests/src/main/scala/tests/chakra/Disclosure.scala new file mode 100644 index 00000000..a048f372 --- /dev/null +++ b/end-to-end-tests/src/main/scala/tests/chakra/Disclosure.scala @@ -0,0 +1,31 @@ +package tests.chakra + +import org.terminal21.client.ConnectedSession +import org.terminal21.client.components.UiElement +import org.terminal21.client.components.chakra.* +import org.terminal21.client.components.std.Paragraph +import tests.chakra.Common.commonBox + +object Disclosure: + def components(using session: ConnectedSession): Seq[UiElement] = + Seq( + commonBox(text = "Tabs"), + Tabs().withChildren( + TabList().withChildren( + Tab(text = "tab-one", _selected = Map("color" -> "white", "bg" -> "blue.500")), + Tab(text = "tab-two", _selected = Map("color" -> "white", "bg" -> "green.400")), + Tab(text = "tab-three") + ), + TabPanels().withChildren( + TabPanel().withChildren( + Paragraph(text = "tab-1-content") + ), + TabPanel().withChildren( + Paragraph(text = "tab-2-content") + ), + TabPanel().withChildren( + Paragraph(text = "tab-3-content") + ) + ) + ) + ) diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala index f84f1060..496bf3e0 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -1793,3 +1793,84 @@ case class Tooltip( override def noChildren = copy(children = Nil) override def withChildren(cn: UiElement*): Tooltip = if cn.size != 1 then throw new IllegalArgumentException("tooltip takes 1 only child") else copy(children = cn) + +/** see https://chakra-ui.com/docs/components/tabs + */ +case class Tabs( + key: String = Keys.nextKey, + defaultIndex: Int = 0, + variant: Option[String] = Some("enclosed"), // line,enclosed, enclosed-colored, soft-rounded, solid-rounded, and unstyled. + align: Option[String] = None, // start, center, end + colorScheme: Option[String] = None, + size: Option[String] = None, + isFitted: Option[Boolean] = None, + style: Map[String, Any] = Map.empty, + children: Seq[UiElement] = Nil +) extends ChakraElement[Tabs] + with HasChildren[Tabs]: + def withKey(v: String) = copy(key = v) + override def withChildren(cn: UiElement*) = copy(children = cn) + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withVariant(v: Option[String]) = copy(variant = v) + def withColorScheme(v: Option[String]) = copy(colorScheme = v) + def withSize(v: Option[String]) = copy(size = v) + def withAlign(v: Option[String]) = copy(align = v) + def withIsFitted(v: Option[Boolean]) = copy(isFitted = v) + +/** see https://chakra-ui.com/docs/components/tabs + */ +case class TabList( + key: String = Keys.nextKey, + style: Map[String, Any] = Map.empty, + children: Seq[UiElement] = Nil +) extends ChakraElement[TabList] + with HasChildren[TabList]: + def withKey(v: String) = copy(key = v) + override def withChildren(cn: UiElement*) = copy(children = cn) + override def withStyle(v: Map[String, Any]) = copy(style = v) + +/** see https://chakra-ui.com/docs/components/tabs + */ +case class Tab( + key: String = Keys.nextKey, + text: String = "tab.text", + isDisabled: Option[Boolean] = None, + _selected: Map[String, Any] = Map.empty, + _hover: Map[String, Any] = Map.empty, + _active: Map[String, Any] = Map.empty, + style: Map[String, Any] = Map.empty, + children: Seq[UiElement] = Nil +) extends ChakraElement[Tab] + with HasChildren[Tab]: + def withKey(v: String) = copy(key = v) + def withText(v: String) = copy(text = v) + override def withChildren(cn: UiElement*) = copy(children = cn) + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withIsDisabled(v: Option[Boolean]) = copy(isDisabled = v) + def withSelected(v: Map[String, Any]) = copy(_selected = v) + def withHover(v: Map[String, Any]) = copy(_hover = v) + def withActive(v: Map[String, Any]) = copy(_active = v) + +/** see https://chakra-ui.com/docs/components/tabs + */ +case class TabPanels( + key: String = Keys.nextKey, + style: Map[String, Any] = Map.empty, + children: Seq[UiElement] = Nil +) extends ChakraElement[TabPanels] + with HasChildren[TabPanels]: + def withKey(v: String) = copy(key = v) + override def withChildren(cn: UiElement*) = copy(children = cn) + override def withStyle(v: Map[String, Any]) = copy(style = v) + +/** see https://chakra-ui.com/docs/components/tabs + */ +case class TabPanel( + key: String = Keys.nextKey, + style: Map[String, Any] = Map.empty, + children: Seq[UiElement] = Nil +) extends ChakraElement[TabPanel] + with HasChildren[TabPanel]: + def withKey(v: String) = copy(key = v) + override def withChildren(cn: UiElement*) = copy(children = cn) + override def withStyle(v: Map[String, Any]) = copy(style = v) diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/std/StdElement.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/std/StdElement.scala index 8ee72beb..bf1b967c 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/std/StdElement.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/std/StdElement.scala @@ -53,7 +53,7 @@ case class Header6(key: String = Keys.nextKey, text: String, style: Map[String, case class Paragraph( key: String = Keys.nextKey, - text: String = "", + text: String = "paragraph.text", style: Map[String, Any] = Map.empty, children: Seq[UiElement] = Nil ) extends StdElement[Paragraph] From b7faa5142705a0f98fc6e9319bffe71369fae5e8 Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Mon, 5 Feb 2024 11:55:00 +0000 Subject: [PATCH 14/18] - --- .../main/scala/tests/ChakraComponents.scala | 2 +- .../main/scala/tests/chakra/Navigation.scala | 29 ++++++++++ .../components/chakra/ChakraElement.scala | 53 +++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 end-to-end-tests/src/main/scala/tests/chakra/Navigation.scala diff --git a/end-to-end-tests/src/main/scala/tests/ChakraComponents.scala b/end-to-end-tests/src/main/scala/tests/ChakraComponents.scala index c7ec1db5..328ed5b6 100644 --- a/end-to-end-tests/src/main/scala/tests/ChakraComponents.scala +++ b/end-to-end-tests/src/main/scala/tests/ChakraComponents.scala @@ -27,7 +27,7 @@ import java.util.concurrent.atomic.AtomicBoolean (Overlay.components ++ Forms.components ++ Editables.components ++ Stacks.components ++ Grids.components ++ Buttons.components( latch - ) ++ Etc.components ++ MediaAndIcons.components ++ DataDisplay.components ++ Typography.components ++ Feedback.components ++ Disclosure.components ++ Seq( + ) ++ Etc.components ++ MediaAndIcons.components ++ DataDisplay.components ++ Typography.components ++ Feedback.components ++ Disclosure.components ++ Navigation.components ++ Seq( krButton )) .render() diff --git a/end-to-end-tests/src/main/scala/tests/chakra/Navigation.scala b/end-to-end-tests/src/main/scala/tests/chakra/Navigation.scala new file mode 100644 index 00000000..991b6c73 --- /dev/null +++ b/end-to-end-tests/src/main/scala/tests/chakra/Navigation.scala @@ -0,0 +1,29 @@ +package tests.chakra + +import org.terminal21.client.ConnectedSession +import org.terminal21.client.components.UiElement +import org.terminal21.client.components.chakra.* +import org.terminal21.client.components.std.Paragraph +import tests.chakra.Common.commonBox + +object Navigation: + def components(using session: ConnectedSession): Seq[UiElement] = + val clickedBreadcrumb = Paragraph(text = "no-breadcrumb-clicked") + def breadcrumbClicked(t: String): Unit = + clickedBreadcrumb.withText(s"breadcrumb-click: $t").renderChanges() + + Seq( + commonBox(text = "Breadcrumbs"), + Breadcrumb().withChildren( + BreadcrumbItem().withChildren( + BreadcrumbLink(text = "breadcrumb-home").onClick(() => breadcrumbClicked("breadcrumb-home")) + ), + BreadcrumbItem().withChildren( + BreadcrumbLink(text = "breadcrumb-link1").onClick(() => breadcrumbClicked("breadcrumb-link1")) + ), + BreadcrumbItem(isCurrentPage = Some(true)).withChildren( + BreadcrumbLink(text = "breadcrumb-link2").onClick(() => breadcrumbClicked("breadcrumb-link2")) + ) + ), + clickedBreadcrumb + ) diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala index 496bf3e0..ed9e4979 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -1874,3 +1874,56 @@ case class TabPanel( def withKey(v: String) = copy(key = v) override def withChildren(cn: UiElement*) = copy(children = cn) override def withStyle(v: Map[String, Any]) = copy(style = v) + +/** https://chakra-ui.com/docs/components/breadcrumb + */ +case class Breadcrumb( + key: String = Keys.nextKey, + separator: String = "/", + spacing: Option[String] = None, + fontWeight: Option[String] = None, + fontSize: Option[String] = None, + pt: Option[Int] = None, + style: Map[String, Any] = Map.empty, + children: Seq[UiElement] = Nil +) extends ChakraElement[Breadcrumb] + with HasChildren[Breadcrumb]: + def withKey(v: String) = copy(key = v) + override def withChildren(cn: UiElement*) = copy(children = cn) + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withSeparator(v: String) = copy(separator = v) + def withSpacing(v: Option[String]) = copy(spacing = v) + def withFontWeight(v: Option[String]) = copy(fontWeight = v) + def withFontSize(v: Option[String]) = copy(fontSize = v) + def withPt(v: Option[Int]) = copy(pt = v) + +/** https://chakra-ui.com/docs/components/breadcrumb + */ +case class BreadcrumbItem( + key: String = Keys.nextKey, + isCurrentPage: Option[Boolean] = None, + style: Map[String, Any] = Map.empty, + children: Seq[UiElement] = Nil +) extends ChakraElement[BreadcrumbItem] + with HasChildren[BreadcrumbItem]: + def withKey(v: String) = copy(key = v) + override def withChildren(cn: UiElement*) = copy(children = cn) + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withIsCurrentPage(v: Option[Boolean]) = copy(isCurrentPage = v) + +/** https://chakra-ui.com/docs/components/breadcrumb + */ +case class BreadcrumbLink( + key: String = Keys.nextKey, + text: String = "breadcrumblink.text", + href: Option[String] = None, + style: Map[String, Any] = Map.empty, + children: Seq[UiElement] = Nil +) extends ChakraElement[BreadcrumbLink] + with HasChildren[BreadcrumbLink] + with OnClickEventHandler.CanHandleOnClickEvent[BreadcrumbLink]: + def withKey(v: String) = copy(key = v) + override def withChildren(cn: UiElement*) = copy(children = cn) + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withHref(v: Option[String]) = copy(href = v) + def withText(v: String) = copy(text = v) From 775078d5ad5edbdaf17fe09d3458337289537e3f Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Mon, 5 Feb 2024 12:13:46 +0000 Subject: [PATCH 15/18] - --- .../main/scala/tests/chakra/Navigation.scala | 9 ++++++++- .../components/chakra/ChakraElement.scala | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/end-to-end-tests/src/main/scala/tests/chakra/Navigation.scala b/end-to-end-tests/src/main/scala/tests/chakra/Navigation.scala index 991b6c73..afa7df70 100644 --- a/end-to-end-tests/src/main/scala/tests/chakra/Navigation.scala +++ b/end-to-end-tests/src/main/scala/tests/chakra/Navigation.scala @@ -12,6 +12,8 @@ object Navigation: def breadcrumbClicked(t: String): Unit = clickedBreadcrumb.withText(s"breadcrumb-click: $t").renderChanges() + val clickedLink = Paragraph(text = "no-link-clicked") + Seq( commonBox(text = "Breadcrumbs"), Breadcrumb().withChildren( @@ -25,5 +27,10 @@ object Navigation: BreadcrumbLink(text = "breadcrumb-link2").onClick(() => breadcrumbClicked("breadcrumb-link2")) ) ), - clickedBreadcrumb + clickedBreadcrumb, + commonBox(text = "Link"), + Link(text = "link-external-google", href = "https://www.google.com/", isExternal = Some(true)) + .onClick: () => + clickedLink.withText("link-clicked").renderChanges(), + clickedLink ) diff --git a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala index ed9e4979..fe08e86a 100644 --- a/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala +++ b/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -1927,3 +1927,20 @@ case class BreadcrumbLink( override def withStyle(v: Map[String, Any]) = copy(style = v) def withHref(v: Option[String]) = copy(href = v) def withText(v: String) = copy(text = v) + +case class Link( + key: String = Keys.nextKey, + text: String = "link.text", + href: String = "#", + isExternal: Option[Boolean] = None, + style: Map[String, Any] = Map.empty, + children: Seq[UiElement] = Nil +) extends ChakraElement[Link] + with HasChildren[Link] + with OnClickEventHandler.CanHandleOnClickEvent[Link]: + def withKey(v: String) = copy(key = v) + override def withChildren(cn: UiElement*) = copy(children = cn) + override def withStyle(v: Map[String, Any]) = copy(style = v) + def withIsExternal(v: Option[Boolean]) = copy(isExternal = v) + def withHref(v: String) = copy(href = v) + def withText(v: String) = copy(text = v) From 5deeb055bc777dc1fe05c3d5e1b3d1df0dc973dd Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Mon, 5 Feb 2024 12:36:26 +0000 Subject: [PATCH 16/18] - --- build.sbt | 2 +- example-scripts/bouncing-ball.sc | 7 ++++--- example-scripts/csv-editor.sc | 1 - example-scripts/csv-viewer.sc | 6 +++--- example-scripts/hello-world.sc | 2 +- example-scripts/postit.sc | 6 +++--- example-scripts/project.scala | 6 +++--- example-scripts/server.sc | 2 +- example-scripts/textedit.sc | 12 ++++++------ 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/build.sbt b/build.sbt index 03eee7fb..495aa8ae 100644 --- a/build.sbt +++ b/build.sbt @@ -5,7 +5,7 @@ import sbt.librarymanagement.ModuleFilter */ val scala3Version = "3.3.1" -ThisBuild / version := "0.20" +ThisBuild / version := "0.21" ThisBuild / organization := "io.github.kostaskougios" name := "rest-api" ThisBuild / scalaVersion := scala3Version diff --git a/example-scripts/bouncing-ball.sc b/example-scripts/bouncing-ball.sc index abd85ce1..11b491fb 100755 --- a/example-scripts/bouncing-ball.sc +++ b/example-scripts/bouncing-ball.sc @@ -7,7 +7,6 @@ // always import these import org.terminal21.client.* -// std components, https://github.com/kostaskougios/terminal21-restapi/blob/main/terminal21-ui-std/src/main/scala/org/terminal21/client/components/StdElement.scala import org.terminal21.client.components.* // use the chakra components for menus, forms etc, https://chakra-ui.com/docs/components // The scala case classes : https://github.com/kostaskougios/terminal21-restapi/blob/main/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -18,7 +17,9 @@ import scala.annotation.tailrec Sessions.withNewSession("bouncing-ball", "C64 bouncing ball"): session => given ConnectedSession = session - // Files under ~/.terminal21/web will be served under /web . Please place a ball.png file under ~/.terminal21/web/images on the box where the server runs. + println( + "Files under ~/.terminal21/web will be served under /web . Please place a ball.png file under ~/.terminal21/web/images on the box where the server runs." + ) val ball = Image(src = "/web/images/ball.png") ball.render() @@ -27,6 +28,6 @@ Sessions.withNewSession("bouncing-ball", "C64 bouncing ball"): session => Thread.sleep(1000 / 120) val newDx = if x < 0 || x > 600 then -dx else dx val newDy = if y < 0 || y > 500 then -dy else dy - animateBall(x + newDx, y + newDy, newDx, newDy) + if !session.isClosed then animateBall(x + newDx, y + newDy, newDx, newDy) animateBall(50, 50, 8, 8) diff --git a/example-scripts/csv-editor.sc b/example-scripts/csv-editor.sc index 139e5b8e..75abf9cb 100755 --- a/example-scripts/csv-editor.sc +++ b/example-scripts/csv-editor.sc @@ -8,7 +8,6 @@ import org.terminal21.client.* import java.util.concurrent.atomic.AtomicBoolean -// std components, https://github.com/kostaskougios/terminal21-restapi/blob/main/terminal21-ui-std/src/main/scala/org/terminal21/client/components/StdElement.scala import org.terminal21.client.components.* // use the chakra components for menus, forms etc, https://chakra-ui.com/docs/components // The scala case classes : https://github.com/kostaskougios/terminal21-restapi/blob/main/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala diff --git a/example-scripts/csv-viewer.sc b/example-scripts/csv-viewer.sc index 85fbcfcc..bf084500 100755 --- a/example-scripts/csv-viewer.sc +++ b/example-scripts/csv-viewer.sc @@ -6,7 +6,6 @@ // always import these import org.terminal21.client.* -// std components, https://github.com/kostaskougios/terminal21-restapi/blob/main/terminal21-ui-std/src/main/scala/org/terminal21/client/components/StdElement.scala import org.terminal21.client.components.* // use the chakra components for menus, forms etc, https://chakra-ui.com/docs/components // The scala case classes : https://github.com/kostaskougios/terminal21-restapi/blob/main/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -23,7 +22,7 @@ if args.length != 1 then ) val fileName = args(0) -val file = new File(fileName) +val file = new File(fileName) val contents = FileUtils.readFileToString(file, "UTF-8") val csv = contents.split("\n").map(_.split(",")) @@ -44,7 +43,8 @@ Sessions.withNewSession(s"csv-viewer-$fileName", s"CsvView: $fileName"): session ) ) ) - ).render() + ) + .render() println(s"Now open ${session.uiUrl} to view the UI.") // since this is a read-only UI, we can exit the app but leave the session open on the UI for the user to examine the data. session.leaveSessionOpenAfterExiting() diff --git a/example-scripts/hello-world.sc b/example-scripts/hello-world.sc index e314267f..6057391d 100755 --- a/example-scripts/hello-world.sc +++ b/example-scripts/hello-world.sc @@ -5,8 +5,8 @@ // always import these import org.terminal21.client.* -// std components, https://github.com/kostaskougios/terminal21-restapi/blob/main/terminal21-ui-std/src/main/scala/org/terminal21/client/components/StdElement.scala import org.terminal21.client.components.* +// std components, https://github.com/kostaskougios/terminal21-restapi/blob/main/terminal21-ui-std/src/main/scala/org/terminal21/client/components/StdElement.scala import org.terminal21.client.components.std.* Sessions.withNewSession("hello-world", "Hello World Example"): session => diff --git a/example-scripts/postit.sc b/example-scripts/postit.sc index b64c48a6..4c2326a7 100755 --- a/example-scripts/postit.sc +++ b/example-scripts/postit.sc @@ -5,8 +5,8 @@ // always import these import org.terminal21.client.* -// std components, https://github.com/kostaskougios/terminal21-restapi/blob/main/terminal21-ui-std/src/main/scala/org/terminal21/client/components/StdElement.scala import org.terminal21.client.components.* +// std components, https://github.com/kostaskougios/terminal21-restapi/blob/main/terminal21-ui-std/src/main/scala/org/terminal21/client/components/StdElement.scala import org.terminal21.client.components.std.* // use the chakra components for menus, forms etc, https://chakra-ui.com/docs/components // The scala case classes : https://github.com/kostaskougios/terminal21-restapi/blob/main/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -15,9 +15,9 @@ import org.terminal21.client.components.chakra.* Sessions.withNewSession("postit", "Post-It"): session => given ConnectedSession = session - val editor = Textarea(placeholder = "Please post your note by clicking here and editing the content") + val editor = Textarea(placeholder = "Please post your note by clicking here and editing the content") val messages = VStack(align = Some("stretch")) - val add = Button(text = "Post It.").onClick: () => + val add = Button(text = "Post It.").onClick: () => // add the new msg. // note: editor.value is automatically updated by terminal-ui val currentMessages = messages.current diff --git a/example-scripts/project.scala b/example-scripts/project.scala index 320278ba..a8914413 100644 --- a/example-scripts/project.scala +++ b/example-scripts/project.scala @@ -1,8 +1,8 @@ //> using jvm "21" //> using scala 3 -//> using dep io.github.kostaskougios::terminal21-ui-std:0.20 -//> using dep io.github.kostaskougios::terminal21-nivo:0.20 -//> using dep io.github.kostaskougios::terminal21-mathjax:0.20 +//> using dep io.github.kostaskougios::terminal21-ui-std:0.21 +//> using dep io.github.kostaskougios::terminal21-nivo:0.21 +//> using dep io.github.kostaskougios::terminal21-mathjax:0.21 //> using dep commons-io:commons-io:2.15.1 diff --git a/example-scripts/server.sc b/example-scripts/server.sc index be0e534a..08612e3d 100755 --- a/example-scripts/server.sc +++ b/example-scripts/server.sc @@ -2,7 +2,7 @@ //> using jvm "21" //> using scala 3 -//> using dep io.github.kostaskougios::terminal21-server:0.20 +//> using dep io.github.kostaskougios::terminal21-server:0.21 import org.terminal21.server.Terminal21Server diff --git a/example-scripts/textedit.sc b/example-scripts/textedit.sc index e0561f3b..77fe5756 100755 --- a/example-scripts/textedit.sc +++ b/example-scripts/textedit.sc @@ -10,8 +10,8 @@ import java.io.File // always import these import org.terminal21.client.* -// std components, https://github.com/kostaskougios/terminal21-restapi/blob/main/terminal21-ui-std/src/main/scala/org/terminal21/client/components/StdElement.scala import org.terminal21.client.components.* +// std components, https://github.com/kostaskougios/terminal21-restapi/blob/main/terminal21-ui-std/src/main/scala/org/terminal21/client/components/StdElement.scala import org.terminal21.client.components.std.* // use the chakra components for menus, forms etc, https://chakra-ui.com/docs/components // The scala case classes : https://github.com/kostaskougios/terminal21-restapi/blob/main/terminal21-ui-std/src/main/scala/org/terminal21/client/components/chakra/ChakraElement.scala @@ -25,7 +25,7 @@ if args.length != 1 then ) val fileName = args(0) -val file = new File(fileName) +val file = new File(fileName) val contents = if file.exists() then FileUtils.readFileToString(file, "UTF-8") else "" @@ -34,13 +34,13 @@ def saveFile(content: String) = FileUtils.writeStringToFile(file, content, "UTF- Sessions.withNewSession(s"textedit-$fileName", s"Edit: $fileName"): session => given ConnectedSession = session // we will wait till the user clicks the "Exit" menu, this latch makes sure the main thread of the app waits. - val exitLatch = new CountDownLatch(1) + val exitLatch = new CountDownLatch(1) // the main editor area. - val editor = Textarea(value = contents) + val editor = Textarea(value = contents) // This will display a "saved" badge for a second when the user saves the file - val status = Badge() + val status = Badge() // This will display an asterisk when the contents of the file are changed in the editor - val modified = Badge(colorScheme = Some("red")) + val modified = Badge(colorScheme = Some("red")) // when the user changes the textarea, we get the new text and we can compare it with the loaded value. editor.onChange: newValue => From a373519d03c39cb6dde067aa2f925419bf97afbc Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Mon, 5 Feb 2024 12:46:35 +0000 Subject: [PATCH 17/18] - --- example-spark/project.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/example-spark/project.scala b/example-spark/project.scala index a3ec4846..72a41970 100644 --- a/example-spark/project.scala +++ b/example-spark/project.scala @@ -8,10 +8,10 @@ //> using javaOpt -Dlogback.configurationFile=file:etc/logback.xml // terminal21 dependencies -//> using dep io.github.kostaskougios::terminal21-ui-std:0.20 -//> using dep io.github.kostaskougios::terminal21-spark:0.20 -//> using dep io.github.kostaskougios::terminal21-nivo:0.20 -//> using dep io.github.kostaskougios::terminal21-mathjax:0.20 +//> using dep io.github.kostaskougios::terminal21-ui-std:0.21 +//> using dep io.github.kostaskougios::terminal21-spark:0.21 +//> using dep io.github.kostaskougios::terminal21-nivo:0.21 +//> using dep io.github.kostaskougios::terminal21-mathjax:0.21 //> using dep ch.qos.logback:logback-classic:1.4.14 From c1094b7e47249eda9e54d8939d347203942eaf03 Mon Sep 17 00:00:00 2001 From: Kostas Kougios Date: Mon, 5 Feb 2024 12:53:18 +0000 Subject: [PATCH 18/18] - --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index fc7d216c..922ec8e0 100644 --- a/Readme.md +++ b/Readme.md @@ -160,7 +160,7 @@ Please use the [discussions](https://github.com/kostaskougios/terminal21-restapi # Changelog ## Version 0.21 -- more std and chakra components +- more std and chakra components like Alert, Progress, Tooltip, Tabs. ## Version 0.20