Просмотр исходного кода

move the files to src and tests folders under utils

Aakansha Doshi 1 год назад
Родитель
Сommit
58567dd2b6

+ 1 - 1
packages/excalidraw/tests/scene/export.test.ts

@@ -6,7 +6,7 @@ import {
   rectangleWithLinkFixture,
 } from "../fixtures/elementFixture";
 import { API } from "../helpers/api";
-import { exportToCanvas, exportToSvg } from "../../../utils/export";
+import { exportToCanvas, exportToSvg } from "../../../utils/src/export";
 import { FRAME_STYLE } from "../../constants";
 import { prepareElementsForExport } from "../../data";
 

+ 6 - 6
packages/utils/index.ts

@@ -1,6 +1,6 @@
-export * from "./export";
-export * from "./withinBounds";
-export * from "./bbox";
-export * from "./collision";
-export * from "./geometry/shape";
-export * from "./geometry/geometry";
+export * from "./src/export";
+export * from "./src/withinBounds";
+export * from "./src/bbox";
+export * from "./src/collision";
+export * from "./src/geometry/shape";
+export * from "./src/geometry/geometry";

+ 2 - 0
packages/utils/package.json

@@ -64,6 +64,7 @@
     "@babel/preset-typescript": "7.18.6",
     "babel-loader": "8.2.5",
     "babel-plugin-transform-class-properties": "6.24.1",
+    "chokidar": "3.6.0",
     "cross-env": "7.0.3",
     "css-loader": "6.7.1",
     "file-loader": "6.2.0",
@@ -79,6 +80,7 @@
   "scripts": {
     "gen:types": "rm -rf types && tsc",
     "build:umd": "cross-env NODE_ENV=production webpack --config webpack.prod.config.js",
+    "build:src": "rm -rf dist && node ../../scripts/buildUtils.js",
     "build:esm": "rm -rf dist && node ../../scripts/buildUtils.js && yarn gen:types",
     "build:umd:withAnalyzer": "cross-env NODE_ENV=production ANALYZER=true webpack --config webpack.prod.config.js",
     "clear": "rm -rf dist",

+ 3 - 2
packages/utils/bbox.ts → packages/utils/src/bbox.ts

@@ -1,5 +1,5 @@
-import type { Bounds } from "../excalidraw/element/bounds";
-import type { Point } from "../excalidraw/types";
+import type { Bounds } from "../../excalidraw/element/bounds";
+import type { Point } from "../../excalidraw/types";
 
 export type LineSegment = [Point, Point];
 
@@ -17,6 +17,7 @@ export function crossProduct(a: Point, b: Point) {
 }
 
 export function doBBoxesIntersect(a: Bounds, b: Bounds) {
+  console.log("HI");
   return a[0] <= b[2] && a[2] >= b[0] && a[1] <= b[3] && a[3] >= b[1];
 }
 

+ 0 - 0
packages/utils/collision.ts → packages/utils/src/collision.ts


+ 10 - 10
packages/utils/export.ts → packages/utils/src/export.ts

@@ -1,23 +1,23 @@
 import {
   exportToCanvas as _exportToCanvas,
   exportToSvg as _exportToSvg,
-} from "../excalidraw/scene/export";
-import { getDefaultAppState } from "../excalidraw/appState";
-import type { AppState, BinaryFiles } from "../excalidraw/types";
+} from "../../excalidraw/scene/export";
+import { getDefaultAppState } from "../../excalidraw/appState";
+import type { AppState, BinaryFiles } from "../../excalidraw/types";
 import type {
   ExcalidrawElement,
   ExcalidrawFrameLikeElement,
   NonDeleted,
-} from "../excalidraw/element/types";
-import { restore } from "../excalidraw/data/restore";
-import { MIME_TYPES } from "../excalidraw/constants";
-import { encodePngMetadata } from "../excalidraw/data/image";
-import { serializeAsJSON } from "../excalidraw/data/json";
+} from "../../excalidraw/element/types";
+import { restore } from "../../excalidraw/data/restore";
+import { MIME_TYPES } from "../../excalidraw/constants";
+import { encodePngMetadata } from "../../excalidraw/data/image";
+import { serializeAsJSON } from "../../excalidraw/data/json";
 import {
   copyBlobToClipboardAsPng,
   copyTextToSystemClipboard,
   copyToClipboard,
-} from "../excalidraw/clipboard";
+} from "../../excalidraw/clipboard";
 
 export { MIME_TYPES };
 
