0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-23 15:26:29 -05:00

Add abstraction for page emptiness checking

This commit is contained in:
Andrey Antukh 2025-02-18 16:55:16 +01:00
parent 272bbdd54a
commit 7d840722c4
2 changed files with 11 additions and 5 deletions

View file

@ -5,6 +5,7 @@
;; Copyright (c) KALEIDOS INC ;; Copyright (c) KALEIDOS INC
(ns app.common.types.page (ns app.common.types.page
(:refer-clojure :exclude [empty?])
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.point :as-alias gpt] [app.common.geom.point :as-alias gpt]
@ -98,3 +99,8 @@
(defn get-frame-flow (defn get-frame-flow
[flows frame-id] [flows frame-id]
(d/seek #(= (:starting-frame %) frame-id) (vals flows))) (d/seek #(= (:starting-frame %) frame-id) (vals flows)))
(defn is-empty?
"Check if page is empty or contains shapes"
[page]
(= 1 (count (:objects page))))

View file

@ -29,6 +29,7 @@
[app.common.types.components-list :as ctkl] [app.common.types.components-list :as ctkl]
[app.common.types.container :as ctn] [app.common.types.container :as ctn]
[app.common.types.file :as ctf] [app.common.types.file :as ctf]
[app.common.types.page :as ctp]
[app.common.types.shape :as cts] [app.common.types.shape :as cts]
[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]
@ -271,13 +272,12 @@
dwz/zoom-to-selected-shape))))) dwz/zoom-to-selected-shape)))))
(defn- select-frame-tool (defn- select-frame-tool
[page-id file-id] [file-id page-id]
(ptk/reify ::select-frame-tool (ptk/reify ::select-frame-tool
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [objects (dsh/lookup-page-objects state file-id page-id) (let [page (dsh/lookup-page state file-id page-id)]
is-page-empty? (= (count objects) 1)] (when (ctp/is-empty? page)
(when is-page-empty?
(rx/of (dwd/select-for-drawing :frame))))))) (rx/of (dwd/select-for-drawing :frame)))))))
(defn- fetch-bundle (defn- fetch-bundle
@ -475,7 +475,7 @@
(dwth/watch-state-changes file-id page-id) (dwth/watch-state-changes file-id page-id)
(dwl/watch-component-changes) (dwl/watch-component-changes)
(when (cf/external-feature-flag "boards-02" "test") (when (cf/external-feature-flag "boards-02" "test")
(select-frame-tool page-id file-id))) (select-frame-tool file-id page-id)))
(rx/of (dcm/go-to-workspace :file-id file-id ::rt/replace true)))))) (rx/of (dcm/go-to-workspace :file-id file-id ::rt/replace true))))))
(defn finalize-page (defn finalize-page