@mangoweb/scripts-base
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -1,2 +0,2 @@ | ||
import { ComponentEl, DelegateTarget, EventMap, EventMapByElement } from './componentTypes'; | ||
import { ComponentEl, DefaultComponentEl, DelegateTarget, EventMap, EventMapByElement } from './componentTypes'; | ||
export interface ComponentConstructor<Props, ComponentElement extends ComponentEl, EMap extends EventMap = EventMapByElement<ComponentElement>> { | ||
@@ -8,3 +8,3 @@ componentName: string; | ||
} | ||
export declare class Component<Props = {}, ComponentElement extends ComponentEl = HTMLElement, EMap extends EventMap = EventMapByElement<ComponentElement>> { | ||
export declare class Component<Props = {}, ComponentElement extends ComponentEl = DefaultComponentEl, EMap extends EventMap = EventMapByElement<ComponentElement>> { | ||
protected readonly el: ComponentElement; | ||
@@ -11,0 +11,0 @@ protected readonly props: Props; |
export declare type ComponentEl = HTMLElement | SVGElement | Window; | ||
export declare type DefaultComponentEl = HTMLElement; | ||
export declare type EventMapByElement<E extends ComponentEl> = E extends Window ? WindowEventMap : (E extends SVGElement ? SVGElementEventMap : (E extends HTMLBodyElement ? HTMLBodyElementEventMap : (E extends HTMLVideoElement ? HTMLVideoElementEventMap : (E extends HTMLAudioElement ? HTMLMediaElementEventMap : (E extends HTMLElement ? HTMLElementEventMap : never))))); | ||
export declare type DelegateTarget<Container extends ComponentEl> = Container extends Window ? HTMLElement | SVGElement : Container extends SVGElement ? SVGElement : Container extends HTMLElement ? HTMLElement | SVGElement : never; | ||
export declare type EventMap = WindowEventMap | SVGElementEventMap | HTMLBodyElementEventMap | HTMLVideoElementEventMap | HTMLMediaElementEventMap | HTMLElementEventMap; | ||
export declare type CompleteEventMap = WindowEventMap & SVGElementEventMap & HTMLBodyElementEventMap & HTMLVideoElementEventMap & HTMLMediaElementEventMap & HTMLElementEventMap; | ||
export declare type NonBubblingEventType = 'abort' | 'blur' | 'error' | 'focus' | 'load' | 'loadend' | 'loadstart' | 'progress' | 'scroll'; | ||
export declare type BubblingEventType<EMap extends EventMap> = Exclude<keyof EMap, NonBubblingEventType>; | ||
export declare type DelegateEvent<E extends BubblingEventType<EMap>, Container extends ComponentEl = HTMLElement, EMap extends EventMap = EventMapByElement<Container>> = EMap[E] & { | ||
export declare type DelegateEvent<E extends BubblingEventType<EMap>, Container extends ComponentEl = DefaultComponentEl, EMap extends EventMap = EventMapByElement<Container>> = EMap[E] & { | ||
delegateTarget: DelegateTarget<Container>; | ||
}; | ||
export declare type DelegateEventListenerCallback<E extends BubblingEventType<EMap>, Container extends ComponentEl = HTMLElement, EMap extends EventMap = EventMapByElement<Container>> = (event: DelegateEvent<E, Container, EMap>) => void; | ||
export declare type DelegateEventListenerSpec<E extends BubblingEventType<EMap>, Container extends ComponentEl = HTMLElement, EMap extends EventMap = EventMapByElement<Container>> = [E, string, DelegateEventListenerCallback<E, Container, EMap>]; | ||
export declare type DelegateEventListenerCallback<E extends BubblingEventType<EMap>, Container extends ComponentEl = DefaultComponentEl, EMap extends EventMap = EventMapByElement<Container>> = (event: DelegateEvent<E, Container, EMap>) => void; | ||
export declare type DelegateEventListenerSpec<E extends BubblingEventType<EMap>, Container extends ComponentEl = DefaultComponentEl, EMap extends EventMap = EventMapByElement<Container>> = [E, string, DelegateEventListenerCallback<E, Container, EMap>]; | ||
export declare type EventListenerCallback<E extends keyof EMap, EMap extends EventMap> = (event: EMap[E]) => void; | ||
export declare type EventListenerSpec<E extends keyof EMap, EMap extends EventMap> = [E, EventListenerCallback<E, EMap>]; | ||
export declare type EventListeners<Container extends ComponentEl = HTMLElement, EMap extends EventMap = EventMapByElement<Container>> = Array<{ | ||
export declare type EventListeners<Container extends ComponentEl = DefaultComponentEl, EMap extends EventMap = EventMapByElement<Container>> = Array<{ | ||
[E in keyof EMap]: EventListenerSpec<E, EMap>; | ||
@@ -16,0 +18,0 @@ }[keyof EMap] | { |
import { ComponentConstructor } from './Component'; | ||
import { ComponentEl } from './componentTypes'; | ||
export declare const initializeComponents: (components: ComponentConstructor<unknown, ComponentEl, HTMLElementEventMap | SVGElementEventMap | WindowEventMap>[], initializerName?: "initComponents" | "initAdminComponents" | "initStyleguideComponents") => void; | ||
import { CompleteEventMap } from './componentTypes'; | ||
export declare const initializeComponents: (components: ComponentConstructor<any, any, CompleteEventMap>[], initializerName?: "initComponents" | "initAdminComponents" | "initStyleguideComponents") => void; | ||
//# sourceMappingURL=initializeComponents.d.ts.map |
@@ -27,3 +27,3 @@ "use strict"; | ||
catch (e) { | ||
if (e instanceof Component_1.ComponentInitializationError && DEBUG) { | ||
if (e instanceof Component_1.ComponentInitializationError) { | ||
console.warn("The component '" + component.name + "' failed to initialize. " + e.message); | ||
@@ -30,0 +30,0 @@ } |
{ | ||
"name": "@mangoweb/scripts-base", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Simple component model for small to meduim sites. Usable from JS & TS.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
import { | ||
ComponentEl, | ||
DefaultComponentEl, | ||
DelegateEvent, | ||
@@ -24,3 +25,3 @@ DelegateTarget, | ||
Props = {}, | ||
ComponentElement extends ComponentEl = HTMLElement, | ||
ComponentElement extends ComponentEl = DefaultComponentEl, | ||
EMap extends EventMap = EventMapByElement<ComponentElement> | ||
@@ -27,0 +28,0 @@ > { |
export type ComponentEl = HTMLElement | SVGElement | Window | ||
export type DefaultComponentEl = HTMLElement | ||
export type EventMapByElement<E extends ComponentEl> = E extends Window | ||
@@ -31,2 +33,9 @@ ? WindowEventMap | ||
export type CompleteEventMap = WindowEventMap & | ||
SVGElementEventMap & | ||
HTMLBodyElementEventMap & | ||
HTMLVideoElementEventMap & | ||
HTMLMediaElementEventMap & | ||
HTMLElementEventMap | ||
export type NonBubblingEventType = | ||
@@ -47,3 +56,3 @@ | 'abort' | ||
E extends BubblingEventType<EMap>, | ||
Container extends ComponentEl = HTMLElement, | ||
Container extends ComponentEl = DefaultComponentEl, | ||
EMap extends EventMap = EventMapByElement<Container> | ||
@@ -56,3 +65,3 @@ > = EMap[E] & { | ||
E extends BubblingEventType<EMap>, | ||
Container extends ComponentEl = HTMLElement, | ||
Container extends ComponentEl = DefaultComponentEl, | ||
EMap extends EventMap = EventMapByElement<Container> | ||
@@ -63,3 +72,3 @@ > = (event: DelegateEvent<E, Container, EMap>) => void | ||
E extends BubblingEventType<EMap>, | ||
Container extends ComponentEl = HTMLElement, | ||
Container extends ComponentEl = DefaultComponentEl, | ||
EMap extends EventMap = EventMapByElement<Container> | ||
@@ -73,3 +82,3 @@ > = [E, string, DelegateEventListenerCallback<E, Container, EMap>] | ||
export type EventListeners< | ||
Container extends ComponentEl = HTMLElement, | ||
Container extends ComponentEl = DefaultComponentEl, | ||
EMap extends EventMap = EventMapByElement<Container> | ||
@@ -76,0 +85,0 @@ > = Array< |
import { ComponentConstructor, ComponentInitializationError } from './Component' | ||
import { ComponentEl } from './componentTypes' | ||
import { CompleteEventMap } from './componentTypes' | ||
export const initializeComponents = ( | ||
components: Array<ComponentConstructor<unknown, ComponentEl>>, | ||
components: Array<ComponentConstructor<any, any, CompleteEventMap>>, | ||
initializerName: ComponentInitializerName = 'initComponents' | ||
) => { | ||
const componentsByName: { | ||
[name: string]: ComponentConstructor<unknown, ComponentEl> | ||
[name: string]: ComponentConstructor<any, any, CompleteEventMap> | ||
} = {} | ||
@@ -39,3 +39,3 @@ | ||
} catch (e) { | ||
if (e instanceof ComponentInitializationError && DEBUG) { | ||
if (e instanceof ComponentInitializationError) { | ||
console.warn(`The component '${component.name}' failed to initialize. ${e.message}`) | ||
@@ -42,0 +42,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
133053
80
1435
1