diff --git a/frontend/deps.edn b/frontend/deps.edn index 41f154c6f..32e661047 100644 --- a/frontend/deps.edn +++ b/frontend/deps.edn @@ -4,19 +4,17 @@ com.cognitect/transit-cljs {:mvn/version "0.8.256"} funcool/rumext {:git/url "https://github.com/funcool/rumext.git", - :sha "3d598e749ba429eae6544e532fc9f81369b307f5"} + :sha "3d598e749ba429eae6544e532fc9f81369b307f5" + :exclusions [org.omcljs/om sablono/sablono]} cljsjs/react {:mvn/version "16.8.6-0"} cljsjs/react-dom {:mvn/version "16.8.6-0"} cljsjs/react-dom-server {:mvn/version "16.8.6-0"} environ/environ {:mvn/version "1.1.0"} - metosin/reitit-core {:mvn/version "0.3.9"} - metosin/reitit-frontend {:mvn/version "0.3.9"} funcool/beicon {:mvn/version "5.0.0"} - funcool/bide {:mvn/version "1.6.1-SNAPSHOT"} funcool/cuerdas {:mvn/version "2.2.0"} funcool/lentes {:mvn/version "1.2.0"} funcool/potok {:mvn/version "2.3.0"} diff --git a/frontend/src/uxbox/main.cljs b/frontend/src/uxbox/main.cljs index e128971e8..636fdc30f 100644 --- a/frontend/src/uxbox/main.cljs +++ b/frontend/src/uxbox/main.cljs @@ -16,7 +16,7 @@ [uxbox.main.ui.lightbox :refer [lightbox]] [uxbox.main.ui.loader :refer [loader]] [uxbox.util.dom :as dom] - [uxbox.util.html-history :as html-history] + [uxbox.util.html.history :as html-history] [uxbox.util.i18n :as i18n :refer [tr]] [uxbox.util.messages :as uum] [uxbox.util.router :as rt] diff --git a/frontend/src/uxbox/main/ui.cljs b/frontend/src/uxbox/main/ui.cljs index 2e7154c6f..1fe385448 100644 --- a/frontend/src/uxbox/main/ui.cljs +++ b/frontend/src/uxbox/main/ui.cljs @@ -25,7 +25,7 @@ [uxbox.main.ui.workspace :refer [workspace]] [uxbox.util.data :refer [parse-int uuid-str?]] [uxbox.util.dom :as dom] - [uxbox.util.html-history :as html-history] + [uxbox.util.html.history :as html-history] [uxbox.util.i18n :refer [tr]] [uxbox.util.messages :as uum] [uxbox.util.router :as rt] diff --git a/frontend/src/uxbox/util/html/TokenTransformer.js b/frontend/src/uxbox/util/html/TokenTransformer.js new file mode 100644 index 000000000..be81568bb --- /dev/null +++ b/frontend/src/uxbox/util/html/TokenTransformer.js @@ -0,0 +1,60 @@ +/** + * TokenTransformer + * + * @author Paul Anderson , 2018 + * @license BSD License + */ + +goog.provide('uxbox.util.html.TokenTransformer'); +goog.require('goog.history.Html5History'); + +goog.scope(function() { + /** + * A goog.history.Html5History.TokenTransformer implementation that + * includes the query string in the token. + * + * The implementation of token<->url transforms in + * `goog.history.Html5History`, when useFragment is false and no custom + * transformer is supplied, assumes that a token is equivalent to + * `window.location.pathname` minus any configured path prefix. Since + * bide allows constructing urls that include a query string, we want + * to be able to store those as tokens. + * + * Addresses funcool/bide#15. + * + * @constructor + * @implements {goog.history.Html5History.TokenTransformer} + */ + uxbox.util.html.TokenTransformer = function () {}; + + /** + * Retrieves a history token given the path prefix and + * `window.location` object. + * + * @param {string} pathPrefix The path prefix to use when storing token + * in a path; always begin with a slash. + * @param {Location} location The `window.location` object. + * Treat this object as read-only. + * @return {string} token The history token. + */ + uxbox.util.html.TokenTransformer.prototype.retrieveToken = function(pathPrefix, location) { + return location.pathname.substr(pathPrefix.length) + location.search; + }; + + /** + * Creates a URL to be pushed into HTML5 history stack when storing + * token without using hash fragment. + * + * @param {string} token The history token. + * @param {string} pathPrefix The path prefix to use when storing token + * in a path; always begin with a slash. + * @param {Location} location The `window.location` object. + * Treat this object as read-only. + * @return {string} url The complete URL string from path onwards + * (without {@code protocol://host:port} part); must begin with a + * slash. + */ + uxbox.util.html.TokenTransformer.prototype.createUrl = function(token, pathPrefix, location) { + return pathPrefix + token; + }; +}); diff --git a/frontend/src/uxbox/util/html_history.cljs b/frontend/src/uxbox/util/html/history.cljs similarity index 70% rename from frontend/src/uxbox/util/html_history.cljs rename to frontend/src/uxbox/util/html/history.cljs index 760810e89..e41c6824e 100644 --- a/frontend/src/uxbox/util/html_history.cljs +++ b/frontend/src/uxbox/util/html/history.cljs @@ -2,23 +2,25 @@ ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; -;; Copyright (c) 2015-2017 Andrey Antukh +;; Copyright (c) 2019 Andrey Antukh -(ns uxbox.util.html-history +(ns uxbox.util.html.history "A singleton abstraction for the html5 fragment based history." (:require [goog.events :as e]) - (:import bide.impl.TokenTransformer + (:import uxbox.util.html.TokenTransformer goog.history.Html5History goog.history.EventType)) -(defonce +instance+ +(defonce ^:private +instance+ (doto (Html5History. nil (TokenTransformer.)) (.setUseFragment true) (.setEnabled true))) (defonce path (atom (.getToken +instance+))) -(e/listen +instance+ EventType.NAVIGATE #(reset! path (.-token %))) +(defonce ^:private +instance-sem+ + (e/listen +instance+ EventType.NAVIGATE + #(reset! path (.-token %)))) (defn set-path! [path] diff --git a/frontend/src/uxbox/util/router.cljs b/frontend/src/uxbox/util/router.cljs index 54888aeb5..6f74e02b8 100644 --- a/frontend/src/uxbox/util/router.cljs +++ b/frontend/src/uxbox/util/router.cljs @@ -8,7 +8,7 @@ (:require [reitit.core :as r] [cuerdas.core :as str] [potok.core :as ptk] - [uxbox.util.html-history :as html-history]) + [uxbox.util.html.history :as html-history]) (:import goog.Uri goog.Uri.QueryData)) diff --git a/frontend/src/uxbox/view.cljs b/frontend/src/uxbox/view.cljs index e451d1b55..bd86008b0 100644 --- a/frontend/src/uxbox/view.cljs +++ b/frontend/src/uxbox/view.cljs @@ -9,7 +9,7 @@ [rumext.core :as mx :include-macros true] [uxbox.config] [uxbox.util.dom :as dom] - [uxbox.util.html-history :as html-history] + [uxbox.util.html.history :as html-history] [uxbox.util.i18n :as i18n :refer [tr]] [uxbox.util.messages :as uum] [uxbox.util.router :as rt]