From 8eae8929835314eda7418d851bc18d0ab5d90f85 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 31 Mar 2022 00:28:34 +0200 Subject: [PATCH] :fire: Remove old and already deprecated utils.data ns --- .../src/app/main/ui/workspace/libraries.cljs | 2 +- .../app/main/ui/workspace/sidebar/assets.cljs | 2 +- .../sidebar/options/shapes/svg_raw.cljs | 4 +- frontend/src/app/util/data.cljs | 169 ------------------ frontend/src/app/util/strings.cljs | 8 +- 5 files changed, 11 insertions(+), 174 deletions(-) delete mode 100644 frontend/src/app/util/data.cljs diff --git a/frontend/src/app/main/ui/workspace/libraries.cljs b/frontend/src/app/main/ui/workspace/libraries.cljs index cee01fae2..c9742069f 100644 --- a/frontend/src/app/main/ui/workspace/libraries.cljs +++ b/frontend/src/app/main/ui/workspace/libraries.cljs @@ -13,9 +13,9 @@ [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.icons :as i] - [app.util.data :refer [matches-search]] [app.util.dom :as dom] [app.util.i18n :as i18n :refer [tr]] + [app.util.strings :refer [matches-search]] [cuerdas.core :as str] [okulary.core :as l] [rumext.alpha :as mf])) diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs index 9f8032f39..5d9023544 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs @@ -32,12 +32,12 @@ [app.main.ui.context :as ctx] [app.main.ui.icons :as i] [app.main.ui.workspace.sidebar.options.menus.typography :refer [typography-entry]] - [app.util.data :refer [matches-search]] [app.util.dom :as dom] [app.util.dom.dnd :as dnd] [app.util.i18n :as i18n :refer [tr]] [app.util.keyboard :as kbd] [app.util.router :as rt] + [app.util.strings :refer [matches-search]] [cljs.spec.alpha :as s] [cuerdas.core :as str] [okulary.core :as l] diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/svg_raw.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/svg_raw.cljs index fa209083e..c21726de8 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/svg_raw.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/svg_raw.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.workspace.sidebar.options.shapes.svg-raw (:require [app.common.colors :as clr] + [app.common.data :as d] [app.main.ui.workspace.sidebar.options.menus.blur :refer [blur-menu]] [app.main.ui.workspace.sidebar.options.menus.constraints :refer [constraint-attrs constraints-menu]] [app.main.ui.workspace.sidebar.options.menus.fill :refer [fill-attrs fill-menu]] @@ -15,7 +16,6 @@ [app.main.ui.workspace.sidebar.options.menus.stroke :refer [stroke-attrs stroke-menu]] [app.main.ui.workspace.sidebar.options.menus.svg-attrs :refer [svg-attrs-menu]] [app.util.color :as uc] - [app.util.data :as d] [cuerdas.core :as str] [rumext.alpha :as mf])) @@ -75,7 +75,7 @@ stroke-width (-> (or (get-in shape [:content :attrs :stroke-width]) (get-in shape [:content :attrs :style :stroke-width]) "1") - (d/parse-int)) + (d/parse-integer)) stroke-values (if (empty? stroke-values) {:stroke-color stroke-color diff --git a/frontend/src/app/util/data.cljs b/frontend/src/app/util/data.cljs deleted file mode 100644 index 0c0d500af..000000000 --- a/frontend/src/app/util/data.cljs +++ /dev/null @@ -1,169 +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.data - "A collection of data transformation utils." - (:require [cljs.reader :as r] - [cuerdas.core :as str])) - -;; TODO: partially move to app.common.data - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Data structure manipulation -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defn index-by - "Return a indexed map of the collection - keyed by the result of executing the getter - over each element of the collection." - [getter coll] - (persistent! - (reduce #(assoc! %1 (getter %2) %2) (transient {}) coll))) - -(def index-by-id #(index-by :id %)) - -(defn without-nils - "Given a map, return a map removing key-value - pairs when value is `nil`." - [data] - (into {} (remove (comp nil? second) data))) - -(defn without-keys - "Return a map without the keys provided - in the `keys` parameter." - [data keys] - (persistent! - (reduce #(dissoc! %1 %2) (transient data) keys))) - -(defn dissoc-in - [m [k & ks :as _keys]] - (if ks - (if-let [nextmap (get m k)] - (let [newmap (dissoc-in nextmap ks)] - (if (seq newmap) - (assoc m k newmap) - (dissoc m k))) - m) - (dissoc m k))) - -(defn index-of - "Return the first index when appears the `v` value - in the `coll` collection." - [coll v] - (first (keep-indexed (fn [idx x] - (when (= v x) idx)) - coll))) - -(defn replace-by-id - ([value] - (map (fn [item] - (if (= (:id item) (:id value)) - value - item)))) - ([coll value] - (sequence (replace-by-id value) coll))) - -(defn deep-merge - "Like merge, but merges maps recursively." - [& maps] - (if (every? map? maps) - (apply merge-with deep-merge maps) - (last maps))) - -(defn conj-or-disj - "Given a set, and an element remove that element from set - if it exists or add it if it does not exists." - [s v] - (if (contains? s v) - (disj s v) - (conj s v))) - -(defn enumerate - ([items] (enumerate items 0)) - ([items start] - (loop [idx start - items items - res []] - (if (empty? items) - res - (recur (inc idx) - (rest items) - (conj res [idx (first items)])))))) - -(defn concatv - [& colls] - (loop [colls colls - result []] - (if (seq colls) - (recur (rest colls) (reduce conj result (first colls))) - result))) - -(defn seek - ([pred coll] - (seek pred coll nil)) - ([pred coll not-found] - (reduce (fn [_ x] - (if (pred x) - (reduced x) - not-found)) - not-found coll))) - -(defn remove-equal-values [m1 m2] - (if (and (map? m1) (map? m2) (not (nil? m1)) (not (nil? m2))) - (->> m1 - (remove (fn [[k v]] (= (k m2) v))) - (into {})) - m1)) - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Numbers Parsing -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defn nan? - [v] - (js/isNaN v)) - -(defn read-string - [v] - (r/read-string v)) - -(defn parse-int - ([v] - (parse-int v nil)) - ([v default] - (let [v (js/parseInt v 10)] - (if (or (not v) (nan? v)) - default - v)))) - -(defn parse-float - ([v] - (parse-float v nil)) - ([v default] - (let [v (js/parseFloat v)] - (if (or (not v) (nan? v)) - default - v)))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Other -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defn normalize-props - [props] - (clj->js props :keyword-fn (fn [key] - (if (or (= key :class) (= key :class-name)) - "className" - (str/camel (name key)))))) - -(defn matches-search - [name search-term] - (if (str/empty? search-term) - true - (let [st (str/trim (str/lower search-term)) - nm (str/trim (str/lower name))] - (str/includes? nm st)))) diff --git a/frontend/src/app/util/strings.cljs b/frontend/src/app/util/strings.cljs index e51bbe86d..c1d6ad2b4 100644 --- a/frontend/src/app/util/strings.cljs +++ b/frontend/src/app/util/strings.cljs @@ -8,7 +8,6 @@ (:require [cuerdas.core :as str])) - (def ^:const trail-zeros-regex-1 #"\.0+$") (def ^:const trail-zeros-regex-2 #"(\.\d*[^0])0+$") @@ -36,3 +35,10 @@ (catch :default _ (str num)))) +(defn matches-search + [name search-term] + (if (str/empty? search-term) + true + (let [st (str/trim (str/lower search-term)) + nm (str/trim (str/lower name))] + (str/includes? nm st))))