mirror of
https://github.com/penpot/penpot.git
synced 2026-08-04 20:09:05 +00:00
🔧 Normalize text nodes comparison, to be used in tokens detach
This commit is contained in:
parent
1c8d26faaf
commit
5f8d9740d6
@ -9,7 +9,7 @@
|
|||||||
data resources."
|
data resources."
|
||||||
(:refer-clojure :exclude [read-string hash-map merge name update-vals
|
(:refer-clojure :exclude [read-string hash-map merge name update-vals
|
||||||
parse-double group-by iteration concat mapcat
|
parse-double group-by iteration concat mapcat
|
||||||
parse-uuid max min regexp? array?])
|
parse-uuid max min regexp? array? empty?])
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
(:require-macros [app.common.data]))
|
(:require-macros [app.common.data]))
|
||||||
|
|
||||||
@ -175,11 +175,17 @@
|
|||||||
(.isArray (class o))
|
(.isArray (class o))
|
||||||
false)))
|
false)))
|
||||||
|
|
||||||
|
(defn empty?
|
||||||
|
[val]
|
||||||
|
(if (or (coll? val) (string? val))
|
||||||
|
(clojure.core/empty? val)
|
||||||
|
(nil? val)))
|
||||||
|
|
||||||
(defn not-empty?
|
(defn not-empty?
|
||||||
[coll]
|
[val]
|
||||||
(if (coll? coll)
|
(if (or (coll? val) (string? val))
|
||||||
(boolean (seq coll))
|
(boolean (seq val))
|
||||||
(not (nil? coll))))
|
(some? val)))
|
||||||
|
|
||||||
(defn editable-collection?
|
(defn editable-collection?
|
||||||
[m]
|
[m]
|
||||||
|
|||||||
@ -201,6 +201,27 @@
|
|||||||
[text]
|
[text]
|
||||||
(subs text 0 (min 280 (count text))))
|
(subs text 0 (min 280 (count text))))
|
||||||
|
|
||||||
|
(defn- compare-text-attr
|
||||||
|
"Compare two attribute values and return true if they are different.
|
||||||
|
Take into account the following:
|
||||||
|
- Only process keys that belong to text node attrs (ignore deprecated
|
||||||
|
attributes or other things that may be attached).
|
||||||
|
- Consider nil values, empty strings or empty lists all equal.
|
||||||
|
- Normalize numeric values (legacy) into strings.
|
||||||
|
- No value is equal than the default value."
|
||||||
|
[key value1 value2]
|
||||||
|
(when (d/index-of text-node-attrs key)
|
||||||
|
(let [default-value (get default-text-attrs key)
|
||||||
|
normalize-value (fn [value]
|
||||||
|
(as-> value $
|
||||||
|
(if (number? $) (str $) $)
|
||||||
|
(if (or (d/empty? $) (= $ default-value))
|
||||||
|
nil
|
||||||
|
$)))
|
||||||
|
value1' (normalize-value value1)
|
||||||
|
value2' (normalize-value value2)]
|
||||||
|
(not= value1' value2'))))
|
||||||
|
|
||||||
(defn- compare-text-content
|
(defn- compare-text-content
|
||||||
"Given two content text structures, conformed by maps and vectors,
|
"Given two content text structures, conformed by maps and vectors,
|
||||||
compare them, and returns a set with the differences info.
|
compare them, and returns a set with the differences info.
|
||||||
@ -245,8 +266,7 @@
|
|||||||
;; If the key is not :text, and they are different, it is an attribute difference.
|
;; If the key is not :text, and they are different, it is an attribute difference.
|
||||||
;; Take into account that some processes remove empty attributes, so in some
|
;; Take into account that some processes remove empty attributes, so in some
|
||||||
;; cases we will compare [] with nil, and this is not a difference.
|
;; cases we will compare [] with nil, and this is not a difference.
|
||||||
(if (and (not= v1 v2)
|
(if (compare-text-attr k v1 v2)
|
||||||
(or (d/not-empty? v1) (d/not-empty? v2)))
|
|
||||||
(attribute-cb acc k)
|
(attribute-cb acc k)
|
||||||
acc))))
|
acc))))
|
||||||
#{}
|
#{}
|
||||||
|
|||||||
@ -331,7 +331,7 @@
|
|||||||
d/txt-merge
|
d/txt-merge
|
||||||
{:fills (ths/sample-fills-color :fill-color "#fabada")
|
{:fills (ths/sample-fills-color :fill-color "#fabada")
|
||||||
:font-size "1"
|
:font-size "1"
|
||||||
:letter-spacing "0"
|
:letter-spacing "2"
|
||||||
:font-family "Arial"}))
|
:font-family "Arial"}))
|
||||||
(:objects page)
|
(:objects page)
|
||||||
{})
|
{})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user