mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 01:29:57 +02:00
feat: Add SplitViewsBase class with event listeners and public API
This commit is contained in:
parent
d4e80c2719
commit
bde9763255
9 changed files with 746 additions and 43 deletions
29
package-lock.json
generated
Normal file
29
package-lock.json
generated
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "components",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "components",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"typescript": "^5.5.4"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.5.4",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz",
|
||||
"integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
16
package.json
Normal file
16
package.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "components",
|
||||
"version": "1.0.0",
|
||||
"description": "Some components used by @zen-browser and @Floorp-Projects as an attempt to make firefox forks a better place",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": "tsc"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"typescript": "^5.5.4"
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
};
|
520
src/common/gecko.d.ts
vendored
Normal file
520
src/common/gecko.d.ts
vendored
Normal file
|
@ -0,0 +1,520 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// https://github.com/Floorp-Projects/Floorp-core/blob/95ce9eb44c06a682e9d6379eaa4a5d1bbd5db6cd/%40types/gecko.d.ts#L198
|
||||
|
||||
/**
|
||||
* Namespace anything that has its types mocked out here. These definitions are
|
||||
* only "good enough" to get the type checking to pass in this directory.
|
||||
* Eventually some more structured solution should be found. This namespace is
|
||||
* global and makes sure that all the definitions inside do not clash with
|
||||
* naming.
|
||||
*/
|
||||
declare namespace MockedExports {
|
||||
/**
|
||||
* This interface teaches ChromeUtils.import how to find modules.
|
||||
*/
|
||||
interface KnownModules {
|
||||
"resource://gre/modules/FileUtils.sys.mjs": FileUtils;
|
||||
"resource://gre/modules/FileUtils.jsm": FileUtils;
|
||||
|
||||
Services: Services;
|
||||
"resource://gre/modules/Services.jsm": Services;
|
||||
"resource://gre/modules/AppConstants.sys.mjs": typeof AppConstantsSYSMJS;
|
||||
"resource:///modules/CustomizableUI.sys.mjs": typeof CustomizableUISYSMJS;
|
||||
"resource:///modules/CustomizableWidgets.sys.mjs": typeof CustomizableWidgetsSYSMJS;
|
||||
"resource://devtools/shared/loader/Loader.sys.mjs": typeof LoaderESM;
|
||||
//"resource://devtools/client/performance-new/shared/background.jsm.js": typeof import("resource://devtools/client/performance-new/shared/background.jsm.js");
|
||||
//"resource://devtools/client/performance-new/shared/symbolication.jsm.js": typeof import("resource://devtools/client/performance-new/shared/symbolication.jsm.js");
|
||||
"resource://devtools/shared/loader/browser-loader.js": any;
|
||||
//"resource://devtools/client/performance-new/popup/menu-button.jsm.js": typeof import("resource://devtools/client/performance-new/popup/menu-button.jsm.js");
|
||||
//"resource://devtools/client/performance-new/shared/typescript-lazy-load.jsm.js": typeof import("resource://devtools/client/performance-new/shared/typescript-lazy-load.jsm.js");
|
||||
//"resource://devtools/client/performance-new/popup/logic.jsm.js": typeof import("resource://devtools/client/performance-new/popup/logic.jsm.js");
|
||||
"resource:///modules/PanelMultiView.sys.mjs": typeof PanelMultiViewSYSMJS;
|
||||
}
|
||||
|
||||
type Services = {
|
||||
Services: import("firefox").Services;
|
||||
};
|
||||
|
||||
type FileUtils = {
|
||||
FileUtils: IFileUtils;
|
||||
};
|
||||
|
||||
interface IFileUtils {
|
||||
MODE_RDONLY: number;
|
||||
MODE_WRONLY: number;
|
||||
MODE_RDWR: number;
|
||||
MODE_CREATE: number;
|
||||
MODE_APPEND: number;
|
||||
MODE_TRUNCATE: number;
|
||||
|
||||
PERMS_FILE: number;
|
||||
PERMS_DIRECTORY: number;
|
||||
/**
|
||||
* Gets a file at the specified hierarchy under a nsIDirectoryService key.
|
||||
* @param key
|
||||
* The Directory Service Key to start from
|
||||
* @param pathArray
|
||||
* An array of path components to locate beneath the directory
|
||||
* specified by |key|. The last item in this array must be the
|
||||
* leaf name of a file.
|
||||
* @return nsIFile object for the file specified. The file is NOT created
|
||||
* if it does not exist, however all required directories along
|
||||
* the way are if pathArray has more than one item.
|
||||
*/
|
||||
getFile: (key: any, pathArray: any) => any;
|
||||
/**
|
||||
* Gets a directory at the specified hierarchy under a nsIDirectoryService
|
||||
* key.
|
||||
* @param key
|
||||
* The Directory Service Key to start from
|
||||
* @param pathArray
|
||||
* An array of path components to locate beneath the directory
|
||||
* specified by |key|
|
||||
* @param shouldCreate
|
||||
* true if the directory hierarchy specified in |pathArray|
|
||||
* should be created if it does not exist, false otherwise.
|
||||
* @return nsIFile object for the location specified.
|
||||
*/
|
||||
getDir: (key, pathArray, shouldCreate) => any;
|
||||
/**
|
||||
* Opens a file output stream for writing.
|
||||
* @param file
|
||||
* The file to write to.
|
||||
* @param modeFlags
|
||||
* (optional) File open flags. Can be undefined.
|
||||
* @returns nsIFileOutputStream to write to.
|
||||
* @note The stream is initialized with the DEFER_OPEN behavior flag.
|
||||
* See nsIFileOutputStream.
|
||||
*/
|
||||
openFileOutputStream: (file, modeFlags) => any;
|
||||
/**
|
||||
* Opens an atomic file output stream for writing.
|
||||
* @param file
|
||||
* The file to write to.
|
||||
* @param modeFlags
|
||||
* (optional) File open flags. Can be undefined.
|
||||
* @returns nsIFileOutputStream to write to.
|
||||
* @note The stream is initialized with the DEFER_OPEN behavior flag.
|
||||
* See nsIFileOutputStream.
|
||||
* OpeanAtomicFileOutputStream is generally better than openSafeFileOutputStream
|
||||
* baecause flushing is not needed in most of the issues.
|
||||
*/
|
||||
openAtomicFileOutputStream: (file, modeFlags) => any;
|
||||
/**
|
||||
* Opens a safe file output stream for writing.
|
||||
* @param file
|
||||
* The file to write to.
|
||||
* @param modeFlags
|
||||
* (optional) File open flags. Can be undefined.
|
||||
* @returns nsIFileOutputStream to write to.
|
||||
* @note The stream is initialized with the DEFER_OPEN behavior flag.
|
||||
* See nsIFileOutputStream.
|
||||
*/
|
||||
openSafeFileOutputStream: (file, modeFlags) => any;
|
||||
|
||||
_initFileOutputStream: (fos, file, modeFlags) => any;
|
||||
/**
|
||||
* Closes an atomic file output stream.
|
||||
* @param stream
|
||||
* The stream to close.
|
||||
*/
|
||||
|
||||
closeAtomicFileOutputStream: <
|
||||
Stream extends
|
||||
import("firefox").Components_Interfaces["nsISafeOutputStream"] & any,
|
||||
>(
|
||||
stream: Stream
|
||||
) => void;
|
||||
/**
|
||||
* Closes a safe file output stream.
|
||||
* @param stream
|
||||
* The stream to close.
|
||||
*/
|
||||
closeSafeFileOutputStream: <
|
||||
Stream extends
|
||||
import("firefox").Components_Interfaces["nsISafeOutputStream"] & any,
|
||||
>(
|
||||
stream: Stream
|
||||
) => void;
|
||||
File: any;
|
||||
}
|
||||
|
||||
//TODO: add to window
|
||||
interface MozXULElement {
|
||||
/**
|
||||
* Allows eager deterministic construction of XUL elements with XBL attached, by
|
||||
* parsing an element tree and returning a DOM fragment to be inserted in the
|
||||
* document before any of the inner elements is referenced by JavaScript.
|
||||
*
|
||||
* This process is required instead of calling the createElement method directly
|
||||
* because bindings get attached when:
|
||||
*
|
||||
* 1. the node gets a layout frame constructed, or
|
||||
* 2. the node gets its JavaScript reflector created, if it's in the document,
|
||||
*
|
||||
* whichever happens first. The createElement method would return a JavaScript
|
||||
* reflector, but the element wouldn't be in the document, so the node wouldn't
|
||||
* get XBL attached. After that point, even if the node is inserted into a
|
||||
* document, it won't get XBL attached until either the frame is constructed or
|
||||
* the reflector is garbage collected and the element is touched again.
|
||||
*
|
||||
* @param {string} str
|
||||
* String with the XML representation of XUL elements.
|
||||
* @param {string[]} [entities]
|
||||
* An array of DTD URLs containing entity definitions.
|
||||
*
|
||||
* @return {DocumentFragment} `DocumentFragment` instance containing
|
||||
* the corresponding element tree, including element nodes
|
||||
* but excluding any text node.
|
||||
*/
|
||||
parseXULToFragment: (str: string, entities: string[]) => DocumentFragment;
|
||||
}
|
||||
|
||||
interface ChromeUtils {
|
||||
/**
|
||||
* This function reads the KnownModules and resolves which import to use.
|
||||
* If you are getting the TS2345 error:
|
||||
*
|
||||
* Argument of type '"resource:///.../file.jsm"' is not assignable to parameter
|
||||
* of type
|
||||
*
|
||||
* Then add the file path to the KnownModules above.
|
||||
*/
|
||||
import: <S extends keyof KnownModules>(module: S) => KnownModules[S];
|
||||
importESModule: <S extends keyof KnownModules>(
|
||||
module: S
|
||||
) => KnownModules[S];
|
||||
defineModuleGetter: (target: any, variable: string, path: string) => void;
|
||||
defineESModuleGetters: (target: any, mappings: any) => void;
|
||||
}
|
||||
|
||||
interface MessageManager {
|
||||
loadFrameScript(url: string, flag: boolean): void;
|
||||
sendAsyncMessage: (event: string, data: any) => void;
|
||||
addMessageListener: (event: string, listener: (event: any) => void) => void;
|
||||
}
|
||||
|
||||
interface Browser {
|
||||
addWebTab: (url: string, options: any) => BrowserTab;
|
||||
contentPrincipal: any;
|
||||
selectedTab: BrowserTab;
|
||||
selectedBrowser?: ChromeBrowser;
|
||||
messageManager: MessageManager;
|
||||
ownerDocument?: ChromeDocument;
|
||||
}
|
||||
|
||||
interface BrowserTab extends HTMLElement {
|
||||
linkedBrowser: Browser;
|
||||
}
|
||||
|
||||
interface ChromeWindow {
|
||||
gBrowser: Browser;
|
||||
focus(): void;
|
||||
openWebLinkIn(
|
||||
url: string,
|
||||
where: "current" | "tab" | "window",
|
||||
options: Partial<{
|
||||
// Not all possible options are present, please add more if/when needed.
|
||||
userContextId: number;
|
||||
forceNonPrivate: boolean;
|
||||
resolveOnContentBrowserCreated: (
|
||||
contentBrowser: ChromeBrowser
|
||||
) => unknown;
|
||||
}>
|
||||
): void;
|
||||
}
|
||||
|
||||
interface ChromeBrowser {
|
||||
browsingContext?: BrowsingContext;
|
||||
}
|
||||
|
||||
interface BrowsingContext {
|
||||
/**
|
||||
* A unique identifier for the browser element that is hosting this
|
||||
* BrowsingContext tree. Every BrowsingContext in the element's tree will
|
||||
* return the same ID in all processes and it will remain stable regardless of
|
||||
* process changes. When a browser element's frameloader is switched to
|
||||
* another browser element this ID will remain the same but hosted under the
|
||||
* under the new browser element.
|
||||
* We are using this identifier for getting the active tab ID and passing to
|
||||
* the profiler back-end. See `getActiveBrowserID` for the usage.
|
||||
*/
|
||||
browserId: number;
|
||||
}
|
||||
|
||||
type GetPref<T> = (prefName: string, defaultValue?: T) => T;
|
||||
type SetPref<T> = (prefName: string, value?: T) => T;
|
||||
|
||||
type PrefObserverFunction = (
|
||||
aSubject: import("./firefox/modules/libpref/nsIPrefBranch").nsIPrefBranch,
|
||||
aTopic: "nsPref:changed",
|
||||
aData: string
|
||||
) => unknown;
|
||||
type PrefObserver = PrefObserverFunction | { observe: PrefObserverFunction };
|
||||
|
||||
interface SharedLibrary {
|
||||
start: number;
|
||||
end: number;
|
||||
offset: number;
|
||||
name: string;
|
||||
path: string;
|
||||
debugName: string;
|
||||
debugPath: string;
|
||||
breakpadId: string;
|
||||
arch: string;
|
||||
}
|
||||
|
||||
interface ProfileGenerationAdditionalInformation {
|
||||
sharedLibraries: SharedLibrary[];
|
||||
}
|
||||
|
||||
interface ProfileAndAdditionalInformation {
|
||||
profile: ArrayBuffer;
|
||||
additionalInformation?: ProfileGenerationAdditionalInformation;
|
||||
}
|
||||
|
||||
const EventEmitter: {
|
||||
decorate: (target: object) => void;
|
||||
};
|
||||
|
||||
const AppConstantsSYSMJS: {
|
||||
AppConstants: {
|
||||
platform: string;
|
||||
};
|
||||
};
|
||||
|
||||
interface BrowsingContextStub {}
|
||||
interface PrincipalStub {}
|
||||
|
||||
interface WebChannelTarget {
|
||||
browsingContext: BrowsingContextStub;
|
||||
browser: Browser;
|
||||
eventTarget: null;
|
||||
principal: PrincipalStub;
|
||||
}
|
||||
|
||||
// TS-TODO
|
||||
const CustomizableUISYSMJS: any;
|
||||
const CustomizableWidgetsSYSMJS: any;
|
||||
const PanelMultiViewSYSMJS: any;
|
||||
|
||||
const LoaderESM: {
|
||||
require: (path: string) => any;
|
||||
};
|
||||
|
||||
//const Services: Services;
|
||||
|
||||
// This class is needed by the Cc importing mechanism. e.g.
|
||||
// Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
|
||||
//class nsIFilePicker {}
|
||||
|
||||
interface FilePicker {
|
||||
init: (window: Window, title: string, mode: number) => void;
|
||||
open: (callback: (rv: number) => unknown) => void;
|
||||
// The following are enum values.
|
||||
modeGetFolder: number;
|
||||
returnOK: number;
|
||||
file: {
|
||||
path: string;
|
||||
};
|
||||
}
|
||||
|
||||
// interface Cc {
|
||||
// "@mozilla.org/filepicker;1": {
|
||||
// createInstance(instance: nsIFilePicker): FilePicker;
|
||||
// };
|
||||
// }
|
||||
|
||||
// interface Ci {
|
||||
// nsIFilePicker: nsIFilePicker;
|
||||
// }
|
||||
|
||||
// interface Cu {
|
||||
// /**
|
||||
// * This function reads the KnownModules and resolves which import to use.
|
||||
// * If you are getting the TS2345 error:
|
||||
// *
|
||||
// * Argument of type '"resource:///.../file.jsm"' is not assignable to parameter
|
||||
// * of type
|
||||
// *
|
||||
// * Then add the file path to the KnownModules above.
|
||||
// */
|
||||
// import: <S extends keyof KnownModules>(module: S) => KnownModules[S];
|
||||
// exportFunction: (fn: Function, scope: object, options?: object) => void;
|
||||
// cloneInto: (value: any, scope: object, options?: object) => void;
|
||||
// isInAutomation: boolean;
|
||||
// }
|
||||
|
||||
interface FluentLocalization {
|
||||
/**
|
||||
* This function sets the attributes data-l10n-id and possibly data-l10n-args
|
||||
* on the element.
|
||||
*/
|
||||
setAttributes(
|
||||
target: Element,
|
||||
id?: string,
|
||||
args?: Record<string, string>
|
||||
): void;
|
||||
}
|
||||
}
|
||||
|
||||
interface PathUtilsInterface {
|
||||
split: (path: string) => string[];
|
||||
isAbsolute: (path: string) => boolean;
|
||||
}
|
||||
|
||||
// export module "resource://devtools/client/shared/vendor/react.js" {
|
||||
// import * as React from "react";
|
||||
// export = React;
|
||||
// }
|
||||
|
||||
// declare module "resource://devtools/client/shared/vendor/react-dom-factories.js" {
|
||||
// import * as ReactDomFactories from "react-dom-factories";
|
||||
// export = ReactDomFactories;
|
||||
// }
|
||||
|
||||
// declare module "resource://devtools/client/shared/vendor/redux.js" {
|
||||
// import * as Redux from "redux";
|
||||
// export = Redux;
|
||||
// }
|
||||
|
||||
// declare module "resource://devtools/client/shared/vendor/react-redux.js" {
|
||||
// import * as ReactRedux from "react-redux";
|
||||
// export = ReactRedux;
|
||||
// }
|
||||
|
||||
// declare module "resource://devtools/shared/event-emitter2.js" {
|
||||
// export = MockedExports.EventEmitter;
|
||||
// }
|
||||
|
||||
// declare module "Services" {
|
||||
// export = Services;
|
||||
// }
|
||||
|
||||
// declare module "ChromeUtils" {
|
||||
// export = ChromeUtils;
|
||||
// }
|
||||
|
||||
// declare module "resource://gre/modules/AppConstants.sys.mjs" {
|
||||
// export = MockedExports.AppConstantsSYSMJS;
|
||||
// }
|
||||
|
||||
// declare module "resource://devtools/client/performance-new/shared/background.jsm.js" {
|
||||
// import * as Background from "devtools/client/performance-new/shared/background.jsm.js";
|
||||
// export = Background;
|
||||
// }
|
||||
|
||||
// declare module "resource://devtools/client/performance-new/shared/symbolication.jsm.js" {
|
||||
// import * as PerfSymbolication from "devtools/client/performance-new/shared/symbolication.jsm.js";
|
||||
// export = PerfSymbolication;
|
||||
// }
|
||||
|
||||
// declare module "resource:///modules/CustomizableUI.sys.mjs" {
|
||||
// export = MockedExports.CustomizableUISYSMJS;
|
||||
// }
|
||||
|
||||
// declare module "resource:///modules/CustomizableWidgets.sys.mjs" {
|
||||
// export = MockedExports.CustomizableWidgetsSYSMJS;
|
||||
// }
|
||||
|
||||
// declare module "resource:///modules/PanelMultiView.sys.mjs" {
|
||||
// export = MockedExports.PanelMultiViewSYSMJS;
|
||||
// }
|
||||
|
||||
// declare module "resource://devtools/shared/loader/Loader.sys.mjs" {
|
||||
// export = MockedExports.LoaderESM;
|
||||
// }
|
||||
|
||||
declare var ChromeUtils: MockedExports.ChromeUtils;
|
||||
|
||||
declare var PathUtils: PathUtilsInterface;
|
||||
|
||||
/**
|
||||
* This is a variant on the normal Document, as it contains chrome-specific properties.
|
||||
*/
|
||||
declare interface ChromeDocument extends Document {
|
||||
/**
|
||||
* Create a XUL element of a specific type. Right now this function
|
||||
* only refines iframes, but more tags could be added.
|
||||
*/
|
||||
createXULElement: ((type: "iframe") => XULIframeElement) &
|
||||
((type: string) => XULElement);
|
||||
|
||||
/**
|
||||
* This is a fluent instance connected to this document.
|
||||
*/
|
||||
l10n: MockedExports.FluentLocalization;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a variant on the HTMLElement, as it contains chrome-specific properties.
|
||||
*/
|
||||
declare interface ChromeHTMLElement extends HTMLElement {
|
||||
ownerDocument: ChromeDocument;
|
||||
}
|
||||
|
||||
declare interface XULElement extends HTMLElement {
|
||||
ownerDocument: ChromeDocument;
|
||||
}
|
||||
|
||||
declare interface XULIframeElement extends XULElement {
|
||||
contentWindow: ChromeWindow;
|
||||
src: string;
|
||||
}
|
||||
|
||||
declare interface ChromeWindow extends Window {
|
||||
openWebLinkIn: (
|
||||
url: string,
|
||||
where: "current" | "tab" | "tabshifted" | "window" | "save",
|
||||
// TS-TODO
|
||||
params?: unknown
|
||||
) => void;
|
||||
openTrustedLinkIn: (
|
||||
url: string,
|
||||
where: "current" | "tab" | "tabshifted" | "window" | "save",
|
||||
// TS-TODO
|
||||
params?: unknown
|
||||
) => void;
|
||||
}
|
||||
|
||||
declare class ChromeWorker extends Worker {}
|
||||
|
||||
declare interface MenuListElement extends XULElement {
|
||||
value: string;
|
||||
disabled: boolean;
|
||||
}
|
||||
|
||||
declare interface XULCommandEvent extends Event {
|
||||
target: XULElement;
|
||||
}
|
||||
|
||||
declare interface XULElementWithCommandHandler {
|
||||
addEventListener: (
|
||||
type: "command",
|
||||
handler: (event: XULCommandEvent) => void,
|
||||
isCapture?: boolean
|
||||
) => void;
|
||||
removeEventListener: (
|
||||
type: "command",
|
||||
handler: (event: XULCommandEvent) => void,
|
||||
isCapture?: boolean
|
||||
) => void;
|
||||
}
|
||||
|
||||
//declare type nsIPrefBranch = MockedExports.nsIPrefBranch;
|
||||
|
||||
// chrome context-only DOM isInstance method
|
||||
// XXX: This hackishly extends Function because there is no way to extend DOM constructors.
|
||||
// Callers should manually narrow the type when needed.
|
||||
// See also https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/222
|
||||
interface Function {
|
||||
isInstance(obj: any): boolean;
|
||||
}
|
||||
|
||||
declare module "resource://gre/modules/FileUtils.sys.mjs" {
|
||||
const FileUtils: MockedExports.IFileUtils;
|
||||
export { FileUtils };
|
||||
}
|
79
src/split-views/index.ts
Normal file
79
src/split-views/index.ts
Normal file
|
@ -0,0 +1,79 @@
|
|||
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
// Public API exposed by the module
|
||||
export class gSplitViews 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');
|
||||
}
|
||||
};
|
|
@ -7,9 +7,7 @@ export interface SplitViewConfig extends Config {
|
|||
defaultSplitView: SplitType;
|
||||
};
|
||||
|
||||
export type Tab = HTMLDivElement;
|
||||
|
||||
export interface SplitView {
|
||||
type: SplitType;
|
||||
tabs: Tab[];
|
||||
tabs: MockedExports.BrowserTab[];
|
||||
};
|
101
tsconfig.json
Normal file
101
tsconfig.json
Normal file
|
@ -0,0 +1,101 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
|
||||
// "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
|
||||
/* Modules */
|
||||
"module": "commonjs", /* Specify what module code is generated. */
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
// "moduleResolution": "node", /* 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. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
|
||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "resolveJsonModule": true, /* Enable importing .json files */
|
||||
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
/* 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. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
|
||||
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
"outFile": "./dist/components.js", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
|
||||
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
||||
|
||||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
|
||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||
// "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
|
||||
// "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
|
||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
// "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
|
||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue