18 Commits

Author SHA1 Message Date
Eva Marco
01ab6bed79 🐛 Validate pasted shapes where they are pasted
generate-duplicate-changes looked for the instance roots of the copied
shapes in the page they were copied from, and mapped them to the new
ids. Pasting a main into another main creates a nested copy, but the
copy was validated on its own and reported :nested-copy-not-allowed.
Shapes copied from inside a component and pasted outside were not
validated at all: the unchanged source root was validated instead.

Look for the instance roots from the new shapes, in the objects of the
changes builder, where they already are in their new place.

This fixes three tests in frontend pasting_in_containers_test.

AI-assisted-by: claude-opus-5-5
2026-11-24 13:30:18 +01:00
Eva Marco
5d2c940ed4 🔧 Validate variant containers after moving shapes into them
generate-make-shapes-variant does not validate, as its callers may run
it before the shapes are inside the container. Validate in the callers
instead, once the action is complete:

- generate-relocate validates the variant containers the variants come
  from (unless they are deleted for being empty) and the one they go
  into.
- prepare-restore-component validates the container when it restores a
  component into a variant.
- duplicate-variant validates the container after moving the new
  variant into it.

AI-assisted-by: claude-opus-5-5
2026-11-24 13:30:18 +01:00
Eva Marco
5fab1bd4f8 🐛 Validate the enclosing root when instantiating a nested copy
generate-instantiate-component validated the new copy on its own. When
the copy is created inside another component it is a nested copy, but
the validator starts with a :not-component context and reported
:nested-copy-not-allowed, a false error that broke 34 common tests on JS.

When the new copy is not an instance root, validate the instance roots
that hold its parent instead. The validator then walks the copy with the
right context, and also checks the parents that may change (e.g.
layouts).

AI-assisted-by: claude-opus-5-5
2026-11-24 13:30:17 +01:00
Eva Marco
f769364479 🐛 Fix assertion when restoring a deleted component
The changes builder getters now assert that their context was given,
but prepare-restore-component and generate-delete-shapes relied on them
returning nil to fall back to other data. The workspace restores
components with changes that carry no library data, so restoring a
main component or a variant from one of its copies failed.

Add has-library-data?, has-objects? and has-page? to the changes builder,
and check them in those fallbacks before calling the getters.

Add tests that restore a component, and a variant whose container was
deleted, with changes that carry no library data, as the workspace does.

AI-assisted-by: claude-opus-5-5
2026-11-24 13:30:14 +01:00
Andrés Moya
c38a1d5d59 🔧 Add tests and validations to variant functions 2026-11-24 13:30:12 +01:00
Andrey Antukh
5fafca7665 🐛 Correct UI CSS export and test restore flow
Point the public CSS export to the generated file and test its build.
Clarify component restoration and cover the deleted-file path. Update
integration test documentation for the release bundle.

