mirror of
https://github.com/penpot/penpot.git
synced 2025-07-23 16:07:24 +02:00
♻️ Reorganize workspace persistence related namespace
This commit is contained in:
parent
3ab3ea68b4
commit
c01e4e52f8
21 changed files with 503 additions and 536 deletions
|
@ -10,8 +10,10 @@
|
|||
[app.common.data.macros :as dm]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.logging :as log]
|
||||
[app.common.media :as cm]
|
||||
[app.util.globals :as globals]
|
||||
[app.util.object :as obj]
|
||||
[app.util.webapi :as wapi]
|
||||
[cuerdas.core :as str]
|
||||
[goog.dom :as dom]
|
||||
[promesa.core :as p]))
|
||||
|
@ -319,28 +321,11 @@
|
|||
(log/error :msg "Seems like the current browser does not support fullscreen api.")
|
||||
false)))
|
||||
|
||||
(defn ^boolean blob?
|
||||
(defn blob?
|
||||
[^js v]
|
||||
(when (some? v)
|
||||
(instance? js/Blob v)))
|
||||
|
||||
(defn create-blob
|
||||
"Create a blob from content."
|
||||
([content]
|
||||
(create-blob content "application/octet-stream"))
|
||||
([content mimetype]
|
||||
(js/Blob. #js [content] #js {:type mimetype})))
|
||||
|
||||
(defn revoke-uri
|
||||
[url]
|
||||
(js/URL.revokeObjectURL url))
|
||||
|
||||
(defn create-uri
|
||||
"Create a url from blob."
|
||||
[b]
|
||||
{:pre [(blob? b)]}
|
||||
(js/URL.createObjectURL b))
|
||||
|
||||
(defn make-node
|
||||
([namespace name]
|
||||
(.createElementNS globals/document namespace name))
|
||||
|
@ -432,21 +417,6 @@
|
|||
(when (some? node)
|
||||
(.getAttribute node (str "data-" attr))))
|
||||
|
||||
(defn mtype->extension [mtype]
|
||||
;; https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
|
||||
(case mtype
|
||||
"image/apng" ".apng"
|
||||
"image/avif" ".avif"
|
||||
"image/gif" ".gif"
|
||||
"image/jpeg" ".jpg"
|
||||
"image/png" ".png"
|
||||
"image/svg+xml" ".svg"
|
||||
"image/webp" ".webp"
|
||||
"application/zip" ".zip"
|
||||
"application/penpot" ".penpot"
|
||||
"application/pdf" ".pdf"
|
||||
nil))
|
||||
|
||||
(defn set-attribute! [^js node ^string attr value]
|
||||
(when (some? node)
|
||||
(.setAttribute node attr value)))
|
||||
|
@ -497,7 +467,7 @@
|
|||
(defn trigger-download-uri
|
||||
[filename mtype uri]
|
||||
(let [link (create-element "a")
|
||||
extension (mtype->extension mtype)
|
||||
extension (cm/mtype->extension mtype)
|
||||
filename (if (and extension (not (str/ends-with? filename extension)))
|
||||
(str/concat filename extension)
|
||||
filename)]
|
||||
|
@ -510,14 +480,14 @@
|
|||
|
||||
(defn trigger-download
|
||||
[filename blob]
|
||||
(trigger-download-uri filename (.-type ^js blob) (create-uri blob)))
|
||||
(trigger-download-uri filename (.-type ^js blob) (wapi/create-uri blob)))
|
||||
|
||||
(defn save-as
|
||||
[uri filename mtype description]
|
||||
|
||||
;; Only chrome supports the save dialog
|
||||
(if (obj/contains? globals/window "showSaveFilePicker")
|
||||
(let [extension (mtype->extension mtype)
|
||||
(let [extension (cm/mtype->extension mtype)
|
||||
opts {:suggestedName (str filename "." extension)
|
||||
:types [{:description description
|
||||
:accept { mtype [(str "." extension)]}}]}]
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; 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) UXBOX Labs SL
|
||||
|
||||
(ns app.util.uri
|
||||
(:require
|
||||
[app.util.object :as obj]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
(defn uri-name [url]
|
||||
(let [query-idx (str/last-index-of url "?")
|
||||
url (if (> query-idx 0) (subs url 0 query-idx) url)
|
||||
filename (->> (str/split url "/") (last))
|
||||
ext-idx (str/last-index-of filename ".")]
|
||||
(if (> ext-idx 0) (subs filename 0 ext-idx) filename)))
|
||||
|
||||
(defn data-uri->blob
|
||||
[data-uri]
|
||||
|
||||
(let [[mtype b64-data] (str/split data-uri ";base64,")
|
||||
|
||||
mtype (subs mtype (inc (str/index-of mtype ":")))
|
||||
|
||||
decoded (.atob js/window b64-data)
|
||||
size (.-length decoded)
|
||||
|
||||
content (js/Uint8Array. size)]
|
||||
|
||||
(doseq [i (range 0 size)]
|
||||
(obj/set! content i (.charCodeAt decoded i)))
|
||||
|
||||
(js/Blob. #js [content] #js {"type" mtype})))
|
|
@ -37,7 +37,7 @@
|
|||
[file]
|
||||
(file-reader #(.readAsDataURL ^js %1 file)))
|
||||
|
||||
(defn ^boolean blob?
|
||||
(defn blob?
|
||||
[v]
|
||||
(instance? js/Blob v))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue