mirror of
https://github.com/zen-browser/components.git
synced 2025-07-07 21:39:58 +02:00
Add SplitViewsBase class with event listeners and public API
This commit is contained in:
parent
6b1bf7b7e5
commit
d4e80c2719
4 changed files with 63 additions and 4 deletions
15
common/component.ts
Normal file
15
common/component.ts
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
5
common/config.ts
Normal file
5
common/config.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
export interface Config {
|
||||
debug: boolean;
|
||||
browserName: string;
|
||||
};
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -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[];
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue