0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-12 23:11:23 -05:00

Merge remote-tracking branch 'origin/staging' into develop

This commit is contained in:
Andrey Antukh 2025-03-21 11:17:26 +01:00
commit 8c302e314f
8 changed files with 117 additions and 83 deletions

View file

@ -390,13 +390,13 @@
[:before-path [:maybe [:vector :string]]]
[:before-group [:maybe :boolean]]]]
[:move-token-set-group-before
[:map {:title "MoveTokenSetGroupBefore"}
[:type [:= :move-token-set-group-before]]
[:move-token-set-group
[:map {:title "MoveTokenSetGroup"}
[:type [:= :move-token-set-group]]
[:from-path [:vector :string]]
[:to-path [:vector :string]]
[:before-path [:maybe [:vector :string]]]
[:before-group? [:maybe :boolean]]]]
[:before-group [:maybe :boolean]]]]
[:set-token-theme
[:map {:title "SetTokenThemeChange"}
@ -1057,11 +1057,11 @@
(ctob/ensure-tokens-lib)
(ctob/move-set from-path to-path before-path before-group))))
(defmethod process-change :move-token-set-group-before
[data {:keys [from-path to-path before-path before-group?]}]
(defmethod process-change :move-token-set-group
[data {:keys [from-path to-path before-path before-group]}]
(update data :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

View file

@ -824,19 +824,19 @@
:before-group prev-before-group?})
(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
(update :redo-changes conj {:type :move-token-set-group-before
(update :redo-changes conj {:type :move-token-set-group
:from-path from-path
:to-path to-path
:before-path before-path
:before-group? before-group?})
(update :undo-changes conj {:type :move-token-set-group-before
:before-group before-group?})
(update :undo-changes conj {:type :move-token-set-group
:from-path to-path
:to-path from-path
:before-path prev-before-path
:before-group? prev-before-group?})
:before-group prev-before-group?})
(apply-changes-local)))
(defn set-tokens-lib

View file

@ -140,7 +140,7 @@
(defn generate-move-token-set-group
"Create changes for dropping a token set or token set group.
Throws for impossible moves"
[changes tokens-lib drop-opts]
(if-let [drop-opts' (calculate-move-token-set-or-set-group tokens-lib drop-opts)]
(pcb/move-token-set-group-before changes drop-opts')
[changes tokens-lib params]
(if-let [params (calculate-move-token-set-or-set-group tokens-lib params)]
(pcb/move-token-set-group changes params)
changes))

View file

@ -799,7 +799,7 @@
(map-indexed (fn [index item]
(assoc item :index index))))))
(defn flatten-nested-tokens-json
(defn- flatten-nested-tokens-json
"Recursively flatten the dtcg token structure, joining keys with '.'."
[tokens token-path]
(reduce-kv
@ -1290,54 +1290,85 @@ Will return a value that matches this schema:
(assoc-in ["$metadata" "activeThemes"] active-themes-clear)
(assoc-in ["$metadata" "activeSets"] active-sets))))
(decode-dtcg-json [_ parsed-json]
(let [metadata (get parsed-json "$metadata")
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)
(decode-dtcg-json [_ data]
(assert (map? data) "expected a map data structure for `data`")
set-order (get metadata "tokenSetOrder")
name->pos (into {} (map-indexed (fn [idx itm] [itm idx]) set-order))
sets-data' (sort-by (comp name->pos first) sets-data)
lib (make-tokens-lib)
lib' (->> sets-data'
(reduce (fn [lib [set-name tokens]]
(add-set lib (make-token-set
:name set-name
:tokens (flatten-nested-tokens-json tokens ""))))
lib))
lib' (cond-> lib'
(and (seq active-sets) (= #{hidden-token-theme-path} active-themes))
(update-theme hidden-token-theme-group hidden-token-theme-name
#(assoc % :sets active-sets)))]
(if-let [themes-data (seq themes-data)]
(as-> lib' $
(reduce
(fn [lib {:strs [name group description is-source id modified-at sets]}]
(add-theme lib (TokenTheme. name
(or group "")
description
(some? is-source)
(or id (str (uuid/next)))
(or (some-> modified-at
(dt/parse-instant))
(dt/now))
(set sets))))
$ themes-data)
(reduce
(fn [lib active-theme]
(let [[group name] (split-token-theme-path active-theme)]
(activate-theme lib group name)))
$ active-themes))
lib')))
(let [metadata (get data "$metadata")
xf-normalize-set-name
(map normalize-set-name)
sets
(dissoc data "$themes" "$metadata")
ordered-sets
(-> (d/ordered-set)
(into xf-normalize-set-name (get metadata "tokenSetOrder"))
(into xf-normalize-set-name (keys sets)))
active-sets
(or (->> (get metadata "activeSets")
(into #{} xf-normalize-set-name)
(not-empty))
#{})
active-themes
(or (->> (get metadata "activeThemes")
(into #{})
(not-empty))
#{hidden-token-theme-path})
themes
(->> (get data "$themes")
(map (fn [theme]
(make-token-theme
:name (get theme "name")
:group (get theme "group")
:is-source (get theme "is-source")
:id (get theme "id")
: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]
(let [other-data (select-keys parsed-legacy-json ["$themes" "$metadata"])

View file

@ -91,16 +91,21 @@
(ptk/reify ::update-token-theme
ptk/WatchEvent
(watch [it state _]
(let [tokens-lib (get-tokens-lib state)
data (dsh/lookup-file-data state)
prev-token-theme (some-> tokens-lib (ctob/get-theme group name))
changes (-> (pcb/empty-changes it)
(pcb/with-library-data data)
(pcb/set-token-theme (:group prev-token-theme)
(:name prev-token-theme)
token-theme))]
(rx/of
(dch/commit-changes changes))))))
(let [data (dsh/lookup-file-data state)
tokens-lib (get data :tokens-lib)]
(if (and (or (not= group (:group token-theme))
(not= name (:name token-theme)))
(ctob/get-theme tokens-lib
(:group token-theme)
(:name token-theme)))
(rx/of (ntf/show {:content (tr "errors.token-theme-already-exists")
:type :toast
: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]
(ptk/reify ::toggle-token-theme-active?

View file

@ -253,7 +253,6 @@
(watch [_ state _]
(let [team-id (:current-team-id state)
file-id (:id file)]
(rx/of (dwn/initialize team-id file-id)
(dwsl/initialize-shape-layout)
(fetch-libraries file-id))))))

View file

@ -308,7 +308,6 @@
;; Form / Modal handlers
on-back #(set-state (constantly {:type :themes-overview}))
on-submit #(st/emit! (wdt/update-token-theme [(:group theme) (:name theme)] %))
disabled? (-> (:name theme-state)
(str/trim)
(str/empty?))
@ -320,16 +319,16 @@
on-save-form
(mf/use-fn
(mf/deps theme-state on-submit)
(mf/deps theme theme-state)
(fn [e]
(dom/prevent-default e)
(let [theme (-> theme-state
(update :name str/trim)
(update :group str/trim)
(update :description str/trim))]
(let [theme' (-> theme-state
(update :name str/trim)
(update :group str/trim)
(update :description str/trim))]
(when-not (str/empty? (:name theme))
(on-submit theme)))
(on-back)))
(st/emit! (wdt/update-token-theme [(:group theme) (:name theme)] theme')))
(on-back))))
close-modal
(mf/use-fn

View file

@ -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
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
msgid "workspace.token.label.group"