directive-helpers.d.ts 4.4 KB

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