♻️ Remove ? char from shape attrs

This commit is contained in:
Andrey Antukh 2023-05-29 18:21:48 +02:00
parent 405aa66357
commit 6e7595f48c
36 changed files with 203 additions and 168 deletions

View file

@ -492,7 +492,7 @@
(let [components-to-delete (->> page
:objects
vals
(filter #(true? (:main-instance? %)))
(filter #(true? (:main-instance %)))
(map :component-id))
changes (reduce (fn [changes component-id]
@ -632,7 +632,7 @@
(rx/of (update-shape shape-id {:name name})))
;; Update the component in case if shape is a main instance
(when (:main-instance? shape)
(when (:main-instance shape)
(when-let [component-id (:component-id shape)]
(rx/of (dwl/rename-component component-id name)))))))))))
@ -743,7 +743,7 @@
;; Unmask groups whose mask have moved outside
(pcb/update-shapes groups-to-unmask
(fn [shape]
(assoc shape :masked-group? false)))
(assoc shape :masked-group false)))
;; Detach shapes moved out of their component
(pcb/update-shapes shapes-to-detach ctk/detach-shape)
@ -751,12 +751,12 @@
;; Make non root a component moved inside another one
(pcb/update-shapes shapes-to-deroot
(fn [shape]
(assoc shape :component-root? nil)))
(assoc shape :component-root nil)))
;; Make root a subcomponent moved outside its parent component
(pcb/update-shapes shapes-to-reroot
(fn [shape]
(assoc shape :component-root? true)))
(assoc shape :component-root true)))
;; Reset constraints depending on the new parent
(pcb/update-shapes shapes-to-unconstraint
@ -856,7 +856,7 @@
;; removed, and it must be converted to a normal group.
(let [obj (get objects id)
parent (get objects (:parent-id obj))]
(if (and (:masked-group? parent)
(if (and (:masked-group parent)
(= id (first (:shapes parent)))
(not= (:id parent) parent-id))
(conj group-ids (:id parent))
@ -1801,10 +1801,9 @@
(-> shape
(assoc :frame-id frame-id :parent-id parent-id)
(cond-> detach?
(->
;; this is used later, if the paste needs to create a new component from the detached shape
(assoc :saved-component-root? (:component-root? shape))
ctk/detach-shape))
;; this is used later, if the paste needs to create a new component from the detached shape
(-> (assoc :saved-component-root (:component-root shape))
(ctk/detach-shape)))
;; if is a text, remove references to external typographies
(cond-> (= (:type shape) :text)
(ctt/remove-external-typographies file-id)))))

View file

@ -292,7 +292,7 @@
(pcb/update-shapes [(:id group)]
(fn [group]
(assoc group
:masked-group? true
:masked-group true
:selrect (:selrect first-shape)
:points (:points first-shape)
:transform (:transform first-shape)
@ -321,7 +321,7 @@
(-> changes
(pcb/update-shapes [(:id mask)]
(fn [shape]
(dissoc shape :masked-group?)))
(dissoc shape :masked-group)))
(pcb/resize-parents [(:id mask)])))
(-> (pcb/empty-changes it page-id)
(pcb/with-objects objects))

View file

@ -74,8 +74,8 @@
[(assoc root
:component-id new-id
:component-file file-id
:component-root? true
:main-instance? true)]]))
:component-root true
:main-instance true)]]))
changes (-> changes
(pcb/add-component (:id root-shape)
@ -135,7 +135,7 @@
position (gpt/point (:x main-instance-shape) (:y main-instance-shape))
component-instance-extra-data (if components-v2 {:main-instance? true} {})
component-instance-extra-data (if components-v2 {:main-instance true} {})
[new-instance-shape new-instance-shapes]
(when (and (some? main-instance-page) (some? main-instance-shape))
@ -204,7 +204,7 @@
(let [shape (ctn/get-shape container shape-id)]
(if (and (ctk/instance-head? shape) (not first))
;; Subinstances are not detached, but converted in top instances
(pcb/update-shapes changes [(:id shape)] #(assoc % :component-root? true))
(pcb/update-shapes changes [(:id shape)] #(assoc % :component-root true))
;; Otherwise, detach the shape and all children
(let [children-ids (:shapes shape)]
(reduce #(generate-detach-recursive %1 container %2 false)
@ -499,7 +499,7 @@
;; * IF THE INITIAL SHAPE IS THE SUBINSTANCE, the sync is done against
;; the remote component. Therefore, IShape-2-2-1 is synched with
;; Shape-1-1. Then the "touched" flags are reset, and the
;; "remote-synced?" flag is set (it will be set until the shape is
;; "remote-synced" flag is set (it will be set until the shape is
;; touched again or it's synced forced normal or inverse with the
;; near component).
;;
@ -509,19 +509,19 @@
;; cleared. Then, the "touched" flags THAT ARE TRUE are copied to
;; Shape-2-2-1. This may cause that Shape-2-2-1 is now touched respect
;; to Shape-1-1, and so, some attributes are not copied in a subsequent
;; normal sync. Or, if "remote-synced?" flag is set in IShape-2-2-1,
;; all touched flags are cleared in Shape-2-2-1 and "remote-synced?"
;; normal sync. Or, if "remote-synced" flag is set in IShape-2-2-1,
;; all touched flags are cleared in Shape-2-2-1 and "remote-synced"
;; is removed.
;;
;; * IN AN INVERSE SYNC INITIATED IN THE SUBINSTANCE, the update is done
;; to the remote component. E.g. IShape-2-2-1 attributes are copied into
;; Shape-1-1, and then touched cleared and "remote-synced?" flag set.
;; Shape-1-1, and then touched cleared and "remote-synced" flag set.
;;
;; #### WARNING: there are two conditions that are invisible to user:
;; - When the near shape (Shape-2-2-1) is touched respect the remote
;; one (Shape-1-1), there is no asterisk displayed anywhere.
;; - When the instance shape (IShape-2-2-1) is synced with the remote
;; shape (remote-synced? = true), the user will see that this shape
;; shape (remote-synced = true), the user will see that this shape
;; is different than the one in the near component (Shape-2-2-1)
;; but it's not touched.
@ -540,7 +540,7 @@
shape-main (when component
(ctf/get-ref-shape library component shape-inst))
initial-root? (:component-root? shape-inst)
initial-root? (:component-root shape-inst)
root-inst shape-inst
root-main (when component
@ -673,7 +673,7 @@
component (ctkl/get-component library (:component-id shape-inst))
shape-main (ctf/get-ref-shape library component shape-inst)
initial-root? (:component-root? shape-inst)
initial-root? (:component-root shape-inst)
root-inst shape-inst
root-main (ctf/get-component-root library component)]
@ -867,7 +867,7 @@
(assoc :shape-ref (:id original-shape))
set-remote-synced?
(assoc :remote-synced? true))))
(assoc :remote-synced true))))
update-original-shape (fn [original-shape _new-shape]
original-shape)
@ -967,8 +967,8 @@
:attr :component-file
:val (:component-file shape')}
{:type :set
:attr :component-root?
:val (:component-root? shape')}
:attr :component-root
:val (:component-root shape')}
{:type :set
:attr :shape-ref
:val (:shape-ref shape')}
@ -1087,7 +1087,7 @@
reset-touched?
nil
copy-touched?
(if (:remote-synced? origin-shape)
(if (:remote-synced origin-shape)
nil
(set/union
(:touched dest-shape)
@ -1117,7 +1117,7 @@
(log/info :msg (str "CHANGE-REMOTE-SYNCED? "
(if (cph/page? container) "[P] " "[C] ")
(:name shape))
:remote-synced? remote-synced?)
:remote-synced remote-synced?)
(-> changes
(update :redo-changes conj (make-change
container
@ -1125,14 +1125,14 @@
:id (:id shape)
:operations
[{:type :set-remote-synced
:remote-synced? remote-synced?}]}))
:remote-synced remote-synced?}]}))
(update :undo-changes d/preconj (make-change
container
{:type :mod-obj
:id (:id shape)
:operations
[{:type :set-remote-synced
:remote-synced? (:remote-synced? shape)}]}))))))
:remote-synced (:remote-synced shape)}]}))))))
(defn- update-attrs
"The main function that implements the attribute sync algorithm. Copy

View file

@ -50,7 +50,7 @@
[shape root transformed-shape transformed-root objects modif-tree]
(let [root
(cond
(:component-root? shape)
(:component-root shape)
shape
(nil? root)
@ -60,7 +60,7 @@
transformed-root
(cond
(:component-root? transformed-shape)
(:component-root transformed-shape)
transformed-shape
(nil? transformed-root)

View file

@ -422,8 +422,8 @@
parent-id (or parent-id frame-id)
name (:name obj)
is-component-root? (:saved-component-root? obj)
is-component-main? (:main-instance? obj)
is-component-root? (:saved-component-root obj)
is-component-main? (:main-instance obj)
regenerate-component
(fn [changes shape]
(let [components-v2 (dm/get-in library-data [:options :components-v2])
@ -436,9 +436,9 @@
:parent-id parent-id
:frame-id frame-id)
(dissoc :shapes
:main-instance?
:main-instance
:shape-ref
:use-for-thumbnail?)
:use-for-thumbnail)
(gsh/move delta)
(d/update-when :interactions #(ctsi/remap-interactions % ids-map objects))

View file

@ -197,7 +197,7 @@
;; converted to a normal group.
(let [obj (lookup id)
parent (lookup (:parent-id obj))]
(if (and (:masked-group? parent)
(if (and (:masked-group parent)
(= id (first (:shapes parent))))
(conj group-ids (:id parent))
group-ids)))
@ -265,7 +265,7 @@
(reduce (fn [components id]
(let [shape (get objects id)]
(if (and (= (:component-file shape) (:id file)) ;; Main instances should exist only in local file
(:main-instance? shape)) ;; but check anyway
(:main-instance shape)) ;; but check anyway
(conj components (:component-id shape))
components)))
[]
@ -289,7 +289,7 @@
(pcb/resize-parents all-parents)
(pcb/update-shapes groups-to-unmask
(fn [shape]
(assoc shape :masked-group? false)))
(assoc shape :masked-group false)))
(pcb/update-shapes (map :id interacting-shapes)
(fn [shape]
(d/update-when shape :interactions
@ -310,7 +310,6 @@
(let [[changes _all-parents] (real-delete-shapes-changes changes file page objects ids it components-v2)]
changes))
(defn- real-delete-shapes
[file page objects ids it components-v2]
(let [[changes all-parents] (real-delete-shapes-changes file page objects ids it components-v2)

View file

@ -37,7 +37,7 @@
:path i/curve
:rect i/box
:text i/text
:group (if (:masked-group? shape)
:group (if (:masked-group shape)
i/mask
i/folder)
:bool (case (:bool-type shape)

View file

@ -29,7 +29,7 @@
;; TODO: GRID ICON
:else
i/board-refactor)
i/board-refactor)
;; TODO -> THUMBNAIL ICON
:image i/img-refactor
:line i/path-refactor
@ -37,7 +37,7 @@
:path i/path-refactor
:rect i/rectangle-refactor
:text i/text-refactor
:group (if (:masked-group? shape)
:group (if (:masked-group shape)
i/mask-refactor
i/group-refactor)
:bool (case (:bool-type shape)
@ -60,4 +60,4 @@
:text i/text-refactor
:mask i/mask-refactor
:group i/group-refactor
nil)))
nil)))

View file

@ -70,7 +70,7 @@
image? (= :image (:type shape))
text? (= :text (:type shape))
path? (= :path (:type shape))
mask? (and group? (:masked-group? shape))
mask? (and group? (:masked-group shape))
bool? (= :bool (:type shape))
center (gsh/shape->center shape)]
(-> props
@ -137,8 +137,8 @@
(add! :typography-ref-file)
(add! :component-file)
(add! :component-id)
(add! :component-root?)
(add! :main-instance?)
(add! :component-root)
(add! :main-instance)
(add! :shape-ref))))
(defn prefix-keys [m]

View file

@ -22,7 +22,7 @@
childs (unchecked-get props "childs")
objects (unchecked-get props "objects")
render-id (mf/use-ctx muc/render-id)
masked-group? (:masked-group? shape)
masked-group? (:masked-group shape)
[mask childs] (if masked-group?
[(first childs) (rest childs)]

View file

@ -64,7 +64,7 @@
[:li {:ref item-ref
:class (dom/classnames
:component (not (nil? (:component-id item)))
:masked (:masked-group? item)
:masked (:masked-group item)
:selected selected?)}
[:div.element-list-body {:class (dom/classnames :selected selected?

View file

@ -255,7 +255,7 @@
has-frame? (->> shapes (d/seek cph/frame-shape?))
has-group? (->> shapes (d/seek cph/group-shape?))
has-bool? (->> shapes (d/seek cph/bool-shape?))
has-mask? (->> shapes (d/seek :masked-group?))
has-mask? (->> shapes (d/seek :masked-group))
is-group? (and single? has-group?)
is-bool? (and single? has-bool?)

View file

@ -51,7 +51,7 @@
workspace-read-only? (mf/use-ctx ctx/workspace-read-only?)
new-css-system (mf/use-ctx ctx/new-css-system)
main-instance? (if components-v2
(:main-instance? item)
(:main-instance item)
true)
parent-board? (and (= :frame (:type item))
(= uuid/zero (:parent-id item)))
@ -165,7 +165,7 @@
ref (mf/use-ref)
depth (+ recieved-depth 1)
component-tree? (or component-child? (:component-root? item))]
component-tree? (or component-child? (:component-root item))]
(mf/with-effect [selected? selected]
(let [single? (= (count selected) 1)
@ -185,7 +185,7 @@
#(when (some? subid)
(rx/dispose! subid))))
(if new-css-system
[:*
[:div {:on-context-menu on-context-menu
@ -195,7 +195,7 @@
:class (dom/classnames
(css :layer-row) true
(css :component) (not (nil? (:component-id item)))
(css :masked) (:masked-group? item)
(css :masked) (:masked-group item)
(css :selected) selected?
(css :type-frame) (= :frame (:type item))
(css :type-bool) (= :bool (:type item))
@ -289,7 +289,7 @@
:ref dref
:class (dom/classnames
:component (not (nil? (:component-id item)))
:masked (:masked-group? item)
:masked (:masked-group item)
:dnd-over (= (:over dprops) :center)
:dnd-over-top (= (:over dprops) :top)
:dnd-over-bot (= (:over dprops) :bot)
@ -343,4 +343,4 @@
:index index
:objects objects
:key (:id item)
:sortable? sortable?}]))])])))
:sortable? sortable?}]))])])))

View file

@ -202,10 +202,10 @@
(some #{:group} filters)
(and (= :group (:type shape))
(not (contains? shape :component-id))
(or (not (contains? shape :masked-group?)) (false? (:masked-group? shape)))))
(or (not (contains? shape :masked-group)) (false? (:masked-group shape)))))
(and
(some #{:mask} filters)
(true? (:masked-group? shape))))))))
(true? (:masked-group shape))))))))
filtered-objects-total
(mf/use-memo

View file

@ -22,12 +22,12 @@
[cuerdas.core :as str]
[rumext.v2 :as mf]))
(def component-attrs [:component-id :component-file :shape-ref :main-instance? :annotation])
(def component-attrs [:component-id :component-file :shape-ref :main-instance :annotation])
(mf/defc component-annotation
[{:keys [id values shape component] :as props}]
(let [main-instance? (:main-instance? values)
(let [main-instance? (:main-instance values)
component-id (:component-id values)
annotation (:annotation component)
editing? (mf/use-state false)
@ -140,8 +140,6 @@
(when (or @editing? creating?)
[:div.counter (str @size "/300")])]])))
(mf/defc component-menu
[{:keys [ids values shape] :as props}]
(let [current-file-id (mf/use-ctx ctx/current-file-id)
@ -160,9 +158,11 @@
library-id (:component-file values)
show? (some? component-id)
main-instance? (if components-v2
(:main-instance? values)
(:main-instance values)
true)
main-component? (:main-instance? values)
main-component? (:main-instance values)
lacks-annotation? (nil? (:annotation values))
local-component? (= library-id current-file-id)
workspace-data (deref refs/workspace-data)
workspace-libraries (deref refs/workspace-libraries)
@ -170,7 +170,6 @@
(ctkl/get-component workspace-data component-id)
(ctf/get-component workspace-libraries library-id component-id))
is-dangling? (nil? component)
lacks-annotation? (nil? (:annotation component))
lib-exists? (and (not local-component?)
(some? (get workspace-libraries library-id)))

View file

@ -413,10 +413,10 @@
:component-file component-file)
component-root?
(assoc :component-root? component-root?)
(assoc :component-root component-root?)
main-instance?
(assoc :main-instance? main-instance?)
(assoc :main-instance main-instance?)
(some? shape-ref)
(assoc :shape-ref shape-ref))))
@ -538,7 +538,7 @@
(let [mask? (get-meta node :masked-group str->bool)]
(cond-> props
mask?
(assoc :masked-group? true))))
(assoc :masked-group true))))
(defn add-bool-data
[props node]

View file

@ -239,7 +239,7 @@
(when v
(let [v (if (datetime? v) (format v :date) v)
locale (obj/get locales locale)
f (.date (.-formatLong locale) v)]
f (.date (.-formatLong ^js locale) v)]
(->> #js {:locale locale}
(dateFnsFormat v f))))))

View file

@ -206,7 +206,7 @@
(dissoc :stroke-color-ref-id :stroke-color-ref-file)
(not= file-id (get-component-ref-file objects shape))
(dissoc :component-id :component-file :shape-ref :component-root?)
(dissoc :component-id :component-file :shape-ref :component-root)
(= :text (:type shape))
(update :content detach-text)))