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.

Drag on canvas closest detachable (#2197)

Bogdan Chadkincc0336e50d1d
diff --git a/apps/builder/app/canvas/shared/use-drag-drop.ts b/apps/builder/app/canvas/shared/use-drag-drop.ts
index 90a08a6030..94fa19e467 100644
--- a/apps/builder/app/canvas/shared/use-drag-drop.ts
+++ b/apps/builder/app/canvas/shared/use-drag-drop.ts
@@ -8,7 +8,6 @@ import {
useDrag,
useDrop,
computeIndicatorPlacement,
- toast,
} from "@webstudio-is/design-system";
import {
instancesStore,
@@ -18,12 +17,11 @@ import { publish, useSubscribe } from "~/shared/pubsub";
import {
computeInstancesConstraints,
findClosestDroppableComponentIndex,
- findClosestEditableInstanceSelector,
+ findClosestDetachableInstanceSelector,
getComponentTemplateData,
insertTemplateData,
reparentInstance,
type InsertConstraints,
- isInstanceDetachable,
} from "~/shared/instance-utils";
import {
getElementByInstanceSelector,
@@ -229,21 +227,15 @@ export const useDragAndDrop = () => {
}
// When trying to drag an instance inside editor, drag the editor instead
return (
- findClosestEditableInstanceSelector(
+ findClosestDetachableInstanceSelector(
instanceSelector,
instancesStore.get(),
registeredComponentMetasStore.get()
- ) ?? instanceSelector
+ ) ?? false
);
},
onStart({ data: dragInstanceSelector }) {
- if (isInstanceDetachable(dragInstanceSelector) === false) {
- toast.error(
- "This instance can not be moved outside of its parent component."
- );
- return;
- }
publish({
type: "dragStart",
payload: {
diff --git a/apps/builder/app/shared/instance-utils.ts b/apps/builder/app/shared/instance-utils.ts
index d8aa84eff3..0a95d1a46a 100644
--- a/apps/builder/app/shared/instance-utils.ts
+++ b/apps/builder/app/shared/instance-utils.ts
@@ -93,6 +93,28 @@ export const findClosestEditableInstanceSelector = (
}
};
+export const findClosestDetachableInstanceSelector = (
+ instanceSelector: InstanceSelector,
+ instances: Instances,
+ metas: Map<string, WsComponentMeta>
+) => {
+ for (const instanceId of instanceSelector) {
+ const instance = instances.get(instanceId);
+ if (instance === undefined) {
+ return;
+ }
+ const meta = metas.get(instance.component);
+ if (meta === undefined) {
+ return;
+ }
+ const detachable = meta.detachable ?? true;
+ if (meta.type !== "container" || detachable === false) {
+ continue;
+ }
+ return getAncestorInstanceSelector(instanceSelector, instanceId);
+ }
+};
+
export const isInstanceDetachable = (instanceSelector: InstanceSelector) => {
const instances = instancesStore.get();
const metas = registeredComponentMetasStore.get();
diff --git a/packages/sdk-components-react-radix/src/__generated__/select.props.ts b/packages/sdk-components-react-radix/src/__generated__/select.props.ts
index 594efdd52c..518b5ee5d7 100644
--- a/packages/sdk-components-react-radix/src/__generated__/select.props.ts
+++ b/packages/sdk-components-react-radix/src/__generated__/select.props.ts
@@ -919,6 +919,7 @@ export const propsSelectValue: Record<string, PropMeta> = {
itemType: { required: false, control: "text", type: "string" },
lang: { required: false, control: "text", type: "string" },
nonce: { required: false, control: "text", type: "string" },
+ placeholder: { required: false, control: "text", type: "string" },
prefix: { required: false, control: "text", type: "string" },
property: { required: false, control: "text", type: "string" },
radioGroup: { required: false, control: "text", type: "string" },
diff --git a/packages/sdk-components-react-radix/src/select.tsx b/packages/sdk-components-react-radix/src/select.tsx
index 60780c3131..b7e901f0bf 100644
--- a/packages/sdk-components-react-radix/src/select.tsx
+++ b/packages/sdk-components-react-radix/src/select.tsx
@@ -37,9 +37,14 @@ export const SelectTrigger: ForwardRefExoticComponent<
ComponentPropsWithRef<typeof Trigger>
> = Trigger;
-export const SelectValue: ForwardRefExoticComponent<
- ComponentPropsWithRef<typeof Value>
-> = Value;
+export const SelectValue = forwardRef<
+ HTMLDivElement,
+ Omit<ComponentPropsWithoutRef<typeof Value>, "placeholder"> & {
+ placeholder?: string;
+ }
+>((props, ref) => {
+ return <Value ref={ref} {...props} />;
+});
export const SelectContent = forwardRef<
HTMLDivElement,