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.

refactor: drop legeacy data source prop support (#2600)

Bogdan Chadkin6dd5b0687a3e
diff --git a/apps/builder/app/builder/features/settings-panel/controls/combined.tsx b/apps/builder/app/builder/features/settings-panel/controls/combined.tsx
index 2eaceebbd5..f0b39c888a 100644
--- a/apps/builder/app/builder/features/settings-panel/controls/combined.tsx
+++ b/apps/builder/app/builder/features/settings-panel/controls/combined.tsx
@@ -15,9 +15,6 @@ export const renderControl = ({
prop,
...rest
}: ControlProps<string, string> & { key?: string }) => {
- if (prop?.type === "dataSource") {
- throw Error("Data source is not resolved");
- }
if (prop?.type === "expression") {
throw Error("Expression is not resolved");
}
diff --git a/apps/builder/app/builder/features/settings-panel/props-section/props-section.tsx b/apps/builder/app/builder/features/settings-panel/props-section/props-section.tsx
index ae84c04710..f15e899801 100644
--- a/apps/builder/app/builder/features/settings-panel/props-section/props-section.tsx
+++ b/apps/builder/app/builder/features/settings-panel/props-section/props-section.tsx
@@ -217,31 +217,9 @@ export const PropsSectionContainer = ({
updateProp: (update) => {
const props = propsStore.get();
const prop = props.get(update.id);
- // update data source instead when real prop has data source type
+ // update the variable when real prop has expression type
// update the prop when new expression is added
- if (prop?.type === "dataSource" && update.type !== "dataSource") {
- let dataSourceId = prop.value;
- const dataSources = dataSourcesStore.get();
- const dataSource = dataSources.get(dataSourceId);
- // when data source is expression containing only reference to variable
- // update that variable instead
- if (dataSource?.type === "expression") {
- // extract id without parsing expression
- const potentialVariableId = decodeDataSourceVariable(dataSource.code);
- if (
- potentialVariableId !== undefined &&
- dataSources.has(potentialVariableId)
- ) {
- dataSourceId = potentialVariableId;
- }
- }
-
- const dataSourceVariables = new Map(dataSourceVariablesStore.get());
- dataSourceVariables.set(dataSourceId, update.value);
- dataSourceVariablesStore.set(dataSourceVariables);
- // update the variable when real prop has expression type
- // update the prop when new expression is added
- } else if (prop?.type === "expression" && update.type !== "expression") {
+ if (prop?.type === "expression" && update.type !== "expression") {
const dataSources = dataSourcesStore.get();
// when expression contains only reference to variable update that variable
// extract id without parsing expression
diff --git a/apps/builder/app/builder/features/settings-panel/props-section/use-props-logic.ts b/apps/builder/app/builder/features/settings-panel/props-section/use-props-logic.ts
index 465bf80ba2..8b8705ed19 100644
--- a/apps/builder/app/builder/features/settings-panel/props-section/use-props-logic.ts
+++ b/apps/builder/app/builder/features/settings-panel/props-section/use-props-logic.ts
@@ -5,7 +5,6 @@ import type { PropValue } from "../shared";
import { useStore } from "@nanostores/react";
import {
dataSourcesLogicStore,
- dataSourcesStore,
registeredComponentPropsMetasStore,
} from "~/shared/nano-states";
@@ -92,10 +91,6 @@ const getDefaultMetaForType = (type: Prop["type"]): PropMeta => {
throw new Error(
"A prop with type json must have a meta, we can't provide a default one because we need a list of options"
);
- case "dataSource":
- throw new Error(
- "A prop with type dataSource must have a meta, we can't provide a default one because we need a list of options"
- );
case "expression":
throw new Error(
"A prop with type expression must have a meta, we can't provide a default one because we need a list of options"
@@ -158,7 +153,6 @@ export const usePropsLogic = ({
const meta = useStore(registeredComponentPropsMetasStore).get(
instance.component
);
- const dataSources = useStore(dataSourcesStore);
const dataSourcesLogic = useStore(dataSourcesLogicStore);
if (meta === undefined) {
@@ -180,26 +174,6 @@ export const usePropsLogic = ({
} satisfies Prop,
];
}
- if (prop.type === "dataSource") {
- // convert data source prop to typed prop
- const dataSourceId = prop.value;
- const dataSource = dataSources.get(dataSourceId);
- const dataSourceValue =
- dataSourcesLogic.get(prop.id) ?? dataSourcesLogic.get(dataSourceId);
- if (dataSource === undefined) {
- return [];
- }
- return [
- {
- id: prop.id,
- instanceId: prop.instanceId,
- name: prop.name,
- required: prop.required,
- // infer type from value
- ...getPropTypeAndValue(dataSourceValue),
- } satisfies Prop,
- ];
- }
return [prop];
});
diff --git a/apps/builder/app/builder/features/settings-panel/variables.tsx b/apps/builder/app/builder/features/settings-panel/variables.tsx
index 7b8beae4c2..bff7953548 100644
--- a/apps/builder/app/builder/features/settings-panel/variables.tsx
+++ b/apps/builder/app/builder/features/settings-panel/variables.tsx
@@ -249,17 +249,12 @@ const EmptyList = ({ onAdd }: { onAdd: () => void }) => {
);
};
-const $usedVariables = computed(
- [dataSourcesStore, propsStore],
- (dataSources, props) => {
- const usedVariables = new Set<DataSource["id"]>();
- // @todo remove data sources checks after migrating to prop expression
- for (const dataSource of dataSources.values()) {
- if (dataSource.type !== "expression") {
- continue;
- }
+const $usedVariables = computed([propsStore], (props) => {
+ const usedVariables = new Set<DataSource["id"]>();
+ for (const prop of props.values()) {
+ if (prop.type === "expression") {
try {
- validateExpression(dataSource.code, {
+ validateExpression(prop.value, {
transformIdentifier: (identifier) => {
const id = decodeDataSourceVariable(identifier);
if (id !== undefined) {
@@ -272,10 +267,11 @@ const $usedVariables = computed(
// empty block
}
}
- for (const prop of props.values()) {
- if (prop.type === "expression") {
+ if (prop.type === "action") {
+ for (const value of prop.value) {
try {
- validateExpression(prop.value, {
+ validateExpression(value.code, {
+ effectful: true,
transformIdentifier: (identifier) => {
const id = decodeDataSourceVariable(identifier);
if (id !== undefined) {
@@ -288,28 +284,10 @@ const $usedVariables = computed(
// empty block
}
}
- if (prop.type === "action") {
- for (const value of prop.value) {
- try {
- validateExpression(value.code, {
- effectful: true,
- transformIdentifier: (identifier) => {
- const id = decodeDataSourceVariable(identifier);
- if (id !== undefined) {
- usedVariables.add(id);
- }
- return identifier;
- },
- });
- } catch {
- // empty block
- }
- }
- }
}
- return usedVariables;
}
-);
+ return usedVariables;
+});
const deleteVariable = (variable: VariableDataSource) => {
serverSyncStore.createTransaction([dataSourcesStore], (dataSources) => {
@@ -369,35 +347,6 @@ const ListItem = ({
);
};
-const getPropExpressionStore = (propId: undefined | string) => {
- const $propExpression = computed(
- [propsStore, dataSourcesStore],
- (props, dataSources) => {
- if (propId === undefined) {
- return "";
- }
- const prop = props.get(propId);
- if (prop?.type === "expression") {
- return prop.value;
- }
- if (prop?.type !== "dataSource") {
- return "";
- }
- const dataSourceId = prop.value;
- const dataSource = dataSources.get(dataSourceId);
- // convert variable to expression
- if (dataSource?.type === "variable") {
- return encodeDataSourceVariable(dataSource.id);
- }
- if (dataSource?.type === "expression") {
- return dataSource.code;
- }
- return "";
- }
- );
- return $propExpression;
-};
-
const getExpressionVariables = (expression: string) => {
const variableIds = new Set<VariableDataSource["id"]>();
if (expression === "") {
@@ -461,11 +410,7 @@ const ListPanel = ({
}
return variables;
}, [matchedVariables]);
- const propId = prop?.id;
- // @todo const propExpression = prop.value ?? ''
- const propExpression = useStore(
- useMemo(() => getPropExpressionStore(propId), [propId])
- );
+ const propExpression = prop?.type === "expression" ? prop?.value ?? "" : "";
const exoressionVariables = useMemo(
() => getExpressionVariables(propExpression),
[propExpression]
@@ -473,20 +418,6 @@ const ListPanel = ({
const usedVariables = useStore($usedVariables);
const [expression, setExpression] = useState<undefined | string>();
- const applyExpression = (expression: string) => {
- // @todo remove after migrating to prop extession
- serverSyncStore.createTransaction([dataSourcesStore], (dataSources) => {
- // replace data source expression with prop expression
- const dataSource =
- prop?.type === "dataSource" ? dataSources.get(prop.value) : undefined;
- if (dataSource?.type === "expression") {
- dataSources.delete(dataSource.id);
- return;
- }
- });
- onChange({ type: "expression", value: expression });
- };
-
return (
<ScrollArea
css={{
@@ -511,7 +442,10 @@ const ListPanel = ({
deletable={usedVariables.has(variable.id) === false}
onSelect={() =>
// convert variable to expression
- applyExpression(encodeDataSourceVariable(variable.id))
+ onChange({
+ type: "expression",
+ value: encodeDataSourceVariable(variable.id),
+ })
}
onEdit={onEdit}
/>
@@ -552,7 +486,7 @@ const ListPanel = ({
return;
}
- applyExpression(expression);
+ onChange({ type: "expression", value: expression });
setExpression(undefined);
}}
/>
@@ -615,15 +549,6 @@ export const VariablesPanel = ({
}
const removeExpression = () => {
- // delete expression if exists
- if (prop?.type === "dataSource") {
- serverSyncStore.createTransaction([dataSourcesStore], (dataSources) => {
- const dataSource = dataSources.get(prop.value);
- if (dataSource?.type === "expression") {
- dataSources.delete(dataSource.id);
- }
- });
- }
// reset prop with initial value from meta
setPropValue({
propId,
@@ -653,7 +578,7 @@ export const VariablesPanel = ({
<FloatingPanelPopoverTitle
actions={
<>
- {(prop?.type === "dataSource" || prop?.type === "expression") && (
+ {prop?.type === "expression" && (
<Tooltip content="Remove expression" side="bottom">
{/* automatically close popover when remove expression */}
<FloatingPanelPopoverClose asChild>
diff --git a/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsx b/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsx
index 448285f2ce..bc3d717e5d 100644
--- a/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsx
+++ b/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsx
@@ -163,18 +163,6 @@ const useInstanceProps = (instanceId: Instance["id"]) => {
if (prop.type === "asset" || prop.type === "page") {
continue;
}
- if (prop.type === "dataSource") {
- const dataSourceId = prop.value;
- const value =
- // access expression by prop id
- dataSourcesLogic.get(prop.id) ??
- // access variable by data source id
- dataSourcesLogic.get(dataSourceId);
- if (value !== undefined) {
- instancePropsObject[prop.name] = value;
- }
- continue;
- }
if (prop.type === "expression") {
const value = dataSourcesLogic.get(prop.id);
if (value !== undefined) {
diff --git a/apps/builder/app/shared/copy-paste/plugin-instance.test.ts b/apps/builder/app/shared/copy-paste/plugin-instance.test.ts
index 58e5e065a6..74a21edec9 100644
--- a/apps/builder/app/shared/copy-paste/plugin-instance.test.ts
+++ b/apps/builder/app/shared/copy-paste/plugin-instance.test.ts
@@ -144,35 +144,28 @@ describe("data sources", () => {
name: "state",
value: { type: "string", value: "initial" },
},
- {
- id: "box2$stateInitial",
- scopeInstanceId: "box2",
- type: "expression",
- name: "stateInitial",
- code: `$ws$dataSource$box1$state === 'initial'`,
- },
] satisfies DataSource[]);
const props: Props = toMap([
{
id: "box1$stateProp",
instanceId: "box1",
- type: "dataSource",
name: "state",
- value: "box1$state",
+ type: "expression",
+ value: "$ws$dataSource$box1$state",
},
{
id: "box2$stateProp",
instanceId: "box2",
- type: "dataSource",
name: "state",
- value: "box1$state",
+ type: "expression",
+ value: "$ws$dataSource$box1$state",
},
{
id: "box2$showProp",
instanceId: "box2",
- type: "dataSource",
name: "show",
- value: "box2$stateInitial",
+ type: "expression",
+ value: `$ws$dataSource$box1$state === 'initial'`,
},
{
id: "box2$onChangeProp",
@@ -191,129 +184,7 @@ describe("data sources", () => {
test("are copy pasted when scoped to copied instances", () => {
instancesStore.set(instances);
- propsStore.set(props);
dataSourcesStore.set(dataSources);
- selectedInstanceSelectorStore.set(["box1", "body0"]);
- const clipboardData = onCopy() ?? "";
- selectedInstanceSelectorStore.set(["body0"]);
- onPaste(clipboardData);
-
- const instancesDifference = getMapDifference(
- instances,
- instancesStore.get()
- );
- const [newBox1, newBox2] = instancesDifference.keys();
-
- const dataSourcesDifference = getMapDifference(
- dataSources,
- dataSourcesStore.get()
- );
- const [newDataSource1, newDataSource2] = dataSourcesDifference.keys();
- expect(dataSourcesDifference).toEqual(
- toMap([
- {
- ...dataSources.get("box1$state"),
- id: newDataSource1,
- scopeInstanceId: newBox1,
- },
- {
- ...dataSources.get("box2$stateInitial"),
- id: newDataSource2,
- scopeInstanceId: newBox2,
- code: `${encodeDataSourceVariable(newDataSource1)} === 'initial'`,
- },
- ])
- );
-
- const propsDifference = getMapDifference(props, propsStore.get());
- const [newProp1, newProp2, newProp3, newProp4] = propsDifference.keys();
- expect(propsDifference).toEqual(
- toMap([
- {
- ...props.get("box1$stateProp"),
- id: newProp1,
- instanceId: newBox1,
- value: newDataSource1,
- },
- {
- id: newProp2,
- instanceId: newBox2,
- name: "state",
- type: "dataSource",
- value: newDataSource1,
- },
- {
- id: newProp3,
- instanceId: newBox2,
- name: "show",
- type: "dataSource",
- value: newDataSource2,
- },
- {
- id: newProp4,
- instanceId: newBox2,
- name: "onChange",
- type: "action",
- value: [
- {
- type: "execute",
- args: ["value"],
- code: `${encodeDataSourceVariable(newDataSource1)} = value`,
- },
- ],
- },
- ])
- );
- });
-
- test("are copy pasted when scoped to copied instances 2", () => {
- instancesStore.set(instances);
- const dataSources = toMap<DataSource>([
- {
- id: "box1$state",
- scopeInstanceId: "box1",
- type: "variable",
- name: "state",
- value: { type: "string", value: "initial" },
- },
- ]);
- dataSourcesStore.set(dataSources);
- const props = toMap<Prop>([
- {
- id: "box1$stateProp",
- instanceId: "box1",
- name: "state",
- type: "expression",
- value: "$ws$dataSource$box1$state",
- },
- {
- id: "box2$stateProp",
- instanceId: "box2",
- name: "state",
- type: "expression",
- value: "$ws$dataSource$box1$state",
- },
- {
- id: "box2$showProp",
- instanceId: "box2",
- name: "show",
- type: "expression",
- value: `$ws$dataSource$box1$state === 'initial'`,
- },
- {
- id: "box2$onChangeProp",
- instanceId: "box2",
- type: "action",
- name: "onChange",
- value: [
- {
- type: "execute",
- args: ["value"],
- code: `$ws$dataSource$box1$state = value`,
- },
- ],
- },
- ]);
propsStore.set(props);
selectedInstanceSelectorStore.set(["box1", "body0"]);
const clipboardData = onCopy() ?? "";
@@ -402,18 +273,7 @@ describe("data sources", () => {
dataSources,
dataSourcesStore.get()
);
- const [dataSourceId] = dataSourcesDifference.keys();
- expect(dataSourcesDifference).toEqual(
- toMap([
- {
- id: dataSourceId,
- scopeInstanceId: newBox2,
- name: "stateInitial",
- type: "expression",
- code: `"initial" === 'initial'`,
- },
- ])
- );
+ expect(dataSourcesDifference).toEqual(new Map());
const propsDifference = getMapDifference(props, propsStore.get());
const [newProp1, newProp2, newProp3] = propsDifference.keys();
@@ -422,16 +282,16 @@ describe("data sources", () => {
{
id: newProp1,
instanceId: newBox2,
- type: "string",
name: "state",
- value: "initial",
+ type: "expression",
+ value: `"initial"`,
},
{
id: newProp2,
instanceId: newBox2,
name: "show",
- type: "dataSource",
- value: dataSourceId,
+ type: "expression",
+ value: `"initial" === 'initial'`,
},
{
id: newProp3,
@@ -463,18 +323,7 @@ describe("data sources", () => {
dataSources,
dataSourcesStore.get()
);
- const [dataSourceId] = dataSourcesDifference.keys();
- expect(dataSourcesDifference).toEqual(
- toMap([
- {
- id: dataSourceId,
- scopeInstanceId: newBox2,
- name: "stateInitial",
- type: "expression",
- code: "$ws$dataSource$box1$state === 'initial'",
- },
- ])
- );
+ expect(dataSourcesDifference).toEqual(new Map());
const propsDifference = getMapDifference(props, propsStore.get());
const [newProp1, newProp2, newProp3] = propsDifference.keys();
@@ -484,15 +333,15 @@ describe("data sources", () => {
id: newProp1,
instanceId: newBox2,
name: "state",
- type: "dataSource",
- value: "box1$state",
+ type: "expression",
+ value: `$ws$dataSource$box1$state`,
},
{
id: newProp2,
instanceId: newBox2,
name: "show",
- type: "dataSource",
- value: dataSourceId,
+ type: "expression",
+ value: `$ws$dataSource$box1$state === 'initial'`,
},
{
id: newProp3,
diff --git a/apps/builder/app/shared/copy-paste/plugin-instance.ts b/apps/builder/app/shared/copy-paste/plugin-instance.ts
index 5a6300b11c..0c4a8e43d9 100644
--- a/apps/builder/app/shared/copy-paste/plugin-instance.ts
+++ b/apps/builder/app/shared/copy-paste/plugin-instance.ts
@@ -290,44 +290,6 @@ export const onPaste = (clipboardData: string): boolean => {
return identifier;
};
- if (prop.type === "dataSource") {
- const dataSource = copiedDataSources.get(prop.value);
- // convert to value prop when variable is not scoped to copied tree or paste target
- if (dataSource?.type === "variable") {
- // data source is within copied tree
- if (copiedDataSourceIds.has(dataSource.id)) {
- return prop;
- }
- // data source is within paste target
- if (
- dataSource.scopeInstanceId !== undefined &&
- instanceSelector.includes(dataSource.scopeInstanceId)
- ) {
- return prop;
- }
- return {
- ...prop,
- ...dataSource.value,
- };
- }
- if (dataSource?.type === "expression") {
- const newDataSourceId =
- copiedDataSourceIds.get(dataSource.id) ?? dataSource.id;
- const newInstanceId =
- copiedInstanceIds.get(dataSource.scopeInstanceId) ??
- dataSource.scopeInstanceId;
- dataSources.set(newDataSourceId, {
- ...dataSource,
- id: newDataSourceId,
- scopeInstanceId: newInstanceId,
- code: validateExpression(dataSource.code, {
- transformIdentifier,
- }),
- });
- return prop;
- }
- }
-
if (prop.type === "expression") {
return {
...prop,
@@ -359,8 +321,7 @@ export const onPaste = (clipboardData: string): boolean => {
return prop;
}),
- copiedInstanceIds,
- copiedDataSourceIds
+ copiedInstanceIds
);
insertStyleSourceSelectionsCopyMutable(
diff --git a/apps/builder/app/shared/instance-utils.test.ts b/apps/builder/app/shared/instance-utils.test.ts
index d4a8d7ba70..fb2ef91605 100644
--- a/apps/builder/app/shared/instance-utils.test.ts
+++ b/apps/builder/app/shared/instance-utils.test.ts
@@ -755,124 +755,6 @@ describe("get instances slice", () => {
});
test("collect data sources used in expressions within instances", () => {
- // body
- // box1
- // box2
- instancesStore.set(
- toMap([
- createInstance("body", "Body", [{ type: "id", value: "box1" }]),
- createInstance("box1", "Box", [{ type: "id", value: "box2" }]),
- createInstance("box2", "Box", []),
- ])
- );
- dataSourcesStore.set(
- toMap([
- {
- id: "box1$state",
- scopeInstanceId: "box1",
- type: "variable",
- name: "state",
- value: { type: "string", value: "initial" },
- },
- {
- id: "box2$stateInitial",
- scopeInstanceId: "box2",
- type: "expression",
- name: "stateInitial",
- code: `$ws$dataSource$box1$state === 'initial'`,
- },
- {
- id: "box2$true",
- scopeInstanceId: "box2",
- type: "expression",
- name: "trueValue",
- code: `true`,
- },
- ])
- );
- propsStore.set(
- toMap([
- {
- id: "box1$stateProp",
- instanceId: "box1",
- type: "dataSource",
- name: "state",
- value: "box1$state",
- },
- {
- id: "box2$stateProp",
- instanceId: "box2",
- type: "dataSource",
- name: "state",
- value: "box1$state",
- },
- {
- id: "box2$showProp",
- instanceId: "box2",
- type: "dataSource",
- name: "show",
- value: "box2$stateInitial",
- },
- {
- id: "box2$trueProp",
- instanceId: "box2",
- type: "dataSource",
- name: "bool-prop",
- value: "box2$true",
- },
- ])
- );
- const { props, dataSources } = getInstancesSlice("box2");
-
- expect(dataSources).toEqual([
- {
- id: "box1$state",
- scopeInstanceId: "box1",
- type: "variable",
- name: "state",
- value: { type: "string", value: "initial" },
- },
- {
- id: "box2$stateInitial",
- scopeInstanceId: "box2",
- type: "expression",
- name: "stateInitial",
- code: `$ws$dataSource$box1$state === 'initial'`,
- },
- {
- id: "box2$true",
- scopeInstanceId: "box2",
- type: "expression",
- name: "trueValue",
- code: `true`,
- },
- ]);
- expect(props).toEqual([
- {
- id: "box2$stateProp",
- instanceId: "box2",
- name: "state",
- type: "dataSource",
- value: "box1$state",
- },
- {
- id: "box2$showProp",
- instanceId: "box2",
- name: "show",
- type: "dataSource",
- value: "box2$stateInitial",
- },
- {
- id: "box2$trueProp",
- instanceId: "box2",
- name: "bool-prop",
- type: "dataSource",
- value: "box2$true",
- },
- ]);
- });
-
- test("collect data sources used in expressions within instances 2", () => {
// body
// box1
// box2
diff --git a/apps/builder/app/shared/instance-utils.ts b/apps/builder/app/shared/instance-utils.ts
index 42177fb6d1..724487d6ce 100644
--- a/apps/builder/app/shared/instance-utils.ts
+++ b/apps/builder/app/shared/instance-utils.ts
@@ -325,7 +325,7 @@ export const insertTemplateData = (
children,
dropTarget
);
- insertPropsCopyMutable(props, insertedProps, new Map(), new Map());
+ insertPropsCopyMutable(props, insertedProps, new Map());
for (const dataSource of insertedDataSources) {
dataSources.set(dataSource.id, dataSource);
}
@@ -616,25 +616,6 @@ export const getInstancesSlice = (rootInstanceId: string) => {
slicedProps.set(prop.id, prop);
- if (prop.type === "dataSource") {
- const dataSource = dataSources.get(prop.value);
- if (dataSource?.type === "variable") {
- usedDataSourceIds.add(dataSource.id);
- }
- if (dataSource?.type === "expression") {
- usedDataSourceIds.add(dataSource.id);
- validateExpression(dataSource.code, {
- transformIdentifier(identifier) {
- const id = decodeDataSourceVariable(identifier);
- if (id !== undefined) {
- usedDataSourceIds.add(id);
- }
- return identifier;
- },
- });
- }
- }
-
if (prop.type === "expression") {
validateExpression(prop.value, {
transformIdentifier(identifier) {
diff --git a/apps/builder/app/shared/nano-states/components.ts b/apps/builder/app/shared/nano-states/components.ts
index 18f7a8617a..16b6f8bc12 100644
--- a/apps/builder/app/shared/nano-states/components.ts
+++ b/apps/builder/app/shared/nano-states/components.ts
@@ -55,14 +55,6 @@ const createHookContext = (): HookContext => {
const dataSources = new Map(dataSourcesStore.get());
const props = propsStore.get();
for (const prop of props.values()) {
- if (
- prop.instanceId === instanceId &&
- prop.name === propName &&
- prop.type === "dataSource"
- ) {
- const dataSourceId = prop.value;
- dataSourceVariables.set(dataSourceId, value);
- }
if (
prop.instanceId === instanceId &&
prop.name === propName &&
diff --git a/apps/builder/app/shared/tree-utils.test.ts b/apps/builder/app/shared/tree-utils.test.ts
index 96c28be752..d38437a421 100644
--- a/apps/builder/app/shared/tree-utils.test.ts
+++ b/apps/builder/app/shared/tree-utils.test.ts
@@ -867,7 +867,7 @@ test("insert props copy with new ids and apply new instance ids", () => {
const clonedInstanceIds = new Map<Instance["id"], Instance["id"]>([
["instance2", "newInstance2"],
]);
- insertPropsCopyMutable(props, copiedProps, clonedInstanceIds, new Map());
+ insertPropsCopyMutable(props, copiedProps, clonedInstanceIds);
expect(Array.from(props.entries())).toEqual([
["prop1", createProp("prop1", "instance1")],
["prop2", createProp("prop2", "instance2")],
diff --git a/apps/builder/app/shared/tree-utils.ts b/apps/builder/app/shared/tree-utils.ts
index 40802e27de..e11c2a86b7 100644
--- a/apps/builder/app/shared/tree-utils.ts
+++ b/apps/builder/app/shared/tree-utils.ts
@@ -2,7 +2,6 @@ import { nanoid } from "nanoid";
import {
Breakpoint,
Breakpoints,
- DataSource,
getStyleDeclKey,
Instance,
Instances,
@@ -491,8 +490,7 @@ export const insertStyleSourcesCopyMutable = (
export const insertPropsCopyMutable = (
props: Props,
copiedProps: Prop[],
- copiedInstanceIds: Map<Instance["id"], Instance["id"]>,
- copiedDataSourceIds: Map<DataSource["id"], DataSource["id"]>
+ copiedInstanceIds: Map<Instance["id"], Instance["id"]>
) => {
for (const prop of copiedProps) {
const newInstanceId = copiedInstanceIds.get(prop.instanceId);
@@ -507,20 +505,11 @@ export const insertPropsCopyMutable = (
// copy prop before inserting
const newPropId = nanoid();
- if (prop.type === "dataSource") {
- props.set(newPropId, {
- ...prop,
- id: newPropId,
- instanceId: newInstanceId,
- value: copiedDataSourceIds.get(prop.value) ?? prop.value,
- });
- } else {
- props.set(newPropId, {
- ...prop,
- id: newPropId,
- instanceId: newInstanceId,
- });
- }
+ props.set(newPropId, {
+ ...prop,
+ id: newPropId,
+ instanceId: newInstanceId,
+ });
}
};
diff --git a/packages/react-sdk/src/component-generator.test.ts b/packages/react-sdk/src/component-generator.test.ts
index 1db9e93110..566cefe291 100644
--- a/packages/react-sdk/src/component-generator.test.ts
+++ b/packages/react-sdk/src/component-generator.test.ts
@@ -236,16 +236,16 @@ test("generate jsx element with data sources and action", () => {
createPropPair({
id: "1",
instanceId: "box",
- type: "dataSource",
+ type: "expression",
name: "variable",
- value: "variableId",
+ value: "$ws$dataSource$variableId",
}),
createPropPair({
id: "2",
instanceId: "box",
- type: "dataSource",
+ type: "expression",
name: "expression",
- value: "expressionId",
+ value: `$ws$dataSource$variableId + 1`,
}),
createPropPair({
id: "3",
@@ -272,12 +272,6 @@ test("generate jsx element with data sources and action", () => {
name: "variableName",
value: { type: "number", value: 0 },
}),
- createDataSourcePair({
- type: "expression",
- id: "expressionId",
- name: "expressionName",
- code: `$ws$dataSource$variableId + 1`,
- }),
]),
indexesWithinAncestors: new Map(),
children: "",
@@ -287,7 +281,7 @@ test("generate jsx element with data sources and action", () => {
<Box
data-ws-id="box"
data-ws-component="Box"
- variable={variableName}
+ variable={variable}
expression={expression}
onClick={onClick}
onChange={onChange} />
@@ -338,39 +332,6 @@ test("generate jsx element with condition based on show prop", () => {
children: "",
})
).toEqual("");
- expect(
- generateJsxElement({
- scope: createScope(),
- instance: createInstance("box", "Box", []),
- props: new Map([
- createPropPair({
- id: "1",
- instanceId: "box",
- type: "dataSource",
- name: showAttribute,
- value: "conditionId",
- }),
- ]),
- dataSources: new Map([
- createDataSourcePair({
- type: "variable",
- id: "conditionId",
- name: "conditionName",
- value: { type: "boolean", value: false },
- }),
- ]),
- indexesWithinAncestors: new Map(),
- children: "",
- })
- ).toEqual(
- clear(`
- {conditionName &&
- <Box
- data-ws-id="box"
- data-ws-component="Box" />
- }
- `)
- );
expect(
generateJsxElement({
scope: createScope(),
@@ -523,71 +484,6 @@ test("deduplicate base and namespaced components with same short name", () => {
);
});
-test("generate page component with data sources", () => {
- expect(
- generatePageComponent({
- scope: createScope(),
- rootInstanceId: "body",
- instances: new Map([
- createInstancePair("body", "Body", [{ type: "id", value: "input" }]),
- createInstancePair("input", "Input", []),
- ]),
- dataSources: new Map([
- createDataSourcePair({
- type: "variable",
- id: "variableId",
- name: "variableName",
- value: { type: "string", value: "initial" },
- }),
- ]),
- props: new Map([
- createPropPair({
- id: "1",
- instanceId: "input",
- name: "value",
- type: "dataSource",
- value: "variableId",
- }),
- createPropPair({
- id: "2",
- instanceId: "input",
- name: "onChange",
- type: "action",
- value: [
- {
- type: "execute",
- args: ["value"],
- code: `$ws$dataSource$variableId = value`,
- },
- ],
- }),
- ]),
- indexesWithinAncestors: new Map([["input", 0]]),
- })
- ).toEqual(
- clear(`
- const Page = (props: { scripts?: ReactNode }) => {
- let [variableName, set$variableName] = useState<any>("initial")
- let onChange = (value: any) => {
- variableName = value
- set$variableName(variableName)
- }
- return <Body
- data-ws-id="body"
- data-ws-component="Body">
- <Input
- data-ws-id="input"
- data-ws-component="Input"
- data-ws-index="0"
- value={variableName}
- onChange={onChange} />
- {props.scripts}
- </Body>
- }
- `)
- );
-});
-
test("generate page component with variables and actions", () => {
expect(
generatePageComponent({
diff --git a/packages/react-sdk/src/component-generator.ts b/packages/react-sdk/src/component-generator.ts
index aee698aee6..7d3286d444 100644
--- a/packages/react-sdk/src/component-generator.ts
+++ b/packages/react-sdk/src/component-generator.ts
@@ -54,19 +54,6 @@ export const generateJsxElement = ({
if (prop.type === "boolean" && prop.value === false) {
return "";
}
- if (prop.type === "dataSource") {
- const dataSourceId = prop.value;
- const dataSource = dataSources.get(dataSourceId);
- if (dataSource === undefined) {
- continue;
- }
- if (dataSource.type === "variable") {
- conditionVariableName = scope.getName(dataSource.id, dataSource.name);
- }
- if (dataSource.type === "expression") {
- conditionVariableName = scope.getName(prop.id, prop.name);
- }
- }
if (prop.type === "expression") {
conditionVariableName = scope.getName(prop.id, prop.name);
}
@@ -87,25 +74,6 @@ export const generateJsxElement = ({
if (prop.type === "asset" || prop.type === "page") {
continue;
}
- if (prop.type === "dataSource") {
- const dataSourceId = prop.value;
- const dataSource = dataSources.get(dataSourceId);
- if (dataSource === undefined) {
- continue;
- }
- if (dataSource.type === "variable") {
- const dataSourceVariable = scope.getName(
- dataSource.id,
- dataSource.name
- );
- generatedProps += `\n${prop.name}={${dataSourceVariable}}`;
- }
- if (dataSource.type === "expression") {
- const dataSourceVariable = scope.getName(prop.id, prop.name);
- generatedProps += `\n${prop.name}={${dataSourceVariable}}`;
- }
- continue;
- }
if (prop.type === "expression") {
const propVariable = scope.getName(prop.id, prop.name);
generatedProps += `\n${prop.name}={${propVariable}}`;
diff --git a/packages/react-sdk/src/expression.test.ts b/packages/react-sdk/src/expression.test.ts
index ee84855350..6300702095 100644
--- a/packages/react-sdk/src/expression.test.ts
+++ b/packages/react-sdk/src/expression.test.ts
@@ -268,90 +268,6 @@ test("generate variables with actions", () => {
);
});
-test("generate variables with data source expressions", () => {
- const generated = generateDataSources({
- scope: createScope(),
- dataSources: new Map([
- [
- "dataSource1",
- {
- id: "dataSource1",
- scopeInstanceId: "instance1",
- type: "variable",
- name: "myVar",
- value: { type: "string", value: "initial" },
- },
- ],
- [
- "dataSource2",
- {
- id: "dataSource2",
- scopeInstanceId: "instance1",
- type: "expression",
- name: "myExp",
- code: `$ws$dataSource$dataSource1 + "Name"`,
- },
- ],
- [
- "dataSource3",
- {
- id: "dataSource3",
- scopeInstanceId: "instance1",
- type: "expression",
- name: "myExp",
- code: `$ws$dataSource$dataSource1 + "Value"`,
- },
- ],
- ]),
- props: new Map([
- [
- "prop1",
- {
- id: "prop1",
- instanceId: "instance1",
- type: "dataSource",
- name: "exp",
- value: "dataSource2",
- },
- ],
- [
- "prop2",
- {
- id: "prop2",
- instanceId: "instance2",
- type: "dataSource",
- name: "exp",
- value: "dataSource3",
- },
- ],
- ]),
- });
- expect(generated.body).toMatchInlineSnapshot(`
-"let exp = (myVar + "Name");
-let exp_1 = (myVar + "Value");
-"
-`);
- expect(generated.variables).toEqual(
- new Map([
- [
- "dataSource1",
- {
- initialValue: "initial",
- setterName: "set$myVar",
- valueName: "myVar",
- },
- ],
- ])
- );
- expect(generated.output).toEqual(
- new Map([
- ["dataSource1", "myVar"],
- ["prop1", "exp"],
- ["prop2", "exp_1"],
- ])
- );
-});
-
test("generate variables witha prop expressions", () => {
const generated = generateDataSources({
scope: createScope(),
diff --git a/packages/react-sdk/src/expression.ts b/packages/react-sdk/src/expression.ts
index 7a4e54dc11..91d82d7104 100644
--- a/packages/react-sdk/src/expression.ts
+++ b/packages/react-sdk/src/expression.ts
@@ -250,29 +250,6 @@ export const generateDataSources = ({
for (const prop of props.values()) {
// generate prop expressions
- if (prop.type === "dataSource") {
- const dataSource = dataSources.get(prop.value);
- if (dataSource?.type !== "expression") {
- continue;
- }
- const name = scope.getName(prop.id, prop.name);
- output.set(prop.id, name);
- const code = validateExpression(dataSource.code, {
- optional: true,
- transformIdentifier: (identifier) => {
- const depId = decodeDataSourceVariable(identifier);
- const dep = depId ? dataSources.get(depId) : undefined;
- if (dep) {
- return scope.getName(dep.id, dep.name);
- }
- // eslint-disable-next-line no-console
- console.error(`Unknown dependency "${identifier}"`);
- return identifier;
- },
- });
- body += `let ${name} = (${code});\n`;
- }
-
if (prop.type === "expression") {
const name = scope.getName(prop.id, prop.name);
output.set(prop.id, name);
diff --git a/packages/sdk/src/schema/data-sources.ts b/packages/sdk/src/schema/data-sources.ts
index 09d4d654ac..819be05de2 100644
--- a/packages/sdk/src/schema/data-sources.ts
+++ b/packages/sdk/src/schema/data-sources.ts
@@ -34,13 +34,7 @@ export const DataSource = z.union([
name: z.string(),
value: DataSourceVariableValue,
}),
- z.object({
- type: z.literal("expression"),
- id: DataSourceId,
- scopeInstanceId: z.optional(z.string()),
- name: z.string(),
- code: z.string(),
- }),
+ z.never(),
]);
export type DataSource = z.infer<typeof DataSource>;
diff --git a/packages/sdk/src/schema/props.ts b/packages/sdk/src/schema/props.ts
index d98f86b375..76bc414b6c 100644
--- a/packages/sdk/src/schema/props.ts
+++ b/packages/sdk/src/schema/props.ts
@@ -51,12 +51,6 @@ export const Prop = z.union([
type: z.literal("string[]"),
value: z.array(z.string()),
}),
- z.object({
- ...baseProp,
- type: z.literal("dataSource"),
- // data source id
- value: z.string(),
- }),
z.object({
...baseProp,
type: z.literal("expression"),