mirror of
https://github.com/penpot/penpot.git
synced 2025-06-04 16:11:38 +02:00
feat(frontend): remove bide dependency
This commit is contained in:
parent
1bf12a7338
commit
0115a86b24
7 changed files with 73 additions and 13 deletions
60
frontend/src/uxbox/util/html/TokenTransformer.js
Normal file
60
frontend/src/uxbox/util/html/TokenTransformer.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
* TokenTransformer
|
||||
*
|
||||
* @author Paul Anderson <paul@andersonpaul.com>, 2018
|
||||
* @license BSD License <https://opensource.org/licenses/BSD-2-Clause>
|
||||
*/
|
||||
|
||||
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;
|
||||
};
|
||||
});
|
|
@ -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 <niwi@niwi.nz>
|
||||
;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(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]
|
|
@ -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))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue