directive-helpers.d.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * @license
  3. * Copyright 2020 Google LLC
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. import { Part, DirectiveParent, CompiledTemplateResult, MaybeCompiledTemplateResult, UncompiledTemplateResult } from './lit-html.js';
  7. import { DirectiveResult, DirectiveClass, PartInfo } from './directive.js';
  8. type Primitive = null | undefined | boolean | number | string | symbol | bigint;
  9. declare const ChildPart: typeof import("./lit-html.js").ChildPart;
  10. type ChildPart = InstanceType<typeof ChildPart>;
  11. /**
  12. * Tests if a value is a primitive value.
  13. *
  14. * See https://tc39.github.io/ecma262/#sec-typeof-operator
  15. */
  16. export declare const isPrimitive: (value: unknown) => value is Primitive;
  17. export declare const TemplateResultType: {
  18. readonly HTML: 1;
  19. readonly SVG: 2;
  20. readonly MATHML: 3;
  21. };
  22. export type TemplateResultType = (typeof TemplateResultType)[keyof typeof TemplateResultType];
  23. type IsTemplateResult = {
  24. (val: unknown): val is MaybeCompiledTemplateResult;
  25. <T extends TemplateResultType>(val: unknown, type: T): val is UncompiledTemplateResult<T>;
  26. };
  27. /**
  28. * Tests if a value is a TemplateResult or a CompiledTemplateResult.
  29. */
  30. export declare const isTemplateResult: IsTemplateResult;
  31. /**
  32. * Tests if a value is a CompiledTemplateResult.
  33. */
  34. export declare const isCompiledTemplateResult: (value: unknown) => value is CompiledTemplateResult;
  35. /**
  36. * Tests if a value is a DirectiveResult.
  37. */
  38. export declare const isDirectiveResult: (value: unknown) => value is DirectiveResult;
  39. /**
  40. * Retrieves the Directive class for a DirectiveResult
  41. */
  42. export declare const getDirectiveClass: (value: unknown) => DirectiveClass | undefined;
  43. /**
  44. * Tests whether a part has only a single-expression with no strings to
  45. * interpolate between.
  46. *
  47. * Only AttributePart and PropertyPart can have multiple expressions.
  48. * Multi-expression parts have a `strings` property and single-expression
  49. * parts do not.
  50. */
  51. export declare const isSingleExpression: (part: PartInfo) => boolean;
  52. /**
  53. * Inserts a ChildPart into the given container ChildPart's DOM, either at the
  54. * end of the container ChildPart, or before the optional `refPart`.
  55. *
  56. * This does not add the part to the containerPart's committed value. That must
  57. * be done by callers.
  58. *
  59. * @param containerPart Part within which to add the new ChildPart
  60. * @param refPart Part before which to add the new ChildPart; when omitted the
  61. * part added to the end of the `containerPart`
  62. * @param part Part to insert, or undefined to create a new part
  63. */
  64. export declare const insertPart: (containerPart: ChildPart, refPart?: ChildPart, part?: ChildPart) => ChildPart;
  65. /**
  66. * Sets the value of a Part.
  67. *
  68. * Note that this should only be used to set/update the value of user-created
  69. * parts (i.e. those created using `insertPart`); it should not be used
  70. * by directives to set the value of the directive's container part. Directives
  71. * should return a value from `update`/`render` to update their part state.
  72. *
  73. * For directives that require setting their part value asynchronously, they
  74. * should extend `AsyncDirective` and call `this.setValue()`.
  75. *
  76. * @param part Part to set
  77. * @param value Value to set
  78. * @param index For `AttributePart`s, the index to set
  79. * @param directiveParent Used internally; should not be set by user
  80. */
  81. export declare const setChildPartValue: <T extends ChildPart>(part: T, value: unknown, directiveParent?: DirectiveParent) => T;
  82. /**
  83. * Sets the committed value of a ChildPart directly without triggering the
  84. * commit stage of the part.
  85. *
  86. * This is useful in cases where a directive needs to update the part such
  87. * that the next update detects a value change or not. When value is omitted,
  88. * the next update will be guaranteed to be detected as a change.
  89. *
  90. * @param part
  91. * @param value
  92. */
  93. export declare const setCommittedValue: (part: Part, value?: unknown) => unknown;
  94. /**
  95. * Returns the committed value of a ChildPart.
  96. *
  97. * The committed value is used for change detection and efficient updates of
  98. * the part. It can differ from the value set by the template or directive in
  99. * cases where the template value is transformed before being committed.
  100. *
  101. * - `TemplateResult`s are committed as a `TemplateInstance`
  102. * - Iterables are committed as `Array<ChildPart>`
  103. * - All other types are committed as the template value or value returned or
  104. * set by a directive.
  105. *
  106. * @param part
  107. */
  108. export declare const getCommittedValue: (part: ChildPart) => unknown;
  109. /**
  110. * Removes a ChildPart from the DOM, including any of its content and markers.
  111. *
  112. * Note: The only difference between this and clearPart() is that this also
  113. * removes the part's start node. This means that the ChildPart must own its
  114. * start node, ie it must be a marker node specifically for this part and not an
  115. * anchor from surrounding content.
  116. *
  117. * @param part The Part to remove
  118. */
  119. export declare const removePart: (part: ChildPart) => void;
  120. export declare const clearPart: (part: ChildPart) => void;
  121. export {};
  122. //# sourceMappingURL=directive-helpers.d.ts.map