aurelia-templating
Version:
An extensible HTML templating engine supporting databinding, custom elements, attached behaviors and more.
1,245 lines (1,243 loc) • 78.1 kB
TypeScript
// Generated by dts-bundle-generator v6.5.0
import { Binding, BindingBehaviorResource, Expression, Scope, ValueConverterResource, bindingMode } from 'aurelia-binding';
import { Container } from 'aurelia-dependency-injection';
import { Loader, TemplateRegistryEntry } from 'aurelia-loader';
import { Origin } from 'aurelia-metadata';
import { TaskQueue } from 'aurelia-task-queue';
export interface EventHandler {
eventName: string;
bubbles: boolean;
capture: boolean;
dispose: Function;
handler: Function;
}
/**
* Dispatches subscribets to and publishes events in the DOM.
* @param element
*/
export declare class ElementEvents {
static defaultListenerOptions: boolean | AddEventListenerOptions;
constructor(element: EventTarget);
/**
* Dispatches an Event on the context element.
* @param eventName
* @param detail
* @param bubbles
* @param cancelable
*/
publish(eventName: string, detail?: object, bubbles?: boolean, cancelable?: boolean): void;
/**
* Adds and Event Listener on the context element.
* @return Returns the eventHandler containing a dispose method
*/
subscribe(eventName: string, handler: Function, captureOrOptions?: boolean | AddEventListenerOptions): EventHandler;
/**
* Adds an Event Listener on the context element, that will be disposed on the first trigger.
* @return Returns the eventHandler containing a dispose method
*/
subscribeOnce(eventName: string, handler: Function, captureOrOptions?: boolean | AddEventListenerOptions): EventHandler;
/**
* Removes all events that are listening to the specified eventName.
* @param eventName
*/
dispose(eventName: string): void;
/**
* Removes all event handlers.
*/
disposeAll(): void;
}
/**
* Controls a view model (and optionally its view), according to a particular behavior and by following a set of instructions.
*/
export declare class Controller {
/**
* The HtmlBehaviorResource that provides the base behavior for this controller.
*/
behavior: HtmlBehaviorResource;
/**
* The developer's view model instance which provides the custom behavior for this controller.
*/
viewModel: Object;
/**
* The view associated with the component being controlled by this controller.
* Note: Not all components will have a view, so the value may be null.
*/
view: View;
/**
* Creates an instance of Controller.
* @param behavior The HtmlBehaviorResource that provides the base behavior for this controller.
* @param instruction The instructions pertaining to the controller's behavior.
* @param viewModel The developer's view model instance which provides the custom behavior for this controller.
* @param container The container that the controller's view was created from.
*/
constructor(behavior: HtmlBehaviorResource, instruction: BehaviorInstruction, viewModel: Object, container: Container);
/**
* Invoked when the view which contains this controller is created.
* @param owningView The view inside which this controller resides.
*/
created(owningView: View): void;
/**
* Used to automate the proper binding of this controller and its view. Used by the composition engine for dynamic component creation.
* This should be considered a semi-private API and is subject to change without notice, even across minor or patch releases.
* @param overrideContext An override context for binding.
* @param owningView The view inside which this controller resides.
*/
automate(overrideContext?: Object, owningView?: View): void;
/**
* Binds the controller to the scope.
* @param scope The binding scope.
*/
bind(scope: Object): void;
/**
* Unbinds the controller.
*/
unbind(): void;
/**
* Attaches the controller.
*/
attached(): void;
/**
* Detaches the controller.
*/
detached(): void;
}
/**
* A factory capable of creating View instances, bound to a location within another view hierarchy.
*/
export declare class BoundViewFactory {
viewFactory: ViewFactory;
/**
* Creates an instance of BoundViewFactory.
* @param parentContainer The parent DI container.
* @param viewFactory The internal unbound factory.
* @param partReplacements Part replacement overrides for the internal factory.
*/
constructor(parentContainer: Container, viewFactory: ViewFactory, partReplacements?: Object);
/**
* Creates a view or returns one from the internal cache, if available.
* @return The created view.
*/
create(): View;
/**
* Indicates whether this factory is currently using caching.
*/
get isCaching(): boolean;
/**
* Sets the cache size for this factory.
* @param size The number of views to cache or "*" to cache all.
* @param doNotOverrideIfAlreadySet Indicates that setting the cache should not override the setting if previously set.
*/
setCacheSize(size: number | string, doNotOverrideIfAlreadySet: boolean): void;
/**
* Gets a cached view if available...
* @return A cached view or null if one isn't available.
*/
getCachedView(): View;
/**
* Returns a view to the cache.
* @param view The view to return to the cache if space is available.
*/
returnViewToCache(view: View): void;
}
/**
* A factory capable of creating View instances.
*/
export declare class ViewFactory {
/**
* Indicates whether this factory is currently using caching.
*/
isCaching: boolean;
template: DocumentFragment;
instructions: Object;
resources: ViewResources;
cacheSize: number;
cache: any;
surrogateInstruction: any;
part: any;
/**
* Creates an instance of ViewFactory.
* @param template The document fragment that serves as a template for the view to be created.
* @param instructions The instructions to be applied ot the template during the creation of a view.
* @param resources The resources used to compile this factory.
*/
constructor(template: DocumentFragment, instructions: Object, resources: ViewResources);
/**
* Sets the cache size for this factory.
* @param size The number of views to cache or "*" to cache all.
* @param doNotOverrideIfAlreadySet Indicates that setting the cache should not override the setting if previously set.
*/
setCacheSize(size: number | string, doNotOverrideIfAlreadySet?: boolean): void;
/**
* Gets a cached view if available...
* @return A cached view or null if one isn't available.
*/
getCachedView(): View;
/**
* Returns a view to the cache.
* @param view The view to return to the cache if space is available.
*/
returnViewToCache(view: View): void;
/**
* Creates a view or returns one from the internal cache, if available.
* @param container The container to create the view from.
* @param createInstruction The instruction used to customize view creation.
* @param element The custom element that hosts the view.
* @return The created view.
*/
create(container: Container, createInstruction?: ViewCreateInstruction, element?: Element): View;
}
/**
* Represents a node in the view hierarchy.
*/
export interface ViewNode {
/**
* The children of this view node
*/
children: ViewNode[];
/**
* Binds the node and it's children.
* @param bindingContext The binding context to bind to.
* @param overrideContext A secondary binding context that can override the standard context.
*/
bind(bindingContext: Object, overrideContext?: Object): void;
/**
* Triggers the attach for the node and its children.
*/
attached(): void;
/**
* Triggers the detach for the node and its children.
*/
detached(): void;
/**
* Unbinds the node and its children.
*/
unbind(): void;
}
export declare class View {
/**
* The Dependency Injection Container that was used to create this View instance.
*/
container: Container;
/**
* The ViewFactory that built this View instance.
*/
viewFactory: ViewFactory;
/**
* Contains the DOM Nodes which represent this View. If the view was created via the "enhance" API, this will be an Element, otherwise it will be a DocumentFragment. If not created via "enhance" then the fragment will only contain nodes when the View is detached from the DOM.
*/
fragment: DocumentFragment | Element;
/**
* The primary binding context that this view is data-bound to.
*/
bindingContext: Object;
/**
* The override context which contains properties capable of overriding those found on the binding context.
*/
overrideContext: Object;
/**
* The Controller instance that owns this View.
*/
controller: Controller;
/**
* Creates a View instance.
* @param container The container from which the view was created.
* @param viewFactory The factory that created this view.
* @param fragment The DOM fragement representing the view.
* @param controllers The controllers inside this view.
* @param bindings The bindings inside this view.
* @param children The children view nodes of this view.
*/
constructor(container: Container, viewFactory: ViewFactory, fragment: DocumentFragment, controllers: Controller[], bindings: Binding[], children: ViewNode[], slots: Object);
/**
* Returns this view to the appropriate view cache.
*/
returnToCache(): void;
/**
* Triggers the created callback for this view and its children.
*/
created(): void;
/**
* Binds the view and it's children.
* @param bindingContext The binding context to bind to.
* @param overrideContext A secondary binding context that can override the standard context.
*/
bind(bindingContext: Object, overrideContext?: Object, _systemUpdate?: boolean): void;
/**
* Adds a binding instance to this view.
* @param binding The binding instance.
*/
addBinding(binding: Object): void;
/**
* Unbinds the view and its children.
*/
unbind(): void;
/**
* Inserts this view's nodes before the specified DOM node.
* @param refNode The node to insert this view's nodes before.
*/
insertNodesBefore(refNode: Node): void;
/**
* Appends this view's to the specified DOM node.
* @param parent The parent element to append this view's nodes to.
*/
appendNodesTo(parent: Element): void;
/**
* Removes this view's nodes from the DOM.
*/
removeNodes(): void;
/**
* Triggers the attach for the view and its children.
*/
attached(): void;
/**
* Triggers the detach for the view and its children.
*/
detached(): void;
}
/**
* An abstract class representing a mechanism for animating the DOM during various DOM state transitions.
*/
export declare class Animator {
static instance: Animator;
/**
* Execute an 'enter' animation on an element
* @param element Element to animate
* @returns Resolved when the animation is done
*/
enter(element: HTMLElement): Promise<boolean>;
/**
* Execute a 'leave' animation on an element
* @param element Element to animate
* @returns Resolved when the animation is done
*/
leave(element: HTMLElement): Promise<boolean>;
/**
* Add a class to an element to trigger an animation.
* @param element Element to animate
* @param className Properties to animate or name of the effect to use
* @returns Resolved when the animation is done
*/
removeClass(element: HTMLElement, className: string): Promise<boolean>;
/**
* Add a class to an element to trigger an animation.
* @param element Element to animate
* @param className Properties to animate or name of the effect to use
* @returns Resolved when the animation is done
*/
addClass(element: HTMLElement, className: string): Promise<boolean>;
/**
* Execute a single animation.
* @param element Element to animate
* @param className Properties to animate or name of the effect to use. For css animators this represents the className to be added and removed right after the animation is done.
* @param options options for the animation (duration, easing, ...)
* @returns Resolved when the animation is done
*/
animate(element: HTMLElement | Array<HTMLElement>, className: string): Promise<boolean>;
/**
* Run a sequence of animations one after the other.
* for example: animator.runSequence("fadeIn","callout")
* @param sequence An array of effectNames or classNames
* @returns Resolved when all animations are done
*/
runSequence(animations: Array<any>): Promise<boolean>;
/**
* Register an effect (for JS based animators)
* @param effectName identifier of the effect
* @param properties Object with properties for the effect
*/
registerEffect(effectName: string, properties: object): void;
/**
* Unregister an effect (for JS based animators)
* @param effectName identifier of the effect
*/
unregisterEffect(effectName: string): void;
}
/**
* Represents a slot or location within the DOM to which views can be added and removed.
* Manages the view lifecycle for its children.
*/
export declare class ViewSlot {
/**
* Creates an instance of ViewSlot.
* @param anchor The DOM node which will server as the anchor or container for insertion.
* @param anchorIsContainer Indicates whether the node is a container.
* @param animator The animator that will controll enter/leave transitions for this slot.
*/
constructor(anchor: Node, anchorIsContainer: boolean, animator?: Animator);
/**
* Runs the animator against the first animatable element found within the view's fragment
* @param view The view to use when searching for the element.
* @param direction The animation direction enter|leave.
* @returns An animation complete Promise or undefined if no animation was run.
*/
animateView(view: View, direction?: string): void | Promise<any>;
/**
* Takes the child nodes of an existing element that has been converted into a ViewSlot
* and makes those nodes into a View within the slot.
*/
transformChildNodesIntoView(): void;
/**
* Binds the slot and it's children.
* @param bindingContext The binding context to bind to.
* @param overrideContext A secondary binding context that can override the standard context.
*/
bind(bindingContext: Object, overrideContext: Object): void;
/**
* Unbinds the slot and its children.
*/
unbind(): void;
/**
* Adds a view to the slot.
* @param view The view to add.
* @return May return a promise if the view addition triggered an animation.
*/
add(view: View): void | Promise<any>;
/**
* Inserts a view into the slot.
* @param index The index to insert the view at.
* @param view The view to insert.
* @return May return a promise if the view insertion triggered an animation.
*/
insert(index: number, view: View): void | Promise<any>;
/**
* Moves a view across the slot.
* @param sourceIndex The index the view is currently at.
* @param targetIndex The index to insert the view at.
*/
move(sourceIndex: any, targetIndex: any): void;
/**
* Removes a view from the slot.
* @param view The view to remove.
* @param returnToCache Should the view be returned to the view cache?
* @param skipAnimation Should the removal animation be skipped?
* @return May return a promise if the view removal triggered an animation.
*/
remove(view: View, returnToCache?: boolean, skipAnimation?: boolean): View | Promise<View>;
/**
* Removes many views from the slot.
* @param viewsToRemove The array of views to remove.
* @param returnToCache Should the views be returned to the view cache?
* @param skipAnimation Should the removal animation be skipped?
* @return May return a promise if the view removal triggered an animation.
*/
removeMany(viewsToRemove: View[], returnToCache?: boolean, skipAnimation?: boolean): void | Promise<void>;
/**
* Removes a view an a specified index from the slot.
* @param index The index to remove the view at.
* @param returnToCache Should the view be returned to the view cache?
* @param skipAnimation Should the removal animation be skipped?
* @return May return a promise if the view removal triggered an animation.
*/
removeAt(index: number, returnToCache?: boolean, skipAnimation?: boolean): View | Promise<View>;
/**
* Removes all views from the slot.
* @param returnToCache Should the view be returned to the view cache?
* @param skipAnimation Should the removal animation be skipped?
* @return May return a promise if the view removals triggered an animation.
*/
removeAll(returnToCache?: boolean, skipAnimation?: boolean): void | Promise<any>;
/**
* Triggers the attach for the slot and its children.
*/
attached(): void;
/**
* Triggers the detach for the slot and its children.
*/
detached(): void;
projectTo(slots: Object): void;
}
export declare class SlotCustomAttribute {
element: any;
value: any;
constructor(element: any);
valueChanged(newValue: any, oldValue: any): void;
}
export declare class PassThroughSlot {
constructor(anchor: any, name: any, destinationName: any, fallbackFactory: any);
/**
* Indicate whether this slot should render fallback default slot content
*/
get needsFallbackRendering(): boolean;
/**
* @param view
* @param nodes
* @param projectionSource
* @param index
*/
renderFallbackContent(view: View, nodes: Node[], projectionSource: ViewSlot | ShadowSlot, index?: number): void;
passThroughTo(destinationSlot: PassThroughSlot | ShadowSlot): void;
addNode(view: View, node: Node, projectionSource: ViewSlot | ShadowSlot, index: number): void;
removeView(view: View, projectionSource: ViewSlot | ShadowSlot): void;
removeAll(projectionSource: ViewSlot | ShadowSlot): void;
projectFrom(view: View, projectionSource: ViewSlot | ShadowSlot): void;
created(ownerView: View): void;
bind(view: View): void;
attached(): void;
detached(): void;
unbind(): void;
}
export declare class ShadowSlot {
constructor(anchor: any, name: any, fallbackFactory: any);
get needsFallbackRendering(): boolean;
/**
* @param view
* @param node
* @param projectionSource
* @param index
* @param destination
*/
addNode(view: View, node: Node, projectionSource: ViewSlot | ShadowSlot, index?: number, destination?: string): void;
removeView(view: View, projectionSource: ViewSlot | ShadowSlot): void;
removeAll(projectionSource: ViewSlot | ShadowSlot): void;
projectTo(slots: Record<string, ShadowSlot | PassThroughSlot>): void;
projectFrom(view: View, projectionSource: ViewSlot | ShadowSlot): void;
renderFallbackContent(view: View, nodes: Node[], projectionSource: ViewSlot | ShadowSlot, index?: number): void;
/**
* @param ownerView
*/
created(ownerView: View): void;
/**
* @param view
*/
bind(view: View): void;
attached(): void;
detached(): void;
unbind(): void;
}
export declare class ShadowDOM {
static defaultSlotKey: "__au-default-slot-key__";
static getSlotName(node: any): any;
/**
* Project the nodes of a view to a record of slots
* @param destinationOverride the override name of the slot to distribute to
*/
static distributeView(view: View, slots: Record<string, PassThroughSlot | ShadowSlot>, projectionSource?: ViewSlot | ShadowSlot, index?: number, destinationOverride?: string): void;
static undistributeView(view: View, slots: Record<string, PassThroughSlot | ShadowSlot>, projectionSource: ViewSlot | ShadowSlot): void;
/**
* @param {Record<string, ShadowSlot | PassThroughSlot>} slots
* @param {ViewSlot} projectionSource
*/
static undistributeAll(slots: Record<string, ShadowSlot | PassThroughSlot>, projectionSource: ViewSlot | ShadowSlot): void;
/**
* Distrbiute nodes of a projected view based on the given slots
* @param view
* @param nodes
* @param slots
* @param projectionSource
* @param index
* @param destinationOverride
*/
static distributeNodes(view: View, nodes: Node[], slots: Record<string, PassThroughSlot | ShadowSlot>, projectionSource?: ViewSlot | ShadowSlot, index?: number, destinationOverride?: string): void;
}
export declare class ViewEngineHooksResource {
initialize(container: any, target: any): void;
register(registry: any, name: any): void;
load(container: any, target: any): void;
static convention(name: any): ViewEngineHooksResource;
}
export declare function viewEngineHooks(target?: any): any;
export type ViewResourceType = HtmlBehaviorResource | ValueConverterResource | BindingBehaviorResource | ViewEngineHooksResource;
export type ProcessContentCallback = (viewCompiler: ViewCompiler, resources: ViewResources, node: Element, instruction: BehaviorInstruction) => boolean;
export type ProcessAttributeCallback = (compiler: ViewCompiler, resources: ViewResources, node: Element, attributes: Element["attributes"], elementInstruction: BehaviorInstruction) => void;
/**
* View engine hooks that enable a view resource to provide custom processing during the compilation or creation of a view.
*/
export interface ViewEngineHooks {
/**
* Invoked before a template is compiled.
* @param content The DocumentFragment to compile.
* @param resources The resources to compile the view against.
* @param instruction The compilation instruction associated with the compilation process.
*/
beforeCompile?: (content: DocumentFragment, resources: ViewResources, instruction: ViewCompileInstruction) => void;
/**
* Invoked after a template is compiled.
* @param viewFactory The view factory that was produced from the compilation process.
*/
afterCompile?: (viewFactory: ViewFactory) => void;
/**
* Invoked before a view is created.
* @param viewFactory The view factory that will be used to create the view.
* @param container The DI container used during view creation.
* @param content The cloned document fragment representing the view.
* @param instruction The view creation instruction associated with this creation process.
*/
beforeCreate?: (viewFactory: ViewFactory, container: Container, content: DocumentFragment, instruction: ViewCreateInstruction) => void;
/**
* Invoked after a view is created.
* @param view The view that was created by the factory.
*/
afterCreate?: (view: View) => void;
/**
* Invoked after the bindingContext and overrideContext are configured on the view but before the view is bound.
* @param view The view that was created by the factory.
*/
beforeBind?: (view: View) => void;
/**
* Invoked before the view is unbind. The bindingContext and overrideContext are still available on the view.
* @param view The view that was created by the factory.
*/
beforeUnbind?: (view: View) => void;
}
export interface IBindablePropertyConfig {
/**
* The name of the property.
*/
name?: string;
attribute?: string;
/**
* The default binding mode of the property. If given string, will use to lookup
*/
defaultBindingMode?: bindingMode | "oneTime" | "oneWay" | "twoWay" | "fromView" | "toView";
/**
* The name of a view model method to invoke when the property is updated.
*/
changeHandler?: string;
/**
* A default value for the property.
*/
defaultValue?: any;
/**
* Designates the property as the default bindable property among all the other bindable properties when used in a custom attribute with multiple bindable properties.
*/
primaryProperty?: boolean;
[key: string]: any;
}
export declare type IStaticResource = Function & {
$resource?: string | IStaticResourceConfig | (() => string | IStaticResourceConfig);
};
export interface IStaticResourceConfig {
/**
* Resource type of this class, omit equals to custom element
*/
type?: "element" | "attribute" | "valueConverter" | "bindingBehavior" | "viewEngineHooks";
/**
* Name of this resource. Reccommended to explicitly set to works better with minifier
*/
name?: string;
/**
* Used to tell if a custom attribute is a template controller
*/
templateController?: boolean;
/**
* Used to set default binding mode of default custom attribute view model "value" property
*/
defaultBindingMode?: bindingMode | "oneTime" | "oneWay" | "twoWay" | "fromView" | "toView";
/**
* Flags a custom attribute has dynamic options
*/
hasDynamicOptions?: boolean;
/**
* Flag if this custom element uses native shadow dom instead of emulation
*/
usesShadowDOM?: boolean;
/**
* Options that will be used if the element is flagged with usesShadowDOM
*/
shadowDOMOptions?: ShadowRootInit;
/**
* Flag a custom element as containerless. Which will remove their render target
*/
containerless?: boolean;
/**
* Custom processing of the attributes on an element before the framework inspects them.
*/
processAttributes?: (viewCompiler: ViewCompiler, resources: ViewResources, node: Element, attributes: NamedNodeMap, elementInstruction: BehaviorInstruction) => void;
/**
* Enables custom processing of the content that is places inside the custom element by its consumer.
* Pass a boolean to direct the template compiler to not process
* the content placed inside this element. Alternatively, pass a function which
* can provide custom processing of the content. This function should then return
* a boolean indicating whether the compiler should also process the content.
*/
processContent?: (viewCompiler: ViewCompiler, resources: ViewResources, node: Element, instruction: BehaviorInstruction) => boolean;
/**
* List of bindable properties of this custom element / custom attribute, by name or full config object
*/
bindables?: Array<string | IBindablePropertyConfig>;
}
export declare function validateBehaviorName(name: string, type: string): string;
/**
* Represents a collection of resources used during the compilation of a view.
* Will optinally add information to an existing HtmlBehaviorResource if given
*/
export declare class ViewResources {
/**
* Checks whether the provided class contains any resource conventions
* @param target Target class to extract metadata based on convention
* @param existing If supplied, all custom element / attribute metadata extracted from convention will be apply to this instance
*/
static convention(target: IStaticResource, existing?: HtmlBehaviorResource): ViewResourceType;
/**
* A custom binding language used in the view.
*/
bindingLanguage: any;
/**
* Creates an instance of ViewResources.
* @param parent The parent resources. This resources can override them, but if a resource is not found, it will be looked up in the parent.
* @param viewUrl The url of the view to which these resources apply.
*/
constructor(parent?: ViewResources, viewUrl?: string);
/**
* Registers view engine hooks for the view.
* @param hooks The hooks to register.
*/
registerViewEngineHooks(hooks: ViewEngineHooks): void;
/**
* Gets the binding language associated with these resources, or return the provided fallback implementation.
* @param bindingLanguageFallback The fallback binding language implementation to use if no binding language is configured locally.
* @return The binding language.
*/
getBindingLanguage(bindingLanguageFallback: BindingLanguage): BindingLanguage;
/**
* Patches an immediate parent into the view resource resolution hierarchy.
* @param newParent The new parent resources to patch in.
*/
patchInParent(newParent: ViewResources): void;
/**
* Maps a path relative to the associated view's origin.
* @param path The relative path.
* @return The calcualted path.
*/
relativeToView(path: string): string;
/**
* Registers an HTML element.
* @param tagName The name of the custom element.
* @param behavior The behavior of the element.
*/
registerElement(tagName: string, behavior: HtmlBehaviorResource): void;
/**
* Gets an HTML element behavior.
* @param tagName The tag name to search for.
* @return The HtmlBehaviorResource for the tag name or null.
*/
getElement(tagName: string): HtmlBehaviorResource;
/**
* Gets the known attribute name based on the local attribute name.
* @param attribute The local attribute name to lookup.
* @return The known name.
*/
mapAttribute(attribute: string): string;
/**
* Registers an HTML attribute.
* @param attribute The name of the attribute.
* @param behavior The behavior of the attribute.
* @param knownAttribute The well-known name of the attribute (in lieu of the local name).
*/
registerAttribute(attribute: string, behavior: HtmlBehaviorResource, knownAttribute: string): void;
/**
* Gets an HTML attribute behavior.
* @param attribute The name of the attribute to lookup.
* @return The HtmlBehaviorResource for the attribute or null.
*/
getAttribute(attribute: string): HtmlBehaviorResource;
/**
* Registers a value converter.
* @param name The name of the value converter.
* @param valueConverter The value converter instance.
*/
registerValueConverter(name: string, valueConverter: Object): void;
/**
* Gets a value converter.
* @param name The name of the value converter.
* @return The value converter instance.
*/
getValueConverter(name: string): Object;
/**
* Registers a binding behavior.
* @param name The name of the binding behavior.
* @param bindingBehavior The binding behavior instance.
*/
registerBindingBehavior(name: string, bindingBehavior: Object): void;
/**
* Gets a binding behavior.
* @param name The name of the binding behavior.
* @return The binding behavior instance.
*/
getBindingBehavior(name: string): Object;
/**
* Registers a value.
* @param name The name of the value.
* @param value The value.
*/
registerValue(name: string, value: any): void;
/**
* Gets a value.
* @param name The name of the value.
* @return The value.
*/
getValue(name: string): any;
/**
* Not supported for public use. Can be changed without warning.
*
* Auto register a resources based on its metadata or convention
* Will fallback to custom element if no metadata found and all conventions fail
* @param container
* @param impl
*/
autoRegister(container: Container, impl: Function): ViewResourceType;
}
export interface LetExpression {
createBinding(): LetBinding;
}
export interface LetBinding {
source: Scope;
isBound: boolean;
/**
* The expression to access/assign/connect the binding source property.
*/
sourceExpression: Expression;
/**
* Assigns a value to the target.
*/
updateTarget(value: any): void;
/**
* Connects the binding to a scope.
*/
bind(source: Scope): void;
/**
* Disconnects the binding from a scope.
*/
unbind(): void;
}
/**
* An abstract base class for implementations of a binding language.
*/
export declare class BindingLanguage {
/**
* Inspects an attribute for bindings.
* @param resources The ViewResources for the view being compiled.
* @param elementName The element name to inspect.
* @param attrName The attribute name to inspect.
* @param attrValue The attribute value to inspect.
* @return An info object with the results of the inspection.
*/
inspectAttribute(resources: ViewResources, elementName: string, attrName: string, attrValue: string): Object;
/**
* Creates an attribute behavior instruction.
* @param resources The ViewResources for the view being compiled.
* @param element The element that the attribute is defined on.
* @param info The info object previously returned from inspectAttribute.
* @param existingInstruction A previously created instruction for this attribute.
* @param context HtmlBehaviorResource
* @return The instruction instance.
*/
createAttributeInstruction(resources: ViewResources, element: Element, info: Object, existingInstruction?: Object, context?: HtmlBehaviorResource): BehaviorInstruction;
/**
* Creates let expressions from a <let/> element
* @param resources The ViewResources for the view being compiled
* @param element the let element in the view template
* @param existingExpressions the array that will hold compiled let expressions from the let element
* @return the expression array created from the <let/> element
*/
createLetExpressions(resources: ViewResources, element: Element): LetExpression[];
/**
* Parses the text for bindings.
* @param resources The ViewResources for the view being compiled.
* @param value The value of the text to parse.
* @return A binding expression.
*/
inspectTextContent(resources: ViewResources, value: string): Object;
}
/**
* Compiles html templates, dom fragments and strings into ViewFactory instances, capable of instantiating Views.
*/
export declare class ViewCompiler {
/**
* Creates an instance of ViewCompiler.
* @param bindingLanguage The default data binding language and syntax used during view compilation.
* @param resources The global resources used during compilation when none are provided for compilation.
*/
constructor(bindingLanguage: BindingLanguage, resources: ViewResources);
/**
* Compiles an html template, dom fragment or string into ViewFactory instances, capable of instantiating Views.
* @param source The template, fragment or string to compile.
* @param resources The view resources used during compilation.
* @param compileInstruction A set of instructions that customize how compilation occurs.
* @return The compiled ViewFactory.
*/
compile(source: Element | DocumentFragment | string, resources?: ViewResources, compileInstruction?: ViewCompileInstruction): ViewFactory;
}
/**
* Represents a module with view resources.
*/
export declare class ResourceModule {
/**
* Creates an instance of ResourceModule.
* @param moduleId The id of the module that contains view resources.
*/
constructor(moduleId: string);
/**
* Initializes the resources within the module.
* @param container The dependency injection container usable during resource initialization.
*/
initialize(container: Container): void;
/**
* Registers the resources in the module with the view resources.
* @param registry The registry of view resources to regiser within.
* @param name The name to use in registering the default resource.
*/
register(registry: ViewResources, name?: string): void;
/**
* Loads any dependencies of the resources within this module.
* @param container The DI container to use during dependency resolution.
* @param loadContext The loading context used for loading all resources and dependencies.
* @return A promise that resolves when all loading is complete.
*/
load(container: Container, loadContext?: ResourceLoadContext): Promise<void>;
}
/**
* Represents a single view resource with a ResourceModule.
*/
export declare class ResourceDescription {
/**
* Creates an instance of ResourceDescription.
* @param key The key that the resource was exported as.
* @param exportedValue The exported resource.
* @param resourceTypeMeta The metadata located on the resource.
*/
constructor(key: string, exportedValue: any, resourceTypeMeta?: Object);
/**
* Initializes the resource.
* @param container The dependency injection container usable during resource initialization.
*/
initialize(container: Container): void;
/**
* Registrers the resource with the view resources.
* @param registry The registry of view resources to regiser within.
* @param name The name to use in registering the resource.
*/
register(registry: ViewResources, name?: string): void;
/**
* Loads any dependencies of the resource.
* @param container The DI container to use during dependency resolution.
* @param loadContext The loading context used for loading all resources and dependencies.
* @return A promise that resolves when all loading is complete.
*/
load(container: Container, loadContext?: ResourceLoadContext): Promise<void> | void;
}
/**
* Analyzes a module in order to discover the view resources that it exports.
*/
export declare class ModuleAnalyzer {
/**
* Creates an instance of ModuleAnalyzer.
*/
constructor();
/**
* Retrieves the ResourceModule analysis for a previously analyzed module.
* @param moduleId The id of the module to lookup.
* @return The ResouceModule if found, undefined otherwise.
*/
getAnalysis(moduleId: string): ResourceModule;
/**
* Analyzes a module.
* @param moduleId The id of the module to analyze.
* @param moduleInstance The module instance to analyze.
* @param mainResourceKey The name of the main resource.
* @return The ResouceModule representing the analysis.
*/
analyze(moduleId: string, moduleInstance: any, mainResourceKey?: string): ResourceModule;
}
/**
* Controls the view resource loading pipeline.
*/
export declare class ViewEngine {
/**
* The metadata key for storing requires declared in a ViewModel.
*/
static viewModelRequireMetadataKey: string;
/**
* Creates an instance of ViewEngine.
* @param loader The module loader.
* @param container The root DI container for the app.
* @param viewCompiler The view compiler.
* @param moduleAnalyzer The module analyzer.
* @param appResources The app-level global resources.
*/
constructor(loader: Loader, container: Container, viewCompiler: ViewCompiler, moduleAnalyzer: ModuleAnalyzer, appResources: ViewResources);
/**
* Adds a resource plugin to the resource loading pipeline.
* @param extension The file extension to match in require elements.
* @param implementation The plugin implementation that handles the resource type.
*/
addResourcePlugin(extension: string, implementation: Object): void;
/**
* Loads and compiles a ViewFactory from a url or template registry entry.
* @param urlOrRegistryEntry A url or template registry entry to generate the view factory for.
* @param compileInstruction Instructions detailing how the factory should be compiled.
* @param loadContext The load context if this factory load is happening within the context of a larger load operation.
* @param target A class from which to extract metadata of additional resources to load.
* @return A promise for the compiled view factory.
*/
loadViewFactory(urlOrRegistryEntry: string | TemplateRegistryEntry, compileInstruction?: ViewCompileInstruction, loadContext?: ResourceLoadContext, target?: any): Promise<ViewFactory>;
/**
* Loads all the resources specified by the registry entry.
* @param registryEntry The template registry entry to load the resources for.
* @param compileInstruction The compile instruction associated with the load.
* @param loadContext The load context if this is happening within the context of a larger load operation.
* @param target A class from which to extract metadata of additional resources to load.
* @return A promise of ViewResources for the registry entry.
*/
loadTemplateResources(registryEntry: TemplateRegistryEntry, compileInstruction?: ViewCompileInstruction, loadContext?: ResourceLoadContext, target?: any): Promise<ViewResources>;
/**
* Loads a view model as a resource.
* @param moduleImport The module to import.
* @param moduleMember The export from the module to generate the resource for.
* @return A promise for the ResourceDescription.
*/
importViewModelResource(moduleImport: string, moduleMember?: string): Promise<ResourceDescription>;
/**
* Imports the specified resources with the specified names into the view resources object.
* @param moduleIds The modules to load.
* @param names The names associated with resource modules to import.
* @param resources The resources lookup to add the loaded resources to.
* @param compileInstruction The compilation instruction associated with the resource imports.
* @return A promise for the ViewResources.
*/
importViewResources(moduleIds: string[], names: string[], resources: ViewResources, compileInstruction?: ViewCompileInstruction, loadContext?: ResourceLoadContext): Promise<ViewResources>;
}
/**
* Locates a view for an object.
*/
export declare class ViewLocator {
/**
* The metadata key for storing/finding view strategies associated with an class/object.
*/
static viewStrategyMetadataKey: string;
/**
* Gets the view strategy for the value.
* @param value The value to locate the view strategy for.
* @return The located ViewStrategy instance.
*/
getViewStrategy(value: any): ViewStrategy;
/**
* Creates a fallback View Strategy. Used when unable to locate a configured strategy.
* The default implementation returns and instance of ConventionalViewStrategy.
* @param origin The origin of the view model to return the strategy for.
* @return The fallback ViewStrategy.
*/
createFallbackViewStrategy(origin: Origin): ViewStrategy;
/**
* Conventionally converts a view model origin to a view url.
* Used by the ConventionalViewStrategy.
* @param origin The origin of the view model to convert.
* @return The view url.
*/
convertOriginToViewUrl(origin: Origin): string;
}
/**
* Implemented by classes that describe how a view factory should be loaded.
*/
export interface ViewStrategy {
moduleId?: string;
/**
* Loads a view factory.
* @param viewEngine The view engine to use during the load process.
* @param compileInstruction Additional instructions to use during compilation of the view.
* @param loadContext The loading context used for loading all resources and dependencies.
* @param target A class from which to extract metadata of additional resources to load.
* @return A promise for the view factory that is produced by this strategy.
*/
loadViewFactory(viewEngine: ViewEngine, compileInstruction: ViewCompileInstruction, loadContext?: ResourceLoadContext, target?: any): Promise<ViewFactory>;
}
export declare type ViewStrategyDecorator = Function & {
assert(value: any): value is ViewStrategy;
validate(target: any): boolean;
compose(target: any): void;
decorates(target: any): any;
};
/**
* Decorator: Indicates that the decorated class/object is a view strategy.
*/
export declare const viewStrategy: ViewStrategyDecorator;
/**
* A view strategy that loads a view relative to its associated view-model.
*/
export declare class RelativeViewStrategy {
/**
* Creates an instance of RelativeViewStrategy.
* @param path The relative path to the view.
*/
constructor(path: string);
/**
* Loads a view factory.
* @param viewEngine The view engine to use during the load process.
* @param compileInstruction Additional instructions to use during compilation of the view.
* @param loadContext The loading context used for loading all resources and dependencies.
* @param target A class from which to extract metadata of additional resources to load.
* @return A promise for the view factory that is produced by this strategy.
*/
loadViewFactory(viewEngine: ViewEngine, compileInstruction: ViewCompileInstruction, loadContext?: ResourceLoadContext, target?: any): Promise<ViewFactory>;
/**
* Makes the view loaded by this strategy relative to the provided file path.
* @param file The path to load the view relative to.
*/
makeRelativeTo(file: string): void;
}
/**
* A view strategy based on naming conventions.
*/
export declare class ConventionalViewStrategy {
moduleId: string;
viewUrl: any;
/**
* Creates an instance of ConventionalViewStrategy.
* @param viewLocator The view locator service for conventionally locating the view.
* @param origin The origin of the view model to conventionally load the view for.
*/
constructor(viewLocator: ViewLocator, origin: Origin);
/**
* Loads a view factory.
* @param viewEngine The view engine to use during the load process.
* @param compileInstruction Additional instructions to use during compilation of the view.
* @param loadContext The loading context used for loading all resources and dependencies.
* @param target A class from which to extract metadata of additional resources to load.
* @return A promise for the view factory that is produced by this strategy.
*/
loadViewFactory(viewEngine: ViewEngine, compileInstruction: ViewCompileInstruction, loadContext?: ResourceLoadContext, target?: any): Promise<ViewFactory>;
}
export interface ViewStrategyDependencyConfig {
from: string;
as: string;
}
/**
* A view strategy that indicates that the component has no view that the templating engine needs to manage.
* Typically used when the component author wishes to take over fine-grained rendering control.
*/
export declare class NoViewStrategy {
dependencies: (string | ViewStrategyDependencyConfig | Function)[];
dependencyBaseUrl: string;
entry: any;
moduleId: any;
/**
* Creates an instance of NoViewStrategy.
* @param dependencies A list of view resource dependencies of this view.
* @param dependencyBaseUrl The base url for the view dependencies.
*/
constructor(dependencies?: Array<string | Function | ViewStrategyDependencyConfig>, dependencyBaseUrl?: string);
/**
* Loads a view factory.
* @param viewEngine The view engine to use during the load process.
* @param compileInstruction Additional instructions to use during compilation of the view.
* @param loadContext The loading context used for loading all resources and dependencies.
* @param target A class from which to extract metadata of additional resources to load.
* @return A promise for the view factory that is produced by this strategy.
*/
loadViewFactory(viewEngine: ViewEngine, compileInstruction: ViewCompileInstruction, loadContext?: ResourceLoadContext, target?: any): Promise<ViewFactory>;
}
/**
* A view strategy created directly from the template registry entry.
*/
export declare class TemplateRegistryViewStrategy {
moduleId: string;
entry: TemplateRegistryEntry;
/**
* Creates an instance of TemplateRegistryViewStrategy.
* @param moduleId The associated moduleId of the view to be loaded.
* @param entry The template registry entry used in loading the view factory.
*/
constructor(moduleId: string, entry: TemplateRegistryEntry);
/**
* Loads a view factory.
* @param viewEngine The view engine to use during the load process.
* @param compileInstruction Additional instructions to use during compilation of the view.
* @param loadContext The loading context used for loading all resources and dependencies.
* @param target A class from which to extract metadata of additional resources to load.
* @return A promise for the view factory that is produced by this strategy.
*/
loadViewFactory(viewEngine: ViewEngine, compileInstruction: ViewCompileInstruction, loadContext?: ResourceLoadContext, target?: any): Promise<ViewFactory>;
}
/**
* A view strategy that allows the component author to inline the html for the view.
*/
export declare class InlineViewStrategy {
markup: string;
dependencies: (string | ViewStrategyDependencyConfig | Function)[];
dependencyBaseUrl: string;
entry: any;
moduleId: any;
/**
* Creates an instance of InlineViewStrategy.
* @param markup The markup for the view. Be sure to include the wrapping template tag.
* @param dependencies A list of view resource dependencies of this view.
* @param dependencyBaseUrl The base url for the view dependencies.
*/
constructor(markup: string, dependencies?: Array<string | Function | ViewStrategyDependencyConfig>, dependencyBaseUrl?: string);
/**
* Loads a view factory.
* @param viewEngine The view engine to use during the load process.
* @param compileInstruction Additional instructions to use during compilation of the view.
* @param loadContext The loading context used for loading all resources and dependencies.
* @param target A class from which to extract metadata of additional resources to load.
* @return A promise for the view factory that is produced by this strategy.
*/
loadViewFactory(viewEngine: ViewEngine, compileInstruction: ViewCompileInstruction, loadContext?: ResourceLoadContext, target?: any): Promise<ViewFactory>;
}
export interface IStaticViewConfig {
template: string | HTMLTemplateElement;
dependencies?: Function[] | (() => Array<Function | Promise<Function | Record<string, Function>>>);
}
export declare class StaticViewStrategy {
factoryIsReady: boolean;
factory: ViewFactory;
onReady: any;
moduleId: string;
constructor(config: string | HTMLTemplateElement | IStaticViewConfig);
/**
* Loads a view factory.
* @param viewEngine The view engine to use during the load process.
* @param compileInstruction Additional instructions to use during compilation of the view.
* @param loadContext The loading context used for loading all resources and dependencies.
* @param target A class from which to extract metadata of additional resources to load.
* @return A promise for the view factory that is produced by this strategy.
*/
loadViewFactory(viewEngine: ViewEngine, compileInstruction: ViewCompileInstruction, loadContext: ResourceLoadContext, target: any): Promise<ViewFactory>;
}
/**
* Identifies a class as a resource that implements custom element or custom
* attribute functionality.
*/
export declare class HtmlBehaviorResource {
/**
* Creates an instance of HtmlBehaviorResource.
*/
constructor();
/**
* Checks whether the provided name matches any naming conventions for HtmlBehaviorResource.
* @param name The name of the potential resource.
* @param existing An already existing resource that may need a convention name applied.
*/
static convention(name: string, existing?: HtmlBehaviorResource): HtmlBehaviorResource;
/**
* Adds a binding expression to the component created by this resource.
* @param behavior The binding expression.
*/
addChildBinding(behavior: Object): void;
/**
* Provides an opportunity for the resource to initialize iteself.
* @param container The dependency injection container from which the resource
* can aquire needed services.
* @param target The class to which this resource metadata is attached.
*/
initialize(container: Container, target: Function): void;
/**
* Allows the resource to be registered in the view resources for the particular
* view into which it was required.
* @param registry The view resource registry for the view that required this resource.
* @param name The name provided by the end user for this resource, within the
* particular view it's being used.
*/
register(registry: ViewResources, name?: string): void;
aliases(aliases: any): void;
/**
* Enables the resource to asynchronously load additional resources.
* @param container The dependency injection container from which the resource
* can aquire needed services.
* @param target The class to which this resource metadata is attached.
* @param loadContext The loading context object provided by the view engine.
* @param viewStrategy A view strategy to overload the default strategy defined by the resource.
* @param transientView Indicated whether the view strategy is transient or
* permanently tied to this component.
*/
load(container: Container, target: Function, loadContext?: ResourceLoadContex