171 Commits
Author SHA1 Message Date
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
Roman Pominov 55280b8348 use RemixLink in Link (#488)
Fixes #457
2022-11-29 13:42:40 +03:00
Bogdan Chadkin 3e96357a2c Use sources as type deifnitions (#539)
Right now our build and CI take a lot of time. 1:40min - 2min on CI and
1min locally. We spend time on vercel, on main CI, on publish and
locally.

At the moment in packages anything outside of src folder is not checked
because of rootDir.

We have to generate "references" field on precommit.

All these issues can be avoided if remove .d.ts generation completely
and specify sources in "types" field. This way we get zero build time
for types and can switch to other build tool (like esbuild) for .js
generation and get almost instant build on vercel, on main CI and on
publish.

Downsides

- it can be slower (actually not really caz we delete .tsbuildinfo cache
anyway and we can still generate it with incremental flag)
- it contraditcs recommended practices for published packages (we can
generate .d.ts in publish script only and use "types" as source
internally)
2022-11-28 22:27:56 +03:00
Ivan Starkov fe3811a373 Move defaults into ws (#541)
meta props are moved to *.ws.ts
Component removed from *.ws.ts

This allows to merge ws props with registered components props
`registerComponents` now are 
-   registerComponents(customComponents);
-   registerComponentsMeta(customComponentsMeta);

_(Splitting will allow for code splitting to work.)_

Removal of `Component` (and then `Icon` prop) would allow serializing
*.ws.ts metadata between iframe and app designer

Next PR:

Move Icon into base64 or like.

publish/subscribe ws meta of registered components, so it can be reused
on the Designer side
I need this to pass props of registered components to Designer.
2022-11-28 21:14:35 +04:00
Bogdan Chadkin b4bf640dcc Replace flags with component type (#532)
Boolean flags may have a lot of combinations which can lead to
unexpected bugs. Better approach is to categorize nodes with specific
behaviours.

Here I added 5 types

- container - can accept other components with dnd
- control - usually form controls like inputs, without children
- embed - images, videos or other embeddable components, without
children
- rich-text - can be edited on double click
- rich-text-child - formatted text fragment, not listed in components
list
2022-11-28 15:04:53 +03:00
Roman Pominov 26f0990347 fix UserProp schema 2022-11-28 12:53:56 +04:00
Roman Pominov da1e8d5056 fix rebase 2022-11-28 11:44:15 +04:00
Oleg Isonen 4fcbf1d108 Merge branch 'main' into 494-primitive-tokens 2022-11-27 18:41:41 +01:00
Ivan Starkov a7125fe695 [release-fix] Fix adding new prop (#531)
- [x] - New property creation was broken
- [x] - Switch on `tag` was seriosly broken

<img width="403" alt="image"
src="https://user-images.githubusercontent.com/5077042/204138926-2ca2e13c-6e46-4ca1-9233-ffdc6475dad8.png">
2022-11-27 21:32:03 +04:00
Bogdan Chadkin 6e5c0f9c1d Split Link and RichTextLink components (#530)
Droppable link an link created in text editor have different
requirements. We should split them. In the next PR they will get
different types so we will avoid similar issues in the future.
2022-11-27 17:25:24 +03:00
Oleg Isonen 52a4f9af6b added aspect ratio property to sizes 2022-11-27 13:46:53 +01:00
Ivan Starkov 9e3f3c46c6 Fix accidentally commented code at #516 (#524)
https://github.com/webstudio-is/webstudio-designer/pull/516#pullrequestreview-1194934498
2022-11-27 11:44:48 +04:00
Roman Pominovandistarkov a9fede0a1d Ability to replace SDK components (#516)
Whats done:
- [x] - Added getComponent, getComponentMeta (old getComponenMeta
renamed to getComponentMetaProps)
- [x] - Added `registerComponents` (for now able only override existing
components)
- [x] - Renamed react-sd `remix` folder to `app`
- [x] - At the `app` folder added `custom-components/Image` wrapper
component, which reads assets etc, and use `webstudio/image`
- [x] `getParams`, `setParams` added at `react-sdk/app/` as they are app
level


TODO:
- [x] Create "normal" `useParams` to be able to use data.params
https://github.com/webstudio-is/webstudio-designer/blob/c05f40818beaac8a811fe0a97ba49e30f01f5045/packages/react-sdk/src/app/custom-components/image.tsx#L15-L23
- [x] Reuse props meta from imported image - created issue
https://github.com/webstudio-is/webstudio-designer/issues/521

Co-authored-by: istarkov <istarkov@gmail.com>
2022-11-27 02:47:14 +04:00