tiptap/demos/setup/react.ts

39 lines
999 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, splitName } 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 [demoCategory, demoName, frameworkName] = splitName(name)
2021-08-25 17:52:20 +08:00
import(`../src/${demoCategory}/${demoName}/${frameworkName}/index.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(`../src/${demoCategory}/${demoName}/${frameworkName}/index.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
}