From 8d0d7b3902d4b04c9a894e1e6edfd0d63e51ace4 Mon Sep 17 00:00:00 2001 From: Mauro Balades Date: Tue, 6 Aug 2024 10:29:56 +0200 Subject: [PATCH] feat: Remove unused code and update types --- package.json | 7 +- src/common/component.ts | 15 ---- src/common/{config.ts => index.d.ts} | 0 src/index.ts | 2 - src/split-views/index.ts | 85 -------------------- src/splitViews.mjs | 98 ++++++++++++++++++++++++ src/{split-views/types.ts => types.d.ts} | 4 +- tsconfig.json | 7 +- webpack.config.js | 23 ------ 9 files changed, 106 insertions(+), 135 deletions(-) delete mode 100644 src/common/component.ts rename src/common/{config.ts => index.d.ts} (100%) delete mode 100644 src/index.ts delete mode 100644 src/split-views/index.ts create mode 100644 src/splitViews.mjs rename src/{split-views/types.ts => types.d.ts} (71%) delete mode 100644 webpack.config.js diff --git a/package.json b/package.json index eab510d..44209f0 100644 --- a/package.json +++ b/package.json @@ -5,15 +5,12 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "build": "webpack --mode production" + "check": "tsc" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { - "ts-loader": "^9.5.1", - "typescript": "^5.5.4", - "webpack": "^5.93.0", - "webpack-cli": "^5.1.4" + "typescript": "^5.5.4" } } diff --git a/src/common/component.ts b/src/common/component.ts deleted file mode 100644 index 351d8f2..0000000 --- a/src/common/component.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Config } from "./config"; - -export default class Component { - readonly config: Config; - - constructor(config: Config) { - this.config = config; - } - - log(message: string) { - if (this.config.debug) { - console.log(this.config.browserName + ': ' + message); - } - } -} diff --git a/src/common/config.ts b/src/common/index.d.ts similarity index 100% rename from src/common/config.ts rename to src/common/index.d.ts diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index 500cee4..0000000 --- a/src/index.ts +++ /dev/null @@ -1,2 +0,0 @@ - -export * from './split-views'; diff --git a/src/split-views/index.ts b/src/split-views/index.ts deleted file mode 100644 index 5e3def8..0000000 --- a/src/split-views/index.ts +++ /dev/null @@ -1,85 +0,0 @@ - -import Component from '../common/component'; -import { SplitViewConfig, SplitView, SplitType } from './types'; - -class SplitViewsBase extends Component { - data: SplitView[]; - currentView: number; - - constructor(config: SplitViewConfig) { - super(config); - this.data = []; - this.currentView = -1; - this.addEventListeners(); - this.log('SplitViewsBase initialized'); - } - - get viewConfig() { - return this.config as SplitViewConfig; - } - - addEventListeners() { - window.addEventListener('TabClose', this); - } - - handleEvent(event: Event) { - switch (event.type) { - case 'TabClose': - this.onTabClose(event as CustomEvent); - break; - } - } - - onTabClose(event: CustomEvent) { - } - - public get isActivated() { - return this.currentView !== -1; - } - - get activeView() { - if (!this.isActivated) { - throw new Error('No active view'); - } - return this.data[this.currentView]; - } -} - -declare global { - interface Window { - gSplitViewsComponent: typeof SplitViewsBase; - } -} - -// Public API exposed by the module -window.gSplitViewsComponent = class extends SplitViewsBase { - constructor(config: SplitViewConfig) { - super(config); - } - - public onLocationChange(browser: MockedExports.Browser) { - this.log('onLocationChange'); - } - - public tileCurrentView(type: SplitType) { - this.log('tileCurrentView'); - } - - public closeCurrentView() { - this.log('closeCurrentView'); - } - - public tabIsInActiveView(tab: MockedExports.BrowserTab) { - this.log('tabIsInActiveView'); - return false; - } - - public getActiveViewTabs() { - this.log('getActiveViewTabs'); - return []; - } - - public createSplitView(tabs: MockedExports.BrowserTab[], type: SplitType = this.viewConfig.defaultSplitView) { - this.log('createSplitView'); - } -}; diff --git a/src/splitViews.mjs b/src/splitViews.mjs new file mode 100644 index 0000000..ecdc2a1 --- /dev/null +++ b/src/splitViews.mjs @@ -0,0 +1,98 @@ + +class SplitViewsBase { + /** + * @param {SplitViewConfig} config + * @param {SplitViewData[]} data + * @param {number} currentView + * @param {SplitViewConfig} config + */ + constructor(config) { + this.config = config.awd; + this.data = []; + this.currentView = -1; + this.addEventListeners(); + this.log('SplitViewsBase initialized'); + } + + addEventListeners() { + window.addEventListener('TabClose', this); + } + + /** + * @param {Event} event + */ + handleEvent(event) { + switch (event.type) { + case 'TabClose': + this.onTabClose(event); + break; + } + } + + /** + * @param {Event} event + */ + onTabClose(event) { + } + + get isActivated() { + return this.currentView !== -1; + } + + get activeView() { + if (!this.isActivated) { + throw new Error('No active view'); + } + return this.data[this.currentView]; + } +} + +// Public API exposed by the module +export class SplitViews extends SplitViewsBase { + /** + * @param {SplitViewConfig} config + */ + constructor(config) { + super(config); + } + + /** + * @param {MockedExports.Browser} browser + */ + onLocationChange(browser) { + this.log('onLocationChange'); + } + + /** + * @param {SplitType} type + */ + tileCurrentView(type) { + this.log('tileCurrentView'); + } + + closeCurrentView() { + this.log('closeCurrentView'); + } + + /** + * @param {MockedExports.BrowserTab} tab + */ + tabIsInActiveView(tab) { + this.log('tabIsInActiveView'); + return false; + } + + getActiveViewTabs() { + this.log('getActiveViewTabs'); + return []; + } + + /** + * @param {MockedExports.BrowserTab[]} tabs + * @param {SplitType} type + * @private + */ + createSplitView(tabs, type = this.viewConfig.defaultSplitView) { + this.log('createSplitView'); + } +}; diff --git a/src/split-views/types.ts b/src/types.d.ts similarity index 71% rename from src/split-views/types.ts rename to src/types.d.ts index bd30cfb..db9c6a9 100644 --- a/src/split-views/types.ts +++ b/src/types.d.ts @@ -1,8 +1,8 @@ -import { Config } from "../common/config"; +import { Config } from "./common"; export type SplitType = 'horizontal' | 'vertical' | 'grid'; -export interface SplitViewConfig extends Config { +export interface SplitViewConfig { keyIndicator: string; // e.g. "split-tab='true'" defaultSplitView: SplitType; }; diff --git a/tsconfig.json b/tsconfig.json index 9953397..261548d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,14 +23,15 @@ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ // Make the type checking as strict as possible. // TypeScript will check JS files only if they have a @ts-check comment in them. - // "allowJs": true, + "allowJs": true, // Allow esnext syntax. Otherwise the default is ES5 only. "target": "esnext", "lib": ["esnext", "dom"], + "noEmit": true, /* Modules */ "module": "CommonJS", /* Specify what module code is generated. */ - "rootDir": "./src", /* Specify the root folder within your source files. */ + //"rootDir": "./src", /* Specify the root folder within your source files. */ // "moduleResolution": "NodeNext", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ @@ -43,7 +44,7 @@ /* JavaScript Support */ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ /* Emit */ diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index 99bedd6..0000000 --- a/webpack.config.js +++ /dev/null @@ -1,23 +0,0 @@ -const path = require('path'); - -module.exports = { - entry: './src/index.ts', - devtool: 'inline-source-map', - module: { - rules: [ - { - test: /\.tsx?$/, - use: 'ts-loader', - exclude: /node_modules/, - }, - ], - }, - resolve: { - extensions: ['.tsx', '.ts', '.js'], - }, - output: { - filename: 'components.js', - path: path.resolve(__dirname, 'dist'), - library: 'modulename' - }, -}; \ No newline at end of file