183 Commits
Author SHA1 Message Date
Ivan Starkov d76c598090 Switch on link and generate css for all pages on server (#1041)
## Description

We are going to render CSS for all pages in production mode.
That allows us to switch on native remix links i.e. `export const links`

Also now for `published` pages we use same data as SaaS will. 
That would allow for investigating SaaS issues faster.

[x] - Also now check does ssr css is needed at all at "edit" mode.
_Checked, as of now we don't render `style` tags serverside and that
cause FOUC in designer on page switch,
cc @TrySound probably in Canvas we can render styles serverside too that
would allow us to not use /s/css path for canvas inside designer_


closes #929
closes https://github.com/webstudio-is/webstudio-saas/issues/51
closes #606

## Steps for reproduction

In local dev mode, create 2 pages in a project, and add cross-links on
both pages.
Do publish.
Go to the published page, see no fouc on link clicks.




## Code Review
- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)

- [ ] hi @TrySound , I need you to do
  - 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-builder/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `builder/env-check.js` if mandatory
2023-02-16 14:24:04 +03:00
Roman Pominov 343647d52a Props panel: Basics (#1031)
#992

1. Cleaned up control types
2. Control type is now chosen by component meta (including Image.src)
3. Added custom labels support
4. Some other changes mentioned in comments in diff
2023-02-16 11:18:43 +03:00
Bogdan Chadkin 0c506ed79e Move breakpoints schema to project-build (#1027)
Breakpoints are not really related to css data and represent project
build data so moving it before switching to map patches.
2023-02-14 16:37:33 +03:00
Andras Bacsai ac413cdd5f rename designer to builder 2023-02-14 11:15:24 +01:00
Ivan Starkov 2f1ba03544 Update typescript (#1025)
## Description

1. What is this PR about (link the issue and add a short description)

## 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-designer/blob/main/apps/designer/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `designer/env-check.js` if mandatory
2023-02-13 23:19:11 +03:00
Roman Pominov 2e43ba1b39 Don't crash on href=// (#1017)
Fixes #997
2023-02-13 16:02:22 +03:00
Bogdan Chadkin 10ea732ee2 Resolve props assets on client (#1005)
Before we checked looked for all asset ids in props, loaded assets and
replaced ids with resolved assets. This is all on server. We faced a few
problems with it.

- requires to maintain two versions of types: stored in db and resolved
for client
- easy to break project by writing to db wrong version

Here I provide to sdk both props and assets and resolve on client with
almost same amount of code.

Also replaced store setter with context, see
https://github.com/webstudio-is/webstudio-designer/issues/213
2023-02-13 12:42:02 +03:00
Bogdan Chadkin 136a7bd157 Represent props on client as map (#972)
Ref https://github.com/webstudio-is/webstudio-designer/issues/696

While normalized array of props give us flexibility with atomic updates
we still cannot use it for collaboration because patches are applied
with index in this array which may leads to unexpected results when two
users collaboate on the same tree, for example both put new prop and
edit it before synchronization by the same index, we are getting
conflict.

To avoid such issues we can switch client representation to maps. Almost
all data have ids to use in map as keys. Map makes collaboration almost
conflict free.
2023-02-08 20:23:41 +03:00
Bogdan Chadkin 073062a4bf Move breakpoints to Build table (#926)
Ref https://github.com/webstudio-is/webstudio-designer/issues/744

We are trying to co-locate data and simplify cloning/copying. Here I
migrated Breakpoints.values into Build.breakpoints.

This makes Build responsible to all data scoped to project build similar
to tree scope.

We get projectId defined for free and no need additional sql
maintenance.
2023-02-02 21:43:03 +03:00
Oleg Isonen e925d26bc9 Delete design tokens prototype (#873)
## Description

1. With all the new ideas and directions we don't need that initial
implementation

## Code Review

- [ ] hi @TrySound , 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-designer/blob/main/apps/designer/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `designer/env-check.js` if mandatory
2023-01-28 18:05:53 +01:00
Bogdan Chadkin 8635dc6755 Switch to normalized props on server (#883)
Ref https://github.com/webstudio-is/webstudio-designer/issues/696

Now all props is migrated on client side, we can drop legacy store and
switch to new format server side.
2023-01-28 15:24:23 +03:00
Bogdan Chadkin ff049a000c Inject props store to sdk (#871)
Ref https://github.com/webstudio-is/webstudio-designer/issues/696

We use store to render props in sdk components. Though it's easier to
maintain actual store in designer and provide necessary data to sdk.

Here I added utilities to inject computed store on module level. Now we
can get rid of legacy store and rewrite rest api to use normalized
props.
2023-01-28 10:48:13 +03:00
Bogdan Chadkin bf50c0c547 Move project build schema into separate package (#864)
The new package will be responsible for schema and db access to all
build and tree data.

Decoupling will let us make sdk and project thinner.
2023-01-26 21:03:17 +03:00
Bogdan Chadkin 185fb27c85 Treat component name as generic string (#861)
We want to decouple schema stored in db from sdk which generates a list
of components. Components will be added dynamically later so better
avoid component name enum.
2023-01-26 17:33:26 +03:00
Bogdan Chadkin aba909ad63 Drop preset styles from db (#848)
After discussing with @kof figured we do not need to store preset styles
in db as after sdk upgrade components may still break.

Sdk versioning along with its hardcoded values will solve the problem
better.
2023-01-25 18:55:11 +03:00
Bogdan Chadkin 78196958cd Transform styles without zod (#822)
Found zod allows to pass anything in transform without type checking.
This means we can easily get unexpected result. In this case we could
get undefined as asset.

As a solution I defined two versions of types, client side and stored in
db. Conversion is implemented on db routes side.

This makes data flow more clear and let us describe only two versions of
types instead of tree (in, out, client side).
2023-01-23 20:39:48 +03:00
Bogdan Chadkin bb288f309b Replace UserProp with PropsItem (#833)
Here is migration to new props type with more safe conversion to db
format. Added two versions StoredPropsItem for and PropsItem for client
and got rid of "as" casting.
2023-01-22 15:57:37 +03:00
Bogdan Chadkin 78af54b017 Migrate InstanceProps into Tree table as props column (#819)
InstanceProps is designed to store props per each instance which
requires a lot of sql updates on every props change.

Here moved per instance props into array with props for whole tree. This
way patches are safer to apply on large trees.

```
type PropsItem = {
  id: string,
  instanceId: string,
  name: string,
  required?: boolean,
  type: 'number' | 'string' | 'boolean' | 'asset',
  value: number | string | boolean
}
```
2023-01-20 13:02:13 +03:00
Bogdan Chadkin 1d457b5b98 Normalize instances in db (#788)
Ref https://github.com/webstudio-is/webstudio-designer/issues/696

Here only migration and converters between tree and list on db access.
2023-01-16 14:58:49 +03:00
Bogdan Chadkin 35354522d9 Move props updates to designer (#784)
Props have a lot of logic to synchronize values. And after moving
updates into designer we get fresh state instantly and can simplify the
logic even more.
2023-01-14 14:11:26 +03:00
Bogdan Chadkin f9052681a3 Simplify props state (#783)
Turns out we store whole db representation in each props each per
instance item. This is wasteful and increase complexity of code.

```
{
  [InstanceId]: {
    id: UUID,
    instanceId: InstanceId,
    treeId: TreeId,
    props: UserProp[]
  }
}
```

Where instance id is duplicated and tree id is provided as patch
context. Id can be replaced with combination of instance id and tree id.

```
{
  [InstanceId]:  UserProp[]
}
```
2023-01-14 12:46:49 +03:00
Bogdan Chadkin 3abb54a875 Migrate to nanostores (#779)
Ref https://github.com/nanostores/nanostores

Nanostores is another open source implementation of reactive states.
Supports a lot of frameworks and provides useful utilities like computed
stores. Api is slightly different

```
store.get(): Value
store.set(value: Value)
```

`useStore` resolves only value so I temporary added custom `useValue` to
not rewrite whole project. Since we gonna use computed atoms it makes
more sense to invoke useStore where atom value is used instead of
reusable hook.
2023-01-13 15:13:40 +03:00
Bogdan Chadkin 44a7083fde Drop css rules from instance (#775)
Ref https://github.com/webstudio-is/webstudio-designer/issues/696

Finally got rid of legacy instance.cssRules.
Removed style utils for working with tree.
Now will be easier to normalize tree.
2023-01-13 13:04:21 +03:00
Bogdan Chadkin 8a691b92d1 Update normalized styles directly (#757)
Ref https://github.com/webstudio-is/webstudio-designer/issues/696

Migrated updating and rendering to normalized styles. There are still a
few cases to migrate so left legacy root instance updates.

Styles are updated with immerhin consistently with whole project.

Can be tested changing styles and deleting breakpoints.
2023-01-09 12:17:20 +03:00
Bogdan Chadkin 6387accf0d Render static css from normalized styles (#750)
Ref https://github.com/webstudio-is/webstudio-designer/issues/696

Gradually starting to migrate to new styles format. Here replaced
getCssRules and getPresetStylesMap with getStyleRules and
getPresetStyleRules utilities.

Will reuse both at once on release.
2023-01-06 16:44:03 +03:00
Bogdan Chadkin 7c5c737bfb Normalize styles in database (#749)
Ref https://github.com/webstudio-is/webstudio-designer/issues/696

Here only migration and transforms for load and patch. Styles have the
following type and stored in Tree.styles column.

```
Array<{
  breakpointId: string,
  instanceId: string,
  property: StyleProperty,
  value: StyleValue
}>
```

Did migration with cursor pagination with 1000 trees per transaction.
2023-01-06 14:38:21 +03:00
Bogdan Chadkin d79c96566b Store preset style separately from tree (#724)
Before we populated preset style on instance creation. This does not let
us to distinct preset style from local one.

As an option we could use preset style hardcoded in meta though this may
affect user when we change defaults.

Here I added presetStyle column in Tree table with the list of styles
for component.

```
Array<{
  component: string,
  property: string,
  value: StyleValue
}>
```

Will style controls as grey for such styles.
2023-01-05 21:27:33 +03:00
Roman Pominov 91e209e974 rename Spacing to Space (#745)
Renamed Spacing section to Space in code and in UI
2023-01-05 14:59:32 +03:00
Bogdan Chadkin 5fe9364cb1 Improve units in style panel (#735)
Ref https://github.com/webstudio-is/webstudio-designer/issues/366

- generate grouped units for non length values
- show unit select when initial unitless

So we get all 3 points from the issue

- all properties has only supported units
- hidden but supported units still can be entered
- unsupported values are validated

<img width="243" alt="Screenshot 2023-01-04 at 14 12 29"
src="https://user-images.githubusercontent.com/5635476/210546684-ca696096-f78c-445f-bbc3-04db7326239b.png">
<img width="224" alt="Screenshot 2023-01-04 at 14 14 54"
src="https://user-images.githubusercontent.com/5635476/210546689-396c7d42-e6f0-42a9-869c-7b231baa3d71.png">
2023-01-04 18:20:15 +03:00
Mateusz Burzyński 28a2d85465 Tweak Instance type (#732) 2023-01-03 21:27:25 +01:00
Bogdan Chadkin 5a2b3b8eec Parse properties initial value (#726)
Ref https://github.com/webstudio-is/webstudio-designer/issues/366

Parsed initial values to get correct unit instead of px for some
properties. There is still edge case with unitless values I'm gonna fix
in another PR.

Also bumped mdn-data and removed overrides fixed on mdn side.
2023-01-03 19:57:16 +03:00
Oleg Isonen ce5cfeca0a Add object position property (#708)
## Description

Somehow we forgot to add object-position

## Steps for reproduction

1. select instance
2. go to sizes section in style panel

## Code Review

- [ ] hi @istarkov  I need you to do
  - conceptual review (architecture, feature-correctness)

## Before requesting a review

- [x] made a self-review
- [x] 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-designer/blob/main/apps/designer/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `designer/env-check.js` if mandatory
2022-12-27 13:21:45 +01:00
Bogdan Chadkin 41c533271a Convert text children to nodes in tree (#654)
Ref https://github.com/webstudio-is/webstudio-designer/issues/651

We want to normalize our tree structure and need to distinct text
children with ids. Now instead of string its respresented as
```
{
  type: 'text',
  value: string
}
```

This also gives us a little type safety because typeof child ===
'string' ignores when child cannot be string.
2022-12-19 22:44:13 +03:00
Bogdan Chadkin bb0e315338 Update hovered rect when scroll ends (#650)
Ref https://github.com/webstudio-is/webstudio-designer/issues/630

Simplified hovered logic to single effect, removed unnecessary
nano-state container and fixed hovered outline rect when scroll ends.
2022-12-18 16:44:24 +03:00
Oleg Isonen 703a9fe215 Merge pull request #639 from webstudio-is/621-smallest-breakpoint-should-start-from-0
Start the smallest breakpoint at 0
2022-12-16 18:35:38 +00:00
Bogdan Chadkin 752768abbc Use explicit imports from @jest/globals (#645)
pnpm prevents access to jest and @types/jest from packages so we need to
explicitly install it. Though @types/jest is not officially maintained
and often late for months with new major which bloats node_modules with
two versions of jest transitives.

Here is alternative way to use official types. The only downside is
complains these types has less descriptions.
2022-12-16 16:35:22 +03:00
Oleg Isonen 7f62539435 start the smallest breakpoint at 0 and use the upper bound to set the canvas size 2022-12-15 18:09:04 +00:00
Bogdan Chadkin 122bd8adb5 Track selected rect close to element (#627)
Ref https://github.com/webstudio-is/webstudio-designer/issues/598

When tracking selected element from the root it's hard to get current
element which can be changed with props.

One more issue is storing element in state doubles amount of renders and
in selected instance logic we have a chain of state -> effect -> state
-> effect cases.

Here I store element in ref so we avoid rerender when set element to
state. Then tracked element rect is not written to state and sent to
designer directly.

Since the effect is unmounted along with element we do not need to use
mutation observer to track parent changes and can just recompute rect on
remount.
2022-12-15 16:01:40 +03:00
Bogdan Chadkin 1459fd7cbd Remove treeId from props updates (#635)
Will help with
https://github.com/webstudio-is/webstudio-designer/issues/628

treeId is stored in every props update which complicates data flow and
requires passing it everywhere. Here I instead pass it inside of
transaction.

This allowed us pass undefined in props data when select instance so we
no longer need to create empty instance props. Updates will create it
lazily.
2022-12-15 15:56:27 +03:00
Oleg Isonen 142fbda626 defaultStyle presetStyle 2022-12-14 23:51:01 +00:00
Ivan Starkov 1ac167d959 Add initial props 2022-12-12 00:14:43 +03:00
Andras Bacsai 27469787a0 fix eslint 2022-12-08 13:21:37 +01:00
Ivan Starkov bb6a1d28e3 [progress] Naive aspectRatio (#556)
## Before requesting a review

- [ ] if the PR is WIP - use draft mode
- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")
- [ ] what kind of review is needed?
  - [ ] conceptual
  - [ ] detailed
  - [ ] with testing

## Test cases

- [ ] step by step interaction description and what is expected to
happen

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio-designer/blob/main/apps/designer/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `designer/env-check.js` if mandatory
2022-12-07 22:05:49 +04:00
Bogdan Chadkin 05e69ac016 Give body separate type in sdk (#560)
Body is the only container which should not be listed. After discussing
with Oleg decided to give it separate body type.
2022-12-07 16:17:33 +03:00
Oleg Isonen 3c088b2c04 Merge branch 'main' into 494-primitive-tokens 2022-12-03 15:38:31 +01:00
Bogdan Chadkin fb946ab296 Fix span component type (#552)
Mistyped when added type to components.
2022-12-03 16:33:06 +03:00
Oleg Isonen 8d26bf781b move shared design tokens logic to a separate package 2022-12-03 12:09:22 +00:00
Oleg Isonen 0d07f9a27c Merge branch 'main' into 494-primitive-tokens 2022-12-03 11:41:08 +00:00
Ivan Starkov b6c6f57f2c Fix that images with asset had value inside db (#549)
ref #196

- [x] UserProps now [discriminated union by
type](https://github.com/webstudio-is/webstudio-designer/blob/img_asset/packages/react-sdk/src/user-props/schema.ts#L10-L31)

- [x] Data migrations done
2022-12-02 14:53:30 +04:00
Oleg Isonen a06a3db058 Merge branch 'main' into 494-primitive-tokens 2022-12-02 00:27:51 +00:00