Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Rename singular props and styles names (#953)

Bogdan Chadkin49e82f8f2d40
diff --git a/apps/designer/app/canvas/features/wrapper-component/selected-instance-connector.ts b/apps/designer/app/canvas/features/wrapper-component/selected-instance-connector.ts
index 3029905fc1..fb6b805f10 100644
--- a/apps/designer/app/canvas/features/wrapper-component/selected-instance-connector.ts
+++ b/apps/designer/app/canvas/features/wrapper-component/selected-instance-connector.ts
@@ -1,5 +1,5 @@
import { useEffect } from "react";
-import type { Instance, PropsItem, Styles } from "@webstudio-is/project-build";
+import type { Instance, Prop, Styles } from "@webstudio-is/project-build";
import { getBrowserStyle } from "@webstudio-is/react-sdk";
import { publish, subscribe, subscribeAll } from "~/shared/pubsub";
import {
@@ -54,7 +54,7 @@ export const SelectedInstanceConnector = ({
instanceElementRef: { current: undefined | HTMLElement };
instance: Instance;
instanceStyles: Styles;
- instanceProps: undefined | PropsItem[];
+ instanceProps: undefined | Prop[];
}) => {
useEffect(() => {
const element = instanceElementRef.current;
diff --git a/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx b/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx
index 0717c52b98..40bb2384c5 100644
--- a/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx
+++ b/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx
@@ -2,7 +2,7 @@ import type { MouseEvent, FormEvent } from "react";
import { Suspense, lazy, useCallback, useMemo, useRef } from "react";
import { useStore } from "@nanostores/react";
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
-import type { Instance, PropsItem } from "@webstudio-is/project-build";
+import type { Instance, Prop } from "@webstudio-is/project-build";
import {
type OnChangeChildren,
renderWrapperComponentChildren,
@@ -41,7 +41,7 @@ const ContentEditable = ({
return <Component ref={ref} {...props} contentEditable={true} />;
};
-type UserProps = Record<PropsItem["name"], string | number | boolean>;
+type UserProps = Record<Prop["name"], string | number | boolean>;
type WrapperComponentDevProps = {
instance: Instance;
diff --git a/apps/designer/app/designer/features/props-panel/control.tsx b/apps/designer/app/designer/features/props-panel/control.tsx
index 0ece62ab9d..71ebd592bd 100644
--- a/apps/designer/app/designer/features/props-panel/control.tsx
+++ b/apps/designer/app/designer/features/props-panel/control.tsx
@@ -1,4 +1,4 @@
-import type { Instance, PropsItem } from "@webstudio-is/project-build";
+import type { Instance, Prop } from "@webstudio-is/project-build";
import { getComponentMetaProps } from "@webstudio-is/react-sdk";
import warnOnce from "warn-once";
import {
@@ -176,7 +176,7 @@ const assertUnreachable = (_arg: never, errorMessage: string) => {
type ControlProps = {
component: Instance["component"];
- userProp: PropsItem;
+ userProp: Prop;
onChangePropValue: (value: UserPropValue) => void;
setCssProperty: SetProperty;
};
diff --git a/apps/designer/app/designer/features/props-panel/props-panel.stories.tsx b/apps/designer/app/designer/features/props-panel/props-panel.stories.tsx
index 0a6eb07a19..39d0f94460 100644
--- a/apps/designer/app/designer/features/props-panel/props-panel.stories.tsx
+++ b/apps/designer/app/designer/features/props-panel/props-panel.stories.tsx
@@ -1,5 +1,5 @@
import type { ComponentStory } from "@storybook/react";
-import type { PropsItem } from "@webstudio-is/project-build";
+import type { Prop } from "@webstudio-is/project-build";
import { getComponentMetaProps } from "@webstudio-is/react-sdk";
import { propsStore } from "~/shared/nano-states";
import { PropsPanel } from "./props-panel";
@@ -78,7 +78,7 @@ export const AllProps: ComponentStory<typeof PropsPanel> = () => {
instanceId: "3",
name,
value: value?.defaultValue ?? "",
- } as PropsItem;
+ } as Prop;
})
);
return (
diff --git a/apps/designer/app/designer/features/props-panel/props-panel.tsx b/apps/designer/app/designer/features/props-panel/props-panel.tsx
index a6cff879d7..0903b492e0 100644
--- a/apps/designer/app/designer/features/props-panel/props-panel.tsx
+++ b/apps/designer/app/designer/features/props-panel/props-panel.tsx
@@ -1,6 +1,6 @@
import { useState } from "react";
import store from "immerhin";
-import type { Instance, PropsItem, Tree } from "@webstudio-is/project-build";
+import type { Instance, Prop, Tree } from "@webstudio-is/project-build";
import { getComponentMetaProps } from "@webstudio-is/react-sdk";
import {
theme,
@@ -119,7 +119,7 @@ const Combobox = ({
};
type PropertyProps = {
- userProp: PropsItem;
+ userProp: Prop;
component: Instance["component"];
onChangePropName: (name: string) => void;
onChangePropValue: (value: UserPropValue) => void;
diff --git a/apps/designer/app/designer/features/props-panel/use-props-logic.ts b/apps/designer/app/designer/features/props-panel/use-props-logic.ts
index 39ace6c452..0c053bd7ee 100644
--- a/apps/designer/app/designer/features/props-panel/use-props-logic.ts
+++ b/apps/designer/app/designer/features/props-panel/use-props-logic.ts
@@ -1,14 +1,14 @@
import { useMemo, useState } from "react";
import { nanoid } from "nanoid";
import warnOnce from "warn-once";
-import type { Instance, PropsItem } from "@webstudio-is/project-build";
+import type { Instance, Prop } from "@webstudio-is/project-build";
import type { MetaProps } from "@webstudio-is/react-sdk";
import {
getComponentMeta,
getComponentMetaProps,
} from "@webstudio-is/react-sdk";
-export type UserPropValue = PropsItem extends infer T
+export type UserPropValue = Prop extends infer T
? T extends { value: unknown; type: unknown }
? { value: T["value"]; type: T["type"] }
: never
@@ -69,13 +69,13 @@ const getRequiredPropsList = (component: string) => {
};
type UsePropsLogic = {
- props: PropsItem[];
+ props: Prop[];
selectedInstance: Instance;
- updateProps: (update: PropsItem) => void;
- deleteProp: (id: PropsItem["id"]) => void;
+ updateProps: (update: Prop) => void;
+ deleteProp: (id: Prop["id"]) => void;
};
-const getPropsItemFromMetaProps = (
+const getPropFromMetaProps = (
instanceId: Instance["id"],
metaProps: MetaProps,
name: string
@@ -111,31 +111,31 @@ export const usePropsLogic = ({
() => getRequiredPropsList(component),
[component]
);
- const requiredPropsByName = new Map<string, PropsItem>();
+ const requiredPropsByName = new Map<string, Prop>();
for (const name of requiredPropsList) {
- const propsItem = getPropsItemFromMetaProps(instanceId, metaProps, name);
- if (propsItem) {
- requiredPropsByName.set(name, propsItem);
+ const prop = getPropFromMetaProps(instanceId, metaProps, name);
+ if (prop) {
+ requiredPropsByName.set(name, prop);
}
}
- const [addedProps, setAddedProps] = useState<PropsItem[]>([]);
- const addedPropsById = new Map<string, PropsItem>();
- for (const propsItem of addedProps) {
- addedPropsById.set(propsItem.id, propsItem);
+ const [addedProps, setAddedProps] = useState<Prop[]>([]);
+ const addedPropsById = new Map<string, Prop>();
+ for (const prop of addedProps) {
+ addedPropsById.set(prop.id, prop);
}
- const propsById = new Map<string, PropsItem>();
- for (const propsItem of props) {
- if (requiredPropsByName.has(propsItem.name)) {
- requiredPropsByName.set(propsItem.name, propsItem);
+ const propsById = new Map<string, Prop>();
+ for (const prop of props) {
+ if (requiredPropsByName.has(prop.name)) {
+ requiredPropsByName.set(prop.name, prop);
continue;
}
- if (addedPropsById.has(propsItem.id)) {
- addedPropsById.set(propsItem.id, propsItem);
+ if (addedPropsById.has(prop.id)) {
+ addedPropsById.set(prop.id, prop);
continue;
}
- propsById.set(propsItem.id, propsItem);
+ propsById.set(prop.id, prop);
}
// maintain added props order until panel is closed
@@ -146,30 +146,27 @@ export const usePropsLogic = ({
...addedPropsById.values(),
];
- const handleChangePropName = (propsItem: PropsItem, name: string) => {
+ const handleChangePropName = (prop: Prop, name: string) => {
// prevent changing name of required props
- if (isRequired(propsItem)) {
+ if (isRequired(prop)) {
return;
}
const typedValue = getValueFromPropMeta(metaProps[name]);
- updateProps({ id: propsItem.id, instanceId, name, ...typedValue });
+ updateProps({ id: prop.id, instanceId, name, ...typedValue });
};
- const handleChangePropValue = (
- propsItem: PropsItem,
- value: UserPropValue
- ) => {
- updateProps({ ...propsItem, ...value });
+ const handleChangePropValue = (prop: Prop, value: UserPropValue) => {
+ updateProps({ ...prop, ...value });
};
- const handleDeleteProp = (propsItem: PropsItem) => {
+ const handleDeleteProp = (prop: Prop) => {
// required prop should never be deleted
- if (isRequired(propsItem)) {
+ if (isRequired(prop)) {
return;
}
- const id = propsItem.id;
+ const id = prop.id;
deleteProp(id);
- setAddedProps((prev) => prev.filter((propsItem) => propsItem.id !== id));
+ setAddedProps((prev) => prev.filter((prop) => prop.id !== id));
};
const addEmptyProp = () => {
@@ -185,8 +182,8 @@ export const usePropsLogic = ({
]);
};
- const isRequired = (propsItem: PropsItem) => {
- return propsItem.required || requiredPropsList.includes(propsItem.name);
+ const isRequired = (prop: Prop) => {
+ return prop.required || requiredPropsList.includes(prop.name);
};
return {
diff --git a/apps/designer/app/shared/nano-states/nano-states.ts b/apps/designer/app/shared/nano-states/nano-states.ts
index b9f5e2a157..d24208c193 100644
--- a/apps/designer/app/shared/nano-states/nano-states.ts
+++ b/apps/designer/app/shared/nano-states/nano-states.ts
@@ -174,14 +174,14 @@ export const stylesIndexStore = computed(
[stylesStore, styleSourceSelectionsStore],
(styles, styleSourceSelections) => {
const stylesByStyleSourceId = new Map<StyleSource["id"], Styles>();
- for (const stylesItem of styles) {
- const { styleSourceId } = stylesItem;
+ for (const styleDecl of styles) {
+ const { styleSourceId } = styleDecl;
let styleSourceStyles = stylesByStyleSourceId.get(styleSourceId);
if (styleSourceStyles === undefined) {
styleSourceStyles = [];
stylesByStyleSourceId.set(styleSourceId, styleSourceStyles);
}
- styleSourceStyles.push(stylesItem);
+ styleSourceStyles.push(styleDecl);
}
const stylesByInstanceId = new Map<Instance["id"], Styles>();
diff --git a/apps/designer/app/shared/tree-utils.test.ts b/apps/designer/app/shared/tree-utils.test.ts
index 98a6ab8870..efa2331cc2 100644
--- a/apps/designer/app/shared/tree-utils.test.ts
+++ b/apps/designer/app/shared/tree-utils.test.ts
@@ -1,8 +1,8 @@
import { test, expect } from "@jest/globals";
import type {
Instance,
- PropsItem,
- StylesItem,
+ Prop,
+ StyleDecl,
StyleSource,
StyleSourceSelection,
} from "@webstudio-is/project-build";
@@ -27,7 +27,7 @@ const createInstance = (id: Instance["id"], children: Instance[]): Instance => {
};
};
-const createProp = (id: string, instanceId: string): PropsItem => {
+const createProp = (id: string, instanceId: string): Prop => {
return {
id,
instanceId,
@@ -65,7 +65,7 @@ const createStyleSourceSelection = (
};
};
-const createStyleDecl = (styleSourceId: string): StylesItem => {
+const createStyleDecl = (styleSourceId: string): StyleDecl => {
return {
styleSourceId,
breakpointId: "breakpointId",
diff --git a/packages/project-build/src/schema/props.ts b/packages/project-build/src/schema/props.ts
index 144456e79e..289649aade 100644
--- a/packages/project-build/src/schema/props.ts
+++ b/packages/project-build/src/schema/props.ts
@@ -1,58 +1,58 @@
import { z } from "zod";
import { Asset } from "@webstudio-is/asset-uploader";
-const basePropsItem = {
+const baseProp = {
id: z.string(),
instanceId: z.string(),
name: z.string(),
required: z.optional(z.boolean()),
};
-const SharedPropsItem = z.union([
+const SharedProp = z.union([
z.object({
- ...basePropsItem,
+ ...baseProp,
type: z.literal("number"),
value: z.number(),
}),
z.object({
- ...basePropsItem,
+ ...baseProp,
type: z.literal("string"),
value: z.string(),
}),
z.object({
- ...basePropsItem,
+ ...baseProp,
type: z.literal("boolean"),
value: z.boolean(),
}),
]);
-export const StoredPropsItem = z.union([
- SharedPropsItem,
+export const StoredProp = z.union([
+ SharedProp,
z.object({
- ...basePropsItem,
+ ...baseProp,
type: z.literal("asset"),
// asset.id is stored in database
value: z.string(),
}),
]);
-export type StoredPropsItem = z.infer<typeof StoredPropsItem>;
+export type StoredProp = z.infer<typeof StoredProp>;
-export const StoredProps = z.array(StoredPropsItem);
+export const StoredProps = z.array(StoredProp);
export type StoredProps = z.infer<typeof StoredProps>;
-export const PropsItem = z.union([
- SharedPropsItem,
+export const Prop = z.union([
+ SharedProp,
z.object({
- ...basePropsItem,
+ ...baseProp,
type: z.literal("asset"),
value: Asset,
}),
]);
-export type PropsItem = z.infer<typeof PropsItem>;
+export type Prop = z.infer<typeof Prop>;
-export const Props = z.array(PropsItem);
+export const Props = z.array(Prop);
export type Props = z.infer<typeof Props>;
diff --git a/packages/project-build/src/schema/styles.ts b/packages/project-build/src/schema/styles.ts
index 5c68b454fa..e75e0440b0 100644
--- a/packages/project-build/src/schema/styles.ts
+++ b/packages/project-build/src/schema/styles.ts
@@ -10,7 +10,7 @@ const StoredImageValue = z.object({
value: z.array(z.object({ type: z.literal("asset"), value: z.string() })),
});
-export const StoredStylesItem = z.object({
+export const StoredStyleDecl = z.object({
styleSourceId: z.string(),
breakpointId: z.string(),
// @todo can't figure out how to make property to be enum
@@ -18,13 +18,13 @@ export const StoredStylesItem = z.object({
value: z.union([StoredImageValue, SharedStyleValue]),
});
-export type StoredStylesItem = z.infer<typeof StoredStylesItem>;
+export type StoredStyleDecl = z.infer<typeof StoredStyleDecl>;
-export const StoredStyles = z.array(StoredStylesItem);
+export const StoredStyles = z.array(StoredStyleDecl);
export type StoredStyles = z.infer<typeof StoredStyles>;
-export const StylesItem = z.object({
+export const StyleDecl = z.object({
styleSourceId: z.string(),
breakpointId: z.string(),
// @todo can't figure out how to make property to be enum
@@ -32,8 +32,8 @@ export const StylesItem = z.object({
value: z.union([ImageValue, SharedStyleValue]),
});
-export type StylesItem = z.infer<typeof StylesItem>;
+export type StyleDecl = z.infer<typeof StyleDecl>;
-export const Styles = z.array(StylesItem);
+export const Styles = z.array(StyleDecl);
export type Styles = z.infer<typeof Styles>;