template-content.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * @license
  3. * Copyright 2020 Google LLC
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. import { noChange } from '../lit-html.js';
  7. import { directive, Directive, PartType } from '../directive.js';
  8. class TemplateContentDirective extends Directive {
  9. constructor(partInfo) {
  10. super(partInfo);
  11. if (partInfo.type !== PartType.CHILD) {
  12. throw new Error('templateContent can only be used in child bindings');
  13. }
  14. }
  15. render(template) {
  16. if (this._previousTemplate === template) {
  17. return noChange;
  18. }
  19. this._previousTemplate = template;
  20. return document.importNode(template.content, true);
  21. }
  22. }
  23. /**
  24. * Renders the content of a template element as HTML.
  25. *
  26. * Note, the template should be developer controlled and not user controlled.
  27. * Rendering a user-controlled template with this directive
  28. * could lead to cross-site-scripting vulnerabilities.
  29. */
  30. export const templateContent = directive(TemplateContentDirective);
  31. //# sourceMappingURL=template-content.js.map