2021-11-29 22:00:45 +01:00
|
|
|
;; 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/.
|
|
|
|
;;
|
2022-09-20 23:23:22 +02:00
|
|
|
;; Copyright (c) KALEIDOS INC
|
2021-11-29 22:00:45 +01:00
|
|
|
|
|
|
|
(ns debug
|
|
|
|
(:require
|
|
|
|
[app.common.data :as d]
|
2023-08-17 11:06:19 +02:00
|
|
|
[app.common.data.macros :as dm]
|
2023-09-01 17:35:33 +02:00
|
|
|
[app.common.files.repair :as cfr]
|
|
|
|
[app.common.files.validate :as cfv]
|
2024-08-26 20:41:05 +02:00
|
|
|
[app.common.json :as json]
|
2022-04-04 09:26:05 +02:00
|
|
|
[app.common.logging :as l]
|
2021-12-30 11:19:46 +01:00
|
|
|
[app.common.transit :as t]
|
2022-06-23 17:43:43 +02:00
|
|
|
[app.common.types.file :as ctf]
|
2021-12-21 12:32:04 +01:00
|
|
|
[app.common.uuid :as uuid]
|
2023-07-25 11:20:52 +02:00
|
|
|
[app.main.data.changes :as dwc]
|
2024-12-03 18:23:41 +01:00
|
|
|
[app.main.data.common :as dcm]
|
2022-03-25 12:18:33 +01:00
|
|
|
[app.main.data.dashboard.shortcuts]
|
2023-09-25 12:19:00 +02:00
|
|
|
[app.main.data.preview :as dp]
|
2022-03-25 11:53:50 +01:00
|
|
|
[app.main.data.viewer.shortcuts]
|
2022-01-21 13:45:17 +01:00
|
|
|
[app.main.data.workspace :as dw]
|
2024-10-14 15:19:40 +02:00
|
|
|
[app.main.data.workspace.common :as dwcm]
|
2022-03-25 11:53:50 +01:00
|
|
|
[app.main.data.workspace.path.shortcuts]
|
2023-10-11 14:42:10 +02:00
|
|
|
[app.main.data.workspace.selection :as dws]
|
2022-03-25 11:53:50 +01:00
|
|
|
[app.main.data.workspace.shortcuts]
|
2023-11-17 11:31:45 +01:00
|
|
|
[app.main.errors :as errors]
|
2023-09-01 17:35:33 +02:00
|
|
|
[app.main.features :as features]
|
2023-08-24 23:45:01 +02:00
|
|
|
[app.main.repo :as rp]
|
2021-11-29 22:00:45 +01:00
|
|
|
[app.main.store :as st]
|
2023-09-21 15:53:34 +02:00
|
|
|
[app.util.debug :as dbg]
|
2022-04-01 11:21:50 +02:00
|
|
|
[app.util.dom :as dom]
|
2021-11-29 22:00:45 +01:00
|
|
|
[app.util.object :as obj]
|
|
|
|
[app.util.timers :as timers]
|
2023-12-21 20:02:49 +01:00
|
|
|
[beicon.v2.core :as rx]
|
2021-11-29 22:00:45 +01:00
|
|
|
[cljs.pprint :refer [pprint]]
|
|
|
|
[cuerdas.core :as str]
|
2023-12-21 20:02:49 +01:00
|
|
|
[potok.v2.core :as ptk]
|
2022-03-25 12:18:33 +01:00
|
|
|
[promesa.core :as p]))
|
2021-11-29 22:00:45 +01:00
|
|
|
|
2023-09-01 17:35:33 +02:00
|
|
|
(l/set-level! :debug)
|
|
|
|
|
2022-04-04 09:26:05 +02:00
|
|
|
(defn ^:export set-logging
|
|
|
|
([level]
|
|
|
|
(l/set-level! :app (keyword level)))
|
|
|
|
([ns level]
|
|
|
|
(l/set-level! (keyword ns) (keyword level))))
|
|
|
|
|
2021-11-29 22:00:45 +01:00
|
|
|
;; These events are excluded when we activate the :events flag
|
|
|
|
(def debug-exclude-events
|
|
|
|
#{:app.main.data.workspace.notifications/handle-pointer-update
|
2022-12-02 12:17:32 +01:00
|
|
|
:app.main.data.workspace.notifications/handle-pointer-send
|
|
|
|
:app.main.data.websocket/send-message
|
2021-11-29 22:00:45 +01:00
|
|
|
:app.main.data.workspace.selection/change-hover-state})
|
|
|
|
|
2024-01-29 14:18:58 +01:00
|
|
|
(defn enable!
|
2023-09-21 15:53:34 +02:00
|
|
|
[option]
|
|
|
|
(dbg/enable! option)
|
2023-01-11 11:34:30 +01:00
|
|
|
(when (= :events option)
|
|
|
|
(set! st/*debug-events* true))
|
|
|
|
(js* "app.main.reinit()"))
|
|
|
|
|
2024-01-29 14:18:58 +01:00
|
|
|
(defn disable!
|
2023-09-21 15:53:34 +02:00
|
|
|
[option]
|
|
|
|
(dbg/disable! option)
|
2023-01-11 11:34:30 +01:00
|
|
|
(when (= :events option)
|
|
|
|
(set! st/*debug-events* false))
|
|
|
|
(js* "app.main.reinit()"))
|
2021-11-29 22:00:45 +01:00
|
|
|
|
2023-09-21 15:53:34 +02:00
|
|
|
(defn ^:export toggle-debug
|
|
|
|
[name]
|
|
|
|
(let [option (keyword name)]
|
|
|
|
(if (dbg/enabled? option)
|
|
|
|
(disable! option)
|
|
|
|
(enable! option))))
|
2021-11-29 22:00:45 +01:00
|
|
|
|
2023-09-21 15:53:34 +02:00
|
|
|
(defn ^:export debug-all
|
|
|
|
[]
|
|
|
|
(reset! dbg/state dbg/options)
|
|
|
|
(js* "app.main.reinit()"))
|
|
|
|
|
|
|
|
(defn ^:export debug-none
|
|
|
|
[]
|
|
|
|
(reset! dbg/state #{})
|
|
|
|
(js* "app.main.reinit()"))
|
2021-11-29 22:00:45 +01:00
|
|
|
|
|
|
|
(defn ^:export tap
|
|
|
|
"Transducer function that can execute a side-effect `effect-fn` per input"
|
|
|
|
[effect-fn]
|
|
|
|
(fn [rf]
|
|
|
|
(fn
|
|
|
|
([] (rf))
|
|
|
|
([result] (rf result))
|
|
|
|
([result input]
|
|
|
|
(effect-fn input)
|
|
|
|
(rf result input)))))
|
|
|
|
|
|
|
|
(defn ^:export logjs
|
|
|
|
([str] (tap (partial logjs str)))
|
|
|
|
([str val]
|
2024-08-26 20:41:05 +02:00
|
|
|
(js/console.log str (json/->js val))
|
2021-11-29 22:00:45 +01:00
|
|
|
val))
|
|
|
|
|
|
|
|
(when (exists? js/window)
|
2024-08-26 20:41:05 +02:00
|
|
|
(set! (.-dbg ^js js/window) json/->js)
|
2021-11-29 22:00:45 +01:00
|
|
|
(set! (.-pp ^js js/window) pprint))
|
|
|
|
|
|
|
|
(defonce widget-style "
|
|
|
|
background: black;
|
|
|
|
bottom: 10px;
|
|
|
|
color: white;
|
|
|
|
height: 20px;
|
|
|
|
padding-left: 8px;
|
|
|
|
position: absolute;
|
|
|
|
right: 10px;
|
|
|
|
width: 40px;
|
|
|
|
z-index: 99999;
|
|
|
|
opacity: 0.5;
|
|
|
|
")
|
|
|
|
|
|
|
|
(defn ^:export fps
|
|
|
|
"Adds a widget to keep track of the average FPS's"
|
|
|
|
[]
|
|
|
|
(let [last (volatile! (.now js/performance))
|
|
|
|
avg (volatile! 0)
|
|
|
|
node (-> (.createElement js/document "div")
|
|
|
|
(obj/set! "id" "fps")
|
|
|
|
(obj/set! "style" widget-style))
|
|
|
|
body (obj/get js/document "body")
|
|
|
|
|
|
|
|
do-thing (fn do-thing []
|
|
|
|
(timers/raf
|
|
|
|
(fn []
|
|
|
|
(let [cur (.now js/performance)
|
|
|
|
ts (/ 1000 (* (- cur @last)))
|
|
|
|
val (+ @avg (* (- ts @avg) 0.1))]
|
|
|
|
|
2022-03-02 15:50:06 +01:00
|
|
|
(obj/set! node "innerText" val)
|
2021-11-29 22:00:45 +01:00
|
|
|
(vreset! last cur)
|
|
|
|
(vreset! avg val)
|
|
|
|
(do-thing)))))]
|
|
|
|
|
|
|
|
(.appendChild body node)
|
|
|
|
(do-thing)))
|
|
|
|
|
|
|
|
(defn ^:export dump-state []
|
2021-12-21 12:32:04 +01:00
|
|
|
(logjs "state" @st/state)
|
|
|
|
nil)
|
2021-11-29 22:00:45 +01:00
|
|
|
|
2022-09-23 10:20:20 +02:00
|
|
|
(defn ^:export dump-data []
|
|
|
|
(logjs "workspace-data" (get @st/state :workspace-data))
|
|
|
|
nil)
|
|
|
|
|
2021-11-29 22:00:45 +01:00
|
|
|
(defn ^:export dump-buffer []
|
2022-04-29 11:05:04 +02:00
|
|
|
(logjs "last-events" @st/last-events)
|
2021-12-21 12:32:04 +01:00
|
|
|
nil)
|
2021-11-29 22:00:45 +01:00
|
|
|
|
|
|
|
(defn ^:export get-state [str-path]
|
|
|
|
(let [path (->> (str/split str-path " ")
|
2022-04-29 11:05:04 +02:00
|
|
|
(map d/read-string)
|
|
|
|
vec)]
|
|
|
|
(js/console.log (clj->js (get-in @st/state path))))
|
2021-12-21 12:32:04 +01:00
|
|
|
nil)
|
2021-11-29 22:00:45 +01:00
|
|
|
|
2022-03-16 11:27:51 +01:00
|
|
|
(defn dump-objects'
|
|
|
|
[state]
|
|
|
|
(let [page-id (get state :current-page-id)
|
|
|
|
objects (get-in state [:workspace-data :pages-index page-id :objects])]
|
2021-12-21 12:32:04 +01:00
|
|
|
(logjs "objects" objects)
|
|
|
|
nil))
|
2021-11-29 22:00:45 +01:00
|
|
|
|
2022-03-16 11:27:51 +01:00
|
|
|
(defn ^:export dump-objects
|
|
|
|
[]
|
|
|
|
(dump-objects' @st/state))
|
|
|
|
|
|
|
|
(defn dump-object'
|
|
|
|
[state name]
|
|
|
|
(let [page-id (get state :current-page-id)
|
|
|
|
objects (get-in state [:workspace-data :pages-index page-id :objects])
|
2024-10-24 18:35:57 +02:00
|
|
|
result (or (d/seek (fn [shape] (= name (:name shape))) (vals objects))
|
2021-12-21 12:32:04 +01:00
|
|
|
(get objects (uuid/uuid name)))]
|
2024-10-24 18:35:57 +02:00
|
|
|
#_(logjs name result)
|
|
|
|
result
|
|
|
|
|
|
|
|
#_nil))
|
2021-12-21 12:32:04 +01:00
|
|
|
|
2022-03-16 11:27:51 +01:00
|
|
|
(defn ^:export dump-object
|
|
|
|
[name]
|
|
|
|
(dump-object' @st/state name))
|
|
|
|
|
|
|
|
(defn dump-selected'
|
|
|
|
[state]
|
|
|
|
(let [page-id (get state :current-page-id)
|
|
|
|
objects (get-in state [:workspace-data :pages-index page-id :objects])
|
|
|
|
selected (get-in state [:workspace-local :selected])
|
2021-12-21 12:32:04 +01:00
|
|
|
result (->> selected (map (d/getf objects)))]
|
|
|
|
(logjs "selected" result)
|
|
|
|
nil))
|
2021-11-29 22:00:45 +01:00
|
|
|
|
2022-03-16 11:27:51 +01:00
|
|
|
(defn ^:export dump-selected
|
|
|
|
[]
|
|
|
|
(dump-selected' @st/state))
|
|
|
|
|
2023-09-25 12:19:00 +02:00
|
|
|
(defn ^:export preview-selected
|
|
|
|
[]
|
|
|
|
(st/emit! (dp/open-preview-selected)))
|
|
|
|
|
2023-01-27 13:06:32 +01:00
|
|
|
(defn ^:export parent
|
|
|
|
[]
|
|
|
|
(let [state @st/state
|
|
|
|
page-id (get state :current-page-id)
|
|
|
|
objects (get-in state [:workspace-data :pages-index page-id :objects])
|
|
|
|
selected (first (get-in state [:workspace-local :selected]))
|
|
|
|
parent-id (get-in objects [selected :parent-id])
|
|
|
|
parent (get objects parent-id)]
|
|
|
|
(when parent
|
|
|
|
(prn (str (:name parent) " - " (:id parent))))
|
|
|
|
nil))
|
|
|
|
|
|
|
|
(defn ^:export frame
|
|
|
|
[]
|
|
|
|
(let [state @st/state
|
|
|
|
page-id (get state :current-page-id)
|
|
|
|
objects (get-in state [:workspace-data :pages-index page-id :objects])
|
|
|
|
selected (first (get-in state [:workspace-local :selected]))
|
|
|
|
frame-id (get-in objects [selected :frame-id])
|
|
|
|
frame (get objects frame-id)]
|
|
|
|
(when frame
|
|
|
|
(prn (str (:name frame) " - " (:id frame))))
|
|
|
|
nil))
|
|
|
|
|
2024-01-04 14:25:22 +01:00
|
|
|
(defn ^:export select-by-object-id
|
|
|
|
[object-id]
|
|
|
|
(let [[_ page-id shape-id _] (str/split object-id #"/")]
|
2024-12-03 18:23:41 +01:00
|
|
|
(st/emit! (dcm/go-to-workspace :page-id (uuid/uuid page-id)))
|
2024-01-04 14:25:22 +01:00
|
|
|
(st/emit! (dws/select-shape (uuid/uuid shape-id)))))
|
|
|
|
|
2023-10-11 14:42:10 +02:00
|
|
|
(defn ^:export select-by-id
|
|
|
|
[shape-id]
|
|
|
|
(st/emit! (dws/select-shape (uuid/uuid shape-id))))
|
|
|
|
|
2022-03-16 11:27:51 +01:00
|
|
|
(defn dump-tree'
|
2023-05-04 09:34:38 +02:00
|
|
|
([state] (dump-tree' state false false false))
|
|
|
|
([state show-ids] (dump-tree' state show-ids false false))
|
|
|
|
([state show-ids show-touched] (dump-tree' state show-ids show-touched false))
|
|
|
|
([state show-ids show-touched show-modified]
|
2022-03-16 11:27:51 +01:00
|
|
|
(let [page-id (get state :current-page-id)
|
2023-08-02 16:31:26 +02:00
|
|
|
file (assoc (get state :workspace-file)
|
|
|
|
:data (get state :workspace-data))
|
2024-12-10 14:45:56 +01:00
|
|
|
libraries (get state :libraries)]
|
2023-08-02 16:31:26 +02:00
|
|
|
(ctf/dump-tree file page-id libraries {:show-ids show-ids
|
|
|
|
:show-touched show-touched
|
|
|
|
:show-modified show-modified}))))
|
2022-03-16 11:27:51 +01:00
|
|
|
(defn ^:export dump-tree
|
|
|
|
([] (dump-tree' @st/state))
|
2023-05-04 09:34:38 +02:00
|
|
|
([show-ids] (dump-tree' @st/state show-ids false false))
|
|
|
|
([show-ids show-touched] (dump-tree' @st/state show-ids show-touched false))
|
|
|
|
([show-ids show-touched show-modified] (dump-tree' @st/state show-ids show-touched show-modified)))
|
2022-03-16 11:27:51 +01:00
|
|
|
|
2023-08-02 16:31:26 +02:00
|
|
|
(defn ^:export dump-subtree'
|
|
|
|
([state shape-id] (dump-subtree' state shape-id false false false))
|
|
|
|
([state shape-id show-ids] (dump-subtree' state shape-id show-ids false false))
|
|
|
|
([state shape-id show-ids show-touched] (dump-subtree' state shape-id show-ids show-touched false))
|
|
|
|
([state shape-id show-ids show-touched show-modified]
|
|
|
|
(let [page-id (get state :current-page-id)
|
|
|
|
file (assoc (get state :workspace-file)
|
|
|
|
:data (get state :workspace-data))
|
2024-12-10 14:45:56 +01:00
|
|
|
libraries (get state :libraries)
|
2024-06-13 16:09:51 +02:00
|
|
|
shape-id (if (some? shape-id)
|
|
|
|
(uuid/uuid shape-id)
|
|
|
|
(let [objects (get-in state [:workspace-data :pages-index page-id :objects])
|
|
|
|
selected (get-in state [:workspace-local :selected])]
|
|
|
|
(->> selected (map (d/getf objects)) first :id)))]
|
|
|
|
(if (some? shape-id)
|
|
|
|
(ctf/dump-subtree file page-id shape-id libraries {:show-ids show-ids
|
|
|
|
:show-touched show-touched
|
|
|
|
:show-modified show-modified})
|
|
|
|
(println "no selected shape")))))
|
|
|
|
|
2023-08-02 16:31:26 +02:00
|
|
|
(defn ^:export dump-subtree
|
2024-06-13 16:09:51 +02:00
|
|
|
([shape-id] (dump-subtree' @st/state shape-id))
|
|
|
|
([shape-id show-ids] (dump-subtree' @st/state shape-id show-ids false false))
|
|
|
|
([shape-id show-ids show-touched] (dump-subtree' @st/state shape-id show-ids show-touched false))
|
|
|
|
([shape-id show-ids show-touched show-modified] (dump-subtree' @st/state shape-id show-ids show-touched show-modified)))
|
2023-08-02 16:31:26 +02:00
|
|
|
|
2021-11-29 22:00:45 +01:00
|
|
|
(when *assert*
|
|
|
|
(defonce debug-subscription
|
|
|
|
(->> st/stream
|
|
|
|
(rx/filter ptk/event?)
|
2023-09-21 15:53:34 +02:00
|
|
|
(rx/filter (fn [s] (and (dbg/enabled? :events)
|
2021-11-29 22:00:45 +01:00
|
|
|
(not (debug-exclude-events (ptk/type s))))))
|
2023-12-21 20:02:49 +01:00
|
|
|
(rx/subs! #(println "[stream]: " (ptk/repr-event %))))))
|
2021-11-29 22:00:45 +01:00
|
|
|
|
2021-12-30 11:19:46 +01:00
|
|
|
(defn ^:export apply-changes
|
|
|
|
"Takes a Transit JSON changes"
|
|
|
|
[^string changes*]
|
|
|
|
|
|
|
|
(let [file-id (:current-file-id @st/state)
|
|
|
|
changes (t/decode-str changes*)]
|
2023-07-25 11:20:52 +02:00
|
|
|
(st/emit! (dwc/commit-changes {:redo-changes changes
|
2021-12-30 11:19:46 +01:00
|
|
|
:undo-changes []
|
|
|
|
:save-undo? true
|
|
|
|
:file-id file-id}))))
|
|
|
|
|
|
|
|
(defn ^:export fetch-apply
|
|
|
|
[^string url]
|
|
|
|
(-> (p/let [response (js/fetch url)]
|
|
|
|
(.text response))
|
|
|
|
(p/then apply-changes)))
|
2022-01-21 13:45:17 +01:00
|
|
|
|
|
|
|
(defn ^:export reset-viewport
|
|
|
|
[]
|
|
|
|
(st/emit!
|
|
|
|
dw/reset-zoom
|
|
|
|
(dw/update-viewport-position {:x (constantly 0) :y (constantly 0)})))
|
|
|
|
|
2022-01-26 17:26:57 +01:00
|
|
|
(defn ^:export hide-ui
|
|
|
|
[]
|
|
|
|
(st/emit!
|
2022-03-07 23:22:05 +01:00
|
|
|
(dw/toggle-layout-flag :hide-ui)))
|
2022-03-25 11:53:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
(defn ^:export shortcuts
|
|
|
|
[]
|
|
|
|
|
|
|
|
(letfn [(print-shortcuts [shortcuts]
|
|
|
|
(.table js/console
|
|
|
|
(->> shortcuts
|
|
|
|
(map (fn [[key {:keys [command]}]]
|
|
|
|
[(d/name key)
|
|
|
|
(if (vector? command)
|
|
|
|
(str/join " | " command)
|
|
|
|
command)]))
|
|
|
|
(into {})
|
|
|
|
(clj->js))))]
|
2022-03-25 12:18:33 +01:00
|
|
|
(let [style "font-weight: bold; font-size: 1.25rem;"]
|
|
|
|
(.log js/console "%c Dashboard" style)
|
|
|
|
(print-shortcuts app.main.data.dashboard.shortcuts/shortcuts)
|
2022-03-25 11:53:50 +01:00
|
|
|
|
2022-03-25 12:18:33 +01:00
|
|
|
(.log js/console "%c Workspace" style)
|
|
|
|
(print-shortcuts app.main.data.workspace.shortcuts/shortcuts)
|
2022-03-25 11:53:50 +01:00
|
|
|
|
2022-03-25 12:18:33 +01:00
|
|
|
(.log js/console "%c Path" style)
|
|
|
|
(print-shortcuts app.main.data.workspace.path.shortcuts/shortcuts)
|
2022-03-25 11:53:50 +01:00
|
|
|
|
2022-03-25 12:18:33 +01:00
|
|
|
(.log js/console "%c Viewer" style)
|
|
|
|
(print-shortcuts app.main.data.viewer.shortcuts/shortcuts)))
|
2022-03-25 11:53:50 +01:00
|
|
|
nil)
|
2022-04-01 11:21:50 +02:00
|
|
|
|
|
|
|
(defn ^:export nodeStats
|
|
|
|
[]
|
|
|
|
(let [root-node (dom/query ".viewport .render-shapes")
|
|
|
|
num-nodes (->> (dom/seq-nodes root-node) count)]
|
|
|
|
#js {:number num-nodes}))
|
2022-07-06 12:40:07 +02:00
|
|
|
|
2022-10-14 14:44:10 +02:00
|
|
|
(defn modif->js
|
2022-07-06 12:40:07 +02:00
|
|
|
[modif-tree objects]
|
|
|
|
(clj->js (into {}
|
|
|
|
(map (fn [[k v]]
|
|
|
|
[(get-in objects [k :name]) v]))
|
|
|
|
modif-tree)))
|
2022-10-14 14:44:10 +02:00
|
|
|
|
|
|
|
(defn ^:export dump-modifiers
|
|
|
|
[]
|
|
|
|
(let [page-id (get @st/state :current-page-id)
|
|
|
|
objects (get-in @st/state [:workspace-data :pages-index page-id :objects])]
|
|
|
|
(.log js/console (modif->js (:workspace-modifiers @st/state) objects)))
|
|
|
|
nil)
|
2022-11-22 16:52:31 +01:00
|
|
|
|
|
|
|
(defn ^:export set-workspace-read-only
|
|
|
|
[read-only?]
|
2024-10-14 15:19:40 +02:00
|
|
|
(st/emit! (dwcm/set-workspace-read-only read-only?)))
|
2022-11-22 16:52:31 +01:00
|
|
|
|
2023-11-17 11:31:45 +01:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; REPAIR & VALIDATION
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2023-08-17 11:06:19 +02:00
|
|
|
|
|
|
|
;; Validation and repair
|
|
|
|
|
|
|
|
(defn ^:export validate
|
|
|
|
([] (validate nil))
|
|
|
|
([shape-id]
|
|
|
|
(let [file (assoc (get @st/state :workspace-file)
|
|
|
|
:data (get @st/state :workspace-data))
|
2024-12-10 14:45:56 +01:00
|
|
|
libraries (get @st/state :libraries)]
|
2023-11-17 11:31:45 +01:00
|
|
|
|
|
|
|
(try
|
2023-12-13 15:31:53 +01:00
|
|
|
(->> (if-let [shape-id (some-> shape-id parse-uuid)]
|
2023-11-17 11:31:45 +01:00
|
|
|
(let [page (dm/get-in file [:data :pages-index (get @st/state :current-page-id)])]
|
2024-01-08 16:24:01 +01:00
|
|
|
(cfv/validate-shape shape-id file page libraries))
|
2023-11-17 11:31:45 +01:00
|
|
|
(cfv/validate-file file libraries))
|
|
|
|
(group-by :code)
|
|
|
|
(clj->js))
|
|
|
|
(catch :default cause
|
|
|
|
(errors/print-error! cause))))))
|
2023-09-01 17:35:33 +02:00
|
|
|
|
2023-11-20 17:31:21 +01:00
|
|
|
(defn ^:export validate-schema
|
|
|
|
[]
|
|
|
|
(try
|
|
|
|
(-> (get @st/state :workspace-file)
|
|
|
|
(assoc :data (get @st/state :workspace-data))
|
|
|
|
(cfv/validate-file-schema!))
|
|
|
|
(catch :default cause
|
|
|
|
(errors/print-error! cause))))
|
|
|
|
|
2023-09-01 17:35:33 +02:00
|
|
|
(defn ^:export repair
|
2023-12-13 15:31:53 +01:00
|
|
|
[reload?]
|
|
|
|
(st/emit!
|
|
|
|
(ptk/reify ::repair-current-file
|
|
|
|
ptk/EffectEvent
|
|
|
|
(effect [_ state _]
|
|
|
|
(let [features (features/get-team-enabled-features state)
|
|
|
|
sid (:session-id state)
|
|
|
|
|
|
|
|
file (get state :workspace-file)
|
|
|
|
fdata (get state :workspace-data)
|
|
|
|
|
|
|
|
file (assoc file :data fdata)
|
2024-12-10 14:45:56 +01:00
|
|
|
libs (get state :libraries)
|
2023-12-13 15:31:53 +01:00
|
|
|
|
|
|
|
errors (cfv/validate-file file libs)
|
|
|
|
_ (l/dbg :hint "repair current file" :errors (count errors))
|
|
|
|
|
|
|
|
changes (cfr/repair-file file libs errors)
|
|
|
|
|
|
|
|
params {:id (:id file)
|
|
|
|
:revn (:revn file)
|
2024-10-15 12:11:32 +02:00
|
|
|
:vern (:vern file)
|
2023-12-13 15:31:53 +01:00
|
|
|
:session-id sid
|
|
|
|
:changes changes
|
|
|
|
:features features
|
|
|
|
:skip-validate true}]
|
|
|
|
|
|
|
|
(->> (rp/cmd! :update-file params)
|
2023-12-21 20:02:49 +01:00
|
|
|
(rx/subs! (fn [_]
|
2024-01-05 14:23:30 +01:00
|
|
|
(when reload?
|
|
|
|
(dom/reload-current-window)))
|
|
|
|
(fn [cause]
|
|
|
|
(errors/print-error! cause)))))))))
|
2023-08-17 11:06:19 +02:00
|
|
|
|
2022-12-27 07:03:12 +01:00
|
|
|
(defn ^:export fix-orphan-shapes
|
|
|
|
[]
|
|
|
|
(st/emit! (dw/fix-orphan-shapes)))
|
2023-07-27 10:44:32 +02:00
|
|
|
|
|
|
|
(defn ^:export find-components-norefs
|
|
|
|
[]
|
|
|
|
(st/emit! (dw/find-components-norefs)))
|
|
|
|
|
|
|
|
(defn ^:export set-shape-ref
|
|
|
|
[id shape-ref]
|
|
|
|
(st/emit! (dw/set-shape-ref id shape-ref)))
|
|
|
|
|
2024-10-02 16:59:59 +02:00
|
|
|
(defn ^:export enable-text-v2
|
|
|
|
[]
|
|
|
|
(st/emit! (features/enable-feature "text-editor/v2")))
|