64 Commits
Author SHA1 Message Date
Oleg Isonen d339dc55cf feat: Add token conflict detection and resolution for marketplace templates (#5609)
- Add Token class and token() helper in template package for JSX token
support
- Refactor insertFragmentWithConflictResolution to
detectFragmentTokenConflicts
- Refactor insertPageWithConflictResolution to detectPageTokenConflicts
- Move dialog display to callers for better testability
- Add conflictResolution parameter to page-utils
- Add comprehensive tests for token functionality and conflict detection
- Fix bug: remove .values() call on arrays in breakpoint handling
2026-02-05 22:34:17 +01:00
Oleg Isonen 11ba996f13 feat: New token conflict resolution logic (#5524)
Fixes https://github.com/webstudio-is/webstudio/issues/5491

## Description

- When pasting an instance with tokens, we can compare the name and the
contents. If they are identical, we can choose the existing one and
avoid having any conflicts.
- When pasting a token and the name is already used, add a numeric
suffix to it.
- find duplicate tokens command that will go based on content even if
name is different


## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
0000)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env` file
2025-12-18 17:31:31 +01:00
Bogdan Chadkin 3d064f1b20 fix: paste markdown (#5235)
Async in html paste broke markdown because await was missing in onPaste.
2025-05-28 00:24:46 +03:00
Bogdan Chadkin 59b6471c4f experimental: support paste html (#5185)
Ref https://github.com/webstudio-is/webstudio/issues/4404

Slightly reworked paste story. Now minimal API to insert html looks like
this

```js
const fragment = generateFragmentFromHtml(html);
insertWebstudioFragmentAt(fragment);
```

- attributes are casted to string, number and boolean types
- text is wrapped with spans when outside of rich text
- unsupported tags are ignored in result



https://github.com/user-attachments/assets/c8072d86-72bd-4446-a26a-e678b193f93e
2025-05-06 13:31:13 +04:00
Bogdan Chadkin 655b887ab9 feat: support paste from other browsers (#5181)
Users started to build own marketplaces. And we found paste something
copied from other browser like firefox -> chromium based app doesn't
work. This is because OSs guarantee only text/plain to be stored in
system clipboard.

Here I changed copy paste logic to copy as text/plain and paste as both
application/json and text/plain if possible.
2025-05-04 18:41:00 +04:00
Bogdan Chadkin e622e08df6 refactor: drop legacy matchers (#5146)
We already fully switched to component content model and no longer
necessary legacy matchers.
2025-04-20 16:59:22 +07:00
Bogdan Chadkin 4e6a448d96 fix: insert marketplace sections after selected instance (#4918)
Closes https://github.com/webstudio-is/webstudio/issues/4902

Rapid prototyping requires slightly different logic for inserting from
marketplace so sections could be added one after another.
2025-02-27 01:44:21 +07:00
Bogdan Chadkin 8ed3fbb085 feat: support global data variables (#4870)
Ref https://github.com/webstudio-is/webstudio/issues/4166
https://github.com/webstudio-is/webstudio/issues/3686

Added "Settings" section to global root. Now users can create data
variables which are available for all pages and inside slots.



https://github.com/user-attachments/assets/be2cf862-08ec-427e-aea3-076fa03a4437
2025-02-15 01:23:16 +08:00
Bogdan Chadkin 453956bf83 refactor: delete prop resources (#4839)
Ref https://github.com/webstudio-is/webstudio/issues/4093

Here a few delete instance improvements

- fixed deleting resources bound to props (action in webhook form)
- rewrote all tests with jsx template
- switched from instance selector to instance path
- added slot test
2025-02-07 10:50:44 +07:00
Bogdan Chadkin 94f219c249 refactor: rewrite core components templates with jsx (#4756)
Here refactored all core components with jsx templates and moved them to
sdk package. Fixed all imports as well.
2025-01-17 18:29:40 +07:00
Bogdan Chadkin 14494a9c77 fix: relax detaching constraint (#4672)
Every time somebody is facing invalid constraint issue whole tree is
blocked from deleting instances except the problematic one with actual
issue.

Here rewrote detachability check to validate only ancestors and avoid
traversing potentially problematic siblings.
2025-01-07 02:28:15 +07:00
Bogdan Chadkin bc0f6bb6a3 refactor: generalize insertable lookup (#4398)
Here replaced a bunch boilerplaty code with more general
findClosestInsertable. This also reduced amount of explicit instance
selector calls. Prevented inserting list item into body. Refactored
tests with jsx.
2024-11-10 23:02:15 +04:00
Bogdan Chadkin 6b1ea5eb4a refactor: move selected page into awareness state (#4371)
Ref https://github.com/webstudio-is/webstudio/issues/4364

We need to implement universal linking of current user view. For this I
added "awareness" state which reflects terminology from collaboration
libraries.

First migrated selected page id and fixed usages.
2024-11-06 02:29:52 +04:00
Oleg Isonen 4aef12cd7a experimental: Paste from webflow 4 (#3491)
## Description

- webflow css preset

## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env` file
2024-06-05 17:14:23 +02:00
Bogdan Chadkin 9e37075e7d refactor: move insert instance children logic into utility (#2931)
Here split and consolidated utility for adding children to instances. It
can be universally reused almost everywhere.
2024-02-21 17:08:10 +07:00
Bogdan Chadkin bf6223902e refactor: allow to extract webstudio fragment from any data (#2927)
Here refactored to extract fragment or copy from any data not only
global stores.
2024-02-19 17:33:26 +07:00
Bogdan Chadkin 3863abec2a refactor: rename instances slice to webstudio fragment (#2925)
Here renamed everywhere in the code instances slice to webstudio
fragment to keep naming consistent across whole app.
2024-02-18 17:43:07 +07:00
Bogdan Chadkin 29df24bfaf experimental: update variables when duplicate page (#2886)
Here improved page duplicate logic to support replacing old variables in
page meta and path params variable with new references.

Also improved path duplicating to preserve path params by prefixing with
`/copy-n` subpath.
2024-02-09 23:53:37 +07:00
Bogdan Chadkin 1e7ef26dc9 refactor: make inserting fragments copy composable (#2783)
Ref https://github.com/webstudio-is/webstudio/issues/2532

Here refactored insertInstancesSliceCopy to accept webstudio data
instead of creating transaction.

This let us avoid hacky callbacks in duplicate instance and duplicate
page functionalities.

Note: review with hidden whitespaces
2024-01-21 12:15:08 +07:00
Bogdan Chadkin a84320666d refactor: make delete instance composable (#2781)
Here refactored delete instance to accept and mutate webstudio data
instead of accessing data stores.
Now we can avoid double transaction when delete pages.

Note: review with hidden whitespaces
2024-01-19 22:55:10 +07:00
Bogdan Chadkin f620e2e1f2 refactor: generalize transferrable fragments (#2780)
Here added two new types

WebstudioFragment - reusable fragment of webstudio data which can be
generated (markdown, embed template), transferred (copied or stored in
marketplace) and inserted.

WebstudioData - all available normalized data to allow composing
multiple operations within single transaction like delete instance and
then insert into other part of the page.
2024-01-19 22:24:59 +07:00
Bogdan Chadkin a76c29fc05 feat: inline variables outside current component/slot (#2778)
Ref https://github.com/webstudio-is/webstudio/issues/2532

Important constrain on the way to custom components to not use data
sources defined in other components when copy paste.

## Steps for reproduction

1. Test covers it
2024-01-18 23:37:50 +07:00
Bogdan Chadkin 8e1683ed86 refactor: switch to instances slice for copy paste (#2666)
Use same well tested utility to slice and insert its copy for copy
paste. Moved most utilities inside of instance plugin and added more
tests for it.

## Steps for reproduction

1. play with copy paste
2023-12-06 23:49:48 +07:00
Bogdan Chadkin d361c9ecee feat: add collection component to builder (#2657)
Ref https://github.com/webstudio-is/webstudio/issues/2532

Here added a "core" collection component to support iterating over json
arrays.

There is a lot of room for unification of all this logic though would
require building reactive tree abstraction.

Canvas automatically renders stub component for collection to make it
droppable. We can do the same for slot component.

Slot and Fragment eventually will go to "core" components too.

Added json/parameter prop types to embed template to support collection.

Fixed loosing focus while typing in json prop.

## Steps for reproduction

1. Drop collection component
2. play with it
2023-11-29 17:07:28 +03:00
Bogdan Chadkin 6dd5b0687a refactor: drop legeacy data source prop support (#2600)
Ref https://github.com/webstudio-is/webstudio/issues/2532

We successfullly migrated prod to expression prop. Now we can safely
remove legacy data source prop
handling across codebase.
2023-11-11 18:07:17 +03:00
Bogdan Chadkin 052fe4e3ce refactor: add expression prop (#2582)
Ref https://github.com/webstudio-is/webstudio/issues/2532

On the last discussion about bindings we agreed expression are always
bound to single prop and cannot be reused.

Here added new prop.type = 'expression' as a replacement to
dataSource.type = 'expression'.

This will let us unify expression/variable reference and avoid deep
dependencies. Expressions and actions become similar.

For now both expression prop and legacy expression data source are
supported until we migrate completely in db.
2023-11-08 20:46:57 +03:00
Bogdan Chadkin fa06b7d495 feat: reuse variables on copy/paste within same tree (#2580)
Ref https://github.com/webstudio-is/webstudio/issues/2532

Here improved copy/paste behavior.

Before variables outside of copied tree were inlined. For example
ErrorMessage were loosing its expression when duplicated within same
form.

Now expressions and variables are preserved
and variables are inlined into expressions when paste target do not have
such variable. For example ErrorMessage get `"initial" == "error"`. With
upcoming UI it will be more obvious. The main idea here to not loose all
expressions but only references to unavailable variables.
2023-11-07 18:58:50 +03:00
Bogdan Chadkin 78d9ea912d refactor: split instances slice into separate utility (#2521)
Split instances slicer into separate utility from copy paste plugin.
Will be used to duplicate pages. Along with splitting added more tests
to better cover behavior.
2023-10-25 23:55:11 +04:00
Bogdan Chadkin a379a98c1f refactor: split stores with server synchronization (#2410)
New version of immerhin moved global queue into store instance so we can
stop filtering and just call store.popAll().

Also replaced default store with webstudio own serverSyncStore instance.
Now auto import works much better.
2023-10-03 20:13:57 +04:00
Bogdan Chadkin 75f72eeccf Drop legacy data sources from builder (#2319)
Here removed all left usages of previous data sources implementation and
removed no longer used expression utilities.
2023-09-16 14:17:10 +04:00
Bogdan Chadkin ee0e0f7e7a Drop prisma from cli (#2241)
Here moved types and utilities from project-build to sdk package. This
removed huge prisma from cli.

```
du -ck node_modules
137460
72464
```
2023-09-04 12:43:56 +04:00
Bogdan Chadkin 5794e8d1e7 Move app schema to sdk (#2237)
We are planning to decouple cli from prisma and all unrelated packages.
Here moved whole app schema into sdk package.
2023-09-03 22:27:30 +04:00
Bogdan Chadkin f5882256b8 Move assets schema into sdk package (#2220)
We are planning to move all types necessary to represent generated site
into separate package. This way we will be able to make CLI as small as
possible.

Here moved only assets schema. Now we get rid of aws, sharp and one
prisma usage (project-build still use it)

```diff
- 99MB
+ 75MB
```
2023-08-31 19:39:20 +04:00
Bogdan Chadkin 685ca24552 Support actions copy paste (#1976)
Here added action copy paste support.

When all action dependencies are scoped to copied instance new variable
nams are ussed.

When some any dependency is not scoped execution is removed from copied
prop.
2023-07-28 01:53:58 +03:00
Bogdan Chadkin 9328961b87 Allow to disable components detaching (#1986)
Here added meta.detachable flag which allows when set to true disable
copying, dragging and deleting instances of this component without ts
parent instance.

This is necessary to constrain components based on external code and
prevent deleting hidden components user cannot add again.
2023-07-27 20:43:46 +03:00
Bogdan Chadkin be74680674 Support duplicating instances (#1995)
Fixes https://github.com/webstudio-is/webstudio-builder/issues/1994

Here changed behavior when copy and paste without changing instance
selection. Now it works as duplicating and copy is inserted after
selection.

Added cmd+d and ctrl+d shortcut to do this with single press without
polluting clipboard.
2023-07-27 15:52:10 +03:00
Bogdan Chadkin b226343599 Support copy pasting of data sources (#1963)
Here fixed the case when copy pasted form looses state and give errors
on submit.

Immerhin now converted to esm to work in tests.
Added tests for instances copy paste plugin.
The new logic is copy data sources as is if they are bound to copied
instances.

The new computeExpressionsDependencies used to detect if expression
depends on data sources outside of copied instances scope.
2023-07-23 11:56:13 +03:00
Bogdan Chadkin 6037a039b7 Compute insert constraints for tree (#1954)
Fixes https://github.com/webstudio-is/webstudio-builder/issues/1950

Here added new utility to compute constraints for tree when insert embed
template, paste something or reparent. I previous implementation all
constraints were merged which gave us false positives like when paste
List>ListItem we got "requiredAncestors: [List]". Here tree layout is
considered to exclude such false positives.

For testing try to copy paste List>ListItem
2023-07-19 22:23:34 +03:00
Bogdan Chadkin eb0bc5ff77 Support pasting embed templates (#1936)
Here refactored copy paste plugin system to try each plugin until it
succeeds. This way we can have multiple solutions to copy paste from
plain text. For example embed template is hand written text and should
succeed before markdown starts parsing it.

```json
{
  "@webstudio/template": [
    {
      "type": "instance",
      "component": "Box",
      "children": [
        { "type": "text", "value": "Hello, I'm Box!" }
      ]
    }
  ]
}
```
2023-07-16 13:38:07 +03:00
Bogdan Chadkin b424f9fbde Fix invalid ancestors for deeply nested instances (#1932)
Fixed the issue with pasting checkbox into button
which is wrapped into label

Prevented inserting label, checkbox, radio button and input into
buttons.
2023-07-14 19:28:29 +03:00
Bogdan Chadkin 05df3910f5 Support effectful expressions in component actions (#1914)
Here added support for callbacks or event handlers on components which
basically can do only assignment to variables for now with extended
(with assignment operator) syntax of expressions.
2023-07-11 20:27:06 +03:00
Bogdan Chadkin 114817c266 Support data source expressions (#1882)
Ref https://github.com/webstudio-is/webstudio-builder/issues/1529

Here introduced two types of data sources into "variable" and
"expression". First stores the value, the second only executable code.

Execute expressions now output results of all expressions so we could
access values globally with "computed" store

Embed template references now allow to define both variable reference
and expression.
2023-06-30 22:22:12 +03:00
Bogdan Chadkin 730d897039 Support data source insert from template (#1826)
Ref https://github.com/webstudio-is/webstudio-builder/issues/1529

- added data sources store
- added dataSource type to props
- insert data sources from template (prop.dataSourceReference allows to
bind several props to the same data source)
- convert to static prop on copying (simplification until requirements
are clear)
2023-06-21 19:57:42 +03:00
Bogdan Chadkin fa8dc705ba Prevent selection of pasted data (#1782)
Ref https://github.com/webstudio-is/webstudio/discussions/34

Looks like selection of pasted data does not work well so here remove
it.
2023-06-14 16:35:36 +03:00
Bogdan Chadkin dcae1b5a9d Allow inserting into editable containers (#1735)
Here I removed "rich-text" type from components. Instead "container" can
be edited when has only text or rich text children.

And any time user can drop into editablle container which will wrap all
text and rich text children into "Span" component.

Had to implement position adjustment to consider text children which do
not have representation in navigator tree and canvas dnd.

Span has temporary SpanContainer name to not conflict with existinig
Span for styled text in rich text. Will rename in other PR when remove
no longer necessary components.
2023-06-10 00:55:46 +03:00
Bogdan Chadkin 7c66afef74 Add requiredAncestors and invalidAncestors to meta (#1684)
Here added two component restrictions to meta.

requiredAncestors prevent inserting components outside of required ones
here restricted ListItem to always be inside of List.

invalidAncestors prevent inserting components inside of invalid ones
here prevented nested buttons
2023-05-30 12:33:44 +07:00
Roman Pominov 68243c6876 Assets copy-paste (#1636)
## Description

1. Closes #1325
2. Assets used in styles are copied
3. Assets used in props are copied
2023-05-16 14:34:42 +03:00
Bogdan Chadkin a167d702f7 Fix copy paste of style sources (#1570)
Ref
https://discord.com/channels/955905230107738152/955907841070346300/1103260031048241182

Here style sources were pasted without copying. Here I renamed the
utility to clarify a little and provided proper list of instance ids.
2023-05-05 14:34:51 +07:00
Bogdan Chadkin 4e31256b2a Restrict allowed parents with config in meta (#1542)
Added `allowedParentComponents: string[]` option to meta which prevents
dropping, inserting or pasting components into wrong parents. For
example ListItem now can be placed only inside of List component.

This will unlock better experience with compound radix components.
2023-05-02 15:20:22 +08:00
Bogdan Chadkin a148507e48 Render style states (#1420)
Ref https://github.com/webstudio-is/webstudio-builder/issues/807

Refactored styles rendering in canvas to consider states and added style
states support to css text renderer.
2023-04-17 15:50:14 +07:00