From e087b87c19f2def6d51342851f70c8d2946b5302 Mon Sep 17 00:00:00 2001 From: ochafik Date: Tue, 31 Dec 2024 17:53:45 +0000 Subject: [PATCH] Fix type lints in editor --- src/components/CustomizerPanel.tsx | 6 +++--- src/components/EditorPanel.tsx | 12 ++++++------ src/components/ExportButton.tsx | 4 ++-- src/components/FilePicker.tsx | 10 +++++----- src/components/Footer.tsx | 12 ++++++------ src/components/MultimaterialColorsDialog.tsx | 2 +- src/components/PanelSwitcher.tsx | 4 ++-- src/components/SettingsMenu.tsx | 4 ++-- src/components/ViewerPanel.tsx | 4 ++-- src/components/contexts.ts | 2 +- src/index.tsx | 20 ++++++++++---------- src/runner/actions.ts | 14 +++++++------- src/runner/openscad-runner.ts | 6 +++--- src/state/app-state.ts | 4 ++-- src/state/fragment-state.ts | 10 ++++------ src/state/initial-state.ts | 12 ++++++------ src/state/model.ts | 20 ++++++++++---------- src/utils.ts | 2 +- tsconfig.json | 4 ++-- 19 files changed, 75 insertions(+), 77 deletions(-) diff --git a/src/components/CustomizerPanel.tsx b/src/components/CustomizerPanel.tsx index 0005af6..35b267b 100644 --- a/src/components/CustomizerPanel.tsx +++ b/src/components/CustomizerPanel.tsx @@ -1,7 +1,7 @@ // Portions of this file are Copyright 2021 Google LLC, and licensed under GPL2+. See COPYING. -import { CSSProperties, useContext } from 'react'; -import { ModelContext } from './contexts'; +import React, { CSSProperties, useContext } from 'react'; +import { ModelContext } from './contexts.ts'; import { Dropdown } from 'primereact/dropdown'; import { Slider } from 'primereact/slider'; @@ -9,7 +9,7 @@ import { Checkbox } from 'primereact/checkbox'; import { InputNumber } from 'primereact/inputnumber'; import { InputText } from 'primereact/inputtext'; import { Fieldset } from 'primereact/fieldset'; -import { Parameter } from '../state/customizer-types'; +import { Parameter } from '../state/customizer-types.ts'; import { Button } from 'primereact/button'; export default function CustomizerPanel({className, style}: {className?: string, style?: CSSProperties}) { diff --git a/src/components/EditorPanel.tsx b/src/components/EditorPanel.tsx index 9d1c04d..270bd64 100644 --- a/src/components/EditorPanel.tsx +++ b/src/components/EditorPanel.tsx @@ -2,16 +2,16 @@ import React, { CSSProperties, useContext, useRef, useState } from 'react'; import Editor, { loader, Monaco } from '@monaco-editor/react'; -import openscadEditorOptions from '../language/openscad-editor-options'; +import openscadEditorOptions from '../language/openscad-editor-options.ts'; import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; import { InputTextarea } from 'primereact/inputtextarea'; import { Button } from 'primereact/button'; import { MenuItem } from 'primereact/menuitem'; import { Menu } from 'primereact/menu'; -import { buildUrlForStateParams } from '../state/fragment-state'; -import { getBlankProjectState, defaultSourcePath } from '../state/initial-state'; -import { ModelContext, FSContext } from './contexts'; -import FilePicker, { } from './FilePicker'; +import { buildUrlForStateParams } from '../state/fragment-state.ts'; +import { getBlankProjectState, defaultSourcePath } from '../state/initial-state.ts'; +import { ModelContext, FSContext } from './contexts.ts'; +import FilePicker, { } from './FilePicker.tsx'; // const isMonacoSupported = false; const isMonacoSupported = (() => { @@ -89,7 +89,7 @@ export default function EditorPanel({className, style}: {className?: string, sty { label: "New project", icon: 'pi pi-plus-circle', - command: async () => window.open(buildUrlForStateParams(await getBlankProjectState()), '_blank'), + command: () => window.open(buildUrlForStateParams(getBlankProjectState()), '_blank'), target: '_blank', }, { diff --git a/src/components/ExportButton.tsx b/src/components/ExportButton.tsx index 4e27ad4..b8920f3 100644 --- a/src/components/ExportButton.tsx +++ b/src/components/ExportButton.tsx @@ -1,5 +1,5 @@ -import React, { useContext, useState } from 'react'; -import { ModelContext } from './contexts'; +import React, { useContext } from 'react'; +import { ModelContext } from './contexts.ts'; import { SplitButton } from 'primereact/splitbutton'; import { MenuItem } from 'primereact/menuitem'; diff --git a/src/components/FilePicker.tsx b/src/components/FilePicker.tsx index 5629817..20638b7 100644 --- a/src/components/FilePicker.tsx +++ b/src/components/FilePicker.tsx @@ -1,12 +1,12 @@ // Portions of this file are Copyright 2021 Google LLC, and licensed under GPL2+. See COPYING. -import { CSSProperties, useContext } from 'react'; +import React, { CSSProperties, useContext } from 'react'; import { TreeSelect } from 'primereact/treeselect'; import { TreeNode } from 'primereact/treenode'; -import { ModelContext, FSContext } from './contexts'; -import { getParentDir, join } from '../fs/filesystem'; -import { defaultSourcePath } from '../state/initial-state'; -import { zipArchives } from '../fs/zip-archives'; +import { ModelContext, FSContext } from './contexts.ts'; +import { getParentDir, join } from '../fs/filesystem.ts'; +import { defaultSourcePath } from '../state/initial-state.ts'; +import { zipArchives } from '../fs/zip-archives.ts'; const biasedCompare = (a: string, b: string) => a === 'openscad' ? -1 : b === 'openscad' ? 1 : a.localeCompare(b); diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index a604f25..3030e57 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -1,16 +1,16 @@ // Portions of this file are Copyright 2021 Google LLC, and licensed under GPL2+. See COPYING. -import { CSSProperties, useContext, useRef } from 'react'; -import { ModelContext } from './contexts'; +import React, { CSSProperties, useContext, useRef } from 'react'; +import { ModelContext } from './contexts.ts'; import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; import { Button } from 'primereact/button'; import { ProgressBar } from 'primereact/progressbar'; import { Badge } from 'primereact/badge'; import { Toast } from 'primereact/toast'; -import HelpMenu from './HelpMenu'; -import ExportButton from './ExportButton'; -import SettingsMenu from './SettingsMenu'; -import MultimaterialColorsDialog from './MultimaterialColorsDialog'; +import HelpMenu from './HelpMenu.tsx'; +import ExportButton from './ExportButton.tsx'; +import SettingsMenu from './SettingsMenu.tsx'; +import MultimaterialColorsDialog from './MultimaterialColorsDialog.tsx'; export default function Footer({style}: {style?: CSSProperties}) { diff --git a/src/components/MultimaterialColorsDialog.tsx b/src/components/MultimaterialColorsDialog.tsx index edb1d78..bd65e20 100644 --- a/src/components/MultimaterialColorsDialog.tsx +++ b/src/components/MultimaterialColorsDialog.tsx @@ -3,7 +3,7 @@ import React, { useContext, useState } from 'react'; import { ColorPicker } from 'primereact/colorpicker'; import { Button } from 'primereact/button'; import { InputText } from 'primereact/inputtext'; -import { ModelContext } from './contexts'; +import { ModelContext } from './contexts.ts'; import { Dialog } from 'primereact/dialog'; export default function MultimaterialColorsDialog() { diff --git a/src/components/PanelSwitcher.tsx b/src/components/PanelSwitcher.tsx index 7794393..a3fcc95 100644 --- a/src/components/PanelSwitcher.tsx +++ b/src/components/PanelSwitcher.tsx @@ -1,10 +1,10 @@ // Portions of this file are Copyright 2021 Google LLC, and licensed under GPL2+. See COPYING. import React, { useContext } from 'react'; -import { SingleLayoutComponentId } from '../state/app-state' +import { SingleLayoutComponentId } from '../state/app-state.ts' import { TabMenu } from 'primereact/tabmenu'; import { ToggleButton } from 'primereact/togglebutton'; -import { ModelContext, FSContext } from './contexts'; +import { ModelContext } from './contexts.ts'; export default function PanelSwitcher() { const model = useContext(ModelContext); diff --git a/src/components/SettingsMenu.tsx b/src/components/SettingsMenu.tsx index 328ed6c..06a8205 100644 --- a/src/components/SettingsMenu.tsx +++ b/src/components/SettingsMenu.tsx @@ -4,8 +4,8 @@ import { CSSProperties, useContext, useRef } from 'react'; import { Button } from 'primereact/button'; import { MenuItem } from 'primereact/menuitem'; import { Menu } from 'primereact/menu'; -import { ModelContext } from './contexts'; -import { isInStandaloneMode } from '../utils'; +import { ModelContext } from './contexts.ts'; +import { isInStandaloneMode } from '../utils.ts'; import { confirmDialog } from 'primereact/confirmdialog'; export default function SettingsMenu({className, style}: {className?: string, style?: CSSProperties}) { diff --git a/src/components/ViewerPanel.tsx b/src/components/ViewerPanel.tsx index 9d08604..ee7489f 100644 --- a/src/components/ViewerPanel.tsx +++ b/src/components/ViewerPanel.tsx @@ -1,9 +1,9 @@ // Portions of this file are Copyright 2021 Google LLC, and licensed under GPL2+. See COPYING. import { CSSProperties, useCallback, useContext, useEffect, useRef, useState } from 'react'; -import { ModelContext } from './contexts'; +import { ModelContext } from './contexts.ts'; import { Toast } from 'primereact/toast'; -import { blurHashToImage, imageToBlurhash, imageToThumbhash, thumbHashToImage } from '../io/image_hashes'; +import { blurHashToImage, imageToBlurhash, imageToThumbhash, thumbHashToImage } from '../io/image_hashes.ts'; declare global { namespace JSX { diff --git a/src/components/contexts.ts b/src/components/contexts.ts index b899c39..2d035b7 100644 --- a/src/components/contexts.ts +++ b/src/components/contexts.ts @@ -1,5 +1,5 @@ import React from "react"; -import { Model } from "../state/model"; +import { Model } from "../state/model.ts"; export const FSContext = React.createContext(undefined); diff --git a/src/index.tsx b/src/index.tsx index 5f507cc..457c01a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -2,18 +2,18 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; -import {App} from './components/App'; -import { createEditorFS } from './fs/filesystem'; -import { registerOpenSCADLanguage } from './language/openscad-register-language'; -import { zipArchives } from './fs/zip-archives'; -import {readStateFromFragment} from './state/fragment-state' -import { createInitialState } from './state/initial-state'; +import {App} from './components/App.tsx'; +import { createEditorFS } from './fs/filesystem.ts'; +import { registerOpenSCADLanguage } from './language/openscad-register-language.ts'; +import { zipArchives } from './fs/zip-archives.ts'; +import {readStateFromFragment} from './state/fragment-state.ts' +import { createInitialState } from './state/initial-state.ts'; import './index.css'; import debug from 'debug'; -import { isInStandaloneMode, registerCustomAppHeightCSSProperty } from './utils'; -import { State, StatePersister } from './state/app-state'; -import { writeStateInFragment } from "./state/fragment-state"; +import { isInStandaloneMode, registerCustomAppHeightCSSProperty } from './utils.ts'; +import { State, StatePersister } from './state/app-state.ts'; +import { writeStateInFragment } from "./state/fragment-state.ts"; import "primereact/resources/themes/lara-light-indigo/theme.css"; import "primereact/resources/primereact.min.css"; @@ -89,7 +89,7 @@ window.addEventListener('load', async () => { }; } - const initialState = await createInitialState(persistedState); + const initialState = createInitialState(persistedState); const root = ReactDOM.createRoot( document.getElementById('root') as HTMLElement diff --git a/src/runner/actions.ts b/src/runner/actions.ts index 93f2f2a..41c02df 100644 --- a/src/runner/actions.ts +++ b/src/runner/actions.ts @@ -1,12 +1,12 @@ // Portions of this file are Copyright 2021 Google LLC, and licensed under GPL2+. See COPYING. import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; -import { ProcessStreams, spawnOpenSCAD } from "./openscad-runner"; -import { processMergedOutputs } from "./output-parser"; -import { AbortablePromise, turnIntoDelayableExecution } from '../utils'; -import { Source } from '../state/app-state'; -import { VALID_EXPORT_FORMATS_2D, VALID_EXPORT_FORMATS_3D, VALID_RENDER_FORMATS } from '../state/formats'; -import { ParameterSet } from '../state/customizer-types'; +import { ProcessStreams, spawnOpenSCAD } from "./openscad-runner.ts"; +import { processMergedOutputs } from "./output-parser.ts"; +import { AbortablePromise, turnIntoDelayableExecution } from '../utils.ts'; +import { Source } from '../state/app-state.ts'; +import { VALID_EXPORT_FORMATS_2D, VALID_EXPORT_FORMATS_3D } from '../state/formats.ts'; +import { ParameterSet } from '../state/customizer-types.ts'; const syntaxDelay = 300; @@ -85,7 +85,7 @@ export type RenderArgs = { extraArgs?: string[], isPreview: boolean, mountArchives: boolean, - renderFormat: keyof typeof VALID_EXPORT_FORMATS_2D | keyof typeof VALID_EXPORT_FORMATS_3D | keyof typeof VALID_RENDER_FORMATS, + renderFormat: keyof typeof VALID_EXPORT_FORMATS_2D | keyof typeof VALID_EXPORT_FORMATS_3D, streamsCallback: (ps: ProcessStreams) => void, } diff --git a/src/runner/openscad-runner.ts b/src/runner/openscad-runner.ts index ba0d1f1..69fb8db 100644 --- a/src/runner/openscad-runner.ts +++ b/src/runner/openscad-runner.ts @@ -1,8 +1,8 @@ // Portions of this file are Copyright 2021 Google LLC, and licensed under GPL2+. See COPYING. -import { MergedOutputs } from "./openscad-worker"; -import { AbortablePromise } from "../utils"; -import { Source } from "../state/app-state"; +import { MergedOutputs } from "./openscad-worker.ts"; +import { AbortablePromise } from "../utils.ts"; +import { Source } from "../state/app-state.ts"; export type OpenSCADInvocation = { mountArchives: boolean, diff --git a/src/state/app-state.ts b/src/state/app-state.ts index e2e609f..466a304 100644 --- a/src/state/app-state.ts +++ b/src/state/app-state.ts @@ -1,8 +1,8 @@ // Portions of this file are Copyright 2021 Google LLC, and licensed under GPL2+. See COPYING. import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; -import { ParameterSet } from './customizer-types'; -import { VALID_EXPORT_FORMATS_2D, VALID_EXPORT_FORMATS_3D, VALID_RENDER_FORMATS } from './formats'; +import { ParameterSet } from './customizer-types.ts'; +import { VALID_EXPORT_FORMATS_2D, VALID_EXPORT_FORMATS_3D } from './formats.ts'; export type MultiLayoutComponentId = 'editor' | 'viewer' | 'customizer'; export type SingleLayoutComponentId = MultiLayoutComponentId; diff --git a/src/state/fragment-state.ts b/src/state/fragment-state.ts index b3eb3c6..9c72c11 100644 --- a/src/state/fragment-state.ts +++ b/src/state/fragment-state.ts @@ -1,9 +1,9 @@ // Portions of this file are Copyright 2021 Google LLC, and licensed under GPL2+. See COPYING. -import { State } from "./app-state"; -import { VALID_EXPORT_FORMATS_2D, VALID_EXPORT_FORMATS_3D, VALID_RENDER_FORMATS } from './formats'; -import { validateArray, validateBoolean, validateString, validateStringEnum } from "../utils"; -import { createInitialState, defaultModelColor, defaultSourcePath } from "./initial-state"; +import { State } from "./app-state.ts"; +import { VALID_EXPORT_FORMATS_2D, VALID_EXPORT_FORMATS_3D } from './formats.ts'; +import { validateArray, validateBoolean, validateString, validateStringEnum } from "../utils.ts"; +import { createInitialState, defaultModelColor, defaultSourcePath } from "./initial-state.ts"; export function buildUrlForStateParams(state: State) {//partialState: {params: State['params'], view: State['view']}) { return `${location.protocol}//${location.host}${location.pathname}#${encodeStateParamsAsFragment(state)}`; @@ -17,7 +17,6 @@ async function compressString(input: string): Promise { controller.enqueue(new TextEncoder().encode(input)); controller.close(); } - // @ts-ignore }).pipeThrough(new CompressionStream('gzip'))).arrayBuffer()))); } @@ -27,7 +26,6 @@ async function decompressString(compressedInput: string): Promise { controller.enqueue(Uint8Array.from(atob(compressedInput), c => c.charCodeAt(0))); controller.close(); } - // @ts-ignore }).pipeThrough(new DecompressionStream('gzip'))).arrayBuffer()); } diff --git a/src/state/initial-state.ts b/src/state/initial-state.ts index f242503..548c173 100644 --- a/src/state/initial-state.ts +++ b/src/state/initial-state.ts @@ -1,16 +1,16 @@ // Portions of this file are Copyright 2021 Google LLC, and licensed under GPL2+. See COPYING. -import defaultScad from './default-scad'; -import { State } from './app-state'; -import { fetchSource } from '../utils'; +import defaultScad from './default-scad.ts'; +import { State } from './app-state.ts'; export const defaultSourcePath = '/playground.scad'; export const defaultModelColor = '#f9d72c'; const defaultBlurhash = "|KSPX^%3~qtjMx$lR*x]t7n,R%xuxbM{WBt7ayfk_3bY9FnAt8XOxanjNF%fxbMyIn%3t7NFoLaeoeV[WBo{xar^IoS1xbxcR*S0xbofRjV[j[kCNGofxaWBNHW-xasDR*WTkBxuWBM{s:t7bYahRjfkozWUadofbIW:jZ"; -export async function createInitialState(state: State | null, source?: {content?: string, path?: string, url?: string, blurhash?: string}): Promise { +export function createInitialState(state: State | null, source?: {content?: string, path?: string, url?: string, blurhash?: string}): State { type Mode = State['view']['layout']['mode']; + const mode: Mode = window.matchMedia("(min-width: 768px)").matches ? 'multi' : 'single'; @@ -87,8 +87,8 @@ export async function createInitialState(state: State | null, source?: {content? return initialState; } -export async function getBlankProjectState() { - return await createInitialState(null, { +export function getBlankProjectState() { + return createInitialState(null, { path: defaultSourcePath, content: defaultScad, }); diff --git a/src/state/model.ts b/src/state/model.ts index 4f0ab1c..e4634cc 100644 --- a/src/state/model.ts +++ b/src/state/model.ts @@ -1,17 +1,17 @@ // Portions of this file are Copyright 2021 Google LLC, and licensed under GPL2+. See COPYING. -import { checkSyntax, render, RenderArgs, RenderOutput } from "../runner/actions"; -import { MultiLayoutComponentId, SingleLayoutComponentId, Source, State, StatePersister } from "./app-state"; -import { VALID_EXPORT_FORMATS_2D, VALID_EXPORT_FORMATS_3D, VALID_RENDER_FORMATS } from './formats'; -import { bubbleUpDeepMutations } from "./deep-mutate"; -import { downloadUrl, fetchSource, formatBytes, formatMillis, readFileAsDataURL } from '../utils' +import { checkSyntax, render, RenderArgs, RenderOutput } from "../runner/actions.ts"; +import { MultiLayoutComponentId, SingleLayoutComponentId, State, StatePersister } from "./app-state.ts"; +import { VALID_EXPORT_FORMATS_2D, VALID_EXPORT_FORMATS_3D } from './formats.ts'; +import { bubbleUpDeepMutations } from "./deep-mutate.ts"; +import { downloadUrl, fetchSource, formatBytes, formatMillis, readFileAsDataURL } from '../utils.ts' import JSZip from 'jszip'; -import { ProcessStreams } from "../runner/openscad-runner"; -import { is2DFormatExtension } from "./formats"; -import { parseOff } from "../io/import_off"; -import { exportGlb } from "../io/export_glb"; -import { export3MF } from "../io/export_3mf"; +import { ProcessStreams } from "../runner/openscad-runner.ts"; +import { is2DFormatExtension } from "./formats.ts"; +import { parseOff } from "../io/import_off.ts"; +import { exportGlb } from "../io/export_glb.ts"; +import { export3MF } from "../io/export_3mf.ts"; import chroma from "chroma-js"; const githubRx = /^https:\/\/github.com\/([^/]+)\/([^/]+)\/blob\/(.+)$/; diff --git a/src/utils.ts b/src/utils.ts index 8f1b6f4..ef13b3f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,6 +1,6 @@ // Portions of this file are Copyright 2021 Google LLC, and licensed under GPL2+. See COPYING. -import { Source } from "./state/app-state"; +import { Source } from "./state/app-state.ts"; export function mapObject(o: any, f: (key: string, value: any) => any, ifPred: (key: string) => boolean) { const ret = []; diff --git a/tsconfig.json b/tsconfig.json index 4bba2af..d13bb4a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,8 +2,8 @@ "compilerOptions": { "target": "ES2022", "lib": [ - "dom", - "dom.iterable", + "DOM", + "DOM.Iterable", "ES2022", "WebWorker" ],