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
fix minor review comments
Roman Pominov94656733a26b
diff --git a/apps/designer/app/canvas/shared/use-drag-drop.ts b/apps/designer/app/canvas/shared/use-drag-drop.tsindex adbad0c437..599a739ea4 100644--- a/apps/designer/app/canvas/shared/use-drag-drop.ts+++ b/apps/designer/app/canvas/shared/use-drag-drop.ts@@ -22,7 +22,7 @@ export type DropTargetChangePayload = {placement: DropTarget<null>["placement"];position: number;instanceId: Instance["id"];- instanceComponent: Instance["component"];+ component: Instance["component"];};export type DragStartPayload = {@@ -45,7 +45,7 @@ export const useDragAndDrop = () => {const state = useRef({ ...initialState });- const autoScrollHandlers = useAutoScroll({ fullScreen: true });+ const autoScrollHandlers = useAutoScroll({ fullscreen: true });const getDefaultDropTarget = () => {const element = rootInstance && document.getElementById(rootInstance.id);@@ -87,8 +87,10 @@ export const useDragAndDrop = () => {path.shift();}- // Don't allow to dpop inside drag item or any of its children- const dragItemIndex = path.findIndex((x) => x.id === dragItem.id);+ // Don't allow to drop inside drag item or any of its children+ const dragItemIndex = path.findIndex(+ (instance) => instance.id === dragItem.id+ );if (dragItemIndex !== -1) {path.splice(0, dragItemIndex + 1);}@@ -107,7 +109,7 @@ export const useDragAndDrop = () => {const element = data && document.getElementById(data.id);- if (!element) {+ if (element === null) {return getDefaultDropTarget();}@@ -122,8 +124,10 @@ export const useDragAndDrop = () => {rect: dropTarget.rect,placement: dropTarget.placement,position: dropTarget.indexWithinChildren,++ // @todo: use ShalowInstanceinstanceId: dropTarget.data.id,- instanceComponent: dropTarget.data.component,+ component: dropTarget.data.component,},});},@@ -166,9 +170,9 @@ export const useDragAndDrop = () => {},});},- onMove: (poiterCoordinate) => {- dropHandlers.handleMove(poiterCoordinate);- autoScrollHandlers.handleMove(poiterCoordinate);+ onMove: (point) => {+ dropHandlers.handleMove(point);+ autoScrollHandlers.handleMove(point);},onEnd() {dropHandlers.handleEnd();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.tsindex 7f1e3a5a72..886cc951e2 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@@ -117,7 +117,7 @@ export const usePropsLogic = ({const isPropRequired = draft[index].required;switch (field) {case "prop":- if (!isPropRequired) {+ if (isPropRequired !== true) {// TODO: Use discriminant type to make this more clear or separate into 2 functionsdraft[index].prop = value as UserProp["prop"];}diff --git a/apps/designer/app/designer/features/sidebar-left/panels/components/components.tsx b/apps/designer/app/designer/features/sidebar-left/panels/components/components.tsxindex f302f33c0d..27fbdee2a7 100644--- a/apps/designer/app/designer/features/sidebar-left/panels/components/components.tsx+++ b/apps/designer/app/designer/features/sidebar-left/panels/components/components.tsx@@ -39,10 +39,10 @@ const DraggableThumb = ({ component, onClick }: DraggableThumbProps) => {const DragLayer = ({component,- pointerPosition,+ point,}: {component: Instance["component"];- pointerPosition: { x: number; y: number };+ point: { x: number; y: number };}) => {return createPortal(<Flex@@ -59,7 +59,7 @@ const DragLayer = ({<ComponentThumbcomponent={component}style={{- transform: `translate3d(${pointerPosition.x}px, ${pointerPosition.y}px, 0)`,+ transform: `translate3d(${point.x}px, ${point.y}px, 0)`,}}state="dragging"/>@@ -74,20 +74,20 @@ type TabContentProps = {};const elementToComponentName = (element: Element) => {+ // If drag doesn't start on the button element directly but on one of its children,+ // we need to trace back to the button that has the data.const parentWithData = element.closest("[data-drag-component]");- if (parentWithData === null || !(parentWithData instanceof HTMLElement)) {++ if (!(parentWithData instanceof HTMLElement)) {return;}const { dragComponent } = parentWithData.dataset;- return componentNames.find((c) => c === dragComponent);+ return componentNames.find((component) => component === dragComponent);};export const TabContent = ({ publish, onSetActiveTab }: TabContentProps) => {const [dragComponent, setDragComponent] = useState<Instance["component"]>();- const [pointerPosition, setPointerPosition] = useState<{- x: number;- y: number;- }>({ x: 0, y: 0 });+ const [point, setPoint] = useState<{ x: number; y: number }>({ x: 0, y: 0 });const [canvasRect] = useCanvasRect();const [zoom] = useZoom();@@ -118,11 +118,11 @@ export const TabContent = ({ publish, onSetActiveTab }: TabContentProps) => {},});},- onMove: (poiterCoordinate) => {- setPointerPosition(poiterCoordinate);+ onMove: (point) => {+ setPoint(point);publish<"dragMove", DragMovePayload>({type: "dragMove",- payload: { canvasCoordinates: toCanvasCoordinates(poiterCoordinate) },+ payload: { canvasCoordinates: toCanvasCoordinates(point) },});},onEnd() {@@ -154,12 +154,7 @@ export const TabContent = ({ publish, onSetActiveTab }: TabContentProps) => {}}/>))}- {dragComponent && (- <DragLayer- component={dragComponent}- pointerPosition={pointerPosition}- />- )}+ {dragComponent && <DragLayer component={dragComponent} point={point} />}</Flex>);};diff --git a/apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsx b/apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsxindex 894f95ea71..2383f86139 100644--- a/apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsx+++ b/apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsx@@ -99,7 +99,7 @@ export const AssetManagerThumbnail = ({...(isUploading ? { filter: "blur(1px)", opacity: 0.7 } : {}),}}></Box>- {!isUploading && (+ {isUploading === false && (<Tooltipopen={isTooltipOpen}multilinediff --git a/apps/designer/app/designer/features/topbar/preview.tsx b/apps/designer/app/designer/features/topbar/preview.tsxindex 62a2585216..53c1158815 100644--- a/apps/designer/app/designer/features/topbar/preview.tsx+++ b/apps/designer/app/designer/features/topbar/preview.tsx@@ -19,7 +19,7 @@ export const PreviewButton = ({ publish }: PreviewButtonProps) => {};useSubscribe<"togglePreviewMode">("togglePreviewMode", () => {- setValue(!isPreviewMode);+ setValue(isPreviewMode === false);});return (diff --git a/apps/designer/app/designer/features/workspace/canvas-tools/outline/drop-target-outline.tsx b/apps/designer/app/designer/features/workspace/canvas-tools/outline/drop-target-outline.tsxindex 9a3bc6e7f3..6f0bbc230a 100644--- a/apps/designer/app/designer/features/workspace/canvas-tools/outline/drop-target-outline.tsx+++ b/apps/designer/app/designer/features/workspace/canvas-tools/outline/drop-target-outline.tsx@@ -9,10 +9,7 @@ export const DropTargetOutline = ({}) => {return (<Outline rect={dropTarget.rect}>- <Label- component={dropTarget.instanceComponent}- instanceRect={dropTarget.rect}- />+ <Label component={dropTarget.component} instanceRect={dropTarget.rect} /></Outline>);};diff --git a/apps/designer/app/shared/session/use-login-error-message.ts b/apps/designer/app/shared/session/use-login-error-message.tsindex 38dc96651c..c0200109fd 100644--- a/apps/designer/app/shared/session/use-login-error-message.ts+++ b/apps/designer/app/shared/session/use-login-error-message.ts@@ -26,7 +26,7 @@ export const useLoginErrorMessage = (): string => {const message = searchParams.get("message");const hasMessageToShow =- error !== null && !isNil(message) && message !== "";+ error !== null && message != null && message !== "";if (hasMessageToShow) {sentryException({diff --git a/apps/designer/app/shared/tree-utils/reparent-instance.ts b/apps/designer/app/shared/tree-utils/reparent-instance.tsindex 5ae2ef574e..0785f81be5 100644--- a/apps/designer/app/shared/tree-utils/reparent-instance.ts+++ b/apps/designer/app/shared/tree-utils/reparent-instance.ts@@ -21,7 +21,7 @@ export const reparentInstanceMutable = (const currentParent = findParentInstance(rootInstance, instance.id);if (currentParent !== undefined && currentParent.id === newParentId) {const currentPosition = currentParent.children.findIndex(- (x) => typeof x !== "string" && x.id === instance.id+ (child) => typeof child !== "string" && child.id === instance.id);if (currentPosition < newPosition) {newPositionAdjusted--;diff --git a/packages/asset-uploader/jest.config.js b/packages/asset-uploader/jest.config.jsindex 9eae0843c6..4eeecbaf4e 100644--- a/packages/asset-uploader/jest.config.js+++ b/packages/asset-uploader/jest.config.js@@ -1,6 +1 @@-// eslint-disable-next-line-const base = require("@webstudio-is/jest-config");--module.exports = {- ...base,-};+module.exports = require("@webstudio-is/jest-config");diff --git a/packages/design-system/jest.config.js b/packages/design-system/jest.config.jsindex 9eae0843c6..4eeecbaf4e 100644--- a/packages/design-system/jest.config.js+++ b/packages/design-system/jest.config.js@@ -1,6 +1 @@-// eslint-disable-next-line-const base = require("@webstudio-is/jest-config");--module.exports = {- ...base,-};+module.exports = require("@webstudio-is/jest-config");diff --git a/packages/design-system/src/components/primitives/dnd/canvas.stories.tsx b/packages/design-system/src/components/primitives/dnd/canvas.stories.tsxindex 1f010225eb..f5695ba47d 100644--- a/packages/design-system/src/components/primitives/dnd/canvas.stories.tsx+++ b/packages/design-system/src/components/primitives/dnd/canvas.stories.tsx@@ -223,7 +223,7 @@ export const Canvas = () => {path.shift();}- // Don't allow to dpop inside drag item or any of its children+ // Don't allow to drop inside drag item or any of its childrenconst dragItemIndex = path.findIndex((item) => item.id === dragItemId);if (dragItemIndex !== -1) {path.splice(0, dragItemIndex + 1);@@ -263,9 +263,9 @@ export const Canvas = () => {setDragItemId(id);autoScrollHandlers.setEnabled(true);},- onMove: (poiterCoordinate) => {- dropHandlers.handleMove(poiterCoordinate);- autoScrollHandlers.handleMove(poiterCoordinate);+ onMove: (point) => {+ dropHandlers.handleMove(point);+ autoScrollHandlers.handleMove(point);},onEnd() {if (dragItemId !== undefined && currentDropTarget !== undefined) {diff --git a/packages/design-system/src/components/primitives/dnd/geometry-utils.ts b/packages/design-system/src/components/primitives/dnd/geometry-utils.tsindex fc7efd928a..9a0bf72e72 100644--- a/packages/design-system/src/components/primitives/dnd/geometry-utils.ts+++ b/packages/design-system/src/components/primitives/dnd/geometry-utils.ts@@ -243,18 +243,20 @@ export const getRectsOrientation = (// @todo: Maybe we should check that at least one is reversed.// Need to test what works better, but keep an eye on false positives.- const allReverse = orientations.every((x) => !x || x.reverse !== false);+ const allReverse = orientations.every(+ (orientation) => orientation?.reverse !== false+ );- const types = orientations.map((x) => x && x.type);+ const types = orientations.map((orientation) => orientation?.type);const includesVertical = types.includes("vertical");const includesHorizontal = types.includes("horizontal");- if (includesVertical && !includesHorizontal) {+ if (includesVertical && includesHorizontal === false) {return { type: "vertical", reverse: allReverse };}- if (includesHorizontal && !includesVertical) {+ if (includesHorizontal && includesVertical === false) {return { type: "horizontal", reverse: allReverse };}diff --git a/packages/design-system/src/components/primitives/dnd/sortable-list.stories.tsx b/packages/design-system/src/components/primitives/dnd/sortable-list.stories.tsxindex 526c2baa6d..b1ad53dab9 100644--- a/packages/design-system/src/components/primitives/dnd/sortable-list.stories.tsx+++ b/packages/design-system/src/components/primitives/dnd/sortable-list.stories.tsx@@ -74,13 +74,15 @@ export const SortableList = ({return element instanceof HTMLUListElement;},swapDropTarget(dropTarget) {- if (!dropTarget) {- if (rootRef.current === null) {- throw new Error("should not happen");- }- return { data: true, element: rootRef.current };+ if (dropTarget) {+ return dropTarget;+ }++ if (rootRef.current === null) {+ throw new Error("should not happen");}- return dropTarget;++ return { data: true, element: rootRef.current };},onDropTargetChange(dropTarget) {setDropTarget(dropTarget);@@ -97,9 +99,9 @@ export const SortableList = ({setDragItemId(event.target.dataset.id);autoScrollHandlers.setEnabled(true);},- onMove: (poiterCoordinate) => {- useDropHandlers.handleMove(poiterCoordinate);- autoScrollHandlers.handleMove(poiterCoordinate);+ onMove: (point) => {+ useDropHandlers.handleMove(point);+ autoScrollHandlers.handleMove(point);},onEnd() {if (dropTarget !== undefined && dragItemId !== undefined) {diff --git a/packages/design-system/src/components/primitives/dnd/use-auto-scroll.ts b/packages/design-system/src/components/primitives/dnd/use-auto-scroll.tsindex e05d76df70..e325884871 100644--- a/packages/design-system/src/components/primitives/dnd/use-auto-scroll.ts+++ b/packages/design-system/src/components/primitives/dnd/use-auto-scroll.ts@@ -43,7 +43,7 @@ export type UseAutoScrollProps = {// If set to true the entire document will be scrolled.// No need to set targetRef in this case.- fullScreen?: boolean;+ fullscreen?: boolean;// min/max speed of the scroll animation in pixels per secondminSpeed?: number;@@ -76,7 +76,7 @@ export const useAutoScroll = (return useMemo(() => {const getViewportRect = () => {- if (latestProps.current.fullScreen) {+ if (latestProps.current.fullscreen) {return {top: 0,left: 0,@@ -93,7 +93,7 @@ export const useAutoScroll = (};const scrollBy = (x: number, y: number) => {- if (latestProps.current.fullScreen) {+ if (latestProps.current.fullscreen) {window.scrollBy(x, y);}diff --git a/packages/design-system/src/components/primitives/dnd/use-drop.ts b/packages/design-system/src/components/primitives/dnd/use-drop.tsindex 4cb3f2ef27..5480352cad 100644--- a/packages/design-system/src/components/primitives/dnd/use-drop.ts+++ b/packages/design-system/src/components/primitives/dnd/use-drop.ts@@ -132,7 +132,7 @@ export const useDrop = <Data>(props: UseDropProps<Data>): UseDropHandlers => {current === undefined ||current.element !== partialDropTarget.element ||current.indexWithinChildren !== indexWithinChildren ||- !isEqualRect(current.rect, parentRect)+ isEqualRect(current.rect, parentRect) === false) {const toGlobalCoordinates = (placement: Placement | undefined) =>placement && {@@ -213,7 +213,11 @@ export const useDrop = <Data>(props: UseDropProps<Data>): UseDropHandlers => {const isNewIsNearEdge =candidateIsNearEdge !== state.current.lastCandidateIsNearEdge;state.current.lastCandidateIsNearEdge = candidateIsNearEdge;- if (!isNewCandidate && !isNewIsNearEdge && state.current.dropTarget) {+ if (+ isNewCandidate === false &&+ isNewIsNearEdge === false &&+ state.current.dropTarget+ ) {// Still need to call setDropTarget to update rect and/or placement.// Because indexWithinChildren might have changed,// or parent coordinates might have moved in case of a scroll@@ -275,7 +279,7 @@ const findClosestDropTarget = <Data>({isDropTarget: (target: UsableElement) => Data | false;}): PartialDropTarget<Data> | undefined => {// The element we get from elementFromPoint() might not be inside the root- if (!initialElement || !root.contains(initialElement)) {+ if (initialElement === undefined || root.contains(initialElement) === false) {return undefined;}diff --git a/packages/design-system/src/components/primitives/dnd/use-move.ts b/packages/design-system/src/components/primitives/dnd/use-move.tsindex 393d73d562..1a7f2e0407 100644--- a/packages/design-system/src/components/primitives/dnd/use-move.ts+++ b/packages/design-system/src/components/primitives/dnd/use-move.ts@@ -159,30 +159,30 @@ export function useMove(props: MoveEvents): MoveResult {}};- let onPointerMove = (e: PointerEvent) => {+ let onPointerMove = (event: PointerEvent) => {if (- e.pointerId === state.current.id &&+ event.pointerId === state.current.id &&state.current.lastPosition !== null) {- let pointerType = (e.pointerType || "mouse") as PointerType;+ let pointerType = (event.pointerType || "mouse") as PointerType;// Problems with PointerEvent#movementX/movementY:// 1. it is always 0 on macOS Safari.// 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOSmove(- e,+ event,pointerType,- e.pageX - state.current.lastPosition.pageX,- e.pageY - state.current.lastPosition.pageY+ event.pageX - state.current.lastPosition.pageX,+ event.pageY - state.current.lastPosition.pageY);- state.current.lastPosition = { pageX: e.pageX, pageY: e.pageY };+ state.current.lastPosition = { pageX: event.pageX, pageY: event.pageY };}};- let onPointerUp = (e: PointerEvent) => {- if (e.pointerId === state.current.id) {- let pointerType = (e.pointerType || "mouse") as PointerType;- end(e, pointerType);+ let onPointerUp = (event: PointerEvent) => {+ if (event.pointerId === state.current.id) {+ let pointerType = (event.pointerType || "mouse") as PointerType;+ end(event, pointerType);state.current.id = null;removeGlobalListener(window, "pointermove", onPointerMove, false);removeGlobalListener(window, "pointerup", onPointerUp, false);@@ -191,17 +191,20 @@ export function useMove(props: MoveEvents): MoveResult {};return {- onPointerDown: (e: PointerEvent) => {+ onPointerDown: (event: PointerEvent) => {if (- e.button === 0 &&+ event.button === 0 &&state.current.id == null &&- latestProps.current.shouldStart(e)+ latestProps.current.shouldStart(event)) {start();- e.stopPropagation();- e.preventDefault();- state.current.lastPosition = { pageX: e.pageX, pageY: e.pageY };- state.current.id = e.pointerId;+ event.stopPropagation();+ event.preventDefault();+ state.current.lastPosition = {+ pageX: event.pageX,+ pageY: event.pageY,+ };+ state.current.id = event.pointerId;addGlobalListener(window, "pointermove", onPointerMove, false);addGlobalListener(window, "pointerup", onPointerUp, false);addGlobalListener(window, "pointercancel", onPointerUp, false);diff --git a/packages/react-sdk/jest.config.js b/packages/react-sdk/jest.config.jsindex 9eae0843c6..4eeecbaf4e 100644--- a/packages/react-sdk/jest.config.js+++ b/packages/react-sdk/jest.config.js@@ -1,6 +1 @@-// eslint-disable-next-line-const base = require("@webstudio-is/jest-config");--module.exports = {- ...base,-};+module.exports = require("@webstudio-is/jest-config");