diff --git a/common/component.ts b/common/component.ts new file mode 100644 index 0000000..351d8f2 --- /dev/null +++ b/common/component.ts @@ -0,0 +1,15 @@ +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/common/config.ts b/common/config.ts new file mode 100644 index 0000000..9cbebb3 --- /dev/null +++ b/common/config.ts @@ -0,0 +1,5 @@ + +export interface Config { + debug: boolean; + browserName: string; +}; diff --git a/split-views/index.ts b/split-views/index.ts index 139597f..aae81c5 100644 --- a/split-views/index.ts +++ b/split-views/index.ts @@ -1,2 +1,40 @@ +import Component from '../common/component'; +import { SplitViewConfig, SplitView } 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'); + } + + addEventListeners() { + // Add event listeners here like TabClose, TabOpen, etc. + } + + public 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 gSplitViews extends SplitViewsBase { + constructor(config: SplitViewConfig) { + super(config); + } + +}; diff --git a/split-views/types.ts b/split-views/types.ts index 2c91c24..733f7f1 100644 --- a/split-views/types.ts +++ b/split-views/types.ts @@ -1,14 +1,15 @@ +import { Config } from "../common/config"; -type SplitType = 'horizontal' | 'vertical' | 'grid'; +export type SplitType = 'horizontal' | 'vertical' | 'grid'; -interface Config { +export interface SplitViewConfig extends Config { keyIndicator: string; // e.g. "split-tab='true'" defaultSplitView: SplitType; }; -type Tab = any; +export type Tab = HTMLDivElement; -interface SplitView { +export interface SplitView { type: SplitType; tabs: Tab[]; };