2021-08-25 17:52:20 +08:00
|
|
|
const waitUntilElementExists = (selector: any, callback: (element: Element) => void) => {
|
|
|
|
const element = document.querySelector(selector)
|
|
|
|
|
|
|
|
if (element) {
|
|
|
|
return callback(element)
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(() => waitUntilElementExists(selector, callback), 500)
|
|
|
|
}
|
|
|
|
|
|
|
|
const sendData = (eventName: string, data: any) => {
|
|
|
|
const event = new CustomEvent(eventName, { detail: data })
|
|
|
|
|
|
|
|
window.parent.document.dispatchEvent(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function splitName(name: string) {
|
|
|
|
const parts = name.split('/')
|
|
|
|
|
2023-06-02 00:21:47 +08:00
|
|
|
if (parts.length !== 3) {
|
2021-08-25 17:52:20 +08:00
|
|
|
throw Error('Demos must always be within exactly one category. Nested categories are not supported.')
|
|
|
|
}
|
|
|
|
|
|
|
|
return parts
|
|
|
|
}
|
|
|
|
|
|
|
|
export function debug() {
|
|
|
|
sendData('editor', null)
|
|
|
|
// @ts-ignore
|
|
|
|
sendData('source', window.source)
|
|
|
|
|
2023-05-25 19:45:06 +08:00
|
|
|
waitUntilElementExists('.tiptap', element => {
|
2021-08-25 17:52:20 +08:00
|
|
|
// @ts-ignore
|
|
|
|
const editor = element.editor
|
|
|
|
|
|
|
|
sendData('editor', editor)
|
|
|
|
})
|
|
|
|
}
|