AI-assisted-by: gpt-6.1-terra
2026-11-24 12:44:30 +01:00
Andrés Moya
0e4be21320
🐛 Ensure component name always matches root instance name (#12794)
* 🐛 Remove svg extension when creating a component from a svg file

* 🐛 Normalize root names to always match the component name

* ✨ Remove any extension ignoring case, not only .svg

* 🔧 Add some fixes and checks

* 🔧 Improve rename detection
2026-11-13 13:53:28 +01:00
Andrés Moya
a5f75c7394
🐛 Fix repair bad variants (#11983)
* 🐛 Ensure normalized names in components and variants

We have a rule of that shape names that include / separator should have
it normalized, with one space before and one after. But this rule is
being enforced only in the UI and the plugins API. There may be other
ways of creating shapes that does not follow it.

For normal shapes this is not really a problem. But for main instances
it may cause that the name of the shape does not match the joined
path+name of the component, and this may generate some problems.

We have decided to add a migration to fix this in all main instances and
variant containers and enforce it in the future with integrity
validations (normal shapes may be left as is).

* 🐛 Fix bad variant-id in the component and the main instance

* 🔧 Fix some issues detected in PR review

* 🐛 Add nil guard
2026-10-16 10:59:57 +02:00
Andrey Antukh
81c3b3cd56
📎 Update copyright name on file header (#11346) 2026-08-25 11:55:10 +02:00
Andrey Antukh
c5de4c27b0 Merge remote-tracking branch 'origin/main' into staging 2026-06-01 12:57:39 +02:00
Yamila Moreno
ddba2ffa75
📎 Update Kaleidos Copyright (#9929) 2026-05-29 11:24:58 +02:00
FairyPiggyDev
9c2a80bfa1
🐛 Fix crash pasting component with variants from shared library (#9136)
Copying a component with variants from a shared library file ("Lib")
and pasting it into a file that uses that library ("Using Lib") would
crash the destination file with the referential-integrity validator
error:

    {:code :component-main-external
     :hint "Main instance should refer to a component in the same file"}

Root cause
----------

Paste goes through `generate-duplicate-shape-change` in
`common/src/app/common/logic/libraries.cljc`. When the shape is a
main instance of a known component and the copy set includes its
variant container, dispatch lands in `duplicate-variant`, then
`generate-duplicate-component`, and finally `duplicate-component`,
which clones the main-instance shape tree. Its `update-new-shape`
helper already re-links the new outer main's `:component-id` to the
freshly created local component (`new-component-id`), but it never
touches `:component-file`. The cloned shape therefore inherits
`:component-file` from the source library while the new component is
registered in the destination's local library
(`:apply-changes-local-library? true`), leaving the main-instance
dangling.

Fix
---

Extend `update-new-shape` with a second clause, sibling to the
existing `:component-id` rewrite: when a destination file id is
provided and differs from the new main's current `:component-file`,
re-root the shape. The same `(= (:component-id new-shape) (:id
component))` guard already used for the id rewrite ensures only the
outer main-instance is touched; nested shapes are unaffected.

The destination file id is threaded from the paste entry point
through the two orchestration functions that already knew the
source/destination distinction:

- `generate-duplicate-shape-change` — supplies the destination
  `file-id` it already has in scope when dispatching to
  `generate-duplicate-component-change`.
- `generate-duplicate-component-change` — accepts `:new-component-file`
  as a kwarg; renames its internal `file-id` binding to
  `source-file-id` for clarity (it was always the component's
  originating library file); forwards `new-component-file` to
  `duplicate-variant`.
- `duplicate-variant` — takes and forwards the `new-component-file`
  positional arg.
- `generate-duplicate-component` — accepts `:new-component-file` kwarg
  and passes it to `duplicate-component`.
- `duplicate-component` — applies the rewrite inside
  `update-new-shape`. The `new-component-file` parameter is placed
  right after `new-component-id` since component-id and component-file
  are typically managed together.

Same-file duplication is not affected: without `:new-component-file`
the new clause is skipped, and when source and destination match the
`(not= new-component-file (:component-file new-shape))` guard fails.

Tests
-----

Added in `common/test/common_tests/logic/comp_creation_test.cljc`:

- `test-duplicate-component-rewrites-component-file-to-destination`
  asserts that passing `:new-component-file` to
  `generate-duplicate-component` produces a main-instance with
  `:component-file` equal to the destination id.
- `test-duplicate-component-keeps-component-file-without-dest`
  baseline: without `:new-component-file`, `:component-file` is left
  untouched, matching pre-existing same-file behavior.

Github #8144

Signed-off-by: FairyPigDev <luislee3108@gmail.com>
Co-authored-by: Andrey Antukh <niwi@niwi.nz>
2026-04-30 15:54:24 +02:00
Pablo Alba
f961b75bba ♻️ Cleanup of componentsv2 2025-04-03 11:38:35 +02:00
alonso.torres
052282cff9 🐛 Fix problem updating layout when duplicating component 2025-02-25 11:21:41 +01:00
Pablo Alba
3268225941
🎉 Add variations POC 2025-02-17 16:47:25 +01:00
Andrés Moya
c16ef39abf ♻️ Make test helpers globally usable 2024-05-13 13:10:01 +02:00
Andrés Moya
b6e633865e ✅ Add tests for component creation and modification 2024-05-09 14:49:10 +02:00
Andrés Moya
8b4e52a2be 💄 Improve copy child selection and test robustness 2024-05-09 13:33:52 +02:00