🎉 Add open url action

This commit is contained in:
Andrés Moya 2021-09-27 09:41:01 +02:00 committed by Alonso Torres
parent 4697a1904a
commit 57245dd77e
8 changed files with 56 additions and 13 deletions

View file

@ -67,8 +67,10 @@
(st/emit! (dv/close-overlay frame-id)))
:prev-screen
(do
(st/emit! (rt/nav-back-local)))
(st/emit! (rt/nav-back-local))
:open-url
(st/emit! (dom/open-new-window (:url interaction)))
nil))

View file

@ -39,7 +39,8 @@
:open-overlay (tr "workspace.options.interaction-open-overlay")
:toggle-overlay (tr "workspace.options.interaction-toggle-overlay")
:close-overlay (tr "workspace.options.interaction-close-overlay")
:prev-screen (tr "workspace.options.interaction-prev-screen")})
:prev-screen (tr "workspace.options.interaction-prev-screen")
:open-url (tr "workspace.options.interaction-open-url")})
(defn- action-summary
[interaction destination]
@ -53,6 +54,7 @@
:close-overlay (tr "workspace.options.interaction-close-overlay-dest"
(get destination :name (tr "workspace.options.interaction-self")))
:prev-screen (tr "workspace.options.interaction-prev-screen")
:open-url (tr "workspace.options.interaction-open-url")
"--"))
(defn- overlay-pos-type-names
@ -106,6 +108,11 @@
value (when (not= value "") (uuid/uuid value))]
(update-interaction index #(cti/set-destination % value shape objects))))
change-url
(fn [event]
(let [value (-> event dom/get-target dom/get-value)]
(update-interaction index #(cti/set-url % value))))
change-overlay-pos-type
(fn [event]
(let [value (-> event dom/get-target dom/get-value d/read-string)]
@ -186,6 +193,13 @@
(not= (:id frame) (:frame-id shape))) ; nor a shape to its container frame
[:option {:value (str (:id frame))} (:name frame)]))]])
; URL
(when (= action-type :open-url)
[:div.interactions-element
[:span.element-set-subtitle.wide (tr "workspace.options.interaction-url")]
[:input.input-text {:default-value (str (:url interaction))
:on-blur change-url}]])
(when (or (= action-type :open-overlay)
(= action-type :toggle-overlay))
[:*

View file

@ -11,7 +11,6 @@
goog.provide("app.util.browser_history");
goog.require("goog.history.Html5History");
goog.scope(function() {
const self = app.util.browser_history;
const Html5History = goog.history.Html5History;

View file

@ -394,3 +394,14 @@
(defn left-mouse? [bevent]
(let [event (.-nativeEvent ^js bevent)]
(= 1 (.-which event))))
(defn open-new-window
([uri]
(open-new-window uri "_blank"))
([uri name]
(js/window.open (str uri) name)))
(defn browser-back
[]
(.back (.-history js/window)))

View file

@ -10,6 +10,7 @@
[app.common.uri :as u]
[app.config :as cfg]
[app.util.browser-history :as bhistory]
[app.util.dom :as dom]
[app.util.timers :as ts]
[beicon.core :as rx]
[goog.events :as e]
@ -110,14 +111,13 @@
uri (-> (u/uri cfg/public-uri)
(assoc :fragment path))
name (str (name id) "-" (:file-id params))]
(js/window.open (str uri) name))))
(dom/open-new-window (str uri) name))))
(defn nav-new-window
([id] (nav-new-window id nil nil))
([id params] (nav-new-window id params nil))
([id params qparams] (NavigateNewWindow. id params qparams)))
(defn nav-new-window*
[{:keys [rname path-params query-params name]}]
(ptk/reify ::nav-new-window
@ -127,17 +127,14 @@
path (resolve router rname path-params query-params)
uri (-> (u/uri cfg/public-uri)
(assoc :fragment path))]
(js/window.open (str uri) name)))))
(dom/open-new-window (str uri) name)))))
(defn nav-back
[]
(ptk/reify ::nav-back
ptk/EffectEvent
(effect [_ _ _]
(ts/asap #(.back (.-history js/window))))))
(ts/asap dom/browser-back))))
(defn nav-back-local
"Navigate back only if the previous page is in penpot app."