diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index c5ccdfd6e..000000000 --- a/.eslintrc +++ /dev/null @@ -1,111 +0,0 @@ -{ - "parser": "@typescript-eslint/parser", - "parserOptions": { - "project": "./tsconfig.json" - }, - "plugins": [ - "react-perf", - "css-modules", - "jest", - "jsx-a11y", - "react", - "react-hooks", - "suggest-no-throw", - "testing-library", - "@typescript-eslint" - ], - "extends": [ - "plugin:css-modules/recommended", - "plugin:jsx-a11y/recommended", - "plugin:react-hooks/recommended" - ], - "rules": { - "no-array-constructor": "off", // This is wrong; use the @typescript-eslint one instead. - "@typescript-eslint/no-array-constructor": "error", - "@typescript-eslint/no-array-delete": "error", - "@typescript-eslint/no-duplicate-enum-values": "error", - "@typescript-eslint/no-duplicate-type-constituents": "error", - "@typescript-eslint/no-empty-object-type": "error", - "@typescript-eslint/no-extra-non-null-assertion": "error", - "@typescript-eslint/no-floating-promises": "error", - "@typescript-eslint/no-for-in-array": "error", - "no-implied-eval": "off", // This is wrong; use the @typescript-eslint one instead. - "@typescript-eslint/no-implied-eval": "error", - "@typescript-eslint/no-misused-new": "error", - "@typescript-eslint/no-misused-promises": "error", - "@typescript-eslint/no-namespace": "error", - "@typescript-eslint/no-non-null-asserted-optional-chain": "error", - "@typescript-eslint/no-redundant-type-constituents": "error", - "@typescript-eslint/no-this-alias": "warn", - "@typescript-eslint/no-unnecessary-type-assertion": "error", - "@typescript-eslint/no-unnecessary-type-constraint": "error", - "no-unused-vars": "off", // This is wrong; use the @typescript-eslint one instead. - "@typescript-eslint/no-unused-vars": ["error", { - "varsIgnorePattern": "^_", - "argsIgnorePattern": "^_", - "ignoreRestSiblings": true, - "vars": "all", - "args": "none" - }], - "@typescript-eslint/no-unsafe-unary-minus": "error", - "@typescript-eslint/no-wrapper-object-types": "error", - "no-throw-literal": "off", // Use @typescript-eslint/only-throw-error instead. - "@typescript-eslint/only-throw-error": "error", - "@typescript-eslint/prefer-as-const": "warn", - "@typescript-eslint/prefer-namespace-keyword": "error", - "@typescript-eslint/restrict-plus-operands": "error", - "jsx-a11y/click-events-have-key-events": "off", - "jsx-a11y/no-autofocus": "off", - "jsx-a11y/no-noninteractive-element-interactions": "off", - "no-restricted-globals": [ - "error", - { - "name": "isNaN", - "message": "Use Number.isNaN() instead." - } - ], - "no-restricted-syntax": [ - "error", - { - "selector": "CallExpression[callee.object.name='Array'][callee.property.name='isArray']", - "message": "Use isArray() in lib/utils.ts instead of Array.isArray()." - }, - { - "selector": "CallExpression[callee.object.name='TOML'][callee.property.name='stringify']", - "message": "Do not use TOML.stringify directly. Use the wrappers in test-utils instead like settingsToToml." - }, - { - "selector": "CallExpression[callee.object.name='TOML'][callee.property.name='parse']", - "message": "Do not use TOML.parse directly. Use the wrappers in test-utils instead like tomlToSettings." - } - ], - "semi": [ - "error", - "never" - ], - "react-hooks/exhaustive-deps": "off", - "suggest-no-throw/suggest-no-throw": "error" - }, - "overrides": [ - { - "files": ["e2e/**/*.ts"], // Update the pattern based on your file structure - "extends": [ - "plugin:testing-library/react" - ], - "rules": { - "suggest-no-throw/suggest-no-throw": "off", - "testing-library/prefer-screen-queries": "off", - "jest/valid-expect": "off" - } - }, - { - "files": ["src/**/*.test.ts"], - "extends": [ - "plugin:testing-library/react" - ], - "rules": { - "suggest-no-throw/suggest-no-throw": "off" - } - } - ] -} diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 000000000..e60b0800e --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,127 @@ +{ + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "./tsconfig.json" + }, + "plugins": [ + "react-perf", + "css-modules", + "jest", + "jsx-a11y", + "react", + "react-hooks", + "suggest-no-throw", + "testing-library", + "@typescript-eslint" + ], + "extends": [ + "plugin:css-modules/recommended", + "plugin:jsx-a11y/recommended", + "plugin:react-hooks/recommended" + ], + "rules": { + "no-array-constructor": "off", // This is wrong; use the @typescript-eslint one instead. + "@typescript-eslint/no-array-constructor": "error", + "@typescript-eslint/no-array-delete": "error", + "@typescript-eslint/no-duplicate-enum-values": "error", + "@typescript-eslint/no-duplicate-type-constituents": "error", + "@typescript-eslint/no-empty-object-type": "error", + "@typescript-eslint/no-extra-non-null-assertion": "error", + "@typescript-eslint/no-floating-promises": "error", + "@typescript-eslint/no-for-in-array": "error", + "no-implied-eval": "off", // This is wrong; use the @typescript-eslint one instead. + "@typescript-eslint/no-implied-eval": "error", + "@typescript-eslint/no-misused-new": "error", + "@typescript-eslint/no-misused-promises": "error", + "@typescript-eslint/no-namespace": "error", + "@typescript-eslint/no-non-null-asserted-optional-chain": "error", + "@typescript-eslint/no-redundant-type-constituents": "error", + "@typescript-eslint/no-this-alias": "warn", + "@typescript-eslint/no-unnecessary-type-assertion": "error", + "@typescript-eslint/no-unnecessary-type-constraint": "error", + "no-unused-vars": "off", // This is wrong; use the @typescript-eslint one instead. + "@typescript-eslint/no-unused-vars": [ + "error", + { + "varsIgnorePattern": "^_", + "argsIgnorePattern": "^_", + "ignoreRestSiblings": true, + "vars": "all", + "args": "none" + } + ], + "@typescript-eslint/no-unsafe-unary-minus": "error", + "@typescript-eslint/no-wrapper-object-types": "error", + "no-throw-literal": "off", // Use @typescript-eslint/only-throw-error instead. + "@typescript-eslint/only-throw-error": "error", + "@typescript-eslint/prefer-as-const": "warn", + "@typescript-eslint/prefer-namespace-keyword": "error", + "@typescript-eslint/consistent-type-imports": "error", + "@typescript-eslint/restrict-plus-operands": "error", + "jsx-a11y/click-events-have-key-events": "off", + "jsx-a11y/no-autofocus": "off", + "jsx-a11y/no-noninteractive-element-interactions": "off", + "no-restricted-globals": [ + "error", + { + "name": "isNaN", + "message": "Use Number.isNaN() instead." + } + ], + "no-restricted-syntax": [ + "error", + { + "selector": "CallExpression[callee.object.name='Array'][callee.property.name='isArray']", + "message": "Use isArray() in lib/utils.ts instead of Array.isArray()." + }, + { + "selector": "CallExpression[callee.object.name='TOML'][callee.property.name='stringify']", + "message": "Do not use TOML.stringify directly. Use the wrappers in test-utils instead like settingsToToml." + }, + { + "selector": "CallExpression[callee.object.name='TOML'][callee.property.name='parse']", + "message": "Do not use TOML.parse directly. Use the wrappers in test-utils instead like tomlToSettings." + } + ], + "no-restricted-imports": [ + "error", + { + "patterns": [ + // Restrict all relative imports except for .css files. + { + "group": ["./*", "../*", "!./*.css", "!../*.css"], + "message": "Use absolute imports instead." + } + ] + } + ], + "semi": ["error", "never"], + "react-hooks/exhaustive-deps": "off", + "suggest-no-throw/suggest-no-throw": "error" + }, + "overrides": [ + { + "files": ["e2e/**/*.ts"], // Update the pattern based on your file structure + "extends": ["plugin:testing-library/react"], + "rules": { + "suggest-no-throw/suggest-no-throw": "off", + "testing-library/prefer-screen-queries": "off", + "jest/valid-expect": "off" + } + }, + { + "files": ["src/**/*.test.ts"], + "extends": ["plugin:testing-library/react"], + "rules": { + "suggest-no-throw/suggest-no-throw": "off" + } + }, + { + "files": ["packages/**/*.ts", "rust/**/*.ts"], + "extends": [], + "rules": { + "no-restricted-imports": "off" + } + } + ] +} diff --git a/e2e/playwright/app-header-tests.spec.ts b/e2e/playwright/app-header-tests.spec.ts index c663c83a8..4ec2a4ff1 100644 --- a/e2e/playwright/app-header-tests.spec.ts +++ b/e2e/playwright/app-header-tests.spec.ts @@ -1,4 +1,4 @@ -import { test, expect } from './zoo-test' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Electron app header tests', () => { test( diff --git a/e2e/playwright/basic-sketch.spec.ts b/e2e/playwright/basic-sketch.spec.ts index 3cb1e78fb..adf2270bf 100644 --- a/e2e/playwright/basic-sketch.spec.ts +++ b/e2e/playwright/basic-sketch.spec.ts @@ -1,13 +1,14 @@ -import { Page } from '@playwright/test' -import { test, expect } from './zoo-test' +import type { Page } from '@playwright/test' + +import type { HomePageFixture } from '@e2e/playwright/fixtures/homePageFixture' import { - getUtils, + PERSIST_MODELING_CONTEXT, TEST_COLORS, commonPoints, - PERSIST_MODELING_CONTEXT, + getUtils, orRunWhenFullSuiteEnabled, -} from './test-utils' -import { HomePageFixture } from './fixtures/homePageFixture' +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.setTimeout(120000) diff --git a/e2e/playwright/boolean.spec.ts b/e2e/playwright/boolean.spec.ts index 67127ef68..d8b5f62ad 100644 --- a/e2e/playwright/boolean.spec.ts +++ b/e2e/playwright/boolean.spec.ts @@ -1,7 +1,8 @@ -import { test, expect } from './zoo-test' import fs from 'node:fs/promises' import path from 'node:path' +import { expect, test } from '@e2e/playwright/zoo-test' + test.describe('Point and click for boolean workflows', () => { // Boolean operations to test const booleanOperations = [ diff --git a/e2e/playwright/can-create-sketches-on-all-planes-and-their-back-sides.spec.ts b/e2e/playwright/can-create-sketches-on-all-planes-and-their-back-sides.spec.ts index b8e1b9ff0..e317701a2 100644 --- a/e2e/playwright/can-create-sketches-on-all-planes-and-their-back-sides.spec.ts +++ b/e2e/playwright/can-create-sketches-on-all-planes-and-their-back-sides.spec.ts @@ -1,10 +1,11 @@ -import { Page } from '@playwright/test' -import { test, expect } from './zoo-test' -import { HomePageFixture } from './fixtures/homePageFixture' -import { getUtils } from './test-utils' -import { EngineCommand } from 'lang/std/artifactGraph' -import { uuidv4 } from 'lib/utils' -import { SceneFixture } from './fixtures/sceneFixture' +import type { Page } from '@playwright/test' +import type { EngineCommand } from '@src/lang/std/artifactGraph' +import { uuidv4 } from '@src/lib/utils' + +import type { HomePageFixture } from '@e2e/playwright/fixtures/homePageFixture' +import type { SceneFixture } from '@e2e/playwright/fixtures/sceneFixture' +import { getUtils } from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe( 'Can create sketches on all planes and their back sides', diff --git a/e2e/playwright/code-pane-and-errors.spec.ts b/e2e/playwright/code-pane-and-errors.spec.ts index 1908ab38d..89ca3e48f 100644 --- a/e2e/playwright/code-pane-and-errors.spec.ts +++ b/e2e/playwright/code-pane-and-errors.spec.ts @@ -1,13 +1,14 @@ -import { test, expect } from './zoo-test' -import { - orRunWhenFullSuiteEnabled, - getUtils, - executorInputPath, -} from './test-utils' -import { join } from 'path' -import { bracket } from 'lib/exampleKcl' -import { TEST_CODE_LONG_WITH_ERROR_OUT_OF_VIEW } from './storageStates' +import { bracket } from '@src/lib/exampleKcl' import fsp from 'fs/promises' +import { join } from 'path' + +import { TEST_CODE_LONG_WITH_ERROR_OUT_OF_VIEW } from '@e2e/playwright/storageStates' +import { + executorInputPath, + getUtils, + orRunWhenFullSuiteEnabled, +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Code pane and errors', { tag: ['@skipWin'] }, () => { test('Typing KCL errors induces a badge on the code pane button', async ({ diff --git a/e2e/playwright/command-bar-tests.spec.ts b/e2e/playwright/command-bar-tests.spec.ts index a162a70b7..69a767e62 100644 --- a/e2e/playwright/command-bar-tests.spec.ts +++ b/e2e/playwright/command-bar-tests.spec.ts @@ -1,12 +1,13 @@ -import { test, expect } from './zoo-test' +import { KCL_DEFAULT_LENGTH } from '@src/lib/constants' import * as fsp from 'fs/promises' +import path, { join } from 'path' + import { executorInputPath, getUtils, orRunWhenFullSuiteEnabled, -} from './test-utils' -import { KCL_DEFAULT_LENGTH } from 'lib/constants' -import path, { join } from 'path' +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Command bar tests', { tag: ['@skipWin'] }, () => { test('Extrude from command bar selects extrude line after', async ({ diff --git a/e2e/playwright/copilot-ghost-test.spec.ts b/e2e/playwright/copilot-ghost-test.spec.ts index c7f552258..c507176d4 100644 --- a/e2e/playwright/copilot-ghost-test.spec.ts +++ b/e2e/playwright/copilot-ghost-test.spec.ts @@ -1,5 +1,5 @@ -import { test, expect } from './zoo-test' -import { getUtils } from './test-utils' +import { getUtils } from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Copilot ghost text', () => { // eslint-disable-next-line jest/valid-title diff --git a/e2e/playwright/debug-pane.spec.ts b/e2e/playwright/debug-pane.spec.ts index 59ff83605..81514761f 100644 --- a/e2e/playwright/debug-pane.spec.ts +++ b/e2e/playwright/debug-pane.spec.ts @@ -1,6 +1,5 @@ -import { test, expect } from './zoo-test' - -import { getUtils } from './test-utils' +import { getUtils } from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' function countNewlines(input: string): number { let count = 0 diff --git a/e2e/playwright/desktop-export.spec.ts b/e2e/playwright/desktop-export.spec.ts index c4d32ccd1..f491d5d6a 100644 --- a/e2e/playwright/desktop-export.spec.ts +++ b/e2e/playwright/desktop-export.spec.ts @@ -1,11 +1,12 @@ -import { test, expect } from './zoo-test' +import fsp from 'fs/promises' import path from 'path' + import { - getUtils, executorInputPath, getPlaywrightDownloadDir, -} from './test-utils' -import fsp from 'fs/promises' + getUtils, +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test( 'export works on the first try', diff --git a/e2e/playwright/editor-tests.spec.ts b/e2e/playwright/editor-tests.spec.ts index 739236857..02801d296 100644 --- a/e2e/playwright/editor-tests.spec.ts +++ b/e2e/playwright/editor-tests.spec.ts @@ -1,14 +1,14 @@ -import { test, expect } from './zoo-test' +import { uuidv4 } from '@src/lib/utils' import fsp from 'fs/promises' -import { uuidv4 } from 'lib/utils' +import { join } from 'path' + import { + TEST_COLORS, executorInputPath, getUtils, orRunWhenFullSuiteEnabled, - TEST_COLORS, -} from './test-utils' - -import { join } from 'path' +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Editor tests', { tag: ['@skipWin'] }, () => { test('can comment out code with ctrl+/', async ({ page, homePage }) => { diff --git a/e2e/playwright/feature-tree-pane.spec.ts b/e2e/playwright/feature-tree-pane.spec.ts index 54e4ed0b6..beb5fe6c6 100644 --- a/e2e/playwright/feature-tree-pane.spec.ts +++ b/e2e/playwright/feature-tree-pane.spec.ts @@ -1,7 +1,8 @@ -import { test, expect } from './zoo-test' import * as fsp from 'fs/promises' import { join } from 'path' +import { expect, test } from '@e2e/playwright/zoo-test' + const FEATURE_TREE_EXAMPLE_CODE = `export fn timesFive(x) { return 5 * x } diff --git a/e2e/playwright/file-tree.spec.ts b/e2e/playwright/file-tree.spec.ts index 88ed2d403..422754f26 100644 --- a/e2e/playwright/file-tree.spec.ts +++ b/e2e/playwright/file-tree.spec.ts @@ -1,15 +1,16 @@ -import { test, expect } from './zoo-test' -import * as fsp from 'fs/promises' +import { FILE_EXT } from '@src/lib/constants' import * as fs from 'fs' +import * as fsp from 'fs/promises' +import { join } from 'path' + import { createProject, executorInputPath, getUtils, orRunWhenFullSuiteEnabled, runningOnWindows, -} from './test-utils' -import { join } from 'path' -import { FILE_EXT } from 'lib/constants' +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('integrations tests', () => { test( diff --git a/e2e/playwright/fixtures/cmdBarFixture.ts b/e2e/playwright/fixtures/cmdBarFixture.ts index 18800ef9e..e73194eba 100644 --- a/e2e/playwright/fixtures/cmdBarFixture.ts +++ b/e2e/playwright/fixtures/cmdBarFixture.ts @@ -1,5 +1,5 @@ -import type { Page, Locator, Route, Request } from '@playwright/test' -import { expect, TestInfo } from '@playwright/test' +import type { Locator, Page, Request, Route, TestInfo } from '@playwright/test' +import { expect } from '@playwright/test' import * as fs from 'fs' import * as path from 'path' diff --git a/e2e/playwright/fixtures/editorFixture.ts b/e2e/playwright/fixtures/editorFixture.ts index 3304a8a66..266a30137 100644 --- a/e2e/playwright/fixtures/editorFixture.ts +++ b/e2e/playwright/fixtures/editorFixture.ts @@ -1,11 +1,12 @@ -import type { Page, Locator } from '@playwright/test' +import type { Locator, Page } from '@playwright/test' import { expect } from '@playwright/test' + import { - closePane, checkIfPaneIsOpen, + closePane, openPane, sansWhitespace, -} from '../test-utils' +} from '@e2e/playwright/test-utils' interface EditorState { activeLines: Array diff --git a/e2e/playwright/fixtures/fixtureSetup.ts b/e2e/playwright/fixtures/fixtureSetup.ts index 93edc2ccf..1c370bae7 100644 --- a/e2e/playwright/fixtures/fixtureSetup.ts +++ b/e2e/playwright/fixtures/fixtureSetup.ts @@ -2,25 +2,27 @@ import type { BrowserContext, ElectronApplication, - TestInfo, Page, + TestInfo, } from '@playwright/test' - import { _electron as electron } from '@playwright/test' -import { TEST_SETTINGS } from '../storageStates' -import { SETTINGS_FILE_NAME } from 'lib/constants' -import { getUtils, setup, settingsToToml } from '../test-utils' +import { SETTINGS_FILE_NAME } from '@src/lib/constants' +import type { DeepPartial } from '@src/lib/types' import fsp from 'fs/promises' import fs from 'node:fs' import path from 'path' -import { CmdBarFixture } from './cmdBarFixture' -import { EditorFixture } from './editorFixture' -import { ToolbarFixture } from './toolbarFixture' -import { SceneFixture } from './sceneFixture' -import { HomePageFixture } from './homePageFixture' -import { DeepPartial } from 'lib/types' -import { Settings } from '@rust/kcl-lib/bindings/Settings' + +import type { Settings } from '@rust/kcl-lib/bindings/Settings' + +import { CmdBarFixture } from '@e2e/playwright/fixtures/cmdBarFixture' +import { EditorFixture } from '@e2e/playwright/fixtures/editorFixture' +import { HomePageFixture } from '@e2e/playwright/fixtures/homePageFixture' +import { SceneFixture } from '@e2e/playwright/fixtures/sceneFixture' +import { ToolbarFixture } from '@e2e/playwright/fixtures/toolbarFixture' + +import { TEST_SETTINGS } from '@e2e/playwright/storageStates' +import { getUtils, settingsToToml, setup } from '@e2e/playwright/test-utils' export class AuthenticatedApp { public readonly page: Page diff --git a/e2e/playwright/fixtures/homePageFixture.ts b/e2e/playwright/fixtures/homePageFixture.ts index e6caf43a8..891c66a84 100644 --- a/e2e/playwright/fixtures/homePageFixture.ts +++ b/e2e/playwright/fixtures/homePageFixture.ts @@ -1,4 +1,4 @@ -import type { Page, Locator } from '@playwright/test' +import type { Locator, Page } from '@playwright/test' import { expect } from '@playwright/test' interface ProjectCardState { diff --git a/e2e/playwright/fixtures/sceneFixture.ts b/e2e/playwright/fixtures/sceneFixture.ts index b47538345..a1b9c891e 100644 --- a/e2e/playwright/fixtures/sceneFixture.ts +++ b/e2e/playwright/fixtures/sceneFixture.ts @@ -1,15 +1,17 @@ -import type { Page, Locator } from '@playwright/test' -import { expect } from '../zoo-test' -import { isArray, uuidv4 } from 'lib/utils' -import { CmdBarFixture } from './cmdBarFixture' +import type { Locator, Page } from '@playwright/test' +import { isArray, uuidv4 } from '@src/lib/utils' + +import type { CmdBarFixture } from '@e2e/playwright/fixtures/cmdBarFixture' + import { closeDebugPanel, doAndWaitForImageDiff, getPixelRGBs, + getUtils, openAndClearDebugPanel, sendCustomCmd, - getUtils, -} from '../test-utils' +} from '@e2e/playwright/test-utils' +import { expect } from '@e2e/playwright/zoo-test' type MouseParams = { pixelDiff?: number diff --git a/e2e/playwright/fixtures/toolbarFixture.ts b/e2e/playwright/fixtures/toolbarFixture.ts index 09dd54d96..29eef26cb 100644 --- a/e2e/playwright/fixtures/toolbarFixture.ts +++ b/e2e/playwright/fixtures/toolbarFixture.ts @@ -1,14 +1,15 @@ -import { type Page, type Locator, test } from '@playwright/test' -import { expect } from '../zoo-test' +import { type Locator, type Page, test } from '@playwright/test' +import type { SidebarType } from '@src/components/ModelingSidebar/ModelingPanes' +import { SIDEBAR_BUTTON_SUFFIX } from '@src/lib/constants' +import type { ToolbarModeName } from '@src/lib/toolbar' + import { checkIfPaneIsOpen, closePane, doAndWaitForImageDiff, openPane, -} from '../test-utils' -import { SidebarType } from 'components/ModelingSidebar/ModelingPanes' -import { SIDEBAR_BUTTON_SUFFIX } from 'lib/constants' -import { ToolbarModeName } from 'lib/toolbar' +} from '@e2e/playwright/test-utils' +import { expect } from '@e2e/playwright/zoo-test' export class ToolbarFixture { public page: Page diff --git a/e2e/playwright/machines.spec.ts b/e2e/playwright/machines.spec.ts index 113f59ffc..9f4c3cc4d 100644 --- a/e2e/playwright/machines.spec.ts +++ b/e2e/playwright/machines.spec.ts @@ -1,7 +1,8 @@ -import { test, expect } from './zoo-test' -import { executorInputPath } from './test-utils' -import { join } from 'path' import fsp from 'fs/promises' +import { join } from 'path' + +import { executorInputPath } from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test( 'When machine-api server not found butt is disabled and shows the reason', diff --git a/e2e/playwright/named-views.spec.ts b/e2e/playwright/named-views.spec.ts index c24ea6de9..3eca7adbd 100644 --- a/e2e/playwright/named-views.spec.ts +++ b/e2e/playwright/named-views.spec.ts @@ -1,13 +1,15 @@ -import { test, expect } from './zoo-test' -import { PROJECT_SETTINGS_FILE_NAME } from 'lib/constants' +import { PROJECT_SETTINGS_FILE_NAME } from '@src/lib/constants' import * as fsp from 'fs/promises' import { join } from 'path' + +import type { NamedView } from '@rust/kcl-lib/bindings/NamedView' + import { createProject, - tomlToPerProjectSettings, perProjectsettingsToToml, -} from './test-utils' -import { NamedView } from '@rust/kcl-lib/bindings/NamedView' + tomlToPerProjectSettings, +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' // Helper function to determine if the file path on disk exists // Specifically this is used to check if project.toml exists on disk diff --git a/e2e/playwright/native-file-menu.spec.ts b/e2e/playwright/native-file-menu.spec.ts index 822ecd3df..affb8d6ae 100644 --- a/e2e/playwright/native-file-menu.spec.ts +++ b/e2e/playwright/native-file-menu.spec.ts @@ -1,4 +1,4 @@ -import { test, expect } from './zoo-test' +import { expect, test } from '@e2e/playwright/zoo-test' /** * Not all menu actions are tested. Some are default electron menu actions. diff --git a/e2e/playwright/null.spec.ts b/e2e/playwright/null.spec.ts index dcb213a9f..3e05f7a3b 100644 --- a/e2e/playwright/null.spec.ts +++ b/e2e/playwright/null.spec.ts @@ -2,8 +2,7 @@ // application, check it can make it to the project pane, and nothing more. // It also tests our test wrappers are working. // Additionally this serves as a nice minimal example. - -import { test, expect } from './zoo-test' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Open the application', () => { test('see the project view', async ({ page, context }) => { diff --git a/e2e/playwright/onboarding-tests.spec.ts b/e2e/playwright/onboarding-tests.spec.ts index 4ecac34e3..05944297b 100644 --- a/e2e/playwright/onboarding-tests.spec.ts +++ b/e2e/playwright/onboarding-tests.spec.ts @@ -1,22 +1,23 @@ -import { test, expect } from './zoo-test' -import { join } from 'path' +import { bracket } from '@src/lib/exampleKcl' +import { onboardingPaths } from '@src/routes/Onboarding/paths' import fsp from 'fs/promises' -import { - getUtils, - executorInputPath, - createProject, - settingsToToml, - orRunWhenFullSuiteEnabled, -} from './test-utils' -import { bracket } from 'lib/exampleKcl' -import { onboardingPaths } from 'routes/Onboarding/paths' +import { join } from 'path' + +import { expectPixelColor } from '@e2e/playwright/fixtures/sceneFixture' import { TEST_SETTINGS_KEY, - TEST_SETTINGS_ONBOARDING_START, TEST_SETTINGS_ONBOARDING_EXPORT, + TEST_SETTINGS_ONBOARDING_START, TEST_SETTINGS_ONBOARDING_USER_MENU, -} from './storageStates' -import { expectPixelColor } from './fixtures/sceneFixture' +} from '@e2e/playwright/storageStates' +import { + createProject, + executorInputPath, + getUtils, + orRunWhenFullSuiteEnabled, + settingsToToml, +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' // Because our default test settings have the onboardingStatus set to 'dismissed', // we must set it to empty for the tests where we want to see the onboarding immediately. diff --git a/e2e/playwright/playwright-deprecated.ts b/e2e/playwright/playwright-deprecated.ts index b92a52dfc..2c25b4f57 100644 --- a/e2e/playwright/playwright-deprecated.ts +++ b/e2e/playwright/playwright-deprecated.ts @@ -1,4 +1,4 @@ -import { test, expect } from '@playwright/test' +import { expect, test } from '@playwright/test' /** @deprecated, import from ./fixtureSetup.ts instead */ export const _test = test diff --git a/e2e/playwright/point-click.spec.ts b/e2e/playwright/point-click.spec.ts index 7c18108a5..ebeb47513 100644 --- a/e2e/playwright/point-click.spec.ts +++ b/e2e/playwright/point-click.spec.ts @@ -1,12 +1,12 @@ -import { Page } from '@playwright/test' -import { test, expect } from './zoo-test' -import { EditorFixture } from './fixtures/editorFixture' -import { SceneFixture } from './fixtures/sceneFixture' -import { ToolbarFixture } from './fixtures/toolbarFixture' +import type { Locator, Page } from '@playwright/test' import fs from 'node:fs/promises' import path from 'node:path' -import { getUtils, orRunWhenFullSuiteEnabled } from './test-utils' -import { Locator } from '@playwright/test' + +import type { EditorFixture } from '@e2e/playwright/fixtures/editorFixture' +import type { SceneFixture } from '@e2e/playwright/fixtures/sceneFixture' +import type { ToolbarFixture } from '@e2e/playwright/fixtures/toolbarFixture' +import { getUtils, orRunWhenFullSuiteEnabled } from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' // test file is for testing point an click code gen functionality that's not sketch mode related diff --git a/e2e/playwright/projects.spec.ts b/e2e/playwright/projects.spec.ts index 425fd9d2b..efba3c04e 100644 --- a/e2e/playwright/projects.spec.ts +++ b/e2e/playwright/projects.spec.ts @@ -1,19 +1,20 @@ -import { test, expect } from './zoo-test' +import { DEFAULT_PROJECT_KCL_FILE } from '@src/lib/constants' +import fs from 'fs' +import fsp from 'fs/promises' +import path from 'path' + +import type { Paths } from '@e2e/playwright/test-utils' import { + createProject, doExport, executorInputPath, + getPlaywrightDownloadDir, getUtils, isOutOfViewInScrollContainer, - Paths, - createProject, - getPlaywrightDownloadDir, orRunWhenFullSuiteEnabled, runningOnWindows, -} from './test-utils' -import fsp from 'fs/promises' -import fs from 'fs' -import path from 'path' -import { DEFAULT_PROJECT_KCL_FILE } from 'lib/constants' +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test( 'projects reload if a new one is created, deleted, or renamed externally', diff --git a/e2e/playwright/prompt-to-edit-snapshot-tests.spec.ts b/e2e/playwright/prompt-to-edit-snapshot-tests.spec.ts index 083ea8406..86f6c3804 100644 --- a/e2e/playwright/prompt-to-edit-snapshot-tests.spec.ts +++ b/e2e/playwright/prompt-to-edit-snapshot-tests.spec.ts @@ -1,4 +1,5 @@ -import { test, expect } from './zoo-test' +import { expect, test } from '@e2e/playwright/zoo-test' + /* eslint-disable jest/no-conditional-expect */ /** diff --git a/e2e/playwright/prompt-to-edit.spec.ts b/e2e/playwright/prompt-to-edit.spec.ts index 0121a1d32..e79db800c 100644 --- a/e2e/playwright/prompt-to-edit.spec.ts +++ b/e2e/playwright/prompt-to-edit.spec.ts @@ -1,5 +1,5 @@ -import { test, expect } from './zoo-test' -import { orRunWhenFullSuiteEnabled } from './test-utils' +import { orRunWhenFullSuiteEnabled } from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' /* eslint-disable jest/no-conditional-expect */ diff --git a/e2e/playwright/regression-tests.spec.ts b/e2e/playwright/regression-tests.spec.ts index c261120c6..d17c321dd 100644 --- a/e2e/playwright/regression-tests.spec.ts +++ b/e2e/playwright/regression-tests.spec.ts @@ -1,17 +1,18 @@ -import { Page } from '@playwright/test' -import { test, expect } from './zoo-test' -import path from 'path' +import type { Page } from '@playwright/test' +import { bracket } from '@src/lib/exampleKcl' +import { reportRejection } from '@src/lib/trap' import * as fsp from 'fs/promises' +import path from 'path' + +import { TEST_CODE_TRIGGER_ENGINE_EXPORT_ERROR } from '@e2e/playwright/storageStates' +import type { TestColor } from '@e2e/playwright/test-utils' import { - getUtils, TEST_COLORS, - TestColor, executorInputPath, + getUtils, orRunWhenFullSuiteEnabled, -} from './test-utils' -import { TEST_CODE_TRIGGER_ENGINE_EXPORT_ERROR } from './storageStates' -import { bracket } from 'lib/exampleKcl' -import { reportRejection } from 'lib/trap' +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Regression tests', { tag: ['@skipWin'] }, () => { // bugs we found that don't fit neatly into other categories diff --git a/e2e/playwright/sketch-tests.spec.ts b/e2e/playwright/sketch-tests.spec.ts index 628f55bca..39379c5b7 100644 --- a/e2e/playwright/sketch-tests.spec.ts +++ b/e2e/playwright/sketch-tests.spec.ts @@ -1,20 +1,20 @@ -import { Page } from '@playwright/test' -import { test, expect } from './zoo-test' +import type { Page } from '@playwright/test' +import { roundOff, uuidv4 } from '@src/lib/utils' import fs from 'node:fs/promises' import path from 'node:path' -import { HomePageFixture } from './fixtures/homePageFixture' +import type { CmdBarFixture } from '@e2e/playwright/fixtures/cmdBarFixture' +import type { HomePageFixture } from '@e2e/playwright/fixtures/homePageFixture' +import type { SceneFixture } from '@e2e/playwright/fixtures/sceneFixture' +import type { ToolbarFixture } from '@e2e/playwright/fixtures/toolbarFixture' import { - getMovementUtils, - getUtils, PERSIST_MODELING_CONTEXT, TEST_COLORS, + getMovementUtils, + getUtils, orRunWhenFullSuiteEnabled, -} from './test-utils' -import { uuidv4, roundOff } from 'lib/utils' -import { SceneFixture } from './fixtures/sceneFixture' -import { ToolbarFixture } from './fixtures/toolbarFixture' -import { CmdBarFixture } from './fixtures/cmdBarFixture' +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Sketch tests', { tag: ['@skipWin'] }, () => { test('multi-sketch file shows multiple Edit Sketch buttons', async ({ diff --git a/e2e/playwright/snapshot-tests.spec.ts b/e2e/playwright/snapshot-tests.spec.ts index 9e5729f43..e12239241 100644 --- a/e2e/playwright/snapshot-tests.spec.ts +++ b/e2e/playwright/snapshot-tests.spec.ts @@ -1,21 +1,22 @@ -import { test, expect } from './zoo-test' -import { secrets } from './secrets' -import { - Paths, - doExport, - getUtils, - settingsToToml, - orRunWhenFullSuiteEnabled, -} from './test-utils' -import { Models } from '@kittycad/lib' -import fsp from 'fs/promises' +import type { Models } from '@kittycad/lib' +import { KCL_DEFAULT_LENGTH } from '@src/lib/constants' import { spawn } from 'child_process' -import { KCL_DEFAULT_LENGTH } from 'lib/constants' +import fsp from 'fs/promises' import JSZip from 'jszip' import path from 'path' -import { TEST_SETTINGS, TEST_SETTINGS_KEY } from './storageStates' -import { SceneFixture } from './fixtures/sceneFixture' -import { CmdBarFixture } from './fixtures/cmdBarFixture' + +import type { CmdBarFixture } from '@e2e/playwright/fixtures/cmdBarFixture' +import type { SceneFixture } from '@e2e/playwright/fixtures/sceneFixture' +import { secrets } from '@e2e/playwright/secrets' +import { TEST_SETTINGS, TEST_SETTINGS_KEY } from '@e2e/playwright/storageStates' +import type { Paths } from '@e2e/playwright/test-utils' +import { + doExport, + getUtils, + orRunWhenFullSuiteEnabled, + settingsToToml, +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.beforeEach(async ({ page, context }) => { // Make the user avatar image always 404 diff --git a/e2e/playwright/storageStates.ts b/e2e/playwright/storageStates.ts index c85ae77ff..f09a53002 100644 --- a/e2e/playwright/storageStates.ts +++ b/e2e/playwright/storageStates.ts @@ -1,8 +1,9 @@ -import { Settings } from '@rust/kcl-lib/bindings/Settings' -import { SaveSettingsPayload } from 'lib/settings/settingsTypes' -import { Themes } from 'lib/theme' -import { DeepPartial } from 'lib/types' -import { onboardingPaths } from 'routes/Onboarding/paths' +import type { SaveSettingsPayload } from '@src/lib/settings/settingsTypes' +import { Themes } from '@src/lib/theme' +import type { DeepPartial } from '@src/lib/types' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + +import type { Settings } from '@rust/kcl-lib/bindings/Settings' export const IS_PLAYWRIGHT_KEY = 'playwright' diff --git a/e2e/playwright/test-network-and-connection-issues.spec.ts b/e2e/playwright/test-network-and-connection-issues.spec.ts index 50bf53b64..e8cf451a4 100644 --- a/e2e/playwright/test-network-and-connection-issues.spec.ts +++ b/e2e/playwright/test-network-and-connection-issues.spec.ts @@ -1,7 +1,12 @@ -import { test, expect } from './zoo-test' -import { commonPoints, getUtils, orRunWhenFullSuiteEnabled } from './test-utils' -import { EngineCommand } from 'lang/std/artifactGraph' -import { uuidv4 } from 'lib/utils' +import type { EngineCommand } from '@src/lang/std/artifactGraph' +import { uuidv4 } from '@src/lib/utils' + +import { + commonPoints, + getUtils, + orRunWhenFullSuiteEnabled, +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Test network and connection issues', () => { test( diff --git a/e2e/playwright/test-utils.test.ts b/e2e/playwright/test-utils.test.ts index e8dc1491b..9d717b8fa 100644 --- a/e2e/playwright/test-utils.test.ts +++ b/e2e/playwright/test-utils.test.ts @@ -1,9 +1,9 @@ import { + orRunWhenFullSuiteEnabled, runningOnLinux, runningOnMac, runningOnWindows, - orRunWhenFullSuiteEnabled, -} from './test-utils' +} from '@e2e/playwright/test-utils' describe('platform detection utilities', () => { const originalPlatform = process.platform diff --git a/e2e/playwright/test-utils.ts b/e2e/playwright/test-utils.ts index 8286fb56f..1e8914046 100644 --- a/e2e/playwright/test-utils.ts +++ b/e2e/playwright/test-utils.ts @@ -1,32 +1,29 @@ -import { - expect, - BrowserContext, - TestInfo, - Locator, - Page, -} from '@playwright/test' -import { test } from './zoo-test' -import { EngineCommand } from 'lang/std/artifactGraph' +import * as TOML from '@iarna/toml' +import type { Models } from '@kittycad/lib' +import type { BrowserContext, Locator, Page, TestInfo } from '@playwright/test' +import { expect } from '@playwright/test' +import type { EngineCommand } from '@src/lang/std/artifactGraph' +import type { Configuration } from '@src/lang/wasm' +import { COOKIE_NAME } from '@src/lib/constants' +import { reportRejection } from '@src/lib/trap' +import type { DeepPartial } from '@src/lib/types' +import { isArray } from '@src/lib/utils' import fsp from 'fs/promises' import path from 'path' import pixelMatch from 'pixelmatch' +import type { Protocol } from 'playwright-core/types/protocol' import { PNG } from 'pngjs' -import { Protocol } from 'playwright-core/types/protocol' -import type { Models } from '@kittycad/lib' -import { COOKIE_NAME } from 'lib/constants' -import { secrets } from './secrets' + +import type { ProjectConfiguration } from '@rust/kcl-lib/bindings/ProjectConfiguration' + +import { isErrorWhitelisted } from '@e2e/playwright/lib/console-error-whitelist' +import { secrets } from '@e2e/playwright/secrets' import { - TEST_SETTINGS_KEY, - TEST_SETTINGS, IS_PLAYWRIGHT_KEY, -} from './storageStates' -import * as TOML from '@iarna/toml' -import { isErrorWhitelisted } from './lib/console-error-whitelist' -import { isArray } from 'lib/utils' -import { reportRejection } from 'lib/trap' -import { DeepPartial } from 'lib/types' -import { Configuration } from 'lang/wasm' -import { ProjectConfiguration } from '@rust/kcl-lib/bindings/ProjectConfiguration' + TEST_SETTINGS, + TEST_SETTINGS_KEY, +} from '@e2e/playwright/storageStates' +import { test } from '@e2e/playwright/zoo-test' const toNormalizedCode = (text: string) => { return text.replace(/\s+/g, '') @@ -683,8 +680,8 @@ const _makeTemplate = ( isArray(currentOptions) ? currentOptions[i] : typeof currentOptions === 'number' - ? currentOptions - : '' + ? currentOptions + : '' ) ) }) diff --git a/e2e/playwright/testing-camera-movement.spec.ts b/e2e/playwright/testing-camera-movement.spec.ts index c900f3fc6..9b649d81c 100644 --- a/e2e/playwright/testing-camera-movement.spec.ts +++ b/e2e/playwright/testing-camera-movement.spec.ts @@ -1,7 +1,8 @@ -import { test, expect } from './zoo-test' -import { EngineCommand } from 'lang/std/artifactGraph' -import { uuidv4 } from 'lib/utils' -import { getUtils, orRunWhenFullSuiteEnabled } from './test-utils' +import type { EngineCommand } from '@src/lang/std/artifactGraph' +import { uuidv4 } from '@src/lib/utils' + +import { getUtils, orRunWhenFullSuiteEnabled } from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Testing Camera Movement', { tag: ['@skipWin'] }, () => { test('Can move camera reliably', async ({ page, context, homePage }) => { diff --git a/e2e/playwright/testing-constraints.spec.ts b/e2e/playwright/testing-constraints.spec.ts index da190a058..26db7ea1c 100644 --- a/e2e/playwright/testing-constraints.spec.ts +++ b/e2e/playwright/testing-constraints.spec.ts @@ -1,14 +1,15 @@ -import { test, expect } from './zoo-test' +import { XOR } from '@src/lib/utils' import * as fsp from 'fs/promises' -import { - getUtils, - TEST_COLORS, - pollEditorLinesSelectedLength, - orRunWhenFullSuiteEnabled, -} from './test-utils' -import { XOR } from 'lib/utils' import path from 'node:path' +import { + TEST_COLORS, + getUtils, + orRunWhenFullSuiteEnabled, + pollEditorLinesSelectedLength, +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' + test.describe('Testing constraints', { tag: ['@skipWin'] }, () => { test('Can constrain line length', async ({ page, homePage }) => { await page.addInitScript(async () => { diff --git a/e2e/playwright/testing-gizmo.spec.ts b/e2e/playwright/testing-gizmo.spec.ts index 75b222b32..62422f8fe 100644 --- a/e2e/playwright/testing-gizmo.spec.ts +++ b/e2e/playwright/testing-gizmo.spec.ts @@ -1,7 +1,8 @@ -import { test, expect } from './zoo-test' -import { getUtils } from './test-utils' -import { uuidv4 } from 'lib/utils' -import { TEST_CODE_GIZMO } from './storageStates' +import { uuidv4 } from '@src/lib/utils' + +import { TEST_CODE_GIZMO } from '@e2e/playwright/storageStates' +import { getUtils } from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Testing Gizmo', { tag: ['@skipWin'] }, () => { const cases = [ diff --git a/e2e/playwright/testing-perspective-toggle.spec.ts b/e2e/playwright/testing-perspective-toggle.spec.ts index 78c83e7b0..eb1306e98 100644 --- a/e2e/playwright/testing-perspective-toggle.spec.ts +++ b/e2e/playwright/testing-perspective-toggle.spec.ts @@ -1,5 +1,5 @@ -import { test, expect } from './zoo-test' -import { getUtils, orRunWhenFullSuiteEnabled } from './test-utils' +import { getUtils, orRunWhenFullSuiteEnabled } from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Test toggling perspective', () => { test('via command palette and toggle', async ({ page, homePage }) => { diff --git a/e2e/playwright/testing-samples-loading.spec.ts b/e2e/playwright/testing-samples-loading.spec.ts index 182925fe9..0e033e89b 100644 --- a/e2e/playwright/testing-samples-loading.spec.ts +++ b/e2e/playwright/testing-samples-loading.spec.ts @@ -1,9 +1,10 @@ -import { test, expect } from './zoo-test' -import { getUtils } from './test-utils' -import { bracket } from 'lib/exampleKcl' +import { FILE_EXT } from '@src/lib/constants' +import { bracket } from '@src/lib/exampleKcl' import * as fsp from 'fs/promises' import { join } from 'path' -import { FILE_EXT } from 'lib/constants' + +import { getUtils } from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Testing in-app sample loading', () => { /** diff --git a/e2e/playwright/testing-segment-overlays.spec.ts b/e2e/playwright/testing-segment-overlays.spec.ts index 809ad55bb..e761d9ff6 100644 --- a/e2e/playwright/testing-segment-overlays.spec.ts +++ b/e2e/playwright/testing-segment-overlays.spec.ts @@ -1,15 +1,15 @@ -import { Page } from '@playwright/test' -import { test, expect } from './zoo-test' +import type { Page } from '@playwright/test' +import type { LineInputsType } from '@src/lang/std/sketchcombos' +import { uuidv4 } from '@src/lib/utils' +import type { EditorFixture } from '@e2e/playwright/fixtures/editorFixture' import { deg, getUtils, - wiggleMove, orRunWhenFullSuiteEnabled, -} from './test-utils' -import { LineInputsType } from 'lang/std/sketchcombos' -import { uuidv4 } from 'lib/utils' -import { EditorFixture } from './fixtures/editorFixture' + wiggleMove, +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Testing segment overlays', { tag: ['@skipWin'] }, () => { test('Hover over a segment should show its overlay, hovering over the input overlays should show its popover, clicking the input overlay should constrain/unconstrain it:\nfor the following segments', () => { diff --git a/e2e/playwright/testing-selections.spec.ts b/e2e/playwright/testing-selections.spec.ts index 0b1ded979..756375f0c 100644 --- a/e2e/playwright/testing-selections.spec.ts +++ b/e2e/playwright/testing-selections.spec.ts @@ -1,9 +1,13 @@ -import { test, expect } from './zoo-test' +import type { Coords2d } from '@src/lang/std/sketch' +import { KCL_DEFAULT_LENGTH } from '@src/lib/constants' +import { uuidv4 } from '@src/lib/utils' -import { commonPoints, getUtils, orRunWhenFullSuiteEnabled } from './test-utils' -import { Coords2d } from 'lang/std/sketch' -import { KCL_DEFAULT_LENGTH } from 'lib/constants' -import { uuidv4 } from 'lib/utils' +import { + commonPoints, + getUtils, + orRunWhenFullSuiteEnabled, +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Testing selections', { tag: ['@skipWin'] }, () => { test.setTimeout(90_000) diff --git a/e2e/playwright/testing-settings.spec.ts b/e2e/playwright/testing-settings.spec.ts index 5a58b3427..8cd4241e0 100644 --- a/e2e/playwright/testing-settings.spec.ts +++ b/e2e/playwright/testing-settings.spec.ts @@ -1,24 +1,29 @@ -import { test, expect } from './zoo-test' +import { + PROJECT_SETTINGS_FILE_NAME, + SETTINGS_FILE_NAME, +} from '@src/lib/constants' +import type { SettingsLevel } from '@src/lib/settings/settingsTypes' +import type { DeepPartial } from '@src/lib/types' import * as fsp from 'fs/promises' import { join } from 'path' + +import type { Settings } from '@rust/kcl-lib/bindings/Settings' + import { - getUtils, - executorInputPath, - createProject, - tomlToSettings, - TEST_COLORS, - orRunWhenFullSuiteEnabled, -} from './test-utils' -import { SettingsLevel } from 'lib/settings/settingsTypes' -import { SETTINGS_FILE_NAME, PROJECT_SETTINGS_FILE_NAME } from 'lib/constants' -import { - TEST_SETTINGS_KEY, - TEST_SETTINGS_CORRUPTED, TEST_SETTINGS, + TEST_SETTINGS_CORRUPTED, TEST_SETTINGS_DEFAULT_THEME, -} from './storageStates' -import { DeepPartial } from 'lib/types' -import { Settings } from '@rust/kcl-lib/bindings/Settings' + TEST_SETTINGS_KEY, +} from '@e2e/playwright/storageStates' +import { + TEST_COLORS, + createProject, + executorInputPath, + getUtils, + orRunWhenFullSuiteEnabled, + tomlToSettings, +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Testing settings', () => { test('Stored settings are validated and fall back to defaults', async ({ diff --git a/e2e/playwright/text-to-cad-tests.spec.ts b/e2e/playwright/text-to-cad-tests.spec.ts index 8dddbcb33..da2406141 100644 --- a/e2e/playwright/text-to-cad-tests.spec.ts +++ b/e2e/playwright/text-to-cad-tests.spec.ts @@ -1,12 +1,13 @@ -import { Page } from '@playwright/test' -import { test, expect } from './zoo-test' -import { - getUtils, - createProject, - orRunWhenFullSuiteEnabled, -} from './test-utils' -import { join } from 'path' +import type { Page } from '@playwright/test' import fs from 'fs' +import { join } from 'path' + +import { + createProject, + getUtils, + orRunWhenFullSuiteEnabled, +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test.describe('Text-to-CAD tests', { tag: ['@skipWin'] }, () => { test('basic lego happy case', async ({ page, homePage }) => { diff --git a/e2e/playwright/various.spec.ts b/e2e/playwright/various.spec.ts index d49ff9514..2488404b4 100644 --- a/e2e/playwright/various.spec.ts +++ b/e2e/playwright/various.spec.ts @@ -1,11 +1,10 @@ -import { test, expect } from './zoo-test' - import { doExport, getUtils, makeTemplate, orRunWhenFullSuiteEnabled, -} from './test-utils' +} from '@e2e/playwright/test-utils' +import { expect, test } from '@e2e/playwright/zoo-test' test('Units menu', async ({ page, homePage }) => { test.fixme(orRunWhenFullSuiteEnabled()) diff --git a/e2e/playwright/zoo-test.ts b/e2e/playwright/zoo-test.ts index 5096686a4..63010757b 100644 --- a/e2e/playwright/zoo-test.ts +++ b/e2e/playwright/zoo-test.ts @@ -1,12 +1,11 @@ /* eslint-disable react-hooks/rules-of-hooks */ - import { test as playwrightTestFn } from '@playwright/test' +import type { Fixtures } from '@e2e/playwright/fixtures/fixtureSetup' import { - fixturesBasedOnProcessEnvPlatform, - Fixtures, ElectronZoo, -} from './fixtures/fixtureSetup' + fixturesBasedOnProcessEnvPlatform, +} from '@e2e/playwright/fixtures/fixtureSetup' export { expect } from '@playwright/test' diff --git a/forge.config.ts b/forge.config.ts index 5a079660e..ace957e8b 100644 --- a/forge.config.ts +++ b/forge.config.ts @@ -1,6 +1,6 @@ -import type { ForgeConfig } from '@electron-forge/shared-types' -import { VitePlugin } from '@electron-forge/plugin-vite' import { FusesPlugin } from '@electron-forge/plugin-fuses' +import { VitePlugin } from '@electron-forge/plugin-vite' +import type { ForgeConfig } from '@electron-forge/shared-types' import { FuseV1Options, FuseVersion } from '@electron/fuses' import path from 'path' diff --git a/forge.env.d.ts b/forge.env.d.ts index eb0a5a87e..4408b1e64 100644 --- a/forge.env.d.ts +++ b/forge.env.d.ts @@ -26,7 +26,7 @@ declare global { declare module 'vite' { interface ConfigEnv< - K extends keyof VitePluginConfig = keyof VitePluginConfig + K extends keyof VitePluginConfig = keyof VitePluginConfig, > { root: string forgeConfig: VitePluginConfig diff --git a/interface.d.ts b/interface.d.ts index 27c97f3ac..81f789ea7 100644 --- a/interface.d.ts +++ b/interface.d.ts @@ -1,13 +1,10 @@ -import fs from 'node:fs/promises' -import fsSync from 'node:fs' -import path from 'path' -import { dialog, shell } from 'electron' import { MachinesListing } from 'components/MachineManagerProvider' -import type { Channel } from 'src/menu/channels' -import { Menu, WebContents } from 'electron' -import { ZooLabel, ZooMenuEvents } from 'menu/roles' -import type { MenuActionIPC } from 'menu/rules' +import 'electron' +import { dialog, shell } from 'electron' import type { WebContentSendPayload } from 'menu/channels' +import { ZooLabel } from 'menu/roles' +import fs from 'node:fs/promises' +import path from 'path' // Extend the interface with additional custom properties declare module 'electron' { diff --git a/package.json b/package.json index dd9cc0259..641aa5f70 100644 --- a/package.json +++ b/package.json @@ -88,9 +88,9 @@ "simpleserver:ci": "yarn pretest && http-server ./public --cors -p 3000 &", "simpleserver:bg": "yarn pretest && http-server ./public --cors -p 3000 &", "simpleserver:stop": "kill-port 3000", - "fmt": "prettier --write ./src *.ts *.json *.js ./e2e ./packages ./rust/kcl-language-server ./rust/kcl-lib/bindings ./rust/kcl-wasm-lib/pkg", - "fmt:generated": "prettier --write *.ts *.json *.js ./rust/kcl-lib/bindings ./rust/kcl-wasm-lib/pkg", - "fmt-check": "prettier --check ./src *.ts *.json *.js ./e2e ./packages ./rust/kcl-language-server", + "fmt": "prettier --write .eslintrc.json ./src *.ts *.json *.js ./e2e ./packages ./rust/kcl-language-server ./rust/kcl-lib/bindings ./rust/kcl-wasm-lib/pkg", + "fmt:generated": "prettier --write .eslintrc.json *.ts *.json *.js ./rust/kcl-lib/bindings ./rust/kcl-wasm-lib/pkg", + "fmt-check": "prettier --check .eslintrc.json ./src *.ts *.json *.js ./e2e ./packages ./rust/kcl-language-server", "fetch:wasm": "./scripts/get-latest-wasm-bundle.sh", "fetch:wasm:windows": "./scripts/get-latest-wasm-bundle.ps1", "fetch:samples": "rm -rf public/kcl-samples* && curl -L -o public/kcl-samples.zip https://github.com/KittyCAD/kcl-samples/archive/refs/heads/achalmers/kw-args-xylineto.zip && unzip -o public/kcl-samples.zip -d public && mv public/kcl-samples-* public/kcl-samples", @@ -102,6 +102,7 @@ "remove-importmeta": "sed -i 's/import.meta.url/window.location.origin/g' \"./rust/kcl-wasm-lib/pkg/kcl_wasm_lib.js\"; sed -i '' 's/import.meta.url/window.location.origin/g' \"./rust/kcl-wasm-lib/pkg/kcl_wasm_lib.js\" || echo \"sed for both mac and linux\"", "lint-fix": "eslint --fix --ext .ts --ext .tsx src e2e packages/codemirror-lsp-client/src rust/kcl-language-server/client/src", "lint": "eslint --max-warnings 0 --ext .ts --ext .tsx src e2e packages/codemirror-lsp-client/src rust/kcl-language-server/client/src", + "circular-deps": "dpdm --no-warning --no-tree -T --skip-dynamic-imports=circular src/index.tsx", "files:set-version": "echo \"$(jq --arg v \"$VERSION\" '.version=$v' package.json --indent 2)\" > package.json", "files:set-notes": "./scripts/set-files-notes.sh", "files:flip-to-nightly": "./scripts/flip-files-to-nightly.sh", @@ -139,7 +140,20 @@ "trailingComma": "es5", "tabWidth": 2, "semi": false, - "singleQuote": true + "singleQuote": true, + "importOrder": [ + "", + "^@rust/(.*)$", + "^@e2e/(.*)$", + "^@src/(.*)$", + "^[./]" + ], + "importOrderSeparation": true, + "importOrderSortSpecifiers": true, + "plugins": [ + "@trivago/prettier-plugin-sort-imports", + "prettier-plugin-organize-imports" + ] }, "browserslist": { "production": [ @@ -167,6 +181,7 @@ "@playwright/test": "^1.51.1", "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^15.0.2", + "@trivago/prettier-plugin-sort-imports": "^5.2.2", "@types/diff": "^7.0.2", "@types/electron": "^1.6.10", "@types/isomorphic-fetch": "^0.0.39", @@ -187,6 +202,7 @@ "@vitest/web-worker": "^1.5.0", "@xstate/cli": "^0.5.17", "autoprefixer": "^10.4.21", + "dpdm": "^3.14.0", "electron": "^34.1.1", "electron-builder": "^26.0.12", "eslint": "^8.0.1", @@ -208,7 +224,8 @@ "pngjs": "^7.0.0", "postcss": "^8.4.43", "postinstall-postinstall": "^2.1.0", - "prettier": "^2.8.8", + "prettier": "^3.5.3", + "prettier-plugin-organize-imports": "^4.1.0", "setimmediate": "^1.0.5", "tailwindcss": "^3.4.17", "ts-node": "^10.0.0", diff --git a/packages/codemirror-lang-kcl/rollup.config.js b/packages/codemirror-lang-kcl/rollup.config.js index d558688be..deadb2519 100644 --- a/packages/codemirror-lang-kcl/rollup.config.js +++ b/packages/codemirror-lang-kcl/rollup.config.js @@ -1,6 +1,6 @@ -import dts from 'rollup-plugin-dts' import { lezer } from '@lezer/generator/rollup' import typescript from '@rollup/plugin-typescript' +import dts from 'rollup-plugin-dts' export default [ { diff --git a/packages/codemirror-lang-kcl/src/index.ts b/packages/codemirror-lang-kcl/src/index.ts index 7d77f1375..238340459 100644 --- a/packages/codemirror-lang-kcl/src/index.ts +++ b/packages/codemirror-lang-kcl/src/index.ts @@ -1,14 +1,14 @@ // Base CodeMirror language support for kcl. - import { LRLanguage, LanguageSupport, - indentNodeProp, continuedIndent, delimitedIndent, - foldNodeProp, foldInside, + foldNodeProp, + indentNodeProp, } from '@codemirror/language' + // @ts-ignore: No types available import { parser } from './kcl.grammar' diff --git a/packages/codemirror-lang-kcl/test/all.test.ts b/packages/codemirror-lang-kcl/test/all.test.ts index dba913ceb..5d03f09f3 100644 --- a/packages/codemirror-lang-kcl/test/all.test.ts +++ b/packages/codemirror-lang-kcl/test/all.test.ts @@ -1,9 +1,9 @@ -import { KclLanguage } from '../src/index' import { fileTests } from '@lezer/generator/dist/test' - import * as fs from 'fs' import * as path from 'path' +import { KclLanguage } from '../src/index' + let caseDir = path.dirname(__filename) for (let file of fs.readdirSync(caseDir)) { diff --git a/packages/codemirror-lang-kcl/vitest.main.config.ts b/packages/codemirror-lang-kcl/vitest.main.config.ts index 814142a18..e16fa0092 100644 --- a/packages/codemirror-lang-kcl/vitest.main.config.ts +++ b/packages/codemirror-lang-kcl/vitest.main.config.ts @@ -1,9 +1,8 @@ // Overrides the test options from the modeling-app config. - -import viteTsconfigPaths from 'vite-tsconfig-paths' -import { defineConfig, configDefaults } from 'vitest/config' // @ts-ignore: No types available import { lezer } from '@lezer/generator/rollup' +import viteTsconfigPaths from 'vite-tsconfig-paths' +import { defineConfig } from 'vitest/config' const config = defineConfig({ test: { diff --git a/packages/codemirror-lsp-client/src/client/codec/bytes.ts b/packages/codemirror-lsp-client/src/client/codec/bytes.ts index 73d778752..f90c8994f 100644 --- a/packages/codemirror-lsp-client/src/client/codec/bytes.ts +++ b/packages/codemirror-lsp-client/src/client/codec/bytes.ts @@ -1,4 +1,4 @@ -import { encoder, decoder } from '../codec' +import { decoder, encoder } from './encode-decode' export default class Bytes { static encode(input: string): Uint8Array { @@ -10,7 +10,7 @@ export default class Bytes { } static append< - T extends { length: number; set(arr: T, offset: number): void } + T extends { length: number; set(arr: T, offset: number): void }, >(constructor: { new (length: number): T }, ...arrays: T[]) { let totalLength = 0 for (const arr of arrays) { diff --git a/packages/codemirror-lsp-client/src/client/codec/demuxer.ts b/packages/codemirror-lsp-client/src/client/codec/demuxer.ts index dff846d6a..c4690d0a1 100644 --- a/packages/codemirror-lsp-client/src/client/codec/demuxer.ts +++ b/packages/codemirror-lsp-client/src/client/codec/demuxer.ts @@ -1,10 +1,10 @@ import * as vsrpc from 'vscode-jsonrpc' -import { Codec } from '.' import Bytes from './bytes' +import PromiseMap from './map' import Queue from './queue' import Tracer from './tracer' -import PromiseMap from './map' +import { Codec } from './utils' export default class StreamDemuxer extends Queue { readonly responses: PromiseMap = diff --git a/packages/codemirror-lsp-client/src/client/codec/encode-decode.ts b/packages/codemirror-lsp-client/src/client/codec/encode-decode.ts new file mode 100644 index 000000000..30325efc4 --- /dev/null +++ b/packages/codemirror-lsp-client/src/client/codec/encode-decode.ts @@ -0,0 +1,2 @@ +export const encoder = new TextEncoder() +export const decoder = new TextDecoder() diff --git a/packages/codemirror-lsp-client/src/client/codec/index.ts b/packages/codemirror-lsp-client/src/client/codec/index.ts index db50b1392..4c1ea80ab 100644 --- a/packages/codemirror-lsp-client/src/client/codec/index.ts +++ b/packages/codemirror-lsp-client/src/client/codec/index.ts @@ -1,8 +1,7 @@ -import * as jsrpc from 'json-rpc-2.0' -import * as vsrpc from 'vscode-jsonrpc' +import type * as vsrpc from 'vscode-jsonrpc' -import Bytes from './bytes' import StreamDemuxer from './demuxer' +import { decoder } from './encode-decode' import Headers from './headers' import Queue from './queue' import Tracer from './tracer' @@ -12,25 +11,6 @@ export enum LspWorkerEventType { Call = 'call', } -export const encoder = new TextEncoder() -export const decoder = new TextDecoder() - -export class Codec { - static encode( - json: jsrpc.JSONRPCRequest | jsrpc.JSONRPCResponse - ): Uint8Array { - const message = JSON.stringify(json) - const delimited = Headers.add(message) - return Bytes.encode(delimited) - } - - static decode(data: Uint8Array): T { - const delimited = Bytes.decode(data) - const message = Headers.remove(delimited) - return JSON.parse(message) as T - } -} - // FIXME: tracing efficiency export class IntoServer extends Queue diff --git a/packages/codemirror-lsp-client/src/client/codec/tracer.ts b/packages/codemirror-lsp-client/src/client/codec/tracer.ts index 816540c8b..3bde2fcb2 100644 --- a/packages/codemirror-lsp-client/src/client/codec/tracer.ts +++ b/packages/codemirror-lsp-client/src/client/codec/tracer.ts @@ -1,4 +1,4 @@ -import { Message } from 'vscode-languageserver-protocol' +import type { Message } from 'vscode-languageserver-protocol' export default class Tracer { static client(message: string): void { diff --git a/packages/codemirror-lsp-client/src/client/codec/utils.ts b/packages/codemirror-lsp-client/src/client/codec/utils.ts new file mode 100644 index 000000000..bb27e60bf --- /dev/null +++ b/packages/codemirror-lsp-client/src/client/codec/utils.ts @@ -0,0 +1,20 @@ +import type * as jsrpc from 'json-rpc-2.0' + +import Bytes from './bytes' +import Headers from './headers' + +export class Codec { + static encode( + json: jsrpc.JSONRPCRequest | jsrpc.JSONRPCResponse + ): Uint8Array { + const message = JSON.stringify(json) + const delimited = Headers.add(message) + return Bytes.encode(delimited) + } + + static decode(data: Uint8Array): T { + const delimited = Bytes.decode(data) + const message = Headers.remove(delimited) + return JSON.parse(message) as T + } +} diff --git a/packages/codemirror-lsp-client/src/client/index.ts b/packages/codemirror-lsp-client/src/client/index.ts index 822957482..63ffe744b 100644 --- a/packages/codemirror-lsp-client/src/client/index.ts +++ b/packages/codemirror-lsp-client/src/client/index.ts @@ -1,8 +1,8 @@ import type * as LSP from 'vscode-languageserver-protocol' -import { FromServer, IntoServer } from './codec' +import type { LanguageServerPlugin } from '../plugin/lsp' +import type { FromServer, IntoServer } from './codec' import Client from './jsonrpc' -import { LanguageServerPlugin } from '../plugin/lsp' // https://microsoft.github.io/language-server-protocol/specifications/specification-current/ @@ -12,15 +12,15 @@ interface LSPRequestMap { 'textDocument/hover': [LSP.HoverParams, LSP.Hover] 'textDocument/completion': [ LSP.CompletionParams, - LSP.CompletionItem[] | LSP.CompletionList | null + LSP.CompletionItem[] | LSP.CompletionList | null, ] 'textDocument/semanticTokens/full': [ LSP.SemanticTokensParams, - LSP.SemanticTokens + LSP.SemanticTokens, ] 'textDocument/formatting': [ LSP.DocumentFormattingParams, - LSP.TextEdit[] | null + LSP.TextEdit[] | null, ] 'textDocument/foldingRange': [LSP.FoldingRangeParams, LSP.FoldingRange[]] } diff --git a/packages/codemirror-lsp-client/src/client/jsonrpc.ts b/packages/codemirror-lsp-client/src/client/jsonrpc.ts index 0a18bf9d0..9bb873684 100644 --- a/packages/codemirror-lsp-client/src/client/jsonrpc.ts +++ b/packages/codemirror-lsp-client/src/client/jsonrpc.ts @@ -1,11 +1,12 @@ import * as jsrpc from 'json-rpc-2.0' import * as LSP from 'vscode-languageserver-protocol' +import type { FromServer, IntoServer } from './codec' +import { Codec } from './codec/utils' import { registerServerCapability, unregisterServerCapability, } from './server-capability-registration' -import { Codec, FromServer, IntoServer } from './codec' const client_capabilities: LSP.ClientCapabilities = { textDocument: { diff --git a/packages/codemirror-lsp-client/src/client/server-capability-registration.ts b/packages/codemirror-lsp-client/src/client/server-capability-registration.ts index 36b21566c..6dc9304a1 100644 --- a/packages/codemirror-lsp-client/src/client/server-capability-registration.ts +++ b/packages/codemirror-lsp-client/src/client/server-capability-registration.ts @@ -1,4 +1,4 @@ -import { +import type { Registration, ServerCapabilities, Unregistration, diff --git a/packages/codemirror-lsp-client/src/index.ts b/packages/codemirror-lsp-client/src/index.ts index 708aca942..3bcb983d9 100644 --- a/packages/codemirror-lsp-client/src/index.ts +++ b/packages/codemirror-lsp-client/src/index.ts @@ -1,36 +1,34 @@ import { foldService } from '@codemirror/language' -import { Extension, EditorState } from '@codemirror/state' +import type { EditorState, Extension } from '@codemirror/state' import { ViewPlugin } from '@codemirror/view' +import type { LanguageServerOptions } from './plugin/lsp' import { - docPathFacet, LanguageServerPlugin, LanguageServerPluginSpec, + docPathFacet, languageId, workspaceFolders, - LanguageServerOptions, } from './plugin/lsp' -export type { LanguageServerClientOptions } from './client' export { LanguageServerClient } from './client' +export type { LanguageServerClientOptions } from './client' +export { FromServer, IntoServer, LspWorkerEventType } from './client/codec' +export { Codec } from './client/codec/utils' export { - Codec, - FromServer, - IntoServer, - LspWorkerEventType, -} from './client/codec' -export type { LanguageServerOptions } from './plugin/lsp' + lspDiagnosticsEvent, + lspFormatCodeEvent, + lspSemanticTokensEvent, +} from './plugin/annotation' export { LanguageServerPlugin, LanguageServerPluginSpec, docPathFacet, languageId, workspaceFolders, - lspSemanticTokensEvent, - lspDiagnosticsEvent, - lspFormatCodeEvent, } from './plugin/lsp' -export { posToOffset, offsetToPos } from './plugin/util' +export type { LanguageServerOptions } from './plugin/lsp' +export { offsetToPos, posToOffset } from './plugin/util' export function lspPlugin(options: LanguageServerOptions): Extension { let plugin: LanguageServerPlugin | null = null diff --git a/packages/codemirror-lsp-client/src/plugin/annotation.ts b/packages/codemirror-lsp-client/src/plugin/annotation.ts new file mode 100644 index 000000000..10feb8135 --- /dev/null +++ b/packages/codemirror-lsp-client/src/plugin/annotation.ts @@ -0,0 +1,12 @@ +import { Annotation } from '@codemirror/state' + +export enum LspAnnotation { + SemanticTokens = 'semantic-tokens', + FormatCode = 'format-code', + Diagnostics = 'diagnostics', +} + +const lspEvent = Annotation.define() +export const lspSemanticTokensEvent = lspEvent.of(LspAnnotation.SemanticTokens) +export const lspFormatCodeEvent = lspEvent.of(LspAnnotation.FormatCode) +export const lspDiagnosticsEvent = lspEvent.of(LspAnnotation.Diagnostics) diff --git a/packages/codemirror-lsp-client/src/plugin/autocomplete.ts b/packages/codemirror-lsp-client/src/plugin/autocomplete.ts index a1352c71c..9d2baebf7 100644 --- a/packages/codemirror-lsp-client/src/plugin/autocomplete.ts +++ b/packages/codemirror-lsp-client/src/plugin/autocomplete.ts @@ -9,17 +9,18 @@ import { prevSnippetField, startCompletion, } from '@codemirror/autocomplete' -import { Prec, Extension } from '@codemirror/state' -import { EditorView, keymap, KeyBinding, ViewPlugin } from '@codemirror/view' - +import { syntaxTree } from '@codemirror/language' +import type { Extension } from '@codemirror/state' +import { Prec } from '@codemirror/state' +import type { EditorView, KeyBinding, ViewPlugin } from '@codemirror/view' +import { keymap } from '@codemirror/view' import { CompletionItemKind, CompletionTriggerKind, } from 'vscode-languageserver-protocol' -import { LanguageServerPlugin } from './lsp' +import type { LanguageServerPlugin } from './lsp' import { offsetToPos } from './util' -import { syntaxTree } from '@codemirror/language' export const CompletionItemKindMap = Object.fromEntries( Object.entries(CompletionItemKind).map(([key, value]) => [value, key]) diff --git a/packages/codemirror-lsp-client/src/plugin/format.ts b/packages/codemirror-lsp-client/src/plugin/format.ts index d7cedc1a4..4a33a35d6 100644 --- a/packages/codemirror-lsp-client/src/plugin/format.ts +++ b/packages/codemirror-lsp-client/src/plugin/format.ts @@ -1,7 +1,9 @@ -import { Extension, Prec } from '@codemirror/state' -import { EditorView, keymap, KeyBinding, ViewPlugin } from '@codemirror/view' +import type { Extension } from '@codemirror/state' +import { Prec } from '@codemirror/state' +import type { EditorView, KeyBinding, ViewPlugin } from '@codemirror/view' +import { keymap } from '@codemirror/view' -import { LanguageServerPlugin } from './lsp' +import type { LanguageServerPlugin } from './lsp' export default function lspFormatExt( plugin: ViewPlugin diff --git a/packages/codemirror-lsp-client/src/plugin/hover.ts b/packages/codemirror-lsp-client/src/plugin/hover.ts index ec2a843d7..02b1d566d 100644 --- a/packages/codemirror-lsp-client/src/plugin/hover.ts +++ b/packages/codemirror-lsp-client/src/plugin/hover.ts @@ -1,12 +1,8 @@ -import { Extension } from '@codemirror/state' -import { - hoverTooltip, - tooltips, - ViewPlugin, - EditorView, -} from '@codemirror/view' +import type { Extension } from '@codemirror/state' +import type { ViewPlugin } from '@codemirror/view' +import { EditorView, hoverTooltip, tooltips } from '@codemirror/view' -import { LanguageServerPlugin } from './lsp' +import type { LanguageServerPlugin } from './lsp' import { offsetToPos } from './util' export default function lspHoverExt( diff --git a/packages/codemirror-lsp-client/src/plugin/indent.ts b/packages/codemirror-lsp-client/src/plugin/indent.ts index 323301b0e..c835736b1 100644 --- a/packages/codemirror-lsp-client/src/plugin/indent.ts +++ b/packages/codemirror-lsp-client/src/plugin/indent.ts @@ -1,5 +1,5 @@ import { indentService } from '@codemirror/language' -import { Extension } from '@codemirror/state' +import type { Extension } from '@codemirror/state' export default function lspIndentExt(): Extension { // Match the indentation of the previous line (if present). diff --git a/packages/codemirror-lsp-client/src/plugin/lsp.ts b/packages/codemirror-lsp-client/src/plugin/lsp.ts index c8c7e0fb6..b68c8a783 100644 --- a/packages/codemirror-lsp-client/src/plugin/lsp.ts +++ b/packages/codemirror-lsp-client/src/plugin/lsp.ts @@ -4,39 +4,34 @@ import type { CompletionResult, } from '@codemirror/autocomplete' import { completeFromList, snippetCompletion } from '@codemirror/autocomplete' -import { - Facet, - StateEffect, - Extension, - Transaction, - Annotation, -} from '@codemirror/state' -import type { - ViewUpdate, - PluginValue, - PluginSpec, - ViewPlugin, -} from '@codemirror/view' -import { EditorView, Tooltip } from '@codemirror/view' import { linter } from '@codemirror/lint' - -import type { PublishDiagnosticsParams } from 'vscode-languageserver-protocol' +import type { Extension, StateEffect } from '@codemirror/state' +import { Facet, Transaction } from '@codemirror/state' +import type { + EditorView, + PluginSpec, + PluginValue, + Tooltip, + ViewPlugin, + ViewUpdate, +} from '@codemirror/view' import type * as LSP from 'vscode-languageserver-protocol' -import { - DiagnosticSeverity, +import type { CompletionTriggerKind, + PublishDiagnosticsParams, } from 'vscode-languageserver-protocol' +import { DiagnosticSeverity } from 'vscode-languageserver-protocol' import { URI } from 'vscode-uri' -import { LanguageServerClient } from '../client' -import { CompletionItemKindMap } from './autocomplete' -import { addToken, SemanticToken } from './semantic-tokens' -import { posToOffset, formatMarkdownContents } from './util' -import lspAutocompleteExt from './autocomplete' -import lspHoverExt from './hover' +import type { LanguageServerClient } from '../client' +import { lspFormatCodeEvent, lspSemanticTokensEvent } from './annotation' +import lspAutocompleteExt, { CompletionItemKindMap } from './autocomplete' import lspFormatExt from './format' +import lspHoverExt from './hover' import lspIndentExt from './indent' -import lspSemanticTokensExt from './semantic-tokens' +import type { SemanticToken } from './semantic-tokens' +import lspSemanticTokensExt, { addToken } from './semantic-tokens' +import { formatMarkdownContents, posToOffset } from './util' const useLast = (values: readonly any[]) => values.reduce((_, v) => v, '') export const docPathFacet = Facet.define({ @@ -48,17 +43,6 @@ export const workspaceFolders = Facet.define< LSP.WorkspaceFolder[] >({ combine: useLast }) -export enum LspAnnotation { - SemanticTokens = 'semantic-tokens', - FormatCode = 'format-code', - Diagnostics = 'diagnostics', -} - -const lspEvent = Annotation.define() -export const lspSemanticTokensEvent = lspEvent.of(LspAnnotation.SemanticTokens) -export const lspFormatCodeEvent = lspEvent.of(LspAnnotation.FormatCode) -export const lspDiagnosticsEvent = lspEvent.of(LspAnnotation.Diagnostics) - export interface LanguageServerOptions { // We assume this is the main project directory, we are currently working in. workspaceFolders: LSP.WorkspaceFolder[] @@ -98,7 +82,10 @@ export class LanguageServerPlugin implements PluginValue { // document. private sendScheduled: number | null = null - constructor(options: LanguageServerOptions, private view: EditorView) { + constructor( + options: LanguageServerOptions, + private view: EditorView + ) { this.client = options.client this.documentVersion = 0 diff --git a/packages/codemirror-lsp-client/src/plugin/semantic-tokens.ts b/packages/codemirror-lsp-client/src/plugin/semantic-tokens.ts index 02af94d33..4ed17b0e4 100644 --- a/packages/codemirror-lsp-client/src/plugin/semantic-tokens.ts +++ b/packages/codemirror-lsp-client/src/plugin/semantic-tokens.ts @@ -1,10 +1,12 @@ import { highlightingFor } from '@codemirror/language' -import { StateEffect, StateField, Extension } from '@codemirror/state' -import { EditorView, Decoration, DecorationSet } from '@codemirror/view' +import type { Extension } from '@codemirror/state' +import { StateEffect, StateField } from '@codemirror/state' +import type { DecorationSet } from '@codemirror/view' +import { Decoration, EditorView } from '@codemirror/view' +import type { Tag } from '@lezer/highlight' +import { tags } from '@lezer/highlight' -import { Tag, tags } from '@lezer/highlight' - -import { lspSemanticTokensEvent } from './lsp' +import { lspSemanticTokensEvent } from './annotation' export interface SemanticToken { from: number diff --git a/packages/codemirror-lsp-client/src/plugin/util.ts b/packages/codemirror-lsp-client/src/plugin/util.ts index f70e429f3..53fa1fbe3 100644 --- a/packages/codemirror-lsp-client/src/plugin/util.ts +++ b/packages/codemirror-lsp-client/src/plugin/util.ts @@ -1,7 +1,8 @@ -import { Text } from '@codemirror/state' -import { Marked, MarkedOptions } from '@ts-stack/markdown' - +import type { Text } from '@codemirror/state' +import type { MarkedOptions } from '@ts-stack/markdown' +import { Marked } from '@ts-stack/markdown' import type * as LSP from 'vscode-languageserver-protocol' + import { isArray } from '../lib/utils' // takes a function and executes it after the wait time, if the function is called again before the wait time is up, the timer is reset diff --git a/rust/kcl-language-server/client/src/bootstrap.ts b/rust/kcl-language-server/client/src/bootstrap.ts index 77d5e0f04..fdda77e8f 100644 --- a/rust/kcl-language-server/client/src/bootstrap.ts +++ b/rust/kcl-language-server/client/src/bootstrap.ts @@ -1,10 +1,11 @@ /* eslint suggest-no-throw/suggest-no-throw: 0 */ -import * as vscode from 'vscode' -import * as os from 'os' -import type { Config } from './config' -import { log, isValidExecutable } from './util' -import type { PersistentState } from './persistent_state' import { exec } from 'child_process' +import * as os from 'os' +import * as vscode from 'vscode' + +import type { Config } from './config' +import type { PersistentState } from './persistent_state' +import { isValidExecutable, log } from './util' export async function bootstrap( context: vscode.ExtensionContext, diff --git a/rust/kcl-language-server/client/src/client.ts b/rust/kcl-language-server/client/src/client.ts index 968fe7d65..772103c34 100644 --- a/rust/kcl-language-server/client/src/client.ts +++ b/rust/kcl-language-server/client/src/client.ts @@ -1,6 +1,6 @@ /* eslint suggest-no-throw/suggest-no-throw: 0 */ -import * as lc from 'vscode-languageclient/node' import type * as vscode from 'vscode' +import * as lc from 'vscode-languageclient/node' export async function createClient( traceOutputChannel: vscode.OutputChannel, diff --git a/rust/kcl-language-server/client/src/commands.ts b/rust/kcl-language-server/client/src/commands.ts index b51c8ec53..31b629399 100644 --- a/rust/kcl-language-server/client/src/commands.ts +++ b/rust/kcl-language-server/client/src/commands.ts @@ -1,8 +1,8 @@ /* eslint suggest-no-throw/suggest-no-throw: 0 */ +import { spawnSync } from 'child_process' import * as vscode from 'vscode' import type { Cmd, CtxInit } from './ctx' -import { spawnSync } from 'child_process' export function serverVersion(ctx: CtxInit): Cmd { return async () => { diff --git a/rust/kcl-language-server/client/src/config.ts b/rust/kcl-language-server/client/src/config.ts index 49ad5addd..7a96d42e7 100644 --- a/rust/kcl-language-server/client/src/config.ts +++ b/rust/kcl-language-server/client/src/config.ts @@ -1,10 +1,11 @@ /* eslint suggest-no-throw/suggest-no-throw: 0 */ -import * as Is from 'vscode-languageclient/lib/common/utils/is' import * as os from 'os' import * as path from 'path' import * as vscode from 'vscode' -import { log, type Env } from './util' +import * as Is from 'vscode-languageclient/lib/common/utils/is' + import { expectNotUndefined, unwrapUndefinable } from './undefinable' +import { type Env, log } from './util' export type RunnableEnvCfgItem = { mask?: string diff --git a/rust/kcl-language-server/client/src/ctx.ts b/rust/kcl-language-server/client/src/ctx.ts index 7ebe3f7af..ffe4100a5 100644 --- a/rust/kcl-language-server/client/src/ctx.ts +++ b/rust/kcl-language-server/client/src/ctx.ts @@ -1,20 +1,20 @@ /* eslint suggest-no-throw/suggest-no-throw: 0 */ import * as vscode from 'vscode' import type * as lc from 'vscode-languageclient/node' +import { TransportKind } from 'vscode-languageclient/node' -import { Config, prepareVSCodeConfig } from './config' +import { bootstrap } from './bootstrap' import { createClient } from './client' -import { - isKclDocument, - isKclEditor, - LazyOutputChannel, - log, - type KclEditor, -} from './util' +import { Config, prepareVSCodeConfig } from './config' import type { ServerStatusParams } from './lsp_ext' import { PersistentState } from './persistent_state' -import { bootstrap } from './bootstrap' -import { TransportKind } from 'vscode-languageclient/node' +import { + type KclEditor, + LazyOutputChannel, + isKclDocument, + isKclEditor, + log, +} from './util' // We only support local folders, not eg. Live Share (`vlsl:` scheme), so don't activate if // only those are in use. We use "Empty" to represent these scenarios diff --git a/rust/kcl-language-server/client/src/persistent_state.ts b/rust/kcl-language-server/client/src/persistent_state.ts index ae9e60204..14c02e1d1 100644 --- a/rust/kcl-language-server/client/src/persistent_state.ts +++ b/rust/kcl-language-server/client/src/persistent_state.ts @@ -1,5 +1,6 @@ /* eslint suggest-no-throw/suggest-no-throw: 0 */ import type * as vscode from 'vscode' + import { log } from './util' export class PersistentState { diff --git a/rust/kcl-language-server/client/src/test/runTest.ts b/rust/kcl-language-server/client/src/test/runTest.ts index 542d5903e..7467c59a4 100644 --- a/rust/kcl-language-server/client/src/test/runTest.ts +++ b/rust/kcl-language-server/client/src/test/runTest.ts @@ -1,6 +1,5 @@ -import * as path from 'path' - import { runTests } from '@vscode/test-electron' +import * as path from 'path' async function main() { try { diff --git a/rust/kcl-language-server/client/src/test/suite/extension.test.ts b/rust/kcl-language-server/client/src/test/suite/extension.test.ts index d28ece25b..42b002018 100644 --- a/rust/kcl-language-server/client/src/test/suite/extension.test.ts +++ b/rust/kcl-language-server/client/src/test/suite/extension.test.ts @@ -1,8 +1,8 @@ import * as assert from 'assert' - // You can import and use all API from the 'vscode' module // as well as import your extension to test it import * as vscode from 'vscode' + // import * as myExtension from '../../extension'; suite('Extension Test Suite', () => { diff --git a/rust/kcl-language-server/client/src/test/suite/index.ts b/rust/kcl-language-server/client/src/test/suite/index.ts index d6681067c..c1c17b03b 100644 --- a/rust/kcl-language-server/client/src/test/suite/index.ts +++ b/rust/kcl-language-server/client/src/test/suite/index.ts @@ -1,4 +1,5 @@ import * as path from 'path' + const Mocha = require('mocha') const { glob } = require('glob') diff --git a/rust/kcl-language-server/client/src/util.ts b/rust/kcl-language-server/client/src/util.ts index 04ad5a1fd..b8e5fa89b 100644 --- a/rust/kcl-language-server/client/src/util.ts +++ b/rust/kcl-language-server/client/src/util.ts @@ -1,8 +1,8 @@ /* eslint suggest-no-throw/suggest-no-throw: 0 */ -import * as vscode from 'vscode' import { strict as nativeAssert } from 'assert' -import { exec, type ExecOptions, spawnSync } from 'child_process' +import { type ExecOptions, exec, spawnSync } from 'child_process' import { inspect } from 'util' +import * as vscode from 'vscode' export interface Env { [name: string]: string diff --git a/src/App.tsx b/src/App.tsx index d6a63dd45..4786ed4c5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,36 +1,43 @@ import { useEffect, useMemo, useRef } from 'react' -import { useHotKeyListener } from './hooks/useHotKeyListener' -import { Stream } from './components/Stream' -import { AppHeader } from './components/AppHeader' -import { useHotkeys } from 'react-hotkeys-hook' -import { useLoaderData, useNavigate } from 'react-router-dom' -import { type IndexLoaderData } from 'lib/types' -import { PATHS } from 'lib/paths' -import { onboardingPaths } from 'routes/Onboarding/paths' -import { useEngineConnectionSubscriptions } from 'hooks/useEngineConnectionSubscriptions' -import { codeManager, engineCommandManager } from 'lib/singletons' -import { useAbsoluteFilePath } from 'hooks/useAbsoluteFilePath' -import { isDesktop } from 'lib/isDesktop' -import { useLspContext } from 'components/LspProvider' -import { ModelingSidebar } from 'components/ModelingSidebar/ModelingSidebar' -import { LowerRightControls } from 'components/LowerRightControls' -import ModalContainer from 'react-modal-promise' -import useHotkeyWrapper from 'lib/hotkeyWrapper' -import Gizmo from 'components/Gizmo' -import { CoreDumpManager } from 'lib/coredump' -import { UnitsMenu } from 'components/UnitsMenu' -import { CameraProjectionToggle } from 'components/CameraProjectionToggle' -import { useCreateFileLinkQuery } from 'hooks/useCreateFileLinkQueryWatcher' -import { maybeWriteToDisk } from 'lib/telemetry' -import { takeScreenshotOfVideoStreamCanvas } from 'lib/screenshot' -import { writeProjectThumbnailFile } from 'lib/desktop' -import { useRouteLoaderData } from 'react-router-dom' -import { useEngineCommands } from 'components/EngineCommands' -import { commandBarActor } from 'machines/commandBarMachine' -import { useToken } from 'machines/appMachine' -import { useSettings } from 'machines/appMachine' -import { rustContext } from 'lib/singletons' import toast from 'react-hot-toast' +import { useHotkeys } from 'react-hotkeys-hook' +import ModalContainer from 'react-modal-promise' +import { + useLoaderData, + useNavigate, + useRouteLoaderData, +} from 'react-router-dom' + +import { AppHeader } from '@src/components/AppHeader' +import { CameraProjectionToggle } from '@src/components/CameraProjectionToggle' +import { useEngineCommands } from '@src/components/EngineCommands' +import Gizmo from '@src/components/Gizmo' +import { LowerRightControls } from '@src/components/LowerRightControls' +import { useLspContext } from '@src/components/LspProvider' +import { ModelingSidebar } from '@src/components/ModelingSidebar/ModelingSidebar' +import { Stream } from '@src/components/Stream' +import { UnitsMenu } from '@src/components/UnitsMenu' +import { useAbsoluteFilePath } from '@src/hooks/useAbsoluteFilePath' +import { useCreateFileLinkQuery } from '@src/hooks/useCreateFileLinkQueryWatcher' +import { useEngineConnectionSubscriptions } from '@src/hooks/useEngineConnectionSubscriptions' +import { useHotKeyListener } from '@src/hooks/useHotKeyListener' +import { CoreDumpManager } from '@src/lib/coredump' +import { writeProjectThumbnailFile } from '@src/lib/desktop' +import useHotkeyWrapper from '@src/lib/hotkeyWrapper' +import { isDesktop } from '@src/lib/isDesktop' +import { PATHS } from '@src/lib/paths' +import { takeScreenshotOfVideoStreamCanvas } from '@src/lib/screenshot' +import { + codeManager, + engineCommandManager, + rustContext, +} from '@src/lib/singletons' +import { maybeWriteToDisk } from '@src/lib/telemetry' +import { type IndexLoaderData } from '@src/lib/types' +import { useSettings, useToken } from '@src/machines/appMachine' +import { commandBarActor } from '@src/machines/commandBarMachine' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + maybeWriteToDisk() .then(() => {}) .catch(() => {}) diff --git a/src/AppState.tsx b/src/AppState.tsx index 7ecb30fdc..61e6d0fff 100644 --- a/src/AppState.tsx +++ b/src/AppState.tsx @@ -1,4 +1,5 @@ -import { createContext, useContext, useState, ReactNode } from 'react' +import type { ReactNode } from 'react' +import { createContext, useContext, useState } from 'react' /* diff --git a/src/Auth.tsx b/src/Auth.tsx index 7281471c2..19fa736a9 100644 --- a/src/Auth.tsx +++ b/src/Auth.tsx @@ -1,5 +1,5 @@ -import { useAuthState } from 'machines/appMachine' -import Loading from './components/Loading' +import Loading from '@src/components/Loading' +import { useAuthState } from '@src/machines/appMachine' // Wrapper around protected routes, used in src/Router.tsx export const Auth = ({ children }: React.PropsWithChildren) => { diff --git a/src/Router.tsx b/src/Router.tsx index b13e97301..16e0a720f 100644 --- a/src/Router.tsx +++ b/src/Router.tsx @@ -1,46 +1,53 @@ -import { App } from './App' +import { useMemo } from 'react' +import toast from 'react-hot-toast' import { + Outlet, + RouterProvider, createBrowserRouter, createHashRouter, - Outlet, redirect, - RouterProvider, } from 'react-router-dom' -import { ErrorPage } from './components/ErrorPage' -import { Settings } from './routes/Settings' -import { Telemetry } from './routes/Telemetry' -import Onboarding, { onboardingRoutes } from './routes/Onboarding' -import SignIn from './routes/SignIn' -import { Auth } from './Auth' -import { isDesktop } from './lib/isDesktop' -import Home from './routes/Home' -import { NetworkContext } from './hooks/useNetworkContext' -import { useNetworkStatus } from './hooks/useNetworkStatus' -import makeUrlPathRelative from './lib/makeUrlPathRelative' -import DownloadAppBanner from 'components/DownloadAppBanner' -import { WasmErrBanner } from 'components/WasmErrBanner' -import { CommandBar } from 'components/CommandBar/CommandBar' -import ModelingMachineProvider from 'components/ModelingMachineProvider' -import FileMachineProvider from 'components/FileMachineProvider' -import { MachineManagerProvider } from 'components/MachineManagerProvider' -import { PATHS } from 'lib/paths' -import { fileLoader, homeLoader, telemetryLoader } from 'lib/routeLoaders' -import LspProvider from 'components/LspProvider' -import { KclContextProvider } from 'lang/KclProvider' -import { ASK_TO_OPEN_QUERY_PARAM, BROWSER_PROJECT_NAME } from 'lib/constants' -import { CoreDumpManager } from 'lib/coredump' -import { codeManager, engineCommandManager } from 'lib/singletons' -import useHotkeyWrapper from 'lib/hotkeyWrapper' -import toast from 'react-hot-toast' -import { coreDump } from 'lang/wasm' -import { useMemo } from 'react' -import { AppStateProvider } from 'AppState' -import { reportRejection } from 'lib/trap' -import { RouteProvider } from 'components/RouteProvider' -import { ProjectsContextProvider } from 'components/ProjectsContextProvider' -import { useToken } from 'machines/appMachine' -import { OpenInDesktopAppHandler } from 'components/OpenInDesktopAppHandler' -import { rustContext } from 'lib/singletons' + +import { App } from '@src/App' +import { AppStateProvider } from '@src/AppState' +import { Auth } from '@src/Auth' +import { CommandBar } from '@src/components/CommandBar/CommandBar' +import DownloadAppBanner from '@src/components/DownloadAppBanner' +import { ErrorPage } from '@src/components/ErrorPage' +import FileMachineProvider from '@src/components/FileMachineProvider' +import LspProvider from '@src/components/LspProvider' +import { MachineManagerProvider } from '@src/components/MachineManagerProvider' +import ModelingMachineProvider from '@src/components/ModelingMachineProvider' +import { OpenInDesktopAppHandler } from '@src/components/OpenInDesktopAppHandler' +import { ProjectsContextProvider } from '@src/components/ProjectsContextProvider' +import { RouteProvider } from '@src/components/RouteProvider' +import { WasmErrBanner } from '@src/components/WasmErrBanner' +import { NetworkContext } from '@src/hooks/useNetworkContext' +import { useNetworkStatus } from '@src/hooks/useNetworkStatus' +import { KclContextProvider } from '@src/lang/KclProvider' +import { coreDump } from '@src/lang/wasm' +import { + ASK_TO_OPEN_QUERY_PARAM, + BROWSER_PROJECT_NAME, +} from '@src/lib/constants' +import { CoreDumpManager } from '@src/lib/coredump' +import useHotkeyWrapper from '@src/lib/hotkeyWrapper' +import { isDesktop } from '@src/lib/isDesktop' +import makeUrlPathRelative from '@src/lib/makeUrlPathRelative' +import { PATHS } from '@src/lib/paths' +import { fileLoader, homeLoader, telemetryLoader } from '@src/lib/routeLoaders' +import { + codeManager, + engineCommandManager, + rustContext, +} from '@src/lib/singletons' +import { reportRejection } from '@src/lib/trap' +import { useToken } from '@src/machines/appMachine' +import Home from '@src/routes/Home' +import Onboarding, { onboardingRoutes } from '@src/routes/Onboarding' +import { Settings } from '@src/routes/Settings' +import SignIn from '@src/routes/SignIn' +import { Telemetry } from '@src/routes/Telemetry' const createRouter = isDesktop() ? createHashRouter : createBrowserRouter diff --git a/src/Toolbar.tsx b/src/Toolbar.tsx index 7a0aa1348..e327a8b8b 100644 --- a/src/Toolbar.tsx +++ b/src/Toolbar.tsx @@ -1,28 +1,29 @@ -import { useRef, useMemo, memo, useCallback, useState } from 'react' -import { isCursorInSketchCommandRange } from 'lang/util' -import { editorManager, kclManager } from 'lib/singletons' -import { useModelingContext } from 'hooks/useModelingContext' -import { useNetworkContext } from 'hooks/useNetworkContext' -import { NetworkHealthState } from 'hooks/useNetworkStatus' -import { ActionButton } from 'components/ActionButton' -import { useKclContext } from 'lang/KclProvider' -import { ActionButtonDropdown } from 'components/ActionButtonDropdown' +import { memo, useCallback, useMemo, useRef, useState } from 'react' import { useHotkeys } from 'react-hotkeys-hook' -import Tooltip from 'components/Tooltip' -import { useAppState } from 'AppState' -import { CustomIcon } from 'components/CustomIcon' -import { - toolbarConfig, + +import { useAppState } from '@src/AppState' +import { ActionButton } from '@src/components/ActionButton' +import { ActionButtonDropdown } from '@src/components/ActionButtonDropdown' +import { CustomIcon } from '@src/components/CustomIcon' +import Tooltip from '@src/components/Tooltip' +import { useModelingContext } from '@src/hooks/useModelingContext' +import { useNetworkContext } from '@src/hooks/useNetworkContext' +import { NetworkHealthState } from '@src/hooks/useNetworkStatus' +import { useKclContext } from '@src/lang/KclProvider' +import { isCursorInFunctionDefinition } from '@src/lang/queryAst' +import { isCursorInSketchCommandRange } from '@src/lang/util' +import { isDesktop } from '@src/lib/isDesktop' +import { openExternalBrowserIfDesktop } from '@src/lib/openWindow' +import { editorManager, kclManager } from '@src/lib/singletons' +import type { ToolbarItem, ToolbarItemCallbackProps, ToolbarItemResolved, ToolbarModeName, -} from 'lib/toolbar' -import { isDesktop } from 'lib/isDesktop' -import { openExternalBrowserIfDesktop } from 'lib/openWindow' -import { isCursorInFunctionDefinition } from 'lang/queryAst' -import { commandBarActor } from 'machines/commandBarMachine' -import { isArray } from 'lib/utils' +} from '@src/lib/toolbar' +import { toolbarConfig } from '@src/lib/toolbar' +import { isArray } from '@src/lib/utils' +import { commandBarActor } from '@src/machines/commandBarMachine' export function Toolbar({ className = '', diff --git a/src/clientSideScene/CameraControls.ts b/src/clientSideScene/CameraControls.ts index 92ae7196d..a25d3bf99 100644 --- a/src/clientSideScene/CameraControls.ts +++ b/src/clientSideScene/CameraControls.ts @@ -1,4 +1,5 @@ -import { cameraMouseDragGuards, MouseGuard } from 'lib/cameraControls' +import type { CameraDragInteractionType_type } from '@kittycad/lib/dist/types/src/models' +import * as TWEEN from '@tweenjs/tween.js' import { Euler, MathUtils, @@ -10,26 +11,34 @@ import { Vector2, Vector3, } from 'three' + +import type { CameraProjectionType } from '@rust/kcl-lib/bindings/CameraProjectionType' + +import { isQuaternionVertical } from '@src/clientSideScene/helpers' import { DEBUG_SHOW_INTERSECTION_PLANE, INTERSECTION_PLANE_LAYER, SKETCH_LAYER, ZOOM_MAGIC_NUMBER, -} from './sceneInfra' -import { - Subscription, +} from '@src/clientSideScene/sceneInfra' +import type { EngineCommand } from '@src/lang/std/artifactGraph' +import type { EngineCommandManager, + Subscription, UnreliableSubscription, -} from 'lang/std/engineConnection' -import { EngineCommand } from 'lang/std/artifactGraph' -import { toSync, uuidv4, getNormalisedCoordinates } from 'lib/utils' -import { deg2Rad } from 'lib/utils2d' -import { isReducedMotion, roundOff, throttle } from 'lib/utils' -import * as TWEEN from '@tweenjs/tween.js' -import { isQuaternionVertical } from './helpers' -import { reportRejection } from 'lib/trap' -import { CameraProjectionType } from '@rust/kcl-lib/bindings/CameraProjectionType' -import { CameraDragInteractionType_type } from '@kittycad/lib/dist/types/src/models' +} from '@src/lang/std/engineConnection' +import type { MouseGuard } from '@src/lib/cameraControls' +import { cameraMouseDragGuards } from '@src/lib/cameraControls' +import { reportRejection } from '@src/lib/trap' +import { + getNormalisedCoordinates, + isReducedMotion, + roundOff, + throttle, + toSync, + uuidv4, +} from '@src/lib/utils' +import { deg2Rad } from '@src/lib/utils2d' const ORTHOGRAPHIC_CAMERA_SIZE = 20 const FRAMES_TO_ANIMATE_IN = 30 diff --git a/src/clientSideScene/ClientSideSceneComp.tsx b/src/clientSideScene/ClientSideSceneComp.tsx index 06c9a70e5..106734c5c 100644 --- a/src/clientSideScene/ClientSideSceneComp.tsx +++ b/src/clientSideScene/ClientSideSceneComp.tsx @@ -1,54 +1,60 @@ -import { useRef, useEffect, useState, useMemo, Fragment } from 'react' -import { useModelingContext } from 'hooks/useModelingContext' +import { Dialog, Popover, Transition } from '@headlessui/react' +import { Fragment, useEffect, useMemo, useRef, useState } from 'react' +import toast from 'react-hot-toast' +import type { InstanceProps } from 'react-modal-promise' +import { create } from 'react-modal-promise' -import { cameraMouseDragGuards } from 'lib/cameraControls' -import { ARROWHEAD, DEBUG_SHOW_BOTH_SCENES } from './sceneInfra' -import { ReactCameraProperties } from './CameraControls' -import { throttle, toSync } from 'lib/utils' -import { - sceneInfra, - kclManager, - codeManager, - editorManager, - sceneEntitiesManager, - engineCommandManager, - rustContext, -} from 'lib/singletons' +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import type { ReactCameraProperties } from '@src/clientSideScene/CameraControls' import { EXTRA_SEGMENT_HANDLE, PROFILE_START, getParentGroup, -} from './sceneEntities' -import { SegmentOverlay, SketchDetails } from 'machines/modelingMachine' -import { findUsesOfTagInPipe, getNodeFromPath } from 'lang/queryAst' +} from '@src/clientSideScene/sceneConstants' import { - CallExpression, - CallExpressionKw, - PathToNode, - Program, - Expr, - parse, - recast, - defaultSourceRange, - resultIsOk, - topLevelRange, -} from 'lang/wasm' -import { CustomIcon, CustomIconName } from 'components/CustomIcon' -import { ConstrainInfo } from 'lang/std/stdTypes' -import { getConstraintInfo, getConstraintInfoKw } from 'lang/std/sketch' -import { Dialog, Popover, Transition } from '@headlessui/react' -import toast from 'react-hot-toast' -import { InstanceProps, create } from 'react-modal-promise' -import { executeAstMock } from 'lang/langHelpers' + ARROWHEAD, + DEBUG_SHOW_BOTH_SCENES, +} from '@src/clientSideScene/sceneInfra' +import { ActionButton } from '@src/components/ActionButton' +import type { CustomIconName } from '@src/components/CustomIcon' +import { CustomIcon } from '@src/components/CustomIcon' +import { useModelingContext } from '@src/hooks/useModelingContext' +import { executeAstMock } from '@src/lang/langHelpers' import { deleteSegmentFromPipeExpression, removeSingleConstraintInfo, -} from 'lang/modifyAst' -import { ActionButton } from 'components/ActionButton' -import { err, reportRejection, trap } from 'lib/trap' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { commandBarActor } from 'machines/commandBarMachine' -import { useSettings } from 'machines/appMachine' +} from '@src/lang/modifyAst' +import { findUsesOfTagInPipe, getNodeFromPath } from '@src/lang/queryAst' +import { getConstraintInfo, getConstraintInfoKw } from '@src/lang/std/sketch' +import type { ConstrainInfo } from '@src/lang/std/stdTypes' +import { topLevelRange } from '@src/lang/util' +import type { + CallExpression, + CallExpressionKw, + Expr, + PathToNode, + Program, +} from '@src/lang/wasm' +import { defaultSourceRange, parse, recast, resultIsOk } from '@src/lang/wasm' +import { cameraMouseDragGuards } from '@src/lib/cameraControls' +import { + codeManager, + editorManager, + engineCommandManager, + kclManager, + rustContext, + sceneEntitiesManager, + sceneInfra, +} from '@src/lib/singletons' +import { err, reportRejection, trap } from '@src/lib/trap' +import { throttle, toSync } from '@src/lib/utils' +import type { useSettings } from '@src/machines/appMachine' +import { commandBarActor } from '@src/machines/commandBarMachine' +import type { + SegmentOverlay, + SketchDetails, +} from '@src/machines/modelingMachine' function useShouldHideScene(): { hideClient: boolean; hideServer: boolean } { const [isCamMoving, setIsCamMoving] = useState(false) @@ -635,8 +641,8 @@ const ConstraintSymbol = ({ implicitDesc ? 'bg-chalkboard-10 dark:bg-chalkboard-100 border-transparent border-0 rounded' : isConstrained - ? 'bg-chalkboard-10 dark:bg-chalkboard-90 dark:hover:bg-chalkboard-80 border-chalkboard-40 dark:border-chalkboard-70 rounded-sm' - : 'bg-primary/30 dark:bg-primary text-primary dark:text-chalkboard-10 dark:border-transparent group-hover:bg-primary/40 group-hover:border-primary/50 group-hover:brightness-125' + ? 'bg-chalkboard-10 dark:bg-chalkboard-90 dark:hover:bg-chalkboard-80 border-chalkboard-40 dark:border-chalkboard-70 rounded-sm' + : 'bg-primary/30 dark:bg-primary text-primary dark:text-chalkboard-10 dark:border-transparent group-hover:bg-primary/40 group-hover:border-primary/50 group-hover:brightness-125' } h-[26px] w-[26px] rounded-sm relative m-0 p-0`} onMouseEnter={() => { editorManager.setHighlightRange([range]) diff --git a/src/clientSideScene/helpers.test.ts b/src/clientSideScene/helpers.test.ts index 1b6a68309..e20f28f42 100644 --- a/src/clientSideScene/helpers.test.ts +++ b/src/clientSideScene/helpers.test.ts @@ -1,5 +1,6 @@ import { Quaternion } from 'three' -import { isQuaternionVertical } from './helpers' + +import { isQuaternionVertical } from '@src/clientSideScene/helpers' describe('isQuaternionVertical', () => { it('should identify vertical quaternions', () => { diff --git a/src/clientSideScene/helpers.ts b/src/clientSideScene/helpers.ts index e938fa2c5..b99c3e9ed 100644 --- a/src/clientSideScene/helpers.ts +++ b/src/clientSideScene/helpers.ts @@ -1,15 +1,13 @@ -import { compareVec2Epsilon2 } from 'lang/std/sketch' +import type { Group, Mesh, OrthographicCamera, Quaternion } from 'three' import { GridHelper, LineBasicMaterial, - OrthographicCamera, PerspectiveCamera, - Group, - Mesh, - Quaternion, Vector3, } from 'three' +import { compareVec2Epsilon2 } from '@src/lang/std/sketch' + export function createGridHelper({ size, divisions, diff --git a/src/clientSideScene/sceneConstants.ts b/src/clientSideScene/sceneConstants.ts new file mode 100644 index 000000000..4e1dead89 --- /dev/null +++ b/src/clientSideScene/sceneConstants.ts @@ -0,0 +1,76 @@ +// Constants shared between sceneEntities.ts and segments.ts +// This file helps break circular dependencies +import type { Group } from 'three' + +// Segment types +export const ARC_SEGMENT = 'arc-segment' +export const ARC_SEGMENT_BODY = 'arc-segment-body' +export const ARC_SEGMENT_DASH = 'arc-segment-dash' +export const STRAIGHT_SEGMENT = 'straight-segment' +export const STRAIGHT_SEGMENT_BODY = 'straight-segment-body' +export const STRAIGHT_SEGMENT_DASH = 'straight-segment-body-dashed' +export const CIRCLE_SEGMENT = 'circle-segment' +export const CIRCLE_SEGMENT_BODY = 'circle-segment-body' +export const CIRCLE_SEGMENT_DASH = 'circle-segment-body-dashed' +export const TANGENTIAL_ARC_TO_SEGMENT = 'tangential-arc-to-segment' +export const TANGENTIAL_ARC_TO_SEGMENT_BODY = 'tangential-arc-to-segment-body' +export const TANGENTIAL_ARC_TO__SEGMENT_DASH = + 'tangential-arc-to-segment-body-dashed' +export const THREE_POINT_ARC_SEGMENT = 'three-point-arc-segment' +export const THREE_POINT_ARC_SEGMENT_BODY = 'three-point-arc-segment-body' +export const THREE_POINT_ARC_SEGMENT_DASH = 'three-point-arc-segment-dash' +export const CIRCLE_THREE_POINT_SEGMENT = 'circle-three-point-segment' +export const CIRCLE_THREE_POINT_SEGMENT_BODY = 'circle-segment-body' +export const CIRCLE_THREE_POINT_SEGMENT_DASH = + 'circle-three-point-segment-body-dashed' + +// Handle names +export const ARC_ANGLE_END = 'arc-angle-end' +export const ARC_ANGLE_REFERENCE_LINE = 'arc-angle-reference-line' +export const ARC_CENTER_TO_FROM = 'arc-center-to-from' +export const ARC_CENTER_TO_TO = 'arc-center-to-to' +export const CIRCLE_CENTER_HANDLE = 'circle-center-handle' +export const CIRCLE_THREE_POINT_HANDLE1 = 'circle-three-point-handle1' +export const CIRCLE_THREE_POINT_HANDLE2 = 'circle-three-point-handle2' +export const CIRCLE_THREE_POINT_HANDLE3 = 'circle-three-point-handle3' +export const THREE_POINT_ARC_HANDLE2 = 'three-point-arc-handle2' +export const THREE_POINT_ARC_HANDLE3 = 'three-point-arc-handle3' +export const EXTRA_SEGMENT_HANDLE = 'extraSegmentHandle' +export const PROFILE_START = 'profile-start' + +// Additional types +export const DRAFT_DASHED_LINE = 'draft-dashed-line' + +// Measurements +export const EXTRA_SEGMENT_OFFSET_PX = 8 +export const SEGMENT_WIDTH_PX = 1.6 +export const HIDE_SEGMENT_LENGTH = 75 +export const HIDE_HOVER_SEGMENT_LENGTH = 60 + +// Segment groups +export const SEGMENT_BODIES = [ + STRAIGHT_SEGMENT, + TANGENTIAL_ARC_TO_SEGMENT, + CIRCLE_SEGMENT, + CIRCLE_THREE_POINT_SEGMENT, + ARC_SEGMENT, + THREE_POINT_ARC_SEGMENT, +] + +export const SEGMENT_BODIES_PLUS_PROFILE_START = [ + ...SEGMENT_BODIES, + PROFILE_START, +] + +// Helper functions +export function getParentGroup( + object: any, + stopAt: string[] = SEGMENT_BODIES +): Group | null { + if (stopAt.includes(object?.userData?.type)) { + return object + } else if (object?.parent) { + return getParentGroup(object.parent, stopAt) + } + return null +} diff --git a/src/clientSideScene/sceneEntities.ts b/src/clientSideScene/sceneEntities.ts index e2181ed94..697bfc773 100644 --- a/src/clientSideScene/sceneEntities.ts +++ b/src/clientSideScene/sceneEntities.ts @@ -1,189 +1,171 @@ +import toast from 'react-hot-toast' +import type { + Intersection, + Object3D, + Object3DEventMap, + Quaternion, +} from 'three' import { BoxGeometry, DoubleSide, + ExtrudeGeometry, Group, - Intersection, + LineCurve3, Mesh, MeshBasicMaterial, - Object3D, - Object3DEventMap, OrthographicCamera, PerspectiveCamera, PlaneGeometry, Points, - Quaternion, + Shape, Vector2, Vector3, - Shape, - LineCurve3, - ExtrudeGeometry, } from 'three' +import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer' +import { radToDeg } from 'three/src/math/MathUtils' + +import type { Models } from '@kittycad/lib/dist/types/src' +import type { CallExpression } from '@rust/kcl-lib/bindings/CallExpression' +import type { CallExpressionKw } from '@rust/kcl-lib/bindings/CallExpressionKw' +import type { Node } from '@rust/kcl-lib/bindings/Node' +import type { Path } from '@rust/kcl-lib/bindings/Path' +import type { PipeExpression } from '@rust/kcl-lib/bindings/PipeExpression' +import type { Point3d } from '@rust/kcl-lib/bindings/Point3d' +import type { Program } from '@rust/kcl-lib/bindings/Program' +import type { Sketch } from '@rust/kcl-lib/bindings/Sketch' +import type { SourceRange } from '@rust/kcl-lib/bindings/SourceRange' +import type { VariableDeclaration } from '@rust/kcl-lib/bindings/VariableDeclaration' +import type { VariableDeclarator } from '@rust/kcl-lib/bindings/VariableDeclarator' +import { uuidv4 } from '@src/lib/utils' + +import { + createGridHelper, + isQuaternionVertical, + orthoScale, + perspScale, + quaternionFromUpNForward, +} from '@src/clientSideScene/helpers' +import { + ARC_ANGLE_END, + ARC_SEGMENT, + CIRCLE_CENTER_HANDLE, + CIRCLE_SEGMENT, + CIRCLE_THREE_POINT_HANDLE1, + CIRCLE_THREE_POINT_HANDLE2, + CIRCLE_THREE_POINT_HANDLE3, + CIRCLE_THREE_POINT_SEGMENT, + DRAFT_DASHED_LINE, + EXTRA_SEGMENT_HANDLE, + PROFILE_START, + SEGMENT_BODIES, + SEGMENT_BODIES_PLUS_PROFILE_START, + SEGMENT_WIDTH_PX, + STRAIGHT_SEGMENT, + STRAIGHT_SEGMENT_DASH, + TANGENTIAL_ARC_TO_SEGMENT, + THREE_POINT_ARC_HANDLE2, + THREE_POINT_ARC_HANDLE3, + THREE_POINT_ARC_SEGMENT, + getParentGroup, +} from '@src/clientSideScene/sceneConstants' +import type { + OnClickCallbackArgs, + OnMouseEnterLeaveArgs, + SceneInfra, +} from '@src/clientSideScene/sceneInfra' import { ANGLE_SNAP_THRESHOLD_DEGREES, ARROWHEAD, AXIS_GROUP, DRAFT_POINT, DRAFT_POINT_GROUP, - getSceneScale, INTERSECTION_PLANE_LAYER, - OnClickCallbackArgs, - OnMouseEnterLeaveArgs, RAYCASTABLE_PLANE, SKETCH_GROUP_SEGMENTS, SKETCH_LAYER, X_AXIS, Y_AXIS, -} from './sceneInfra' -import { isQuaternionVertical, quaternionFromUpNForward } from './helpers' -import { - CallExpression, - parse, - Path, - PathToNode, - PipeExpression, - Program, - recast, - Sketch, - VariableDeclaration, - VariableDeclarator, - sketchFromKclValue, - defaultSourceRange, - sourceRangeFromRust, - resultIsOk, - SourceRange, - topLevelRange, - CallExpressionKw, - VariableMap, -} from 'lang/wasm' -import { - engineCommandManager, - kclManager, - sceneInfra, - codeManager, - editorManager, - rustContext, -} from 'lib/singletons' -import { getNodeFromPath } from 'lang/queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { executeAstMock, ToolTip } from 'lang/langHelpers' + getSceneScale, +} from '@src/clientSideScene/sceneInfra' +import type { SegmentUtils } from '@src/clientSideScene/segments' import { createProfileStartHandle, dashedStraight, - SegmentUtils, segmentUtils, -} from './segments' -import { - addCallExpressionsToPipe, - addCloseToPipe, - addNewSketchLn, - ARG_END_ABSOLUTE, - changeSketchArguments, - Coords2d, - updateStartProfileAtArgs, -} from 'lang/std/sketch' -import { isArray, isOverlap, roundOff } from 'lib/utils' +} from '@src/clientSideScene/segments' +import type EditorManager from '@src/editor/manager' +import type CodeManager from '@src/lang/codeManager' +import { ARG_END_ABSOLUTE } from '@src/lang/constants' import { createArrayExpression, createCallExpressionStdLib, - createLocalName, createCallExpressionStdLibKw, createLabeledArg, createLiteral, - createNodeFromExprSnippet, + createLocalName, createPipeExpression, createPipeSubstitution, createVariableDeclaration, findUniqueName, +} from '@src/lang/create' +import type { KclManager } from '@src/lang/KclSingleton' +import type { ToolTip } from '@src/lang/langHelpers' +import { executeAstMock } from '@src/lang/langHelpers' +import { updateModelingState } from '@src/lang/modelingWorkflows' +import { + createNodeFromExprSnippet, getInsertIndex, insertNewStartProfileAt, updateSketchNodePathsWithInsertIndex, -} from 'lang/modifyAst' -import { Selections, getEventForSegmentSelection } from 'lib/selections' -import { createGridHelper, orthoScale, perspScale } from './helpers' -import { Models } from '@kittycad/lib' -import { uuidv4 } from 'lib/utils' +} from '@src/lang/modifyAst' +import { getNodeFromPath } from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' import { + codeRefFromRange, + getArtifactFromRange, +} from '@src/lang/std/artifactGraph' +import type { EngineCommandManager } from '@src/lang/std/engineConnection' +import type { Coords2d } from '@src/lang/std/sketch' +import { + addCallExpressionsToPipe, + addCloseToPipe, + addNewSketchLn, + changeSketchArguments, + updateStartProfileAtArgs, +} from '@src/lang/std/sketch' +import type { SegmentInputs } from '@src/lang/std/stdTypes' +import { topLevelRange } from '@src/lang/util' +import type { PathToNode, VariableMap } from '@src/lang/wasm' +import { + defaultSourceRange, + parse, + recast, + resultIsOk, + sketchFromKclValue, + sourceRangeFromRust, +} from '@src/lang/wasm' +import { EXECUTION_TYPE_MOCK } from '@src/lib/constants' +import { + getRectangleCallExpressions, + updateCenterRectangleSketch, + updateRectangleSketch, +} from '@src/lib/rectangleTool' +import type RustContext from '@src/lib/rustContext' +import type { Selections } from '@src/lib/selections' +import { getEventForSegmentSelection } from '@src/lib/selections' +import type { Themes } from '@src/lib/theme' +import { getThemeColorForThreeJs } from '@src/lib/theme' +import { err, reportRejection, trap } from '@src/lib/trap' +import { isArray, isOverlap, roundOff } from '@src/lib/utils' +import type { SegmentOverlayPayload, SketchDetails, SketchDetailsUpdate, SketchTool, -} from 'machines/modelingMachine' -import { EngineCommandManager } from 'lang/std/engineConnection' -import { - getRectangleCallExpressions, - updateRectangleSketch, - updateCenterRectangleSketch, -} from 'lib/rectangleTool' -import { getThemeColorForThreeJs, Themes } from 'lib/theme' -import { err, reportRejection, trap } from 'lib/trap' -import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer' -import { Point3d } from '@rust/kcl-lib/bindings/Point3d' -import { SegmentInputs } from 'lang/std/stdTypes' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { radToDeg } from 'three/src/math/MathUtils' -import toast from 'react-hot-toast' -import { getArtifactFromRange, codeRefFromRange } from 'lang/std/artifactGraph' -import { updateModelingState } from 'lang/modelingWorkflows' -import { EXECUTION_TYPE_MOCK } from 'lib/constants' +} from '@src/machines/modelingMachine' type DraftSegment = 'line' | 'tangentialArcTo' -export const EXTRA_SEGMENT_HANDLE = 'extraSegmentHandle' -export const EXTRA_SEGMENT_OFFSET_PX = 8 -export const PROFILE_START = 'profile-start' - -export const DRAFT_DASHED_LINE = 'draft-dashed-line' - -export const STRAIGHT_SEGMENT = 'straight-segment' -export const STRAIGHT_SEGMENT_BODY = 'straight-segment-body' -export const STRAIGHT_SEGMENT_DASH = 'straight-segment-body-dashed' -export const TANGENTIAL_ARC_TO__SEGMENT_DASH = - 'tangential-arc-to-segment-body-dashed' -export const TANGENTIAL_ARC_TO_SEGMENT = 'tangential-arc-to-segment' -export const TANGENTIAL_ARC_TO_SEGMENT_BODY = 'tangential-arc-to-segment-body' -export const CIRCLE_THREE_POINT_SEGMENT = 'circle-three-point-segment' -export const CIRCLE_THREE_POINT_SEGMENT_BODY = 'circle-segment-body' -export const CIRCLE_THREE_POINT_SEGMENT_DASH = - 'circle-three-point-segment-body-dashed' -export const CIRCLE_THREE_POINT_HANDLE1 = 'circle-three-point-handle1' -export const CIRCLE_THREE_POINT_HANDLE2 = 'circle-three-point-handle2' -export const CIRCLE_THREE_POINT_HANDLE3 = 'circle-three-point-handle3' -export const CIRCLE_SEGMENT = 'circle-segment' -export const CIRCLE_SEGMENT_BODY = 'circle-segment-body' -export const CIRCLE_SEGMENT_DASH = 'circle-segment-body-dashed' -export const CIRCLE_CENTER_HANDLE = 'circle-center-handle' -export const SEGMENT_WIDTH_PX = 1.6 - -// Arc segment constants -export const ARC_SEGMENT = 'arc-segment' -export const ARC_SEGMENT_BODY = 'arc-segment-body' -export const ARC_SEGMENT_DASH = 'arc-segment-dash' -export const ARC_ANGLE_END = 'arc-angle-end' -export const ARC_CENTER_TO_FROM = 'arc-center-to-from' -export const ARC_CENTER_TO_TO = 'arc-center-to-to' -export const ARC_ANGLE_REFERENCE_LINE = 'arc-angle-reference-line' - -export const THREE_POINT_ARC_SEGMENT = 'three-point-arc-segment' -export const THREE_POINT_ARC_SEGMENT_BODY = 'three-point-arc-segment-body' -export const THREE_POINT_ARC_SEGMENT_DASH = 'three-point-arc-segment-dash' -export const THREE_POINT_ARC_HANDLE2 = 'three-point-arc-handle2' -export const THREE_POINT_ARC_HANDLE3 = 'three-point-arc-handle3' - -export const HIDE_SEGMENT_LENGTH = 75 // in pixels -export const HIDE_HOVER_SEGMENT_LENGTH = 60 // in pixels -export const SEGMENT_BODIES = [ - STRAIGHT_SEGMENT, - TANGENTIAL_ARC_TO_SEGMENT, - CIRCLE_SEGMENT, - CIRCLE_THREE_POINT_SEGMENT, - ARC_SEGMENT, - THREE_POINT_ARC_SEGMENT, -] -export const SEGMENT_BODIES_PLUS_PROFILE_START = [ - ...SEGMENT_BODIES, - PROFILE_START, -] - type Vec3Array = [number, number, number] // This singleton Class is responsible for all of the things the user sees and interacts with. @@ -191,15 +173,34 @@ type Vec3Array = [number, number, number] // Cameras, controls, raycasters, etc are handled by sceneInfra export class SceneEntities { readonly engineCommandManager: EngineCommandManager + readonly sceneInfra: SceneInfra + readonly editorManager: EditorManager + readonly codeManager: CodeManager + readonly kclManager: KclManager + readonly rustContext: RustContext activeSegments: { [key: string]: Group } = {} readonly intersectionPlane: Mesh axisGroup: Group | null = null draftPointGroups: Group[] = [] currentSketchQuaternion: Quaternion | null = null - constructor(engineCommandManager: EngineCommandManager) { + constructor( + engineCommandManager: EngineCommandManager, + sceneInfra: SceneInfra, + editorManager: EditorManager, + codeManager: CodeManager, + kclManager: KclManager, + rustContext: RustContext + ) { this.engineCommandManager = engineCommandManager - this.intersectionPlane = SceneEntities.createIntersectionPlane() - sceneInfra.camControls.subscribeToCamChange(this.onCamChange) + this.sceneInfra = sceneInfra + this.editorManager = editorManager + this.codeManager = codeManager + this.kclManager = kclManager + this.rustContext = rustContext + this.intersectionPlane = SceneEntities.createIntersectionPlane( + this.sceneInfra + ) + this.sceneInfra.camControls.subscribeToCamChange(this.onCamChange) window.addEventListener('resize', this.onWindowResize) } @@ -207,14 +208,14 @@ export class SceneEntities { this.onCamChange() } onCamChange = () => { - const orthoFactor = orthoScale(sceneInfra.camControls.camera) + const orthoFactor = orthoScale(this.sceneInfra.camControls.camera) const callbacks: (() => SegmentOverlayPayload | null)[] = [] Object.values(this.activeSegments).forEach((segment, index) => { const factor = - (sceneInfra.camControls.camera instanceof OrthographicCamera + (this.sceneInfra.camControls.camera instanceof OrthographicCamera ? orthoFactor - : perspScale(sceneInfra.camControls.camera, segment)) / - sceneInfra._baseUnitMultiplier + : perspScale(this.sceneInfra.camControls.camera, segment)) / + this.sceneInfra._baseUnitMultiplier let input: SegmentInputs = { type: 'straight-segment', from: segment.userData.from, @@ -307,7 +308,7 @@ export class SceneEntities { input, group: segment, scale: factor, - sceneInfra, + sceneInfra: this.sceneInfra, }) callBack && !err(callBack) && callbacks.push(callBack) if (segment.name === PROFILE_START) { @@ -316,18 +317,18 @@ export class SceneEntities { }) if (this.axisGroup) { const factor = - sceneInfra.camControls.camera instanceof OrthographicCamera + this.sceneInfra.camControls.camera instanceof OrthographicCamera ? orthoFactor - : perspScale(sceneInfra.camControls.camera, this.axisGroup) + : perspScale(this.sceneInfra.camControls.camera, this.axisGroup) const x = this.axisGroup.getObjectByName(X_AXIS) - x?.scale.set(1, factor / sceneInfra._baseUnitMultiplier, 1) + x?.scale.set(1, factor / this.sceneInfra._baseUnitMultiplier, 1) const y = this.axisGroup.getObjectByName(Y_AXIS) - y?.scale.set(factor / sceneInfra._baseUnitMultiplier, 1, 1) + y?.scale.set(factor / this.sceneInfra._baseUnitMultiplier, 1, 1) } - sceneInfra.overlayCallbacks(callbacks) + this.sceneInfra.overlayCallbacks(callbacks) } - private static createIntersectionPlane() { + private static createIntersectionPlane(sceneInfra: SceneInfra) { const hundredM = 100_0000 const planeGeometry = new PlaneGeometry(hundredM, hundredM) const planeMaterial = new MeshBasicMaterial({ @@ -349,7 +350,7 @@ export class SceneEntities { up: [number, number, number], sketchPosition?: [number, number, number] ) { - const orthoFactor = orthoScale(sceneInfra.camControls.camera) + const orthoFactor = orthoScale(this.sceneInfra.camControls.camera) const baseXColor = 0x000055 const baseYColor = 0x550000 const axisPixelWidth = 1.6 @@ -391,17 +392,17 @@ export class SceneEntities { gridHelper.renderOrder = -3 // is this working? gridHelper.name = 'gridHelper' const sceneScale = getSceneScale( - sceneInfra.camControls.camera, - sceneInfra.camControls.target + this.sceneInfra.camControls.camera, + this.sceneInfra.camControls.target ) gridHelper.scale.set(sceneScale, sceneScale, sceneScale) const factor = - sceneInfra.camControls.camera instanceof OrthographicCamera + this.sceneInfra.camControls.camera instanceof OrthographicCamera ? orthoFactor - : perspScale(sceneInfra.camControls.camera, this.axisGroup) - xAxisMesh?.scale.set(1, factor / sceneInfra._baseUnitMultiplier, 1) - yAxisMesh?.scale.set(factor / sceneInfra._baseUnitMultiplier, 1, 1) + : perspScale(this.sceneInfra.camControls.camera, this.axisGroup) + xAxisMesh?.scale.set(1, factor / this.sceneInfra._baseUnitMultiplier, 1) + yAxisMesh?.scale.set(factor / this.sceneInfra._baseUnitMultiplier, 1, 1) this.axisGroup.add(xAxisMesh, yAxisMesh, gridHelper) this.currentSketchQuaternion && @@ -420,10 +421,10 @@ export class SceneEntities { ) this.axisGroup.setRotationFromQuaternion(quat) sketchPosition && this.axisGroup.position.set(...sketchPosition) - sceneInfra.scene.add(this.axisGroup) + this.sceneInfra.scene.add(this.axisGroup) } getDraftPoint() { - return sceneInfra.scene.getObjectByName(DRAFT_POINT) + return this.sceneInfra.scene.getObjectByName(DRAFT_POINT) } createDraftPoint({ point, @@ -449,16 +450,16 @@ export class SceneEntities { new Vector3(...zAxis) ) draftPointGroup.setRotationFromQuaternion(currentSketchQuaternion) - sceneInfra.scene.add(draftPointGroup) + this.sceneInfra.scene.add(draftPointGroup) const dummy = new Mesh() dummy.position.set(0, 0, 0) - const scale = sceneInfra.getClientSceneScaleFactor(dummy) + const scale = this.sceneInfra.getClientSceneScaleFactor(dummy) const draftPoint = createProfileStartHandle({ isDraft: true, from: [point.x, point.y], scale, - theme: sceneInfra._theme, + theme: this.sceneInfra._theme, // default is 12, this makes the draft point pop a bit more, // especially when snapping to the startProfileAt handle as it's it was the exact same size size: 16, @@ -505,7 +506,7 @@ export class SceneEntities { this.intersectionPlane.position.copy( new Vector3(...(sketchDetails?.origin || [0, 0, 0])) ) - sceneInfra.setCallbacks({ + this.sceneInfra.setCallbacks({ onMove: (args) => { if (!args.intersects.length) return const axisIntersection = args.intersects.find( @@ -570,7 +571,7 @@ export class SceneEntities { this.removeDraftPoint() if (!args) return // If there is a valid camera interaction that matches, do that instead - const interaction = sceneInfra.camControls.getInteractionType( + const interaction = this.sceneInfra.camControls.getInteractionType( args.mouseEvent ) if (interaction !== 'none') return @@ -610,7 +611,7 @@ export class SceneEntities { } const inserted = insertNewStartProfileAt( - kclManager.ast, + this.kclManager.ast, sketchDetails.sketchEntryNodePath || [], sketchDetails.sketchNodePaths, sketchDetails.planeNodePath, @@ -621,7 +622,7 @@ export class SceneEntities { if (trap(inserted)) return const { modifiedAst } = inserted - await kclManager.updateAst(modifiedAst, false) + await this.kclManager.updateAst(modifiedAst, false) // Now perform the caller-specified action afterClick(args, { @@ -660,12 +661,13 @@ export class SceneEntities { const { execState } = await executeAstMock({ ast: truncatedAst, - rustContext, + rustContext: this.rustContext, }) const sketchesInfo = getSketchesInfo({ sketchNodePaths, ast: maybeModdedAst, variables: execState.variables, + kclManager: this.kclManager, }) const group = new Group() @@ -677,7 +679,7 @@ export class SceneEntities { const dummy = new Mesh() // TODO: When we actually have sketch positions and rotations we can use them here. dummy.position.set(0, 0, 0) - const scale = sceneInfra.getClientSceneScaleFactor(dummy) + const scale = this.sceneInfra.getClientSceneScaleFactor(dummy) const callbacks: (() => SegmentOverlayPayload | null)[] = [] @@ -696,7 +698,7 @@ export class SceneEntities { id: sketch.start.__geoMeta.id, pathToNode: segPathToNode, scale, - theme: sceneInfra._theme, + theme: this.sceneInfra._theme, isDraft: false, }) _profileStart.layers.set(SKETCH_LAYER) @@ -758,14 +760,14 @@ export class SceneEntities { segment.type === 'TangentialArcTo' ? segmentUtils.tangentialArcTo.init : segment.type === 'Circle' - ? segmentUtils.circle.init - : segment.type === 'Arc' - ? segmentUtils.arc.init - : segment.type === 'CircleThreePoint' - ? segmentUtils.circleThreePoint.init - : segment.type === 'ArcThreePoint' - ? segmentUtils.threePointArc.init - : segmentUtils.straight.init + ? segmentUtils.circle.init + : segment.type === 'Arc' + ? segmentUtils.arc.init + : segment.type === 'CircleThreePoint' + ? segmentUtils.circleThreePoint.init + : segment.type === 'ArcThreePoint' + ? segmentUtils.threePointArc.init + : segmentUtils.straight.init const input: SegmentInputs = segment.type === 'Circle' ? { @@ -777,33 +779,34 @@ export class SceneEntities { radius: segment.radius, } : segment.type === 'CircleThreePoint' || - segment.type === 'ArcThreePoint' - ? { - type: 'circle-three-point-segment', - p1: segment.p1, - p2: segment.p2, - p3: segment.p3, - } - : segment.type === 'Arc' - ? { - type: 'arc-segment', - from: segment.from, - center: segment.center, - to: segment.to, - ccw: segment.ccw, - radius: segment.radius, - } - : { - type: 'straight-segment', - from: segment.from, - to: segment.to, - } + segment.type === 'ArcThreePoint' + ? { + type: 'circle-three-point-segment', + p1: segment.p1, + p2: segment.p2, + p3: segment.p3, + } + : segment.type === 'Arc' + ? { + type: 'arc-segment', + from: segment.from, + center: segment.center, + to: segment.to, + ccw: segment.ccw, + radius: segment.radius, + } + : { + type: 'straight-segment', + from: segment.from, + to: segment.to, + } const startRange = _node1.node.start const endRange = _node1.node.end const sourceRange: SourceRange = [startRange, endRange, 0] const selection: Selections = computeSelectionFromSourceRangeAndAST( sourceRange, - maybeModdedAst + maybeModdedAst, + this.kclManager ) const result = initSegment({ prevSegment: sketch.paths[index - 1], @@ -813,10 +816,10 @@ export class SceneEntities { pathToNode: segPathToNode, isDraftSegment, scale, - texture: sceneInfra.extraSegmentTexture, - theme: sceneInfra._theme, + texture: this.sceneInfra.extraSegmentTexture, + theme: this.sceneInfra._theme, isSelected, - sceneInfra, + sceneInfra: this.sceneInfra, selection, }) if (err(result)) return @@ -845,9 +848,9 @@ export class SceneEntities { this.currentSketchQuaternion ) position && this.intersectionPlane.position.set(...position) - sceneInfra.scene.add(group) - sceneInfra.camControls.enableRotate = false - sceneInfra.overlayCallbacks(callbacks) + this.sceneInfra.scene.add(group) + this.sceneInfra.camControls.enableRotate = false + this.sceneInfra.overlayCallbacks(callbacks) return { truncatedAst, @@ -864,9 +867,9 @@ export class SceneEntities { origin: [number, number, number] ) => { if (trap(modifiedAst)) return Promise.reject(modifiedAst) - const nextAst = await kclManager.updateAst(modifiedAst, false) + const nextAst = await this.kclManager.updateAst(modifiedAst, false) this.tearDownSketch({ removeAxis: false }) - sceneInfra.resetMouseListeners() + this.sceneInfra.resetMouseListeners() await this.setupSketch({ sketchEntryNodePath, sketchNodePaths, @@ -903,7 +906,7 @@ export class SceneEntities { segmentName: 'line' | 'tangentialArcTo' = 'line', shouldTearDown = true ) => { - const _ast = structuredClone(kclManager.ast) + const _ast = structuredClone(this.kclManager.ast) const _node1 = getNodeFromPath( _ast, @@ -914,7 +917,7 @@ export class SceneEntities { const variableDeclarationName = _node1.node?.declaration.id?.name || '' const sg = sketchFromKclValue( - kclManager.variables[variableDeclarationName], + this.kclManager.variables[variableDeclarationName], variableDeclarationName ) if (err(sg)) return Promise.reject(sg) @@ -923,7 +926,7 @@ export class SceneEntities { const index = sg.paths.length // because we've added a new segment that's not in the memory yet, no need for `.length -1` const mod = addNewSketchLn({ node: _ast, - variables: kclManager.variables, + variables: this.kclManager.variables, input: { type: 'straight-segment', to: lastSeg.to, @@ -940,7 +943,7 @@ export class SceneEntities { const draftExpressionsIndices = { start: index, end: index } if (shouldTearDown) this.tearDownSketch({ removeAxis: false }) - sceneInfra.resetMouseListeners() + this.sceneInfra.resetMouseListeners() const { truncatedAst } = await this.setupSketch({ sketchEntryNodePath, @@ -951,11 +954,11 @@ export class SceneEntities { maybeModdedAst: modifiedAst, draftExpressionsIndices, }) - sceneInfra.setCallbacks({ + this.sceneInfra.setCallbacks({ onClick: async (args) => { if (!args) return // If there is a valid camera interaction that matches, do that instead - const interaction = sceneInfra.camControls.getInteractionType( + const interaction = this.sceneInfra.camControls.getInteractionType( args.mouseEvent ) if (interaction !== 'none') return @@ -968,12 +971,15 @@ export class SceneEntities { sketchEntryNodePath ) - let modifiedAst: Node | Error = structuredClone(kclManager.ast) + let modifiedAst: Node | Error = structuredClone( + this.kclManager.ast + ) const sketch = sketchFromPathToNode({ pathToNode: sketchEntryNodePath, - ast: kclManager.ast, - variables: kclManager.variables, + ast: this.kclManager.ast, + variables: this.kclManager.variables, + kclManager: this.kclManager, }) if (err(sketch)) return Promise.reject(sketch) if (!sketch) return Promise.reject(new Error('No sketch found')) @@ -989,8 +995,8 @@ export class SceneEntities { ]), ]) modifiedAst = addCallExpressionsToPipe({ - node: kclManager.ast, - variables: kclManager.variables, + node: this.kclManager.ast, + variables: this.kclManager.variables, pathToNode: sketchEntryNodePath, expressions: [ segmentName === 'tangentialArcTo' @@ -1006,7 +1012,7 @@ export class SceneEntities { if (trap(modifiedAst)) return Promise.reject(modifiedAst) modifiedAst = addCloseToPipe({ node: modifiedAst, - variables: kclManager.variables, + variables: this.kclManager.variables, pathToNode: sketchEntryNodePath, }) if (trap(modifiedAst)) return Promise.reject(modifiedAst) @@ -1059,8 +1065,8 @@ export class SceneEntities { } const tmp = addNewSketchLn({ - node: kclManager.ast, - variables: kclManager.variables, + node: this.kclManager.ast, + variables: this.kclManager.variables, input: { type: 'straight-segment', from: [lastSegment.to[0], lastSegment.to[1]], @@ -1078,13 +1084,13 @@ export class SceneEntities { } await updateModelingState(modifiedAst, EXECUTION_TYPE_MOCK, { - kclManager, - editorManager, - codeManager, + kclManager: this.kclManager, + editorManager: this.editorManager, + codeManager: this.codeManager, }) if (intersectsProfileStart) { - sceneInfra.modelingSend({ type: 'Close sketch' }) + this.sceneInfra.modelingSend({ type: 'Close sketch' }) } else { await this.setupDraftSegment( sketchEntryNodePath, @@ -1132,7 +1138,7 @@ export class SceneEntities { sketchOrigin: [number, number, number], rectangleOrigin: [x: number, y: number] ): Promise => { - let _ast = structuredClone(kclManager.ast) + let _ast = structuredClone(this.kclManager.ast) const varDec = getNodeFromPath( _ast, @@ -1174,7 +1180,7 @@ export class SceneEntities { _ast = pResult.program // do a quick mock execution to get the program memory up-to-date - await kclManager.executeAstMock(_ast) + await this.kclManager.executeAstMock(_ast) const justCreatedNode = getNodeFromPath( _ast, @@ -1207,7 +1213,7 @@ export class SceneEntities { draftExpressionsIndices: { start: 0, end: 3 }, }) - sceneInfra.setCallbacks({ + this.sceneInfra.setCallbacks({ onMove: async (args) => { // Update the width and height of the draft rectangle @@ -1235,12 +1241,12 @@ export class SceneEntities { const { execState } = await executeAstMock({ ast: truncatedAst, - rustContext, + rustContext: this.rustContext, }) const sketch = sketchFromKclValue(execState.variables[varName], varName) if (err(sketch)) return Promise.reject(sketch) const sgPaths = sketch.paths - const orthoFactor = orthoScale(sceneInfra.camControls.camera) + const orthoFactor = orthoScale(this.sceneInfra.camControls.camera) const varDecIndex = Number(updatedEntryNodePath[1][0]) @@ -1275,7 +1281,7 @@ export class SceneEntities { }, onClick: async (args) => { // If there is a valid camera interaction that matches, do that instead - const interaction = sceneInfra.camControls.getInteractionType( + const interaction = this.sceneInfra.camControls.getInteractionType( args.mouseEvent ) if (interaction !== 'none') return @@ -1312,11 +1318,11 @@ export class SceneEntities { // possible sketchFromKclValue "fails" when sketching on a face, // and this couldn't wouldn't run. await updateModelingState(_ast, EXECUTION_TYPE_MOCK, { - kclManager, - editorManager, - codeManager, + kclManager: this.kclManager, + editorManager: this.editorManager, + codeManager: this.codeManager, }) - sceneInfra.modelingSend({ type: 'Finish rectangle' }) + this.sceneInfra.modelingSend({ type: 'Finish rectangle' }) }, }) return { @@ -1334,7 +1340,7 @@ export class SceneEntities { sketchOrigin: [number, number, number], rectangleOrigin: [x: number, y: number] ): Promise => { - let _ast = structuredClone(kclManager.ast) + let _ast = structuredClone(this.kclManager.ast) const varDec = getNodeFromPath( _ast, @@ -1375,7 +1381,7 @@ export class SceneEntities { _ast = __recastAst.program // do a quick mock execution to get the program memory up-to-date - await kclManager.executeAstMock(_ast) + await this.kclManager.executeAstMock(_ast) const justCreatedNode = getNodeFromPath( _ast, @@ -1407,7 +1413,7 @@ export class SceneEntities { draftExpressionsIndices: { start: 0, end: 3 }, }) - sceneInfra.setCallbacks({ + this.sceneInfra.setCallbacks({ onMove: async (args) => { // Update the width and height of the draft rectangle @@ -1442,12 +1448,12 @@ export class SceneEntities { const { execState } = await executeAstMock({ ast: truncatedAst, - rustContext, + rustContext: this.rustContext, }) const sketch = sketchFromKclValue(execState.variables[varName], varName) if (err(sketch)) return Promise.reject(sketch) const sgPaths = sketch.paths - const orthoFactor = orthoScale(sceneInfra.camControls.camera) + const orthoFactor = orthoScale(this.sceneInfra.camControls.camera) const varDecIndex = Number(updatedEntryNodePath[1][0]) @@ -1465,7 +1471,7 @@ export class SceneEntities { }, onClick: async (args) => { // If there is a valid camera interaction that matches, do that instead - const interaction = sceneInfra.camControls.getInteractionType( + const interaction = this.sceneInfra.camControls.getInteractionType( args.mouseEvent ) if (interaction !== 'none') return @@ -1505,11 +1511,11 @@ export class SceneEntities { // possible sketchFromKclValue "fails" when sketching on a face, // and this couldn't wouldn't run. await updateModelingState(_ast, EXECUTION_TYPE_MOCK, { - kclManager, - editorManager, - codeManager, + kclManager: this.kclManager, + editorManager: this.editorManager, + codeManager: this.codeManager, }) - sceneInfra.modelingSend({ type: 'Finish center rectangle' }) + this.sceneInfra.modelingSend({ type: 'Finish center rectangle' }) } }, }) @@ -1529,7 +1535,7 @@ export class SceneEntities { point1: [x: number, y: number], point2: [x: number, y: number] ): Promise => { - let _ast = structuredClone(kclManager.ast) + let _ast = structuredClone(this.kclManager.ast) const varDec = getNodeFromPath( _ast, @@ -1568,7 +1574,7 @@ export class SceneEntities { _ast = pResult.program // do a quick mock execution to get the program memory up-to-date - await kclManager.executeAstMock(_ast) + await this.kclManager.executeAstMock(_ast) const { truncatedAst } = await this.setupSketch({ sketchEntryNodePath: updatedEntryNodePath, @@ -1580,7 +1586,7 @@ export class SceneEntities { draftExpressionsIndices: { start: 0, end: 0 }, }) - sceneInfra.setCallbacks({ + this.sceneInfra.setCallbacks({ onMove: async (args) => { const firstProfileIndex = Number(updatedSketchNodePaths[0][1][0]) const nodePathWithCorrectedIndexForTruncatedAst = @@ -1601,7 +1607,7 @@ export class SceneEntities { if (sketchInit.type === 'CallExpressionKw') { const moddedResult = changeSketchArguments( modded, - kclManager.variables, + this.kclManager.variables, { type: 'path', pathToNode: nodePathWithCorrectedIndexForTruncatedAst, @@ -1622,12 +1628,12 @@ export class SceneEntities { const { execState } = await executeAstMock({ ast: modded, - rustContext, + rustContext: this.rustContext, }) const sketch = sketchFromKclValue(execState.variables[varName], varName) if (err(sketch)) return const sgPaths = sketch.paths - const orthoFactor = orthoScale(sceneInfra.camControls.camera) + const orthoFactor = orthoScale(this.sceneInfra.camControls.camera) const varDecIndex = Number(updatedEntryNodePath[1][0]) @@ -1645,7 +1651,7 @@ export class SceneEntities { }, onClick: async (args) => { // If there is a valid camera interaction that matches, do that instead - const interaction = sceneInfra.camControls.getInteractionType( + const interaction = this.sceneInfra.camControls.getInteractionType( args.mouseEvent ) if (interaction !== 'none') return @@ -1665,7 +1671,7 @@ export class SceneEntities { if (sketchInit.type === 'CallExpressionKw') { const moddedResult = changeSketchArguments( modded, - kclManager.variables, + this.kclManager.variables, { type: 'path', pathToNode: updatedEntryNodePath, @@ -1689,11 +1695,11 @@ export class SceneEntities { // Update the primary AST and unequip the rectangle tool await updateModelingState(_ast, EXECUTION_TYPE_MOCK, { - kclManager, - editorManager, - codeManager, + kclManager: this.kclManager, + editorManager: this.editorManager, + codeManager: this.codeManager, }) - sceneInfra.modelingSend({ type: 'Finish circle three point' }) + this.sceneInfra.modelingSend({ type: 'Finish circle three point' }) } }, }) @@ -1712,7 +1718,7 @@ export class SceneEntities { sketchOrigin: [number, number, number], center: [x: number, y: number] ): Promise => { - let _ast = structuredClone(kclManager.ast) + let _ast = structuredClone(this.kclManager.ast) const _node1 = getNodeFromPath( _ast, @@ -1723,7 +1729,7 @@ export class SceneEntities { const variableDeclarationName = _node1.node?.declaration.id?.name || '' const sg = sketchFromKclValue( - kclManager.variables[variableDeclarationName], + this.kclManager.variables[variableDeclarationName], variableDeclarationName ) if (err(sg)) return Promise.reject(sg) @@ -1744,7 +1750,7 @@ export class SceneEntities { // Use addNewSketchLn to append an arc to the existing sketch const mod = addNewSketchLn({ node: _ast, - variables: kclManager.variables, + variables: this.kclManager.variables, input: { type: 'arc-segment', from, @@ -1763,13 +1769,13 @@ export class SceneEntities { _ast = pResult.program // do a quick mock execution to get the program memory up-to-date - await kclManager.executeAstMock(_ast) + await this.kclManager.executeAstMock(_ast) const index = sg.paths.length // because we've added a new segment that's not in the memory yet const draftExpressionsIndices = { start: index, end: index } this.tearDownSketch({ removeAxis: false }) - sceneInfra.resetMouseListeners() + this.sceneInfra.resetMouseListeners() const { truncatedAst } = await this.setupSketch({ sketchEntryNodePath, @@ -1781,7 +1787,7 @@ export class SceneEntities { draftExpressionsIndices, }) - sceneInfra.setCallbacks({ + this.sceneInfra.setCallbacks({ onMove: async (args) => { const firstProfileIndex = Number(sketchNodePaths[0][1][0]) const nodePathWithCorrectedIndexForTruncatedAst = structuredClone( @@ -1815,7 +1821,7 @@ export class SceneEntities { const moddedResult = changeSketchArguments( modded, - kclManager.variables, + this.kclManager.variables, { type: 'path', pathToNode: nodePathWithCorrectedIndexForTruncatedAst, @@ -1834,7 +1840,7 @@ export class SceneEntities { } const { execState } = await executeAstMock({ ast: modded, - rustContext, + rustContext: this.rustContext, }) const sketch = sketchFromKclValue( execState.variables[variableDeclarationName], @@ -1842,7 +1848,7 @@ export class SceneEntities { ) if (err(sketch)) return const sgPaths = sketch.paths - const orthoFactor = orthoScale(sceneInfra.camControls.camera) + const orthoFactor = orthoScale(this.sceneInfra.camControls.camera) const varDecIndex = Number(sketchEntryNodePath[1][0]) @@ -1868,7 +1874,7 @@ export class SceneEntities { Number(nodePathWithCorrectedIndexForTruncatedAst[1][0]) - firstProfileIndex // If there is a valid camera interaction that matches, do that instead - const interaction = sceneInfra.camControls.getInteractionType( + const interaction = this.sceneInfra.camControls.getInteractionType( args.mouseEvent ) if (interaction !== 'none') return @@ -1900,7 +1906,7 @@ export class SceneEntities { const moddedResult = changeSketchArguments( modded, - kclManager.variables, + this.kclManager.variables, { type: 'path', pathToNode: mod.pathToNode, @@ -1926,11 +1932,11 @@ export class SceneEntities { // Update the primary AST and unequip the arc tool await updateModelingState(_ast, EXECUTION_TYPE_MOCK, { - kclManager, - editorManager, - codeManager, + kclManager: this.kclManager, + editorManager: this.editorManager, + codeManager: this.codeManager, }) - sceneInfra.modelingSend({ type: 'Finish arc' }) + this.sceneInfra.modelingSend({ type: 'Finish arc' }) } }, }) @@ -1949,7 +1955,7 @@ export class SceneEntities { sketchOrigin: [number, number, number], p2: [x: number, y: number] ): Promise => { - let _ast = structuredClone(kclManager.ast) + let _ast = structuredClone(this.kclManager.ast) const _node1 = getNodeFromPath( _ast, @@ -1960,7 +1966,7 @@ export class SceneEntities { const variableDeclarationName = _node1.node?.declaration.id?.name || '' const sg = sketchFromKclValue( - kclManager.variables[variableDeclarationName], + this.kclManager.variables[variableDeclarationName], variableDeclarationName ) if (err(sg)) return Promise.reject(sg) @@ -1973,7 +1979,7 @@ export class SceneEntities { // Use addNewSketchLn to append an arc to the existing sketch const mod = addNewSketchLn({ node: _ast, - variables: kclManager.variables, + variables: this.kclManager.variables, input: { type: 'circle-three-point-segment', p1, @@ -1990,7 +1996,7 @@ export class SceneEntities { _ast = pResult.program // do a quick mock execution to get the program memory up-to-date - await kclManager.executeAstMock(_ast) + await this.kclManager.executeAstMock(_ast) const index = sg.paths.length // because we've added a new segment that's not in the memory yet const draftExpressionsIndices = { start: index, end: index } @@ -1999,7 +2005,7 @@ export class SceneEntities { const insertIndex = Number(mod.pathToNode[1][0]) this.tearDownSketch({ removeAxis: false }) - sceneInfra.resetMouseListeners() + this.sceneInfra.resetMouseListeners() const { truncatedAst } = await this.setupSketch({ sketchEntryNodePath, @@ -2013,7 +2019,7 @@ export class SceneEntities { const doNotSnapAsThreePointArcIsTheOnlySegment = sg.paths.length === 0 - sceneInfra.setCallbacks({ + this.sceneInfra.setCallbacks({ onMove: async (args) => { const firstProfileIndex = Number(sketchNodePaths[0][1][0]) const nodePathWithCorrectedIndexForTruncatedAst = structuredClone( @@ -2048,7 +2054,7 @@ export class SceneEntities { if (sketchInit.type === 'PipeExpression') { const moddedResult = changeSketchArguments( modded, - kclManager.variables, + this.kclManager.variables, { type: 'path', pathToNode: nodePathWithCorrectedIndexForTruncatedAst, @@ -2065,7 +2071,7 @@ export class SceneEntities { } const { execState } = await executeAstMock({ ast: modded, - rustContext, + rustContext: this.rustContext, }) const sketch = sketchFromKclValue( execState.variables[variableDeclarationName], @@ -2073,7 +2079,7 @@ export class SceneEntities { ) if (err(sketch)) return const sgPaths = sketch.paths - const orthoFactor = orthoScale(sceneInfra.camControls.camera) + const orthoFactor = orthoScale(this.sceneInfra.camControls.camera) const varDecIndex = Number(sketchEntryNodePath[1][0]) @@ -2099,7 +2105,7 @@ export class SceneEntities { Number(nodePathWithCorrectedIndexForTruncatedAst[1][0]) - firstProfileIndex // If there is a valid camera interaction that matches, do that instead - const interaction = sceneInfra.camControls.getInteractionType( + const interaction = this.sceneInfra.camControls.getInteractionType( args.mouseEvent ) if (interaction !== 'none') return @@ -2125,7 +2131,7 @@ export class SceneEntities { const moddedResult = changeSketchArguments( modded, - kclManager.variables, + this.kclManager.variables, { type: 'path', pathToNode: mod.pathToNode, @@ -2167,7 +2173,7 @@ export class SceneEntities { const moddedResult = addCloseToPipe({ node: modded, - variables: kclManager.variables, + variables: this.kclManager.variables, pathToNode: sketchEntryNodePath, }) if (err(moddedResult)) return @@ -2183,14 +2189,14 @@ export class SceneEntities { // Update the primary AST and unequip the arc tool await updateModelingState(_ast, EXECUTION_TYPE_MOCK, { - kclManager, - editorManager, - codeManager, + kclManager: this.kclManager, + editorManager: this.editorManager, + codeManager: this.codeManager, }) if (intersectsProfileStart) { - sceneInfra.modelingSend({ type: 'Close sketch' }) + this.sceneInfra.modelingSend({ type: 'Close sketch' }) } else { - sceneInfra.modelingSend({ type: 'Finish arc' }) + this.sceneInfra.modelingSend({ type: 'Finish arc' }) } } }, @@ -2210,7 +2216,7 @@ export class SceneEntities { sketchOrigin: [number, number, number], circleCenter: [x: number, y: number] ): Promise => { - let _ast = structuredClone(kclManager.ast) + let _ast = structuredClone(this.kclManager.ast) const varDec = getNodeFromPath( _ast, @@ -2255,7 +2261,7 @@ export class SceneEntities { _ast = pResult.program // do a quick mock execution to get the program memory up-to-date - await kclManager.executeAstMock(_ast) + await this.kclManager.executeAstMock(_ast) const { truncatedAst } = await this.setupSketch({ sketchEntryNodePath: updatedEntryNodePath, @@ -2267,7 +2273,7 @@ export class SceneEntities { draftExpressionsIndices: { start: 0, end: 0 }, }) - sceneInfra.setCallbacks({ + this.sceneInfra.setCallbacks({ onMove: async (args) => { const nodePathWithCorrectedIndexForTruncatedAst = structuredClone(updatedEntryNodePath) @@ -2290,7 +2296,7 @@ export class SceneEntities { if (sketchInit.type === 'CallExpressionKw') { const moddedResult = changeSketchArguments( modded, - kclManager.variables, + this.kclManager.variables, { type: 'path', pathToNode: nodePathWithCorrectedIndexForTruncatedAst, @@ -2312,12 +2318,12 @@ export class SceneEntities { const { execState } = await executeAstMock({ ast: modded, - rustContext, + rustContext: this.rustContext, }) const sketch = sketchFromKclValue(execState.variables[varName], varName) if (err(sketch)) return const sgPaths = sketch.paths - const orthoFactor = orthoScale(sceneInfra.camControls.camera) + const orthoFactor = orthoScale(this.sceneInfra.camControls.camera) const varDecIndex = Number(updatedEntryNodePath[1][0]) @@ -2335,7 +2341,7 @@ export class SceneEntities { }, onClick: async (args) => { // If there is a valid camera interaction that matches, do that instead - const interaction = sceneInfra.camControls.getInteractionType( + const interaction = this.sceneInfra.camControls.getInteractionType( args.mouseEvent ) if (interaction !== 'none') return @@ -2358,7 +2364,7 @@ export class SceneEntities { if (sketchInit.type === 'CallExpressionKw') { const moddedResult = changeSketchArguments( modded, - kclManager.variables, + this.kclManager.variables, { type: 'path', pathToNode: updatedEntryNodePath, @@ -2384,11 +2390,11 @@ export class SceneEntities { // Update the primary AST and unequip the rectangle tool await updateModelingState(_ast, EXECUTION_TYPE_MOCK, { - kclManager, - editorManager, - codeManager, + kclManager: this.kclManager, + editorManager: this.editorManager, + codeManager: this.codeManager, }) - sceneInfra.modelingSend({ type: 'Finish circle' }) + this.sceneInfra.modelingSend({ type: 'Finish circle' }) } }, }) @@ -2414,7 +2420,7 @@ export class SceneEntities { position?: [number, number, number] }) => { let addingNewSegmentStatus: 'nothing' | 'pending' | 'added' = 'nothing' - sceneInfra.setCallbacks({ + this.sceneInfra.setCallbacks({ onDragEnd: async () => { if (addingNewSegmentStatus !== 'nothing') { this.tearDownSketch({ removeAxis: false }) @@ -2422,7 +2428,7 @@ export class SceneEntities { this.setupSketch({ sketchEntryNodePath, sketchNodePaths, - maybeModdedAst: kclManager.ast, + maybeModdedAst: this.kclManager.ast, up, forward, position, @@ -2436,7 +2442,7 @@ export class SceneEntities { forward, position, }) - await codeManager.writeToFile() + await this.codeManager.writeToFile() } }, onDrag: async ({ @@ -2457,8 +2463,9 @@ export class SceneEntities { const sketch = sketchFromPathToNode({ pathToNode, - ast: kclManager.ast, - variables: kclManager.variables, + ast: this.kclManager.ast, + variables: this.kclManager.variables, + kclManager: this.kclManager, }) if (trap(sketch)) return if (!sketch) { @@ -2470,8 +2477,8 @@ export class SceneEntities { if (addingNewSegmentStatus === 'nothing') { const prevSegment = sketch.paths[pipeIndex - 2] const mod = addNewSketchLn({ - node: kclManager.ast, - variables: kclManager.variables, + node: this.kclManager.ast, + variables: this.kclManager.variables, input: { type: 'straight-segment', to: [intersectionPoint.twoD.x, intersectionPoint.twoD.y], @@ -2487,13 +2494,13 @@ export class SceneEntities { addingNewSegmentStatus = 'pending' if (trap(mod)) return - await kclManager.executeAstMock(mod.modifiedAst) + await this.kclManager.executeAstMock(mod.modifiedAst) this.tearDownSketch({ removeAxis: false }) // eslint-disable-next-line @typescript-eslint/no-floating-promises this.setupSketch({ sketchEntryNodePath: pathToNode, sketchNodePaths, - maybeModdedAst: kclManager.ast, + maybeModdedAst: this.kclManager.ast, up, forward, position, @@ -2526,13 +2533,13 @@ export class SceneEntities { onMove: () => {}, onClick: (args) => { // If there is a valid camera interaction that matches, do that instead - const interaction = sceneInfra.camControls.getInteractionType( + const interaction = this.sceneInfra.camControls.getInteractionType( args.mouseEvent ) if (interaction !== 'none') return if (args?.mouseEvent.which !== 1) return if (!args || !args.selected) { - sceneInfra.modelingSend({ + this.sceneInfra.modelingSend({ type: 'Set selection', data: { selectionType: 'singleCodeCursor', @@ -2543,7 +2550,7 @@ export class SceneEntities { const { selected } = args const event = getEventForSegmentSelection(selected) if (!event) return - sceneInfra.modelingSend(event) + this.sceneInfra.modelingSend(event) }, ...this.mouseEnterLeaveCallbacks(), }) @@ -2555,8 +2562,8 @@ export class SceneEntities { ) => prepareTruncatedAst( sketchNodePaths, - ast || kclManager.ast, - kclManager.lastSuccessfulVariables, + ast || this.kclManager.ast, + this.kclManager.lastSuccessfulVariables, draftSegment ) getSnappedDragPoint({ @@ -2690,7 +2697,9 @@ export class SceneEntities { intersects, intersection2d, }).snappedPoint - let modifiedAst = draftInfo ? draftInfo.truncatedAst : { ...kclManager.ast } + let modifiedAst = draftInfo + ? draftInfo.truncatedAst + : { ...this.kclManager.ast } const nodePathWithCorrectedIndexForTruncatedAst = structuredClone(pathToNode) @@ -2862,12 +2871,12 @@ export class SceneEntities { to: dragTo, from, }, - variables: kclManager.variables, + variables: this.kclManager.variables, }) } else { modded = changeSketchArguments( modifiedAst, - kclManager.variables, + this.kclManager.variables, { type: 'sourceRange', sourceRange: topLevelRange(node.start, node.end), @@ -2889,16 +2898,17 @@ export class SceneEntities { if (!draftInfo) // don't want to mod the user's code yet as they have't committed to the change yet // plus this would be the truncated ast being recast, it would be wrong - codeManager.updateCodeEditor(code) + this.codeManager.updateCodeEditor(code) const { execState } = await executeAstMock({ ast: truncatedAst, - rustContext, + rustContext: this.rustContext, }) const variables = execState.variables const sketchesInfo = getSketchesInfo({ sketchNodePaths, ast: truncatedAst, variables, + kclManager: this.kclManager, }) const callBacks: (() => SegmentOverlayPayload | null)[] = [] for (const sketchInfo of sketchesInfo) { @@ -2908,7 +2918,7 @@ export class SceneEntities { if (!sketch) return const sgPaths = sketch.paths - const orthoFactor = orthoScale(sceneInfra.camControls.camera) + const orthoFactor = orthoScale(this.sceneInfra.camControls.camera) this.updateSegment( sketch.start, @@ -2932,7 +2942,7 @@ export class SceneEntities { ) ) } - sceneInfra.overlayCallbacks(callBacks) + this.sceneInfra.overlayCallbacks(callBacks) })().catch(reportRejection) } @@ -2968,10 +2978,10 @@ export class SceneEntities { this.activeSegments[originalPathToNodeStr] const type = group?.userData?.type const factor = - (sceneInfra.camControls.camera instanceof OrthographicCamera + (this.sceneInfra.camControls.camera instanceof OrthographicCamera ? orthoFactor - : perspScale(sceneInfra.camControls.camera, group)) / - sceneInfra._baseUnitMultiplier + : perspScale(this.sceneInfra.camControls.camera, group)) / + this.sceneInfra._baseUnitMultiplier let input: SegmentInputs = { type: 'straight-segment', from: segment.from, @@ -3043,7 +3053,7 @@ export class SceneEntities { group, scale: factor, prevSegment: sgPaths[index - 1], - sceneInfra, + sceneInfra: this.sceneInfra, }) if (callBack && !err(callBack)) return callBack @@ -3074,18 +3084,19 @@ export class SceneEntities { }) } removeSketchGrid() { - if (this.axisGroup) sceneInfra.scene.remove(this.axisGroup) + if (this.axisGroup) this.sceneInfra.scene.remove(this.axisGroup) } tearDownSketch({ removeAxis = true }: { removeAxis?: boolean }) { // Remove all draft groups this.draftPointGroups.forEach((draftPointGroup) => { - sceneInfra.scene.remove(draftPointGroup) + this.sceneInfra.scene.remove(draftPointGroup) }) // Remove all sketch tools - if (this.axisGroup && removeAxis) sceneInfra.scene.remove(this.axisGroup) - const sketchSegments = sceneInfra.scene.children.find( + if (this.axisGroup && removeAxis) + this.sceneInfra.scene.remove(this.axisGroup) + const sketchSegments = this.sceneInfra.scene.children.find( ({ userData }) => userData?.type === SKETCH_GROUP_SEGMENTS ) if (sketchSegments) { @@ -3097,9 +3108,9 @@ export class SceneEntities { object.remove() } }) - sceneInfra.scene.remove(sketchSegments) + this.sceneInfra.scene.remove(sketchSegments) } - sceneInfra.camControls.enableRotate = true + this.sceneInfra.camControls.enableRotate = true this.activeSegments = {} } mouseEnterLeaveCallbacks() { @@ -3116,7 +3127,7 @@ export class SceneEntities { SEGMENT_BODIES_PLUS_PROFILE_START ) if (parent?.userData?.pathToNode) { - const pResult = parse(recast(kclManager.ast)) + const pResult = parse(recast(this.kclManager.ast)) if (trap(pResult) || !resultIsOk(pResult)) return Promise.reject(pResult) const updatedAst = pResult.program @@ -3128,7 +3139,9 @@ export class SceneEntities { ]) if (trap(_node, { suppress: true })) return const node = _node.node - editorManager.setHighlightRange([topLevelRange(node.start, node.end)]) + this.editorManager.setHighlightRange([ + topLevelRange(node.start, node.end), + ]) const yellow = 0xffff00 colorSegment(selected, yellow) const extraSegmentGroup = parent.getObjectByName(EXTRA_SEGMENT_HANDLE) @@ -3139,7 +3152,7 @@ export class SceneEntities { } }) } - const orthoFactor = orthoScale(sceneInfra.camControls.camera) + const orthoFactor = orthoScale(this.sceneInfra.camControls.camera) let input: SegmentInputs = { type: 'straight-segment', @@ -3147,10 +3160,10 @@ export class SceneEntities { to: parent.userData.to, } const factor = - (sceneInfra.camControls.camera instanceof OrthographicCamera + (this.sceneInfra.camControls.camera instanceof OrthographicCamera ? orthoFactor - : perspScale(sceneInfra.camControls.camera, parent)) / - sceneInfra._baseUnitMultiplier + : perspScale(this.sceneInfra.camControls.camera, parent)) / + this.sceneInfra._baseUnitMultiplier let update: SegmentUtils['update'] | null = null if (parent.name === STRAIGHT_SEGMENT) { update = segmentUtils.straight.update @@ -3203,20 +3216,20 @@ export class SceneEntities { input, group: parent, scale: factor, - sceneInfra, + sceneInfra: this.sceneInfra, }) return } - editorManager.setHighlightRange([defaultSourceRange()]) + this.editorManager.setHighlightRange([defaultSourceRange()]) }, onMouseLeave: ({ selected, ...rest }: OnMouseEnterLeaveArgs) => { - editorManager.setHighlightRange([defaultSourceRange()]) + this.editorManager.setHighlightRange([defaultSourceRange()]) const parent = getParentGroup( selected, SEGMENT_BODIES_PLUS_PROFILE_START ) if (parent) { - const orthoFactor = orthoScale(sceneInfra.camControls.camera) + const orthoFactor = orthoScale(this.sceneInfra.camControls.camera) let input: SegmentInputs = { type: 'straight-segment', @@ -3224,10 +3237,10 @@ export class SceneEntities { to: parent.userData.to, } const factor = - (sceneInfra.camControls.camera instanceof OrthographicCamera + (this.sceneInfra.camControls.camera instanceof OrthographicCamera ? orthoFactor - : perspScale(sceneInfra.camControls.camera, parent)) / - sceneInfra._baseUnitMultiplier + : perspScale(this.sceneInfra.camControls.camera, parent)) / + this.sceneInfra._baseUnitMultiplier let update: SegmentUtils['update'] | null = null if (parent.name === STRAIGHT_SEGMENT) { update = segmentUtils.straight.update @@ -3280,7 +3293,7 @@ export class SceneEntities { input, group: parent, scale: factor, - sceneInfra, + sceneInfra: this.sceneInfra, }) } const isSelected = parent?.userData?.isSelected @@ -3289,7 +3302,7 @@ export class SceneEntities { isSelected ? 0x0000ff : parent?.userData?.baseColor || - getThemeColorForThreeJs(sceneInfra._theme) + getThemeColorForThreeJs(this.sceneInfra._theme) ) const extraSegmentGroup = parent?.getObjectByName(EXTRA_SEGMENT_HANDLE) if (extraSegmentGroup) { @@ -3309,7 +3322,7 @@ export class SceneEntities { } } resetOverlays() { - sceneInfra.modelingSend({ + this.sceneInfra.modelingSend({ type: 'Set Segment Overlays', data: { type: 'clear', @@ -3317,8 +3330,90 @@ export class SceneEntities { }) } + async getSketchOrientationDetails(sketch: Sketch): Promise<{ + quat: Quaternion + sketchDetails: Omit< + SketchDetails & { faceId?: string }, + 'sketchNodePaths' | 'sketchEntryNodePath' | 'planeNodePath' + > + }> { + if (sketch.on.type === 'plane') { + const zAxis = sketch?.on.zAxis + return { + quat: getQuaternionFromZAxis(massageFormats(zAxis)), + sketchDetails: { + zAxis: [zAxis.x, zAxis.y, zAxis.z], + yAxis: [sketch.on.yAxis.x, sketch.on.yAxis.y, sketch.on.yAxis.z], + origin: [0, 0, 0], + faceId: sketch.on.id, + }, + } + } + const faceInfo = await this.getFaceDetails(sketch.on.id) + + if (!faceInfo?.origin || !faceInfo?.z_axis || !faceInfo?.y_axis) + return Promise.reject('face info') + const { z_axis, y_axis, origin } = faceInfo + const quaternion = quaternionFromUpNForward( + new Vector3(y_axis.x, y_axis.y, y_axis.z), + new Vector3(z_axis.x, z_axis.y, z_axis.z) + ) + return { + quat: quaternion, + sketchDetails: { + zAxis: [z_axis.x, z_axis.y, z_axis.z], + yAxis: [y_axis.x, y_axis.y, y_axis.z], + origin: [origin.x, origin.y, origin.z], + faceId: sketch.on.id, + }, + } + } + + /** + * Retrieves orientation details for a given entity representing a face (brep face or default plane). + * This function asynchronously fetches and returns the origin, x-axis, y-axis, and z-axis details + * for a specified entity ID. It is primarily used to obtain the orientation of a face in the scene, + * which is essential for calculating the correct positioning and alignment of the client side sketch. + * + * @param entityId - The ID of the entity for which orientation details are being fetched. + * @returns A promise that resolves with the orientation details of the face. + */ + async getFaceDetails( + entityId: string + ): Promise { + // TODO mode engine connection to allow batching returns and batch the following + await this.engineCommandManager.sendSceneCommand({ + type: 'modeling_cmd_req', + cmd_id: uuidv4(), + cmd: { + type: 'enable_sketch_mode', + adjust_camera: false, + animated: false, + ortho: false, + entity_id: entityId, + }, + }) + const resp = await this.engineCommandManager.sendSceneCommand({ + type: 'modeling_cmd_req', + cmd_id: uuidv4(), + cmd: { type: 'get_sketch_mode_plane' }, + }) + const faceInfo = + resp?.success && + resp?.resp.type === 'modeling' && + resp?.resp?.data?.modeling_response?.type === 'get_sketch_mode_plane' + ? resp?.resp?.data?.modeling_response.data + : ({} as Models['GetSketchModePlane_type']) + await this.engineCommandManager.sendSceneCommand({ + type: 'modeling_cmd_req', + cmd_id: uuidv4(), + cmd: { type: 'sketch_mode_disable' }, + }) + return faceInfo + } + drawDashedLine({ from, to }: { from: Coords2d; to: Coords2d }) { - const baseColor = getThemeColorForThreeJs(sceneInfra._theme) + const baseColor = getThemeColorForThreeJs(this.sceneInfra._theme) const color = baseColor const meshType = STRAIGHT_SEGMENT_DASH @@ -3359,10 +3454,10 @@ export class SceneEntities { group: segmentGroup, updater: (group: Group, to: Coords2d, orthoFactor: number) => { const scale = - (sceneInfra.camControls.camera instanceof OrthographicCamera + (this.sceneInfra.camControls.camera instanceof OrthographicCamera ? orthoFactor - : perspScale(sceneInfra.camControls.camera, group)) / - sceneInfra._baseUnitMultiplier + : perspScale(this.sceneInfra.camControls.camera, group)) / + this.sceneInfra._baseUnitMultiplier const from = group.userData.from const shape = new Shape() @@ -3478,26 +3573,16 @@ function prepareTruncatedAst( } } -export function getParentGroup( - object: any, - stopAt: string[] = SEGMENT_BODIES -): Group | null { - if (stopAt.includes(object?.userData?.type)) { - return object - } else if (object?.parent) { - return getParentGroup(object.parent, stopAt) - } - return null -} - function sketchFromPathToNode({ pathToNode, ast, variables, + kclManager, }: { pathToNode: PathToNode ast: Program variables: VariableMap + kclManager: KclManager }): Sketch | null | Error { const _varDec = getNodeFromPath( kclManager.ast, @@ -3540,12 +3625,14 @@ function colorSegment(object: any, color: number) { export function getSketchQuaternion( sketchPathToNode: PathToNode, - sketchNormalBackUp: [number, number, number] | null + sketchNormalBackUp: [number, number, number] | null, + kclManager: KclManager ): Quaternion | Error { const sketch = sketchFromPathToNode({ pathToNode: sketchPathToNode, ast: kclManager.ast, variables: kclManager.variables, + kclManager, }) if (err(sketch)) return sketch const zAxis = sketch?.on.zAxis || sketchNormalBackUp @@ -3553,87 +3640,6 @@ export function getSketchQuaternion( return getQuaternionFromZAxis(massageFormats(zAxis)) } -export async function getSketchOrientationDetails(sketch: Sketch): Promise<{ - quat: Quaternion - sketchDetails: Omit< - SketchDetails & { faceId?: string }, - 'sketchNodePaths' | 'sketchEntryNodePath' | 'planeNodePath' - > -}> { - if (sketch.on.type === 'plane') { - const zAxis = sketch?.on.zAxis - return { - quat: getQuaternionFromZAxis(massageFormats(zAxis)), - sketchDetails: { - zAxis: [zAxis.x, zAxis.y, zAxis.z], - yAxis: [sketch.on.yAxis.x, sketch.on.yAxis.y, sketch.on.yAxis.z], - origin: [0, 0, 0], - faceId: sketch.on.id, - }, - } - } - const faceInfo = await getFaceDetails(sketch.on.id) - - if (!faceInfo?.origin || !faceInfo?.z_axis || !faceInfo?.y_axis) - return Promise.reject('face info') - const { z_axis, y_axis, origin } = faceInfo - const quaternion = quaternionFromUpNForward( - new Vector3(y_axis.x, y_axis.y, y_axis.z), - new Vector3(z_axis.x, z_axis.y, z_axis.z) - ) - return { - quat: quaternion, - sketchDetails: { - zAxis: [z_axis.x, z_axis.y, z_axis.z], - yAxis: [y_axis.x, y_axis.y, y_axis.z], - origin: [origin.x, origin.y, origin.z], - faceId: sketch.on.id, - }, - } -} - -/** - * Retrieves orientation details for a given entity representing a face (brep face or default plane). - * This function asynchronously fetches and returns the origin, x-axis, y-axis, and z-axis details - * for a specified entity ID. It is primarily used to obtain the orientation of a face in the scene, - * which is essential for calculating the correct positioning and alignment of the client side sketch. - * - * @param entityId - The ID of the entity for which orientation details are being fetched. - * @returns A promise that resolves with the orientation details of the face. - */ -export async function getFaceDetails( - entityId: string -): Promise { - // TODO mode engine connection to allow batching returns and batch the following - await engineCommandManager.sendSceneCommand({ - type: 'modeling_cmd_req', - cmd_id: uuidv4(), - cmd: { - type: 'enable_sketch_mode', - adjust_camera: false, - animated: false, - ortho: false, - entity_id: entityId, - }, - }) - const resp = await engineCommandManager.sendSceneCommand({ - type: 'modeling_cmd_req', - cmd_id: uuidv4(), - cmd: { type: 'get_sketch_mode_plane' }, - }) - const faceInfo = - resp?.success && - resp?.resp.type === 'modeling' && - resp?.resp?.data?.modeling_response?.type === 'get_sketch_mode_plane' - ? resp?.resp?.data?.modeling_response.data - : ({} as Models['GetSketchModePlane_type']) - await engineCommandManager.sendSceneCommand({ - type: 'modeling_cmd_req', - cmd_id: uuidv4(), - cmd: { type: 'sketch_mode_disable' }, - }) - return faceInfo -} export function getQuaternionFromZAxis(zAxis: Vector3): Quaternion { const dummyCam = new PerspectiveCamera() @@ -3663,10 +3669,12 @@ function getSketchesInfo({ sketchNodePaths, ast, variables, + kclManager, }: { sketchNodePaths: PathToNode[] ast: Node variables: VariableMap + kclManager: KclManager }): { sketch: Sketch pathToNode: PathToNode @@ -3680,6 +3688,7 @@ function getSketchesInfo({ pathToNode: path, ast, variables, + kclManager, }) if (err(sketch)) continue if (!sketch) continue @@ -3698,7 +3707,8 @@ function getSketchesInfo({ */ function computeSelectionFromSourceRangeAndAST( sourceRange: SourceRange, - ast: Node + ast: Node, + kclManager: KclManager ): Selections { const artifactGraph = kclManager.artifactGraph const artifact = getArtifactFromRange(sourceRange, artifactGraph) || undefined diff --git a/src/clientSideScene/sceneInfra.ts b/src/clientSideScene/sceneInfra.ts index 40d9dbbbc..34254119a 100644 --- a/src/clientSideScene/sceneInfra.ts +++ b/src/clientSideScene/sceneInfra.ts @@ -1,3 +1,13 @@ +import * as TWEEN from '@tweenjs/tween.js' +import type { + Group, + Intersection, + Mesh, + MeshBasicMaterial, + Object3D, + Object3DEventMap, + Texture, +} from 'three' import { AmbientLight, Color, @@ -5,32 +15,29 @@ import { LineBasicMaterial, OrthographicCamera, PerspectiveCamera, + Raycaster, Scene, + TextureLoader, + Vector2, Vector3, WebGLRenderer, - Raycaster, - Vector2, - Group, - MeshBasicMaterial, - Mesh, - Intersection, - Object3D, - Object3DEventMap, - TextureLoader, - Texture, } from 'three' -import { Coords2d, compareVec2Epsilon2 } from 'lang/std/sketch' -import { useModelingContext } from 'hooks/useModelingContext' -import * as TWEEN from '@tweenjs/tween.js' -import { Axis, NonCodeSelection } from 'lib/selections' -import { type BaseUnit } from 'lib/settings/settingsTypes' -import { CameraControls } from './CameraControls' -import { EngineCommandManager } from 'lang/std/engineConnection' -import { MouseState, SegmentOverlayPayload } from 'machines/modelingMachine' -import { getAngle, throttle } from 'lib/utils' -import { Themes } from 'lib/theme' import { CSS2DRenderer } from 'three/examples/jsm/renderers/CSS2DRenderer' -import { orthoScale, perspScale } from './helpers' + +import { CameraControls } from '@src/clientSideScene/CameraControls' +import { orthoScale, perspScale } from '@src/clientSideScene/helpers' +import type { useModelingContext } from '@src/hooks/useModelingContext' +import type { EngineCommandManager } from '@src/lang/std/engineConnection' +import type { Coords2d } from '@src/lang/std/sketch' +import { compareVec2Epsilon2 } from '@src/lang/std/sketch' +import type { Axis, NonCodeSelection } from '@src/lib/selections' +import { type BaseUnit } from '@src/lib/settings/settingsTypes' +import { Themes } from '@src/lib/theme' +import { getAngle, throttle } from '@src/lib/utils' +import type { + MouseState, + SegmentOverlayPayload, +} from '@src/machines/modelingMachine' type SendType = ReturnType['send'] diff --git a/src/clientSideScene/sceneUtils.ts b/src/clientSideScene/sceneUtils.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/clientSideScene/segments.ts b/src/clientSideScene/segments.ts index bcb70ba0d..869669d70 100644 --- a/src/clientSideScene/segments.ts +++ b/src/clientSideScene/segments.ts @@ -1,4 +1,4 @@ -import { Coords2d } from 'lang/std/sketch' +import type { NormalBufferAttributes, Texture } from 'three' import { BoxGeometry, BufferGeometry, @@ -8,25 +8,33 @@ import { EllipseCurve, ExtrudeGeometry, Group, - LineCurve3, - LineBasicMaterial, - LineDashedMaterial, Line, + LineBasicMaterial, + LineCurve3, + LineDashedMaterial, Mesh, MeshBasicMaterial, - NormalBufferAttributes, Points, PointsMaterial, Shape, SphereGeometry, - Texture, Vector2, Vector3, } from 'three' -import { mergeGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils.js' import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer' -import { PathToNode, Sketch, getTangentialArcToInfo } from 'lang/wasm' +import { mergeGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils.js' + +import { calculate_circle_from_3_points } from '@rust/kcl-wasm-lib/pkg/kcl_wasm_lib' + +import type { Sketch } from '@rust/kcl-lib/bindings/Sketch' import { + ARC_ANGLE_END, + ARC_ANGLE_REFERENCE_LINE, + ARC_CENTER_TO_FROM, + ARC_CENTER_TO_TO, + ARC_SEGMENT, + ARC_SEGMENT_BODY, + ARC_SEGMENT_DASH, CIRCLE_CENTER_HANDLE, CIRCLE_SEGMENT, CIRCLE_SEGMENT_BODY, @@ -49,42 +57,37 @@ import { TANGENTIAL_ARC_TO_SEGMENT, TANGENTIAL_ARC_TO_SEGMENT_BODY, TANGENTIAL_ARC_TO__SEGMENT_DASH, - ARC_SEGMENT, - ARC_SEGMENT_BODY, - ARC_SEGMENT_DASH, - ARC_ANGLE_END, - getParentGroup, - ARC_CENTER_TO_FROM, - ARC_CENTER_TO_TO, - ARC_ANGLE_REFERENCE_LINE, + THREE_POINT_ARC_HANDLE2, + THREE_POINT_ARC_HANDLE3, THREE_POINT_ARC_SEGMENT, THREE_POINT_ARC_SEGMENT_BODY, THREE_POINT_ARC_SEGMENT_DASH, - THREE_POINT_ARC_HANDLE2, - THREE_POINT_ARC_HANDLE3, -} from './sceneEntities' -import { getTangentPointFromPreviousArc } from 'lib/utils2d' + getParentGroup, +} from '@src/clientSideScene/sceneConstants' +import type { SceneInfra } from '@src/clientSideScene/sceneInfra' import { ARROWHEAD, DRAFT_POINT, - SceneInfra, SEGMENT_LENGTH_LABEL, SEGMENT_LENGTH_LABEL_OFFSET_PX, SEGMENT_LENGTH_LABEL_TEXT, -} from './sceneInfra' -import { Themes, getThemeColorForThreeJs } from 'lib/theme' -import { isClockwise, normaliseAngle, roundOff } from 'lib/utils' -import { +} from '@src/clientSideScene/sceneInfra' +import type { Coords2d } from '@src/lang/std/sketch' +import type { SegmentInputs } from '@src/lang/std/stdTypes' +import type { PathToNode } from '@src/lang/wasm' +import { getTangentialArcToInfo } from '@src/lang/wasm' +import type { Selections } from '@src/lib/selections' +import type { Themes } from '@src/lib/theme' +import { getThemeColorForThreeJs } from '@src/lib/theme' +import { err } from '@src/lib/trap' +import { isClockwise, normaliseAngle, roundOff } from '@src/lib/utils' +import { getTangentPointFromPreviousArc } from '@src/lib/utils2d' +import { commandBarActor } from '@src/machines/commandBarMachine' +import type { SegmentOverlay, SegmentOverlayPayload, SegmentOverlays, -} from 'machines/modelingMachine' -import { SegmentInputs } from 'lang/std/stdTypes' -import { err } from 'lib/trap' -import { sceneInfra } from 'lib/singletons' -import { Selections } from 'lib/selections' -import { calculate_circle_from_3_points } from '@rust/kcl-wasm-lib/pkg/kcl_wasm_lib' -import { commandBarActor } from 'machines/commandBarMachine' +} from '@src/machines/modelingMachine' const ANGLE_INDICATOR_RADIUS = 30 // in px interface CreateSegmentArgs { @@ -205,6 +208,7 @@ class StraightSegment implements SegmentUtils { from, to, scale, + sceneInfra, }) segmentGroup.add(arrowGroup) segmentGroup.add(lengthIndicatorGroup) @@ -572,6 +576,7 @@ class CircleSegment implements SegmentUtils { from: center, to: [center[0] + radius, center[1]], scale, + sceneInfra, }) arcMesh.userData.type = meshType @@ -1002,6 +1007,7 @@ class ArcSegment implements SegmentUtils { from: center, to: from, scale, + sceneInfra, }) const grey = 0xaaaaaa @@ -1059,6 +1065,7 @@ class ArcSegment implements SegmentUtils { center[1] + Math.sin(endAngle) * radius, ], scale, + sceneInfra, }) endAngleLengthIndicator.name = 'endAngleLengthIndicator' @@ -1679,11 +1686,13 @@ function createLengthIndicator({ to, scale, length = 0.1, + sceneInfra, }: { from: Coords2d to: Coords2d scale: number length?: number + sceneInfra: SceneInfra }) { const lengthIndicatorGroup = new Group() lengthIndicatorGroup.name = SEGMENT_LENGTH_LABEL diff --git a/src/commandLineArgs.test.ts b/src/commandLineArgs.test.ts index 6fec7cdad..af383faa0 100644 --- a/src/commandLineArgs.test.ts +++ b/src/commandLineArgs.test.ts @@ -1,4 +1,4 @@ -import { getPathOrUrlFromArgs, parseCLIArgs } from 'commandLineArgs' +import { getPathOrUrlFromArgs, parseCLIArgs } from '@src/commandLineArgs' const linuxDeepLinkArgv = [ '/tmp/.mount_Zoo Movq3t0x/zoo-modeling-app', diff --git a/src/components/ActionButton.test.tsx b/src/components/ActionButton.test.tsx index fd649fa67..c900da372 100644 --- a/src/components/ActionButton.test.tsx +++ b/src/components/ActionButton.test.tsx @@ -1,6 +1,7 @@ import { render, screen } from '@testing-library/react' import { describe, expect, it } from 'vitest' -import { ActionButton } from './ActionButton' + +import { ActionButton } from '@src/components/ActionButton' describe('ActionButton tests', () => { it('ActionButton with no iconStart or iconEnd should have even left and right padding', () => { diff --git a/src/components/ActionButton.tsx b/src/components/ActionButton.tsx index 2905f8ae0..766d19d93 100644 --- a/src/components/ActionButton.tsx +++ b/src/components/ActionButton.tsx @@ -1,9 +1,12 @@ -import { ActionIcon, ActionIconProps } from './ActionIcon' -import { openExternalBrowserIfDesktop } from 'lib/openWindow' -import React, { ForwardedRef, forwardRef } from 'react' -import { PATHS } from 'lib/paths' -import { Link } from 'react-router-dom' +import type { ForwardedRef } from 'react' +import React, { forwardRef } from 'react' import type { LinkProps } from 'react-router-dom' +import { Link } from 'react-router-dom' + +import type { ActionIconProps } from '@src/components/ActionIcon' +import { ActionIcon } from '@src/components/ActionIcon' +import { openExternalBrowserIfDesktop } from '@src/lib/openWindow' +import { PATHS } from '@src/lib/paths' interface BaseActionButtonProps { iconStart?: ActionIconProps @@ -47,8 +50,8 @@ export const ActionButton = forwardRef((props: ActionButtonProps, ref) => { ? 'px-0' // No padding if both icons are present : 'pr-2' // Padding on the right if only the start icon is present : props.iconEnd - ? 'pl-2' // Padding on the left if only the end icon is present - : 'px-2' // Padding on both sides if no icons are present + ? 'pl-2' // Padding on the left if only the end icon is present + : 'px-2' // Padding on both sides if no icons are present } ${props.className ? props.className : ''}` switch (props.Element) { diff --git a/src/components/ActionButtonDropdown.tsx b/src/components/ActionButtonDropdown.tsx index 32c55db98..37e037aa1 100644 --- a/src/components/ActionButtonDropdown.tsx +++ b/src/components/ActionButtonDropdown.tsx @@ -1,7 +1,8 @@ import { Popover } from '@headlessui/react' -import { ActionButtonProps } from './ActionButton' -import { CustomIcon } from './CustomIcon' -import Tooltip from './Tooltip' + +import type { ActionButtonProps } from '@src/components/ActionButton' +import { CustomIcon } from '@src/components/CustomIcon' +import Tooltip from '@src/components/Tooltip' type ActionButtonSplitProps = ActionButtonProps & { Element: 'button' } & { name?: string diff --git a/src/components/ActionIcon.tsx b/src/components/ActionIcon.tsx index 1609360bc..0a8447240 100644 --- a/src/components/ActionIcon.tsx +++ b/src/components/ActionIcon.tsx @@ -1,9 +1,9 @@ -import { - IconDefinition, - faCircleExclamation, -} from '@fortawesome/free-solid-svg-icons' +import type { IconDefinition } from '@fortawesome/free-solid-svg-icons' +import { faCircleExclamation } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { CustomIcon, CustomIconName } from './CustomIcon' + +import type { CustomIconName } from '@src/components/CustomIcon' +import { CustomIcon } from '@src/components/CustomIcon' const iconSizes = { xs: 12, diff --git a/src/components/AppHeader.tsx b/src/components/AppHeader.tsx index 58dd37b20..81f537648 100644 --- a/src/components/AppHeader.tsx +++ b/src/components/AppHeader.tsx @@ -1,12 +1,13 @@ -import { Toolbar } from '../Toolbar' -import UserSidebarMenu from 'components/UserSidebarMenu' -import { type IndexLoaderData } from 'lib/types' -import ProjectSidebarMenu from './ProjectSidebarMenu' +import { Toolbar } from '@src/Toolbar' +import { CommandBarOpenButton } from '@src/components/CommandBarOpenButton' +import ProjectSidebarMenu from '@src/components/ProjectSidebarMenu' +import { RefreshButton } from '@src/components/RefreshButton' +import UserSidebarMenu from '@src/components/UserSidebarMenu' +import { isDesktop } from '@src/lib/isDesktop' +import { type IndexLoaderData } from '@src/lib/types' +import { useUser } from '@src/machines/appMachine' + import styles from './AppHeader.module.css' -import { RefreshButton } from 'components/RefreshButton' -import { CommandBarOpenButton } from './CommandBarOpenButton' -import { isDesktop } from 'lib/isDesktop' -import { useUser } from 'machines/appMachine' interface AppHeaderProps extends React.PropsWithChildren { showToolbar?: boolean diff --git a/src/components/AstExplorer.tsx b/src/components/AstExplorer.tsx index 5d85ab7b4..4e0fba201 100644 --- a/src/components/AstExplorer.tsx +++ b/src/components/AstExplorer.tsx @@ -1,13 +1,15 @@ -import { useModelingContext } from 'hooks/useModelingContext' -import { editorManager, kclManager } from 'lib/singletons' -import { getNodeFromPath } from 'lang/queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' import { useEffect, useRef, useState } from 'react' -import { trap } from 'lib/trap' -import { codeToIdSelections } from 'lib/selections' -import { codeRefFromRange } from 'lang/std/artifactGraph' -import { defaultSourceRange, topLevelRange } from 'lang/wasm' -import { isArray } from 'lib/utils' + +import { useModelingContext } from '@src/hooks/useModelingContext' +import { getNodeFromPath } from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import { codeRefFromRange } from '@src/lang/std/artifactGraph' +import { topLevelRange } from '@src/lang/util' +import { defaultSourceRange } from '@src/lang/wasm' +import { codeToIdSelections } from '@src/lib/selections' +import { editorManager, kclManager } from '@src/lib/singletons' +import { trap } from '@src/lib/trap' +import { isArray } from '@src/lib/utils' export function AstExplorer() { const { context } = useModelingContext() diff --git a/src/components/AvailableVarsHelpers.tsx b/src/components/AvailableVarsHelpers.tsx index 40f624d35..c880069fb 100644 --- a/src/components/AvailableVarsHelpers.tsx +++ b/src/components/AvailableVarsHelpers.tsx @@ -1,10 +1,10 @@ -import { BinaryPart } from '../lang/wasm' import { - createLocalName, createLiteral, + createLocalName, createUnaryExpression, -} from '../lang/modifyAst' -import { PrevVariable } from '../lang/queryAst' +} from '@src/lang/create' +import type { PrevVariable } from '@src/lang/queryAst' +import type { BinaryPart } from '@src/lang/wasm' export const AvailableVars = ({ onVarClick, diff --git a/src/components/CamToggle.tsx b/src/components/CamToggle.tsx index 4e1b3d48a..d80ce652f 100644 --- a/src/components/CamToggle.tsx +++ b/src/components/CamToggle.tsx @@ -1,8 +1,9 @@ -import { useState, useEffect } from 'react' -import { EngineCommandManagerEvents } from 'lang/std/engineConnection' -import { engineCommandManager, sceneInfra } from 'lib/singletons' -import { throttle, isReducedMotion } from 'lib/utils' -import { reportRejection } from 'lib/trap' +import { useEffect, useState } from 'react' + +import { EngineCommandManagerEvents } from '@src/lang/std/engineConnection' +import { engineCommandManager, sceneInfra } from '@src/lib/singletons' +import { reportRejection } from '@src/lib/trap' +import { isReducedMotion, throttle } from '@src/lib/utils' const updateDollyZoom = throttle( (newFov: number) => sceneInfra.camControls.dollyZoom(newFov), diff --git a/src/components/CameraProjectionToggle.tsx b/src/components/CameraProjectionToggle.tsx index 907351dea..314fc56f5 100644 --- a/src/components/CameraProjectionToggle.tsx +++ b/src/components/CameraProjectionToggle.tsx @@ -1,7 +1,8 @@ import { Switch } from '@headlessui/react' -import { settingsActor, useSettings } from 'machines/appMachine' import { useEffect, useState } from 'react' +import { settingsActor, useSettings } from '@src/machines/appMachine' + export function CameraProjectionToggle() { const settings = useSettings() const isCameraProjectionPerspective = diff --git a/src/components/CommandBar/CommandArgOptionInput.tsx b/src/components/CommandBar/CommandArgOptionInput.tsx index 427fcfbf6..ac4195f0f 100644 --- a/src/components/CommandBar/CommandArgOptionInput.tsx +++ b/src/components/CommandBar/CommandArgOptionInput.tsx @@ -1,10 +1,17 @@ import { Combobox } from '@headlessui/react' import { useSelector } from '@xstate/react' import Fuse from 'fuse.js' -import { CommandArgument, CommandArgumentOption } from 'lib/commandTypes' -import { commandBarActor, useCommandBarState } from 'machines/commandBarMachine' import { useEffect, useMemo, useRef, useState } from 'react' -import { AnyStateMachine, StateFrom } from 'xstate' +import type { AnyStateMachine, StateFrom } from 'xstate' + +import type { + CommandArgument, + CommandArgumentOption, +} from '@src/lib/commandTypes' +import { + commandBarActor, + useCommandBarState, +} from '@src/machines/commandBarMachine' const contextSelector = (snapshot: StateFrom | undefined) => snapshot?.context diff --git a/src/components/CommandBar/CommandBar.tsx b/src/components/CommandBar/CommandBar.tsx index 07ca73b44..30a834d49 100644 --- a/src/components/CommandBar/CommandBar.tsx +++ b/src/components/CommandBar/CommandBar.tsx @@ -1,13 +1,17 @@ import { Dialog, Popover, Transition } from '@headlessui/react' import { Fragment, useEffect } from 'react' -import CommandBarArgument from './CommandBarArgument' -import CommandComboBox from '../CommandComboBox' -import CommandBarReview from './CommandBarReview' import { useLocation } from 'react-router-dom' -import useHotkeyWrapper from 'lib/hotkeyWrapper' -import { CustomIcon } from 'components/CustomIcon' -import Tooltip from 'components/Tooltip' -import { commandBarActor, useCommandBarState } from 'machines/commandBarMachine' + +import CommandBarArgument from '@src/components/CommandBar/CommandBarArgument' +import CommandBarReview from '@src/components/CommandBar/CommandBarReview' +import CommandComboBox from '@src/components/CommandComboBox' +import { CustomIcon } from '@src/components/CustomIcon' +import Tooltip from '@src/components/Tooltip' +import useHotkeyWrapper from '@src/lib/hotkeyWrapper' +import { + commandBarActor, + useCommandBarState, +} from '@src/machines/commandBarMachine' export const COMMAND_PALETTE_HOTKEY = 'mod+k' diff --git a/src/components/CommandBar/CommandBarArgument.tsx b/src/components/CommandBar/CommandBarArgument.tsx index 93d4fa345..0418c3c95 100644 --- a/src/components/CommandBar/CommandBarArgument.tsx +++ b/src/components/CommandBar/CommandBarArgument.tsx @@ -1,12 +1,15 @@ -import CommandArgOptionInput from './CommandArgOptionInput' -import CommandBarBasicInput from './CommandBarBasicInput' -import CommandBarSelectionInput from './CommandBarSelectionInput' -import CommandBarSelectionMixedInput from './CommandBarSelectionMixedInput' -import { CommandArgument } from 'lib/commandTypes' -import CommandBarHeader from './CommandBarHeader' -import CommandBarKclInput from './CommandBarKclInput' -import CommandBarTextareaInput from './CommandBarTextareaInput' -import { commandBarActor, useCommandBarState } from 'machines/commandBarMachine' +import CommandArgOptionInput from '@src/components/CommandBar/CommandArgOptionInput' +import CommandBarBasicInput from '@src/components/CommandBar/CommandBarBasicInput' +import CommandBarHeader from '@src/components/CommandBar/CommandBarHeader' +import CommandBarKclInput from '@src/components/CommandBar/CommandBarKclInput' +import CommandBarSelectionInput from '@src/components/CommandBar/CommandBarSelectionInput' +import CommandBarSelectionMixedInput from '@src/components/CommandBar/CommandBarSelectionMixedInput' +import CommandBarTextareaInput from '@src/components/CommandBar/CommandBarTextareaInput' +import type { CommandArgument } from '@src/lib/commandTypes' +import { + commandBarActor, + useCommandBarState, +} from '@src/machines/commandBarMachine' function CommandBarArgument({ stepBack }: { stepBack: () => void }) { const commandBarState = useCommandBarState() diff --git a/src/components/CommandBar/CommandBarBasicInput.tsx b/src/components/CommandBar/CommandBarBasicInput.tsx index 7398c2a8c..b079af0d2 100644 --- a/src/components/CommandBar/CommandBarBasicInput.tsx +++ b/src/components/CommandBar/CommandBarBasicInput.tsx @@ -1,8 +1,12 @@ -import { CommandArgument } from 'lib/commandTypes' -import { commandBarActor, useCommandBarState } from 'machines/commandBarMachine' import { useEffect, useRef } from 'react' import { useHotkeys } from 'react-hotkeys-hook' +import type { CommandArgument } from '@src/lib/commandTypes' +import { + commandBarActor, + useCommandBarState, +} from '@src/machines/commandBarMachine' + function CommandBarBasicInput({ arg, stepBack, diff --git a/src/components/CommandBar/CommandBarHeader.tsx b/src/components/CommandBar/CommandBarHeader.tsx index 64bda41a4..7d72e31dd 100644 --- a/src/components/CommandBar/CommandBarHeader.tsx +++ b/src/components/CommandBar/CommandBarHeader.tsx @@ -1,12 +1,20 @@ -import { CustomIcon } from '../CustomIcon' import React, { useMemo, useState } from 'react' -import { ActionButton } from '../ActionButton' -import { Selections, getSelectionTypeDisplayText } from 'lib/selections' import { useHotkeys } from 'react-hotkeys-hook' -import { KclCommandValue, KclExpressionWithVariable } from 'lib/commandTypes' -import Tooltip from 'components/Tooltip' -import { roundOff } from 'lib/utils' -import { commandBarActor, useCommandBarState } from 'machines/commandBarMachine' + +import { ActionButton } from '@src/components/ActionButton' +import { CustomIcon } from '@src/components/CustomIcon' +import Tooltip from '@src/components/Tooltip' +import type { + KclCommandValue, + KclExpressionWithVariable, +} from '@src/lib/commandTypes' +import type { Selections } from '@src/lib/selections' +import { getSelectionTypeDisplayText } from '@src/lib/selections' +import { roundOff } from '@src/lib/utils' +import { + commandBarActor, + useCommandBarState, +} from '@src/machines/commandBarMachine' function CommandBarHeader({ children }: React.PropsWithChildren) { const commandBarState = useCommandBarState() diff --git a/src/components/CommandBar/CommandBarKclInput.tsx b/src/components/CommandBar/CommandBarKclInput.tsx index 1014e38f1..68204a2a7 100644 --- a/src/components/CommandBar/CommandBarKclInput.tsx +++ b/src/components/CommandBar/CommandBarKclInput.tsx @@ -1,33 +1,41 @@ +import type { Completion } from '@codemirror/autocomplete' import { closeBrackets, closeBracketsKeymap, - Completion, completionKeymap, completionStatus, } from '@codemirror/autocomplete' -import { EditorView, keymap, ViewUpdate } from '@codemirror/view' -import { CustomIcon } from 'components/CustomIcon' -import { CommandArgument, KclCommandValue } from 'lib/commandTypes' -import { getSystemTheme } from 'lib/theme' -import { useCalculateKclExpression } from 'lib/useCalculateKclExpression' -import { roundOff } from 'lib/utils' -import { varMentions } from 'lib/varCompletionExtension' -import { useEffect, useMemo, useRef, useState } from 'react' -import { useHotkeys } from 'react-hotkeys-hook' -import styles from './CommandBarKclInput.module.css' -import { createLocalName, createVariableDeclaration } from 'lang/modifyAst' -import { useCodeMirror } from 'components/ModelingSidebar/ModelingPanes/CodeEditor' +import type { ViewUpdate } from '@codemirror/view' +import { EditorView, keymap } from '@codemirror/view' import { useSelector } from '@xstate/react' -import { commandBarActor, useCommandBarState } from 'machines/commandBarMachine' -import { useSettings } from 'machines/appMachine' +import { useEffect, useMemo, useRef, useState } from 'react' import toast from 'react-hot-toast' -import { AnyStateMachine, SnapshotFrom } from 'xstate' -import { kclManager } from 'lib/singletons' -import { getNodeFromPath } from 'lang/queryAst' -import { isPathToNode, SourceRange, VariableDeclarator } from 'lang/wasm' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { err } from 'lib/trap' -import { Spinner } from 'components/Spinner' +import { useHotkeys } from 'react-hotkeys-hook' +import type { AnyStateMachine, SnapshotFrom } from 'xstate' + +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { CustomIcon } from '@src/components/CustomIcon' +import { useCodeMirror } from '@src/components/ModelingSidebar/ModelingPanes/CodeEditor' +import { Spinner } from '@src/components/Spinner' +import { createLocalName, createVariableDeclaration } from '@src/lang/create' +import { getNodeFromPath } from '@src/lang/queryAst' +import type { SourceRange, VariableDeclarator } from '@src/lang/wasm' +import { isPathToNode } from '@src/lang/wasm' +import type { CommandArgument, KclCommandValue } from '@src/lib/commandTypes' +import { kclManager } from '@src/lib/singletons' +import { getSystemTheme } from '@src/lib/theme' +import { err } from '@src/lib/trap' +import { useCalculateKclExpression } from '@src/lib/useCalculateKclExpression' +import { roundOff } from '@src/lib/utils' +import { varMentions } from '@src/lib/varCompletionExtension' +import { useSettings } from '@src/machines/appMachine' +import { + commandBarActor, + useCommandBarState, +} from '@src/machines/commandBarMachine' + +import styles from './CommandBarKclInput.module.css' // TODO: remove the need for this selector once we decouple all actors from React const machineContextSelector = (snapshot?: SnapshotFrom) => diff --git a/src/components/CommandBar/CommandBarReview.tsx b/src/components/CommandBar/CommandBarReview.tsx index a944560ba..8eb52e9ad 100644 --- a/src/components/CommandBar/CommandBarReview.tsx +++ b/src/components/CommandBar/CommandBarReview.tsx @@ -1,7 +1,11 @@ -import { commandBarActor, useCommandBarState } from 'machines/commandBarMachine' -import CommandBarHeader from './CommandBarHeader' import { useHotkeys } from 'react-hotkeys-hook' +import CommandBarHeader from '@src/components/CommandBar/CommandBarHeader' +import { + commandBarActor, + useCommandBarState, +} from '@src/machines/commandBarMachine' + function CommandBarReview({ stepBack }: { stepBack: () => void }) { const commandBarState = useCommandBarState() const { diff --git a/src/components/CommandBar/CommandBarSelectionInput.tsx b/src/components/CommandBar/CommandBarSelectionInput.tsx index 454c22cf5..db06d6473 100644 --- a/src/components/CommandBar/CommandBarSelectionInput.tsx +++ b/src/components/CommandBar/CommandBarSelectionInput.tsx @@ -1,18 +1,22 @@ import { useSelector } from '@xstate/react' -import { Artifact } from 'lang/std/artifactGraph' -import { CommandArgument } from 'lib/commandTypes' +import { useEffect, useMemo, useRef, useState } from 'react' +import type { StateFrom } from 'xstate' + +import type { Artifact } from '@src/lang/std/artifactGraph' +import type { CommandArgument } from '@src/lib/commandTypes' import { canSubmitSelectionArg, getSelectionCountByType, getSelectionTypeDisplayText, -} from 'lib/selections' -import { engineCommandManager, kclManager } from 'lib/singletons' -import { reportRejection } from 'lib/trap' -import { toSync } from 'lib/utils' -import { commandBarActor, useCommandBarState } from 'machines/commandBarMachine' -import { modelingMachine } from 'machines/modelingMachine' -import { useEffect, useMemo, useRef, useState } from 'react' -import { StateFrom } from 'xstate' +} from '@src/lib/selections' +import { engineCommandManager, kclManager } from '@src/lib/singletons' +import { reportRejection } from '@src/lib/trap' +import { toSync } from '@src/lib/utils' +import { + commandBarActor, + useCommandBarState, +} from '@src/machines/commandBarMachine' +import type { modelingMachine } from '@src/machines/modelingMachine' const semanticEntityNames: { [key: string]: Array diff --git a/src/components/CommandBar/CommandBarSelectionMixedInput.tsx b/src/components/CommandBar/CommandBarSelectionMixedInput.tsx index fbee6d5ae..1db4dd3be 100644 --- a/src/components/CommandBar/CommandBarSelectionMixedInput.tsx +++ b/src/components/CommandBar/CommandBarSelectionMixedInput.tsx @@ -1,13 +1,17 @@ +import { useSelector } from '@xstate/react' import { useEffect, useMemo, useRef, useState } from 'react' -import { CommandArgument } from 'lib/commandTypes' + +import type { CommandArgument } from '@src/lib/commandTypes' +import type { Selections } from '@src/lib/selections' import { - Selections, canSubmitSelectionArg, getSelectionCountByType, -} from 'lib/selections' -import { useSelector } from '@xstate/react' -import { commandBarActor, useCommandBarState } from 'machines/commandBarMachine' -import { kclManager } from 'lib/singletons' +} from '@src/lib/selections' +import { kclManager } from '@src/lib/singletons' +import { + commandBarActor, + useCommandBarState, +} from '@src/machines/commandBarMachine' const selectionSelector = (snapshot: any) => snapshot?.context.selectionRanges diff --git a/src/components/CommandBar/CommandBarTextareaInput.tsx b/src/components/CommandBar/CommandBarTextareaInput.tsx index 589cf24c3..78c9cb885 100644 --- a/src/components/CommandBar/CommandBarTextareaInput.tsx +++ b/src/components/CommandBar/CommandBarTextareaInput.tsx @@ -1,8 +1,13 @@ -import { CommandArgument } from 'lib/commandTypes' -import { commandBarActor, useCommandBarState } from 'machines/commandBarMachine' -import { RefObject, useEffect, useRef } from 'react' +import type { RefObject } from 'react' +import { useEffect, useRef } from 'react' import { useHotkeys } from 'react-hotkeys-hook' +import type { CommandArgument } from '@src/lib/commandTypes' +import { + commandBarActor, + useCommandBarState, +} from '@src/machines/commandBarMachine' + function CommandBarTextareaInput({ arg, stepBack, diff --git a/src/components/CommandBarOpenButton.tsx b/src/components/CommandBarOpenButton.tsx index a0b3d466e..0d1cf26a0 100644 --- a/src/components/CommandBarOpenButton.tsx +++ b/src/components/CommandBarOpenButton.tsx @@ -1,7 +1,7 @@ -import usePlatform from 'hooks/usePlatform' -import { hotkeyDisplay } from 'lib/hotkeyWrapper' -import { COMMAND_PALETTE_HOTKEY } from './CommandBar/CommandBar' -import { commandBarActor } from 'machines/commandBarMachine' +import { COMMAND_PALETTE_HOTKEY } from '@src/components/CommandBar/CommandBar' +import usePlatform from '@src/hooks/usePlatform' +import { hotkeyDisplay } from '@src/lib/hotkeyWrapper' +import { commandBarActor } from '@src/machines/commandBarMachine' export function CommandBarOpenButton() { const platform = usePlatform() diff --git a/src/components/CommandComboBox.tsx b/src/components/CommandComboBox.tsx index c589d8a2b..983dfea61 100644 --- a/src/components/CommandComboBox.tsx +++ b/src/components/CommandComboBox.tsx @@ -1,11 +1,12 @@ import { Combobox } from '@headlessui/react' import Fuse from 'fuse.js' -import { Command } from 'lib/commandTypes' import { useEffect, useState } from 'react' -import { CustomIcon } from './CustomIcon' -import { getActorNextEvents } from 'lib/utils' -import { sortCommands } from 'lib/commandUtils' -import { commandBarActor } from 'machines/commandBarMachine' + +import { CustomIcon } from '@src/components/CustomIcon' +import type { Command } from '@src/lib/commandTypes' +import { sortCommands } from '@src/lib/commandUtils' +import { getActorNextEvents } from '@src/lib/utils' +import { commandBarActor } from '@src/machines/commandBarMachine' function CommandComboBox({ options, diff --git a/src/components/ContextMenu.tsx b/src/components/ContextMenu.tsx index b263e29c2..106567929 100644 --- a/src/components/ContextMenu.tsx +++ b/src/components/ContextMenu.tsx @@ -1,15 +1,11 @@ -import toast from 'react-hot-toast' -import { ActionIcon, ActionIconProps } from './ActionIcon' -import { - RefObject, - useCallback, - useEffect, - useMemo, - useRef, - useState, -} from 'react' -import { useHotkeys } from 'react-hotkeys-hook' import { Dialog } from '@headlessui/react' +import type { RefObject } from 'react' +import { useCallback, useEffect, useMemo, useRef, useState } from 'react' +import toast from 'react-hot-toast' +import { useHotkeys } from 'react-hotkeys-hook' + +import type { ActionIconProps } from '@src/components/ActionIcon' +import { ActionIcon } from '@src/components/ActionIcon' export interface ContextMenuProps extends Omit, 'children'> { diff --git a/src/components/DebugArtifactGraph.tsx b/src/components/DebugArtifactGraph.tsx index 5436ab237..32a432334 100644 --- a/src/components/DebugArtifactGraph.tsx +++ b/src/components/DebugArtifactGraph.tsx @@ -1,8 +1,11 @@ import { useMemo } from 'react' -import { kclManager } from 'lib/singletons' -import { expandPlane, PlaneArtifactRich } from 'lang/std/artifactGraph' -import { ArtifactGraph } from 'lang/wasm' -import { DebugDisplayArray, GenericObj } from './DebugDisplayObj' + +import type { GenericObj } from '@src/components/DebugDisplayObj' +import { DebugDisplayArray } from '@src/components/DebugDisplayObj' +import type { PlaneArtifactRich } from '@src/lang/std/artifactGraph' +import { expandPlane } from '@src/lang/std/artifactGraph' +import type { ArtifactGraph } from '@src/lang/wasm' +import { kclManager } from '@src/lib/singletons' export function DebugArtifactGraph() { const artifactGraphTree = useMemo(() => { diff --git a/src/components/DebugDisplayObj.tsx b/src/components/DebugDisplayObj.tsx index 55b6ec244..ee3c54ef6 100644 --- a/src/components/DebugDisplayObj.tsx +++ b/src/components/DebugDisplayObj.tsx @@ -1,6 +1,7 @@ -import { isArray, isNonNullable } from 'lib/utils' import { useRef, useState } from 'react' +import { isArray, isNonNullable } from '@src/lib/utils' + type Primitive = string | number | bigint | boolean | symbol | null | undefined export type GenericObj = { diff --git a/src/components/DownloadAppBanner.tsx b/src/components/DownloadAppBanner.tsx index cbc278d75..702cee99b 100644 --- a/src/components/DownloadAppBanner.tsx +++ b/src/components/DownloadAppBanner.tsx @@ -1,7 +1,8 @@ import { Dialog } from '@headlessui/react' -import { ActionButton } from './ActionButton' import { useState } from 'react' -import { useSettings } from 'machines/appMachine' + +import { ActionButton } from '@src/components/ActionButton' +import { useSettings } from '@src/machines/appMachine' const DownloadAppBanner = () => { const settings = useSettings() diff --git a/src/components/DragWarningToast.tsx b/src/components/DragWarningToast.tsx index 1f4c2a98d..a7d72abcd 100644 --- a/src/components/DragWarningToast.tsx +++ b/src/components/DragWarningToast.tsx @@ -1,4 +1,4 @@ -import { MoveDesc } from 'machines/modelingMachine' +import type { MoveDesc } from '@src/machines/modelingMachine' export const DragWarningToast = (moveDescs: MoveDesc[]) => { if (moveDescs.length === 1) { diff --git a/src/components/EngineCommands.tsx b/src/components/EngineCommands.tsx index ace639518..6bf3cfd20 100644 --- a/src/components/EngineCommands.tsx +++ b/src/components/EngineCommands.tsx @@ -1,7 +1,8 @@ -import { CommandLog } from 'lang/std/engineConnection' -import { engineCommandManager } from 'lib/singletons' -import { reportRejection } from 'lib/trap' -import { useState, useEffect } from 'react' +import { useEffect, useState } from 'react' + +import type { CommandLog } from '@src/lang/std/engineConnection' +import { engineCommandManager } from '@src/lib/singletons' +import { reportRejection } from '@src/lib/trap' export function useEngineCommands(): [CommandLog[], () => void] { const [engineCommands, setEngineCommands] = useState( diff --git a/src/components/ErrorPage.tsx b/src/components/ErrorPage.tsx index 0705074be..73467e226 100644 --- a/src/components/ErrorPage.tsx +++ b/src/components/ErrorPage.tsx @@ -1,12 +1,13 @@ -import { isDesktop } from 'lib/isDesktop' -import { useRouteError, isRouteErrorResponse } from 'react-router-dom' -import { ActionButton } from './ActionButton' import { faBug, faHome, faRefresh, faTrash, } from '@fortawesome/free-solid-svg-icons' +import { isRouteErrorResponse, useRouteError } from 'react-router-dom' + +import { ActionButton } from '@src/components/ActionButton' +import { isDesktop } from '@src/lib/isDesktop' /** Type narrowing function of unknown error to a string */ function errorMessage(error: unknown): string { diff --git a/src/components/FileMachineProvider.tsx b/src/components/FileMachineProvider.tsx index dcfd2fb6a..d65cb5145 100644 --- a/src/components/FileMachineProvider.tsx +++ b/src/components/FileMachineProvider.tsx @@ -1,41 +1,39 @@ import { useMachine } from '@xstate/react' -import { useLocation, useNavigate, useRouteLoaderData } from 'react-router-dom' -import { type IndexLoaderData } from 'lib/types' -import { BROWSER_PATH, PATHS } from 'lib/paths' import React, { createContext, useEffect, useMemo } from 'react' import { toast } from 'react-hot-toast' -import { +import { useLocation, useNavigate, useRouteLoaderData } from 'react-router-dom' +import type { Actor, AnyStateMachine, ContextFrom, Prop, StateFrom, - fromPromise, } from 'xstate' -import { fileMachine } from 'machines/fileMachine' -import { isDesktop } from 'lib/isDesktop' +import { fromPromise } from 'xstate' + +import { newKclFile } from '@src/lang/project' +import { createNamedViewsCommand } from '@src/lib/commandBarConfigs/namedViewsConfig' +import { createRouteCommands } from '@src/lib/commandBarConfigs/routeCommandConfig' import { DEFAULT_DEFAULT_LENGTH_UNIT, DEFAULT_FILE_NAME, DEFAULT_PROJECT_KCL_FILE, FILE_EXT, -} from 'lib/constants' -import { getProjectInfo } from 'lib/desktop' -import { getNextDirName, getNextFileName } from 'lib/desktopFS' -import { kclCommands } from 'lib/kclCommands' -import { codeManager, kclManager } from 'lib/singletons' -import { - getKclSamplesManifest, - KclSamplesManifestItem, -} from 'lib/getKclSamplesManifest' -import { markOnce } from 'lib/performance' -import { commandBarActor } from 'machines/commandBarMachine' -import { useSettings } from 'machines/appMachine' -import { createRouteCommands } from 'lib/commandBarConfigs/routeCommandConfig' -import { useToken } from 'machines/appMachine' -import { createNamedViewsCommand } from 'lib/commandBarConfigs/namedViewsConfig' -import { err, reportRejection } from 'lib/trap' -import { newKclFile } from 'lang/project' +} from '@src/lib/constants' +import { getProjectInfo } from '@src/lib/desktop' +import { getNextDirName, getNextFileName } from '@src/lib/desktopFS' +import type { KclSamplesManifestItem } from '@src/lib/getKclSamplesManifest' +import { getKclSamplesManifest } from '@src/lib/getKclSamplesManifest' +import { isDesktop } from '@src/lib/isDesktop' +import { kclCommands } from '@src/lib/kclCommands' +import { BROWSER_PATH, PATHS } from '@src/lib/paths' +import { markOnce } from '@src/lib/performance' +import { codeManager, kclManager } from '@src/lib/singletons' +import { err, reportRejection } from '@src/lib/trap' +import { type IndexLoaderData } from '@src/lib/types' +import { useSettings, useToken } from '@src/machines/appMachine' +import { commandBarActor } from '@src/machines/commandBarMachine' +import { fileMachine } from '@src/machines/fileMachine' type MachineContext = { state: StateFrom diff --git a/src/components/FileTree.tsx b/src/components/FileTree.tsx index 27d5f5f21..35ee4b7d9 100644 --- a/src/components/FileTree.tsx +++ b/src/components/FileTree.tsx @@ -1,30 +1,34 @@ -import type { IndexLoaderData } from 'lib/types' -import { PATHS } from 'lib/paths' -import { ActionButton } from './ActionButton' -import Tooltip from './Tooltip' -import { Dispatch, useCallback, useRef, useState } from 'react' -import { useNavigate, useRouteLoaderData } from 'react-router-dom' -import { Disclosure } from '@headlessui/react' -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faChevronRight, faPencil } from '@fortawesome/free-solid-svg-icons' -import { useFileContext } from 'hooks/useFileContext' +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { Disclosure } from '@headlessui/react' +import type { Dispatch } from 'react' +import { useCallback, useRef, useState } from 'react' +import { useNavigate, useRouteLoaderData } from 'react-router-dom' + +import { ActionButton } from '@src/components/ActionButton' +import { ContextMenu, ContextMenuItem } from '@src/components/ContextMenu' +import { CustomIcon } from '@src/components/CustomIcon' +import { useLspContext } from '@src/components/LspProvider' +import { DeleteConfirmationDialog } from '@src/components/ProjectCard/DeleteProjectDialog' +import Tooltip from '@src/components/Tooltip' +import { useFileContext } from '@src/hooks/useFileContext' +import { useFileSystemWatcher } from '@src/hooks/useFileSystemWatcher' +import { useModelingContext } from '@src/hooks/useModelingContext' +import usePlatform from '@src/hooks/usePlatform' +import { useKclContext } from '@src/lang/KclProvider' +import type { KCLError } from '@src/lang/errors' +import { kclErrorsByFilename } from '@src/lang/errors' +import { normalizeLineEndings } from '@src/lib/codeEditor' +import { FILE_EXT } from '@src/lib/constants' +import { sortFilesAndDirectories } from '@src/lib/desktopFS' +import useHotkeyWrapper from '@src/lib/hotkeyWrapper' +import { PATHS } from '@src/lib/paths' +import type { FileEntry } from '@src/lib/project' +import { codeManager, kclManager } from '@src/lib/singletons' +import { reportRejection } from '@src/lib/trap' +import type { IndexLoaderData } from '@src/lib/types' + import styles from './FileTree.module.css' -import { sortFilesAndDirectories } from 'lib/desktopFS' -import { FILE_EXT } from 'lib/constants' -import { CustomIcon } from './CustomIcon' -import { codeManager, kclManager } from 'lib/singletons' -import { useLspContext } from './LspProvider' -import useHotkeyWrapper from 'lib/hotkeyWrapper' -import { useModelingContext } from 'hooks/useModelingContext' -import { DeleteConfirmationDialog } from './ProjectCard/DeleteProjectDialog' -import { ContextMenu, ContextMenuItem } from './ContextMenu' -import usePlatform from 'hooks/usePlatform' -import { FileEntry } from 'lib/project' -import { useFileSystemWatcher } from 'hooks/useFileSystemWatcher' -import { normalizeLineEndings } from 'lib/codeEditor' -import { reportRejection } from 'lib/trap' -import { useKclContext } from 'lang/KclProvider' -import { kclErrorsByFilename, KCLError } from 'lang/errors' function getIndentationCSS(level: number) { return `calc(1rem * ${level + 1})` diff --git a/src/components/Gizmo.tsx b/src/components/Gizmo.tsx index 06c681bb6..b05dddd88 100644 --- a/src/components/Gizmo.tsx +++ b/src/components/Gizmo.tsx @@ -1,34 +1,33 @@ -import { SceneInfra } from 'clientSideScene/sceneInfra' -import { sceneInfra } from 'lib/singletons' -import { MutableRefObject, useEffect, useRef } from 'react' +import { Popover } from '@headlessui/react' +import type { MutableRefObject } from 'react' +import { useEffect, useRef } from 'react' +import type { Camera, ColorRepresentation, Intersection, Object3D } from 'three' import { - WebGLRenderer, - Scene, - OrthographicCamera, BoxGeometry, - SphereGeometry, - MeshBasicMaterial, + Clock, Color, Mesh, - Clock, + MeshBasicMaterial, + OrthographicCamera, Quaternion, - ColorRepresentation, - Vector2, Raycaster, - Camera, - Intersection, - Object3D, + Scene, + SphereGeometry, + Vector2, + WebGLRenderer, } from 'three' -import { Popover } from '@headlessui/react' -import { CustomIcon } from './CustomIcon' -import { reportRejection } from 'lib/trap' + +import type { SceneInfra } from '@src/clientSideScene/sceneInfra' +import { CustomIcon } from '@src/components/CustomIcon' import { - useViewControlMenuItems, ViewControlContextMenu, -} from './ViewControlMenu' -import { AxisNames } from 'lib/constants' -import { useModelingContext } from 'hooks/useModelingContext' -import { useSettings } from 'machines/appMachine' + useViewControlMenuItems, +} from '@src/components/ViewControlMenu' +import { useModelingContext } from '@src/hooks/useModelingContext' +import { AxisNames } from '@src/lib/constants' +import { sceneInfra } from '@src/lib/singletons' +import { reportRejection } from '@src/lib/trap' +import { useSettings } from '@src/machines/appMachine' const CANVAS_SIZE = 80 const FRUSTUM_SIZE = 0.5 diff --git a/src/components/HelpMenu.tsx b/src/components/HelpMenu.tsx index 56a186f22..64c83063d 100644 --- a/src/components/HelpMenu.tsx +++ b/src/components/HelpMenu.tsx @@ -1,16 +1,17 @@ import { Popover } from '@headlessui/react' -import Tooltip from './Tooltip' -import { CustomIcon } from './CustomIcon' import { useLocation, useNavigate } from 'react-router-dom' -import { PATHS } from 'lib/paths' -import { createAndOpenNewTutorialProject } from 'lib/desktopFS' -import { useAbsoluteFilePath } from 'hooks/useAbsoluteFilePath' -import { useLspContext } from './LspProvider' -import { openExternalBrowserIfDesktop } from 'lib/openWindow' -import { reportRejection } from 'lib/trap' -import { settingsActor } from 'machines/appMachine' -import type { WebContentSendPayload } from '../menu/channels' -import { useMenuListener } from 'hooks/useMenu' + +import { CustomIcon } from '@src/components/CustomIcon' +import { useLspContext } from '@src/components/LspProvider' +import Tooltip from '@src/components/Tooltip' +import { useAbsoluteFilePath } from '@src/hooks/useAbsoluteFilePath' +import { useMenuListener } from '@src/hooks/useMenu' +import { createAndOpenNewTutorialProject } from '@src/lib/desktopFS' +import { openExternalBrowserIfDesktop } from '@src/lib/openWindow' +import { PATHS } from '@src/lib/paths' +import { reportRejection } from '@src/lib/trap' +import { settingsActor } from '@src/machines/appMachine' +import type { WebContentSendPayload } from '@src/menu/channels' const HelpMenuDivider = () => (
diff --git a/src/components/Loading.tsx b/src/components/Loading.tsx index 7d2972340..b9950069f 100644 --- a/src/components/Loading.tsx +++ b/src/components/Loading.tsx @@ -1,17 +1,15 @@ import { useEffect, useState } from 'react' +import { Spinner } from '@src/components/Spinner' import { - EngineConnectionStateType, + CONNECTION_ERROR_TEXT, + ConnectionError, DisconnectingType, EngineCommandManagerEvents, EngineConnectionEvents, - ConnectionError, - CONNECTION_ERROR_TEXT, -} from '../lang/std/engineConnection' - -import { engineCommandManager } from '../lib/singletons' - -import { Spinner } from './Spinner' + EngineConnectionStateType, +} from '@src/lang/std/engineConnection' +import { engineCommandManager } from '@src/lib/singletons' interface LoadingProps extends React.PropsWithChildren { className?: string diff --git a/src/components/LowerRightControls.tsx b/src/components/LowerRightControls.tsx index ac942204c..5666422aa 100644 --- a/src/components/LowerRightControls.tsx +++ b/src/components/LowerRightControls.tsx @@ -1,18 +1,19 @@ -import { APP_VERSION, getReleaseUrl } from 'routes/Settings' -import { CustomIcon } from 'components/CustomIcon' -import Tooltip from 'components/Tooltip' -import { PATHS } from 'lib/paths' -import { NetworkHealthIndicator } from 'components/NetworkHealthIndicator' -import { HelpMenu } from './HelpMenu' -import { Link, useLocation } from 'react-router-dom' -import { useAbsoluteFilePath } from 'hooks/useAbsoluteFilePath' -import { coreDump } from 'lang/wasm' import toast from 'react-hot-toast' -import { CoreDumpManager } from 'lib/coredump' -import openWindow, { openExternalBrowserIfDesktop } from 'lib/openWindow' -import { NetworkMachineIndicator } from './NetworkMachineIndicator' -import { ModelStateIndicator } from './ModelStateIndicator' -import { reportRejection } from 'lib/trap' +import { Link, useLocation } from 'react-router-dom' + +import { CustomIcon } from '@src/components/CustomIcon' +import { HelpMenu } from '@src/components/HelpMenu' +import { ModelStateIndicator } from '@src/components/ModelStateIndicator' +import { NetworkHealthIndicator } from '@src/components/NetworkHealthIndicator' +import { NetworkMachineIndicator } from '@src/components/NetworkMachineIndicator' +import Tooltip from '@src/components/Tooltip' +import { useAbsoluteFilePath } from '@src/hooks/useAbsoluteFilePath' +import { coreDump } from '@src/lang/wasm' +import type { CoreDumpManager } from '@src/lib/coredump' +import openWindow, { openExternalBrowserIfDesktop } from '@src/lib/openWindow' +import { PATHS } from '@src/lib/paths' +import { reportRejection } from '@src/lib/trap' +import { APP_VERSION, getReleaseUrl } from '@src/routes/Settings' export function LowerRightControls({ children, diff --git a/src/components/LspProvider.tsx b/src/components/LspProvider.tsx index 71f158eef..355531341 100644 --- a/src/components/LspProvider.tsx +++ b/src/components/LspProvider.tsx @@ -1,32 +1,33 @@ -import type * as LSP from 'vscode-languageserver-protocol' -import React, { createContext, useMemo, useContext, useState } from 'react' +import type { LanguageSupport } from '@codemirror/language' +import type { Extension } from '@codemirror/state' +import type { LanguageServerPlugin } from '@kittycad/codemirror-lsp-client' import { - LanguageServerClient, FromServer, IntoServer, + LanguageServerClient, LspWorkerEventType, - LanguageServerPlugin, } from '@kittycad/codemirror-lsp-client' -import { TEST, VITE_KC_API_BASE_URL } from 'env' -import { kcl } from 'editor/plugins/lsp/kcl/language' -import { copilotPlugin } from 'editor/plugins/lsp/copilot' -import { Extension } from '@codemirror/state' -import { LanguageSupport } from '@codemirror/language' +import { TEST, VITE_KC_API_BASE_URL } from '@src/env' +import React, { createContext, useContext, useMemo, useState } from 'react' import { useNavigate } from 'react-router-dom' -import { PATHS } from 'lib/paths' -import { FileEntry } from 'lib/project' -import Worker from 'editor/plugins/lsp/worker.ts?worker' -import { - KclWorkerOptions, +import type * as LSP from 'vscode-languageserver-protocol' + +import { copilotPlugin } from '@src/editor/plugins/lsp/copilot' +import { kcl } from '@src/editor/plugins/lsp/kcl/language' +import type { CopilotWorkerOptions, - LspWorker, -} from 'editor/plugins/lsp/types' -import { wasmUrl } from 'lang/wasm' -import { PROJECT_ENTRYPOINT } from 'lib/constants' -import { err } from 'lib/trap' -import { isDesktop } from 'lib/isDesktop' -import { codeManager } from 'lib/singletons' -import { useToken } from 'machines/appMachine' + KclWorkerOptions, +} from '@src/editor/plugins/lsp/types' +import { LspWorker } from '@src/editor/plugins/lsp/types' +import Worker from '@src/editor/plugins/lsp/worker.ts?worker' +import { wasmUrl } from '@src/lang/wasm' +import { PROJECT_ENTRYPOINT } from '@src/lib/constants' +import { isDesktop } from '@src/lib/isDesktop' +import { PATHS } from '@src/lib/paths' +import type { FileEntry } from '@src/lib/project' +import { codeManager } from '@src/lib/singletons' +import { err } from '@src/lib/trap' +import { useToken } from '@src/machines/appMachine' function getWorkspaceFolders(): LSP.WorkspaceFolder[] { return [] diff --git a/src/components/MachineManagerProvider.tsx b/src/components/MachineManagerProvider.tsx index 8e0605bae..8a4ca2e3c 100644 --- a/src/components/MachineManagerProvider.tsx +++ b/src/components/MachineManagerProvider.tsx @@ -1,11 +1,11 @@ import { createContext, useEffect, useState } from 'react' -import { engineCommandManager } from 'lib/singletons' -import { isDesktop } from 'lib/isDesktop' -import { components } from 'lib/machine-api' -import { reportRejection } from 'lib/trap' -import { toSync } from 'lib/utils' -import { commandBarActor } from 'machines/commandBarMachine' +import { isDesktop } from '@src/lib/isDesktop' +import type { components } from '@src/lib/machine-api' +import { engineCommandManager } from '@src/lib/singletons' +import { reportRejection } from '@src/lib/trap' +import { toSync } from '@src/lib/utils' +import { commandBarActor } from '@src/machines/commandBarMachine' export type MachinesListing = Array< components['schemas']['MachineInfoResponse'] diff --git a/src/components/ModelStateIndicator.tsx b/src/components/ModelStateIndicator.tsx index 660d7e99c..54e5b52c8 100644 --- a/src/components/ModelStateIndicator.tsx +++ b/src/components/ModelStateIndicator.tsx @@ -1,6 +1,7 @@ -import { useEngineCommands } from './EngineCommands' -import { Spinner } from './Spinner' -import { CustomIcon } from './CustomIcon' +import { CustomIcon } from '@src/components/CustomIcon' +import { useEngineCommands } from '@src/components/EngineCommands' +import { Spinner } from '@src/components/Spinner' + export const ModelStateIndicator = () => { const [commands] = useEngineCommands() const lastCommandType = commands[commands.length - 1]?.type diff --git a/src/components/ModelingMachineProvider.tsx b/src/components/ModelingMachineProvider.tsx index e26f67d23..33dcd4893 100644 --- a/src/components/ModelingMachineProvider.tsx +++ b/src/components/ModelingMachineProvider.tsx @@ -1,70 +1,46 @@ import { useMachine, useSelector } from '@xstate/react' import React, { createContext, + useContext, useEffect, useMemo, useRef, - useContext, } from 'react' -import { - Actor, - ContextFrom, - Prop, - SnapshotFrom, - StateFrom, - assign, - fromPromise, -} from 'xstate' -import { - getPersistedContext, - modelingMachine, - modelingMachineDefaultContext, -} from 'machines/modelingMachine' -import { useSetupEngineManager } from 'hooks/useSetupEngineManager' -import { - isCursorInSketchCommandRange, - updateSketchDetailsNodePaths, -} from 'lang/util' -import { - kclManager, - sceneInfra, - engineCommandManager, - codeManager, - editorManager, - sceneEntitiesManager, - rustContext, -} from 'lib/singletons' -import { - MachineManager, - MachineManagerContext, -} from 'components/MachineManagerProvider' +import toast from 'react-hot-toast' import { useHotkeys } from 'react-hotkeys-hook' -import { applyConstraintHorzVertDistance } from './Toolbar/SetHorzVertDistance' -import { - angleBetweenInfo, - applyConstraintAngleBetween, -} from './Toolbar/SetAngleBetween' -import { - applyConstraintAngleLength, - applyConstraintLength, -} from './Toolbar/setAngleLength' -import { - handleSelectionBatch, - Selections, - updateSelections, -} from 'lib/selections' -import { applyConstraintIntersect } from './Toolbar/Intersect' -import { applyConstraintAbsDistance } from './Toolbar/SetAbsDistance' -import useStateMachineCommands from 'hooks/useStateMachineCommands' -import { - ModelingCommandSchema, - modelingMachineCommandConfig, -} from 'lib/commandBarConfigs/modelingCommandConfig' +import { useLoaderData, useNavigate, useSearchParams } from 'react-router-dom' +import type { Actor, ContextFrom, Prop, SnapshotFrom, StateFrom } from 'xstate' +import { assign, fromPromise } from 'xstate' + +import type { + OutputFormat3d, + Point3d, +} from '@rust/kcl-lib/bindings/ModelingCmd' +import type { Node } from '@rust/kcl-lib/bindings/Node' +import type { Plane } from '@rust/kcl-lib/bindings/Plane' + +import { letEngineAnimateAndSyncCamAfter } from '@src/clientSideScene/CameraControls' import { SEGMENT_BODIES, getParentGroup, - getSketchOrientationDetails, -} from 'clientSideScene/sceneEntities' +} from '@src/clientSideScene/sceneConstants' +import type { MachineManager } from '@src/components/MachineManagerProvider' +import { MachineManagerContext } from '@src/components/MachineManagerProvider' +import { applyConstraintIntersect } from '@src/components/Toolbar/Intersect' +import { applyConstraintAbsDistance } from '@src/components/Toolbar/SetAbsDistance' +import { + angleBetweenInfo, + applyConstraintAngleBetween, +} from '@src/components/Toolbar/SetAngleBetween' +import { applyConstraintHorzVertDistance } from '@src/components/Toolbar/SetHorzVertDistance' +import { + applyConstraintAngleLength, + applyConstraintLength, +} from '@src/components/Toolbar/setAngleLength' +import { useFileContext } from '@src/hooks/useFileContext' +import { useSetupEngineManager } from '@src/hooks/useSetupEngineManager' +import useStateMachineCommands from '@src/hooks/useStateMachineCommands' +import { updateModelingState } from '@src/lang/modelingWorkflows' import { insertNamedConstant, replaceValueAtNodePath, @@ -72,55 +48,69 @@ import { sketchOnOffsetPlane, splitPipedProfile, startSketchOnDefault, -} from 'lang/modifyAst' -import { - KclValue, - PathToNode, - PipeExpression, - Program, - VariableDeclaration, - parse, - recast, - resultIsOk, -} from 'lang/wasm' +} from '@src/lang/modifyAst' import { artifactIsPlaneWithPaths, doesSketchPipeNeedSplitting, getNodeFromPath, isCursorInFunctionDefinition, traverse, -} from 'lang/queryAst' -import toast from 'react-hot-toast' -import { useLoaderData, useNavigate, useSearchParams } from 'react-router-dom' -import { letEngineAnimateAndSyncCamAfter } from 'clientSideScene/CameraControls' -import { err, reportRejection, trap, reject } from 'lib/trap' -import { - EngineConnectionStateType, - EngineConnectionEvents, -} from 'lang/std/engineConnection' -import { submitAndAwaitTextToKcl } from 'lib/textToCad' -import { useFileContext } from 'hooks/useFileContext' -import { platform, uuidv4 } from 'lib/utils' -import { Node } from '@rust/kcl-lib/bindings/Node' +} from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' import { getFaceCodeRef, getPathsFromArtifact, getPlaneFromArtifact, -} from 'lang/std/artifactGraph' -import { promptToEditFlow } from 'lib/promptToEdit' -import { kclEditorActor } from 'machines/kclEditorMachine' -import { commandBarActor } from 'machines/commandBarMachine' -import { useToken } from 'machines/appMachine' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { useSettings } from 'machines/appMachine' -import { IndexLoaderData } from 'lib/types' -import { OutputFormat3d, Point3d } from '@rust/kcl-lib/bindings/ModelingCmd' -import { EXPORT_TOAST_MESSAGES, MAKE_TOAST_MESSAGES } from 'lib/constants' -import { exportMake } from 'lib/exportMake' -import { exportSave } from 'lib/exportSave' -import { Plane } from '@rust/kcl-lib/bindings/Plane' -import { updateModelingState } from 'lang/modelingWorkflows' -import { EXECUTION_TYPE_MOCK } from 'lib/constants' +} from '@src/lang/std/artifactGraph' +import { + EngineConnectionEvents, + EngineConnectionStateType, +} from '@src/lang/std/engineConnection' +import { + isCursorInSketchCommandRange, + updateSketchDetailsNodePaths, +} from '@src/lang/util' +import type { + KclValue, + PathToNode, + PipeExpression, + Program, + VariableDeclaration, +} from '@src/lang/wasm' +import { parse, recast, resultIsOk } from '@src/lang/wasm' +import type { ModelingCommandSchema } from '@src/lib/commandBarConfigs/modelingCommandConfig' +import { modelingMachineCommandConfig } from '@src/lib/commandBarConfigs/modelingCommandConfig' +import { + EXECUTION_TYPE_MOCK, + EXPORT_TOAST_MESSAGES, + MAKE_TOAST_MESSAGES, +} from '@src/lib/constants' +import { exportMake } from '@src/lib/exportMake' +import { exportSave } from '@src/lib/exportSave' +import { promptToEditFlow } from '@src/lib/promptToEdit' +import type { Selections } from '@src/lib/selections' +import { handleSelectionBatch, updateSelections } from '@src/lib/selections' +import { + codeManager, + editorManager, + engineCommandManager, + kclManager, + rustContext, + sceneEntitiesManager, + sceneInfra, +} from '@src/lib/singletons' +import { submitAndAwaitTextToKcl } from '@src/lib/textToCad' +import { err, reject, reportRejection, trap } from '@src/lib/trap' +import type { IndexLoaderData } from '@src/lib/types' +import { platform, uuidv4 } from '@src/lib/utils' +import { useSettings, useToken } from '@src/machines/appMachine' +import { commandBarActor } from '@src/machines/commandBarMachine' +import { kclEditorActor } from '@src/machines/kclEditorMachine' +import { + getPersistedContext, + modelingMachine, + modelingMachineDefaultContext, +} from '@src/machines/modelingMachine' export const ModelingMachineContext = createContext( {} as { @@ -911,7 +901,9 @@ export const ModelingMachineProvider = ({ } return Promise.reject(new Error('No sketch')) } - const info = await getSketchOrientationDetails(sketch.value) + const info = await sceneEntitiesManager.getSketchOrientationDetails( + sketch.value + ) await letEngineAnimateAndSyncCamAfter( engineCommandManager, info?.sketchDetails?.faceId || '' diff --git a/src/components/ModelingSidebar/ModelingPane.tsx b/src/components/ModelingSidebar/ModelingPane.tsx index b39c0e05d..734b8dbd6 100644 --- a/src/components/ModelingSidebar/ModelingPane.tsx +++ b/src/components/ModelingSidebar/ModelingPane.tsx @@ -1,12 +1,14 @@ -import { ReactNode } from 'react' +import type { IconDefinition } from '@fortawesome/free-solid-svg-icons' +import type { ReactNode } from 'react' + +import { ActionButton } from '@src/components/ActionButton' +import { ActionIcon } from '@src/components/ActionIcon' +import type { CustomIconName } from '@src/components/CustomIcon' +import Tooltip from '@src/components/Tooltip' +import { useSettings } from '@src/machines/appMachine' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + import styles from './ModelingPane.module.css' -import { ActionButton } from 'components/ActionButton' -import Tooltip from 'components/Tooltip' -import { CustomIconName } from 'components/CustomIcon' -import { IconDefinition } from '@fortawesome/free-solid-svg-icons' -import { ActionIcon } from 'components/ActionIcon' -import { onboardingPaths } from 'routes/Onboarding/paths' -import { useSettings } from 'machines/appMachine' export interface ModelingPaneProps { id: string diff --git a/src/components/ModelingSidebar/ModelingPanes/CodeEditor.tsx b/src/components/ModelingSidebar/ModelingPanes/CodeEditor.tsx index 050d9c098..87d4d3fbe 100644 --- a/src/components/ModelingSidebar/ModelingPanes/CodeEditor.tsx +++ b/src/components/ModelingSidebar/ModelingPanes/CodeEditor.tsx @@ -1,20 +1,17 @@ -import React, { +import type { EditorStateConfig, Extension } from '@codemirror/state' +import { EditorState, StateEffect } from '@codemirror/state' +import { oneDark } from '@codemirror/theme-one-dark' +import { EditorView } from '@codemirror/view' +import { + forwardRef, useEffect, + useImperativeHandle, useMemo, useRef, useState, - forwardRef, - useImperativeHandle, } from 'react' -import { - EditorState, - EditorStateConfig, - Extension, - StateEffect, -} from '@codemirror/state' -import { EditorView } from '@codemirror/view' -import { oneDark } from '@codemirror/theme-one-dark' -import { isArray } from 'lib/utils' + +import { isArray } from '@src/lib/utils' //reference: https://github.com/sachinraja/rodemirror/blob/main/src/use-first-render.ts const useFirstRender = () => { diff --git a/src/components/ModelingSidebar/ModelingPanes/DebugPane.tsx b/src/components/ModelingSidebar/ModelingPanes/DebugPane.tsx index 99c4a0166..aa847900c 100644 --- a/src/components/ModelingSidebar/ModelingPanes/DebugPane.tsx +++ b/src/components/ModelingSidebar/ModelingPanes/DebugPane.tsx @@ -1,7 +1,7 @@ -import { DebugArtifactGraph } from 'components/DebugArtifactGraph' -import { AstExplorer } from '../../AstExplorer' -import { EngineCommands } from '../../EngineCommands' -import { CamDebugSettings } from 'clientSideScene/ClientSideSceneComp' +import { CamDebugSettings } from '@src/clientSideScene/ClientSideSceneComp' +import { AstExplorer } from '@src/components/AstExplorer' +import { DebugArtifactGraph } from '@src/components/DebugArtifactGraph' +import { EngineCommands } from '@src/components/EngineCommands' export const DebugPane = () => { return ( diff --git a/src/components/ModelingSidebar/ModelingPanes/FeatureTreeMenu.tsx b/src/components/ModelingSidebar/ModelingPanes/FeatureTreeMenu.tsx index d0cfb1f9e..964c950f3 100644 --- a/src/components/ModelingSidebar/ModelingPanes/FeatureTreeMenu.tsx +++ b/src/components/ModelingSidebar/ModelingPanes/FeatureTreeMenu.tsx @@ -1,8 +1,10 @@ import { Menu } from '@headlessui/react' -import { PropsWithChildren } from 'react' -import { ActionIcon } from 'components/ActionIcon' +import type { PropsWithChildren } from 'react' + +import { ActionIcon } from '@src/components/ActionIcon' +import { commandBarActor } from '@src/machines/commandBarMachine' + import styles from './KclEditorMenu.module.css' -import { commandBarActor } from 'machines/commandBarMachine' export const FeatureTreeMenu = ({ children }: PropsWithChildren) => { return ( diff --git a/src/components/ModelingSidebar/ModelingPanes/FeatureTreePane.tsx b/src/components/ModelingSidebar/ModelingPanes/FeatureTreePane.tsx index ed0b90747..035120e19 100644 --- a/src/components/ModelingSidebar/ModelingPanes/FeatureTreePane.tsx +++ b/src/components/ModelingSidebar/ModelingPanes/FeatureTreePane.tsx @@ -1,28 +1,35 @@ -import { Diagnostic } from '@codemirror/lint' +import type { Diagnostic } from '@codemirror/lint' import { useMachine, useSelector } from '@xstate/react' -import { ContextMenu, ContextMenuItem } from 'components/ContextMenu' -import { CustomIcon, CustomIconName } from 'components/CustomIcon' -import Loading from 'components/Loading' -import { useModelingContext } from 'hooks/useModelingContext' -import { useKclContext } from 'lang/KclProvider' -import { codeRefFromRange, getArtifactFromRange } from 'lang/std/artifactGraph' -import { sourceRangeFromRust } from 'lang/wasm' +import type { ComponentProps } from 'react' +import { useEffect, useMemo, useRef, useState } from 'react' +import type { Actor, Prop } from 'xstate' + +import type { Operation } from '@rust/kcl-lib/bindings/Operation' + +import { ContextMenu, ContextMenuItem } from '@src/components/ContextMenu' +import type { CustomIconName } from '@src/components/CustomIcon' +import { CustomIcon } from '@src/components/CustomIcon' +import Loading from '@src/components/Loading' +import { useModelingContext } from '@src/hooks/useModelingContext' +import { useKclContext } from '@src/lang/KclProvider' +import { + codeRefFromRange, + getArtifactFromRange, +} from '@src/lang/std/artifactGraph' +import { sourceRangeFromRust } from '@src/lang/wasm' import { filterOperations, getOperationIcon, getOperationLabel, stdLibMap, -} from 'lib/operations' -import { editorManager, kclManager } from 'lib/singletons' -import { ComponentProps, useEffect, useMemo, useRef, useState } from 'react' -import { Operation } from '@rust/kcl-lib/bindings/Operation' -import { Actor, Prop } from 'xstate' -import { featureTreeMachine } from 'machines/featureTreeMachine' +} from '@src/lib/operations' +import { editorManager, kclManager } from '@src/lib/singletons' +import { featureTreeMachine } from '@src/machines/featureTreeMachine' import { editorIsMountedSelector, kclEditorActor, selectionEventSelector, -} from 'machines/kclEditorMachine' +} from '@src/machines/kclEditorMachine' export const FeatureTreePane = () => { const isEditorMounted = useSelector(kclEditorActor, editorIsMountedSelector) diff --git a/src/components/ModelingSidebar/ModelingPanes/KclEditorMenu.tsx b/src/components/ModelingSidebar/ModelingPanes/KclEditorMenu.tsx index ba462d5d4..d713d7d3d 100644 --- a/src/components/ModelingSidebar/ModelingPanes/KclEditorMenu.tsx +++ b/src/components/ModelingSidebar/ModelingPanes/KclEditorMenu.tsx @@ -1,15 +1,17 @@ -import { Menu } from '@headlessui/react' -import { PropsWithChildren } from 'react' import { faArrowUpRightFromSquare } from '@fortawesome/free-solid-svg-icons' -import { ActionIcon } from 'components/ActionIcon' -import styles from './KclEditorMenu.module.css' -import { useConvertToVariable } from 'hooks/useToolbarGuards' -import { editorShortcutMeta } from './KclEditorPane' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { kclManager } from 'lib/singletons' -import { openExternalBrowserIfDesktop } from 'lib/openWindow' -import { reportRejection } from 'lib/trap' -import { commandBarActor } from 'machines/commandBarMachine' +import { Menu } from '@headlessui/react' +import type { PropsWithChildren } from 'react' + +import { ActionIcon } from '@src/components/ActionIcon' +import { editorShortcutMeta } from '@src/components/ModelingSidebar/ModelingPanes/KclEditorPane' +import { useConvertToVariable } from '@src/hooks/useToolbarGuards' +import { openExternalBrowserIfDesktop } from '@src/lib/openWindow' +import { kclManager } from '@src/lib/singletons' +import { reportRejection } from '@src/lib/trap' +import { commandBarActor } from '@src/machines/commandBarMachine' + +import styles from './KclEditorMenu.module.css' export const KclEditorMenu = ({ children }: PropsWithChildren) => { const { enable: convertToVarEnabled, handleClick: handleConvertToVarClick } = diff --git a/src/components/ModelingSidebar/ModelingPanes/KclEditorPane.tsx b/src/components/ModelingSidebar/ModelingPanes/KclEditorPane.tsx index 5094d0fc5..25084aedf 100644 --- a/src/components/ModelingSidebar/ModelingPanes/KclEditorPane.tsx +++ b/src/components/ModelingSidebar/ModelingPanes/KclEditorPane.tsx @@ -1,56 +1,58 @@ -import { TEST } from 'env' -import { Themes, getSystemTheme } from 'lib/theme' -import { useEffect, useMemo, useRef } from 'react' -import { highlightSelectionMatches, searchKeymap } from '@codemirror/search' -import { lineHighlightField } from 'editor/highlightextension' -import { onMouseDragMakeANewNumber, onMouseDragRegex } from 'lib/utils' -import { - lineNumbers, - rectangularSelection, - highlightActiveLineGutter, - highlightSpecialChars, - highlightActiveLine, - keymap, - EditorView, - dropCursor, - drawSelection, -} from '@codemirror/view' -import { - indentWithTab, - defaultKeymap, - historyKeymap, - history, -} from '@codemirror/commands' -import { diagnosticCount, lintGutter, lintKeymap } from '@codemirror/lint' -import { - foldGutter, - foldKeymap, - bracketMatching, - indentOnInput, - codeFolding, - syntaxHighlighting, - defaultHighlightStyle, -} from '@codemirror/language' -import interact from '@replit/codemirror-interact' -import { kclManager, editorManager, codeManager } from 'lib/singletons' -import { useHotkeys } from 'react-hotkeys-hook' -import { useLspContext } from 'components/LspProvider' -import { Prec, EditorState, Extension, Transaction } from '@codemirror/state' import { closeBrackets, closeBracketsKeymap, completionKeymap, } from '@codemirror/autocomplete' -import CodeEditor from './CodeEditor' -import { codeManagerHistoryCompartment } from 'lang/codeManager' +import { + defaultKeymap, + history, + historyKeymap, + indentWithTab, +} from '@codemirror/commands' +import { + bracketMatching, + codeFolding, + defaultHighlightStyle, + foldGutter, + foldKeymap, + indentOnInput, + syntaxHighlighting, +} from '@codemirror/language' +import { diagnosticCount, lintGutter, lintKeymap } from '@codemirror/lint' +import { highlightSelectionMatches, searchKeymap } from '@codemirror/search' +import type { Extension } from '@codemirror/state' +import { EditorState, Prec, Transaction } from '@codemirror/state' +import { + EditorView, + drawSelection, + dropCursor, + highlightActiveLine, + highlightActiveLineGutter, + highlightSpecialChars, + keymap, + lineNumbers, + rectangularSelection, +} from '@codemirror/view' +import interact from '@replit/codemirror-interact' +import { TEST } from '@src/env' +import { useSelector } from '@xstate/react' +import { useEffect, useMemo, useRef } from 'react' +import { useHotkeys } from 'react-hotkeys-hook' + +import { useLspContext } from '@src/components/LspProvider' +import CodeEditor from '@src/components/ModelingSidebar/ModelingPanes/CodeEditor' +import { lineHighlightField } from '@src/editor/highlightextension' +import { modelingMachineEvent } from '@src/editor/manager' +import { codeManagerHistoryCompartment } from '@src/lang/codeManager' +import { codeManager, editorManager, kclManager } from '@src/lib/singletons' +import { Themes, getSystemTheme } from '@src/lib/theme' +import { onMouseDragMakeANewNumber, onMouseDragRegex } from '@src/lib/utils' +import { useSettings } from '@src/machines/appMachine' import { editorIsMountedSelector, kclEditorActor, selectionEventSelector, -} from 'machines/kclEditorMachine' -import { useSelector } from '@xstate/react' -import { modelingMachineEvent } from 'editor/manager' -import { useSettings } from 'machines/appMachine' +} from '@src/machines/kclEditorMachine' export const editorShortcutMeta = { formatCode: { diff --git a/src/components/ModelingSidebar/ModelingPanes/LoggingPanes.tsx b/src/components/ModelingSidebar/ModelingPanes/LoggingPanes.tsx index 91b7d628b..718530145 100644 --- a/src/components/ModelingSidebar/ModelingPanes/LoggingPanes.tsx +++ b/src/components/ModelingSidebar/ModelingPanes/LoggingPanes.tsx @@ -1,6 +1,7 @@ import ReactJson from 'react-json-view' -import { useKclContext } from 'lang/KclProvider' -import { useResolvedTheme } from 'hooks/useResolvedTheme' + +import { useResolvedTheme } from '@src/hooks/useResolvedTheme' +import { useKclContext } from '@src/lang/KclProvider' const ReactJsonTypeHack = ReactJson as any diff --git a/src/components/ModelingSidebar/ModelingPanes/MemoryPane.test.tsx b/src/components/ModelingSidebar/ModelingPanes/MemoryPane.test.tsx index 1e598ad60..d19b78a0c 100644 --- a/src/components/ModelingSidebar/ModelingPanes/MemoryPane.test.tsx +++ b/src/components/ModelingSidebar/ModelingPanes/MemoryPane.test.tsx @@ -1,6 +1,6 @@ -import { processMemory } from './MemoryPane' -import { enginelessExecutor } from '../../../lib/testHelpers' -import { assertParse, initPromise } from '../../../lang/wasm' +import { processMemory } from '@src/components/ModelingSidebar/ModelingPanes/MemoryPane' +import { assertParse, initPromise } from '@src/lang/wasm' +import { enginelessExecutor } from '@src/lib/testHelpers' beforeAll(async () => { await initPromise diff --git a/src/components/ModelingSidebar/ModelingPanes/MemoryPane.tsx b/src/components/ModelingSidebar/ModelingPanes/MemoryPane.tsx index 7b11fd6b1..7e5f4d001 100644 --- a/src/components/ModelingSidebar/ModelingPanes/MemoryPane.tsx +++ b/src/components/ModelingSidebar/ModelingPanes/MemoryPane.tsx @@ -1,18 +1,18 @@ +import { useMemo } from 'react' import toast from 'react-hot-toast' import ReactJson from 'react-json-view' -import { useMemo } from 'react' -import { - Path, - ExtrudeSurface, - sketchFromKclValueOptional, - VariableMap, -} from 'lang/wasm' -import { useKclContext } from 'lang/KclProvider' -import { useResolvedTheme } from 'hooks/useResolvedTheme' -import { ActionButton } from 'components/ActionButton' -import { Reason, trap } from 'lib/trap' -import Tooltip from 'components/Tooltip' -import { useModelingContext } from 'hooks/useModelingContext' + +import type { ExtrudeSurface } from '@rust/kcl-lib/bindings/ExtrudeSurface' +import type { Path } from '@rust/kcl-lib/bindings/Path' + +import { ActionButton } from '@src/components/ActionButton' +import Tooltip from '@src/components/Tooltip' +import { useModelingContext } from '@src/hooks/useModelingContext' +import { useResolvedTheme } from '@src/hooks/useResolvedTheme' +import { useKclContext } from '@src/lang/KclProvider' +import type { VariableMap } from '@src/lang/wasm' +import { sketchFromKclValueOptional } from '@src/lang/wasm' +import { Reason, trap } from '@src/lib/trap' export const MemoryPaneMenu = () => { const { variables } = useKclContext() diff --git a/src/components/ModelingSidebar/ModelingPanes/index.tsx b/src/components/ModelingSidebar/ModelingPanes/index.tsx index 6ec850748..00ef6224e 100644 --- a/src/components/ModelingSidebar/ModelingPanes/index.tsx +++ b/src/components/ModelingSidebar/ModelingPanes/index.tsx @@ -1,25 +1,30 @@ -import { IconDefinition, faBugSlash } from '@fortawesome/free-solid-svg-icons' -import { KclEditorMenu } from 'components/ModelingSidebar/ModelingPanes/KclEditorMenu' -import { CustomIconName } from 'components/CustomIcon' -import { KclEditorPane } from 'components/ModelingSidebar/ModelingPanes/KclEditorPane' -import { ModelingPaneHeader } from 'components/ModelingSidebar/ModelingPane' -import { MouseEventHandler, ReactNode } from 'react' -import { MemoryPane, MemoryPaneMenu } from './MemoryPane' -import { LogsPane } from './LoggingPanes' -import { DebugPane } from './DebugPane' +import type { IconDefinition } from '@fortawesome/free-solid-svg-icons' +import { faBugSlash } from '@fortawesome/free-solid-svg-icons' +import type { MouseEventHandler, ReactNode } from 'react' +import type { ContextFrom } from 'xstate' + +import type { CustomIconName } from '@src/components/CustomIcon' import { FileTreeInner, FileTreeMenu, FileTreeRoot, useFileTreeOperations, -} from 'components/FileTree' -import { useKclContext } from 'lang/KclProvider' -import { editorManager } from 'lib/singletons' -import { ContextFrom } from 'xstate' -import { settingsMachine } from 'machines/settingsMachine' -import { FeatureTreePane } from './FeatureTreePane' -import { kclErrorsByFilename } from 'lang/errors' -import { FeatureTreeMenu } from './FeatureTreeMenu' +} from '@src/components/FileTree' +import { ModelingPaneHeader } from '@src/components/ModelingSidebar/ModelingPane' +import { DebugPane } from '@src/components/ModelingSidebar/ModelingPanes/DebugPane' +import { FeatureTreeMenu } from '@src/components/ModelingSidebar/ModelingPanes/FeatureTreeMenu' +import { FeatureTreePane } from '@src/components/ModelingSidebar/ModelingPanes/FeatureTreePane' +import { KclEditorMenu } from '@src/components/ModelingSidebar/ModelingPanes/KclEditorMenu' +import { KclEditorPane } from '@src/components/ModelingSidebar/ModelingPanes/KclEditorPane' +import { LogsPane } from '@src/components/ModelingSidebar/ModelingPanes/LoggingPanes' +import { + MemoryPane, + MemoryPaneMenu, +} from '@src/components/ModelingSidebar/ModelingPanes/MemoryPane' +import type { useKclContext } from '@src/lang/KclProvider' +import { kclErrorsByFilename } from '@src/lang/errors' +import { editorManager } from '@src/lib/singletons' +import type { settingsMachine } from '@src/machines/settingsMachine' export type SidebarType = | 'code' diff --git a/src/components/ModelingSidebar/ModelingSidebar.tsx b/src/components/ModelingSidebar/ModelingSidebar.tsx index 38146b8a8..43d4ab205 100644 --- a/src/components/ModelingSidebar/ModelingSidebar.tsx +++ b/src/components/ModelingSidebar/ModelingSidebar.tsx @@ -1,26 +1,26 @@ +import type { IconDefinition } from '@fortawesome/free-solid-svg-icons' import { Resizable } from 're-resizable' -import { - MouseEventHandler, - useCallback, - useEffect, - useMemo, - useContext, -} from 'react' +import type { MouseEventHandler } from 'react' +import { useCallback, useContext, useEffect, useMemo } from 'react' import { useHotkeys } from 'react-hotkeys-hook' -import { SidebarAction, SidebarType, sidebarPanes } from './ModelingPanes' -import Tooltip from 'components/Tooltip' -import { ActionIcon } from 'components/ActionIcon' -import { ModelingPane } from './ModelingPane' -import { isDesktop } from 'lib/isDesktop' -import { useModelingContext } from 'hooks/useModelingContext' -import { CustomIconName } from 'components/CustomIcon' -import { IconDefinition } from '@fortawesome/free-solid-svg-icons' -import { useKclContext } from 'lang/KclProvider' -import { MachineManagerContext } from 'components/MachineManagerProvider' -import { onboardingPaths } from 'routes/Onboarding/paths' -import { SIDEBAR_BUTTON_SUFFIX } from 'lib/constants' -import { commandBarActor } from 'machines/commandBarMachine' -import { useSettings } from 'machines/appMachine' + +import { ActionIcon } from '@src/components/ActionIcon' +import type { CustomIconName } from '@src/components/CustomIcon' +import { MachineManagerContext } from '@src/components/MachineManagerProvider' +import { ModelingPane } from '@src/components/ModelingSidebar/ModelingPane' +import type { + SidebarAction, + SidebarType, +} from '@src/components/ModelingSidebar/ModelingPanes' +import { sidebarPanes } from '@src/components/ModelingSidebar/ModelingPanes' +import Tooltip from '@src/components/Tooltip' +import { useModelingContext } from '@src/hooks/useModelingContext' +import { useKclContext } from '@src/lang/KclProvider' +import { SIDEBAR_BUTTON_SUFFIX } from '@src/lib/constants' +import { isDesktop } from '@src/lib/isDesktop' +import { useSettings } from '@src/machines/appMachine' +import { commandBarActor } from '@src/machines/commandBarMachine' +import { onboardingPaths } from '@src/routes/Onboarding/paths' interface ModelingSidebarProps { paneOpacity: '' | 'opacity-20' | 'opacity-40' @@ -113,17 +113,20 @@ export function ModelingSidebar({ paneOpacity }: ModelingSidebarProps) { ) const paneBadgeMap: Record = useMemo(() => { - return filteredPanes.reduce((acc, pane) => { - if (pane.showBadge) { - acc[pane.id] = { - value: pane.showBadge.value(paneCallbackProps), - onClick: pane.showBadge.onClick, - className: pane.showBadge.className, - title: pane.showBadge.title, + return filteredPanes.reduce( + (acc, pane) => { + if (pane.showBadge) { + acc[pane.id] = { + value: pane.showBadge.value(paneCallbackProps), + onClick: pane.showBadge.onClick, + className: pane.showBadge.className, + title: pane.showBadge.title, + } } - } - return acc - }, {} as Record) + return acc + }, + {} as Record + ) }, [paneCallbackProps]) // Clear any hidden panes from the `openPanes` array diff --git a/src/components/NetworkHealthIndicator.test.tsx b/src/components/NetworkHealthIndicator.test.tsx index 84e2ef978..db5659391 100644 --- a/src/components/NetworkHealthIndicator.test.tsx +++ b/src/components/NetworkHealthIndicator.test.tsx @@ -1,10 +1,11 @@ import { fireEvent, render, screen } from '@testing-library/react' import { BrowserRouter } from 'react-router-dom' + import { NETWORK_HEALTH_TEXT, NetworkHealthIndicator, -} from './NetworkHealthIndicator' -import { NetworkHealthState } from 'hooks/useNetworkStatus' +} from '@src/components/NetworkHealthIndicator' +import { NetworkHealthState } from '@src/hooks/useNetworkStatus' function TestWrap({ children }: { children: React.ReactNode }) { // wrap in router and xState context diff --git a/src/components/NetworkHealthIndicator.tsx b/src/components/NetworkHealthIndicator.tsx index 45381dc5f..3380154fa 100644 --- a/src/components/NetworkHealthIndicator.tsx +++ b/src/components/NetworkHealthIndicator.tsx @@ -1,11 +1,13 @@ import { Popover } from '@headlessui/react' -import { ActionIcon, ActionIconProps } from './ActionIcon' -import Tooltip from './Tooltip' -import { ConnectingTypeGroup } from '../lang/std/engineConnection' -import { useNetworkContext } from '../hooks/useNetworkContext' -import { NetworkHealthState } from '../hooks/useNetworkStatus' -import { toSync } from 'lib/utils' -import { reportRejection } from 'lib/trap' + +import type { ActionIconProps } from '@src/components/ActionIcon' +import { ActionIcon } from '@src/components/ActionIcon' +import Tooltip from '@src/components/Tooltip' +import { useNetworkContext } from '@src/hooks/useNetworkContext' +import { NetworkHealthState } from '@src/hooks/useNetworkStatus' +import type { ConnectingTypeGroup } from '@src/lang/std/engineConnection' +import { reportRejection } from '@src/lib/trap' +import { toSync } from '@src/lib/utils' export const NETWORK_HEALTH_TEXT: Record = { [NetworkHealthState.Ok]: 'Connected', diff --git a/src/components/NetworkMachineIndicator.tsx b/src/components/NetworkMachineIndicator.tsx index 6d07fd946..2d3867216 100644 --- a/src/components/NetworkMachineIndicator.tsx +++ b/src/components/NetworkMachineIndicator.tsx @@ -1,10 +1,11 @@ import { Popover } from '@headlessui/react' import { useContext } from 'react' -import Tooltip from './Tooltip' -import { isDesktop } from 'lib/isDesktop' -import { components } from 'lib/machine-api' -import { MachineManagerContext } from 'components/MachineManagerProvider' -import { CustomIcon } from './CustomIcon' + +import { CustomIcon } from '@src/components/CustomIcon' +import { MachineManagerContext } from '@src/components/MachineManagerProvider' +import Tooltip from '@src/components/Tooltip' +import { isDesktop } from '@src/lib/isDesktop' +import type { components } from '@src/lib/machine-api' export const NetworkMachineIndicator = ({ className, diff --git a/src/components/OpenInDesktopAppHandler.test.tsx b/src/components/OpenInDesktopAppHandler.test.tsx index 9cac84fee..a68e02147 100644 --- a/src/components/OpenInDesktopAppHandler.test.tsx +++ b/src/components/OpenInDesktopAppHandler.test.tsx @@ -1,6 +1,7 @@ import { fireEvent, render, screen } from '@testing-library/react' import { BrowserRouter, Route, Routes } from 'react-router-dom' -import { OpenInDesktopAppHandler } from './OpenInDesktopAppHandler' + +import { OpenInDesktopAppHandler } from '@src/components/OpenInDesktopAppHandler' /** * The behavior under test requires a router, diff --git a/src/components/OpenInDesktopAppHandler.tsx b/src/components/OpenInDesktopAppHandler.tsx index 3c34dad1e..fbd81c399 100644 --- a/src/components/OpenInDesktopAppHandler.tsx +++ b/src/components/OpenInDesktopAppHandler.tsx @@ -1,11 +1,14 @@ -import { getSystemTheme, Themes } from 'lib/theme' -import { ZOO_STUDIO_PROTOCOL } from 'lib/constants' -import { isDesktop } from 'lib/isDesktop' -import { useSearchParams } from 'react-router-dom' -import { ASK_TO_OPEN_QUERY_PARAM } from 'lib/constants' -import { VITE_KC_SITE_BASE_URL } from 'env' -import { ActionButton } from './ActionButton' import { Transition } from '@headlessui/react' +import { VITE_KC_SITE_BASE_URL } from '@src/env' +import { useSearchParams } from 'react-router-dom' + +import { ActionButton } from '@src/components/ActionButton' +import { + ASK_TO_OPEN_QUERY_PARAM, + ZOO_STUDIO_PROTOCOL, +} from '@src/lib/constants' +import { isDesktop } from '@src/lib/isDesktop' +import { Themes, getSystemTheme } from '@src/lib/theme' /** * This component is a handler that checks if a certain query parameter diff --git a/src/components/ProjectCard/DeleteProjectDialog.tsx b/src/components/ProjectCard/DeleteProjectDialog.tsx index 0fd43e848..74d9ed102 100644 --- a/src/components/ProjectCard/DeleteProjectDialog.tsx +++ b/src/components/ProjectCard/DeleteProjectDialog.tsx @@ -1,5 +1,6 @@ import { Dialog } from '@headlessui/react' -import { ActionButton } from 'components/ActionButton' + +import { ActionButton } from '@src/components/ActionButton' type DeleteConfirmationDialogProps = React.PropsWithChildren<{ title: string diff --git a/src/components/ProjectCard/ProjectCard.tsx b/src/components/ProjectCard/ProjectCard.tsx index da6a20313..5a7908d01 100644 --- a/src/components/ProjectCard/ProjectCard.tsx +++ b/src/components/ProjectCard/ProjectCard.tsx @@ -1,15 +1,17 @@ -import { FormEvent, useEffect, useRef, useState } from 'react' -import { PATHS } from 'lib/paths' -import { Link } from 'react-router-dom' -import { ActionButton } from '../ActionButton' -import { FILE_EXT, PROJECT_IMAGE_NAME } from 'lib/constants' +import type { FormEvent } from 'react' +import { useEffect, useRef, useState } from 'react' import { useHotkeys } from 'react-hotkeys-hook' -import Tooltip from '../Tooltip' -import { DeleteConfirmationDialog } from './DeleteProjectDialog' -import { ProjectCardRenameForm } from './ProjectCardRenameForm' -import { Project } from 'lib/project' -import { toSync } from 'lib/utils' -import { reportRejection } from 'lib/trap' +import { Link } from 'react-router-dom' + +import { ActionButton } from '@src/components/ActionButton' +import { DeleteConfirmationDialog } from '@src/components/ProjectCard/DeleteProjectDialog' +import { ProjectCardRenameForm } from '@src/components/ProjectCard/ProjectCardRenameForm' +import Tooltip from '@src/components/Tooltip' +import { FILE_EXT, PROJECT_IMAGE_NAME } from '@src/lib/constants' +import { PATHS } from '@src/lib/paths' +import type { Project } from '@src/lib/project' +import { reportRejection } from '@src/lib/trap' +import { toSync } from '@src/lib/utils' function ProjectCard({ project, diff --git a/src/components/ProjectCard/ProjectCardRenameForm.tsx b/src/components/ProjectCard/ProjectCardRenameForm.tsx index 91addd69c..af578f3f6 100644 --- a/src/components/ProjectCard/ProjectCardRenameForm.tsx +++ b/src/components/ProjectCard/ProjectCardRenameForm.tsx @@ -1,7 +1,9 @@ -import { ActionButton } from 'components/ActionButton' -import Tooltip from 'components/Tooltip' -import { HTMLProps, forwardRef } from 'react' -import { Project } from 'lib/project' +import type { HTMLProps } from 'react' +import { forwardRef } from 'react' + +import { ActionButton } from '@src/components/ActionButton' +import Tooltip from '@src/components/Tooltip' +import type { Project } from '@src/lib/project' interface ProjectCardRenameFormProps extends HTMLProps { project: Project diff --git a/src/components/ProjectSearchBar.tsx b/src/components/ProjectSearchBar.tsx index 2eabd3035..4637700fd 100644 --- a/src/components/ProjectSearchBar.tsx +++ b/src/components/ProjectSearchBar.tsx @@ -1,8 +1,9 @@ -import { Project } from 'lib/project' -import { CustomIcon } from './CustomIcon' +import Fuse from 'fuse.js' import { useEffect, useRef, useState } from 'react' import { useHotkeys } from 'react-hotkeys-hook' -import Fuse from 'fuse.js' + +import { CustomIcon } from '@src/components/CustomIcon' +import type { Project } from '@src/lib/project' export function useProjectSearch(projects: Project[]) { const [query, setQuery] = useState('') diff --git a/src/components/ProjectSidebarMenu.test.tsx b/src/components/ProjectSidebarMenu.test.tsx index 60c43184c..7ebd3450e 100644 --- a/src/components/ProjectSidebarMenu.test.tsx +++ b/src/components/ProjectSidebarMenu.test.tsx @@ -1,7 +1,8 @@ import { render, screen } from '@testing-library/react' import { BrowserRouter } from 'react-router-dom' -import ProjectSidebarMenu from './ProjectSidebarMenu' -import { Project } from 'lib/project' + +import ProjectSidebarMenu from '@src/components/ProjectSidebarMenu' +import type { Project } from '@src/lib/project' const now = new Date() const projectWellFormed = { diff --git a/src/components/ProjectSidebarMenu.tsx b/src/components/ProjectSidebarMenu.tsx index 5e125a829..d8726c5a7 100644 --- a/src/components/ProjectSidebarMenu.tsx +++ b/src/components/ProjectSidebarMenu.tsx @@ -1,24 +1,30 @@ import { Popover, Transition } from '@headlessui/react' -import { ActionButton, ActionButtonProps } from './ActionButton' -import { type IndexLoaderData } from 'lib/types' -import { PATHS } from 'lib/paths' -import { isDesktop } from '../lib/isDesktop' -import { Link, useLocation, useNavigate } from 'react-router-dom' -import { Fragment, useMemo, useContext } from 'react' -import { Logo } from './Logo' -import { APP_NAME } from 'lib/constants' -import { CustomIcon } from './CustomIcon' -import { useLspContext } from './LspProvider' -import { codeManager, engineCommandManager, kclManager } from 'lib/singletons' -import { MachineManagerContext } from 'components/MachineManagerProvider' -import usePlatform from 'hooks/usePlatform' -import { useAbsoluteFilePath } from 'hooks/useAbsoluteFilePath' -import Tooltip from './Tooltip' -import { SnapshotFrom } from 'xstate' -import { commandBarActor } from 'machines/commandBarMachine' import { useSelector } from '@xstate/react' -import { copyFileShareLink } from 'lib/links' -import { useToken } from 'machines/appMachine' +import { Fragment, useContext, useMemo } from 'react' +import { Link, useLocation, useNavigate } from 'react-router-dom' +import type { SnapshotFrom } from 'xstate' + +import type { ActionButtonProps } from '@src/components/ActionButton' +import { ActionButton } from '@src/components/ActionButton' +import { CustomIcon } from '@src/components/CustomIcon' +import { Logo } from '@src/components/Logo' +import { useLspContext } from '@src/components/LspProvider' +import { MachineManagerContext } from '@src/components/MachineManagerProvider' +import Tooltip from '@src/components/Tooltip' +import { useAbsoluteFilePath } from '@src/hooks/useAbsoluteFilePath' +import usePlatform from '@src/hooks/usePlatform' +import { APP_NAME } from '@src/lib/constants' +import { isDesktop } from '@src/lib/isDesktop' +import { copyFileShareLink } from '@src/lib/links' +import { PATHS } from '@src/lib/paths' +import { + codeManager, + engineCommandManager, + kclManager, +} from '@src/lib/singletons' +import { type IndexLoaderData } from '@src/lib/types' +import { useToken } from '@src/machines/appMachine' +import { commandBarActor } from '@src/machines/commandBarMachine' const ProjectSidebarMenu = ({ project, diff --git a/src/components/ProjectsContextProvider.tsx b/src/components/ProjectsContextProvider.tsx index 0c6559f98..74ef8fc35 100644 --- a/src/components/ProjectsContextProvider.tsx +++ b/src/components/ProjectsContextProvider.tsx @@ -1,39 +1,41 @@ import { useMachine } from '@xstate/react' -import { useFileSystemWatcher } from 'hooks/useFileSystemWatcher' -import { useProjectsLoader } from 'hooks/useProjectsLoader' -import { projectsMachine } from 'machines/projectsMachine' import { createContext, useCallback, useEffect, useState } from 'react' -import { Actor, AnyStateMachine, fromPromise, Prop, StateFrom } from 'xstate' -import { useLspContext } from './LspProvider' import toast from 'react-hot-toast' import { useLocation, useNavigate, useSearchParams } from 'react-router-dom' -import { PATHS } from 'lib/paths' -import { - createNewProjectDirectory, - listProjects, - renameProjectDirectory, -} from 'lib/desktop' -import { - getNextProjectIndex, - interpolateProjectNameWithIndex, - doesProjectNameNeedInterpolated, - getUniqueProjectName, - getNextFileName, -} from 'lib/desktopFS' -import useStateMachineCommands from 'hooks/useStateMachineCommands' -import { projectsCommandBarConfig } from 'lib/commandBarConfigs/projectsCommandConfig' -import { isDesktop } from 'lib/isDesktop' -import { commandBarActor } from 'machines/commandBarMachine' -import { useSettings } from 'machines/appMachine' +import type { Actor, AnyStateMachine, Prop, StateFrom } from 'xstate' +import { fromPromise } from 'xstate' + +import { useLspContext } from '@src/components/LspProvider' +import { useFileSystemWatcher } from '@src/hooks/useFileSystemWatcher' +import { useProjectsLoader } from '@src/hooks/useProjectsLoader' +import useStateMachineCommands from '@src/hooks/useStateMachineCommands' +import { newKclFile } from '@src/lang/project' +import { projectsCommandBarConfig } from '@src/lib/commandBarConfigs/projectsCommandConfig' import { CREATE_FILE_URL_PARAM, FILE_EXT, PROJECT_ENTRYPOINT, -} from 'lib/constants' -import { codeManager, kclManager } from 'lib/singletons' -import { Project } from 'lib/project' -import { newKclFile } from 'lang/project' -import { err } from 'lib/trap' +} from '@src/lib/constants' +import { + createNewProjectDirectory, + listProjects, + renameProjectDirectory, +} from '@src/lib/desktop' +import { + doesProjectNameNeedInterpolated, + getNextFileName, + getNextProjectIndex, + getUniqueProjectName, + interpolateProjectNameWithIndex, +} from '@src/lib/desktopFS' +import { isDesktop } from '@src/lib/isDesktop' +import { PATHS } from '@src/lib/paths' +import type { Project } from '@src/lib/project' +import { codeManager, kclManager } from '@src/lib/singletons' +import { err } from '@src/lib/trap' +import { useSettings } from '@src/machines/appMachine' +import { commandBarActor } from '@src/machines/commandBarMachine' +import { projectsMachine } from '@src/machines/projectsMachine' type MachineContext = { state?: StateFrom @@ -382,8 +384,8 @@ const ProjectsContextDesktop = ({ input.method === 'newProject' ? PROJECT_ENTRYPOINT : input.name.endsWith(FILE_EXT) - ? input.name - : input.name + FILE_EXT + ? input.name + : input.name + FILE_EXT let message = 'File created successfully' const needsInterpolated = doesProjectNameNeedInterpolated(projectName) diff --git a/src/components/RefreshButton.tsx b/src/components/RefreshButton.tsx index 65aefb741..12fe4bb8e 100644 --- a/src/components/RefreshButton.tsx +++ b/src/components/RefreshButton.tsx @@ -1,16 +1,20 @@ -import { coreDump } from 'lang/wasm' -import { CoreDumpManager } from 'lib/coredump' -import { CustomIcon } from './CustomIcon' -import { codeManager, engineCommandManager } from 'lib/singletons' import React, { useMemo } from 'react' import toast from 'react-hot-toast' -import Tooltip from './Tooltip' -import { reportRejection } from 'lib/trap' -import { toSync } from 'lib/utils' -import { useToken } from 'machines/appMachine' -import { rustContext } from 'lib/singletons' -import type { WebContentSendPayload } from '../menu/channels' -import { useMenuListener } from 'hooks/useMenu' + +import { CustomIcon } from '@src/components/CustomIcon' +import Tooltip from '@src/components/Tooltip' +import { useMenuListener } from '@src/hooks/useMenu' +import { coreDump } from '@src/lang/wasm' +import { CoreDumpManager } from '@src/lib/coredump' +import { + codeManager, + engineCommandManager, + rustContext, +} from '@src/lib/singletons' +import { reportRejection } from '@src/lib/trap' +import { toSync } from '@src/lib/utils' +import { useToken } from '@src/machines/appMachine' +import type { WebContentSendPayload } from '@src/menu/channels' export const RefreshButton = ({ children }: React.PropsWithChildren) => { const token = useToken() diff --git a/src/components/RouteProvider.tsx b/src/components/RouteProvider.tsx index 6662f8702..c118d20f5 100644 --- a/src/components/RouteProvider.tsx +++ b/src/components/RouteProvider.tsx @@ -1,22 +1,24 @@ -import { useEffect, useState, createContext, ReactNode } from 'react' +import type { ReactNode } from 'react' +import { createContext, useEffect, useState } from 'react' import { - useNavigation, useLocation, useNavigate, + useNavigation, useRouteLoaderData, } from 'react-router-dom' -import { PATHS } from 'lib/paths' -import { markOnce } from 'lib/performance' -import { useAuthNavigation } from 'hooks/useAuthNavigation' -import { useSettings } from 'machines/appMachine' -import { IndexLoaderData } from 'lib/types' -import { getAppSettingsFilePath } from 'lib/desktop' -import { isDesktop } from 'lib/isDesktop' -import { trap } from 'lib/trap' -import { useFileSystemWatcher } from 'hooks/useFileSystemWatcher' -import { loadAndValidateSettings } from 'lib/settings/settingsUtils' -import { settingsActor } from 'machines/appMachine' -import { OnboardingStatus } from '@rust/kcl-lib/bindings/OnboardingStatus' + +import type { OnboardingStatus } from '@rust/kcl-lib/bindings/OnboardingStatus' + +import { useAuthNavigation } from '@src/hooks/useAuthNavigation' +import { useFileSystemWatcher } from '@src/hooks/useFileSystemWatcher' +import { getAppSettingsFilePath } from '@src/lib/desktop' +import { isDesktop } from '@src/lib/isDesktop' +import { PATHS } from '@src/lib/paths' +import { markOnce } from '@src/lib/performance' +import { loadAndValidateSettings } from '@src/lib/settings/settingsUtils' +import { trap } from '@src/lib/trap' +import type { IndexLoaderData } from '@src/lib/types' +import { settingsActor, useSettings } from '@src/machines/appMachine' export const RouteProviderContext = createContext({}) diff --git a/src/components/SetAngleLengthModal.tsx b/src/components/SetAngleLengthModal.tsx index 982f98bfb..e45518b36 100644 --- a/src/components/SetAngleLengthModal.tsx +++ b/src/components/SetAngleLengthModal.tsx @@ -1,14 +1,15 @@ import { Dialog, Transition } from '@headlessui/react' import { Fragment, useState } from 'react' import { type InstanceProps, create } from 'react-modal-promise' -import { Expr } from '../lang/wasm' + import { AvailableVars, - addToInputHelper, CalcResult, CreateNewVariable, -} from './AvailableVarsHelpers' -import { useCalculateKclExpression } from 'lib/useCalculateKclExpression' + addToInputHelper, +} from '@src/components/AvailableVarsHelpers' +import type { Expr } from '@src/lang/wasm' +import { useCalculateKclExpression } from '@src/lib/useCalculateKclExpression' type ModalResolve = { value: string diff --git a/src/components/SetHorVertDistanceModal.tsx b/src/components/SetHorVertDistanceModal.tsx index 46c1f2ff6..dd9fd406e 100644 --- a/src/components/SetHorVertDistanceModal.tsx +++ b/src/components/SetHorVertDistanceModal.tsx @@ -1,14 +1,15 @@ import { Dialog, Transition } from '@headlessui/react' import { Fragment, useState } from 'react' import { type InstanceProps, create } from 'react-modal-promise' -import { Expr } from '../lang/wasm' + import { AvailableVars, - addToInputHelper, CalcResult, CreateNewVariable, -} from './AvailableVarsHelpers' -import { useCalculateKclExpression } from 'lib/useCalculateKclExpression' + addToInputHelper, +} from '@src/components/AvailableVarsHelpers' +import type { Expr } from '@src/lang/wasm' +import { useCalculateKclExpression } from '@src/lib/useCalculateKclExpression' type ModalResolve = { value: string diff --git a/src/components/SetVarNameModal.tsx b/src/components/SetVarNameModal.tsx index e69f1f2de..7a1a02177 100644 --- a/src/components/SetVarNameModal.tsx +++ b/src/components/SetVarNameModal.tsx @@ -1,10 +1,11 @@ import { Dialog, Transition } from '@headlessui/react' import { Fragment } from 'react' -import { CreateNewVariable } from './AvailableVarsHelpers' -import { ActionButton } from './ActionButton' import { toast } from 'react-hot-toast' import { type InstanceProps, create } from 'react-modal-promise' -import { useCalculateKclExpression } from 'lib/useCalculateKclExpression' + +import { ActionButton } from '@src/components/ActionButton' +import { CreateNewVariable } from '@src/components/AvailableVarsHelpers' +import { useCalculateKclExpression } from '@src/lib/useCalculateKclExpression' type ModalResolve = { variableName: string } type ModalReject = boolean diff --git a/src/components/Settings/AllKeybindingsFields.tsx b/src/components/Settings/AllKeybindingsFields.tsx index 356ec7746..004bc437f 100644 --- a/src/components/Settings/AllKeybindingsFields.tsx +++ b/src/components/Settings/AllKeybindingsFields.tsx @@ -1,10 +1,12 @@ +import type { ForwardedRef } from 'react' +import { forwardRef } from 'react' +import { useLocation } from 'react-router-dom' + +import type { InteractionMapItem } from '@src/lib/settings/initialKeybindings' import { - InteractionMapItem, interactionMap, sortInteractionMapByCategory, -} from 'lib/settings/initialKeybindings' -import { ForwardedRef, forwardRef } from 'react' -import { useLocation } from 'react-router-dom' +} from '@src/lib/settings/initialKeybindings' type AllKeybindingsFieldsProps = object diff --git a/src/components/Settings/AllSettingsFields.tsx b/src/components/Settings/AllSettingsFields.tsx index 6b9ae8da6..167f0440c 100644 --- a/src/components/Settings/AllSettingsFields.tsx +++ b/src/components/Settings/AllSettingsFields.tsx @@ -1,31 +1,36 @@ +import { useSelector } from '@xstate/react' import decamelize from 'decamelize' -import { Setting } from 'lib/settings/initialSettings' -import { SetEventTypes, SettingsLevel } from 'lib/settings/settingsTypes' -import { - shouldHideSetting, - shouldShowSettingInput, -} from 'lib/settings/settingsUtils' -import { Fragment } from 'react/jsx-runtime' -import { SettingsSection } from './SettingsSection' -import { useLocation, useNavigate } from 'react-router-dom' -import { isDesktop } from 'lib/isDesktop' -import { ActionButton } from 'components/ActionButton' -import { SettingsFieldInput } from './SettingsFieldInput' +import type { ForwardedRef } from 'react' +import { forwardRef, useEffect, useMemo } from 'react' import toast from 'react-hot-toast' -import { APP_VERSION, IS_NIGHTLY, getReleaseUrl } from 'routes/Settings' -import { PATHS } from 'lib/paths' +import { useLocation, useNavigate } from 'react-router-dom' +import { Fragment } from 'react/jsx-runtime' + +import { ActionButton } from '@src/components/ActionButton' +import { useLspContext } from '@src/components/LspProvider' +import { SettingsFieldInput } from '@src/components/Settings/SettingsFieldInput' +import { SettingsSection } from '@src/components/Settings/SettingsSection' +import { useDotDotSlash } from '@src/hooks/useDotDotSlash' import { createAndOpenNewTutorialProject, getSettingsFolderPaths, -} from 'lib/desktopFS' -import { useDotDotSlash } from 'hooks/useDotDotSlash' -import { ForwardedRef, forwardRef, useEffect, useMemo } from 'react' -import { useLspContext } from 'components/LspProvider' -import { toSync } from 'lib/utils' -import { reportRejection } from 'lib/trap' -import { openExternalBrowserIfDesktop } from 'lib/openWindow' -import { settingsActor, useSettings } from 'machines/appMachine' -import { useSelector } from '@xstate/react' +} from '@src/lib/desktopFS' +import { isDesktop } from '@src/lib/isDesktop' +import { openExternalBrowserIfDesktop } from '@src/lib/openWindow' +import { PATHS } from '@src/lib/paths' +import type { Setting } from '@src/lib/settings/initialSettings' +import type { + SetEventTypes, + SettingsLevel, +} from '@src/lib/settings/settingsTypes' +import { + shouldHideSetting, + shouldShowSettingInput, +} from '@src/lib/settings/settingsUtils' +import { reportRejection } from '@src/lib/trap' +import { toSync } from '@src/lib/utils' +import { settingsActor, useSettings } from '@src/machines/appMachine' +import { APP_VERSION, IS_NIGHTLY, getReleaseUrl } from '@src/routes/Settings' interface AllSettingsFieldsProps { searchParamTab: SettingsLevel diff --git a/src/components/Settings/KeybindingsSectionsList.tsx b/src/components/Settings/KeybindingsSectionsList.tsx index 11a9ecdad..16ea15b48 100644 --- a/src/components/Settings/KeybindingsSectionsList.tsx +++ b/src/components/Settings/KeybindingsSectionsList.tsx @@ -1,7 +1,7 @@ import { interactionMap, sortInteractionMapByCategory, -} from 'lib/settings/initialKeybindings' +} from '@src/lib/settings/initialKeybindings' interface KeybindingSectionsListProps { scrollRef: React.RefObject diff --git a/src/components/Settings/SettingsFieldInput.tsx b/src/components/Settings/SettingsFieldInput.tsx index 83ae6166c..a70ae59ed 100644 --- a/src/components/Settings/SettingsFieldInput.tsx +++ b/src/components/Settings/SettingsFieldInput.tsx @@ -1,14 +1,15 @@ -import { Toggle } from 'components/Toggle/Toggle' -import { Setting } from 'lib/settings/initialSettings' -import { +import { useMemo } from 'react' +import type { EventFrom } from 'xstate' + +import { Toggle } from '@src/components/Toggle/Toggle' +import type { Setting } from '@src/lib/settings/initialSettings' +import type { SetEventTypes, SettingsLevel, WildcardSetEvent, -} from 'lib/settings/settingsTypes' -import { getSettingInputType } from 'lib/settings/settingsUtils' -import { settingsActor, useSettings } from 'machines/appMachine' -import { useMemo } from 'react' -import { EventFrom } from 'xstate' +} from '@src/lib/settings/settingsTypes' +import { getSettingInputType } from '@src/lib/settings/settingsUtils' +import { settingsActor, useSettings } from '@src/machines/appMachine' interface SettingsFieldInputProps { // We don't need the fancy types here, diff --git a/src/components/Settings/SettingsSearchBar.tsx b/src/components/Settings/SettingsSearchBar.tsx index def38320e..b36429fb3 100644 --- a/src/components/Settings/SettingsSearchBar.tsx +++ b/src/components/Settings/SettingsSearchBar.tsx @@ -1,14 +1,15 @@ import { Combobox } from '@headlessui/react' -import { CustomIcon } from 'components/CustomIcon' import decamelize from 'decamelize' import Fuse from 'fuse.js' -import { interactionMap } from 'lib/settings/initialKeybindings' -import { SettingsLevel } from 'lib/settings/settingsTypes' -import { useSettings } from 'machines/appMachine' import { useEffect, useMemo, useRef, useState } from 'react' import { useHotkeys } from 'react-hotkeys-hook' import { useNavigate } from 'react-router-dom' +import { CustomIcon } from '@src/components/CustomIcon' +import { interactionMap } from '@src/lib/settings/initialKeybindings' +import type { SettingsLevel } from '@src/lib/settings/settingsTypes' +import { useSettings } from '@src/machines/appMachine' + type ExtendedSettingsLevel = SettingsLevel | 'keybindings' export type SettingsSearchItem = { diff --git a/src/components/Settings/SettingsSection.tsx b/src/components/Settings/SettingsSection.tsx index d40ea1c1c..099bd7920 100644 --- a/src/components/Settings/SettingsSection.tsx +++ b/src/components/Settings/SettingsSection.tsx @@ -1,6 +1,6 @@ -import { CustomIcon } from 'components/CustomIcon' -import Tooltip from 'components/Tooltip' -import { SettingsLevel } from 'lib/settings/settingsTypes' +import { CustomIcon } from '@src/components/CustomIcon' +import Tooltip from '@src/components/Tooltip' +import type { SettingsLevel } from '@src/lib/settings/settingsTypes' interface SettingsSectionProps extends React.HTMLProps { title: string diff --git a/src/components/Settings/SettingsSectionsList.tsx b/src/components/Settings/SettingsSectionsList.tsx index 2ce5d750c..f1fbfcfd5 100644 --- a/src/components/Settings/SettingsSectionsList.tsx +++ b/src/components/Settings/SettingsSectionsList.tsx @@ -1,8 +1,9 @@ import decamelize from 'decamelize' -import { Setting } from 'lib/settings/initialSettings' -import { SettingsLevel } from 'lib/settings/settingsTypes' -import { shouldHideSetting } from 'lib/settings/settingsUtils' -import { useSettings } from 'machines/appMachine' + +import type { Setting } from '@src/lib/settings/initialSettings' +import type { SettingsLevel } from '@src/lib/settings/settingsTypes' +import { shouldHideSetting } from '@src/lib/settings/settingsUtils' +import { useSettings } from '@src/machines/appMachine' interface SettingsSectionsListProps { searchParamTab: SettingsLevel diff --git a/src/components/Settings/SettingsTabButton.tsx b/src/components/Settings/SettingsTabButton.tsx index 43cab40f0..f873ab499 100644 --- a/src/components/Settings/SettingsTabButton.tsx +++ b/src/components/Settings/SettingsTabButton.tsx @@ -1,4 +1,5 @@ -import { CustomIcon, CustomIconName } from 'components/CustomIcon' +import type { CustomIconName } from '@src/components/CustomIcon' +import { CustomIcon } from '@src/components/CustomIcon' interface SettingsTabButtonProps { checked: boolean diff --git a/src/components/Settings/SettingsTabs.tsx b/src/components/Settings/SettingsTabs.tsx index 2b93cb40b..3f372d8ac 100644 --- a/src/components/Settings/SettingsTabs.tsx +++ b/src/components/Settings/SettingsTabs.tsx @@ -1,5 +1,6 @@ import { RadioGroup } from '@headlessui/react' -import { SettingsTabButton } from './SettingsTabButton' + +import { SettingsTabButton } from '@src/components/Settings/SettingsTabButton' interface SettingsTabButtonProps { value: string diff --git a/src/components/Spinner.tsx b/src/components/Spinner.tsx index 63a5b356f..539511f0c 100644 --- a/src/components/Spinner.tsx +++ b/src/components/Spinner.tsx @@ -1,4 +1,4 @@ -import { SVGProps } from 'react' +import type { SVGProps } from 'react' export const Spinner = (props: SVGProps) => { return ( diff --git a/src/components/Stream.tsx b/src/components/Stream.tsx index f64b45431..500c4e9b7 100644 --- a/src/components/Stream.tsx +++ b/src/components/Stream.tsx @@ -1,26 +1,32 @@ -import { MouseEventHandler, useEffect, useRef, useState } from 'react' -import Loading from './Loading' -import { useModelingContext } from 'hooks/useModelingContext' -import { useNetworkContext } from 'hooks/useNetworkContext' -import { NetworkHealthState } from 'hooks/useNetworkStatus' -import { ClientSideScene } from 'clientSideScene/ClientSideSceneComp' -import { btnName } from 'lib/cameraControls' -import { sendSelectEventToEngine } from 'lib/selections' -import { kclManager, engineCommandManager, sceneInfra } from 'lib/singletons' -import { useAppStream } from 'AppState' +import { useAppStream } from '@src/AppState' +import type { MouseEventHandler } from 'react' +import { useEffect, useRef, useState } from 'react' +import { useRouteLoaderData } from 'react-router-dom' + +import { ClientSideScene } from '@src/clientSideScene/ClientSideSceneComp' +import Loading from '@src/components/Loading' +import { ViewControlContextMenu } from '@src/components/ViewControlMenu' +import { useModelingContext } from '@src/hooks/useModelingContext' +import { useNetworkContext } from '@src/hooks/useNetworkContext' +import { NetworkHealthState } from '@src/hooks/useNetworkStatus' +import { getArtifactOfTypes } from '@src/lang/std/artifactGraph' import { + DisconnectingType, EngineCommandManagerEvents, EngineConnectionStateType, - DisconnectingType, -} from 'lang/std/engineConnection' -import { useRouteLoaderData } from 'react-router-dom' -import { PATHS } from 'lib/paths' -import { IndexLoaderData } from 'lib/types' -import { err, reportRejection } from 'lib/trap' -import { getArtifactOfTypes } from 'lang/std/artifactGraph' -import { ViewControlContextMenu } from './ViewControlMenu' -import { useCommandBarState } from 'machines/commandBarMachine' -import { useSettings } from 'machines/appMachine' +} from '@src/lang/std/engineConnection' +import { btnName } from '@src/lib/cameraControls' +import { PATHS } from '@src/lib/paths' +import { sendSelectEventToEngine } from '@src/lib/selections' +import { + engineCommandManager, + kclManager, + sceneInfra, +} from '@src/lib/singletons' +import { err, reportRejection } from '@src/lib/trap' +import type { IndexLoaderData } from '@src/lib/types' +import { useSettings } from '@src/machines/appMachine' +import { useCommandBarState } from '@src/machines/commandBarMachine' enum StreamState { Playing = 'playing', diff --git a/src/components/TelemetryExplorer.tsx b/src/components/TelemetryExplorer.tsx index 24c0d85a2..1ff2c085c 100644 --- a/src/components/TelemetryExplorer.tsx +++ b/src/components/TelemetryExplorer.tsx @@ -1,11 +1,10 @@ -import { getMarks } from 'lib/performance' - +import { getMarks } from '@src/lib/performance' import { printDeltaTotal, printInvocationCount, printMarkDownTable, printRawMarks, -} from 'lib/telemetry' +} from '@src/lib/telemetry' export function TelemetryExplorer() { const marks = getMarks() diff --git a/src/components/ToastTextToCad.tsx b/src/components/ToastTextToCad.tsx index 899e60261..56875a123 100644 --- a/src/components/ToastTextToCad.tsx +++ b/src/components/ToastTextToCad.tsx @@ -1,14 +1,10 @@ -import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader' -import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls' -import { useFileContext } from 'hooks/useFileContext' -import { isDesktop } from 'lib/isDesktop' -import { PATHS } from 'lib/paths' -import toast from 'react-hot-toast' -import { - TextToCad_type, +import type { TextToCadIteration_type, + TextToCad_type, } from '@kittycad/lib/dist/types/src/models' import { useCallback, useEffect, useRef, useState } from 'react' +import toast from 'react-hot-toast' +import type { Mesh } from 'three' import { Box3, Color, @@ -16,24 +12,29 @@ import { EdgesGeometry, LineBasicMaterial, LineSegments, - Mesh, MeshBasicMaterial, OrthographicCamera, Scene, Vector3, WebGLRenderer, } from 'three' +import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls' import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader' -import { base64Decode } from 'lang/wasm' -import { sendTelemetry } from 'lib/textToCad' -import { Themes } from 'lib/theme' -import { ActionButton } from './ActionButton' -import { commandBarActor } from 'machines/commandBarMachine' -import { EventFrom } from 'xstate' -import { fileMachine } from 'machines/fileMachine' -import { reportRejection } from 'lib/trap' -import { codeManager, kclManager } from 'lib/singletons' -import { openExternalBrowserIfDesktop } from 'lib/openWindow' +import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader' +import type { EventFrom } from 'xstate' + +import { ActionButton } from '@src/components/ActionButton' +import type { useFileContext } from '@src/hooks/useFileContext' +import { base64Decode } from '@src/lang/wasm' +import { isDesktop } from '@src/lib/isDesktop' +import { openExternalBrowserIfDesktop } from '@src/lib/openWindow' +import { PATHS } from '@src/lib/paths' +import { codeManager, kclManager } from '@src/lib/singletons' +import { sendTelemetry } from '@src/lib/textToCad' +import type { Themes } from '@src/lib/theme' +import { reportRejection } from '@src/lib/trap' +import { commandBarActor } from '@src/machines/commandBarMachine' +import type { fileMachine } from '@src/machines/fileMachine' const CANVAS_SIZE = 128 const PROMPT_TRUNCATE_LENGTH = 128 diff --git a/src/components/ToastUpdate.test.tsx b/src/components/ToastUpdate.test.tsx index 8b141e701..f372528a1 100644 --- a/src/components/ToastUpdate.test.tsx +++ b/src/components/ToastUpdate.test.tsx @@ -1,6 +1,7 @@ import { fireEvent, render, screen } from '@testing-library/react' import { vi } from 'vitest' -import { ToastUpdate } from './ToastUpdate' + +import { ToastUpdate } from '@src/components/ToastUpdate' describe('ToastUpdate tests', () => { const testData = { diff --git a/src/components/ToastUpdate.tsx b/src/components/ToastUpdate.tsx index fbedc03fd..208ade576 100644 --- a/src/components/ToastUpdate.tsx +++ b/src/components/ToastUpdate.tsx @@ -1,9 +1,11 @@ +import type { MarkedOptions } from '@ts-stack/markdown' +import { Marked, escape, unescape } from '@ts-stack/markdown' import toast from 'react-hot-toast' -import { ActionButton } from './ActionButton' -import { openExternalBrowserIfDesktop } from 'lib/openWindow' -import { escape, Marked, MarkedOptions, unescape } from '@ts-stack/markdown' -import { getReleaseUrl } from 'routes/Settings' -import { SafeRenderer } from 'lib/markdown' + +import { ActionButton } from '@src/components/ActionButton' +import { SafeRenderer } from '@src/lib/markdown' +import { openExternalBrowserIfDesktop } from '@src/lib/openWindow' +import { getReleaseUrl } from '@src/routes/Settings' export function ToastUpdate({ version, diff --git a/src/components/Toolbar/EqualAngle.tsx b/src/components/Toolbar/EqualAngle.tsx index c2ba55c46..190042688 100644 --- a/src/components/Toolbar/EqualAngle.tsx +++ b/src/components/Toolbar/EqualAngle.tsx @@ -1,17 +1,17 @@ -import { toolTips } from 'lang/langHelpers' -import { Selections } from 'lib/selections' -import { Program, Expr, VariableDeclarator } from '../../lang/wasm' -import { getNodeFromPath } from '../../lang/queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints' +import { toolTips } from '@src/lang/langHelpers' +import { getNodeFromPath } from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import { isSketchVariablesLinked } from '@src/lang/std/sketchConstraints' +import type { PathToNodeMap } from '@src/lang/std/sketchcombos' import { - transformSecondarySketchLinesTagFirst, getTransformInfos, - PathToNodeMap, -} from '../../lang/std/sketchcombos' -import { kclManager } from 'lib/singletons' -import { err } from 'lib/trap' -import { TransformInfo } from 'lang/std/stdTypes' + transformSecondarySketchLinesTagFirst, +} from '@src/lang/std/sketchcombos' +import type { TransformInfo } from '@src/lang/std/stdTypes' +import type { Expr, Program, VariableDeclarator } from '@src/lang/wasm' +import type { Selections } from '@src/lib/selections' +import { kclManager } from '@src/lib/singletons' +import { err } from '@src/lib/trap' export function equalAngleInfo({ selectionRanges, diff --git a/src/components/Toolbar/EqualLength.tsx b/src/components/Toolbar/EqualLength.tsx index 9d41df1f0..0460f7b16 100644 --- a/src/components/Toolbar/EqualLength.tsx +++ b/src/components/Toolbar/EqualLength.tsx @@ -1,17 +1,18 @@ -import { toolTips } from 'lang/langHelpers' -import { Selections } from 'lib/selections' -import { Program, Expr, VariableDeclarator } from '../../lang/wasm' -import { getNodeFromPath } from '../../lang/queryAst' -import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints' +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { toolTips } from '@src/lang/langHelpers' +import { getNodeFromPath } from '@src/lang/queryAst' +import { isSketchVariablesLinked } from '@src/lang/std/sketchConstraints' +import type { PathToNodeMap } from '@src/lang/std/sketchcombos' import { - transformSecondarySketchLinesTagFirst, getTransformInfos, - PathToNodeMap, -} from '../../lang/std/sketchcombos' -import { TransformInfo } from 'lang/std/stdTypes' -import { kclManager } from 'lib/singletons' -import { err } from 'lib/trap' -import { Node } from '@rust/kcl-lib/bindings/Node' + transformSecondarySketchLinesTagFirst, +} from '@src/lang/std/sketchcombos' +import type { TransformInfo } from '@src/lang/std/stdTypes' +import type { Expr, Program, VariableDeclarator } from '@src/lang/wasm' +import type { Selections } from '@src/lib/selections' +import { kclManager } from '@src/lib/singletons' +import { err } from '@src/lib/trap' export function setEqualLengthInfo({ selectionRanges, diff --git a/src/components/Toolbar/HorzVert.tsx b/src/components/Toolbar/HorzVert.tsx index 46593d009..8c744a7b9 100644 --- a/src/components/Toolbar/HorzVert.tsx +++ b/src/components/Toolbar/HorzVert.tsx @@ -1,16 +1,17 @@ -import { toolTips } from 'lang/langHelpers' -import { Selections } from 'lib/selections' -import { Program, Expr, VariableMap } from '../../lang/wasm' -import { getNodeFromPath } from '../../lang/queryAst' +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { toolTips } from '@src/lang/langHelpers' +import { getNodeFromPath } from '@src/lang/queryAst' +import type { PathToNodeMap } from '@src/lang/std/sketchcombos' import { - PathToNodeMap, getTransformInfos, transformAstSketchLines, -} from '../../lang/std/sketchcombos' -import { TransformInfo } from 'lang/std/stdTypes' -import { kclManager } from 'lib/singletons' -import { err } from 'lib/trap' -import { Node } from '@rust/kcl-lib/bindings/Node' +} from '@src/lang/std/sketchcombos' +import type { TransformInfo } from '@src/lang/std/stdTypes' +import type { Expr, Program, VariableMap } from '@src/lang/wasm' +import type { Selections } from '@src/lib/selections' +import { kclManager } from '@src/lib/singletons' +import { err } from '@src/lib/trap' export function horzVertInfo( selectionRanges: Selections, diff --git a/src/components/Toolbar/Intersect.tsx b/src/components/Toolbar/Intersect.tsx index 762fd38cd..de0b6f764 100644 --- a/src/components/Toolbar/Intersect.tsx +++ b/src/components/Toolbar/Intersect.tsx @@ -1,24 +1,28 @@ -import { toolTips } from 'lang/langHelpers' -import { Program, Expr, VariableDeclarator } from '../../lang/wasm' -import { Selections } from 'lib/selections' +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { removeDoubleNegatives } from '@src/components/AvailableVarsHelpers' +import { + GetInfoModal, + createInfoModal, +} from '@src/components/SetHorVertDistanceModal' +import { createVariableDeclaration } from '@src/lang/create' +import { toolTips } from '@src/lang/langHelpers' import { getNodeFromPath, isLinesParallelAndConstrained, -} from '../../lang/queryAst' -import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints' +} from '@src/lang/queryAst' +import { isSketchVariablesLinked } from '@src/lang/std/sketchConstraints' +import type { PathToNodeMap } from '@src/lang/std/sketchcombos' import { - transformSecondarySketchLinesTagFirst, getTransformInfos, - PathToNodeMap, isExprBinaryPart, -} from '../../lang/std/sketchcombos' -import { TransformInfo } from 'lang/std/stdTypes' -import { GetInfoModal, createInfoModal } from '../SetHorVertDistanceModal' -import { createVariableDeclaration } from '../../lang/modifyAst' -import { removeDoubleNegatives } from '../AvailableVarsHelpers' -import { kclManager } from 'lib/singletons' -import { err } from 'lib/trap' -import { Node } from '@rust/kcl-lib/bindings/Node' + transformSecondarySketchLinesTagFirst, +} from '@src/lang/std/sketchcombos' +import type { TransformInfo } from '@src/lang/std/stdTypes' +import type { Expr, Program, VariableDeclarator } from '@src/lang/wasm' +import type { Selections } from '@src/lib/selections' +import { kclManager } from '@src/lib/singletons' +import { err } from '@src/lib/trap' const getModalInfo = createInfoModal(GetInfoModal) diff --git a/src/components/Toolbar/RemoveConstrainingValues.tsx b/src/components/Toolbar/RemoveConstrainingValues.tsx index 94fd626c2..b2d99f004 100644 --- a/src/components/Toolbar/RemoveConstrainingValues.tsx +++ b/src/components/Toolbar/RemoveConstrainingValues.tsx @@ -1,17 +1,19 @@ -import { toolTips } from 'lang/langHelpers' -import { Selection, Selections } from 'lib/selections' -import { PathToNode, Program, Expr, topLevelRange } from '../../lang/wasm' -import { getNodeFromPath } from '../../lang/queryAst' +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { toolTips } from '@src/lang/langHelpers' +import { getNodeFromPath } from '@src/lang/queryAst' +import { codeRefFromRange } from '@src/lang/std/artifactGraph' +import type { PathToNodeMap } from '@src/lang/std/sketchcombos' import { - PathToNodeMap, getRemoveConstraintsTransforms, transformAstSketchLines, -} from '../../lang/std/sketchcombos' -import { TransformInfo } from 'lang/std/stdTypes' -import { kclManager } from 'lib/singletons' -import { err } from 'lib/trap' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { codeRefFromRange } from 'lang/std/artifactGraph' +} from '@src/lang/std/sketchcombos' +import type { TransformInfo } from '@src/lang/std/stdTypes' +import { topLevelRange } from '@src/lang/util' +import type { Expr, PathToNode, Program } from '@src/lang/wasm' +import type { Selection, Selections } from '@src/lib/selections' +import { kclManager } from '@src/lib/singletons' +import { err } from '@src/lib/trap' export function removeConstrainingValuesInfo({ selectionRanges, diff --git a/src/components/Toolbar/SetAbsDistance.tsx b/src/components/Toolbar/SetAbsDistance.tsx index 4efeb7fff..3aa97dbb3 100644 --- a/src/components/Toolbar/SetAbsDistance.tsx +++ b/src/components/Toolbar/SetAbsDistance.tsx @@ -1,23 +1,24 @@ -import { toolTips } from 'lang/langHelpers' -import { Program, Expr } from '../../lang/wasm' -import { Selections } from 'lib/selections' -import { getNodeFromPath } from '../../lang/queryAst' -import { - getTransformInfos, - transformAstSketchLines, - PathToNodeMap, - isExprBinaryPart, -} from '../../lang/std/sketchcombos' -import { TransformInfo } from 'lang/std/stdTypes' +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { removeDoubleNegatives } from '@src/components/AvailableVarsHelpers' import { SetAngleLengthModal, createSetAngleLengthModal, -} from '../SetAngleLengthModal' -import { createName, createVariableDeclaration } from '../../lang/modifyAst' -import { removeDoubleNegatives } from '../AvailableVarsHelpers' -import { kclManager } from 'lib/singletons' -import { err } from 'lib/trap' -import { Node } from '@rust/kcl-lib/bindings/Node' +} from '@src/components/SetAngleLengthModal' +import { createName, createVariableDeclaration } from '@src/lang/create' +import { toolTips } from '@src/lang/langHelpers' +import { getNodeFromPath } from '@src/lang/queryAst' +import type { PathToNodeMap } from '@src/lang/std/sketchcombos' +import { + getTransformInfos, + isExprBinaryPart, + transformAstSketchLines, +} from '@src/lang/std/sketchcombos' +import type { TransformInfo } from '@src/lang/std/stdTypes' +import type { Expr, Program } from '@src/lang/wasm' +import type { Selections } from '@src/lib/selections' +import { kclManager } from '@src/lib/singletons' +import { err } from '@src/lib/trap' const getModalInfo = createSetAngleLengthModal(SetAngleLengthModal) @@ -39,8 +40,8 @@ export function absDistanceInfo({ constraint === 'xAbs' || constraint === 'yAbs' ? constraint : constraint === 'snapToYAxis' - ? 'xAbs' - : 'yAbs' + ? 'xAbs' + : 'yAbs' const _nodes = selectionRanges.graphSelections.map(({ codeRef }) => { const tmp = getNodeFromPath(kclManager.ast, codeRef.pathToNode, [ 'CallExpression', diff --git a/src/components/Toolbar/SetAngleBetween.tsx b/src/components/Toolbar/SetAngleBetween.tsx index 7bd192889..1046cc1ba 100644 --- a/src/components/Toolbar/SetAngleBetween.tsx +++ b/src/components/Toolbar/SetAngleBetween.tsx @@ -1,20 +1,23 @@ -import { toolTips } from 'lang/langHelpers' -import { Program, Expr, VariableDeclarator } from '../../lang/wasm' -import { Selections } from 'lib/selections' -import { getNodeFromPath } from '../../lang/queryAst' -import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints' +import { removeDoubleNegatives } from '@src/components/AvailableVarsHelpers' +import { + GetInfoModal, + createInfoModal, +} from '@src/components/SetHorVertDistanceModal' +import { createVariableDeclaration } from '@src/lang/create' +import { toolTips } from '@src/lang/langHelpers' +import { getNodeFromPath } from '@src/lang/queryAst' +import { isSketchVariablesLinked } from '@src/lang/std/sketchConstraints' +import type { PathToNodeMap } from '@src/lang/std/sketchcombos' import { - transformSecondarySketchLinesTagFirst, getTransformInfos, - PathToNodeMap, isExprBinaryPart, -} from '../../lang/std/sketchcombos' -import { TransformInfo } from 'lang/std/stdTypes' -import { GetInfoModal, createInfoModal } from '../SetHorVertDistanceModal' -import { createVariableDeclaration } from '../../lang/modifyAst' -import { removeDoubleNegatives } from '../AvailableVarsHelpers' -import { kclManager } from 'lib/singletons' -import { err } from 'lib/trap' + transformSecondarySketchLinesTagFirst, +} from '@src/lang/std/sketchcombos' +import type { TransformInfo } from '@src/lang/std/stdTypes' +import type { Expr, Program, VariableDeclarator } from '@src/lang/wasm' +import type { Selections } from '@src/lib/selections' +import { kclManager } from '@src/lib/singletons' +import { err } from '@src/lib/trap' const getModalInfo = createInfoModal(GetInfoModal) diff --git a/src/components/Toolbar/SetHorzVertDistance.tsx b/src/components/Toolbar/SetHorzVertDistance.tsx index 7a85abb49..d18e023ee 100644 --- a/src/components/Toolbar/SetHorzVertDistance.tsx +++ b/src/components/Toolbar/SetHorzVertDistance.tsx @@ -1,21 +1,25 @@ -import { toolTips } from 'lang/langHelpers' -import { Program, Expr, VariableDeclarator } from '../../lang/wasm' -import { getNodeFromPath } from '../../lang/queryAst' -import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints' +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { removeDoubleNegatives } from '@src/components/AvailableVarsHelpers' +import { + GetInfoModal, + createInfoModal, +} from '@src/components/SetHorVertDistanceModal' +import { createLiteral, createVariableDeclaration } from '@src/lang/create' +import { toolTips } from '@src/lang/langHelpers' +import { getNodeFromPath } from '@src/lang/queryAst' +import { isSketchVariablesLinked } from '@src/lang/std/sketchConstraints' +import type { PathToNodeMap } from '@src/lang/std/sketchcombos' import { - transformSecondarySketchLinesTagFirst, getTransformInfos, - PathToNodeMap, isExprBinaryPart, -} from '../../lang/std/sketchcombos' -import { TransformInfo } from 'lang/std/stdTypes' -import { GetInfoModal, createInfoModal } from '../SetHorVertDistanceModal' -import { createLiteral, createVariableDeclaration } from '../../lang/modifyAst' -import { removeDoubleNegatives } from '../AvailableVarsHelpers' -import { kclManager } from 'lib/singletons' -import { Selections } from 'lib/selections' -import { cleanErrs, err } from 'lib/trap' -import { Node } from '@rust/kcl-lib/bindings/Node' + transformSecondarySketchLinesTagFirst, +} from '@src/lang/std/sketchcombos' +import type { TransformInfo } from '@src/lang/std/stdTypes' +import type { Expr, Program, VariableDeclarator } from '@src/lang/wasm' +import type { Selections } from '@src/lib/selections' +import { kclManager } from '@src/lib/singletons' +import { cleanErrs, err } from '@src/lib/trap' const getModalInfo = createInfoModal(GetInfoModal) diff --git a/src/components/Toolbar/setAngleLength.tsx b/src/components/Toolbar/setAngleLength.tsx index ac04f093c..0d0f39204 100644 --- a/src/components/Toolbar/setAngleLength.tsx +++ b/src/components/Toolbar/setAngleLength.tsx @@ -1,29 +1,29 @@ -import { toolTips } from 'lang/langHelpers' -import { Program, Expr } from '../../lang/wasm' -import { Selections } from 'lib/selections' -import { getNodeFromPath } from '../../lang/queryAst' -import { - PathToNodeMap, - getTransformInfos, - isExprBinaryPart, - transformAstSketchLines, -} from '../../lang/std/sketchcombos' -import { TransformInfo } from 'lang/std/stdTypes' +import { removeDoubleNegatives } from '@src/components/AvailableVarsHelpers' import { SetAngleLengthModal, createSetAngleLengthModal, -} from '../SetAngleLengthModal' +} from '@src/components/SetAngleLengthModal' import { createBinaryExpressionWithUnary, createLocalName, createName, createVariableDeclaration, -} from '../../lang/modifyAst' -import { removeDoubleNegatives } from '../AvailableVarsHelpers' -import { normaliseAngle } from '../../lib/utils' -import { kclManager } from 'lib/singletons' -import { err } from 'lib/trap' -import { KclCommandValue } from 'lib/commandTypes' +} from '@src/lang/create' +import { toolTips } from '@src/lang/langHelpers' +import { getNodeFromPath } from '@src/lang/queryAst' +import type { PathToNodeMap } from '@src/lang/std/sketchcombos' +import { + getTransformInfos, + isExprBinaryPart, + transformAstSketchLines, +} from '@src/lang/std/sketchcombos' +import type { TransformInfo } from '@src/lang/std/stdTypes' +import type { Expr, Program } from '@src/lang/wasm' +import type { KclCommandValue } from '@src/lib/commandTypes' +import type { Selections } from '@src/lib/selections' +import { kclManager } from '@src/lib/singletons' +import { err } from '@src/lib/trap' +import { normaliseAngle } from '@src/lib/utils' const getModalInfo = createSetAngleLengthModal(SetAngleLengthModal) diff --git a/src/components/Tooltip.module.css b/src/components/Tooltip.module.css index 033f2c7a5..896f9adc7 100644 --- a/src/components/Tooltip.module.css +++ b/src/components/Tooltip.module.css @@ -20,7 +20,9 @@ /* The parts that will be transitioned */ opacity: 0; transform: translate(var(--_x, 0), var(--_y, 0)); - transition: transform 0.15s ease-out, opacity 0.11s ease-out; + transition: + transform 0.15s ease-out, + opacity 0.11s ease-out; } .tooltip { diff --git a/src/components/UnitsMenu.tsx b/src/components/UnitsMenu.tsx index 6be30d721..28addb6f2 100644 --- a/src/components/UnitsMenu.tsx +++ b/src/components/UnitsMenu.tsx @@ -1,16 +1,19 @@ import { Popover } from '@headlessui/react' +import { useEffect, useState } from 'react' +import toast from 'react-hot-toast' + import { changeKclSettings, unitAngleToUnitAng, unitLengthToUnitLen, -} from 'lang/wasm' -import { DEFAULT_DEFAULT_ANGLE_UNIT } from 'lib/constants' -import { DEFAULT_DEFAULT_LENGTH_UNIT } from 'lib/constants' -import { baseUnitLabels, baseUnitsUnion } from 'lib/settings/settingsTypes' -import { codeManager, kclManager } from 'lib/singletons' -import { err, reportRejection } from 'lib/trap' -import { useEffect, useState } from 'react' -import toast from 'react-hot-toast' +} from '@src/lang/wasm' +import { + DEFAULT_DEFAULT_ANGLE_UNIT, + DEFAULT_DEFAULT_LENGTH_UNIT, +} from '@src/lib/constants' +import { baseUnitLabels, baseUnitsUnion } from '@src/lib/settings/settingsTypes' +import { codeManager, kclManager } from '@src/lib/singletons' +import { err, reportRejection } from '@src/lib/trap' export function UnitsMenu() { const [fileSettings, setFileSettings] = useState(kclManager.fileSettings) diff --git a/src/components/UpdaterRestartModal.test.tsx b/src/components/UpdaterRestartModal.test.tsx index c177bbab8..a97b9cc7d 100644 --- a/src/components/UpdaterRestartModal.test.tsx +++ b/src/components/UpdaterRestartModal.test.tsx @@ -1,6 +1,7 @@ import { fireEvent, render, screen } from '@testing-library/react' import { vi } from 'vitest' -import { UpdaterRestartModal } from './UpdaterRestartModal' + +import { UpdaterRestartModal } from '@src/components/UpdaterRestartModal' describe('UpdaterRestartModal tests', () => { test('Renders the modal', () => { diff --git a/src/components/UpdaterRestartModal.tsx b/src/components/UpdaterRestartModal.tsx index 0be9f82f8..7901c080b 100644 --- a/src/components/UpdaterRestartModal.tsx +++ b/src/components/UpdaterRestartModal.tsx @@ -1,5 +1,7 @@ -import { create, InstanceProps } from 'react-modal-promise' -import { ActionButton } from './ActionButton' +import type { InstanceProps } from 'react-modal-promise' +import { create } from 'react-modal-promise' + +import { ActionButton } from '@src/components/ActionButton' type ModalResolve = { wantRestart: boolean diff --git a/src/components/UserSidebarMenu.test.tsx b/src/components/UserSidebarMenu.test.tsx index afa3ebd94..e0870d14d 100644 --- a/src/components/UserSidebarMenu.test.tsx +++ b/src/components/UserSidebarMenu.test.tsx @@ -1,12 +1,13 @@ +import type { Models } from '@kittycad/lib' import { fireEvent, render, screen, waitFor } from '@testing-library/react' -import UserSidebarMenu from './UserSidebarMenu' import { Route, RouterProvider, createMemoryRouter, createRoutesFromElements, } from 'react-router-dom' -import { Models } from '@kittycad/lib' + +import UserSidebarMenu from '@src/components/UserSidebarMenu' type User = Models['User_type'] diff --git a/src/components/UserSidebarMenu.tsx b/src/components/UserSidebarMenu.tsx index 8f76a9f4f..685bf21f7 100644 --- a/src/components/UserSidebarMenu.tsx +++ b/src/components/UserSidebarMenu.tsx @@ -1,15 +1,17 @@ import { Popover, Transition } from '@headlessui/react' -import { ActionButton, ActionButtonProps } from './ActionButton' -import { useLocation, useNavigate } from 'react-router-dom' +import type { Models } from '@kittycad/lib' import { Fragment, useMemo, useState } from 'react' -import { PATHS } from 'lib/paths' -import { Models } from '@kittycad/lib' -import { useAbsoluteFilePath } from 'hooks/useAbsoluteFilePath' -import Tooltip from './Tooltip' -import usePlatform from 'hooks/usePlatform' -import { isDesktop } from 'lib/isDesktop' -import { CustomIcon } from './CustomIcon' -import { authActor } from 'machines/appMachine' +import { useLocation, useNavigate } from 'react-router-dom' + +import type { ActionButtonProps } from '@src/components/ActionButton' +import { ActionButton } from '@src/components/ActionButton' +import { CustomIcon } from '@src/components/CustomIcon' +import Tooltip from '@src/components/Tooltip' +import { useAbsoluteFilePath } from '@src/hooks/useAbsoluteFilePath' +import usePlatform from '@src/hooks/usePlatform' +import { isDesktop } from '@src/lib/isDesktop' +import { PATHS } from '@src/lib/paths' +import { authActor } from '@src/machines/appMachine' type User = Models['User_type'] diff --git a/src/components/ViewControlMenu.tsx b/src/components/ViewControlMenu.tsx index 4e9c8c5bd..123131beb 100644 --- a/src/components/ViewControlMenu.tsx +++ b/src/components/ViewControlMenu.tsx @@ -1,16 +1,18 @@ -import { reportRejection } from 'lib/trap' +import { useMemo } from 'react' + +import type { ContextMenuProps } from '@src/components/ContextMenu' import { ContextMenu, ContextMenuDivider, ContextMenuItem, ContextMenuItemRefresh, - ContextMenuProps, -} from './ContextMenu' -import { AxisNames, VIEW_NAMES_SEMANTIC } from 'lib/constants' -import { useModelingContext } from 'hooks/useModelingContext' -import { useMemo } from 'react' -import { sceneInfra } from 'lib/singletons' -import { useSettings } from 'machines/appMachine' +} from '@src/components/ContextMenu' +import { useModelingContext } from '@src/hooks/useModelingContext' +import type { AxisNames } from '@src/lib/constants' +import { VIEW_NAMES_SEMANTIC } from '@src/lib/constants' +import { sceneInfra } from '@src/lib/singletons' +import { reportRejection } from '@src/lib/trap' +import { useSettings } from '@src/machines/appMachine' export function useViewControlMenuItems() { const { state: modelingState, send: modelingSend } = useModelingContext() diff --git a/src/components/WasmErrBanner.tsx b/src/components/WasmErrBanner.tsx index 67bc3fdd3..ff36422ff 100644 --- a/src/components/WasmErrBanner.tsx +++ b/src/components/WasmErrBanner.tsx @@ -1,7 +1,8 @@ import { Dialog } from '@headlessui/react' import { useState } from 'react' -import { ActionButton } from './ActionButton' -import { useKclContext } from 'lang/KclProvider' + +import { ActionButton } from '@src/components/ActionButton' +import { useKclContext } from '@src/lang/KclProvider' export function WasmErrBanner() { const [isBannerDismissed, setBannerDismissed] = useState(false) diff --git a/src/editor/highlightextension.ts b/src/editor/highlightextension.ts index 90df5deb5..c6b6220e9 100644 --- a/src/editor/highlightextension.ts +++ b/src/editor/highlightextension.ts @@ -1,5 +1,5 @@ -import { StateField, StateEffect, Annotation } from '@codemirror/state' -import { EditorView, Decoration } from '@codemirror/view' +import { Annotation, StateEffect, StateField } from '@codemirror/state' +import { Decoration, EditorView } from '@codemirror/view' export { EditorView } diff --git a/src/editor/manager.test.ts b/src/editor/manager.test.ts index d214ba5ec..471481ed0 100644 --- a/src/editor/manager.test.ts +++ b/src/editor/manager.test.ts @@ -1,5 +1,6 @@ -import { editorManager } from 'lib/singletons' -import { Diagnostic } from '@codemirror/lint' +import type { Diagnostic } from '@codemirror/lint' + +import { editorManager } from '@src/lib/singletons' describe('EditorManager Class', () => { describe('makeUniqueDiagnostics', () => { diff --git a/src/editor/manager.ts b/src/editor/manager.ts index 8b97d97cf..b6492bf53 100644 --- a/src/editor/manager.ts +++ b/src/editor/manager.ts @@ -1,19 +1,25 @@ -import { EditorView, ViewUpdate } from '@codemirror/view' +import { redo, undo } from '@codemirror/commands' import { syntaxTree } from '@codemirror/language' -import { EditorSelection, Annotation, Transaction } from '@codemirror/state' -import { engineCommandManager, kclManager } from 'lib/singletons' -import { modelingMachine, ModelingMachineEvent } from 'machines/modelingMachine' -import { Selections, Selection, processCodeMirrorRanges } from 'lib/selections' -import { undo, redo } from '@codemirror/commands' -import { addLineHighlight, addLineHighlightEvent } from './highlightextension' +import type { Diagnostic } from '@codemirror/lint' +import { forEachDiagnostic, setDiagnosticsEffect } from '@codemirror/lint' +import { Annotation, EditorSelection, Transaction } from '@codemirror/state' +import type { ViewUpdate } from '@codemirror/view' +import { EditorView } from '@codemirror/view' +import type { StateFrom } from 'xstate' + import { - Diagnostic, - forEachDiagnostic, - setDiagnosticsEffect, -} from '@codemirror/lint' -import { StateFrom } from 'xstate' -import { markOnce } from 'lib/performance' -import { kclEditorActor } from 'machines/kclEditorMachine' + addLineHighlight, + addLineHighlightEvent, +} from '@src/editor/highlightextension' +import { markOnce } from '@src/lib/performance' +import type { Selection, Selections } from '@src/lib/selections' +import { processCodeMirrorRanges } from '@src/lib/selections' +import { engineCommandManager, kclManager } from '@src/lib/singletons' +import { kclEditorActor } from '@src/machines/kclEditorMachine' +import type { + ModelingMachineEvent, + modelingMachine, +} from '@src/machines/modelingMachine' declare global { interface Window { diff --git a/src/editor/plugins/lsp/copilot/index.ts b/src/editor/plugins/lsp/copilot/index.ts index 85982daaa..729531e06 100644 --- a/src/editor/plugins/lsp/copilot/index.ts +++ b/src/editor/plugins/lsp/copilot/index.ts @@ -1,42 +1,42 @@ /// Thanks to the Cursor folks for their heavy lifting here. /// This has been heavily modified from their original implementation but we are /// still grateful. +import { completionStatus } from '@codemirror/autocomplete' import { indentUnit } from '@codemirror/language' -import { - Decoration, - DecorationSet, - EditorView, - KeyBinding, - PluginValue, - ViewPlugin, - ViewUpdate, - keymap, -} from '@codemirror/view' +import type { Extension } from '@codemirror/state' import { Annotation, EditorState, - Extension, Prec, StateEffect, StateField, Transaction, } from '@codemirror/state' -import { completionStatus } from '@codemirror/autocomplete' -import { - offsetToPos, - posToOffset, - LanguageServerOptions, +import type { + DecorationSet, + KeyBinding, + PluginValue, + ViewUpdate, +} from '@codemirror/view' +import { Decoration, EditorView, ViewPlugin, keymap } from '@codemirror/view' +import type { LanguageServerClient, + LanguageServerOptions, +} from '@kittycad/codemirror-lsp-client' +import { docPathFacet, languageId, + offsetToPos, + posToOffset, } from '@kittycad/codemirror-lsp-client' -import { deferExecution } from 'lib/utils' -import { CopilotLspCompletionParams } from '@rust/kcl-lib/bindings/CopilotLspCompletionParams' -import { CopilotCompletionResponse } from '@rust/kcl-lib/bindings/CopilotCompletionResponse' -import { CopilotAcceptCompletionParams } from '@rust/kcl-lib/bindings/CopilotAcceptCompletionParams' -import { CopilotRejectCompletionParams } from '@rust/kcl-lib/bindings/CopilotRejectCompletionParams' -import { editorManager } from 'lib/singletons' -import { reportRejection } from 'lib/trap' +import { editorManager } from '@src/lib/singletons' +import { reportRejection } from '@src/lib/trap' +import { deferExecution } from '@src/lib/utils' + +import type { CopilotAcceptCompletionParams } from '@rust/kcl-lib/bindings/CopilotAcceptCompletionParams' +import type { CopilotCompletionResponse } from '@rust/kcl-lib/bindings/CopilotCompletionResponse' +import type { CopilotLspCompletionParams } from '@rust/kcl-lib/bindings/CopilotLspCompletionParams' +import type { CopilotRejectCompletionParams } from '@rust/kcl-lib/bindings/CopilotRejectCompletionParams' const copilotPluginAnnotation = Annotation.define() export const copilotPluginEvent = copilotPluginAnnotation.of(true) @@ -205,7 +205,10 @@ export class CompletionRequester implements PluginValue { // document. private sendScheduledInput: number | null = null - constructor(readonly view: EditorView, client: LanguageServerClient) { + constructor( + readonly view: EditorView, + client: LanguageServerClient + ) { this.client = client } diff --git a/src/editor/plugins/lsp/kcl/colors.ts b/src/editor/plugins/lsp/kcl/colors.ts index 9fc11b129..4587505db 100644 --- a/src/editor/plugins/lsp/kcl/colors.ts +++ b/src/editor/plugins/lsp/kcl/colors.ts @@ -1,15 +1,15 @@ -import { - EditorView, - WidgetType, - ViewUpdate, - ViewPlugin, - DecorationSet, - Decoration, -} from '@codemirror/view' -import { Range, Extension, Text } from '@codemirror/state' -import { NodeProp, Tree } from '@lezer/common' import { language, syntaxTree } from '@codemirror/language' -import { isArray } from 'lib/utils' +import type { Extension, Range, Text } from '@codemirror/state' +import type { DecorationSet, ViewUpdate } from '@codemirror/view' +import { + Decoration, + EditorView, + ViewPlugin, + WidgetType, +} from '@codemirror/view' +import type { Tree } from '@lezer/common' +import { NodeProp } from '@lezer/common' +import { isArray } from '@src/lib/utils' interface PickerState { from: number diff --git a/src/editor/plugins/lsp/kcl/index.ts b/src/editor/plugins/lsp/kcl/index.ts index 2c1543a2b..c12e9544d 100644 --- a/src/editor/plugins/lsp/kcl/index.ts +++ b/src/editor/plugins/lsp/kcl/index.ts @@ -1,20 +1,22 @@ -import { Extension } from '@codemirror/state' -import { ViewPlugin, PluginValue, ViewUpdate } from '@codemirror/view' -import { - LanguageServerOptions, +import type { Extension } from '@codemirror/state' +import type { PluginValue, ViewUpdate } from '@codemirror/view' +import { ViewPlugin } from '@codemirror/view' +import type { LanguageServerClient, - lspPlugin, - lspFormatCodeEvent, + LanguageServerOptions, } from '@kittycad/codemirror-lsp-client' -import { deferExecution } from 'lib/utils' -import { codeManager, editorManager, kclManager } from 'lib/singletons' -import { UpdateUnitsParams } from '@rust/kcl-lib/bindings/UpdateUnitsParams' -import { UpdateCanExecuteParams } from '@rust/kcl-lib/bindings/UpdateCanExecuteParams' -import { UpdateUnitsResponse } from '@rust/kcl-lib/bindings/UpdateUnitsResponse' -import { UpdateCanExecuteResponse } from '@rust/kcl-lib/bindings/UpdateCanExecuteResponse' -import { codeManagerUpdateEvent } from 'lang/codeManager' -import { copilotPluginEvent } from '../copilot' -import { updateOutsideEditorEvent } from 'editor/manager' +import { lspFormatCodeEvent, lspPlugin } from '@kittycad/codemirror-lsp-client' +import { updateOutsideEditorEvent } from '@src/editor/manager' +import { codeManagerUpdateEvent } from '@src/lang/codeManager' +import { codeManager, editorManager, kclManager } from '@src/lib/singletons' +import { deferExecution } from '@src/lib/utils' + +import type { UpdateCanExecuteParams } from '@rust/kcl-lib/bindings/UpdateCanExecuteParams' +import type { UpdateCanExecuteResponse } from '@rust/kcl-lib/bindings/UpdateCanExecuteResponse' +import type { UpdateUnitsParams } from '@rust/kcl-lib/bindings/UpdateUnitsParams' +import type { UpdateUnitsResponse } from '@rust/kcl-lib/bindings/UpdateUnitsResponse' + +import { copilotPluginEvent } from '@src/editor/plugins/lsp/copilot' const changesDelay = 600 diff --git a/src/editor/plugins/lsp/kcl/language.ts b/src/editor/plugins/lsp/kcl/language.ts index d1884b498..a9a7ac4ab 100644 --- a/src/editor/plugins/lsp/kcl/language.ts +++ b/src/editor/plugins/lsp/kcl/language.ts @@ -1,14 +1,14 @@ // Code mirror language implementation for kcl. - import { LanguageSupport } from '@codemirror/language' -import { +import { KclLanguage } from '@kittycad/codemirror-lang-kcl' +import type { LanguageServerClient, LanguageServerPlugin, } from '@kittycad/codemirror-lsp-client' -import { kclPlugin } from '.' import type * as LSP from 'vscode-languageserver-protocol' -import { colorPicker } from './colors' -import { KclLanguage } from '@kittycad/codemirror-lang-kcl' + +import { kclPlugin } from '@src/editor/plugins/lsp/kcl' +import { colorPicker } from '@src/editor/plugins/lsp/kcl/colors' export interface LanguageOptions { workspaceFolders: LSP.WorkspaceFolder[] diff --git a/src/editor/plugins/lsp/types.ts b/src/editor/plugins/lsp/types.ts index b512de30f..11ef70fc8 100644 --- a/src/editor/plugins/lsp/types.ts +++ b/src/editor/plugins/lsp/types.ts @@ -1,4 +1,4 @@ -import { LspWorkerEventType } from '@kittycad/codemirror-lsp-client' +import type { LspWorkerEventType } from '@kittycad/codemirror-lsp-client' export enum LspWorker { Kcl = 'kcl', diff --git a/src/editor/plugins/lsp/worker.ts b/src/editor/plugins/lsp/worker.ts index 05cdfd2cc..ec80718d0 100644 --- a/src/editor/plugins/lsp/worker.ts +++ b/src/editor/plugins/lsp/worker.ts @@ -4,20 +4,22 @@ import { IntoServer, LspWorkerEventType, } from '@kittycad/codemirror-lsp-client' -import { fileSystemManager } from 'lang/std/fileSystemManager' +import type * as jsrpc from 'json-rpc-2.0' + import init, { LspServerConfig, lsp_run_copilot, lsp_run_kcl, } from '@rust/kcl-wasm-lib/pkg/kcl_wasm_lib' -import * as jsrpc from 'json-rpc-2.0' -import { - LspWorkerEvent, - LspWorker, - KclWorkerOptions, + +import type { CopilotWorkerOptions, -} from 'editor/plugins/lsp/types' -import { err, reportRejection } from 'lib/trap' + KclWorkerOptions, + LspWorkerEvent, +} from '@src/editor/plugins/lsp/types' +import { LspWorker } from '@src/editor/plugins/lsp/types' +import { fileSystemManager } from '@src/lang/std/fileSystemManager' +import { err, reportRejection } from '@src/lib/trap' const intoServer: IntoServer = new IntoServer() const fromServer: FromServer | Error = FromServer.create() diff --git a/src/hooks/useAbsoluteFilePath.ts b/src/hooks/useAbsoluteFilePath.ts index 4e9c9dc37..06c5672d7 100644 --- a/src/hooks/useAbsoluteFilePath.ts +++ b/src/hooks/useAbsoluteFilePath.ts @@ -1,7 +1,8 @@ -import { type IndexLoaderData } from 'lib/types' -import { BROWSER_PATH, PATHS } from 'lib/paths' import { useRouteLoaderData } from 'react-router-dom' +import { BROWSER_PATH, PATHS } from '@src/lib/paths' +import { type IndexLoaderData } from '@src/lib/types' + export function useAbsoluteFilePath() { const routeData = useRouteLoaderData(PATHS.FILE) as IndexLoaderData diff --git a/src/hooks/useAuthNavigation.tsx b/src/hooks/useAuthNavigation.tsx index b58bc99c0..116f8e1d8 100644 --- a/src/hooks/useAuthNavigation.tsx +++ b/src/hooks/useAuthNavigation.tsx @@ -1,8 +1,9 @@ -import { PATHS } from 'lib/paths' -import { useAuthState } from 'machines/appMachine' import { useEffect } from 'react' import { useLocation, useNavigate } from 'react-router-dom' +import { PATHS } from '@src/lib/paths' +import { useAuthState } from '@src/machines/appMachine' + /** * A simple hook that listens to the auth state of the app and navigates * accordingly. diff --git a/src/hooks/useCreateFileLinkQueryWatcher.ts b/src/hooks/useCreateFileLinkQueryWatcher.ts index 04237aadf..d02594a6f 100644 --- a/src/hooks/useCreateFileLinkQueryWatcher.ts +++ b/src/hooks/useCreateFileLinkQueryWatcher.ts @@ -1,11 +1,12 @@ -import { base64ToString } from 'lib/base64' -import { CREATE_FILE_URL_PARAM, DEFAULT_FILE_NAME } from 'lib/constants' import { useEffect } from 'react' import { useSearchParams } from 'react-router-dom' -import { isDesktop } from 'lib/isDesktop' -import { FileLinkParams } from 'lib/links' -import { ProjectsCommandSchema } from 'lib/commandBarConfigs/projectsCommandConfig' -import { useSettings } from 'machines/appMachine' + +import { base64ToString } from '@src/lib/base64' +import type { ProjectsCommandSchema } from '@src/lib/commandBarConfigs/projectsCommandConfig' +import { CREATE_FILE_URL_PARAM, DEFAULT_FILE_NAME } from '@src/lib/constants' +import { isDesktop } from '@src/lib/isDesktop' +import type { FileLinkParams } from '@src/lib/links' +import { useSettings } from '@src/machines/appMachine' // For initializing the command arguments, we actually want `method` to be undefined // so that we don't skip it in the command palette. @@ -45,8 +46,8 @@ export function useCreateFileLinkQuery( ? params.name.replace('.kcl', '') : params.name : isDesktop() - ? settings.projects.defaultProjectName.current - : DEFAULT_FILE_NAME, + ? settings.projects.defaultProjectName.current + : DEFAULT_FILE_NAME, code: params.code || '', method: isDesktop() ? undefined : 'existingProject', } diff --git a/src/hooks/useDocumentHasFocus.ts b/src/hooks/useDocumentHasFocus.ts index fab729ab6..f97045bad 100644 --- a/src/hooks/useDocumentHasFocus.ts +++ b/src/hooks/useDocumentHasFocus.ts @@ -1,5 +1,5 @@ // Based on https://learnersbucket.com/examples/interview/usehasfocus-hook-in-react/ -import { useState, useEffect } from 'react' +import { useEffect, useState } from 'react' export const useDocumentHasFocus = () => { // get the initial state diff --git a/src/hooks/useEngineConnectionSubscriptions.ts b/src/hooks/useEngineConnectionSubscriptions.ts index ff7c94108..ee11b6491 100644 --- a/src/hooks/useEngineConnectionSubscriptions.ts +++ b/src/hooks/useEngineConnectionSubscriptions.ts @@ -1,28 +1,33 @@ import { useEffect, useRef } from 'react' + +import { useModelingContext } from '@src/hooks/useModelingContext' +import { getNodeFromPath } from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import type { SegmentArtifact } from '@src/lang/std/artifactGraph' +import { + getArtifactOfTypes, + getCapCodeRef, + getCodeRefsByArtifactId, + getSweepFromSuspectedSweepSurface, + getWallCodeRef, +} from '@src/lang/std/artifactGraph' +import type { CallExpression, CallExpressionKw } from '@src/lang/wasm' +import { defaultSourceRange } from '@src/lang/wasm' +import type { DefaultPlaneStr } from '@src/lib/planes' +import { getEventForSelectWithPoint } from '@src/lib/selections' import { editorManager, engineCommandManager, kclManager, + rustContext, + sceneEntitiesManager, sceneInfra, -} from 'lib/singletons' -import { useModelingContext } from './useModelingContext' -import { getEventForSelectWithPoint } from 'lib/selections' -import { - getCapCodeRef, - getSweepFromSuspectedSweepSurface, - getWallCodeRef, - getCodeRefsByArtifactId, - getArtifactOfTypes, - SegmentArtifact, -} from 'lang/std/artifactGraph' -import { err, reportRejection } from 'lib/trap' -import { getFaceDetails } from 'clientSideScene/sceneEntities' -import { DefaultPlaneStr } from 'lib/planes' -import { getNodeFromPath } from 'lang/queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { CallExpression, CallExpressionKw, defaultSourceRange } from 'lang/wasm' -import { EdgeCutInfo, ExtrudeFacePlane } from 'machines/modelingMachine' -import { rustContext } from 'lib/singletons' +} from '@src/lib/singletons' +import { err, reportRejection } from '@src/lib/trap' +import type { + EdgeCutInfo, + ExtrudeFacePlane, +} from '@src/machines/modelingMachine' export function useEngineConnectionSubscriptions() { const { send, context, state } = useModelingContext() @@ -143,7 +148,8 @@ export function useEngineConnectionSubscriptions() { const artifact = kclManager.artifactGraph.get(planeOrFaceId) if (artifact?.type === 'plane') { - const planeInfo = await getFaceDetails(planeOrFaceId) + const planeInfo = + await sceneEntitiesManager.getFaceDetails(planeOrFaceId) sceneInfra.modelingSend({ type: 'Select default plane', data: { @@ -165,7 +171,7 @@ export function useEngineConnectionSubscriptions() { ].map((num) => num / sceneInfra._baseUnitMultiplier) as [ number, number, - number + number, ], planeId: planeOrFaceId, pathToNode: artifact.codeRef.pathToNode, @@ -194,10 +200,10 @@ export function useEngineConnectionSubscriptions() { artifact.type === 'cap' ? getCapCodeRef(artifact, kclManager.artifactGraph) : artifact.type === 'wall' - ? getWallCodeRef(artifact, kclManager.artifactGraph) - : artifact.codeRef + ? getWallCodeRef(artifact, kclManager.artifactGraph) + : artifact.codeRef - const faceInfo = await getFaceDetails(faceId) + const faceInfo = await sceneEntitiesManager.getFaceDetails(faceId) if (!faceInfo?.origin || !faceInfo?.z_axis || !faceInfo?.y_axis) return const { z_axis, y_axis, origin } = faceInfo @@ -275,11 +281,11 @@ export function useEngineConnectionSubscriptions() { const _faceInfo: ExtrudeFacePlane['faceInfo'] = edgeCutMeta ? edgeCutMeta : artifact.type === 'cap' - ? { - type: 'cap', - subType: artifact.subType, - } - : { type: 'wall' } + ? { + type: 'cap', + subType: artifact.subType, + } + : { type: 'wall' } const extrudePathToNode = !err(extrusion) ? getNodePathFromSourceRange( diff --git a/src/hooks/useFileContext.ts b/src/hooks/useFileContext.ts index a41135d06..4e66a60fd 100644 --- a/src/hooks/useFileContext.ts +++ b/src/hooks/useFileContext.ts @@ -1,6 +1,7 @@ -import { FileContext } from 'components/FileMachineProvider' import { useContext } from 'react' +import { FileContext } from '@src/components/FileMachineProvider' + export const useFileContext = () => { return useContext(FileContext) } diff --git a/src/hooks/useFileSystemWatcher.tsx b/src/hooks/useFileSystemWatcher.tsx index 210b31e11..c6f5cc78f 100644 --- a/src/hooks/useFileSystemWatcher.tsx +++ b/src/hooks/useFileSystemWatcher.tsx @@ -1,6 +1,7 @@ -import { isDesktop } from 'lib/isDesktop' -import { reportRejection } from 'lib/trap' -import { useEffect, useState, useRef } from 'react' +import { useEffect, useRef, useState } from 'react' + +import { isDesktop } from '@src/lib/isDesktop' +import { reportRejection } from '@src/lib/trap' type Path = string diff --git a/src/hooks/useHotKeyListener.ts b/src/hooks/useHotKeyListener.ts index 10d6a3eed..999907144 100644 --- a/src/hooks/useHotKeyListener.ts +++ b/src/hooks/useHotKeyListener.ts @@ -1,6 +1,7 @@ -import { editorManager } from 'lib/singletons' import { useEffect } from 'react' +import { editorManager } from '@src/lib/singletons' + // Kurt's note: codeMirror styling overrides were needed to make this work // namely, the cursor needs to still be shown when the editor is not focused // search for code-mirror-override in the repo to find the relevant styles diff --git a/src/hooks/useMenu.ts b/src/hooks/useMenu.ts index f99e2d8b9..4842ae81e 100644 --- a/src/hooks/useMenu.ts +++ b/src/hooks/useMenu.ts @@ -1,6 +1,8 @@ import { useEffect } from 'react' -import type { WebContentSendPayload } from '../menu/channels' -import { isDesktop } from 'lib/isDesktop' + +import { isDesktop } from '@src/lib/isDesktop' +import type { WebContentSendPayload } from '@src/menu/channels' + export function useMenuListener( callback: (data: WebContentSendPayload) => void ) { diff --git a/src/hooks/useModelingContext.ts b/src/hooks/useModelingContext.ts index 3af3c5d79..9aa202789 100644 --- a/src/hooks/useModelingContext.ts +++ b/src/hooks/useModelingContext.ts @@ -1,6 +1,7 @@ -import { ModelingMachineContext } from 'components/ModelingMachineProvider' import { useContext } from 'react' +import { ModelingMachineContext } from '@src/components/ModelingMachineProvider' + export const useModelingContext = () => { return useContext(ModelingMachineContext) } diff --git a/src/hooks/useNetworkContext.tsx b/src/hooks/useNetworkContext.tsx index 16da16a11..35ce44412 100644 --- a/src/hooks/useNetworkContext.tsx +++ b/src/hooks/useNetworkContext.tsx @@ -1,11 +1,13 @@ import { createContext, useContext } from 'react' + +import type { NetworkStatus } from '@src/hooks/useNetworkStatus' +import { NetworkHealthState } from '@src/hooks/useNetworkStatus' +import type { EngineConnectionState } from '@src/lang/std/engineConnection' import { ConnectingTypeGroup, EngineConnectionStateType, - EngineConnectionState, initialConnectingTypeGroupState, -} from '../lang/std/engineConnection' -import { NetworkStatus, NetworkHealthState } from './useNetworkStatus' +} from '@src/lang/std/engineConnection' export const NetworkContext = createContext({ immediateState: { diff --git a/src/hooks/useNetworkStatus.tsx b/src/hooks/useNetworkStatus.tsx index 30c4ccf2c..d01dcdd4d 100644 --- a/src/hooks/useNetworkStatus.tsx +++ b/src/hooks/useNetworkStatus.tsx @@ -1,16 +1,19 @@ import { useEffect, useState } from 'react' -import { + +import type { ConnectingType, + EngineConnectionState, + ErrorType, +} from '@src/lang/std/engineConnection' +import { ConnectingTypeGroup, DisconnectingType, EngineCommandManagerEvents, EngineConnectionEvents, EngineConnectionStateType, - EngineConnectionState, - ErrorType, initialConnectingTypeGroupState, -} from '../lang/std/engineConnection' -import { engineCommandManager } from '../lib/singletons' +} from '@src/lang/std/engineConnection' +import { engineCommandManager } from '@src/lib/singletons' export enum NetworkHealthState { Ok, @@ -69,10 +72,10 @@ export function useNetworkStatus() { !internetConnected ? NetworkHealthState.Disconnected : hasIssues || hasIssues === undefined - ? NetworkHealthState.Issue - : pingPongHealth === 'TIMEOUT' - ? NetworkHealthState.Weak - : NetworkHealthState.Ok + ? NetworkHealthState.Issue + : pingPongHealth === 'TIMEOUT' + ? NetworkHealthState.Weak + : NetworkHealthState.Ok ) }, [hasIssues, internetConnected, pingPongHealth]) diff --git a/src/hooks/usePlatform.ts b/src/hooks/usePlatform.ts index d74944745..3d5ef847b 100644 --- a/src/hooks/usePlatform.ts +++ b/src/hooks/usePlatform.ts @@ -1,6 +1,8 @@ -import { Platform, platform } from 'lib/utils' import { useEffect, useState } from 'react' +import type { Platform } from '@src/lib/utils' +import { platform } from '@src/lib/utils' + export default function usePlatform() { const [platformName, setPlatformName] = useState('') diff --git a/src/hooks/useProjectsContext.ts b/src/hooks/useProjectsContext.ts index 2cc3551be..2e68535a7 100644 --- a/src/hooks/useProjectsContext.ts +++ b/src/hooks/useProjectsContext.ts @@ -1,6 +1,7 @@ -import { ProjectsMachineContext } from 'components/ProjectsContextProvider' import { useContext } from 'react' +import { ProjectsMachineContext } from '@src/components/ProjectsContextProvider' + export const useProjectsContext = () => { return useContext(ProjectsMachineContext) } diff --git a/src/hooks/useProjectsLoader.tsx b/src/hooks/useProjectsLoader.tsx index 8df3bab8a..d7d158a31 100644 --- a/src/hooks/useProjectsLoader.tsx +++ b/src/hooks/useProjectsLoader.tsx @@ -1,9 +1,10 @@ -import { trap } from 'lib/trap' -import { useState, useEffect } from 'react' -import { ensureProjectDirectoryExists, listProjects } from 'lib/desktop' -import { loadAndValidateSettings } from 'lib/settings/settingsUtils' -import { Project } from 'lib/project' -import { isDesktop } from 'lib/isDesktop' +import { useEffect, useState } from 'react' + +import { ensureProjectDirectoryExists, listProjects } from '@src/lib/desktop' +import { isDesktop } from '@src/lib/isDesktop' +import type { Project } from '@src/lib/project' +import { loadAndValidateSettings } from '@src/lib/settings/settingsUtils' +import { trap } from '@src/lib/trap' // Gotcha: This should be ported to the ProjectMachine and keep track of // projectDirs and projectPaths in the context when it internally calls listProjects diff --git a/src/hooks/useResolvedTheme.ts b/src/hooks/useResolvedTheme.ts index 325dcf0f4..4f13c94cc 100644 --- a/src/hooks/useResolvedTheme.ts +++ b/src/hooks/useResolvedTheme.ts @@ -1,5 +1,5 @@ -import { Themes, getSystemTheme } from 'lib/theme' -import { useSettings } from 'machines/appMachine' +import { Themes, getSystemTheme } from '@src/lib/theme' +import { useSettings } from '@src/machines/appMachine' /** * Resolves the current theme based on the theme setting diff --git a/src/hooks/useSetupEngineManager.ts b/src/hooks/useSetupEngineManager.ts index 5092bc8bf..689a3c624 100644 --- a/src/hooks/useSetupEngineManager.ts +++ b/src/hooks/useSetupEngineManager.ts @@ -1,15 +1,16 @@ -import { useLayoutEffect, useEffect, useRef } from 'react' -import { engineCommandManager } from 'lib/singletons' -import { deferExecution } from 'lib/utils' -import { Themes } from 'lib/theme' -import { useModelingContext } from './useModelingContext' -import { useNetworkContext } from 'hooks/useNetworkContext' -import { useAppState, useAppStream } from 'AppState' -import { SettingsViaQueryString } from 'lib/settings/settingsTypes' +import { useAppState, useAppStream } from '@src/AppState' +import { useEffect, useLayoutEffect, useRef } from 'react' + +import type { useModelingContext } from '@src/hooks/useModelingContext' +import { useNetworkContext } from '@src/hooks/useNetworkContext' import { - EngineConnectionStateType, DisconnectingType, -} from 'lang/std/engineConnection' + EngineConnectionStateType, +} from '@src/lang/std/engineConnection' +import type { SettingsViaQueryString } from '@src/lib/settings/settingsTypes' +import { engineCommandManager } from '@src/lib/singletons' +import { Themes } from '@src/lib/theme' +import { deferExecution } from '@src/lib/utils' export function useSetupEngineManager( streamRef: React.RefObject, diff --git a/src/hooks/useStateMachineCommands.ts b/src/hooks/useStateMachineCommands.ts index 923d8ae79..47c110092 100644 --- a/src/hooks/useStateMachineCommands.ts +++ b/src/hooks/useStateMachineCommands.ts @@ -1,20 +1,21 @@ +import { useAppState } from '@src/AppState' import { useEffect } from 'react' -import { AnyStateMachine, Actor, StateFrom, EventFrom } from 'xstate' -import { createMachineCommand } from '../lib/createMachineCommand' -import { modelingMachine } from 'machines/modelingMachine' -import { authMachine } from 'machines/authMachine' -import { settingsMachine } from 'machines/settingsMachine' -import { projectsMachine } from 'machines/projectsMachine' -import { +import type { Actor, AnyStateMachine, EventFrom, StateFrom } from 'xstate' + +import { useNetworkContext } from '@src/hooks/useNetworkContext' +import { NetworkHealthState } from '@src/hooks/useNetworkStatus' +import { useKclContext } from '@src/lang/KclProvider' +import type { Command, StateMachineCommandSetConfig, StateMachineCommandSetSchema, -} from 'lib/commandTypes' -import { useKclContext } from 'lang/KclProvider' -import { useNetworkContext } from 'hooks/useNetworkContext' -import { NetworkHealthState } from 'hooks/useNetworkStatus' -import { useAppState } from 'AppState' -import { commandBarActor } from 'machines/commandBarMachine' +} from '@src/lib/commandTypes' +import { createMachineCommand } from '@src/lib/createMachineCommand' +import type { authMachine } from '@src/machines/authMachine' +import { commandBarActor } from '@src/machines/commandBarMachine' +import type { modelingMachine } from '@src/machines/modelingMachine' +import type { projectsMachine } from '@src/machines/projectsMachine' +import type { settingsMachine } from '@src/machines/settingsMachine' // This might not be necessary, AnyStateMachine from xstate is working export type AllMachines = @@ -25,7 +26,7 @@ export type AllMachines = interface UseStateMachineCommandsArgs< T extends AllMachines, - S extends StateMachineCommandSetSchema + S extends StateMachineCommandSetSchema, > { machineId: T['id'] state: StateFrom @@ -38,7 +39,7 @@ interface UseStateMachineCommandsArgs< export default function useStateMachineCommands< T extends AnyStateMachine, - S extends StateMachineCommandSetSchema + S extends StateMachineCommandSetSchema, >({ machineId, state, diff --git a/src/hooks/useToolbarGuards.ts b/src/hooks/useToolbarGuards.ts index 0319a0ef1..36b73244d 100644 --- a/src/hooks/useToolbarGuards.ts +++ b/src/hooks/useToolbarGuards.ts @@ -1,16 +1,18 @@ +import { useEffect, useState } from 'react' + import { SetVarNameModal, createSetVarNameModal, -} from 'components/SetVarNameModal' -import { editorManager, kclManager, codeManager } from 'lib/singletons' -import { reportRejection, trap, err } from 'lib/trap' -import { moveValueIntoNewVariable } from 'lang/modifyAst' -import { isNodeSafeToReplace } from 'lang/queryAst' -import { useEffect, useState } from 'react' -import { useModelingContext } from './useModelingContext' -import { PathToNode, SourceRange, recast } from 'lang/wasm' -import { useKclContext } from 'lang/KclProvider' -import { toSync } from 'lib/utils' +} from '@src/components/SetVarNameModal' +import { useModelingContext } from '@src/hooks/useModelingContext' +import { useKclContext } from '@src/lang/KclProvider' +import { moveValueIntoNewVariable } from '@src/lang/modifyAst' +import { isNodeSafeToReplace } from '@src/lang/queryAst' +import type { PathToNode, SourceRange } from '@src/lang/wasm' +import { recast } from '@src/lang/wasm' +import { codeManager, editorManager, kclManager } from '@src/lib/singletons' +import { err, reportRejection, trap } from '@src/lib/trap' +import { toSync } from '@src/lib/utils' export const getVarNameModal = createSetVarNameModal(SetVarNameModal) diff --git a/src/index.css b/src/index.css index 90e9e9a84..fb216014c 100644 --- a/src/index.css +++ b/src/index.css @@ -131,13 +131,13 @@ input { } .mono { - font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', - monospace; + font-family: + source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; } code { - font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', - monospace; + font-family: + source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; } /* diff --git a/src/index.tsx b/src/index.tsx index b7abe9b9f..45f9b4d11 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,19 +1,20 @@ +import { AppStreamProvider } from '@src/AppState' import ReactDOM from 'react-dom/client' -import './index.css' -import reportWebVitals from './reportWebVitals' import toast, { Toaster } from 'react-hot-toast' -import { Router } from './Router' import { HotkeysProvider } from 'react-hotkeys-hook' import ModalContainer from 'react-modal-promise' -import { isDesktop } from 'lib/isDesktop' -import { AppStreamProvider } from 'AppState' -import { ToastUpdate } from 'components/ToastUpdate' -import { markOnce } from 'lib/performance' -import { AUTO_UPDATER_TOAST_ID } from 'lib/constants' -import { initializeWindowExceptionHandler } from 'lib/exceptions' -import { initPromise } from 'lang/wasm' -import { appActor } from 'machines/appMachine' -import { reportRejection } from 'lib/trap' + +import { Router } from '@src/Router' +import { ToastUpdate } from '@src/components/ToastUpdate' +import '@src/index.css' +import { initPromise } from '@src/lang/wasm' +import { AUTO_UPDATER_TOAST_ID } from '@src/lib/constants' +import { initializeWindowExceptionHandler } from '@src/lib/exceptions' +import { isDesktop } from '@src/lib/isDesktop' +import { markOnce } from '@src/lib/performance' +import { reportRejection } from '@src/lib/trap' +import { appActor } from '@src/machines/appMachine' +import reportWebVitals from '@src/reportWebVitals' markOnce('code/willAuth') initializeWindowExceptionHandler() diff --git a/src/lang/KclProvider.tsx b/src/lang/KclProvider.tsx index 61dc05f39..5d174a4b7 100644 --- a/src/lang/KclProvider.tsx +++ b/src/lang/KclProvider.tsx @@ -1,10 +1,12 @@ +import type { Diagnostic } from '@codemirror/lint' import { createContext, useContext, useEffect, useState } from 'react' -import { type IndexLoaderData } from 'lib/types' import { useRouteLoaderData } from 'react-router-dom' -import { codeManager, kclManager } from 'lib/singletons' -import { Diagnostic } from '@codemirror/lint' -import { KCLError } from './errors' -import { PATHS } from 'lib/paths' + +import { PATHS } from '@src/lib/paths' +import { codeManager, kclManager } from '@src/lib/singletons' +import { type IndexLoaderData } from '@src/lib/types' + +import type { KCLError } from '@src/lang/errors' const KclContext = createContext({ code: codeManager?.code || '', diff --git a/src/lang/KclSingleton.ts b/src/lang/KclSingleton.ts index 10d518866..7ef452477 100644 --- a/src/lang/KclSingleton.ts +++ b/src/lang/KclSingleton.ts @@ -1,49 +1,53 @@ -import { executeAst, executeAstMock, lintAst } from 'lang/langHelpers' -import { handleSelectionBatch, Selections } from 'lib/selections' -import { - KCLError, - compilationErrorsToDiagnostics, - kclErrorsToDiagnostics, -} from './errors' -import { uuidv4, isOverlap, deferExecution } from 'lib/utils' -import { EngineCommandManager } from './std/engineConnection' -import { err, reportRejection } from 'lib/trap' -import { EXECUTE_AST_INTERRUPT_ERROR_MESSAGE } from 'lib/constants' -import { buildArtifactIndex } from 'lib/artifactIndex' -import { ArtifactIndex } from 'lib/artifactIndex' - -import { - emptyExecState, - ExecState, - getKclVersion, - initPromise, - jsAppSettings, - KclValue, - parse, - PathToNode, - Program, - recast, - SourceRange, - topLevelRange, - VariableMap, - ArtifactGraph, -} from 'lang/wasm' -import { getNodeFromPath, getSettingsAnnotation } from './queryAst' -import { - codeManager, - editorManager, - sceneInfra, - rustContext, -} from 'lib/singletons' -import { Diagnostic } from '@codemirror/lint' -import { markOnce } from 'lib/performance' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { +import type { Diagnostic } from '@codemirror/lint' +import type { EntityType_type, ModelingCmdReq_type, } from '@kittycad/lib/dist/types/src/models' -import { Operation } from '@rust/kcl-lib/bindings/Operation' -import { KclSettingsAnnotation } from 'lib/settings/settingsTypes' + +import type { Node } from '@rust/kcl-lib/bindings/Node' +import type { Operation } from '@rust/kcl-lib/bindings/Operation' + +import type { KCLError } from '@src/lang/errors' +import { + compilationErrorsToDiagnostics, + kclErrorsToDiagnostics, +} from '@src/lang/errors' +import { executeAst, executeAstMock, lintAst } from '@src/lang/langHelpers' +import { getNodeFromPath, getSettingsAnnotation } from '@src/lang/queryAst' +import type { EngineCommandManager } from '@src/lang/std/engineConnection' +import { topLevelRange } from '@src/lang/util' +import type { + ArtifactGraph, + ExecState, + KclValue, + PathToNode, + Program, + SourceRange, + VariableMap, +} from '@src/lang/wasm' +import { + emptyExecState, + getKclVersion, + initPromise, + parse, + recast, +} from '@src/lang/wasm' +import type { ArtifactIndex } from '@src/lib/artifactIndex' +import { buildArtifactIndex } from '@src/lib/artifactIndex' +import { EXECUTE_AST_INTERRUPT_ERROR_MESSAGE } from '@src/lib/constants' +import { markOnce } from '@src/lib/performance' +import type { Selections } from '@src/lib/selections' +import { handleSelectionBatch } from '@src/lib/selections' +import type { KclSettingsAnnotation } from '@src/lib/settings/settingsTypes' +import { jsAppSettings } from '@src/lib/settings/settingsUtils' +import { + codeManager, + editorManager, + rustContext, + sceneInfra, +} from '@src/lib/singletons' +import { err, reportRejection } from '@src/lib/trap' +import { deferExecution, isOverlap, uuidv4 } from '@src/lib/utils' interface ExecuteArgs { ast?: Node diff --git a/src/lang/artifact.test.ts b/src/lang/artifact.test.ts index 3ac0a67af..b480bd6cf 100644 --- a/src/lang/artifact.test.ts +++ b/src/lang/artifact.test.ts @@ -1,5 +1,5 @@ -import { assertParse, initPromise } from './wasm' -import { enginelessExecutor } from '../lib/testHelpers' +import { assertParse, initPromise } from '@src/lang/wasm' +import { enginelessExecutor } from '@src/lib/testHelpers' beforeAll(async () => { await initPromise diff --git a/src/lang/codeManager.ts b/src/lang/codeManager.ts index 96ea4fa2c..f8bf489df 100644 --- a/src/lang/codeManager.ts +++ b/src/lang/codeManager.ts @@ -1,16 +1,17 @@ // A little class for updating the code state when we need to and explicitly // NOT updating the code state when we don't need to. // This prevents re-renders of the codemirror editor, when typing. -import { bracket } from 'lib/exampleKcl' -import { isDesktop } from 'lib/isDesktop' -import toast from 'react-hot-toast' -import { editorManager } from 'lib/singletons' -import { Annotation, Transaction } from '@codemirror/state' -import { EditorView, KeyBinding } from '@codemirror/view' -import { recast, Program, parse } from 'lang/wasm' -import { err, reportRejection } from 'lib/trap' -import { Compartment } from '@codemirror/state' import { history } from '@codemirror/commands' +import { Annotation, Compartment, Transaction } from '@codemirror/state' +import type { EditorView, KeyBinding } from '@codemirror/view' +import toast from 'react-hot-toast' + +import type { Program } from '@src/lang/wasm' +import { parse, recast } from '@src/lang/wasm' +import { bracket } from '@src/lib/exampleKcl' +import { isDesktop } from '@src/lib/isDesktop' +import { editorManager } from '@src/lib/singletons' +import { err, reportRejection } from '@src/lib/trap' const PERSIST_CODE_KEY = 'persistCode' diff --git a/src/lang/constants.ts b/src/lang/constants.ts new file mode 100644 index 000000000..00032417d --- /dev/null +++ b/src/lang/constants.ts @@ -0,0 +1,7 @@ +export const ARG_TAG = 'tag' +export const ARG_END = 'end' +export const ARG_LENGTH = 'length' +export const ARG_END_ABSOLUTE = 'endAbsolute' +export const ARG_CIRCLE_CENTER = 'center' +export const ARG_CIRCLE_RADIUS = 'radius' +export const DETERMINING_ARGS = [ARG_LENGTH, ARG_END, ARG_END_ABSOLUTE] diff --git a/src/lang/create.ts b/src/lang/create.ts new file mode 100644 index 000000000..1a630d11a --- /dev/null +++ b/src/lang/create.ts @@ -0,0 +1,439 @@ +import type { Name } from '@rust/kcl-lib/bindings/Name' +import type { Node } from '@rust/kcl-lib/bindings/Node' +import type { TagDeclarator } from '@rust/kcl-lib/bindings/TagDeclarator' + +import { ARG_TAG } from '@src/lang/constants' +import { getNodeFromPath } from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import { findKwArg } from '@src/lang/util' +import type { + ArrayExpression, + BinaryExpression, + CallExpression, + CallExpressionKw, + Expr, + Identifier, + LabeledArg, + Literal, + LiteralValue, + ObjectExpression, + PathToNode, + PipeExpression, + PipeSubstitution, + Program, + SourceRange, + UnaryExpression, + VariableDeclaration, + VariableDeclarator, +} from '@src/lang/wasm' +import { formatNumber } from '@src/lang/wasm' +import { err } from '@src/lib/trap' + +/** + * Note: This depends on WASM, but it's not async. Callers are responsible for + * awaiting init of the WASM module. + */ +export function createLiteral(value: LiteralValue | number): Node { + if (typeof value === 'number') { + value = { value, suffix: 'None' } + } + let raw: string + if (typeof value === 'string') { + // TODO: Should we handle escape sequences? + raw = `${value}` + } else if (typeof value === 'boolean') { + raw = `${value}` + } else if (typeof value.value === 'number' && value.suffix === 'None') { + // Fast path for numbers when there are no units. + raw = `${value.value}` + } else { + raw = formatNumber(value.value, value.suffix) + } + return { + type: 'Literal', + start: 0, + end: 0, + moduleId: 0, + value, + raw, + outerAttrs: [], + preComments: [], + commentStart: 0, + } +} + +export function createTagDeclarator(value: string): Node { + return { + type: 'TagDeclarator', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + + value, + } +} + +export function createIdentifier(name: string): Node { + return { + type: 'Identifier', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + + name, + } +} + +export function createLocalName(name: string): Node { + return { + type: 'Name', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + + abs_path: false, + path: [], + name: createIdentifier(name), + } +} + +export function createName(path: [string], name: string): Node { + return { + type: 'Name', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + + abs_path: false, + path: path.map(createIdentifier), + name: createIdentifier(name), + } +} + +export function createPipeSubstitution(): Node { + return { + type: 'PipeSubstitution', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + } +} + +export function createCallExpressionStdLib( + name: string, + args: CallExpression['arguments'] +): Node { + return { + type: 'CallExpression', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + callee: createLocalName(name), + arguments: args, + } +} + +export const nonCodeMetaEmpty = () => { + return { nonCodeNodes: {}, startNodes: [], start: 0, end: 0 } +} + +export function createCallExpressionStdLibKw( + name: string, + unlabeled: CallExpressionKw['unlabeled'], + args: CallExpressionKw['arguments'] +): Node { + return { + type: 'CallExpressionKw', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + nonCodeMeta: nonCodeMetaEmpty(), + callee: createLocalName(name), + unlabeled, + arguments: args, + } +} + +export function createCallExpression( + name: string, + args: CallExpression['arguments'] +): Node { + return { + type: 'CallExpression', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + callee: createLocalName(name), + arguments: args, + } +} + +export function createArrayExpression( + elements: ArrayExpression['elements'] +): Node { + return { + type: 'ArrayExpression', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + + nonCodeMeta: nonCodeMetaEmpty(), + elements, + } +} + +export function createPipeExpression( + body: PipeExpression['body'] +): Node { + return { + type: 'PipeExpression', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + + body, + nonCodeMeta: nonCodeMetaEmpty(), + } +} + +export function createVariableDeclaration( + varName: string, + init: VariableDeclarator['init'], + visibility: VariableDeclaration['visibility'] = 'default', + kind: VariableDeclaration['kind'] = 'const' +): Node { + return { + type: 'VariableDeclaration', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + + declaration: { + type: 'VariableDeclarator', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + + id: createIdentifier(varName), + init, + }, + visibility, + kind, + } +} + +export function createObjectExpression(properties: { + [key: string]: Expr +}): Node { + return { + type: 'ObjectExpression', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + + nonCodeMeta: nonCodeMetaEmpty(), + properties: Object.entries(properties).map(([key, value]) => ({ + type: 'ObjectProperty', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + key: createIdentifier(key), + + value, + })), + } +} + +export function createUnaryExpression( + argument: UnaryExpression['argument'], + operator: UnaryExpression['operator'] = '-' +): Node { + return { + type: 'UnaryExpression', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + + operator, + argument, + } +} + +export function createBinaryExpression([left, operator, right]: [ + BinaryExpression['left'], + BinaryExpression['operator'], + BinaryExpression['right'], +]): Node { + return { + type: 'BinaryExpression', + start: 0, + end: 0, + moduleId: 0, + outerAttrs: [], + preComments: [], + commentStart: 0, + + operator, + left, + right, + } +} + +export function createBinaryExpressionWithUnary([left, right]: [ + BinaryExpression['left'], + BinaryExpression['right'], +]): Node { + if (right.type === 'UnaryExpression' && right.operator === '-') + return createBinaryExpression([left, '-', right.argument]) + return createBinaryExpression([left, '+', right]) +} + +export function findUniqueName( + ast: Program | string, + name: string, + pad = 3, + index = 1 +): string { + let searchStr: string = typeof ast === 'string' ? ast : JSON.stringify(ast) + const indexStr = String(index).padStart(pad, '0') + + const endingDigitsMatcher = /\d+$/ + const nameEndsInDigits = name.match(endingDigitsMatcher) + let nameIsInString = searchStr.includes(`:"${name}"`) + + if (nameEndsInDigits !== null) { + // base case: name is unique and ends in digits + if (!nameIsInString) return name + + // recursive case: name is not unique and ends in digits + const newPad = nameEndsInDigits[0].length + const newIndex = parseInt(nameEndsInDigits[0]) + 1 + const nameWithoutDigits = name.replace(endingDigitsMatcher, '') + + return findUniqueName(searchStr, nameWithoutDigits, newPad, newIndex) + } + + const newName = `${name}${indexStr}` + nameIsInString = searchStr.includes(`:"${newName}"`) + + // base case: name is unique and does not end in digits + if (!nameIsInString) return newName + + // recursive case: name is not unique and does not end in digits + return findUniqueName(searchStr, name, pad, index + 1) +} + +export function giveSketchFnCallTag( + ast: Node, + range: SourceRange, + tag?: string +): + | { + modifiedAst: Node + tag: string + isTagExisting: boolean + pathToNode: PathToNode + } + | Error { + const path = getNodePathFromSourceRange(ast, range) + const maybeTag = (() => { + const callNode = getNodeFromPath( + ast, + path, + ['CallExpression', 'CallExpressionKw'] + ) + if (!err(callNode) && callNode.node.type === 'CallExpressionKw') { + const { node: primaryCallExp } = callNode + const existingTag = findKwArg(ARG_TAG, primaryCallExp) + const tagDeclarator = + existingTag || createTagDeclarator(tag || findUniqueName(ast, 'seg', 2)) + const isTagExisting = !!existingTag + if (!isTagExisting) { + callNode.node.arguments.push(createLabeledArg(ARG_TAG, tagDeclarator)) + } + return { tagDeclarator, isTagExisting } + } + + // We've handled CallExpressionKw above, so this has to be positional. + const _node1 = getNodeFromPath(ast, path, 'CallExpression') + if (err(_node1)) return _node1 + const { node: primaryCallExp } = _node1 + + // Tag is always 3rd expression now, using arg index feels brittle + // but we can come up with a better way to identify tag later. + const thirdArg = primaryCallExp.arguments?.[2] + const tagDeclarator = + thirdArg || + (createTagDeclarator( + tag || findUniqueName(ast, 'seg', 2) + ) as TagDeclarator) + const isTagExisting = !!thirdArg + if (!isTagExisting) { + primaryCallExp.arguments[2] = tagDeclarator + } + return { tagDeclarator, isTagExisting } + })() + + if (err(maybeTag)) return maybeTag + const { tagDeclarator, isTagExisting } = maybeTag + if ('value' in tagDeclarator) { + // Now TypeScript knows tagDeclarator has a value property + return { + modifiedAst: ast, + tag: String(tagDeclarator.value), + isTagExisting, + pathToNode: path, + } + } else { + return new Error('Unable to assign tag without value') + } +} + +export const createLabeledArg = (label: string, arg: Expr): LabeledArg => { + return { label: createIdentifier(label), arg, type: 'LabeledArg' } +} diff --git a/src/lang/errors.test.ts b/src/lang/errors.test.ts index f115eb0da..41393830b 100644 --- a/src/lang/errors.test.ts +++ b/src/lang/errors.test.ts @@ -1,5 +1,7 @@ -import { kclErrorsToDiagnostics, KCLError } from './errors' -import { defaultArtifactGraph, topLevelRange } from 'lang/wasm' +import type { KCLError } from '@src/lang/errors' +import { kclErrorsToDiagnostics } from '@src/lang/errors' +import { defaultArtifactGraph } from '@src/lang/std/artifactGraph' +import { topLevelRange } from '@src/lang/util' describe('test kclErrToDiagnostic', () => { it('converts KCL errors to CodeMirror diagnostics', () => { diff --git a/src/lang/errors.ts b/src/lang/errors.ts index efb35ca67..2612c779d 100644 --- a/src/lang/errors.ts +++ b/src/lang/errors.ts @@ -1,20 +1,20 @@ -import { KclError as RustKclError } from '@rust/kcl-lib/bindings/KclError' -import { CompilationError } from '@rust/kcl-lib/bindings/CompilationError' -import { Diagnostic as CodeMirrorDiagnostic } from '@codemirror/lint' +import type { Diagnostic as CodeMirrorDiagnostic } from '@codemirror/lint' +import type { Text } from '@codemirror/state' import { posToOffset } from '@kittycad/codemirror-lsp-client' -import { Diagnostic as LspDiagnostic } from 'vscode-languageserver-protocol' -import { Text } from '@codemirror/state' -import { EditorView } from 'codemirror' -import { - ArtifactCommand, - ArtifactGraph, - defaultArtifactGraph, - isTopLevelModule, - SourceRange, -} from 'lang/wasm' -import { Operation } from '@rust/kcl-lib/bindings/Operation' -import { ModulePath } from '@rust/kcl-lib/bindings/ModulePath' -import { DefaultPlanes } from '@rust/kcl-lib/bindings/DefaultPlanes' +import type { EditorView } from 'codemirror' +import type { Diagnostic as LspDiagnostic } from 'vscode-languageserver-protocol' + +import type { CompilationError } from '@rust/kcl-lib/bindings/CompilationError' +import type { DefaultPlanes } from '@rust/kcl-lib/bindings/DefaultPlanes' +import type { KclError as RustKclError } from '@rust/kcl-lib/bindings/KclError' +import type { ModulePath } from '@rust/kcl-lib/bindings/ModulePath' +import type { Operation } from '@rust/kcl-lib/bindings/Operation' + +import type { ArtifactCommand } from '@rust/kcl-lib/bindings/Artifact' +import type { SourceRange } from '@rust/kcl-lib/bindings/SourceRange' +import { defaultArtifactGraph } from '@src/lang/std/artifactGraph' +import { isTopLevelModule } from '@src/lang/util' +import type { ArtifactGraph } from '@src/lang/wasm' type ExtractKind = T extends { kind: infer K } ? K : never export class KCLError extends Error { diff --git a/src/lang/executor.test.ts b/src/lang/executor.test.ts index 1ca8e7c8c..682f493ea 100644 --- a/src/lang/executor.test.ts +++ b/src/lang/executor.test.ts @@ -1,15 +1,11 @@ import fs from 'node:fs' -import { - assertParse, - Sketch, - initPromise, - sketchFromKclValue, - defaultArtifactGraph, - topLevelRange, -} from './wasm' -import { enginelessExecutor } from '../lib/testHelpers' -import { KCLError } from './errors' +import { KCLError } from '@src/lang/errors' +import { defaultArtifactGraph } from '@src/lang/std/artifactGraph' +import { topLevelRange } from '@src/lang/util' +import type { Sketch } from '@src/lang/wasm' +import { assertParse, initPromise, sketchFromKclValue } from '@src/lang/wasm' +import { enginelessExecutor } from '@src/lib/testHelpers' beforeAll(async () => { await initPromise diff --git a/src/lang/getNodePathFromSourceRange.test.ts b/src/lang/getNodePathFromSourceRange.test.ts index acec223af..d7fb0a74a 100644 --- a/src/lang/getNodePathFromSourceRange.test.ts +++ b/src/lang/getNodePathFromSourceRange.test.ts @@ -1,8 +1,12 @@ -import { getNodeFromPath, LABELED_ARG_FIELD, ARG_INDEX_FIELD } from './queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { assertParse, initPromise, Parameter, topLevelRange } from './wasm' -import { err } from 'lib/trap' -import { Name } from '@rust/kcl-lib/bindings/Name' +import type { Name } from '@rust/kcl-lib/bindings/Name' + +import { getNodeFromPath } from '@src/lang/queryAst' +import { ARG_INDEX_FIELD, LABELED_ARG_FIELD } from '@src/lang/queryAstConstants' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import { topLevelRange } from '@src/lang/util' +import type { Parameter } from '@src/lang/wasm' +import { assertParse, initPromise } from '@src/lang/wasm' +import { err } from '@src/lib/trap' beforeAll(async () => { await initPromise diff --git a/src/lang/kclSamples.test.ts b/src/lang/kclSamples.test.ts index 6bb9720b4..e9914960d 100644 --- a/src/lang/kclSamples.test.ts +++ b/src/lang/kclSamples.test.ts @@ -1,8 +1,8 @@ -import { assertParse, initPromise } from './wasm' -import { enginelessExecutor } from '../lib/testHelpers' - -import path from 'node:path' import fs from 'node:fs/promises' +import path from 'node:path' + +import { assertParse, initPromise } from '@src/lang/wasm' +import { enginelessExecutor } from '@src/lib/testHelpers' // The purpose of these tests is to act as a first line of defense // if something gets real screwy with our KCL ecosystem. diff --git a/src/lang/langHelpers.ts b/src/lang/langHelpers.ts index a8fd7bd1e..b76ed1f22 100644 --- a/src/lang/langHelpers.ts +++ b/src/lang/langHelpers.ts @@ -1,15 +1,13 @@ -import { - Program, - kclLint, - emptyExecState, - ExecState, - jsAppSettings, -} from 'lang/wasm' -import { KCLError } from 'lang/errors' -import { Diagnostic } from '@codemirror/lint' -import { Node } from '@rust/kcl-lib/bindings/Node' -import RustContext from 'lib/rustContext' -import { EXECUTE_AST_INTERRUPT_ERROR_STRING } from 'lib/constants' +import type { Diagnostic } from '@codemirror/lint' + +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { KCLError } from '@src/lang/errors' +import type { ExecState, Program } from '@src/lang/wasm' +import { emptyExecState, kclLint } from '@src/lang/wasm' +import { EXECUTE_AST_INTERRUPT_ERROR_STRING } from '@src/lib/constants' +import type RustContext from '@src/lib/rustContext' +import { jsAppSettings } from '@src/lib/settings/settingsUtils' export type ToolTip = | 'lineTo' diff --git a/src/lang/modelingWorkflows.ts b/src/lang/modelingWorkflows.ts index d77bcf4b3..a422a5eb5 100644 --- a/src/lang/modelingWorkflows.ts +++ b/src/lang/modelingWorkflows.ts @@ -5,18 +5,18 @@ * coordinate between different subsystems in the modeling app: * AST, code editor, file system and 3D engine. */ +import type { Node } from '@rust/kcl-lib/bindings/Node' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { KclManager } from 'lang/KclSingleton' -import { ExecutionType } from 'lib/constants' +import type EditorManager from '@src/editor/manager' +import type { KclManager } from '@src/lang/KclSingleton' +import type CodeManager from '@src/lang/codeManager' +import type { PathToNode, Program, SourceRange } from '@src/lang/wasm' +import type { ExecutionType } from '@src/lib/constants' import { EXECUTION_TYPE_MOCK, EXECUTION_TYPE_NONE, EXECUTION_TYPE_REAL, -} from 'lib/constants' -import { PathToNode, Program, SourceRange } from 'lang/wasm' -import EditorManager from 'editor/manager' -import CodeManager from 'lang/codeManager' +} from '@src/lib/constants' /** * Updates the complete modeling state: diff --git a/src/lang/modifyAst.test.ts b/src/lang/modifyAst.test.ts index f647640fb..7fb23708e 100644 --- a/src/lang/modifyAst.test.ts +++ b/src/lang/modifyAst.test.ts @@ -1,38 +1,36 @@ +import type { Node } from '@rust/kcl-lib/bindings/Node' + import { - assertParse, - recast, - initPromise, - Identifier, - topLevelRange, - LiteralValue, - Literal, -} from './wasm' -import { - createLiteral, - createIdentifier, - createCallExpression, - createObjectExpression, createArrayExpression, + createCallExpression, + createIdentifier, + createLiteral, + createObjectExpression, + createPipeExpression, createPipeSubstitution, createVariableDeclaration, - createPipeExpression, findUniqueName, - addSketchTo, giveSketchFnCallTag, - moveValueIntoNewVariable, - sketchOnExtrudedFace, - deleteSegmentFromPipeExpression, - removeSingleConstraintInfo, +} from '@src/lang/create' +import { + addSketchTo, deleteFromSelection, + deleteSegmentFromPipeExpression, + moveValueIntoNewVariable, + removeSingleConstraintInfo, + sketchOnExtrudedFace, splitPipedProfile, -} from './modifyAst' -import { enginelessExecutor } from '../lib/testHelpers' -import { findUsesOfTagInPipe } from './queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { err } from 'lib/trap' -import { SimplifiedArgDetails } from './std/stdTypes' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { Artifact, codeRefFromRange } from './std/artifactGraph' +} from '@src/lang/modifyAst' +import { findUsesOfTagInPipe } from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import type { Artifact } from '@src/lang/std/artifactGraph' +import { codeRefFromRange } from '@src/lang/std/artifactGraph' +import type { SimplifiedArgDetails } from '@src/lang/std/stdTypes' +import { topLevelRange } from '@src/lang/util' +import type { Identifier, Literal, LiteralValue } from '@src/lang/wasm' +import { assertParse, initPromise, recast } from '@src/lang/wasm' +import { enginelessExecutor } from '@src/lib/testHelpers' +import { err } from '@src/lib/trap' beforeAll(async () => { await initPromise diff --git a/src/lang/modifyAst.ts b/src/lang/modifyAst.ts index f7423c95a..f23ad90b5 100644 --- a/src/lang/modifyAst.ts +++ b/src/lang/modifyAst.ts @@ -1,68 +1,46 @@ -import { err, reportRejection, trap } from 'lib/trap' -import { Selection } from 'lib/selections' +import type { Models } from '@kittycad/lib' + +import type { BodyItem } from '@rust/kcl-lib/bindings/BodyItem' +import type { Name } from '@rust/kcl-lib/bindings/Name' +import type { Node } from '@rust/kcl-lib/bindings/Node' + import { - Program, - CallExpression, - LabeledArg, - CallExpressionKw, - PipeExpression, - VariableDeclaration, - VariableDeclarator, - Expr, - Literal, - LiteralValue, - PipeSubstitution, - Identifier, - ArrayExpression, - ObjectExpression, - UnaryExpression, - BinaryExpression, - PathToNode, - SourceRange, - isPathToNodeNumber, - parse, - formatNumber, - ArtifactGraph, - VariableMap, - KclValue, -} from './wasm' + createArrayExpression, + createCallExpression, + createCallExpressionStdLib, + createCallExpressionStdLibKw, + createIdentifier, + createLabeledArg, + createLiteral, + createLocalName, + createObjectExpression, + createPipeExpression, + createPipeSubstitution, + createVariableDeclaration, + findUniqueName, +} from '@src/lang/create' +import { + deleteEdgeTreatment, + locateExtrudeDeclarator, +} from '@src/lang/modifyAst/addEdgeTreatment' import { - isNodeSafeToReplacePath, findAllPreviousVariables, findAllPreviousVariablesPath, - getNodeFromPath, - isNodeSafeToReplace, - traverse, getBodyIndex, + getNodeFromPath, isCallExprWithName, + isNodeSafeToReplace, + isNodeSafeToReplacePath, + traverse, +} from '@src/lang/queryAst' +import { ARG_INDEX_FIELD, LABELED_ARG_FIELD, UNLABELED_ARG, -} from './queryAst' +} from '@src/lang/queryAstConstants' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import type { Artifact } from '@src/lang/std/artifactGraph' import { - addTagForSketchOnFace, - ARG_TAG, - getConstraintInfo, - getConstraintInfoKw, -} from './std/sketch' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { - PathToNodeMap, - isLiteralArrayOrStatic, - removeSingleConstraint, - transformAstSketchLines, -} from './std/sketchcombos' -import { DefaultPlaneStr } from 'lib/planes' -import { isArray, isOverlap, roundOff } from 'lib/utils' -import { KCL_DEFAULT_CONSTANT_PREFIXES } from 'lib/constants' -import { SimplifiedArgDetails } from './std/stdTypes' -import { TagDeclarator } from '@rust/kcl-lib/bindings/TagDeclarator' -import { Models } from '@kittycad/lib' -import { ExtrudeFacePlane } from 'machines/modelingMachine' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { KclExpressionWithVariable } from 'lib/commandTypes' -import { - Artifact, expandCap, expandPlane, expandWall, @@ -70,14 +48,43 @@ import { getArtifactsOfTypes, getFaceCodeRef, getPathsFromArtifact, -} from './std/artifactGraph' -import { BodyItem } from '@rust/kcl-lib/bindings/BodyItem' -import { findKwArg } from './util' +} from '@src/lang/std/artifactGraph' import { - deleteEdgeTreatment, - locateExtrudeDeclarator, -} from './modifyAst/addEdgeTreatment' -import { Name } from '@rust/kcl-lib/bindings/Name' + addTagForSketchOnFace, + getConstraintInfo, + getConstraintInfoKw, +} from '@src/lang/std/sketch' +import type { PathToNodeMap } from '@src/lang/std/sketchcombos' +import { + isLiteralArrayOrStatic, + removeSingleConstraint, + transformAstSketchLines, +} from '@src/lang/std/sketchcombos' +import type { SimplifiedArgDetails } from '@src/lang/std/stdTypes' +import type { + ArrayExpression, + ArtifactGraph, + CallExpression, + CallExpressionKw, + Expr, + KclValue, + Literal, + PathToNode, + PipeExpression, + Program, + SourceRange, + VariableDeclaration, + VariableDeclarator, + VariableMap, +} from '@src/lang/wasm' +import { isPathToNodeNumber, parse } from '@src/lang/wasm' +import type { KclExpressionWithVariable } from '@src/lib/commandTypes' +import { KCL_DEFAULT_CONSTANT_PREFIXES } from '@src/lib/constants' +import type { DefaultPlaneStr } from '@src/lib/planes' +import type { Selection } from '@src/lib/selections' +import { err, reportRejection, trap } from '@src/lib/trap' +import { isArray, isOverlap, roundOff } from '@src/lib/utils' +import type { ExtrudeFacePlane } from '@src/machines/modelingMachine' export function startSketchOnDefault( node: Node, @@ -209,41 +216,6 @@ export function addSketchTo( } } -export function findUniqueName( - ast: Program | string, - name: string, - pad = 3, - index = 1 -): string { - let searchStr: string = typeof ast === 'string' ? ast : JSON.stringify(ast) - const indexStr = String(index).padStart(pad, '0') - - const endingDigitsMatcher = /\d+$/ - const nameEndsInDigits = name.match(endingDigitsMatcher) - let nameIsInString = searchStr.includes(`:"${name}"`) - - if (nameEndsInDigits !== null) { - // base case: name is unique and ends in digits - if (!nameIsInString) return name - - // recursive case: name is not unique and ends in digits - const newPad = nameEndsInDigits[0].length - const newIndex = parseInt(nameEndsInDigits[0]) + 1 - const nameWithoutDigits = name.replace(endingDigitsMatcher, '') - - return findUniqueName(searchStr, nameWithoutDigits, newPad, newIndex) - } - - const newName = `${name}${indexStr}` - nameIsInString = searchStr.includes(`:"${newName}"`) - - // base case: name is unique and does not end in digits - if (!nameIsInString) return newName - - // recursive case: name is not unique and does not end in digits - return findUniqueName(searchStr, name, pad, index + 1) -} - /** Set the keyword argument to the given value. Returns true if it overwrote an existing argument. @@ -493,8 +465,8 @@ export function addShell({ insertIndex !== undefined ? insertIndex : modifiedAst.body.length - ? modifiedAst.body.length - : 0 + ? modifiedAst.body.length + : 0 if (modifiedAst.body.length) { modifiedAst.body.splice(insertAt, 0, variable) @@ -553,8 +525,8 @@ export function addSweep({ insertIndex !== undefined ? insertIndex : modifiedAst.body.length - ? modifiedAst.body.length - : 0 + ? modifiedAst.body.length + : 0 modifiedAst.body.length ? modifiedAst.body.splice(insertAt, 0, variable) @@ -787,8 +759,8 @@ export function addOffsetPlane({ insertIndex !== undefined ? insertIndex : modifiedAst.body.length - ? modifiedAst.body.length - : 0 + ? modifiedAst.body.length + : 0 modifiedAst.body.length ? modifiedAst.body.splice(insertAt, 0, newPlane) @@ -866,8 +838,8 @@ export function addHelix({ insertIndex !== undefined ? insertIndex : modifiedAst.body.length - ? modifiedAst.body.length - : 0 + ? modifiedAst.body.length + : 0 modifiedAst.body.length ? modifiedAst.body.splice(insertAt, 0, variable) @@ -1010,372 +982,6 @@ export function splitPathAtPipeExpression(pathToNode: PathToNode): { return splitPathAtPipeExpression(pathToNode.slice(0, -1)) } -/** - * Note: This depends on WASM, but it's not async. Callers are responsible for - * awaiting init of the WASM module. - */ -export function createLiteral(value: LiteralValue | number): Node { - if (typeof value === 'number') { - value = { value, suffix: 'None' } - } - let raw: string - if (typeof value === 'string') { - // TODO: Should we handle escape sequences? - raw = `${value}` - } else if (typeof value === 'boolean') { - raw = `${value}` - } else if (typeof value.value === 'number' && value.suffix === 'None') { - // Fast path for numbers when there are no units. - raw = `${value.value}` - } else { - raw = formatNumber(value.value, value.suffix) - } - return { - type: 'Literal', - start: 0, - end: 0, - moduleId: 0, - value, - raw, - outerAttrs: [], - preComments: [], - commentStart: 0, - } -} - -export function createTagDeclarator(value: string): Node { - return { - type: 'TagDeclarator', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - - value, - } -} - -export function createIdentifier(name: string): Node { - return { - type: 'Identifier', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - - name, - } -} - -export function createLocalName(name: string): Node { - return { - type: 'Name', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - - abs_path: false, - path: [], - name: createIdentifier(name), - } -} - -export function createName(path: [string], name: string): Node { - return { - type: 'Name', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - - abs_path: false, - path: path.map(createIdentifier), - name: createIdentifier(name), - } -} - -export function createPipeSubstitution(): Node { - return { - type: 'PipeSubstitution', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - } -} - -export function createCallExpressionStdLib( - name: string, - args: CallExpression['arguments'] -): Node { - return { - type: 'CallExpression', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - callee: createLocalName(name), - arguments: args, - } -} - -export function createCallExpressionStdLibKw( - name: string, - unlabeled: CallExpressionKw['unlabeled'], - args: CallExpressionKw['arguments'] -): Node { - return { - type: 'CallExpressionKw', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - nonCodeMeta: nonCodeMetaEmpty(), - callee: createLocalName(name), - unlabeled, - arguments: args, - } -} - -export function createCallExpression( - name: string, - args: CallExpression['arguments'] -): Node { - return { - type: 'CallExpression', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - callee: createLocalName(name), - arguments: args, - } -} - -export function createArrayExpression( - elements: ArrayExpression['elements'] -): Node { - return { - type: 'ArrayExpression', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - - nonCodeMeta: nonCodeMetaEmpty(), - elements, - } -} - -export function createPipeExpression( - body: PipeExpression['body'] -): Node { - return { - type: 'PipeExpression', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - - body, - nonCodeMeta: nonCodeMetaEmpty(), - } -} - -export function createVariableDeclaration( - varName: string, - init: VariableDeclarator['init'], - visibility: VariableDeclaration['visibility'] = 'default', - kind: VariableDeclaration['kind'] = 'const' -): Node { - return { - type: 'VariableDeclaration', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - - declaration: { - type: 'VariableDeclarator', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - - id: createIdentifier(varName), - init, - }, - visibility, - kind, - } -} - -export function createObjectExpression(properties: { - [key: string]: Expr -}): Node { - return { - type: 'ObjectExpression', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - - nonCodeMeta: nonCodeMetaEmpty(), - properties: Object.entries(properties).map(([key, value]) => ({ - type: 'ObjectProperty', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - key: createIdentifier(key), - - value, - })), - } -} - -export function createUnaryExpression( - argument: UnaryExpression['argument'], - operator: UnaryExpression['operator'] = '-' -): Node { - return { - type: 'UnaryExpression', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - - operator, - argument, - } -} - -export function createBinaryExpression([left, operator, right]: [ - BinaryExpression['left'], - BinaryExpression['operator'], - BinaryExpression['right'] -]): Node { - return { - type: 'BinaryExpression', - start: 0, - end: 0, - moduleId: 0, - outerAttrs: [], - preComments: [], - commentStart: 0, - - operator, - left, - right, - } -} - -export function createBinaryExpressionWithUnary([left, right]: [ - BinaryExpression['left'], - BinaryExpression['right'] -]): Node { - if (right.type === 'UnaryExpression' && right.operator === '-') - return createBinaryExpression([left, '-', right.argument]) - return createBinaryExpression([left, '+', right]) -} - -export function giveSketchFnCallTag( - ast: Node, - range: SourceRange, - tag?: string -): - | { - modifiedAst: Node - tag: string - isTagExisting: boolean - pathToNode: PathToNode - } - | Error { - const path = getNodePathFromSourceRange(ast, range) - const maybeTag = (() => { - const callNode = getNodeFromPath( - ast, - path, - ['CallExpression', 'CallExpressionKw'] - ) - if (!err(callNode) && callNode.node.type === 'CallExpressionKw') { - const { node: primaryCallExp } = callNode - const existingTag = findKwArg(ARG_TAG, primaryCallExp) - const tagDeclarator = - existingTag || createTagDeclarator(tag || findUniqueName(ast, 'seg', 2)) - const isTagExisting = !!existingTag - if (!isTagExisting) { - callNode.node.arguments.push(createLabeledArg(ARG_TAG, tagDeclarator)) - } - return { tagDeclarator, isTagExisting } - } - - // We've handled CallExpressionKw above, so this has to be positional. - const _node1 = getNodeFromPath(ast, path, 'CallExpression') - if (err(_node1)) return _node1 - const { node: primaryCallExp } = _node1 - - // Tag is always 3rd expression now, using arg index feels brittle - // but we can come up with a better way to identify tag later. - const thirdArg = primaryCallExp.arguments?.[2] - const tagDeclarator = - thirdArg || - (createTagDeclarator( - tag || findUniqueName(ast, 'seg', 2) - ) as TagDeclarator) - const isTagExisting = !!thirdArg - if (!isTagExisting) { - primaryCallExp.arguments[2] = tagDeclarator - } - return { tagDeclarator, isTagExisting } - })() - - if (err(maybeTag)) return maybeTag - const { tagDeclarator, isTagExisting } = maybeTag - if ('value' in tagDeclarator) { - // Now TypeScript knows tagDeclarator has a value property - return { - modifiedAst: ast, - tag: String(tagDeclarator.value), - isTagExisting, - pathToNode: path, - } - } else { - return new Error('Unable to assign tag without value') - } -} - /** * Replace a */ @@ -1557,7 +1163,7 @@ export async function deleteFromSelection( variables: VariableMap, artifactGraph: ArtifactGraph, getFaceDetails: (id: string) => Promise = () => - ({} as any) + ({}) as any ): Promise | Error> { const astClone = structuredClone(ast) let deletionArtifact = selection.artifact @@ -1591,8 +1197,8 @@ export async function deleteFromSelection( deletionArtifact.type === 'plane' ? expandPlane(deletionArtifact, artifactGraph) : deletionArtifact.type === 'wall' - ? expandWall(deletionArtifact, artifactGraph) - : expandCap(deletionArtifact, artifactGraph) + ? expandWall(deletionArtifact, artifactGraph) + : expandCap(deletionArtifact, artifactGraph) for (const path of plane.paths.sort( (a, b) => b.codeRef.range?.[0] - a.codeRef.range?.[0] )) { @@ -1732,12 +1338,12 @@ export async function deleteFromSelection( selection.artifact?.type === 'wall' ? selection.artifact : selection.artifact?.type === 'segment' && - selection.artifact.surfaceId - ? getArtifactOfTypes( - { key: selection.artifact.surfaceId, types: ['wall'] }, - artifactGraph - ) - : null + selection.artifact.surfaceId + ? getArtifactOfTypes( + { key: selection.artifact.surfaceId, types: ['wall'] }, + artifactGraph + ) + : null if (err(wallArtifact)) return if (wallArtifact) { const sweep = getArtifactOfTypes( @@ -1802,15 +1408,15 @@ export async function deleteFromSelection( variable.type === 'Sketch' ? variable.value.artifactId : variable.type === 'Face' - ? variable.value.artifactId - : '' + ? variable.value.artifactId + : '' if (!artifactId) return new Error('Sketch not on anything') const onId = variable.type === 'Sketch' ? variable.value.on.id : variable.type === 'Face' - ? variable.value.id - : '' + ? variable.value.id + : '' if (!onId) return new Error('Sketch not on anything') // Can't kick off multiple requests at once as getFaceDetails // is three engine calls in one and they conflict @@ -1943,10 +1549,6 @@ export function deleteNodeInExtrudePipe( lookup.extrudeDeclarator.init.body.splice(node[pipeIndex][0], 1) } -export const nonCodeMetaEmpty = () => { - return { nonCodeNodes: {}, startNodes: [], start: 0, end: 0 } -} - export function getInsertIndex( sketchNodePaths: PathToNode[], planeNodePath: PathToNode, @@ -1963,8 +1565,8 @@ export function getInsertIndex( const insertIndex = !sketchNodePaths.length ? Number(planeNodePath[1][0]) + 1 : insertType === 'start' - ? minIndex - : maxIndex + 1 + ? minIndex + : maxIndex + 1 return insertIndex } @@ -2107,7 +1709,3 @@ export function createNodeFromExprSnippet( if (!node) return new Error('No node found') return node } - -export const createLabeledArg = (label: string, arg: Expr): LabeledArg => { - return { label: createIdentifier(label), arg, type: 'LabeledArg' } -} diff --git a/src/lang/modifyAst/addEdgeTreatment.test.ts b/src/lang/modifyAst/addEdgeTreatment.test.ts index aa91f9389..35576ace8 100644 --- a/src/lang/modifyAst/addEdgeTreatment.test.ts +++ b/src/lang/modifyAst/addEdgeTreatment.test.ts @@ -1,41 +1,42 @@ -import { - assertParse, - recast, - initPromise, - PathToNode, - Program, - CallExpression, - PipeExpression, - VariableDeclarator, - SourceRange, - topLevelRange, - CallExpressionKw, -} from '../wasm' +import { VITE_KC_DEV_TOKEN } from '@src/env' + +import { createLiteral } from '@src/lang/create' +import type { + ChamferParameters, + EdgeTreatmentParameters, + FilletParameters, +} from '@src/lang/modifyAst/addEdgeTreatment' import { EdgeTreatmentType, + deleteEdgeTreatment, getPathToExtrudeForSegmentSelection, hasValidEdgeTreatmentSelection, isTagUsedInEdgeTreatment, modifyAstWithEdgeTreatmentAndTag, - FilletParameters, - ChamferParameters, - EdgeTreatmentParameters, - deleteEdgeTreatment, -} from './addEdgeTreatment' -import { getNodeFromPath } from '../queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { createLiteral } from 'lang/modifyAst' -import { err } from 'lib/trap' -import { Selection, Selections } from 'lib/selections' +} from '@src/lang/modifyAst/addEdgeTreatment' +import { getNodeFromPath } from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import { codeRefFromRange } from '@src/lang/std/artifactGraph' +import { topLevelRange } from '@src/lang/util' +import type { + CallExpression, + CallExpressionKw, + PathToNode, + PipeExpression, + Program, + SourceRange, + VariableDeclarator, +} from '@src/lang/wasm' +import { assertParse, initPromise, recast } from '@src/lang/wasm' +import type { Selection, Selections } from '@src/lib/selections' import { codeManager, editorManager, engineCommandManager, kclManager, -} from 'lib/singletons' -import { VITE_KC_DEV_TOKEN } from 'env' -import { isOverlap } from 'lib/utils' -import { codeRefFromRange } from 'lang/std/artifactGraph' +} from '@src/lib/singletons' +import { err } from '@src/lib/trap' +import { isOverlap } from '@src/lib/utils' beforeAll(async () => { await initPromise diff --git a/src/lang/modifyAst/addEdgeTreatment.ts b/src/lang/modifyAst/addEdgeTreatment.ts index db6a285ad..01d4a174f 100644 --- a/src/lang/modifyAst/addEdgeTreatment.ts +++ b/src/lang/modifyAst/addEdgeTreatment.ts @@ -1,4 +1,36 @@ +import type { Name } from '@rust/kcl-lib/bindings/Name' +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import type EditorManager from '@src/editor/manager' +import type { KclManager } from '@src/lang/KclSingleton' +import type CodeManager from '@src/lang/codeManager' +import { ARG_TAG } from '@src/lang/constants' import { + createArrayExpression, + createCallExpressionStdLib, + createCallExpressionStdLibKw, + createLabeledArg, + createLocalName, + createPipeExpression, +} from '@src/lang/create' +import { updateModelingState } from '@src/lang/modelingWorkflows' +import { + getNodeFromPath, + hasSketchPipeBeenExtruded, + traverse, +} from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import type { Artifact } from '@src/lang/std/artifactGraph' +import { getSweepArtifactFromSelection } from '@src/lang/std/artifactGraph' +import type { EngineCommandManager } from '@src/lang/std/engineConnection' +import { + addTagForSketchOnFace, + getTagFromCallExpression, + sketchLineHelperMap, + sketchLineHelperMapKw, +} from '@src/lang/std/sketch' +import { findKwArg } from '@src/lang/util' +import type { ArtifactGraph, CallExpression, CallExpressionKw, @@ -9,42 +41,12 @@ import { Program, VariableDeclaration, VariableDeclarator, -} from '../wasm' -import { - createCallExpressionStdLib, - createArrayExpression, - createLocalName, - createPipeExpression, - createCallExpressionStdLibKw, - createLabeledArg, -} from '../modifyAst' -import { - getNodeFromPath, - hasSketchPipeBeenExtruded, - traverse, -} from '../queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { - addTagForSketchOnFace, - ARG_TAG, - getTagFromCallExpression, - sketchLineHelperMap, - sketchLineHelperMapKw, -} from '../std/sketch' -import { err } from 'lib/trap' -import { Selection, Selections } from 'lib/selections' -import { KclCommandValue } from 'lib/commandTypes' -import { isArray } from 'lib/utils' -import { Artifact, getSweepArtifactFromSelection } from 'lang/std/artifactGraph' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { findKwArg } from 'lang/util' -import { KclManager } from 'lang/KclSingleton' -import { EXECUTION_TYPE_REAL } from 'lib/constants' -import { EngineCommandManager } from 'lang/std/engineConnection' -import EditorManager from 'editor/manager' -import CodeManager from 'lang/codeManager' -import { updateModelingState } from 'lang/modelingWorkflows' -import { Name } from '@rust/kcl-lib/bindings/Name' +} from '@src/lang/wasm' +import type { KclCommandValue } from '@src/lib/commandTypes' +import { EXECUTION_TYPE_REAL } from '@src/lib/constants' +import type { Selection, Selections } from '@src/lib/selections' +import { err } from '@src/lib/trap' +import { isArray } from '@src/lib/utils' // Edge Treatment Types export enum EdgeTreatmentType { diff --git a/src/lang/modifyAst/addRevolve.ts b/src/lang/modifyAst/addRevolve.ts index 3841a7f7b..bfd0460f3 100644 --- a/src/lang/modifyAst/addRevolve.ts +++ b/src/lang/modifyAst/addRevolve.ts @@ -1,27 +1,30 @@ -import { err } from 'lib/trap' -import { KCL_DEFAULT_CONSTANT_PREFIXES } from 'lib/constants' -import { Program, PathToNode, Expr, VariableDeclarator } from 'lang/wasm' -import { Selections } from 'lib/selections' -import { Node } from '@rust/kcl-lib/bindings/Node' +import type { Node } from '@rust/kcl-lib/bindings/Node' + import { - createLiteral, - createLocalName, - findUniqueName, - createVariableDeclaration, createCallExpressionStdLibKw, createLabeledArg, -} from 'lang/modifyAst' + createLiteral, + createLocalName, + createVariableDeclaration, + findUniqueName, +} from '@src/lang/create' import { - ARG_INDEX_FIELD, - getNodeFromPath, - LABELED_ARG_FIELD, -} from 'lang/queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { - mutateAstWithTagForSketchSegment, getEdgeTagCall, -} from 'lang/modifyAst/addEdgeTreatment' -import { getSafeInsertIndex } from 'lang/queryAst/getSafeInsertIndex' + mutateAstWithTagForSketchSegment, +} from '@src/lang/modifyAst/addEdgeTreatment' +import { getNodeFromPath } from '@src/lang/queryAst' +import { getSafeInsertIndex } from '@src/lang/queryAst/getSafeInsertIndex' +import { ARG_INDEX_FIELD, LABELED_ARG_FIELD } from '@src/lang/queryAstConstants' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import type { + Expr, + PathToNode, + Program, + VariableDeclarator, +} from '@src/lang/wasm' +import { KCL_DEFAULT_CONSTANT_PREFIXES } from '@src/lib/constants' +import type { Selections } from '@src/lib/selections' +import { err } from '@src/lib/trap' export function getAxisExpressionAndIndex( axisOrEdge: 'Axis' | 'Edge', diff --git a/src/lang/modifyAst/boolean.ts b/src/lang/modifyAst/boolean.ts index 322907cc2..a1f9cca21 100644 --- a/src/lang/modifyAst/boolean.ts +++ b/src/lang/modifyAst/boolean.ts @@ -1,8 +1,8 @@ -import { Node } from '@rust/kcl-lib/bindings/Node' -import EditorManager from 'editor/manager' -import CodeManager from 'lang/codeManager' -import { KclManager } from 'lang/KclSingleton' -import { updateModelingState } from 'lang/modelingWorkflows' +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import type EditorManager from '@src/editor/manager' +import type { KclManager } from '@src/lang/KclSingleton' +import type CodeManager from '@src/lang/codeManager' import { createArrayExpression, createCallExpressionStdLibKw, @@ -10,21 +10,22 @@ import { createLocalName, createVariableDeclaration, findUniqueName, -} from 'lang/modifyAst' -import { getNodeFromPath } from 'lang/queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { getFaceCodeRef } from 'lang/std/artifactGraph' -import { EngineCommandManager } from 'lang/std/engineConnection' -import { +} from '@src/lang/create' +import { updateModelingState } from '@src/lang/modelingWorkflows' +import { getNodeFromPath } from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import { getFaceCodeRef } from '@src/lang/std/artifactGraph' +import type { EngineCommandManager } from '@src/lang/std/engineConnection' +import type { Artifact, ArtifactGraph, Program, VariableDeclaration, -} from 'lang/wasm' -import { EXECUTION_TYPE_REAL } from 'lib/constants' -import { Selection, Selections } from 'lib/selections' -import { err } from 'lib/trap' -import { isArray } from 'lib/utils' +} from '@src/lang/wasm' +import { EXECUTION_TYPE_REAL } from '@src/lib/constants' +import type { Selection, Selections } from '@src/lib/selections' +import { err } from '@src/lib/trap' +import { isArray } from '@src/lib/utils' export async function applySubtractFromTargetOperatorSelections( target: Selection, diff --git a/src/lang/modifyAst/deleteSelection.ts b/src/lang/modifyAst/deleteSelection.ts index 95b46921b..4dc654ab1 100644 --- a/src/lang/modifyAst/deleteSelection.ts +++ b/src/lang/modifyAst/deleteSelection.ts @@ -1,16 +1,16 @@ -import { Selection } from 'lib/selections' -import { getFaceDetails } from 'clientSideScene/sceneEntities' -import { deleteFromSelection } from 'lang/modifyAst' +import { executeAstMock } from '@src/lang/langHelpers' +import { updateModelingState } from '@src/lang/modelingWorkflows' +import { deleteFromSelection } from '@src/lang/modifyAst' +import { EXECUTION_TYPE_REAL } from '@src/lib/constants' +import type { Selection } from '@src/lib/selections' import { codeManager, editorManager, kclManager, rustContext, -} from 'lib/singletons' -import { err } from 'lib/trap' -import { executeAstMock } from 'lang/langHelpers' -import { updateModelingState } from 'lang/modelingWorkflows' -import { EXECUTION_TYPE_REAL } from 'lib/constants' + sceneEntitiesManager, +} from '@src/lib/singletons' +import { err } from '@src/lib/trap' export const deletionErrorMessage = 'Unable to delete selection. Please edit manually in code pane.' @@ -25,7 +25,7 @@ export async function deleteSelectionPromise( selection, kclManager.variables, kclManager.artifactGraph, - getFaceDetails + sceneEntitiesManager.getFaceDetails ) if (err(modifiedAst)) { return new Error(deletionErrorMessage) diff --git a/src/lang/modifyAst/setAppearance.ts b/src/lang/modifyAst/setAppearance.ts index 1775569eb..b1cc397ea 100644 --- a/src/lang/modifyAst/setAppearance.ts +++ b/src/lang/modifyAst/setAppearance.ts @@ -1,15 +1,16 @@ -import { PathToNode, Program } from 'lang/wasm' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { locateExtrudeDeclarator } from './addEdgeTreatment' -import { err } from 'lib/trap' +import type { Node } from '@rust/kcl-lib/bindings/Node' + import { createCallExpressionStdLibKw, createLabeledArg, createLiteral, createPipeExpression, -} from 'lang/modifyAst' -import { createPipeSubstitution } from 'lang/modifyAst' -import { COMMAND_APPEARANCE_COLOR_DEFAULT } from 'lib/commandBarConfigs/modelingCommandConfig' + createPipeSubstitution, +} from '@src/lang/create' +import { locateExtrudeDeclarator } from '@src/lang/modifyAst/addEdgeTreatment' +import type { PathToNode, Program } from '@src/lang/wasm' +import { COMMAND_APPEARANCE_COLOR_DEFAULT } from '@src/lib/commandBarConfigs/modelingCommandConfig' +import { err } from '@src/lib/trap' export function setAppearance({ ast, diff --git a/src/lang/project.ts b/src/lang/project.ts index 17141a034..aada9a51b 100644 --- a/src/lang/project.ts +++ b/src/lang/project.ts @@ -1,11 +1,14 @@ -import { UnitLength } from '@rust/kcl-lib/bindings/ModelingCmd' +import type { UnitLength } from '@rust/kcl-lib/bindings/ModelingCmd' + import { changeKclSettings, unitAngleToUnitAng, unitLengthToUnitLen, -} from './wasm' -import { DEFAULT_DEFAULT_ANGLE_UNIT } from 'lib/constants' -import { DEFAULT_DEFAULT_LENGTH_UNIT } from 'lib/constants' +} from '@src/lang/wasm' +import { + DEFAULT_DEFAULT_ANGLE_UNIT, + DEFAULT_DEFAULT_LENGTH_UNIT, +} from '@src/lib/constants' /** * Create a new KCL file with the given initial content and default length unit. diff --git a/src/lang/queryAst.test.ts b/src/lang/queryAst.test.ts index 7a1261c37..eb314c1b4 100644 --- a/src/lang/queryAst.test.ts +++ b/src/lang/queryAst.test.ts @@ -1,36 +1,32 @@ -import { - assertParse, - recast, - initPromise, - PathToNode, - Identifier, - topLevelRange, -} from './wasm' -import { - findAllPreviousVariables, - isNodeSafeToReplace, - isTypeInValue, - hasExtrudeSketch, - findUsesOfTagInPipe, - hasSketchPipeBeenExtruded, - doesSceneHaveSweepableSketch, - traverse, - getNodeFromPath, - doesSceneHaveExtrudedSketch, -} from './queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { enginelessExecutor } from '../lib/testHelpers' +import type { Name } from '@rust/kcl-lib/bindings/Name' + import { createArrayExpression, createCallExpression, + createCallExpressionStdLib, createLiteral, createPipeSubstitution, - createCallExpressionStdLib, -} from './modifyAst' -import { err } from 'lib/trap' -import { codeRefFromRange } from './std/artifactGraph' -import { addCallExpressionsToPipe, addCloseToPipe } from 'lang/std/sketch' -import { Name } from '@rust/kcl-lib/bindings/Name' +} from '@src/lang/create' +import { + doesSceneHaveExtrudedSketch, + doesSceneHaveSweepableSketch, + findAllPreviousVariables, + findUsesOfTagInPipe, + getNodeFromPath, + hasExtrudeSketch, + hasSketchPipeBeenExtruded, + isNodeSafeToReplace, + isTypeInValue, + traverse, +} from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import { codeRefFromRange } from '@src/lang/std/artifactGraph' +import { addCallExpressionsToPipe, addCloseToPipe } from '@src/lang/std/sketch' +import { topLevelRange } from '@src/lang/util' +import type { Identifier, PathToNode } from '@src/lang/wasm' +import { assertParse, initPromise, recast } from '@src/lang/wasm' +import { enginelessExecutor } from '@src/lib/testHelpers' +import { err } from '@src/lib/trap' beforeAll(async () => { await initPromise diff --git a/src/lang/queryAst.ts b/src/lang/queryAst.ts index d2d16251d..b741ab14c 100644 --- a/src/lang/queryAst.ts +++ b/src/lang/queryAst.ts @@ -1,54 +1,56 @@ -import { ToolTip } from 'lang/langHelpers' -import { Selection, Selections } from 'lib/selections' +import type { FunctionExpression } from '@rust/kcl-lib/bindings/FunctionExpression' +import type { ImportStatement } from '@rust/kcl-lib/bindings/ImportStatement' +import type { Node } from '@rust/kcl-lib/bindings/Node' +import type { TypeDeclaration } from '@rust/kcl-lib/bindings/TypeDeclaration' + +import { ARG_TAG } from '@src/lang/constants' +import { createLocalName } from '@src/lang/create' +import type { ToolTip } from '@src/lang/langHelpers' +import { splitPathAtLastIndex } from '@src/lang/modifyAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import { codeRefFromRange } from '@src/lang/std/artifactGraph' +import { getArgForEnd, getFirstArg } from '@src/lang/std/sketch' +import { getSketchSegmentFromSourceRange } from '@src/lang/std/sketchConstraints' import { + getConstraintLevelFromSourceRange, + getConstraintType, +} from '@src/lang/std/sketchcombos' +import { findKwArg, topLevelRange } from '@src/lang/util' +import type { ArrayExpression, + ArtifactGraph, BinaryExpression, CallExpression, CallExpressionKw, Expr, ExpressionStatement, + Identifier, ObjectExpression, ObjectProperty, PathToNode, PipeExpression, Program, ReturnStatement, - sketchFromKclValue, - sketchFromKclValueOptional, SourceRange, SyntaxType, - topLevelRange, VariableDeclaration, VariableDeclarator, - recast, - ArtifactGraph, - kclSettings, - unitLenToUnitLength, - unitAngToUnitAngle, VariableMap, - Identifier, -} from './wasm' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { createLocalName, splitPathAtLastIndex } from './modifyAst' -import { getSketchSegmentFromSourceRange } from './std/sketchConstraints' -import { getAngle, isArray } from '../lib/utils' -import { ARG_TAG, getArgForEnd, getFirstArg } from './std/sketch' +} from '@src/lang/wasm' import { - getConstraintLevelFromSourceRange, - getConstraintType, -} from './std/sketchcombos' -import { err, Reason } from 'lib/trap' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { findKwArg } from './util' -import { codeRefFromRange } from './std/artifactGraph' -import { FunctionExpression } from '@rust/kcl-lib/bindings/FunctionExpression' -import { ImportStatement } from '@rust/kcl-lib/bindings/ImportStatement' -import { KclSettingsAnnotation } from 'lib/settings/settingsTypes' -import { TypeDeclaration } from '@rust/kcl-lib/bindings/TypeDeclaration' + kclSettings, + recast, + sketchFromKclValue, + sketchFromKclValueOptional, + unitAngToUnitAngle, + unitLenToUnitLength, +} from '@src/lang/wasm' +import type { Selection, Selections } from '@src/lib/selections' +import type { KclSettingsAnnotation } from '@src/lib/settings/settingsTypes' +import { Reason, err } from '@src/lib/trap' +import { getAngle, isArray } from '@src/lib/utils' -export const LABELED_ARG_FIELD = 'LabeledArg -> Arg' -export const UNLABELED_ARG = 'unlabeled first arg' -export const ARG_INDEX_FIELD = 'arg index' +import { ARG_INDEX_FIELD, LABELED_ARG_FIELD } from '@src/lang/queryAstConstants' /** * Retrieves a node from a given path within a Program node structure, optionally stopping at a specified node type. diff --git a/src/lang/queryAst/getIdentifiersInProgram.test.ts b/src/lang/queryAst/getIdentifiersInProgram.test.ts index c2a2cf557..42f1f55a0 100644 --- a/src/lang/queryAst/getIdentifiersInProgram.test.ts +++ b/src/lang/queryAst/getIdentifiersInProgram.test.ts @@ -1,5 +1,5 @@ -import { assertParse, initPromise } from 'lang/wasm' -import { getIdentifiersInProgram } from './getIndentifiersInProgram' +import { getIdentifiersInProgram } from '@src/lang/queryAst/getIndentifiersInProgram' +import { assertParse, initPromise } from '@src/lang/wasm' function identifier(name: string, start: number, end: number) { return { diff --git a/src/lang/queryAst/getIndentifiersInProgram.ts b/src/lang/queryAst/getIndentifiersInProgram.ts index 4a06d8b4d..2189baa29 100644 --- a/src/lang/queryAst/getIndentifiersInProgram.ts +++ b/src/lang/queryAst/getIndentifiersInProgram.ts @@ -1,6 +1,7 @@ -import { traverse } from 'lang/queryAst' -import { Expr, Name, Program } from 'lang/wasm' -import { Node } from '@rust/kcl-lib/bindings/Node' +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { traverse } from '@src/lang/queryAst' +import type { Expr, Name, Program } from '@src/lang/wasm' /** * Given an AST `Program`, return an array of diff --git a/src/lang/queryAst/getSafeInsertIndex.test.ts b/src/lang/queryAst/getSafeInsertIndex.test.ts index af62d6bd1..23d574b80 100644 --- a/src/lang/queryAst/getSafeInsertIndex.test.ts +++ b/src/lang/queryAst/getSafeInsertIndex.test.ts @@ -1,5 +1,5 @@ -import { assertParse, initPromise } from 'lang/wasm' -import { getSafeInsertIndex } from './getSafeInsertIndex' +import { getSafeInsertIndex } from '@src/lang/queryAst/getSafeInsertIndex' +import { assertParse, initPromise } from '@src/lang/wasm' beforeAll(async () => { await initPromise diff --git a/src/lang/queryAst/getSafeInsertIndex.ts b/src/lang/queryAst/getSafeInsertIndex.ts index 37c6587b1..fd01e68e0 100644 --- a/src/lang/queryAst/getSafeInsertIndex.ts +++ b/src/lang/queryAst/getSafeInsertIndex.ts @@ -1,7 +1,8 @@ -import { getIdentifiersInProgram } from './getIndentifiersInProgram' -import { Program, Expr } from 'lang/wasm' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { getTagDeclaratorsInProgram } from './getTagDeclaratorsInProgram' +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { getIdentifiersInProgram } from '@src/lang/queryAst/getIndentifiersInProgram' +import { getTagDeclaratorsInProgram } from '@src/lang/queryAst/getTagDeclaratorsInProgram' +import type { Expr, Program } from '@src/lang/wasm' /** * Given a target expression, return the body index of the last-used variable diff --git a/src/lang/queryAst/getTagDeclaratorsInProgram.test.ts b/src/lang/queryAst/getTagDeclaratorsInProgram.test.ts index d8a78ebb2..883078415 100644 --- a/src/lang/queryAst/getTagDeclaratorsInProgram.test.ts +++ b/src/lang/queryAst/getTagDeclaratorsInProgram.test.ts @@ -1,5 +1,5 @@ -import { assertParse, initPromise } from 'lang/wasm' -import { getTagDeclaratorsInProgram } from './getTagDeclaratorsInProgram' +import { getTagDeclaratorsInProgram } from '@src/lang/queryAst/getTagDeclaratorsInProgram' +import { assertParse, initPromise } from '@src/lang/wasm' function tagDeclaratorWithIndex( value: string, diff --git a/src/lang/queryAst/getTagDeclaratorsInProgram.ts b/src/lang/queryAst/getTagDeclaratorsInProgram.ts index 31e96132e..e1291c8e8 100644 --- a/src/lang/queryAst/getTagDeclaratorsInProgram.ts +++ b/src/lang/queryAst/getTagDeclaratorsInProgram.ts @@ -1,8 +1,9 @@ -import { getBodyIndex, traverse } from 'lang/queryAst' -import { Expr, Program } from 'lang/wasm' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { TagDeclarator } from '@rust/kcl-lib/bindings/TagDeclarator' -import { err } from 'lib/trap' +import type { Node } from '@rust/kcl-lib/bindings/Node' +import type { TagDeclarator } from '@rust/kcl-lib/bindings/TagDeclarator' + +import { getBodyIndex, traverse } from '@src/lang/queryAst' +import type { Expr, Program } from '@src/lang/wasm' +import { err } from '@src/lib/trap' type TagWithBodyIndex = { tag: TagDeclarator; bodyIndex: number } diff --git a/src/lang/queryAst/getVariableDeclaration.ts b/src/lang/queryAst/getVariableDeclaration.ts index 277952293..036c345fe 100644 --- a/src/lang/queryAst/getVariableDeclaration.ts +++ b/src/lang/queryAst/getVariableDeclaration.ts @@ -1,5 +1,6 @@ -import { Node } from '@rust/kcl-lib/bindings/Node' -import { Program } from 'lang/wasm' +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import type { Program } from '@src/lang/wasm' /** * Given a program and a variable name, return the variable declaration diff --git a/src/lang/queryAst/getVariableDeclarationIndex.ts b/src/lang/queryAst/getVariableDeclarationIndex.ts index d3960771b..976d362e9 100644 --- a/src/lang/queryAst/getVariableDeclarationIndex.ts +++ b/src/lang/queryAst/getVariableDeclarationIndex.ts @@ -1,5 +1,6 @@ -import { Node } from '@rust/kcl-lib/bindings/Node' -import { Program } from 'lang/wasm' +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import type { Program } from '@src/lang/wasm' /** * Given a program and a variable name, return the index of the variable declaration diff --git a/src/lang/queryAstConstants.ts b/src/lang/queryAstConstants.ts new file mode 100644 index 000000000..452829ba9 --- /dev/null +++ b/src/lang/queryAstConstants.ts @@ -0,0 +1,3 @@ +export const LABELED_ARG_FIELD = 'LabeledArg -> Arg' +export const UNLABELED_ARG = 'unlabeled first arg' +export const ARG_INDEX_FIELD = 'arg index' diff --git a/src/lang/queryAstNodePathUtils.ts b/src/lang/queryAstNodePathUtils.ts index 2f00457fb..6c1b9000d 100644 --- a/src/lang/queryAstNodePathUtils.ts +++ b/src/lang/queryAstNodePathUtils.ts @@ -1,17 +1,18 @@ -import { +import type { ImportStatement } from '@rust/kcl-lib/bindings/ImportStatement' +import type { Node } from '@rust/kcl-lib/bindings/Node' +import type { TypeDeclaration } from '@rust/kcl-lib/bindings/TypeDeclaration' + +import { ARG_INDEX_FIELD, LABELED_ARG_FIELD } from '@src/lang/queryAstConstants' +import type { Expr, ExpressionStatement, - VariableDeclaration, - ReturnStatement, - SourceRange, + Identifier, PathToNode, Program, - Identifier, -} from './wasm' -import { ImportStatement } from '@rust/kcl-lib/bindings/ImportStatement' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { ARG_INDEX_FIELD, LABELED_ARG_FIELD } from './queryAst' -import { TypeDeclaration } from '@rust/kcl-lib/bindings/TypeDeclaration' + ReturnStatement, + SourceRange, + VariableDeclaration, +} from '@src/lang/wasm' function moreNodePathFromSourceRange( node: Node< diff --git a/src/lang/recast.test.ts b/src/lang/recast.test.ts index 38110f71b..5ae49d83b 100644 --- a/src/lang/recast.test.ts +++ b/src/lang/recast.test.ts @@ -1,6 +1,8 @@ -import { assertParse, Program, recast, initPromise } from './wasm' import fs from 'node:fs' -import { err } from 'lib/trap' + +import type { Program } from '@src/lang/wasm' +import { assertParse, initPromise, recast } from '@src/lang/wasm' +import { err } from '@src/lib/trap' beforeAll(async () => { await initPromise diff --git a/src/lang/std/artifactGraph.ts b/src/lang/std/artifactGraph.ts index b13b2c81c..05adb0647 100644 --- a/src/lang/std/artifactGraph.ts +++ b/src/lang/std/artifactGraph.ts @@ -1,35 +1,41 @@ -import { - Expr, - Artifact, - ArtifactGraph, - ArtifactId, - PathToNode, - Program, - SourceRange, - PathArtifact, - PlaneArtifact, - WallArtifact, - SegmentArtifact, - Solid2dArtifact as Solid2D, - SweepArtifact, - SweepEdge, - CapArtifact, - EdgeCut, -} from 'lang/wasm' -import { Models } from '@kittycad/lib' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { Selection } from 'lib/selections' -import { err } from 'lib/trap' -import { +import type { Models } from '@kittycad/lib' + +import type { Cap, + CapSubType, Plane, StartSketchOnFace, StartSketchOnPlane, Wall, } from '@rust/kcl-lib/bindings/Artifact' -import { CapSubType } from '@rust/kcl-lib/bindings/Artifact' -export type { Artifact, ArtifactId, SegmentArtifact } from 'lang/wasm' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import type { + Artifact, + ArtifactGraph, + ArtifactId, + CapArtifact, + EdgeCut, + Expr, + PathArtifact, + PathToNode, + PlaneArtifact, + Program, + SegmentArtifact, + Solid2dArtifact as Solid2D, + SourceRange, + SweepArtifact, + SweepEdge, + WallArtifact, +} from '@src/lang/wasm' +import type { Selection } from '@src/lib/selections' +import { err } from '@src/lib/trap' + +export type { Artifact, ArtifactId, SegmentArtifact } from '@src/lang/wasm' + +export function defaultArtifactGraph(): ArtifactGraph { + return new Map() +} interface BaseArtifact { id: ArtifactId diff --git a/src/lang/std/engineConnection.ts b/src/lang/std/engineConnection.ts index 855510a34..f2bd71603 100644 --- a/src/lang/std/engineConnection.ts +++ b/src/lang/std/engineConnection.ts @@ -1,22 +1,24 @@ -import { defaultSourceRange, SourceRange } from 'lang/wasm' -import { VITE_KC_API_WS_MODELING_URL, VITE_KC_DEV_TOKEN } from 'env' -import { Models } from '@kittycad/lib' -import { uuidv4, binaryToUuid } from 'lib/utils' +import type { Models } from '@kittycad/lib' +import { VITE_KC_API_WS_MODELING_URL, VITE_KC_DEV_TOKEN } from '@src/env' import { BSON } from 'bson' + +import type { MachineManager } from '@src/components/MachineManagerProvider' +import type { useModelingContext } from '@src/hooks/useModelingContext' +import type { KclManager } from '@src/lang/KclSingleton' +import type { EngineCommand, ResponseMap } from '@src/lang/std/artifactGraph' +import type { SourceRange } from '@src/lang/wasm' +import { defaultSourceRange } from '@src/lang/wasm' +import { EXECUTE_AST_INTERRUPT_ERROR_MESSAGE } from '@src/lib/constants' +import { markOnce } from '@src/lib/performance' +import type { SettingsViaQueryString } from '@src/lib/settings/settingsTypes' import { Themes, - getThemeColorForEngine, - getOppositeTheme, darkModeMatcher, -} from 'lib/theme' -import { EngineCommand, ResponseMap } from 'lang/std/artifactGraph' -import { useModelingContext } from 'hooks/useModelingContext' -import { SettingsViaQueryString } from 'lib/settings/settingsTypes' -import { EXECUTE_AST_INTERRUPT_ERROR_MESSAGE } from 'lib/constants' -import { KclManager } from 'lang/KclSingleton' -import { reportRejection } from 'lib/trap' -import { markOnce } from 'lib/performance' -import { MachineManager } from 'components/MachineManagerProvider' + getOppositeTheme, + getThemeColorForEngine, +} from '@src/lib/theme' +import { reportRejection } from '@src/lib/trap' +import { binaryToUuid, uuidv4 } from '@src/lib/utils' // TODO(paultag): This ought to be tweakable. const pingIntervalMs = 5_000 @@ -48,8 +50,8 @@ interface WebRTCClientMetrics extends ClientMetrics { type Value = U extends undefined ? { type: T; value: U } : U extends void - ? { type: T } - : { type: T; value: U } + ? { type: T } + : { type: T; value: U } type State = Value @@ -309,8 +311,10 @@ class EngineConnection extends EventTarget { private engineCommandManager: EngineCommandManager private pingPongSpan: { ping?: Date; pong?: Date } - private pingIntervalId: ReturnType = setInterval(() => {}, - 60_000) + private pingIntervalId: ReturnType = setInterval( + () => {}, + 60_000 + ) isUsingConnectionLite: boolean = false constructor({ diff --git a/src/lang/std/sketch.test.ts b/src/lang/std/sketch.test.ts index 0a47f2f86..77b5335de 100644 --- a/src/lang/std/sketch.test.ts +++ b/src/lang/std/sketch.test.ts @@ -1,26 +1,22 @@ +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { getNodeFromPath } from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' import { - changeSketchArguments, - addTagForSketchOnFace, - addNewSketchLn, - getYComponent, - getXComponent, addCloseToPipe, + addNewSketchLn, + addTagForSketchOnFace, + changeSketchArguments, getConstraintInfo, getConstraintInfoKw, -} from './sketch' -import { - assertParse, - recast, - initPromise, - CallExpression, - topLevelRange, - CallExpressionKw, -} from '../wasm' -import { getNodeFromPath } from '../queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { enginelessExecutor } from '../../lib/testHelpers' -import { err } from 'lib/trap' -import { Node } from '@rust/kcl-lib/bindings/Node' + getXComponent, + getYComponent, +} from '@src/lang/std/sketch' +import { topLevelRange } from '@src/lang/util' +import type { CallExpression, CallExpressionKw } from '@src/lang/wasm' +import { assertParse, initPromise, recast } from '@src/lang/wasm' +import { enginelessExecutor } from '@src/lib/testHelpers' +import { err } from '@src/lib/trap' const eachQuad: [number, [number, number]][] = [ [-315, [1, 1]], diff --git a/src/lang/std/sketch.ts b/src/lang/std/sketch.ts index 1076ef19d..514062c17 100644 --- a/src/lang/std/sketch.ts +++ b/src/lang/std/sketch.ts @@ -1,88 +1,86 @@ +import { perpendicularDistance } from 'sketch-helpers' + +import type { Name } from '@rust/kcl-lib/bindings/Name' +import type { Node } from '@rust/kcl-lib/bindings/Node' +import type { TagDeclarator } from '@rust/kcl-lib/bindings/TagDeclarator' + import { - Path, - Sketch, - SourceRange, - PathToNode, - Program, - PipeExpression, - CallExpression, - CallExpressionKw, - VariableDeclarator, - Expr, - VariableDeclaration, - sketchFromKclValue, - topLevelRange, - VariableMap, -} from 'lang/wasm' + ARG_CIRCLE_CENTER, + ARG_CIRCLE_RADIUS, + ARG_END, + ARG_END_ABSOLUTE, + ARG_LENGTH, + ARG_TAG, + DETERMINING_ARGS, +} from '@src/lang/constants' import { - ARG_INDEX_FIELD, - getNodeFromPath, - getNodeFromPathCurry, - LABELED_ARG_FIELD, -} from 'lang/queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' + createArrayExpression, + createCallExpression, + createCallExpressionStdLibKw, + createLabeledArg, + createLiteral, + createObjectExpression, + createPipeExpression, + createPipeSubstitution, + createTagDeclarator, + findUniqueName, + nonCodeMetaEmpty, +} from '@src/lang/create' +import type { ToolTip } from '@src/lang/langHelpers' +import { toolTips } from '@src/lang/langHelpers' +import { + mutateArrExp, + mutateKwArg, + mutateObjExpProp, + removeKwArgs, + splitPathAtPipeExpression, +} from '@src/lang/modifyAst' +import { getNodeFromPath, getNodeFromPathCurry } from '@src/lang/queryAst' +import { ARG_INDEX_FIELD, LABELED_ARG_FIELD } from '@src/lang/queryAstConstants' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' import { isLiteralArrayOrStatic, isNotLiteralArrayOrStatic, -} from 'lang/std/sketchcombos' -import { toolTips, ToolTip } from 'lang/langHelpers' -import { - createPipeExpression, - mutateKwArg, - nonCodeMetaEmpty, - removeKwArgs, - splitPathAtPipeExpression, -} from '../modifyAst' - -import { - SketchLineHelper, - ConstrainInfo, - ArrayItemInput, - ObjectPropertyInput, - SingleValueInput, +} from '@src/lang/std/sketchcombos' +import type { AddTagInfo, + ArrayItemInput, + ConstrainInfo, + CreatedSketchExprResult, + InputArgKeys, + ObjectPropertyInput, + RawArgs, SegmentInputs, SimplifiedArgDetails, - RawArgs, - CreatedSketchExprResult, + SingleValueInput, + SketchLineHelper, SketchLineHelperKw, - InputArgKeys, -} from 'lang/std/stdTypes' - -import { - createLiteral, - createTagDeclarator, - createCallExpression, - createCallExpressionStdLibKw, - createArrayExpression, - createLabeledArg, - createPipeSubstitution, - createObjectExpression, - mutateArrExp, - mutateObjExpProp, - findUniqueName, -} from 'lang/modifyAst' -import { roundOff, getLength, getAngle, isArray } from 'lib/utils' -import { err } from 'lib/trap' -import { perpendicularDistance } from 'sketch-helpers' -import { TagDeclarator } from '@rust/kcl-lib/bindings/TagDeclarator' -import { EdgeCutInfo } from 'machines/modelingMachine' -import { Node } from '@rust/kcl-lib/bindings/Node' +} from '@src/lang/std/stdTypes' import { findKwArg, - findKwArgWithIndex, findKwArgAny, findKwArgAnyIndex, -} from 'lang/util' -import { Name } from '@rust/kcl-lib/bindings/Name' - -export const ARG_TAG = 'tag' -export const ARG_END = 'end' -export const ARG_LENGTH = 'length' -export const ARG_END_ABSOLUTE = 'endAbsolute' -export const ARG_CIRCLE_CENTER = 'center' -export const ARG_CIRCLE_RADIUS = 'radius' -export const DETERMINING_ARGS = [ARG_LENGTH, ARG_END, ARG_END_ABSOLUTE] + findKwArgWithIndex, + topLevelRange, +} from '@src/lang/util' +import type { + CallExpression, + CallExpressionKw, + Expr, + Path, + PathToNode, + PipeExpression, + Program, + Sketch, + SourceRange, + VariableDeclaration, + VariableDeclarator, + VariableMap, +} from '@src/lang/wasm' +import { sketchFromKclValue } from '@src/lang/wasm' +import { err } from '@src/lib/trap' +import { getAngle, getLength, isArray, roundOff } from '@src/lib/utils' +import type { EdgeCutInfo } from '@src/machines/modelingMachine' const STRAIGHT_SEGMENT_ERR = new Error( 'Invalid input, expected "straight-segment"' @@ -158,10 +156,10 @@ const constrainInfo = ( g === 'singleValue' ? { type: 'singleValue' } : typeof g === 'number' - ? { type: 'arrayItem', index: g } - : typeof g === 'string' - ? { type: 'objectProperty', key: g } - : undefined, + ? { type: 'arrayItem', index: g } + : typeof g === 'string' + ? { type: 'objectProperty', key: g } + : undefined, pathToNode: e, stdLibFnName: f, }) @@ -178,7 +176,7 @@ const commonConstraintInfoHelper = ( { arrayInput?: 0 | 1 objInput?: ObjectPropertyInput['key'] - } + }, ], code: string, pathToNode: PathToNode, @@ -3459,10 +3457,11 @@ function isAngleLiteral(lineArugement: Expr): boolean { return lineArugement?.type === 'ArrayExpression' ? isLiteralArrayOrStatic(lineArugement.elements[0]) : lineArugement?.type === 'ObjectExpression' - ? isLiteralArrayOrStatic( - lineArugement.properties.find(({ key }) => key.name === 'angle')?.value - ) - : false + ? isLiteralArrayOrStatic( + lineArugement.properties.find(({ key }) => key.name === 'angle') + ?.value + ) + : false } type addTagFn = ( diff --git a/src/lang/std/sketchConstraints.test.ts b/src/lang/std/sketchConstraints.test.ts index 67f091556..2c51751be 100644 --- a/src/lang/std/sketchConstraints.test.ts +++ b/src/lang/std/sketchConstraints.test.ts @@ -1,21 +1,20 @@ +import { codeRefFromRange } from '@src/lang/std/artifactGraph' +import { getSketchSegmentFromSourceRange } from '@src/lang/std/sketchConstraints' +import type { ConstraintType } from '@src/lang/std/sketchcombos' import { - assertParse, - Sketch, - recast, - initPromise, - sketchFromKclValue, - SourceRange, - topLevelRange, -} from '../wasm' -import { - ConstraintType, getTransformInfos, transformAstSketchLines, -} from './sketchcombos' -import { getSketchSegmentFromSourceRange } from './sketchConstraints' -import { enginelessExecutor } from '../../lib/testHelpers' -import { err } from 'lib/trap' -import { codeRefFromRange } from './artifactGraph' +} from '@src/lang/std/sketchcombos' +import { topLevelRange } from '@src/lang/util' +import type { Sketch, SourceRange } from '@src/lang/wasm' +import { + assertParse, + initPromise, + recast, + sketchFromKclValue, +} from '@src/lang/wasm' +import { enginelessExecutor } from '@src/lib/testHelpers' +import { err } from '@src/lib/trap' beforeAll(async () => { await initPromise diff --git a/src/lang/std/sketchConstraints.ts b/src/lang/std/sketchConstraints.ts index f9c57e490..09f280d83 100644 --- a/src/lang/std/sketchConstraints.ts +++ b/src/lang/std/sketchConstraints.ts @@ -1,22 +1,23 @@ -import { getNodeFromPath } from 'lang/queryAst' -import { ToolTip, toolTips } from 'lang/langHelpers' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { - Program, - VariableDeclarator, +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { DETERMINING_ARGS } from '@src/lang/constants' +import type { ToolTip } from '@src/lang/langHelpers' +import { toolTips } from '@src/lang/langHelpers' +import { getNodeFromPath } from '@src/lang/queryAst' +import { findKwArgAny, topLevelRange } from '@src/lang/util' +import type { CallExpression, - Sketch, - SourceRange, + CallExpressionKw, + Expr, + LabeledArg, Path, PathToNode, - Expr, - topLevelRange, - LabeledArg, - CallExpressionKw, -} from '../wasm' -import { err } from 'lib/trap' -import { findKwArgAny } from 'lang/util' -import { DETERMINING_ARGS } from './sketch' + Program, + Sketch, + SourceRange, + VariableDeclarator, +} from '@src/lang/wasm' +import { err } from '@src/lib/trap' export function getSketchSegmentFromPathToNode( sketch: Sketch, diff --git a/src/lang/std/sketchcombos.test.ts b/src/lang/std/sketchcombos.test.ts index 13c1dc6ec..e27e97756 100644 --- a/src/lang/std/sketchcombos.test.ts +++ b/src/lang/std/sketchcombos.test.ts @@ -1,32 +1,24 @@ +import { ARG_END, ARG_END_ABSOLUTE } from '@src/lang/constants' +import type { ToolTip } from '@src/lang/langHelpers' +import { codeRefFromRange } from '@src/lang/std/artifactGraph' +import { getArgForEnd, isAbsoluteLine } from '@src/lang/std/sketch' +import type { + ConstraintLevel, + ConstraintType, +} from '@src/lang/std/sketchcombos' import { - assertParse, - Expr, - recast, - initPromise, - Program, - topLevelRange, -} from '../wasm' -import { + getConstraintLevelFromSourceRange, getConstraintType, getTransformInfos, transformAstSketchLines, transformSecondarySketchLinesTagFirst, - ConstraintType, - ConstraintLevel, - getConstraintLevelFromSourceRange, -} from './sketchcombos' -import { ToolTip } from 'lang/langHelpers' -import { Selections, Selection } from 'lib/selections' -import { err } from 'lib/trap' -import { enginelessExecutor } from '../../lib/testHelpers' -import { codeRefFromRange } from './artifactGraph' -import { findKwArg } from 'lang/util' -import { - ARG_END, - ARG_END_ABSOLUTE, - getArgForEnd, - isAbsoluteLine, -} from './sketch' +} from '@src/lang/std/sketchcombos' +import { findKwArg, topLevelRange } from '@src/lang/util' +import type { Expr, Program } from '@src/lang/wasm' +import { assertParse, initPromise, recast } from '@src/lang/wasm' +import type { Selection, Selections } from '@src/lib/selections' +import { enginelessExecutor } from '@src/lib/testHelpers' +import { err } from '@src/lib/trap' beforeAll(async () => { await initPromise diff --git a/src/lang/std/sketchcombos.ts b/src/lang/std/sketchcombos.ts index a5ba6029a..17aa4cbba 100644 --- a/src/lang/std/sketchcombos.ts +++ b/src/lang/std/sketchcombos.ts @@ -1,31 +1,12 @@ +import type { Node } from '@rust/kcl-lib/bindings/Node' + import { - CreatedSketchExprResult, - CreateStdLibSketchCallExpr, - InputArg, - InputArgs, - SimplifiedArgDetails, - TransformInfo, -} from './stdTypes' -import { ToolTip, toolTips } from 'lang/langHelpers' -import { Selections } from 'lib/selections' -import { cleanErrs, err } from 'lib/trap' -import { - CallExpression, - CallExpressionKw, - Program, - Expr, - BinaryPart, - VariableDeclarator, - PathToNode, - sketchFromKclValue, - Literal, - SourceRange, - LiteralValue, - LabeledArg, - VariableMap, -} from '../wasm' -import { getNodeFromPath, getNodeFromPathCurry } from '../queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' + ARG_END, + ARG_END_ABSOLUTE, + ARG_LENGTH, + ARG_TAG, + DETERMINING_ARGS, +} from '@src/lang/constants' import { createArrayExpression, createBinaryExpression, @@ -40,31 +21,54 @@ import { createPipeSubstitution, createUnaryExpression, giveSketchFnCallTag, -} from '../modifyAst' +} from '@src/lang/create' +import type { ToolTip } from '@src/lang/langHelpers' +import { toolTips } from '@src/lang/langHelpers' +import { getNodeFromPath, getNodeFromPathCurry } from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' import { createFirstArg, - getConstraintInfo, - getFirstArg, - getArgForEnd, - replaceSketchLine, - ARG_TAG, - ARG_END, - ARG_END_ABSOLUTE, - getConstraintInfoKw, - isAbsoluteLine, - getCircle, - ARG_LENGTH, - tooltipToFnName, fnNameToTooltip, - DETERMINING_ARGS, -} from './sketch' + getArgForEnd, + getCircle, + getConstraintInfo, + getConstraintInfoKw, + getFirstArg, + isAbsoluteLine, + replaceSketchLine, + tooltipToFnName, +} from '@src/lang/std/sketch' import { getSketchSegmentFromPathToNode, getSketchSegmentFromSourceRange, -} from './sketchConstraints' -import { getAngle, roundOff, normaliseAngle, isArray } from '../../lib/utils' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { findKwArg, findKwArgAny } from 'lang/util' +} from '@src/lang/std/sketchConstraints' +import type { + CreateStdLibSketchCallExpr, + CreatedSketchExprResult, + InputArg, + InputArgs, + SimplifiedArgDetails, + TransformInfo, +} from '@src/lang/std/stdTypes' +import { findKwArg, findKwArgAny } from '@src/lang/util' +import type { + BinaryPart, + CallExpression, + CallExpressionKw, + Expr, + LabeledArg, + Literal, + LiteralValue, + PathToNode, + Program, + SourceRange, + VariableDeclarator, + VariableMap, +} from '@src/lang/wasm' +import { sketchFromKclValue } from '@src/lang/wasm' +import type { Selections } from '@src/lib/selections' +import { cleanErrs, err } from '@src/lib/trap' +import { getAngle, isArray, normaliseAngle, roundOff } from '@src/lib/utils' export type LineInputsType = | 'xAbsolute' @@ -322,8 +326,8 @@ const xyLineSetLength = const lineVal = forceValueUsedInTransform ? forceValueUsedInTransform : referenceSeg - ? segRef - : args[0].expr + ? segRef + : args[0].expr const literalArg = asNum(args[0].expr.value) if (err(literalArg)) return literalArg return createCallWrapper(xOrY, lineVal, tag, literalArg) @@ -351,18 +355,18 @@ const basicAngledLineCreateNode = varValToUse === 'ang' ? inputs[0].expr : referenceSeg === 'ang' - ? getClosesAngleDirection( - argValue, - refAng, - createSegAngle(referenceSegName) - ) - : args[0].expr + ? getClosesAngleDirection( + argValue, + refAng, + createSegAngle(referenceSegName) + ) + : args[0].expr const nonForcedLen = varValToUse === 'len' ? inputs[1].expr : referenceSeg === 'len' - ? createSegLen(referenceSegName) - : args[1].expr + ? createSegLen(referenceSegName) + : args[1].expr const shouldForceAng = valToForce === 'ang' && forceValueUsedInTransform const shouldForceLen = valToForce === 'len' && forceValueUsedInTransform const literalArg = asNum( @@ -678,13 +682,13 @@ const setAngleBetweenCreateNode = tranformToType === 'none' ? 'angledLine' : tranformToType === 'xAbs' - ? 'angledLineToX' - : 'angledLineToY', + ? 'angledLineToX' + : 'angledLineToY', tranformToType === 'none' ? [binExp, args[1].expr] : tranformToType === 'xAbs' - ? [binExp, inputs[0].expr] - : [binExp, inputs[1].expr], + ? [binExp, inputs[0].expr] + : [binExp, inputs[1].expr], tag, valueUsedInTransform ) @@ -2104,17 +2108,17 @@ export function transformAstSketchLines({ ccw: true, // Default to counter-clockwise for circles } : seg.type === 'CircleThreePoint' || seg.type === 'ArcThreePoint' - ? { - type: 'circle-three-point-segment', - p1: seg.p1, - p2: seg.p2, - p3: seg.p3, - } - : { - type: 'straight-segment', - to, - from, - }, + ? { + type: 'circle-three-point-segment', + p1: seg.p1, + p2: seg.p2, + p3: seg.p3, + } + : { + type: 'straight-segment', + to, + from, + }, replaceExistingCallback: (rawArgs) => callBack({ diff --git a/src/lang/std/std.test.ts b/src/lang/std/std.test.ts index f18183ab2..cb33c6506 100644 --- a/src/lang/std/std.test.ts +++ b/src/lang/std/std.test.ts @@ -1,5 +1,5 @@ -import { assertParse, initPromise } from '../wasm' -import { enginelessExecutor } from '../../lib/testHelpers' +import { assertParse, initPromise } from '@src/lang/wasm' +import { enginelessExecutor } from '@src/lib/testHelpers' beforeAll(async () => { await initPromise diff --git a/src/lang/std/stdTypes.ts b/src/lang/std/stdTypes.ts index c29c5e677..157d42b2c 100644 --- a/src/lang/std/stdTypes.ts +++ b/src/lang/std/stdTypes.ts @@ -1,18 +1,19 @@ -import { ToolTip } from 'lang/langHelpers' -import { - Path, - SourceRange, - Program, - Expr, - PathToNode, - CallExpression, - Literal, +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import type { ToolTip } from '@src/lang/langHelpers' +import type { LineInputsType } from '@src/lang/std/sketchcombos' +import type { BinaryPart, + CallExpression, CallExpressionKw, + Expr, + Literal, + Path, + PathToNode, + Program, + SourceRange, VariableMap, -} from '../wasm' -import { LineInputsType } from './sketchcombos' -import { Node } from '@rust/kcl-lib/bindings/Node' +} from '@src/lang/wasm' export interface ModifyAstBase { node: Node diff --git a/src/lang/util.ts b/src/lang/util.ts index aa91956c6..16033f019 100644 --- a/src/lang/util.ts +++ b/src/lang/util.ts @@ -1,18 +1,35 @@ -import { Selections } from 'lib/selections' -import { - PathToNode, - CallExpression, - Literal, +import { filterArtifacts, getFaceCodeRef } from '@src/lang/std/artifactGraph' +import type { ArrayExpression, - BinaryExpression, ArtifactGraph, + BinaryExpression, + CallExpression, CallExpressionKw, Expr, + Literal, LiteralValue, NumericSuffix, -} from './wasm' -import { filterArtifacts, getFaceCodeRef } from 'lang/std/artifactGraph' -import { isArray, isOverlap } from 'lib/utils' + PathToNode, +} from '@src/lang/wasm' +import type { Selections } from '@src/lib/selections' +import { isArray, isOverlap } from '@src/lib/utils' + +import type { SourceRange } from '@rust/kcl-lib/bindings/SourceRange' + +/** + * Create a SourceRange for the top-level module. + */ +export function topLevelRange(start: number, end: number): SourceRange { + return [start, end, 0] +} + +/** + * Returns true if this source range is from the file being executed. Returns + * false if it's from a file that was imported. + */ +export function isTopLevelModule(range: SourceRange): boolean { + return range[2] === 0 +} /** * Updates pathToNode body indices to account for the insertion of an expression @@ -81,12 +98,12 @@ export function isCursorInSketchCommandRange( firstEntry?.type === 'segment' ? firstEntry.pathId : ((firstEntry?.type === 'plane' || - firstEntry?.type === 'cap' || - firstEntry?.type === 'wall') && - firstEntry.pathIds?.length) || - false - ? firstEntry.pathIds[0] - : false + firstEntry?.type === 'cap' || + firstEntry?.type === 'wall') && + firstEntry.pathIds?.length) || + false + ? firstEntry.pathIds[0] + : false return parentId ? parentId diff --git a/src/lang/wasm.test.ts b/src/lang/wasm.test.ts index e792085c5..313cb1c61 100644 --- a/src/lang/wasm.test.ts +++ b/src/lang/wasm.test.ts @@ -1,8 +1,10 @@ -import { err } from 'lib/trap' -import { formatNumber, initPromise, parse, ParseResult } from './wasm' -import { enginelessExecutor } from 'lib/testHelpers' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { Program } from '@rust/kcl-lib/bindings/Program' +import type { Node } from '@rust/kcl-lib/bindings/Node' +import type { Program } from '@rust/kcl-lib/bindings/Program' + +import type { ParseResult } from '@src/lang/wasm' +import { formatNumber, initPromise, parse } from '@src/lang/wasm' +import { enginelessExecutor } from '@src/lib/testHelpers' +import { err } from '@src/lib/trap' beforeEach(async () => { await initPromise diff --git a/src/lang/wasm.ts b/src/lang/wasm.ts index 861264234..42235a69d 100644 --- a/src/lang/wasm.ts +++ b/src/lang/wasm.ts @@ -1,105 +1,110 @@ -import { - init, - parse_wasm, - recast_wasm, - format_number, - kcl_lint, - is_points_ccw, - get_tangential_arc_to_info, - get_kcl_version, - coredump, - default_app_settings, - parse_app_settings, - parse_project_settings, - default_project_settings, - base64_decode, - kcl_settings, - change_kcl_settings, - serialize_project_configuration, - serialize_configuration, - reloadModule, - is_kcl_empty_or_only_settings, -} from 'lib/wasm_lib_wrapper' - -import { KCLError } from './errors' -import { KclError as RustKclError } from '@rust/kcl-lib/bindings/KclError' -import { Discovered } from '@rust/kcl-lib/bindings/Discovered' -import { KclValue } from '@rust/kcl-lib/bindings/KclValue' +import type { + ArtifactCommand, + ArtifactId, + ArtifactGraph as RustArtifactGraph, +} from '@rust/kcl-lib/bindings/Artifact' +import type { CompilationError } from '@rust/kcl-lib/bindings/CompilationError' +import type { Configuration } from '@rust/kcl-lib/bindings/Configuration' +import type { CoreDumpInfo } from '@rust/kcl-lib/bindings/CoreDumpInfo' +import type { DefaultPlanes } from '@rust/kcl-lib/bindings/DefaultPlanes' +import type { Discovered } from '@rust/kcl-lib/bindings/Discovered' +import type { ExecOutcome as RustExecOutcome } from '@rust/kcl-lib/bindings/ExecOutcome' +import type { KclError as RustKclError } from '@rust/kcl-lib/bindings/KclError' +import type { KclErrorWithOutputs } from '@rust/kcl-lib/bindings/KclErrorWithOutputs' +import type { KclValue } from '@rust/kcl-lib/bindings/KclValue' +import type { MetaSettings } from '@rust/kcl-lib/bindings/MetaSettings' +import type { UnitAngle, UnitLength } from '@rust/kcl-lib/bindings/ModelingCmd' +import type { ModulePath } from '@rust/kcl-lib/bindings/ModulePath' +import type { Node } from '@rust/kcl-lib/bindings/Node' +import type { NumericSuffix } from '@rust/kcl-lib/bindings/NumericSuffix' +import type { Operation } from '@rust/kcl-lib/bindings/Operation' import type { Program } from '@rust/kcl-lib/bindings/Program' -import { Coords2d } from './std/sketch' -import { CoreDumpInfo } from '@rust/kcl-lib/bindings/CoreDumpInfo' -import { CoreDumpManager } from 'lib/coredump' -import openWindow from 'lib/openWindow' -import { TEST } from 'env' -import { err, Reason } from 'lib/trap' -import { Configuration } from '@rust/kcl-lib/bindings/Configuration' -import { DeepPartial } from 'lib/types' -import { ProjectConfiguration } from '@rust/kcl-lib/bindings/ProjectConfiguration' -import { Sketch } from '@rust/kcl-lib/bindings/Sketch' -import { ExecOutcome as RustExecOutcome } from '@rust/kcl-lib/bindings/ExecOutcome' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { CompilationError } from '@rust/kcl-lib/bindings/CompilationError' -import { SourceRange } from '@rust/kcl-lib/bindings/SourceRange' -import { getAllCurrentSettings } from 'lib/settings/settingsUtils' -import { Operation } from '@rust/kcl-lib/bindings/Operation' -import { KclErrorWithOutputs } from '@rust/kcl-lib/bindings/KclErrorWithOutputs' -import { ArtifactId } from '@rust/kcl-lib/bindings/Artifact' -import { ArtifactCommand } from '@rust/kcl-lib/bindings/Artifact' -import { ArtifactGraph as RustArtifactGraph } from '@rust/kcl-lib/bindings/Artifact' -import { Artifact } from './std/artifactGraph' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { NumericSuffix } from '@rust/kcl-lib/bindings/NumericSuffix' -import { MetaSettings } from '@rust/kcl-lib/bindings/MetaSettings' -import { UnitAngle, UnitLength } from '@rust/kcl-lib/bindings/ModelingCmd' -import { UnitLen } from '@rust/kcl-lib/bindings/UnitLen' -import { UnitAngle as UnitAng } from '@rust/kcl-lib/bindings/UnitAngle' -import { ModulePath } from '@rust/kcl-lib/bindings/ModulePath' -import { DefaultPlanes } from '@rust/kcl-lib/bindings/DefaultPlanes' -import { isArray } from 'lib/utils' +import type { ProjectConfiguration } from '@rust/kcl-lib/bindings/ProjectConfiguration' +import type { Sketch } from '@rust/kcl-lib/bindings/Sketch' +import type { SourceRange } from '@rust/kcl-lib/bindings/SourceRange' +import type { UnitAngle as UnitAng } from '@rust/kcl-lib/bindings/UnitAngle' +import type { UnitLen } from '@rust/kcl-lib/bindings/UnitLen' + +import { KCLError } from '@src/lang/errors' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import { + defaultArtifactGraph, + type Artifact, +} from '@src/lang/std/artifactGraph' +import type { Coords2d } from '@src/lang/std/sketch' import { DEFAULT_DEFAULT_ANGLE_UNIT, DEFAULT_DEFAULT_LENGTH_UNIT, -} from 'lib/constants' +} from '@src/lib/constants' +import type { CoreDumpManager } from '@src/lib/coredump' +import openWindow from '@src/lib/openWindow' +import { Reason, err } from '@src/lib/trap' +import type { DeepPartial } from '@src/lib/types' +import { isArray } from '@src/lib/utils' +import { + base64_decode, + change_kcl_settings, + coredump, + default_app_settings, + default_project_settings, + format_number, + get_kcl_version, + get_tangential_arc_to_info, + init, + is_kcl_empty_or_only_settings, + is_points_ccw, + kcl_lint, + kcl_settings, + parse_app_settings, + parse_project_settings, + parse_wasm, + recast_wasm, + reloadModule, + serialize_configuration, + serialize_project_configuration, +} from '@src/lib/wasm_lib_wrapper' -export type { Artifact } from '@rust/kcl-lib/bindings/Artifact' -export type { ArtifactCommand } from '@rust/kcl-lib/bindings/Artifact' -export type { ArtifactId } from '@rust/kcl-lib/bindings/Artifact' -export type { Cap as CapArtifact } from '@rust/kcl-lib/bindings/Artifact' -export type { CodeRef } from '@rust/kcl-lib/bindings/Artifact' -export type { EdgeCut } from '@rust/kcl-lib/bindings/Artifact' -export type { Path as PathArtifact } from '@rust/kcl-lib/bindings/Artifact' -export type { Plane as PlaneArtifact } from '@rust/kcl-lib/bindings/Artifact' -export type { Segment as SegmentArtifact } from '@rust/kcl-lib/bindings/Artifact' -export type { Solid2d as Solid2dArtifact } from '@rust/kcl-lib/bindings/Artifact' -export type { Sweep as SweepArtifact } from '@rust/kcl-lib/bindings/Artifact' -export type { SweepEdge } from '@rust/kcl-lib/bindings/Artifact' -export type { Wall as WallArtifact } from '@rust/kcl-lib/bindings/Artifact' -export type { Configuration } from '@rust/kcl-lib/bindings/Configuration' -export type { Program } from '@rust/kcl-lib/bindings/Program' -export type { Expr } from '@rust/kcl-lib/bindings/Expr' -export type { ObjectExpression } from '@rust/kcl-lib/bindings/ObjectExpression' -export type { ObjectProperty } from '@rust/kcl-lib/bindings/ObjectProperty' -export type { MemberExpression } from '@rust/kcl-lib/bindings/MemberExpression' -export type { PipeExpression } from '@rust/kcl-lib/bindings/PipeExpression' -export type { VariableDeclaration } from '@rust/kcl-lib/bindings/VariableDeclaration' -export type { Parameter } from '@rust/kcl-lib/bindings/Parameter' -export type { PipeSubstitution } from '@rust/kcl-lib/bindings/PipeSubstitution' -export type { Identifier } from '@rust/kcl-lib/bindings/Identifier' -export type { Name } from '@rust/kcl-lib/bindings/Name' -export type { UnaryExpression } from '@rust/kcl-lib/bindings/UnaryExpression' +export type { ArrayExpression } from '@rust/kcl-lib/bindings/ArrayExpression' +export type { + Artifact, + ArtifactCommand, + ArtifactId, + Cap as CapArtifact, + CodeRef, + EdgeCut, + Path as PathArtifact, + Plane as PlaneArtifact, + Segment as SegmentArtifact, + Solid2d as Solid2dArtifact, + Sweep as SweepArtifact, + SweepEdge, + Wall as WallArtifact, +} from '@rust/kcl-lib/bindings/Artifact' export type { BinaryExpression } from '@rust/kcl-lib/bindings/BinaryExpression' -export type { ReturnStatement } from '@rust/kcl-lib/bindings/ReturnStatement' -export type { ExpressionStatement } from '@rust/kcl-lib/bindings/ExpressionStatement' +export type { BinaryPart } from '@rust/kcl-lib/bindings/BinaryPart' export type { CallExpression } from '@rust/kcl-lib/bindings/CallExpression' export type { CallExpressionKw } from '@rust/kcl-lib/bindings/CallExpressionKw' +export type { Configuration } from '@rust/kcl-lib/bindings/Configuration' +export type { Expr } from '@rust/kcl-lib/bindings/Expr' +export type { ExpressionStatement } from '@rust/kcl-lib/bindings/ExpressionStatement' +export type { Identifier } from '@rust/kcl-lib/bindings/Identifier' export type { LabeledArg } from '@rust/kcl-lib/bindings/LabeledArg' -export type { VariableDeclarator } from '@rust/kcl-lib/bindings/VariableDeclarator' -export type { BinaryPart } from '@rust/kcl-lib/bindings/BinaryPart' export type { Literal } from '@rust/kcl-lib/bindings/Literal' export type { LiteralValue } from '@rust/kcl-lib/bindings/LiteralValue' -export type { ArrayExpression } from '@rust/kcl-lib/bindings/ArrayExpression' -export type { SourceRange } from '@rust/kcl-lib/bindings/SourceRange' +export type { MemberExpression } from '@rust/kcl-lib/bindings/MemberExpression' +export type { Name } from '@rust/kcl-lib/bindings/Name' export type { NumericSuffix } from '@rust/kcl-lib/bindings/NumericSuffix' +export type { ObjectExpression } from '@rust/kcl-lib/bindings/ObjectExpression' +export type { ObjectProperty } from '@rust/kcl-lib/bindings/ObjectProperty' +export type { Parameter } from '@rust/kcl-lib/bindings/Parameter' +export type { PipeExpression } from '@rust/kcl-lib/bindings/PipeExpression' +export type { PipeSubstitution } from '@rust/kcl-lib/bindings/PipeSubstitution' +export type { Program } from '@rust/kcl-lib/bindings/Program' +export type { ReturnStatement } from '@rust/kcl-lib/bindings/ReturnStatement' +export type { SourceRange } from '@rust/kcl-lib/bindings/SourceRange' +export type { UnaryExpression } from '@rust/kcl-lib/bindings/UnaryExpression' +export type { VariableDeclaration } from '@rust/kcl-lib/bindings/VariableDeclaration' +export type { VariableDeclarator } from '@rust/kcl-lib/bindings/VariableDeclarator' export type SyntaxType = | 'Program' @@ -123,11 +128,11 @@ export type SyntaxType = | 'NonCodeNode' | 'UnaryExpression' +export type { ExtrudeSurface } from '@rust/kcl-lib/bindings/ExtrudeSurface' +export type { KclValue } from '@rust/kcl-lib/bindings/KclValue' export type { Path } from '@rust/kcl-lib/bindings/Path' export type { Sketch } from '@rust/kcl-lib/bindings/Sketch' export type { Solid } from '@rust/kcl-lib/bindings/Solid' -export type { KclValue } from '@rust/kcl-lib/bindings/KclValue' -export type { ExtrudeSurface } from '@rust/kcl-lib/bindings/ExtrudeSurface' /** * Convert a SourceRange as used inside the KCL interpreter into the above one for use in the @@ -146,21 +151,6 @@ export function defaultSourceRange(): SourceRange { return [0, 0, 0] } -/** - * Create a SourceRange for the top-level module. - */ -export function topLevelRange(start: number, end: number): SourceRange { - return [start, end, 0] -} - -/** - * Returns true if this source range is from the file being executed. Returns - * false if it's from a file that was imported. - */ -export function isTopLevelModule(range: SourceRange): boolean { - return range[2] === 0 -} - function firstSourceRange(error: RustKclError): SourceRange { return error.sourceRanges.length > 0 ? sourceRangeFromRust(error.sourceRanges[0]) @@ -384,10 +374,6 @@ function rustArtifactGraphToMap( return map } -export function defaultArtifactGraph(): ArtifactGraph { - return new Map() -} - // TODO: In the future, make the parameter be a KclValue. export function sketchFromKclValueOptional( obj: any, @@ -422,19 +408,6 @@ export function sketchFromKclValue( return result } -export const jsAppSettings = async () => { - let jsAppSettings = default_app_settings() - if (!TEST) { - const settings = await import('machines/appMachine').then((module) => - module.getSettings() - ) - if (settings) { - jsAppSettings = getAllCurrentSettings(settings) - } - } - return jsAppSettings -} - export const errFromErrWithOutputs = (e: any): KCLError => { const parsed: KclErrorWithOutputs = JSON.parse(e.toString()) return new KCLError( diff --git a/src/lib/artifactIndex.ts b/src/lib/artifactIndex.ts index 19cb92b8a..e9d582e8b 100644 --- a/src/lib/artifactIndex.ts +++ b/src/lib/artifactIndex.ts @@ -1,5 +1,10 @@ -import { ArtifactGraph, ArtifactId, SourceRange, Artifact } from 'lang/wasm' -import { getFaceCodeRef } from 'lang/std/artifactGraph' +import { getFaceCodeRef } from '@src/lang/std/artifactGraph' +import type { + Artifact, + ArtifactGraph, + ArtifactId, + SourceRange, +} from '@src/lang/wasm' // Index artifacts in an ordered list for binary search export type ArtifactEntry = { artifact: Artifact; id: ArtifactId } diff --git a/src/lib/base64.test.ts b/src/lib/base64.test.ts index edb7db9d2..d33281931 100644 --- a/src/lib/base64.test.ts +++ b/src/lib/base64.test.ts @@ -1,5 +1,6 @@ import { expect } from 'vitest' -import { base64ToString, stringToBase64 } from './base64' + +import { base64ToString, stringToBase64 } from '@src/lib/base64' describe('base64 encoding', () => { test('to base64, simple code', async () => { diff --git a/src/lib/browserSaveFile.ts b/src/lib/browserSaveFile.ts index 73004d695..33a347656 100644 --- a/src/lib/browserSaveFile.ts +++ b/src/lib/browserSaveFile.ts @@ -1,9 +1,9 @@ /// The method below uses the File System Access API when it's supported and // else falls back to the classic approach. In both cases the function saves // the file, but in case of where the File System Access API is supported, the - import toast from 'react-hot-toast' -import { EXPORT_TOAST_MESSAGES } from './constants' + +import { EXPORT_TOAST_MESSAGES } from '@src/lib/constants' // user will get a file save dialog where they can choose where the file should be saved. export const browserSaveFile = async ( diff --git a/src/lib/cameraControls.ts b/src/lib/cameraControls.ts index e102ee9f4..1a8f7fc53 100644 --- a/src/lib/cameraControls.ts +++ b/src/lib/cameraControls.ts @@ -1,5 +1,6 @@ -import { MouseControlType } from '@rust/kcl-lib/bindings/MouseControlType' -import { platform } from './utils' +import type { MouseControlType } from '@rust/kcl-lib/bindings/MouseControlType' + +import { platform } from '@src/lib/utils' const PLATFORM = platform() const META = diff --git a/src/lib/commandBarConfigs/authCommandConfig.ts b/src/lib/commandBarConfigs/authCommandConfig.ts index 1f77434ae..0417d973d 100644 --- a/src/lib/commandBarConfigs/authCommandConfig.ts +++ b/src/lib/commandBarConfigs/authCommandConfig.ts @@ -1,6 +1,6 @@ -import { Command } from 'lib/commandTypes' -import { authActor } from 'machines/appMachine' -import { ACTOR_IDS } from 'machines/machineConstants' +import type { Command } from '@src/lib/commandTypes' +import { authActor } from '@src/machines/appMachine' +import { ACTOR_IDS } from '@src/machines/machineConstants' export const authCommands: Command[] = [ { diff --git a/src/lib/commandBarConfigs/modelingCommandConfig.ts b/src/lib/commandBarConfigs/modelingCommandConfig.ts index 4e8cebf8d..edfb0c0ce 100644 --- a/src/lib/commandBarConfigs/modelingCommandConfig.ts +++ b/src/lib/commandBarConfigs/modelingCommandConfig.ts @@ -1,30 +1,34 @@ -import { Models } from '@kittycad/lib' -import { angleLengthInfo } from 'components/Toolbar/setAngleLength' -import { transformAstSketchLines } from 'lang/std/sketchcombos' -import { - isPathToNode, +import type { Models } from '@kittycad/lib' +import { DEV } from '@src/env' + +import { angleLengthInfo } from '@src/components/Toolbar/setAngleLength' +import { getNodeFromPath } from '@src/lang/queryAst' +import { getVariableDeclaration } from '@src/lang/queryAst/getVariableDeclaration' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import { transformAstSketchLines } from '@src/lang/std/sketchcombos' +import type { PathToNode, SourceRange, VariableDeclarator, -} from 'lang/wasm' -import { StateMachineCommandSetConfig, KclCommandValue } from 'lib/commandTypes' -import { KCL_DEFAULT_LENGTH, KCL_DEFAULT_DEGREE } from 'lib/constants' -import { components } from 'lib/machine-api' -import { Selections } from 'lib/selections' -import { codeManager, kclManager } from 'lib/singletons' -import { err } from 'lib/trap' -import { modelingMachine, SketchTool } from 'machines/modelingMachine' +} from '@src/lang/wasm' +import { isPathToNode } from '@src/lang/wasm' import { loftValidator, revolveAxisValidator, shellValidator, sweepValidator, -} from './validators' -import { getVariableDeclaration } from 'lang/queryAst/getVariableDeclaration' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { getNodeFromPath } from 'lang/queryAst' -import { IS_NIGHTLY_OR_DEBUG } from 'routes/Settings' -import { DEV } from 'env' +} from '@src/lib/commandBarConfigs/validators' +import type { + KclCommandValue, + StateMachineCommandSetConfig, +} from '@src/lib/commandTypes' +import { KCL_DEFAULT_DEGREE, KCL_DEFAULT_LENGTH } from '@src/lib/constants' +import type { components } from '@src/lib/machine-api' +import type { Selections } from '@src/lib/selections' +import { codeManager, kclManager } from '@src/lib/singletons' +import { err } from '@src/lib/trap' +import type { SketchTool, modelingMachine } from '@src/machines/modelingMachine' +import { IS_NIGHTLY_OR_DEBUG } from '@src/routes/Settings' type OutputFormat = Models['OutputFormat3d_type'] type OutputTypeKey = OutputFormat['type'] diff --git a/src/lib/commandBarConfigs/namedViewsConfig.ts b/src/lib/commandBarConfigs/namedViewsConfig.ts index d758ecb39..de0822067 100644 --- a/src/lib/commandBarConfigs/namedViewsConfig.ts +++ b/src/lib/commandBarConfigs/namedViewsConfig.ts @@ -1,16 +1,18 @@ -import { NamedView } from '@rust/kcl-lib/bindings/NamedView' -import { Command, CommandArgumentOption } from '../commandTypes' -import toast from 'react-hot-toast' -import { engineCommandManager } from 'lib/singletons' -import { uuidv4 } from 'lib/utils' -import { settingsActor, getSettings } from 'machines/appMachine' -import { err, reportRejection } from 'lib/trap' -import { +import type { CameraViewState_type, Point3d_type, Point4d_type, WorldCoordinateSystem_type, } from '@kittycad/lib/dist/types/src/models' +import toast from 'react-hot-toast' + +import type { NamedView } from '@rust/kcl-lib/bindings/NamedView' + +import type { Command, CommandArgumentOption } from '@src/lib/commandTypes' +import { engineCommandManager } from '@src/lib/singletons' +import { err, reportRejection } from '@src/lib/trap' +import { uuidv4 } from '@src/lib/utils' +import { getSettings, settingsActor } from '@src/machines/appMachine' function isWorldCoordinateSystemType( x: string diff --git a/src/lib/commandBarConfigs/projectsCommandConfig.ts b/src/lib/commandBarConfigs/projectsCommandConfig.ts index 3b82ddc1f..bc6b4a7bb 100644 --- a/src/lib/commandBarConfigs/projectsCommandConfig.ts +++ b/src/lib/commandBarConfigs/projectsCommandConfig.ts @@ -1,7 +1,7 @@ -import { CommandBarOverwriteWarning } from 'components/CommandBarOverwriteWarning' -import { StateMachineCommandSetConfig } from 'lib/commandTypes' -import { isDesktop } from 'lib/isDesktop' -import { projectsMachine } from 'machines/projectsMachine' +import { CommandBarOverwriteWarning } from '@src/components/CommandBarOverwriteWarning' +import type { StateMachineCommandSetConfig } from '@src/lib/commandTypes' +import { isDesktop } from '@src/lib/isDesktop' +import type { projectsMachine } from '@src/machines/projectsMachine' export type ProjectsCommandSchema = { 'Read projects': Record diff --git a/src/lib/commandBarConfigs/routeCommandConfig.ts b/src/lib/commandBarConfigs/routeCommandConfig.ts index 4c058137d..0dbc38d72 100644 --- a/src/lib/commandBarConfigs/routeCommandConfig.ts +++ b/src/lib/commandBarConfigs/routeCommandConfig.ts @@ -1,6 +1,8 @@ -import { Command } from '../commandTypes' -import { PATHS } from 'lib/paths' -import { NavigateFunction, Location } from 'react-router-dom' +import type { Location, NavigateFunction } from 'react-router-dom' + +import type { Command } from '@src/lib/commandTypes' +import { PATHS } from '@src/lib/paths' + export function createRouteCommands( navigate: NavigateFunction, location: Location, diff --git a/src/lib/commandBarConfigs/settingsCommandConfig.ts b/src/lib/commandBarConfigs/settingsCommandConfig.ts index a79b4a29f..4b2adb99d 100644 --- a/src/lib/commandBarConfigs/settingsCommandConfig.ts +++ b/src/lib/commandBarConfigs/settingsCommandConfig.ts @@ -1,26 +1,27 @@ -import { +import decamelize from 'decamelize' +import type { ActorRefFrom, AnyStateMachine } from 'xstate' + +import type { Command, CommandArgument, CommandArgumentConfig, -} from '../commandTypes' -import { - SettingsPaths, - SettingsLevel, - SettingProps, - SetEventTypes, -} from 'lib/settings/settingsTypes' -import { settingsMachine } from 'machines/settingsMachine' -import { PathValue } from 'lib/types' -import { ActorRefFrom, AnyStateMachine } from 'xstate' -import { getPropertyByPath } from 'lib/objectPropertyByPath' -import { buildCommandArgument } from 'lib/createMachineCommand' -import decamelize from 'decamelize' -import { isDesktop } from 'lib/isDesktop' -import { - createSettings, +} from '@src/lib/commandTypes' +import { buildCommandArgument } from '@src/lib/createMachineCommand' +import { isDesktop } from '@src/lib/isDesktop' +import { getPropertyByPath } from '@src/lib/objectPropertyByPath' +import type { Setting, SettingsType, -} from 'lib/settings/initialSettings' + createSettings, +} from '@src/lib/settings/initialSettings' +import type { + SetEventTypes, + SettingProps, + SettingsLevel, + SettingsPaths, +} from '@src/lib/settings/settingsTypes' +import type { PathValue } from '@src/lib/types' +import type { settingsMachine } from '@src/machines/settingsMachine' // An array of the paths to all of the settings that have commandConfigs export const settingsWithCommandConfigs = (s: SettingsType) => diff --git a/src/lib/commandBarConfigs/validators.test.ts b/src/lib/commandBarConfigs/validators.test.ts index 4862ab5a6..977a3aca4 100644 --- a/src/lib/commandBarConfigs/validators.test.ts +++ b/src/lib/commandBarConfigs/validators.test.ts @@ -1,4 +1,4 @@ -import { parseEngineErrorMessage } from './validators' +import { parseEngineErrorMessage } from '@src/lib/commandBarConfigs/validators' describe('parseEngineErrorMessage', () => { it('takes an engine error string and parses its json message', () => { diff --git a/src/lib/commandBarConfigs/validators.ts b/src/lib/commandBarConfigs/validators.ts index b199ced47..87be89757 100644 --- a/src/lib/commandBarConfigs/validators.ts +++ b/src/lib/commandBarConfigs/validators.ts @@ -1,9 +1,10 @@ -import { Models } from '@kittycad/lib' -import { engineCommandManager, kclManager } from 'lib/singletons' -import { uuidv4 } from 'lib/utils' -import { CommandBarContext } from 'machines/commandBarMachine' -import { Selections } from 'lib/selections' -import { ApiError_type } from '@kittycad/lib/dist/types/src/models' +import type { Models } from '@kittycad/lib' +import type { ApiError_type } from '@kittycad/lib/dist/types/src/models' + +import type { Selections } from '@src/lib/selections' +import { engineCommandManager, kclManager } from '@src/lib/singletons' +import { uuidv4 } from '@src/lib/utils' +import type { CommandBarContext } from '@src/machines/commandBarMachine' export const disableDryRunWithRetry = async (numberOfRetries = 3) => { for (let tries = 0; tries < numberOfRetries; tries++) { diff --git a/src/lib/commandTypes.ts b/src/lib/commandTypes.ts index 026b00865..61dd6d691 100644 --- a/src/lib/commandTypes.ts +++ b/src/lib/commandTypes.ts @@ -1,14 +1,18 @@ -import { CustomIconName } from 'components/CustomIcon' -import { AllMachines } from 'hooks/useStateMachineCommands' -import { Actor, AnyStateMachine, ContextFrom, EventFrom } from 'xstate' -import { Expr, Name, VariableDeclaration } from 'lang/wasm' -import { commandBarMachine } from 'machines/commandBarMachine' -import { ReactNode } from 'react' -import { MachineManager } from 'components/MachineManagerProvider' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { Artifact } from 'lang/std/artifactGraph' -import { CommandBarContext } from 'machines/commandBarMachine' -import { EntityType_type } from '@kittycad/lib/dist/types/src/models' +import type { EntityType_type } from '@kittycad/lib/dist/types/src/models' +import type { ReactNode } from 'react' +import type { Actor, AnyStateMachine, ContextFrom, EventFrom } from 'xstate' + +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import type { CustomIconName } from '@src/components/CustomIcon' +import type { MachineManager } from '@src/components/MachineManagerProvider' +import type { AllMachines } from '@src/hooks/useStateMachineCommands' +import type { Artifact } from '@src/lang/std/artifactGraph' +import type { Expr, Name, VariableDeclaration } from '@src/lang/wasm' +import type { + CommandBarContext, + commandBarMachine, +} from '@src/machines/commandBarMachine' type Icon = CustomIconName const _PLATFORMS = ['both', 'web', 'desktop'] as const @@ -43,7 +47,7 @@ export type StateMachineCommandSetSchema = Partial<{ export type StateMachineCommandSet< T extends AllMachines, - Schema extends StateMachineCommandSetSchema + Schema extends StateMachineCommandSetSchema, > = Partial<{ [EventType in EventFrom['type']]: Command< T, @@ -60,7 +64,7 @@ export type StateMachineCommandSet< */ export type StateMachineCommandSetConfig< T extends AllMachines, - Schema extends StateMachineCommandSetSchema + Schema extends StateMachineCommandSetSchema, > = Partial<{ [EventType in EventFrom['type']]: | CommandConfig['type'], Schema[EventType]> @@ -70,7 +74,8 @@ export type StateMachineCommandSetConfig< export type Command< T extends AnyStateMachine = AnyStateMachine, CommandName extends EventFrom['type'] = EventFrom['type'], - CommandSchema extends StateMachineCommandSetSchema[CommandName] = StateMachineCommandSetSchema[CommandName] + CommandSchema extends + StateMachineCommandSetSchema[CommandName] = StateMachineCommandSetSchema[CommandName], > = { name: CommandName groupId: T['id'] @@ -96,7 +101,8 @@ export type Command< export type CommandConfig< T extends AnyStateMachine = AnyStateMachine, CommandName extends EventFrom['type'] = EventFrom['type'], - CommandSchema extends StateMachineCommandSetSchema[CommandName] = StateMachineCommandSetSchema[CommandName] + CommandSchema extends + StateMachineCommandSetSchema[CommandName] = StateMachineCommandSetSchema[CommandName], > = Omit< Command, 'name' | 'groupId' | 'onSubmit' | 'onCancel' | 'args' | 'needsReview' @@ -113,7 +119,7 @@ export type CommandConfig< export type CommandArgumentConfig< OutputType, - C = ContextFrom + C = ContextFrom, > = { displayName?: string description?: string @@ -239,7 +245,7 @@ export type CommandArgumentConfig< export type CommandArgument< OutputType, - T extends AnyStateMachine = AnyStateMachine + T extends AnyStateMachine = AnyStateMachine, > = { displayName?: string description?: string @@ -360,7 +366,7 @@ export type CommandArgument< export type CommandArgumentWithName< OutputType, - T extends AnyStateMachine = AnyStateMachine + T extends AnyStateMachine = AnyStateMachine, > = CommandArgument & { name: string } diff --git a/src/lib/commandUtils.test.ts b/src/lib/commandUtils.test.ts index 85d45bbad..abb7ef8c4 100644 --- a/src/lib/commandUtils.test.ts +++ b/src/lib/commandUtils.test.ts @@ -1,4 +1,5 @@ -import { CommandWithDisabledState, sortCommands } from './commandUtils' +import type { CommandWithDisabledState } from '@src/lib/commandUtils' +import { sortCommands } from '@src/lib/commandUtils' function commandWithDisabled( name: string, diff --git a/src/lib/commandUtils.ts b/src/lib/commandUtils.ts index ec7bdb59d..7c75f9d45 100644 --- a/src/lib/commandUtils.ts +++ b/src/lib/commandUtils.ts @@ -2,8 +2,7 @@ // That object also contains some metadata about what to do with the KCL expression, // such as whether we need to create a new variable for it. // This function extracts the value field from those arg payloads and returns - -import { Command } from './commandTypes' +import type { Command } from '@src/lib/commandTypes' // The arg object with all its field as natural values that the command to be executed will expect. export function getCommandArgumentKclValuesOnly(args: Record) { diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 3731990b0..d6c3b1940 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -1,5 +1,6 @@ -import { Models } from '@kittycad/lib/dist/types/src' -import { UnitAngle, UnitLength } from '@rust/kcl-lib/bindings/ModelingCmd' +import type { Models } from '@kittycad/lib/dist/types/src' + +import type { UnitAngle, UnitLength } from '@rust/kcl-lib/bindings/ModelingCmd' export const APP_NAME = 'Modeling App' /** Search string in new project names to increment as an index */ diff --git a/src/lib/coredump.ts b/src/lib/coredump.ts index 326cd4871..384aa53b4 100644 --- a/src/lib/coredump.ts +++ b/src/lib/coredump.ts @@ -1,13 +1,18 @@ -import { CommandLog, EngineCommandManager } from 'lang/std/engineConnection' -import { WebrtcStats } from '@rust/kcl-lib/bindings/WebrtcStats' -import { OsInfo } from '@rust/kcl-lib/bindings/OsInfo' -import { isDesktop } from 'lib/isDesktop' -import { APP_VERSION } from 'routes/Settings' +import { VITE_KC_API_BASE_URL } from '@src/env' import { UAParser } from 'ua-parser-js' -import screenshot from 'lib/screenshot' -import { VITE_KC_API_BASE_URL } from 'env' -import CodeManager from 'lang/codeManager' -import RustContext from 'lib/rustContext' + +import type { OsInfo } from '@rust/kcl-lib/bindings/OsInfo' +import type { WebrtcStats } from '@rust/kcl-lib/bindings/WebrtcStats' + +import type CodeManager from '@src/lang/codeManager' +import type { + CommandLog, + EngineCommandManager, +} from '@src/lang/std/engineConnection' +import { isDesktop } from '@src/lib/isDesktop' +import type RustContext from '@src/lib/rustContext' +import screenshot from '@src/lib/screenshot' +import { APP_VERSION } from '@src/routes/Settings' /* eslint-disable suggest-no-throw/suggest-no-throw -- * All the throws in CoreDumpManager are intentional and should be caught and handled properly diff --git a/src/lib/createMachineCommand.ts b/src/lib/createMachineCommand.ts index 3e0595980..501ffd5ab 100644 --- a/src/lib/createMachineCommand.ts +++ b/src/lib/createMachineCommand.ts @@ -1,25 +1,26 @@ -import { +import { DEV } from '@src/env' +import type { + Actor, AnyStateMachine, ContextFrom, EventFrom, - Actor, StateFrom, } from 'xstate' -import { isDesktop } from './isDesktop' -import { + +import type { Command, CommandArgument, CommandArgumentConfig, CommandConfig, StateMachineCommandSetConfig, StateMachineCommandSetSchema, -} from './commandTypes' -import { DEV } from 'env' -import { IS_NIGHTLY_OR_DEBUG } from 'routes/Settings' +} from '@src/lib/commandTypes' +import { isDesktop } from '@src/lib/isDesktop' +import { IS_NIGHTLY_OR_DEBUG } from '@src/routes/Settings' interface CreateMachineCommandProps< T extends AnyStateMachine, - S extends StateMachineCommandSetSchema + S extends StateMachineCommandSetSchema, > { type: EventFrom['type'] groupId: T['id'] @@ -34,7 +35,7 @@ interface CreateMachineCommandProps< // from a more terse Command Bar Meta definition. export function createMachineCommand< T extends AnyStateMachine, - S extends StateMachineCommandSetSchema + S extends StateMachineCommandSetSchema, >({ groupId, type, @@ -132,7 +133,7 @@ export function createMachineCommand< function buildCommandArguments< T extends AnyStateMachine, S extends StateMachineCommandSetSchema, - CommandName extends EventFrom['type'] = EventFrom['type'] + CommandName extends EventFrom['type'] = EventFrom['type'], >( state: StateFrom, args: CommandConfig['args'], @@ -151,7 +152,7 @@ function buildCommandArguments< export function buildCommandArgument< T extends AnyStateMachine, - O extends StateMachineCommandSetSchema = StateMachineCommandSetSchema + O extends StateMachineCommandSetSchema = StateMachineCommandSetSchema, >( arg: CommandArgumentConfig, context: ContextFrom, diff --git a/src/lib/crossPlatformFetch.ts b/src/lib/crossPlatformFetch.ts index 7baaa63bc..28247442d 100644 --- a/src/lib/crossPlatformFetch.ts +++ b/src/lib/crossPlatformFetch.ts @@ -1,7 +1,8 @@ -import { DEV } from 'env' -import { isDesktop } from 'lib/isDesktop' +import { DEV } from '@src/env' import isomorphicFetch from 'isomorphic-fetch' +import { isDesktop } from '@src/lib/isDesktop' + // TODO I not sure this file should exist const headers = (token?: string): HeadersInit => ({ diff --git a/src/lib/desktop.test.ts b/src/lib/desktop.test.ts index 2868ceb10..bcb415f9a 100644 --- a/src/lib/desktop.test.ts +++ b/src/lib/desktop.test.ts @@ -1,7 +1,9 @@ -import { vi, describe, it, expect, beforeEach } from 'vitest' -import { listProjects } from './desktop' -import { DeepPartial } from './types' -import { Configuration } from '@rust/kcl-lib/bindings/Configuration' +import { beforeEach, describe, expect, it, vi } from 'vitest' + +import type { Configuration } from '@rust/kcl-lib/bindings/Configuration' + +import { listProjects } from '@src/lib/desktop' +import type { DeepPartial } from '@src/lib/types' // Mock the electron window global const mockElectron = { diff --git a/src/lib/desktop.ts b/src/lib/desktop.ts index a63a26d7c..bb69f170d 100644 --- a/src/lib/desktop.ts +++ b/src/lib/desktop.ts @@ -1,13 +1,15 @@ -import { err } from 'lib/trap' -import { Models } from '@kittycad/lib' -import { Project, FileEntry } from 'lib/project' +import type { Models } from '@kittycad/lib' +import type { Configuration } from '@rust/kcl-lib/bindings/Configuration' +import type { ProjectConfiguration } from '@rust/kcl-lib/bindings/ProjectConfiguration' + +import { newKclFile } from '@src/lang/project' import { defaultAppSettings, initPromise, parseAppSettings, parseProjectSettings, -} from 'lang/wasm' +} from '@src/lang/wasm' import { DEFAULT_DEFAULT_LENGTH_UNIT, PROJECT_ENTRYPOINT, @@ -18,11 +20,10 @@ import { TELEMETRY_FILE_NAME, TELEMETRY_RAW_FILE_NAME, TOKEN_FILE_NAME, -} from './constants' -import { DeepPartial } from './types' -import { ProjectConfiguration } from '@rust/kcl-lib/bindings/ProjectConfiguration' -import { Configuration } from '@rust/kcl-lib/bindings/Configuration' -import { newKclFile } from 'lang/project' +} from '@src/lib/constants' +import type { FileEntry, Project } from '@src/lib/project' +import { err } from '@src/lib/trap' +import type { DeepPartial } from '@src/lib/types' export async function renameProjectDirectory( projectPath: string, diff --git a/src/lib/desktopFS.test.ts b/src/lib/desktopFS.test.ts index a590c64f5..d8032e81f 100644 --- a/src/lib/desktopFS.test.ts +++ b/src/lib/desktopFS.test.ts @@ -1,5 +1,5 @@ -import { getUniqueProjectName } from './desktopFS' -import { FileEntry } from './project' +import { getUniqueProjectName } from '@src/lib/desktopFS' +import type { FileEntry } from '@src/lib/project' /** Create a dummy project */ function project(name: string, children?: FileEntry[]): FileEntry { diff --git a/src/lib/desktopFS.ts b/src/lib/desktopFS.ts index e7b9bf1df..1a4a13b54 100644 --- a/src/lib/desktopFS.ts +++ b/src/lib/desktopFS.ts @@ -1,18 +1,18 @@ -import { isDesktop } from './isDesktop' -import type { FileEntry } from 'lib/project' import { FILE_EXT, INDEX_IDENTIFIER, MAX_PADDING, ONBOARDING_PROJECT_NAME, -} from 'lib/constants' -import { bracket } from './exampleKcl' -import { PATHS } from './paths' +} from '@src/lib/constants' import { createNewProjectDirectory, listProjects, readAppSettingsFile, -} from './desktop' +} from '@src/lib/desktop' +import { bracket } from '@src/lib/exampleKcl' +import { isDesktop } from '@src/lib/isDesktop' +import { PATHS } from '@src/lib/paths' +import type { FileEntry } from '@src/lib/project' export const isHidden = (fileOrDir: FileEntry) => !!fileOrDir.name?.startsWith('.') diff --git a/src/lib/exceptions.ts b/src/lib/exceptions.ts index d72075221..e80f7c0ce 100644 --- a/src/lib/exceptions.ts +++ b/src/lib/exceptions.ts @@ -1,7 +1,8 @@ -import { kclManager } from 'lib/singletons' -import { reloadModule, getModule } from 'lib/wasm_lib_wrapper' import toast from 'react-hot-toast' -import { reportRejection } from './trap' + +import { kclManager } from '@src/lib/singletons' +import { reportRejection } from '@src/lib/trap' +import { getModule, reloadModule } from '@src/lib/wasm_lib_wrapper' let initialized = false diff --git a/src/lib/exportMake.ts b/src/lib/exportMake.ts index 14ba4fe46..46b366c10 100644 --- a/src/lib/exportMake.ts +++ b/src/lib/exportMake.ts @@ -1,8 +1,9 @@ -import { MachineManager } from 'components/MachineManagerProvider' import toast from 'react-hot-toast' -import { components } from './machine-api' -import ModelingAppFile from './modelingAppFile' -import { MAKE_TOAST_MESSAGES } from './constants' + +import type { MachineManager } from '@src/components/MachineManagerProvider' +import { MAKE_TOAST_MESSAGES } from '@src/lib/constants' +import type { components } from '@src/lib/machine-api' +import type ModelingAppFile from '@src/lib/modelingAppFile' // Make files locally from an export call. export async function exportMake({ diff --git a/src/lib/exportSave.ts b/src/lib/exportSave.ts index 43683e6da..a239395f5 100644 --- a/src/lib/exportSave.ts +++ b/src/lib/exportSave.ts @@ -1,10 +1,10 @@ -import { isDesktop } from './isDesktop' -import { browserSaveFile } from './browserSaveFile' - import JSZip from 'jszip' -import ModelingAppFile from './modelingAppFile' import toast from 'react-hot-toast' -import { EXPORT_TOAST_MESSAGES } from './constants' + +import { browserSaveFile } from '@src/lib/browserSaveFile' +import { EXPORT_TOAST_MESSAGES } from '@src/lib/constants' +import { isDesktop } from '@src/lib/isDesktop' +import type ModelingAppFile from '@src/lib/modelingAppFile' const save_ = async (file: ModelingAppFile, toastId: string) => { try { diff --git a/src/lib/getCurrentProjectFile.test.ts b/src/lib/getCurrentProjectFile.test.ts index 78b0cea52..10221bf41 100644 --- a/src/lib/getCurrentProjectFile.test.ts +++ b/src/lib/getCurrentProjectFile.test.ts @@ -1,8 +1,9 @@ import { promises as fs } from 'fs' -import path from 'path' import os from 'os' +import path from 'path' import { v4 as uuidv4 } from 'uuid' -import getCurrentProjectFile from './getCurrentProjectFile' + +import getCurrentProjectFile from '@src/lib/getCurrentProjectFile' describe('getCurrentProjectFile', () => { test('with explicit open file with space (URL encoded)', async () => { diff --git a/src/lib/getCurrentProjectFile.ts b/src/lib/getCurrentProjectFile.ts index d3638cb26..10235d802 100644 --- a/src/lib/getCurrentProjectFile.ts +++ b/src/lib/getCurrentProjectFile.ts @@ -1,8 +1,9 @@ -import * as path from 'path' +import type { Models } from '@kittycad/lib/dist/types/src' +import type { Stats } from 'fs' import * as fs from 'fs/promises' -import { Stats } from 'fs' -import { Models } from '@kittycad/lib/dist/types/src' -import { PROJECT_ENTRYPOINT } from './constants' +import * as path from 'path' + +import { PROJECT_ENTRYPOINT } from '@src/lib/constants' // Create a const object with the values const FILE_IMPORT_FORMATS = { diff --git a/src/lib/getKclSamplesManifest.ts b/src/lib/getKclSamplesManifest.ts index b03e922a2..3c7347ddf 100644 --- a/src/lib/getKclSamplesManifest.ts +++ b/src/lib/getKclSamplesManifest.ts @@ -1,5 +1,5 @@ -import { KCL_SAMPLES_MANIFEST_URL } from './constants' -import { isDesktop } from './isDesktop' +import { KCL_SAMPLES_MANIFEST_URL } from '@src/lib/constants' +import { isDesktop } from '@src/lib/isDesktop' export type KclSamplesManifestItem = { file: string diff --git a/src/lib/hotkeyWrapper.test.ts b/src/lib/hotkeyWrapper.test.ts index df15f8af5..a3e082df3 100644 --- a/src/lib/hotkeyWrapper.test.ts +++ b/src/lib/hotkeyWrapper.test.ts @@ -1,4 +1,4 @@ -import { hotkeyDisplay } from './hotkeyWrapper' +import { hotkeyDisplay } from '@src/lib/hotkeyWrapper' describe('hotkeyDisplay', () => { it('displays mod', async () => { diff --git a/src/lib/hotkeyWrapper.ts b/src/lib/hotkeyWrapper.ts index ce5bf747e..a270246d2 100644 --- a/src/lib/hotkeyWrapper.ts +++ b/src/lib/hotkeyWrapper.ts @@ -1,7 +1,9 @@ -import { Options, useHotkeys } from 'react-hotkeys-hook' import { useEffect } from 'react' -import { codeManager } from './singletons' -import { Platform } from './utils' +import type { Options } from 'react-hotkeys-hook' +import { useHotkeys } from 'react-hotkeys-hook' + +import { codeManager } from '@src/lib/singletons' +import type { Platform } from '@src/lib/utils' // Hotkey wrapper wraps hotkeys for the app (outside of the editor) // with hotkeys inside the editor. diff --git a/src/lib/kclCommands.ts b/src/lib/kclCommands.ts index 923c24202..41afa5524 100644 --- a/src/lib/kclCommands.ts +++ b/src/lib/kclCommands.ts @@ -1,23 +1,24 @@ -import { CommandBarOverwriteWarning } from 'components/CommandBarOverwriteWarning' -import { Command, CommandArgumentOption } from './commandTypes' -import { codeManager, kclManager } from './singletons' -import { isDesktop } from './isDesktop' +import type { UnitLength_type } from '@kittycad/lib/dist/types/src/models' +import toast from 'react-hot-toast' + +import { CommandBarOverwriteWarning } from '@src/components/CommandBarOverwriteWarning' +import { + changeKclSettings, + unitAngleToUnitAng, + unitLengthToUnitLen, +} from '@src/lang/wasm' +import type { Command, CommandArgumentOption } from '@src/lib/commandTypes' import { DEFAULT_DEFAULT_ANGLE_UNIT, DEFAULT_DEFAULT_LENGTH_UNIT, FILE_EXT, -} from './constants' -import { UnitLength_type } from '@kittycad/lib/dist/types/src/models' -import { err, reportRejection } from './trap' -import { IndexLoaderData } from './types' -import { copyFileShareLink } from './links' -import { baseUnitsUnion } from './settings/settingsTypes' -import toast from 'react-hot-toast' -import { - changeKclSettings, - unitLengthToUnitLen, - unitAngleToUnitAng, -} from 'lang/wasm' +} from '@src/lib/constants' +import { isDesktop } from '@src/lib/isDesktop' +import { copyFileShareLink } from '@src/lib/links' +import { baseUnitsUnion } from '@src/lib/settings/settingsTypes' +import { codeManager, kclManager } from '@src/lib/singletons' +import { err, reportRejection } from '@src/lib/trap' +import type { IndexLoaderData } from '@src/lib/types' interface OnSubmitProps { sampleName: string diff --git a/src/lib/kclHelpers.test.ts b/src/lib/kclHelpers.test.ts index 18179ed36..c3b79a50e 100644 --- a/src/lib/kclHelpers.test.ts +++ b/src/lib/kclHelpers.test.ts @@ -1,5 +1,5 @@ -import { ParseResult } from 'lang/wasm' -import { getCalculatedKclExpressionValue } from './kclHelpers' +import type { ParseResult } from '@src/lang/wasm' +import { getCalculatedKclExpressionValue } from '@src/lib/kclHelpers' describe('KCL expression calculations', () => { it('calculates a simple expression', async () => { diff --git a/src/lib/kclHelpers.ts b/src/lib/kclHelpers.ts index 34a65bbf6..2427a183a 100644 --- a/src/lib/kclHelpers.ts +++ b/src/lib/kclHelpers.ts @@ -1,8 +1,8 @@ -import { err } from './trap' -import { parse, resultIsOk } from 'lang/wasm' -import { executeAstMock } from 'lang/langHelpers' -import { KclExpression } from './commandTypes' -import { rustContext } from './singletons' +import { executeAstMock } from '@src/lang/langHelpers' +import { parse, resultIsOk } from '@src/lang/wasm' +import type { KclExpression } from '@src/lib/commandTypes' +import { rustContext } from '@src/lib/singletons' +import { err } from '@src/lib/trap' const DUMMY_VARIABLE_NAME = '__result__' diff --git a/src/lib/links.test.ts b/src/lib/links.test.ts index a65dec09e..32d2c6dff 100644 --- a/src/lib/links.test.ts +++ b/src/lib/links.test.ts @@ -1,5 +1,6 @@ -import { VITE_KC_SITE_APP_URL } from 'env' -import { createCreateFileUrl } from './links' +import { VITE_KC_SITE_APP_URL } from '@src/env' + +import { createCreateFileUrl } from '@src/lib/links' describe(`link creation tests`, () => { test(`createCreateFileUrl happy path`, async () => { diff --git a/src/lib/links.ts b/src/lib/links.ts index 2b31f46eb..f03613273 100644 --- a/src/lib/links.ts +++ b/src/lib/links.ts @@ -1,8 +1,13 @@ -import { ASK_TO_OPEN_QUERY_PARAM, CREATE_FILE_URL_PARAM } from './constants' -import { stringToBase64 } from './base64' -import { VITE_KC_API_BASE_URL, VITE_KC_SITE_APP_URL } from 'env' +import { VITE_KC_API_BASE_URL, VITE_KC_SITE_APP_URL } from '@src/env' import toast from 'react-hot-toast' -import { err } from './trap' + +import { stringToBase64 } from '@src/lib/base64' +import { + ASK_TO_OPEN_QUERY_PARAM, + CREATE_FILE_URL_PARAM, +} from '@src/lib/constants' +import { err } from '@src/lib/trap' + export interface FileLinkParams { code: string name: string diff --git a/src/lib/markdown.ts b/src/lib/markdown.ts index d4afcf746..b31069138 100644 --- a/src/lib/markdown.ts +++ b/src/lib/markdown.ts @@ -1,5 +1,7 @@ -import { MarkedOptions, Renderer, unescape } from '@ts-stack/markdown' -import { openExternalBrowserIfDesktop } from './openWindow' +import type { MarkedOptions } from '@ts-stack/markdown' +import { Renderer, unescape } from '@ts-stack/markdown' + +import { openExternalBrowserIfDesktop } from '@src/lib/openWindow' /** * Main goal of this custom renderer is to prevent links from changing the current location diff --git a/src/lib/objectPropertyByPath.ts b/src/lib/objectPropertyByPath.ts index 3a9e1ad61..6e6ea98d5 100644 --- a/src/lib/objectPropertyByPath.ts +++ b/src/lib/objectPropertyByPath.ts @@ -1,8 +1,8 @@ -import { PathValue, Paths } from './types' +import type { PathValue, Paths } from '@src/lib/types' export function setPropertyByPath< T extends { [key: string]: any }, - P extends Paths + P extends Paths, >(obj: T, path: P, value: PathValue) { if (typeof path === 'string') { const pList = path.split('.') @@ -25,7 +25,7 @@ export function setPropertyByPath< export function getPropertyByPath< T extends { [key: string]: any }, - P extends Paths + P extends Paths, >(obj: T, path: P): unknown { if (typeof path === 'string') { return path.split('.').reduce((accumulator, currentValue) => { diff --git a/src/lib/openWindow.ts b/src/lib/openWindow.ts index cc7d8b023..e48a2e1ea 100644 --- a/src/lib/openWindow.ts +++ b/src/lib/openWindow.ts @@ -1,6 +1,7 @@ -import { MouseEventHandler } from 'react' -import { isDesktop } from 'lib/isDesktop' -import { reportRejection } from './trap' +import type { MouseEventHandler } from 'react' + +import { isDesktop } from '@src/lib/isDesktop' +import { reportRejection } from '@src/lib/trap' export const openExternalBrowserIfDesktop = (to?: string) => function (e) { diff --git a/src/lib/operations.test.ts b/src/lib/operations.test.ts index 98f409bda..2ce781b86 100644 --- a/src/lib/operations.test.ts +++ b/src/lib/operations.test.ts @@ -1,6 +1,7 @@ -import { defaultSourceRange } from 'lang/wasm' -import { filterOperations } from './operations' -import { Operation } from '@rust/kcl-lib/bindings/Operation' +import type { Operation } from '@rust/kcl-lib/bindings/Operation' + +import { defaultSourceRange } from '@src/lang/wasm' +import { filterOperations } from '@src/lib/operations' function stdlib(name: string): Operation { return { diff --git a/src/lib/operations.ts b/src/lib/operations.ts index 7109488d5..239fd9280 100644 --- a/src/lib/operations.ts +++ b/src/lib/operations.ts @@ -1,26 +1,27 @@ -import { CustomIconName } from 'components/CustomIcon' +import type { Operation } from '@rust/kcl-lib/bindings/Operation' + +import type { CustomIconName } from '@src/components/CustomIcon' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import type { Artifact } from '@src/lang/std/artifactGraph' import { - Artifact, getArtifactOfTypes, getCapCodeRef, getEdgeCutConsumedCodeRef, getSweepEdgeCodeRef, getWallCodeRef, -} from 'lang/std/artifactGraph' -import { Operation } from '@rust/kcl-lib/bindings/Operation' -import { codeManager, kclManager, rustContext } from './singletons' -import { err } from './trap' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { sourceRangeFromRust } from 'lang/wasm' -import { CommandBarMachineEvent } from 'machines/commandBarMachine' -import { stringToKclExpression } from './kclHelpers' -import { +} from '@src/lang/std/artifactGraph' +import { sourceRangeFromRust } from '@src/lang/wasm' +import type { HelixModes, ModelingCommandSchema, -} from './commandBarConfigs/modelingCommandConfig' -import { isDefaultPlaneStr } from './planes' -import { Selection, Selections } from './selections' -import { KclExpression } from './commandTypes' +} from '@src/lib/commandBarConfigs/modelingCommandConfig' +import type { KclExpression } from '@src/lib/commandTypes' +import { stringToKclExpression } from '@src/lib/kclHelpers' +import { isDefaultPlaneStr } from '@src/lib/planes' +import type { Selection, Selections } from '@src/lib/selections' +import { codeManager, kclManager, rustContext } from '@src/lib/singletons' +import { err } from '@src/lib/trap' +import type { CommandBarMachineEvent } from '@src/machines/commandBarMachine' type ExecuteCommandEvent = CommandBarMachineEvent & { type: 'Find and select command' diff --git a/src/lib/paths.test.ts b/src/lib/paths.test.ts index a6d8cd7ea..e61e367a9 100644 --- a/src/lib/paths.test.ts +++ b/src/lib/paths.test.ts @@ -1,6 +1,7 @@ -import { parseProjectRoute } from './paths' import * as path from 'path' +import { parseProjectRoute } from '@src/lib/paths' + describe('testing parseProjectRoute', () => { it('should parse a project as a subpath of project dir', async () => { let config = { diff --git a/src/lib/paths.ts b/src/lib/paths.ts index 7320918f1..4ad514f19 100644 --- a/src/lib/paths.ts +++ b/src/lib/paths.ts @@ -1,13 +1,20 @@ -import { onboardingPaths } from 'routes/Onboarding/paths' -import { BROWSER_FILE_NAME, BROWSER_PROJECT_NAME, FILE_EXT } from './constants' -import { isDesktop } from './isDesktop' -import { readAppSettingsFile } from './desktop' -import { readLocalStorageAppSettingsFile } from './settings/settingsUtils' -import { err } from 'lib/trap' -import { IS_PLAYWRIGHT_KEY } from '../../e2e/playwright/storageStates' -import { DeepPartial } from './types' -import { Configuration } from '@rust/kcl-lib/bindings/Configuration' -import { PlatformPath } from 'path' +import type { PlatformPath } from 'path' + +import type { Configuration } from '@rust/kcl-lib/bindings/Configuration' + +import { IS_PLAYWRIGHT_KEY } from '@e2e/playwright/storageStates' + +import { + BROWSER_FILE_NAME, + BROWSER_PROJECT_NAME, + FILE_EXT, +} from '@src/lib/constants' +import { readAppSettingsFile } from '@src/lib/desktop' +import { isDesktop } from '@src/lib/isDesktop' +import { readLocalStorageAppSettingsFile } from '@src/lib/settings/settingsUtils' +import { err } from '@src/lib/trap' +import type { DeepPartial } from '@src/lib/types' +import { onboardingPaths } from '@src/routes/Onboarding/paths' const prependRoutes = (routesObject: Record) => (prepend: string) => { diff --git a/src/lib/performance.ts b/src/lib/performance.ts index c9b359bf0..b40185d78 100644 --- a/src/lib/performance.ts +++ b/src/lib/performance.ts @@ -1,4 +1,4 @@ -import { isDesktop } from 'lib/isDesktop' +import { isDesktop } from '@src/lib/isDesktop' function isWeb(): boolean { // Identify browser environment when following property is not present diff --git a/src/lib/planes.ts b/src/lib/planes.ts index 162c06721..bef4c487b 100644 --- a/src/lib/planes.ts +++ b/src/lib/planes.ts @@ -1,4 +1,4 @@ -import { DefaultPlanes } from '@rust/kcl-lib/bindings/DefaultPlanes' +import type { DefaultPlanes } from '@rust/kcl-lib/bindings/DefaultPlanes' // KCL string representation of default planes export type DefaultPlaneStr = 'XY' | 'XZ' | 'YZ' | '-XY' | '-XZ' | '-YZ' diff --git a/src/lib/promptToEdit.ts b/src/lib/promptToEdit.ts index 1578a428e..c8289f2df 100644 --- a/src/lib/promptToEdit.ts +++ b/src/lib/promptToEdit.ts @@ -1,17 +1,20 @@ -import { Models } from '@kittycad/lib' -import { VITE_KC_API_BASE_URL } from 'env' -import crossPlatformFetch from './crossPlatformFetch' -import { err, reportRejection } from './trap' -import { Selections } from './selections' -import { getArtifactOfTypes } from 'lang/std/artifactGraph' -import { ArtifactGraph, SourceRange, topLevelRange } from 'lang/wasm' -import toast from 'react-hot-toast' -import { codeManager, editorManager, kclManager } from './singletons' -import { ToastPromptToEditCadSuccess } from 'components/ToastTextToCad' -import { uuidv4 } from './utils' +import type { SelectionRange } from '@codemirror/state' +import { EditorSelection, Transaction } from '@codemirror/state' +import type { Models } from '@kittycad/lib' +import { VITE_KC_API_BASE_URL } from '@src/env' import { diffLines } from 'diff' -import { Transaction, EditorSelection, SelectionRange } from '@codemirror/state' -import { modelingMachineEvent } from 'editor/manager' +import toast from 'react-hot-toast' + +import { ToastPromptToEditCadSuccess } from '@src/components/ToastTextToCad' +import { modelingMachineEvent } from '@src/editor/manager' +import { getArtifactOfTypes } from '@src/lang/std/artifactGraph' +import { topLevelRange } from '@src/lang/util' +import type { ArtifactGraph, SourceRange } from '@src/lang/wasm' +import crossPlatformFetch from '@src/lib/crossPlatformFetch' +import type { Selections } from '@src/lib/selections' +import { codeManager, editorManager, kclManager } from '@src/lib/singletons' +import { err, reportRejection } from '@src/lib/trap' +import { uuidv4 } from '@src/lib/utils' function sourceIndexToLineColumn( code: string, diff --git a/src/lib/rectangleTool.test.ts b/src/lib/rectangleTool.test.ts index 33010c130..6b60341a4 100644 --- a/src/lib/rectangleTool.test.ts +++ b/src/lib/rectangleTool.test.ts @@ -1,15 +1,12 @@ import { expect } from 'vitest' -import { - recast, - assertParse, - topLevelRange, - VariableDeclaration, - initPromise, -} from 'lang/wasm' -import { updateCenterRectangleSketch } from './rectangleTool' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { getNodeFromPath } from 'lang/queryAst' -import { trap } from './trap' + +import { getNodeFromPath } from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import { topLevelRange } from '@src/lang/util' +import type { VariableDeclaration } from '@src/lang/wasm' +import { assertParse, initPromise, recast } from '@src/lang/wasm' +import { updateCenterRectangleSketch } from '@src/lib/rectangleTool' +import { trap } from '@src/lib/trap' beforeAll(async () => { await initPromise diff --git a/src/lib/rectangleTool.ts b/src/lib/rectangleTool.ts index bb8509e94..5fb44d8b3 100644 --- a/src/lib/rectangleTool.ts +++ b/src/lib/rectangleTool.ts @@ -1,3 +1,4 @@ +import { ARG_END_ABSOLUTE } from '@src/lang/constants' import { createArrayExpression, createBinaryExpression, @@ -9,17 +10,20 @@ import { createPipeSubstitution, createTagDeclarator, createUnaryExpression, -} from 'lang/modifyAst' -import { ArrayExpression, CallExpression, PipeExpression } from 'lang/wasm' -import { roundOff } from 'lib/utils' +} from '@src/lang/create' import { - isCallExpression, isArrayExpression, - isLiteral, isBinaryExpression, + isCallExpression, + isLiteral, isLiteralValueNumber, -} from 'lang/util' -import { ARG_END_ABSOLUTE } from 'lang/std/sketch' +} from '@src/lang/util' +import type { + ArrayExpression, + CallExpression, + PipeExpression, +} from '@src/lang/wasm' +import { roundOff } from '@src/lib/utils' /** * It does not create the startSketchOn and it does not create the startProfileAt. diff --git a/src/lib/routeLoaders.ts b/src/lib/routeLoaders.ts index 7da9a221a..8d547e366 100644 --- a/src/lib/routeLoaders.ts +++ b/src/lib/routeLoaders.ts @@ -1,21 +1,26 @@ -import { LoaderFunction, redirect } from 'react-router-dom' -import { FileLoaderData, HomeLoaderData, IndexLoaderData } from './types' -import { getProjectMetaByRouteId, PATHS } from './paths' -import { isDesktop } from './isDesktop' -import { BROWSER_PATH } from 'lib/paths' +import type { LoaderFunction } from 'react-router-dom' +import { redirect } from 'react-router-dom' +import { waitFor } from 'xstate' + +import { fileSystemManager } from '@src/lang/std/fileSystemManager' +import { normalizeLineEndings } from '@src/lib/codeEditor' import { BROWSER_FILE_NAME, BROWSER_PROJECT_NAME, FILE_EXT, PROJECT_ENTRYPOINT, -} from 'lib/constants' -import { loadAndValidateSettings } from './settings/settingsUtils' -import { codeManager } from 'lib/singletons' -import { fileSystemManager } from 'lang/std/fileSystemManager' -import { getProjectInfo } from './desktop' -import { normalizeLineEndings } from 'lib/codeEditor' -import { settingsActor } from 'machines/appMachine' -import { waitFor } from 'xstate' +} from '@src/lib/constants' +import { getProjectInfo } from '@src/lib/desktop' +import { isDesktop } from '@src/lib/isDesktop' +import { BROWSER_PATH, PATHS, getProjectMetaByRouteId } from '@src/lib/paths' +import { loadAndValidateSettings } from '@src/lib/settings/settingsUtils' +import { codeManager } from '@src/lib/singletons' +import type { + FileLoaderData, + HomeLoaderData, + IndexLoaderData, +} from '@src/lib/types' +import { settingsActor } from '@src/machines/appMachine' export const telemetryLoader: LoaderFunction = async ({ params, diff --git a/src/lib/rustContext.ts b/src/lib/rustContext.ts index 4f29bc3cf..2dc549108 100644 --- a/src/lib/rustContext.ts +++ b/src/lib/rustContext.ts @@ -1,25 +1,29 @@ +import toast from 'react-hot-toast' + +import type { Configuration } from '@rust/kcl-lib/bindings/Configuration' +import type { DefaultPlanes } from '@rust/kcl-lib/bindings/DefaultPlanes' +import type { KclError as RustKclError } from '@rust/kcl-lib/bindings/KclError' +import type { OutputFormat3d } from '@rust/kcl-lib/bindings/ModelingCmd' +import type { Node } from '@rust/kcl-lib/bindings/Node' +import type { Program } from '@rust/kcl-lib/bindings/Program' +import type { Context } from '@rust/kcl-wasm-lib/pkg/kcl_wasm_lib' + +import type { EngineCommandManager } from '@src/lang/std/engineConnection' +import { fileSystemManager } from '@src/lang/std/fileSystemManager' +import type { ExecState } from '@src/lang/wasm' import { errFromErrWithOutputs, - ExecState, execStateFromRust, initPromise, mockExecStateFromRust, -} from 'lang/wasm' -import { getModule, ModuleType } from 'lib/wasm_lib_wrapper' -import { fileSystemManager } from 'lang/std/fileSystemManager' -import type { Configuration } from '@rust/kcl-lib/bindings/Configuration' -import { DeepPartial } from 'lib/types' -import { Node } from '@rust/kcl-lib/bindings/Node' -import type { Program } from '@rust/kcl-lib/bindings/Program' -import { Context } from '@rust/kcl-wasm-lib/pkg/kcl_wasm_lib' -import { DefaultPlanes } from '@rust/kcl-lib/bindings/DefaultPlanes' -import { DefaultPlaneStr, defaultPlaneStrToKey } from 'lib/planes' -import { err } from 'lib/trap' -import { EngineCommandManager } from 'lang/std/engineConnection' -import { OutputFormat3d } from '@rust/kcl-lib/bindings/ModelingCmd' -import ModelingAppFile from './modelingAppFile' -import toast from 'react-hot-toast' -import { KclError as RustKclError } from '@rust/kcl-lib/bindings/KclError' +} from '@src/lang/wasm' +import type ModelingAppFile from '@src/lib/modelingAppFile' +import type { DefaultPlaneStr } from '@src/lib/planes' +import { defaultPlaneStrToKey } from '@src/lib/planes' +import { err } from '@src/lib/trap' +import type { DeepPartial } from '@src/lib/types' +import type { ModuleType } from '@src/lib/wasm_lib_wrapper' +import { getModule } from '@src/lib/wasm_lib_wrapper' export default class RustContext { private wasmInitFailed: boolean = true diff --git a/src/lib/selections.test.ts b/src/lib/selections.test.ts index 545dfd2d5..955737411 100644 --- a/src/lib/selections.test.ts +++ b/src/lib/selections.test.ts @@ -1,13 +1,16 @@ import { expect } from 'vitest' -import { assertParse, initPromise, ArtifactGraph, SourceRange } from 'lang/wasm' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' + +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import type { Artifact } from '@src/lang/std/artifactGraph' +import type { ArtifactGraph, SourceRange } from '@src/lang/wasm' +import { assertParse, initPromise } from '@src/lang/wasm' +import type { ArtifactIndex } from '@src/lib/artifactIndex' +import { buildArtifactIndex } from '@src/lib/artifactIndex' +import type { Selection } from '@src/lib/selections' import { codeToIdSelections, - Selection, findLastRangeStartingBefore, -} from './selections' -import { buildArtifactIndex, ArtifactIndex } from './artifactIndex' -import { Artifact } from 'lang/std/artifactGraph' +} from '@src/lib/selections' beforeAll(async () => { await initPromise diff --git a/src/lib/selections.ts b/src/lib/selections.ts index 0fb624f17..ff548d54c 100644 --- a/src/lib/selections.ts +++ b/src/lib/selections.ts @@ -1,46 +1,49 @@ -import { Models } from '@kittycad/lib' +import type { SelectionRange } from '@codemirror/state' +import { EditorSelection } from '@codemirror/state' +import type { Models } from '@kittycad/lib' +import type { Object3D, Object3DEventMap } from 'three' +import { Mesh } from 'three' + +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { + SEGMENT_BODIES_PLUS_PROFILE_START, + getParentGroup, +} from '@src/clientSideScene/sceneConstants' +import { AXIS_GROUP, X_AXIS } from '@src/clientSideScene/sceneInfra' +import { getNodeFromPath, isSingleCursorInPipe } from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import type { Artifact, ArtifactId, CodeRef } from '@src/lang/std/artifactGraph' +import { getCodeRefsByArtifactId } from '@src/lang/std/artifactGraph' +import type { PathToNodeMap } from '@src/lang/std/sketchcombos' +import { isCursorInSketchCommandRange, topLevelRange } from '@src/lang/util' +import type { + ArtifactGraph, + CallExpression, + CallExpressionKw, + Expr, + Program, + SourceRange, +} from '@src/lang/wasm' +import { defaultSourceRange } from '@src/lang/wasm' +import type { ArtifactEntry, ArtifactIndex } from '@src/lib/artifactIndex' +import type { CommandArgument } from '@src/lib/commandTypes' +import type { DefaultPlaneStr } from '@src/lib/planes' import { codeManager, engineCommandManager, kclManager, + rustContext, sceneEntitiesManager, -} from 'lib/singletons' +} from '@src/lib/singletons' +import { err } from '@src/lib/trap' import { - CallExpression, - SourceRange, - Expr, - defaultSourceRange, - topLevelRange, - ArtifactGraph, - CallExpressionKw, -} from 'lang/wasm' -import { ModelingMachineEvent } from 'machines/modelingMachine' -import { isNonNullable, uuidv4 } from 'lib/utils' -import { EditorSelection, SelectionRange } from '@codemirror/state' -import { getNormalisedCoordinates, isOverlap } from 'lib/utils' -import { isCursorInSketchCommandRange } from 'lang/util' -import { Program } from 'lang/wasm' -import { getNodeFromPath, isSingleCursorInPipe } from 'lang/queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' -import { CommandArgument } from './commandTypes' -import { - getParentGroup, - SEGMENT_BODIES_PLUS_PROFILE_START, -} from 'clientSideScene/sceneEntities' -import { Mesh, Object3D, Object3DEventMap } from 'three' -import { AXIS_GROUP, X_AXIS } from 'clientSideScene/sceneInfra' -import { PathToNodeMap } from 'lang/std/sketchcombos' -import { err } from 'lib/trap' -import { - Artifact, - CodeRef, - getCodeRefsByArtifactId, - ArtifactId, -} from 'lang/std/artifactGraph' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { DefaultPlaneStr } from './planes' -import { ArtifactEntry, ArtifactIndex } from './artifactIndex' -import { rustContext } from './singletons' + getNormalisedCoordinates, + isNonNullable, + isOverlap, + uuidv4, +} from '@src/lib/utils' +import type { ModelingMachineEvent } from '@src/machines/modelingMachine' export const X_AXIS_UUID = 'ad792545-7fd3-482a-a602-a93924e3055b' export const Y_AXIS_UUID = '680fd157-266f-4b8a-984f-cdf46b8bdf01' diff --git a/src/lib/settings/initialKeybindings.ts b/src/lib/settings/initialKeybindings.ts index 2071068e1..b49bd1462 100644 --- a/src/lib/settings/initialKeybindings.ts +++ b/src/lib/settings/initialKeybindings.ts @@ -1,5 +1,5 @@ -import { isDesktop } from 'lib/isDesktop' -import { platform } from 'lib/utils' +import { isDesktop } from '@src/lib/isDesktop' +import { platform } from '@src/lib/utils' export type InteractionMapItem = { name: string diff --git a/src/lib/settings/initialSettings.tsx b/src/lib/settings/initialSettings.tsx index 21bccdb79..a82a99a9c 100644 --- a/src/lib/settings/initialSettings.tsx +++ b/src/lib/settings/initialSettings.tsx @@ -1,28 +1,29 @@ -import { DEFAULT_PROJECT_NAME } from 'lib/constants' +import { useRef } from 'react' + +import type { CameraOrbitType } from '@rust/kcl-lib/bindings/CameraOrbitType' +import type { CameraProjectionType } from '@rust/kcl-lib/bindings/CameraProjectionType' +import type { NamedView } from '@rust/kcl-lib/bindings/NamedView' +import type { OnboardingStatus } from '@rust/kcl-lib/bindings/OnboardingStatus' + +import { CustomIcon } from '@src/components/CustomIcon' +import Tooltip from '@src/components/Tooltip' +import type { CameraSystem } from '@src/lib/cameraControls' +import { cameraMouseDragGuards, cameraSystems } from '@src/lib/cameraControls' import { + DEFAULT_DEFAULT_LENGTH_UNIT, + DEFAULT_PROJECT_NAME, +} from '@src/lib/constants' +import { isDesktop } from '@src/lib/isDesktop' +import type { BaseUnit, SettingProps, SettingsLevel, - baseUnitsUnion, -} from 'lib/settings/settingsTypes' -import { Themes } from 'lib/theme' -import { isEnumMember } from 'lib/types' -import { - CameraSystem, - cameraMouseDragGuards, - cameraSystems, -} from 'lib/cameraControls' -import { isDesktop } from 'lib/isDesktop' -import { useRef } from 'react' -import { CustomIcon } from 'components/CustomIcon' -import Tooltip from 'components/Tooltip' -import { isArray, toSync } from 'lib/utils' -import { reportRejection } from 'lib/trap' -import { CameraProjectionType } from '@rust/kcl-lib/bindings/CameraProjectionType' -import { OnboardingStatus } from '@rust/kcl-lib/bindings/OnboardingStatus' -import { NamedView } from '@rust/kcl-lib/bindings/NamedView' -import { CameraOrbitType } from '@rust/kcl-lib/bindings/CameraOrbitType' -import { DEFAULT_DEFAULT_LENGTH_UNIT } from 'lib/constants' +} from '@src/lib/settings/settingsTypes' +import { baseUnitsUnion } from '@src/lib/settings/settingsTypes' +import { Themes } from '@src/lib/theme' +import { reportRejection } from '@src/lib/trap' +import { isEnumMember } from '@src/lib/types' +import { isArray, toSync } from '@src/lib/utils' /** * A setting that can be set at the user or project level @@ -91,8 +92,8 @@ export class Setting { return this._project !== undefined ? this._project : this._user !== undefined - ? this._user - : this._default + ? this._user + : this._default } /** * @param {SettingsLevel} level - The level to get the fallback for diff --git a/src/lib/settings/settingsTypes.ts b/src/lib/settings/settingsTypes.ts index bbf17ec4a..3df094095 100644 --- a/src/lib/settings/settingsTypes.ts +++ b/src/lib/settings/settingsTypes.ts @@ -1,14 +1,16 @@ import { type Models } from '@kittycad/lib' -import { Setting, settings } from './initialSettings' -import { AtLeast, PathValue, Paths } from 'lib/types' -import { CommandArgumentConfig } from 'lib/commandTypes' -import { Themes } from 'lib/theme' -import { CameraProjectionType } from '@rust/kcl-lib/bindings/CameraProjectionType' -import { +import type { UnitAngle_type, UnitLength_type, } from '@kittycad/lib/dist/types/src/models' -import { CameraOrbitType } from '@rust/kcl-lib/bindings/CameraOrbitType' + +import type { CameraOrbitType } from '@rust/kcl-lib/bindings/CameraOrbitType' +import type { CameraProjectionType } from '@rust/kcl-lib/bindings/CameraProjectionType' + +import type { CommandArgumentConfig } from '@src/lib/commandTypes' +import type { Setting, settings } from '@src/lib/settings/initialSettings' +import type { Themes } from '@src/lib/theme' +import type { AtLeast, PathValue, Paths } from '@src/lib/types' export interface SettingsViaQueryString { pool: string | null diff --git a/src/lib/settings/settingsUtils.test.ts b/src/lib/settings/settingsUtils.test.ts index 3994662f7..f8840d165 100644 --- a/src/lib/settings/settingsUtils.test.ts +++ b/src/lib/settings/settingsUtils.test.ts @@ -1,12 +1,13 @@ -import { DeepPartial } from 'lib/types' -import { Configuration } from '@rust/kcl-lib/bindings/Configuration' +import type { Configuration } from '@rust/kcl-lib/bindings/Configuration' + +import { createSettings } from '@src/lib/settings/initialSettings' import { configurationToSettingsPayload, getAllCurrentSettings, projectConfigurationToSettingsPayload, setSettingsAtLevel, -} from './settingsUtils' -import { createSettings } from './initialSettings' +} from '@src/lib/settings/settingsUtils' +import type { DeepPartial } from '@src/lib/types' describe(`testing settings initialization`, () => { it(`sets settings at the 'user' level`, () => { diff --git a/src/lib/settings/settingsUtils.ts b/src/lib/settings/settingsUtils.ts index a3cf9f6f6..deb34baeb 100644 --- a/src/lib/settings/settingsUtils.ts +++ b/src/lib/settings/settingsUtils.ts @@ -1,3 +1,9 @@ +import type { Configuration } from '@rust/kcl-lib/bindings/Configuration' +import type { NamedView } from '@rust/kcl-lib/bindings/NamedView' +import type { ProjectConfiguration } from '@rust/kcl-lib/bindings/ProjectConfiguration' +import { default_app_settings } from '@rust/kcl-wasm-lib/pkg/kcl_wasm_lib' +import { TEST } from '@src/env' + import { defaultAppSettings, defaultProjectSettings, @@ -6,25 +12,26 @@ import { parseProjectSettings, serializeConfiguration, serializeProjectConfiguration, -} from 'lang/wasm' -import { mouseControlsToCameraSystem } from 'lib/cameraControls' -import { BROWSER_PROJECT_NAME } from 'lib/constants' +} from '@src/lang/wasm' +import { mouseControlsToCameraSystem } from '@src/lib/cameraControls' +import { BROWSER_PROJECT_NAME } from '@src/lib/constants' import { getInitialDefaultDir, readAppSettingsFile, readProjectSettingsFile, writeAppSettingsFile, writeProjectSettingsFile, -} from 'lib/desktop' -import { isDesktop } from 'lib/isDesktop' -import { Setting, createSettings, settings } from 'lib/settings/initialSettings' -import { appThemeToTheme } from 'lib/theme' -import { err } from 'lib/trap' -import { DeepPartial } from 'lib/types' -import { Configuration } from '@rust/kcl-lib/bindings/Configuration' -import { ProjectConfiguration } from '@rust/kcl-lib/bindings/ProjectConfiguration' -import { NamedView } from '@rust/kcl-lib/bindings/NamedView' -import { SaveSettingsPayload, SettingsLevel } from './settingsTypes' +} from '@src/lib/desktop' +import { isDesktop } from '@src/lib/isDesktop' +import type { Setting } from '@src/lib/settings/initialSettings' +import { createSettings, settings } from '@src/lib/settings/initialSettings' +import type { + SaveSettingsPayload, + SettingsLevel, +} from '@src/lib/settings/settingsTypes' +import { appThemeToTheme } from '@src/lib/theme' +import { err } from '@src/lib/trap' +import type { DeepPartial } from '@src/lib/types' /** * Convert from a rust settings struct into the JS settings struct. @@ -440,3 +447,16 @@ export function getSettingInputType(setting: Setting) { return setting.commandConfig.inputType as 'string' | 'options' | 'boolean' return typeof setting.default as 'string' | 'boolean' } + +export const jsAppSettings = async () => { + let jsAppSettings = default_app_settings() + if (!TEST) { + const settings = await import('@src/machines/appMachine').then((module) => + module.getSettings() + ) + if (settings) { + jsAppSettings = getAllCurrentSettings(settings) + } + } + return jsAppSettings +} diff --git a/src/lib/singletons.ts b/src/lib/singletons.ts index c54c5d662..d027a3719 100644 --- a/src/lib/singletons.ts +++ b/src/lib/singletons.ts @@ -1,11 +1,12 @@ -import { SceneEntities } from 'clientSideScene/sceneEntities' -import { SceneInfra } from 'clientSideScene/sceneInfra' -import EditorManager from 'editor/manager' -import { KclManager } from 'lang/KclSingleton' -import CodeManager from 'lang/codeManager' -import { EngineCommandManager } from 'lang/std/engineConnection' -import { uuidv4 } from './utils' -import RustContext from 'lib/rustContext' +import EditorManager from '@src/editor/manager' +import { KclManager } from '@src/lang/KclSingleton' +import CodeManager from '@src/lang/codeManager' +import { EngineCommandManager } from '@src/lang/std/engineConnection' +import RustContext from '@src/lib/rustContext' +import { uuidv4 } from '@src/lib/utils' + +import { SceneEntities } from '@src/clientSideScene/sceneEntities' +import { SceneInfra } from '@src/clientSideScene/sceneInfra' export const codeManager = new CodeManager() @@ -28,13 +29,20 @@ engineCommandManager.kclManager = kclManager export const sceneInfra = new SceneInfra(engineCommandManager) engineCommandManager.camControlsCameraChange = sceneInfra.onCameraChange -export const sceneEntitiesManager = new SceneEntities(engineCommandManager) - // This needs to be after sceneInfra and engineCommandManager are is created. export const editorManager = new EditorManager() export const rustContext = new RustContext(engineCommandManager) +export const sceneEntitiesManager = new SceneEntities( + engineCommandManager, + sceneInfra, + editorManager, + codeManager, + kclManager, + rustContext +) + if (typeof window !== 'undefined') { ;(window as any).engineCommandManager = engineCommandManager ;(window as any).kclManager = kclManager diff --git a/src/lib/sorting.ts b/src/lib/sorting.ts index 63306f11e..02af6d09b 100644 --- a/src/lib/sorting.ts +++ b/src/lib/sorting.ts @@ -1,5 +1,5 @@ -import { CustomIconName } from 'components/CustomIcon' -import { Project } from 'lib/project' +import type { CustomIconName } from '@src/components/CustomIcon' +import type { Project } from '@src/lib/project' const DESC = ':desc' diff --git a/src/lib/tauriFS.test.ts b/src/lib/tauriFS.test.ts index b5f7c7640..daf5bd200 100644 --- a/src/lib/tauriFS.test.ts +++ b/src/lib/tauriFS.test.ts @@ -1,8 +1,8 @@ +import { MAX_PADDING } from '@src/lib/constants' import { getNextProjectIndex, interpolateProjectNameWithIndex, -} from './desktopFS' -import { MAX_PADDING } from './constants' +} from '@src/lib/desktopFS' describe('Test project name utility functions', () => { it('interpolates a project name without an index', () => { diff --git a/src/lib/telemetry.test.ts b/src/lib/telemetry.test.ts index 9c1d6b45e..f52eaf01f 100644 --- a/src/lib/telemetry.test.ts +++ b/src/lib/telemetry.test.ts @@ -1,10 +1,10 @@ +import type { MaxWidth } from '@src/lib/telemetry' import { columnWidth, - MaxWidth, - printHeader, printDivider, + printHeader, printRow, -} from 'lib/telemetry' +} from '@src/lib/telemetry' describe('Telemetry', () => { describe('columnWidth', () => { diff --git a/src/lib/telemetry.ts b/src/lib/telemetry.ts index 6258d8f89..ac159714b 100644 --- a/src/lib/telemetry.ts +++ b/src/lib/telemetry.ts @@ -1,5 +1,7 @@ -import { PerformanceMark, getMarks } from 'lib/performance' -import { writeTelemetryFile, writeRawTelemetryFile } from 'lib/desktop' +import { writeRawTelemetryFile, writeTelemetryFile } from '@src/lib/desktop' +import type { PerformanceMark } from '@src/lib/performance' +import { getMarks } from '@src/lib/performance' + let args: any = null // Get the longest width of values or column name diff --git a/src/lib/testHelpers.ts b/src/lib/testHelpers.ts index b9d70faf9..b7de7206b 100644 --- a/src/lib/testHelpers.ts +++ b/src/lib/testHelpers.ts @@ -1,6 +1,8 @@ -import { Program, ExecState, jsAppSettings } from '../lang/wasm' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { rustContext } from './singletons' +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import type { ExecState, Program } from '@src/lang/wasm' +import { jsAppSettings } from '@src/lib/settings/settingsUtils' +import { rustContext } from '@src/lib/singletons' export async function enginelessExecutor( ast: Node, diff --git a/src/lib/textToCad.ts b/src/lib/textToCad.ts index b9aaef243..d4b3db734 100644 --- a/src/lib/textToCad.ts +++ b/src/lib/textToCad.ts @@ -1,21 +1,22 @@ -import { Models } from '@kittycad/lib' +import type { Models } from '@kittycad/lib' +import { VITE_KC_API_BASE_URL } from '@src/env' +import toast from 'react-hot-toast' +import type { NavigateFunction } from 'react-router-dom' +import type { ContextFrom, EventFrom } from 'xstate' + import { ToastTextToCadError, ToastTextToCadSuccess, -} from 'components/ToastTextToCad' -import { VITE_KC_API_BASE_URL } from 'env' -import toast from 'react-hot-toast' -import { FILE_EXT } from './constants' -import { ContextFrom, EventFrom } from 'xstate' -import { fileMachine } from 'machines/fileMachine' -import { NavigateFunction } from 'react-router-dom' -import crossPlatformFetch from './crossPlatformFetch' -import { isDesktop } from 'lib/isDesktop' -import { Themes } from './theme' -import { getNextFileName } from './desktopFS' -import { reportRejection } from './trap' -import { toSync } from './utils' -import { kclManager } from './singletons' +} from '@src/components/ToastTextToCad' +import { FILE_EXT } from '@src/lib/constants' +import crossPlatformFetch from '@src/lib/crossPlatformFetch' +import { getNextFileName } from '@src/lib/desktopFS' +import { isDesktop } from '@src/lib/isDesktop' +import { kclManager } from '@src/lib/singletons' +import type { Themes } from '@src/lib/theme' +import { reportRejection } from '@src/lib/trap' +import { toSync } from '@src/lib/utils' +import type { fileMachine } from '@src/machines/fileMachine' async function submitTextToCadPrompt( prompt: string, diff --git a/src/lib/theme.ts b/src/lib/theme.ts index fdfe6bd73..a99ef53c0 100644 --- a/src/lib/theme.ts +++ b/src/lib/theme.ts @@ -1,4 +1,4 @@ -import { AppTheme } from '@rust/kcl-lib/bindings/AppTheme' +import type { AppTheme } from '@rust/kcl-lib/bindings/AppTheme' /** A media query matcher for dark mode */ export const darkModeMatcher = diff --git a/src/lib/toolbar.ts b/src/lib/toolbar.ts index b1cc024ab..ad0e1adc0 100644 --- a/src/lib/toolbar.ts +++ b/src/lib/toolbar.ts @@ -1,13 +1,14 @@ -import { CustomIconName } from 'components/CustomIcon' -import { DEV } from 'env' -import { commandBarActor } from 'machines/commandBarMachine' +import { DEV } from '@src/env' +import type { EventFrom, StateFrom } from 'xstate' + +import type { CustomIconName } from '@src/components/CustomIcon' +import { commandBarActor } from '@src/machines/commandBarMachine' +import type { modelingMachine } from '@src/machines/modelingMachine' import { isEditingExistingSketch, - modelingMachine, pipeHasCircle, -} from 'machines/modelingMachine' -import { IS_NIGHTLY_OR_DEBUG } from 'routes/Settings' -import { EventFrom, StateFrom } from 'xstate' +} from '@src/machines/modelingMachine' +import { IS_NIGHTLY_OR_DEBUG } from '@src/routes/Settings' export type ToolbarModeName = 'modeling' | 'sketching' diff --git a/src/lib/types.ts b/src/lib/types.ts index b76a5c8f2..230a09381 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -1,4 +1,4 @@ -import { Project, FileEntry } from 'lib/project' +import type { FileEntry, Project } from '@src/lib/project' export type IndexLoaderData = { code: string | null @@ -44,30 +44,30 @@ type Prev = [ 18, 19, 20, - ...0[] + ...0[], ] export type Paths = [D] extends [never] ? never : T extends object - ? { - [K in keyof T]-?: K extends string | number - ? `${K}` | Join> - : never - }[keyof T] - : '' + ? { + [K in keyof T]-?: K extends string | number + ? `${K}` | Join> + : never + }[keyof T] + : '' type Idx = K extends keyof T ? T[K] : number extends keyof T - ? K extends `${number}` - ? T[number] + ? K extends `${number}` + ? T[number] + : never : never - : never export type PathValue< T, - P extends Paths + P extends Paths, > = P extends `${infer Key}.${infer Rest}` ? Rest extends Paths, 1> ? PathValue, Rest> @@ -77,8 +77,8 @@ export type PathValue< export type Leaves = [D] extends [never] ? never : T extends object - ? { [K in keyof T]-?: Join> }[keyof T] - : '' + ? { [K in keyof T]-?: Join> }[keyof T] + : '' // Thanks to @micfan on StackOverflow for this utility type: // https://stackoverflow.com/a/57390160/22753272 diff --git a/src/lib/useCalculateKclExpression.ts b/src/lib/useCalculateKclExpression.ts index cc79afafc..ead3acf4e 100644 --- a/src/lib/useCalculateKclExpression.ts +++ b/src/lib/useCalculateKclExpression.ts @@ -1,14 +1,16 @@ -import { useModelingContext } from 'hooks/useModelingContext' -import { kclManager } from 'lib/singletons' -import { useKclContext } from 'lang/KclProvider' -import { findUniqueName } from 'lang/modifyAst' -import { PrevVariable, findAllPreviousVariables } from 'lang/queryAst' -import { Expr, SourceRange } from 'lang/wasm' import { useEffect, useMemo, useRef, useState } from 'react' -import { getCalculatedKclExpressionValue } from './kclHelpers' -import { parse, resultIsOk } from 'lang/wasm' -import { err } from 'lib/trap' -import { getSafeInsertIndex } from 'lang/queryAst/getSafeInsertIndex' + +import { useModelingContext } from '@src/hooks/useModelingContext' +import { useKclContext } from '@src/lang/KclProvider' +import { findUniqueName } from '@src/lang/create' +import type { PrevVariable } from '@src/lang/queryAst' +import { findAllPreviousVariables } from '@src/lang/queryAst' +import { getSafeInsertIndex } from '@src/lang/queryAst/getSafeInsertIndex' +import type { Expr, SourceRange } from '@src/lang/wasm' +import { parse, resultIsOk } from '@src/lang/wasm' +import { getCalculatedKclExpressionValue } from '@src/lib/kclHelpers' +import { kclManager } from '@src/lib/singletons' +import { err } from '@src/lib/trap' const isValidVariableName = (name: string) => /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name) diff --git a/src/lib/usePreviousVarMentions.ts b/src/lib/usePreviousVarMentions.ts index 66787eaac..2a7f43356 100644 --- a/src/lib/usePreviousVarMentions.ts +++ b/src/lib/usePreviousVarMentions.ts @@ -1,5 +1,6 @@ -import { CompletionContext } from '@codemirror/autocomplete' -import { usePreviousVariables } from './usePreviousVariables' +import type { CompletionContext } from '@codemirror/autocomplete' + +import { usePreviousVariables } from '@src/lib/usePreviousVariables' /// Basically a fork of the `mentions` extension https://github.com/uiwjs/react-codemirror/blob/master/extensions/mentions/src/index.ts /// But it matches on any word, not just the `@` symbol diff --git a/src/lib/usePreviousVariables.ts b/src/lib/usePreviousVariables.ts index c6ec4be93..f0fc816d4 100644 --- a/src/lib/usePreviousVariables.ts +++ b/src/lib/usePreviousVariables.ts @@ -1,9 +1,10 @@ -import { useModelingContext } from 'hooks/useModelingContext' -import { kclManager } from 'lib/singletons' -import { useKclContext } from 'lang/KclProvider' -import { findAllPreviousVariables } from 'lang/queryAst' import { useEffect, useState } from 'react' +import { useModelingContext } from '@src/hooks/useModelingContext' +import { useKclContext } from '@src/lang/KclProvider' +import { findAllPreviousVariables } from '@src/lang/queryAst' +import { kclManager } from '@src/lib/singletons' + export function usePreviousVariables() { const { variables, code } = useKclContext() const { context } = useModelingContext() diff --git a/src/lib/utils.test.ts b/src/lib/utils.test.ts index 9f95000a5..cd792403f 100644 --- a/src/lib/utils.test.ts +++ b/src/lib/utils.test.ts @@ -1,13 +1,14 @@ +import type { SourceRange } from '@rust/kcl-lib/bindings/SourceRange' +import { topLevelRange } from '@src/lang/util' import { + hasDigitsLeftOfDecimal, + hasLeadingZero, + isClockwise, isOverlap, + onDragNumberCalculation, roundOff, simulateOnMouseDragMatch, - onDragNumberCalculation, - hasLeadingZero, - hasDigitsLeftOfDecimal, - isClockwise, -} from './utils' -import { SourceRange, topLevelRange } from '../lang/wasm' +} from '@src/lib/utils' describe('testing isOverlapping', () => { testBothOrders(topLevelRange(0, 3), topLevelRange(3, 10)) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 94ec96d5d..30ff5576a 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,10 +1,10 @@ -import { SourceRange } from '../lang/wasm' - +import type { Binary as BSONBinary } from 'bson' import { v4 } from 'uuid' -import { isDesktop } from './isDesktop' -import { AnyMachineSnapshot } from 'xstate' -import { AsyncFn } from './types' -import { Binary as BSONBinary } from 'bson' +import type { AnyMachineSnapshot } from 'xstate' + +import type { SourceRange } from '@src/lang/wasm' +import { isDesktop } from '@src/lib/isDesktop' +import type { AsyncFn } from '@src/lib/types' export const uuidv4 = v4 diff --git a/src/lib/utils2d.test.ts b/src/lib/utils2d.test.ts index d64b0ca92..aa77cc96b 100644 --- a/src/lib/utils2d.test.ts +++ b/src/lib/utils2d.test.ts @@ -1,5 +1,5 @@ -import { Coords2d } from 'lang/std/sketch' -import { isPointsCCW, initPromise } from 'lang/wasm' +import type { Coords2d } from '@src/lang/std/sketch' +import { initPromise, isPointsCCW } from '@src/lang/wasm' beforeAll(async () => { await initPromise diff --git a/src/lib/utils2d.ts b/src/lib/utils2d.ts index d0e59844c..e0fe46125 100644 --- a/src/lib/utils2d.ts +++ b/src/lib/utils2d.ts @@ -1,5 +1,5 @@ -import { Coords2d } from 'lang/std/sketch' -import { getAngle } from './utils' +import type { Coords2d } from '@src/lang/std/sketch' +import { getAngle } from '@src/lib/utils' export function deg2Rad(deg: number): number { return (deg * Math.PI) / 180 diff --git a/src/lib/varCompletionExtension.ts b/src/lib/varCompletionExtension.ts index d2a5f08f1..91894e39a 100644 --- a/src/lib/varCompletionExtension.ts +++ b/src/lib/varCompletionExtension.ts @@ -1,9 +1,6 @@ -import { Extension } from '@codemirror/state' -import { - CompletionContext, - autocompletion, - Completion, -} from '@codemirror/autocomplete' +import type { Completion, CompletionContext } from '@codemirror/autocomplete' +import { autocompletion } from '@codemirror/autocomplete' +import type { Extension } from '@codemirror/state' /// Basically a fork of the `mentions` extension https://github.com/uiwjs/react-codemirror/blob/master/extensions/mentions/src/index.ts /// But it matches on any word, not just the `@` symbol diff --git a/src/lib/wasm_lib_wrapper.ts b/src/lib/wasm_lib_wrapper.ts index 8dbddd847..6d1e3d427 100644 --- a/src/lib/wasm_lib_wrapper.ts +++ b/src/lib/wasm_lib_wrapper.ts @@ -6,28 +6,28 @@ * A way to bypass this is by reloading the entire .js file so the global wasm variable * gets reinitialized and we do not use that old reference */ - -import { - parse_wasm as ParseWasm, - recast_wasm as RecastWasm, - format_number as FormatNumber, - kcl_lint as KclLint, - is_points_ccw as IsPointsCcw, - get_tangential_arc_to_info as GetTangentialArcToInfo, +import type { + base64_decode as Base64Decode, + change_kcl_settings as ChangeKclSettings, coredump as CoreDump, default_app_settings as DefaultAppSettings, + default_project_settings as DefaultProjectSettings, + format_number as FormatNumber, + get_kcl_version as GetKclVersion, + get_tangential_arc_to_info as GetTangentialArcToInfo, + is_kcl_empty_or_only_settings as IsKclEmptyOrOnlySettings, + is_points_ccw as IsPointsCcw, + kcl_lint as KclLint, + kcl_settings as KclSettings, parse_app_settings as ParseAppSettings, parse_project_settings as ParseProjectSettings, - default_project_settings as DefaultProjectSettings, - base64_decode as Base64Decode, - kcl_settings as KclSettings, - change_kcl_settings as ChangeKclSettings, - is_kcl_empty_or_only_settings as IsKclEmptyOrOnlySettings, - get_kcl_version as GetKclVersion, + parse_wasm as ParseWasm, + recast_wasm as RecastWasm, serialize_configuration as SerializeConfiguration, serialize_project_configuration as SerializeProjectConfiguration, } from '@rust/kcl-wasm-lib/pkg/kcl_wasm_lib' +// eslint-disable-next-line @typescript-eslint/consistent-type-imports export type ModuleType = typeof import('@rust/kcl-wasm-lib/pkg/kcl_wasm_lib') // Stores the result of the import of the wasm_lib file diff --git a/src/lib/withBaseURL.ts b/src/lib/withBaseURL.ts index 4ea2d3986..e23436bd3 100644 --- a/src/lib/withBaseURL.ts +++ b/src/lib/withBaseURL.ts @@ -1,4 +1,4 @@ -import { VITE_KC_API_BASE_URL } from '../env' +import { VITE_KC_API_BASE_URL } from '@src/env' export default function withBaseUrl(path: string): string { return VITE_KC_API_BASE_URL + path diff --git a/src/machines/appMachine.ts b/src/machines/appMachine.ts index 531d78d91..1938af55d 100644 --- a/src/machines/appMachine.ts +++ b/src/machines/appMachine.ts @@ -1,9 +1,11 @@ -import { ActorRefFrom, createActor, setup, spawnChild } from 'xstate' -import { authMachine } from './authMachine' import { useSelector } from '@xstate/react' -import { ACTOR_IDS } from './machineConstants' -import { settingsMachine } from './settingsMachine' -import { createSettings } from 'lib/settings/initialSettings' +import type { ActorRefFrom } from 'xstate' +import { createActor, setup, spawnChild } from 'xstate' + +import { createSettings } from '@src/lib/settings/initialSettings' +import { authMachine } from '@src/machines/authMachine' +import { ACTOR_IDS } from '@src/machines/machineConstants' +import { settingsMachine } from '@src/machines/settingsMachine' const { AUTH, SETTINGS } = ACTOR_IDS const appMachineActors = { diff --git a/src/machines/authMachine.ts b/src/machines/authMachine.ts index 8e76ba838..66507e7f7 100644 --- a/src/machines/authMachine.ts +++ b/src/machines/authMachine.ts @@ -1,22 +1,25 @@ -import { assign, setup, fromPromise } from 'xstate' -import { Models } from '@kittycad/lib' -import withBaseURL from '../lib/withBaseURL' -import { isDesktop } from 'lib/isDesktop' +import type { Models } from '@kittycad/lib' import { + DEV, VITE_KC_API_BASE_URL, VITE_KC_DEV_TOKEN, VITE_KC_SKIP_AUTH, - DEV, -} from 'env' +} from '@src/env' +import { assign, fromPromise, setup } from 'xstate' + +import { COOKIE_NAME } from '@src/lib/constants' import { getUser as getUserDesktop, readTokenFile, writeTokenFile, -} from 'lib/desktop' -import { COOKIE_NAME } from 'lib/constants' -import { markOnce } from 'lib/performance' -import { ACTOR_IDS } from './machineConstants' -import withBaseUrl from '../lib/withBaseURL' +} from '@src/lib/desktop' +import { isDesktop } from '@src/lib/isDesktop' +import { markOnce } from '@src/lib/performance' +import { + default as withBaseURL, + default as withBaseUrl, +} from '@src/lib/withBaseURL' +import { ACTOR_IDS } from '@src/machines/machineConstants' const SKIP_AUTH = VITE_KC_SKIP_AUTH === 'true' && DEV diff --git a/src/machines/commandBarMachine.ts b/src/machines/commandBarMachine.ts index b8e1a0eb0..fb45c2f81 100644 --- a/src/machines/commandBarMachine.ts +++ b/src/machines/commandBarMachine.ts @@ -1,15 +1,17 @@ -import { assign, createActor, fromPromise, setup, SnapshotFrom } from 'xstate' -import { +import { useSelector } from '@xstate/react' +import toast from 'react-hot-toast' +import type { SnapshotFrom } from 'xstate' +import { assign, createActor, fromPromise, setup } from 'xstate' + +import type { MachineManager } from '@src/components/MachineManagerProvider' +import { authCommands } from '@src/lib/commandBarConfigs/authCommandConfig' +import type { Command, CommandArgument, CommandArgumentWithName, KclCommandValue, -} from 'lib/commandTypes' -import { getCommandArgumentKclValuesOnly } from 'lib/commandUtils' -import { MachineManager } from 'components/MachineManagerProvider' -import toast from 'react-hot-toast' -import { useSelector } from '@xstate/react' -import { authCommands } from 'lib/commandBarConfigs/authCommandConfig' +} from '@src/lib/commandTypes' +import { getCommandArgumentKclValuesOnly } from '@src/lib/commandUtils' export type CommandBarContext = { commands: Command[] @@ -134,10 +136,11 @@ export const commandBarMachine = setup({ // that is, the first argument that is not already in the argumentsToSubmit // or hidden, or that is not undefined, or that is not marked as "skippable". // TODO validate the type of the existing arguments - const nonHiddenArgs = Object.entries(selectedCommand.args).filter((a) => - a[1].hidden && typeof a[1].hidden === 'function' - ? !a[1].hidden(context) - : !a[1].hidden + const nonHiddenArgs = Object.entries(selectedCommand.args).filter( + (a) => + a[1].hidden && typeof a[1].hidden === 'function' + ? !a[1].hidden(context) + : !a[1].hidden ) let argIndex = 0 @@ -241,8 +244,8 @@ export const commandBarMachine = setup({ argName in event.data.argDefaultValues ? event.data.argDefaultValues[argName] : arg.skip && 'defaultValue' in arg - ? arg.defaultValue - : undefined + ? arg.defaultValue + : undefined } return args }, diff --git a/src/machines/featureTreeMachine.ts b/src/machines/featureTreeMachine.ts index b436a2a38..5f86651d7 100644 --- a/src/machines/featureTreeMachine.ts +++ b/src/machines/featureTreeMachine.ts @@ -1,21 +1,21 @@ -import { Artifact, getArtifactFromRange } from 'lang/std/artifactGraph' -import { SourceRange } from 'lang/wasm' -import { - enterAppearanceFlow, - enterEditFlow, - EnterEditFlowProps, -} from 'lib/operations' -import { kclManager } from 'lib/singletons' -import { err } from 'lib/trap' import toast from 'react-hot-toast' -import { Operation } from '@rust/kcl-lib/bindings/Operation' import { assign, fromPromise, setup } from 'xstate' -import { commandBarActor } from './commandBarMachine' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' + +import type { Operation } from '@rust/kcl-lib/bindings/Operation' + import { deleteSelectionPromise, deletionErrorMessage, -} from 'lang/modifyAst/deleteSelection' +} from '@src/lang/modifyAst/deleteSelection' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import type { Artifact } from '@src/lang/std/artifactGraph' +import { getArtifactFromRange } from '@src/lang/std/artifactGraph' +import type { SourceRange } from '@src/lang/wasm' +import type { EnterEditFlowProps } from '@src/lib/operations' +import { enterAppearanceFlow, enterEditFlow } from '@src/lib/operations' +import { kclManager } from '@src/lib/singletons' +import { err } from '@src/lib/trap' +import { commandBarActor } from '@src/machines/commandBarMachine' type FeatureTreeEvent = | { @@ -273,10 +273,10 @@ export const featureTreeMachine = setup({ src: 'prepareEditCommand', input: ({ context }) => { const artifact = context.targetSourceRange - ? getArtifactFromRange( + ? (getArtifactFromRange( context.targetSourceRange, kclManager.artifactGraph - ) ?? undefined + ) ?? undefined) : undefined return { // currentOperation is guaranteed to be defined here @@ -327,10 +327,10 @@ export const featureTreeMachine = setup({ src: 'prepareAppearanceCommand', input: ({ context }) => { const artifact = context.targetSourceRange - ? getArtifactFromRange( + ? (getArtifactFromRange( context.targetSourceRange, kclManager.artifactGraph - ) ?? undefined + ) ?? undefined) : undefined return { // currentOperation is guaranteed to be defined here @@ -381,10 +381,10 @@ export const featureTreeMachine = setup({ src: 'sendDeleteCommand', input: ({ context }) => { const artifact = context.targetSourceRange - ? getArtifactFromRange( + ? (getArtifactFromRange( context.targetSourceRange, kclManager.artifactGraph - ) ?? undefined + ) ?? undefined) : undefined return { artifact, diff --git a/src/machines/fileMachine.ts b/src/machines/fileMachine.ts index f628ed643..a200226c5 100644 --- a/src/machines/fileMachine.ts +++ b/src/machines/fileMachine.ts @@ -1,5 +1,6 @@ import { assign, fromPromise, setup } from 'xstate' -import { Project, FileEntry } from 'lib/project' + +import type { FileEntry, Project } from '@src/lib/project' type FileMachineContext = { project: Project diff --git a/src/machines/kclEditorMachine.ts b/src/machines/kclEditorMachine.ts index 86c16efe6..a23e32a0c 100644 --- a/src/machines/kclEditorMachine.ts +++ b/src/machines/kclEditorMachine.ts @@ -1,5 +1,6 @@ -import { assign, createActor, setup, StateFrom } from 'xstate' -import { EditorSelection } from '@codemirror/state' +import type { EditorSelection } from '@codemirror/state' +import type { StateFrom } from 'xstate' +import { assign, createActor, setup } from 'xstate' type SelectionEvent = { codeMirrorSelection: EditorSelection diff --git a/src/machines/modelingMachine.ts b/src/machines/modelingMachine.ts index f4b9da995..5db9c563a 100644 --- a/src/machines/modelingMachine.ts +++ b/src/machines/modelingMachine.ts @@ -1,4 +1,92 @@ +import toast from 'react-hot-toast' +import { Mesh, Vector2, Vector3 } from 'three' +import { assign, fromPromise, setup } from 'xstate' + +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { deleteSegment } from '@src/clientSideScene/ClientSideSceneComp' import { + orthoScale, + quaternionFromUpNForward, +} from '@src/clientSideScene/helpers' +import { DRAFT_DASHED_LINE } from '@src/clientSideScene/sceneConstants' +import { DRAFT_POINT } from '@src/clientSideScene/sceneInfra' +import { createProfileStartHandle } from '@src/clientSideScene/segments' +import type { MachineManager } from '@src/components/MachineManagerProvider' +import type { ModelingMachineContext } from '@src/components/ModelingMachineProvider' +import type { SidebarType } from '@src/components/ModelingSidebar/ModelingPanes' +import { + applyConstraintEqualAngle, + equalAngleInfo, +} from '@src/components/Toolbar/EqualAngle' +import { + applyConstraintEqualLength, + setEqualLengthInfo, +} from '@src/components/Toolbar/EqualLength' +import { + applyConstraintHorzVert, + horzVertInfo, +} from '@src/components/Toolbar/HorzVert' +import { intersectInfo } from '@src/components/Toolbar/Intersect' +import { + applyRemoveConstrainingValues, + removeConstrainingValuesInfo, +} from '@src/components/Toolbar/RemoveConstrainingValues' +import { + absDistanceInfo, + applyConstraintAxisAlign, +} from '@src/components/Toolbar/SetAbsDistance' +import { angleBetweenInfo } from '@src/components/Toolbar/SetAngleBetween' +import { + applyConstraintHorzVertAlign, + horzVertDistanceInfo, +} from '@src/components/Toolbar/SetHorzVertDistance' +import { angleLengthInfo } from '@src/components/Toolbar/setAngleLength' +import { createLiteral, createLocalName } from '@src/lang/create' +import { updateModelingState } from '@src/lang/modelingWorkflows' +import { + addHelix, + addOffsetPlane, + addShell, + addSweep, + deleteNodeInExtrudePipe, + extrudeSketch, + insertNamedConstant, + loftSketches, +} from '@src/lang/modifyAst' +import type { + ChamferParameters, + FilletParameters, +} from '@src/lang/modifyAst/addEdgeTreatment' +import { + EdgeTreatmentType, + applyEdgeTreatmentToSelection, + getPathToExtrudeForSegmentSelection, + mutateAstWithTagForSketchSegment, +} from '@src/lang/modifyAst/addEdgeTreatment' +import { + getAxisExpressionAndIndex, + revolveSketch, +} from '@src/lang/modifyAst/addRevolve' +import { + applyIntersectFromTargetOperatorSelections, + applySubtractFromTargetOperatorSelections, + applyUnionFromTargetOperatorSelections, +} from '@src/lang/modifyAst/boolean' +import { + deleteSelectionPromise, + deletionErrorMessage, +} from '@src/lang/modifyAst/deleteSelection' +import { setAppearance } from '@src/lang/modifyAst/setAppearance' +import { + getNodeFromPath, + isNodeSafeToReplacePath, + stringifyPathToNode, +} from '@src/lang/queryAst' +import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' +import { getPathsFromPlaneArtifact } from '@src/lang/std/artifactGraph' +import type { Coords2d } from '@src/lang/std/sketch' +import type { CallExpression, CallExpressionKw, Expr, @@ -7,112 +95,30 @@ import { PathToNode, VariableDeclaration, VariableDeclarator, - parse, - recast, - resultIsOk, - sketchFromKclValue, -} from 'lang/wasm' -import { +} from '@src/lang/wasm' +import { parse, recast, resultIsOk, sketchFromKclValue } from '@src/lang/wasm' +import type { ModelingCommandSchema } from '@src/lib/commandBarConfigs/modelingCommandConfig' +import type { KclCommandValue } from '@src/lib/commandTypes' +import { EXECUTION_TYPE_REAL } from '@src/lib/constants' +import type { DefaultPlaneStr } from '@src/lib/planes' +import type { Axis, DefaultPlaneSelection, - Selections, Selection, - updateSelections, -} from 'lib/selections' -import { assign, fromPromise, setup } from 'xstate' -import { SidebarType } from 'components/ModelingSidebar/ModelingPanes' -import { isNodeSafeToReplacePath, stringifyPathToNode } from 'lang/queryAst' -import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' + Selections, +} from '@src/lib/selections' +import { updateSelections } from '@src/lib/selections' import { - kclManager, - sceneInfra, - sceneEntitiesManager, - engineCommandManager, - editorManager, codeManager, -} from 'lib/singletons' -import { - horzVertInfo, - applyConstraintHorzVert, -} from 'components/Toolbar/HorzVert' -import { - applyConstraintHorzVertAlign, - horzVertDistanceInfo, -} from 'components/Toolbar/SetHorzVertDistance' -import { angleBetweenInfo } from 'components/Toolbar/SetAngleBetween' -import { angleLengthInfo } from 'components/Toolbar/setAngleLength' -import { - applyConstraintEqualLength, - setEqualLengthInfo, -} from 'components/Toolbar/EqualLength' -import { - getAxisExpressionAndIndex, - revolveSketch, -} from 'lang/modifyAst/addRevolve' -import { - addHelix, - addOffsetPlane, - addShell, - addSweep, - createLiteral, - createLocalName, - deleteNodeInExtrudePipe, - extrudeSketch, - insertNamedConstant, - loftSketches, -} from 'lang/modifyAst' -import { - applyEdgeTreatmentToSelection, - ChamferParameters, - EdgeTreatmentType, - FilletParameters, - getPathToExtrudeForSegmentSelection, - mutateAstWithTagForSketchSegment, -} from 'lang/modifyAst/addEdgeTreatment' -import { getNodeFromPath } from '../lang/queryAst' -import { - applyConstraintEqualAngle, - equalAngleInfo, -} from 'components/Toolbar/EqualAngle' -import { - applyRemoveConstrainingValues, - removeConstrainingValuesInfo, -} from 'components/Toolbar/RemoveConstrainingValues' -import { intersectInfo } from 'components/Toolbar/Intersect' -import { - absDistanceInfo, - applyConstraintAxisAlign, -} from 'components/Toolbar/SetAbsDistance' -import { ModelingCommandSchema } from 'lib/commandBarConfigs/modelingCommandConfig' -import { err, reportRejection, trap } from 'lib/trap' -import { DefaultPlaneStr } from 'lib/planes' -import { isArray, uuidv4 } from 'lib/utils' -import { Coords2d } from 'lang/std/sketch' -import { deleteSegment } from 'clientSideScene/ClientSideSceneComp' -import toast from 'react-hot-toast' -import { ToolbarModeName } from 'lib/toolbar' -import { orthoScale, quaternionFromUpNForward } from 'clientSideScene/helpers' -import { Mesh, Vector2, Vector3 } from 'three' -import { MachineManager } from 'components/MachineManagerProvider' -import { KclCommandValue } from 'lib/commandTypes' -import { ModelingMachineContext } from 'components/ModelingMachineProvider' -import { - deleteSelectionPromise, - deletionErrorMessage, -} from 'lang/modifyAst/deleteSelection' -import { getPathsFromPlaneArtifact } from 'lang/std/artifactGraph' -import { createProfileStartHandle } from 'clientSideScene/segments' -import { DRAFT_POINT } from 'clientSideScene/sceneInfra' -import { setAppearance } from 'lang/modifyAst/setAppearance' -import { DRAFT_DASHED_LINE } from 'clientSideScene/sceneEntities' -import { Node } from '@rust/kcl-lib/bindings/Node' -import { updateModelingState } from 'lang/modelingWorkflows' -import { EXECUTION_TYPE_REAL } from 'lib/constants' -import { - applyIntersectFromTargetOperatorSelections, - applySubtractFromTargetOperatorSelections, - applyUnionFromTargetOperatorSelections, -} from 'lang/modifyAst/boolean' + editorManager, + engineCommandManager, + kclManager, + sceneEntitiesManager, + sceneInfra, +} from '@src/lib/singletons' +import type { ToolbarModeName } from '@src/lib/toolbar' +import { err, reportRejection, trap } from '@src/lib/trap' +import { isArray, uuidv4 } from '@src/lib/utils' export const MODELING_PERSIST_KEY = 'MODELING_PERSIST_KEY' @@ -1107,8 +1113,8 @@ export const modelingMachine = setup({ currentTool === 'tangentialArc' ? { type: 'Continue existing profile', data } : currentTool === 'arc' - ? { type: 'Add start point', data } - : { type: 'Add start point', data } + ? { type: 'Add start point', data } + : { type: 'Add start point', data } ), }) }, diff --git a/src/machines/projectsMachine.ts b/src/machines/projectsMachine.ts index 7344259f6..1be6a2d71 100644 --- a/src/machines/projectsMachine.ts +++ b/src/machines/projectsMachine.ts @@ -1,7 +1,8 @@ import { assign, fromPromise, setup } from 'xstate' -import { ProjectsCommandSchema } from 'lib/commandBarConfigs/projectsCommandConfig' -import { Project } from 'lib/project' -import { isArray } from 'lib/utils' + +import type { ProjectsCommandSchema } from '@src/lib/commandBarConfigs/projectsCommandConfig' +import type { Project } from '@src/lib/project' +import { isArray } from '@src/lib/utils' export const projectsMachine = setup({ types: { diff --git a/src/machines/settingsMachine.ts b/src/machines/settingsMachine.ts index 758602ebd..270dce448 100644 --- a/src/machines/settingsMachine.ts +++ b/src/machines/settingsMachine.ts @@ -1,5 +1,7 @@ +import decamelize from 'decamelize' +import toast from 'react-hot-toast' +import type { AnyActorRef } from 'xstate' import { - AnyActorRef, assign, enqueueActions, fromCallback, @@ -7,25 +9,24 @@ import { sendTo, setup, } from 'xstate' + +import type { NamedView } from '@rust/kcl-lib/bindings/NamedView' + import { - Themes, - darkModeMatcher, - getOppositeTheme, - getSystemTheme, - setThemeClass, -} from 'lib/theme' -import { - createSettings, - settings, - SettingsType, -} from 'lib/settings/initialSettings' -import { + createSettingsCommand, + settingsWithCommandConfigs, +} from '@src/lib/commandBarConfigs/settingsCommandConfig' +import type { Command } from '@src/lib/commandTypes' +import type { Project } from '@src/lib/project' +import type { SettingsType } from '@src/lib/settings/initialSettings' +import { createSettings, settings } from '@src/lib/settings/initialSettings' +import type { BaseUnit, SetEventTypes, SettingsLevel, SettingsPaths, WildcardSetEvent, -} from 'lib/settings/settingsTypes' +} from '@src/lib/settings/settingsTypes' import { clearSettingsAtLevel, configurationToSettingsPayload, @@ -33,25 +34,23 @@ import { projectConfigurationToSettingsPayload, saveSettings, setSettingsAtLevel, -} from 'lib/settings/settingsUtils' -import { NamedView } from '@rust/kcl-lib/bindings/NamedView' +} from '@src/lib/settings/settingsUtils' import { codeManager, engineCommandManager, kclManager, sceneEntitiesManager, sceneInfra, -} from 'lib/singletons' -import toast from 'react-hot-toast' -import decamelize from 'decamelize' -import { reportRejection } from 'lib/trap' -import { Project } from 'lib/project' +} from '@src/lib/singletons' import { - createSettingsCommand, - settingsWithCommandConfigs, -} from 'lib/commandBarConfigs/settingsCommandConfig' -import { Command } from 'lib/commandTypes' -import { commandBarActor } from './commandBarMachine' + Themes, + darkModeMatcher, + getOppositeTheme, + getSystemTheme, + setThemeClass, +} from '@src/lib/theme' +import { reportRejection } from '@src/lib/trap' +import { commandBarActor } from '@src/machines/commandBarMachine' type SettingsMachineContext = SettingsType & { currentProject?: Project @@ -206,7 +205,7 @@ export const settingsMachine = setup({ if (!('data' in event)) return const eventParts = event.type.replace(/^set./, '').split('.') as [ keyof typeof settings, - string + string, ] const truncatedNewValue = event.data.value?.toString().slice(0, 28) const message = diff --git a/src/main.ts b/src/main.ts index aa0697f47..849938526 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,41 +1,43 @@ // Some of the following was taken from bits and pieces of the vite-typescript // template that ElectronJS provides. -import dotenv from 'dotenv' -import { - app, - BrowserWindow, - ipcMain, - dialog, - shell, - nativeTheme, - desktopCapturer, - systemPreferences, - Menu, - screen, -} from 'electron' -import path from 'path' -import { Issuer } from 'openid-client' -import { Bonjour, Service } from 'bonjour-service' // @ts-ignore: TS1343 import * as kittycad from '@kittycad/lib/import' +import * as packageJSON from '@root/package.json' +import type { Service } from 'bonjour-service' +import { Bonjour } from 'bonjour-service' +import dotenv from 'dotenv' +import { + BrowserWindow, + Menu, + app, + desktopCapturer, + dialog, + ipcMain, + nativeTheme, + screen, + shell, + systemPreferences, +} from 'electron' import electronUpdater, { type AppUpdater } from 'electron-updater' -import getCurrentProjectFile from 'lib/getCurrentProjectFile' import os from 'node:os' -import { reportRejection } from 'lib/trap' -import { ZOO_STUDIO_PROTOCOL } from 'lib/constants' +import { Issuer } from 'openid-client' +import path from 'path' + import { argvFromYargs, getPathOrUrlFromArgs, parseCLIArgs, -} from './commandLineArgs' -import * as packageJSON from '../package.json' +} from '@src/commandLineArgs' +import { ZOO_STUDIO_PROTOCOL } from '@src/lib/constants' +import getCurrentProjectFile from '@src/lib/getCurrentProjectFile' +import { reportRejection } from '@src/lib/trap' import { buildAndSetMenuForFallback, buildAndSetMenuForModelingPage, buildAndSetMenuForProjectPage, - enableMenu, disableMenu, -} from './menu' + enableMenu, +} from '@src/menu' let mainWindow: BrowserWindow | null = null @@ -369,10 +371,7 @@ ipcMain.handle('startDeviceFlow', async (_, host: string) => { ipcMain.handle('kittycad', (event, data) => { return data.access .split('.') - .reduce( - (obj: any, prop: any) => obj[prop], - kittycad - )(data.args) + .reduce((obj: any, prop: any) => obj[prop], kittycad)(data.args) }) // Used to find other devices on the local network, e.g. 3D printers, CNC machines, etc. diff --git a/src/menu.ts b/src/menu.ts index 8384916de..c3a47557a 100644 --- a/src/menu.ts +++ b/src/menu.ts @@ -1,11 +1,13 @@ -import { app, Menu, BrowserWindow } from 'electron' -import { projectFileRole } from 'menu/fileRole' -import { projectEditRole } from 'menu/editRole' -import { helpRole } from 'menu/helpRole' -import { projectViewRole } from 'menu/viewRole' - +import type { BrowserWindow } from 'electron' +import { Menu, app } from 'electron' import os from 'node:os' -import { ZooMenuItemConstructorOptions } from 'menu/roles' + +import { projectEditRole } from '@src/menu/editRole' +import { projectFileRole } from '@src/menu/fileRole' +import { helpRole } from '@src/menu/helpRole' +import type { ZooMenuItemConstructorOptions } from '@src/menu/roles' +import { projectViewRole } from '@src/menu/viewRole' + const isMac = os.platform() === 'darwin' // Default electron menu. diff --git a/src/menu/channels.ts b/src/menu/channels.ts index b01dde3bd..84a96d394 100644 --- a/src/menu/channels.ts +++ b/src/menu/channels.ts @@ -1,5 +1,6 @@ -import { BrowserWindow } from 'electron' -import type { Channel } from '../channels' +import type { BrowserWindow } from 'electron' + +import type { Channel } from '@src/channels' // types for knowing what menu sends what webContent payload export type MenuLabels = diff --git a/src/menu/editRole.ts b/src/menu/editRole.ts index b19b59dda..1d2f42059 100644 --- a/src/menu/editRole.ts +++ b/src/menu/editRole.ts @@ -1,7 +1,9 @@ -import { BrowserWindow } from 'electron' -import { typeSafeWebContentsSend } from './channels' +import type { BrowserWindow } from 'electron' import os from 'node:os' -import { ZooMenuItemConstructorOptions } from './roles' + +import { typeSafeWebContentsSend } from '@src/menu/channels' +import type { ZooMenuItemConstructorOptions } from '@src/menu/roles' + const isMac = os.platform() === 'darwin' export const projectEditRole = ( diff --git a/src/menu/fileRole.ts b/src/menu/fileRole.ts index 295661301..4c2e0e63b 100644 --- a/src/menu/fileRole.ts +++ b/src/menu/fileRole.ts @@ -1,7 +1,9 @@ -import { BrowserWindow } from 'electron' -import { typeSafeWebContentsSend } from './channels' -import { ZooMenuItemConstructorOptions } from './roles' +import type { BrowserWindow } from 'electron' import os from 'node:os' + +import { typeSafeWebContentsSend } from '@src/menu/channels' +import type { ZooMenuItemConstructorOptions } from '@src/menu/roles' + const isMac = os.platform() === 'darwin' export const projectFileRole = ( diff --git a/src/menu/helpRole.ts b/src/menu/helpRole.ts index ff4d84325..5c10687f6 100644 --- a/src/menu/helpRole.ts +++ b/src/menu/helpRole.ts @@ -1,7 +1,9 @@ -import { shell, BrowserWindow } from 'electron' -import { ZooMenuItemConstructorOptions } from './roles' -import { reportRejection } from 'lib/trap' -import { typeSafeWebContentsSend } from './channels' +import type { BrowserWindow } from 'electron' +import { shell } from 'electron' + +import { reportRejection } from '@src/lib/trap' +import { typeSafeWebContentsSend } from '@src/menu/channels' +import type { ZooMenuItemConstructorOptions } from '@src/menu/roles' export const helpRole = ( mainWindow: BrowserWindow diff --git a/src/menu/roles.ts b/src/menu/roles.ts index e2a843a70..b04daa4d7 100644 --- a/src/menu/roles.ts +++ b/src/menu/roles.ts @@ -1,6 +1,6 @@ // Does not matter what labels belong to what type. I only split these into some internal types to easily parse // what labels should belong to what grouping -import { Menu, MenuItemConstructorOptions } from 'electron' +import type { Menu, MenuItemConstructorOptions } from 'electron' type HeaderLabel = | 'File' diff --git a/src/menu/viewRole.ts b/src/menu/viewRole.ts index 5e16746d9..ea901b716 100644 --- a/src/menu/viewRole.ts +++ b/src/menu/viewRole.ts @@ -1,7 +1,9 @@ -import { BrowserWindow } from 'electron' -import { ZooMenuItemConstructorOptions } from './roles' -import { typeSafeWebContentsSend } from './channels' +import type { BrowserWindow } from 'electron' import os from 'node:os' + +import { typeSafeWebContentsSend } from '@src/menu/channels' +import type { ZooMenuItemConstructorOptions } from '@src/menu/roles' + const isMac = os.platform() === 'darwin' export const projectViewRole = ( diff --git a/src/preload.ts b/src/preload.ts index abcbd425c..0cf65d788 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -1,13 +1,15 @@ -import { ipcRenderer, contextBridge, IpcRendererEvent } from 'electron' -import path from 'path' +import packageJson from '@root/package.json' +import type { MachinesListing } from '@src/components/MachineManagerProvider' +import chokidar from 'chokidar' +import type { IpcRendererEvent } from 'electron' +import { contextBridge, ipcRenderer } from 'electron' +import fsSync from 'node:fs' import fs from 'node:fs/promises' import os from 'node:os' -import fsSync from 'node:fs' -import packageJson from '../package.json' -import { MachinesListing } from 'components/MachineManagerProvider' -import chokidar from 'chokidar' -import type { Channel } from './channels' -import type { WebContentSendPayload } from './menu/channels' +import path from 'path' + +import type { Channel } from '@src/channels' +import type { WebContentSendPayload } from '@src/menu/channels' const typeSafeIpcRendererOn = ( channel: Channel, diff --git a/src/reportWebVitals.ts b/src/reportWebVitals.ts index 918338364..af6501be0 100644 --- a/src/reportWebVitals.ts +++ b/src/reportWebVitals.ts @@ -1,5 +1,5 @@ -import { reportRejection } from 'lib/trap' -import { ReportHandler } from 'web-vitals' +import { reportRejection } from '@src/lib/trap' +import type { ReportHandler } from 'web-vitals' const reportWebVitals = (onPerfEntry?: ReportHandler) => { if (onPerfEntry && onPerfEntry instanceof Function) { diff --git a/src/routes/Home.tsx b/src/routes/Home.tsx index c3bed4479..385251f7f 100644 --- a/src/routes/Home.tsx +++ b/src/routes/Home.tsx @@ -1,32 +1,35 @@ -import { FormEvent, useEffect, useRef, useState } from 'react' -import { ActionButton } from 'components/ActionButton' -import { AppHeader } from 'components/AppHeader' -import ProjectCard from 'components/ProjectCard/ProjectCard' -import { useNavigate, useSearchParams } from 'react-router-dom' -import { Link } from 'react-router-dom' +import type { FormEvent } from 'react' +import { useEffect, useRef, useState } from 'react' import { toast } from 'react-hot-toast' -import Loading from 'components/Loading' -import { PATHS } from 'lib/paths' +import { useHotkeys } from 'react-hotkeys-hook' +import { Link, useNavigate, useSearchParams } from 'react-router-dom' + +import { ActionButton } from '@src/components/ActionButton' +import { AppHeader } from '@src/components/AppHeader' +import Loading from '@src/components/Loading' +import { LowerRightControls } from '@src/components/LowerRightControls' +import ProjectCard from '@src/components/ProjectCard/ProjectCard' +import { + ProjectSearchBar, + useProjectSearch, +} from '@src/components/ProjectSearchBar' +import { useCreateFileLinkQuery } from '@src/hooks/useCreateFileLinkQueryWatcher' +import { useMenuListener } from '@src/hooks/useMenu' +import { useProjectsContext } from '@src/hooks/useProjectsContext' +import { isDesktop } from '@src/lib/isDesktop' +import { PATHS } from '@src/lib/paths' +import { markOnce } from '@src/lib/performance' +import type { Project } from '@src/lib/project' +import { kclManager } from '@src/lib/singletons' import { getNextSearchParams, getSortFunction, getSortIcon, -} from '../lib/sorting' -import { useHotkeys } from 'react-hotkeys-hook' -import { isDesktop } from 'lib/isDesktop' -import { kclManager } from 'lib/singletons' -import { LowerRightControls } from 'components/LowerRightControls' -import { ProjectSearchBar, useProjectSearch } from 'components/ProjectSearchBar' -import { Project } from 'lib/project' -import { markOnce } from 'lib/performance' -import { useProjectsContext } from 'hooks/useProjectsContext' -import { commandBarActor } from 'machines/commandBarMachine' -import { useCreateFileLinkQuery } from 'hooks/useCreateFileLinkQueryWatcher' -import { useSettings } from 'machines/appMachine' -import { reportRejection } from 'lib/trap' -import { authActor } from 'machines/appMachine' -import type { WebContentSendPayload } from '../menu/channels' -import { useMenuListener } from 'hooks/useMenu' +} from '@src/lib/sorting' +import { reportRejection } from '@src/lib/trap' +import { authActor, useSettings } from '@src/machines/appMachine' +import { commandBarActor } from '@src/machines/commandBarMachine' +import type { WebContentSendPayload } from '@src/menu/channels' // This route only opens in the desktop context for now, // as defined in Router.tsx, so we can use the desktop APIs and types. diff --git a/src/routes/Onboarding/Camera.tsx b/src/routes/Onboarding/Camera.tsx index 19aa6a19a..04e7b50fd 100644 --- a/src/routes/Onboarding/Camera.tsx +++ b/src/routes/Onboarding/Camera.tsx @@ -1,12 +1,14 @@ -import { OnboardingButtons, useDismiss, useNextClick } from '.' -import { onboardingPaths } from 'routes/Onboarding/paths' +import { SettingsSection } from '@src/components/Settings/SettingsSection' +import type { CameraSystem } from '@src/lib/cameraControls' +import { cameraMouseDragGuards, cameraSystems } from '@src/lib/cameraControls' +import { settingsActor, useSettings } from '@src/machines/appMachine' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + import { - CameraSystem, - cameraMouseDragGuards, - cameraSystems, -} from 'lib/cameraControls' -import { SettingsSection } from 'components/Settings/SettingsSection' -import { settingsActor, useSettings } from 'machines/appMachine' + OnboardingButtons, + useDismiss, + useNextClick, +} from '@src/routes/Onboarding/utils' export default function Units() { useDismiss() diff --git a/src/routes/Onboarding/CmdK.tsx b/src/routes/Onboarding/CmdK.tsx index 1ed836eb0..29610c9ac 100644 --- a/src/routes/Onboarding/CmdK.tsx +++ b/src/routes/Onboarding/CmdK.tsx @@ -1,8 +1,9 @@ -import usePlatform from 'hooks/usePlatform' -import { OnboardingButtons, kbdClasses } from '.' -import { onboardingPaths } from 'routes/Onboarding/paths' -import { hotkeyDisplay } from 'lib/hotkeyWrapper' -import { COMMAND_PALETTE_HOTKEY } from 'components/CommandBar/CommandBar' +import { COMMAND_PALETTE_HOTKEY } from '@src/components/CommandBar/CommandBar' +import usePlatform from '@src/hooks/usePlatform' +import { hotkeyDisplay } from '@src/lib/hotkeyWrapper' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + +import { OnboardingButtons, kbdClasses } from '@src/routes/Onboarding/utils' export default function CmdK() { const platformName = usePlatform() diff --git a/src/routes/Onboarding/CodeEditor.tsx b/src/routes/Onboarding/CodeEditor.tsx index 9af30860c..e0e4e47fb 100644 --- a/src/routes/Onboarding/CodeEditor.tsx +++ b/src/routes/Onboarding/CodeEditor.tsx @@ -1,5 +1,10 @@ -import { kbdClasses, OnboardingButtons, useDemoCode } from '.' -import { onboardingPaths } from 'routes/Onboarding/paths' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + +import { + OnboardingButtons, + kbdClasses, + useDemoCode, +} from '@src/routes/Onboarding/utils' export default function OnboardingCodeEditor() { useDemoCode() diff --git a/src/routes/Onboarding/Export.tsx b/src/routes/Onboarding/Export.tsx index c71455080..5d14b4d87 100644 --- a/src/routes/Onboarding/Export.tsx +++ b/src/routes/Onboarding/Export.tsx @@ -1,6 +1,7 @@ -import { APP_NAME } from 'lib/constants' -import { OnboardingButtons } from '.' -import { onboardingPaths } from 'routes/Onboarding/paths' +import { APP_NAME } from '@src/lib/constants' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + +import { OnboardingButtons } from '@src/routes/Onboarding/utils' export default function Export() { return ( diff --git a/src/routes/Onboarding/FutureWork.tsx b/src/routes/Onboarding/FutureWork.tsx index 4be5e0fce..fa2756adf 100644 --- a/src/routes/Onboarding/FutureWork.tsx +++ b/src/routes/Onboarding/FutureWork.tsx @@ -1,9 +1,11 @@ -import { OnboardingButtons, useDemoCode } from '.' import { useEffect } from 'react' -import { useModelingContext } from 'hooks/useModelingContext' -import { APP_NAME } from 'lib/constants' -import { onboardingPaths } from './paths' -import { sceneInfra } from 'lib/singletons' + +import { useModelingContext } from '@src/hooks/useModelingContext' +import { APP_NAME } from '@src/lib/constants' +import { sceneInfra } from '@src/lib/singletons' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + +import { OnboardingButtons, useDemoCode } from '@src/routes/Onboarding/utils' export default function FutureWork() { const { send } = useModelingContext() diff --git a/src/routes/Onboarding/InteractiveNumbers.tsx b/src/routes/Onboarding/InteractiveNumbers.tsx index d8a6cb0c5..0b9017f8d 100644 --- a/src/routes/Onboarding/InteractiveNumbers.tsx +++ b/src/routes/Onboarding/InteractiveNumbers.tsx @@ -1,6 +1,11 @@ -import { OnboardingButtons, kbdClasses, useDemoCode } from '.' -import { onboardingPaths } from 'routes/Onboarding/paths' -import { bracketWidthConstantLine } from 'lib/exampleKcl' +import { bracketWidthConstantLine } from '@src/lib/exampleKcl' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + +import { + kbdClasses, + OnboardingButtons, + useDemoCode, +} from '@src/routes/Onboarding/utils' export default function OnboardingInteractiveNumbers() { useDemoCode() diff --git a/src/routes/Onboarding/Introduction.tsx b/src/routes/Onboarding/Introduction.tsx index c3103d12c..860a0ca13 100644 --- a/src/routes/Onboarding/Introduction.tsx +++ b/src/routes/Onboarding/Introduction.tsx @@ -1,20 +1,22 @@ -import { OnboardingButtons, useDemoCode } from '.' -import { onboardingPaths } from 'routes/Onboarding/paths' -import { Themes, getSystemTheme } from 'lib/theme' -import { bracket } from 'lib/exampleKcl' -import { createAndOpenNewTutorialProject } from 'lib/desktopFS' -import { isDesktop } from 'lib/isDesktop' -import { useNavigate, useRouteLoaderData } from 'react-router-dom' -import { codeManager, kclManager } from 'lib/singletons' -import { APP_NAME } from 'lib/constants' import { useEffect, useState } from 'react' -import { IndexLoaderData } from 'lib/types' -import { PATHS } from 'lib/paths' -import { useFileContext } from 'hooks/useFileContext' -import { useLspContext } from 'components/LspProvider' -import { reportRejection } from 'lib/trap' -import { useSettings } from 'machines/appMachine' -import { isKclEmptyOrOnlySettings } from 'lang/wasm' +import { useNavigate, useRouteLoaderData } from 'react-router-dom' + +import { useLspContext } from '@src/components/LspProvider' +import { useFileContext } from '@src/hooks/useFileContext' +import { isKclEmptyOrOnlySettings } from '@src/lang/wasm' +import { APP_NAME } from '@src/lib/constants' +import { createAndOpenNewTutorialProject } from '@src/lib/desktopFS' +import { bracket } from '@src/lib/exampleKcl' +import { isDesktop } from '@src/lib/isDesktop' +import { PATHS } from '@src/lib/paths' +import { codeManager, kclManager } from '@src/lib/singletons' +import { Themes, getSystemTheme } from '@src/lib/theme' +import { reportRejection } from '@src/lib/trap' +import type { IndexLoaderData } from '@src/lib/types' +import { useSettings } from '@src/machines/appMachine' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + +import { OnboardingButtons, useDemoCode } from '@src/routes/Onboarding/utils' /** * Show either a welcome screen or a warning screen diff --git a/src/routes/Onboarding/ParametricModeling.tsx b/src/routes/Onboarding/ParametricModeling.tsx index ae13f1ef1..4360b5067 100644 --- a/src/routes/Onboarding/ParametricModeling.tsx +++ b/src/routes/Onboarding/ParametricModeling.tsx @@ -1,9 +1,10 @@ -import { OnboardingButtons, useDemoCode } from '.' -import { onboardingPaths } from 'routes/Onboarding/paths' -import { Themes, getSystemTheme } from 'lib/theme' -import { bracketThicknessCalculationLine } from 'lib/exampleKcl' -import { isDesktop } from 'lib/isDesktop' -import { useSettings } from 'machines/appMachine' +import { bracketThicknessCalculationLine } from '@src/lib/exampleKcl' +import { isDesktop } from '@src/lib/isDesktop' +import { Themes, getSystemTheme } from '@src/lib/theme' +import { useSettings } from '@src/machines/appMachine' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + +import { OnboardingButtons, useDemoCode } from '@src/routes/Onboarding/utils' export default function OnboardingParametricModeling() { useDemoCode() diff --git a/src/routes/Onboarding/ProjectMenu.tsx b/src/routes/Onboarding/ProjectMenu.tsx index db02afc26..6e2ebe976 100644 --- a/src/routes/Onboarding/ProjectMenu.tsx +++ b/src/routes/Onboarding/ProjectMenu.tsx @@ -1,6 +1,7 @@ -import { OnboardingButtons } from '.' -import { onboardingPaths } from 'routes/Onboarding/paths' -import { isDesktop } from 'lib/isDesktop' +import { isDesktop } from '@src/lib/isDesktop' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + +import { OnboardingButtons } from '@src/routes/Onboarding/utils' export default function ProjectMenu() { const onDesktop = isDesktop() diff --git a/src/routes/Onboarding/Sketching.tsx b/src/routes/Onboarding/Sketching.tsx index 7129ee196..b3cf1bc12 100644 --- a/src/routes/Onboarding/Sketching.tsx +++ b/src/routes/Onboarding/Sketching.tsx @@ -1,7 +1,9 @@ -import { OnboardingButtons } from '.' -import { onboardingPaths } from 'routes/Onboarding/paths' import { useEffect } from 'react' -import { codeManager, kclManager } from 'lib/singletons' + +import { codeManager, kclManager } from '@src/lib/singletons' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + +import { OnboardingButtons } from '@src/routes/Onboarding/utils' export default function Sketching() { useEffect(() => { diff --git a/src/routes/Onboarding/Streaming.tsx b/src/routes/Onboarding/Streaming.tsx index bd0028152..4dfec2e72 100644 --- a/src/routes/Onboarding/Streaming.tsx +++ b/src/routes/Onboarding/Streaming.tsx @@ -1,5 +1,6 @@ -import { OnboardingButtons } from '.' -import { onboardingPaths } from 'routes/Onboarding/paths' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + +import { OnboardingButtons } from '@src/routes/Onboarding/utils' export default function Streaming() { return ( diff --git a/src/routes/Onboarding/Units.tsx b/src/routes/Onboarding/Units.tsx index 7ec94ac34..82e16235b 100644 --- a/src/routes/Onboarding/Units.tsx +++ b/src/routes/Onboarding/Units.tsx @@ -1,10 +1,12 @@ import { faArrowRight, faXmark } from '@fortawesome/free-solid-svg-icons' -import { type BaseUnit, baseUnitsUnion } from 'lib/settings/settingsTypes' -import { ActionButton } from 'components/ActionButton' -import { SettingsSection } from 'components/Settings/SettingsSection' -import { useDismiss, useNextClick } from '.' -import { onboardingPaths } from 'routes/Onboarding/paths' -import { settingsActor, useSettings } from 'machines/appMachine' + +import { ActionButton } from '@src/components/ActionButton' +import { SettingsSection } from '@src/components/Settings/SettingsSection' +import { type BaseUnit, baseUnitsUnion } from '@src/lib/settings/settingsTypes' +import { settingsActor, useSettings } from '@src/machines/appMachine' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + +import { useDismiss, useNextClick } from '@src/routes/Onboarding/utils' export default function Units() { const dismiss = useDismiss() diff --git a/src/routes/Onboarding/UserMenu.tsx b/src/routes/Onboarding/UserMenu.tsx index ca2448c1b..30849812a 100644 --- a/src/routes/Onboarding/UserMenu.tsx +++ b/src/routes/Onboarding/UserMenu.tsx @@ -1,7 +1,9 @@ -import { OnboardingButtons } from '.' -import { onboardingPaths } from 'routes/Onboarding/paths' import { useEffect, useState } from 'react' -import { useUser } from 'machines/appMachine' + +import { useUser } from '@src/machines/appMachine' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + +import { OnboardingButtons } from '@src/routes/Onboarding/utils' export default function UserMenu() { const user = useUser() diff --git a/src/routes/Onboarding/index.tsx b/src/routes/Onboarding/index.tsx index c867e74fc..1652d70ac 100644 --- a/src/routes/Onboarding/index.tsx +++ b/src/routes/Onboarding/index.tsx @@ -1,37 +1,21 @@ import { useHotkeys } from 'react-hotkeys-hook' -import { Outlet, useNavigate } from 'react-router-dom' -import Introduction from './Introduction' -import Camera from './Camera' -import Sketching from './Sketching' -import { useCallback, useEffect } from 'react' -import makeUrlPathRelative from '../../lib/makeUrlPathRelative' -import Streaming from './Streaming' -import CodeEditor from './CodeEditor' -import ParametricModeling from './ParametricModeling' -import InteractiveNumbers from './InteractiveNumbers' -import CmdK from './CmdK' -import UserMenu from './UserMenu' -import ProjectMenu from './ProjectMenu' -import Export from './Export' -import FutureWork from './FutureWork' -import { PATHS } from 'lib/paths' -import { useAbsoluteFilePath } from 'hooks/useAbsoluteFilePath' -import { ActionButton } from 'components/ActionButton' -import { onboardingPaths } from 'routes/Onboarding/paths' -import { codeManager, editorManager, kclManager } from 'lib/singletons' -import { bracket } from 'lib/exampleKcl' -import { toSync } from 'lib/utils' -import { reportRejection } from 'lib/trap' -import { useNetworkContext } from 'hooks/useNetworkContext' -import { NetworkHealthState } from 'hooks/useNetworkStatus' -import { EngineConnectionStateType } from 'lang/std/engineConnection' -import { settingsActor } from 'machines/appMachine' -import { CustomIcon } from 'components/CustomIcon' -import Tooltip from 'components/Tooltip' -import { waitFor } from 'xstate' +import { Outlet } from 'react-router-dom' -export const kbdClasses = - 'py-0.5 px-1 text-sm rounded bg-chalkboard-10 dark:bg-chalkboard-100 border border-chalkboard-50 border-b-2' +import makeUrlPathRelative from '@src/lib/makeUrlPathRelative' +import Camera from '@src/routes/Onboarding/Camera' +import CmdK from '@src/routes/Onboarding/CmdK' +import CodeEditor from '@src/routes/Onboarding/CodeEditor' +import Export from '@src/routes/Onboarding/Export' +import FutureWork from '@src/routes/Onboarding/FutureWork' +import InteractiveNumbers from '@src/routes/Onboarding/InteractiveNumbers' +import Introduction from '@src/routes/Onboarding/Introduction' +import ParametricModeling from '@src/routes/Onboarding/ParametricModeling' +import ProjectMenu from '@src/routes/Onboarding/ProjectMenu' +import Sketching from '@src/routes/Onboarding/Sketching' +import Streaming from '@src/routes/Onboarding/Streaming' +import UserMenu from '@src/routes/Onboarding/UserMenu' +import { onboardingPaths } from '@src/routes/Onboarding/paths' +import { useDismiss } from '@src/routes/Onboarding/utils' export const onboardingRoutes = [ { @@ -85,168 +69,6 @@ export const onboardingRoutes = [ }, ] -export function useDemoCode() { - const { overallState, immediateState } = useNetworkContext() - - useEffect(() => { - // Don't run if the editor isn't loaded or the code is already the bracket - if (!editorManager.editorView || codeManager.code === bracket) { - return - } - // Don't run if the network isn't healthy or the connection isn't established - if ( - overallState !== NetworkHealthState.Ok || - immediateState.type !== EngineConnectionStateType.ConnectionEstablished - ) { - return - } - setTimeout( - toSync(async () => { - codeManager.updateCodeStateEditor(bracket) - await kclManager.executeCode(true) - await codeManager.writeToFile() - }, reportRejection) - ) - }, [editorManager.editorView, immediateState, overallState]) -} - -export function useNextClick(newStatus: string) { - const filePath = useAbsoluteFilePath() - const navigate = useNavigate() - - return useCallback(() => { - settingsActor.send({ - type: 'set.app.onboardingStatus', - data: { level: 'user', value: newStatus }, - }) - navigate(filePath + PATHS.ONBOARDING.INDEX.slice(0, -1) + newStatus) - }, [filePath, newStatus, settingsActor.send, navigate]) -} - -export function useDismiss() { - const filePath = useAbsoluteFilePath() - const send = settingsActor.send - const navigate = useNavigate() - - const settingsCallback = useCallback(() => { - send({ - type: 'set.app.onboardingStatus', - data: { level: 'user', value: 'dismissed' }, - }) - waitFor(settingsActor, (state) => state.matches('idle')) - .then(() => navigate(filePath)) - .catch(reportRejection) - }, [send]) - - return settingsCallback -} - -// Get the 1-indexed step number of the current onboarding step -export function useStepNumber( - slug?: (typeof onboardingPaths)[keyof typeof onboardingPaths] -) { - return slug - ? slug === onboardingPaths.INDEX - ? 1 - : onboardingRoutes.findIndex( - (r) => r.path === makeUrlPathRelative(slug) - ) + 1 - : 1 -} - -export function OnboardingButtons({ - currentSlug, - className, - dismissClassName, - onNextOverride, - ...props -}: { - currentSlug?: (typeof onboardingPaths)[keyof typeof onboardingPaths] - className?: string - dismissClassName?: string - onNextOverride?: () => void -} & React.HTMLAttributes) { - const dismiss = useDismiss() - const stepNumber = useStepNumber(currentSlug) - const previousStep = - !stepNumber || stepNumber === 0 ? null : onboardingRoutes[stepNumber - 2] - const goToPrevious = useNextClick( - onboardingPaths.INDEX + (previousStep?.path ?? '') - ) - const nextStep = - !stepNumber || stepNumber === onboardingRoutes.length - ? null - : onboardingRoutes[stepNumber] - const goToNext = useNextClick(onboardingPaths.INDEX + (nextStep?.path ?? '')) - - return ( - <> - -
- - previousStep?.path || previousStep?.index - ? goToPrevious() - : dismiss() - } - iconStart={{ - icon: previousStep ? 'arrowLeft' : 'close', - className: 'text-chalkboard-10', - bgClassName: 'bg-destroy-80 group-hover:bg-destroy-80', - }} - className="hover:border-destroy-40 hover:bg-destroy-10/50 dark:hover:bg-destroy-80/50" - data-testid="onboarding-prev" - > - {previousStep ? `Back` : 'Dismiss'} - - {stepNumber !== undefined && ( -

- {stepNumber} / {onboardingRoutes.length} -

- )} - { - if (nextStep?.path) { - onNextOverride ? onNextOverride() : goToNext() - } else { - dismiss() - } - }} - iconStart={{ - icon: nextStep ? 'arrowRight' : 'checkmark', - bgClassName: 'dark:bg-chalkboard-80', - }} - className="dark:hover:bg-chalkboard-80/50" - data-testid="onboarding-next" - > - {nextStep ? `Next` : 'Finish'} - -
- - ) -} - const Onboarding = () => { const dismiss = useDismiss() useHotkeys('esc', dismiss) diff --git a/src/routes/Onboarding/paths.ts b/src/routes/Onboarding/paths.ts index 8e92107a6..f8a069331 100644 --- a/src/routes/Onboarding/paths.ts +++ b/src/routes/Onboarding/paths.ts @@ -1,4 +1,4 @@ -import { OnboardingStatus } from '@rust/kcl-lib/bindings/OnboardingStatus' +import type { OnboardingStatus } from '@rust/kcl-lib/bindings/OnboardingStatus' export const onboardingPaths: Record = { INDEX: '/', diff --git a/src/routes/Onboarding/utils.tsx b/src/routes/Onboarding/utils.tsx new file mode 100644 index 000000000..1536390cf --- /dev/null +++ b/src/routes/Onboarding/utils.tsx @@ -0,0 +1,184 @@ +import { useCallback, useEffect } from 'react' +import { useNavigate } from 'react-router-dom' +import { waitFor } from 'xstate' + +import { ActionButton } from '@src/components/ActionButton' +import { CustomIcon } from '@src/components/CustomIcon' +import Tooltip from '@src/components/Tooltip' +import { useAbsoluteFilePath } from '@src/hooks/useAbsoluteFilePath' +import { useNetworkContext } from '@src/hooks/useNetworkContext' +import { NetworkHealthState } from '@src/hooks/useNetworkStatus' +import { EngineConnectionStateType } from '@src/lang/std/engineConnection' +import { bracket } from '@src/lib/exampleKcl' +import makeUrlPathRelative from '@src/lib/makeUrlPathRelative' +import { PATHS } from '@src/lib/paths' +import { codeManager, editorManager, kclManager } from '@src/lib/singletons' +import { reportRejection } from '@src/lib/trap' +import { toSync } from '@src/lib/utils' +import { settingsActor } from '@src/machines/appMachine' +import { onboardingRoutes } from '@src/routes/Onboarding' +import { onboardingPaths } from '@src/routes/Onboarding/paths' + +export const kbdClasses = + 'py-0.5 px-1 text-sm rounded bg-chalkboard-10 dark:bg-chalkboard-100 border border-chalkboard-50 border-b-2' + +// Get the 1-indexed step number of the current onboarding step +function useStepNumber( + slug?: (typeof onboardingPaths)[keyof typeof onboardingPaths] +) { + return slug + ? slug === onboardingPaths.INDEX + ? 1 + : onboardingRoutes.findIndex( + (r) => r.path === makeUrlPathRelative(slug) + ) + 1 + : 1 +} + +export function useDemoCode() { + const { overallState, immediateState } = useNetworkContext() + + useEffect(() => { + // Don't run if the editor isn't loaded or the code is already the bracket + if (!editorManager.editorView || codeManager.code === bracket) { + return + } + // Don't run if the network isn't healthy or the connection isn't established + if ( + overallState !== NetworkHealthState.Ok || + immediateState.type !== EngineConnectionStateType.ConnectionEstablished + ) { + return + } + setTimeout( + toSync(async () => { + codeManager.updateCodeStateEditor(bracket) + await kclManager.executeCode(true) + await codeManager.writeToFile() + }, reportRejection) + ) + }, [editorManager.editorView, immediateState, overallState]) +} + +export function useNextClick(newStatus: string) { + const filePath = useAbsoluteFilePath() + const navigate = useNavigate() + + return useCallback(() => { + settingsActor.send({ + type: 'set.app.onboardingStatus', + data: { level: 'user', value: newStatus }, + }) + navigate(filePath + PATHS.ONBOARDING.INDEX.slice(0, -1) + newStatus) + }, [filePath, newStatus, settingsActor.send, navigate]) +} + +export function useDismiss() { + const filePath = useAbsoluteFilePath() + const send = settingsActor.send + const navigate = useNavigate() + + const settingsCallback = useCallback(() => { + send({ + type: 'set.app.onboardingStatus', + data: { level: 'user', value: 'dismissed' }, + }) + waitFor(settingsActor, (state) => state.matches('idle')) + .then(() => navigate(filePath)) + .catch(reportRejection) + }, [send]) + + return settingsCallback +} +export function OnboardingButtons({ + currentSlug, + className, + dismissClassName, + onNextOverride, + ...props +}: { + currentSlug?: (typeof onboardingPaths)[keyof typeof onboardingPaths] + className?: string + dismissClassName?: string + onNextOverride?: () => void +} & React.HTMLAttributes) { + const dismiss = useDismiss() + const stepNumber = useStepNumber(currentSlug) + const previousStep = + !stepNumber || stepNumber === 0 ? null : onboardingRoutes[stepNumber - 2] + const goToPrevious = useNextClick( + onboardingPaths.INDEX + (previousStep?.path ?? '') + ) + const nextStep = + !stepNumber || stepNumber === onboardingRoutes.length + ? null + : onboardingRoutes[stepNumber] + const goToNext = useNextClick(onboardingPaths.INDEX + (nextStep?.path ?? '')) + + return ( + <> + +
+ + previousStep?.path || previousStep?.index + ? goToPrevious() + : dismiss() + } + iconStart={{ + icon: previousStep ? 'arrowLeft' : 'close', + className: 'text-chalkboard-10', + bgClassName: 'bg-destroy-80 group-hover:bg-destroy-80', + }} + className="hover:border-destroy-40 hover:bg-destroy-10/50 dark:hover:bg-destroy-80/50" + data-testid="onboarding-prev" + > + {previousStep ? `Back` : 'Dismiss'} + + {stepNumber !== undefined && ( +

+ {stepNumber} / {onboardingRoutes.length} +

+ )} + { + if (nextStep?.path) { + onNextOverride ? onNextOverride() : goToNext() + } else { + dismiss() + } + }} + iconStart={{ + icon: nextStep ? 'arrowRight' : 'checkmark', + bgClassName: 'dark:bg-chalkboard-80', + }} + className="dark:hover:bg-chalkboard-80/50" + data-testid="onboarding-next" + > + {nextStep ? `Next` : 'Finish'} + +
+ + ) +} diff --git a/src/routes/Settings.tsx b/src/routes/Settings.tsx index 9ce3af3c1..287f8340f 100644 --- a/src/routes/Settings.tsx +++ b/src/routes/Settings.tsx @@ -1,20 +1,22 @@ -import { SettingsLevel } from 'lib/settings/settingsTypes' -import { useLocation, useNavigate, useSearchParams } from 'react-router-dom' -import { useHotkeys } from 'react-hotkeys-hook' -import { PATHS } from 'lib/paths' -import { useDotDotSlash } from 'hooks/useDotDotSlash' -import { Fragment, useEffect, useRef } from 'react' import { Dialog, Transition } from '@headlessui/react' -import { CustomIcon } from 'components/CustomIcon' -import { SettingsSearchBar } from 'components/Settings/SettingsSearchBar' -import { SettingsTabs } from 'components/Settings/SettingsTabs' -import { SettingsSectionsList } from 'components/Settings/SettingsSectionsList' -import { AllSettingsFields } from 'components/Settings/AllSettingsFields' -import { AllKeybindingsFields } from 'components/Settings/AllKeybindingsFields' -import { KeybindingsSectionsList } from 'components/Settings/KeybindingsSectionsList' -import { isDesktop } from 'lib/isDesktop' -import { IS_PLAYWRIGHT_KEY } from '../../e2e/playwright/storageStates' -import { NODE_ENV } from 'env' +import { NODE_ENV } from '@src/env' +import { Fragment, useEffect, useRef } from 'react' +import { useHotkeys } from 'react-hotkeys-hook' +import { useLocation, useNavigate, useSearchParams } from 'react-router-dom' + +import { IS_PLAYWRIGHT_KEY } from '@e2e/playwright/storageStates' + +import { CustomIcon } from '@src/components/CustomIcon' +import { AllKeybindingsFields } from '@src/components/Settings/AllKeybindingsFields' +import { AllSettingsFields } from '@src/components/Settings/AllSettingsFields' +import { KeybindingsSectionsList } from '@src/components/Settings/KeybindingsSectionsList' +import { SettingsSearchBar } from '@src/components/Settings/SettingsSearchBar' +import { SettingsSectionsList } from '@src/components/Settings/SettingsSectionsList' +import { SettingsTabs } from '@src/components/Settings/SettingsTabs' +import { useDotDotSlash } from '@src/hooks/useDotDotSlash' +import { isDesktop } from '@src/lib/isDesktop' +import { PATHS } from '@src/lib/paths' +import type { SettingsLevel } from '@src/lib/settings/settingsTypes' const isTestEnv = window?.localStorage.getItem(IS_PLAYWRIGHT_KEY) === 'true' @@ -22,9 +24,9 @@ export const APP_VERSION = isTestEnv && NODE_ENV === 'development' ? '11.22.33' : isDesktop() - ? // @ts-ignore - window.electron.packageJson.version - : 'main' + ? // @ts-ignore + window.electron.packageJson.version + : 'main' export const PACKAGE_NAME = isDesktop() ? window.electron.packageJson.name diff --git a/src/routes/SignIn.tsx b/src/routes/SignIn.tsx index 45c711d12..68f9e5047 100644 --- a/src/routes/SignIn.tsx +++ b/src/routes/SignIn.tsx @@ -1,20 +1,21 @@ -import { ActionButton } from '../components/ActionButton' -import { isDesktop } from '../lib/isDesktop' -import { VITE_KC_SITE_BASE_URL, VITE_KC_API_BASE_URL } from '../env' -import { Themes, getSystemTheme } from '../lib/theme' -import { PATHS } from 'lib/paths' -import { APP_NAME } from 'lib/constants' -import { CSSProperties, useCallback, useState } from 'react' -import { Logo } from 'components/Logo' -import { CustomIcon } from 'components/CustomIcon' -import { Link } from 'react-router-dom' -import { APP_VERSION } from './Settings' -import { openExternalBrowserIfDesktop } from 'lib/openWindow' -import { toSync } from 'lib/utils' -import { reportRejection } from 'lib/trap' +import type { CSSProperties } from 'react' +import { useCallback, useState } from 'react' import toast from 'react-hot-toast' -import { authActor } from 'machines/appMachine' -import { useSettings } from 'machines/appMachine' +import { Link } from 'react-router-dom' + +import { ActionButton } from '@src/components/ActionButton' +import { CustomIcon } from '@src/components/CustomIcon' +import { Logo } from '@src/components/Logo' +import { VITE_KC_API_BASE_URL, VITE_KC_SITE_BASE_URL } from '@src/env' +import { APP_NAME } from '@src/lib/constants' +import { isDesktop } from '@src/lib/isDesktop' +import { openExternalBrowserIfDesktop } from '@src/lib/openWindow' +import { PATHS } from '@src/lib/paths' +import { Themes, getSystemTheme } from '@src/lib/theme' +import { reportRejection } from '@src/lib/trap' +import { toSync } from '@src/lib/utils' +import { authActor, useSettings } from '@src/machines/appMachine' +import { APP_VERSION } from '@src/routes/Settings' const subtleBorder = 'border border-solid border-chalkboard-30 dark:border-chalkboard-80' @@ -48,8 +49,8 @@ const SignIn = () => { ? '-dark' : '' : shouldContrast - ? '' - : '-dark', + ? '' + : '-dark', [theme.current] ) diff --git a/src/routes/Telemetry.tsx b/src/routes/Telemetry.tsx index a5cd91b0d..a0e5aed96 100644 --- a/src/routes/Telemetry.tsx +++ b/src/routes/Telemetry.tsx @@ -1,11 +1,12 @@ -import { useLocation, useNavigate } from 'react-router-dom' -import { useHotkeys } from 'react-hotkeys-hook' -import { PATHS } from 'lib/paths' -import { useDotDotSlash } from 'hooks/useDotDotSlash' -import { Fragment } from 'react' import { Dialog, Transition } from '@headlessui/react' -import { CustomIcon } from 'components/CustomIcon' -import { TelemetryExplorer } from 'components/TelemetryExplorer' +import { Fragment } from 'react' +import { useHotkeys } from 'react-hotkeys-hook' +import { useLocation, useNavigate } from 'react-router-dom' + +import { CustomIcon } from '@src/components/CustomIcon' +import { TelemetryExplorer } from '@src/components/TelemetryExplorer' +import { useDotDotSlash } from '@src/hooks/useDotDotSlash' +import { PATHS } from '@src/lib/paths' export const Telemetry = () => { const navigate = useNavigate() diff --git a/src/setupTests.ts b/src/setupTests.ts index 2c9bd3b0f..bccb50d2d 100644 --- a/src/setupTests.ts +++ b/src/setupTests.ts @@ -1,9 +1,8 @@ import '@testing-library/jest-dom' -import { WebSocket } from 'ws' +import fetch from 'node-fetch' import { vi } from 'vitest' import 'vitest-webgl-canvas-mock' - -import fetch from 'node-fetch' +import { WebSocket } from 'ws' // @ts-ignore globalThis.fetch = fetch diff --git a/src/test-utils.test.ts b/src/test-utils.test.ts index 9f0266e9c..245ee24f5 100644 --- a/src/test-utils.test.ts +++ b/src/test-utils.test.ts @@ -1,4 +1,4 @@ -import { normaliseKclNumbers } from '../e2e/playwright/test-utils' +import { normaliseKclNumbers } from '@e2e/playwright/test-utils' test('normaliseKclNumbers', () => { expect( diff --git a/tsconfig.json b/tsconfig.json index 4dd68fb00..d379580d9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,16 +1,17 @@ { "compilerOptions": { - "baseUrl": "src", "noErrorTruncation": true, "paths": { "@kittycad/codemirror-lsp-client": [ - "../packages/codemirror-lsp-client/src/index.ts" + "./packages/codemirror-lsp-client/src/index.ts" ], "@kittycad/codemirror-lang-kcl": [ - "../packages/codemirror-lang-kcl/src/index.ts" + "./packages/codemirror-lang-kcl/src/index.ts" ], - "@rust/*": ["../rust/*"], - "/*": ["src/*"] + "@rust/*": ["./rust/*"], + "@e2e/*": ["./e2e/*"], + "@src/*": ["./src/*"], + "@root/*": ["./*"] }, "types": [ "vite/client", diff --git a/vite.base.config.ts b/vite.base.config.ts index fd213f2df..515e959ee 100644 --- a/vite.base.config.ts +++ b/vite.base.config.ts @@ -1,6 +1,7 @@ import { builtinModules } from 'node:module' import type { AddressInfo } from 'node:net' import type { ConfigEnv, Plugin, UserConfig } from 'vite' + import pkg from './package.json' export const builtins = [ @@ -59,17 +60,20 @@ export function getBuildDefine(env: ConfigEnv<'build'>) { .filter(({ name }) => name != null) .map(({ name }) => name!) const defineKeys = getDefineKeys(names) - const define = Object.entries(defineKeys).reduce((acc, [name, keys]) => { - const { VITE_DEV_SERVER_URL, VITE_NAME } = keys - const def = { - [VITE_DEV_SERVER_URL]: - command === 'serve' - ? JSON.stringify(process.env[VITE_DEV_SERVER_URL]) - : undefined, - [VITE_NAME]: JSON.stringify(name), - } - return { ...acc, ...def } - }, {} as Record) + const define = Object.entries(defineKeys).reduce( + (acc, [name, keys]) => { + const { VITE_DEV_SERVER_URL, VITE_NAME } = keys + const def = { + [VITE_DEV_SERVER_URL]: + command === 'serve' + ? JSON.stringify(process.env[VITE_DEV_SERVER_URL]) + : undefined, + [VITE_NAME]: JSON.stringify(name), + } + return { ...acc, ...def } + }, + {} as Record + ) return define } @@ -87,9 +91,8 @@ export function pluginExposeRenderer(name: string): Plugin { server.httpServer?.once('listening', () => { const addressInfo = server.httpServer!.address() as AddressInfo // Expose env constant for main process use. - process.env[ - VITE_DEV_SERVER_URL - ] = `http://localhost:${addressInfo?.port}` + process.env[VITE_DEV_SERVER_URL] = + `http://localhost:${addressInfo?.port}` }) }, } diff --git a/vite.config.ts b/vite.config.ts index d4f918055..beef0bbb4 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,11 +1,11 @@ -import react from '@vitejs/plugin-react' -import viteTsconfigPaths from 'vite-tsconfig-paths' -import eslint from '@nabla/vite-plugin-eslint' -import { defineConfig, configDefaults } from 'vitest/config' -import version from 'vite-plugin-package-version' -import topLevelAwait from 'vite-plugin-top-level-await' // @ts-ignore: No types available import { lezer } from '@lezer/generator/rollup' +import eslint from '@nabla/vite-plugin-eslint' +import react from '@vitejs/plugin-react' +import version from 'vite-plugin-package-version' +import topLevelAwait from 'vite-plugin-top-level-await' +import viteTsconfigPaths from 'vite-tsconfig-paths' +import { configDefaults, defineConfig } from 'vitest/config' const config = defineConfig({ server: { @@ -63,6 +63,9 @@ const config = defineConfig({ '@kittycad/codemirror-lsp-client': '/packages/codemirror-lsp-client/src', '@kittycad/codemirror-lang-kcl': '/packages/codemirror-lang-kcl/src', '@rust': '/rust', + '@e2e': '/e2e', + '@src': '/src', + '@root': '/', }, }, plugins: [ diff --git a/vite.main.config.ts b/vite.main.config.ts index 89645e874..9890813e6 100644 --- a/vite.main.config.ts +++ b/vite.main.config.ts @@ -1,18 +1,19 @@ -import type { ConfigEnv, UserConfig } from 'vite' -import { defineConfig, mergeConfig } from 'vite' -import { configDefaults } from 'vitest/config' -import viteTsconfigPaths from 'vite-tsconfig-paths' -import vitePluginEslint from '@nabla/vite-plugin-eslint' -import vitePluginPackageVersion from 'vite-plugin-package-version' -import { - getBuildConfig, - getBuildDefine, - external, - pluginHotRestart, -} from './vite.base.config' -import viteJsPluginReact from '@vitejs/plugin-react' // @ts-ignore: No types available import { lezer } from '@lezer/generator/rollup' +import vitePluginEslint from '@nabla/vite-plugin-eslint' +import viteJsPluginReact from '@vitejs/plugin-react' +import type { ConfigEnv, UserConfig } from 'vite' +import { defineConfig, mergeConfig } from 'vite' +import vitePluginPackageVersion from 'vite-plugin-package-version' +import viteTsconfigPaths from 'vite-tsconfig-paths' +import { configDefaults } from 'vitest/config' + +import { + external, + getBuildConfig, + getBuildDefine, + pluginHotRestart, +} from './vite.base.config' // https://vitejs.dev/config export default defineConfig((env) => { diff --git a/vite.preload.config.ts b/vite.preload.config.ts index c3a78a01a..fa58bbcfc 100644 --- a/vite.preload.config.ts +++ b/vite.preload.config.ts @@ -1,11 +1,11 @@ import type { ConfigEnv, UserConfig } from 'vite' import { defineConfig, mergeConfig } from 'vite' -import { configDefaults } from 'vitest/config' import viteTsconfigPaths from 'vite-tsconfig-paths' + import { + external, getBuildConfig, getBuildDefine, - external, pluginHotRestart, } from './vite.base.config' diff --git a/vite.renderer.config.ts b/vite.renderer.config.ts index eaf0eb049..6c6d3c1ea 100644 --- a/vite.renderer.config.ts +++ b/vite.renderer.config.ts @@ -1,10 +1,11 @@ -import type { ConfigEnv, UserConfig } from 'vite' -import { defineConfig } from 'vite' -import { pluginExposeRenderer } from './vite.base.config' -import viteTsconfigPaths from 'vite-tsconfig-paths' -import topLevelAwait from 'vite-plugin-top-level-await' // @ts-ignore: No types available import { lezer } from '@lezer/generator/rollup' +import type { ConfigEnv, UserConfig } from 'vite' +import { defineConfig } from 'vite' +import topLevelAwait from 'vite-plugin-top-level-await' +import viteTsconfigPaths from 'vite-tsconfig-paths' + +import { pluginExposeRenderer } from './vite.base.config' // https://vitejs.dev/config export default defineConfig((env) => { diff --git a/yarn.lock b/yarn.lock index 4208a47cd..4a1d47041 100644 --- a/yarn.lock +++ b/yarn.lock @@ -89,7 +89,7 @@ "@jridgewell/trace-mapping" "^0.3.25" jsesc "^3.0.2" -"@babel/generator@^7.27.0": +"@babel/generator@^7.26.5", "@babel/generator@^7.27.0": version "7.27.0" resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.27.0.tgz#764382b5392e5b9aff93cadb190d0745866cbc2c" integrity sha512-VybsKvpiN1gU1sdMZIp7FcqphVVKEwcuj02x73uvcHE0PTihx1nlBcowYWhDwjpoAXRv43+gDzyggGnn1XZhVw== @@ -352,7 +352,7 @@ dependencies: "@babel/types" "^7.26.10" -"@babel/parser@^7.27.0": +"@babel/parser@^7.26.7", "@babel/parser@^7.27.0": version "7.27.0" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.27.0.tgz#3d7d6ee268e41d2600091cbd4e145ffee85a44ec" integrity sha512-iaepho73/2Pz7w2eMS0Q5f83+0RKI7i4xmiYeBmDzfRVbQtTOG7Ts0S4HzJVsTMGI9keU8rNfuZr8DKfSt7Yyg== @@ -992,7 +992,7 @@ debug "^4.3.1" globals "^11.1.0" -"@babel/traverse@^7.26.10": +"@babel/traverse@^7.26.10", "@babel/traverse@^7.26.7": version "7.27.0" resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.27.0.tgz#11d7e644779e166c0442f9a07274d02cd91d4a70" integrity sha512-19lYZFzYVQkkHkl4Cy4WrAVcqBkgvV2YM2TU3xG6DIwO7O3ecbDPfW3yM3bjAGcqcQHi+CCtjMR3dIEHxsd6bA== @@ -1022,7 +1022,7 @@ "@babel/helper-string-parser" "^7.25.9" "@babel/helper-validator-identifier" "^7.25.9" -"@babel/types@^7.27.0": +"@babel/types@^7.26.7", "@babel/types@^7.27.0": version "7.27.0" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.27.0.tgz#ef9acb6b06c3173f6632d993ecb6d4ae470b4559" integrity sha512-H45s8fVLYjbhFH62dIJ3WtmJ6RSPt/3DRO0ZcT2SUiYiQyz3BLVb9ADEnLl91m74aQPS3AzzeajZHYOalWe3bg== @@ -2275,6 +2275,18 @@ resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf" integrity sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A== +"@trivago/prettier-plugin-sort-imports@^5.2.2": + version "5.2.2" + resolved "https://registry.yarnpkg.com/@trivago/prettier-plugin-sort-imports/-/prettier-plugin-sort-imports-5.2.2.tgz#38983f0b83490a0a7d974a6f1e409fb4bf678d02" + integrity sha512-fYDQA9e6yTNmA13TLVSA+WMQRc5Bn/c0EUBditUHNfMMxN7M82c38b1kEggVE3pLpZ0FwkwJkUEKMiOi52JXFA== + dependencies: + "@babel/generator" "^7.26.5" + "@babel/parser" "^7.26.7" + "@babel/traverse" "^7.26.7" + "@babel/types" "^7.26.7" + javascript-natural-sort "^0.7.1" + lodash "^4.17.21" + "@ts-stack/markdown@^1.5.0": version "1.5.0" resolved "https://registry.yarnpkg.com/@ts-stack/markdown/-/markdown-1.5.0.tgz#5dc298a20dc3dc040143c5a5948201eb6bf5419d" @@ -4203,6 +4215,19 @@ dotenv@^16.4.5: resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.7.tgz#0e20c5b82950140aa99be360a8a5f52335f53c26" integrity sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ== +dpdm@^3.14.0: + version "3.14.0" + resolved "https://registry.yarnpkg.com/dpdm/-/dpdm-3.14.0.tgz#12a60a2d88b23981c91239b86e7462a5c203e5e9" + integrity sha512-YJzsFSyEtj88q5eTELg3UWU7TVZkG1dpbF4JDQ3t1b07xuzXmdoGeSz9TKOke1mUuOpWlk4q+pBh+aHzD6GBTg== + dependencies: + chalk "^4.1.2" + fs-extra "^11.1.1" + glob "^10.3.4" + ora "^5.4.1" + tslib "^2.6.2" + typescript "^5.2.2" + yargs "^17.7.2" + dunder-proto@^1.0.0, dunder-proto@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/dunder-proto/-/dunder-proto-1.0.1.tgz#d7ae667e1dc83482f8b70fd0f6eefc50da30f58a" @@ -5413,7 +5438,7 @@ glob-parent@^6.0.2: dependencies: is-glob "^4.0.3" -glob@^10.3.10, glob@^10.3.12: +glob@^10.3.10, glob@^10.3.12, glob@^10.3.4: version "10.4.5" resolved "https://registry.yarnpkg.com/glob/-/glob-10.4.5.tgz#f4d9f0b90ffdbab09c9d77f5f29b4262517b0956" integrity sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg== @@ -6253,6 +6278,11 @@ jake@^10.8.5: filelist "^1.0.4" minimatch "^3.1.2" +javascript-natural-sort@^0.7.1: + version "0.7.1" + resolved "https://registry.yarnpkg.com/javascript-natural-sort/-/javascript-natural-sort-0.7.1.tgz#f9e2303d4507f6d74355a73664d1440fb5a0ef59" + integrity sha512-nO6jcEfZWQXDhOiBtG2KvKyEptz7RVbpGP4vTD2hLBdmNQSsCiicO2Ioinv6UI4y9ukqnBpy+XZ9H6uLNgJTlw== + jest-diff@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-29.7.0.tgz#017934a66ebb7ecf6f205e84699be10afd70458a" @@ -6572,7 +6602,7 @@ lodash.merge@^4.6.2: resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== -lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.2, lodash@^4.17.20: +lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.2, lodash@^4.17.20, lodash@^4.17.21: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== @@ -7203,7 +7233,7 @@ optionator@^0.9.3: type-check "^0.4.0" word-wrap "^1.2.5" -ora@^5.1.0: +ora@^5.1.0, ora@^5.4.1: version "5.4.1" resolved "https://registry.yarnpkg.com/ora/-/ora-5.4.1.tgz#1b2678426af4ac4a509008e5e4ac9e9959db9e18" integrity sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ== @@ -7570,11 +7600,21 @@ prelude-ls@^1.2.1: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== +prettier-plugin-organize-imports@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/prettier-plugin-organize-imports/-/prettier-plugin-organize-imports-4.1.0.tgz#f3d3764046a8e7ba6491431158b9be6ffd83b90f" + integrity sha512-5aWRdCgv645xaa58X8lOxzZoiHAldAPChljr/MT0crXVOWTZ+Svl4hIWlz+niYSlO6ikE5UXkN1JrRvIP2ut0A== + prettier@^2.8.8: version "2.8.8" resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da" integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q== +prettier@^3.5.3: + version "3.5.3" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.5.3.tgz#4fc2ce0d657e7a02e602549f053b239cb7dfe1b5" + integrity sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw== + pretty-format@^27.0.2: version "27.5.1" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.5.1.tgz#2181879fdea51a7a5851fb39d920faa63f01d88e" @@ -9016,6 +9056,11 @@ tslib@^2.0.1, tslib@^2.3.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0" integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ== +tslib@^2.6.2: + version "2.8.1" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f" + integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w== + tslib@~2.4: version "2.4.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.1.tgz#0d0bfbaac2880b91e22df0768e55be9753a5b17e" @@ -9154,7 +9199,7 @@ typescript-eslint@^8.26.1: "@typescript-eslint/parser" "8.26.1" "@typescript-eslint/utils" "8.26.1" -typescript@^5.4.3, typescript@^5.8.2: +typescript@^5.2.2, typescript@^5.4.3, typescript@^5.8.2: version "5.8.2" resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.8.2.tgz#8170b3702f74b79db2e5a96207c15e65807999e4" integrity sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ==