feat: Remove unused code and update types

This commit is contained in:
Mauro Balades 2024-08-06 10:29:56 +02:00
parent 6ad0e99b54
commit 8d0d7b3902
9 changed files with 106 additions and 135 deletions

View file

@ -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"
}
}

View file

@ -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);
}
}
}

View file

@ -1,2 +0,0 @@
export * from './split-views';

View file

@ -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');
}
};

98
src/splitViews.mjs Normal file
View file

@ -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');
}
};

View file

@ -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;
};

View file

@ -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 */

View file

@ -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'
},
};