Compare commits

...

365 Commits
2.6.2 ... 2.7.1

Author SHA1 Message Date
Andrés Moya
050ffa235c ⬆️ Update cuerdas library (#6556) 2025-05-26 13:22:30 +02:00
Andrey Antukh
fdd6502671 📚 Update changelog 2025-05-26 12:41:34 +02:00
Alejandro Alonso
ac0b74e11a Merge pull request #6549 from penpot/niwinz-staging-hotfix-1
🐛 Fix incorrect relink operation for stroke image
2025-05-26 09:50:52 +02:00
Andrey Antukh
b5d96d312a 🐛 Fix incorrect relink operation for stroke image 2025-05-24 09:16:10 +02:00
Eva Marco
99fb905070 🐛 Fix at icon (#6540) 2025-05-22 13:15:09 +02:00
María Valderrama
faa68784af 💄 Add styles for external widgets on workspace (#6509)
* 💄 Add styles for Inkeep Chat at workspace

* 📎 Styles review
2025-05-22 11:56:45 +02:00
Alejandro Alonso
0748ef7267 Merge pull request #6518 from penpot/niwinz-staging-tokenslib-json-encoding
🐛 Add json encoding for tokenslib type
2025-05-21 10:17:37 +02:00
Andrey Antukh
9ca4fa752c 🐛 Add json encoding for tokenslib type 2025-05-21 09:59:28 +02:00
Alejandro Alonso
ff9c8f5929 Merge pull request #6483 from penpot/niwinz-staging-bugfixes-error-report
🐛 Several bugfixes
2025-05-20 13:54:54 +02:00
Alejandro Alonso
e4c563f917 Merge pull request #6479 from penpot/niwinz-develop-json-encoding-fix
🐛 Fix exception on rendering openapi.json
2025-05-20 13:46:16 +02:00
Andrey Antukh
2d3ad5a88f 📎 Update changelog 2025-05-20 13:30:04 +02:00
Andrey Antukh
1334d733cd 🐛 Fix openapi json generation for :re schemas 2025-05-20 13:29:44 +02:00
Andrey Antukh
004a9f17d3 Add minor js-like type schema formatting improvements 2025-05-20 13:29:44 +02:00
Andrey Antukh
c87fa4f723 Make the rpc doc generation lazy 2025-05-20 13:29:44 +02:00
Andrey Antukh
9378a5786f Replace json library used for generate openapi json 2025-05-20 13:29:44 +02:00
Andrey Antukh
3224ba26f1 ♻️ Replace :any schema with own ::sm/any
That a more specific, json friendly generator
2025-05-20 13:29:44 +02:00
Andrey Antukh
d33a5e6df1 Backport from develop partial improvements to sm/register! helper 2025-05-20 13:29:44 +02:00
Yamila Moreno
b6be416c7b 📎 Add wasm envvar to manage script 2025-05-20 12:15:14 +02:00
Aitor Moreno
aaa57cb17f 🐛 Fix inline styles in code tab (#6428) 2025-05-20 10:05:35 +02:00
Andrey Antukh
0b289153cb Add the ability to disable wasm on build script 2025-05-18 17:30:41 +02:00
Andrey Antukh
cf274099c4 Improve events/sse internal API
For make code cleaner and more evident for a quick view
2025-05-18 17:30:41 +02:00
Andrey Antukh
6524e75770 💄 Fix check-fn naming on types.container 2025-05-18 17:30:41 +02:00
Andrey Antukh
9b80f7c9b3 💄 Don't return unnecesary object from db query
the return value is already ignored
2025-05-18 17:30:41 +02:00
Andrey Antukh
bf76f328c8 Remove duplicate error logging on sse response 2025-05-18 17:30:41 +02:00
Alonso Torres
ba25ce3098 🐛 Fix share button being displayed with no permissions (#6476)
* 🐛 Fix share button being displayed with no permissions

*  Simplify impl by accessing perms from teams directly

---------

Co-authored-by: Andrey Antukh <niwi@niwi.nz>
2025-05-15 09:49:29 +02:00
Alejandro Alonso
f5f1316f0b Merge pull request #6474 from penpot/superalex-develop-paste-html-fix
🐛 Fix exception on paste invalid html
2025-05-14 16:16:53 +02:00
Andrey Antukh
79a164be6d 🐛 Fix exception on paste invalid html 2025-05-14 16:07:01 +02:00
alonso.torres
ecb85778bc 🐛 Fix problem with path edition of shapes 2025-05-14 14:45:29 +02:00
Andrés Moya
2cdc241e68 Merge branch 'hiru-update-tech-guide' into staging 2025-05-14 12:00:03 +02:00
Andrés Moya
057bf9bf25 📚 Update code samples 2025-05-14 11:38:55 +02:00
Andrés Moya
2ddcd0ce15 📚 Update Tech Guide about abstraction levels 2025-05-14 11:37:28 +02:00
Alonso Torres
ca2891d441 🐛 Fix problem syncing library colors and typographies (#6467) 2025-05-13 13:28:16 +02:00
Elenzakaleidos
37abb7b237 💄 Update video in readme page (#6461)
Signed-off-by: Elenzakaleidos <elena.scilinguo@kaleidos.net>
2025-05-13 08:10:19 +02:00
Ramiro Andres Sanchez Balo
5fc2208c16 📚 Improve metadata descriptions (#6457) 2025-05-13 08:09:59 +02:00
Andrey Antukh
86bcd1b681 🐛 Fix issue on shortcuts restore operation (#6462)
* 🐛 Fix issue on shortcuts restore operation

Happens when the order of shortcuts pop events is inconsistent with
push events. Using less strictly order policy for pop operations
allows relax this and make it eventually consistent.

* 💄 Add cosmetic changes on shortcuts hooks on colorpicker and    wport

* 📎 Update changelog

* 📎 Add PR feedback changes
2025-05-12 15:08:14 +02:00
Andrey Antukh
70b1989f10 Merge tag '2.7.0-RC2' 2025-05-12 13:11:40 +02:00
ºelhombretecla
e6b5618bd3 🎉 Add 2.7 release slides (#6440) 2025-05-12 11:38:00 +02:00
Alejandro Alonso
5199b306aa Merge pull request #6446 from penpot/niwinz-staging-bugfixes-2
🐛 Properly propagate export errors from worker to main thread
2025-05-12 10:47:46 +02:00
Alejandro Alonso
8febfaa21e Merge pull request #6447 from penpot/niwinz-staging-bugfixes
 Ensure read-only mode on non-workspace access to file
2025-05-12 10:43:02 +02:00
andrés gonzález
5e675dbf0b 📚 Update changelog for 2.7 (#6448) 2025-05-09 12:20:39 +02:00
Andrey Antukh
fc5d9659d6 🐛 Properly propagate export errors from worker to main thread 2025-05-09 11:15:04 +02:00
Andrey Antukh
bc20598b3d Don't persist file on several read operations
after applying migrations
2025-05-08 19:15:28 +02:00
Andrey Antukh
9de8ebb52c Add read-only option for files/get-file 2025-05-08 19:12:50 +02:00
Alonso Torres
9be569c54c 🐛 Fix problem when duplicating grid layout (#6426) 2025-05-08 13:39:47 +02:00
Alonso Torres
7e6a621484 🐛 Restore component fix order inside flex (#6432) 2025-05-08 13:37:59 +02:00
Eva Marco
66b47f9444 🐛 Fix resize bar background (#6435) 2025-05-08 13:37:00 +02:00
Alejandro Alonso
71aa8e5a86 Merge pull request #6434 from penpot/niwinz-staging-webhook-audit
 Add webhook trigger to the audit events
2025-05-08 13:00:04 +02:00
Andrey Antukh
e203536506 Add webhook trigger to audit events 2025-05-08 11:56:06 +02:00
Belén Albeza
3fe16bd8f9 🐛 Fix history panel shortcut (#6420)
*  Remove duplicate ID in file menu

* 🐛 Fix shortcut for Show Version History

*  Add regression test
2025-05-07 16:49:54 +02:00
Alejandro Alonso
a9725a1aac Merge pull request #6422 from penpot/superalex-add-even-to-power-up-link-from-workspace-menu
🐛 Add event to power up link from workspace menu
2025-05-07 15:13:31 +02:00
Alejandro Alonso
c3e76817cd 🐛 Add event to power up link from workspace menu 2025-05-07 13:45:57 +02:00
alonso.torres
36b78e5e21 🐛 Fix restore component restore layout 2025-05-05 11:50:08 +02:00
Alonso Torres
a2c9d307df 🐛 Fix problem in viewer with the back button (#6385) 2025-05-05 08:54:05 +02:00
Andrés Moya
e52fd90963 💄 Add copyright header to all tokens source files (#6389) 2025-05-01 10:06:17 +02:00
alonso.torres
d8b3b216e9 🐛 Fix import modal style problem 2025-04-30 10:48:48 +02:00
Andrey Antukh
a60b3d4b08 Merge pull request #6375 from penpot/hiru-move-tokens-staging
🔧 Reorganize tokens data functions
2025-04-29 10:43:13 +02:00
Andrés Moya
b14798b405 🔧 Make private function 2025-04-29 10:28:00 +02:00
Andrés Moya
8382a88efe 🔧 Move errors and warnings to workspace.data 2025-04-29 10:27:56 +02:00
Andrés Moya
53057c4bf2 🔧 Move token update to workspace.data and rename to propagation 2025-04-29 10:27:50 +02:00
Andrés Moya
3e0f38e8c3 🔧 Move token helpers to common.files 2025-04-29 10:27:46 +02:00
Andrés Moya
a5bbe765b9 🔧 Move style-dictionary and tinycolor to main.data 2025-04-29 10:27:42 +02:00
Andrés Moya
4455adc813 🔧 Move token lib edit to workspace.data and remove unused code 2025-04-29 10:27:38 +02:00
Andrés Moya
abca763aa5 🔧 Move token application to workspace.data 2025-04-29 10:27:20 +02:00
Andrey Antukh
62a12a64a3 Merge branch 'staging' into develop 2025-04-28 08:44:05 +02:00
Andrey Antukh
049427c6ca Merge branch 'main' into develop 2025-04-28 08:43:39 +02:00
alonso.torres
8ce71e792e Add dynamic properties modifiers to WASM 2025-04-25 15:03:24 +02:00
Elena Torro
44d68ad723 🐛 Calculate text-length in bytes correctly 2025-04-25 09:48:12 +02:00
Elena Torró
9e4c9d3101 Merge pull request #6353 from penpot/ladybenko-10867-comment-crash
🐛 Fix comment loading crash (new renderer viewport)
2025-04-25 08:41:51 +02:00
Andrey Antukh
050692952e Merge remote-tracking branch 'origin/staging' into develop 2025-04-24 15:11:12 +02:00
Belén Albeza
ab90d9d01c 🔧 Increase the cap for gradient stops 2025-04-24 12:20:34 +02:00
Belén Albeza
281c0068d9 Embed stop data into RawGradientData 2025-04-24 12:20:34 +02:00
Belén Albeza
e7b74939cb 💄 Change to more idiomatic code in main.rs functions 2025-04-24 12:20:34 +02:00
Elena Torró
c2ae58bf08 🎉 Add text shadows (#6335) 2025-04-24 12:19:41 +02:00
Elena Torró
14e8026e30 🐛 Fix take new lines into account when rendering text (#6337) 2025-04-24 12:16:21 +02:00
Xaviju
eb29a42209 📚 Update tokens changelog for 2.6.2 and 2.7 (#6363)
Co-authored-by: Xavier Julian <xaviju@proton.me>
2025-04-24 11:40:06 +02:00
Pablo Alba
6fdaad1bf4 🐛 Fix corner case when selecting component to switch (#6350) 2025-04-24 10:38:32 +02:00
Elena Torró
dfa6c502dc Improve left sidebar horizontal layers scroll (#6317) 2025-04-24 10:00:15 +02:00
Belén Albeza
b958dcb891 🐛 Fix positioning of comment thread draft (#6357)
* 🐛 Fix positioning of comment thread draft

* 📚 Update changelog
2025-04-24 09:53:07 +02:00
Andrey Antukh
9c4896d72b Merge remote-tracking branch 'origin/staging' into develop 2025-04-24 09:00:13 +02:00
Alejandro Alonso
01fec1a0cf Merge pull request #6339 from penpot/azazeln28-refactor-rebuild-tiles
♻️ Refactor how rebuild_tiles works
2025-04-24 07:38:56 +02:00
Aitor Moreno
caf13eb774 ♻️ Refactor how rebuild_tiles works 2025-04-24 07:34:35 +02:00
Marina López
fef342b489 🐛 Fixed team info settings alignment (#6354) 2025-04-23 22:59:07 +02:00
Pablo Alba
6e9adece1f 🐛 Fix problems cutting-paste a variant to another page or file (#6359) 2025-04-23 22:58:12 +02:00
Andrés Moya
c0315e2c30 🔥 Remove redundant schemas (and add some tooling) 2025-04-23 12:27:01 +02:00
Andrés Moya
2f20ccf289 🔥 Remove unused functions 2025-04-23 12:27:01 +02:00
Belén Albeza
1a7d60bb88 🐛 Fix comment loading crash 2025-04-23 12:15:16 +02:00
Alejandro Alonso
90b1895f19 Merge pull request #6352 from penpot/alotor-update-scripts
🐛 Fix wasm scripts
2025-04-23 11:39:15 +02:00
alonso.torres
7945a95522 🐛 Fix wasm scripts 2025-04-23 11:21:24 +02:00
Andrey Antukh
40fe6369cb Merge remote-tracking branch 'origin/staging' into develop 2025-04-23 08:59:33 +02:00
Alejandro Alonso
55da3ee275 Merge pull request #6349 from penpot/azazeln28-fix-rendering-order
🐛 Fix rendering order
2025-04-23 07:07:27 +02:00
Aitor Moreno
38a708e12b 🐛 Fix rendering order 2025-04-22 18:49:57 +02:00
Alonso Torres
53dcd94f0d Add support for self mentions (#6341) 2025-04-22 18:49:10 +02:00
Pablo Alba
a3ccc3dfef Select correct component to switch when changing variant property (#6346) 2025-04-22 18:48:18 +02:00
luisδμ
77d8504baf Selection of several components of a variant at the same time 2025-04-22 15:56:38 +02:00
Aitor Moreno
484772e3b2 Merge pull request #6313 from penpot/superalex-improve-images-performance-wasm
🎉 Improve images performance
2025-04-22 11:36:24 +02:00
Alejandro Alonso
5c7a1fb407 🎉 Improve tile caching 2025-04-22 11:03:21 +02:00
Pablo Alba
064981ff3d Merge remote-tracking branch 'origin/staging' into develop 2025-04-22 10:44:29 +02:00
Pablo Alba
fe003d7496 Add removal of variant container when it becomes empty (#6311) 2025-04-22 09:22:18 +02:00
Pablo Alba
fae1df7f4b 🐛 Fix extract component variant from variant with path (#6303) 2025-04-22 09:18:31 +02:00
Florian Schrödl
0bff76e5f1 Don't override user provided color format (#6231) 2025-04-22 09:10:07 +02:00
Elena Torró
c7b062f483 Merge pull request #6278 from penpot/elenatorro-send-leaf-attrs-uint-arr
🔧 Parse text leaves all at once
2025-04-21 14:27:26 +02:00
Elena Torro
83f72f3e41 🔧 Parse text leaves all at once 2025-04-21 13:24:39 +02:00
Aitor Moreno
d8b71d76dd Merge pull request #6225 from penpot/elenatorro-10710-render-text-while-typing
🎉 Render text while typing
2025-04-21 12:33:08 +02:00
Aitor Moreno
a6d2f385af Merge pull request #6266 from penpot/superalex-fix-path-unions
🐛 Fix unions for new render
2025-04-21 11:23:14 +02:00
Pablo Alba
db9e397531 🐛 Fix variant from a shared lib doesnt't show props 2025-04-21 09:25:00 +02:00
Elena Torró
18dea6c3a3 Merge pull request #6298 from penpot/ladybenko-10752-gradient-stops
 Send fill + Stops in a single wasm call
2025-04-21 09:17:26 +02:00
Alejandro Alonso
8ebaecc472 🐛 Fix unions for new render 2025-04-21 08:10:15 +02:00
Andrey Antukh
43a75b64b4 Merge pull request #6318 from penpot/ladybenko-10781-rust-devenv
🔧 Improve Rust dev env
2025-04-17 08:48:50 +02:00
Xaviju
3a741d1c14 🐛 Hide inactive warning if sets are empty (#6295)
* 🐛 Hide inactive warning if sets are empty

* 📎 Add simplified impl with proper comment

---------

Co-authored-by: Xavier Julian <xaviju@proton.me>
Co-authored-by: Andrey Antukh <niwi@niwi.nz>
2025-04-16 17:17:13 +02:00
Pablo Alba
ba442e1549 Allow copy-paste variants into another file (#6319) 2025-04-16 17:12:12 +02:00
Andrés Moya
8c15296d07 Merge branch 'tokens-studio-hyma/99-improve-token-error-messages' into develop 2025-04-16 16:31:53 +02:00
Florian Schroedl
d26464c810 Catch invalid name errors in json 2025-04-16 16:30:47 +02:00
Belén Albeza
8ee202e5a1 🔧 Fix emscripten version in devenv 2025-04-16 15:30:29 +02:00
Belén Albeza
689cddfd0c 🔧 Use cargo env variable for target and allow to override it as well as SKIA_BINARIES_URL 2025-04-16 15:05:31 +02:00
Elena Torró
25950bb5a5 Merge pull request #6312 from penpot/elenatorro-fix-children-removal-regression
🐛 Fix last shape removal
2025-04-16 15:03:26 +02:00
Belén Albeza
1da623e63f 💄 Change naming and args order of write-gradient-fill! 2025-04-16 14:09:24 +02:00
Belén Albeza
4bf9e24d43 ♻️ Avoid using get-prop when unneeded in serializers 2025-04-16 14:09:24 +02:00
Belén Albeza
b41a7b8547 💄 Remove no longer used functions in wasm serialization 2025-04-16 14:09:23 +02:00
Belén Albeza
f500a00d04 ♻️ Extract wasm-functions for fills and strokes out of main.rs 2025-04-16 14:09:19 +02:00
Belén Albeza
64a2a08d24 ♻️ Refactor gradient parsing from bytes 2025-04-16 14:08:38 +02:00
Belén Albeza
1f58f96e88 ♻️ Refactor serializing gradient fill 2025-04-16 14:07:35 +02:00
Belén Albeza
dc3d802d3d 🎉 Serialize radial fills in one go 2025-04-16 14:07:35 +02:00
Belén Albeza
5765d1c56c ♻️ Switch to a f32 offset for gradient stops 2025-04-16 14:07:35 +02:00
Belén Albeza
abcd050c69 ♻️ Adapt linear gradient type so it can be used for radial too (wasm) 2025-04-16 14:07:33 +02:00
Belén Albeza
f40ef26c69 ♻️ Move color and fill serializers to their own sub-namespaces 2025-04-16 14:06:22 +02:00
Belén Albeza
fccd1a5bd7 Send fill + stops data in one call for linear fills 2025-04-16 14:05:39 +02:00
Alejandro Alonso
16012a3881 Merge remote-tracking branch 'origin/staging' into develop 2025-04-16 13:15:18 +02:00
Marina López
7ada3692cf Design improvements to the Invitations page with an empty state 2025-04-16 12:38:47 +02:00
Elena Torro
1ab5d5027f 🐛 Fix last shape removal 2025-04-16 12:37:29 +02:00
Alejandro Alonso
1f16816fe4 Merge pull request #6310 from penpot/alotor-perf-reparent-modifiers
 Reparent modifiers
2025-04-16 12:21:20 +02:00
alonso.torres
daf048e258 Reparent modifiers 2025-04-16 11:27:51 +02:00
Alejandro Alonso
f3d13005b2 🐛 Fix avoid uncacheable tiles (#6281) 2025-04-16 10:59:24 +02:00
Elena Torró
25a44e1387 Merge pull request #6306 from penpot/ladybenko-fix-raf-macros
🐛 Fix broken test build for rust wasm
2025-04-16 07:15:27 +02:00
Belén Albeza
9e9612cf1f 🐛 Fix broken test build for rust wasm 2025-04-15 16:58:49 +02:00
Aitor Moreno
304c44048f ♻️ Refactor how rAF/cAF is handled (#6241) 2025-04-15 15:45:28 +02:00
Alejandro Alonso
99e64ad387 Merge pull request #6274 from penpot/alotor-perf-grid-layout-modifiers-3
 Modifiers grid multi-span
2025-04-15 13:39:45 +02:00
Marina López
0f0c45af8e Propagate sharing a prototype to editors and viewers (#6297) 2025-04-15 12:50:01 +02:00
Marina López
f2977cf938 Visual indicators for unlimited tier users (#6270)
*  Visual indicators for unlimited tier users

* ♻️ Refactor to organize properly subscription

* ♻️ Refactor with PR feedback

* 💄 Add minor cosmetic changes

---------

Co-authored-by: Andrey Antukh <niwi@niwi.nz>
2025-04-15 12:47:37 +02:00
Andrey Antukh
bb80da137d Merge remote-tracking branch 'origin/staging' into develop 2025-04-15 12:10:53 +02:00
Pablo Alba
f4b16a255c Copy values of same named properties moving a variant into another (#6288)
*  Copy values of same named properties moving a variant into another

*  Add MR changes
2025-04-15 12:06:58 +02:00
Marina López
ec8c30f060 Update board presets with newer devices (#6296) 2025-04-15 10:42:46 +02:00
Andrey Antukh
7990400c7a 🐛 Fix srepl helper for restore file snapshots (#6300) 2025-04-15 10:39:51 +02:00
Eva Marco
eee5cf5fb4 Add duplicate sets feature (#6240)
*  Add duplicate sets feature

*  Add test to each module

* 🎉 Fix comments

* 🎉 Remove duplicate from groups

* 🎉 Remove create theme from test

* 🎉 Remove ' from names
2025-04-14 16:22:40 +02:00
Xavier Julian
f5c699ab7a Improve copy on inactive set warning title 2025-04-14 10:30:48 +02:00
Pablo Alba
dcf1a593f7 Add playwright tests for cut-copy-paste variants 2025-04-11 15:17:33 +02:00
Pablo Alba
785b61be2f Fix corner cases of duplicate/copy-paste/cut-paste variants 2025-04-11 15:17:33 +02:00
Elena Torró
39c7782019 Merge pull request #6264 from penpot/elenatorro-10681-update-component-color-preview
🐛 Update the component thumbnail on component change
2025-04-11 14:33:07 +02:00
Alejandro Alonso
1c5c51907a Merge remote-tracking branch 'origin/staging' into develop 2025-04-11 14:05:00 +02:00
alonso.torres
a59014cad0 Modifiers grid multi-span 2025-04-11 13:35:16 +02:00
Aitor Moreno
87650de9bc 🐛 Fix color gradient on text positioned incorrectly (#6253) 2025-04-11 11:36:31 +02:00
Florian Schrödl
ee5596067e ⬆️ Upgrade style_dictionary dependency to v5-rc1 (#6283) 2025-04-11 11:31:28 +02:00
Eva Marco
870fec6bbd 🐛 Fix modal hint as context notification (#6276) 2025-04-11 11:27:30 +02:00
Alejandro Alonso
686ab14b43 Merge pull request #6282 from penpot/alotor-fix-bool-wasm
🐛 Fix problem with booleans in wasm
2025-04-11 11:06:31 +02:00
alonso.torres
fced0cf3b1 🐛 Fix problem with booleans in wasm 2025-04-11 10:56:08 +02:00
Andrey Antukh
25dd53290c 🐛 Fix component thumbnail refresh on change
Happens when a component is nested in an other top level frame
2025-04-11 10:40:56 +02:00
Elena Torró
de8e27feb8 Merge pull request #6242 from penpot/ladybenko-10666-builtin-fonts
🎉 Load built-in font and its variants (wasm)
2025-04-11 08:48:31 +02:00
luisδμ
e7144142e5 Add, edit and delete variant properties from layer panel (#6257) 2025-04-10 21:15:23 +02:00
Xavier Julian
b6f2a434cf Display inactive set warning 2025-04-10 15:02:30 +02:00
Alonso Torres
caf558f8dd 🐛 Fix import error messages (#6265) 2025-04-10 14:46:50 +02:00
Florian Schrödl
6f2f1b7a76 ⬆️ Update style dictionary to 4.3.3 (#6260)
Co-authored-by: Andrey Fedorov <oran9e.red@gmail.com>
2025-04-10 14:42:24 +02:00
Elena Torró
744ef1958b Merge pull request #6269 from penpot/elenatorro-fix-render-wasm-tests
🔧 Return the test output
2025-04-10 14:19:02 +02:00
Elena Torro
08b44e1857 🔧 Return the test output 2025-04-10 14:10:05 +02:00
Eva Marco
580b60550c 🐛 Fix notification vertical alignment (#6272) 2025-04-10 13:53:20 +02:00
Elena Torró
20f695e8d7 Merge pull request #6271 from penpot/ladybenko-fix-test-run
🔧 Update test script to use the right architecture
2025-04-10 13:04:22 +02:00
Belén Albeza
1d7ff1f9e4 🔧 Fix requiring an emscripten macro in non-wasm architectures 2025-04-10 12:52:56 +02:00
Belén Albeza
5b18f1d76d 🔧 Update test script to use the right architecture 2025-04-10 12:50:22 +02:00
Aitor Moreno
d880307a9b 🎉 Add performance measuring functions (#6229) 2025-04-10 11:33:22 +02:00
Alejandro
97c24c8b9c 🐛 Fix merge path nodes with only one node selected (#6248) 2025-04-10 09:08:44 +02:00
Alejandro Alonso
43535ae573 Merge remote-tracking branch 'origin/staging' into develop 2025-04-10 08:40:29 +02:00
Alejandro
61643f676c Merge pull request #6249 from penpot/elenatorro-10750-fix-path-nil-svg-attrs
🔧 Do not try to set svg path attrs if none
2025-04-10 06:51:50 +02:00
Alejandro
9b8c8c4971 Merge pull request #6258 from penpot/elenatorro-10756-delete-last-shape
🐛 Remove children correctly
2025-04-10 06:49:41 +02:00
Alejandro
033ca0d56b 🐛 Fix error when an external user tries to export a shape on viewer (#6252) 2025-04-09 16:48:49 +02:00
Alonso Torres
28a6797595 🐛 Fix problem with error detail in toast (#6259) 2025-04-09 16:36:11 +02:00
Elena Torro
953db56a0d 🐛 Remove children correctly 2025-04-09 14:39:21 +02:00
Alejandro Alonso
82cf474863 Merge remote-tracking branch 'origin/staging' into develop 2025-04-09 13:52:54 +02:00
Andrey Antukh
edfcac3d5c 🐛 Restore uid assignation on devenv entrypoint 2025-04-09 13:11:12 +02:00
Alejandro Alonso
774e11c827 Merge remote-tracking branch 'origin/staging' into develop 2025-04-09 12:53:18 +02:00
Elena Torro
43f77376b6 🔧 Do not try to set svg path attrs if none 2025-04-09 10:13:39 +02:00
Belén Albeza
c0ba92f503 🎉 Add support for default font variants (wasm) 2025-04-08 16:45:27 +02:00
Belén Albeza
90cb0357c6 🎉 Swap default font for source sans (wasm) 2025-04-08 14:48:28 +02:00
Alejandro
d55e55ebcc Merge pull request #6237 from penpot/niwinz-upgrade-devenv
⬆️ Upgrade devenv (ubuntu, jvm, node)
2025-04-08 10:50:50 +02:00
Aitor Moreno
c2522329fd Merge pull request #6235 from penpot/alotor-perf-grid-layout-modifiers-2
 Grid layout modifiers
2025-04-08 09:47:42 +02:00
Alejandro
2470c1788e 🐛 Fix render wasm build (#6239) 2025-04-08 09:06:32 +02:00
Pablo Alba
230d259551 Merge pull request #6238 from penpot/luis-improve-input-with-values-doc
📚 Update documentation for input-with-values component
2025-04-07 23:31:40 +02:00
Luis de Dios
cb533335c4 📚 Update documentation for input-with-values component 2025-04-07 17:18:21 +02:00
Andrés Moya
a8890e4b13 Merge branch 'tokens-studio-florian-70-sets-in-theme-create' into develop 2025-04-07 17:08:33 +02:00
Florian Schroedl
0281e0dba4 🚧 Explicit state handling 2025-04-07 16:42:43 +02:00
Florian Schroedl
1c209f49fc 🚧 Don't expose state 2025-04-07 16:36:02 +02:00
Andrey Antukh
a4701866a4 ⬆️ Upgrade devenv (ubuntu, jvm, node) 2025-04-07 16:26:04 +02:00
Florian Schroedl
12f72c8ca9 🚧 Show back button only when coming from a modal view 2025-04-07 16:04:18 +02:00
Florian Schroedl
c1165bd12d 🚧 Convert rumext 2025-04-07 16:04:18 +02:00
Florian Schroedl
215fb53c52 🚧 Use use-fn 2025-04-07 16:04:18 +02:00
Florian Schroedl
8df780b237 Allow editing of sets in create theme dialog
♻️ theme-state -> current-theme
2025-04-07 16:04:18 +02:00
Andrés Moya
79679cbb16 Merge branch 'tokens-studio-andrei/91-single-set-import-refactoring' into develop 2025-04-07 15:56:22 +02:00
Andrey Fedorov
fb2db4b918 ♻️ Refactor single set import functionality 2025-04-07 15:48:27 +02:00
Andrey Antukh
05b66f1dcf Merge remote-tracking branch 'origin/develop' into develop 2025-04-07 14:45:29 +02:00
Andrey Antukh
0f1b2003be Merge branch 'staging' into develop 2025-04-07 14:45:08 +02:00
Belén Albeza
6f91da9461 🔧 Fix Rust tests (#6208)
* 🔧 Fix test script (rust wasm)

* 🔧 Make code compile in test mode + using aarch64 as a target for tests
2025-04-07 14:08:41 +02:00
alonso.torres
63666fca48 Grid layout modifiers 2025-04-07 11:51:28 +02:00
Andrey Antukh
d279b6c232 📎 Fix linter issues 2025-04-07 11:40:19 +02:00
Andrey Antukh
17f7f920c4 Merge branch 'staging' into develop 2025-04-07 11:32:41 +02:00
Andrey Antukh
b55c86544b 📎 Fix linter issues 2025-04-07 10:52:07 +02:00
Pablo Alba
af1d5b86e1 Merge pull request #6214 from penpot/palba-cleanup-components-v2
♻️ Cleanup of componentsv2
 Add check to avoid open files with components v1
2025-04-07 10:18:53 +02:00
Alonso Torres
137e8d042f 🐛 Fix problem with boolean edges (#6218) 2025-04-07 09:19:43 +02:00
Elena Torro
4ceaedcbe8 🎉 Render text while typing 2025-04-04 14:02:02 +02:00
Pablo Alba
f375cc9a82 Add check to avoid open files with components v1 2025-04-04 11:08:30 +02:00
Elena Torró
5937ed57ce 🎉 Update font and variant on change (#6220) 2025-04-04 10:17:39 +02:00
Aitor Moreno
2e3ed0c23f Merge pull request #6230 from penpot/azazeln28-fix-mem-bytes-alloc-32
🐛 Fix bytes-alloc-32
2025-04-04 09:55:34 +02:00
Aitor Moreno
5d1d2ef289 🐛 Fix bytes-alloc-32 2025-04-04 09:43:48 +02:00
Elena Torró
480c224250 🐛 Fix long file names (#6216)
* 🔧 Add truncate str macro

* 🐛 Use truncate instead of prune to prevent title override

* 💄 Use text-overflow ellipsis on file names

* 📎 Add #10662 to 2.7 bugfixes
2025-04-03 16:06:02 +02:00
Aitor Moreno
cd731c3ad2 ♻️ Refactor heap usage (#6204) 2025-04-03 16:04:51 +02:00
Andrey Antukh
9bc49e3381 Merge pull request #6209 from penpot/niwinz-features-enhancement
 Make feature resolved on team load
2025-04-03 15:43:12 +02:00
Pablo Alba
f961b75bba ♻️ Cleanup of componentsv2 2025-04-03 11:38:35 +02:00
Marina López
1e16fb8ca2 🐛 Fix horizontal scroll from design tab (#6213) 2025-04-02 20:00:22 +02:00
Elena Torró
c332528185 🐛 Fix render object with pending status (#6215) 2025-04-02 19:58:03 +02:00
Pablo Alba
387c5e67f3 🐛 Fix flick on create variant (#6217) 2025-04-02 19:54:48 +02:00
Elena Torró
2ed780e14d Merge pull request #6205 from penpot/elenatorro-10528-fix-google-font-variant-styles
🐛 Fix Google Fonts load by parsing italic variant ids correctly
2025-04-02 17:16:51 +02:00
Pablo Alba
1b8714fe7f 🐛 Fix position problems cutting-pasting a component 2025-04-02 12:10:18 +02:00
Andrey Antukh
e28f8cae74 Merge remote-tracking branch 'origin/staging' into develop 2025-04-02 10:34:31 +02:00
Andrey Antukh
87ef98dad5 Consolidate layout/grid feature 2025-04-01 21:15:38 +02:00
Andrey Antukh
e6e71e9278 Add minor enhacement for error reporting 2025-04-01 20:24:07 +02:00
Andrey Antukh
02220d02ed ⬆️ Update svgo 2025-04-01 20:01:21 +02:00
Andrey Antukh
ff7b77bda7 ⬆️ Update yarn 2025-04-01 20:01:21 +02:00
Andrey Antukh
f8ffae75c4 Make feature resolved on team load
That simplifies features retrieval to simple get
2025-04-01 20:01:21 +02:00
Andrey Antukh
cb350b26a1 Merge remote-tracking branch 'origin/develop' into develop 2025-04-01 18:27:02 +02:00
Andrey Antukh
dccebb0bea Merge remote-tracking branch 'origin/staging' into develop 2025-04-01 18:26:37 +02:00
Elena Torró
4cefbb52e1 Merge pull request #6206 from penpot/azazeln28-fix-not-enough-surfaces
🐛 Fix not enough surfaces
2025-04-01 15:47:59 +02:00
Elena Torro
d757009b48 🐛 Fix Google Fonts load by parsing italic variant ids correctly 2025-04-01 14:01:54 +02:00
Aitor Moreno
ca202711e1 🐛 Fix not enough surfaces 2025-04-01 13:41:33 +02:00
Pablo Alba
f04229d8cb 🎉 Allow duplicate/copy-paste/cut-paste variants 2025-04-01 11:07:22 +02:00
Andrey Antukh
076d64df8f Merge remote-tracking branch 'origin/staging' into develop 2025-04-01 11:02:32 +02:00
Elena Torró
3d7479f9aa 🐛 Fix stroke image rendering (#6189) 2025-04-01 09:55:19 +02:00
Elena Torró
76ffc2d268 🔧 Log error on process animation frame (#6182) 2025-04-01 09:01:49 +02:00
Elena Scilinguo
d0d118b31e 📚 Update README.md
Signed-off-by: Elena Scilinguo <elena.scilinguo@kaleidos.net >
2025-04-01 08:51:23 +02:00
Elena Torró
895b5b2ee1 🐛 Fix new line parsing (#6180) 2025-03-31 14:59:34 +02:00
Elena Torró
9fd0e9af66 Merge pull request #6178 from penpot/ladybenko-10528-google-fonts
🎉 Render text that uses a google font (wasm)
2025-03-31 11:55:57 +02:00
luisδμ
648a8f9237 Allow modifying property name when a variation is selected (#6174)
*  Change property name when a variation is selected

* 📎 PR changes
2025-03-31 09:12:43 +02:00
Aitor Moreno
4e1ae1bc1a Merge pull request #6181 from penpot/superalex-tada-avoid-full-tiles-rebuild-on-set-modifiers
🎉 Avoid full tiles rebuild on set modifiers
2025-03-28 16:27:30 +01:00
Aitor Moreno
b6ac1dea4d 🐛 Fix TileSurfaceCache not deref surfaces 2025-03-28 16:14:37 +01:00
Belén Albeza
219d9af885 ♻️ Simplify font ids 2025-03-28 15:21:42 +01:00
Belén Albeza
c6bba54573 ♻️ Refactor font-related wasm code into a sub-namespace 2025-03-28 15:17:13 +01:00
Belén Albeza
f53cae0faa 🎉 Render text that uses a Google Font 2025-03-28 15:17:12 +01:00
Alejandro Alonso
6953a57333 🎉 Avoid full tiles rebuild on set modifiers 2025-03-28 11:55:54 +01:00
Alejandro
a109f11926 Merge pull request #6187 from penpot/azazeln28-fix-surface-pool-missing-deallocation
🐛 Fix SurfacePool missing deallocation
2025-03-28 11:55:45 +01:00
Alejandro
45c9904e05 Merge pull request #6155 from penpot/azazeln28-feat-cache-extra-tiles
🎉 Cache extra tiles
2025-03-28 11:55:31 +01:00
Aitor Moreno
08fc32cdc6 🎉 Cache extra tiles 2025-03-28 11:34:18 +01:00
Aitor Moreno
6c10f1e364 🐛 Fix SurfacePool missing deallocation 2025-03-28 11:34:04 +01:00
Alejandro
e8549ffb79 Merge pull request #6177 from penpot/azazeln28-feat-sort-viewport-tiles
🎉 Sort viewport tiles by distance to center
2025-03-28 11:32:08 +01:00
Aitor Moreno
8a8d89dfc0 🎉 Sort viewport tiles by distance to center 2025-03-28 11:22:10 +01:00
Pablo Alba
b6c4376217 🐛 Fix bugs from varaints design review 2025-03-28 11:20:10 +01:00
Alejandro
bd5e47f5fc Merge pull request #6126 from penpot/elenatorro-10516-fix-stroke-shadows
🐛 Fix stroke shadows
2025-03-28 09:54:39 +01:00
Alejandro
2aa756af38 Merge pull request #6175 from penpot/niwinz-develop-binfile-path-fix
🐛 Fix binfile-v3 importation related to bool shape normalization
2025-03-28 09:46:16 +01:00
Andrey Antukh
78c2840b22 Merge remote-tracking branch 'origin/staging' into develop 2025-03-28 09:45:34 +01:00
Aitor Moreno
af0a516a79 🐛 Fix path editing with wrong selrect (#6168) 2025-03-28 09:43:46 +01:00
Andrey Antukh
651beb4b9c 🐛 Fix binfile-v3 importation related to bool shape normalization 2025-03-28 08:57:47 +01:00
Elena Torro
f4d04a3dcb 🐛 Fix Stroke Shadows
- Move shadows surface responsibility
- Draw shadows directly into DropShadows and InnerShadows surfaces
- Draw stroke shadows directly into Strokes in order
- Clean up old shadow surfaces (Shadow & Overlay)
2025-03-28 08:56:37 +01:00
Elena Torró
d573da55b0 Merge pull request #6179 from penpot/elenatorro-10530-fix-paragraph
🐛 Revert offset change to fix paragraph rendering
2025-03-27 17:29:50 +01:00
Elena Torro
3c4be537d9 🐛 Revert offset change to fix paragraph rendering 2025-03-27 17:17:36 +01:00
Elena Torró
9800331505 🎉 Improve performance reducing unnecessary calls to set-objects
🎉 Improve performance reducing unnecessary calls to set-objects
2025-03-27 16:19:36 +01:00
Alejandro Alonso
7728d5b317 🎉 Improve performance reducing unnecessary calls to set-objects 2025-03-27 15:47:03 +01:00
Aitor Moreno
8f47ed8b0a Merge pull request #6136 from penpot/superalex-disable-svg-viewport-texts-for-wasm-render
🐛 Disable svg viewport texts for wasm render
2025-03-27 14:46:38 +01:00
Alejandro
c137e682dc Merge pull request #6172 from penpot/elenatorro-10530-fix-text-drag-and-drop
 Render text properly while dragging and resizing the text Shape
2025-03-27 14:18:11 +01:00
Andrey Antukh
14c639a425 🐛 Fix bool type shape normalize migration 2025-03-27 14:15:13 +01:00
Elena Torró
06bfb1ad26 🎉 Add PathData data type
🎉 Add PathData data type
2025-03-27 13:39:54 +01:00
Elena Torro
33c3611345 Render text properly while dragging and resizing the text Shape 2025-03-27 13:04:45 +01:00
Alejandro Alonso
e012046f62 Merge remote-tracking branch 'origin/staging' into develop 2025-03-27 12:12:57 +01:00
Andrey Antukh
ebf3730454 Normalize the content prop from bool type (#6162)
Make it the same as path shape, because they are essentially the
same data type
2025-03-27 11:15:48 +01:00
Aitor Moreno
3cf823ffb3 Merge pull request #6137 from penpot/superalex-rendering-wasm-performance
🎉 Avoid rendering too small shapes
2025-03-27 10:22:02 +01:00
Aitor Moreno
6231a9f931 Merge pull request #6130 from penpot/azazeln28-fix-tile-cache-exhaustion
🐛 Fix tile cache exhaustion
2025-03-27 09:51:16 +01:00
Elena Torró
dd30e939ae 📎 Add #9489 bug fix to CHANGELOG
📎 Add #9489 bug fix to CHANGELOG
2025-03-26 14:14:34 +01:00
Elena Torro
6f2e1d3794 📎 Add #9489 bug fix to CHANGELOG 2025-03-26 13:55:42 +01:00
Elena Torró
2e41bd7607 🐛 Fix linecap SVG path property (#6163) 2025-03-26 13:46:35 +01:00
Andrey Antukh
b9907ec401 🎉 Add PathData data type
That replaces the ad-hoc helpers for convert path content from
plain with encapsulated type that implements the appropriate
clojure protocols and interfaces that helps interacting with
binary encoded path data
2025-03-26 13:17:25 +01:00
Andrey Antukh
416e9e8e1d Merge remote-tracking branch 'origin/staging' into develop 2025-03-26 13:15:58 +01:00
Alonso Torres
83d41dba6f Serialization of grid layout data (#6148)
*  Add serializators for grid layout properties

*  Extract serializers for wasm api module
2025-03-26 12:10:31 +01:00
Pablo Alba
7284fb539f 🐛 Fix when editing a property name, the wrong property changes name (#6156) 2025-03-26 11:17:48 +01:00
luisδμ
f932f3efb1 Filter variant by name on layers panel 2025-03-25 21:50:29 +01:00
Aitor Moreno
60bc88a075 🐛 Fix tile cache exhaustion 2025-03-25 16:35:49 +01:00
Aitor Moreno
6eb686c06b ♻️ Refactor Custom Fonts allocations (#6146)
* ♻️ Refactor Custom Fonts allocations

* 💄 Remove commented code

---------

Co-authored-by: Belén Albeza <belen@hey.com>
2025-03-25 15:34:11 +01:00
Alejandro
065b50f5a2 🐛 Fix asynchronous content dependant rendering (#6142)
* 🐛 Fix custom fonts rendering

* 🐛 Fix asynchronous content dependant rendering

* 🎉 Renaming clear_cache to clear_drawing_cache
2025-03-25 09:49:47 +01:00
Alejandro Alonso
85b24e1e8d 🎉 Disable antialias for small shapes 2025-03-24 16:27:43 +01:00
Pablo Alba
9653e72e47 ♻️ Refactor variants
* ♻️ Refactor variants

*  Add MR changes
2025-03-24 13:15:02 +01:00
Alejandro Alonso
a80f114d66 🎉 Avoid rendering too small shapes 2025-03-24 11:49:38 +01:00
Alejandro Alonso
74ae4743d8 🐛 Disable svg viewport texts for wasm render 2025-03-24 11:06:14 +01:00
Andrey Antukh
d1d30e7eb5 Revert "📎 Add workaround for wasm production build failure"
This reverts commit f8a2291a55.
2025-03-24 10:48:22 +01:00
Andrey Antukh
e83be01475 Merge remote-tracking branch 'origin/staging' into develop 2025-03-24 10:42:14 +01:00
Aitor Moreno
22efd6574d Merge pull request #6125 from penpot/alotor-perf-flex-layout-2
 Improvements on flex layout positioning
2025-03-24 09:53:30 +01:00
Andrey Antukh
f8a2291a55 📎 Add workaround for wasm production build failure 2025-03-21 14:07:02 +01:00
Andrey Antukh
8c302e314f Merge remote-tracking branch 'origin/staging' into develop 2025-03-21 11:17:26 +01:00
alonso.torres
a830c27ceb Improvements on flex layout positioning 2025-03-21 10:18:34 +01:00
Alejandro
4c12af957c Merge pull request #6121 from penpot/superalex-tada-improve-tile-shapes-iteration-2
🎉 Improve tile shapes iteration
2025-03-21 07:30:52 +01:00
Alejandro Alonso
9ea3c54b92 🎉 Improve tile shapes iteration 2025-03-21 07:20:45 +01:00
Aitor Moreno
4620764111 Merge pull request #6127 from penpot/superalex-fix-wasm-state-warning
🐛 Fix wasm state warning
2025-03-20 18:47:49 +01:00
Alejandro Alonso
ca86137d0f 🐛 Fix wasm state warning 2025-03-20 18:18:50 +01:00
Alejandro Alonso
b299a732c0 Merge remote-tracking branch 'origin/staging' into develop 2025-03-20 18:08:06 +01:00
Alejandro
7a4c9d9933 Merge pull request #6122 from penpot/elenatorro-10516-fix-inner-shadow-rendering
🐛 Fix Fill Inner Shadow rendering
2025-03-20 15:46:15 +01:00
Elena Torro
91d15ea221 🐛 Fix Fill Inner Shadows 2025-03-20 15:20:15 +01:00
Andrey Antukh
b043fec0d5 🌐 Validate and rehash translation files 2025-03-20 14:46:46 +01:00
Andrey Antukh
0bab46eb5c Merge remote-tracking branch 'weblate/develop' into develop 2025-03-20 14:45:42 +01:00
Andrey Antukh
82bff09373 🐛 Fix incorrect syntax on spanish translation file 2025-03-20 14:45:20 +01:00
Andrey Antukh
329b2d30d0 Revert "🌐 Sync, validate and rehash translations"
This reverts commit 37a8bf7bfc.
2025-03-20 14:44:57 +01:00
Anonymous
0d65b652d4 🌐 Add translations for: Swedish
Currently translated at 93.1% (1612 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/sv/
2025-03-20 14:42:44 +01:00
Anonymous
9d3c19e86a 🌐 Add translations for: Yoruba
Currently translated at 69.1% (1196 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/yo/
2025-03-20 14:42:43 +01:00
Anonymous
56a7800519 🌐 Add translations for: Hausa
Currently translated at 72.9% (1262 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/ha/
2025-03-20 14:42:43 +01:00
Anonymous
ba0cebd713 🌐 Add translations for: Dutch
Currently translated at 94.0% (1627 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/nl/
2025-03-20 14:42:43 +01:00
Anonymous
e28628d148 🌐 Add translations for: Latvian
Currently translated at 94.0% (1627 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/lv/
2025-03-20 14:42:42 +01:00
Anonymous
40bc860dc6 🌐 Add translations for: Ukrainian (ukr_UA)
Currently translated at 93.9% (1626 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/ukr_UA/
2025-03-20 14:42:42 +01:00
Anonymous
decf32fdd5 🌐 Add translations for: Croatian
Currently translated at 93.8% (1623 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/hr/
2025-03-20 14:42:42 +01:00
Anonymous
d9d6ee9922 🌐 Add translations for: Portuguese (Portugal)
Currently translated at 88.9% (1539 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/pt_PT/
2025-03-20 14:42:42 +01:00
Anonymous
903609a38f 🌐 Add translations for: Czech
Currently translated at 93.6% (1621 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/cs/
2025-03-20 14:42:41 +01:00
Anonymous
4504903b4c 🌐 Add translations for: Italian
Currently translated at 93.9% (1626 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/it/
2025-03-20 14:42:40 +01:00
Anonymous
4bf4972b6e 🌐 Add translations for: Chinese (Traditional Han script)
Currently translated at 93.9% (1626 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/zh_Hant/
2025-03-20 14:42:40 +01:00
Anonymous
47e4b41dd2 🌐 Add translations for: Hebrew
Currently translated at 94.0% (1627 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/he/
2025-03-20 14:42:39 +01:00
Anonymous
af413ff1c0 🌐 Add translations for: Indonesian
Currently translated at 94.0% (1627 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/id/
2025-03-20 14:42:39 +01:00
Anonymous
5fcf0808c6 🌐 Add translations for: German
Currently translated at 94.0% (1627 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/de/
2025-03-20 14:42:39 +01:00
Anonymous
fb956b3aa1 🌐 Add translations for: Chinese (Simplified Han script)
Currently translated at 79.3% (1373 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/zh_Hans/
2025-03-20 14:42:38 +01:00
Anonymous
93986af181 🌐 Add translations for: Russian
Currently translated at 83.5% (1446 of 1730 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/ru/
2025-03-20 14:42:38 +01:00
Andrey Antukh
37a8bf7bfc 🌐 Sync, validate and rehash translations 2025-03-20 14:41:50 +01:00
Elena Torro
e60e36a0e2 🔧 Refactor RenderState scale calculation 2025-03-20 14:36:45 +01:00
Hosted Weblate
199e182399 🌐 Update translation files
Updated by "Cleanup translation files" hook in Weblate.

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/
2025-03-20 14:31:52 +01:00
Andrey Antukh
a9f4b29f32 Merge remote-tracking branch 'weblate/develop' into develop 2025-03-20 14:31:09 +01:00
Andrey Antukh
22cd43b8a2 Merge remote-tracking branch 'origin/staging' into develop 2025-03-20 14:27:37 +01:00
Alejandro
2d61644b05 Merge pull request #5914 from penpot/azazeln28-feat-tile-rendering
🎉 Tile rendering
2025-03-20 11:25:58 +01:00
Aitor Moreno
084816fb9f 🎉 Tile rendering system 2025-03-20 11:14:14 +01:00
william chen
b5ea90f740 🌐 Add translations for: Chinese (Traditional Han script)
Currently translated at 100.0% (1646 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/zh_Hant/
2025-03-20 10:02:52 +01:00
Andrey Antukh
e6839e4983 Merge pull request #6106 from penpot/palba--variants-inspect-header
 Add subtitle to inspect tab for components
2025-03-19 13:42:57 +01:00
Pablo Alba
82d3e466be Add subtitle to inspect tab for components 2025-03-19 10:34:19 +01:00
Alejandro
b0dacf6b11 Merge pull request #6105 from penpot/superalex-add-changelog-for-2.7.0
📎 Update changelog (add entry for 2.7.0)
2025-03-19 10:02:49 +01:00
Alejandro Alonso
64d090839d 📎 Update changelog (add entry for 2.7.0) 2025-03-19 09:51:22 +01:00
al0cam
12d3994f45 🌐 Add translations for: Croatian
Currently translated at 99.6% (1641 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/hr/
2025-03-18 10:01:54 +00:00
Tummas Jóhan Sigvardsen
e3b6b24c5f 🌐 Add translations for: Faroese
Currently translated at 10.0% (165 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/fo/
2025-03-17 00:01:53 +01:00
Louis Chance
1eb7205c12 🌐 Add translations for: French
Currently translated at 85.3% (1405 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/fr/
2025-03-17 00:01:52 +01:00
al0cam
92f4bdae03 🌐 Add translations for: Croatian
Currently translated at 87.7% (1445 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/hr/
2025-03-14 22:02:57 +01:00
Vin
bd63a460eb 🌐 Add translations for: Russian
Currently translated at 88.0% (1450 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/ru/
2025-03-14 22:02:56 +01:00
al0cam
02e975f594 🌐 Add translations for: Croatian
Currently translated at 77.8% (1282 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/hr/
2025-03-13 17:02:00 +00:00
Denys Kisil
fdeabc15ab 🌐 Add translations for: Ukrainian (ukr_UA)
Currently translated at 99.6% (1641 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/ukr_UA/
2025-03-11 09:02:04 +01:00
Denys Kisil
8363cb7449 🌐 Add translations for: Ukrainian (ukr_UA)
Currently translated at 99.6% (1641 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/ukr_UA/
2025-03-09 19:02:05 +01:00
Nicola Bortoletto
da43a4d3b4 🌐 Add translations for: Italian
Currently translated at 99.6% (1641 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/it/
2025-03-03 16:04:07 +01:00
william chen
69d21e20c9 🌐 Add translations for: Chinese (Traditional Han script)
Currently translated at 100.0% (1646 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/zh_Hant/
2025-02-27 04:02:34 +00:00
william chen
a925d6710a 🌐 Add translations for: Chinese (Traditional Han script)
Currently translated at 88.2% (1453 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/zh_Hant/
2025-02-26 03:05:58 +00:00
Andy Li
f5218e207b 🌐 Add translations for: Chinese (Traditional Han script)
Currently translated at 66.1% (1089 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/zh_Hant/
2025-02-25 03:04:17 +01:00
william chen
7fb6a095c6 🌐 Add translations for: Chinese (Traditional Han script)
Currently translated at 66.1% (1089 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/zh_Hant/
2025-02-25 03:04:16 +01:00
Edgars Andersons
6a0bb2f452 🌐 Add translations for: Latvian
Currently translated at 99.6% (1641 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/lv/
2025-02-14 16:01:57 +01:00
Amerey.eu
d02f85315a 🌐 Add translations for: Czech
Currently translated at 99.3% (1635 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/cs/
2025-02-14 16:01:56 +01:00
Edgars Andersons
fbd5c404d2 🌐 Add translations for: Latvian
Currently translated at 98.1% (1616 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/lv/
2025-02-13 11:02:06 +01:00
Nicola Bortoletto
32b65e8dbc 🌐 Add translations for: Italian
Currently translated at 99.6% (1641 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/it/
2025-02-13 11:02:04 +01:00
Stas Haas
bf153eb96b 🌐 Add translations for: German
Currently translated at 99.6% (1641 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/de/
2025-02-11 14:22:12 +01:00
TheScientistPT
f16fcf25e2 🌐 Add translations for: Portuguese (Portugal)
Currently translated at 93.9% (1546 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/pt_PT/
2025-02-09 21:02:46 +01:00
Linerly
0048f9725d 🌐 Add translations for: Indonesian
Currently translated at 100.0% (1646 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/id/
2025-02-07 15:01:51 +01:00
Robson Cardoso dos Santos
4bb5592e75 🌐 Add translations for: Portuguese (Brazil)
Currently translated at 72.7% (1198 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/pt_BR/
2025-02-07 15:01:51 +01:00
Renan Mayrinck
d7fbd3c3bc 🌐 Add translations for: Portuguese (Brazil)
Currently translated at 72.7% (1198 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/pt_BR/
2025-02-06 14:41:03 +01:00
Robson Cardoso dos Santos
0b62bee90d 🌐 Add translations for: Portuguese (Brazil)
Currently translated at 72.7% (1198 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/pt_BR/
2025-02-06 14:41:03 +01:00
Edgars Andersons
a4a88769af 🌐 Add translations for: Latvian
Currently translated at 97.5% (1605 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/lv/
2025-02-06 12:02:04 +01:00
Denys Kisil
2dce8d09b8 🌐 Add translations for: Ukrainian (ukr_UA)
Currently translated at 99.6% (1641 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/ukr_UA/
2025-02-06 12:02:03 +01:00
TheScientistPT
e6e6401702 🌐 Add translations for: Portuguese (Portugal)
Currently translated at 93.6% (1542 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/pt_PT/
2025-02-06 12:02:01 +01:00
Robson Cardoso dos Santos
e83ece392c 🌐 Add translations for: Portuguese (Brazil)
Currently translated at 70.7% (1164 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/pt_BR/
2025-02-06 12:02:00 +01:00
Late Night Defender
bb161f9da8 🌐 Add translations for: Thai
Currently translated at 12.5% (206 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/th/
2025-02-04 22:02:01 +01:00
Denys Kisil
07360efd17 🌐 Add translations for: Ukrainian (ukr_UA)
Currently translated at 99.6% (1641 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/ukr_UA/
2025-02-04 22:01:59 +01:00
TheScientistPT
7c8eaaa4f9 🌐 Add translations for: Portuguese (Portugal)
Currently translated at 93.3% (1537 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/pt_PT/
2025-02-04 22:01:58 +01:00
Denys Kisil
01e04843bf 🌐 Add translations for: Ukrainian (ukr_UA)
Currently translated at 99.6% (1641 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/ukr_UA/
2025-02-02 14:01:52 +01:00
Linerly
3907f39c29 🌐 Add translations for: Indonesian
Currently translated at 98.9% (1628 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/id/
2025-02-01 02:01:53 +01:00
Stephan Paternotte
c570c0929f 🌐 Add translations for: Dutch
Currently translated at 99.6% (1641 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/nl/
2025-01-31 00:57:21 +01:00
Denys Kisil
f53473f9e9 🌐 Add translations for: Ukrainian (ukr_UA)
Currently translated at 99.6% (1641 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/ukr_UA/
2025-01-31 00:57:20 +01:00
Nicola Bortoletto
39e6d28826 🌐 Add translations for: Italian
Currently translated at 99.6% (1641 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/it/
2025-01-31 00:57:18 +01:00
Yaron Shahrabani
0b56d07a67 🌐 Add translations for: Hebrew
Currently translated at 99.6% (1641 of 1646 strings)

Translation: Penpot/frontend
Translate-URL: https://hosted.weblate.org/projects/penpot/frontend/he/
2025-01-31 00:57:17 +01:00
413 changed files with 34941 additions and 19538 deletions

View File

@@ -1,5 +1,69 @@
# CHANGELOG
## 2.7.1
### :bug: Bugs fixed
- Fix incorrect handling of strokes with images on importing files
- Fix tokens disappearing after manual additions [Taiga #11063](https://tree.taiga.io/project/penpot/issue/11063)
## 2.7.0
### :rocket: Epics and highlights
### :boom: Breaking changes & Deprecations
### :heart: Community contributions (Thank you!)
- Design improvements to the Invitations page with an empty state [GitHub #2608](https://github.com/penpot/penpot/issues/2608) by [@iprithvitharun](https://github.com/iprithvitharun)
### :sparkles: New features
- Update board presets with a newer devices [Taiga #10610](https://tree.taiga.io/project/penpot/us/10610)
- Propagate "sharing a prototype" to editors and viewers [Taiga #8853](https://tree.taiga.io/project/penpot/us/8853)
- Design improvements to the Invitations page with an empty state [Taiga #4554](https://tree.taiga.io/project/penpot/us/4554)
- Duplicate token sets [Taiga #10694](https://tree.taiga.io/project/penpot/issue/10694)
- Add set selection in create Token themes flow [Taiga #10746](https://tree.taiga.io/project/penpot/issue/10746)
- Display indicator on not active sets [Taiga #10668](https://tree.taiga.io/project/penpot/issue/10668)
### :bug: Bugs fixed
- Fix "at" icon to match all icons on app [Taiga #11136](https://tree.taiga.io/project/penpot/issue/11136)
- Fix problem in viewer with the back button [Taiga #10907](https://tree.taiga.io/project/penpot/issue/10907)
- Fix resize bar background on tokens panel [Taiga #10811](https://tree.taiga.io/project/penpot/issue/10811)
- Fix shortcut for history version panel [Taiga #11006](https://tree.taiga.io/project/penpot/issue/11006)
- Fix positioning of comment drafts when near the right / bottom edges of viewport [Taiga #10534](https://tree.taiga.io/project/penpot/issue/10534)
- Fix path having a wrong selrect [Taiga #10257](https://tree.taiga.io/project/penpot/issue/10257)
- Fix SVG `stroke-linecap` property when importing SVGs [Taiga #9489](https://tree.taiga.io/project/penpot/issue/9489)
- Fix position problems cutting-pasting a component [Taiga #10677](https://tree.taiga.io/project/penpot/issue/10677)
- Fix design tab has a horizontal scroll [Taiga #10660](https://tree.taiga.io/project/penpot/issue/10660)
- Fix long file names being clipped when longer than allowed length [Taiga #10662](https://tree.taiga.io/project/penpot/issue/10662)
- Fix problem with error detail in toast [Taiga #10519](https://tree.taiga.io/project/penpot/issue/10519)
- Fix view mode error when an external user tries to export something from a prototype using a shared link [Taiga #10251](https://tree.taiga.io/project/penpot/issue/10251)
- Fix merge path nodes with only one node selected [Taiga #9626](https://tree.taiga.io/project/penpot/issue/9626)
- Fix problem with import errors [Taiga #10040](https://tree.taiga.io/project/penpot/issue/10040)
- Fix color gradient on texts [Taiga Issue #7488](https://tree.taiga.io/project/penpot/issue/7488)
- Add support for self mentions [Taiga #10809](https://tree.taiga.io/project/penpot/issue/10809)
- Fix team info settings alignment [Taiga #10869](https://tree.taiga.io/project/penpot/issue/10869)
- Fix left sidebar horizontal scroll on nested layers [Taiga #10791](https://tree.taiga.io/project/penpot/issue/10791)
- Improve error message details importing tokens [Taiga Issue #10772](https://tree.taiga.io/project/penpot/issue/10772)
- Fix no selected set after Drag & Drop [Github #71](https://github.com/tokens-studio/penpot/issues/71)
- Styledictionary v5 Update [Github #6283](https://github.com/penpot/penpot/pull/6283)
- Fix Rename a set throws an internal error [Github #78](https://github.com/tokens-studio/penpot/issues/78)
- Fix Out of Sync Token Value & Color Picker [Github #102](https://github.com/tokens-studio/penpot/issues/102)
- Fix Color should preserve color space [Github #69](https://github.com/tokens-studio/penpot/issues/69)
- Fix cannot rename Design Token Sets when group of same name exists [Taiga Issue #10773](https://tree.taiga.io/project/penpot/issue/10773)
- Fix problem when duplicating grid layout [Github #6391](https://github.com/penpot/penpot/issues/6391)
- Fix issue that makes workspace shortcuts stop working [Taiga #11062](https://tree.taiga.io/project/penpot/issue/11062)
- Fix problem while syncing library colors and typographies [Taiga #11068](https://tree.taiga.io/project/penpot/issue/11068)
- Fix problem with path edition of shapes [Taiga #9496](https://tree.taiga.io/project/penpot/issue/9496)
- Fix exception on paste invalid html [Taiga #11047](https://tree.taiga.io/project/penpot/issue/11047)
- Fix share button being displayed with no permissions [Taiga #11086](https://tree.taiga.io/project/penpot/issue/11086)
- Fix inline styles in code tab [Taiga Issue #7583](https://tree.taiga.io/project/penpot/issue/7583)
- Fix exception on returning openapi.json
- Fix json encoding of TokensLib [Taiga #10994](https://tree.taiga.io/project/penpot/issue/10994)
## 2.6.2
### :bug: Bugs fixed

View File

@@ -16,36 +16,37 @@
</p>
<p align="center">
<a href="https://penpot.app/"><b>Website</b></a> •
<a href="https://help.penpot.app/technical-guide/getting-started/"><b>Getting Started</b></a> •
<a href="https://help.penpot.app/user-guide/"><b>User Guide</b></a> •
<a href="https://help.penpot.app/user-guide/introduction/info/"><b>Tutorials & Info</b></a> •
<a href="https://penpot.app/"><b>Website</b></a> •
<a href="https://help.penpot.app/user-guide/"><b>User Guide</b></a> •
<a href="https://penpot.app/learning-center"><b>Learning Center</b></a> •
<a href="https://community.penpot.app/"><b>Community</b></a>
</p>
<p align="center">
<a href="https://www.youtube.com/@Penpot"><b>Youtube</b></a> •
<a href="https://peertube.kaleidos.net/a/penpot_app/video-channels"><b>Peertube</b></a> •
<a href="https://www.linkedin.com/company/penpot/"><b>Linkedin</b></a> •
<a href="https://instagram.com/penpot.app"><b>Instagram</b></a> •
<a href="https://fosstodon.org/@penpot/"><b>Mastodon</b></a> •
<a href="https://www.youtube.com/@Penpot"><b>Youtube</b></a> •
<a href="https://peertube.kaleidos.net/a/penpot_app/video-channels"><b>Peertube</b></a> •
<a href="https://www.linkedin.com/company/penpot/"><b>Linkedin</b></a> •
<a href="https://instagram.com/penpot.app"><b>Instagram</b></a> •
<a href="https://fosstodon.org/@penpot/"><b>Mastodon</b></a> •
<a href="https://bsky.app/profile/penpot.app"><b>Bluesky</b></a> •
<a href="https://twitter.com/penpotapp"><b>X</b></a>
</p>
<br />
[Penpot video](https://github.com/penpot/penpot/assets/5446186/b8ad0764-585e-4ddc-b098-9b4090d337cc)
[Penpot video](https://github.com/user-attachments/assets/08b83119-c090-4a74-86ed-7bfbdda9a793)
<br />
Penpot is the first **open-source** design tool for design and code collaboration. Designers can create stunning designs, interactive prototypes, design systems at scale, while developers enjoy ready-to-use code and make their workflow easy and fast. And all of this with no handoff drama.
Penpot is available on browser and [self host](https://penpot.app/self-host). Its web-based and works with open standards (SVG, CSS and HTML). And last but not least, its free!
Available on browser or self-hosted, Penpot works with open standards like SVG, CSS, HTML and JSON, and its free!
Penpots latest [huge release 2.0](https://penpot.app/dev-diaries), takes the platform to a whole new level. This update introduces the ground-breaking [CSS Grid Layout feature](https://penpot.app/penpot-2.0), a complete UI redesign, a new Components system, and much more. Plus, it's faster and more accessible.
The latest updates take Penpot even further. Its the first design tool to integrate native [design tokens](https://penpot.dev/collaboration/design-tokens)—a single source of truth to improve efficiency and collaboration between product design and development.
With the [huge 2.0 release](https://penpot.app/dev-diaries), Penpot took the platform to a whole new level. This update introduces the ground-breaking [CSS Grid Layout feature](https://penpot.app/penpot-2.0), a complete UI redesign, a new Components system, and much more.
For organizations that need extra service for its teams, [get in touch](https://cal.com/team/penpot/talk-to-us)
🎇 **Penpot Fest** is our design, code & Open Source event. Check out the highlights from [Penpot Fest 2023 edition](https://www.youtube.com/watch?v=sOpLZaK5mDc)!
🎇 Design, code, and Open Source meet at [Penpot Fest](https://penpot.app/penpotfest)! Be part of the 2025 edition in Madrid, Spain, on October 9-10.
## Table of contents ##
@@ -61,7 +62,7 @@ Penpots latest [huge release 2.0](https://penpot.app/dev-diaries), takes the
Penpot expresses designs as code. Designers can do their best work and see it will be beautifully implemented by developers in a two-way collaboration.
### Plugin system ###
[Penpot plugins](https://penpot.app/penpothub/plugins) let you expand the platform's capabilities, give you the flexibility to integrate it with other apps, and design custom solutions.
[Penpot plugins](https://penpot.app/penpothub/plugins) let you expand the platform's capabilities, give you the flexibility to integrate it with other apps, and design custom solutions.
### Designed for developers ###
Penpot was built to serve both designers and developers and create a fluid design-code process. You have the choice to enjoy real-time collaboration or play "solo".
@@ -78,6 +79,10 @@ Penpot offers integration into the development toolchain, thanks to its support
### Whats great for design ###
With Penpot you can design libraries to share and reuse; turn design elements into components and tokens to allow reusability and scalability; and build realistic user flows and interactions.
### Design Tokens ###
With Penpots standardized [design tokens](https://penpot.dev/collaboration/design-tokens) format, you can easily reuse and sync tokens across different platforms, workflows, and disciplines.
<br />
<p align="center">
@@ -125,13 +130,13 @@ You will find the following categories:
## Contributing ##
Any contribution will make a difference to improve Penpot. How can you get involved?
Any contribution will make a difference to improve Penpot. How can you get involved?
Choose your way:
Choose your way:
- Create and [share Libraries & Templates](https://penpot.app/libraries-templates.html) that will be helpful for the community
- Invite your [team to join](https://design.penpot.app/#/auth/register)
- Star this repo and follow us on Social Media: [Mastodon](https://fosstodon.org/@penpot/), [Youtube](https://www.youtube.com/c/Penpot), [Instagram](https://instagram.com/penpot.app), [Linkedin](https://www.linkedin.com/company/penpotdesign), [Peertube](https://peertube.kaleidos.net/a/penpot_app) and [X](https://twitter.com/penpotapp).
- Give this repo a star and follow us on Social Media: [Mastodon](https://fosstodon.org/@penpot/), [Youtube](https://www.youtube.com/c/Penpot), [Instagram](https://instagram.com/penpot.app), [Linkedin](https://www.linkedin.com/company/penpotdesign), [Peertube](https://peertube.kaleidos.net/a/penpot_app), [X](https://twitter.com/penpotapp) and [BlueSky](https://bsky.app/profile/penpot.app)
- Participate in the [Community](https://community.penpot.app/) space by asking and answering questions; reacting to others articles; opening your own conversations and following along on decisions affecting the project.
- Report bugs with our easy [guide for bugs hunting](https://help.penpot.app/contributing-guide/reporting-bugs/) or [GitHub issues](https://github.com/penpot/penpot/issues)
- Become a [translator](https://help.penpot.app/contributing-guide/translations)

View File

@@ -31,7 +31,8 @@ export PENPOT_FLAGS="\
enable-tiered-file-data-storage \
enable-file-validation \
enable-file-schema-validation \
enable-subscriptions-old";
enable-subscriptons \
enable-subscriptons-old";
# Default deletion delay for devenv
export PENPOT_DELETION_DELAY="24h"
@@ -71,15 +72,18 @@ export PENPOT_OBJECTS_STORAGE_S3_ENDPOINT=http://minio:9000
export PENPOT_OBJECTS_STORAGE_S3_BUCKET=penpot
export PENPOT_OBJECTS_STORAGE_FS_DIRECTORY="assets"
export JAVA_OPTS="--enable-preview \
export JAVA_OPTS="\
-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager \
-Djdk.attach.allowAttachSelf \
-Dlog4j2.configurationFile=log4j2-devenv-repl.xml \
-Djdk.tracePinnedThreads=full \
-XX:+EnableDynamicAgentLoading \
-XX:-OmitStackTraceInFastThrow \
-XX:-OmitStackTraceInFastThrow \
-XX:+UnlockDiagnosticVMOptions \
-XX:+DebugNonSafepoints";
-XX:+DebugNonSafepoints \
--sun-misc-unsafe-memory-access=allow \
--enable-preview \
--enable-native-access=ALL-UNNAMED";
export OPTIONS="-A:jmx-remote -A:dev"

View File

@@ -18,7 +18,7 @@ if [ -f ./environ ]; then
source ./environ
fi
export JVM_OPTS="-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager -Dlog4j2.configurationFile=log4j2.xml -XX:-OmitStackTraceInFastThrow --enable-preview $JVM_OPTS"
export JVM_OPTS="-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager -Dlog4j2.configurationFile=log4j2.xml -XX:-OmitStackTraceInFastThrow --enable-native-access=ALL-UNNAMED --enable-preview $JVM_OPTS"
ENTRYPOINT=${1:-app.main};

View File

@@ -24,18 +24,8 @@ export PENPOT_FLAGS="\
enable-tiered-file-data-storage \
enable-file-validation \
enable-file-schema-validation \
enable-subscriptions-old";
export OPTIONS="
-A:jmx-remote -A:dev \
-J-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager \
-J-Djdk.attach.allowAttachSelf \
-J-Dpolyglot.engine.WarnInterpreterOnly=false \
-J-Dlog4j2.configurationFile=log4j2-devenv.xml \
-J-XX:+EnableDynamicAgentLoading \
-J-XX:-OmitStackTraceInFastThrow \
-J-XX:+UnlockDiagnosticVMOptions \
-J-XX:+DebugNonSafepoints"
enable-subscriptons \
enable-subscriptons-old ";
# Default deletion delay for devenv
export PENPOT_DELETION_DELAY="24h"
@@ -66,6 +56,20 @@ export PENPOT_OBJECTS_STORAGE_S3_BUCKET=penpot
entrypoint=${1:-app.main};
set -ex
export JAVA_OPTS="\
-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager \
-Djdk.attach.allowAttachSelf \
-Dlog4j2.configurationFile=log4j2-devenv.xml \
-Djdk.tracePinnedThreads=full \
-XX:+EnableDynamicAgentLoading \
-XX:-OmitStackTraceInFastThrow \
-XX:+UnlockDiagnosticVMOptions \
-XX:+DebugNonSafepoints \
--sun-misc-unsafe-memory-access=allow \
--enable-preview \
--enable-native-access=ALL-UNNAMED";
clojure $OPTIONS -A:dev -M -m $entrypoint;
export OPTIONS="-A:jmx-remote -A:dev"
set -ex
clojure $OPTIONS -M -m $entrypoint;

View File

@@ -11,6 +11,25 @@
[app.common.data :as d]
[app.common.uuid :as uuid]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PRE DECODE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn clean-shape-pre-decode
"Applies a pre-decode phase migration to the shape"
[shape]
(if (= "bool" (:type shape))
(if-let [content (get shape :bool-content)]
(-> shape
(assoc :content content)
(dissoc :bool-content))
shape)
shape))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; POST DECODE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- fix-shape-shadow-color
"Some shapes can come with invalid `id` property on shadow colors
caused by incorrect uuid parsing bug that should be already fixed;

View File

@@ -603,10 +603,20 @@
(reduce-kv (fn [objects id shape]
(assoc objects id (bfl/clean-shape-post-decode shape)))
objects
objects))))
clean-component-pre-decode
(fn [component]
(d/update-when component :objects
(fn [objects]
(reduce-kv (fn [objects id shape]
(assoc objects id (bfl/clean-shape-pre-decode shape)))
objects
objects))))]
(->> (keep (match-component-entry-fn file-id) entries)
(reduce (fn [result {:keys [id entry]}]
(let [object (->> (read-entry input entry)
(clean-component-pre-decode)
(decode-component)
(clean-component-post-decode)
(validate-component))]
@@ -641,10 +651,10 @@
(->> (keep (match-shape-entry-fn file-id page-id) entries)
(reduce (fn [result {:keys [id entry]}]
(let [object (->> (read-entry input entry)
(bfl/clean-shape-pre-decode)
(decode-shape)
(bfl/clean-shape-post-decode)
(validate-shape))]
(if (= id (:id object))
(assoc result id object)
result)))
@@ -755,7 +765,6 @@
;; only the applied
(vary-meta dissoc ::fmg/migrated))]
(bfm/register-pending-migrations! cfg file)
(bfc/save-file! cfg file ::db/return-keys false)

View File

@@ -1462,8 +1462,6 @@
(:objects page)
(:id page)
file-id
true
nil
cfsh/prepare-create-artboard-from-selection)]
(shape-cb shape)

View File

@@ -9,7 +9,6 @@
(:refer-clojure :exclude [tap])
(:require
[app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.logging :as l]
[app.common.transit :as t]
[app.http.errors :as errors]
@@ -54,18 +53,20 @@
::yres/status 200
::yres/body (yres/stream-body
(fn [_ output]
(binding [events/*channel* (sp/chan :buf buf :xf (keep encode))]
(let [listener (events/start-listener
(partial write! output)
(partial pu/close! output))]
(try
(let [channel (sp/chan :buf buf :xf (keep encode))
listener (events/start-listener
channel
(partial write! output)
(partial pu/close! output))]
(try
(binding [events/*channel* channel]
(let [result (handler)]
(events/tap :end result))
(catch Throwable cause
(events/tap :error (errors/handle' cause request))
(when-not (ex/instance? java.io.EOFException cause)
(binding [l/*context* (errors/request->context request)]
(l/err :hint "unexpected error on processing sse response" :cause cause))))
(finally
(sp/close! events/*channel*)
(px/await! listener)))))))}))
(events/tap :end result)))
(catch Throwable cause
(let [result (errors/handle' cause request)]
(events/tap channel :error result)))
(finally
(sp/close! channel)
(px/await! listener))))))}))

View File

@@ -108,6 +108,7 @@
[::ip-addr {:optional true} ::sm/text]
[::props {:optional true} [:map-of :keyword :any]]
[::context {:optional true} [:map-of :keyword :any]]
[::tracked-at {:optional true} ::sm/inst]
[::webhooks/event? {:optional true} ::sm/boolean]
[::webhooks/batch-timeout {:optional true} ::dt/duration]
[::webhooks/batch-key {:optional true}
@@ -118,12 +119,12 @@
(defn prepare-event
[cfg mdata params result]
(let [resultm (meta result)
request (-> params meta ::http/request)
profile-id (or (::profile-id resultm)
(:profile-id result)
(::rpc/profile-id params)
uuid/zero)
(let [resultm (meta result)
request (-> params meta ::http/request)
profile-id (or (::profile-id resultm)
(:profile-id result)
(::rpc/profile-id params)
uuid/zero)
session-id (get params ::rpc/external-session-id)
event-origin (get params ::rpc/external-event-origin)
@@ -135,14 +136,14 @@
(clean-props))
token-id (::actoken/id request)
context (-> (::context resultm)
(assoc :external-session-id session-id)
(assoc :external-event-origin event-origin)
(assoc :access-token-id (some-> token-id str))
(d/without-nils))
token-id (::actoken/id request)
context (-> (::context resultm)
(assoc :external-session-id session-id)
(assoc :external-event-origin event-origin)
(assoc :access-token-id (some-> token-id str))
(d/without-nils))
ip-addr (inet/parse-request request)]
ip-addr (inet/parse-request request)]
{::type (or (::type resultm)
(::rpc/type cfg))

View File

@@ -15,6 +15,7 @@
[app.config :as cf]
[app.db :as db]
[app.http.client :as http]
[app.loggers.audit :as audit]
[app.util.time :as dt]
[app.worker :as wrk]
[clojure.data.json :as json]
@@ -67,18 +68,27 @@
(defmethod ig/init-key ::process-event-handler
[_ cfg]
(fn [{:keys [props] :as task}]
(l/dbg :hint "process webhook event" :name (:name props))
(when-let [items (lookup-webhooks cfg props)]
(l/trc :hint "webhooks found for event" :total (count items))
(db/tx-run! cfg (fn [cfg]
(doseq [item items]
(wrk/submit! (-> cfg
(assoc ::wrk/task :run-webhook)
(assoc ::wrk/queue :webhooks)
(assoc ::wrk/max-retries 3)
(assoc ::wrk/params {:event props
:config item})))))))))
(let [items (lookup-webhooks cfg props)
event {::audit/profile-id (:profile-id props)
::audit/name "webhook"
::audit/type "trigger"
::audit/props {:name (get props :name)
:event-id (get props :id)
:total-affected (count items)}}]
(audit/insert! cfg event)
(when items
(l/trc :hint "webhooks found for event" :total (count items))
(db/tx-run! cfg (fn [cfg]
(doseq [item items]
(wrk/submit! (-> cfg
(assoc ::wrk/task :run-webhook)
(assoc ::wrk/queue :webhooks)
(assoc ::wrk/max-retries 3)
(assoc ::wrk/params {:event props
:config item}))))))))))
;; --- RUN
(declare interpret-exception)

View File

@@ -92,9 +92,9 @@
[:string {:max 250}]
[::sm/one-of {:format "string"} valid-event-types]]]
[:props
[:map-of :keyword :any]]
[:map-of :keyword ::sm/any]]
[:context {:optional true}
[:map-of :keyword :any]]])
[:map-of :keyword ::sm/any]]])
(def schema:push-audit-events
[:map {:title "push-audit-events"}

View File

@@ -115,7 +115,8 @@
(db/update! pool :project
{:modified-at (dt/now)}
{:id project-id})
{:id project-id}
{::db/return-keys false})
result))

View File

@@ -189,7 +189,7 @@
[:is-shared ::sm/boolean]
[:project-id ::sm/uuid]
[:created-at ::dt/instant]
[:data {:optional true} :any]])
[:data {:optional true} ::sm/any]])
(def schema:permissions-mixin
[:map {:title "PermissionsMixin"}
@@ -208,7 +208,7 @@
[:project-id {:optional true} ::sm/uuid]])
(defn- migrate-file
[{:keys [::db/conn] :as cfg} {:keys [id] :as file}]
[{:keys [::db/conn] :as cfg} {:keys [id] :as file} {:keys [read-only?]}]
(binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg id)
pmap/*tracked* (pmap/create-tracked)]
(let [;; For avoid unnecesary overhead of creating multiple pointers and
@@ -219,43 +219,45 @@
file (-> file
(update :data feat.fdata/process-pointers deref)
(update :data feat.fdata/process-objects (partial into {}))
(fmg/migrate-file))
(fmg/migrate-file))]
;; When file is migrated, we break the rule of no perform
;; mutations on get operations and update the file with all
;; migrations applied
;;
;; WARN: he following code will not work on read-only mode,
;; it is a known issue; we keep is not implemented until we
;; really need this.
file (if (contains? (:features file) "fdata/objects-map")
(feat.fdata/enable-objects-map file)
file)
file (if (contains? (:features file) "fdata/pointer-map")
(feat.fdata/enable-pointer-map file)
file)]
(if (or read-only? (db/read-only? conn))
file
(let [;; When file is migrated, we break the rule of no perform
;; mutations on get operations and update the file with all
;; migrations applied
file (if (contains? (:features file) "fdata/objects-map")
(feat.fdata/enable-objects-map file)
file)
file (if (contains? (:features file) "fdata/pointer-map")
(feat.fdata/enable-pointer-map file)
file)]
(db/update! conn :file
{:data (blob/encode (:data file))
:version (:version file)
:features (db/create-array conn "text" (:features file))}
{:id id})
(db/update! conn :file
{:data (blob/encode (:data file))
:version (:version file)
:features (db/create-array conn "text" (:features file))}
{:id id}
{::db/return-keys false})
(when (contains? (:features file) "fdata/pointer-map")
(feat.fdata/persist-pointers! cfg id))
(when (contains? (:features file) "fdata/pointer-map")
(feat.fdata/persist-pointers! cfg id))
(feat.fmigr/upsert-migrations! conn file)
(feat.fmigr/resolve-applied-migrations cfg file))))
(feat.fmigr/upsert-migrations! conn file)
(feat.fmigr/resolve-applied-migrations cfg file))))))
(defn get-file
[{:keys [::db/conn ::wrk/executor] :as cfg} id
& {:keys [project-id
migrate?
include-deleted?
lock-for-update?]
lock-for-update?
preload-pointers?]
:or {include-deleted? false
lock-for-update? false
migrate? true}}]
migrate? true
preload-pointers? false}
:as options}]
(assert (db/connection? conn) "expected cfg with valid connection")
@@ -273,10 +275,16 @@
;; because it has heavy and synchronous operations for
;; decoding file body that are not very friendly with virtual
;; threads.
file (px/invoke! executor #(decode-row file))]
file (px/invoke! executor #(decode-row file))
file (if (and migrate? (fmg/need-migration? file))
(migrate-file cfg file options)
file)]
(if preload-pointers?
(binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg id)]
(update file :data feat.fdata/process-pointers deref))
(if (and migrate? (fmg/need-migration? file))
(migrate-file cfg file)
file)))
(defn get-minimal-file
@@ -474,7 +482,7 @@
(update page :objects update-vals #(dissoc % :thumbnail)))
(defn get-page
[{:keys [::db/conn] :as cfg} {:keys [profile-id file-id page-id object-id] :as params}]
[{:keys [::db/conn] :as cfg} {:keys [profile-id file-id page-id object-id share-id] :as params}]
(when (and (uuid? object-id)
(not (uuid? page-id)))
@@ -482,22 +490,30 @@
:code :params-validation
:hint "page-id is required when object-id is provided"))
(let [team (teams/get-team conn
:profile-id profile-id
:file-id file-id)
(let [perms (get-permissions conn profile-id file-id share-id)
file (get-file cfg file-id)
file (get-file cfg file-id :read-only? true)
_ (-> (cfeat/get-team-enabled-features cf/flags team)
(cfeat/check-client-features! (:features params))
(cfeat/check-file-features! (:features file)))
proj (db/get conn :project {:id (:project-id file)})
page (binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg file-id)]
(let [page-id (or page-id (-> file :data :pages first))
page (dm/get-in file [:data :pages-index page-id])]
(if (pmap/pointer-map? page)
(deref page)
page)))]
team (-> (db/get conn :team {:id (:team-id proj)})
(teams/decode-row))
_ (-> (cfeat/get-team-enabled-features cf/flags team)
(cfeat/check-client-features! (:features params))
(cfeat/check-file-features! (:features file)))
page (binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg file-id)]
(let [page-id (or page-id (-> file :data :pages first))
page (dm/get-in file [:data :pages-index page-id])]
(if (pmap/pointer-map? page)
(deref page)
page)))]
(when-not perms
(ex/raise :type :not-found
:code :object-not-found
:hint "object not found"))
(cond-> (prune-thumbnails page)
(some? object-id)
@@ -733,7 +749,9 @@
:project-id project-id
:file-id id)
file (get-file cfg id :project-id project-id)]
file (get-file cfg id
:project-id project-id
:read-only? true)]
(-> (cfeat/get-team-enabled-features cf/flags team)
(cfeat/check-client-features! (:features params))

View File

@@ -10,7 +10,6 @@
[app.common.data.macros :as dm]
[app.common.features :as cfeat]
[app.common.files.helpers :as cfh]
[app.common.files.migrations :as fmg]
[app.common.geom.shapes :as gsh]
[app.common.schema :as sm]
[app.common.thumbnails :as thc]
@@ -18,7 +17,6 @@
[app.config :as cf]
[app.db :as db]
[app.db.sql :as-alias sql]
[app.features.fdata :as feat.fdata]
[app.loggers.audit :as-alias audit]
[app.loggers.webhooks :as-alias webhooks]
[app.media :as media]
@@ -200,14 +198,13 @@
(db/run! cfg (fn [{:keys [::db/conn] :as cfg}]
(files/check-read-permissions! conn profile-id file-id)
(let [team (teams/get-team conn
:profile-id profile-id
:file-id file-id)
(let [team (teams/get-team conn
:profile-id profile-id
:file-id file-id)
file (binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg file-id)]
(-> (files/get-file cfg file-id :migrate? false)
(update :data feat.fdata/process-pointers deref)
(fmg/migrate-file)))]
file (files/get-file cfg file-id
:preload-pointers? true
:read-only? true)]
(-> (cfeat/get-team-enabled-features cf/flags team)
(cfeat/check-file-features! (:features file)))

View File

@@ -80,9 +80,9 @@
(def ^:private schema:create-font-variant
[:map {:title "create-font-variant"}
[:team-id ::sm/uuid]
[:data [:map-of :string :any]]
[:data [:map-of ::sm/text ::sm/any]]
[:font-id ::sm/uuid]
[:font-family :string]
[:font-family ::sm/text]
[:font-weight [::sm/one-of {:format "number"} valid-weight]]
[:font-style [::sm/one-of {:format "string"} valid-style]]])

View File

@@ -9,6 +9,7 @@
(:require
[app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.json :as json]
[app.common.pprint :as pp]
[app.common.schema :as sm]
[app.common.schema.desc-js-like :as smdj]
@@ -19,7 +20,6 @@
[app.http.sse :as-alias sse]
[app.loggers.webhooks :as-alias webhooks]
[app.rpc :as-alias rpc]
[app.util.json :as json]
[app.util.services :as sv]
[app.util.template :as tmpl]
[clojure.java.io :as io]
@@ -86,7 +86,7 @@
(fn [request]
(let [params (:query-params request)
pstyle (:type params "js")
context (assoc context :param-style pstyle)]
context (assoc @context :param-style pstyle)]
{::yres/status 200
::yres/body (-> (io/resource "app/templates/api-doc.tmpl")
@@ -178,8 +178,7 @@
(fn [_]
{::yres/status 200
::yres/headers {"content-type" "application/json; charset=utf-8"}
::yres/body (json/encode context)})
::yres/body (json/encode @context)})
(fn [_]
{::yres/status 404})))
@@ -209,7 +208,7 @@
(defmethod ig/init-key ::routes
[_ {:keys [::rpc/methods] :as cfg}]
[(let [context (prepare-doc-context methods)]
[(let [context (delay (prepare-doc-context methods))]
[["/_doc"
{:handler (doc-handler context)
:allowed-methods #{:get}}]
@@ -217,7 +216,7 @@
{:handler (doc-handler context)
:allowed-methods #{:get}}]])
(let [context (prepare-openapi-context methods)]
(let [context (delay (prepare-openapi-context methods))]
[["/openapi"
{:handler (openapi-handler)
:allowed-methods #{:get}}]

View File

@@ -179,7 +179,7 @@
component-child (first component-children)]
(if (or (nil? child) (nil? component-child))
container
(let [container (if (and (not (ctk/is-main-of? component-child child true))
(let [container (if (and (not (ctk/is-main-of? component-child child))
(nil? (ctk/get-swap-slot child))
(ctk/instance-head? child))
(let [slot (guess-swap-slot component-child component-container)]

View File

@@ -10,7 +10,6 @@
to them. Mainly used in http.sse for progress reporting."
(:refer-clojure :exclude [tap run!])
(:require
[app.common.data.macros :as dm]
[app.common.exceptions :as ex]
[app.common.logging :as l]
[promesa.exec :as px]
@@ -18,33 +17,30 @@
(def ^:dynamic *channel* nil)
(defn channel
[]
(sp/chan :buf 32))
(defn tap
[type data]
(when-let [channel *channel*]
(sp/put! channel [type data])
nil))
([type data]
(when-let [channel *channel*]
(sp/put! channel [type data])
nil))
([channel type data]
(when channel
(sp/put! channel [type data])
nil)))
(defn start-listener
[on-event on-close]
(dm/assert!
"expected active events channel"
(sp/chan? *channel*))
[channel on-event on-close]
(assert (sp/chan? channel) "expected active events channel")
(px/thread
{:virtual true}
(try
(loop []
(when-let [event (sp/take! *channel*)]
(when-let [event (sp/take! channel)]
(let [result (ex/try! (on-event event))]
(if (ex/exception? result)
(do
(l/wrn :hint "unexpected exception" :cause result)
(sp/close! *channel*))
(sp/close! channel))
(recur)))))
(finally
(on-close)))))
@@ -55,7 +51,7 @@
[f on-event]
(binding [*channel* (sp/chan :buf 32)]
(let [listener (start-listener on-event (constantly nil))]
(let [listener (start-listener *channel* on-event (constantly nil))]
(try
(f)
(finally

View File

@@ -28,7 +28,7 @@
integrant/integrant {:mvn/version "0.13.1"}
funcool/tubax {:mvn/version "2021.05.20-0"}
funcool/cuerdas {:mvn/version "2023.11.09-407"}
funcool/cuerdas {:mvn/version "2025.05.26-411"}
funcool/promesa
{:git/sha "0c5ed6ad033515a2df4b55addea044f60e9653d0"
:git/url "https://github.com/funcool/promesa"}

View File

@@ -6,7 +6,7 @@
(ns app.common.data.macros
"Data retrieval & manipulation specific macros."
(:refer-clojure :exclude [get-in select-keys str with-open min max])
(:refer-clojure :exclude [get-in select-keys str with-open max])
#?(:cljs (:require-macros [app.common.data.macros]))
(:require
#?(:clj [clojure.core :as c]
@@ -144,3 +144,8 @@
(str "expr assert: " (pr-str expr)))]
(when *assert*
`(runtime-assert ~hint (fn [] ~expr))))))
(defn truncate
"Truncates a string to a certain length"
[s max-length]
(subs s 0 (min max-length (count s))))

View File

@@ -103,9 +103,7 @@
"Translate a flag to a feature name"
[flag]
(case flag
:feature-components-v2 "components/v2"
:feature-styles-v2 "styles/v2"
:feature-grid-layout "layout/grid"
:feature-fdata-objects-map "fdata/objects-map"
:feature-fdata-pointer-map "fdata/pointer-map"
:feature-plugins "plugins/runtime"
@@ -216,6 +214,12 @@
(check-supported-features! file-features)
;; Components v1 is deprecated
(when-not (contains? file-features "components/v2")
(ex/raise :type :restriction
:code :file-in-components-v1
:hint "components v1 is deprecated"))
(let [not-supported (-> file-features
(set/difference enabled-features)
(set/difference backend-only-features)

View File

@@ -11,7 +11,6 @@
[app.common.exceptions :as ex]
[app.common.files.changes :as ch]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.pprint :as pp]
[app.common.schema :as sm]
@@ -38,20 +37,12 @@
fail-on-spec?]
:or {add-container? false
fail-on-spec? false}}]
(let [components-v2 (dm/get-in file [:data :options :components-v2])
component-id (:current-component-id file)
change (cond-> change
(and add-container? (some? component-id) (not components-v2))
(-> (assoc :component-id component-id)
(cond-> (some? (:current-frame-id file))
(assoc :frame-id (:current-frame-id file))))
(and add-container? (or (nil? component-id) components-v2))
(let [change (cond-> change
add-container?
(assoc :page-id (:current-page-id file)
:frame-id (:current-frame-id file)))
valid? (or (and components-v2
(nil? (:component-id change))
valid? (or (and (nil? (:component-id change))
(nil? (:page-id change)))
(ch/valid-change? change))]
@@ -66,11 +57,11 @@
(cond-> file
(and valid? (or (not add-container?) (some? (:component-id change)) (some? (:page-id change))))
(-> (update :changes conjv change) ;; In components-v2 we do not add shapes
(update :data ch/process-changes [change] false)) ;; inside a component
(-> (update :changes conjv change)
(update :data ch/process-changes [change] false))
(not valid?)
(update :errors conjv change)))));)
(update :errors conjv change)))))
(defn- lookup-objects
([file]
@@ -185,12 +176,10 @@
(update :parent-stack conjv (:id obj)))))
(defn close-artboard [file]
(let [components-v2 (dm/get-in file [:data :options :components-v2])
parent-id (-> file :parent-stack peek)
(let [parent-id (-> file :parent-stack peek)
parent (lookup-shape file parent-id)
current-frame-id (or (:frame-id parent)
(when (or (nil? (:current-component-id file)) components-v2)
root-id))]
root-id)]
(-> file
(assoc :current-frame-id current-frame-id)
(update :parent-stack pop))))
@@ -283,14 +272,14 @@
:else
(let [objects (lookup-objects file)
bool-content (gsh/calc-bool-content bool objects)
bool' (gsh/update-bool-selrect bool children objects)]
content (gsh/calc-bool-content bool objects)
bool' (gsh/update-bool-selrect bool children objects)]
(commit-change
file
{:type :mod-obj
:id bool-id
:operations
[{:type :set :attr :bool-content :val bool-content :ignore-touched true}
[{:type :set :attr :content :val content :ignore-touched true}
{:type :set :attr :selrect :val (:selrect bool') :ignore-touched true}
{:type :set :attr :points :val (:points bool') :ignore-touched true}
{:type :set :attr :x :val (-> bool' :selrect :x) :ignore-touched true}
@@ -514,58 +503,29 @@
(defn start-component
([file data]
(let [components-v2 (dm/get-in file [:data :options :components-v2])
root-type (if components-v2 :frame :group)]
(start-component file data root-type)))
(start-component file data :frame))
([file data root-type]
;; FIXME: data probably can be a shape instance, then we can use gsh/shape->rect
(let [components-v2 (dm/get-in file [:data :options :components-v2])
selrect (or (grc/make-rect (:x data) (:y data) (:width data) (:height data))
grc/empty-rect)
name (:name data)
(let [name (:name data)
path (:path data)
main-instance-id (:main-instance-id data)
main-instance-page (:main-instance-page data)
;; In components v1 we must create the root shape and set it inside
;; the :objects attribute of the component. When in components-v2,
;; this will be ignored as the root shape has already been created
;; in its page, by the normal page import.
attrs (-> data
(assoc :type root-type)
(assoc :x (:x selrect))
(assoc :y (:y selrect))
(assoc :width (:width selrect))
(assoc :height (:height selrect))
(assoc :selrect selrect)
(dissoc :path)
(dissoc :main-instance-id)
(dissoc :main-instance-page)
(dissoc :main-instance-x)
(dissoc :main-instance-y))
obj (-> (cts/setup-shape attrs)
(check-name file root-type)
;; Components need to have nil values for frame and parent
(assoc :frame-id nil)
(assoc :parent-id nil))]
obj-id (or (:id data) (uuid/next))]
(-> file
(commit-change
(cond-> {:type :add-component
:id (:id obj)
:name name
:path path
:main-instance-id main-instance-id
:main-instance-page main-instance-page}
(not components-v2)
(assoc :shapes [obj])))
{:type :add-component
:id obj-id
:name name
:path path
:main-instance-id main-instance-id
:main-instance-page main-instance-page})
(assoc :last-id (:id obj))
(assoc :parent-stack [(:id obj)])
(assoc :current-component-id (:id obj))
(assoc :current-frame-id (if (= (:type obj) :frame) (:id obj) uuid/zero))))))
(assoc :last-id obj-id)
(assoc :parent-stack [obj-id])
(assoc :current-component-id obj-id)
(assoc :current-frame-id (if (= root-type :frame) obj-id uuid/zero))))))
(defn start-deleted-component
[file data]
@@ -600,8 +560,7 @@
file
(cond
;; In components-v2 components haven't any shape inside them.
(and component-data (:main-instance-id component-data))
component-data
(update file :data
(fn [data]
(ctkl/update-component data component-id dissoc :objects)))
@@ -677,17 +636,12 @@
page (ctpl/get-page (:data file) page-id)
component (ctkl/get-component (:data file) component-id)
components-v2 (dm/get-in file [:options :components-v2])
[shape shapes]
(ctn/make-component-instance page
component
(:id file)
(gpt/point x
y)
components-v2
#_{:main-instance true
:force-id main-instance-id})]
y))]
(as-> file $
(reduce #(commit-change %1

View File

@@ -26,11 +26,10 @@
[app.common.types.pages-list :as ctpl]
[app.common.types.shape :as cts]
[app.common.types.shape-tree :as ctst]
[app.common.types.token :as cto]
[app.common.types.token-theme :as ctot]
[app.common.types.tokens-lib :as ctob]
[app.common.types.typographies-list :as ctyl]
[app.common.types.typography :as ctt]
[app.common.types.variant :as ctv]
[app.common.uuid :as uuid]
[clojure.set :as set]))
@@ -48,14 +47,14 @@
[:type [:= :assign]]
;; NOTE: the full decoding is happening on the handler because it
;; needs a proper context of the current shape and its type
[:value [:map-of :keyword :any]]
[:value [:map-of :keyword ::sm/any]]
[:ignore-touched {:optional true} :boolean]
[:ignore-geometry {:optional true} :boolean]]]
[:set
[:map {:title "SetOperation"}
[:type [:= :set]]
[:attr :keyword]
[:val :any]
[:val ::sm/any]
[:ignore-touched {:optional true} :boolean]
[:ignore-geometry {:optional true} :boolean]]]
[:set-touched
@@ -239,9 +238,9 @@
[:component-id {:optional true} ::sm/uuid]
[:ignore-touched {:optional true} :boolean]
[:parent-id ::sm/uuid]
[:shapes :any]
[:shapes ::sm/any]
[:index {:optional true} [:maybe :int]]
[:after-shape {:optional true} :any]
[:after-shape {:optional true} ::sm/any]
[:component-swap {:optional true} :boolean]]]
[:reorder-children
@@ -251,14 +250,14 @@
[:component-id {:optional true} ::sm/uuid]
[:ignore-touched {:optional true} :boolean]
[:parent-id ::sm/uuid]
[:shapes :any]]]
[:shapes ::sm/any]]]
[:add-page
[:map {:title "AddPageChange"}
[:type [:= :add-page]]
[:id {:optional true} ::sm/uuid]
[:name {:optional true} :string]
[:page {:optional true} :any]]]
[:page {:optional true} ::sm/any]]]
[:mod-page
[:map {:title "ModPageChange"}
@@ -328,21 +327,25 @@
[:type [:= :add-component]]
[:id ::sm/uuid]
[:name :string]
[:shapes {:optional true} [:vector {:gen/max 3} :any]]
[:shapes {:optional true} [:vector {:gen/max 3} ::sm/any]]
[:path {:optional true} :string]]]
[:mod-component
[:map {:title "ModCompoenentChange"}
[:type [:= :mod-component]]
[:id ::sm/uuid]
[:shapes {:optional true} [:vector {:gen/max 3} :any]]
[:name {:optional true} :string]]]
[:shapes {:optional true} [:vector {:gen/max 3} ::sm/any]]
[:name {:optional true} :string]
[:variant-id {:optional true} ::sm/uuid]
[:variant-properties {:optional true} [:vector ::ctv/variant-property]]]]
[:del-component
[:map {:title "DelComponentChange"}
[:type [:= :del-component]]
[:id ::sm/uuid]
[:main-instance {:optional true} :any]
;; when it is an undo of a cut-paste, we need to undo the movement
;; of the shapes so we need to move them delta
[:delta {:optional true} ::gpt/point]
[:skip-undelete? {:optional true} :boolean]]]
[:restore-component
@@ -403,26 +406,26 @@
[:type [:= :set-token-theme]]
[:theme-name :string]
[:group :string]
[:theme [:maybe ::ctot/token-theme]]]]
[:theme [:maybe ctob/schema:token-theme-attrs]]]]
[:set-tokens-lib
[:map {:title "SetTokensLib"}
[:type [:= :set-tokens-lib]]
[:tokens-lib :any]]]
[:tokens-lib ::sm/any]]]
[:set-token-set
[:map {:title "SetTokenSetChange"}
[:type [:= :set-token-set]]
[:set-name :string]
[:group? :boolean]
[:token-set [:maybe ::ctot/token-set]]]]
[:token-set [:maybe ctob/schema:token-set-attrs]]]]
[:set-token
[:map {:title "SetTokenChange"}
[:type [:= :set-token]]
[:set-name :string]
[:token-name :string]
[:token [:maybe ::cto/token]]]]]])
[:token [:maybe ctob/schema:token-attrs]]]]]])
(def schema:changes
[:sequential {:gen/max 5 :gen/min 1} schema:change])
@@ -956,8 +959,8 @@
(ctkl/mod-component data params))
(defmethod process-change :del-component
[data {:keys [id skip-undelete? main-instance]}]
(ctf/delete-component data id skip-undelete? main-instance))
[data {:keys [id skip-undelete? delta]}]
(ctf/delete-component data id skip-undelete? delta))
(defmethod process-change :restore-component
[data {:keys [id page-id]}]

View File

@@ -25,18 +25,19 @@
;; Auxiliary functions to help create a set of changes (undo + redo)
(sm/register!
^{::sm/type ::changes}
[:map {:title "changes"}
[:redo-changes vector?]
[:undo-changes seq?]
[:origin {:optional true} any?]
[:save-undo? {:optional true} boolean?]
[:stack-undo? {:optional true} boolean?]
[:undo-group {:optional true} any?]])
(def schema:changes
(sm/register!
^{::sm/type ::changes}
[:map {:title "changes"}
[:redo-changes vector?]
[:undo-changes seq?]
[:origin {:optional true} ::sm/any]
[:save-undo? {:optional true} boolean?]
[:stack-undo? {:optional true} boolean?]
[:undo-group {:optional true} ::sm/any]]))
(def check-changes!
(sm/check-fn ::changes))
(sm/check-fn schema:changes))
(defn empty-changes
([origin page-id]
@@ -921,11 +922,11 @@
(apply-changes-local))))
(defn add-component
([changes id path name new-shapes updated-shapes main-instance-id main-instance-page]
(add-component changes id path name new-shapes updated-shapes main-instance-id main-instance-page nil nil nil))
([changes id path name new-shapes updated-shapes main-instance-id main-instance-page annotation]
(add-component changes id path name new-shapes updated-shapes main-instance-id main-instance-page annotation nil nil))
([changes id path name new-shapes updated-shapes main-instance-id main-instance-page annotation variant-id variant-properties & {:keys [apply-changes-local-library?]}]
([changes id path name updated-shapes main-instance-id main-instance-page]
(add-component changes id path name updated-shapes main-instance-id main-instance-page nil nil nil))
([changes id path name updated-shapes main-instance-id main-instance-page annotation]
(add-component changes id path name updated-shapes main-instance-id main-instance-page annotation nil nil))
([changes id path name updated-shapes main-instance-id main-instance-page annotation variant-id variant-properties & {:keys [apply-changes-local-library?]}]
(assert-page-id! changes)
(assert-objects! changes)
(let [page-id (::page-id (meta changes))
@@ -964,11 +965,11 @@
:name name
:main-instance-id main-instance-id
:main-instance-page main-instance-page
:annotation annotation
:variant-id variant-id
:variant-properties variant-properties}
(some? new-shapes) ;; this will be null in components-v2
(assoc :shapes (vec new-shapes))))
:annotation annotation}
(some? variant-id)
(assoc :variant-id variant-id)
(seq variant-properties)
(assoc :variant-properties variant-properties)))
(into (map mk-change) updated-shapes))))
(update :undo-changes
(fn [undo-changes]
@@ -991,27 +992,39 @@
new-component (update-fn prev-component)]
(if prev-component
(-> changes
(update :redo-changes conj {:type :mod-component
:id id
:name (:name new-component)
:path (:path new-component)
:main-instance-id (:main-instance-id new-component)
:main-instance-page (:main-instance-page new-component)
:annotation (:annotation new-component)
:variant-id (:variant-id new-component)
:variant-properties (:variant-properties new-component)
:objects (:objects new-component) ;; this won't exist in components-v2 (except for deleted components)
:modified-at (:modified-at new-component)})
(update :undo-changes conj {:type :mod-component
:id id
:name (:name prev-component)
:path (:path prev-component)
:main-instance-id (:main-instance-id prev-component)
:main-instance-page (:main-instance-page prev-component)
:annotation (:annotation prev-component)
:variant-id (:variant-id prev-component)
:variant-properties (:variant-properties prev-component)
:objects (:objects prev-component)})
(update :redo-changes conj (cond-> {:type :mod-component
:id id
:name (:name new-component)
:path (:path new-component)
:main-instance-id (:main-instance-id new-component)
:main-instance-page (:main-instance-page new-component)
:annotation (:annotation new-component)
:objects (:objects new-component) ;; for deleted components
:modified-at (:modified-at new-component)}
(some? (:variant-id new-component))
(assoc :variant-id (:variant-id new-component))
(nil? (:variant-id new-component))
(dissoc :variant-id)
(seq (:variant-properties new-component))
(assoc :variant-properties (:variant-properties new-component))
(not (seq (:variant-properties new-component)))
(dissoc :variant-properties)))
(update :undo-changes conj (cond-> {:type :mod-component
:id id
:name (:name prev-component)
:path (:path prev-component)
:main-instance-id (:main-instance-id prev-component)
:main-instance-page (:main-instance-page prev-component)
:annotation (:annotation prev-component)
:objects (:objects prev-component)}
(some? (:variant-id prev-component))
(assoc :variant-id (:variant-id prev-component))
(nil? (:variant-id prev-component))
(dissoc :variant-id)
(seq (:variant-properties prev-component))
(assoc :variant-properties (:variant-properties prev-component))
(not (seq (:variant-properties prev-component)))
(dissoc :variant-properties)))
(cond-> apply-changes-local-library?
(apply-changes-local {:apply-to-library? true})))
changes)))
@@ -1027,7 +1040,7 @@
:page-id page-id})))
(defn restore-component
[changes id page-id main-instance]
[changes id page-id delta]
(assert-library! changes)
(-> changes
(update :redo-changes conj {:type :restore-component
@@ -1035,7 +1048,34 @@
:page-id page-id})
(update :undo-changes conj {:type :del-component
:id id
:main-instance main-instance})))
:delta delta})))
(defn reorder-children
[changes id children]
(assert-page-id! changes)
(assert-objects! changes)
(let [page-id (::page-id (meta changes))
objects (lookup-objects changes)
shape (get objects id)
old-children (:shapes shape)
redo-change
{:type :reorder-children
:parent-id (:id shape)
:page-id page-id
:shapes children}
undo-change
{:type :reorder-children
:parent-id (:id shape)
:page-id page-id
:shapes old-children}]
(-> changes
(update :redo-changes conj redo-change)
(update :undo-changes conj undo-change)
(apply-changes-local))))
(defn reorder-grid-children
[changes ids]
@@ -1083,3 +1123,11 @@
(defn get-objects
[changes]
(dm/get-in (::file-data (meta changes)) [:pages-index uuid/zero :objects]))
(defn get-page
[changes]
(::page (meta changes)))
(defn get-page-id
[changes]
(::page-id (meta changes)))

View File

@@ -427,11 +427,6 @@
(map #(str/concat base-name (suffix-fn %))
(iterate inc 1))))
(defn ^:private get-suffix
"Default suffix impelemtation"
[copy-count]
(str/concat " " copy-count))
(defn generate-unique-name
"Generates a unique name by selecting the first available name from a generated sequence.
The sequence consists of `base-name` and its variants, avoiding conflicts with `existing-names`.
@@ -445,8 +440,7 @@
Returns:
- A unique name not present in `existing-names`."
[base-name existing-names & {:keys [suffix-fn immediate-suffix?]
:or {suffix-fn get-suffix}}]
[base-name existing-names & {:keys [suffix-fn immediate-suffix? suffix]}]
(dm/assert!
"expected a set of strings"
(coll? existing-names))
@@ -454,9 +448,21 @@
(dm/assert!
"expected a string for `basename`."
(string? base-name))
(let [existing-name-set (cond-> (set existing-names)
(let [suffix-fn (if suffix-fn
suffix-fn
(if suffix
(fn [copy-count]
(str/concat "-"
suffix
(when (> copy-count 1)
(str "-" copy-count))))
(fn [copy-count]
(str/concat " " copy-count))))
existing-name-set (cond-> (set existing-names)
immediate-suffix? (conj base-name))
names (name-seq base-name suffix-fn)]
(->> names
(remove #(contains? existing-name-set %))
first)))
@@ -620,6 +626,9 @@
(map? (:fill-image form))
(update-in [:fill-image :id] lookup-index)
(map? (:stroke-image form))
(update-in [:stroke-image :id] lookup-index)
;; This covers old shapes and the new :fills.
(uuid? (:fill-color-ref-file form))
(update :fill-color-ref-file lookup-index)

View File

@@ -1264,6 +1264,26 @@
(update :pages-index d/update-vals update-container)
(d/update-when :components d/update-vals update-container))))
(defmethod migrate-data "0002-normalize-bool-content"
[data _]
(letfn [(update-object [object]
;; NOTE: we still preserve the previous value for possible
;; rollback, we still need to perform an other migration
;; for properly delete the bool-content prop from shapes
;; once the know the migration was OK
(if (cfh/bool-shape? object)
(if-let [content (:bool-content object)]
(assoc object :content content)
object)
(dissoc object :bool-content :bool-type)))
(update-container [container]
(d/update-when container :objects update-vals update-object))]
(-> data
(update :pages-index update-vals update-container)
(update :components update-vals update-container))))
(defmethod migrate-data "0003-fix-root-shape"
[data _]
(letfn [(update-object [shape]
@@ -1341,5 +1361,6 @@
"legacy-66"
"legacy-67"
"0001-remove-tokens-from-groups"
"0002-normalize-bool-content"
"0002-clean-shape-interactions"
"0003-fix-root-shape"]))

View File

@@ -572,6 +572,51 @@
(pcb/with-file-data file-data)
(pcb/update-shapes [(:id shape)] repair-shape))))
(defmethod repair-error :not-a-variant
[_ error file _]
(log/error :hint "Variant error code, we don't want to auto repair it for now" :code (:code error))
file)
(defmethod repair-error :invalid-variant-id
[_ error file _]
(log/error :hint "Variant error code, we don't want to auto repair it for now" :code (:code error))
file)
(defmethod repair-error :invalid-variant-properties
[_ error file _]
(log/error :hint "Variant error code, we don't want to auto repair it for now" :code (:code error))
file)
(defmethod repair-error :variant-not-main
[_ error file _]
(log/error :hint "Variant error code, we don't want to auto repair it for now" :code (:code error))
file)
(defmethod repair-error :parent-not-variant
[_ error file _]
(log/error :hint "Variant error code, we don't want to auto repair it for now" :code (:code error))
file)
(defmethod repair-error :variant-bad-name
[_ error file _]
(log/error :hint "Variant error code, we don't want to auto repair it for now" :code (:code error))
file)
(defmethod repair-error :variant-no-properties
[_ error file _]
(log/error :hint "Variant error code, we don't want to auto repair it for now" :code (:code error))
file)
(defmethod repair-error :variant-bad-variant-name
[_ error file _]
(log/error :hint "Variant error code, we don't want to auto repair it for now" :code (:code error))
file)
(defmethod repair-error :variant-component-bad-name
[_ error file _]
(log/error :hint "Variant error code, we don't want to auto repair it for now" :code (:code error))
file)
(defmethod repair-error :default
[_ error file _]
(log/error :hint "Unknown error code, don't know how to repair" :code (:code error))

View File

@@ -62,6 +62,10 @@
changes id parent-id objects selected index frame-name without-fill? nil))
([changes id parent-id objects selected index frame-name without-fill? target-cell-id]
(prepare-create-artboard-from-selection
changes id parent-id objects selected index frame-name without-fill? target-cell-id nil))
([changes id parent-id objects selected index frame-name without-fill? target-cell-id delta]
(when-let [selected-objs (->> selected
(map (d/getf objects))
(not-empty))]
@@ -99,10 +103,11 @@
:id))
target-cell-id)
attrs
{:type :frame
:x (:x srect)
:y (:y srect)
:x (cond-> (:x srect) delta (+ (:x delta)))
:y (cond-> (:y srect) delta (+ (:y delta)))
:width (:width srect)
:height (:height srect)}

View File

@@ -1,8 +1,13 @@
(ns app.main.ui.workspace.tokens.token
;; 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/.
;;
;; Copyright (c) KALEIDOS INC
(ns app.common.files.tokens
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.main.ui.workspace.tokens.tinycolor :as tinycolor]
[clojure.set :as set]
[cuerdas.core :as str]))
@@ -128,18 +133,6 @@
(defn color-token? [token]
(= (:type token) :color))
;; FIXME: this should be precalculated ?
(defn is-reference? [token]
(str/includes? (:value token) "{"))
(defn color-bullet-color [token-color-value]
(when-let [tc (tinycolor/valid-color token-color-value)]
(if (tinycolor/alpha tc)
{:color (tinycolor/->hex-string tc)
:opacity (tinycolor/alpha tc)}
(tinycolor/->hex-string tc))))
(defn resolved-token-bullet-color [{:keys [resolved-value] :as token}]
(when (and resolved-value (color-token? token))
(color-bullet-color resolved-value)))

View File

@@ -10,12 +10,15 @@
[app.common.data.macros :as dm]
[app.common.exceptions :as ex]
[app.common.files.helpers :as cfh]
[app.common.files.variant :as cfv]
[app.common.schema :as sm]
[app.common.types.component :as ctk]
[app.common.types.components-list :as ctkl]
[app.common.types.container :as ctn]
[app.common.types.file :as ctf]
[app.common.types.pages-list :as ctpl]
[app.common.types.shape-tree :as ctst]
[app.common.types.variant :as ctv]
[app.common.uuid :as uuid]
[cuerdas.core :as str]))
@@ -56,7 +59,17 @@
:instance-head-not-frame
:misplaced-slot
:missing-slot
:shape-ref-cycle})
:shape-ref-cycle
:not-a-variant
:invalid-variant-id
:invalid-variant-properties
:variant-not-main
:parent-not-variant
:variant-bad-name
:variant-bad-variant-name
:variant-component-bad-name
:variant-no-properties
:variant-component-bad-id})
(def ^:private schema:error
[:map {:title "ValidationError"}
@@ -401,6 +414,68 @@
(check-empty-swap-slot shape file page)
(run! #(check-shape % file page libraries :context :not-component) (:shapes shape)))
(defn- check-variant-container
"Shape is a variant container, so:
-all its children should be variants with variant-id equals to the shape-id
-all the components should have the same properties
"
[shape file page]
(let [shape-id (:id shape)
shapes (:shapes shape)
children (map #(ctst/get-shape page %) shapes)
prop-names (cfv/extract-properties-names (first children) (:data file))]
(doseq [child children]
(if (not (ctk/is-variant? child))
(report-error :not-a-variant
(str/ffmt "Shape % should be a variant" (:id child))
child file page)
(do
(when (not= (:variant-id child) shape-id)
(report-error :invalid-variant-id
(str/ffmt "Variant % has invalid variant-id %" (:id child) (:variant-id child))
child file page))
(when (not= prop-names (cfv/extract-properties-names child (:data file)))
(report-error :invalid-variant-properties
(str/ffmt "Variant % has invalid properties %" (:id child) (vec prop-names))
child file page)))))))
(defn- check-variant
"Shape is a variant, so
-it should be a main component
-its parent should be a variant-container
-its variant-name is derived from the properties
-its name should be tha same as its parent's
"
[shape file page]
(let [parent (ctst/get-shape page (:parent-id shape))
component (ctkl/get-component (:data file) (:component-id shape) true)
name (ctv/properties-to-name (:variant-properties component))]
(when-not (ctk/main-instance? shape)
(report-error :variant-not-main
(str/ffmt "Variant % is not a main instance" (:id shape))
shape file page))
(when-not (ctk/is-variant-container? parent)
(report-error :parent-not-variant
(str/ffmt "Variant % has an invalid parent" (:id shape))
shape file page))
(when-not (= name (:variant-name shape))
(report-error :variant-bad-variant-name
(str/ffmt "Variant % has an invalid variant-name" (:id shape))
shape file page))
(when-not (= (:name parent) (:name shape))
(report-error :variant-bad-name
(str/ffmt "Variant % has an invalid name" (:id shape))
shape file page))
(when-not (= (:name parent) (cfh/merge-path-item (:path component) (:name component)))
(report-error :variant-component-bad-name
(str/ffmt "Component % has an invalid name" (:id shape))
shape file page))
(when-not (= (:variant-id component) (:variant-id shape))
(report-error :variant-component-bad-id
(str/ffmt "Variant % has adifferent variant-id than its component" (:id shape))
shape file page))))
(defn- check-shape
"Validate referential integrity and semantic coherence of
a shape and all its children. Report all errors found.
@@ -421,6 +496,12 @@
(check-parent-children shape file page)
(check-frame shape file page)
(when (ctk/is-variant-container? shape)
(check-variant-container shape file page))
(when (ctk/is-variant? shape)
(check-variant shape file page))
(if (ctk/instance-head? shape)
(if (not= :frame (:type shape))
(report-error :instance-head-not-frame
@@ -496,6 +577,24 @@
"This deleted component has shapes with shape-ref pointing to self"
component file nil :cycles-ids cycles-ids))))
(defn- check-variant-component
"Component is a variant, so:
-Its main should be a variant
-It should have at least one variant property"
[component file]
(let [component-page (ctf/get-component-page (:data file) component)
main-component (if (:deleted component)
(dm/get-in component [:objects (:main-instance-id component)])
(ctst/get-shape component-page (:main-instance-id component)))]
(when-not (ctk/is-variant? main-component)
(report-error :not-a-variant
(str/ffmt "Shape % should be a variant" (:id main-component))
main-component file component-page))
(when (< (count (:variant-properties component)) 1)
(report-error :variant-no-properties
(str/ffmt "Component variant % should have properties" (:id main-component))
main-component file nil))))
(defn- check-component
"Validate semantic coherence of a component. Report all errors found."
[component file]
@@ -505,7 +604,10 @@
component file nil))
(when (:deleted component)
(check-component-duplicate-swap-slot component file)
(check-ref-cycles component file)))
(check-ref-cycles component file))
(when (ctk/is-variant? component)
(check-variant-component component file)))
(defn- get-orphan-shapes
[{:keys [objects] :as page}]

View File

@@ -0,0 +1,84 @@
;; 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/.
;;
;; Copyright (c) KALEIDOS INC
(ns app.common.files.variant
(:require
[app.common.data.macros :as dm]
[app.common.types.component :as ctc]
[app.common.types.components-list :as ctcl]
[app.common.types.variant :as ctv]
[cuerdas.core :as str]))
(defn find-variant-components
"Find a list of the components thet belongs to this variant-id"
[data objects variant-id]
;; We can't simply filter components, because we need to maintain the order
(->> (dm/get-in objects [variant-id :shapes])
(map #(dm/get-in objects [% :component-id]))
(map #(ctcl/get-component data % true))
reverse))
(defn- dashes-to-end
[property-values]
(let [dashes (if (some #(= % "--") property-values) ["--"] [])]
(concat (remove #(= % "--") property-values) dashes)))
(defn extract-properties-names
[shape data]
(->> shape
(#(ctcl/get-component data (:component-id %) true))
:variant-properties
(map :name)))
(defn extract-properties-values
[data objects variant-id]
(->> (find-variant-components data objects variant-id)
(mapcat :variant-properties)
(group-by :name)
(map (fn [[k v]]
{:name k
:value (->> v
(map #(if (str/empty? (:value %)) "--" (:value %)))
distinct
dashes-to-end)}))))
(defn get-variant-mains
[component data]
(assert (ctv/valid-variant-component? component) "expected valid component variant")
(when-let [variant-id (:variant-id component)]
(let [page-id (:main-instance-page component)
objects (-> (dm/get-in data [:pages-index page-id])
(get :objects))]
(dm/get-in objects [variant-id :shapes]))))
(defn is-secondary-variant?
[component data]
(let [shapes (get-variant-mains component data)]
(and (seq shapes)
(not= (:main-instance-id component) (last shapes)))))
(defn get-primary-variant
[data component]
(let [page-id (:main-instance-page component)
objects (-> (dm/get-in data [:pages-index page-id])
(get :objects))
variant-id (:variant-id component)]
(->> (dm/get-in objects [variant-id :shapes])
peek
(get objects))))
(defn get-primary-component
[data component-id]
(when-let [component (ctcl/get-component data component-id)]
(if (ctc/is-variant? component)
(->> component
(get-primary-variant data)
:component-id
(ctcl/get-component data))
component)))

View File

@@ -79,7 +79,7 @@
:file-schema-validation
;; Reports the schema validation errors internally.
:soft-file-schema-validation
;; Activates the referential integrity validation during update file; related to components-v2.
;; Activates the referential integrity validation during update file.
:file-validation
;; Reports the referential integrity validation errors internally.
:soft-file-validation
@@ -125,6 +125,7 @@
:export-file-v3
:render-wasm-dpr
:hide-release-modal
:subscriptions
:subscriptions-old})
(def all-flags

View File

@@ -39,7 +39,7 @@
;;
;; 5. If any track still has an infinite growth limit set its growth limit to its base size.
;; - Distribute extra space accross spaned tracks
;; - Distribute extra space accross spaned tracks
;; - Maximize tracks
;;
;; - Expand flexible tracks
@@ -198,7 +198,7 @@
track-list))
(defn add-auto-size
(defn stretch-tracks
[track-list add-size]
(->> track-list
(mapv (fn [{:keys [type size max-size] :as track}]
@@ -357,7 +357,8 @@
to-idx (+ (dec (get cell prop)) (get cell prop-span))
indexed-tracks (subvec (d/enumerate track-list) from-idx to-idx)
to-allocate (size-to-allocate type parent (get children-map shape-id) cell bounds objects)
to-allocate
(size-to-allocate type parent (get children-map shape-id) cell bounds objects)
;; Remove the size and the tracks that are not allocated
[to-allocate total-frs indexed-tracks]
@@ -493,11 +494,11 @@
column-tracks (cond-> column-tracks
(= :stretch (:layout-justify-content parent))
(add-auto-size column-add-auto))
(stretch-tracks column-add-auto))
row-tracks (cond-> row-tracks
(= :stretch (:layout-align-content parent))
(add-auto-size row-add-auto))
(stretch-tracks row-add-auto))
column-total-size (tracks-total-size column-tracks)
row-total-size (tracks-total-size row-tracks)

View File

@@ -347,7 +347,11 @@
move-p nil
content (seq content)]
(if content
(let [command (first content)
(let [last-p (last content)
content (if (= :move-to (:command last-p))
(butlast content)
content)
command (first content)
to-p (command->point command)
[from-p move-p command-pts]

View File

@@ -95,8 +95,8 @@
(d/update-when :x d/safe+ dx)
(d/update-when :y d/safe+ dy)
(d/update-when :position-data move-position-data mvec)
(cond-> (= :bool type) (update :bool-content gpa/move-content mvec))
(cond-> (= :path type) (update :content gpa/move-content mvec)))))
(cond-> (or (= :bool type) (= :path type))
(update :content gpa/move-content mvec)))))
;; --- Absolute Movement
@@ -317,13 +317,10 @@
points (gco/transform-points (dm/get-prop shape :points) transform-mtx)
selrect (gco/transform-selrect (dm/get-prop shape :selrect) transform-mtx)
shape (if (= type :bool)
(update shape :bool-content gpa/transform-content transform-mtx)
shape)
shape (if (= type :text)
(update shape :position-data transform-position-data transform-mtx)
shape)
shape (if (= type :path)
shape (if (or (= type :path) (= type :bool))
(update shape :content gpa/transform-content transform-mtx)
(assoc shape
:x (dm/get-prop selrect :x)
@@ -355,11 +352,8 @@
rotation (mod (+ (d/nilv (:rotation shape) 0)
(d/nilv (dm/get-in shape [:modifiers :rotation]) 0))
360)
shape (if (= type :bool)
(update shape :bool-content gpa/transform-content transform-mtx)
shape)
shape (if (= type :path)
shape (if (or (= type :path) (= type :bool))
(update shape :content gpa/transform-content transform-mtx)
(assoc shape
:x (dm/get-prop selrect :x)
@@ -454,9 +448,14 @@
"Calculates the selrect+points for the boolean shape"
[shape children objects]
(let [bool-content (gshb/calc-bool-content shape objects)
shape (assoc shape :bool-content bool-content)
[points selrect] (gpa/content->points+selrect shape bool-content)]
(let [content
(gshb/calc-bool-content shape objects)
shape
(assoc shape :content content)
[points selrect]
(gpa/content->points+selrect shape content)]
(if (and (some? selrect) (d/not-empty? points))
(-> shape

View File

File diff suppressed because it is too large Load Diff

View File

@@ -10,14 +10,14 @@
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.geom.shapes :as gsh]
[app.common.logic.variants :as clv]
[app.common.logic.variant-properties :as clvp]
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
[app.common.types.pages-list :as ctpl]
[app.common.types.shape.interactions :as ctsi]
[app.common.types.shape.layout :as ctl]
[app.common.types.token :as cto]
[app.common.uuid :as uuid]
[cuerdas.core :as str]))
[app.common.uuid :as uuid]))
(defn- generate-unapply-tokens
"When updating attributes that have a token applied, we must unapply it, because the value
@@ -81,163 +81,167 @@
(pcb/update-shapes ids update-fn {:attrs #{:blocked :hidden}}))))
(defn generate-delete-shapes
[changes file page objects ids {:keys [components-v2 ignore-touched component-swap]}]
(let [ids (cfh/clean-loops objects ids)
([changes file page objects ids options]
(generate-delete-shapes (-> changes
(pcb/with-page page)
(pcb/with-objects objects)
(pcb/with-library-data file))
ids
options))
([changes ids {:keys [ignore-touched component-swap]}]
(let [objects (pcb/get-objects changes)
data (pcb/get-library-data changes)
page-id (pcb/get-page-id changes)
page (or (pcb/get-page changes)
(ctpl/get-page data page-id))
in-component-copy?
(fn [shape-id]
ids (cfh/clean-loops objects ids)
in-component-copy?
(fn [shape-id]
;; Look for shapes that are inside a component copy, but are
;; not the root. In this case, they must not be deleted,
;; but hidden (to be able to recover them more easily).
;; Unless we are doing a component swap, in which case we want
;; to delete the old shape
(let [shape (get objects shape-id)]
(and (ctn/has-any-copy-parent? objects shape)
(not component-swap))))
(let [shape (get objects shape-id)]
(and (ctn/has-any-copy-parent? objects shape)
(not component-swap))))
[ids-to-delete ids-to-hide]
(if components-v2
(loop [ids-seq (seq ids)
ids-to-delete []
ids-to-hide []]
(let [id (first ids-seq)]
(if (nil? id)
[ids-to-delete ids-to-hide]
(if (in-component-copy? id)
(recur (rest ids-seq)
ids-to-delete
(conj ids-to-hide id))
(recur (rest ids-seq)
(conj ids-to-delete id)
ids-to-hide)))))
[ids []])
[ids-to-delete ids-to-hide]
(loop [ids-seq (seq ids)
ids-to-delete []
ids-to-hide []]
(let [id (first ids-seq)]
(if (nil? id)
[ids-to-delete ids-to-hide]
(if (in-component-copy? id)
(recur (rest ids-seq)
ids-to-delete
(conj ids-to-hide id))
(recur (rest ids-seq)
(conj ids-to-delete id)
ids-to-hide)))))
changes (-> changes
(pcb/with-page page)
(pcb/with-objects objects)
(pcb/with-library-data file))
lookup (d/getf objects)
lookup (d/getf objects)
groups-to-unmask
(reduce (fn [group-ids id]
groups-to-unmask
(reduce (fn [group-ids id]
;; When the shape to delete is the mask of a masked group,
;; the mask condition must be removed, and it must be
;; converted to a normal group.
(let [obj (lookup id)
parent (lookup (:parent-id obj))]
(if (and (:masked-group parent)
(= id (first (:shapes parent))))
(conj group-ids (:id parent))
group-ids)))
#{}
ids-to-delete)
(let [obj (lookup id)
parent (lookup (:parent-id obj))]
(if (and (:masked-group parent)
(= id (first (:shapes parent))))
(conj group-ids (:id parent))
group-ids)))
#{}
ids-to-delete)
interacting-shapes
(filter (fn [shape]
interacting-shapes
(filter (fn [shape]
;; If any of the deleted shapes is the destination of
;; some interaction, this must be deleted, too.
(let [interactions (:interactions shape)]
(some #(and (ctsi/has-destination %)
(contains? ids-to-delete (:destination %)))
interactions)))
(vals objects))
(let [interactions (:interactions shape)]
(some #(and (ctsi/has-destination %)
(contains? ids-to-delete (:destination %)))
interactions)))
(vals objects))
changes
(reduce (fn [changes {:keys [id] :as flow}]
(if (contains? ids-to-delete (:starting-frame flow))
(pcb/set-flow changes id nil)
changes))
changes
(:flows page))
changes
(reduce (fn [changes {:keys [id] :as flow}]
(if (contains? ids-to-delete (:starting-frame flow))
(pcb/set-flow changes id nil)
changes))
changes
(:flows page))
all-parents
(reduce (fn [res id]
all-parents
(reduce (fn [res id]
;; All parents of any deleted shape must be resized.
(into res (cfh/get-parent-ids objects id)))
(d/ordered-set)
(concat ids-to-delete ids-to-hide))
(into res (cfh/get-parent-ids objects id)))
(d/ordered-set)
(concat ids-to-delete ids-to-hide))
all-children
(->> ids-to-delete ;; Children of deleted shapes must be also deleted.
(reduce (fn [res id]
(into res (cfh/get-children-ids objects id)))
[])
(reverse)
(into (d/ordered-set)))
all-children
(->> ids-to-delete ;; Children of deleted shapes must be also deleted.
(reduce (fn [res id]
(into res (cfh/get-children-ids objects id)))
[])
(reverse)
(into (d/ordered-set)))
find-all-empty-parents
(fn recursive-find-empty-parents [empty-parents]
(let [all-ids (into empty-parents ids-to-delete)
contains? (partial contains? all-ids)
xform (comp (map lookup)
(filter #(or (cfh/group-shape? %) (cfh/bool-shape? %)))
(remove #(->> (:shapes %) (remove contains?) seq))
(map :id))
parents (into #{} xform all-parents)]
(if (= empty-parents parents)
empty-parents
(recursive-find-empty-parents parents))))
find-all-empty-parents
(fn recursive-find-empty-parents [empty-parents]
(let [all-ids (into empty-parents ids-to-delete)
contains? (partial contains? all-ids)
xform (comp (map lookup)
(filter #(or (cfh/group-shape? %) (cfh/bool-shape? %) (ctk/is-variant-container? %)))
(remove #(->> (:shapes %) (remove contains?) seq))
(map :id))
parents (into #{} xform all-parents)]
(if (= empty-parents parents)
empty-parents
(recursive-find-empty-parents parents))))
empty-parents
empty-parents
;; Any parent whose children are all deleted, must be deleted too.
;; Unless we are during a component swap: in this case we are replacing a shape by
;; other one, so must not delete empty parents.
(if-not component-swap
(into (d/ordered-set) (find-all-empty-parents #{}))
#{})
(if-not component-swap
(into (d/ordered-set) (find-all-empty-parents #{}))
#{})
components-to-delete
(if components-v2
(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
(conj components (:component-id shape))
components)))
[]
(into ids-to-delete all-children))
[])
components-to-delete
(reduce (fn [components id]
(let [shape (get objects id)]
(if (and (= (:component-file shape) (:id data)) ;; Main instances should exist only in local file
(:main-instance shape)) ;; but check anyway
(conj components (:component-id shape))
components)))
[]
(into ids-to-delete all-children))
ids-set (set ids-to-delete)
guides-to-delete
(->> (:guides page)
(vals)
(filter #(contains? ids-set (:frame-id %)))
(map :id))
ids-set (set ids-to-delete)
changes (reduce (fn [changes guide-id]
(pcb/set-flow changes guide-id nil))
changes
guides-to-delete)
guides-to-delete
(->> (:guides page)
(vals)
(filter #(contains? ids-set (:frame-id %)))
(map :id))
changes (reduce (fn [changes component-id]
changes (reduce (fn [changes guide-id]
(pcb/set-flow changes guide-id nil))
changes
guides-to-delete)
changes (reduce (fn [changes component-id]
;; It's important to delete the component before the main instance, because we
;; need to store the instance position if we want to restore it later.
(pcb/delete-component changes component-id (:id page)))
changes
components-to-delete)
(pcb/delete-component changes component-id (:id page)))
changes
components-to-delete)
changes (-> changes
(generate-update-shape-flags ids-to-hide objects {:hidden true})
(pcb/remove-objects all-children {:ignore-touched true})
(pcb/remove-objects ids-to-delete {:ignore-touched ignore-touched})
(pcb/remove-objects empty-parents)
(pcb/resize-parents all-parents)
(pcb/update-shapes groups-to-unmask
(fn [shape]
(assoc shape :masked-group false)))
(pcb/update-shapes (map :id interacting-shapes)
(fn [shape]
(d/update-when shape :interactions
(fn [interactions]
(into []
(remove #(and (ctsi/has-destination %)
(contains? ids-to-delete (:destination %))))
interactions))))))]
[all-parents changes]))
changes (-> changes
(generate-update-shape-flags ids-to-hide objects {:hidden true})
(pcb/remove-objects all-children {:ignore-touched true})
(pcb/remove-objects ids-to-delete {:ignore-touched ignore-touched})
(pcb/remove-objects empty-parents)
(pcb/resize-parents all-parents)
(pcb/update-shapes groups-to-unmask
(fn [shape]
(assoc shape :masked-group false)))
(pcb/update-shapes (map :id interacting-shapes)
(fn [shape]
(d/update-when shape :interactions
(fn [interactions]
(into []
(remove #(and (ctsi/has-destination %)
(contains? ids-to-delete (:destination %))))
interactions))))))]
[all-parents changes])))
(defn generate-relocate
@@ -255,7 +259,7 @@
child-heads-ids (map :id child-heads)
variant-heads (filter ctk/is-variant? child-heads)
variant-shapes (filter ctk/is-variant? shapes)
component-main-parent
(ctn/find-component-main objects parent false)
@@ -339,7 +343,19 @@
(map :id)))
index-cell-data (when to-index (ctl/get-cell-by-index parent to-index))
cell (or cell (and index-cell-data [(:row index-cell-data) (:column index-cell-data)]))]
cell (or cell (and index-cell-data [(:row index-cell-data) (:column index-cell-data)]))
;; Parents that are a variant-container that becomes empty
empty-variant-cont (reduce
(fn [to-delete parent-id]
(let [parent (get objects parent-id)]
(if (and (ctk/is-variant-container? parent)
(empty? (remove (set ids) (:shapes parent))))
(conj to-delete (:id parent))
to-delete)))
#{}
(remove #(= % parent-id) all-parents))]
(-> changes
;; Remove layout-item properties when moving a shape outside a layout
@@ -368,82 +384,11 @@
;; Remove variant info and rename when moving outside a variant-container
(cond-> (not (ctk/is-variant-container? parent))
((fn [changes]
(reduce
(fn [changes shape]
(let [new-name (str/replace (:variant-name shape) #", " " / ")
[cpath cname] (cfh/parse-path-name new-name)]
(-> changes
(pcb/update-component (:component-id shape)
#(-> (dissoc % :variant-id :variant-properties)
(assoc :name cname
:path cpath))
{:apply-changes-local-library? true})
(pcb/update-shapes [(:id shape)]
#(-> (dissoc % :variant-id :variant-name)
(assoc :name new-name))))))
changes
variant-heads))))
(clvp/generate-make-shapes-no-variant variant-shapes))
;; Add variant info and rename when moving into a different variant-container
(cond-> (ctk/is-variant-container? parent)
((fn [changes]
(let [get-base-name #(if (some? (:variant-name %))
(str/replace (:variant-name %) #", " " / ")
(:name %))
calc-num-props #(-> %
get-base-name
cfh/split-path
count)
max-path-items (apply max (map calc-num-props child-heads))
first-comp-id (->> parent
:shapes
first
(get objects)
:component-id)
data (pcb/get-library-data changes)
variant-properties (get-in data [:components first-comp-id :variant-properties])
num-props (count variant-properties)
num-new-props (if (< max-path-items num-props)
0
(- max-path-items num-props))
changes (nth
(iterate #(clv/generate-add-new-property % (:id parent)) changes)
num-new-props)]
(reduce
(fn [changes shape]
(if (= (:id parent) (:variant-id shape))
changes ;; do nothing if we aren't changing the parent
(let [base-name (get-base-name shape)
;; we need to get the updated library data to have access to the current properties
data (pcb/get-library-data changes)
props (clv/path-to-properties
base-name
(get-in data [:components first-comp-id :variant-properties]))
variant-name (clv/properties-to-name props)
[cpath cname] (cfh/parse-path-name (:name parent))]
(-> (pcb/update-component changes
(:component-id shape)
#(assoc % :variant-id (:id parent)
:variant-properties props
:name cname
:path cpath)
{:apply-changes-local-library? true})
(pcb/update-shapes [(:id shape)]
#(assoc % :variant-id (:id parent)
:variant-name variant-name
:name (:name parent)))))))
changes
child-heads)))))
(clvp/generate-make-shapes-variant child-heads parent))
;; Move the shapes
(pcb/change-parent parent-id
@@ -518,7 +463,11 @@
(pcb/update-shapes ids #(assoc % :blocked true)))
;; Resize parent containers that need to
(pcb/resize-parents parents))))
(pcb/resize-parents parents)
;; Remove parents when are a variant-container that becomes empty
(cond-> (seq empty-variant-cont)
(#(second (generate-delete-shapes % empty-variant-cont {})))))))
(defn change-show-in-viewer
[shape hide?]

View File

@@ -0,0 +1,198 @@
;; 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/.
;;
;; Copyright (c) KALEIDOS INC
(ns app.common.logic.variant-properties
(:require
[app.common.data :as d]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.files.variant :as cfv]
[app.common.types.component :as ctk]
[app.common.types.components-list :as ctcl]
[app.common.types.variant :as ctv]
[cuerdas.core :as str]))
(defn generate-update-property-name
[changes variant-id pos new-name]
(let [data (pcb/get-library-data changes)
objects (pcb/get-objects changes)
related-components (cfv/find-variant-components data objects variant-id)]
(reduce (fn [changes component]
(pcb/update-component
changes (:id component)
#(assoc-in % [:variant-properties pos :name] new-name)
{:apply-changes-local-library? true}))
changes
related-components)))
(defn generate-remove-property
[changes variant-id pos]
(let [data (pcb/get-library-data changes)
objects (pcb/get-objects changes)
related-components (cfv/find-variant-components data objects variant-id)]
(reduce (fn [changes component]
(let [props (:variant-properties component)
props (d/remove-at-index props pos)
main-id (:main-instance-id component)
name (ctv/properties-to-name props)]
(-> changes
(pcb/update-component (:id component) #(assoc % :variant-properties props)
{:apply-changes-local-library? true})
(pcb/update-shapes [main-id] #(assoc % :variant-name name)))))
changes
related-components)))
(defn generate-update-property-value
[changes component-id pos value]
(let [data (pcb/get-library-data changes)
component (ctcl/get-component data component-id true)
main-id (:main-instance-id component)
name (-> (:variant-properties component)
(update pos assoc :value value)
ctv/properties-to-name)]
(-> changes
(pcb/update-component component-id #(assoc-in % [:variant-properties pos :value] value)
{:apply-changes-local-library? true})
(pcb/update-shapes [main-id] #(assoc % :variant-name name)))))
(defn generate-add-new-property
[changes variant-id & {:keys [fill-values? property-name]}]
(let [data (pcb/get-library-data changes)
objects (pcb/get-objects changes)
related-components (cfv/find-variant-components data objects variant-id)
props (-> related-components last :variant-properties)
next-prop-num (ctv/next-property-number props)
property-name (or property-name (str ctv/property-prefix next-prop-num))
[_ changes]
(reduce (fn [[num changes] component]
(let [main-id (:main-instance-id component)
update-props #(-> (d/nilv % [])
(conj {:name property-name
:value (if fill-values? (str ctv/value-prefix num) "")}))
update-name #(if fill-values?
(if (str/empty? %)
(str ctv/value-prefix num)
(str % ", " ctv/value-prefix num))
%)]
[(inc num)
(-> changes
(pcb/update-component (:id component)
#(update % :variant-properties update-props)
{:apply-changes-local-library? true})
(pcb/update-shapes [main-id] #(update % :variant-name update-name)))]))
[1 changes]
related-components)]
changes))
(defn- generate-make-shape-no-variant
[changes shape]
(let [new-name (ctv/variant-name-to-name shape)
[cpath cname] (cfh/parse-path-name new-name)]
(-> changes
(pcb/update-component (:component-id shape)
#(-> (dissoc % :variant-id :variant-properties)
(assoc :name cname
:path cpath))
{:apply-changes-local-library? true})
(pcb/update-shapes [(:id shape)]
#(-> (dissoc % :variant-id :variant-name)
(assoc :name new-name))))))
(defn generate-make-shapes-no-variant
[changes shapes]
(reduce generate-make-shape-no-variant changes shapes))
(defn- generate-new-properties-from-variant
[shape min-props data container-name base-properties]
(let [component (ctcl/get-component data (:component-id shape) true)
add-name? (not= (:name component) container-name)
props (ctv/merge-properties base-properties
(:variant-properties component))
new-props (- min-props
(+ (count props)
(if add-name? 1 0)))
props (ctv/add-new-props props (repeat new-props ""))]
(if add-name?
(ctv/add-new-prop props (:name component))
props)))
(defn- generate-new-properties-from-non-variant
[shape min-props container-name base-properties]
(let [;; Remove container name from shape name if present
shape-name (ctv/remove-prefix (:name shape) container-name)]
(ctv/path-to-properties shape-name base-properties min-props)))
(defn generate-make-shapes-variant
[changes shapes variant-container]
(let [data (pcb/get-library-data changes)
objects (pcb/get-objects changes)
variant-id (:id variant-container)
;; If we are cut-pasting a variant-container, this will be null
;; because it hasn't any shapes yet
first-comp-id (->> variant-container
:shapes
first
(get objects)
:component-id)
base-props (->> (get-in data [:components first-comp-id :variant-properties])
(map #(assoc % :value "")))
num-base-props (count base-props)
[cpath cname] (cfh/parse-path-name (:name variant-container))
container-name (:name variant-container)
generate-new-properties
(fn [shape min-props]
(if (ctk/is-variant? shape)
(generate-new-properties-from-variant shape min-props data container-name base-props)
(generate-new-properties-from-non-variant shape min-props container-name base-props)))
total-props (reduce (fn [m shape]
(max m (count (generate-new-properties shape num-base-props))))
0
shapes)
num-new-props (if (or (zero? num-base-props)
(< total-props num-base-props))
0
(- total-props num-base-props))
changes (nth
(iterate #(generate-add-new-property % variant-id) changes)
num-new-props)
changes (pcb/update-shapes changes (map :id shapes)
#(assoc % :variant-id variant-id
:name (:name variant-container)))]
(reduce
(fn [changes shape]
(if (or (zero? num-base-props)
(= variant-id (:variant-id shape)))
changes ;; do nothing more if we aren't changing the parent or there are no base props
(let [props (generate-new-properties shape total-props)
variant-name (ctv/properties-to-name props)]
(-> (pcb/update-component changes
(:component-id shape)
#(assoc % :variant-id variant-id
:variant-properties props
:name cname
:path cpath)
{:apply-changes-local-library? true})
(pcb/update-shapes [(:id shape)]
#(assoc % :variant-name variant-name))))))
changes
shapes)))

View File

@@ -1,160 +1,30 @@
;; 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/.
;;
;; Copyright (c) KALEIDOS INC
(ns app.common.logic.variants
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.types.components-list :as ctcl]
[cuerdas.core :as str]))
[app.common.files.variant :as cfv]
[app.common.logic.libraries :as cll]
[app.common.logic.variant-properties :as clvp]
[app.common.types.variant :as ctv]))
(defn generate-add-new-variant
[changes shape variant-id new-component-id new-shape-id prop-num]
(let [data (pcb/get-library-data changes)
objects (pcb/get-objects changes)
component-id (:component-id shape)
value (str ctv/value-prefix
(-> (cfv/extract-properties-values data objects variant-id)
last
:value
count
inc))
(def property-prefix "Property")
(def property-regex (re-pattern (str property-prefix "(\\d+)")))
(def value-prefix "Value")
(defn find-related-components
"Find a list of the components thet belongs to this variant-id"
[data objects variant-id]
(->> (dm/get-in objects [variant-id :shapes])
(map #(dm/get-in objects [% :component-id]))
(map #(ctcl/get-component data % true))
reverse))
(defn properties-to-name
"Transform the properties into a name, with the values separated by comma"
[properties]
(->> properties
(map :value)
(remove str/empty?)
(str/join ", ")))
(defn next-property-number
"Returns the next property number, to avoid duplicates on the property names"
[properties]
(let [numbers (keep
#(some->> (:name %) (re-find property-regex) second d/parse-integer)
properties)
max-num (if (seq numbers)
(apply max numbers)
0)]
(inc (max max-num (count properties)))))
(defn path-to-properties
"From a list of properties and a name with path, assign each token of the
path as value of a different property"
[path properties]
(let [next-prop-num (next-property-number properties)
cpath (cfh/split-path path)
assigned (mapv #(assoc % :value (nth cpath %2 "")) properties (range))
remaining (drop (count properties) cpath)
new-properties (map-indexed (fn [i v] {:name (str property-prefix (+ next-prop-num i))
:value v}) remaining)]
(into assigned new-properties)))
(defn- dashes-to-end
[property-values]
(let [dashes (if (some #(= % "--") property-values) ["--"] [])]
(concat (remove #(= % "--") property-values) dashes)))
(defn extract-properties-values
[data objects variant-id]
(->> (find-related-components data objects variant-id)
(mapcat :variant-properties)
(group-by :name)
(map (fn [[k v]]
{:name k
:value (->> v
(map #(if (str/empty? (:value %)) "--" (:value %)))
distinct
dashes-to-end)}))))
(defn generate-update-property-name
[changes variant-id pos new-name]
(let [data (pcb/get-library-data changes)
objects (pcb/get-objects changes)
related-components (find-related-components data objects variant-id)]
(reduce (fn [changes component]
(pcb/update-component
changes (:id component)
#(assoc-in % [:variant-properties pos :name] new-name)
{:apply-changes-local-library? true}))
changes
related-components)))
(defn generate-remove-property
[changes variant-id pos]
(let [data (pcb/get-library-data changes)
objects (pcb/get-objects changes)
related-components (find-related-components data objects variant-id)]
(reduce (fn [changes component]
(let [props (:variant-properties component)
props (d/remove-at-index props pos)
main-id (:main-instance-id component)
name (properties-to-name props)]
(-> changes
(pcb/update-component (:id component) #(assoc % :variant-properties props)
{:apply-changes-local-library? true})
(pcb/update-shapes [main-id] #(assoc % :variant-name name)))))
changes
related-components)))
(defn generate-update-property-value
[changes component-id pos value]
(let [data (pcb/get-library-data changes)
component (ctcl/get-component data component-id true)
main-id (:main-instance-id component)
name (-> (:variant-properties component)
(update pos assoc :value value)
properties-to-name)]
[new-shape changes] (-> changes
(cll/generate-duplicate-component
{:data data}
component-id
new-component-id
{:new-shape-id new-shape-id :apply-changes-local-library? true}))]
(-> changes
(pcb/update-component component-id #(assoc-in % [:variant-properties pos :value] value)
{:apply-changes-local-library? true})
(pcb/update-shapes [main-id] #(assoc % :variant-name name)))))
(defn generate-add-new-property
[changes variant-id & {:keys [fill-values?]}]
(let [data (pcb/get-library-data changes)
objects (pcb/get-objects changes)
related-components (find-related-components data objects variant-id)
props (-> related-components first :variant-properties)
next-prop-num (next-property-number props)
property-name (str property-prefix next-prop-num)
[_ changes]
(reduce (fn [[num changes] component]
(let [main-id (:main-instance-id component)
update-props #(-> (d/nilv % [])
(conj {:name property-name
:value (if fill-values? (str value-prefix num) "")}))
update-name #(if fill-values?
(if (str/empty? %)
(str value-prefix num)
(str % ", " value-prefix num))
%)]
[(inc num)
(-> changes
(pcb/update-component (:id component)
#(update % :variant-properties update-props)
{:apply-changes-local-library? true})
(pcb/update-shapes [main-id] #(update % :variant-name update-name)))]))
[1 changes]
related-components)]
changes))
(clvp/generate-update-property-value new-component-id prop-num value)
(pcb/change-parent (:parent-id shape) [new-shape] 0))))

View File

@@ -113,6 +113,10 @@
[schema]
(mu/optional-keys schema default-options))
(defn required-keys
[schema]
(mu/required-keys schema default-options))
(defn transformer
[& transformers]
(apply mt/transformer transformers))
@@ -145,11 +149,30 @@
;; :else
;; o))
(defn -transform-map-keys
([f]
(let [xform (map (fn [[k v]] [(f k) v]))]
#(cond->> % (map? %) (into (empty %) xform))))
([ks f]
(let [xform (map (fn [[k v]] [(cond-> k (contains? ks k) f) v]))]
#(cond->> % (map? %) (into (empty %) xform)))))
(defn json-transformer
[]
(mt/transformer
(mt/json-transformer)
(mt/collection-transformer)))
(let [map-of-key-decoders (mt/-string-decoders)]
(mt/transformer
{:name :json
:decoders (-> (mt/-json-decoders)
(assoc :map-of {:compile (fn [schema _]
(let [key-schema (some-> schema (m/children) (first))]
(or (some-> key-schema (m/type) map-of-key-decoders
(mt/-interceptor schema {}) (m/-intercepting)
(m/-comp m/-keyword->string)
(mt/-transform-if-valid key-schema)
(-transform-map-keys))
(-transform-map-keys m/-keyword->string))))}))
:encoders (mt/-json-encoders)}
(mt/collection-transformer))))
(defn string-transformer
[]
@@ -191,8 +214,7 @@
(defn lazy-validator
[s]
(let [s (schema s)
vfn (delay (validator s))]
(let [vfn (delay (validator s))]
(fn [v] (@vfn v))))
(defn lazy-explainer
@@ -295,11 +317,14 @@
([params]
(cond
(map? params)
(let [type (get params :type)]
(let [mdata (meta params)
type (or (get mdata ::id)
(get mdata ::type)
(get params :type))]
(assert (qualified-keyword? type) "expected qualified keyword for `type`")
(let [s (m/-simple-schema params)]
(swap! sr/registry assoc type s)
nil))
s))
(vector? params)
(let [mdata (meta params)
@@ -307,11 +332,12 @@
(get mdata ::type))]
(assert (qualified-keyword? type) "expected qualified keyword to be on metadata")
(swap! sr/registry assoc type params)
nil)
params)
(m/into-schema? params)
(let [type (m/-type params)]
(swap! sr/registry assoc type params))
(swap! sr/registry assoc type params)
params)
:else
(throw (ex-info "Invalid Arguments" {}))))
@@ -874,7 +900,7 @@
{:title "inst"
:description "Satisfies Inst protocol"
:error/message "should be an instant"
:gen/gen (->> (sg/small-int)
:gen/gen (->> (sg/small-int :min 0 :max 100000)
(sg/fmap (fn [v] (tm/parse-instant v))))
:decode/string tm/parse-instant
@@ -1019,6 +1045,8 @@
{:title "agent"
:description "instance of clojure agent"}}))
(register! ::any (mu/update-properties :any assoc :gen/gen sg/any))
;; ---- PREDICATES
(def valid-safe-number?

View File

@@ -7,6 +7,7 @@
(ns app.common.schema.desc-js-like
(:require
[app.common.data :as d]
[app.common.schema :as-alias sm]
[cuerdas.core :as str]
[malli.core :as m]
[malli.util :as mu]))
@@ -90,7 +91,7 @@
(defmethod visit :int [_ schema _ _] (str "integer" (-titled schema) (-min-max-suffix-number schema)))
(defmethod visit :double [_ schema _ _] (str "double" (-titled schema) (-min-max-suffix-number schema)))
(defmethod visit :select-keys [_ schema _ options] (describe* (m/deref schema) options))
(defmethod visit :and [_ s children _] (str (str/join ", and " children) (-titled s)))
(defmethod visit :and [_ s children _] (str (str/join " && " children) (-titled s)))
(defmethod visit :enum [_ s children _options] (str "enum" (-titled s) " of " (str/join ", " children)))
(defmethod visit :maybe [_ _ children _] (str (first children) " nullable"))
(defmethod visit :tuple [_ _ children _] (str "(" (str/join ", " children) ")"))
@@ -106,7 +107,8 @@
(defmethod visit :qualified-symbol [_ _ _ _] "qualified symbol")
(defmethod visit :uuid [_ _ _ _] "uuid")
(defmethod visit :boolean [_ _ _ _] "boolean")
(defmethod visit :keyword [_ _ _ _] "keyword")
(defmethod visit :keyword [_ _ _ _] "string")
(defmethod visit :fn [_ _ _ _] "FN")
(defmethod visit :vector [_ _ children _]
(str "[" (last children) "]"))
@@ -123,10 +125,12 @@
(defmethod visit :repeat [_ schema children _]
(str "repeat " (-diamond (first children)) (-repeat-suffix schema)))
(defmethod visit :set [_ schema children _]
(str "set[" (first children) "]" (minmax-suffix schema)))
(defmethod visit ::sm/set [_ schema children _]
(str "set[" (first children) "]" (minmax-suffix schema)))
(defmethod visit ::m/val [_ schema children _]
(let [suffix (minmax-suffix schema)]
(cond-> (first children)
@@ -152,7 +156,6 @@
(or (:title props)
"*")))
(defmethod visit :map
[_ schema children {:keys [::level ::max-level] :as options}]
(let [props (m/properties schema)
@@ -172,13 +175,11 @@
": " s)))
(str/join ",\n"))
header (cond-> (if (zero? level)
(str "type " title)
(str title))
header (cond-> (str "type " title)
closed? (str "!")
(some? title) (str " "))]
(str header "{\n" entries "\n" (pad "}" level))))))
(str (pad header level) "{\n" entries "\n" (pad "}\n" level))))))
(defmethod visit :multi
[_ s children {:keys [::level ::max-level] :as options}]
@@ -205,18 +206,18 @@
(defmethod visit :merge
[_ schema children _]
(let [entries (str/join " , " children)
(let [entries (str/join ",\n" children)
props (m/properties schema)
title (or (some-> (:title props) str/camel str/capital)
"<untitled>")]
(str "merge object " title " { " entries " }")))
(str "merge type " title " { \n" entries "\n}\n")))
(defmethod visit :app.common.schema/one-of
[_ _ children _]
(defmethod visit ::sm/one-of
[_ _ children _]
(let [elems (last children)]
(str "OneOf[" (->> elems
(map d/name)
(str/join ",")) "]")))
(str "string oneOf (" (->> elems
(map d/name)
(str/join "|")) ")")))
(defmethod visit :schema [_ schema children options]
(visit ::m/schema schema children options))

View File

@@ -5,7 +5,7 @@
;; Copyright (c) KALEIDOS INC
(ns app.common.schema.generators
(:refer-clojure :exclude [set subseq uuid filter map let boolean])
(:refer-clojure :exclude [set subseq uuid filter map let boolean vector keyword int double])
#?(:cljs (:require-macros [app.common.schema.generators]))
(:require
[app.common.schema.registry :as sr]
@@ -38,10 +38,6 @@
([s opts]
(mg/generator s (assoc opts :registry sr/default-registry))))
(defn filter
[pred gen]
(tg/such-that pred gen 100))
(defn small-double
[& {:keys [min max] :or {min -100 max 100}}]
(tg/double* {:min min, :max max, :infinite? false, :NaN? false}))
@@ -61,7 +57,7 @@
(defn word-keyword
[]
(->> (word-string)
(tg/fmap keyword)))
(tg/fmap c/keyword)))
(defn email
[]
@@ -100,12 +96,11 @@
(c/map second))
(c/map list bools elements)))))))
(def any tg/any)
(def boolean tg/boolean)
(defn set
[g]
(tg/set g))
(defn map-of
([kg vg]
(tg/map kg vg {:min-elements 1 :max-elements 3}))
([kg vg opts]
(tg/map kg vg opts)))
(defn elements
[s]
@@ -119,6 +114,10 @@
[f g]
(tg/fmap f g))
(defn filter
[pred gen]
(tg/such-that pred gen 100))
(defn mcat
[f g]
(tg/bind g f))
@@ -126,3 +125,22 @@
(defn tuple
[& opts]
(apply tg/tuple opts))
(defn vector
[& opts]
(apply tg/vector opts))
(defn set
[g]
(tg/set g))
;; Static Generators
(def boolean tg/boolean)
(def text (word-string))
(def double (small-double))
(def int (small-int))
(def keyword (word-keyword))
(def any
(tg/one-of [text boolean double int keyword]))

View File

@@ -97,7 +97,8 @@
(defmethod visit :enum [_ _ children options] (merge (some-> (m/-infer children) (transform* options)) {:enum children}))
(defmethod visit :maybe [_ _ children _] {:oneOf (conj children {:type "null"})})
(defmethod visit :tuple [_ _ children _] {:type "array", :items children, :additionalItems false})
(defmethod visit :re [_ schema _ options] {:type "string", :pattern (first (m/children schema options))})
(defmethod visit :re [_ schema _ options]
{:type "string", :pattern (str (first (m/children schema options)))})
(defmethod visit :nil [_ _ _ _] {:type "null"})
(defmethod visit :string [_ schema _ _]

View File

@@ -40,76 +40,3 @@
(map (fn [segment]
(.toPersistentMap ^js segment)))
(parser/parse path-str)))))
#?(:cljs
(defn content->buffer
"Converts the path content into binary format."
[content]
(let [total (count content)
ssize 28
buffer (new js/ArrayBuffer (* total ssize))
dview (new js/DataView buffer)]
(loop [index 0]
(when (< index total)
(let [segment (nth content index)
offset (* index ssize)]
(case (:command segment)
:move-to
(let [{:keys [x y]} (:params segment)]
(.setInt16 dview (+ offset 0) 1)
(.setFloat32 dview (+ offset 20) x)
(.setFloat32 dview (+ offset 24) y))
:line-to
(let [{:keys [x y]} (:params segment)]
(.setInt16 dview (+ offset 0) 2)
(.setFloat32 dview (+ offset 20) x)
(.setFloat32 dview (+ offset 24) y))
:curve-to
(let [{:keys [c1x c1y c2x c2y x y]} (:params segment)]
(.setInt16 dview (+ offset 0) 3)
(.setFloat32 dview (+ offset 4) c1x)
(.setFloat32 dview (+ offset 8) c1y)
(.setFloat32 dview (+ offset 12) c2x)
(.setFloat32 dview (+ offset 16) c2y)
(.setFloat32 dview (+ offset 20) x)
(.setFloat32 dview (+ offset 24) y))
:close-path
(.setInt16 dview (+ offset 0) 4))
(recur (inc index)))))
buffer)))
#?(:cljs
(defn buffer->content
"Converts the a buffer to a path content vector"
[buffer]
(assert (instance? js/ArrayBuffer buffer) "expected ArrayBuffer instance")
(let [ssize 28
total (/ (.-byteLength buffer) ssize)
dview (new js/DataView buffer)]
(loop [index 0
result []]
(if (< index total)
(let [offset (* index ssize)
type (.getInt16 dview (+ offset 0))
command (case type
1 :move-to
2 :line-to
3 :curve-to
4 :close-path)
params (case type
1 {:x (.getFloat32 dview (+ offset 20))
:y (.getFloat32 dview (+ offset 24))}
2 {:x (.getFloat32 dview (+ offset 20))
:y (.getFloat32 dview (+ offset 24))}
3 {:c1x (.getFloat32 dview (+ offset 4))
:c1y (.getFloat32 dview (+ offset 8))
:c2x (.getFloat32 dview (+ offset 12))
:c2y (.getFloat32 dview (+ offset 16))
:x (.getFloat32 dview (+ offset 20))
:y (.getFloat32 dview (+ offset 24))}
4 {})]
(recur (inc index)
(conj result {:command command
:params params})))
result)))))

View File

@@ -10,6 +10,7 @@
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
[app.common.geom.shapes.path :as gsp]
[app.common.math :as mth]
[app.common.svg.path.command :as upc]
[app.common.svg.path.subpath :as ups]))
@@ -233,6 +234,45 @@
(gsp/command->point current)
(conj result (dissoc current :prev)))))))
(defn remove-duplicated-segments
"Remove from the content segments"
[content]
(letfn [;; This is a comparator for float points with a precission
;; used to remove already existing segments
(comparator [[fx1 fy1 tx1 ty1 :as v1] [fx2 fy2 tx2 ty2 :as v2]]
(if (and (mth/close? tx1 tx2)
(mth/close? ty1 ty2)
(mth/close? fx1 fx2)
(mth/close? fy1 fy2))
0 ;; equal
(compare v1 v2)))]
(loop [current (first content)
content (rest content)
segments (sorted-set-by comparator)
result []]
(if (nil? current)
result
(let [fx (-> current :prev :x)
fy (-> current :prev :y)
tx (-> current :params :x)
ty (-> current :params :y)
result
(cond-> result
(and (not (contains? segments [fx fy tx ty]))
(not (contains? segments [tx ty fx fy])))
(conj current))
segments (conj segments [fx fy tx ty])]
(recur (first content)
(rest content)
segments
result))))))
(defn create-union [content-a content-a-split content-b content-b-split sr-a sr-b]
;; Pick all segments in content-a that are not inside content-b
;; Pick all segments in content-b that are not inside content-a
@@ -312,15 +352,17 @@
content-a-split (->> content-a-split add-previous (filter is-segment?))
content-b-split (->> content-b-split add-previous (filter is-segment?))
bool-content
content
(case bool-type
:union (create-union content-a content-a-split content-b content-b-split sr-a sr-b)
:difference (create-difference content-a content-a-split content-b content-b-split sr-a sr-b)
:intersection (create-intersection content-a content-a-split content-b content-b-split sr-a sr-b)
:exclude (create-exclusion content-a-split content-b-split))]
(->> (fix-move-to bool-content)
(ups/close-subpaths))))
(-> content
remove-duplicated-segments
fix-move-to
ups/close-subpaths)))
(defn content-bool
[bool-type contents]
@@ -331,4 +373,3 @@
(reduce (partial content-bool-pair bool-type))
(into []))
[]))

View File

@@ -126,7 +126,7 @@
(pt= (:from subpath) (:to subpath)))
(defn close-subpaths
"Searches a path for possible supaths that can create closed loops and merge them"
"Searches a path for possible subpaths that can create closed loops and merge them"
[content]
(let [subpaths (get-subpaths content)
closed-subpaths

View File

@@ -435,16 +435,12 @@
attrs
(-> attrs
(cond-> linecap
(dissoc :strokeLinecap))
(cond-> (some? color)
(dissoc :stroke :strokeWidth :strokeOpacity))
(update
:style
(fn [style]
(-> style
(cond-> linecap
(dissoc :strokeLinecap))
(cond-> (some? color)
(dissoc :stroke :strokeWidth :strokeOpacity)))))
(d/without-nils))]
@@ -461,12 +457,14 @@
(and (some? linecap) (cfh/path-shape? shape)
(or (= linecap :round) (= linecap :square)))
(assoc :stroke-cap-start linecap
:stroke-cap-end linecap)
:stroke-cap-end linecap
:stroke-linecap linecap)
(d/any-key? (dm/get-in shape [:strokes 0])
:strokeColor :strokeOpacity :strokeWidth
:strokeCapStart :strokeCapEnd)
:strokeLinecap :strokeCapStart :strokeCapEnd)
(assoc-in [:strokes 0 :stroke-style] :svg))))
(defn setup-opacity [shape]

View File

@@ -31,7 +31,7 @@
"Need that root is already a frame"
(cfh/frame-shape? root))
(let [[_new-root _new-shapes updated-shapes]
(let [[_new-root updated-shapes]
(ctn/convert-shape-in-component root (:objects page) (:id file))
updated-root (first updated-shapes) ; Can't use new-root because it has a new id
@@ -54,8 +54,7 @@
:name name
:path path
:main-instance-id (:id updated-root)
:main-instance-page (:id page)
:shapes updated-shapes))))))))
:main-instance-page (:id page)))))))))
(defn update-component
[file component-label & {:keys [] :as params}]
@@ -98,7 +97,6 @@
component
(:data library)
(gpt/point 100 100)
true
{:force-id (thi/new-id! copy-root-label)
:force-frame-id frame-id})

View File

@@ -85,7 +85,7 @@
& {:keys [component-params root-params child-params]}]
;; Generated shape tree:
;; {:root-label} [:name Frame1] # [Component :component-label]
;; :child-label [:name Rect1]
;; :child-label [:name Rect1]
(-> file
(add-frame-with-child root-label child-label :frame-params root-params :child-params child-params)
(thc/make-component component-label root-label component-params)))
@@ -95,7 +95,7 @@
& {:keys [component-params main-root-params main-child-params copy-root-params]}]
;; Generated shape tree:
;; {:main-root-label} [:name Frame1] # [Component :component-label]
;; :main-child-label [:name Rect1]
;; :main-child-label [:name Rect1]
;;
;; :copy-root-label [:name Frame1] #--> [Component :component-label] :main-root-label
;; <no-label> [:name Rect1] ---> :main-child-label
@@ -113,9 +113,9 @@
& {:keys [component-params root-params child-params-list]}]
;; Generated shape tree:
;; {:root-label} [:name Frame1] # [Component :component-label]
;; :child1-label [:name Rect1]
;; :child2-label [:name Rect2]
;; :child3-label [:name Rect3]
;; :child1-label [:name Rect1]
;; :child2-label [:name Rect2]
;; :child3-label [:name Rect3]
(as-> file $
(add-frame $ root-label root-params)
(reduce (fn [file [index [label params]]]
@@ -134,9 +134,9 @@
& {:keys [component-params main-root-params main-child-params-list copy-root-params]}]
;; Generated shape tree:
;; {:root-label} [:name Frame1] # [Component :component-label]
;; :child1-label [:name Rect1]
;; :child2-label [:name Rect2]
;; :child3-label [:name Rect3]
;; :child1-label [:name Rect1]
;; :child2-label [:name Rect2]
;; :child3-label [:name Rect3]
;;
;; :copy-root-label [:name Frame1] #--> [Component :component-label] :root-label
;; <no-label> [:name Rect1] ---> :child1-label
@@ -156,7 +156,7 @@
& {:keys [component1-params root1-params main1-child-params component2-params main2-root-params nested-head-params]}]
;; Generated shape tree:
;; {:main1-root-label} [:name Frame1] # [Component :component1-label]
;; :main1-child-label [:name Rect1]
;; :main1-child-label [:name Rect1]
;;
;; {:main2-root-label} [:name Frame2] # [Component :component2-label]
;; :nested-head-label [:name Frame1] @--> [Component :component1-label] :main1-root-label
@@ -183,7 +183,7 @@
& {:keys [component1-params root1-params main1-child-params component2-params main2-root-params nested-head-params copy2-root-params]}]
;; Generated shape tree:
;; {:main1-root-label} [:name Frame1] # [Component :component1-label]
;; :main1-child-label [:name Rect1]
;; :main1-child-label [:name Rect1]
;;
;; {:main2-root-label} [:name Frame2] # [Component :component2-label]
;; :nested-head-label [:name Frame1] @--> [Component :component1-label] :main1-root-label
@@ -336,8 +336,7 @@
file
{file-id file}
(ctn/make-container container :page)
(:id shape)
true))
(:id shape)))
file' (thf/apply-changes file changes)]
(if propagate-fn
(propagate-fn file')
@@ -361,7 +360,7 @@
(:objects page)
#{(-> (ths/get-shape file shape-tag :page-label page-label)
:id)}
{:components-v2 true})
{})
file' (thf/apply-changes file changes)]
(if propagate-fn
(propagate-fn file')
@@ -380,7 +379,7 @@
(gpt/point 0 0) ;; delta
{(:id file) file} ;; libraries
(:data file) ;; library-data
(:id file)) ;; file-id
(:id file)) ;; file-id
(cll/generate-duplicate-changes-update-indices (:objects page) ;; objects
#{(:id shape)}))
file' (thf/apply-changes file changes)]

View File

@@ -22,4 +22,18 @@
(thc/make-component component1-label root1-label)
(thc/update-component component1-label {:variant-id variant-id :variant-properties [{:name "Property1" :value "Value1"}]})
(thc/make-component component2-label root2-label)
(thc/update-component component2-label {:variant-id variant-id :variant-properties [{:name "Property1" :value "Value1"}]}))))
(thc/update-component component2-label {:variant-id variant-id :variant-properties [{:name "Property1" :value "Value2"}]}))))
(defn add-variant-two-properties
[file variant-label component1-label root1-label component2-label root2-label
& {:keys []}]
(let [file (ths/add-sample-shape file variant-label :type :frame :is-variant-container true)
variant-id (thi/id variant-label)]
(-> file
(ths/add-sample-shape root2-label :type :frame :parent-label variant-label :variant-id variant-id :variant-name "p1v2, p2v2")
(ths/add-sample-shape root1-label :type :frame :parent-label variant-label :variant-id variant-id :variant-name "p1v1, p2v1")
(thc/make-component component1-label root1-label)
(thc/update-component component1-label {:variant-id variant-id :variant-properties [{:name "Property1" :value "p1v1"} {:name "Property2" :value "p2v1"}]})
(thc/make-component component2-label root2-label)
(thc/update-component component2-label {:variant-id variant-id :variant-properties [{:name "Property1" :value "p1v2"} {:name "Property2" :value "p2v2"}]}))))

View File

@@ -35,7 +35,7 @@
(.. r (toString 16) (padStart 2 "0"))
(.. g (toString 16) (padStart 2 "0"))
(.. b (toString 16) (padStart 2 "0"))))))
sg/any))
sg/int))
(defn rgb-color-string?
[o]

View File

@@ -10,6 +10,7 @@
[app.common.schema :as sm]
[app.common.types.page :as ctp]
[app.common.types.plugins :as ctpg]
[app.common.types.variant :as ctv]
[cuerdas.core :as str]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -17,15 +18,17 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def schema:component
[:map
[:id ::sm/uuid]
[:name :string]
[:path {:optional true} [:maybe :string]]
[:modified-at {:optional true} ::sm/inst]
[:objects {:gen/max 10 :optional true} ::ctp/objects]
[:main-instance-id ::sm/uuid]
[:main-instance-page ::sm/uuid]
[:plugin-data {:optional true} ::ctpg/plugin-data]])
[:merge
[:map
[:id ::sm/uuid]
[:name :string]
[:path {:optional true} [:maybe :string]]
[:modified-at {:optional true} ::sm/inst]
[:objects {:gen/max 10 :optional true} ::ctp/objects]
[:main-instance-id ::sm/uuid]
[:main-instance-page ::sm/uuid]
[:plugin-data {:optional true} ::ctpg/plugin-data]]
::ctv/variant-component])
(sm/register! ::component schema:component)
@@ -90,8 +93,8 @@
:constraints-h :constraints-group
:constraints-v :constraints-group
:fixed-scroll :constraints-group
:bool-type :bool-group
:bool-content :bool-group
:bool-type :content-group
:bool-content :content-group
:exports :exports-group
:grids :grids-group
@@ -179,10 +182,8 @@
(= (:component-file shape) file-id)))
(defn is-main-of?
[shape-main shape-inst components-v2]
(or (= (:shape-ref shape-inst) (:id shape-main))
(and (= (:shape-ref shape-inst) (:shape-ref shape-main))
(not components-v2))))
[shape-main shape-inst]
(= (:shape-ref shape-inst) (:id shape-main)))
(defn main-instance?
"Check if this shape is the root of the main instance of some
@@ -333,8 +334,6 @@
(let [parent (get objects (:parent-id shape))]
;; We don't want to change the structure of component copies
(and (not (in-component-copy-not-head? shape))
;; We don't want to duplicate variants
(not (is-variant? shape))
;; Non instance, non copy. We allow
(or (not (instance-head? shape))
(not (in-component-copy? parent))))))

View File

@@ -34,20 +34,12 @@
(assoc component :modified-at (dt/now)))
(defn add-component
[fdata {:keys [id name path main-instance-id main-instance-page shapes annotation variant-id variant-properties]}]
(let [components-v2 (dm/get-in fdata [:options :components-v2])
fdata (update fdata :components assoc id (touch {:id id :name name :path path}))]
(if components-v2
(cond-> (update-in fdata [:components id] assoc :main-instance-id main-instance-id :main-instance-page main-instance-page)
annotation (update-in [:components id] assoc :annotation annotation)
variant-id (update-in [:components id] assoc :variant-id variant-id)
variant-properties (update-in [:components id] assoc :variant-properties variant-properties))
(let [wrap-object-fn cfeat/*wrap-with-objects-map-fn*]
(assoc-in fdata [:components id :objects]
(->> shapes
(d/index-by :id)
(wrap-object-fn)))))))
[fdata {:keys [id name path main-instance-id main-instance-page annotation variant-id variant-properties]}]
(let [fdata (update fdata :components assoc id (touch {:id id :name name :path path}))]
(cond-> (update-in fdata [:components id] assoc :main-instance-id main-instance-id :main-instance-page main-instance-page)
annotation (update-in [:components id] assoc :annotation annotation)
variant-id (update-in [:components id] assoc :variant-id variant-id)
variant-properties (update-in [:components id] assoc :variant-properties variant-properties))))
(defn mod-component
[file-data {:keys [id name path main-instance-id main-instance-page objects annotation variant-id variant-properties modified-at]}]
@@ -119,7 +111,6 @@
[file-data component-id f & args]
(d/update-in-when file-data [:components component-id] #(-> (apply f % args)
(touch))))
(defn set-component-modified
[file-data component-id]
(update-component file-data component-id identity))

View File

@@ -41,7 +41,7 @@
[:map-of {:gen/max 10} ::sm/uuid :map]]
[:plugin-data {:optional true} ::ctpg/plugin-data]])
(def check-container!
(def check-container
(sm/check-fn ::container))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -74,13 +74,9 @@
(defn get-shape
[container shape-id]
(dm/assert!
"expected valid container"
(check-container! container))
(dm/assert!
"expected valid uuid for `shape-id`"
(uuid? shape-id))
(assert (check-container container))
(assert (uuid? shape-id)
"expected valid uuid for `shape-id`")
(-> container
(get :objects)
@@ -267,67 +263,8 @@
new-children (->> (cfh/get-children objects (:id root))
(map #(dissoc % :component-root)))]
[(assoc new-root :id new-id)
nil
(into [new-root] new-children)]))
(defn make-component-shape ;; Only used for components v1
"Clone the shape and all children. Generate new ids and detach
from parent and frame. Update the original shapes to have links
to the new ones."
[shape objects file-id components-v2]
(assert (nil? (:component-id shape)))
(assert (nil? (:component-file shape)))
(assert (nil? (:shape-ref shape)))
(let [frame-ids-map (volatile! {})
;; Ensure that the component root is not an instance
update-new-shape (fn [new-shape original-shape]
(when (= (:type original-shape) :frame)
(vswap! frame-ids-map assoc (:id original-shape) (:id new-shape)))
(cond-> new-shape
true
(dissoc :component-root)
(nil? (:parent-id new-shape))
(dissoc :component-id
:component-file
:shape-ref)))
;; Make the original shape an instance of the new component.
;; If one of the original shape children already was a component
;; instance, maintain this instanceness untouched.
update-original-shape (fn [original-shape new-shape]
(cond-> original-shape
(nil? (:shape-ref original-shape))
(-> (assoc :shape-ref (:id new-shape))
(dissoc :touched))
(nil? (:parent-id new-shape))
(assoc :component-id (:id new-shape)
:component-file file-id
:component-root true)
(and (nil? (:parent-id new-shape)) components-v2)
(assoc :main-instance true)
(some? (:parent-id new-shape))
(dissoc :component-root)))
[new-root-shape new-shapes updated-shapes]
(ctst/clone-shape shape
nil
objects
:update-new-shape update-new-shape
:update-original-shape update-original-shape)
;; If frame-id points to a shape inside the component, remap it to the
;; corresponding new frame shape. If not, set it to nil.
remap-frame-id (fn [shape]
(update shape :frame-id #(get @frame-ids-map % nil)))]
[new-root-shape (map remap-frame-id new-shapes) updated-shapes]))
(defn remove-swap-keep-attrs
"Remove flex children properties except the fit-content for flex layouts. These are properties
that we don't have to propagate to copies but will be respected when swapping components"
@@ -352,20 +289,18 @@
WARNING: This process does not remap media references (on fills, strokes, ...); that is
delegated to an async process on the backend side that checks unreferenced shapes and
automatically creates correct references."
([page component library-data position components-v2]
(make-component-instance page component library-data position components-v2 {}))
([page component library-data position components-v2
([page component library-data position]
(make-component-instance page component library-data position {}))
([page component library-data position
{:keys [main-instance? force-id force-frame-id keep-ids?]
:or {main-instance? false force-id nil force-frame-id nil keep-ids? false}}]
(let [component-page (when components-v2
(ctpl/get-page library-data (:main-instance-page component)))
(let [component-page (ctpl/get-page library-data (:main-instance-page component))
component-shape (-> (get-shape component-page (:main-instance-id component))
(assoc :parent-id nil) ;; On v2 we force parent-id to nil in order to behave like v1
(assoc :frame-id uuid/zero)
(remove-swap-keep-attrs))
component-shape (if components-v2
(-> (get-shape component-page (:main-instance-id component))
(assoc :parent-id nil) ;; On v2 we force parent-id to nil in order to behave like v1
(assoc :frame-id uuid/zero)
(remove-swap-keep-attrs))
(get-shape component (:id component)))
orig-pos (gpt/point (:x component-shape) (:y component-shape))
delta (gpt/subtract position orig-pos)
@@ -395,8 +330,7 @@
update-new-shape
(fn [new-shape original-shape]
(let [new-name (:name new-shape)
root? (or (ctk/instance-root? original-shape) ; If shape is inside a component (not components-v2)
(nil? (:parent-id original-shape)))] ; we detect it by having no parent)
root? (ctk/instance-root? original-shape)]
(when root?
(vswap! unames conj new-name))
@@ -417,10 +351,8 @@
main-instance?
(dissoc :shape-ref)
(and (not main-instance?)
(or components-v2 ; In v1, shape-ref points to the remote instance
(nil? (:shape-ref original-shape)))) ; in v2, shape-ref points to the near instance
(assoc :shape-ref (:id original-shape))
(not main-instance?)
(assoc :shape-ref (:id original-shape)) ; shape-ref points to the near instance
(nil? (:parent-id original-shape))
(assoc :component-id (:id component)
@@ -428,14 +360,14 @@
:component-root true
:name new-name)
(or (some? (:parent-id original-shape)) ; On v2 we have removed the parent-id for component roots (see above)
(or (some? (:parent-id original-shape)) ; On v2 we have removed the parent-id for component roots
(some? component-frame))
(dissoc :component-root))))
[new-shape new-shapes _]
(ctst/clone-shape component-shape
frame-id
(if components-v2 (:objects component-page) (:objects component))
(:objects component-page)
:update-new-shape update-new-shape
:force-id force-id
:keep-ids? keep-ids?
@@ -545,21 +477,39 @@
no-changes?
(and (every? #(= parent-id (:parent-id %)) children)
(not pasting?))
;; When pasting frames, children have the frames and their children
;; We need to check only the top shapes
children-ids (set (map :id children))
top-children (remove #(contains? children-ids (:parent-id %)) children)
;; Are all the top-children a main-instance of a component?
all-main?
(every? ctk/main-instance? children)
(every? ctk/main-instance? top-children)
any-main-descendant
(some
(fn [shape]
(some ctk/main-instance? (cfh/get-children-with-self objects (:id shape))))
children)]
children)
;; Are all the top-children a main-instance of a cutted component?
all-comp-cut?
(when all-main?
(->> top-children
(map #(ctkl/get-component (dm/get-in libraries [(:component-file %) :data])
(:component-id %)
true))
(every? :deleted)))]
(if (or no-changes?
(and (not (invalid-structure-for-component? objects parent children pasting? libraries))
;; If we are moving into a variant-container, all the items should be main
(or all-main? (not (ctk/is-variant-container? parent)))
;; If we are moving into a main component, no descendant can be main
(or (nil? any-main-descendant) (not (ctk/main-instance? parent)))))
(or (nil? any-main-descendant) (not (ctk/main-instance? parent)))
;; If we are moving into a variant-container, all the items should be main
;; so if we are pasting, only allow main instances that are cut-and-pasted
(or (not (ctk/is-variant-container? parent))
(and (not pasting?) all-main?)
all-comp-cut?)))
[parent-id (get-frame parent-id)]
(recur (:parent-id parent) objects children pasting? libraries))))))
@@ -602,8 +552,7 @@
;; TODO: the check of :width and :height probably may be
;; removed after the check added in
;; data/workspace/modifiers/check-delta function. Better check
;; it and test toroughly when activating components-v2 mode.
;; data/workspace/modifiers/check-delta function.
in-copy?
(ctk/in-component-copy? shape)

View File

@@ -130,7 +130,7 @@
(some? page-id)
(ctpl/add-page page)
(contains? cfeat/*current* "components/v2")
:always
(assoc-in [:options :components-v2] true)))))
(defn make-file
@@ -221,48 +221,45 @@
(ctpl/get-page file-data (:main-instance-page component)))
(defn get-component-container
"Retrieve the container that holds the component shapes (the page in components-v2
or the component itself in v1 or deleted component)."
"Retrieve the container that holds the component shapes (the page
or the component itself on deleted component)."
[file-data component]
(let [components-v2 (dm/get-in file-data [:options :components-v2])]
(if (and components-v2 (not (:deleted component)))
(let [component-page (get-component-page file-data component)]
(cfh/make-container component-page :page))
(cfh/make-container component :component))))
(if (not (:deleted component))
(let [component-page (get-component-page file-data component)]
(cfh/make-container component-page :page))
(cfh/make-container component :component)))
(defn get-component-root
"Retrieve the root shape of the component."
[file-data component]
(let [components-v2 (dm/get-in file-data [:options :components-v2])]
(if (and components-v2 (not (:deleted component)))
(-> file-data
(get-component-page component)
(ctn/get-shape (:main-instance-id component)))
(ctk/get-component-root component))))
(if (not (:deleted component))
(-> file-data
(get-component-page component)
(ctn/get-shape (:main-instance-id component)))
(ctk/get-component-root component)))
(defn get-component-shape
"Retrieve one shape in the component by id. If with-context? is true, add the
file and container where the shape resides in its metadata."
[file-data component shape-id & {:keys [with-context?] :or {with-context? false}}]
(let [components-v2 (dm/get-in file-data [:options :components-v2])]
(if (and components-v2 (not (:deleted component)))
(let [component-page (get-component-page file-data component)]
(when component-page
(let [child (cfh/get-child (:objects component-page)
(:main-instance-id component)
shape-id)]
(cond-> child
(and child with-context?)
(with-meta {:file {:id (:id file-data)
:data file-data}
:container (ctn/make-container component-page :page)})))))
(if (not (:deleted component))
(let [component-page (get-component-page file-data component)]
(when component-page
(let [child (cfh/get-child (:objects component-page)
(:main-instance-id component)
shape-id)]
(cond-> child
(and child with-context?)
(with-meta {:file {:id (:id file-data)
:data file-data}
:container (ctn/make-container component-page :page)})))))
(let [shape (dm/get-in component [:objects shape-id])]
(cond-> shape
(and shape with-context?)
(with-meta {:file {:id (:id file-data)
:data file-data}
:container (ctn/make-container component :component)}))))))
(let [shape (dm/get-in component [:objects shape-id])]
(cond-> shape
(and shape with-context?)
(with-meta {:file {:id (:id file-data)
:data file-data}
:container (ctn/make-container component :component)})))))
(defn get-ref-shape
"Retrieve the shape in the component that is referenced by the instance shape."
@@ -384,12 +381,11 @@
(defn get-component-shapes
"Retrieve all shapes of the component"
[file-data component]
(let [components-v2 (dm/get-in file-data [:options :components-v2])]
(if (and components-v2
(not (:deleted component))) ;; the deleted components have its children in the :objects property
(let [instance-page (get-component-page file-data component)]
(cfh/get-children-with-self (:objects instance-page) (:main-instance-id component)))
(vals (:objects component)))))
(if (not (:deleted component)) ;; the deleted components have its children in the :objects property
(let [instance-page (get-component-page file-data component)]
(cfh/get-children-with-self (:objects instance-page) (:main-instance-id component)))
(vals (:objects component))))
;; Return true if the object is a component that exists on the file or its libraries (even a deleted one)
(defn is-main-of-known-component?
@@ -403,44 +399,52 @@
(defn load-component-objects
"Add an :objects property to the component, with only the shapes that belong to it"
[file-data component]
(let [components-v2 (dm/get-in file-data [:options :components-v2])]
(if (and components-v2 component (empty? (:objects component))) ;; This operation may be called twice, e.g. in an idempotent change
(let [component-page (get-component-page file-data component)
page-objects (:objects component-page)
objects (->> (cons (:main-instance-id component)
(cfh/get-children-ids page-objects (:main-instance-id component)))
(map #(get page-objects %))
(d/index-by :id))]
(assoc component :objects objects))
component)))
([file-data component]
(load-component-objects file-data component (gpt/point 0 0)))
([file-data component delta]
(if (and component (empty? (:objects component))) ;; This operation may be called twice, e.g. in an idempotent change
(let [component-page (get-component-page file-data component)
page-objects (:objects component-page)
objects (->> (cons (:main-instance-id component)
(cfh/get-children-ids page-objects (:main-instance-id component)))
(map #(get page-objects %))
;; when it is an undo of a cut-paste, we need to undo the movement
;; of the shapes so we need to move them delta
(map #(gsh/move % delta))
(d/index-by :id))]
(assoc component :objects objects))
component)))
(defn delete-component
"Mark a component as deleted and store the main instance shapes iside it, to
be able to be recovered later."
[file-data component-id skip-undelete? main-instance]
(let [components-v2 (dm/get-in file-data [:options :components-v2])]
(if (or (not components-v2) skip-undelete?)
[file-data component-id skip-undelete? delta]
(let [delta (or delta (gpt/point 0 0))]
(if skip-undelete?
(ctkl/delete-component file-data component-id)
(let [set-main-instance ;; If there is a saved main-instance, restore it. This happens on the restore-component action
#(if main-instance
(assoc-in % [:objects (:main-instance-id %)] main-instance)
%)]
(-> file-data
(ctkl/update-component component-id (partial load-component-objects file-data))
(ctkl/update-component component-id set-main-instance)
(ctkl/mark-component-deleted component-id))))))
(-> file-data
(ctkl/update-component component-id #(load-component-objects file-data % delta))
(ctkl/mark-component-deleted component-id)))))
(defn restore-component
"Recover a deleted component and all its shapes and put all this again in place."
[file-data component-id page-id]
(let [components-v2 (dm/get-in file-data [:options :components-v2])
update-page? (and components-v2 (not (nil? page-id)))]
(-> file-data
(ctkl/update-component component-id #(dissoc % :objects))
(ctkl/mark-component-undeleted component-id)
(cond-> update-page?
(ctkl/update-component component-id #(assoc % :main-instance-page page-id))))))
(let [update-page? (not (nil? page-id))
component (ctkl/get-component file-data component-id true)
main-instance-page (or page-id (:main-instance-page component))
main-instance (dm/get-in file-data [:pages-index main-instance-page
:objects (:main-instance-id component)])]
(cond-> file-data
:always
(->
(ctkl/update-component component-id #(dissoc % :objects))
(ctkl/mark-component-undeleted component-id))
update-page?
(ctkl/update-component component-id #(assoc % :main-instance-page page-id))
(ctk/is-variant? component)
(ctkl/update-component component-id #(assoc % :variant-id (:variant-id main-instance))))))
(defn purge-component
"Remove permanently a component."
@@ -557,7 +561,6 @@
component
library-data
position
(dm/get-in file-data [:options :components-v2])
{:main-instance? true
:keep-ids? true})
@@ -589,8 +592,7 @@
:name (:name component)
:path (:path component)
:main-instance-id (:id main-instance-shape)
:main-instance-page page-id
:shapes (get-component-shapes library-data component)}))
:main-instance-page page-id}))
; Change all existing instances to point to the local file
remap-instances

View File

@@ -32,6 +32,7 @@
[app.common.types.shape.shadow :as ctss]
[app.common.types.shape.text :as ctsx]
[app.common.types.token :as cto]
[app.common.types.variant :as ctv]
[app.common.uuid :as uuid]
[clojure.set :as set]))
@@ -233,7 +234,7 @@
[:map {:title "BoolAttrs"}
[:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]
[:bool-type [::sm/one-of bool-types]]
[:bool-content ::ctsp/content]])
[:content ::ctsp/content]])
(def ^:private schema:rect-attrs
[:map {:title "RectAttrs"}])
@@ -317,7 +318,9 @@
schema:frame-attrs
schema:shape-attrs
schema:shape-geom-attrs
schema:shape-base-attrs]]
schema:shape-base-attrs
::ctv/variant-shape
::ctv/variant-container]]
[:bool
[:merge {:title "BoolShape"}

View File

@@ -6,7 +6,16 @@
(ns app.common.types.shape.path
(:require
[app.common.schema :as sm]))
[app.common.schema :as sm])
(:import
#?(:cljs [goog.string StringBuffer]
:clj [java.nio ByteBuffer])))
#?(:clj (set! *warn-on-reflection* true))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SCHEMA: PLAIN FORMAT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def schema:line-to-segment
[:map
@@ -52,5 +61,371 @@
(def schema:path-content
[:vector schema:path-segment])
(def check-path-content
(sm/check-fn schema:path-content))
(sm/register! ::segment schema:path-segment)
(sm/register! ::content schema:path-content)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TYPE: PATH-DATA
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^:const SEGMENT-BYTE-SIZE 28)
(defprotocol IPathData
(-write-to [_ buffer offset] "write the content to the specified buffer"))
(defrecord PathSegment [command params])
(defn- get-path-string
"Format the path data structure to string"
[buffer size]
(let [builder #?(:clj (java.lang.StringBuilder. (int (* size 4)))
:cljs (StringBuffer.))]
(loop [index 0]
(when (< index size)
(let [offset (* index SEGMENT-BYTE-SIZE)
type #?(:clj (.getShort ^ByteBuffer buffer offset)
:cljs (.getInt16 buffer offset))]
(case (long type)
1 (let [x #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 20))
:cljs (.getFloat32 buffer (+ offset 20)))
y #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 24))
:cljs (.getFloat32 buffer (+ offset 24)))]
(doto builder
(.append "M")
(.append x)
(.append ",")
(.append y)))
2 (let [x #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 20))
:cljs (.getFloat32 buffer (+ offset 20)))
y #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 24))
:cljs (.getFloat32 buffer (+ offset 24)))]
(doto builder
(.append "L")
(.append x)
(.append ",")
(.append y)))
3 (let [c1x #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 4))
:cljs (.getFloat32 buffer (+ offset 4)))
c1y #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 8))
:cljs (.getFloat32 buffer (+ offset 8)))
c2x #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 12))
:cljs (.getFloat32 buffer (+ offset 12)))
c2y #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 16))
:cljs (.getFloat32 buffer (+ offset 16)))
x #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 20))
:cljs (.getFloat32 buffer (+ offset 20)))
y #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 24))
:cljs (.getFloat32 buffer (+ offset 24)))]
(doto builder
(.append "C")
(.append c1x)
(.append ",")
(.append c1y)
(.append ",")
(.append c2x)
(.append ",")
(.append c2y)
(.append ",")
(.append x)
(.append ",")
(.append y)))
4 (doto builder
(.append "Z")))
(recur (inc index)))))
(.toString builder)))
(defn- read-segment
[buffer index]
(let [offset (* index SEGMENT-BYTE-SIZE)
type #?(:clj (.getShort ^ByteBuffer buffer offset)
:cljs (.getInt16 buffer offset))]
(case (long type)
1 (let [x #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 20))
:cljs (.getFloat32 buffer (+ offset 20)))
y #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 24))
:cljs (.getFloat32 buffer (+ offset 24)))]
(->PathSegment :move-to {:x x :y y}))
2 (let [x #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 20))
:cljs (.getFloat32 buffer (+ offset 20)))
y #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 24))
:cljs (.getFloat32 buffer (+ offset 24)))]
(->PathSegment :line-to {:x x :y y}))
3 (let [c1x #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 4))
:cljs (.getFloat32 buffer (+ offset 4)))
c1y #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 8))
:cljs (.getFloat32 buffer (+ offset 8)))
c2x #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 12))
:cljs (.getFloat32 buffer (+ offset 12)))
c2y #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 16))
:cljs (.getFloat32 buffer (+ offset 16)))
x #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 20))
:cljs (.getFloat32 buffer (+ offset 20)))
y #?(:clj (.getFloat ^ByteBuffer buffer (+ offset 24))
:cljs (.getFloat32 buffer (+ offset 24)))]
(->PathSegment :curve-to {:x x :y y :c1x c1x :c1y c1y :c2x c2x :c2y c2y}))
4 (->PathSegment :close-path {}))))
(defn- in-range?
[size i]
(and (< i size) (>= i 0)))
#?(:clj
(deftype PathData [size buffer]
Object
(toString [_]
(get-path-string buffer size))
clojure.lang.Sequential
clojure.lang.IPersistentCollection
(empty [_]
(throw (ex-info "not implemented" {})))
(equiv [_ other]
(if (instance? PathData other)
(.equals ^ByteBuffer buffer (.-buffer ^PathData other))
false))
(seq [this]
(when (pos? size)
(->> (range size)
(map (fn [i] (nth this i))))))
(cons [_ _val]
(throw (ex-info "not implemented" {})))
clojure.lang.IReduceInit
(reduce [_ f start]
(loop [index 0
result start]
(if (< index size)
(let [result (f result (read-segment buffer index))]
(if (reduced? result)
@result
(recur (inc index) result)))
result)))
clojure.lang.Indexed
(nth [_ i]
(if (in-range? size i)
(read-segment buffer i)
nil))
(nth [_ i default]
(if (in-range? size i)
(read-segment buffer i)
default))
clojure.lang.Counted
(count [_] size))
:cljs
(deftype PathData [size buffer dview]
Object
(toString [_]
(get-path-string dview size))
IPathData
(-write-to [_ into-buffer offset]
(assert (instance? js/ArrayBuffer into-buffer) "expected an instance of Uint32Array")
(let [size (.-byteLength buffer)
mem (js/Uint32Array. into-buffer offset size)]
(.set mem (js/Uint32Array. buffer))))
cljs.core/ISequential
cljs.core/IEquiv
(-equiv [_ other]
(if (instance? PathData other)
(let [obuffer (.-buffer other)
osize (.-byteLength obuffer)
csize (.-byteLength buffer)]
(if (= osize csize)
(let [cb (js/Uint32Array. buffer)
ob (js/Uint32Array. obuffer)]
(loop [i 0]
(if (< i osize)
(if (= (aget ob i)
(aget cb i))
(recur (inc i))
false)
true)))
false))
false))
cljs.core/IReduce
(-reduce [_ f]
(loop [index 1
result (if (pos? size)
(read-segment dview 0)
nil)]
(if (< index size)
(let [result (f result (read-segment dview index))]
(if (reduced? result)
@result
(recur (inc index) result)))
result)))
(-reduce [_ f start]
(loop [index 0
result start]
(if (< index size)
(let [result (f result (read-segment dview index))]
(if (reduced? result)
@result
(recur (inc index) result)))
result)))
cljs.core/IHash
(-hash [_]
(throw (ex-info "not-implemented" {})))
cljs.core/ICounted
(-count [_] size)
cljs.core/IIndexed
(-nth [_ i]
(if (in-range? size i)
(read-segment dview i)
nil))
(-nth [_ i default]
(if (in-range? i size)
(read-segment dview i)
default))
cljs.core/ISeqable
(-seq [this]
(when (pos? size)
(->> (range size)
(map (fn [i] (cljs.core/-nth this i))))))))
(defn- from-bytes
[buffer]
#?(:clj
(cond
(instance? ByteBuffer buffer)
(let [size (.capacity ^ByteBuffer buffer)
count (long (/ size SEGMENT-BYTE-SIZE))]
(PathData. count buffer))
(bytes? buffer)
(let [size (alength ^bytes buffer)
count (long (/ size SEGMENT-BYTE-SIZE))]
(PathData. count
(ByteBuffer/wrap buffer)))
:else
(throw (java.lang.IllegalArgumentException. "invalid data provided")))
:cljs
(cond
(instance? js/ArrayBuffer buffer)
(let [size (.-byteLength buffer)
count (long (/ size SEGMENT-BYTE-SIZE))]
(PathData. count
buffer
(js/DataView. buffer)))
(instance? js/DataView buffer)
(let [dview buffer
buffer (.-buffer dview)
size (.-byteLength buffer)
count (long (/ size SEGMENT-BYTE-SIZE))]
(PathData. count buffer dview))
:else
(throw (js/Error. "invalid data provided")))))
;; FIXME: consider implementing with reduce
;; FIXME: consider ensure fixed precision for avoid doing it on formatting
(defn- from-plain
"Create a PathData instance from plain data structures"
[content]
(assert (check-path-content content))
(let [content (vec content)
total (count content)
#?@(:cljs [buffer (new js/ArrayBuffer (* total SEGMENT-BYTE-SIZE))
dview (new js/DataView buffer)]
:clj [buffer (ByteBuffer/allocate (* total SEGMENT-BYTE-SIZE))])]
(loop [index 0]
(when (< index total)
(let [segment (nth content index)
offset (* index SEGMENT-BYTE-SIZE)]
(case (get segment :command)
:move-to
(let [params (get segment :params)
x (float (get params :x))
y (float (get params :y))]
#?(:clj (.putShort buffer (int offset) (short 1))
:cljs (.setInt16 dview offset 1))
#?(:clj (.putFloat buffer (+ offset 20) x)
:cljs (.setFloat32 dview (+ offset 20) x))
#?(:clj (.putFloat buffer (+ offset 24) y)
:cljs (.setFloat32 dview (+ offset 24) y)))
:line-to
(let [params (get segment :params)
x (float (get params :x))
y (float (get params :y))]
#?(:clj (.putShort buffer (int offset) (short 2))
:cljs (.setInt16 dview offset 2))
#?(:clj (.putFloat buffer (+ offset 20) x)
:cljs (.setFloat32 dview (+ offset 20) x))
#?(:clj (.putFloat buffer (+ offset 24) y)
:cljs (.setFloat32 dview (+ offset 24) y)))
:curve-to
(let [params (get segment :params)
x (float (get params :x))
y (float (get params :y))
c1x (float (get params :c1x x))
c1y (float (get params :c1y y))
c2x (float (get params :c2x x))
c2y (float (get params :c2y y))]
#?(:clj (.putShort buffer (int offset) (short 3))
:cljs (.setInt16 dview offset 3))
#?(:clj (.putFloat buffer (+ offset 4) c1x)
:cljs (.setFloat32 dview (+ offset 4) c1x))
#?(:clj (.putFloat buffer (+ offset 8) c1y)
:cljs (.setFloat32 dview (+ offset 8) c1y))
#?(:clj (.putFloat buffer (+ offset 12) c2x)
:cljs (.setFloat32 dview (+ offset 12) c2x))
#?(:clj (.putFloat buffer (+ offset 16) c2y)
:cljs (.setFloat32 dview (+ offset 16) c2y))
#?(:clj (.putFloat buffer (+ offset 20) x)
:cljs (.setFloat32 dview (+ offset 20) x))
#?(:clj (.putFloat buffer (+ offset 24) y)
:cljs (.setFloat32 dview (+ offset 24) y)))
:close-path
#?(:clj (.putShort buffer (int offset) (short 4))
:cljs (.setInt16 dview offset 4)))
(recur (inc index)))))
#?(:cljs (from-bytes dview)
:clj (from-bytes buffer))))
(defn path-data
"Create an instance of PathData, returns itself if it is already
PathData instance"
[data]
(cond
(instance? PathData data)
data
(sequential? data)
(from-plain data)
:else
(from-bytes data)))

View File

@@ -16,54 +16,56 @@
(def node-types #{"root" "paragraph-set" "paragraph"})
(sm/register!
^{::sm/type ::content}
[:map
[:type [:= "root"]]
[:key {:optional true} :string]
[:children
{:optional true}
[:maybe
[:vector {:min 1 :gen/max 2 :gen/min 1}
[:map
[:type [:= "paragraph-set"]]
[:key {:optional true} :string]
[:children
[:vector {:min 1 :gen/max 2 :gen/min 1}
[:map
[:type [:= "paragraph"]]
[:key {:optional true} :string]
[:fills {:optional true}
[:maybe
[:vector {:gen/max 2} ::shape/fill]]]
[:font-family {:optional true} :string]
[:font-size {:optional true} :string]
[:font-style {:optional true} :string]
[:font-weight {:optional true} :string]
[:direction {:optional true} :string]
[:text-decoration {:optional true} :string]
[:text-transform {:optional true} :string]
[:typography-ref-id {:optional true} [:maybe ::sm/uuid]]
[:typography-ref-file {:optional true} [:maybe ::sm/uuid]]
[:children
[:vector {:min 1 :gen/max 2 :gen/min 1}
[:map
[:text :string]
[:key {:optional true} :string]
[:fills {:optional true}
[:maybe
[:vector {:gen/max 2} ::shape/fill]]]
[:font-family {:optional true} :string]
[:font-size {:optional true} :string]
[:font-style {:optional true} :string]
[:font-weight {:optional true} :string]
[:direction {:optional true} :string]
[:text-decoration {:optional true} :string]
[:text-transform {:optional true} :string]
[:typography-ref-id {:optional true} [:maybe ::sm/uuid]]
[:typography-ref-file {:optional true} [:maybe ::sm/uuid]]]]]]]]]]]]])
(def schema:content
[:map
[:type [:= "root"]]
[:key {:optional true} :string]
[:children
{:optional true}
[:maybe
[:vector {:min 1 :gen/max 2 :gen/min 1}
[:map
[:type [:= "paragraph-set"]]
[:key {:optional true} :string]
[:children
[:vector {:min 1 :gen/max 2 :gen/min 1}
[:map
[:type [:= "paragraph"]]
[:key {:optional true} :string]
[:fills {:optional true}
[:maybe
[:vector {:gen/max 2} ::shape/fill]]]
[:font-family {:optional true} :string]
[:font-size {:optional true} :string]
[:font-style {:optional true} :string]
[:font-weight {:optional true} :string]
[:direction {:optional true} :string]
[:text-decoration {:optional true} :string]
[:text-transform {:optional true} :string]
[:typography-ref-id {:optional true} [:maybe ::sm/uuid]]
[:typography-ref-file {:optional true} [:maybe ::sm/uuid]]
[:children
[:vector {:min 1 :gen/max 2 :gen/min 1}
[:map
[:text :string]
[:key {:optional true} :string]
[:fills {:optional true}
[:maybe
[:vector {:gen/max 2} ::shape/fill]]]
[:font-family {:optional true} :string]
[:font-size {:optional true} :string]
[:font-style {:optional true} :string]
[:font-weight {:optional true} :string]
[:direction {:optional true} :string]
[:text-decoration {:optional true} :string]
[:text-transform {:optional true} :string]
[:typography-ref-id {:optional true} [:maybe ::sm/uuid]]
[:typography-ref-file {:optional true} [:maybe ::sm/uuid]]]]]]]]]]]]])
(sm/register! ::content schema:content)
(def valid-content?
(sm/lazy-validator schema:content))
(sm/register!
^{::sm/type ::position-data}

View File

@@ -66,16 +66,6 @@
[n]
(string? n))
;; TODO Move this to tokens-lib
(sm/register!
^{::sm/type ::token}
[:map {:title "Token"}
[:name token-name-ref]
[:type [::sm/one-of token-types]]
[:value :any]
[:description {:optional true} [:maybe :string]]
[:modified-at {:optional true} ::sm/inst]])
(sm/register!
^{::sm/type ::color}
[:map

View File

@@ -1,28 +0,0 @@
;; 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/.
;;
;; Copyright (c) KALEIDOS INC
(ns app.common.types.token-theme
(:require
[app.common.schema :as sm]))
(sm/register!
^{::sm/type ::token-theme}
[:map {:title "TokenTheme"}
[:name :string]
[:group :string]
[:description [:maybe :string]]
[:is-source :boolean]
[:id :string]
[:modified-at {:optional true} ::sm/inst]
[:sets :any]])
(sm/register!
^{::sm/type ::token-set}
[:map {:title "TokenSet"}
[:name :string]
[:description {:optional true} [:maybe :string]]
[:modified-at {:optional true} ::sm/inst]
[:tokens {:optional true} :any]])

View File

@@ -7,9 +7,12 @@
(ns app.common.types.tokens-lib
(:require
#?(:clj [app.common.fressian :as fres])
#?(:clj [clojure.data.json :as json])
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.schema :as sm]
[app.common.schema.generators :as sg]
[app.common.time :as dt]
[app.common.transit :as t]
[app.common.types.token :as cto]
@@ -116,13 +119,16 @@
[:map {:title "Token"}
[:name cto/token-name-ref]
[:type [::sm/one-of cto/token-types]]
[:value :any]
[:description [:maybe :string]]
[:modified-at ::sm/inst]])
[:value ::sm/any]
[:description {:optional true} :string]
[:modified-at {:optional true} ::sm/inst]])
(declare make-token)
(def schema:token
[:and
schema:token-attrs
[:and {:gen/gen (->> (sg/generator schema:token-attrs)
(sg/fmap #(make-token %)))}
(sm/required-keys schema:token-attrs)
[:fn token?]])
(def check-token
@@ -321,6 +327,7 @@
(assoc-in [:ids temp-id] token))))
{:tokens-tree {} :ids {}} tokens))
(defprotocol ITokenSet
(update-name [_ set-name] "change a token set name while keeping the path")
(add-token [_ token] "add a token at the end of the list")
@@ -380,15 +387,33 @@
(def schema:token-set-attrs
[:map {:title "TokenSet"}
[:name :string]
[:description [:maybe :string]]
[:modified-at ::sm/inst]
[:tokens [:and
[:map-of {:gen/max 5} :string schema:token]
[:fn d/ordered-map?]]]])
[:description {:optional true} :string]
[:modified-at {:optional true} ::sm/inst]
[:tokens {:optional true
:gen/gen (->> (sg/map-of (sg/generator ::sm/text)
(sg/generator schema:token))
(sg/fmap #(into (d/ordered-map) %)))}
[:and
[:map-of {:gen/max 5
:decode/json (fn [v]
(cond
(d/ordered-map? v)
v
(map? v)
(into (d/ordered-map) v)
:else
v))}
:string schema:token]
[:fn d/ordered-map?]]]])
(declare make-token-set)
(def schema:token-set
[:and
schema:token-set-attrs
[:and {:gen/gen (->> (sg/generator schema:token-set-attrs)
(sg/fmap #(make-token-set %)))}
(sm/required-keys schema:token-set-attrs)
[:fn token-set?]])
(sm/register! ::token-set schema:token-set)
@@ -552,16 +577,16 @@
(def schema:token-theme-attrs
[:map {:title "TokenTheme"}
[:name :string]
[:group :string]
[:description [:maybe :string]]
[:is-source [:maybe :boolean]]
[:id :string]
[:modified-at ::sm/inst]
[:sets [:set {:gen/max 5} :string]]])
[:group {:optional true} :string]
[:description {:optional true} :string]
[:is-source {:optional true} :boolean]
[:id {:optional true} :string]
[:modified-at {:optional true} ::sm/inst]
[:sets {:optional true} [:set {:gen/max 5} :string]]])
(def schema:token-theme
[:and
schema:token-theme-attrs
(sm/required-keys schema:token-theme-attrs)
[:fn token-theme?]])
(sm/register! ::token-theme schema:token-theme)
@@ -803,7 +828,7 @@
(map-indexed (fn [index item]
(assoc item :index index))))))
(defn- flatten-nested-tokens-json
(defn flatten-nested-tokens-json
"Recursively flatten the dtcg token structure, joining keys with '.'."
[tokens token-path]
(reduce-kv
@@ -830,7 +855,7 @@
(declare make-tokens-lib)
(defn- legacy-nodes->dtcg-nodes [sets-data]
(defn legacy-nodes->dtcg-nodes [sets-data]
(walk/postwalk
(fn [node]
(cond-> node
@@ -866,8 +891,6 @@ Will return a value that matches this schema:
(get-active-themes-set-tokens [_] "set of set names that are active in the the active themes")
(encode-dtcg [_] "Encodes library to a dtcg compatible json string")
(decode-dtcg-json [_ parsed-json] "Decodes parsed json containing tokens and converts to library")
(decode-single-set-json [_ set-name tokens] "Decodes parsed json containing single token set and converts to library")
(decode-single-set-legacy-json [_ set-name tokens] "Decodes parsed legacy json containing single token set and converts to library")
(decode-legacy-json [_ parsed-json] "Decodes parsed legacy json containing tokens and converts to library")
(get-all-tokens [_] "all tokens in the lib")
(validate [_]))
@@ -889,6 +912,12 @@ Will return a value that matches this schema:
"themes" (clj->js themes)
"active-themes" (clj->js active-themes)))])
#?@(:clj
[json/JSONWriter
(-write [this writter options] (json/-write (encode-dtcg this) writter options))])
ITokenSets
(add-set [_ token-set]
(let [path (get-token-set-prefixed-path token-set)
@@ -922,6 +951,7 @@ Will return a value that matches this schema:
this)))
(delete-set [_ set-name]
(let [prefixed-path (set-name->prefixed-full-path set-name)]
(TokensLib. (d/dissoc-in sets prefixed-path)
@@ -1311,17 +1341,6 @@ Will return a value that matches this schema:
(assoc-in ["$metadata" "activeThemes"] active-themes-clear)
(assoc-in ["$metadata" "activeSets"] active-sets))))
(decode-single-set-json [this set-name tokens]
(assert (map? tokens) "expected a map data structure for `data`")
(add-set this (make-token-set :name (normalize-set-name set-name)
:tokens (flatten-nested-tokens-json tokens ""))))
(decode-single-set-legacy-json [this set-name tokens]
(assert (map? tokens) "expected a map data structure for `data`")
(decode-single-set-json this set-name (legacy-nodes->dtcg-nodes tokens)))
(decode-dtcg-json [_ data]
(assert (map? data) "expected a map data structure for `data`")
@@ -1481,6 +1500,14 @@ Will return a value that matches this schema:
{:encode/json encode-dtcg
:decode/json decode-dtcg}})
(defn duplicate-set [set-name lib & {:keys [suffix]}]
(let [sets (get-sets lib)
unames (map :name sets)
copy-name (cfh/generate-unique-name set-name unames :suffix suffix)]
(some-> (get-set lib set-name)
(assoc :name copy-name)
(assoc :modified-at (dt/now)))))
(sm/register! type:tokens-lib)
;; === Serialization handlers for RPC API (transit) and database (fressian)

View File

@@ -0,0 +1,281 @@
;; 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/.
;;
;; Copyright (c) KALEIDOS INC
(ns app.common.types.variant
(:require
[app.common.data :as d]
[app.common.files.helpers :as cfh]
[app.common.math :as math]
[app.common.schema :as sm]
[cuerdas.core :as str]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SCHEMA
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def schema:variant-property
[:map
[:name :string]
[:value :string]])
(def schema:variant-component
;; A component that is part of a variant set.
[:map
[:variant-id {:optional true} ::sm/uuid]
[:variant-properties {:optional true} [:vector schema:variant-property]]])
(def schema:variant-shape
;; The root shape of the main instance of a variant component.
[:map
[:variant-id {:optional true} ::sm/uuid]
[:variant-name {:optional true} :string]])
(def schema:variant-container
;; is a board that contains all variant components of a variant set,
;; for grouping them visually in the workspace.
[:map
[:is-variant-container {:optional true} :boolean]])
(sm/register! ::variant-property schema:variant-property)
(sm/register! ::variant-component schema:variant-component)
(sm/register! ::variant-shape schema:variant-shape)
(sm/register! ::variant-container schema:variant-container)
(def valid-variant-component?
(sm/check-fn schema:variant-component))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def property-prefix "Property")
(def property-regex (re-pattern (str property-prefix "(\\d+)")))
(def value-prefix "Value ")
(defn properties-to-name
"Transform the properties into a name, with the values separated by comma"
[properties]
(->> properties
(map :value)
(remove str/empty?)
(str/join ", ")))
(defn next-property-number
"Returns the next property number, to avoid duplicates on the property names"
[properties]
(let [numbers (keep
#(some->> (:name %) (re-find property-regex) second d/parse-integer)
properties)
max-num (if (seq numbers)
(apply max numbers)
0)]
(inc (max max-num (count properties)))))
(defn add-new-prop
"Adds a new property with generated name and provided value to the existing props list."
[props value]
(conj props {:name (str property-prefix (next-property-number props))
:value value}))
(defn add-new-props
"Adds new properties with generated names and provided values to the existing props list."
[props values]
(let [next-prop-num (next-property-number props)
xf (map-indexed (fn [i v]
{:name (str property-prefix (+ next-prop-num i))
:value v}))]
(into props xf values)))
(defn path-to-properties
"From a list of properties and a name with path, assign each token of the
path as value of a different property"
([path properties]
(path-to-properties path properties 0))
([path properties min-props]
(let [cpath (cfh/split-path path)
total-props (max (count cpath) min-props)
assigned (mapv #(assoc % :value (nth cpath %2 "")) properties (range))
;; Add empty strings to the end of cpath to reach the minimum number of properties
cpath (take total-props (concat cpath (repeat "")))
remaining (drop (count properties) cpath)]
(add-new-props assigned remaining))))
(defn properties-map-to-string
"Transforms a map of properties to a string of properties omitting the empty ones"
[properties]
(->> properties
(keep (fn [{:keys [name value]}]
(when (not (str/blank? value))
(str name "=" value))))
(str/join ", ")))
(defn properties-string-to-map
"Transforms a string of properties to a map of properties"
[s]
(->> (str/split s ",")
(mapv #(str/split % "="))
(mapv (fn [[k v]]
{:name (str/trim k)
:value (str/trim v)}))))
(defn valid-properties-string?
"Checks if a string of properties has a processable format or not"
[s]
(let [pattern #"^([a-zA-Z0-9\s]+=[a-zA-Z0-9\s]+)(,\s*[a-zA-Z0-9\s]+=[a-zA-Z0-9\s]+)*$"]
(not (nil? (re-matches pattern s)))))
(defn find-properties-to-remove
"Compares two property maps to find which properties should be removed"
[prev-props upd-props]
(let [upd-names (set (map :name upd-props))]
(filterv #(not (contains? upd-names (:name %))) prev-props)))
(defn find-properties-to-update
"Compares two property maps to find which properties should be updated"
[prev-props upd-props]
(filterv #(some (fn [prop] (and (= (:name %) (:name prop))
(not= (:value %) (:value prop)))) prev-props) upd-props))
(defn find-properties-to-add
"Compares two property maps to find which properties should be added"
[prev-props upd-props]
(let [prev-names (set (map :name prev-props))]
(filterv #(not (contains? prev-names (:name %))) upd-props)))
(defn find-index-for-property-name
"Finds the index of a name in a property map"
[props name]
(some (fn [[idx prop]]
(when (= (:name prop) name)
idx))
(map-indexed vector props)))
(defn remove-prefix
"Removes the given prefix (with or without a trailing ' / ') from the beginning of the name"
[name prefix]
(let [long-name (str prefix " / ")]
(cond
(str/starts-with? name long-name)
(subs name (count long-name))
(str/starts-with? name prefix)
(subs name (count prefix))
:else
name)))
(def ^:private xf:map-name
(map :name))
(defn- matching-indices
[props1 props2]
(let [names-in-p2 (into #{} xf:map-name props2)
xform (comp
(map-indexed (fn [index {:keys [name]}]
(when (contains? names-in-p2 name)
index)))
(filter some?))]
(into #{} xform props1)))
(defn- find-index-by-name
"Returns the index of the first item in props with the given name, or nil if not found."
[name props]
(some (fn [[idx item]]
(when (= (:name item) name)
idx))
(map-indexed vector props)))
(defn- next-valid-position
"Returns the first non-negative integer not present in the used-pos set."
[used-pos]
(loop [p 0]
(if (contains? used-pos p)
(recur (inc p))
p)))
(defn- find-position
"Returns the index of the property with the given name in `props`,
or the next available index not in `used-pos` if not found."
[name props used-pos]
(or (find-index-by-name name props)
(next-valid-position used-pos)))
(defn merge-properties
"Merges props2 into props1 with the following rules:
- For each property p2 in props2:
- Skip it if its value is empty.
- If props1 contains a property with the same name, update its value with that of p2.
- Otherwise, assign p2's value to the first unused property in props1. A property is considered used if:
- Its name exists in both props1 and props2, or
- Its value has already been updated during the merge.
- If no unused properties are available in props1, append a new property with a default name and p2's value."
[props1 props2]
(let [props2 (remove #(str/empty? (:value %)) props2)]
(-> (reduce
(fn [{:keys [props used-pos]} prop]
(let [pos (find-position (:name prop) props used-pos)
used-pos (conj used-pos pos)]
(if (< pos (count props))
{:props (assoc-in (vec props) [pos :value] (:value prop)) :used-pos used-pos}
{:props (add-new-prop props (:value prop)) :used-pos used-pos})))
{:props (vec props1) :used-pos (matching-indices props1 props2)}
props2)
:props)))
(defn compare-properties
"Compares vectors of properties keeping the value if it is the same for all
or setting a custom value where their values do not coincide"
([props-list]
(compare-properties props-list nil))
([props-list distinct-mark]
(let [grouped (group-by :name (apply concat props-list))
check-values (fn [values]
(let [vals (map :value values)]
(if (apply = vals)
(first vals)
distinct-mark)))]
(mapv (fn [[name values]]
{:name name :value (check-values values)})
grouped))))
(defn same-variant?
"Determines if all elements belong to the same variant"
[components]
(let [variant-ids (distinct (map :variant-id components))
not-blank? (complement str/blank?)]
(and
(= 1 (count variant-ids))
(not-blank? (first variant-ids)))))
(defn distance
"Computes a weighted distance between two property lists `props1` and `props2`.
Latter properties weight less that previous ones"
[props1 props2]
(let [total-num-props (count props1)
xform (map-indexed
(fn [idx [p1 p2]]
(if (not= p1 p2)
(math/pow 2 (- total-num-props idx))
0)))]
(transduce
xform
+
(map vector props1 props2))))
(defn variant-name-to-name
"Transforms a variant-name (its properties values) into a standard name:
the real name of the shape joined by the properties values separated by '/'"
[variant]
(cfh/merge-path-item (:name variant) (str/replace (:variant-name variant) #", " " / ")))

View File

@@ -4,36 +4,36 @@
;;
;; Copyright (c) KALEIDOS INC
(ns frontend-tests.tokens.token-test
(ns common-tests.files.tokens-test
(:require
[app.main.ui.workspace.tokens.token :as wtt]
[cljs.test :as t :include-macros true]))
[app.common.files.tokens :as cft]
[clojure.test :as t]))
(t/deftest test-parse-token-value
(t/testing "parses double from a token value"
(t/is (= {:value 100.1 :unit nil} (wtt/parse-token-value "100.1")))
(t/is (= {:value -9 :unit nil} (wtt/parse-token-value "-9"))))
(t/is (= {:value 100.1 :unit nil} (cft/parse-token-value "100.1")))
(t/is (= {:value -9.0 :unit nil} (cft/parse-token-value "-9"))))
(t/testing "trims white-space"
(t/is (= {:value -1.3 :unit nil} (wtt/parse-token-value " -1.3 "))))
(t/is (= {:value -1.3 :unit nil} (cft/parse-token-value " -1.3 "))))
(t/testing "parses unit: px"
(t/is (= {:value 70.3 :unit "px"} (wtt/parse-token-value " 70.3px "))))
(t/is (= {:value 70.3 :unit "px"} (cft/parse-token-value " 70.3px "))))
(t/testing "parses unit: %"
(t/is (= {:value -10 :unit "%"} (wtt/parse-token-value "-10%"))))
(t/is (= {:value -10.0 :unit "%"} (cft/parse-token-value "-10%"))))
(t/testing "parses unit: px")
(t/testing "returns nil for any invalid characters"
(t/is (nil? (wtt/parse-token-value " -1.3a "))))
(t/is (nil? (cft/parse-token-value " -1.3a "))))
(t/testing "doesnt accept invalid double"
(t/is (nil? (wtt/parse-token-value ".3")))))
(t/is (nil? (cft/parse-token-value ".3")))))
(t/deftest token-applied-test
(t/testing "matches passed token with `:token-attributes`"
(t/is (true? (wtt/token-applied? {:name "a"} {:applied-tokens {:x "a"}} #{:x}))))
(t/is (true? (cft/token-applied? {:name "a"} {:applied-tokens {:x "a"}} #{:x}))))
(t/testing "doesn't match empty token"
(t/is (nil? (wtt/token-applied? {} {:applied-tokens {:x "a"}} #{:x}))))
(t/is (nil? (cft/token-applied? {} {:applied-tokens {:x "a"}} #{:x}))))
(t/testing "does't match passed token `:id`"
(t/is (nil? (wtt/token-applied? {:name "b"} {:applied-tokens {:x "a"}} #{:x}))))
(t/is (nil? (cft/token-applied? {:name "b"} {:applied-tokens {:x "a"}} #{:x}))))
(t/testing "doesn't match passed `:token-attributes`"
(t/is (nil? (wtt/token-applied? {:name "a"} {:applied-tokens {:x "a"}} #{:y})))))
(t/is (nil? (cft/token-applied? {:name "a"} {:applied-tokens {:x "a"}} #{:y})))))
(t/deftest shapes-ids-by-applied-attributes
(t/testing "Returns set of matched attributes that fit the applied token"
@@ -54,7 +54,7 @@
shape-applied-x-y
shape-applied-all
shape-applied-none]
expected (wtt/shapes-ids-by-applied-attributes {:name "1"} shapes attributes)]
expected (cft/shapes-ids-by-applied-attributes {:name "1"} shapes attributes)]
(t/is (= (:x expected) (shape-ids shape-applied-x
shape-applied-x-y
shape-applied-all)))
@@ -62,34 +62,34 @@
shape-applied-x-y
shape-applied-all)))
(t/is (= (:z expected) (shape-ids shape-applied-all)))
(t/is (true? (wtt/shapes-applied-all? expected (shape-ids shape-applied-all) attributes)))
(t/is (false? (wtt/shapes-applied-all? expected (apply shape-ids shapes) attributes)))
(t/is (true? (cft/shapes-applied-all? expected (shape-ids shape-applied-all) attributes)))
(t/is (false? (cft/shapes-applied-all? expected (apply shape-ids shapes) attributes)))
(shape-ids shape-applied-x
shape-applied-x-y
shape-applied-all))))
(t/deftest tokens-applied-test
(t/testing "is true when single shape matches the token and attributes"
(t/is (true? (wtt/shapes-token-applied? {:name "a"} [{:applied-tokens {:x "a"}}
(t/is (true? (cft/shapes-token-applied? {:name "a"} [{:applied-tokens {:x "a"}}
{:applied-tokens {:x "b"}}]
#{:x}))))
(t/testing "is false when no shape matches the token or attributes"
(t/is (nil? (wtt/shapes-token-applied? {:name "a"} [{:applied-tokens {:x "b"}}
(t/is (nil? (cft/shapes-token-applied? {:name "a"} [{:applied-tokens {:x "b"}}
{:applied-tokens {:x "b"}}]
#{:x})))
(t/is (nil? (wtt/shapes-token-applied? {:name "a"} [{:applied-tokens {:x "a"}}
(t/is (nil? (cft/shapes-token-applied? {:name "a"} [{:applied-tokens {:x "a"}}
{:applied-tokens {:x "a"}}]
#{:y})))))
(t/deftest name->path-test
(t/is (= ["foo" "bar" "baz"] (wtt/token-name->path "foo.bar.baz")))
(t/is (= ["foo" "bar" "baz"] (wtt/token-name->path "foo..bar.baz")))
(t/is (= ["foo" "bar" "baz"] (wtt/token-name->path "foo..bar.baz...."))))
(t/is (= ["foo" "bar" "baz"] (cft/token-name->path "foo.bar.baz")))
(t/is (= ["foo" "bar" "baz"] (cft/token-name->path "foo..bar.baz")))
(t/is (= ["foo" "bar" "baz"] (cft/token-name->path "foo..bar.baz...."))))
(t/deftest token-name-path-exists?-test
(t/is (true? (wtt/token-name-path-exists? "border-radius" {"border-radius" {"sm" {:name "sm"}}})))
(t/is (true? (wtt/token-name-path-exists? "border-radius" {"border-radius" {:name "sm"}})))
(t/is (true? (wtt/token-name-path-exists? "border-radius.sm" {"border-radius" {:name "sm"}})))
(t/is (true? (wtt/token-name-path-exists? "border-radius.sm.x" {"border-radius" {:name "sm"}})))
(t/is (false? (wtt/token-name-path-exists? "other" {"border-radius" {:name "sm"}})))
(t/is (false? (wtt/token-name-path-exists? "dark.border-radius.md" {"dark" {"border-radius" {"sm" {:name "sm"}}}}))))
(t/is (true? (cft/token-name-path-exists? "border-radius" {"border-radius" {"sm" {:name "sm"}}})))
(t/is (true? (cft/token-name-path-exists? "border-radius" {"border-radius" {:name "sm"}})))
(t/is (true? (cft/token-name-path-exists? "border-radius.sm" {"border-radius" {:name "sm"}})))
(t/is (true? (cft/token-name-path-exists? "border-radius.sm.x" {"border-radius" {:name "sm"}})))
(t/is (false? (cft/token-name-path-exists? "other" {"border-radius" {:name "sm"}})))
(t/is (false? (cft/token-name-path-exists? "dark.border-radius.md" {"dark" {"border-radius" {"sm" {:name "sm"}}}}))))

View File

@@ -40,8 +40,6 @@
(:objects page)
(:id page)
(:id file)
true
nil
nil)
file' (thf/apply-changes file changes)
@@ -74,8 +72,6 @@
(:objects page)
(:id page)
(:id file)
true
nil
cfsh/prepare-create-artboard-from-selection)
file' (thf/apply-changes file changes)
@@ -111,8 +107,6 @@
(:objects page)
(:id page)
(:id file)
true
nil
cfsh/prepare-create-artboard-from-selection)
file' (thf/apply-changes file changes)
@@ -151,8 +145,6 @@
(:objects page)
(:id page)
(:id file)
true
nil
cfsh/prepare-create-artboard-from-selection)
file' (thf/apply-changes file changes)
@@ -191,8 +183,6 @@
(:objects page)
(:id page)
(:id file)
true
nil
nil)
file' (thf/apply-changes file changes)
@@ -232,8 +222,6 @@
(:objects page)
(:id page)
(:id file)
true
nil
cfsh/prepare-create-artboard-from-selection)
file' (thf/apply-changes file changes)
@@ -265,8 +253,7 @@
changes (cll/generate-rename-component (pcb/empty-changes)
(:id component)
"Test component after"
(:data file)
true)
(:data file))
file' (thf/apply-changes file changes)
@@ -445,8 +432,8 @@
(t/is (some? copy1-child'))
(t/is (ctk/instance-root? copy1-root'))
(t/is (ctk/instance-of? copy1-root' (:id file') (:id component')))
(t/is (ctk/is-main-of? main1-root' copy1-root' true))
(t/is (ctk/is-main-of? main1-child' copy1-child' true))
(t/is (ctk/is-main-of? main1-root' copy1-root'))
(t/is (ctk/is-main-of? main1-child' copy1-child'))
(t/is (ctst/parent-of? copy1-root' copy1-child'))))
(t/deftest test-instantiate-component-from-lib
@@ -489,8 +476,8 @@
(t/is (some? copy1-child'))
(t/is (ctk/instance-root? copy1-root'))
(t/is (ctk/instance-of? copy1-root' (:id library) (:id component')))
(t/is (ctk/is-main-of? main1-root' copy1-root' true))
(t/is (ctk/is-main-of? main1-child' copy1-child' true))
(t/is (ctk/is-main-of? main1-root' copy1-root'))
(t/is (ctk/is-main-of? main1-child' copy1-child'))
(t/is (ctst/parent-of? copy1-root' copy1-child'))))
(t/deftest test-instantiate-nested-component
@@ -533,8 +520,8 @@
(t/is (some? copy1-child'))
(t/is (ctk/instance-root? copy1-root'))
(t/is (ctk/instance-of? copy1-root' (:id file') (:id component')))
(t/is (ctk/is-main-of? main1-root' copy1-root' true))
(t/is (ctk/is-main-of? main1-child' copy1-child' true))
(t/is (ctk/is-main-of? main1-root' copy1-root'))
(t/is (ctk/is-main-of? main1-child' copy1-child'))
(t/is (ctst/parent-of? copy1-root' copy1-child'))))
(t/deftest test-instantiate-nested-component-from-lib
@@ -580,8 +567,8 @@
(t/is (some? copy1-child'))
(t/is (ctk/instance-root? copy1-root'))
(t/is (ctk/instance-of? copy1-root' (:id library) (:id component')))
(t/is (ctk/is-main-of? main1-root' copy1-root' true))
(t/is (ctk/is-main-of? main1-child' copy1-child' true))
(t/is (ctk/is-main-of? main1-root' copy1-root'))
(t/is (ctk/is-main-of? main1-child' copy1-child'))
(t/is (ctst/parent-of? copy1-root' copy1-child'))))
(t/deftest test-detach-copy

View File

@@ -47,8 +47,7 @@
file-mdf
{(:id file-mdf) file-mdf}
page-mdf
(:id copy-root)
true)
(:id copy-root))
file' (thf/apply-changes file changes)
@@ -99,8 +98,7 @@
{(:id file-mdf) file-mdf
(:id library) library}
page-mdf
(:id copy-root)
true)
(:id copy-root))
file' (thf/apply-changes file changes)
@@ -151,8 +149,7 @@
file-mdf
{(:id file-mdf) file-mdf}
page-mdf
(:id copy-root)
true)
(:id copy-root))
file' (thf/apply-changes file changes)
@@ -198,8 +195,7 @@
file-mdf
{(:id file-mdf) file-mdf}
page-mdf
(:id copy-root)
true)
(:id copy-root))
file' (thf/apply-changes file changes)
@@ -246,8 +242,7 @@
file-mdf
{(:id file-mdf) file-mdf}
page-mdf
(:id copy-root)
true)
(:id copy-root))
file' (thf/apply-changes file changes)
@@ -291,8 +286,7 @@
file-mdf
{(:id file-mdf) file-mdf}
page-mdf
(:id copy2-root)
true)
(:id copy2-root))
file' (thf/apply-changes file changes)
@@ -338,8 +332,7 @@
file-mdf
{(:id file-mdf) file-mdf}
page-mdf
(:id copy2-root)
true)
(:id copy2-root))
file' (thf/apply-changes file changes)

View File

@@ -227,7 +227,7 @@
(t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-new-child') nil))
(t/is (ctst/parent-of? copy-root' copy-new-child'))
(t/is (ctk/is-main-of? main-free-shape' copy-new-child' true))))
(t/is (ctk/is-main-of? main-free-shape' copy-new-child'))))
(t/deftest test-sync-when-deleting-shape
(let [;; ==== Setup

View File

@@ -1,3 +1,9 @@
;; 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/.
;;
;; Copyright (c) KALEIDOS INC
(ns common-tests.logic.token-test
(:require
[app.common.files.changes-builder :as pcb]

View File

@@ -7,7 +7,10 @@
(ns common-tests.logic.variants-test
(:require
[app.common.files.changes-builder :as pcb]
[app.common.logic.variants :as clv]
[app.common.geom.point :as gpt]
[app.common.logic.libraries :as cll]
[app.common.logic.shapes :as cls]
[app.common.logic.variant-properties :as clvp]
[app.common.test-helpers.components :as thc]
[app.common.test-helpers.files :as thf]
[app.common.test-helpers.ids-map :as thi]
@@ -20,7 +23,7 @@
(t/deftest test-update-property-name
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(thv/add-variant :v01 :c01 :m01 :c02 :m02))
(thv/add-variant-two-properties :v01 :c01 :m01 :c02 :m02))
v-id (-> (ths/get-shape file :v01) :id)
page (thf/current-page file)
@@ -29,8 +32,8 @@
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clv/generate-update-property-name v-id 0 "NewName1")
(clv/generate-update-property-name v-id 1 "NewName2"))
(clvp/generate-update-property-name v-id 0 "NewName1")
(clvp/generate-update-property-name v-id 1 "NewName2"))
file' (thf/apply-changes file changes)
@@ -65,7 +68,7 @@
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clv/generate-add-new-property v-id))
(clvp/generate-add-new-property v-id))
file' (thf/apply-changes file changes)
@@ -101,7 +104,7 @@
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clv/generate-add-new-property v-id {:fill-values? true}))
(clvp/generate-add-new-property v-id {:fill-values? true}))
file' (thf/apply-changes file changes)
@@ -117,7 +120,7 @@
(t/is (= (count (:variant-properties comp01')) 2))
(t/is (= (count (:variant-properties comp02)) 1))
(t/is (= (count (:variant-properties comp02')) 2))
(t/is (= (-> comp01' :variant-properties last :value) "Value1"))))
(t/is (= (-> comp01' :variant-properties last :value) "Value 1"))))
@@ -132,7 +135,7 @@
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clv/generate-add-new-property v-id))
(clvp/generate-add-new-property v-id))
file (thf/apply-changes file changes)
@@ -147,7 +150,7 @@
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clv/generate-remove-property v-id 0))
(clvp/generate-remove-property v-id 0))
file' (thf/apply-changes file changes)
@@ -180,8 +183,8 @@
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clv/generate-update-property-value (:id comp01) 0 "NewValue1")
(clv/generate-update-property-value (:id comp02) 0 "NewValue2"))
(clvp/generate-update-property-value (:id comp01) 0 "NewValue1")
(clvp/generate-update-property-value (:id comp02) 0 "NewValue2"))
file' (thf/apply-changes file changes)
@@ -192,3 +195,73 @@
;; ==== Check
(t/is (= (-> comp01' :variant-properties first :value) "NewValue1"))
(t/is (= (-> comp02' :variant-properties first :value) "NewValue2"))))
(t/deftest test-duplicate-variant-container
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(thv/add-variant :v01 :c01 :m01 :c02 :m02))
data (:data file)
page (thf/current-page file)
objects (:objects page)
variant-container (ths/get-shape file :v01)
;; ==== Action
changes (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(cll/generate-duplicate-changes objects ;; objects
page ;; page
#{(:id variant-container)} ;; ids
(gpt/point 0 0) ;; delta
{(:id file) file} ;; libraries
(:data file) ;; library-data
(:id file))) ;; file-id
;; ==== Get
file' (thf/apply-changes file changes)
data' (:data file')
page' (thf/current-page file')
objects' (:objects page')]
;; ==== Check
(thf/validate-file! file')
(t/is (= (count (:components data)) 2))
(t/is (= (count (:components data')) 4))
(t/is (= (count objects) 4))
(t/is (= (count objects') 7))))
(t/deftest test-delete-variant
;; When a variant container becomes empty, it id automatically deleted
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(thv/add-variant-two-properties :v01 :c01 :m01 :c02 :m02))
container (ths/get-shape file :v01)
m01-id (-> (ths/get-shape file :m01) :id)
m02-id (-> (ths/get-shape file :m02) :id)
page (thf/current-page file)
;; ==== Action
changes (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(#(second (cls/generate-delete-shapes % #{m01-id m02-id} {}))))
file' (thf/apply-changes file changes)
;; ==== Get
container' (ths/get-shape file' :v01)]
;; ==== Check
;; The variant containew was not nil before the deletion
(t/is (not (nil? container)))
;; The variant containew is nil after the deletion
(t/is (nil? container'))))

View File

@@ -41,6 +41,7 @@
[common-tests.types.modifiers-test]
[common-tests.types.shape-decode-encode-test]
[common-tests.types.shape-interactions-test]
[common-tests.types.shape-path-data-test]
[common-tests.types.tokens-lib-test]
[common-tests.uuid-test]))
@@ -90,4 +91,5 @@
'common-tests.types.tokens-lib-test
'common-tests.types.components-test
'common-tests.types.absorb-assets-test
'common-tests.types.shape-path-data-test
'common-tests.uuid-test))

View File

@@ -547,4 +547,3 @@
;; FOR POSSIBLE FUTURE TEST CASES
;; (str "M259.958 89.134c-6.88-.354-10.484-1.241-12.44-3.064-1.871-1.743-6.937-3.098-15.793-4.226-7.171-.913-17.179-2.279-22.24-3.034-5.06-.755-15.252-2.016-22.648-2.8-18.685-1.985-35.63-4.223-38.572-5.096-3.655-1.084-3.016-3.548.708-2.726 1.751.387 13.376 1.701 25.833 2.922 12.456 1.22 29.018 3.114 36.803 4.208 29.94 4.206 29.433 4.204 34.267.136 3.787-3.186 5.669-3.669 14.303-3.669 14.338 0 17.18 1.681 12.182 7.205-2.053 2.268-1.994 2.719.707 5.42 3.828 3.827 3.74 5.846-.238 5.5-1.752-.153-7.544-.502-12.872-.776zm7.563-3.194c0-.778-1.751-1.352-3.892-1.274l-3.893.141 3.539 1.133c1.946.624 3.698 1.197 3.893 1.275.194.077.354-.496.354-1.275zm-15.899-8.493c1.43-2.29 1.414-2.83-.084-2.83-2.05 0-5.25 2.76-5.25 4.529 0 2.226 3.599 1.08 5.334-1.699zm8.114 0c2.486-2.746 2.473-2.83-.438-2.83-1.65 0-3.683 1.273-4.516 2.83-1.175 2.196-1.077 2.831.438 2.831 1.075 0 3.107-1.274 4.516-2.83zm7.814.674c2.858-3.444.476-4.085-3.033-.816-2.451 2.284-2.677 2.973-.975 2.973 1.22 0 3.023-.97 4.008-2.157zm-49.571-4.509c-1.168-.43-3.294-1.802-4.725-3.051-2.112-1.843-9.304-2.595-38.219-3.994-46.474-2.25-63-4.077-60.27-6.665.324-.308 9.507.261 20.406 1.264 10.9 1.003 31.16 2.258 45.024 2.789l25.207.964 4.625-3.527c4.313-3.29 5.41-3.474 16.24-2.732 6.389.438 11.981 1.388 12.428 2.111.447.723-.517 2.73-2.141 4.46l-2.954 3.144c1.607 1.697 3.308 3.289 5.049 4.845 3.248 2.189-5.438 1.289-8.678 1.284-5.428-.061-10.825-.463-11.992-.892zm12.74-3.242c-1.123-.694-2.36-.943-2.75-.554-.389.39.21 1.275 1.334 1.97 1.122.693 2.36.942 2.749.553.389-.39-.21-1.275-1.334-1.97zm-5.663 0a1.42 1.42 0 00-1.415-1.416 1.42 1.42 0 00-1.416 1.416 1.42 1.42 0 001.416 1.415 1.42 1.42 0 001.415-1.415zm-8.464-6.404c.984-1.187 1.35-2.598.813-3.135-1.181-1.18-5.408 1.297-6.184 3.624-.806 2.42 3.265 2.048 5.37-.49zm6.863.258c.867-1.045 1.163-2.313.658-2.819-1.063-1.062-4.719 1.631-4.719 3.476 0 1.864 2.274 1.496 4.061-.657zm8.792-.36c1.637-1.972 1.448-2.197-1.486-1.77-1.848.27-3.622 1.287-3.943 2.26-.838 2.547 3.212 2.181 5.429-.49zm32.443-4.11c-6.156-2.228-67.1-6.138-119.124-7.642-39.208-1.134-72.072-.928-94.618.593-6.617.446-19.681 1.16-29.03 1.587-15.798.72-17.183.573-19.588-2.085-4.498-4.97-2.544-7.857 6.39-9.44 4.394-.778 9.164-2.436 10.6-3.685 5.44-4.729 20.332-14.06 31.14-19.509C65.717 11.88 78.955 7.79 103.837 3.08 121.686-.3 125.552-.642 129.318.82c2.44.948 12.4 1.948 22.132 2.221 15.37.432 20.004 1.18 35.294 5.698 22.36 6.606 39.732 15.1 56.55 27.653 7.307 5.452 14.086 9.913 15.066 9.913.98 0 2.148.956 2.596 2.124.55 1.432 2.798 2.123 6.914 2.123 6.213 0 12.4 3.046 12.38 6.096-.012 1.75-6.502 5.353-9.118 5.063-.818-.09-3.717-.972-6.442-1.958zm-16.986-7.436c0-1.575-33.326-18.118-43.173-21.43-23.008-7.739-54.084-12.922-77.136-12.866-16.863.041-37.877 3.628-52.465 8.956-18.062 6.596-26.563 10.384-29.181 13.002-1.205 1.205-5.306 3.769-9.112 5.698-7.754 3.929-8.841 5.482-3.029 4.325 13.494-2.685 66.794-3.773 110.913-2.264 38.005 1.3 96.812 4.435 102.122 5.443.584.111 1.061-.277 1.061-.864zm-236.39-3.18c0-.78-1.592-1.416-3.539-1.416-1.946 0-3.538.637-3.538 1.415 0 .779 1.592 1.416 3.538 1.416 1.947 0 3.54-.637 3.54-1.416zm7.078-1.416c0-.779-.956-1.416-2.124-1.416-1.167 0-2.123.637-2.123 1.416 0 .778.956 1.415 2.123 1.415 1.168 0 2.124-.637 2.124-1.415zm11.734-4.437c3.278-1.661 6.278-3.483 6.667-4.048 1.366-1.98 20.645-11.231 32.557-15.622 11.862-4.372 36.546-9.865 44.327-9.865 3.485 0 3.867-.404 3.012-3.185-.538-1.752-1.177-3.41-1.42-3.685-.907-1.026-36.72 7.16-45.065 10.302-17.226 6.484-47.566 24.27-47.566 27.886 0 1.786.845 1.585 7.488-1.783zm206.254-5.577c-12.298-10.518-53.842-27.166-70.896-28.41-5.526-.404-6.3-.097-6.695 2.655-.33 2.307.402 3.275 2.831 3.742 32.436 6.237 52.205 12.315 66.975 20.594 11.904 6.673 14.477 7.141 7.785 1.419zM150.1 11.04c-1.949-3.64-7.568-4.078-6.886-.538.256 1.329 2.054 2.817 3.997 3.309 4.498 1.137 4.816.832 2.888-2.771zm6.756.94c-.248-1.752-1.026-3.185-1.727-3.185-.7 0-1.493 1.433-1.76 3.185-.328 2.152.232 3.185 1.727 3.185 1.485 0 2.064-1.047 1.76-3.185zm-30.178-2.458c0-2.303-.908-3.694-2.627-4.025-3.6-.694-5.23 1.301-4.22 5.166 1.216 4.647 6.847 3.709 6.847-1.14zm12.544 2.104c-.448-1.168-1.224-2.132-1.725-2.142-.5-.013-2.343-.404-4.095-.873-2.569-.689-3.185-.274-3.185 2.142 0 2.476.854 2.996 4.91 2.996 3.783 0 4.723-.487 4.095-2.123z")

View File

@@ -54,7 +54,7 @@
(t/is (= (count components') 1))
(t/is (ctk/instance-of? copy-root' (:id file') (:id component')))
(t/is (ctk/is-main-of? main-root' copy-root' true))
(t/is (ctk/is-main-of? main-root' copy-root'))
(t/is (ctk/main-instance-of? (:id main-root') (:id (second pages')) component'))))
(t/deftest absorb-colors

View File

@@ -1,6 +0,0 @@
{"color":
{"red":
{"100":
{"value":"red",
"type":"color",
"description":""}}}}

View File

@@ -1,6 +0,0 @@
{"color":
{"red":
{"100":
{"$value":"red",
"$type":"color",
"$description":""}}}}

View File

@@ -0,0 +1,59 @@
;; 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/.
;;
;; Copyright (c) KALEIDOS INC
(ns common-tests.types.shape-path-data-test
(:require
[app.common.data :as d]
[app.common.math :as mth]
[app.common.pprint :as pp]
[app.common.types.shape.path :as path]
[clojure.test :as t]))
(def sample-content
[{:command :move-to, :params {:x 480.0, :y 839.0}}
{:command :line-to, :params {:x 439.0, :y 802.0}}
{:command :curve-to, :params {:c1x 368.0, :c1y 737.0, :c2x 310.0, :c2y 681.0, :x 264.0, :y 634.0}}
{:command :close-path :params {}}])
(def sample-bytes
[0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 67 -16 0 0 68 81 -64 0
0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 67 -37 -128 0 68 72 -128 0
0 3 0 0 67 -72 0 0 68 56 64 0 67 -101 0 0 68 42 64 0 67 -124 0 0 68 30 -128 0
0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0])
;; This means it implements IReduceInit/IReduce protocols
(t/deftest path-data-to-vector
(let [pdata (path/path-data sample-content)
result (vec pdata)]
(t/is (= 4 (count result)))
(t/is (= (get-in sample-content [0 :command])
(get-in result [0 :command])))
(t/is (= (get-in sample-content [1 :command])
(get-in result [1 :command])))
(t/is (= (get-in sample-content [2 :command])
(get-in result [2 :command])))
(t/is (= (get-in sample-content [3 :command])
(get-in result [3 :command])))
(t/is (= (get-in sample-content [0 :params])
(get-in result [0 :params])))
(t/is (= (get-in sample-content [1 :params])
(get-in result [1 :params])))
(t/is (= (get-in sample-content [2 :params])
(get-in result [2 :params])))
(t/is (= (get-in sample-content [3 :params])
(get-in result [3 :params])))))
(t/deftest path-data-plain-to-binary
(let [pdata (path/path-data sample-content)]
(t/is (= sample-bytes
(vec
#?(:cljs (js/Int8Array. (.-buffer pdata))
:clj (.array (.-buffer pdata))))))
(t/is (= (->> sample-content
(mapv path/map->PathSegment))
(vec pdata)))))

View File

@@ -120,7 +120,6 @@
(t/is (= ["Foo/Foo" "Foo/Baz" "Foo/Bar"] (move ["Foo"] ["Foo" "Foo"] ["Foo" "Baz"] false)))
(t/is (= ["Foo/Baz" "Foo/Bar" "Foo/Foo"] (move ["Foo"] ["Foo" "Foo"] nil false))))))
(t/deftest move-token-set-nested-2
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "a/b"))
@@ -220,7 +219,6 @@
(t/is (thrown-with-msg? #?(:cljs js/Error :clj Exception) #"expected valid params for token-theme"
(ctob/make-token-theme params)))))
(t/deftest make-tokens-lib
(let [tokens-lib (ctob/make-tokens-lib)]
(t/is (= (ctob/set-count tokens-lib) 0))))
@@ -315,6 +313,58 @@
(t/is (= (:sets token-theme') #{}))
(t/is (nil? token-set'))))
(t/deftest duplicate-token-set
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "test-token-set"
:tokens {"test-token"
(ctob/make-token :name "test-token"
:type :boolean
:value true)})))
token-set-copy (ctob/duplicate-set "test-token-set" tokens-lib {:suffix "copy"})
token (get-in token-set-copy [:tokens "test-token"])]
(t/is (some? token-set-copy))
(t/is (= (:name token-set-copy) "test-token-set-copy"))
(t/is (= (count (:tokens token-set-copy)) 1))
(t/is (= (:name token) "test-token"))))
(t/deftest duplicate-token-set-twice
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "test-token-set"
:tokens {"test-token"
(ctob/make-token :name "test-token"
:type :boolean
:value true)})))
tokens-lib (ctob/add-set tokens-lib (ctob/duplicate-set "test-token-set" tokens-lib {:suffix "copy"}))
token-set-copy (ctob/duplicate-set "test-token-set" tokens-lib {:suffix "copy"})
token (get-in token-set-copy [:tokens "test-token"])]
(t/is (some? token-set-copy))
(t/is (= (:name token-set-copy) "test-token-set-copy-2"))
(t/is (= (count (:tokens token-set-copy)) 1))
(t/is (= (:name token) "test-token"))))
(t/deftest duplicate-empty-token-set
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "test-token-set")))
token-set-copy (ctob/duplicate-set "test-token-set" tokens-lib {:suffix "copy"})
tokens (get token-set-copy :tokens)]
(t/is (some? token-set-copy))
(t/is (= (:name token-set-copy) "test-token-set-copy"))
(t/is (= (count (:tokens token-set-copy)) 0))
(t/is (= (count tokens) 0))))
(t/deftest duplicate-not-existing-token-set
(let [tokens-lib (ctob/make-tokens-lib)
token-set-copy (ctob/duplicate-set "test-token-set" tokens-lib {:suffix "copy"})]
(t/is (nil? token-set-copy))))
(t/deftest active-themes-set-names
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "test-token-set")))
@@ -918,7 +968,6 @@
(t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set)))
(t/is (dt/is-after? (:modified-at token') (:modified-at token)))))
(t/deftest update-token-in-sets-rename
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "test-token-set"))
@@ -1371,30 +1420,6 @@
(t/testing "invalid tokens got discarded"
(t/is (nil? (get-set-token "typography" "H1.Bold")))))))
#?(:clj
(t/deftest single-set-legacy-json-decoding
(let [json (-> (slurp "test/common_tests/types/data/legacy-single-set.json")
(tr/decode-str))
lib (ctob/decode-single-set-legacy-json (ctob/ensure-tokens-lib nil) "single_set" json)
get-set-token (fn [set-name token-name]
(some-> (ctob/get-set lib set-name)
(ctob/get-token token-name)))]
(t/is (= '("single_set") (ctob/get-ordered-set-names lib)))
(t/testing "token added"
(t/is (some? (get-set-token "single_set" "color.red.100")))))))
#?(:clj
(t/deftest single-set-dtcg-json-decoding
(let [json (-> (slurp "test/common_tests/types/data/single-set.json")
(tr/decode-str))
lib (ctob/decode-single-set-json (ctob/ensure-tokens-lib nil) "single_set" json)
get-set-token (fn [set-name token-name]
(some-> (ctob/get-set lib set-name)
(ctob/get-token token-name)))]
(t/is (= '("single_set") (ctob/get-ordered-set-names lib)))
(t/testing "token added"
(t/is (some? (get-set-token "single_set" "color.red.100")))))))
#?(:clj
(t/deftest dtcg-encoding-decoding-json
(let [json (-> (slurp "test/common_tests/types/data/tokens-multi-set-example.json")

View File

@@ -0,0 +1,112 @@
;; 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/.
;;
;; Copyright (c) KALEIDOS INC
(ns common-tests.types.variant-test
(:require
[app.common.types.variant :as ctv]
[clojure.test :as t]))
(t/deftest variant-distance01
;;c1: primary, default, rounded, blue, dark
;;c2: primary, hover, squared, blue, dark
;;c3: primary, default, squared, blue, light
;; I have a copy of c1, and I change from rounded to squared
;; c2: 1 difference in pos 2
;; c3: 1 differences in pos 5
;; The min distance should be c3
(let [target [{:name "type" :value "primary"}
{:name "status" :value "default"}
{:name "borders" :value "squared"}
{:name "color" :value "blue"}
{:name "theme" :value "dark"}]
props2 [{:name "type" :value "primary"}
{:name "status" :value "hover"}
{:name "borders" :value "rounded"}
{:name "color" :value "blue"}
{:name "theme" :value "dark"}]
props3 [{:name "type" :value "primary"}
{:name "status" :value "default"}
{:name "borders" :value "rounded"}
{:name "color" :value "blue"}
{:name "theme" :value "light"}]
dist2 (ctv/distance target props2)
dist3 (ctv/distance target props3)]
(t/is (< dist3 dist2))))
(t/deftest variant-distance02
;;c1: primary, default, rounded, blue, dark
;;c2: primary, hover, squared, red, dark
;;c3: secondary, hover, rounded, blue, dark
;; I have a copy of c1, and I change from default to hover
;; c2: 2 differences in pos 3 and 4
;; c3: 1 differences in pos 1
;; The min distance should be c2
(let [target [{:name "type" :value "primary"}
{:name "status" :value "hover"}
{:name "borders" :value "rounded"}
{:name "color" :value "blue"}
{:name "theme" :value "dark"}]
props2 [{:name "type" :value "primary"}
{:name "status" :value "hover"}
{:name "borders" :value "squared"}
{:name "color" :value "red"}
{:name "theme" :value "dark"}]
props3 [{:name "type" :value "secondary"}
{:name "status" :value "hover"}
{:name "borders" :value "rounded"}
{:name "color" :value "blue"}
{:name "theme" :value "dark"}]
dist2 (ctv/distance target props2)
dist3 (ctv/distance target props3)]
(t/is (< dist2 dist3))))
(t/deftest variant-distance03
;;c1: primary, default, rounded, blue, dark
;;c2: secondary, default, rounded, blue, light
;;c3: secondary, hover, squared, blue, dark
;;c4: secondary, hover, rounded, blue, dark
;; I have a copy of c1, and I change from primary to secondary
;; c2: 1 difference in pos 4
;; c3: 2 differences in pos 1 and 2
;; c4: 1 difference in pos 1
;; The distances should be c2 < c4 < c3
(let [target [{:name "type" :value "secondary"}
{:name "status" :value "default"}
{:name "borders" :value "rounded"}
{:name "color" :value "blue"}
{:name "theme" :value "dark"}]
props2 [{:name "type" :value "secondary"}
{:name "status" :value "default"}
{:name "borders" :value "rounded"}
{:name "color" :value "blue"}
{:name "theme" :value "light"}]
props3 [{:name "type" :value "secondary"}
{:name "status" :value "hover"}
{:name "borders" :value "squared"}
{:name "color" :value "blue"}
{:name "theme" :value "dark"}]
props4 [{:name "type" :value "secondary"}
{:name "status" :value "hover"}
{:name "borders" :value "rounded"}
{:name "color" :value "blue"}
{:name "theme" :value "dark"}]
dist2 (ctv/distance target props2)
dist3 (ctv/distance target props3)
dist4 (ctv/distance target props4)]
(t/is (< dist2 dist4))
(t/is (< dist4 dist3))))

View File

@@ -0,0 +1,108 @@
;; 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/.
;;
;; Copyright (c) KALEIDOS INC
(ns common-tests.variant-test
(:require
[app.common.types.variant :as ctv]
[clojure.test :as t]))
(t/deftest convert-between-variant-properties-maps-and-strings
(let [map-with-two-props [{:name "border" :value "yes"} {:name "color" :value "gray"}]
map-with-two-props-one-blank [{:name "border" :value "no"} {:name "color" :value ""}]
map-with-one-prop [{:name "border" :value "no"}]
map-with-spaces [{:name "border 1" :value "of course"} {:name "color 2" :value "dark gray"}]
string-valid-with-two-props "border=yes, color=gray"
string-valid-with-one-prop "border=no"
string-valid-with-spaces "border 1=of course, color 2=dark gray"
string-invalid "border=yes, color="]
(t/testing "convert map to string"
(t/is (= (ctv/properties-map-to-string map-with-two-props) string-valid-with-two-props))
(t/is (= (ctv/properties-map-to-string map-with-two-props-one-blank) string-valid-with-one-prop))
(t/is (= (ctv/properties-map-to-string map-with-spaces) string-valid-with-spaces)))
(t/testing "convert string to map"
(t/is (= (ctv/properties-string-to-map string-valid-with-two-props) map-with-two-props))
(t/is (= (ctv/properties-string-to-map string-valid-with-one-prop) map-with-one-prop))
(t/is (= (ctv/properties-string-to-map string-valid-with-spaces) map-with-spaces)))
(t/testing "check if a string is valid"
(t/is (= (ctv/valid-properties-string? string-valid-with-two-props) true))
(t/is (= (ctv/valid-properties-string? string-valid-with-one-prop) true))
(t/is (= (ctv/valid-properties-string? string-valid-with-spaces) true))
(t/is (= (ctv/valid-properties-string? string-invalid) false)))))
(t/deftest find-properties
(let [prev-props [{:name "border" :value "yes"} {:name "color" :value "gray"}]
upd-props-1 [{:name "border" :value "yes"}]
upd-props-2 [{:name "border" :value "yes"} {:name "color" :value "blue"}]
upd-props-3 [{:name "border" :value "yes"} {:name "color" :value "gray"} {:name "shadow" :value "large"}]
upd-props-4 [{:name "color" :value "yellow"} {:name "shadow" :value "large"}]]
(t/testing "a property to remove"
(t/is (= (ctv/find-properties-to-remove prev-props upd-props-1)
[{:name "color" :value "gray"}]))
(t/is (= (ctv/find-properties-to-update prev-props upd-props-1)
[]))
(t/is (= (ctv/find-properties-to-add prev-props upd-props-1)
[])))
(t/testing "a property to update"
(t/is (= (ctv/find-properties-to-remove prev-props upd-props-2)
[]))
(t/is (= (ctv/find-properties-to-update prev-props upd-props-2)
[{:name "color" :value "blue"}]))
(t/is (= (ctv/find-properties-to-add prev-props upd-props-2)
[])))
(t/testing "a property to add"
(t/is (= (ctv/find-properties-to-remove prev-props upd-props-3)
[]))
(t/is (= (ctv/find-properties-to-update prev-props upd-props-3)
[]))
(t/is (= (ctv/find-properties-to-add prev-props upd-props-3)
[{:name "shadow" :value "large"}])))
(t/testing "properties to remove, update & add"
(t/is (= (ctv/find-properties-to-remove prev-props upd-props-4)
[{:name "border" :value "yes"}]))
(t/is (= (ctv/find-properties-to-update prev-props upd-props-4)
[{:name "color" :value "yellow"}]))
(t/is (= (ctv/find-properties-to-add prev-props upd-props-4)
[{:name "shadow" :value "large"}])))
(t/testing "find property index"
(t/is (= (ctv/find-index-for-property-name prev-props "border") 0))
(t/is (= (ctv/find-index-for-property-name prev-props "color") 1)))))
(t/deftest compare-properties
(let [props-1 [{:name "border" :value "yes"} {:name "color" :value "gray"}]
props-2 [{:name "border" :value "yes"} {:name "color" :value "red"}]
props-3 [{:name "border" :value "no"} {:name "color" :value "gray"}]]
(t/testing "compare properties"
(t/is (= (ctv/compare-properties [props-1 props-2])
[{:name "border" :value "yes"} {:name "color" :value nil}]))
(t/is (= (ctv/compare-properties [props-1 props-2 props-3])
[{:name "border" :value nil} {:name "color" :value nil}]))
(t/is (= (ctv/compare-properties [props-1 props-2 props-3] "&")
[{:name "border" :value "&"} {:name "color" :value "&"}])))))
(t/deftest check-belong-same-variant
(let [components-1 [{:variant-id "a variant"} {:variant-id "a variant"}]
components-2 [{:variant-id "a variant"} {:variant-id "another variant"}]
components-3 [{:variant-id "a variant"} {}]
components-4 [{} {}]]
(t/testing "check-belong-same-variant"
(t/is (= (ctv/same-variant? components-1) true))
(t/is (= (ctv/same-variant? components-2) false))
(t/is (= (ctv/same-variant? components-3) false))
(t/is (= (ctv/same-variant? components-4) false)))))

View File

@@ -1,15 +1,16 @@
FROM debian:bookworm
FROM ubuntu:24.04
LABEL maintainer="Penpot <docker@penpot.app>"
ARG DEBIAN_FRONTEND=noninteractive
ENV NODE_VERSION=v22.13.1 \
ENV NODE_VERSION=v22.14.0 \
CLOJURE_VERSION=1.12.0.1501 \
CLJKONDO_VERSION=2025.01.16 \
BABASHKA_VERSION=1.12.196 \
CLJFMT_VERSION=0.13.0 \
RUSTUP_VERSION=1.27.1 \
RUST_VERSION=1.85.0 \
EMSCRIPTEN_VERSION=4.0.6 \
LANG=en_US.UTF-8 \
LC_ALL=en_US.UTF-8
@@ -45,7 +46,7 @@ RUN set -ex; \
rm -rf /var/lib/apt/lists/*;
RUN set -ex; \
useradd -m -g users -s /bin/bash penpot; \
usermod -l penpot -d /home/penpot -G users -s /bin/bash ubuntu; \
passwd penpot -d; \
echo "penpot ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
@@ -63,8 +64,6 @@ RUN set -ex; \
woff-tools \
woff2 \
fontforge \
gconf-service \
libasound2 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcairo2 \
@@ -73,7 +72,6 @@ RUN set -ex; \
libexpat1 \
libfontconfig1 \
libgcc1 \
libgconf-2-4 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libgtk-3-0 \
@@ -95,7 +93,6 @@ RUN set -ex; \
libxss1 \
libxtst6 \
fonts-liberation \
libappindicator1 \
libnss3 \
libgbm1 \
xvfb \
@@ -107,12 +104,12 @@ RUN set -eux; \
ARCH="$(dpkg --print-architecture)"; \
case "${ARCH}" in \
aarch64|arm64) \
ESUM='fb43ae1202402842559cb6223886ec1663b90ffbec48479abbcb92c92c9012eb'; \
BINARY_URL='https://github.com/adoptium/temurin23-binaries/releases/download/jdk-23.0.2%2B7/OpenJDK23U-jdk_aarch64_linux_hotspot_23.0.2_7.tar.gz'; \
ESUM='18071047526ab4b53131f9bb323e8703485ae37fcb2f2c5ef0f1b7bab66d1b94'; \
BINARY_URL='https://github.com/adoptium/temurin24-binaries/releases/download/jdk-24%2B36/OpenJDK24U-jdk_aarch64_linux_hotspot_24_36.tar.gz'; \
;; \
amd64|x86_64) \
ESUM='870ac8c05c6fe563e7a3878a47d0234b83c050e83651d2c47e8b822ec74512dd'; \
BINARY_URL='https://github.com/adoptium/temurin23-binaries/releases/download/jdk-23.0.2%2B7/OpenJDK23U-jdk_x64_linux_hotspot_23.0.2_7.tar.gz'; \
ESUM='c340dee97b6aa215d248bc196dcac5b56e7be9b5c5d45e691344d40d5d0b171d'; \
BINARY_URL='https://github.com/adoptium/temurin24-binaries/releases/download/jdk-24%2B36/OpenJDK24U-jdk_x64_linux_hotspot_24_36.tar.gz'; \
;; \
*) \
echo "Unsupported arch: ${ARCH}"; \
@@ -137,7 +134,7 @@ RUN set -ex; \
RUN set -ex; \
install -d /usr/share/postgresql-common/pgdg; \
curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc; \
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" >> /etc/apt/sources.list.d/postgresql.list; \
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt noble-pgdg main" >> /etc/apt/sources.list.d/postgresql.list; \
apt-get -qq update; \
apt-get -qqy install postgresql-client-16; \
rm -rf /var/lib/apt/lists/*;
@@ -273,8 +270,8 @@ WORKDIR /usr/local
RUN set -eux; \
git clone https://github.com/emscripten-core/emsdk.git; \
cd emsdk; \
./emsdk install latest; \
./emsdk activate latest; \
./emsdk install $EMSCRIPTEN_VERSION; \
./emsdk activate $EMSCRIPTEN_VERSION; \
rustup target add wasm32-unknown-emscripten;
WORKDIR /home

View File

@@ -68,7 +68,7 @@ services:
- PENPOT_LDAP_ATTRS_PHOTO=jpegPhoto
minio:
image: "minio/minio:RELEASE.2023-11-11T08-14-41Z"
image: "minio/minio:RELEASE.2025-04-03T14-56-28Z"
command: minio server /mnt/data --console-address ":9001"
volumes:
@@ -83,7 +83,7 @@ services:
- 9001:9001
postgres:
image: postgres:16
image: postgres:16.8
command: postgres -c config_file=/etc/postgresql.conf
restart: always
stop_signal: SIGINT

View File

@@ -3,7 +3,6 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="{{ description or metadata.description }}">
<link rel="stylesheet" href="{{ '/css/index.css' | url }}">
<link rel="stylesheet" href="{{ '/css/prism.css' | url }}">
<link rel="shortcut icon" href="/img/favicon.png">
@@ -15,7 +14,7 @@
<link href="https://fonts.googleapis.com/css2?family=Work+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
{% metagen
title=title or metadata.title,
desc=desc or metadata.desc,
desc=desc or metadata.desc or description or metadata.description,
url="https://help.penpot.app" + page.url,
img="https://help.penpot.app/img/th-help-center.jpg",
img_alt=alt,

View File

@@ -1,5 +1,6 @@
---
title: 04· Code of Conduct
desc: Learn about contributing to the Penpot project! This page outlines the Code of Conduct, reporting bugs, translations, core code contributions, & more.
---
<h1 id="coc">Code of conduct</h1>

View File

@@ -1,5 +1,6 @@
---
title: 03· Core code contributions
desc: Learn how to contribute to Penpot's open-source design collaboration platform. Find guidelines for bug reporting, code contributions & more.
---
<h1 id="code-contributions">Core code contributions</h1>

View File

@@ -1,5 +1,6 @@
---
title: Contributing
desc: Learn how to contribute to Penpot, the open-source design collaboration platform! Find guides on bug reporting, translations, code contributions, and more.
eleventyNavigation:
key: Contributing
order: 3

View File

@@ -1,5 +1,6 @@
---
title: 05· Libraries & Templates
desc: Contribute to Penpot's libraries & templates! Learn how to share your files and access resources. Try Penpot - It's free!
---
<h1 id="libraries">Libraries & templates</h1>

View File

@@ -1,5 +1,6 @@
---
title: 01· Reporting bugs
desc: Learn how to contribute to Penpot, the open-source design and prototyping platform! Find guidelines for reporting bugs, translations, & code contributions.
---
<h1 id="reporting-bugs">Reporting bugs</h1>

View File

@@ -1,5 +1,6 @@
---
title: 02· Translations
desc: Contribute to Penpot! Learn how to translate Penpot into your language using Weblate. Add new translations, languages, or edit existing ones today.
---
<h1 id="translations">Translations</h1>

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

View File

@@ -1,5 +1,6 @@
---
title: Help center
desc: Find user guides, technical documentation, plugin info, FAQs, and contributing guidelines in Penpot's help center. Join the open-source community!
layout: layouts/home.njk
twitter: "@penpotapp"
image: img/placeholder.png

View File

@@ -1,6 +1,7 @@
---
layout: layouts/plugins.njk
title: 4. API
desc: Create, deploy, and use the Penpot plugin API with our comprehensive documentation. Get started today and expand Penpot's capabilities.
---
# Penpot plugins API

View File

@@ -1,5 +1,7 @@
---
layout: layouts/plugins-no-sidebar.njk
title: Beta changelog
desc: See the Penpot plugin API changelog for version 1.0! Find breaking changes, deprecations, new features, and updated documentation. Try Penpot for free.
---
# Beta changelog

View File

@@ -1,6 +1,7 @@
---
layout: layouts/plugins.njk
title: 2. Create a Plugin
desc: Dive into Penpot plugin development! This guide covers creating plugins from scratch or using templates, libraries, API communication, & deployment.
---
# Create a Plugin

View File

@@ -1,6 +1,7 @@
---
layout: layouts/plugins.njk
title: 3. Deployment
desc: Deploy your free Penpot plugins! Learn about Netlify, Cloudflare, Surge & Penpot submission in this guide. Build and share your creations.
---
# Deployment

View File

@@ -1,6 +1,7 @@
---
layout: layouts/plugins.njk
title: 5. Examples and templates
desc: Learn to create shapes, text, layouts, components, themes, and interactive prototypes. Start building now! See Penpot plugins with examples & templates!
---
# Examples and templates
@@ -117,7 +118,6 @@ Just a friendly reminder that it's important to have the <b>comment permissions<
<a target="_blank" href="https://github.com/penpot/penpot-plugins-samples/tree/main/create-comments">Comments example</a>
## 5.2. Templates
As we mentioned in the <a target="_blank" href="/plugins/create-a-plugin/">Create a plugin</a> section, we've got two great options for you to get started with your plugin.

View File

@@ -1,6 +1,7 @@
---
layout: layouts/plugins.njk
title: 6. FAQ
desc: Find answers to common questions about plugin development, from choosing the right Node version to creating components. See Penpot plugins!
---
# FAQ

View File

@@ -1,6 +1,7 @@
---
layout: layouts/plugins.njk
title: 1. Getting started
desc: Dive into Penpot plugins! Extend Penpot's functionality by automating tasks and adding new features using JavaScript, HTML, & CSS. Get started now!
---
# Getting started

View File

@@ -1,6 +1,7 @@
---
layout: layouts/plugins-home.njk
title: Plugins
desc: "Get started with Penpot Plugins: Installation, development, and deployment. Access API documentation, examples, templates, and FAQs."
eleventyNavigation:
key: Plugins
order: 5

View File

@@ -1,5 +1,6 @@
---
title: 2. Penpot Configuration
desc: Learn about self-hosting, configuration via environment variables, and authentication providers. Try Penpot - It's free! See Penpot's technical guide.
---
# Penpot Configuration

View File

@@ -0,0 +1,359 @@
---
title: 3.07. Abstraction levels
---
# Code organization in abstraction levels
Initially, Penpot data model implementation was organized in a different way.
We are currently in a process of reorganization. The objective is to have data
manipulation code structured in abstraction layers, with well-defined
boundaries, and a hierarchical structure (each level may only use same or
lower levels, but not higher).
![Abstraction levels](/img/abstraction-levels/abstraction-levels.png)
At this moment the namespace structure is already organized as described here,
but there is much code that does not comply with these rules, and needs to be
moved or refactored. We expect to be refactoring existing modules incrementally,
each time we do an important functionality change.
## Basic data
```text
▾ common/
▾ src/app/common/
data.cljc
▾ src/app/data/
macros.cljc
```
A level for generic data structures or operations, that are not specifically part
of the domain model (e.g. trees, strings, maps, iterators, etc.). Also may belong
here some functions in <code>app.common.geom/</code> and <code>app.common.files.helpers.cljc</code>.
We need to create a new directory for this and move there all functions in this
leve.
## Abstract data types
```text
▾ common/
▾ src/app/common/
▾ types/
file.cljc
page.cljc
shape.cljc
color.cljc
component.cljc
tokens_lib.cljc
...
```
Namespaces here represent a single data entity of the domain model, or a
fragment of one, as an [Abstract Data Type](https://www.geeksforgeeks.org/abstract-data-types/).
An ADT is a data component that is defined through a series of properties and
operations, and that abstracts out the details of how it's implemented and what
is the internal structure. This allows to simplify the logic of the client
code, and also to make future changes in the ADT without affecting callers (if
the abstract interface does not change).
Each structure in this module has:
* A **schema spec** that defines the structure of the type and its values:
```clojure
(def schema:fill
[:map {:title "Fill"}
[:fill-color {:optional true} ::ctc/rgb-color]
[:fill-opacity {:optional true} ::sm/safe-number]
...)
(def schema:shape-base-attrs
[:map {:title "ShapeMinimalRecord"}
[:id ::sm/uuid]
[:name :string]
[:type [::sm/one-of shape-types]]
[:selrect ::grc/rect]
[:points schema:points]
...)
(def schema:token-set-attrs
[:map {:title "TokenSet"}
[:name :string]
[:description {:optional true} :string]
[:modified-at {:optional true} ::sm/inst]
[:tokens {:optional true} [:and
[:map-of {:gen/max 5}
:string
schema:token]
[:fn d/ordered-map?]]]])
```
* A **protocol** that define the external interface to be used for this entity.
(NOTE: this is currently only implemented in some subsystems like Design Tokens
and new path handling).
```clojure
(defprotocol ITokenSet
(update-name [_ set-name] "change a token set name while keeping the path")
(add-token [_ token] "add a token at the end of the list")
(update-token [_ token-name f] "update a token in the list")
(delete-token [_ token-name] "delete a token from the list")
(get-token [_ token-name] "return token by token-name")
(get-tokens [_] "return an ordered sequence of all tokens in the set"))
```
* A **custom data type** that implements this protocol. __Functions here are the only
ones allowed to modify the internal structure of the type__.
Clojure allows us two kinds of custom data types:
* [**`deftype`**](https://funcool.github.io/clojurescript-unraveled/#deftype). We'll
use it when we want the internal structure to be completely opaque and
data accessed through protocol functions. Clojure allows access to the
attributes with the <code class="language-clojure">(.-attr)</code>
syntax, but we prefer not to use it.
* [**`defrecord`**](https://funcool.github.io/clojurescript-unraveled/#defrecord).
We'll use it when we want the structure to be exposed as a plain clojure
map, and thus allowing to read attributes with <code
class="language-clojure">(:attr t)</code>, to use <code
class="language-clojure">get</code>, <code
class="language-clojure">keys</code>, <code
class="language-clojure">vals</code>, etc. Note that this also allows
modifying the object with <code class="language-clojure">assoc</code>,
<code class="language-clojure">update</code>, etc. But in general we
prefer to do all modification via protocol methods, because this way
it's easier to track down where the failure is if an invalid structure
is detected in a validation check, and add business logic like "update
<code class="language-clojure">modified-at</code> whenever any other
attribute is changed".
```clojure
(defrecord TokenSet [name description modified-at tokens]
ITokenSet
(add-token [_ token]
(let [token (check-token token)]
(TokenSet. name
description
(dt/now)
(assoc tokens (:name token) token))))
```
* **Additional helper functions** the protocol should be made as small and compact
as possible. If we need functions for business logic or complex queries that
do not need to directly access the internal structure, but can be implemented by
only calling the abstract procotol, they should be created as standalone functions.
At this level, they must be functions that operate only on instances of the given
domain model entity. They must always ensure the internal integrity of the data.
```clojure
(defn sets-tree-seq
"Get tokens sets tree as a flat list"
[token-sets]
...)
> IMPORTANT SUMMARY
> * Code in this level only knows about one domain model entity.
> * All functions ensure the internal integrity of the data.
> * For this, the schema is used, and the functions must check parameters
> and output values as needed.
> * No outside code should get any knowledge of the internal structure, so it
> can be changed in the future without breaking cliente code.
> * All modifications of the data should be done via protocol methods (even in
> <code class="language-clojure">defrecords</code>). This allows a) more
> control of the internal data dependencies, b) easier bug tracking of
> corrupted data, and c) easier refactoring when the structure is modified.
Currently most of Penpot code does not follow those requirements, but it
should do in new code or in any refactor.
## File operations
```text
▾ common/
▾ src/app/common/
▾ files/
helpers.cljc
shapes_helpers.cljc
...
```
Functions that modify a file object (or a part of it) in place, returning the
file object changed. They ensure the referential integrity within the file, or
between a file and its libraries.
**These functions are used when we need to manipulate objects of different
domain entities inside a file.**
```clojure
(defn resolve-component
"Retrieve the referenced component, from the local file or from a library"
[shape file libraries & {:keys [include-deleted?] :or {include-deleted? False}}]
(if (= (:component-file shape) (:id file))
(ctkl/get-component (:data file) (:component-id shape) include-deleted?)
(get-component libraries
(:component-file shape)
(:component-id shape)
:include-deleted? include-deleted?)))
(defn delete-component
"Mark a component as deleted and store the main instance shapes iside it, to
be able to be recovered later."
[file-data component-id skip-undelete? delta]
(let [delta (or delta (gpt/point 0 0))]
(if skip-undelete?
(ctkl/delete-component file-data component-id)
(-> file-data
(ctkl/update-component component-id #(load-component-objects file-data % delta))
(ctkl/mark-component-deleted component-id)))))
```
> This module is still needing an important refactor. Mainly to take functions
> from common.types and move them here.
### File validation and repair
There is a function in <code class="language-clojure">app.common.files.validate</code> that checks a file for
referential and semantic integrity. It's called automatically when file changes
are sent to backend, but may be invoked manually whenever it's needed.
## File changes objects
```text
▾ common/
▾ src/app/common/
▾ files/
changes_builder.cljc
changes.cljc
...
```
This layer is how we adopt the [Event sourcing pattern](https://www.geeksforgeeks.org/event-sourcing-pattern/).
Instead of directly modifying files, we create <code class="language-clojure">changes</code>
objects, that represent one modification, and that can be serialized, stored,
send to backend, logged, etc. Then it can be *materialized* by a **processing
function**, that takes a file and a change, and returns the updated file.
This also allows an important feature: undoing changes.
Processing functions should not contain business logic or algorithms. Just
adapt the change interface to the operations in **File** or **Abstract Data
Types** levels.
There exists a <code class="language-clojure">changes-builder</code> module
with helper functions to conveniently build changes objects, and to
automatically calculate the reverse undo change.
> IMPORTANT RULES
>
> All changes must satisfy two properties:
> * **[Idempotence](https://en.wikipedia.org/wiki/Idempotence)**. The event
> sourcing architecture and multiuser capability may cause that the same
> change may be applied more than once to a file. So changes must not, for
> example, be like *increment counter* but rather *set counter to value x*.
> * **Minimal scope**. To reduce conflicts, changes should only modify the
> relevant part of the domain entity. This way, if a concurrent change on
> the same entity arrives, from another user, and it modifies a different
> part of the data, they may ve processed without overriding.
## Business logic
```text
▾ common/
▾ src/app/common/
▾ logic/
shapes.cljc
libraries.cljc
```
At this level there are functions that implement high level user actions, in an
abstract way (independent of UI). Here may be complex business logic (eg. to
create a component copy we must clone all shapes, assign new ids, relink
parents, change the head structure to be a copy and link each shape in the copy
with the corresponding one in the main).
They don't directly modify files, but generate changes objects, that may be
executed in frontend or sent to backend.
Those functions may also be composed in even higher level actions. For example
a "update shape attr" action may use "unapply token" actions when the attribute
has an applied token.
```clojure
(defn generate-instantiate-component
"Generate changes to create a new instance from a component."
([changes objects file-id component-id position page libraries]
(generate-instantiate-component changes objects file-id component-id position page libraries nil nil nil {}))
([changes objects file-id component-id position page libraries old-id parent-id frame-id
{:keys [force-frame?]
:or {force-frame? false}}]
(let [component (ctf/get-component libraries file-id component-id)
library (get libraries file-id)
parent (when parent-id (get objects parent-id))
[...]
[new-shape new-shapes]
(ctn/make-component-instance page
component
(:data library)
position
(cond-> {}
force-frame?
(assoc :force-frame-id frame-id)))
[...]
changes
(reduce #(pcb/add-object %1 %2 {:ignore-touched true})
changes
(rest new-shapes))]
[new-shape changes])))
```
## Data events
```text
▾ frontend/
▾ src/app/main/data/
▾ dashboard/
▾ viewer/
▾ workspace/
```
This is the intersection of the logic and the presentation in Penpot. Data
events belong to the presentation interface and they manage the global state of
the application. But they may also work on loaded files by using **File** or
**Abstract Data Types** operations to query the data, and by creating and
commiting **changes** via the **Business logic** generate functions.
**IMPORTANT: data events must not contain business logic theirselves**, or
directly manipulate data structures. They only may modify or query the global
state, and delegate all logic to lower level functions.
In current Penpot code, there is some quantity of business logic in data events,
that should be progressively moved elsewhere as we keep refactoring.
```clojure
(defn detach-component
"Remove all references to components in the shape with the given id,
and all its children, at the current page."
[id]
(dm/assert! (uuid? id))
(ptk/reify ::detach-component
ptk/WatchEvent
(watch [it state _]
(let [page-id (:current-page-id state)
file-id (:current-file-id state)
fdata (dsh/lookup-file-data state file-id)
libraries (dsh/lookup-libraries state)
changes (-> (pcb/empty-changes it)
(cll/generate-detach-component id fdata page-id libraries))]
(rx/of (dch/commit-changes changes))))))
```

View File

@@ -1,5 +1,6 @@
---
title: Backend app
desc: Dive into self-hosting, configuration, developer insights (architecture, data model), integration, and troubleshooting. See Penpot's Technical Guide.
---
# Backend app

Some files were not shown because too many files have changed in this diff Show More