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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Implement slots (#1294)
Bogdan Chadkin12814190d7ac
diff --git a/apps/builder/app/builder/shared/navigator-tree.tsx b/apps/builder/app/builder/shared/navigator-tree.tsxindex cc4a860c4e..99e7365f79 100644--- a/apps/builder/app/builder/shared/navigator-tree.tsx+++ b/apps/builder/app/builder/shared/navigator-tree.tsx@@ -3,18 +3,20 @@ import { useStore } from "@nanostores/react";import type { Instance } from "@webstudio-is/project-build";import {hoveredInstanceSelectorStore,+ instancesStore,rootInstanceStore,selectedInstanceSelectorStore,useDragAndDropState,} from "~/shared/nano-states";+import { textEditingInstanceSelectorStore } from "~/shared/nano-states/instances";import type { InstanceSelector } from "~/shared/tree-utils";import { reparentInstance } from "~/shared/instance-utils";-import { textEditingInstanceSelectorStore } from "~/shared/nano-states/instances";import { InstanceTree } from "./tree";export const NavigatorTree = () => {const selectedInstanceSelector = useStore(selectedInstanceSelectorStore);const rootInstance = useStore(rootInstanceStore);+ const instances = useStore(instancesStore);const [state, setState] = useDragAndDropState();const dragItemSelector =@@ -22,7 +24,13 @@ export const NavigatorTree = () => {? state.dragPayload.dragInstanceSelector: undefined;- const isItemHidden = useCallback((_instanceId: Instance["id"]) => false, []);+ const isItemHidden = useCallback(+ (instanceId: Instance["id"]) =>+ // fragment is internal component to group other instances+ // for example to support multiple children in slots+ instances.get(instanceId)?.component === "Fragment",+ [instances]+ );const handleDragEnd = useCallback((payload: {diff --git a/apps/builder/app/shared/copy-paste/plugin-instance.ts b/apps/builder/app/shared/copy-paste/plugin-instance.tsindex d3583b8b15..3cab431f16 100644--- a/apps/builder/app/shared/copy-paste/plugin-instance.ts+++ b/apps/builder/app/shared/copy-paste/plugin-instance.ts@@ -1,7 +1,7 @@import store from "immerhin";import { z } from "zod";import {- findTreeInstanceIds,+ findTreeInstanceIdsExcludingSlotDescendants,InstancesItem,Prop,StyleDecl,@@ -49,7 +49,10 @@ const getTreeData = (targetInstanceSelector: InstanceSelector) => {const [targetInstanceId] = targetInstanceSelector;const instances = instancesStore.get();- const treeInstanceIds = findTreeInstanceIds(instances, targetInstanceId);+ const treeInstanceIds = findTreeInstanceIdsExcludingSlotDescendants(+ instances,+ targetInstanceId+ );const styleSources = styleSourcesStore.get();const styleSourceSelections = styleSourceSelectionsStore.get();const subtreeLocalStyleSourceIds = findSubtreeLocalStyleSources(diff --git a/apps/builder/app/shared/instance-utils.ts b/apps/builder/app/shared/instance-utils.tsindex d1760c4569..3a9d845b6f 100644--- a/apps/builder/app/shared/instance-utils.ts+++ b/apps/builder/app/shared/instance-utils.ts@@ -1,5 +1,5 @@import store from "immerhin";-import { findTreeInstanceIds } from "@webstudio-is/project-build";+import { findTreeInstanceIdsExcludingSlotDescendants } from "@webstudio-is/project-build";import {propsStore,stylesStore,@@ -53,12 +53,30 @@ export const deleteInstance = (instanceSelector: InstanceSelector) => {stylesStore,],(instances, props, styleSourceSelections, styleSources, styles) => {- const [targetInstanceId, parentInstanceId] = instanceSelector;- const parentInstance =+ let targetInstanceId = instanceSelector[0];+ const parentInstanceId = instanceSelector[1];+ const grandparentInstanceId = instanceSelector[2];+ let parentInstance =parentInstanceId === undefined? undefined: instances.get(parentInstanceId);- const subtreeIds = findTreeInstanceIds(instances, targetInstanceId);++ // delete parent fragment too if its last child is going to be deleted+ // use case for slots: slot became empty and remove display: contents+ // to be displayed properly on canvas+ if (+ parentInstance?.component === "Fragment" &&+ parentInstance.children.length === 1 &&+ grandparentInstanceId !== undefined+ ) {+ targetInstanceId = parentInstance.id;+ parentInstance = instances.get(grandparentInstanceId);+ }++ const subtreeIds = findTreeInstanceIdsExcludingSlotDescendants(+ instances,+ targetInstanceId+ );const subtreeLocalStyleSourceIds = findSubtreeLocalStyleSources(subtreeIds,styleSources,diff --git a/apps/builder/app/shared/tree-utils.test.ts b/apps/builder/app/shared/tree-utils.test.tsindex 08f25e7e0f..781fcde4df 100644--- a/apps/builder/app/shared/tree-utils.test.ts+++ b/apps/builder/app/shared/tree-utils.test.ts@@ -338,6 +338,88 @@ test("reparent instance into target", () => {);});+test("reparent instance into slot", () => {+ const instances: Instances = new Map([+ createInstancePair("root", "Body", [+ { type: "id", value: "slot1" },+ { type: "id", value: "box2" },+ { type: "id", value: "box3" },+ ]),+ createInstancePair("slot1", "Slot", [{ type: "id", value: "fragment11" }]),+ createInstancePair("fragment11", "Fragment", []),+ createInstancePair("box2", "Box", [+ { type: "id", value: "box21" },+ { type: "id", value: "box22" },+ { type: "id", value: "box23" },+ ]),+ createInstancePair("box21", "Box", []),+ createInstancePair("box22", "Box", []),+ createInstancePair("box23", "Box", []),+ createInstancePair("slot3", "Slot", []),+ ]);++ // reuse existing fragment when drop into slot+ reparentInstanceMutable(instances, ["box2", "root"], {+ parentSelector: ["slot1", "root"],+ position: "end",+ });+ expect(instances).toEqual(+ new Map([+ createInstancePair("root", "Body", [+ { type: "id", value: "slot1" },+ { type: "id", value: "box3" },+ ]),+ createInstancePair("slot1", "Slot", [+ { type: "id", value: "fragment11" },+ ]),+ createInstancePair("fragment11", "Fragment", [+ { type: "id", value: "box2" },+ ]),+ createInstancePair("box2", "Box", [+ { type: "id", value: "box21" },+ { type: "id", value: "box22" },+ { type: "id", value: "box23" },+ ]),+ createInstancePair("box21", "Box", []),+ createInstancePair("box22", "Box", []),+ createInstancePair("box23", "Box", []),+ createInstancePair("slot3", "Slot", []),+ ])+ );++ // create new fragment when drop into empty slot+ reparentInstanceMutable(instances, ["box2", "fragment11", "slot1", "root"], {+ parentSelector: ["slot3", "root"],+ position: "end",+ });+ expect(instances).toEqual(+ new Map([+ createInstancePair("root", "Body", [+ { type: "id", value: "slot1" },+ { type: "id", value: "box3" },+ ]),+ createInstancePair("slot1", "Slot", [+ { type: "id", value: "fragment11" },+ ]),+ createInstancePair("fragment11", "Fragment", []),+ createInstancePair("box2", "Box", [+ { type: "id", value: "box21" },+ { type: "id", value: "box22" },+ { type: "id", value: "box23" },+ ]),+ createInstancePair("box21", "Box", []),+ createInstancePair("box22", "Box", []),+ createInstancePair("box23", "Box", []),+ createInstancePair("slot3", "Slot", [+ { type: "id", value: expectString },+ ]),+ createInstancePair(expectString, "Fragment", [+ { type: "id", value: "box2" },+ ]),+ ])+ );+});+test("insert tree of instances copy and provide map from ids map", () => {const instances = new Map([createInstancePair("1", "Body", [diff --git a/apps/builder/app/shared/tree-utils.ts b/apps/builder/app/shared/tree-utils.tsindex 9dedc29a83..9eddf2cbf7 100644--- a/apps/builder/app/shared/tree-utils.ts+++ b/apps/builder/app/shared/tree-utils.ts@@ -149,6 +149,38 @@ export const findClosestDroppableTarget = (return rootDropTarget;};+const getInstanceOrCreateFragmentIfNecessary = (+ instances: Instances,+ instanceId: Instance["id"]+) => {+ const instance = instances.get(instanceId);+ if (instance === undefined) {+ return;+ }+ // slot should accept only single child+ // otherwise multiple slots will have to maintain own children+ // here all slot children are wrapped with fragment instance+ if (instance.component === "Slot") {+ if (instance.children.length === 0) {+ const id = nanoid();+ const fragment: InstancesItem = {+ type: "instance",+ id,+ component: "Fragment",+ children: [],+ };+ instances.set(id, fragment);+ instance.children.push({ type: "id", value: id });+ return fragment;+ }+ // first slot child is always fragment+ if (instance.children[0].type === "id") {+ return instances.get(instance.children[0].value);+ }+ }+ return instance;+};+export const reparentInstanceMutable = (instances: Instances,instanceSelector: InstanceSelector,@@ -159,7 +191,10 @@ export const reparentInstanceMutable = (parentInstanceId === undefined? undefined: instances.get(parentInstanceId);- const nextParent = instances.get(dropTarget.parentSelector[0]);+ const nextParent = getInstanceOrCreateFragmentIfNecessary(+ instances,+ dropTarget.parentSelector[0]+ );const instance = instances.get(instanceId);if (prevParent === undefined ||@@ -248,7 +283,10 @@ export const insertInstancesMutable = (rootIds: Instance["id"][],dropTarget: DroppableTarget) => {- const parentInstance = instances.get(dropTarget.parentSelector[0]);+ const parentInstance = getInstanceOrCreateFragmentIfNecessary(+ instances,+ dropTarget.parentSelector[0]+ );if (parentInstance === undefined) {return;}@@ -290,12 +328,17 @@ export const insertInstancesCopyMutable = (copiedInstanceIds.set(instance.id, newInstanceId);}+ const preservedChildren = new Set<Instance["id"]>();+for (const instance of copiedInstances) {copiedInstancesWithNewIds.push({...instance,id: copiedInstanceIds.get(instance.id) ?? instance.id,children: instance.children.map((child) => {if (child.type === "id") {+ if (copiedInstanceIds.has(child.value) === false) {+ preservedChildren.add(child.value);+ }return {type: "id",value: copiedInstanceIds.get(child.value) ?? child.value,@@ -306,6 +349,15 @@ export const insertInstancesCopyMutable = (});}+ // slot descendants ids are preserved+ // so need to prevent pasting slot inside itself+ // to avoid circular tree+ for (const instanceId of dropTarget.parentSelector) {+ if (preservedChildren.has(instanceId)) {+ return new Map();+ }+ }+insertInstancesMutable(instances,copiedInstancesWithNewIds,diff --git a/packages/icons/icons/slot-component.svg b/packages/icons/icons/slot-component.svgnew file mode 100644index 0000000000..df34a7ec33--- /dev/null+++ b/packages/icons/icons/slot-component.svg@@ -0,0 +1,10 @@+<svg width="22" height="22" viewBox="0 0 22 22" xmlns="http://www.w3.org/2000/svg">+<path d="M5.95996 2.00783C5.71293 2.01348 5.4878 2.02322 5.28265 2.03999C4.77828 2.08122 4.32966 2.16861 3.91232 2.38031C3.24896 2.7126 2.71257 3.24901 2.38029 3.91237C2.16861 4.3297 2.08122 4.7783 2.03999 5.28265C2.02322 5.4878 2.01348 5.71293 2.00783 5.95996H3.50819C3.5133 5.75181 3.52158 5.56916 3.53501 5.40485C3.5687 4.99263 3.63107 4.76195 3.71854 4.58994L3.72082 4.58541C3.90825 4.21056 4.21056 3.90825 4.58541 3.72082L4.58994 3.71854C4.76195 3.63107 4.99263 3.5687 5.40485 3.53501C5.56916 3.52158 5.75181 3.5133 5.95996 3.50819V2.00783Z" />+<path d="M13.29 3.5H8.70996V2H13.29V3.5Z" />+<path d="M18.4918 5.95996C18.4867 5.75181 18.4784 5.56916 18.465 5.40485C18.4313 4.99263 18.3689 4.76195 18.2815 4.58994L18.2792 4.58542C18.0917 4.21056 17.7894 3.90825 17.4146 3.72082L17.4101 3.71855C17.238 3.63109 17.0074 3.5687 16.5951 3.53501C16.4308 3.52158 16.2482 3.5133 16.04 3.50819V2.00783C16.2871 2.01348 16.5122 2.02322 16.7174 2.03999C17.2217 2.08122 17.6703 2.16861 18.0877 2.3803C18.751 2.71258 19.2874 3.24897 19.6197 3.91232C19.8314 4.32966 19.9188 4.77828 19.96 5.28265C19.9768 5.4878 19.9865 5.71293 19.9922 5.95996H18.4918Z" />+<path d="M18.5 13.29V8.70996H20V13.29H18.5Z" />+<path d="M16.04 18.4918C16.2482 18.4867 16.4308 18.4784 16.5951 18.465C17.0074 18.4313 17.238 18.3689 17.4101 18.2815L17.4146 18.2792C17.7894 18.0917 18.0918 17.7894 18.2792 17.4146L18.2814 17.4101C18.3689 17.238 18.4313 17.0074 18.465 16.5951C18.4784 16.4308 18.4867 16.2482 18.4918 16.04H19.9922C19.9865 16.2871 19.9768 16.5122 19.96 16.7174C19.9188 17.2217 19.8314 17.6704 19.6197 18.0877C19.2874 18.751 18.751 19.2874 18.0877 19.6197C17.6703 19.8314 17.2217 19.9188 16.7174 19.96C16.5122 19.9768 16.2871 19.9865 16.04 19.9922V18.4918Z" />+<path d="M8.70996 18.5H13.29V20H8.70996V18.5Z" />+<path d="M3.50819 16.04C3.5133 16.2482 3.52158 16.4308 3.53501 16.5951C3.5687 17.0074 3.63107 17.238 3.71854 17.4101L3.72084 17.4146C3.90826 17.7894 4.21056 18.0918 4.58541 18.2792L4.58994 18.2814C4.76196 18.3689 4.99263 18.4313 5.40485 18.465C5.56916 18.4784 5.75181 18.4867 5.95996 18.4918V19.9922C5.71293 19.9865 5.4878 19.9768 5.28265 19.96C4.77827 19.9188 4.32966 19.8314 3.91232 19.6197C3.24898 19.2874 2.71259 18.751 2.38031 18.0877C2.16861 17.6703 2.08122 17.2217 2.03999 16.7174C2.02322 16.5122 2.01348 16.2871 2.00783 16.04H3.50819Z" />+<path d="M3.5 8.70996V13.29H2V8.70996H3.5Z" />+</svg>diff --git a/packages/icons/src/__generated__/index.ts b/packages/icons/src/__generated__/index.tsindex 6b482c900a..328975102a 100644--- a/packages/icons/src/__generated__/index.ts+++ b/packages/icons/src/__generated__/index.ts@@ -50,6 +50,7 @@ export * from "./repeat-column";export * from "./repeat-grid";export * from "./repeat-row";export * from "./scroll";+export * from "./slot-component";export * from "./subscript";export * from "./subtract";export * from "./superscript";diff --git a/packages/icons/src/__generated__/slot-component.tsx b/packages/icons/src/__generated__/slot-component.tsxnew file mode 100644index 0000000000..a87842c45b--- /dev/null+++ b/packages/icons/src/__generated__/slot-component.tsx@@ -0,0 +1,15 @@+// Generated from icons/slot-component.svg++import { forwardRef } from "react";+import type { IconProps } from "../types";++// prettier-ignore+export const SlotComponentIcon = forwardRef<SVGSVGElement, IconProps>(+ ({ color = "currentColor", size = 16, ...props }, forwardedRef) => {+ return (+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22" width={size} height={size} fill={color} {...props} ref={forwardedRef}><path d="M5.96 2.008c-.247.005-.472.015-.677.032-.505.041-.953.129-1.37.34A3.43 3.43 0 0 0 2.38 3.912c-.211.418-.299.866-.34 1.37-.017.206-.027.43-.032.678h1.5c.005-.208.014-.39.027-.555.034-.412.096-.643.184-.815l.002-.005a1.93 1.93 0 0 1 .864-.864l.005-.002c.172-.088.403-.15.815-.184.164-.013.347-.022.555-.027v-1.5ZM13.29 3.5H8.71V2h4.58v1.5ZM18.492 5.96a9.863 9.863 0 0 0-.027-.555c-.034-.412-.096-.643-.183-.815l-.003-.005a1.93 1.93 0 0 0-.864-.864l-.005-.002c-.172-.088-.403-.15-.815-.184a9.84 9.84 0 0 0-.555-.027v-1.5c.247.005.472.015.677.032.505.041.953.129 1.37.34a3.43 3.43 0 0 1 1.533 1.532c.211.418.299.866.34 1.37.017.206.026.43.032.678h-1.5ZM18.5 13.29V8.71H20v4.58h-1.5ZM16.04 18.492a9.86 9.86 0 0 0 .555-.027c.412-.034.643-.096.815-.183l.005-.003a1.93 1.93 0 0 0 .864-.864l.002-.005c.088-.172.15-.403.184-.815a9.86 9.86 0 0 0 .027-.555h1.5c-.006.247-.015.472-.032.677-.041.505-.129.953-.34 1.37a3.43 3.43 0 0 1-1.532 1.533c-.418.211-.866.299-1.37.34-.206.017-.43.026-.678.032v-1.5ZM8.71 18.5h4.58V20H8.71v-1.5ZM3.508 16.04c.005.208.014.39.027.555.034.412.096.643.184.815l.002.005c.187.374.49.677.864.864l.005.002c.172.088.403.15.815.184.164.013.347.022.555.027v1.5a11.699 11.699 0 0 1-.677-.032c-.505-.041-.953-.129-1.37-.34a3.43 3.43 0 0 1-1.533-1.532c-.211-.418-.299-.866-.34-1.37-.017-.206-.027-.43-.032-.678h1.5ZM3.5 8.71v4.58H2V8.71h1.5Z" /></svg>+ );+ }+);++SlotComponentIcon.displayName = "SlotComponentIcon";diff --git a/packages/project-build/src/shared/instances-utils.test.ts b/packages/project-build/src/shared/instances-utils.test.tsindex 431a5f882c..6e11dd9345 100644--- a/packages/project-build/src/shared/instances-utils.test.ts+++ b/packages/project-build/src/shared/instances-utils.test.ts@@ -1,6 +1,9 @@import { expect, test } from "@jest/globals";import type { Instance, Instances, InstancesItem } from "../schema/instances";-import { findTreeInstanceIds } from "./instances-utils";+import {+ findTreeInstanceIds,+ findTreeInstanceIdsExcludingSlotDescendants,+} from "./instances-utils";const createInstance = (id: Instance["id"],@@ -40,3 +43,28 @@ test("find all tree instances", () => {]);expect(findTreeInstanceIds(instances, "3")).toEqual(new Set(["3", "4", "5"]));});++test("find all tree instances excluding slot descendants", () => {+ const instances: Instances = new Map([+ createInstancePair("root", "Body", [+ { type: "id", value: "box1" },+ { type: "id", value: "box2" },+ ]),+ // this is outside of subtree+ createInstancePair("outside", "Box", []),+ // these should be matched+ createInstancePair("box1", "Box", [+ { type: "id", value: "slot11" },+ { type: "id", value: "box12" },+ ]),+ createInstancePair("slot11", "Slot", [+ { type: "id", value: "box111" },+ { type: "id", value: "box112" },+ ]),+ createInstancePair("box12", "Box", []),+ createInstancePair("box2", "Box", []),+ ]);+ expect(+ findTreeInstanceIdsExcludingSlotDescendants(instances, "box1")+ ).toEqual(new Set(["box1", "box12", "slot11"]));+});diff --git a/packages/project-build/src/shared/instances-utils.ts b/packages/project-build/src/shared/instances-utils.tsindex c98b851a40..ef1bdb6cad 100644--- a/packages/project-build/src/shared/instances-utils.ts+++ b/packages/project-build/src/shared/instances-utils.ts@@ -3,13 +3,16 @@ import type { Instance, Instances, InstancesItem } from "../schema/instances";const traverseInstances = (instances: Instances,instanceId: Instance["id"],- callback: (instance: InstancesItem) => void+ callback: (instance: InstancesItem) => false | void) => {const instance = instances.get(instanceId);if (instance === undefined) {return;}- callback(instance);+ const skipTraversingChildren = callback(instance);+ if (skipTraversingChildren === false) {+ return;+ }for (const child of instance.children) {if (child.type === "id") {traverseInstances(instances, child.value, callback);@@ -27,3 +30,17 @@ export const findTreeInstanceIds = (});return ids;};++export const findTreeInstanceIdsExcludingSlotDescendants = (+ instances: Instances,+ rootInstanceId: Instance["id"]+) => {+ const ids = new Set<Instance["id"]>();+ traverseInstances(instances, rootInstanceId, (instance) => {+ ids.add(instance.id);+ if (instance.component === "Slot") {+ return false;+ }+ });+ return ids;+};diff --git a/packages/react-sdk/src/components/__generated__/fragment.props.ts b/packages/react-sdk/src/components/__generated__/fragment.props.tsnew file mode 100644index 0000000000..9cf655a4a1--- /dev/null+++ b/packages/react-sdk/src/components/__generated__/fragment.props.ts@@ -0,0 +1,3 @@+import type { PropMeta } from "@webstudio-is/generate-arg-types";++export const props: Record<string, PropMeta> = {};diff --git a/packages/react-sdk/src/components/__generated__/slot.props.ts b/packages/react-sdk/src/components/__generated__/slot.props.tsnew file mode 100644index 0000000000..9cf655a4a1--- /dev/null+++ b/packages/react-sdk/src/components/__generated__/slot.props.ts@@ -0,0 +1,3 @@+import type { PropMeta } from "@webstudio-is/generate-arg-types";++export const props: Record<string, PropMeta> = {};diff --git a/packages/react-sdk/src/components/components-utils.ts b/packages/react-sdk/src/components/components-utils.tsindex 251ba3a022..a8efd603b6 100644--- a/packages/react-sdk/src/components/components-utils.ts+++ b/packages/react-sdk/src/components/components-utils.ts@@ -10,6 +10,8 @@ export type ComponentName = keyof typeof components;* @todo this list should not be hardcoded!*/const componentNames = Object.keys({+ Slot: 1,+ Fragment: 1,Box: 1,Body: 1,TextBlock: 1,diff --git a/packages/react-sdk/src/components/components.ts b/packages/react-sdk/src/components/components.tsindex c1e4f8540e..0a72263d70 100644--- a/packages/react-sdk/src/components/components.ts+++ b/packages/react-sdk/src/components/components.ts@@ -5,6 +5,8 @@* getComponent = createGetComponent({ Box, BlaBla })to pass them to RootInstance* see example /packages/sdk-size-test/app/routes/$.tsx*/+export { Slot } from "./slot";+export { Fragment } from "./fragment";export { Body } from "./body";export { Box } from "./box";export { TextBlock } from "./text-block";diff --git a/packages/react-sdk/src/components/fragment.tsx b/packages/react-sdk/src/components/fragment.tsxnew file mode 100644index 0000000000..8b85ef2fba--- /dev/null+++ b/packages/react-sdk/src/components/fragment.tsx@@ -0,0 +1,11 @@+import { forwardRef, type ElementRef, type ReactNode } from "react";++type Props = {+ children?: ReactNode;+};++export const Fragment = forwardRef<ElementRef<"div">, Props>((props, ref) => {+ return <div {...props} ref={ref} style={{ display: "contents" }} />;+});++Fragment.displayName = "Fragment";diff --git a/packages/react-sdk/src/components/fragment.ws.ts b/packages/react-sdk/src/components/fragment.ws.tsnew file mode 100644index 0000000000..9e22b4bfd9--- /dev/null+++ b/packages/react-sdk/src/components/fragment.ws.ts@@ -0,0 +1,11 @@+import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";++export const meta: WsComponentMeta = {+ type: "container",+ label: "Fragment",+ Icon: () => null,+};++export const propsMeta: WsComponentPropsMeta = {+ props: {},+};diff --git a/packages/react-sdk/src/components/index.ts b/packages/react-sdk/src/components/index.tsindex 7afd5dc760..f722c80f84 100644--- a/packages/react-sdk/src/components/index.ts+++ b/packages/react-sdk/src/components/index.ts@@ -1,6 +1,8 @@import { PropMeta } from "@webstudio-is/generate-arg-types";import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";import type { ComponentName } from "./components-utils";+import { meta as SlotMeta } from "./slot.ws";+import { meta as FragmentMeta } from "./fragment.ws";import { meta as BodyMeta } from "./body.ws";import { meta as BoxMeta } from "./box.ws";import { meta as TextBlockMeta } from "./text-block.ws";@@ -25,6 +27,8 @@ import { meta as SeparatorMeta } from "./separator.ws";import { meta as CodeMeta } from "./code.ws";// these are huge JSON objects that we want to be tree-shaken when not used!+import { propsMeta as SlotMetaPropsMeta } from "./slot.ws";+import { propsMeta as FragmentMetaPropsMeta } from "./fragment.ws";import { propsMeta as BodyMetaPropsMeta } from "./body.ws";import { propsMeta as BoxMetaPropsMeta } from "./box.ws";import { propsMeta as TextBlockMetaPropsMeta } from "./text-block.ws";@@ -50,6 +54,8 @@ import { propsMeta as CodePropsMeta } from "./code.ws";// @todo this list should not be hardcoded!const defaultMetas: Record<string, WsComponentMeta> = {+ Slot: SlotMeta,+ Fragment: FragmentMeta,Box: BoxMeta,Body: BodyMeta,TextBlock: TextBlockMeta,@@ -92,6 +98,8 @@ export const registerComponentMetas = (// @todo this list should not be hardcoded!const defaultPropsMetasRaw = {+ Slot: SlotMetaPropsMeta,+ Fragment: FragmentMetaPropsMeta,Box: BoxMetaPropsMeta,Body: BodyMetaPropsMeta,TextBlock: TextBlockMetaPropsMeta,diff --git a/packages/react-sdk/src/components/slot.stories.tsx b/packages/react-sdk/src/components/slot.stories.tsxnew file mode 100644index 0000000000..7d31deb3d9--- /dev/null+++ b/packages/react-sdk/src/components/slot.stories.tsx@@ -0,0 +1,16 @@+import type { ComponentStory, ComponentMeta } from "@storybook/react";+import { Slot as SlotPrimitive } from "./slot";++export default {+ title: "Components/Slot",+ component: SlotPrimitive,+} as ComponentMeta<typeof SlotPrimitive>;++const Template: ComponentStory<typeof SlotPrimitive> = (args) => (+ <SlotPrimitive {...args} />+);++export const Slot = Template.bind({});+Slot.args = {+ children: "Slot",+};diff --git a/packages/react-sdk/src/components/slot.tsx b/packages/react-sdk/src/components/slot.tsxnew file mode 100644index 0000000000..45ce40ab63--- /dev/null+++ b/packages/react-sdk/src/components/slot.tsx@@ -0,0 +1,17 @@+import { forwardRef, type ElementRef, type ReactNode } from "react";++type Props = {+ children?: ReactNode;+};++export const Slot = forwardRef<ElementRef<"div">, Props>((props, ref) => {+ return (+ <div+ {...props}+ ref={ref}+ style={{ display: props.children ? "contents" : "block" }}+ />+ );+});++Slot.displayName = "Slot";diff --git a/packages/react-sdk/src/components/slot.ws.ts b/packages/react-sdk/src/components/slot.ws.tsnew file mode 100644index 0000000000..c2a84d99cb--- /dev/null+++ b/packages/react-sdk/src/components/slot.ws.ts@@ -0,0 +1,13 @@+import { SlotComponentIcon } from "@webstudio-is/icons";+import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";++export const meta: WsComponentMeta = {+ category: "general",+ type: "container",+ label: "Slot",+ Icon: SlotComponentIcon,+};++export const propsMeta: WsComponentPropsMeta = {+ props: {},+};