-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.ts
More file actions
30 lines (24 loc) · 971 Bytes
/
index.ts
File metadata and controls
30 lines (24 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { metaKey } from './utilities'
import SharedStorage from './utilities/shared-storage'
import { WebEditor } from './components/uh-web-editor/uh-web-editor.element'
export function attachEditor() {
Object.defineProperty(globalThis, 'sharedStorage', {
value: new SharedStorage(),
});
if (metaKey === 'ctrl')
[...document.querySelectorAll('kbd')]
.forEach(node => {
node.textContent = node.textContent!.replace('cmd','ctrl')
node.textContent = node.textContent!.replace('opt','alt')
})
if(!customElements.get('uh-web-editor')) customElements.define('uh-web-editor', WebEditor)
if(!document.querySelector('uh-web-editor')) {
const WebEditorElement = new WebEditor();
document.firstElementChild.prepend(WebEditorElement)
}
}
export function detachEditor() {
const WebEditorElement = document.querySelector('uh-web-editor')
if(WebEditorElement) WebEditorElement.remove()
}
export default WebEditor