mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-11 15:16:28 +08:00
6c125d9a38
fix AF-2420, AF-2391, AF-2265
37 lines
917 B
TypeScript
37 lines
917 B
TypeScript
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 });
|
|
};
|