mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 20:31:38 +02:00
Merge remote-tracking branch 'origin/staging' into develop
This commit is contained in:
commit
8c302e314f
8 changed files with 117 additions and 83 deletions
|
@ -390,13 +390,13 @@
|
||||||
[:before-path [:maybe [:vector :string]]]
|
[:before-path [:maybe [:vector :string]]]
|
||||||
[:before-group [:maybe :boolean]]]]
|
[:before-group [:maybe :boolean]]]]
|
||||||
|
|
||||||
[:move-token-set-group-before
|
[:move-token-set-group
|
||||||
[:map {:title "MoveTokenSetGroupBefore"}
|
[:map {:title "MoveTokenSetGroup"}
|
||||||
[:type [:= :move-token-set-group-before]]
|
[:type [:= :move-token-set-group]]
|
||||||
[:from-path [:vector :string]]
|
[:from-path [:vector :string]]
|
||||||
[:to-path [:vector :string]]
|
[:to-path [:vector :string]]
|
||||||
[:before-path [:maybe [:vector :string]]]
|
[:before-path [:maybe [:vector :string]]]
|
||||||
[:before-group? [:maybe :boolean]]]]
|
[:before-group [:maybe :boolean]]]]
|
||||||
|
|
||||||
[:set-token-theme
|
[:set-token-theme
|
||||||
[:map {:title "SetTokenThemeChange"}
|
[:map {:title "SetTokenThemeChange"}
|
||||||
|
@ -1057,11 +1057,11 @@
|
||||||
(ctob/ensure-tokens-lib)
|
(ctob/ensure-tokens-lib)
|
||||||
(ctob/move-set from-path to-path before-path before-group))))
|
(ctob/move-set from-path to-path before-path before-group))))
|
||||||
|
|
||||||
(defmethod process-change :move-token-set-group-before
|
(defmethod process-change :move-token-set-group
|
||||||
[data {:keys [from-path to-path before-path before-group?]}]
|
[data {:keys [from-path to-path before-path before-group]}]
|
||||||
(update data :tokens-lib #(-> %
|
(update data :tokens-lib #(-> %
|
||||||
(ctob/ensure-tokens-lib)
|
(ctob/ensure-tokens-lib)
|
||||||
(ctob/move-set-group from-path to-path before-path before-group?))))
|
(ctob/move-set-group from-path to-path before-path before-group))))
|
||||||
|
|
||||||
;; === Operations
|
;; === Operations
|
||||||
|
|
||||||
|
|
|
@ -824,19 +824,19 @@
|
||||||
:before-group prev-before-group?})
|
:before-group prev-before-group?})
|
||||||
(apply-changes-local)))
|
(apply-changes-local)))
|
||||||
|
|
||||||
(defn move-token-set-group-before
|
(defn move-token-set-group
|
||||||
[changes {:keys [from-path to-path before-path before-group? prev-before-path prev-before-group?]}]
|
[changes {:keys [from-path to-path before-path before-group? prev-before-path prev-before-group?]}]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :move-token-set-group-before
|
(update :redo-changes conj {:type :move-token-set-group
|
||||||
:from-path from-path
|
:from-path from-path
|
||||||
:to-path to-path
|
:to-path to-path
|
||||||
:before-path before-path
|
:before-path before-path
|
||||||
:before-group? before-group?})
|
:before-group before-group?})
|
||||||
(update :undo-changes conj {:type :move-token-set-group-before
|
(update :undo-changes conj {:type :move-token-set-group
|
||||||
:from-path to-path
|
:from-path to-path
|
||||||
:to-path from-path
|
:to-path from-path
|
||||||
:before-path prev-before-path
|
:before-path prev-before-path
|
||||||
:before-group? prev-before-group?})
|
:before-group prev-before-group?})
|
||||||
(apply-changes-local)))
|
(apply-changes-local)))
|
||||||
|
|
||||||
(defn set-tokens-lib
|
(defn set-tokens-lib
|
||||||
|
|
|
@ -140,7 +140,7 @@
|
||||||
(defn generate-move-token-set-group
|
(defn generate-move-token-set-group
|
||||||
"Create changes for dropping a token set or token set group.
|
"Create changes for dropping a token set or token set group.
|
||||||
Throws for impossible moves"
|
Throws for impossible moves"
|
||||||
[changes tokens-lib drop-opts]
|
[changes tokens-lib params]
|
||||||
(if-let [drop-opts' (calculate-move-token-set-or-set-group tokens-lib drop-opts)]
|
(if-let [params (calculate-move-token-set-or-set-group tokens-lib params)]
|
||||||
(pcb/move-token-set-group-before changes drop-opts')
|
(pcb/move-token-set-group changes params)
|
||||||
changes))
|
changes))
|
||||||
|
|
|
@ -799,7 +799,7 @@
|
||||||
(map-indexed (fn [index item]
|
(map-indexed (fn [index item]
|
||||||
(assoc item :index index))))))
|
(assoc item :index index))))))
|
||||||
|
|
||||||
(defn flatten-nested-tokens-json
|
(defn- flatten-nested-tokens-json
|
||||||
"Recursively flatten the dtcg token structure, joining keys with '.'."
|
"Recursively flatten the dtcg token structure, joining keys with '.'."
|
||||||
[tokens token-path]
|
[tokens token-path]
|
||||||
(reduce-kv
|
(reduce-kv
|
||||||
|
@ -1290,54 +1290,85 @@ Will return a value that matches this schema:
|
||||||
(assoc-in ["$metadata" "activeThemes"] active-themes-clear)
|
(assoc-in ["$metadata" "activeThemes"] active-themes-clear)
|
||||||
(assoc-in ["$metadata" "activeSets"] active-sets))))
|
(assoc-in ["$metadata" "activeSets"] active-sets))))
|
||||||
|
|
||||||
(decode-dtcg-json [_ parsed-json]
|
(decode-dtcg-json [_ data]
|
||||||
(let [metadata (get parsed-json "$metadata")
|
(assert (map? data) "expected a map data structure for `data`")
|
||||||
sets-data (dissoc parsed-json "$themes" "$metadata")
|
|
||||||
themes-data (->> (get parsed-json "$themes")
|
|
||||||
(map (fn [theme]
|
|
||||||
(-> theme
|
|
||||||
(set/rename-keys {"selectedTokenSets" "sets"})
|
|
||||||
(update "sets" keys)))))
|
|
||||||
active-sets (get metadata "activeSets")
|
|
||||||
active-themes (get metadata "activeThemes")
|
|
||||||
active-themes (if (empty? active-themes)
|
|
||||||
#{hidden-token-theme-path}
|
|
||||||
active-themes)
|
|
||||||
|
|
||||||
set-order (get metadata "tokenSetOrder")
|
(let [metadata (get data "$metadata")
|
||||||
name->pos (into {} (map-indexed (fn [idx itm] [itm idx]) set-order))
|
|
||||||
sets-data' (sort-by (comp name->pos first) sets-data)
|
xf-normalize-set-name
|
||||||
lib (make-tokens-lib)
|
(map normalize-set-name)
|
||||||
lib' (->> sets-data'
|
|
||||||
(reduce (fn [lib [set-name tokens]]
|
sets
|
||||||
(add-set lib (make-token-set
|
(dissoc data "$themes" "$metadata")
|
||||||
:name set-name
|
|
||||||
:tokens (flatten-nested-tokens-json tokens ""))))
|
ordered-sets
|
||||||
lib))
|
(-> (d/ordered-set)
|
||||||
lib' (cond-> lib'
|
(into xf-normalize-set-name (get metadata "tokenSetOrder"))
|
||||||
(and (seq active-sets) (= #{hidden-token-theme-path} active-themes))
|
(into xf-normalize-set-name (keys sets)))
|
||||||
(update-theme hidden-token-theme-group hidden-token-theme-name
|
|
||||||
#(assoc % :sets active-sets)))]
|
active-sets
|
||||||
(if-let [themes-data (seq themes-data)]
|
(or (->> (get metadata "activeSets")
|
||||||
(as-> lib' $
|
(into #{} xf-normalize-set-name)
|
||||||
(reduce
|
(not-empty))
|
||||||
(fn [lib {:strs [name group description is-source id modified-at sets]}]
|
#{})
|
||||||
(add-theme lib (TokenTheme. name
|
|
||||||
(or group "")
|
active-themes
|
||||||
description
|
(or (->> (get metadata "activeThemes")
|
||||||
(some? is-source)
|
(into #{})
|
||||||
(or id (str (uuid/next)))
|
(not-empty))
|
||||||
(or (some-> modified-at
|
#{hidden-token-theme-path})
|
||||||
(dt/parse-instant))
|
|
||||||
(dt/now))
|
themes
|
||||||
(set sets))))
|
(->> (get data "$themes")
|
||||||
$ themes-data)
|
(map (fn [theme]
|
||||||
(reduce
|
(make-token-theme
|
||||||
(fn [lib active-theme]
|
:name (get theme "name")
|
||||||
(let [[group name] (split-token-theme-path active-theme)]
|
:group (get theme "group")
|
||||||
(activate-theme lib group name)))
|
:is-source (get theme "is-source")
|
||||||
$ active-themes))
|
:id (get theme "id")
|
||||||
lib')))
|
:modified-at (some-> (get theme "modified-at")
|
||||||
|
(dt/parse-instant))
|
||||||
|
:sets (into #{}
|
||||||
|
(comp (map key)
|
||||||
|
xf-normalize-set-name
|
||||||
|
(filter #(contains? ordered-sets %)))
|
||||||
|
(get theme "selectedTokenSets")))))
|
||||||
|
(not-empty))
|
||||||
|
|
||||||
|
library
|
||||||
|
(make-tokens-lib)
|
||||||
|
|
||||||
|
sets
|
||||||
|
(reduce-kv (fn [result name tokens]
|
||||||
|
(assoc result
|
||||||
|
(normalize-set-name name)
|
||||||
|
(flatten-nested-tokens-json tokens "")))
|
||||||
|
{}
|
||||||
|
sets)
|
||||||
|
|
||||||
|
library
|
||||||
|
(reduce (fn [library name]
|
||||||
|
(if-let [tokens (get sets name)]
|
||||||
|
(add-set library (make-token-set :name name :tokens tokens))
|
||||||
|
library))
|
||||||
|
library
|
||||||
|
ordered-sets)
|
||||||
|
|
||||||
|
library
|
||||||
|
(update-theme library hidden-token-theme-group hidden-token-theme-name
|
||||||
|
#(assoc % :sets active-sets))
|
||||||
|
|
||||||
|
library
|
||||||
|
(reduce add-theme library themes)
|
||||||
|
|
||||||
|
library
|
||||||
|
(reduce (fn [library theme-path]
|
||||||
|
(let [[group name] (split-token-theme-path theme-path)]
|
||||||
|
(activate-theme library group name)))
|
||||||
|
library
|
||||||
|
active-themes)]
|
||||||
|
|
||||||
|
library))
|
||||||
|
|
||||||
(decode-legacy-json [this parsed-legacy-json]
|
(decode-legacy-json [this parsed-legacy-json]
|
||||||
(let [other-data (select-keys parsed-legacy-json ["$themes" "$metadata"])
|
(let [other-data (select-keys parsed-legacy-json ["$themes" "$metadata"])
|
||||||
|
|
|
@ -91,16 +91,21 @@
|
||||||
(ptk/reify ::update-token-theme
|
(ptk/reify ::update-token-theme
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [tokens-lib (get-tokens-lib state)
|
(let [data (dsh/lookup-file-data state)
|
||||||
data (dsh/lookup-file-data state)
|
tokens-lib (get data :tokens-lib)]
|
||||||
prev-token-theme (some-> tokens-lib (ctob/get-theme group name))
|
(if (and (or (not= group (:group token-theme))
|
||||||
changes (-> (pcb/empty-changes it)
|
(not= name (:name token-theme)))
|
||||||
(pcb/with-library-data data)
|
(ctob/get-theme tokens-lib
|
||||||
(pcb/set-token-theme (:group prev-token-theme)
|
(:group token-theme)
|
||||||
(:name prev-token-theme)
|
(:name token-theme)))
|
||||||
token-theme))]
|
(rx/of (ntf/show {:content (tr "errors.token-theme-already-exists")
|
||||||
(rx/of
|
:type :toast
|
||||||
(dch/commit-changes changes))))))
|
:level :error
|
||||||
|
:timeout 9000}))
|
||||||
|
(let [changes (-> (pcb/empty-changes it)
|
||||||
|
(pcb/with-library-data data)
|
||||||
|
(pcb/set-token-theme group name token-theme))]
|
||||||
|
(rx/of (dch/commit-changes changes))))))))
|
||||||
|
|
||||||
(defn toggle-token-theme-active? [group name]
|
(defn toggle-token-theme-active? [group name]
|
||||||
(ptk/reify ::toggle-token-theme-active?
|
(ptk/reify ::toggle-token-theme-active?
|
||||||
|
|
|
@ -253,7 +253,6 @@
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [team-id (:current-team-id state)
|
(let [team-id (:current-team-id state)
|
||||||
file-id (:id file)]
|
file-id (:id file)]
|
||||||
|
|
||||||
(rx/of (dwn/initialize team-id file-id)
|
(rx/of (dwn/initialize team-id file-id)
|
||||||
(dwsl/initialize-shape-layout)
|
(dwsl/initialize-shape-layout)
|
||||||
(fetch-libraries file-id))))))
|
(fetch-libraries file-id))))))
|
||||||
|
|
|
@ -308,7 +308,6 @@
|
||||||
|
|
||||||
;; Form / Modal handlers
|
;; Form / Modal handlers
|
||||||
on-back #(set-state (constantly {:type :themes-overview}))
|
on-back #(set-state (constantly {:type :themes-overview}))
|
||||||
on-submit #(st/emit! (wdt/update-token-theme [(:group theme) (:name theme)] %))
|
|
||||||
disabled? (-> (:name theme-state)
|
disabled? (-> (:name theme-state)
|
||||||
(str/trim)
|
(str/trim)
|
||||||
(str/empty?))
|
(str/empty?))
|
||||||
|
@ -320,16 +319,16 @@
|
||||||
|
|
||||||
on-save-form
|
on-save-form
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps theme-state on-submit)
|
(mf/deps theme theme-state)
|
||||||
(fn [e]
|
(fn [e]
|
||||||
(dom/prevent-default e)
|
(dom/prevent-default e)
|
||||||
(let [theme (-> theme-state
|
(let [theme' (-> theme-state
|
||||||
(update :name str/trim)
|
(update :name str/trim)
|
||||||
(update :group str/trim)
|
(update :group str/trim)
|
||||||
(update :description str/trim))]
|
(update :description str/trim))]
|
||||||
(when-not (str/empty? (:name theme))
|
(when-not (str/empty? (:name theme))
|
||||||
(on-submit theme)))
|
(st/emit! (wdt/update-token-theme [(:group theme) (:name theme)] theme')))
|
||||||
(on-back)))
|
(on-back))))
|
||||||
|
|
||||||
close-modal
|
close-modal
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
|
|
|
@ -6743,7 +6743,7 @@ msgstr "Opacity must be between 0 and 100% or 0 and 1 (e.g. 50% or 0.5)."
|
||||||
|
|
||||||
#: src/app/main/ui/workspace/tokens/errors.cljs
|
#: src/app/main/ui/workspace/tokens/errors.cljs
|
||||||
msgid "workspace.token.stroke-width-range"
|
msgid "workspace.token.stroke-width-range"
|
||||||
msgstr "Stroke width must be between equal or bigger than 0."
|
msgstr "Stroke width must be greater than or equal to 0."
|
||||||
|
|
||||||
#: src/app/main/ui/workspace/tokens/modals/themes.cljs:196
|
#: src/app/main/ui/workspace/tokens/modals/themes.cljs:196
|
||||||
msgid "workspace.token.label.group"
|
msgid "workspace.token.label.group"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue