feat(core): peek view api enhancements (#7288)

upstream https://github.com/toeverything/blocksuite/pull/7390
fix AF-917
This commit is contained in:
pengx17
2024-06-21 07:38:42 +00:00
parent f85a321bfa
commit e085b927f6
15 changed files with 182 additions and 219 deletions

View File

@@ -1,2 +1,3 @@
export { createComponent as createReactComponentFromLit } from './create-component';
export * from './lit-portal';
export { toReactNode } from './to-react-node';

View File

@@ -0,0 +1,35 @@
import { LitElement, type TemplateResult } from 'lit';
import React, { createElement, type ReactNode } from 'react';
import { createComponent } from './create-component';
export 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;
}
}
window.customElements.define('affine-lit-template-wrapper', LitTemplateWrapper);
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 });
};