tiptap/demos/setup/react.ts

39 lines
860 B
TypeScript
Raw Normal View History

import 'iframe-resizer/js/iframeResizer.contentWindow'
import './style.scss'
2021-08-25 17:52:20 +08:00
import React from 'react'
2022-04-11 16:16:04 +08:00
import { createRoot } from 'react-dom/client'
import { debug } from './helper'
2021-08-25 17:52:20 +08:00
export default function init(name: string, source: any) {
// @ts-ignore
window.source = source
document.title = name
const path = `../src/${name}/index`
2021-08-25 17:52:20 +08:00
import(`${path}.tsx`)
2021-08-25 17:52:20 +08:00
.then(module => {
2022-04-11 16:16:04 +08:00
const root = document.getElementById('app')
if (root) {
createRoot(root)
.render(React.createElement(module.default))
2022-04-11 16:16:04 +08:00
}
2021-08-25 17:52:20 +08:00
debug()
})
.catch(() => {
import(`${path}.jsx`)
.then(module => {
const root = document.getElementById('app')
if (root) {
createRoot(root)
.render(React.createElement(module.default))
}
debug()
})
})
2021-08-25 17:52:20 +08:00
}