mirror of
https://github.com/penpot/penpot.git
synced 2025-03-12 07:41:43 -05:00
♻️ Merge libraries_common_helpers into libraries_helpers
This commit is contained in:
parent
2e18ce9323
commit
a8738b44a1
5 changed files with 97 additions and 12 deletions
|
@ -12,7 +12,7 @@
|
||||||
[app.common.files.changes :as cp]
|
[app.common.files.changes :as cp]
|
||||||
[app.common.files.changes-builder :as fcb]
|
[app.common.files.changes-builder :as fcb]
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
[app.common.files.libraries-common-helpers :as cflch]
|
[app.common.files.libraries-helpers :as cflh]
|
||||||
[app.common.files.migrations :as fmg]
|
[app.common.files.migrations :as fmg]
|
||||||
[app.common.files.shapes-helpers :as cfsh]
|
[app.common.files.shapes-helpers :as cfsh]
|
||||||
[app.common.files.validate :as cfv]
|
[app.common.files.validate :as cfv]
|
||||||
|
@ -1451,7 +1451,7 @@
|
||||||
(cons shape children))
|
(cons shape children))
|
||||||
|
|
||||||
[_ _ changes2]
|
[_ _ changes2]
|
||||||
(cflch/generate-add-component nil
|
(cflh/generate-add-component nil
|
||||||
[shape]
|
[shape]
|
||||||
(:objects page)
|
(:objects page)
|
||||||
(:id page)
|
(:id page)
|
||||||
|
|
|
@ -25,8 +25,9 @@
|
||||||
[app.common.types.shape-tree :as ctst]
|
[app.common.types.shape-tree :as ctst]
|
||||||
[app.common.types.shape.layout :as ctl]
|
[app.common.types.shape.layout :as ctl]
|
||||||
[app.common.types.typography :as cty]
|
[app.common.types.typography :as cty]
|
||||||
[cljs.spec.alpha :as s]
|
[app.common.uuid :as uuid]
|
||||||
[clojure.set :as set]))
|
[clojure.set :as set]
|
||||||
|
[clojure.spec.alpha :as s]))
|
||||||
|
|
||||||
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
|
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
|
||||||
(log/set-level! :warn)
|
(log/set-level! :warn)
|
||||||
|
@ -1662,3 +1663,92 @@
|
||||||
(if (cfh/page? container)
|
(if (cfh/page? container)
|
||||||
(assoc change :page-id (:id container))
|
(assoc change :page-id (:id container))
|
||||||
(assoc change :component-id (:id container))))
|
(assoc change :component-id (:id container))))
|
||||||
|
|
||||||
|
(defn generate-add-component-changes
|
||||||
|
[changes root objects file-id page-id components-v2]
|
||||||
|
(let [name (:name root)
|
||||||
|
[path name] (cfh/parse-path-name name)
|
||||||
|
|
||||||
|
[root-shape new-shapes updated-shapes]
|
||||||
|
(if-not components-v2
|
||||||
|
(ctn/make-component-shape root objects file-id components-v2)
|
||||||
|
(ctn/convert-shape-in-component root objects file-id))
|
||||||
|
|
||||||
|
changes (-> changes
|
||||||
|
(pcb/add-component (:id root-shape)
|
||||||
|
path
|
||||||
|
name
|
||||||
|
new-shapes
|
||||||
|
updated-shapes
|
||||||
|
(:id root)
|
||||||
|
page-id))]
|
||||||
|
[root-shape changes]))
|
||||||
|
|
||||||
|
(defn generate-add-component
|
||||||
|
"If there is exactly one id, and it's a frame (or a group in v1), and not already a component,
|
||||||
|
use it as root. Otherwise, create a frame (v2) or group (v1) that contains all ids. Then, make a
|
||||||
|
component with it, and link all shapes to their corresponding one in the component."
|
||||||
|
[it shapes objects page-id file-id components-v2 prepare-create-group prepare-create-board]
|
||||||
|
|
||||||
|
(let [changes (pcb/empty-changes it page-id)
|
||||||
|
shapes-count (count shapes)
|
||||||
|
first-shape (first shapes)
|
||||||
|
|
||||||
|
from-singe-frame?
|
||||||
|
(and (= 1 shapes-count)
|
||||||
|
(cfh/frame-shape? first-shape))
|
||||||
|
|
||||||
|
[root changes old-root-ids]
|
||||||
|
(if (and (= shapes-count 1)
|
||||||
|
(or (and (cfh/group-shape? first-shape)
|
||||||
|
(not components-v2))
|
||||||
|
(cfh/frame-shape? first-shape))
|
||||||
|
(not (ctk/instance-head? first-shape)))
|
||||||
|
[first-shape
|
||||||
|
(-> (pcb/empty-changes it page-id)
|
||||||
|
(pcb/with-objects objects))
|
||||||
|
(:shapes first-shape)]
|
||||||
|
|
||||||
|
(let [root-name (if (= 1 shapes-count)
|
||||||
|
(:name first-shape)
|
||||||
|
"Component 1")
|
||||||
|
|
||||||
|
shape-ids (into (d/ordered-set) (map :id) shapes)
|
||||||
|
|
||||||
|
[root changes]
|
||||||
|
(if-not components-v2
|
||||||
|
(prepare-create-group it ; These functions needs to be passed as argument
|
||||||
|
objects ; to avoid a circular dependence
|
||||||
|
page-id
|
||||||
|
shapes
|
||||||
|
root-name
|
||||||
|
(not (ctk/instance-head? first-shape)))
|
||||||
|
(prepare-create-board changes
|
||||||
|
(uuid/next)
|
||||||
|
(:parent-id first-shape)
|
||||||
|
objects
|
||||||
|
shape-ids
|
||||||
|
nil
|
||||||
|
root-name
|
||||||
|
true))]
|
||||||
|
|
||||||
|
[root changes shape-ids]))
|
||||||
|
|
||||||
|
changes
|
||||||
|
(cond-> changes
|
||||||
|
(not from-singe-frame?)
|
||||||
|
(pcb/update-shapes
|
||||||
|
(:shapes root)
|
||||||
|
(fn [shape]
|
||||||
|
(assoc shape :constraints-h :scale :constraints-v :scale))))
|
||||||
|
|
||||||
|
objects' (assoc objects (:id root) root)
|
||||||
|
|
||||||
|
[root-shape changes] (generate-add-component-changes changes root objects' file-id page-id components-v2)
|
||||||
|
|
||||||
|
changes (pcb/update-shapes changes
|
||||||
|
old-root-ids
|
||||||
|
#(dissoc % :component-root)
|
||||||
|
[:component-root])]
|
||||||
|
|
||||||
|
[root (:id root-shape) changes]))
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
[app.common.files.changes :as ch]
|
[app.common.files.changes :as ch]
|
||||||
[app.common.files.changes-builder :as pcb]
|
[app.common.files.changes-builder :as pcb]
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
[app.common.files.libraries-common-helpers :as cflch]
|
|
||||||
[app.common.files.libraries-helpers :as cflh]
|
[app.common.files.libraries-helpers :as cflh]
|
||||||
[app.common.files.shapes-helpers :as cfsh]
|
[app.common.files.shapes-helpers :as cfsh]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
|
@ -352,7 +351,7 @@
|
||||||
parents (into #{} (map :parent-id) shapes)]
|
parents (into #{} (map :parent-id) shapes)]
|
||||||
(when-not (empty? shapes)
|
(when-not (empty? shapes)
|
||||||
(let [[root _ changes]
|
(let [[root _ changes]
|
||||||
(cflch/generate-add-component it shapes objects page-id file-id components-v2
|
(cflh/generate-add-component it shapes objects page-id file-id components-v2
|
||||||
dwg/prepare-create-group
|
dwg/prepare-create-group
|
||||||
cfsh/prepare-create-artboard-from-selection)]
|
cfsh/prepare-create-artboard-from-selection)]
|
||||||
(when-not (empty? (:redo-changes changes))
|
(when-not (empty? (:redo-changes changes))
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
[app.common.files.changes-builder :as pcb]
|
[app.common.files.changes-builder :as pcb]
|
||||||
[app.common.files.focus :as cpf]
|
[app.common.files.focus :as cpf]
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
[app.common.files.libraries-common-helpers :as cflch]
|
|
||||||
[app.common.files.libraries-helpers :as cflh]
|
[app.common.files.libraries-helpers :as cflh]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.rect :as grc]
|
[app.common.geom.rect :as grc]
|
||||||
|
@ -498,7 +497,7 @@
|
||||||
regenerate-component
|
regenerate-component
|
||||||
(fn [changes shape]
|
(fn [changes shape]
|
||||||
(let [components-v2 (dm/get-in library-data [:options :components-v2])
|
(let [components-v2 (dm/get-in library-data [:options :components-v2])
|
||||||
[_ changes] (cflch/generate-add-component-changes changes shape objects file-id (:id page) components-v2)]
|
[_ changes] (cflh/generate-add-component-changes changes shape objects file-id (:id page) components-v2)]
|
||||||
changes))
|
changes))
|
||||||
|
|
||||||
new-obj
|
new-obj
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
(ns frontend-tests.helpers.pages
|
(ns frontend-tests.helpers.pages
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
|
||||||
[app.common.files.changes :as cp]
|
[app.common.files.changes :as cp]
|
||||||
[app.common.files.changes-builder :as pcb]
|
[app.common.files.changes-builder :as pcb]
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
|
@ -17,8 +16,6 @@
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.workspace.groups :as dwg]
|
[app.main.data.workspace.groups :as dwg]
|
||||||
[app.main.data.workspace.layout :as layout]
|
[app.main.data.workspace.layout :as layout]
|
||||||
[app.main.data.workspace.libraries-helpers :as dwlh]
|
|
||||||
[app.main.data.workspace.shapes :as dwsh]
|
|
||||||
[app.main.data.workspace.state-helpers :as wsh]))
|
[app.main.data.workspace.state-helpers :as wsh]))
|
||||||
|
|
||||||
;; ---- Helpers to manage pages and objects
|
;; ---- Helpers to manage pages and objects
|
||||||
|
@ -161,7 +158,7 @@
|
||||||
(pcb/with-objects objects))
|
(pcb/with-objects objects))
|
||||||
|
|
||||||
[new-shape changes]
|
[new-shape changes]
|
||||||
(dwlh/generate-instantiate-component changes
|
(cflh/generate-instantiate-component changes
|
||||||
objects
|
objects
|
||||||
file-id
|
file-id
|
||||||
component-id
|
component-id
|
||||||
|
|
Loading…
Add table
Reference in a new issue