@@ -170,7 +170,7 @@ export const exportToSvg = async ({
   exportPadding?: number;
   renderEmbeddables?: boolean;
 }): Promise<SVGSVGElement> => {
-  console.info("HIIII FROM UTILS WORKSPACE");
+  console.info("Watching exportToSVG :)");
 
   const { elements: restoredElements, appState: restoredAppState } = restore(
     { elements, appState },

+ 1 - 1
packages/utils/geometry/geometry.ts → packages/utils/src/geometry/geometry.ts

@@ -1,4 +1,4 @@
-import { distance2d } from "../../excalidraw/math";
+import { distance2d } from "../../../excalidraw/math";
 import type {
   Point,
   Line,

+ 2 - 2
packages/utils/geometry/shape.ts → packages/utils/src/geometry/shape.ts

@@ -12,7 +12,7 @@
  * to pure shapes
  */
 
-import { getElementAbsoluteCoords } from "../../excalidraw/element";
+import { getElementAbsoluteCoords } from "../../../excalidraw/element";
 import type {
   ElementsMap,
   ExcalidrawDiamondElement,
@@ -27,7 +27,7 @@ import type {
   ExcalidrawRectangleElement,
   ExcalidrawSelectionElement,
   ExcalidrawTextElement,
-} from "../../excalidraw/element/types";
+} from "../../../excalidraw/element/types";
 import { angleToDegrees, close, pointAdd, pointRotate } from "./geometry";
 import { pointsOnBezierCurves } from "points-on-curve";
 import type { Drawable, Op } from "roughjs/bin/core";

+ 7 - 7
packages/utils/withinBounds.ts → packages/utils/src/withinBounds.ts

@@ -3,19 +3,19 @@ import type {
   ExcalidrawFreeDrawElement,
   ExcalidrawLinearElement,
   NonDeletedExcalidrawElement,
-} from "../excalidraw/element/types";
+} from "../../excalidraw/element/types";
 import {
   isArrowElement,
   isExcalidrawElement,
   isFreeDrawElement,
   isLinearElement,
   isTextElement,
-} from "../excalidraw/element/typeChecks";
-import { isValueInRange, rotatePoint } from "../excalidraw/math";
-import type { Point } from "../excalidraw/types";
-import type { Bounds } from "../excalidraw/element/bounds";
-import { getElementBounds } from "../excalidraw/element/bounds";
-import { arrayToMap } from "../excalidraw/utils";
+} from "../../excalidraw/element/typeChecks";
+import { isValueInRange, rotatePoint } from "../../excalidraw/math";
+import type { Point } from "../../excalidraw/types";
+import type { Bounds } from "../../excalidraw/element/bounds";
+import { getElementBounds } from "../../excalidraw/element/bounds";
+import { arrayToMap } from "../../excalidraw/utils";
 
 type Element = NonDeletedExcalidrawElement;
 type Elements = readonly NonDeletedExcalidrawElement[];

+ 4 - 4
packages/utils/export.test.ts → packages/utils/tests/export.test.ts

@@ -1,9 +1,9 @@
-import * as utils from "./export";
-import { diagramFactory } from "../excalidraw/tests/fixtures/diagramFixture";
+import * as utils from "../src/export";
+import { diagramFactory } from "../../excalidraw/tests/fixtures/diagramFixture";
 import { vi } from "vitest";
-import * as mockedSceneExportUtils from "../excalidraw/scene/export";
+import * as mockedSceneExportUtils from "../../excalidraw/scene/export";
 
-import { MIME_TYPES } from "../excalidraw/constants";
+import { MIME_TYPES } from "../../excalidraw/constants";
 
 const exportToSvgSpy = vi.spyOn(mockedSceneExportUtils, "exportToSvg");
 

+ 9 - 2
packages/utils/geometry/geometry.test.ts → packages/utils/tests/geometry.test.ts

@@ -11,8 +11,15 @@ import {
   pointOnPolyline,
   pointRightofLine,
   pointRotate,
-} from "./geometry";
-import type { Curve, Ellipse, Line, Point, Polygon, Polyline } from "./shape";
+} from "../src/geometry/geometry";
+import type {
+  Curve,
+  Ellipse,
+  Line,
+  Point,
+  Polygon,
+  Polyline,
+} from "../src/geometry/shape";
 
 describe("point and line", () => {
   const line: Line = [

+ 7 - 4
packages/utils/utils.unmocked.test.ts → packages/utils/tests/utils.unmocked.test.ts

@@ -1,7 +1,10 @@
-import { decodePngMetadata, decodeSvgMetadata } from "../excalidraw/data/image";
-import type { ImportedDataState } from "../excalidraw/data/types";
-import * as utils from "../utils";
-import { API } from "../excalidraw/tests/helpers/api";
+import {
+  decodePngMetadata,
+  decodeSvgMetadata,
+} from "../../excalidraw/data/image";
+import type { ImportedDataState } from "../../excalidraw/data/types";
+import * as utils from "../dist/prod";
+import { API } from "../../excalidraw/tests/helpers/api";
 
 // NOTE this test file is using the actual API, unmocked. Hence splitting it
 // from the other test file, because I couldn't figure out how to test

+ 3 - 3
packages/utils/withinBounds.test.ts → packages/utils/tests/withinBounds.test.ts

@@ -1,10 +1,10 @@
-import type { Bounds } from "../excalidraw/element/bounds";
-import { API } from "../excalidraw/tests/helpers/api";
+import type { Bounds } from "../../excalidraw/element/bounds";
+import { API } from "../../excalidraw/tests/helpers/api";
 import {
   elementPartiallyOverlapsWithOrContainsBBox,
   elementsOverlappingBBox,
   isElementInsideBBox,
-} from "./withinBounds";
+} from "../src/withinBounds";
 
 const makeElement = (x: number, y: number, width: number, height: number) =>
   API.createElement({