|
| 1 | +// Type definitions for modular-openscriptjs |
| 2 | +// Project: https://github.com/OpenScriptJs/modular-openscript |
| 3 | +// Definitions by: OpenScript Team |
| 4 | + |
| 5 | +/** |
| 6 | + * State Management |
| 7 | + */ |
| 8 | +export interface State<T = any> { |
| 9 | + value: T; |
| 10 | + previousValue: T; |
| 11 | + $__id__: string; |
| 12 | + $__name__: string; |
| 13 | + listener(callback: (state: State<T>) => void): void; |
| 14 | + listener(component: Component): void; |
| 15 | + off(componentName: string): void; |
| 16 | +} |
| 17 | + |
| 18 | +export function state<T>(initialValue: T): State<T>; |
| 19 | + |
| 20 | +/** |
| 21 | + * Component System |
| 22 | + */ |
| 23 | +export class Component { |
| 24 | + static aCId: number; |
| 25 | + static uid: number; |
| 26 | + static FRAGMENT: string; |
| 27 | + |
| 28 | + name: string; |
| 29 | + mounted: boolean; |
| 30 | + bound: boolean; |
| 31 | + rendered: boolean; |
| 32 | + rerendered: boolean; |
| 33 | + visible: boolean; |
| 34 | + states: { [key: string]: State }; |
| 35 | + emitter: Emitter; |
| 36 | + EVENTS: { |
| 37 | + rendered: string; |
| 38 | + rerendered: string; |
| 39 | + premount: string; |
| 40 | + mounted: string; |
| 41 | + prebind: string; |
| 42 | + bound: string; |
| 43 | + markupBound: string; |
| 44 | + beforeHidden: string; |
| 45 | + hidden: string; |
| 46 | + unmounted: string; |
| 47 | + beforeVisible: string; |
| 48 | + visible: string; |
| 49 | + }; |
| 50 | + |
| 51 | + constructor(name?: string); |
| 52 | + |
| 53 | + mount(): Promise<void>; |
| 54 | + unmount(): void; |
| 55 | + render(...args: any[]): HTMLElement | DocumentFragment | string | Array<HTMLElement | DocumentFragment | string>; |
| 56 | + emit(event: string, args?: any[]): void; |
| 57 | + on(event: string, ...listeners: Function[]): void; |
| 58 | + onAll(event: string, ...listeners: Function[]): void; |
| 59 | + hide(): boolean; |
| 60 | + show(): boolean; |
| 61 | + cleanUp(): void; |
| 62 | +} |
| 63 | + |
| 64 | +/** |
| 65 | + * Markup Engine (h) |
| 66 | + */ |
| 67 | +export interface MarkupEngine { |
| 68 | + dom: Document; |
| 69 | + |
| 70 | + // HTML Elements |
| 71 | + div(...args: any[]): HTMLDivElement; |
| 72 | + span(...args: any[]): HTMLSpanElement; |
| 73 | + p(...args: any[]): HTMLParagraphElement; |
| 74 | + h1(...args: any[]): HTMLHeadingElement; |
| 75 | + h2(...args: any[]): HTMLHeadingElement; |
| 76 | + h3(...args: any[]): HTMLHeadingElement; |
| 77 | + h4(...args: any[]): HTMLHeadingElement; |
| 78 | + h5(...args: any[]): HTMLHeadingElement; |
| 79 | + h6(...args: any[]): HTMLHeadingElement; |
| 80 | + ul(...args: any[]): HTMLUListElement; |
| 81 | + ol(...args: any[]): HTMLOListElement; |
| 82 | + li(...args: any[]): HTMLLIElement; |
| 83 | + button(...args: any[]): HTMLButtonElement; |
| 84 | + input(...args: any[]): HTMLInputElement; |
| 85 | + textarea(...args: any[]): HTMLTextAreaElement; |
| 86 | + select(...args: any[]): HTMLSelectElement; |
| 87 | + option(...args: any[]): HTMLOptionElement; |
| 88 | + form(...args: any[]): HTMLFormElement; |
| 89 | + label(...args: any[]): HTMLLabelElement; |
| 90 | + a(...args: any[]): HTMLAnchorElement; |
| 91 | + img(...args: any[]): HTMLImageElement; |
| 92 | + table(...args: any[]): HTMLTableElement; |
| 93 | + thead(...args: any[]): HTMLTableSectionElement; |
| 94 | + tbody(...args: any[]): HTMLTableSectionElement; |
| 95 | + tfoot(...args: any[]): HTMLTableSectionElement; |
| 96 | + tr(...args: any[]): HTMLTableRowElement; |
| 97 | + th(...args: any[]): HTMLTableCellElement; |
| 98 | + td(...args: any[]): HTMLTableCellElement; |
| 99 | + header(...args: any[]): HTMLElement; |
| 100 | + footer(...args: any[]): HTMLElement; |
| 101 | + section(...args: any[]): HTMLElement; |
| 102 | + article(...args: any[]): HTMLElement; |
| 103 | + nav(...args: any[]): HTMLElement; |
| 104 | + aside(...args: any[]): HTMLElement; |
| 105 | + main(...args: any[]): HTMLElement; |
| 106 | + |
| 107 | + // Fragment creators |
| 108 | + $(...args: any[]): DocumentFragment; |
| 109 | + _(...args: any[]): DocumentFragment; |
| 110 | + |
| 111 | + // Component helpers |
| 112 | + getComponent(name: string): Component; |
| 113 | + component(name: string, instance: Component): void; |
| 114 | + |
| 115 | + // Generic element creator |
| 116 | + [key: string]: any; |
| 117 | +} |
| 118 | + |
| 119 | +/** |
| 120 | + * Router |
| 121 | + */ |
| 122 | +export class Router { |
| 123 | + params: { [key: string]: string }; |
| 124 | + basePath(path: string): this; |
| 125 | + on(path: string, handler: () => void, name?: string): this; |
| 126 | + prefix(prefix: string): this; |
| 127 | + group(callback: () => void): this; |
| 128 | + default(handler: () => void): this; |
| 129 | + to(name: string, params?: any): void; |
| 130 | + push(path: string): void; |
| 131 | + back(): void; |
| 132 | + listen(): void; |
| 133 | +} |
| 134 | + |
| 135 | +/** |
| 136 | + * Event System |
| 137 | + */ |
| 138 | +export interface EventData { |
| 139 | + meta(data: any): this; |
| 140 | + message(data: any): this; |
| 141 | + encode(): string; |
| 142 | +} |
| 143 | + |
| 144 | +export function payload(message?: any, meta?: any): string; |
| 145 | +export function eData(meta?: any, message?: any): string; |
| 146 | + |
| 147 | +export class Broker { |
| 148 | + registerEvents(events: any): void; |
| 149 | + send(eventName: string, data?: string): void; |
| 150 | + on(eventName: string, callback: (data: any, eventName: string) => void): void; |
| 151 | +} |
| 152 | + |
| 153 | +export class Listener { |
| 154 | + __ojsRegistered?: boolean; |
| 155 | + register(): Promise<void>; |
| 156 | +} |
| 157 | + |
| 158 | +export class Mediator { |
| 159 | + __ojsRegistered?: boolean; |
| 160 | + register(): Promise<void>; |
| 161 | +} |
| 162 | + |
| 163 | +/** |
| 164 | + * Context System |
| 165 | + */ |
| 166 | +export class Context { |
| 167 | + states(stateObj: { [key: string]: any }): void; |
| 168 | + [key: string]: any; |
| 169 | +} |
| 170 | + |
| 171 | +export class ContextProvider { |
| 172 | + map: Map<string, Context>; |
| 173 | + context(name: string): Context; |
| 174 | + load(referenceName: string | string[], qualifiedName: string): void; |
| 175 | +} |
| 176 | + |
| 177 | +export function context(name: string): Context; |
| 178 | +export function putContext(referenceName: string | string[], qualifiedName: string): void; |
| 179 | + |
| 180 | +/** |
| 181 | + * IoC Container |
| 182 | + */ |
| 183 | +export class Container { |
| 184 | + singleton(name: string, implementation: any, dependencies?: string[]): this; |
| 185 | + transient(name: string, implementation: any, dependencies?: string[]): this; |
| 186 | + factory(name: string, factory: (container: Container) => any): this; |
| 187 | + value(name: string, value: any): this; |
| 188 | + resolve<T = any>(name: string): T; |
| 189 | + has(name: string): boolean; |
| 190 | + getServiceNames(): string[]; |
| 191 | + clear(): void; |
| 192 | +} |
| 193 | + |
| 194 | +export const container: Container; |
| 195 | + |
| 196 | +/** |
| 197 | + * App Helper with Overloads for Type Safety |
| 198 | + */ |
| 199 | +export function app(instance: 'h'): MarkupEngine; |
| 200 | +export function app(instance: 'router'): Router; |
| 201 | +export function app(instance: 'broker'): Broker; |
| 202 | +export function app(instance: 'contextProvider'): ContextProvider; |
| 203 | +export function app(instance: 'mediatorManager'): MediatorManager; |
| 204 | +export function app(instance: 'loader'): AutoLoader; |
| 205 | +export function app(instance: 'autoload'): AutoLoader; |
| 206 | +export function app(): Container; |
| 207 | +export function app(instance: string): any; |
| 208 | + |
| 209 | +/** |
| 210 | + * Additional Classes |
| 211 | + */ |
| 212 | +export class Emitter { |
| 213 | + on(event: string, callback: Function): void; |
| 214 | + once(event: string, callback: Function): void; |
| 215 | + emit(event: string, ...args: any[]): void; |
| 216 | +} |
| 217 | + |
| 218 | +export class MediatorManager { |
| 219 | + fetchMediators(qualifiedName: string): void; |
| 220 | +} |
| 221 | + |
| 222 | +export class AutoLoader { |
| 223 | + req(qualifiedName: string): Promise<any>; |
| 224 | + include(qualifiedName: string): Promise<any>; |
| 225 | +} |
| 226 | + |
| 227 | +export class Runner { |
| 228 | + run(...classDeclarations: any[]): Promise<void>; |
| 229 | + getClassKey(classDeclaration: any): string; |
| 230 | +} |
| 231 | + |
| 232 | +export class ProxyFactory { |
| 233 | + static create(target: any, handler: any): any; |
| 234 | +} |
| 235 | + |
| 236 | +export class DOMReconciler { |
| 237 | + reconcile(newNode: Node, oldNode: Node): void; |
| 238 | +} |
| 239 | + |
| 240 | +export class MarkupHandler { |
| 241 | + static proxy(): MarkupEngine; |
| 242 | +} |
| 243 | + |
| 244 | +/** |
| 245 | + * Utilities |
| 246 | + */ |
| 247 | +export namespace Utils { |
| 248 | + function lazyFor<T>(iterable: T[], callback: (item: T, index: number) => any): any[]; |
| 249 | + function each<T>(iterable: T[], callback: (item: T, index: number) => void): void; |
| 250 | + function ifElse(condition: boolean, trueValue: any, falseValue: any): any; |
| 251 | + function coalesce(...values: any[]): any; |
| 252 | + function parsePayload(encodedData: string): { message: any; meta: any }; |
| 253 | +} |
| 254 | + |
| 255 | +export namespace DOM { |
| 256 | + function querySelector(selector: string): HTMLElement | null; |
| 257 | + function querySelectorAll(selector: string): NodeListOf<Element>; |
| 258 | + function createElement(tag: string): HTMLElement; |
| 259 | +} |
| 260 | + |
| 261 | +/** |
| 262 | + * Helper Functions |
| 263 | + */ |
| 264 | +export function ojs(...classDeclarations: any[]): Promise<void>; |
| 265 | +export function req(qualifiedName: string): Promise<any>; |
| 266 | +export function include(qualifiedName: string): Promise<any>; |
| 267 | +export function v(state: State, callback?: (state: State) => any, ...args: any[]): any; |
| 268 | +export function component(name: string): Component; |
| 269 | +export function mediators(names: string[]): void; |
| 270 | +export function isClass(func: any): boolean; |
| 271 | +export function namespace(path: string): any; |
| 272 | + |
| 273 | +/** |
| 274 | + * Vite Plugin |
| 275 | + */ |
| 276 | +export interface OpenScriptComponentPluginOptions { |
| 277 | + componentsDir?: string; |
| 278 | + autoRegister?: boolean; |
| 279 | + generateTypes?: boolean; |
| 280 | +} |
| 281 | + |
| 282 | +export function openScriptComponentPlugin(options?: OpenScriptComponentPluginOptions): any; |
| 283 | + |
| 284 | +/** |
| 285 | + * Default Export |
| 286 | + */ |
| 287 | +declare const _default: { |
| 288 | + Runner: typeof Runner; |
| 289 | + Emitter: typeof Emitter; |
| 290 | + EventData: typeof EventData; |
| 291 | + State: typeof State; |
| 292 | + ContextProvider: typeof ContextProvider; |
| 293 | + Context: typeof Context; |
| 294 | + ProxyFactory: typeof ProxyFactory; |
| 295 | + AutoLoader: typeof AutoLoader; |
| 296 | + Router: typeof Router; |
| 297 | + Broker: typeof Broker; |
| 298 | + Listener: typeof Listener; |
| 299 | + Mediator: typeof Mediator; |
| 300 | + MediatorManager: typeof MediatorManager; |
| 301 | + Component: typeof Component; |
| 302 | + DOMReconciler: typeof DOMReconciler; |
| 303 | + MarkupEngine: typeof MarkupEngine; |
| 304 | + MarkupHandler: typeof MarkupHandler; |
| 305 | + Utils: typeof Utils; |
| 306 | + DOM: typeof DOM; |
| 307 | + app: typeof app; |
| 308 | + isClass: typeof isClass; |
| 309 | + namespace: typeof namespace; |
| 310 | + Container: typeof Container; |
| 311 | + container: typeof container; |
| 312 | + state: typeof state; |
| 313 | + ojs: typeof ojs; |
| 314 | + req: typeof req; |
| 315 | + include: typeof include; |
| 316 | + v: typeof v; |
| 317 | + context: typeof context; |
| 318 | + putContext: typeof putContext; |
| 319 | + each: typeof Utils.each; |
| 320 | + ifElse: typeof Utils.ifElse; |
| 321 | + coalesce: typeof Utils.coalesce; |
| 322 | + dom: typeof DOM; |
| 323 | + component: typeof component; |
| 324 | + mediators: typeof mediators; |
| 325 | + eData: typeof eData; |
| 326 | + payload: typeof payload; |
| 327 | + ojsRouterEvents: any; |
| 328 | +}; |
| 329 | + |
| 330 | +export default _default; |
0 commit comments