mirror of
https://github.com/penpot/penpot.git
synced 2025-04-01 09:31:26 -05:00
✨ Include page options into the data field.
And remove unused `metadata` field.
This commit is contained in:
parent
904664319a
commit
9c68877328
8 changed files with 47 additions and 28 deletions
|
@ -64,8 +64,7 @@ CREATE TABLE IF NOT EXISTS project_pages (
|
|||
ordering smallint NOT NULL,
|
||||
|
||||
name text NOT NULL,
|
||||
data bytea NOT NULL,
|
||||
metadata bytea NULL DEFAULT NULL
|
||||
data bytea NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS project_page_snapshots (
|
||||
|
|
|
@ -98,8 +98,8 @@
|
|||
|
||||
(def create-page-sql
|
||||
"insert into project_pages (id, user_id, file_id, name,
|
||||
version, ordering, data, metadata)
|
||||
values ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
version, ordering, data)
|
||||
values ($1, $2, $3, $4, $5, $6, $7)
|
||||
returning id;")
|
||||
|
||||
(def create-page-history-sql
|
||||
|
@ -121,8 +121,10 @@
|
|||
:stroke-opacity 1
|
||||
:fill-color "#ffffff"
|
||||
:fill-opacity 1}
|
||||
data {:shapes []
|
||||
data {:version 1
|
||||
:shapes []
|
||||
:canvas [(:id canvas)]
|
||||
:options {}
|
||||
:shapes-by-id {(:id canvas) canvas}}
|
||||
|
||||
sql1 create-page-sql
|
||||
|
@ -134,10 +136,9 @@
|
|||
name (str "page " page-index)
|
||||
version 0
|
||||
ordering page-index
|
||||
data (blob/encode data)
|
||||
mdata (blob/encode {})]
|
||||
data (blob/encode data)]
|
||||
(p/do!
|
||||
(db/query-one conn [sql1 id user-id file-id name version ordering data mdata])
|
||||
(db/query-one conn [sql1 id user-id file-id name version ordering data])
|
||||
#_(db/query-one conn [sql2 id user-id version data]))))
|
||||
|
||||
(def preset-small
|
||||
|
|
|
@ -158,9 +158,9 @@
|
|||
:stored-version (:version page)}))
|
||||
(let [ops (:operations params)
|
||||
data (-> (:data page)
|
||||
(blob/decode)
|
||||
(cp/process-ops ops)
|
||||
(blob/encode))
|
||||
(blob/decode)
|
||||
(cp/process-ops ops)
|
||||
(blob/encode))
|
||||
|
||||
page (assoc page
|
||||
:user-id (:user params)
|
||||
|
|
|
@ -54,8 +54,8 @@
|
|||
removed (set/difference ma-keys mb-keys)
|
||||
both (set/intersection ma-keys mb-keys)]
|
||||
(concat
|
||||
(mapv #(vector :add % (get mb %)) added)
|
||||
(mapv #(vector :del % nil) removed)
|
||||
(mapv #(vector :set % (get mb %)) added)
|
||||
(mapv #(vector :set % nil) removed)
|
||||
(loop [k (first both)
|
||||
r (rest both)
|
||||
rs []]
|
||||
|
@ -64,7 +64,7 @@
|
|||
vmb (get mb k)]
|
||||
(if (= vma vmb)
|
||||
(recur (first r) (rest r) rs)
|
||||
(recur (first r) (rest r) (conj rs [:mod k vmb]))))
|
||||
(recur (first r) (rest r) (conj rs [:set k vmb]))))
|
||||
rs)))))
|
||||
|
||||
(defn index-by
|
||||
|
|
|
@ -38,16 +38,20 @@
|
|||
(s/def ::data
|
||||
(s/keys :req-un [::shapes ::canvas ::shapes-by-id]))
|
||||
|
||||
(s/def ::shape-change
|
||||
(s/tuple #{:add :mod :del} keyword? any?))
|
||||
(s/def ::attr-change
|
||||
(s/tuple #{:set} keyword? any?))
|
||||
|
||||
(s/def ::operation
|
||||
(s/or :mod-shape (s/cat :name #(= % :mod-shape)
|
||||
:id uuid?
|
||||
:changes (s/* ::shape-change))
|
||||
:changes (s/* ::attr-change))
|
||||
:add-shape (s/cat :name #(= % :add-shape)
|
||||
:id uuid?
|
||||
:data any?)
|
||||
|
||||
:mod-opts (s/cat :name #(= % :mod-opts)
|
||||
:changes (s/* ::attr-change))
|
||||
|
||||
:del-shape (s/cat :name #(= % :del-shape)
|
||||
:id uuid?)
|
||||
:mov-shape (s/cat :name #(= % :mov-shape)
|
||||
|
@ -67,6 +71,7 @@
|
|||
|
||||
(declare process-operation)
|
||||
(declare process-mod-shape)
|
||||
(declare process-mod-opts)
|
||||
(declare process-mov-shape)
|
||||
(declare process-add-shape)
|
||||
(declare process-add-canvas)
|
||||
|
@ -86,19 +91,29 @@
|
|||
:add-shape (process-add-shape data rest)
|
||||
:add-canvas (process-add-canvas data rest)
|
||||
:del-shape (process-del-shape data rest)
|
||||
:del-canvas (process-del-canvas data rest)))
|
||||
:del-canvas (process-del-canvas data rest)
|
||||
:mod-opts (process-mod-opts data rest)))
|
||||
|
||||
(defn- process-mod-shape
|
||||
[data [id & changes]]
|
||||
(if (get-in data [:shapes-by-id id])
|
||||
(update-in data [:shapes-by-id id]
|
||||
#(reduce (fn [shape [op att val]]
|
||||
(if (= op :del)
|
||||
#(reduce (fn [shape [_ att val]]
|
||||
(if (nil? val)
|
||||
(dissoc shape att)
|
||||
(assoc shape att val)))
|
||||
% changes))
|
||||
data))
|
||||
|
||||
(defn- process-mod-opts
|
||||
[data changes]
|
||||
(update data :options
|
||||
#(reduce (fn [options [_ att val]]
|
||||
(if (nil? val)
|
||||
(dissoc options att)
|
||||
(assoc options att val)))
|
||||
% changes)))
|
||||
|
||||
(defn- process-add-shape
|
||||
[data [id sdata]]
|
||||
(-> data
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
# Collaborative Edition
|
||||
# Collaborative Edition & Persistence protocol
|
||||
|
||||
This is a collection of design notes for collaborative edition feature.
|
||||
This is a collection of design notes for collaborative edition feature
|
||||
and persistence protocol.
|
||||
|
||||
## Persistence Ops
|
||||
|
||||
## Persistence Operations
|
||||
|
||||
This is a page data structure:
|
||||
|
||||
```
|
||||
{:shapes [<id>, ...]
|
||||
{:version 1
|
||||
:options {}
|
||||
:shapes [<id>, ...]
|
||||
:canvas [<id>, ...]
|
||||
:shapes-by-id {<id> <object>, ...}}
|
||||
```
|
||||
|
@ -16,10 +20,10 @@ This is a potential list of persistent ops:
|
|||
|
||||
```
|
||||
;; Generic (Shapes & Canvas)
|
||||
[:mod-shape <id> [:(mod|add|del) <attr> <val?>], ...] ;; Persistent
|
||||
[:mod-shape <id> [:set <attr> <val?>], ...]
|
||||
|
||||
;; Example:
|
||||
;; [:mod-shape 1 [:add :x 2] [:mod :y 3]]
|
||||
;; [:mod-shape 1 [:set :x 2] [:set :y 3]]
|
||||
|
||||
;; Specific
|
||||
[:add-shape <id> <object>]
|
||||
|
@ -30,6 +34,8 @@ This is a potential list of persistent ops:
|
|||
|
||||
[:mov-canvas <id> :after <id|null>] ;; null implies at first position
|
||||
[:mov-shape <id> :after <id|null>]
|
||||
|
||||
[:mod-opts [:set <attr> <val>], [:del <attr> nil], ...]
|
||||
```
|
||||
|
||||
## Ephemeral communication (Websocket protocol)
|
||||
|
|
|
@ -57,7 +57,6 @@
|
|||
::modified-at
|
||||
::user-id
|
||||
::ordering
|
||||
::metadata
|
||||
::data]))
|
||||
|
||||
;; --- Helpers
|
||||
|
|
|
@ -524,7 +524,6 @@
|
|||
([] (PasteFromClipboard. nil))
|
||||
([id] (PasteFromClipboard. id)))
|
||||
|
||||
|
||||
;; --- Zoom Management
|
||||
|
||||
(def increase-zoom
|
||||
|
|
Loading…
Add table
Reference in a new issue