From b6793d66304ed83c774a2786828329a82ac6e2d9 Mon Sep 17 00:00:00 2001 From: Owen Bickford Date: Sun, 24 Oct 2021 13:38:57 -0400 Subject: [PATCH] Type1fool-smooth-scrolling (#638) * add scroll behavior to html, body, & notebook elems * don't append base url or set target on intra-page links * add back-to-top link, class autosorting/formatting * add convert global style to `.scroll-smooth` util * add `isPageAnchor` function * remove `go-to-top` link * use `isAbsoluteUrl` and add a semicolon ;) --- assets/css/utilities.css | 4 ++ assets/js/cell/markdown.js | 8 +++- lib/livebook_web/live/session_live.ex | 40 +++++++++---------- .../live/session_live/indicators_component.ex | 12 +++--- .../templates/layout/root.html.heex | 4 +- 5 files changed, 38 insertions(+), 30 deletions(-) diff --git a/assets/css/utilities.css b/assets/css/utilities.css index a09f6d865..facee093b 100644 --- a/assets/css/utilities.css +++ b/assets/css/utilities.css @@ -22,4 +22,8 @@ .flip-horizontally { transform: scaleY(-1); } + + .scroll-smooth { + scroll-behavior: smooth; + } } diff --git a/assets/js/cell/markdown.js b/assets/js/cell/markdown.js index 20a572399..08bb37be9 100644 --- a/assets/js/cell/markdown.js +++ b/assets/js/cell/markdown.js @@ -126,7 +126,7 @@ function remarkExpandUrls(options) { return (ast) => { if (options.baseUrl) { visit(ast, "link", (node) => { - if (node.url && !isAbsoluteUrl(node.url)) { + if (node.url && !isAbsoluteUrl(node.url) && !isPageAnchor(node.url)) { node.url = urlAppend(options.baseUrl, node.url); } }); @@ -161,7 +161,7 @@ function rehypeExternalLinks(options) { if (isInternalUrl(url)) { node.properties["data-phx-link"] = "redirect"; node.properties["data-phx-link-state"] = "push"; - } else { + } else if (isAbsoluteUrl(url)) { node.properties.target = "_blank"; node.properties.rel = "noreferrer noopener"; } @@ -174,6 +174,10 @@ function isAbsoluteUrl(url) { return url.startsWith("http") || url.startsWith("/"); } +function isPageAnchor(url) { + return url.startsWith("#"); +} + function isInternalUrl(url) { return url.startsWith("/") || url.startsWith(window.location.origin); } diff --git a/lib/livebook_web/live/session_live.ex b/lib/livebook_web/live/session_live.ex index 5ee5fe4f9..a8ba9e057 100644 --- a/lib/livebook_web/live/session_live.ex +++ b/lib/livebook_web/live/session_live.ex @@ -114,13 +114,13 @@ defmodule LivebookWeb.SessionLive do
-
-

+
+

Sections

-
+
<%= for section_item <- @data_view.sections_items do %> - <% end %>
-
-
-
-

+
+
+

Users

- - + + <%= length(@data_view.clients) %> connected
-
+
<%= for {client_pid, user} <- @data_view.clients do %>
- <%= if client_pid != @self do %> @@ -186,10 +186,10 @@ defmodule LivebookWeb.SessionLive do
-
-
-
-

+
+
+