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
Merge branch 'main' into types/pubsub
Oleg Isonen9123e6bf620a
diff --cc apps/designer/app/canvas/features/wrapper-component/text-editor/example-text-editor.tsxindex 03394f6806,673c6d8651..3e60be6cd3--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/example-text-editor.tsx+++ b/apps/designer/app/canvas/features/wrapper-component/text-editor/example-text-editor.tsx@@@ -8,14 -9,7 +8,14 @@@ import { Box, Button } from "@webstudioimport { LexicalComposer, ContentEditable } from "./lexical";import { TreeViewPlugin } from "./plugins/tree-view-plugin";import { config } from "./config";- import { Editor } from "./editor";+ import Editor from "./editor";+import { publish } from "~/shared/pubsub";++declare module "~/shared/pubsub" {+ export interface PubsubMap {+ insertInlineInstance: Instance;+ }+}type ExampleTextEditorProps = {onChange: (state: ChildrenUpdates) => void;diff --cc apps/designer/app/canvas/shared/instance.tsindex 593254bc07,f0daa9b802..39a3420059--- a/apps/designer/app/canvas/shared/instance.ts+++ b/apps/designer/app/canvas/shared/instance.ts@@@ -113,7 -110,15 +113,9 @@@ export const useInsertInstance = () =>};export const useReparentInstance = () => {+ const [selectedInstance, setSelectedInstance] = useSelectedInstance();+- useSubscribe<- "reparentInstance",- {- instanceId: Instance["id"];- dropTarget: { instanceId: Instance["id"]; position: number | "end" };- }- >("reparentInstance", ({ instanceId, dropTarget }) => {+ useSubscribe("reparentInstance", ({ instanceId, dropTarget }) => {store.createTransaction([rootInstanceContainer], (rootInstance) => {if (rootInstance === undefined) return;reparentInstanceMutable(@@@ -129,29 -144,40 +141,34 @@@export const useDeleteInstance = () => {const [rootInstance] = useRootInstance();const [selectedInstance, setSelectedInstance] = useSelectedInstance();- useSubscribe<"deleteInstance", { id: Instance["id"] }>(- "deleteInstance",- ({ id }) => {- if (rootInstance !== undefined && selectedInstance !== undefined) {- // @todo tell user they can't delete root- if (id === rootInstance.id) {- return;- }+ useSubscribe("deleteInstance", ({ id }) => {+ if (rootInstance !== undefined && selectedInstance !== undefined) {++ // @todo tell user they can't delete root++ if (id === rootInstance.id) {++ return;++ }+- const parentInstance = findParentInstance(rootInstance, id);- if (parentInstance !== undefined) {- const siblingInstance = findClosestSiblingInstance(- parentInstance,- id- );- setSelectedInstance(siblingInstance || parentInstance);- }+ const parentInstance = findParentInstance(rootInstance, id);+ if (parentInstance !== undefined) {+ const siblingInstance = findClosestSiblingInstance(parentInstance, id);+ setSelectedInstance(siblingInstance || parentInstance);}- // @todo deleting instance should involve also deleting it's props- // If we don't delete them - they just live both on client and db- // Pros:- // - if we undo the deletion we don't need to undo the props deletion- // - in a multiplayer environment, some other user could have changed a prop while we have deleted the instance- // and then if we restore the instance, we would be restoring it with our props, potentially overwriting other users changes- // The way it is now it will actually still enable parallel deletion props editing and restoration.- // Contra: we are piling them up.- // Potentially we could also solve this by periodically removing unused props after while when instance was deleted- store.createTransaction([rootInstanceContainer], (rootInstance) => {- if (rootInstance !== undefined) {- deleteInstanceMutable(rootInstance, id);- }- });}- );+ // @todo deleting instance should involve also deleting it's props+ // If we don't delete them - they just live both on client and db+ // Pros:+ // - if we undo the deletion we don't need to undo the props deletion+ // - in a multiplayer environment, some other user could have changed a prop while we have deleted the instance+ // and then if we restore the instance, we would be restoring it with our props, potentially overwriting other users changes+ // The way it is now it will actually still enable parallel deletion props editing and restoration.+ // Contra: we are piling them up.+ // Potentially we could also solve this by periodically removing unused props after while when instance was deleted+ store.createTransaction([rootInstanceContainer], (rootInstance) => {+ if (rootInstance !== undefined) {+ deleteInstanceMutable(rootInstance, id);+ }+ });+ });};export const usePublishSelectedInstanceData = (treeId: Tree["id"]) => {diff --cc apps/designer/app/canvas/shared/use-drag-drop.tsindex 029cf27332,346966cfdc..b178ac4285--- a/apps/designer/app/canvas/shared/use-drag-drop.ts+++ b/apps/designer/app/canvas/shared/use-drag-drop.ts@@@ -184,8 -192,9 +203,9 @@@ export const useDragAndDrop = () =>state.current.dragItem = instance;autoScrollHandlers.setEnabled(true);+ dropHandlers.handleStart();- publish<"dragStart", DragStartPayload>({+ publish({type: "dragStart",payload: {origin: "canvas",@@@ -198,10 -207,10 +218,10 @@@autoScrollHandlers.handleMove(point);},onEnd({ isCanceled }) {- dropHandlers.handleEnd();+ dropHandlers.handleEnd({ isCanceled });autoScrollHandlers.setEnabled(false);- publish<"dragEnd", DragEndPayload>({+ publish({type: "dragEnd",payload: { origin: "canvas", isCanceled },});@@@ -248,39 -263,55 +268,40 @@@// Handle drag from the panel// ================================================================- useSubscribe<"dragStart", DragStartPayload>(- "dragStart",- ({ origin, dragItem }) => {- if (origin === "panel") {- state.current.dragItem = dragItem;- autoScrollHandlers.setEnabled(true);- dropHandlers.handleStart();- }+ useSubscribe("dragStart", ({ origin, dragItem }) => {+ if (origin === "panel") {+ state.current.dragItem = dragItem;+ autoScrollHandlers.setEnabled(true);++ dropHandlers.handleStart();}- );+ });- useSubscribe<"dragMove", DragMovePayload>(- "dragMove",- ({ canvasCoordinates }) => {- dropHandlers.handleMove(canvasCoordinates);- autoScrollHandlers.handleMove(canvasCoordinates);- }- );-- useSubscribe<"dragEnd", DragEndPayload>(- "dragEnd",- ({ origin, isCanceled }) => {- if (origin === "panel") {- dropHandlers.handleEnd({ isCanceled });- autoScrollHandlers.setEnabled(false);-- const { dropTarget, dragItem } = state.current;-- if (dropTarget && dragItem && isCanceled === false) {- publish<- "insertInstance",- {- instance: Instance;- dropTarget: { parentId: Instance["id"]; position: number };- }- >({- type: "insertInstance",- payload: {- instance: createInstance({ component: dragItem.component }),- dropTarget: {- parentId: dropTarget.data.id,- position: dropTarget.indexWithinChildren,- },- },- });- }+ useSubscribe("dragMove", ({ canvasCoordinates }) => {+ dropHandlers.handleMove(canvasCoordinates);+ autoScrollHandlers.handleMove(canvasCoordinates);+ });++ useSubscribe("dragEnd", ({ origin, isCanceled }) => {+ if (origin === "panel") {- dropHandlers.handleEnd();++ dropHandlers.handleEnd({ isCanceled });+ autoScrollHandlers.setEnabled(false);- state.current = { ...initialState };+ const { dropTarget, dragItem } = state.current;++ if (dropTarget && dragItem && isCanceled === false) {+ publish({+ type: "insertInstance",+ payload: {+ instance: createInstance({ component: dragItem.component }),+ dropTarget: {+ parentId: dropTarget.data.id,+ position: dropTarget.indexWithinChildren,+ },+ },+ });}++ state.current = { ...initialState };}- );+ });};diff --cc apps/designer/app/canvas/shared/use-shortcuts.tsindex 25909f0a42,b41f1a83e7..31a5823a1d--- a/apps/designer/app/canvas/shared/use-shortcuts.ts+++ b/apps/designer/app/canvas/shared/use-shortcuts.ts@@@ -1,29 -1,15 +1,26 @@@import { useHotkeys } from "react-hotkeys-hook";import store from "immerhin";-import {- type Instance,- publish,- useSubscribe,- components,-} from "@webstudio-is/react-sdk";+import { type Instance, components } from "@webstudio-is/react-sdk";import { shortcuts, options } from "~/shared/shortcuts";+import { publish, useSubscribe } from "~/shared/pubsub";import { useSelectedInstance } from "./nano-states";import { copy, paste } from "./copy-paste";- import {- useRootInstance,- useTextEditingInstanceId,- } from "~/shared/nano-states";+ import { useTextEditingInstanceId } from "~/shared/nano-states";+import { type SelectedInstanceData } from "~/shared/canvas-components";++declare module "~/shared/pubsub" {+ export interface PubsubMap {+ cancelCurrentDrag: undefined;+ deleteInstance: {+ id: Instance["id"];+ };+ openBreakpointsMenu: undefined;+ selectBreakpointFromShortcut: number;+ selectInstance?: SelectedInstanceData;+ togglePreviewMode: undefined;+ zoom: "zoomOut" | "zoomIn";+ }+}const inputTags = ["INPUT", "SELECT", "TEXTAREA"] as const;@@@ -75,18 -50,12 +71,12 @@@ export const useShortcuts = () =>const [editingInstanceId, setEditingInstanceId] = useTextEditingInstanceId();const publishDeleteInstance = () => {- // @todo tell user they can't delete root- if (- selectedInstance === undefined ||- selectedInstance.id === rootInstance?.id- ) {+ if (selectedInstance === undefined) {return;}- publish<"deleteInstance", { id: Instance["id"] }>({+ publish({type: "deleteInstance",- payload: {- id: selectedInstance.id,- },+ payload: { id: selectedInstance.id },});};diff --cc apps/designer/app/designer/features/breadcrumbs/breadcrumbs.tsxindex 4a3691c435,7cd7205792..ac2321e4b4--- a/apps/designer/app/designer/features/breadcrumbs/breadcrumbs.tsx+++ b/apps/designer/app/designer/features/breadcrumbs/breadcrumbs.tsx@@@ -1,16 -1,14 +1,21 @@@import { ChevronRightIcon } from "@webstudio-is/icons";- import { Button, Flex, Text, darkTheme } from "@webstudio-is/design-system";+ import {+ Button,+ Flex,+ __DEPRECATED__Text,+ darkTheme,+ } from "@webstudio-is/design-system";import { useSelectedInstancePath } from "../../shared/instance/use-selected-instance-path";-import { type Publish, type Instance } from "@webstudio-is/react-sdk";+import { type Instance } from "@webstudio-is/react-sdk";+import { type Publish } from "~/shared/pubsub";import { useSelectedInstanceData } from "~/designer/shared/nano-states";+declare module "~/shared/pubsub" {+ export interface PubsubMap {+ selectInstanceById: Instance["id"];+ }+}+type BreadcrumbProps = {component: Instance["component"];onClick: () => void;diff --cc apps/designer/app/designer/features/breakpoints/breakpoints-editor.tsxindex c172956a12,08c1506b6b..096f62e2c8--- a/apps/designer/app/designer/features/breakpoints/breakpoints-editor.tsx+++ b/apps/designer/app/designer/features/breakpoints/breakpoints-editor.tsx@@@ -1,8 -1,12 +1,13 @@@import { useState } from "react";import useDebounce from "react-use/lib/useDebounce";-import { type Breakpoint, type Publish } from "@webstudio-is/react-sdk";+import { type Breakpoint } from "@webstudio-is/react-sdk";+import { type Publish } from "~/shared/pubsub";- import { Button, TextField, Flex, Text } from "@webstudio-is/design-system";+ import {+ Button,+ TextField,+ Flex,+ __DEPRECATED__Text,+ } from "@webstudio-is/design-system";import { PlusIcon, TrashIcon } from "@webstudio-is/icons";import ObjectId from "bson-objectid";import { useBreakpoints } from "~/shared/nano-states";diff --cc apps/designer/app/designer/features/inspector/inspector.tsxindex 4287854aa1,4eaa2e8ba0..e9908617b7--- a/apps/designer/app/designer/features/inspector/inspector.tsx+++ b/apps/designer/app/designer/features/inspector/inspector.tsx@@@ -1,6 -1,6 +1,6 @@@-import type { Publish } from "@webstudio-is/react-sdk";+import type { Publish } from "~/shared/pubsub";import {- Text,+ __DEPRECATED__Text,Tabs,TabsList,TabsTrigger,diff --cc apps/designer/app/designer/features/sidebar-left/lib/navigator/navigator.tsxindex c53bb762fb,2bfea63e17..c4431c40e9--- a/apps/designer/app/designer/features/sidebar-left/lib/navigator/navigator.tsx+++ b/apps/designer/app/designer/features/sidebar-left/lib/navigator/navigator.tsx@@@ -1,18 -1,11 +1,23 @@@- import { Box } from "@webstudio-is/design-system";+ import { Flex } from "@webstudio-is/design-system";-import { type Instance, type Publish } from "@webstudio-is/react-sdk";+import type { Instance } from "@webstudio-is/react-sdk";+import { type Publish } from "~/shared/pubsub";- import { useSelectedInstancePath } from "~/designer/shared/instance/use-selected-instance-path";+ import { useCallback } from "react";import { useSelectedInstanceData } from "~/designer/shared/nano-states";- import { Tree } from "~/designer/shared/tree";import { useRootInstance } from "~/shared/nano-states";import { Header } from "../header";+ import { InstanceTree } from "~/designer/shared/tree";+declare module "~/shared/pubsub" {+ export interface PubsubMap {+ selectInstanceById: Instance["id"];++ reparentInstance: {++ instanceId: Instance["id"];++ dropTarget: { instanceId: Instance["id"]; position: number | "end" };++ };++ deleteInstance: { id: Instance["id"] };+ }+}+type NavigatorProps = {publish: Publish;isClosable?: boolean;@@@ -22,8 -15,48 +27,44 @@@export const Navigator = ({ publish, isClosable, onClose }: NavigatorProps) => {const [selectedInstanceData] = useSelectedInstanceData();const [rootInstance] = useRootInstance();- const selectedInstancePath = useSelectedInstancePath(- selectedInstanceData?.id++ const handleSelect = useCallback(+ (instanceId: Instance["id"]) => {- publish<"selectInstanceById", Instance["id"]>({++ publish({+ type: "selectInstanceById",+ payload: instanceId,+ });+ },+ [publish]+ );+- type ReparentInstancePayload = {- instanceId: Instance["id"];- dropTarget: { instanceId: Instance["id"]; position: number | "end" };- };+ const handleDragEnd = useCallback(+ (payload: {+ itemId: string;+ dropTarget: { itemId: string; position: number | "end" };+ }) => {- publish<"reparentInstance", ReparentInstancePayload>({++ publish({+ type: "reparentInstance",+ payload: {+ instanceId: payload.itemId,+ dropTarget: {+ instanceId: payload.dropTarget.itemId,+ position: payload.dropTarget.position,+ },+ },+ });+ },+ [publish]+ );++ const handleDelete = useCallback(+ (instanceId: Instance["id"]) => {- publish<"deleteInstance", { id: Instance["id"] }>({++ publish({+ type: "deleteInstance",+ payload: { id: instanceId },+ });+ },+ [publish]);if (rootInstance === undefined) return null;diff --cc apps/designer/app/designer/features/workspace/workspace.tsxindex 65d2df81f5,53c2581306..2be2c62316--- a/apps/designer/app/designer/features/workspace/workspace.tsx+++ b/apps/designer/app/designer/features/workspace/workspace.tsx@@@ -1,23 -1,7 +1,19 @@@import { Box, Flex, Toaster } from "@webstudio-is/design-system";+import { type Instance, type InstanceProps } from "@webstudio-is/react-sdk";import { useCanvasWidth, useZoom } from "~/designer/shared/nano-states";import { CanvasTools } from "./canvas-tools";-import { type Publish } from "@webstudio-is/react-sdk";+import { type Publish } from "~/shared/pubsub";++declare module "~/shared/pubsub" {+ export interface PubsubMap {+ insertInstance: {+ instance: Instance;+ dropTarget?: { parentId: Instance["id"]; position: number };+ props?: InstanceProps;+ };- reparentInstance: {- instanceId: Instance["id"];- dropTarget: { instanceId: Instance["id"]; position: number };- };+ unselectInstance: undefined;+ }+}const workspaceStyle = {flexGrow: 1,diff --cc packages/react-sdk/src/components/index.test.tsindex 0000000000,a2e3fd8cb3..a3b863d31fmode 000000,100644..100644--- a/packages/react-sdk/src/components/index.test.ts+++ b/packages/react-sdk/src/components/index.test.ts@@@ -1,0 -1,9 +1,12 @@@+ import * as components from "./index";+ import { WsComponentMetaSchema } from "./component-type";+-test.each(Object.entries(components))("validating meta definition of %s", (name, component) => {- if (name === "default") {- return;++test.each(Object.entries(components))(++ "validating meta definition of %s",++ (name, component) => {++ if (name === "default") {++ return;++ }++ WsComponentMetaSchema.parse(component);+ }- WsComponentMetaSchema.parse(component);-});++);