Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

917 B
Raw Blame
import { LitElement, type TemplateResult } from 'lit';
import { customElement } from 'lit/decorators.js';
import React, { createElement, type ReactNode } from 'react';

import { createComponent } from './create-component';

export
@customElement('affine-lit-template-wrapper')
class LitTemplateWrapper extends LitElement {
  static override get properties() {
    return {
      template: { type: Object },
    };
  }
  template: TemplateResult | null = null;
  // do not enable shadow root
  override createRenderRoot() {
    return this;
  }

  override render() {
    return this.template;
  }
}

const TemplateWrapper = createComponent({
  elementClass: LitTemplateWrapper,
  react: React,
});

export const toReactNode = (template?: TemplateResult | string): ReactNode => {
  if (!template) return null;
  return typeof template === 'string'
    ? template
    : createElement(TemplateWrapper, { template });
};