Skip to content

Commit

Permalink
Fix type lints in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ochafik committed Dec 31, 2024
1 parent 7ffedcc commit e087b87
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 77 deletions.
6 changes: 3 additions & 3 deletions src/components/CustomizerPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// 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';
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}) {
Expand Down
12 changes: 6 additions & 6 deletions src/components/EditorPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (() => {
Expand Down Expand Up @@ -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',
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/components/ExportButton.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
10 changes: 5 additions & 5 deletions src/components/FilePicker.tsx
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -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}) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/MultimaterialColorsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/PanelSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/components/SettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/ViewerPanel.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/components/contexts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Model } from "../state/model";
import { Model } from "../state/model.ts";

export const FSContext = React.createContext<FS | undefined>(undefined);

Expand Down
20 changes: 10 additions & 10 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/runner/actions.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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,
}

Expand Down
6 changes: 3 additions & 3 deletions src/runner/openscad-runner.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/state/app-state.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
10 changes: 4 additions & 6 deletions src/state/fragment-state.ts
Original file line number Diff line number Diff line change
@@ -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)}`;
Expand All @@ -17,7 +17,6 @@ async function compressString(input: string): Promise<string> {
controller.enqueue(new TextEncoder().encode(input));
controller.close();
}
// @ts-ignore
}).pipeThrough(new CompressionStream('gzip'))).arrayBuffer())));
}

Expand All @@ -27,7 +26,6 @@ async function decompressString(compressedInput: string): Promise<string> {
controller.enqueue(Uint8Array.from(atob(compressedInput), c => c.charCodeAt(0)));
controller.close();
}
// @ts-ignore
}).pipeThrough(new DecompressionStream('gzip'))).arrayBuffer());
}

Expand Down
12 changes: 6 additions & 6 deletions src/state/initial-state.ts
Original file line number Diff line number Diff line change
@@ -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<State> {
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';

Expand Down Expand Up @@ -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,
});
Expand Down
20 changes: 10 additions & 10 deletions src/state/model.ts
Original file line number Diff line number Diff line change
@@ -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\/(.+)$/;
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -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 = [];
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"compilerOptions": {
"target": "ES2022",
"lib": [
"dom",
"dom.iterable",
"DOM",
"DOM.Iterable",
"ES2022",
"WebWorker"
],
Expand Down

0 comments on commit e087b87

Please sign in to comment.