UNPKG

2.57 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2017 Google LLC
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6import { Disconnectable, Part } from './lit-html';
7export { AttributePart, BooleanAttributePart, ChildPart, ElementPart, EventPart, Part, PropertyPart, } from './lit-html';
8export interface DirectiveClass {
9 new (part: PartInfo): Directive;
10}
11/**
12 * This utility type extracts the signature of a directive class's render()
13 * method so we can use it for the type of the generated directive function.
14 */
15export declare type DirectiveParameters<C extends Directive> = Parameters<C['render']>;
16/**
17 * A generated directive function doesn't evaluate the directive, but just
18 * returns a DirectiveResult object that captures the arguments.
19 */
20export interface DirectiveResult<C extends DirectiveClass = DirectiveClass> {
21}
22export declare const PartType: {
23 readonly ATTRIBUTE: 1;
24 readonly CHILD: 2;
25 readonly PROPERTY: 3;
26 readonly BOOLEAN_ATTRIBUTE: 4;
27 readonly EVENT: 5;
28 readonly ELEMENT: 6;
29};
30export declare type PartType = typeof PartType[keyof typeof PartType];
31export interface ChildPartInfo {
32 readonly type: typeof PartType.CHILD;
33}
34export interface AttributePartInfo {
35 readonly type: typeof PartType.ATTRIBUTE | typeof PartType.PROPERTY | typeof PartType.BOOLEAN_ATTRIBUTE | typeof PartType.EVENT;
36 readonly strings?: ReadonlyArray<string>;
37 readonly name: string;
38 readonly tagName: string;
39}
40export interface ElementPartInfo {
41 readonly type: typeof PartType.ELEMENT;
42}
43/**
44 * Information about the part a directive is bound to.
45 *
46 * This is useful for checking that a directive is attached to a valid part,
47 * such as with directive that can only be used on attribute bindings.
48 */
49export declare type PartInfo = ChildPartInfo | AttributePartInfo | ElementPartInfo;
50/**
51 * Creates a user-facing directive function from a Directive class. This
52 * function has the same parameters as the directive's render() method.
53 */
54export declare const directive: <C extends DirectiveClass>(c: C) => (...values: Parameters<InstanceType<C>["render"]>) => DirectiveResult<C>;
55/**
56 * Base class for creating custom directives. Users should extend this class,
57 * implement `render` and/or `update`, and then pass their subclass to
58 * `directive`.
59 */
60export declare abstract class Directive implements Disconnectable {
61 constructor(_partInfo: PartInfo);
62 get _$isConnected(): boolean;
63 abstract render(...props: Array<unknown>): unknown;
64 update(_part: Part, props: Array<unknown>): unknown;
65}
66//# sourceMappingURL=directive.d.ts.map
\No newline at end of file