diff --git a/CHANGES.md b/CHANGES.md index f34c011a8c..340df7330c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,12 +1,54 @@ # CHANGELOG +## 2.9.0 (Unreleased) + +### :rocket: Epics and highlights + +### :boom: Breaking changes & Deprecations + +### :heart: Community contributions (Thank you!) + +- Clarify message when inviting existing team members to make it more user-friendly and clear which invitations will be sent. [Taiga #11441](https://tree.taiga.io/project/penpot/issue/11441) by [@iprithvitharun](https://github.com/iprithvitharun) +- Update email change confirmation message for clarity and correct grammar. [GitHub #6786](https://github.com/penpot/penpot/issues/6786) by [@iprithvitharun](https://github.com/iprithvitharun) + +### :sparkles: New features & Enhancements + +- Add visual indicator for new comments in the workspace [Taiga #11328](https://tree.taiga.io/project/penpot/issue/11328) +- On components overrides, separate the content of the text from the rest of properties [Taiga #7434](https://tree.taiga.io/project/penpot/us/7434) +- Improve dashboard's sidebar [Taiga #10700](https://tree.taiga.io/project/penpot/us/10700) +- Change "Save color" button to primary button [Taiga #9410](https://tree.taiga.io/project/penpot/issue/9410) +- Support for exif rotated images [GitHub #6767](https://github.com/penpot/penpot/issues/6767) +- Display Blend Mode and Layer Opacity properties in the Inspect tab [Taiga #11283](https://tree.taiga.io/project/penpot/issue/11283) +- Provide CSS `mix-blend-mode` property in code editor when present on shape [Taiga #11282](https://tree.taiga.io/project/penpot/issue/11282) +- Add the option to import tokens in a .zip file. [Taiga #11378](https://tree.taiga.io/project/penpot/us/11378) +- New typography token type - font size token [Taiga #10938](https://tree.taiga.io/project/penpot/us/10938) +- Hide bounding box while editing visual effects [Taiga #11576](https://tree.taiga.io/project/penpot/issue/11576) +- Improved text layer resizing: Allow double-click on text bounding box to set auto-width/auto-height [Taiga #11577](https://tree.taiga.io/project/penpot/issue/11577) +- Improve text layer auto-resize: auto-width switches to auto-height on horizontal resize, and only switches to fixed on vertical resize [Taiga #11578](https://tree.taiga.io/project/penpot/issue/11578) +- Highlight first font in font selector search. Apply only on Enter or click. [Taiga #11579](https://tree.taiga.io/project/penpot/issue/11579) +- Add the ability to show login dialog on profile settings [Github #6871](https://github.com/penpot/penpot/pull/6871) + +### :bug: Bugs fixed + +- Copying font size does not copy the unit [Taiga #11143](https://tree.taiga.io/project/penpot/issue/11143) +- Fix text-decoration line-through that displays a wrong property value [Taiga #11145](https://tree.taiga.io/project/penpot/issue/11145) +- Fix display error message on register form [Taiga #11444](https://tree.taiga.io/project/penpot/issue/11444) +- Fix toggle focus mode did not restore viewport and selection upon exit [GitHub #6280](https://github.com/penpot/penpot/issues/6820) +- Fix problem when creating a layout from an existing layout [Taiga #11554](https://tree.taiga.io/project/penpot/issue/11554) +- Fix title button from Title Case to Capitalize [Taiga #11476](https://tree.taiga.io/project/penpot/issue/11476) +- Fix touchpad swipe leading to navigating back/forth [GitHub #4246](https://github.com/penpot/penpot/issues/4246) +- Keep color data when copying from info tab into CSS [Taiga #11144](https://tree.taiga.io/project/penpot/issue/11144) +- Update HSL values to modern syntax as defined in W3C CSS Color Module Level 4 [Taiga #11144](https://tree.taiga.io/project/penpot/issue/11144) +- Fix main component receives focus and is selected when using 'Show Main Component' [Taiga #11402](https://tree.taiga.io/project/penpot/issue/11402) +- Fix duplicating pages with mainInstance shapes nested inside groups [Taiga #10774](https://tree.taiga.io/project/penpot/issue/10774) +- Fix ESC key not closing Add/Manage Libraries modal [Taiga #11523](https://tree.taiga.io/project/penpot/issue/11523) + ## 2.8.1 (Unreleased) ### :bug: Bugs fixed - Fix unexpected exception on processing old texts [Github #6889](https://github.com/penpot/penpot/pull/6889) - ## 2.8.0 ### :rocket: Epics and highlights @@ -27,6 +69,7 @@ in future versions. Therefore, **migration from Redis to ValKey is recommended f on-premises instances** that want to keep up to date. ### :heart: Community contributions (Thank you!) + - Add Serbian language [GitHub #5002](https://github.com/penpot/penpot/issues/5002) by [crnobog69](https://github.com/crnobog69) ### :sparkles: New features & Enhancements @@ -82,7 +125,6 @@ on-premises instances** that want to keep up to date. - Fix copy in error message [GitHub #6615](https://github.com/penpot/penpot/pull/6615) - Fix url on invitation link [Taiga #11284](https://tree.taiga.io/project/penpot/issue/11284) - ## 2.7.1 ### :bug: Bugs fixed @@ -90,7 +132,6 @@ on-premises instances** that want to keep up to date. - 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 @@ -222,7 +263,6 @@ on-premises instances** that want to keep up to date. - Add character limitation to asset inputs [Taiga #10669](https://tree.taiga.io/project/penpot/issue/10669) - Fix Storybook link 'list of all available icons' wrong path [Taiga #10705](https://tree.taiga.io/project/penpot/issue/10705) - ## 2.5.4 ### :heart: Community contributions (Thank you!) @@ -267,7 +307,7 @@ on-premises instances** that want to keep up to date. ### :boom: Breaking changes & Deprecations -Although this is not a breaking change, we believe it’s important to highlight it in this +Although this is not a breaking change, we believe it's important to highlight it in this section: This release includes a fix for an internal bug in Penpot that caused incorrect handling @@ -275,9 +315,9 @@ of media assets (e.g., fill images). The issue has been resolved since version 2 no new incorrect references will be generated. However, existing files may still contain incorrect references. -To address this, we’ve provided a script to correct these references in existing files. +To address this, we've provided a script to correct these references in existing files. -While having incorrect references generally doesn’t result in visible issues, there are +While having incorrect references generally doesn't result in visible issues, there are rare cases where it can cause problems. For example, if a component library (containing images) is deleted, and that library is being used in other files, running the FileGC task (responsible for freeing up space and performing logical deletions) could leave those @@ -352,7 +392,6 @@ is a number of cores) - Fix missing methods reference on API Docs - Fix memory usage issue on file-gc asynchronous task (related to snapshots feature) - ## 2.4.1 ### :bug: Bugs fixed @@ -360,7 +399,6 @@ is a number of cores) - Fix error when importing files with touched components [Taiga #9625](https://tree.taiga.io/project/penpot/issue/9625) - Fix problem when changing color libraries [Plugins #184](https://github.com/penpot/penpot-plugins/issues/184) - ## 2.4.0 ### :rocket: Epics and highlights @@ -414,7 +452,6 @@ is a number of cores) - Add initial documentation for Kubernetes - ## 2.3.1 ### :bug: Bugs fixed @@ -422,7 +459,6 @@ is a number of cores) - Fix unexpected issue on interaction between plugins sandbox and internal impl of promise - ## 2.3.0 ### :rocket: Epics and highlights @@ -448,7 +484,6 @@ is a number of cores) You can enable it with the `enable-feature-text-editor-v2` configuration flag. - ### :bug: Bugs fixed - Fix problem with constraints buttons [Taiga #8465](https://tree.taiga.io/project/penpot/issue/8465) @@ -488,8 +523,8 @@ is a number of cores) ### :boom: Breaking changes & Deprecations - Removed "merge assets" option when exporting ".svg + .json" files. After the components changes the option wasn't -working properly and we're planning to change the format soon. We think it's better to deprecate the option for the -time being. + working properly and we're planning to change the format soon. We think it's better to deprecate the option for the + time being. ### :heart: Community contributions (Thank you!) @@ -505,7 +540,7 @@ time being. freeing up space in the database. It can be enabled with the `enable-enable-tiered-file-data-storage` flag. - *(On-Premise feature, EXPERIMENTAL).* + _(On-Premise feature, EXPERIMENTAL)._ - **JSON Interoperability for HTTP API** [Taiga #8372](https://tree.taiga.io/project/penpot/us/8372) @@ -548,7 +583,7 @@ time being. - **Design System** - We implemented and subbed in new components from our Design System: `loader*` ([Taiga #8355](https://tree.taiga.io/project/penpot/task/8355)) and `tab-switcher*` ([Taiga #8518](https://tree.taiga.io/project/penpot/task/8518)). + We implemented and subbed in new components from our Design System: `loader*` ([Taiga #8355](https://tree.taiga.io/project/penpot/task/8355)) and `tab-switcher*` ([Taiga #8518](https://tree.taiga.io/project/penpot/task/8518)). - **Storybook** [Taiga #6329](https://tree.taiga.io/project/penpot/us/6329) @@ -603,11 +638,11 @@ time being. ### :sparkles: New features -- Consolidate templates new order and naming [Taiga #8392](https://tree.taiga.io/project/penpot/task/8392) +- Consolidate templates new order and naming [Taiga #8392](https://tree.taiga.io/project/penpot/task/8392) ### :bug: Bugs fixed -- Fix the “search” label in translations [Taiga #8402](https://tree.taiga.io/project/penpot/issue/8402) +- Fix the "search" label in translations [Taiga #8402](https://tree.taiga.io/project/penpot/issue/8402) - Fix pencil loader [Taiga #8348](https://tree.taiga.io/project/penpot/issue/8348) - Fix several issues on the OIDC. - Fix regression on the `email-verification` flag [Taiga #8398](https://tree.taiga.io/project/penpot/issue/8398) @@ -687,22 +722,21 @@ time being. - Fix color palette sorting [Taiga #7458](https://tree.taiga.io/project/penpot/issue/7458) - Fix style scoping problem with imported SVG [Taiga #7671](https://tree.taiga.io/project/penpot/issue/7671) - ## 2.0.1 ### :bug: Bugs fixed - Fix different issues related to components v2 migrations including [Github #4443](https://github.com/penpot/penpot/issues/4443) - ## 2.0.0 - I Just Can't Get Enough ### :rocket: Epics and highlights + - Grid CSS layout [Taiga #4915](https://tree.taiga.io/project/penpot/epic/4915) - UI redesign [Taiga #4958](https://tree.taiga.io/project/penpot/epic/4958) - New components System [Taiga #2662](https://tree.taiga.io/project/penpot/epic/2662) - Swap components [Taiga #1331](https://tree.taiga.io/project/penpot/us/1331) -- Images as fill [Taiga #2983](https://tree.taiga.io/project/penpot/us/2983) +- Images as fill [Taiga #2983](https://tree.taiga.io/project/penpot/us/2983) - HTML code generation [Taiga #5277](https://tree.taiga.io/project/penpot/us/5277) - Light and dark themes [Taiga #2287](https://tree.taiga.io/project/penpot/us/2287) @@ -711,9 +745,9 @@ time being. - New strokes default to inside border [Taiga #6847](https://tree.taiga.io/project/penpot/issue/6847) - Change default z ordering on layers in flex layout. The previous behavior was inconsistent with how HTML works and we changed it to be more consistent. Previous layers that overlapped could be hidden, the fastest way to fix this is changing the z-index property but a better way is to change the order of your layers. - ### :heart: Community contributions (Thank you!) -- New Hausa, Yoruba and Igbo translations and update translation files (by All For Tech Empowerment Foundation) [Taiga #6950](https://tree.taiga.io/project/penpot/us/6950), [Taiga #6534](https://tree.taiga.io/project/penpot/us/6534) + +- New Hausa, Yoruba and Igbo translations and update translation files (by All For Tech Empowerment Foundation) [Taiga #6950](https://tree.taiga.io/project/penpot/us/6950), [Taiga #6534](https://tree.taiga.io/project/penpot/us/6534) - Hide bounding-box when editing shape (by @VasilevsVV) [#3930](https://github.com/penpot/penpot/pull/3930) - CTRL + "+" to zoom into canvas instead of browser (by @audriu) [#3848](https://github.com/penpot/penpot/pull/3848) - Add dev deps.edn in the project root (by @PEZ) [#3794](https://github.com/penpot/penpot/pull/3794) @@ -722,6 +756,7 @@ time being. - Typo (by StephanEggermont) [#157](https://github.com/penpot/penpot-docs/pull/157) ### :sparkles: New features + - Send comments with Ctrl+Enter / Cmd + Enter [Taiga #6085](https://tree.taiga.io/project/penpot/issue/6085) - Select through stroke only rectangle [Taiga #5484](https://tree.taiga.io/project/penpot/issue/5484) - Stroke default position [Taiga #6847](https://tree.taiga.io/project/penpot/issue/6847) @@ -789,6 +824,7 @@ time being. - [REDESIGN] Onboarding slides [Taiga #6678](https://tree.taiga.io/project/penpot/us/6678) ### :bug: Bugs fixed + - Fix pixelated thumbnails [Github #3681](https://github.com/penpot/penpot/issues/3681), [Github #3661](https://github.com/penpot/penpot/issues/3661) - Fix problem with not applying colors to boards [Github #3941](https://github.com/penpot/penpot/issues/3941) - Fix problem with path editor undoing changes [Github #3998](https://github.com/penpot/penpot/issues/3998) @@ -797,7 +833,7 @@ time being. - Selecting from Color Palette does not work for board when there is no existing fill [Taiga #6464](https://tree.taiga.io/project/penpot/issue/6464) - Color thumbnails are consistently rounded in the inspect code mode [Taiga #5886](https://tree.taiga.io/project/penpot/issue/5886) - Adding vector path points before first point of existing open path not working [Taiga #6593](https://tree.taiga.io/project/penpot/issue/6593) -- Some image formats include the extension when importing [Taiga #5485](https://tree.taiga.io/project/penpot/issue/5485) +- Some image formats include the extension when importing [Taiga #5485](https://tree.taiga.io/project/penpot/issue/5485) - Gradient color tool doesn't work properly with flipped items [Taiga #6485](https://tree.taiga.io/project/penpot/issue/6485) - [TEXT] Align options are not shown when several text are selected [Taiga #5948](https://tree.taiga.io/project/penpot/issue/5948) - [VIEW MODE] Comments not working properly on multiple pages [Taiga #6281](https://tree.taiga.io/project/penpot/issue/6281) @@ -841,7 +877,7 @@ time being. ### :sparkles: New features -- Improve selected colors [Taiga #5805]( https://tree.taiga.io/project/penpot/us/5805) +- Improve selected colors [Taiga #5805](https://tree.taiga.io/project/penpot/us/5805) ### :bug: Bugs fixed @@ -876,7 +912,6 @@ time being. - Fix deleted pages comments shown in right sidebar [Taiga #5648](https://tree.taiga.io/project/penpot/us/5648) - Fix tooltip on toggle visibility and toggle lock buttons [Taiga #5141](https://tree.taiga.io/project/penpot/issue/5141) - ## 1.19.1 ### :bug: Bugs fixed @@ -990,7 +1025,6 @@ time being. - Update google fonts catalog (at 2023/07/06) [Taiga #5592](https://tree.taiga.io/project/penpot/issue/5592) - ### :heart: Community contributions by (Thank you!) - Update Typography palette order (by @akshay-gupta7) [Github #3156](https://github.com/penpot/penpot/pull/3156) @@ -1144,12 +1178,14 @@ time being. - Fix problem with opacity in imported SVG's [Taiga #4923](https://tree.taiga.io/project/penpot/issue/4923) ### :heart: Community contributions by (Thank you!) + - To @ondrejkonec: for contributing to the code with: - Refactor CSS variables [Github #2948](https://github.com/penpot/penpot/pull/2948) ## 1.17.3 ### :bug: Bugs fixed + - Fix copy and paste very nested inside itself [Taiga #4848](https://tree.taiga.io/project/penpot/issue/4848) - Fix custom fonts not rendered correctly [Taiga #4874](https://tree.taiga.io/project/penpot/issue/4874) - Fix problem with shadows and blur on multiple selection @@ -1182,6 +1218,7 @@ time being. ## 1.17.1 ### :bug: Bugs fixed + - Fix components groups items show the component name in list mode [Taiga #4770](https://tree.taiga.io/project/penpot/issue/4770) - Fix typing CMD+Z on MacOS turns the cursor into a Zoom cursor [Taiga #4778](https://tree.taiga.io/project/penpot/issue/4778) - Fix white space on small screens [Taiga #4774](https://tree.taiga.io/project/penpot/issue/4774) @@ -1296,7 +1333,7 @@ time being. ### :boom: Breaking changes & Deprecations -- Removed the support for v2 internal file data blob format. This +- Removed the support for v2 internal file data blob format. This version has never been documented nor set as default value so technically this is not a breaking change because we are removing a "private API". @@ -1401,7 +1438,6 @@ time being. - Fix when ungrouping, the items previously grouped should ALWAYS remain selected [Taiga #4064](https://tree.taiga.io/project/penpot/issue/4064) - Change shortcut for "Clear undo" [#2219](https://github.com/penpot/penpot/issues/2219) - ## 1.15.2-beta ### :bug: Bugs fixed @@ -1485,6 +1521,7 @@ time being. - Fix bringing complete file data when launching the export dialog [Taiga #4006](https://tree.taiga.io/project/penpot/issue/4006) ### :arrow_up: Deps updates + ### :heart: Community contributions by (Thank you!) ## 1.14.2-beta @@ -1525,10 +1562,10 @@ time being. - Prototype connection should be under the rules [Taiga #3384](https://tree.taiga.io/project/penpot/issue/3384) - Fix problem with empty text boxes events [Taiga #3627](https://tree.taiga.io/project/penpot/issue/3627) - ## 1.13.5-beta ### :bug: Bugs fixed + - Fix orientation artboard preset not working with differently sized artboards [Taiga #3548](https://tree.taiga.io/project/penpot/issue/3548) - Fix background on export arboards [Taiga #1991](https://tree.taiga.io/project/penpot/issue/1991) @@ -1672,6 +1709,7 @@ time being. - Fix problem when resizing a group with texts with auto-width/height [#3171](https://tree.taiga.io/project/penpot/issue/3171) ### :arrow_up: Deps updates + ### :heart: Community contributions by (Thank you!) ## 1.12.4-beta @@ -1689,7 +1727,7 @@ time being. ### :bug: Bugs fixed - Fix issue with shift+select to deselect shapes [Taiga #3154](https://tree.taiga.io/project/penpot/issue/3154) -- Fix issue with drag-select shapes [Taiga #3165](https://tree.taiga.io/project/penpot/issue/3165) +- Fix issue with drag-select shapes [Taiga #3165](https://tree.taiga.io/project/penpot/issue/3165) - Fix issue on password persistence after registration process on private instances ## 1.12.2-beta @@ -1707,7 +1745,6 @@ time being. - Fix length of names in sidebar [Taiga #2962](https://tree.taiga.io/project/penpot/issue/2962) - Fix issues on loki integration - ## 1.12.0-beta ### :boom: Breaking changes diff --git a/backend/resources/app/email/change-email/en.html b/backend/resources/app/email/change-email/en.html index 7a5f1f1189..fa021f55ee 100644 --- a/backend/resources/app/email/change-email/en.html +++ b/backend/resources/app/email/change-email/en.html @@ -193,7 +193,7 @@
- Click to the link below to confirm the change:
+ Click the link below to confirm the change. @@ -217,8 +217,7 @@
- If you received this email by mistake, please consider changing your password for security - reasons.
+ If you did not request this change, consider changing your password for security reasons. diff --git a/backend/resources/app/email/change-email/en.txt b/backend/resources/app/email/change-email/en.txt index 09d6e84a56..eff98baf6f 100644 --- a/backend/resources/app/email/change-email/en.txt +++ b/backend/resources/app/email/change-email/en.txt @@ -2,12 +2,11 @@ Hello {{name|abbreviate:25}}! We received a request to change your current email to {{ pending-email }}. -Click to the link below to confirm the change: +Click the link below to confirm the change. {{ public-uri }}/#/auth/verify-token?token={{token}} -If you received this email by mistake, please consider changing your password -for security reasons. +If you did not request this change, consider changing your password for security reasons. Enjoy! The Penpot team. diff --git a/backend/scripts/manage.py b/backend/scripts/manage.py index f731319c9a..88b5d4f43a 100755 --- a/backend/scripts/manage.py +++ b/backend/scripts/manage.py @@ -71,19 +71,27 @@ def run_cmd(params): print("EXC:", str(cause)) sys.exit(-2) -def create_profile(fullname, email, password): +def create_profile(fullname, email, password, skip_tutorial=False, skip_walkthrough=False): + props = {} + if skip_tutorial: + props["viewed-tutorial?"] = True + if skip_walkthrough: + props["viewed-walkthrough?"] = True + params = { "cmd": "create-profile", "params": { "fullname": fullname, "email": email, - "password": password + "password": password, + **props } } res = run_cmd(params) print(f"Created: {res['email']} / {res['id']}") + def update_profile(email, fullname, password, is_active): params = { "cmd": "update-profile", @@ -170,6 +178,8 @@ parser.add_argument("-n", "--fullname", help="fullname", action="store") parser.add_argument("-e", "--email", help="email", action="store") parser.add_argument("-p", "--password", help="password", action="store") parser.add_argument("-c", "--connect", help="connect to PREPL", action="store", default="tcp://localhost:6063") +parser.add_argument("--skip-tutorial", help="mark tutorial as viewed", action="store_true") +parser.add_argument("--skip-walkthrough", help="mark walkthrough as viewed", action="store_true") args = parser.parse_args() diff --git a/backend/src/app/media.clj b/backend/src/app/media.clj index 710275a542..51649db3d5 100644 --- a/backend/src/app/media.clj +++ b/backend/src/app/media.clj @@ -10,6 +10,7 @@ [app.common.data :as d] [app.common.data.macros :as dm] [app.common.exceptions :as ex] + [app.common.logging :as l] [app.common.media :as cm] [app.common.schema :as sm] [app.common.schema.openapi :as-alias oapi] @@ -21,6 +22,7 @@ [buddy.core.bytes :as bb] [buddy.core.codecs :as bc] [clojure.java.shell :as sh] + [clojure.string] [clojure.xml :as xml] [cuerdas.core :as str] [datoteka.fs :as fs] @@ -215,6 +217,23 @@ {:width (int width) :height (int height)})))])) +(defn- get-dimensions-with-orientation [^String path] + ;; Image magick doesn't give info about exif rotation so we use the identify command + ;; If we are processing an animated gif we use the first frame with -scene 0 + (let [dim-result (sh/sh "identify" "-format" "%w %h\n" path) + orient-result (sh/sh "identify" "-format" "%[EXIF:Orientation]\n" path)] + (if (and (= 0 (:exit dim-result)) + (= 0 (:exit orient-result))) + (let [[w h] (-> (:out dim-result) + str/trim + (clojure.string/split #"\s+") + (->> (mapv #(Integer/parseInt %)))) + orientation (-> orient-result :out str/trim)] + (case orientation + ("6" "8") {:width h :height w} ; Rotated 90 or 270 degrees + {:width w :height h})) ; Normal or unknown orientation + nil))) + (defmethod process :info [{:keys [input] :as params}] (let [{:keys [path mtype] :as input} (check-input input)] @@ -234,13 +253,17 @@ :code :media-type-mismatch :hint (str "Seems like you are uploading a file whose content does not match the extension." "Expected: " mtype ". Got: " mtype'))) - ;; For an animated GIF, getImageWidth/Height returns the delta size of one frame (if no frame given - ;; it returns size of the last one), whereas getPageWidth/Height always return the full size of - ;; any frame. - (assoc input - :width (.getPageWidth instance) - :height (.getPageHeight instance) - :ts (dt/now)))))) + (let [{:keys [width height]} + (or (get-dimensions-with-orientation (str path)) + (do + (l/warn "Failed to read image dimensions with orientation; falling back to im4java" + {:path path}) + {:width (.getPageWidth instance) + :height (.getPageHeight instance)}))] + (assoc input + :width width + :height height + :ts (dt/now))))))) (defmethod process-error org.im4java.core.InfoException [error] diff --git a/backend/src/app/rpc/commands/teams.clj b/backend/src/app/rpc/commands/teams.clj index b0b21cc2fe..bb23c6997c 100644 --- a/backend/src/app/rpc/commands/teams.clj +++ b/backend/src/app/rpc/commands/teams.clj @@ -140,7 +140,7 @@ WHEN 'professional' THEN 'active' ELSE COALESCE(p.props->'~:subscription'->>'~:status', 'incomplete') END, - '~:seats', p.props->'~:quantity' + '~:seats', p.props->'~:subscription'->'~:quantity' ) AS subscription FROM team_profile_rel AS tp JOIN team AS t ON (t.id = tp.team_id) @@ -193,7 +193,8 @@ (def ^:private sql:get-owned-teams "SELECT t.id, t.name, - (SELECT count(*) FROM team_profile_rel WHERE team_id=t.id) AS total_members + (SELECT count(*) FROM team_profile_rel WHERE team_id=t.id) AS total_members, + (SELECT count(*) FROM team_profile_rel WHERE team_id=t.id AND can_edit=true) AS total_editors FROM team AS t JOIN team_profile_rel AS tpr ON (tpr.team_id = t.id) WHERE t.is_default IS false diff --git a/backend/test/backend_tests/rpc_team_test.clj b/backend/test/backend_tests/rpc_team_test.clj index ddb2e33bbc..60bdb62d6d 100644 --- a/backend/test/backend_tests/rpc_team_test.clj +++ b/backend/test/backend_tests/rpc_team_test.clj @@ -460,11 +460,14 @@ ::rpc/profile-id (:id profile1)} out (th/command! params)] + ;; (th/print-result! out) (t/is (th/success? out)) - (let [result (:result out)] + (let [[item1 :as result] (:result out)] (t/is (= 1 (count result))) - (t/is (= (:id team1) (-> result first :id))) - (t/is (not= (:default-team-id profile1) (-> result first :id)))))) + (t/is (= (:id team1) (:id item1))) + (t/is (= 1 (:total-members item1))) + (t/is (= 1 (:total-editors item1))) + (t/is (not= (:default-team-id profile1) (:id item1)))))) (t/deftest team-deletion-1 diff --git a/common/src/app/common/colors.cljc b/common/src/app/common/colors.cljc index 7f4d3adb67..e16acf94a3 100644 --- a/common/src/app/common/colors.cljc +++ b/common/src/app/common/colors.cljc @@ -349,7 +349,7 @@ rounded-s (d/format-number (* 100 s) precision) rounded-l (d/format-number (* 100 l) precision) rounded-a (d/format-number a precision)] - (str/concat "" rounded-h ", " rounded-s "%, " rounded-l "%, " rounded-a))) + (str/concat "" rounded-h " " rounded-s "% " rounded-l "% / " rounded-a))) (defn format-rgba [[r g b a]] diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index c5d1812291..d9965ce556 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -241,7 +241,7 @@ [:shapes ::sm/any] [:index {:optional true} [:maybe :int]] [:after-shape {:optional true} ::sm/any] - [:component-swap {:optional true} :boolean]]] + [:allow-altering-copies {:optional true} :boolean]]] [:reorder-children [:map {:title "ReorderChildrenChange"} @@ -418,7 +418,7 @@ [:type [:= :set-token-set]] [:set-name :string] [:group? :boolean] - [:token-set [:maybe ctob/schema:token-set-attrs]]]] + [:token-set [:maybe [:fn ctob/token-set?]]]]] [:set-token [:map {:title "SetTokenChange"} @@ -761,7 +761,7 @@ (d/update-in-when data [:components component-id :objects] reg-objects)))) (defmethod process-change :mov-objects - [data {:keys [parent-id shapes index page-id component-id ignore-touched after-shape component-swap syncing]}] + [data {:keys [parent-id shapes index page-id component-id ignore-touched after-shape allow-altering-copies syncing]}] (letfn [(calculate-invalid-targets [objects shape-id] (let [reduce-fn #(into %1 (calculate-invalid-targets objects %2))] (->> (get-in objects [shape-id :shapes]) @@ -776,7 +776,7 @@ (and shape (not (invalid-targets parent-id)) (not (cfh/components-nesting-loop? objects shape-id parent-id)) - (or component-swap ;; On a component swap it's allowed to change the structure of a copy + (or allow-altering-copies ;; In some cases (like a component swap) it's allowed to change the structure of a copy syncing ;; If we are syncing the changes of a main component, it's allowed to change the structure of a copy (and (not (ctk/in-component-copy? (get objects (:parent-id shape)))) ;; We don't want to change the structure of component copies @@ -1027,11 +1027,10 @@ (ctob/delete-set lib' set-name)) (not (ctob/get-set lib' set-name)) - (ctob/add-set lib' (ctob/make-token-set token-set)) + (ctob/add-set lib' token-set) :else - (ctob/update-set lib' set-name (fn [prev-token-set] - (ctob/make-token-set (merge prev-token-set token-set))))))))) + (ctob/update-set lib' set-name (fn [_] token-set))))))) (defmethod process-change :set-token-theme [data {:keys [group theme-name theme]}] diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index 9dd4da715d..35f95a78fe 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -464,8 +464,8 @@ (some? index) (assoc :index index) - (:component-swap options) - (assoc :component-swap true) + (:allow-altering-copies options) + (assoc :allow-altering-copies true) (:ignore-touched options) (assoc :ignore-touched true)) @@ -473,12 +473,14 @@ (fn [undo-changes shape] (let [prev-sibling (cfh/get-prev-sibling objects (:id shape))] (conj undo-changes - {:type :mov-objects - :page-id (::page-id (meta changes)) - :parent-id (:parent-id shape) - :shapes [(:id shape)] - :after-shape prev-sibling - :index 0}))) ; index is used in case there is no after-shape (moving bottom shapes) + (cond-> {:type :mov-objects + :page-id (::page-id (meta changes)) + :parent-id (:parent-id shape) + :shapes [(:id shape)] + :after-shape prev-sibling + :index 0} ; index is used in case there is no after-shape (moving bottom shapes) + (:allow-altering-copies options) + (assoc :allow-altering-copies true))))) restore-touched-change {:type :mod-obj @@ -916,7 +918,7 @@ (-> changes (update :redo-changes conj {:type :set-token-set :set-name name - :token-set (assoc prev-token-set :name new-name) + :token-set (ctob/rename prev-token-set new-name) :group? false}) (update :undo-changes conj {:type :set-token-set :set-name new-name @@ -937,11 +939,11 @@ :group? group?}) (update :undo-changes conj (if prev-token-set {:type :set-token-set - :set-name (or - ;; Undo of edit - (:name token-set) - ;; Undo of delete - set-name) + :set-name (if token-set + ;; Undo of edit + (ctob/get-name token-set) + ;; Undo of delete + set-name) :token-set prev-token-set :group? group?} ;; Undo of create diff --git a/common/src/app/common/files/helpers.cljc b/common/src/app/common/files/helpers.cljc index 360d8428d3..7f5c60f12f 100644 --- a/common/src/app/common/files/helpers.cljc +++ b/common/src/app/common/files/helpers.cljc @@ -152,12 +152,22 @@ (dm/get-prop shape :type)))) (defn get-children-ids - [objects id] - (letfn [(get-children-ids-rec [id processed] - (when (not (contains? processed id)) - (when-let [shapes (-> (get objects id) :shapes (some-> vec))] - (into shapes (mapcat #(get-children-ids-rec % (conj processed id))) shapes))))] - (get-children-ids-rec id #{}))) + "Returns the ids of all the descendants of the shape identified + by the id. Optionally, you can pass an ignore function to indicate + when to ignore a descendant (and all its descendants)" + ([objects id] + (get-children-ids objects id {})) + ([objects id {:keys [ignore-children-fn] + ;;ignore-children-fn should receive a shape and return a boolean + :or {ignore-children-fn (constantly false)}}] + (letfn [(get-children-ids-rec [id processed] + (when-not (contains? processed id) + (when-let [shapes (as-> (get objects id) $ + (:shapes $) + (remove ignore-children-fn $) + (some-> $ vec))] + (into shapes (mapcat #(get-children-ids-rec % (conj processed id))) shapes))))] + (get-children-ids-rec id #{})))) (defn get-children-ids-with-self [objects id] diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 3cb3e8daf2..5973451a94 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -32,6 +32,7 @@ [app.common.types.shape :as cts] [app.common.types.shape.interactions :as ctsi] [app.common.types.shape.shadow :as ctss] + [app.common.types.text :as cttx] [app.common.uuid :as uuid] [clojure.set :as set] [cuerdas.core :as str])) @@ -1527,6 +1528,31 @@ colors colors)))) +(defmethod migrate-data "0009-add-partial-text-touched-flags" + [data _] + (letfn [(update-object [page object] + (if (and (cfh/text-shape? object) + (ctk/in-component-copy? object)) + (let [file {:id (:id data) :data data} + libs (when (:libs data) + (deref (:libs data))) + ref-shape (ctf/find-ref-shape file page libs object + {:include-deleted? true :with-context? true}) + partial-touched (when ref-shape + (cttx/get-diff-type (:content object) (:content ref-shape)))] + (if (seq partial-touched) + (update object :touched (fn [touched] + (reduce #(ctk/set-touched-group %1 %2) + touched + partial-touched))) + object)) + object)) + + (update-page [page] + (d/update-when page :objects d/update-vals (partial update-object page)))] + + (update data :pages-index d/update-vals update-page))) + (def available-migrations (into (d/ordered-set) ["legacy-2" @@ -1591,4 +1617,5 @@ "0006-fix-old-texts-fills" "0007-clear-invalid-strokes-and-fills-v2" "0008-fix-library-colors-v4" - "0009-clean-library-colors"])) + "0009-clean-library-colors" + "0009-add-partial-text-touched-flags"])) diff --git a/common/src/app/common/files/repair.cljc b/common/src/app/common/files/repair.cljc index bf51851003..1d638586ee 100644 --- a/common/src/app/common/files/repair.cljc +++ b/common/src/app/common/files/repair.cljc @@ -96,7 +96,7 @@ (log/dbg :hint "repairing shape :invalid-parent" :id (:id shape) :name (:name shape) :page-id page-id) (-> (pcb/empty-changes nil page-id) (pcb/with-file-data file-data) - (pcb/change-parent (:parent-id args) [shape] nil {:component-swap true}))) + (pcb/change-parent (:parent-id args) [shape] nil {:allow-altering-copies true}))) (defmethod repair-error :frame-not-found [_ {:keys [shape page-id] :as error} file-data _] @@ -387,7 +387,7 @@ (-> (pcb/empty-changes nil page-id) (pcb/with-file-data file-data) (pcb/update-shapes [(:id shape)] repair-shape) - (pcb/change-parent uuid/zero [shape] nil {:component-swap true})))) + (pcb/change-parent uuid/zero [shape] nil {:allow-altering-copies true})))) (defmethod repair-error :root-copy-not-allowed [_ {:keys [shape page-id] :as error} file-data _] @@ -602,11 +602,6 @@ (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)) diff --git a/common/src/app/common/files/validate.cljc b/common/src/app/common/files/validate.cljc index 2659f65336..5bdb410669 100644 --- a/common/src/app/common/files/validate.cljc +++ b/common/src/app/common/files/validate.cljc @@ -68,7 +68,6 @@ :variant-bad-name :variant-bad-variant-name :variant-component-bad-name - :variant-no-properties :variant-component-bad-id}) (def ^:private schema:error @@ -589,11 +588,7 @@ (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)))) + main-component file component-page)))) (defn- check-component "Validate semantic coherence of a component. Report all errors found." diff --git a/common/src/app/common/flags.cljc b/common/src/app/common/flags.cljc index 804cac400b..80f96fd8aa 100644 --- a/common/src/app/common/flags.cljc +++ b/common/src/app/common/flags.cljc @@ -117,6 +117,7 @@ ;; Only for developtment. :tiered-file-data-storage :token-units + :token-typography-types :transit-readable-response :user-feedback ;; TODO: remove this flag. @@ -149,7 +150,8 @@ :enable-onboarding :enable-dashboard-templates-section :enable-google-fonts-provider - :enable-component-thumbnails]) + :enable-component-thumbnails + :enable-render-wasm-dpr]) (defn parse [& flags] diff --git a/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc b/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc index 424dcbb34f..1ec6bffd5a 100644 --- a/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc +++ b/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc @@ -467,15 +467,15 @@ row-tracks (set-flex-multi-span parent row-tracks children-map shape-cells bounds objects :row) ;; Once auto sizes have been calculated we get calculate the `fr` unit with the remainining size and adjust the size - free-column-space (max 0 (- bound-width (+ column-total-size-nofr column-total-gap))) - free-row-space (max 0 (- bound-height (+ row-total-size-nofr row-total-gap))) + fr-column-space (max 0 (- bound-width (+ column-total-size-nofr column-total-gap))) + fr-row-space (max 0 (- bound-height (+ row-total-size-nofr row-total-gap))) ;; Get the minimum values for fr's min-column-fr (min-fr-value column-tracks) min-row-fr (min-fr-value row-tracks) - column-fr (if auto-width? min-column-fr (mth/finite (/ free-column-space column-frs) 0)) - row-fr (if auto-height? min-row-fr (mth/finite (/ free-row-space row-frs) 0)) + column-fr (if auto-width? min-column-fr (mth/finite (/ fr-column-space column-frs) 0)) + row-fr (if auto-height? min-row-fr (mth/finite (/ fr-row-space row-frs) 0)) column-tracks (set-fr-value column-tracks column-fr auto-width?) row-tracks (set-fr-value row-tracks row-fr auto-height?) @@ -484,13 +484,13 @@ column-total-size (tracks-total-size column-tracks) row-total-size (tracks-total-size row-tracks) - free-column-space (max 0 (if auto-width? 0 (- bound-width (+ column-total-size column-total-gap)))) - free-row-space (max 0 (if auto-height? 0 (- bound-height (+ row-total-size row-total-gap)))) + auto-column-space (max 0 (if auto-width? 0 (- bound-width (+ column-total-size column-total-gap)))) + auto-row-space (max 0 (if auto-height? 0 (- bound-height (+ row-total-size row-total-gap)))) column-autos (tracks-total-autos column-tracks) row-autos (tracks-total-autos row-tracks) - column-add-auto (/ free-column-space column-autos) - row-add-auto (/ free-row-space row-autos) + column-add-auto (/ auto-column-space column-autos) + row-add-auto (/ auto-row-space row-autos) column-tracks (cond-> column-tracks (= :stretch (:layout-justify-content parent)) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 197f8c8a29..d928268d6e 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -29,6 +29,7 @@ [app.common.types.shape-tree :as ctst] [app.common.types.shape.interactions :as ctsi] [app.common.types.shape.layout :as ctl] + [app.common.types.text :as cttx] [app.common.types.token :as cto] [app.common.types.typography :as cty] [app.common.types.variant :as ctv] @@ -1664,28 +1665,33 @@ :shapes all-parents})])))) +(defn- text-partial-change-value + [touched-content untouched-content touched] + (cond + (touched :text-content-structure-same-attrs) + (if (touched :text-content-attribute) + ;; Both structure and attrs has been touched, keep the + ;; touched-content + touched-content + ;; Keep the touched-content structure and texts, update + ;; its attrs to make them like the untouched-content + (cttx/copy-attrs-keys touched-content (cttx/get-first-paragraph-text-attrs untouched-content))) + + (touched :text-content-text) + ;; Keep the texts touched in touched-content, so copy the + ;; texts from touched-content into untouched-content + (cttx/copy-text-keys touched-content untouched-content) + + (touched :text-content-attribute) + ;; Keep the attrs touched in touched-content, so copy the + ;; texts from untouched-content into touched-content + (cttx/copy-text-keys untouched-content touched-content))) + (defn- add-update-attr-operations - [attr dest-shape origin-shape roperations uoperations touched] - (let [orig-value (get origin-shape attr) - dest-value (get dest-shape attr) - ;; position-data is a special case because can be affected by :geometry-group and :content-group - ;; so, if the position-data changes but the geometry is touched we need to reset the position-data - ;; so it's calculated again - reset-pos-data? - (and (cfh/text-shape? origin-shape) - (= attr :position-data) - (not= orig-value dest-value) - (touched :geometry-group)) - - val (cond - ;; If position data changes and the geometry group is touched - ;; we need to put to nil so we can regenerate it - reset-pos-data? nil - :else orig-value) - - roperation {:type :set + [attr dest-shape roperations uoperations attr-val] + (let [roperation {:type :set :attr attr - :val val + :val attr-val :ignore-touched true} uoperation {:type :set :attr attr @@ -1694,6 +1700,34 @@ [(conj roperations roperation) (conj uoperations uoperation)])) +(defn- is-text-partial-change? + "Check if the attr update is a text partial change" + [untouched-shape touched-shape] + (let [touched (get touched-shape :touched #{}) + partial-text-keys [:text-content-attribute :text-content-text] + active-keys (filter touched partial-text-keys) + untouched-content (:content untouched-shape) + untouched-attrs (cttx/get-first-paragraph-text-attrs untouched-content) + eq-untouched-attrs? (cttx/equal-attrs? untouched-content untouched-attrs)] + (and + (or + ;; One and only one of the keys is pressent + (= 1 (count active-keys)) + (and + (not (touched :text-content-attribute)) + (touched :text-content-structure-same-attrs))) + + (or + ;; Both has the same structure + (cttx/equal-structure? untouched-content (:content touched-shape)) + + ;; The origin and destiny have different structures, but each have the same attrs + ;; for all the items on its content tree + (and + eq-untouched-attrs? + (touched :text-content-structure-same-attrs)))))) + + (defn- update-attrs "The main function that implements the attribute sync algorithm. Copy attributes that have changed in the origin shape to the dest shape. @@ -1737,58 +1771,271 @@ (generate-update-tokens container dest-shape origin-shape touched omit-touched?)) (let [attr-group (get ctk/sync-attrs attr) - skip-operations? (or (= (get origin-shape attr) (get dest-shape attr)) - (and (touched attr-group) - omit-touched?)) + ;; position-data is a special case because can be affected by + ;; :geometry-group and :content-group so, if the position-data + ;; changes but the geometry is touched we need to reset the position-data + ;; so it's calculated again + reset-pos-data? (and (cfh/text-shape? origin-shape) + (= attr :position-data) + (not= (:position-data origin-shape) (:position-data dest-shape)) + (touched :geometry-group)) + + ;; On texts, when we want to omit the touched attrs, both text (the actual letters) + ;; and attrs (bold, font, etc) are in the same attr :content. + ;; If only one of them is touched, we want to adress this case and + ;; only update the untouched one + text-partial-change? + (when (and + omit-touched? + (cfh/text-shape? origin-shape) + (= :content attr) + (touched attr-group)) + (is-text-partial-change? origin-shape dest-shape)) + + skip-operations? + (or (= (get origin-shape attr) (get dest-shape attr)) + (and (touched attr-group) + omit-touched? + ;; When it is a text-partial-change, we should generate operations + ;; even when omit-touched? is true, but updating only the text or + ;; the attributes, omiting the other part + (not text-partial-change?))) + + attr-val (when-not skip-operations? + (cond + ;; If position data changes and the geometry group is touched + ;; we need to put to nil so we can regenerate it + reset-pos-data? + nil + + text-partial-change? + (text-partial-change-value (:content dest-shape) + (:content origin-shape) + touched) + + :else + (get origin-shape attr))) + + ;; If the final attr-value is the actual value, skip + skip-operations? (or skip-operations? + (= attr-val (get dest-shape attr))) + + + ;; On a text-partial-change, we want to force a position-data reset + ;; so it's calculated again + [roperations uoperations] + (if (and text-partial-change? (not skip-operations?)) + (add-update-attr-operations :position-data dest-shape roperations uoperations nil) + [roperations uoperations]) [roperations' uoperations'] (if skip-operations? [roperations uoperations] - (add-update-attr-operations attr dest-shape origin-shape roperations uoperations touched))] + (add-update-attr-operations attr dest-shape roperations uoperations attr-val))] (recur (next attrs) roperations' uoperations'))))))) + +(defn- switch-text-change-value + [prev-content ;; The :content of the text before the switch + current-content ;; The :content of the text after the switch (a clean copy) + ref-content touched] ;; The :content of the referenced text on the main component + ;; before the switch + (let [;; We need the differences between the contents on the main + ;; components. current-content is the content of a clean copy, + ;; so for all effects its the same as the content on its main + main-comps-diff (cttx/get-diff-type ref-content current-content) + can-keep-text? (not (contains? main-comps-diff :text-content-text)) + can-keep-attr? (not (contains? main-comps-diff :text-content-attribute)) + main-diff-structure? (contains? main-comps-diff :text-content-structure) + + current-attrs (cttx/get-first-paragraph-text-attrs current-content) + ;; Have current content an uniform style? + curr-unif-style? (cttx/equal-attrs? current-content current-attrs) + prev-attrs (cttx/get-first-paragraph-text-attrs prev-content) + ;; Have prev content an uniform style? + prev-unif-style? (cttx/equal-attrs? prev-content prev-attrs) + ref-attrs (cttx/get-first-paragraph-text-attrs ref-content) + ;; Have ref content an uniform style? + ref-unif-style? (cttx/equal-attrs? ref-content ref-attrs)] + (cond + ;; When the main components have a difference in structure + ;; (different number of paragraph or text entries) + main-diff-structure? + ;; Special case for adding or removing paragraphs: + ;; If the structure has changed between ref-content and current-content, + ;; but each one have uniform attributes, and the attrs on the main + ;; components were equal, we keep the touched-content structure and + ;; texts, updating its attrs to make them like the current-content + (if (and curr-unif-style? + ref-unif-style? + prev-unif-style? + (= ref-attrs current-attrs)) + (cttx/copy-attrs-keys current-content prev-attrs) + ;; In any other case of structure change, we discard all + ;; the overrides and keep the content of the current-shape + current-content) + + ;; When the main components are equal, we keep the updated + ;; content from previous-shape as is + (and can-keep-text? can-keep-attr?) + prev-content + + ;; When we can't keep anything, we discard all the + ;; overrides and keep the content of the current-shape + (and (not can-keep-text?) (not can-keep-attr?)) + current-content + + ;; Special case for added or removed paragraphs: + ;; If the structure has changed on current-content, but it has uniform attributes + ;; and the previous-content also has uniform attributes, and we can keep the changes + ;; on the text, we keep the touched-content structure and texts, updating + ;; its attrs to make them like the current-content + (and (touched :text-content-structure) + curr-unif-style? + prev-unif-style?) + (if can-keep-text? + (cttx/copy-attrs-keys prev-content current-attrs) + (cttx/copy-attrs-keys current-content prev-attrs)) + + ;; In any other case of structure change, we discard all + ;; the overrides and keep the content of the current-shape + (touched :text-content-structure) + current-content + + ;; When there is a change on :text-content-text, + ;; and and we can keep it, we copy the texts from + ;; previous-shape over the attrs of current-shape + (and + (touched :text-content-text) can-keep-text?) + (cttx/copy-text-keys prev-content current-content) + + ;; When there is a change on :text-content-attribute, + ;; and we can keep it, we copy the texts from current-shape + ;; over the attrs of previous-shape + (and + (touched :text-content-attribute) can-keep-attr?) + (cttx/copy-text-keys current-content prev-content) + + ;; In any other case, we discard all the overrides + ;; and keep the content of the current-shape + :else + current-content))) + (defn update-attrs-on-switch - "Copy attributes that have changed in the origin shape to the dest shape. Used on variants switch" - [changes dest-shape origin-shape dest-root origin-root origin-ref-shape container] + "Copy attributes that have changed in the shape previous to the switch + to the current shape (post switch). Used only on variants switch" + ;; NOTE: This function have similitudes but is very different to + ;; update-attrs: + ;; In components (update-attrs), the source shape is "clean", and the destination + ;; shape may have touched elements that shouldn't be overwritten. + ;; In variants (update-attrs-on-switch), the destination shape is "clean", + ;; and it's the source shape that may have touched elements, and we only want + ;; to copy those touched elements. + [changes current-shape previous-shape current-root prev-root origin-ref-shape container] (let [;; We need to sync only the position relative to the origin of the component. ;; (see update-attrs for a full explanation) - origin-shape (reposition-shape origin-shape origin-root dest-root) - touched (get dest-shape :touched #{}) - touched-origin (get origin-shape :touched #{})] + previous-shape (reposition-shape previous-shape prev-root current-root) + touched (get previous-shape :touched #{})] (loop [attrs updatable-attrs - roperations [{:type :set-touched :touched (:touched origin-shape)}] - uoperations (list {:type :set-touched :touched (:touched dest-shape)})] + roperations [{:type :set-touched :touched (:touched previous-shape)}] + uoperations (list {:type :set-touched :touched (:touched current-shape)})] (if-let [attr (first attrs)] (let [attr-group (get ctk/sync-attrs attr) + skip-operations? + (or + ;; If the attribute is not valid for the destiny, don't copy it + (not (cts/is-allowed-attr? attr (:type current-shape))) + + ;; If the values are already equal, don't copy them + (= (get previous-shape attr) (get current-shape attr)) + + ;; If both variants (origin and destiny) don't have the same value + ;; for that attribute, don't copy it. + ;; Exceptions: :points :selrect and :content can be different + ;; + ;; Sample: + ;; 1. We have a variant with C1 (bg red) and C2 (bg blue). + ;; 2. We make a copy of C1 called Copy. + ;; 3. We set Copy’s bg to green (so it it has an override on the bg). + ;; 4. We switch Copy to use C2 as base. + ;; 5. The bg of Copy now is blue (we ignore the override) + (and + (not (contains? #{:points :selrect :content} attr)) + (not= (get origin-ref-shape attr) (get current-shape attr))) + + ;; The :content attr cant't be copied to elements of different type + (and (= attr :content) (not= (:type previous-shape) (:type current-shape))) + + ;; If the attr is not touched, don't copy it + (not (touched attr-group))) + + ;; On texts, both text (the actual letters) + ;; and attrs (bold, font, etc) are in the same attr :content. + ;; If only one of them is touched, we want to adress this case and + ;; only update the untouched one + text-change? + (and + (not skip-operations?) + (cfh/text-shape? current-shape) + (cfh/text-shape? previous-shape) + (= :content attr) + (touched attr-group)) + + ;; position-data is a special case because can be affected by :geometry-group and :content-group + ;; so, if the position-data changes but the geometry is touched we need to reset the position-data + ;; so it's calculated again + reset-pos-data? (and + (not skip-operations?) + (cfh/text-shape? previous-shape) + (= attr :position-data) + (not= (:position-data previous-shape) (:position-data current-shape)) + (touched :geometry-group)) + + attr-val + (when-not skip-operations? + (cond + ;; If position data changes and the geometry group is touched + ;; we need to put to nil so we can regenerate it + reset-pos-data? + nil + + text-change? + (switch-text-change-value (:content previous-shape) + (:content current-shape) + (:content origin-ref-shape) + touched) + + :else + (get previous-shape attr))) + + ;; If the final attr-value is the actual value, skip + skip-operations? (or skip-operations? + (= attr-val (get current-shape attr))) + + + ;; On a text-change, we want to force a position-data reset + ;; so it's calculated again + [roperations uoperations] + (if (and (not skip-operations?) text-change?) + (add-update-attr-operations :position-data current-shape roperations uoperations nil) + [roperations uoperations]) + [roperations' uoperations'] - (if (or - ;; If the attribute is not valid for the destiny, don't copy it - (not (cts/is-allowed-attr? attr (:type dest-shape))) - ;; If the values are already equal, don't copy it - (= (get origin-shape attr) (get dest-shape attr)) - ;; If the referenced shape on the original component doesn't have the same value, don't copy it - ;; Exceptions: :points :selrect and :content can be different - (and - (not (contains? #{:points :selrect :content} attr)) - (not= (get origin-ref-shape attr) (get dest-shape attr))) - ;; The :content attr cant't be copied to elements of different type - (and (= attr :content) (not= (:type origin-shape) (:type dest-shape))) - ;; If the attr is not touched in the origin shape, don't copy it - (not (touched-origin attr-group))) + (if skip-operations? [roperations uoperations] - (add-update-attr-operations attr dest-shape origin-shape roperations uoperations touched))] + (add-update-attr-operations attr current-shape roperations uoperations attr-val))] (recur (next attrs) roperations' uoperations')) (cond-> changes (> (count roperations) 1) - (add-update-attr-changes dest-shape container roperations uoperations) + (add-update-attr-changes current-shape container roperations uoperations) :always - (generate-update-tokens container dest-shape origin-shape touched false)))))) + (generate-update-tokens container current-shape previous-shape touched false)))))) (defn- propagate-attrs "Helper that puts the origin attributes (attrs) into dest but only if @@ -2115,7 +2362,7 @@ (pcb/update-shapes [(:id new-shape)] #(d/patch-object % keep-props-values)) ;; We need to set the same index as the original shape - (pcb/change-parent (:parent-id shape) [new-shape] index {:component-swap true + (pcb/change-parent (:parent-id shape) [new-shape] index {:allow-altering-copies true :ignore-touched true}) (change-touched new-shape shape @@ -2123,10 +2370,21 @@ {}))])) (defn generate-component-swap - [changes objects shape file page libraries id-new-component index target-cell keep-props-values] - (let [[all-parents changes] + [changes objects shape file page libraries id-new-component + index target-cell keep-props-values ignore-swapped?] + (let [;; When we keep the touched properties, we can't delete the + ;; swapped children (we will keep them too) + ignore-swapped-fn + (if ignore-swapped? + #(-> (get objects %) + (ctk/get-swap-slot)) + (constantly false)) + + [all-parents changes] (-> changes - (cls/generate-delete-shapes file page objects (d/ordered-set (:id shape)) {:component-swap true})) + (cls/generate-delete-shapes + file page objects (d/ordered-set (:id shape)) + {:allow-altering-copies true :ignore-children-fn ignore-swapped-fn})) [new-shape changes] (-> changes (generate-new-shape-for-swap shape file page libraries id-new-component index target-cell keep-props-values))] diff --git a/common/src/app/common/logic/shapes.cljc b/common/src/app/common/logic/shapes.cljc index f26b9f95a8..6590c7bed8 100644 --- a/common/src/app/common/logic/shapes.cljc +++ b/common/src/app/common/logic/shapes.cljc @@ -99,7 +99,14 @@ (pcb/with-library-data file)) ids options)) - ([changes ids {:keys [ignore-touched component-swap]}] + ([changes ids {:keys [ignore-touched + allow-altering-copies + ;; We will delete the shapes and its descendants. + ;; ignore-children-fn is used to ignore some descendants + ;; on the deletion process. It should receive a shape and + ;; return a boolean + ignore-children-fn] + :or {ignore-children-fn (constantly false)}}] (let [objects (pcb/get-objects changes) data (pcb/get-library-data changes) page-id (pcb/get-page-id changes) @@ -112,11 +119,12 @@ ;; 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 + ;; If we want to specifically allow altering the copies, this is + ;; a special case, like 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)))) + (not allow-altering-copies)))) [ids-to-delete ids-to-hide] (loop [ids-seq (seq ids) @@ -177,10 +185,15 @@ (d/ordered-set) (concat ids-to-delete ids-to-hide)) - all-children - (->> ids-to-delete ;; Children of deleted shapes must be also deleted. + ;; Descendants of deleted shapes must be also deleted, + ;; except the ignored ones by the function ignore-children-fn + descendants-to-delete + (->> ids-to-delete (reduce (fn [res id] - (into res (cfh/get-children-ids objects id))) + (into res (cfh/get-children-ids + objects + id + {:ignore-children-fn ignore-children-fn}))) []) (reverse) (into (d/ordered-set))) @@ -200,9 +213,10 @@ 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 + ;; If we want to specifically allow altering the copies, this is a special case, + ;; for example 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 + (if-not allow-altering-copies (into (d/ordered-set) (find-all-empty-parents #{})) #{}) @@ -214,7 +228,7 @@ (conj components (:component-id shape)) components))) [] - (into ids-to-delete all-children)) + (into ids-to-delete descendants-to-delete)) ids-set (set ids-to-delete) @@ -241,7 +255,7 @@ changes (-> changes (generate-update-shape-flags ids-to-hide objects {:hidden true}) - (pcb/remove-objects all-children {:ignore-touched true}) + (pcb/remove-objects descendants-to-delete {:ignore-touched true}) (pcb/remove-objects ids-to-delete {:ignore-touched ignore-touched}) (pcb/remove-objects empty-parents) (pcb/resize-parents all-parents) diff --git a/common/src/app/common/logic/tokens.cljc b/common/src/app/common/logic/tokens.cljc index 5121df8764..b594d3c0aa 100644 --- a/common/src/app/common/logic/tokens.cljc +++ b/common/src/app/common/logic/tokens.cljc @@ -41,7 +41,7 @@ [group-path tokens-lib tokens-lib-theme] (let [deactivate? (contains? #{:all :partial} (ctob/sets-at-path-all-active? tokens-lib group-path)) sets-names (->> (ctob/get-sets-at-path tokens-lib group-path) - (map :name) + (map ctob/get-name) (into #{}))] (if deactivate? (ctob/disable-sets tokens-lib-theme sets-names) diff --git a/common/src/app/common/logic/variant_properties.cljc b/common/src/app/common/logic/variant_properties.cljc index 43938415c9..4a692702d9 100644 --- a/common/src/app/common/logic/variant_properties.cljc +++ b/common/src/app/common/logic/variant_properties.cljc @@ -18,7 +18,12 @@ [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)] + related-components (cfv/find-variant-components data objects variant-id) + + props (-> related-components last :variant-properties) + prop-names (mapv :name props) + prop-names (concat (subvec prop-names 0 pos) (subvec prop-names (inc pos))) + new-name (ctv/update-number-in-repeated-item prop-names new-name)] (reduce (fn [changes component] (pcb/update-component changes (:id component) @@ -81,6 +86,9 @@ next-prop-num (ctv/next-property-number props) property-name (or property-name (str ctv/property-prefix next-prop-num)) + prop-names (mapv :name props) + property-name (ctv/update-number-in-repeated-item prop-names property-name) + [_ changes] (reduce (fn [[num changes] component] (let [main-id (:main-instance-id component) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index fce96410d4..12238a1b73 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -1,13 +1,17 @@ (ns app.common.logic.variants (: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.logic.libraries :as cll] + [app.common.logic.shapes :as cls] [app.common.logic.variant-properties :as clvp] + [app.common.types.component :as ctk] [app.common.types.container :as ctn] [app.common.types.file :as ctf] - [app.common.types.variant :as ctv])) + [app.common.types.variant :as ctv] + [app.common.uuid :as uuid])) (defn generate-add-new-variant [changes shape variant-id new-component-id new-shape-id prop-num] @@ -62,29 +66,142 @@ shapes)))) +(defn- keep-swapped-item + "As part of the keep-touched process on a switch, given a child on the original + copy that was swapped (orig-swapped-child), and its related shape on the new copy + (related-shape-in-new), move the orig-swapped-child into the parent of + related-shape-in-new, fix its swap-slot if needed, and then delete + related-shape-in-new" + [changes related-shape-in-new orig-swapped-child ldata page swap-ref-id] + (let [;; Before to the swap, temporary move the previous + ;; shape to the root panel to avoid problems when + ;; the previous parent is deleted. + before-changes (-> (pcb/empty-changes) + (pcb/with-page page) + (pcb/with-objects (:objects page)) + (pcb/change-parent uuid/zero [orig-swapped-child] 0 {:allow-altering-copies true})) + + objects (pcb/get-objects changes) + prev-swap-slot (ctk/get-swap-slot orig-swapped-child) + current-parent (get objects (:parent-id related-shape-in-new)) + pos (d/index-of (:shapes current-parent) (:id related-shape-in-new))] + + + (-> (pcb/concat-changes before-changes changes) + + ;; Move the previous shape to the new parent + (pcb/change-parent (:parent-id related-shape-in-new) [orig-swapped-child] pos {:allow-altering-copies true}) + + ;; We need to update the swap slot only when it pointed + ;; to the swap-ref-id. Oterwise this is a swapped item + ;; inside a nested copy, so we need to keep it. + (cond-> + (= prev-swap-slot swap-ref-id) + (pcb/update-shapes + [(:id orig-swapped-child)] + #(ctk/set-swap-slot % (:shape-ref related-shape-in-new)))) + + ;; Delete new non-swapped item + (cls/generate-delete-shapes ldata page objects (d/ordered-set (:id related-shape-in-new)) {:allow-altering-copies true}) + second))) + +(defn- child-of-swapped? + "Check if any ancestor of a shape (between base-parent-id and shape) was swapped" + [shape objects base-parent-id] + (let [ancestors (->> (ctn/get-parent-heads objects shape) + ;; Ignore ancestors ahead of base-parent + (drop-while #(not= base-parent-id (:id %))) + seq) + num-ancestors (count ancestors) + ;; Ignore first and last (base-parent and shape) + ancestors (when (and ancestors (<= 3 num-ancestors)) + (subvec (vec ancestors) 1 (dec num-ancestors)))] + (some ctk/get-swap-slot ancestors))) + + (defn generate-keep-touched - [changes new-shape original-shape original-shapes page libraries] + "This is used as part of the switch process, when you switch from + an original-shape to a new-shape. It generate changes to + copy the touched attributes on the shapes children of the original-shape + into the related children of the new-shape. + This relation is tricky. The shapes are related if: + * On the main components, both have the same name (the name on the copies are ignored) + * Both has the same type of ancestors, on the same order (see generate-path for the + translation of the types)" + [changes new-shape original-shape original-shapes page libraries ldata] (let [objects (pcb/get-objects changes) - orig-objects (into {} (map (juxt :id identity) original-shapes)) - orig-shapes-w-path (add-unique-path - (reverse original-shapes) - orig-objects - (:id original-shape)) + container (ctn/make-container page :page) + page-objects (:objects page) + + ;; Get the touched children of the original-shape + ;; Ignore children of swapped items, because + ;; they will be moved without change when + ;; managing their swapped ancestor + orig-touched (->> (filter (comp seq :touched) original-shapes) + (remove + #(child-of-swapped? % + page-objects + (:id original-shape)))) + + ;; Adds a :shape-path attribute to the children of the new-shape, + ;; that contains the type of its ancestors and its name new-shapes-w-path (add-unique-path (reverse (cfh/get-children-with-self objects (:id new-shape))) objects (:id new-shape)) - new-shapes-map (into {} (map (juxt :shape-path identity) new-shapes-w-path)) - orig-touched (filter (comp seq :touched) orig-shapes-w-path) + ;; Creates a map to quickly find a child of the new-shape by its shape-path + new-shapes-map (into {} (map (juxt :shape-path identity)) new-shapes-w-path) - container (ctn/make-container page :page)] + ;; The original-shape is in a copy. For the relation rules, we need the referenced + ;; shape on the main component + orig-ref-shape (ctf/find-ref-shape nil container libraries original-shape) + + orig-ref-objects (-> (ctf/get-component-container-from-head orig-ref-shape libraries) + :objects) + + ;; Adds a :shape-path attribute to the children of the orig-ref-shape, + ;; that contains the type of its ancestors and its name + o-ref-shapes-wp (add-unique-path + (reverse (cfh/get-children-with-self orig-ref-objects (:id orig-ref-shape))) + orig-ref-objects + (:id orig-ref-shape)) + + ;; Creates a map to quickly find a child of the orig-ref-shape by its shape-path + o-ref-shapes-p-map (into {} (map (juxt :id :shape-path)) o-ref-shapes-wp)] + ;; Process each touched children of the original-shape (reduce - (fn [changes touched-shape] - (let [related-shape (get new-shapes-map (:shape-path touched-shape)) - orig-ref-shape (ctf/find-ref-shape nil container libraries touched-shape)] - (if related-shape - (cll/update-attrs-on-switch - changes related-shape touched-shape new-shape original-shape orig-ref-shape container) + (fn [changes orig-child-touched] + (let [;; If the orig-child-touched was swapped, get its swap-slot + swap-slot (ctk/get-swap-slot orig-child-touched) + + ;; orig-child-touched is in a copy. Get the referenced shape on the main component + ;; If there is a swap slot, we will get the referenced shape in another way + orig-ref-shape (when-not swap-slot + ;; TODO Maybe just get it from o-ref-shapes-wp + (ctf/find-ref-shape nil container libraries orig-child-touched)) + + orig-ref-id (if swap-slot + ;; If there is a swap slot, find the referenced shape id + (ctf/find-ref-id-for-swapped orig-child-touched container libraries) + ;; If there is not a swap slot, get the id from the orig-ref-shape + (:id orig-ref-shape)) + + ;; Get the shape path of the referenced main + shape-path (get o-ref-shapes-p-map orig-ref-id) + ;; Get its related shape in the children of new-shape: the one that + ;; has the same shape-path + related-shape-in-new (get new-shapes-map shape-path)] + ;; If there is a related shape, keep its data + (if related-shape-in-new + (if swap-slot + ;; If the orig-child-touched was swapped, keep it + (keep-swapped-item changes related-shape-in-new orig-child-touched + ldata page orig-ref-id) + ;; If the orig-child-touched wasn't swapped, copy + ;; the touched attributes into it + (cll/update-attrs-on-switch + changes related-shape-in-new orig-child-touched + new-shape original-shape orig-ref-shape container)) changes))) changes orig-touched))) diff --git a/common/src/app/common/test_helpers/components.cljc b/common/src/app/common/test_helpers/components.cljc index 687be91871..4e82acd647 100644 --- a/common/src/app/common/test_helpers/components.cljc +++ b/common/src/app/common/test_helpers/components.cljc @@ -156,7 +156,7 @@ [new_shape _ changes] (-> (pcb/empty-changes nil (:id page)) - (cll/generate-component-swap objects shape (:data file) page libraries id-new-component 0 nil keep-props-values)) + (cll/generate-component-swap objects shape (:data file) page libraries id-new-component 0 nil keep-props-values false)) file' (thf/apply-changes file changes)] diff --git a/common/src/app/common/test_helpers/compositions.cljc b/common/src/app/common/test_helpers/compositions.cljc index ca6bd064ba..bf7c64ae51 100644 --- a/common/src/app/common/test_helpers/compositions.cljc +++ b/common/src/app/common/test_helpers/compositions.cljc @@ -8,11 +8,14 @@ (:require [app.common.data :as d] [app.common.files.changes-builder :as pcb] + [app.common.files.helpers :as cfh] [app.common.geom.point :as gpt] [app.common.logic.libraries :as cll] [app.common.logic.shapes :as cls] + [app.common.logic.variants :as clv] [app.common.test-helpers.components :as thc] [app.common.test-helpers.files :as thf] + [app.common.test-helpers.ids-map :as thi] [app.common.test-helpers.shapes :as ths] [app.common.text :as txt] [app.common.types.container :as ctn] @@ -275,25 +278,36 @@ (defn swap-component "Swap the specified shape by the component specified by component-tag" - [file shape component-tag & {:keys [page-label propagate-fn]}] + [file shape component-tag & {:keys [page-label propagate-fn keep-touched? new-shape-label]}] (let [page (if page-label (thf/get-page file page-label) (thf/current-page file)) + libraries {(:id file) file} - [_ _all-parents changes] + orig-shapes (when keep-touched? (cfh/get-children-with-self (:objects page) (:id shape))) + + [new-shape _all-parents changes] (cll/generate-component-swap (pcb/empty-changes) (:objects page) shape (:data file) page - {(:id file) file} + libraries (-> (thc/get-component file component-tag) :id) 0 nil - {}) + {} + (true? keep-touched?)) + + changes (if keep-touched? + (clv/generate-keep-touched changes new-shape shape orig-shapes page libraries (:data file)) + changes) + file' (thf/apply-changes file changes)] + (when new-shape-label + (thi/set-id! new-shape-label (:id new-shape))) (if propagate-fn (propagate-fn file') file'))) diff --git a/common/src/app/common/test_helpers/variants.cljc b/common/src/app/common/test_helpers/variants.cljc index e9a76d0628..7b5d928798 100644 --- a/common/src/app/common/test_helpers/variants.cljc +++ b/common/src/app/common/test_helpers/variants.cljc @@ -8,7 +8,9 @@ (:require [app.common.test-helpers.components :as thc] [app.common.test-helpers.ids-map :as thi] - [app.common.test-helpers.shapes :as ths])) + [app.common.test-helpers.shapes :as ths] + [app.common.text :as txt] + [app.common.types.shape :as cts])) (defn add-variant [file variant-label component1-label root1-label component2-label root2-label @@ -37,3 +39,48 @@ (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"}]})))) + +(defn add-variant-with-child + [file variant-label component1-label root1-label component2-label root2-label child1-label child2-label + & {:keys [child1-params child2-params]}] + (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 "Value2") + (ths/add-sample-shape root1-label :type :frame :parent-label variant-label :variant-id variant-id :variant-name "Value1") + (ths/add-sample-shape child1-label (assoc child1-params :parent-label root1-label)) + (ths/add-sample-shape child2-label (assoc child2-params :parent-label root2-label)) + (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 "Value2"}]})))) + + +(defn add-variant-with-text + [file variant-label component1-label root1-label component2-label root2-label child1-label child2-label text1 text2 + & {:keys [text1-params text2-params]}] + (let [text1 (-> (cts/setup-shape {:type :text :x 0 :y 0 :grow-type :auto-width}) + (txt/change-text text1) + (assoc :position-data nil + :parent-label root1-label)) + text2 (-> (cts/setup-shape {:type :text :x 0 :y 0 :grow-type :auto-width}) + (txt/change-text text2) + (assoc :position-data nil + :parent-label root2-label)) + + 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 "Value2") + (ths/add-sample-shape root1-label :type :frame :parent-label variant-label :variant-id variant-id :variant-name "Value1") + (ths/add-sample-shape child1-label + (merge text1 + text1-params)) + (ths/add-sample-shape child2-label + (merge text2 + text2-params)) + (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 "Value2"}]})))) diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index 395e421315..89e210d871 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -18,6 +18,7 @@ [app.common.types.plugins :as ctpg] [app.common.types.shape-tree :as ctst] [app.common.types.shape.layout :as ctl] + [app.common.types.text :as cttx] [app.common.types.token :as ctt] [app.common.uuid :as uuid] [clojure.set :as set])) @@ -293,8 +294,8 @@ ([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}}] + {:keys [main-instance? force-id force-frame-id keep-ids? force-parent-id] + :or {main-instance? false force-id nil force-frame-id nil keep-ids? false force-parent-id nil}}] (let [component-page (ctpl/get-page library-data (:main-instance-page component)) component-shape (-> (get-shape component-page (:main-instance-id component)) @@ -302,7 +303,6 @@ (assoc :frame-id uuid/zero) (remove-swap-keep-attrs)) - orig-pos (gpt/point (:x component-shape) (:y component-shape)) delta (gpt/subtract position orig-pos) @@ -367,7 +367,7 @@ [new-shape new-shapes _] (ctst/clone-shape component-shape - frame-id + (or force-parent-id frame-id) (:objects component-page) :update-new-shape update-new-shape :force-id force-id @@ -569,13 +569,16 @@ (not equal?) (not (and ignore-geometry is-geometry?))) + content-diff-type (when (and (= (:type shape) :text) (= attr :content)) + (cttx/get-diff-type (:content shape) val)) + token-groups (if (= attr :applied-tokens) (get-token-groups shape val) #{}) groups (cond-> token-groups (and group (not equal?)) - (set/union #{group}))] + (set/union #{group} content-diff-type))] (cond-> shape ;; Depending on the origin of the attribute change, we need or not to ;; set the "touched" flag for the group the attribute belongs to. diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index f4ecbd4acc..521915da96 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -242,6 +242,13 @@ (cfh/make-container component-page :page)) (cfh/make-container component :component))) +(defn get-component-container-from-head + [instance-head libraries & {:keys [include-deleted?] :or {include-deleted? true}}] + (let [library-data (-> (get-component-library libraries instance-head) + :data) + component (ctkl/get-component library-data (:component-id instance-head) include-deleted?)] + (get-component-container library-data component))) + (defn get-component-root "Retrieve the root shape of the component." [file-data component] @@ -390,6 +397,47 @@ (or (= slot-main slot-inst) (= (:id shape-main) slot-inst))))) +(defn- find-next-related-swap-shape-id + "Go up from the chain of references shapes that will eventually lead to the shape + with swap-slot-id as id. Returns the next shape on the chain" + [parent swap-slot-id libraries] + (let [container (get-component-container-from-head parent libraries) + objects (:objects container) + + children (cfh/get-children objects (:id parent)) + original-shape-id (->> children + (filter #(= swap-slot-id (:id %))) + first + :id)] + (if original-shape-id + ;; Return the children which id is the swap-slot-id + original-shape-id + ;; No children with swap-slot-id as id, go up + (let [referenced-shape (find-ref-shape nil container libraries parent) + ;; Recursive call that will get the id of the next shape on + ;; the chain that ends on a shape with swap-slot-id as id + next-shape-id (when referenced-shape + (find-next-related-swap-shape-id referenced-shape swap-slot-id libraries))] + ;; Return the children which shape-ref points to the next-shape-id + (->> children + (filter #(= next-shape-id (:shape-ref %))) + first + :id))))) + +(defn find-ref-id-for-swapped + "When a shape has been swapped, find the original ref-id that the shape had + before the swap" + [shape container libraries] + (let [swap-slot (ctk/get-swap-slot shape) + objects (:objects container) + + parent (get objects (:parent-id shape)) + parent-head (ctn/get-head-shape objects parent) + parent-ref (find-ref-shape nil container libraries parent-head)] + + (when (and swap-slot parent-ref) + (find-next-related-swap-shape-id parent-ref swap-slot libraries)))) + (defn get-component-shapes "Retrieve all shapes of the component" [file-data component] diff --git a/common/src/app/common/types/text.cljc b/common/src/app/common/types/text.cljc index 927c2ca36f..efc1df0bad 100644 --- a/common/src/app/common/types/text.cljc +++ b/common/src/app/common/types/text.cljc @@ -127,7 +127,8 @@ entries" [a b] (cond - (not= (type a) (type b)) + (and (not= (type a) (type b)) + (not (and (map? a) (map? b)))) ;; Sometimes they are both maps but of different subtypes false (map? a) @@ -148,7 +149,7 @@ (cond (map? origin) (into {} - (for [k (keys origin) :when (not= k :key)] ;; We ignore :key because it is a draft artifact + (for [k (keys destiny) :when (not= k :key)] ;; We ignore :key because it is a draft artifact (cond (= :children k) [k (vec (map #(copy-text-keys %1 %2) (get origin k) (get destiny k)))] diff --git a/common/src/app/common/types/token.cljc b/common/src/app/common/types/token.cljc index b92b691acc..d3c1f27657 100644 --- a/common/src/app/common/types/token.cljc +++ b/common/src/app/common/types/token.cljc @@ -33,6 +33,8 @@ :border-radius "borderRadius" :color "color" :dimensions "dimension" + :font-size "fontSizes" + :letter-spacing "letterSpacing" :number "number" :opacity "opacity" :other "other" @@ -101,18 +103,15 @@ [:m1 {:optional true} token-name-ref] [:m2 {:optional true} token-name-ref] [:m3 {:optional true} token-name-ref] - [:m4 {:optional true} token-name-ref] - [:x {:optional true} token-name-ref] - [:y {:optional true} token-name-ref]]) + [:m4 {:optional true} token-name-ref]]) (def spacing-keys (schema-keys schema:spacing)) (def ^:private schema:dimensions - [:merge - schema:sizing - schema:spacing - schema:stroke-width - schema:border-radius]) + (reduce mu/union [schema:sizing + schema:spacing + schema:stroke-width + schema:border-radius])) (def dimensions-keys (schema-keys schema:dimensions)) @@ -122,10 +121,27 @@ (def rotation-keys (schema-keys schema:rotation)) -(def ^:private schema:number +(def ^:private schema:font-size [:map - [:rotation {:optional true} token-name-ref] - [:line-height {:optional true} token-name-ref]]) + [:font-size {:optional true} token-name-ref]]) + +(def font-size-keys (schema-keys schema:font-size)) + +(def ^:private schema:letter-spacing + [:map + [:letter-spacing {:optional true} token-name-ref]]) + +(def letter-spacing-keys (schema-keys schema:letter-spacing)) + +(def typography-keys (set/union font-size-keys letter-spacing-keys)) + +;; TODO: Created to extract the font-size feature from the typography feature flag. +;; Delete this once the typography feature flag is removed. +(def ff-typography-keys (set/difference typography-keys font-size-keys)) + +(def ^:private schema:number + (reduce mu/union [[:map [:line-height {:optional true} token-name-ref]] + schema:rotation])) (def number-keys (schema-keys schema:number)) @@ -137,6 +153,7 @@ spacing-keys dimensions-keys rotation-keys + typography-keys number-keys)) (def ^:private schema:tokens @@ -150,6 +167,8 @@ schema:spacing schema:rotation schema:number + schema:font-size + schema:letter-spacing schema:dimensions]) (defn shape-attr->token-attrs @@ -177,6 +196,8 @@ changed-sub-attr #{:m1 :m2 :m3 :m4}) + (font-size-keys shape-attr) #{shape-attr} + (letter-spacing-keys shape-attr) #{shape-attr} (border-radius-keys shape-attr) #{shape-attr} (sizing-keys shape-attr) #{shape-attr} (opacity-keys shape-attr) #{shape-attr} @@ -192,6 +213,56 @@ :stroke-width :strokes token-attr)) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; TOKEN SHAPE ATTRIBUTES +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def position-attributes #{:x :y}) + +(def generic-attributes + (set/union color-keys + stroke-width-keys + rotation-keys + sizing-keys + opacity-keys + position-attributes)) + +(def rect-attributes + (set/union generic-attributes + border-radius-keys)) + +(def frame-attributes + (set/union rect-attributes + spacing-keys)) + +(def text-attributes + (set/union generic-attributes + typography-keys + number-keys)) + +(defn shape-type->attributes + [type] + (case type + :bool generic-attributes + :circle generic-attributes + :rect rect-attributes + :frame frame-attributes + :image rect-attributes + :path generic-attributes + :svg-raw generic-attributes + :text text-attributes + nil)) + +(defn appliable-attrs + "Returns intersection of shape `attributes` for `token-type`." + [attributes token-type] + (set/intersection attributes (shape-type->attributes token-type))) + +(defn any-appliable-attr? + "Checks if `token-type` supports given shape `attributes`." + [attributes token-type] + (seq (appliable-attrs attributes token-type))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; TOKENS IN SHAPES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -218,13 +289,5 @@ :attributes attributes})] (update shape :applied-tokens #(merge % applied-tokens)))) -(defn maybe-apply-token-to-shape - "When the passed `:token` is non-nil apply it to the `:applied-tokens` on a shape." - [{:keys [shape token _attributes] :as props}] - (if token - (apply-token-to-shape props) - shape)) - (defn unapply-token-id [shape attributes] (update shape :applied-tokens d/without-keys attributes)) - diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index dd64992312..ecfd92b5da 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -17,6 +17,7 @@ [app.common.transit :as t] [app.common.types.token :as cto] [app.common.uuid :as uuid] + [clojure.core.protocols :as protocols] [clojure.set :as set] [clojure.walk :as walk] [cuerdas.core :as str])) @@ -25,13 +26,6 @@ ;; TODO: add again the removed functions and refactor the rest of the module to use them -(def ^:private schema:groupable-item - [:map {:title "Groupable item"} - [:name :string]]) - -(def ^:private valid-groupable-item? - (sm/validator schema:groupable-item)) - (def ^:private xf-map-trim (comp (map str/trim) @@ -60,14 +54,38 @@ (defn get-path "Get the path of object by specified separator (E.g. with '.' separator, the 'group.subgroup.name' -> ['group' 'subgroup'])" - [item separator] - (assert (valid-groupable-item? item) "expected groupable item") - (->> (split-path (:name item) separator) + [name separator] + (->> (split-path name separator) (not-empty))) +;; === Common + +(defprotocol INamedItem + "Protocol for items that have a name, a description and a modified date." + (get-name [_] "Get the name of the item.") + (get-description [_] "Get the description of the item.") + (get-modified-at [_] "Get the description of the item.") + (rename [_ new-name] "Set the name of the item.") + (set-description [_ new-description] "Set the description of the item.")) + ;; === Token -(defrecord Token [id name type value description modified-at]) +(defrecord Token [id name type value description modified-at] + INamedItem + (get-name [_] + name) + + (get-description [_] + description) + + (get-modified-at [_] + modified-at) + + (rename [this new-name] + (assoc this :name new-name)) + + (set-description [this new-description] + (assoc this :description new-description))) (defn token? [o] @@ -109,7 +127,7 @@ (defn get-token-path [token] - (get-path token token-separator)) + (get-path (:name token) token-separator)) (defn find-token-value-references "Returns set of token references found in `token-value`. @@ -146,9 +164,53 @@ (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")) + (get-tokens [_] "return an ordered sequence of all tokens in the set") + (get-tokens-map [_] "return a map of tokens in the set, indexed by token-name")) + +(deftype TokenSet [id name description modified-at tokens] + #?@(:clj [clojure.lang.IDeref + (deref [_] {:id id + :name name + :description description + :modified-at modified-at + :tokens tokens})] + :cljs [cljs.core/IDeref + (-deref [_] {:id id + :name name + :description description + :modified-at modified-at + :tokens tokens})]) + + #?@(:cljs [cljs.core/IEncodeJS + (-clj->js [_] (js-obj "id" (clj->js id) + "name" (clj->js name) + "description" (clj->js description) + "modified-at" (clj->js modified-at) + "tokens" (clj->js tokens)))]) + INamedItem + (get-name [_] + name) + + (get-description [_] + description) + + (get-modified-at [_] + modified-at) + + (rename [_ new-name] + (TokenSet. id + new-name + description + (dt/now) + tokens)) + + (set-description [_ new-description] + (TokenSet. id + name + (d/nilv new-description "") + (dt/now) + tokens)) -(defrecord TokenSet [id name description modified-at tokens] ITokenSet (add-token [_ token] (let [token (check-token token)] @@ -184,7 +246,10 @@ (get tokens token-name)) (get-tokens [_] - (vals tokens))) + (vals tokens)) + + (get-tokens-map [_] + tokens)) (defn token-set? [o] @@ -218,10 +283,7 @@ (declare make-token-set) (def schema:token-set - [: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/required-keys schema:token-set-attrs)) (sm/register! ::token-set schema:token-set) ;; need to register for the recursive schema of token-sets @@ -233,13 +295,17 @@ (defn make-token-set [& {:as attrs}] - (-> attrs - (update :id #(or % (uuid/next))) - (update :modified-at #(or % (dt/now))) - (update :tokens #(into (d/ordered-map) %)) - (update :description d/nilv "") - (check-token-set-attrs) - (map->TokenSet))) + (let [attrs (-> attrs + (update :id #(or % (uuid/next))) + (update :modified-at #(or % (dt/now))) + (update :tokens #(into (d/ordered-map) %)) + (update :description d/nilv "") + (check-token-set-attrs))] + (TokenSet. (:id attrs) + (:name attrs) + (:description attrs) + (:modified-at attrs) + (:tokens attrs)))) (def ^:private set-prefix "S-") @@ -291,7 +357,7 @@ (defn get-set-path [token-set] - (get-path token-set set-separator)) + (get-path (get-name token-set) set-separator)) (defn split-set-name [name] @@ -315,7 +381,7 @@ (set-full-path->set-prefixed-full-path))) (defn get-set-prefixed-path [token-set] - (let [path (get-path token-set set-separator)] + (let [path (get-path (get-name token-set) set-separator)] (set-full-path->set-prefixed-full-path path))) (defn prefixed-set-path-string->set-name-string [path-str] @@ -333,7 +399,7 @@ (conj name))) (defn tokens-tree - "Convert tokens into a nested tree with their `:name` as the path. + "Convert tokens into a nested tree with their name as the path. Optionally use `update-token-fn` option to transform the token." [tokens & {:keys [update-token-fn] :or {update-token-fn identity}}] @@ -343,7 +409,7 @@ {} tokens)) (defn backtrace-tokens-tree - "Convert tokens into a nested tree with their `:name` as the path. + "Convert tokens into a nested tree with their name as the path. Generates a uuid per token to backtrace a token from an external source (StyleDictionary). The backtrace can't be the name as the name might not exist when the user is creating a token." [tokens] @@ -392,7 +458,7 @@ (get-set [_ set-name] "get one set looking for name")) (def schema:token-set-node - [:schema {:registry {::node [:or ::token-set + [:schema {:registry {::node [:or [:fn token-set?] [:and [:map-of {:gen/max 5} :string [:ref ::node]] [:fn d/ordered-map?]]]}} @@ -443,6 +509,22 @@ (hidden-theme? [_] "if a theme is the (from the user ui) hidden temporary theme")) (defrecord TokenTheme [id name group description is-source external-id modified-at sets] + INamedItem + (get-name [_] + name) + + (get-description [_] + description) + + (get-modified-at [_] + modified-at) + + (rename [this new-name] + (assoc this :name new-name)) + + (set-description [this new-description] + (assoc this :description new-description)) + ITokenTheme (set-sets [_ set-names] (TokenTheme. id @@ -528,13 +610,17 @@ (defn make-token-theme [& {:as attrs}] - (let [id (uuid/next)] + (let [new-id (uuid/next)] (-> attrs - (update :id d/nilv id) + (update :id (fn [id] + (-> (if (string? id) ;; TODO: probably this may be deleted in some time, when we may be sure + (uuid/parse* id) ;; that no file exists that has not been correctly migrated to + id) ;; convert :id into :external-id + (d/nilv new-id)))) (update :group d/nilv top-level-theme-group-name) (update :description d/nilv "") (update :is-source d/nilv false) - (update :external-id #(or % (str id))) + (update :external-id #(or % (str new-id))) (update :modified-at #(or % (dt/now))) (update :sets set) (check-token-theme-attrs) @@ -618,7 +704,7 @@ ;; Set (and v (instance? TokenSet v)) [{:group? false - :path (split-set-name (:name v)) + :path (split-set-name (get-name v)) :parent-path parent :depth depth :set v}] @@ -664,7 +750,7 @@ ;; Set (and v (instance? TokenSet v)) - (let [name (:name v)] + (let [name (get-name v)] [{:is-group false :path (split-set-name name) :id name @@ -725,8 +811,14 @@ Will return a value that matches this schema: (declare export-dtcg-json) (deftype TokensLib [sets themes active-themes] - ;; NOTE: This is only for debug purposes, pending to properly - ;; implement the toString and alternative printing. + ;; This is to convert the TokensLib to a plain map, for debugging or unit tests. + protocols/Datafiable + (datafy [_] + {:sets (d/update-vals sets deref) + :themes themes + :active-themes active-themes}) + + ;; TODO: this is used in serialization, but there should be a better way to do it #?@(:clj [clojure.lang.IDeref (deref [_] {:sets sets :themes themes @@ -746,8 +838,8 @@ Will return a value that matches this schema: ITokenSets (add-set [_ token-set] - (let [path (get-set-prefixed-path token-set) - token-set (check-token-set token-set)] + (assert (token-set? token-set) "expected valid token-set") + (let [path (get-set-prefixed-path token-set)] (TokensLib. (d/oassoc-in sets path token-set) themes active-themes))) @@ -756,10 +848,9 @@ Will return a value that matches this schema: (let [prefixed-full-path (set-name->prefixed-full-path set-name) set (get-in sets prefixed-full-path)] (if set - (let [set' (-> (make-token-set (f set)) - (assoc :modified-at (dt/now))) + (let [set' (f set) prefixed-full-path' (get-set-prefixed-path set') - name-changed? (not= (:name set) (:name set'))] + name-changed? (not= (get-name set) (get-name set'))] (if name-changed? (TokensLib. (-> sets (d/oassoc-in-before prefixed-full-path prefixed-full-path' set') @@ -767,7 +858,7 @@ Will return a value that matches this schema: (walk/postwalk (fn [form] (if (instance? TokenTheme form) - (update-set-name form (:name set) (:name set')) + (update-set-name form (get-name set) (get-name set')) form)) themes) active-themes) @@ -791,7 +882,7 @@ Will return a value that matches this schema: (let [path (split-set-name set-group-name) prefixed-path (map add-set-group-prefix path) child-set-names (->> (get-sets-at-path this path) - (map :name) + (map get-name) (into #{}))] (TokensLib. (d/dissoc-in sets prefixed-path) (walk/postwalk @@ -833,7 +924,7 @@ Will return a value that matches this schema: (set-full-path->set-prefixed-full-path before-path))) set - (assoc prev-set :name (join-set-path to-path)) + (rename prev-set (join-set-path to-path)) reorder? (= prefixed-from-path prefixed-to-path) @@ -856,7 +947,7 @@ Will return a value that matches this schema: (walk/postwalk (fn [form] (if (instance? TokenTheme form) - (update-set-name form (:name prev-set) (:name set)) + (update-set-name form (get-name prev-set) (get-name set)) form)) themes)) active-themes)) @@ -888,15 +979,15 @@ Will return a value that matches this schema: (d/oupdate-in prefixed-to-path (fn [sets] (walk/prewalk (fn [form] - (if (instance? TokenSet form) - (update form :name #(str to-path-str (str/strip-prefix % from-path-str))) + (if (token-set? form) + (rename form (str to-path-str (str/strip-prefix (get-name form) from-path-str))) form)) sets))))) themes' (if reorder? themes (let [rename-sets-map (->> (get-sets-at-path this from-path) (map (fn [set] - [(:name set) (str to-path-str (str/strip-prefix (:name set) from-path-str))])) + [(get-name set) (str to-path-str (str/strip-prefix (get-name set) from-path-str))])) (into {}))] (walk/postwalk (fn [form] @@ -934,12 +1025,12 @@ Will return a value that matches this schema: sets (get-sets-at-path this path)] (reduce (fn [lib set] - (update-set lib (:name set) (fn [set'] - (update set' :name #(str to-path-str (str/strip-prefix % from-path-str)))))) + (update-set lib (get-name set) (fn [set'] + (rename set' (str to-path-str (str/strip-prefix (get-name set') from-path-str)))))) this sets))) (get-ordered-set-names [this] - (map :name (get-sets this))) + (map get-name (get-sets this))) (set-count [this] (count (get-sets this))) @@ -1080,7 +1171,7 @@ Will return a value that matches this schema: prefixed-path-str (set-group-path->set-group-prefixed-path-str group-path)] (if (seq active-set-names) (let [path-active-set-names (->> (get-sets-at-prefix-path this prefixed-path-str) - (map :name) + (map get-name) (into #{})) difference (set/difference path-active-set-names active-set-names)] (cond @@ -1095,7 +1186,7 @@ Will return a value that matches this schema: active-set-names (filter theme-set-names all-set-names) tokens (reduce (fn [tokens set-name] (let [set (get-set this set-name)] - (merge tokens (:tokens set)))) + (merge tokens (get-tokens-map set)))) (d/ordered-map) active-set-names)] tokens)) @@ -1160,11 +1251,10 @@ Will return a value that matches this schema: (defn duplicate-set [set-name lib & {:keys [suffix]}] (let [sets (get-sets lib) - unames (map :name sets) + unames (map get-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))))) + (rename copy-name)))) ;; === Import / Export from JSON format @@ -1473,8 +1563,10 @@ Will return a value that matches this schema: [tokens-lib] (let [{:keys [themes active-themes]} (dtcg-export-themes tokens-lib) sets (->> (get-sets tokens-lib) - (map (fn [{:keys [name tokens]}] - [(str name ".json") (tokens-tree tokens :update-token-fn token->dtcg-token)])) + (map (fn [token-set] + (let [name (get-name token-set) + tokens (get-tokens-map token-set)] + [(str name ".json") (tokens-tree tokens :update-token-fn token->dtcg-token)]))) (into {}))] (-> sets (assoc "$themes.json" themes) @@ -1491,8 +1583,9 @@ Will return a value that matches this schema: (->> (get-set-tree tokens-lib) (tree-seq d/ordered-map? vals) (filter (partial instance? TokenSet)) - (map (fn [{:keys [name tokens]}] - [name (tokens-tree tokens :update-token-fn token->dtcg-token)]))) + (map (fn [set] + [(get-name set) + (tokens-tree (get-tokens-map set) :update-token-fn token->dtcg-token)]))) ordered-set-names (mapv first name-set-tuples) @@ -1512,28 +1605,31 @@ Will return a value that matches this schema: (defn get-tokens-of-unknown-type "Search for all tokens in the decoded json file that have a type that is not currently supported by Penpot. Returns a map token-path -> token type." - ([decoded-json] - (get-tokens-of-unknown-type decoded-json "" (get-json-format decoded-json))) - ([decoded-json parent-path json-format] - (let [type-key (if (= json-format :json-format/dtcg) "$type" "type")] - (reduce-kv - (fn [unknown-tokens k v] - (let [child-path (if (empty? parent-path) - (name k) - (str parent-path "." k))] - (if (and (map? v) - (not (contains? v type-key))) - (let [nested-unknown-tokens (get-tokens-of-unknown-type v child-path json-format)] - (merge unknown-tokens nested-unknown-tokens)) - (let [token-type-str (get v type-key) - token-type (cto/dtcg-token-type->token-type token-type-str)] - (if (and (not (some? token-type)) (some? token-type-str)) - (assoc unknown-tokens child-path token-type-str) - unknown-tokens))))) - nil - decoded-json)))) + [decoded-json {:keys [json-format parent-path process-token-type] + :or {json-format (get-json-format decoded-json) + parent-path "" + process-token-type identity} + :as opts}] + (let [type-key (if (= json-format :json-format/dtcg) "$type" "type")] + (reduce-kv + (fn [unknown-tokens k v] + (let [child-path (if (empty? parent-path) + (name k) + (str parent-path "." k))] + (if (and (map? v) + (not (contains? v type-key))) + (let [nested-unknown-tokens (get-tokens-of-unknown-type v (assoc opts :parent-path child-path))] + (merge unknown-tokens nested-unknown-tokens)) + (let [token-type-str (get v type-key) + token-type (-> (cto/dtcg-token-type->token-type token-type-str) + (process-token-type))] + (if (and (not (some? token-type)) (some? token-type-str)) + (assoc unknown-tokens child-path token-type-str) + unknown-tokens))))) + nil + decoded-json))) -;; === Serialization handlers for RPC API (transit) and database (fressian) +;; === Serialization handlers for RPC API (transit) (t/add-handlers! {:id "penpot/tokens-lib" @@ -1543,8 +1639,8 @@ Will return a value that matches this schema: {:id "penpot/token-set" :class TokenSet - :wfn #(into {} %) - :rfn #(map->TokenSet %)} + :wfn deref + :rfn #(make-token-set %)} {:id "penpot/token-theme" :class TokenTheme @@ -1556,6 +1652,8 @@ Will return a value that matches this schema: :wfn #(into {} %) :rfn #(map->Token %)}) +;; === Serialization handlers for database (fressian) + #?(:clj (defn- read-tokens-lib-v1-0 "Reads the first version of tokens lib, now completly obsolete" @@ -1675,16 +1773,16 @@ Will return a value that matches this schema: (fres/write-object! w (into {} o))) :rfn (fn [r] (let [obj (fres/read-object! r)] - (map->Token obj)))} + (make-token obj)))} {:name "penpot/token-set/v1" :class TokenSet :wfn (fn [n w o] (fres/write-tag! w n 1) - (fres/write-object! w (into {} o))) + (fres/write-object! w (into {} (deref o)))) :rfn (fn [r] (let [obj (fres/read-object! r)] - (map->TokenSet obj)))} + (make-token-set obj)))} {:name "penpot/token-theme/v1" :class TokenTheme @@ -1693,7 +1791,7 @@ Will return a value that matches this schema: (fres/write-object! w (into {} o))) :rfn (fn [r] (let [obj (fres/read-object! r)] - (map->TokenTheme obj)))} + (make-token-theme obj)))} ;; LEGACY TOKENS LIB READERS (with migrations) {:name "penpot/tokens-lib/v1" diff --git a/common/src/app/common/types/typography.cljc b/common/src/app/common/types/typography.cljc index 155c958b10..fd172a8e4a 100644 --- a/common/src/app/common/types/typography.cljc +++ b/common/src/app/common/types/typography.cljc @@ -93,13 +93,16 @@ remap-typography content))))) +(defn remove-typography-from-node + "Remove the typography reference from a node." + [node] + (dissoc node :typography-ref-file :typography-ref-id)) + (defn remove-external-typographies "Change the shape so that any use of an external typography now is removed" [shape file-id] - (let [remove-ref-file #(dissoc % :typography-ref-file :typography-ref-id)] - - (update shape :content - (fn [content] - (txt/transform-nodes #(not= (:typography-ref-file %) file-id) - remove-ref-file - content))))) + (update shape :content + (fn [content] + (txt/transform-nodes #(not= (:typography-ref-file %) file-id) + remove-typography-from-node + content)))) diff --git a/common/src/app/common/types/variant.cljc b/common/src/app/common/types/variant.cljc index 9849a30e1a..2d6e1a2ce8 100644 --- a/common/src/app/common/types/variant.cljc +++ b/common/src/app/common/types/variant.cljc @@ -139,7 +139,6 @@ (< (count (first %)) property-max-length) (< (count (second %)) property-max-length))))) - (defn find-properties-to-remove "Compares two property maps to find which properties should be removed" [prev-props upd-props] @@ -161,6 +160,46 @@ (filterv #(not (contains? prev-names (:name %))) upd-props))) +(defn- split-base-name-and-number + "Extract the number in parentheses from an item, if present, and return both the base name and the number" + [item] + (let [pattern-num-parens #"\(\d+\)$" + pattern-num #"\d+" + base (-> item (str/replace pattern-num-parens "") (str/trim)) + num (some->> item (re-find pattern-num-parens) (re-find pattern-num) (d/parse-integer))] + [base (d/nilv num 0)])) + +(defn- group-numbers-by-base-name + "Return a map with a set of numbers associated to each base name" + [items] + (reduce (fn [acc item] + (let [[base num] (split-base-name-and-number item)] + (update acc base (fnil conj #{}) num))) + {} + items)) + +(defn update-number-in-repeated-item + "Add, keep or update a number in parentheses for a given item, if necessary, depending on the items + already present in a list, to avoid repetitions" + [items item] + (let [names (group-numbers-by-base-name items) + [base num] (split-base-name-and-number item) + nums-taken (get names base #{})] + (loop [n num] + (if (nums-taken n) + (recur (inc n)) + (str base (when (pos? n) (str " (" n ")"))))))) + +(defn update-number-in-repeated-prop-names + "Add, keep or update a number for each prop name depending on the previous ones" + [props] + (->> props + (reduce (fn [acc prop] + (conj acc {:name (update-number-in-repeated-item (mapv :name acc) (:name prop)) + :value (:value prop)})) + []))) + + (defn find-index-for-property-name "Finds the index of a name in a property map" [props name] diff --git a/common/test/common_tests/colors_test.cljc b/common/test/common_tests/colors_test.cljc index 89308415df..8c088b9dee 100644 --- a/common/test/common_tests/colors_test.cljc +++ b/common/test/common_tests/colors_test.cljc @@ -8,7 +8,6 @@ (:require #?(:cljs [goog.color :as gcolors]) [app.common.colors :as colors] - [app.common.data :as d] [clojure.test :as t])) (t/deftest valid-hex-color @@ -52,8 +51,8 @@ (t/is (= [1 2 3] (colors/hex->rgb "#010203")))) (t/deftest format-hsla - (t/is (= "210, 50%, 0.78%, 1" (colors/format-hsla [210.0 0.5 0.00784313725490196 1]))) - (t/is (= "220, 5%, 30%, 0.8" (colors/format-hsla [220.0 0.05 0.3 0.8])))) + (t/is (= "210 50% 0.78% / 1" (colors/format-hsla [210.0 0.5 0.00784313725490196 1]))) + (t/is (= "220 5% 30% / 0.8" (colors/format-hsla [220.0 0.05 0.3 0.8])))) (t/deftest format-rgba (t/is (= "210, 199, 12, 0.08" (colors/format-rgba [210 199 12 0.08]))) diff --git a/common/test/common_tests/logic/text_sync_test.cljc b/common/test/common_tests/logic/text_sync_test.cljc new file mode 100644 index 0000000000..3f1fb18c68 --- /dev/null +++ b/common/test/common_tests/logic/text_sync_test.cljc @@ -0,0 +1,881 @@ +;; 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.text-sync-test + (:require + [app.common.files.changes-builder :as pcb] + [app.common.logic.libraries :as cll] + [app.common.logic.shapes :as cls] + [app.common.test-helpers.components :as thc] + [app.common.test-helpers.compositions :as tho] + [app.common.test-helpers.files :as thf] + [app.common.test-helpers.ids-map :as thi] + [app.common.test-helpers.shapes :as ths] + [clojure.test :as t])) + +(t/use-fixtures :each thi/test-fixture) + + +(t/deftest test-sync-unchanged-copy-when-changed-attribute + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page (thf/current-page file) + main-child (ths/get-shape file :main-child) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :font-size] "32")) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + (t/is (= "32" (:font-size line))) + (t/is (= "hello world" (:text line))))) + +(t/deftest test-sync-unchanged-copy-when-changed-text + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page (thf/current-page file) + main-child (ths/get-shape file :main-child) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :text] "Bye")) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + (t/is (= "14" (:font-size line))) + (t/is (= "Bye" (:text line))))) + +(t/deftest test-sync-unchanged-copy-when-changed-both + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page (thf/current-page file) + main-child (ths/get-shape file :main-child) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + (-> shape + (assoc-in [:content :children 0 :children 0 :children 0 :font-size] "32") + (assoc-in [:content :children 0 :children 0 :children 0 :text] "Bye"))) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + (t/is (= "32" (:font-size line))) + (t/is (= "Bye" (:text line))))) + +(t/deftest test-sync-updated-attr-copy-when-changed-attribute + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :font-weight] "700")) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :font-size] "32")) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + ;; The attr doesn't change, because it was touched + (t/is (= "14" (:font-size line))) + (t/is (= "hello world" (:text line))))) + +(t/deftest test-sync-updated-attr-copy-when-changed-text + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :font-weight] "700")) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :text] "Bye")) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + (t/is (= "14" (:font-size line))) + ;; The text is updated because only attrs were touched + (t/is (= "Bye" (:text line))))) + +(t/deftest test-sync-updated-attr-copy-when-changed-both + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :font-weight] "700")) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + (-> shape + (assoc-in [:content :children 0 :children 0 :children 0 :font-size] "32") + (assoc-in [:content :children 0 :children 0 :children 0 :text] "Bye"))) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + ;; The attr doesn't change, because it was touched + (t/is (= "14" (:font-size line))) + ;; The text is updated because only attrs were touched + (t/is (= "Bye" (:text line))))) + +(t/deftest test-sync-updated-text-copy-when-changed-attribute + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :text] "Hi")) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :font-size] "32")) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + ;; The attr is updated because only text were touched + (t/is (= "32" (:font-size line))) + (t/is (= "Hi" (:text line))))) + +(t/deftest test-sync-updated-text-copy-when-changed-text + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :text] "Hi")) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :text] "Bye")) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + (t/is (= "14" (:font-size line))) + ;; The text doesn't change, because it was touched + (t/is (= "Hi" (:text line))))) + +(t/deftest test-sync-updated-text-copy-when-changed-both + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :text] "Hi")) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + (-> shape + (assoc-in [:content :children 0 :children 0 :children 0 :font-size] "32") + (assoc-in [:content :children 0 :children 0 :children 0 :text] "Bye"))) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + ;; The attr is updated because only text were touched + (t/is (= "32" (:font-size line))) + ;; The text doesn't change, because it was touched + (t/is (= "Hi" (:text line))))) + +(t/deftest test-sync-updated-both-copy-when-changed-attribute + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (-> shape + (assoc-in [:content :children 0 :children 0 :children 0 :font-weight] "700") + (assoc-in [:content :children 0 :children 0 :children 0 :text] "Hi"))) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :font-size] "32")) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + ;; The attr doesn't change, because it was touched + (t/is (= "14" (:font-size line))) + (t/is (= "Hi" (:text line))))) + +(t/deftest test-sync-updated-both-copy-when-changed-text + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (-> shape + (assoc-in [:content :children 0 :children 0 :children 0 :font-weight] "700") + (assoc-in [:content :children 0 :children 0 :children 0 :text] "Hi"))) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :text] "Bye")) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + (t/is (= "14" (:font-size line))) + ;; The text doesn't change, because it was touched + (t/is (= "Hi" (:text line))))) + +(t/deftest test-sync-updated-both-copy-when-changed-both + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (-> shape + (assoc-in [:content :children 0 :children 0 :children 0 :font-weight] "700") + (assoc-in [:content :children 0 :children 0 :children 0 :text] "Hi"))) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + (-> shape + (assoc-in [:content :children 0 :children 0 :children 0 :font-size] "32") + (assoc-in [:content :children 0 :children 0 :children 0 :text] "Bye"))) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + ;; The attr doesn't change, because it was touched + (t/is (= "14" (:font-size line))) + ;; The text doesn't change, because it was touched + (t/is (= "Hi" (:text line))))) + +(t/deftest test-sync-updated-structure-same-attrs-copy-when-changed-attribute + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (let [line (get-in shape [:content :children 0 :children 0 :children 0])] + (update-in shape [:content :children 0 :children 0 :children] + #(conj % line)))) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + ;; Update the attrs on all the content tree + (-> shape + (assoc-in [:content :children 0 :children 0 :children 0 :font-size] "32") + (assoc-in [:content :children 0 :children 0 :font-size] "32"))) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + ;; The attr is updated because all the attrs on the structure are equal + (t/is (= "32" (:font-size line))) + (t/is (= "hello world" (:text line))))) + +(t/deftest test-sync-updated-structure-same-attrs-copy-when-changed-text + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (let [line (get-in shape [:content :children 0 :children 0 :children 0])] + (update-in shape [:content :children 0 :children 0 :children] + #(conj % line)))) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :text] "Bye")) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + (t/is (= "14" (:font-size line))) + ;; The text doesn't change, because the structure was touched + (t/is (= "hello world" (:text line))))) + +(t/deftest test-sync-updated-structure-same-attrs-copy-when-changed-both + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (let [line (get-in shape [:content :children 0 :children 0 :children 0])] + (update-in shape [:content :children 0 :children 0 :children] + #(conj % line)))) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + ;; Update the attrs on all the content tree + (-> shape + (assoc-in [:content :children 0 :children 0 :children 0 :font-size] "32") + (assoc-in [:content :children 0 :children 0 :font-size] "32") + (assoc-in [:content :children 0 :children 0 :children 0 :text] "Bye"))) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + ;; The attr is updated because all the attrs on the structure are equal + (t/is (= "32" (:font-size line))) + ;; The text doesn't change, because the structure was touched + (t/is (= "hello world" (:text line))))) + +(t/deftest test-sync-updated-structure-diff-attrs-copy-when-changed-attribute + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (let [line (-> (get-in shape [:content :children 0 :children 0 :children 0]) + (assoc :font-weight "700"))] + (update-in shape [:content :children 0 :children 0 :children] + #(conj % line)))) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + ;; Update the attrs on all the content tree + (-> shape + (assoc-in [:content :children 0 :children 0 :children 0 :font-size] "32") + (assoc-in [:content :children 0 :children 0 :font-size] "32"))) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + ;; The attr doesn't change, because not all the attrs on the structure are equal + (t/is (= "14" (:font-size line))) + (t/is (= "hello world" (:text line))))) + +(t/deftest test-sync-updated-structure-diff-attrs-copy-when-changed-text + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (let [line (-> (get-in shape [:content :children 0 :children 0 :children 0]) + (assoc :font-weight "700"))] + (update-in shape [:content :children 0 :children 0 :children] + #(conj % line)))) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :children 0 :text] "Bye")) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + (t/is (= "14" (:font-size line))) + ;; The text doesn't change, because the structure was touched + (t/is (= "hello world" (:text line))))) + +(t/deftest test-sync-updated-structure-diff-attrs-copy-when-changed-both + (let [;; ==== Setup + file0 (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page0 (thf/current-page file0) + copy-child (ths/get-shape file0 :copy-child) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0)) + #{(:id copy-child)} + (fn [shape] + (let [line (-> (get-in shape [:content :children 0 :children 0 :children 0]) + (assoc :font-weight "700"))] + (update-in shape [:content :children 0 :children 0 :children] + #(conj % line)))) + (:objects (thf/current-page file0)) + {}) + file (thf/apply-changes file0 changes) + main-child (ths/get-shape file :main-child) + page (thf/current-page file) + + ;; ==== Action + changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id main-child)} + (fn [shape] + ;; Update the attrs on all the content tree + (-> shape + (assoc-in [:content :children 0 :children 0 :children 0 :font-size] "32") + (assoc-in [:content :children 0 :children 0 :font-size] "32") + (assoc-in [:content :children 0 :children 0 :children 0 :text] "Bye"))) + (:objects page) + {}) + + updated-file (thf/apply-changes file changes1) + + changes2 (cll/generate-sync-file-changes (pcb/empty-changes) + nil + :components + (:id updated-file) + (thi/id :component1) + (:id updated-file) + {(:id updated-file) updated-file} + (:id updated-file)) + + file' (thf/apply-changes updated-file changes2) + + ;; ==== Get + copy-child' (ths/get-shape file' :copy-child) + line (get-in copy-child' [:content :children 0 :children 0 :children 0])] + ;; The attr doesn't change, because not all the attrs on the structure are equal + (t/is (= "14" (:font-size line))) + ;; The text doesn't change, because the structure was touched + (t/is (= "hello world" (:text line))))) \ No newline at end of file diff --git a/common/test/common_tests/logic/text_touched_test.cljc b/common/test/common_tests/logic/text_touched_test.cljc new file mode 100644 index 0000000000..7aacf4fe52 --- /dev/null +++ b/common/test/common_tests/logic/text_touched_test.cljc @@ -0,0 +1,132 @@ +;; 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.text-touched-test + (:require + [app.common.files.changes-builder :as pcb] + [app.common.logic.shapes :as cls] + [app.common.test-helpers.components :as thc] + [app.common.test-helpers.compositions :as tho] + [app.common.test-helpers.files :as thf] + [app.common.test-helpers.ids-map :as thi] + [app.common.test-helpers.shapes :as ths] + [clojure.test :as t])) + +(t/use-fixtures :each thi/test-fixture) + +(t/deftest test-text-copy-changed-attribute + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page (thf/current-page file) + copy-child (ths/get-shape file :copy-child) + + ;; ==== Action + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id copy-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :font-size] "32")) + (:objects page) + {}) + + file' (thf/apply-changes file changes) + copy-child' (ths/get-shape file' :copy-child)] + (t/is (= #{:content-group :text-content-attribute} (:touched copy-child'))))) + +(t/deftest test-text-copy-changed-text + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page (thf/current-page file) + copy-child (ths/get-shape file :copy-child) + + ;; ==== Action + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id copy-child)} + (fn [shape] + (assoc-in shape [:content :children 0 :children 0 :text] "Bye")) + (:objects page) + {}) + + file' (thf/apply-changes file changes) + copy-child' (ths/get-shape file' :copy-child)] + (t/is (= #{:content-group :text-content-text} (:touched copy-child'))))) + +(t/deftest test-text-copy-changed-both + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page (thf/current-page file) + copy-child (ths/get-shape file :copy-child) + + ;; ==== Action + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id copy-child)} + (fn [shape] + (-> shape + (assoc-in [:content :children 0 :children 0 :font-size] "32") + (assoc-in [:content :children 0 :children 0 :text] "Bye"))) + (:objects page) + {}) + + file' (thf/apply-changes file changes) + copy-child' (ths/get-shape file' :copy-child)] + (t/is (= #{:content-group :text-content-attribute :text-content-text} (:touched copy-child'))))) + +(t/deftest test-text-copy-changed-structure-same-attrs + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page (thf/current-page file) + copy-child (ths/get-shape file :copy-child) + + ;; ==== Action + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id copy-child)} + (fn [shape] + (let [line (get-in shape [:content :children 0 :children 0])] + (update-in shape [:content :children 0 :children] + #(conj % line)))) + (:objects page) + {}) + + file' (thf/apply-changes file changes) + copy-child' (ths/get-shape file' :copy-child)] + (t/is (= #{:content-group :text-content-structure :text-content-structure-same-attrs} (:touched copy-child'))))) + +(t/deftest test-text-copy-changed-structure-diff-attrs + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (tho/add-frame-with-text :main-root :main-child "hello world") + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]})) + page (thf/current-page file) + copy-child (ths/get-shape file :copy-child) + + ;; ==== Action + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id copy-child)} + (fn [shape] + (let [line (-> shape + (get-in [:content :children 0 :children 0]) + (assoc :font-size "32"))] + (update-in shape [:content :children 0 :children] + #(conj % line)))) + (:objects page) + {}) + + file' (thf/apply-changes file changes) + copy-child' (ths/get-shape file' :copy-child)] + (t/is (= #{:content-group :text-content-structure} (:touched copy-child'))))) + diff --git a/common/test/common_tests/logic/token_apply_test.cljc b/common/test/common_tests/logic/token_apply_test.cljc index 8b028e5ebf..384f534e8a 100644 --- a/common/test/common_tests/logic/token_apply_test.cljc +++ b/common/test/common_tests/logic/token_apply_test.cljc @@ -54,9 +54,17 @@ (ctob/add-token-in-set "test-token-set" (ctob/make-token :name "token-dimensions" :type :dimensions - :value 100)))) + :value 100)) + (ctob/add-token-in-set "test-token-set" + (ctob/make-token :name "token-font-size" + :type :font-size + :value 24)) + (ctob/add-token-in-set "test-token-set" + (ctob/make-token :name "token-letter-spacing" + :type :letter-spacing + :value 2)))) (tho/add-frame :frame1) - (tho/add-text :text1 "Hello World"))) + (tho/add-text :text1 "Hello World!"))) (defn- apply-all-tokens [file] @@ -68,19 +76,23 @@ (tht/apply-token-to-shape :frame1 "token-color" [:stroke-color] [:stroke-color] "#00ff00") (tht/apply-token-to-shape :frame1 "token-color" [:fill] [:fill] "#00ff00") (tht/apply-token-to-shape :frame1 "token-dimensions" [:width :height] [:width :height] 100) - (tht/apply-token-to-shape :text1 "token-color" [:fill] [:fill] "#00ff00"))) + (tht/apply-token-to-shape :text1 "token-font-size" [:font-size] [:font-size] 24) + (tht/apply-token-to-shape :text1 "token-letter-spacing" [:letter-spacing] [:letter-spacing] 2))) (t/deftest apply-tokens-to-shape (let [;; ==== Setup file (setup-file) page (thf/current-page file) frame1 (ths/get-shape file :frame1) + text1 (ths/get-shape file :text1) token-radius (tht/get-token file "test-token-set" "token-radius") token-rotation (tht/get-token file "test-token-set" "token-rotation") token-opacity (tht/get-token file "test-token-set" "token-opacity") token-stroke-width (tht/get-token file "test-token-set" "token-stroke-width") token-color (tht/get-token file "test-token-set" "token-color") token-dimensions (tht/get-token file "test-token-set" "token-dimensions") + token-font-size (tht/get-token file "test-token-set" "token-font-size") + token-letter-spacing (tht/get-token file "test-token-set" "token-letter-spacing") ;; ==== Action changes (-> (-> (pcb/empty-changes nil) @@ -89,38 +101,48 @@ (cls/generate-update-shapes [(:id frame1)] (fn [shape] (as-> shape $ - (cto/maybe-apply-token-to-shape {:token nil ; test nil case - :shape $ - :attributes []}) - (cto/maybe-apply-token-to-shape {:token token-radius - :shape $ - :attributes [:r1 :r2 :r3 :r4]}) - (cto/maybe-apply-token-to-shape {:token token-rotation - :shape $ - :attributes [:rotation]}) - (cto/maybe-apply-token-to-shape {:token token-opacity - :shape $ - :attributes [:opacity]}) - (cto/maybe-apply-token-to-shape {:token token-stroke-width - :shape $ - :attributes [:stroke-width]}) - (cto/maybe-apply-token-to-shape {:token token-color - :shape $ - :attributes [:stroke-color]}) - (cto/maybe-apply-token-to-shape {:token token-color - :shape $ - :attributes [:fill]}) - (cto/maybe-apply-token-to-shape {:token token-dimensions - :shape $ - :attributes [:width :height]}))) + (cto/apply-token-to-shape {:token token-radius + :shape $ + :attributes [:r1 :r2 :r3 :r4]}) + (cto/apply-token-to-shape {:token token-rotation + :shape $ + :attributes [:rotation]}) + (cto/apply-token-to-shape {:token token-opacity + :shape $ + :attributes [:opacity]}) + (cto/apply-token-to-shape {:token token-stroke-width + :shape $ + :attributes [:stroke-width]}) + (cto/apply-token-to-shape {:token token-color + :shape $ + :attributes [:stroke-color]}) + (cto/apply-token-to-shape {:token token-color + :shape $ + :attributes [:fill]}) + (cto/apply-token-to-shape {:token token-dimensions + :shape $ + :attributes [:width :height]}))) + (:objects page) + {}) + (cls/generate-update-shapes [(:id text1)] + (fn [shape] + (as-> shape $ + (cto/apply-token-to-shape {:token token-font-size + :shape $ + :attributes [:font-size]}) + (cto/apply-token-to-shape {:token token-letter-spacing + :shape $ + :attributes [:letter-spacing]}))) (:objects page) {})) file' (thf/apply-changes file changes) ;; ==== Get - frame1' (ths/get-shape file' :frame1) - applied-tokens' (:applied-tokens frame1')] + frame1' (ths/get-shape file' :frame1) + applied-tokens' (:applied-tokens frame1') + text1' (ths/get-shape file' :text1) + text1-applied-tokens (:applied-tokens text1')] ;; ==== Check (t/is (= (count applied-tokens') 11)) @@ -134,7 +156,10 @@ (t/is (= (:stroke-color applied-tokens') "token-color")) (t/is (= (:fill applied-tokens') "token-color")) (t/is (= (:width applied-tokens') "token-dimensions")) - (t/is (= (:height applied-tokens') "token-dimensions")))) + (t/is (= (:height applied-tokens') "token-dimensions")) + (t/is (= (count text1-applied-tokens) 2)) + (t/is (= (:font-size text1-applied-tokens) "token-font-size")) + (t/is (= (:letter-spacing text1-applied-tokens) "token-letter-spacing")))) (t/deftest unapply-tokens-from-shape (let [;; ==== Setup @@ -142,6 +167,7 @@ (apply-all-tokens)) page (thf/current-page file) frame1 (ths/get-shape file :frame1) + text1 (ths/get-shape file :text1) ;; ==== Action changes (-> (-> (pcb/empty-changes nil) @@ -158,16 +184,26 @@ (cto/unapply-token-id [:fill]) (cto/unapply-token-id [:width :height]))) (:objects page) + {}) + (cls/generate-update-shapes [(:id text1)] + (fn [shape] + (-> shape + (cto/unapply-token-id [:font-size]) + (cto/unapply-token-id [:letter-spacing]))) + (:objects page) {})) file' (thf/apply-changes file changes) ;; ==== Get - frame1' (ths/get-shape file' :frame1) - applied-tokens' (:applied-tokens frame1')] + frame1' (ths/get-shape file' :frame1) + applied-tokens' (:applied-tokens frame1') + text1' (ths/get-shape file' :text1) + text1-applied-tokens (:applied-tokens text1')] ;; ==== Check - (t/is (= (count applied-tokens') 0)))) + (t/is (= (count applied-tokens') 0)) + (t/is (= (count text1-applied-tokens) 0)))) (t/deftest unapply-tokens-automatic (let [;; ==== Setup @@ -202,7 +238,9 @@ shape txt/is-content-node? d/txt-merge - {:fills (ths/sample-fills-color :fill-color "#fabada")})) + {:fills (ths/sample-fills-color :fill-color "#fabada") + :font-size "1" + :letter-spacing "0"})) (:objects page) {})) @@ -216,4 +254,4 @@ ;; ==== Check (t/is (= (count applied-tokens-frame') 0)) - (t/is (= (count applied-tokens-text') 0)))) \ No newline at end of file + (t/is (= (count applied-tokens-text') 0)))) diff --git a/common/test/common_tests/logic/token_test.cljc b/common/test/common_tests/logic/token_test.cljc index 800ad4111f..e4cec8becf 100644 --- a/common/test/common_tests/logic/token_test.cljc +++ b/common/test/common_tests/logic/token_test.cljc @@ -269,8 +269,7 @@ new-set-name "foo1" changes (-> (pcb/empty-changes) (pcb/with-library-data (:data file)) - (pcb/set-token-set set-name false (assoc prev-token-set - :name new-set-name))) + (pcb/set-token-set set-name false (ctob/rename prev-token-set new-set-name))) redo (thf/apply-changes file changes) redo-lib (tht/get-tokens-lib redo) undo (thf/apply-undo-changes redo changes) diff --git a/common/test/common_tests/logic/variants_switch_test.cljc b/common/test/common_tests/logic/variants_switch_test.cljc new file mode 100644 index 0000000000..bd06cbde6d --- /dev/null +++ b/common/test/common_tests/logic/variants_switch_test.cljc @@ -0,0 +1,1125 @@ +;; 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.variants-switch-test + (:require + [app.common.files.changes-builder :as pcb] + [app.common.logic.shapes :as cls] + [app.common.test-helpers.components :as thc] + [app.common.test-helpers.compositions :as tho] + [app.common.test-helpers.files :as thf] + [app.common.test-helpers.ids-map :as thi] + [app.common.test-helpers.shapes :as ths] + [app.common.test-helpers.variants :as thv] + [clojure.test :as t])) + +(t/use-fixtures :each thi/test-fixture) + +(t/deftest test-simple-switch + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (thv/add-variant-with-child + :v01 :c01 :m01 :c02 :m02 :r01 :r02 + {:child1-params {:width 5} + :child2-params {:width 15}}) + + (thc/instantiate-component :c01 + :copy01 + :children-labels [:copy-r01])) + + page (thf/current-page file) + copy01 (ths/get-shape file :copy01) + rect01 (get-in page [:objects (-> copy01 :shapes first)]) + + ;; ==== Action + file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true}) + + page' (thf/current-page file') + copy02' (ths/get-shape file' :copy02) + rect02' (get-in page' [:objects (-> copy02' :shapes first)])] + ;; The rect had width 5 before the switch + (t/is (= (:width rect01) 5)) + ;; The rect has width 15 after the switch + (t/is (= (:width rect02') 15)))) + + +(t/deftest test-switch-with-override + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (thv/add-variant-with-child + :v01 :c01 :m01 :c02 :m02 :r01 :r02 + {:child1-params {:width 5} + :child2-params {:width 5}}) + + (thc/instantiate-component :c01 + :copy01 + :children-labels [:copy-r01])) + + page (thf/current-page file) + copy01 (ths/get-shape file :copy01) + rect01 (get-in page [:objects (-> copy01 :shapes first)]) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id rect01)} + (fn [shape] + (assoc shape :width 25)) + (:objects page) + {}) + + file (thf/apply-changes file changes) + page (thf/current-page file) + rect01 (get-in page [:objects (:id rect01)]) + + ;; ==== Action + file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true}) + + page' (thf/current-page file') + copy02' (ths/get-shape file' :copy02) + rect02' (get-in page' [:objects (-> copy02' :shapes first)])] + + ;; The rect had width 25 before the switch + (t/is (= (:width rect01) 25)) + ;; The override is keept: The rect still has width 25 after the switch + (t/is (= (:width rect02') 25)))) + +(t/deftest test-switch-with-no-override + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (thv/add-variant-with-child + :v01 :c01 :m01 :c02 :m02 :r01 :r02 + {:child1-params {:width 5} + :child2-params {:width 15}}) + + (thc/instantiate-component :c01 + :copy01 + :children-labels [:copy-r01])) + + page (thf/current-page file) + copy01 (ths/get-shape file :copy01) + rect01 (get-in page [:objects (-> copy01 :shapes first)]) + + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id rect01)} + (fn [shape] + (assoc shape :width 25)) + (:objects page) + {}) + + file (thf/apply-changes file changes) + page (thf/current-page file) + rect01 (get-in page [:objects (:id rect01)]) + + ;; ==== Action + file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true}) + + page' (thf/current-page file') + copy02' (ths/get-shape file' :copy02) + rect02' (get-in page' [:objects (-> copy02' :shapes first)])] + + ;; The rect had width 25 before the switch + (t/is (= (:width rect01) 25)) + ;; The override isn't keept, because the property is different in the mains + ;; The rect has width 15 after the switch + (t/is (= (:width rect02') 15)))) + + +(def font-size-path-paragraph [:content :children 0 :children 0 :font-size]) +(def font-size-path-0 [:content :children 0 :children 0 :children 0 :font-size]) +(def font-size-path-1 [:content :children 0 :children 0 :children 1 :font-size]) + + +(def text-path-0 [:content :children 0 :children 0 :children 0 :text]) +(def text-path-1 [:content :children 0 :children 0 :children 1 :text]) +(def text-lines-path [:content :children 0 :children 0 :children]) + +(defn- update-attr + [file label path value] + (let [page (thf/current-page file) + shape (ths/get-shape file label) + changes (cls/generate-update-shapes + (pcb/empty-changes nil (:id page)) + #{(:id shape)} + (fn [shape] + (cond-> (assoc-in shape path value) + (or (= path font-size-path-0) (= path font-size-path-1)) + (assoc-in font-size-path-paragraph value))) + (:objects page) + {})] + (thf/apply-changes file changes))) + +(defn- change-structure + [file label] + (let [page (thf/current-page file) + shape (ths/get-shape file label) + line1 (-> (get-in shape text-lines-path) + first + (assoc :text "new line 1")) + line2 (assoc line1 :text "new line 2") + changes (cls/generate-update-shapes + (pcb/empty-changes nil (:id page)) + #{(:id shape)} + (fn [shape] + (assoc-in shape text-lines-path [line1 line2])) + (:objects page) + {})] + (thf/apply-changes file changes))) + +(t/deftest test-switch-with-identical-text-override + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + ;; Both components are identical: have the same text and props + (thv/add-variant-with-text + :v01 :c01 :m01 :c02 :m02 :t01 :t02 "hello world" "hello world") + (thc/instantiate-component :c01 + :copy-clean + :children-labels [:copy-clean-t]) + (thc/instantiate-component :c01 + :copy-font-size + :children-labels [:copy-font-size-t]) + (thc/instantiate-component :c01 + :copy-text + :children-labels [:copy-text-t]) + (thc/instantiate-component :c01 + :copy-both + :children-labels [:copy-both-t])) + + + ;; The copy clean has no overrides + copy-clean (ths/get-shape file :copy-clean) + copy-clean-t (ths/get-shape file :copy-clean-t) + + ;; Override font size on copy-font-size + file (update-attr file :copy-font-size-t font-size-path-0 "25") + copy-font-size (ths/get-shape file :copy-font-size) + copy-font-size-t (ths/get-shape file :copy-font-size-t) + + ;; Override text on copy-text + file (update-attr file :copy-text-t text-path-0 "text overriden") + copy-text (ths/get-shape file :copy-text) + copy-text-t (ths/get-shape file :copy-text-t) + + ;; Override both on copy-both + file (update-attr file :copy-both-t font-size-path-0 "25") + file (update-attr file :copy-both-t text-path-0 "text overriden") + copy-both (ths/get-shape file :copy-both) + copy-both-t (ths/get-shape file :copy-both-t) + + + ;; ==== Action: Switch all the copies + file' (-> file + (tho/swap-component copy-clean :c02 {:new-shape-label :copy-clean-2 :keep-touched? true}) + (tho/swap-component copy-font-size :c02 {:new-shape-label :copy-font-size-2 :keep-touched? true}) + (tho/swap-component copy-text :c02 {:new-shape-label :copy-text-2 :keep-touched? true}) + (tho/swap-component copy-both :c02 {:new-shape-label :copy-both-2 :keep-touched? true})) + page' (thf/current-page file') + copy-clean' (ths/get-shape file' :copy-clean-2) + copy-clean-t' (get-in page' [:objects (-> copy-clean' :shapes first)]) + + copy-font-size' (ths/get-shape file' :copy-font-size-2) + copy-font-size-t' (get-in page' [:objects (-> copy-font-size' :shapes first)]) + + copy-text' (ths/get-shape file' :copy-text-2) + copy-text-t' (get-in page' [:objects (-> copy-text' :shapes first)]) + + copy-both' (ths/get-shape file' :copy-both-2) + copy-both-t' (get-in page' [:objects (-> copy-both' :shapes first)])] + + (thf/dump-file file' {:keys [:name #_:content]}) + + + ;;;;;;;;;;; Clean copy + ;; Before the switch: + ;; * font size 14 + ;; * text "hello world" + (t/is (= (get-in copy-clean-t font-size-path-0) "14")) + (t/is (= (get-in copy-clean-t text-path-0) "hello world")) + + ;; After the switch: + ;; * font size 25 (value of c02, because there was no override) + ;; * text "hello world" (value of c02, because there was no override) + (t/is (= (get-in copy-clean-t' font-size-path-0) "14")) + (t/is (= (get-in copy-clean-t' text-path-0) "hello world")) + + + ;;;;;;;;;;; Font size copy + ;; Before the switch: + ;; * font size 25 + ;; * text "hello world" + (t/is (= (get-in copy-font-size-t font-size-path-0) "25")) + (t/is (= (get-in copy-font-size-t text-path-0) "hello world")) + + ;; After the switch: + ;; * font size 25 (the override is preserved) + ;; * text "hello world" (value of c02, because there was no override) + (t/is (= (get-in copy-font-size-t' font-size-path-0) "25")) + (t/is (= (get-in copy-font-size-t' text-path-0) "hello world")) + + ;;;;;;;;;;; Text copy + ;; Before the switch: + ;; * font size 14 + ;; * text "text overriden" + (t/is (= (get-in copy-text-t font-size-path-0) "14")) + (t/is (= (get-in copy-text-t text-path-0) "text overriden")) + + ;; After the switch: + ;; * font size 14 (value of c02, because there was no override) + ;; * text "text overriden" (the override is preserved) + (t/is (= (get-in copy-text-t' font-size-path-0) "14")) + (t/is (= (get-in copy-text-t' text-path-0) "text overriden")) + + ;;;;;;;;;;; Both copy + ;; Before the switch: + ;; * font size 25 + ;; * text "text overriden" + (t/is (= (get-in copy-both-t font-size-path-0) "25")) + (t/is (= (get-in copy-both-t text-path-0) "text overriden")) + + ;; After the switch: + ;; * font size 25 (the override is preserved) + ;; * text "text overriden" (the override is preserved) + (t/is (= (get-in copy-both-t' font-size-path-0) "25")) + (t/is (= (get-in copy-both-t' text-path-0) "text overriden")))) + +(t/deftest test-switch-with-different-prop-text-override + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + ;; The second component has a different prop + (thv/add-variant-with-text + :v01 :c01 :m01 :c02 :m02 :t01 :t02 "hello world" "hello world") + (update-attr :t02 font-size-path-0 "50") + + (thc/instantiate-component :c01 + :copy-clean + :children-labels [:copy-clean-t]) + (thc/instantiate-component :c01 + :copy-font-size + :children-labels [:copy-font-size-t]) + (thc/instantiate-component :c01 + :copy-text + :children-labels [:copy-text-t]) + (thc/instantiate-component :c01 + :copy-both + :children-labels [:copy-both-t])) + + + ;; The copy clean has no overrides + copy-clean (ths/get-shape file :copy-clean) + copy-clean-t (ths/get-shape file :copy-clean-t) + + ;; Override font size on copy-font-size + file (update-attr file :copy-font-size-t font-size-path-0 "25") + copy-font-size (ths/get-shape file :copy-font-size) + copy-font-size-t (ths/get-shape file :copy-font-size-t) + + ;; Override text on copy-text + file (update-attr file :copy-text-t text-path-0 "text overriden") + copy-text (ths/get-shape file :copy-text) + copy-text-t (ths/get-shape file :copy-text-t) + + ;; Override both on copy-both + file (update-attr file :copy-both-t font-size-path-0 "25") + file (update-attr file :copy-both-t text-path-0 "text overriden") + copy-both (ths/get-shape file :copy-both) + copy-both-t (ths/get-shape file :copy-both-t) + + + ;; ==== Action: Switch all the copies + file' (-> file + (tho/swap-component copy-clean :c02 {:new-shape-label :copy-clean-2 :keep-touched? true}) + (tho/swap-component copy-font-size :c02 {:new-shape-label :copy-font-size-2 :keep-touched? true}) + (tho/swap-component copy-text :c02 {:new-shape-label :copy-text-2 :keep-touched? true}) + (tho/swap-component copy-both :c02 {:new-shape-label :copy-both-2 :keep-touched? true})) + page' (thf/current-page file') + copy-clean' (ths/get-shape file' :copy-clean-2) + copy-clean-t' (get-in page' [:objects (-> copy-clean' :shapes first)]) + + copy-font-size' (ths/get-shape file' :copy-font-size-2) + copy-font-size-t' (get-in page' [:objects (-> copy-font-size' :shapes first)]) + + copy-text' (ths/get-shape file' :copy-text-2) + copy-text-t' (get-in page' [:objects (-> copy-text' :shapes first)]) + + copy-both' (ths/get-shape file' :copy-both-2) + copy-both-t' (get-in page' [:objects (-> copy-both' :shapes first)])] + + (thf/dump-file file' {:keys [:name #_:content]}) + + + ;;;;;;;;;;; Clean copy + ;; Before the switch: + ;; * font size 14 + ;; * text "hello world" + (t/is (= (get-in copy-clean-t font-size-path-0) "14")) + (t/is (= (get-in copy-clean-t text-path-0) "hello world")) + + ;; After the switch: + ;; * font size 50 (value of c02, because there was no override) + ;; * text "hello world" (value of c02, because there was no override) + (t/is (= (get-in copy-clean-t' font-size-path-0) "50")) + (t/is (= (get-in copy-clean-t' text-path-0) "hello world")) + + + ;;;;;;;;;;; Font size copy + ;; Before the switch: + ;; * font size 25 + ;; * text "hello world" + (t/is (= (get-in copy-font-size-t font-size-path-0) "25")) + (t/is (= (get-in copy-font-size-t text-path-0) "hello world")) + + ;; After the switch: + ;; * font size 50 (value of c02: the override is not preserved) + ;; * text "hello world" (value of c02, because there was no override) + (t/is (= (get-in copy-font-size-t' font-size-path-0) "50")) + (t/is (= (get-in copy-font-size-t' text-path-0) "hello world")) + + ;;;;;;;;;;; Text copy + ;; Before the switch: + ;; * font size 14 + ;; * text "text overriden" + (t/is (= (get-in copy-text-t font-size-path-0) "14")) + (t/is (= (get-in copy-text-t text-path-0) "text overriden")) + + ;; After the switch: + ;; * font size 50 (value of c02, because there was no override) + ;; * text "text overriden" (the override is preserved) + (t/is (= (get-in copy-text-t' font-size-path-0) "50")) + (t/is (= (get-in copy-text-t' text-path-0) "text overriden")) + + ;;;;;;;;;;; Both copy + ;; Before the switch: + ;; * font size 25 + ;; * text "text overriden" + (t/is (= (get-in copy-both-t font-size-path-0) "25")) + (t/is (= (get-in copy-both-t text-path-0) "text overriden")) + + ;; After the switch: + ;; * font size 50 (value of c02: the override is not preserved) + ;; * text "text overriden" (the override is preserved) + (t/is (= (get-in copy-both-t' font-size-path-0) "50")) + (t/is (= (get-in copy-both-t' text-path-0) "text overriden")))) + + +(t/deftest test-switch-with-different-text-text-override + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + ;; Second comp has different text + (thv/add-variant-with-text + :v01 :c01 :m01 :c02 :m02 :t01 :t02 "hello world" "bye") + (thc/instantiate-component :c01 + :copy-clean + :children-labels [:copy-clean-t]) + (thc/instantiate-component :c01 + :copy-font-size + :children-labels [:copy-font-size-t]) + (thc/instantiate-component :c01 + :copy-text + :children-labels [:copy-text-t]) + (thc/instantiate-component :c01 + :copy-both + :children-labels [:copy-both-t])) + + + ;; The copy clean has no overrides + copy-clean (ths/get-shape file :copy-clean) + copy-clean-t (ths/get-shape file :copy-clean-t) + + ;; Override font size on copy-font-size + file (update-attr file :copy-font-size-t font-size-path-0 "25") + copy-font-size (ths/get-shape file :copy-font-size) + copy-font-size-t (ths/get-shape file :copy-font-size-t) + + ;; Override text on copy-text + file (update-attr file :copy-text-t text-path-0 "text overriden") + copy-text (ths/get-shape file :copy-text) + copy-text-t (ths/get-shape file :copy-text-t) + + ;; Override both on copy-both + file (update-attr file :copy-both-t font-size-path-0 "25") + file (update-attr file :copy-both-t text-path-0 "text overriden") + copy-both (ths/get-shape file :copy-both) + copy-both-t (ths/get-shape file :copy-both-t) + + + ;; ==== Action: Switch all the copies + file' (-> file + (tho/swap-component copy-clean :c02 {:new-shape-label :copy-clean-2 :keep-touched? true}) + (tho/swap-component copy-font-size :c02 {:new-shape-label :copy-font-size-2 :keep-touched? true}) + (tho/swap-component copy-text :c02 {:new-shape-label :copy-text-2 :keep-touched? true}) + (tho/swap-component copy-both :c02 {:new-shape-label :copy-both-2 :keep-touched? true})) + page' (thf/current-page file') + copy-clean' (ths/get-shape file' :copy-clean-2) + copy-clean-t' (get-in page' [:objects (-> copy-clean' :shapes first)]) + + copy-font-size' (ths/get-shape file' :copy-font-size-2) + copy-font-size-t' (get-in page' [:objects (-> copy-font-size' :shapes first)]) + + copy-text' (ths/get-shape file' :copy-text-2) + copy-text-t' (get-in page' [:objects (-> copy-text' :shapes first)]) + + copy-both' (ths/get-shape file' :copy-both-2) + copy-both-t' (get-in page' [:objects (-> copy-both' :shapes first)])] + + (thf/dump-file file' {:keys [:name #_:content]}) + + + ;;;;;;;;;;; Clean copy + ;; Before the switch: + ;; * font size 14 + ;; * text "hello world" + (t/is (= (get-in copy-clean-t font-size-path-0) "14")) + (t/is (= (get-in copy-clean-t text-path-0) "hello world")) + + ;; After the switch: + ;; * font size 25 (value of c02, because there was no override) + ;; * text "bye" (value of c02, because there was no override) + (t/is (= (get-in copy-clean-t' font-size-path-0) "14")) + (t/is (= (get-in copy-clean-t' text-path-0) "bye")) + + + ;;;;;;;;;;; Font size copy + ;; Before the switch: + ;; * font size 25 + ;; * text "hello world" + (t/is (= (get-in copy-font-size-t font-size-path-0) "25")) + (t/is (= (get-in copy-font-size-t text-path-0) "hello world")) + + ;; After the switch: + ;; * font size 25 (the override is preserved) + ;; * text "bye" (value of c02, because there was no override) + (t/is (= (get-in copy-font-size-t' font-size-path-0) "25")) + (t/is (= (get-in copy-font-size-t' text-path-0) "bye")) + + ;;;;;;;;;;; Text copy + ;; Before the switch: + ;; * font size 14 + ;; * text "text overriden" + (t/is (= (get-in copy-text-t font-size-path-0) "14")) + (t/is (= (get-in copy-text-t text-path-0) "text overriden")) + + ;; After the switch: + ;; * font size 14 (value of c02, because there was no override) + ;; * text "text overriden" (value of c02: the override is not preserved) + (t/is (= (get-in copy-text-t' font-size-path-0) "14")) + (t/is (= (get-in copy-text-t' text-path-0) "bye")) + + ;;;;;;;;;;; Both copy + ;; Before the switch: + ;; * font size 25 + ;; * text "text overriden" + (t/is (= (get-in copy-both-t font-size-path-0) "25")) + (t/is (= (get-in copy-both-t text-path-0) "text overriden")) + + ;; After the switch: + ;; * font size 25 (the override is preserved) + ;; * text "text overriden" (value of c02: the override is not preserved) + (t/is (= (get-in copy-both-t' font-size-path-0) "25")) + (t/is (= (get-in copy-both-t' text-path-0) "bye")))) + + +(t/deftest test-switch-with-different-text-and-prop-text-override + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + ;; The second component has a different text and prop + (thv/add-variant-with-text + :v01 :c01 :m01 :c02 :m02 :t01 :t02 "hello world" "bye") + (update-attr :t02 font-size-path-0 "50") + + (thc/instantiate-component :c01 + :copy-clean + :children-labels [:copy-clean-t]) + (thc/instantiate-component :c01 + :copy-font-size + :children-labels [:copy-font-size-t]) + (thc/instantiate-component :c01 + :copy-text + :children-labels [:copy-text-t]) + (thc/instantiate-component :c01 + :copy-both + :children-labels [:copy-both-t])) + + + ;; The copy clean has no overrides + copy-clean (ths/get-shape file :copy-clean) + copy-clean-t (ths/get-shape file :copy-clean-t) + + ;; Override font size on copy-font-size + file (update-attr file :copy-font-size-t font-size-path-0 "25") + copy-font-size (ths/get-shape file :copy-font-size) + copy-font-size-t (ths/get-shape file :copy-font-size-t) + + ;; Override text on copy-text + file (update-attr file :copy-text-t text-path-0 "text overriden") + copy-text (ths/get-shape file :copy-text) + copy-text-t (ths/get-shape file :copy-text-t) + + ;; Override both on copy-both + file (update-attr file :copy-both-t font-size-path-0 "25") + file (update-attr file :copy-both-t text-path-0 "text overriden") + copy-both (ths/get-shape file :copy-both) + copy-both-t (ths/get-shape file :copy-both-t) + + + ;; ==== Action: Switch all the copies + file' (-> file + (tho/swap-component copy-clean :c02 {:new-shape-label :copy-clean-2 :keep-touched? true}) + (tho/swap-component copy-font-size :c02 {:new-shape-label :copy-font-size-2 :keep-touched? true}) + (tho/swap-component copy-text :c02 {:new-shape-label :copy-text-2 :keep-touched? true}) + (tho/swap-component copy-both :c02 {:new-shape-label :copy-both-2 :keep-touched? true})) + page' (thf/current-page file') + copy-clean' (ths/get-shape file' :copy-clean-2) + copy-clean-t' (get-in page' [:objects (-> copy-clean' :shapes first)]) + + copy-font-size' (ths/get-shape file' :copy-font-size-2) + copy-font-size-t' (get-in page' [:objects (-> copy-font-size' :shapes first)]) + + copy-text' (ths/get-shape file' :copy-text-2) + copy-text-t' (get-in page' [:objects (-> copy-text' :shapes first)]) + + copy-both' (ths/get-shape file' :copy-both-2) + copy-both-t' (get-in page' [:objects (-> copy-both' :shapes first)])] + + (thf/dump-file file' {:keys [:name #_:content]}) + + + ;;;;;;;;;;; Clean copy + ;; Before the switch: + ;; * font size 14 + ;; * text "hello world" + (t/is (= (get-in copy-clean-t font-size-path-0) "14")) + (t/is (= (get-in copy-clean-t text-path-0) "hello world")) + + ;; After the switch: + ;; * font size 50 (value of c02, because there was no override) + ;; * text "bye" (value of c02, because there was no override) + (t/is (= (get-in copy-clean-t' font-size-path-0) "50")) + (t/is (= (get-in copy-clean-t' text-path-0) "bye")) + + + ;;;;;;;;;;; Font size copy + ;; Before the switch: + ;; * font size 25 + ;; * text "hello world" + (t/is (= (get-in copy-font-size-t font-size-path-0) "25")) + (t/is (= (get-in copy-font-size-t text-path-0) "hello world")) + + ;; After the switch: + ;; * font size 50 (value of c02: the override is not preserved) + ;; * text "bye" (value of c02, because there was no override) + (t/is (= (get-in copy-font-size-t' font-size-path-0) "50")) + (t/is (= (get-in copy-font-size-t' text-path-0) "bye")) + + ;;;;;;;;;;; Text copy + ;; Before the switch: + ;; * font size 14 + ;; * text "text overriden" + (t/is (= (get-in copy-text-t font-size-path-0) "14")) + (t/is (= (get-in copy-text-t text-path-0) "text overriden")) + + ;; After the switch: + ;; * font size 50 (value of c02, because there was no override) + ;; * text "bye" (value of c02: the override is not preserved) + (t/is (= (get-in copy-text-t' font-size-path-0) "50")) + (t/is (= (get-in copy-text-t' text-path-0) "bye")) + + ;;;;;;;;;;; Both copy + ;; Before the switch: + ;; * font size 25 + ;; * text "text overriden" + (t/is (= (get-in copy-both-t font-size-path-0) "25")) + (t/is (= (get-in copy-both-t text-path-0) "text overriden")) + + ;; After the switch: + ;; * font size 50 (value of c02: the override is not preserved) + ;; * text "bye" (value of c02: the override is not preserved) + (t/is (= (get-in copy-both-t' font-size-path-0) "50")) + (t/is (= (get-in copy-both-t' text-path-0) "bye")))) + + +(t/deftest test-switch-with-identical-structure-text-override + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + ;; Both components are identical: have the same text and props + (thv/add-variant-with-text + :v01 :c01 :m01 :c02 :m02 :t01 :t02 "hello world" "hello world") + (thc/instantiate-component :c01 + :copy-structure-clean + :children-labels [:copy-structure-clean-t]) + (thc/instantiate-component :c01 + :copy-structure-unif + :children-labels [:copy-structure-unif-t]) + (thc/instantiate-component :c01 + :copy-structure-mixed + :children-labels [:copy-structure-mixed-t])) + + + + ;; Duplicate a text line in copy-structure-clean + file (change-structure file :copy-structure-clean-t) + copy-structure-clean (ths/get-shape file :copy-structure-clean) + copy-structure-clean-t (ths/get-shape file :copy-structure-clean-t) + + ;; Duplicate a text line in copy-structure-clean, updating + ;; both lines with the same attrs + file (-> (update-attr file :copy-structure-unif-t font-size-path-0 "25") + (change-structure :copy-structure-unif-t)) + copy-structure-unif (ths/get-shape file :copy-structure-unif) + copy-structure-unif-t (ths/get-shape file :copy-structure-unif-t) + + ;; Duplicate a text line in copy-structure-clean, updating + ;; each line with a different attr + file (-> (change-structure file :copy-structure-mixed-t) + (update-attr :copy-structure-mixed-t font-size-path-0 "35") + (update-attr :copy-structure-mixed-t font-size-path-1 "40")) + copy-structure-mixed (ths/get-shape file :copy-structure-mixed) + copy-structure-mixed-t (ths/get-shape file :copy-structure-mixed-t) + + + ;; ==== Action: Switch all the copies + file' (-> file + (tho/swap-component copy-structure-clean :c02 {:new-shape-label :copy-structure-clean-2 :keep-touched? true}) + (tho/swap-component copy-structure-unif :c02 {:new-shape-label :copy-structure-unif-2 :keep-touched? true}) + (tho/swap-component copy-structure-mixed :c02 {:new-shape-label :copy-structure-mixed-2 :keep-touched? true})) + page' (thf/current-page file') + copy-structure-clean' (ths/get-shape file' :copy-structure-clean-2) + copy-structure-clean-t' (get-in page' [:objects (-> copy-structure-clean' :shapes first)]) + + copy-structure-unif' (ths/get-shape file' :copy-structure-unif-2) + copy-structure-unif-t' (get-in page' [:objects (-> copy-structure-unif' :shapes first)]) + + copy-structure-mixed' (ths/get-shape file' :copy-structure-mixed-2) + copy-structure-mixed-t' (get-in page' [:objects (-> copy-structure-mixed' :shapes first)])] + + (thf/dump-file file' {:keys [:name #_:content]}) + + ;;;;;;;;;;; Copy structure clean + ;; Before the switch, first line: + ;; * font size 14 + ;; * text "new line 1" + ;; Second line: + ;; * font size 14 + ;; * text "new line 2" + (t/is (= (get-in copy-structure-clean-t font-size-path-0) "14")) + (t/is (= (get-in copy-structure-clean-t text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-clean-t font-size-path-1) "14")) + (t/is (= (get-in copy-structure-clean-t text-path-1) "new line 2")) + + ;; After the switch, first line: + ;; * font size 14 (value of c02, because there was no override) + ;; * text "new line 1" (the override is preserved) + ;; Second line: + ;; * font size 14 (value of c02, because there was no override) + ;; * text "new line 2" (the override is preserved) + (t/is (= (get-in copy-structure-clean-t' font-size-path-0) "14")) + (t/is (= (get-in copy-structure-clean-t' text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-clean-t' font-size-path-1) "14")) + (t/is (= (get-in copy-structure-clean-t' text-path-1) "new line 2")) + + ;;;;;;;;;;; Copy structure unif + ;; Before the switch, first line: + ;; * font size 25 + ;; * text "new line 1" + ;; Second line: + ;; * font size 25 + ;; * text "new line 2" + (t/is (= (get-in copy-structure-unif-t font-size-path-0) "25")) + (t/is (= (get-in copy-structure-unif-t text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-unif-t font-size-path-1) "25")) + (t/is (= (get-in copy-structure-unif-t text-path-1) "new line 2")) + + ;; After the switch, first line: + ;; * font size 25 (the override is preserved) + ;; * text "new line 1" (the override is preserved) + ;; Second line: + ;; * font size 25 (the override is preserved) + ;; * text "new line 2" (the override is preserved) + (t/is (= (get-in copy-structure-unif-t' font-size-path-0) "25")) + (t/is (= (get-in copy-structure-unif-t' text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-unif-t' font-size-path-1) "25")) + (t/is (= (get-in copy-structure-unif-t' text-path-1) "new line 2")) + + ;;;;;;;;;;; Copy structure mixed + ;; Before the switch, first line: + ;; * font size 35 + ;; * text "new line 1" + ;; Before the switch, second line: + ;; * font size 40 + ;; * text "new line 2" + (t/is (= (get-in copy-structure-mixed-t font-size-path-0) "35")) + (t/is (= (get-in copy-structure-mixed-t text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-mixed-t font-size-path-1) "40")) + (t/is (= (get-in copy-structure-mixed-t text-path-1) "new line 2")) + + ;; After the switch, first line: + ;; * font size 35 (the override is preserved) + ;; * text "new line 1" (the override is preserved) + ;; Second line: + ;; * font size 40 (the override is preserved) + ;; * text "new line 2" (the override is preserved) + (t/is (= (get-in copy-structure-mixed-t' font-size-path-0) "35")) + (t/is (= (get-in copy-structure-mixed-t' text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-mixed-t' font-size-path-1) "40")) + (t/is (= (get-in copy-structure-mixed-t' text-path-1) "new line 2")))) + + +(t/deftest test-switch-with-different-prop-structure-text-override + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + ;; The second component has a different prop + (thv/add-variant-with-text + :v01 :c01 :m01 :c02 :m02 :t01 :t02 "hello world" "hello world") + (update-attr :t02 font-size-path-0 "50") + (thc/instantiate-component :c01 + :copy-structure-clean + :children-labels [:copy-structure-clean-t]) + (thc/instantiate-component :c01 + :copy-structure-unif + :children-labels [:copy-structure-unif-t]) + (thc/instantiate-component :c01 + :copy-structure-mixed + :children-labels [:copy-structure-mixed-t])) + + + + ;; Duplicate a text line in copy-structure-clean + file (change-structure file :copy-structure-clean-t) + copy-structure-clean (ths/get-shape file :copy-structure-clean) + copy-structure-clean-t (ths/get-shape file :copy-structure-clean-t) + + ;; Duplicate a text line in copy-structure-clean, updating + ;; both lines with the same attrs + file (-> (update-attr file :copy-structure-unif-t font-size-path-0 "25") + (change-structure :copy-structure-unif-t)) + copy-structure-unif (ths/get-shape file :copy-structure-unif) + copy-structure-unif-t (ths/get-shape file :copy-structure-unif-t) + + ;; Duplicate a text line in copy-structure-clean, updating + ;; each line with a different attr + file (-> (change-structure file :copy-structure-mixed-t) + (update-attr :copy-structure-mixed-t font-size-path-0 "35") + (update-attr :copy-structure-mixed-t font-size-path-1 "40")) + copy-structure-mixed (ths/get-shape file :copy-structure-mixed) + copy-structure-mixed-t (ths/get-shape file :copy-structure-mixed-t) + + + ;; ==== Action: Switch all the copies + file' (-> file + (tho/swap-component copy-structure-clean :c02 {:new-shape-label :copy-structure-clean-2 :keep-touched? true}) + (tho/swap-component copy-structure-unif :c02 {:new-shape-label :copy-structure-unif-2 :keep-touched? true}) + (tho/swap-component copy-structure-mixed :c02 {:new-shape-label :copy-structure-mixed-2 :keep-touched? true})) + page' (thf/current-page file') + copy-structure-clean' (ths/get-shape file' :copy-structure-clean-2) + copy-structure-clean-t' (get-in page' [:objects (-> copy-structure-clean' :shapes first)]) + + copy-structure-unif' (ths/get-shape file' :copy-structure-unif-2) + copy-structure-unif-t' (get-in page' [:objects (-> copy-structure-unif' :shapes first)]) + + copy-structure-mixed' (ths/get-shape file' :copy-structure-mixed-2) + copy-structure-mixed-t' (get-in page' [:objects (-> copy-structure-mixed' :shapes first)])] + + (thf/dump-file file' {:keys [:name #_:content]}) + + ;;;;;;;;;;; Copy structure clean + ;; Before the switch, first line: + ;; * font size 14 + ;; * text "new line 1" + ;; Second line: + ;; * font size 14 + ;; * text "new line 2" + (t/is (= (get-in copy-structure-clean-t font-size-path-0) "14")) + (t/is (= (get-in copy-structure-clean-t text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-clean-t font-size-path-1) "14")) + (t/is (= (get-in copy-structure-clean-t text-path-1) "new line 2")) + + ;; After the switch, first line: + ;; * font size 50 (value of c02, because there was no override) + ;; * text "new line 1" (the override is preserved) + ;; Second line: + ;; * font size 50 (value of c02, because there was no override) + ;; * text "new line 2" (the override is preserved) + (t/is (= (get-in copy-structure-clean-t' font-size-path-0) "50")) + (t/is (= (get-in copy-structure-clean-t' text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-clean-t' font-size-path-1) "50")) + (t/is (= (get-in copy-structure-clean-t' text-path-1) "new line 2")) + + ;;;;;;;;;;; Copy structure unif + ;; Before the switch, first line: + ;; * font size 25 + ;; * text "new line 1" + ;; Second line: + ;; * font size 25 + ;; * text "new line 2" + (t/is (= (get-in copy-structure-unif-t font-size-path-0) "25")) + (t/is (= (get-in copy-structure-unif-t text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-unif-t font-size-path-1) "25")) + (t/is (= (get-in copy-structure-unif-t text-path-1) "new line 2")) + + ;; After the switch, first line: + ;; * font size 50 (the override is not preserved) + ;; * text "new line 1" (the override is preserved) + ;; Second line: + ;; * font size 50 (the override is not preserved) + ;; * text "new line 2" (the override is preserved) + (t/is (= (get-in copy-structure-unif-t' font-size-path-0) "50")) + (t/is (= (get-in copy-structure-unif-t' text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-unif-t' font-size-path-1) "50")) + (t/is (= (get-in copy-structure-unif-t' text-path-1) "new line 2")) + + ;;;;;;;;;;; Copy structure mixed + ;; Before the switch, first line: + ;; * font size 35 + ;; * text "new line 1" + ;; Before the switch, second line: + ;; * font size 40 + ;; * text "new line 2" + (t/is (= (get-in copy-structure-mixed-t font-size-path-0) "35")) + (t/is (= (get-in copy-structure-mixed-t text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-mixed-t font-size-path-1) "40")) + (t/is (= (get-in copy-structure-mixed-t text-path-1) "new line 2")) + + ;; After the switch, first line: + ;; * font size 50 (the override is not preserved) + ;; * text "hello world" (the override is not preserved) + ;; No second line + (t/is (= (get-in copy-structure-mixed-t' font-size-path-0) "50")) + (t/is (= (get-in copy-structure-mixed-t' text-path-0) "hello world")) + (t/is (nil? (get-in copy-structure-mixed-t' font-size-path-1))))) + +(t/deftest test-switch-with-different-text-structure-text-override + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + ;; Second comp has different text + (thv/add-variant-with-text + :v01 :c01 :m01 :c02 :m02 :t01 :t02 "hello world" "bye") + (thc/instantiate-component :c01 + :copy-structure-clean + :children-labels [:copy-structure-clean-t]) + (thc/instantiate-component :c01 + :copy-structure-unif + :children-labels [:copy-structure-unif-t]) + (thc/instantiate-component :c01 + :copy-structure-mixed + :children-labels [:copy-structure-mixed-t])) + + + + ;; Duplicate a text line in copy-structure-clean + file (change-structure file :copy-structure-clean-t) + copy-structure-clean (ths/get-shape file :copy-structure-clean) + copy-structure-clean-t (ths/get-shape file :copy-structure-clean-t) + + ;; Duplicate a text line in copy-structure-clean, updating + ;; both lines with the same attrs + file (-> (update-attr file :copy-structure-unif-t font-size-path-0 "25") + (change-structure :copy-structure-unif-t)) + copy-structure-unif (ths/get-shape file :copy-structure-unif) + copy-structure-unif-t (ths/get-shape file :copy-structure-unif-t) + + ;; Duplicate a text line in copy-structure-clean, updating + ;; each line with a different attr + file (-> (change-structure file :copy-structure-mixed-t) + (update-attr :copy-structure-mixed-t font-size-path-0 "35") + (update-attr :copy-structure-mixed-t font-size-path-1 "40")) + copy-structure-mixed (ths/get-shape file :copy-structure-mixed) + copy-structure-mixed-t (ths/get-shape file :copy-structure-mixed-t) + + + ;; ==== Action: Switch all the copies + file' (-> file + (tho/swap-component copy-structure-clean :c02 {:new-shape-label :copy-structure-clean-2 :keep-touched? true}) + (tho/swap-component copy-structure-unif :c02 {:new-shape-label :copy-structure-unif-2 :keep-touched? true}) + (tho/swap-component copy-structure-mixed :c02 {:new-shape-label :copy-structure-mixed-2 :keep-touched? true})) + page' (thf/current-page file') + copy-structure-clean' (ths/get-shape file' :copy-structure-clean-2) + copy-structure-clean-t' (get-in page' [:objects (-> copy-structure-clean' :shapes first)]) + + copy-structure-unif' (ths/get-shape file' :copy-structure-unif-2) + copy-structure-unif-t' (get-in page' [:objects (-> copy-structure-unif' :shapes first)]) + + copy-structure-mixed' (ths/get-shape file' :copy-structure-mixed-2) + copy-structure-mixed-t' (get-in page' [:objects (-> copy-structure-mixed' :shapes first)])] + + (thf/dump-file file' {:keys [:name #_:content]}) + + ;;;;;;;;;;; Copy structure clean + ;; Before the switch, first line: + ;; * font size 14 + ;; * text "new line 1" + ;; Second line: + ;; * font size 14 + ;; * text "new line 2" + (t/is (= (get-in copy-structure-clean-t font-size-path-0) "14")) + (t/is (= (get-in copy-structure-clean-t text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-clean-t font-size-path-1) "14")) + (t/is (= (get-in copy-structure-clean-t text-path-1) "new line 2")) + + ;; After the switch, first line: + ;; * font size 14 (value of c02, because there was no override) + ;; * text "bye" (the override is not preserved) + ;; No second line + (t/is (= (get-in copy-structure-clean-t' font-size-path-0) "14")) + (t/is (= (get-in copy-structure-clean-t' text-path-0) "bye")) + (t/is (nil? (get-in copy-structure-clean-t' font-size-path-1))) + + + ;;;;;;;;;;; Copy structure unif + ;; Before the switch, first line: + ;; * font size 25 + ;; * text "new line 1" + ;; Second line: + ;; * font size 25 + ;; * text "new line 2" + (t/is (= (get-in copy-structure-unif-t font-size-path-0) "25")) + (t/is (= (get-in copy-structure-unif-t text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-unif-t font-size-path-1) "25")) + (t/is (= (get-in copy-structure-unif-t text-path-1) "new line 2")) + + ;; After the switch, first line: + ;; * font size 25 (the override is preserved) + ;; * text "bye" (the override is not preserved) + ;; No second line + (t/is (= (get-in copy-structure-unif-t' font-size-path-0) "25")) + (t/is (= (get-in copy-structure-unif-t' text-path-0) "bye")) + (t/is (nil? (get-in copy-structure-unif-t' font-size-path-1))) + + + ;;;;;;;;;;; Copy structure mixed + ;; Before the switch, first line: + ;; * font size 35 + ;; * text "new line 1" + ;; Before the switch, second line: + ;; * font size 40 + ;; * text "new line 2" + (t/is (= (get-in copy-structure-mixed-t font-size-path-0) "35")) + (t/is (= (get-in copy-structure-mixed-t text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-mixed-t font-size-path-1) "40")) + (t/is (= (get-in copy-structure-mixed-t text-path-1) "new line 2")) + + ;; After the switch, first line: + ;; * font size 14 (the override is not preserved) + ;; * text "bye" (the override is not preserved) + ;; No second line + (t/is (= (get-in copy-structure-mixed-t' font-size-path-0) "14")) + (t/is (= (get-in copy-structure-mixed-t' text-path-0) "bye")) + (t/is (nil? (get-in copy-structure-mixed-t' font-size-path-1))))) + +(t/deftest test-switch-with-different-text-and-prop-structure-text-override + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + ;; The second component has a different text and prop + (thv/add-variant-with-text + :v01 :c01 :m01 :c02 :m02 :t01 :t02 "hello world" "bye") + (update-attr :t02 font-size-path-0 "50") + (thc/instantiate-component :c01 + :copy-structure-clean + :children-labels [:copy-structure-clean-t]) + (thc/instantiate-component :c01 + :copy-structure-unif + :children-labels [:copy-structure-unif-t]) + (thc/instantiate-component :c01 + :copy-structure-mixed + :children-labels [:copy-structure-mixed-t])) + + + + ;; Duplicate a text line in copy-structure-clean + file (change-structure file :copy-structure-clean-t) + copy-structure-clean (ths/get-shape file :copy-structure-clean) + copy-structure-clean-t (ths/get-shape file :copy-structure-clean-t) + + ;; Duplicate a text line in copy-structure-clean, updating + ;; both lines with the same attrs + file (-> (update-attr file :copy-structure-unif-t font-size-path-0 "25") + (change-structure :copy-structure-unif-t)) + copy-structure-unif (ths/get-shape file :copy-structure-unif) + copy-structure-unif-t (ths/get-shape file :copy-structure-unif-t) + + ;; Duplicate a text line in copy-structure-clean, updating + ;; each line with a different attr + file (-> (change-structure file :copy-structure-mixed-t) + (update-attr :copy-structure-mixed-t font-size-path-0 "35") + (update-attr :copy-structure-mixed-t font-size-path-1 "40")) + copy-structure-mixed (ths/get-shape file :copy-structure-mixed) + copy-structure-mixed-t (ths/get-shape file :copy-structure-mixed-t) + + + ;; ==== Action: Switch all the copies + file' (-> file + (tho/swap-component copy-structure-clean :c02 {:new-shape-label :copy-structure-clean-2 :keep-touched? true}) + (tho/swap-component copy-structure-unif :c02 {:new-shape-label :copy-structure-unif-2 :keep-touched? true}) + (tho/swap-component copy-structure-mixed :c02 {:new-shape-label :copy-structure-mixed-2 :keep-touched? true})) + page' (thf/current-page file') + copy-structure-clean' (ths/get-shape file' :copy-structure-clean-2) + copy-structure-clean-t' (get-in page' [:objects (-> copy-structure-clean' :shapes first)]) + + copy-structure-unif' (ths/get-shape file' :copy-structure-unif-2) + copy-structure-unif-t' (get-in page' [:objects (-> copy-structure-unif' :shapes first)]) + + copy-structure-mixed' (ths/get-shape file' :copy-structure-mixed-2) + copy-structure-mixed-t' (get-in page' [:objects (-> copy-structure-mixed' :shapes first)])] + + (thf/dump-file file' {:keys [:name #_:content]}) + + ;;;;;;;;;;; Copy structure clean + ;; Before the switch, first line: + ;; * font size 14 + ;; * text "new line 1" + ;; Second line: + ;; * font size 14 + ;; * text "new line 2" + (t/is (= (get-in copy-structure-clean-t font-size-path-0) "14")) + (t/is (= (get-in copy-structure-clean-t text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-clean-t font-size-path-1) "14")) + (t/is (= (get-in copy-structure-clean-t text-path-1) "new line 2")) + + ;; After the switch, first line: + ;; * font size 50 (value of c02, because there was no override) + ;; * text "bye" (the override is not preserved) + ;; No second line + (t/is (= (get-in copy-structure-clean-t' font-size-path-0) "50")) + (t/is (= (get-in copy-structure-clean-t' text-path-0) "bye")) + (t/is (nil? (get-in copy-structure-clean-t' font-size-path-1))) + + + ;;;;;;;;;;; Copy structure unif + ;; Before the switch, first line: + ;; * font size 25 + ;; * text "new line 1" + ;; Second line: + ;; * font size 25 + ;; * text "new line 2" + (t/is (= (get-in copy-structure-unif-t font-size-path-0) "25")) + (t/is (= (get-in copy-structure-unif-t text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-unif-t font-size-path-1) "25")) + (t/is (= (get-in copy-structure-unif-t text-path-1) "new line 2")) + + ;; After the switch, first line: + ;; * font size 50 (the override is not preserved) + ;; * text "bye" (the override is not preserved) + ;; No second line + (t/is (= (get-in copy-structure-unif-t' font-size-path-0) "50")) + (t/is (= (get-in copy-structure-unif-t' text-path-0) "bye")) + (t/is (nil? (get-in copy-structure-unif-t' font-size-path-1))) + + + ;;;;;;;;;;; Copy structure mixed + ;; Before the switch, first line: + ;; * font size 35 + ;; * text "new line 1" + ;; Before the switch, second line: + ;; * font size 40 + ;; * text "new line 2" + (t/is (= (get-in copy-structure-mixed-t font-size-path-0) "35")) + (t/is (= (get-in copy-structure-mixed-t text-path-0) "new line 1")) + (t/is (= (get-in copy-structure-mixed-t font-size-path-1) "40")) + (t/is (= (get-in copy-structure-mixed-t text-path-1) "new line 2")) + + ;; After the switch, first line: + ;; * font size 50 (the override is not preserved) + ;; * text "bye" (the override is not preserved) + ;; No second line + (t/is (= (get-in copy-structure-mixed-t' font-size-path-0) "50")) + (t/is (= (get-in copy-structure-mixed-t' text-path-0) "bye")) + (t/is (nil? (get-in copy-structure-mixed-t' font-size-path-1))))) \ No newline at end of file diff --git a/common/test/common_tests/types/tokens_lib_test.cljc b/common/test/common_tests/types/tokens_lib_test.cljc index 095c044048..e2ac474139 100644 --- a/common/test/common_tests/types/tokens_lib_test.cljc +++ b/common/test/common_tests/types/tokens_lib_test.cljc @@ -14,6 +14,7 @@ [app.common.time :as dt] [app.common.transit :as tr] [app.common.types.tokens-lib :as ctob] + [clojure.datafy :refer [datafy]] [clojure.test :as t])) (defn setup-virtual-time @@ -72,14 +73,14 @@ :modified-at now :tokens [])] - (t/is (= (:name token-set1) "test-token-set-1")) - (t/is (= (:description token-set1) "")) - (t/is (some? (:modified-at token-set1))) - (t/is (empty? (:tokens token-set1))) - (t/is (= (:name token-set2) "test-token-set-2")) - (t/is (= (:description token-set2) "test description")) - (t/is (= (:modified-at token-set2) now)) - (t/is (empty? (:tokens token-set2))))) + (t/is (= (ctob/get-name token-set1) "test-token-set-1")) + (t/is (= (ctob/get-description token-set1) "")) + (t/is (some? (ctob/get-modified-at token-set1))) + (t/is (empty? (ctob/get-tokens-map token-set1))) + (t/is (= (ctob/get-name token-set2) "test-token-set-2")) + (t/is (= (ctob/get-description token-set2) "test description")) + (t/is (= (ctob/get-modified-at token-set2) now)) + (t/is (empty? (ctob/get-tokens-map token-set2))))) (t/deftest make-invalid-token-set (let [params {:name 777 :description 999}] @@ -183,7 +184,7 @@ :type :boolean :value true)}))) expected (-> (ctob/get-set tokens-lib "A") - (get :tokens) + (ctob/get-tokens-map) (ctob/tokens-tree))] (t/is (= (get-in expected ["foo" "bar" "baz" :name]) "foo.bar.baz")) (t/is (= (get-in expected ["foo" "bar" "bam" :name]) "foo.bar.bam")) @@ -249,20 +250,18 @@ tokens-lib' (-> tokens-lib (ctob/update-set "test-token-set" (fn [token-set] - (assoc token-set - :description "some description"))) + (ctob/set-description token-set "some description"))) (ctob/update-set "not-existing-set" (fn [token-set] - (assoc token-set - :description "no-effect")))) + (ctob/set-description token-set "no-effect")))) token-set (ctob/get-set tokens-lib "test-token-set") token-set' (ctob/get-set tokens-lib' "test-token-set")] (t/is (= (ctob/set-count tokens-lib') 1)) - (t/is (= (:name token-set') "test-token-set")) - (t/is (= (:description token-set') "some description")) - (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))))) + (t/is (= (ctob/get-name token-set') "test-token-set")) + (t/is (= (ctob/get-description token-set') "some description")) + (t/is (dt/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))))) (t/deftest rename-token-set (let [tokens-lib (-> (ctob/make-tokens-lib) @@ -271,15 +270,14 @@ tokens-lib' (-> tokens-lib (ctob/update-set "test-token-set" (fn [token-set] - (assoc token-set - :name "updated-name")))) + (ctob/rename token-set "updated-name")))) token-set (ctob/get-set tokens-lib "test-token-set") token-set' (ctob/get-set tokens-lib' "updated-name")] (t/is (= (ctob/set-count tokens-lib') 1)) - (t/is (= (:name token-set') "updated-name")) - (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))))) + (t/is (= (ctob/get-name token-set') "updated-name")) + (t/is (dt/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))))) (t/deftest rename-token-set-group (let [tokens-lib (-> (ctob/make-tokens-lib) @@ -323,11 +321,11 @@ :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"])] + token (ctob/get-token token-set-copy "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 (= (ctob/get-name token-set-copy) "test-token-set-copy")) + (t/is (= (count (ctob/get-tokens-map token-set-copy)) 1)) (t/is (= (:name token) "test-token")))) (t/deftest duplicate-token-set-twice @@ -341,11 +339,11 @@ 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"])] + token (ctob/get-token token-set-copy "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 (= (ctob/get-name token-set-copy) "test-token-set-copy-2")) + (t/is (= (count (ctob/get-tokens-map token-set-copy)) 1)) (t/is (= (:name token) "test-token")))) (t/deftest duplicate-empty-token-set @@ -353,11 +351,11 @@ (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)] + tokens (ctob/get-tokens-map token-set-copy)] (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 (= (ctob/get-name token-set-copy) "test-token-set-copy")) + (t/is (= (count (ctob/get-tokens-map token-set-copy)) 0)) (t/is (= (count tokens) 0)))) (t/deftest duplicate-not-existing-token-set @@ -392,12 +390,12 @@ token-set (ctob/get-set tokens-lib "test-token-set") token-set' (ctob/get-set tokens-lib' "test-token-set") - token' (get-in token-set' [:tokens "test-token"])] + token' (ctob/get-token token-set' "test-token")] (t/is (= (ctob/set-count tokens-lib') 1)) - (t/is (= (count (:tokens token-set')) 1)) + (t/is (= (count (ctob/get-tokens-map token-set')) 1)) (t/is (= (:name token') "test-token")) - (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))))) + (t/is (dt/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))))) (t/deftest update-token (let [tokens-lib (-> (ctob/make-tokens-lib) @@ -428,16 +426,16 @@ token-set (ctob/get-set tokens-lib "test-token-set") token-set' (ctob/get-set tokens-lib' "test-token-set") - token (get-in token-set [:tokens "test-token-1"]) - token' (get-in token-set' [:tokens "test-token-1"])] + token (ctob/get-token token-set "test-token-1") + token' (ctob/get-token token-set' "test-token-1")] (t/is (= (ctob/set-count tokens-lib') 1)) - (t/is (= (count (:tokens token-set')) 2)) - (t/is (= (d/index-of (keys (:tokens token-set')) "test-token-1") 0)) + (t/is (= (count (ctob/get-tokens-map token-set')) 2)) + (t/is (= (d/index-of (keys (ctob/get-tokens-map token-set')) "test-token-1") 0)) (t/is (= (:name token') "test-token-1")) (t/is (= (:description token') "some description")) (t/is (= (:value token') false)) - (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))) + (t/is (dt/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))) (t/is (dt/is-after? (:modified-at token') (:modified-at token))))) (t/deftest rename-token @@ -460,16 +458,16 @@ token-set (ctob/get-set tokens-lib "test-token-set") token-set' (ctob/get-set tokens-lib' "test-token-set") - token (get-in token-set [:tokens "test-token-1"]) - token' (get-in token-set' [:tokens "updated-name"])] + token (ctob/get-token token-set "test-token-1") + token' (ctob/get-token token-set' "updated-name")] (t/is (= (ctob/set-count tokens-lib') 1)) - (t/is (= (count (:tokens token-set')) 2)) - (t/is (= (d/index-of (keys (:tokens token-set')) "updated-name") 0)) + (t/is (= (count (ctob/get-tokens-map token-set')) 2)) + (t/is (= (d/index-of (keys (ctob/get-tokens-map token-set')) "updated-name") 0)) (t/is (= (:name token') "updated-name")) (t/is (= (:description token') "")) (t/is (= (:value token') true)) - (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))) + (t/is (dt/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))) (t/is (dt/is-after? (:modified-at token') (:modified-at token))))) (t/deftest delete-token @@ -486,12 +484,12 @@ token-set (ctob/get-set tokens-lib "test-token-set") token-set' (ctob/get-set tokens-lib' "test-token-set") - token' (get-in token-set' [:tokens "test-token"])] + token' (ctob/get-token token-set' "test-token")] (t/is (= (ctob/set-count tokens-lib') 1)) - (t/is (= (count (:tokens token-set')) 0)) + (t/is (= (count (ctob/get-tokens-map token-set')) 0)) (t/is (nil? token')) - (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))))) + (t/is (dt/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))))) (t/deftest get-ordered-sets (let [tokens-lib (-> (ctob/make-tokens-lib) @@ -897,7 +895,7 @@ :value true))) set (ctob/get-set tokens-lib "test-token-set") - tokens-list (vals (:tokens set))] + tokens-list (ctob/get-tokens set)] (t/is (= (count tokens-list) 5)) (t/is (= (:name (nth tokens-list 0)) "token1")) @@ -931,14 +929,14 @@ token-set (ctob/get-set tokens-lib "test-token-set") token-set' (ctob/get-set tokens-lib' "test-token-set") - token (get-in token-set [:tokens "group1.test-token-2"]) - token' (get-in token-set' [:tokens "group1.test-token-2"])] + token (ctob/get-token token-set "group1.test-token-2") + token' (ctob/get-token token-set' "group1.test-token-2")] (t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (:name token') "group1.test-token-2")) (t/is (= (:description token') "some description")) (t/is (= (:value token') false)) - (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))) + (t/is (dt/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))) (t/is (dt/is-after? (:modified-at token') (:modified-at token))))) (t/deftest update-token-in-sets-rename @@ -965,14 +963,14 @@ token-set (ctob/get-set tokens-lib "test-token-set") token-set' (ctob/get-set tokens-lib' "test-token-set") - token (get-in token-set [:tokens "group1.test-token-2"]) - token' (get-in token-set' [:tokens "group1.updated-name"])] + token (ctob/get-token token-set "group1.test-token-2") + token' (ctob/get-token token-set' "group1.updated-name")] (t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (:name token') "group1.updated-name")) (t/is (= (:description token') "")) (t/is (= (:value token') true)) - (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))) + (t/is (dt/is-after? (ctob/get-modified-at token-set') (:ctob/get-modified-at token-set))) (t/is (dt/is-after? (:modified-at token') (:modified-at token))))) (t/deftest move-token-of-group @@ -999,15 +997,15 @@ token-set (ctob/get-set tokens-lib "test-token-set") token-set' (ctob/get-set tokens-lib' "test-token-set") - token (get-in token-set [:tokens "group1.test-token-2"]) - token' (get-in token-set' [:tokens "group2.updated-name"])] + token (ctob/get-token token-set "group1.test-token-2") + token' (ctob/get-token token-set' "group2.updated-name")] (t/is (= (ctob/set-count tokens-lib') 1)) - (t/is (= (d/index-of (keys (:tokens token-set')) "group2.updated-name") 1)) + (t/is (= (d/index-of (keys (ctob/get-tokens-map token-set')) "group2.updated-name") 1)) (t/is (= (:name token') "group2.updated-name")) (t/is (= (:description token') "")) (t/is (= (:value token') true)) - (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))) + (t/is (dt/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))) (t/is (dt/is-after? (:modified-at token') (:modified-at token))))) (t/deftest delete-token-in-group @@ -1026,12 +1024,12 @@ token-set (ctob/get-set tokens-lib "test-token-set") token-set' (ctob/get-set tokens-lib' "test-token-set") - token' (get-in token-set' [:tokens "group1.test-token-2"])] + token' (ctob/get-token token-set' "group1.test-token-2")] (t/is (= (ctob/set-count tokens-lib') 1)) - (t/is (= (count (:tokens token-set')) 1)) + (t/is (= (count (ctob/get-tokens-map token-set')) 1)) (t/is (nil? token')) - (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))))) + (t/is (dt/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))))) (t/deftest update-token-set-in-groups (let [tokens-lib (-> (ctob/make-tokens-lib) @@ -1044,7 +1042,7 @@ tokens-lib' (-> tokens-lib (ctob/update-set "group1/token-set-2" (fn [token-set] - (assoc token-set :description "some description")))) + (ctob/set-description token-set "some description")))) sets-tree (ctob/get-set-tree tokens-lib) sets-tree' (ctob/get-set-tree tokens-lib') @@ -1055,9 +1053,9 @@ (t/is (= (ctob/set-count tokens-lib') 5)) (t/is (= (count group1') 3)) (t/is (= (d/index-of (keys group1') "S-token-set-2") 0)) - (t/is (= (:name token-set') "group1/token-set-2")) - (t/is (= (:description token-set') "some description")) - (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))))) + (t/is (= (ctob/get-name token-set') "group1/token-set-2")) + (t/is (= (ctob/get-description token-set') "some description")) + (t/is (dt/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))))) (t/deftest rename-token-set-in-groups (let [tokens-lib (-> (ctob/make-tokens-lib) @@ -1070,8 +1068,7 @@ tokens-lib' (-> tokens-lib (ctob/update-set "group1/token-set-2" (fn [token-set] - (assoc token-set - :name "group1/updated-name")))) + (ctob/rename token-set "group1/updated-name")))) sets-tree (ctob/get-set-tree tokens-lib) sets-tree' (ctob/get-set-tree tokens-lib') @@ -1082,9 +1079,9 @@ (t/is (= (ctob/set-count tokens-lib') 5)) (t/is (= (count group1') 3)) (t/is (= (d/index-of (keys group1') "S-updated-name") 0)) - (t/is (= (:name token-set') "group1/updated-name")) - (t/is (= (:description token-set') "")) - (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))))) + (t/is (= (ctob/get-name token-set') "group1/updated-name")) + (t/is (= (ctob/get-description token-set') "")) + (t/is (dt/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))))) (t/deftest move-token-set-of-group (let [tokens-lib (-> (ctob/make-tokens-lib) @@ -1097,8 +1094,7 @@ tokens-lib' (-> tokens-lib (ctob/update-set "group1/token-set-2" (fn [token-set] - (assoc token-set - :name "group2/updated-name")))) + (ctob/rename token-set "group2/updated-name")))) sets-tree (ctob/get-set-tree tokens-lib) sets-tree' (ctob/get-set-tree tokens-lib') @@ -1111,9 +1107,9 @@ (t/is (= (count group1') 2)) (t/is (= (count group2') 1)) (t/is (nil? (get group1' "S-updated-name"))) - (t/is (= (:name token-set') "group2/updated-name")) - (t/is (= (:description token-set') "")) - (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))))) + (t/is (= (ctob/get-name token-set') "group2/updated-name")) + (t/is (= (ctob/get-description token-set') "")) + (t/is (dt/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))))) (t/deftest delete-token-set-in-group (let [tokens-lib (-> (ctob/make-tokens-lib) @@ -1413,7 +1409,7 @@ tokens-lib' (ctob/parse-decoded-json encoded "")] (t/testing "library got updated but data is equal" (t/is (not= tokens-lib' tokens-lib)) - (t/is (= @tokens-lib' @tokens-lib))))))) + (t/is (= (datafy tokens-lib') (datafy tokens-lib)))))))) #?(:clj (t/deftest export-dtcg-json-with-default-theme diff --git a/common/test/common_tests/variant_test.cljc b/common/test/common_tests/variant_test.cljc index 433f008573..05bc748703 100644 --- a/common/test/common_tests/variant_test.cljc +++ b/common/test/common_tests/variant_test.cljc @@ -15,13 +15,13 @@ map-with-two-props-dashes [{:name "border" :value "no"} {:name "color" :value "--"}] map-with-one-prop [{:name "border" :value "no"}] map-with-equal [{:name "border" :value "yes color=yes"}] - map-with-spaces [{:name "border 1" :value "of course"} - {:name "color 2" :value "dark gray"} - {:name "background 3" :value "anoth€r co-lor"}] + map-with-spaces [{:name "border (1)" :value "of course"} + {:name "color (2)" :value "dark gray"} + {:name "background (3)" :value "anoth€r co-lor"}] 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, background 3=anoth€r co-lor" + string-valid-with-spaces "border (1)=of course, color (2)=dark gray, background (3)=anoth€r co-lor" string-valid-with-no-value "border=no, color=" string-valid-with-dashes "border=no, color=--" string-valid-with-equal "border=yes color=yes" @@ -131,3 +131,31 @@ (t/is (= (ctv/same-variant? components-2) false)) (t/is (= (ctv/same-variant? components-3) false)) (t/is (= (ctv/same-variant? components-4) false))))) + + +(t/deftest update-number-in-repeated-item + (let [names ["border" "color" "color 1" "color 2" "color (1)" "color (7)" "area 51"]] + + (t/testing "update-number-in-repeated-item" + (t/is (= (ctv/update-number-in-repeated-item names "background") "background")) + (t/is (= (ctv/update-number-in-repeated-item names "border") "border (1)")) + (t/is (= (ctv/update-number-in-repeated-item names "color") "color (2)")) + (t/is (= (ctv/update-number-in-repeated-item names "color 1") "color 1 (1)")) + (t/is (= (ctv/update-number-in-repeated-item names "color (1)") "color (2)")) + (t/is (= (ctv/update-number-in-repeated-item names "area 51") "area 51 (1)"))))) + + +(t/deftest update-number-in-repeated-prop-names + (let [props [{:name "color" :value "yellow"} + {:name "color" :value "blue"} + {:name "color" :value "red"} + {:name "border (1)" :value "no"} + {:name "border (1)" :value "yes"}] + numbered-props [{:name "color" :value "yellow"} + {:name "color (1)" :value "blue"} + {:name "color (2)" :value "red"} + {:name "border (1)" :value "no"} + {:name "border (2)" :value "yes"}]] + + (t/testing "update-number-in-repeated-prop-names" + (t/is (= (ctv/update-number-in-repeated-prop-names props) numbered-props))))) diff --git a/docker/devenv/Dockerfile b/docker/devenv/Dockerfile index a7c5ff8265..c938bc9a58 100644 --- a/docker/devenv/Dockerfile +++ b/docker/devenv/Dockerfile @@ -26,8 +26,6 @@ RUN set -ex; \ build-essential autoconf libtool pkg-config -COPY files/apt.sources /etc/apt/sources.list.d/ubuntu.sources - ################################################################################ ## IMAGE MAGICK ################################################################################ diff --git a/docker/devenv/docker-compose.yaml b/docker/devenv/docker-compose.yaml index 6de50d6684..b546301643 100644 --- a/docker/devenv/docker-compose.yaml +++ b/docker/devenv/docker-compose.yaml @@ -96,6 +96,10 @@ services: - ./files/postgresql.conf:/etc/postgresql.conf:z - ./files/postgresql_init.sql:/docker-entrypoint-initdb.d/init.sql:z - postgres_data_pg16:/var/lib/postgresql/data + networks: + default: + aliases: + - postgres redis: image: valkey/valkey:8.1 diff --git a/docker/devenv/files/entrypoint.sh b/docker/devenv/files/entrypoint.sh index a1cabc2aaf..1427b19148 100755 --- a/docker/devenv/files/entrypoint.sh +++ b/docker/devenv/files/entrypoint.sh @@ -10,7 +10,7 @@ cp /root/.bashrc /home/penpot/.bashrc cp /root/.vimrc /home/penpot/.vimrc cp /root/.tmux.conf /home/penpot/.tmux.conf -chown -R penpot:users /home/penpot +chown penpot:users /home/penpot rsync -ar --chown=penpot:users /opt/cargo/ /home/penpot/.cargo/ export PATH="/home/penpot/.cargo/bin:$PATH" diff --git a/docs/technical-guide/developer/backend.md b/docs/technical-guide/developer/backend.md index 1a0c69d013..0f60c928d7 100644 --- a/docs/technical-guide/developer/backend.md +++ b/docs/technical-guide/developer/backend.md @@ -4,14 +4,22 @@ title: 3.06. Backend Guide # Backend guide # -This guide intends to explain the essential details of the backend -application. - +This guide collects some basic information on the backend application. ## REPL ## -In the devenv environment you can execute scripts/repl to open a -Clojure interactive shell ([REPL](https://codewith.mu/en/tutorials/1.0/repl)). +_Note:_ When in development mode, the backend spins up a traditional nREPL socket on port 6064. +If you are experimenting locally, you can connect to it using your Clojure editor or +with `backend/scripts/nrepl`, which starts a [REPLy client](https://github.com/trptcolin/reply), +[see here][1] for more information. + +[1]: /technical-guide/developer/devenv/#backend + +In the devenv environment you can execute `backend/scripts/repl` to open a +Clojure interactive shell ([REPL](https://codewith.mu/en/tutorials/1.0/repl)) (this is not a socket-based +REPL, but a local, in-process console (over stdin/stdout) with some fancy line-editing and colors). Note +that the backend must be stopped before executing this script, otherwise it will fail with `Port already +in use: 9090`. Once there, you can execute (restart) to load and execute the backend process, or to reload it after making changes to the source code. @@ -39,11 +47,11 @@ For example: ## Fixtures ## -This is a development feature that allows populate the database with a -good amount of content (usually used for just test the application or -perform performance tweaks on queries). +This is a development feature that allows populating the database with a +good amount of content (typically used to test the application or to run +performance tweaks on queries). -In order to load fixtures, enter to the REPL environment with the scripts/repl +In order to load fixtures, enter the REPL environment with the backend/scripts/repl script, and then execute (app.cli.fixtures/run {:preset :small}). You also can execute this as a standalone script with: @@ -52,11 +60,11 @@ You also can execute this as a standalone script with: clojure -Adev -X:fn-fixtures ``` -NOTE: It is an optional step because the application can start with an +_NOTE:_ This is an optional step because the application can start with an empty database. -This by default will create a bunch of users that can be used to login -in the application. All users uses the following pattern: +The above will create several users that can be used to login +into the application. All of them follow the pattern: - Username: profileN@example.com - Password: 123123 diff --git a/docs/technical-guide/developer/devenv.md b/docs/technical-guide/developer/devenv.md index 7e572c50fe..3c98df3484 100644 --- a/docs/technical-guide/developer/devenv.md +++ b/docs/technical-guide/developer/devenv.md @@ -170,6 +170,23 @@ similar to a webmail client. Simply navigate to: [http://localhost:1080](http://localhost:1080) +## Create user + +You can register a new user manually, or create new users automatically with this script. From your tmux instance, run: + + +```sh +cd penpot/backend/scripts +python3 manage.py create-profile +``` + +You can also skip tutorial and walkthrough steps: + +```sh +python3 manage.py create-profile --skip-tutorial --skip-walkthrough +python3 manage.py create-profile -n "Jane Doe" -e jane@example.com -p secretpassword --skip-tutorial --skip-walkthrough +``` + ## Team Feature Flags To test a Feature Flag, you can enable or disable them by team through the `dbg` page: diff --git a/docs/technical-guide/getting-started/docker.md b/docs/technical-guide/getting-started/docker.md index 5608c6882d..2e82d8d629 100644 --- a/docs/technical-guide/getting-started/docker.md +++ b/docs/technical-guide/getting-started/docker.md @@ -89,6 +89,13 @@ For instance, if the registration is disabled, the only way to create a new use docker exec -ti penpot-penpot-backend-1 python3 manage.py create-profile ``` +or + +```bash +docker exec -ti penpot-penpot-backend-1 python3 manage.py create-profile --skip-tutorial --skip-walkthrough +``` + + **NOTE:** the exact container name depends on your docker version and platform. For example it could be penpot-penpot-backend-1 or penpot_penpot-backend-1. You can check the correct name executing docker ps. diff --git a/docs/technical-guide/getting-started/index.md b/docs/technical-guide/getting-started/index.md index 175cf99195..38f8f939bc 100644 --- a/docs/technical-guide/getting-started/index.md +++ b/docs/technical-guide/getting-started/index.md @@ -28,5 +28,6 @@ Use Docker if you already know the tool, if need full control of the process or and do not want to depend on any external provider, or need to do any special customization.

