Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added typescript declaration files #77

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "2.4.1",
"description": "Manage your js components",
"main": "packages/core/core.js",
"typings": "./types/core/core.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/sulu/web-js.git"
Expand All @@ -29,9 +30,9 @@
"jquery": ">=1.7.2"
},
"devDependencies": {
"jquery": ">=1.7.2",
"eslint": "^4.19.1",
"eslint-config-ma": "^1.0.1",
"jquery": ">=1.7.2",
"postcss": "^8.4.7",
"postcss-scss": "^4.0.3",
"stylelint": "^14.0.0",
Expand Down
22 changes: 22 additions & 0 deletions types/components/accordion/accordion.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
declare interface AccordionItem {
container: HTMLElement;
button: HTMLElement;
body: HTMLElement;
}

declare interface AccordionOptions {
modifier?: string;
}

declare interface Accordion {
initialize(el: HTMLElement, options: AccordionOptions): void;
addClickListenersToAccordionButtons(): void;
toggle(item: AccordionItem): void;
toggleAttribute(element: HTMLElement, attributeName: string): void;
}

declare const Accordion: {
new (): Accordion;
};

export = Accordion;
11 changes: 11 additions & 0 deletions types/components/container-link/container-link.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare interface ContainerLink {
initialize(el: HTMLElement): void;
bindEvents(): void;
gotoFirstLink(event: Event): void;
}

declare const ContainerLink: {
new (): ContainerLink;
};

export = ContainerLink;
19 changes: 19 additions & 0 deletions types/components/expand/expand.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
declare interface ExpandOptions {
closeOnEsc?: boolean;
container?: string;
modifier?: string;
}

declare interface Expand {
initialize(el: HTMLElement, options: ExpandOptions): void;
getFirstClass(element: HTMLElement): string;
bindEvents(): void;
toggle(): void;
close(): void;
}

declare const Expand: {
new (): Expand;
};

export = Expand;
15 changes: 15 additions & 0 deletions types/components/scroll-direction/scroll-direction.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
declare interface ScrollDirectionOptions {
upClass?: string;
downClass?: string;
}

declare interface ScrollDirection {
initialize(el: HTMLElement, options: ScrollDirectionOptions): void;
checkPosition(el: HTMLElement): void;
}

declare const ScrollDirection: {
new (): ScrollDirection;
};

export = ScrollDirection;
16 changes: 16 additions & 0 deletions types/components/scroll-menu/scroll-menu.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
declare interface ScrollMenuOptions {
tolerance?: number;
upClass?: string;
downClass?: string;
}

declare interface ScrollMenu {
initialize(el: HTMLElement, options: ScrollMenuOptions): void;
checkPosition(el: HTMLElement): void;
}

declare const ScrollMenu: {
new (): ScrollMenu;
};

export = ScrollMenu;
11 changes: 11 additions & 0 deletions types/components/tabs/tabs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare interface Tabs {
initialize(el: HTMLElement): void;
bindEvents(): void;
toggle(item: { button: HTMLElement; body: HTMLElement }): void;
}

declare const Tabs: {
new (): Tabs;
};

export = Tabs;
11 changes: 11 additions & 0 deletions types/components/toggle/toggle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare interface Toggle {
initialize(el: HTMLElement, options: { modifier?: string }): void;
bindEvents(): void;
toggleClass(): void;
}

declare const Toggle: {
new (): Toggle;
};

export = Toggle;
11 changes: 11 additions & 0 deletions types/components/truncate/truncate.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare interface Truncate {
initialize(el: HTMLElement, options: { separator?: string, debounceDelay?: number }): void;
calculateRegex(): void;
calculateText(): void;
}

declare const Truncate: {
new (): Truncate;
};

export = Truncate;
10 changes: 10 additions & 0 deletions types/components/window-scroll/window-scroll.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare interface WindowScroll {
initialize(el: HTMLElement, options: { offset?: number }): void;
checkPosition(el: HTMLElement): void;
}

declare const WindowScroll: {
new (): WindowScroll;
};

export = WindowScroll;
30 changes: 30 additions & 0 deletions types/core/core.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
declare interface Component {
name: string;
id: string;
options: unknown;
}

declare const web: {
registerService(name: string, service: object): void;
getService(name: string): object | undefined;
hasService(name: string): boolean;
callService(name: string, method: string, args: string): object | undefined;
callServices(services: Component[]): object[];
startComponent(name: string, id: string, options: object): object | undefined;
startComponents(components: Component[]): void;
hasComponent(name: string): boolean;
getElement(id: string): HTMLElement | null;
removeElement(id: string): void;
getBaseComponent(name: string): object;
registerComponent(
name: string,
component: object,
defaultOptions?: object
): void;
getComponent(id: string): object | undefined;
removeComponent(component: object | string): void;
destroyComponentInstance(id: string): void;
emitError(): void;
};

export = web;
26 changes: 26 additions & 0 deletions types/experimental/lazy/lazy.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
declare interface LazyComponent {
name: string;
id: string;
options?: unknown;
}

declare interface LazyService {
name: string;
func: string;
args?: unknown;
}

declare interface Lazy {
registerComponent(name: string, component: object): void;
registerService(name: string, service: object): void;
startComponent(component: LazyComponent): void;
loadComponent(componentName: string): void;
startService(service: LazyService): void;
loadService(serviceName: string): void;
startComponents(components: LazyComponent[]): void;
startServices(services: LazyService[]): void;
}

declare const lazy: Lazy;

export = lazy;
10 changes: 10 additions & 0 deletions types/services/api/api.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare interface Api {
get(uri: string, data?: object): Promise<unknown>;
post(uri: string, data?: object): Promise<unknown>;
put(uri: string, data?: object): Promise<unknown>;
delete(uri: string, data?: object): Promise<unknown>;
}

declare const api: Api;

export = api;
7 changes: 7 additions & 0 deletions types/services/debounce/debounce.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare function debounce<T extends (...args: unknown[]) => void>(
func: T,
wait: number,
immediate?: boolean
): (...args: Parameters<T>) => void;

export = debounce;
13 changes: 13 additions & 0 deletions types/services/google-map-library/google-map-library.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
declare namespace GoogleMapLibrary {
interface Library {
key: string;
promise: Promise<unknown> | null;
setKey(key: string): void;
getKey(): string;
load(): Promise<unknown>;
}
}

declare const GoogleMapLibrary: GoogleMapLibrary.Library;

export = GoogleMapLibrary;
3 changes: 3 additions & 0 deletions types/services/passive-events/passive-events.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const supportsPassive: boolean;

export = supportsPassive;