-Or you can try other options, -offered by Penpot community. +Or you can try [other options][1], offered by Penpot community. + +[1]: /technical-guide/getting-started/unofficial-options/ diff --git a/docs/user-guide/layer-basics/index.njk b/docs/user-guide/layer-basics/index.njk index ff17a77738..317857423c 100644 --- a/docs/user-guide/layer-basics/index.njk +++ b/docs/user-guide/layer-basics/index.njk @@ -281,12 +281,15 @@ press Shift/⇧ + left click over the right arrow of a group or a boa

Focus mode

-

Select the elements of a page you want to work with in a specific moment hiding the rest so they don’t get in the way of your attention. This option is also useful to improve the performance in cases where the page has a large number of elements.

+

Focus mode zooms into the elements of a page you want to work with in a specific moment, and hides the rest so that they don’t get in the way. When the page has many elements, focus mode can also improve performance.

To activate focus mode:

-
    +
    1. Select one or more elements.
    2. -
    3. Right click to show the menu and select the option "Focus on" or press F.
    4. +
    5. Right click on the selection to show the menu and select the option “Focus on” or press F.
    +

    Notice that the layer panel will now only show the focused layers. A focus mode status line will also appear at the top.

    +

    To exit focus mode and return to the original viewport and selection, right click anywhere and select “Focus off” or just press F again. You can also click anywhere on the focus mode status line at the top of the layer panel. +