-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathUniverSheet.razor.js
More file actions
71 lines (59 loc) · 1.88 KB
/
UniverSheet.razor.js
File metadata and controls
71 lines (59 loc) · 1.88 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { isFunction, registerBootstrapBlazorModule } from '../../BootstrapBlazor/modules/utility.js'
import { createUniverSheetAsync } from '../univer.js'
import Data from '../../BootstrapBlazor/modules/data.js'
import EventHandler from "../../BootstrapBlazor/modules/event-handler.js"
export async function init(id, invoke, options) {
const el = document.getElementById(id);
if (el === null) {
return;
}
const { theme, lang, plugins, data, ribbonType, darkMode } = options;
const univerSheet = {
el,
invoke,
data,
plugins,
theme,
lang,
ribbonType,
darkMode
};
await createUniverSheetAsync(univerSheet);
Data.set(id, univerSheet);
invoke.invokeMethodAsync('TriggerReadyAsync');
registerBootstrapBlazorModule('UniverSheet', id, () => {
EventHandler.on(document, 'changed.bb.theme', updateTheme);
});
}
export function execute(id, data) {
const univerSheet = Data.get(id);
return univerSheet.pushData(data);
}
export function dispose(id) {
const univerSheet = Data.get(id);
Data.remove(id);
if (isFunction(univerSheet.dispose)) {
univerSheet.dispose();
}
const { UniverSheet } = window.BootstrapBlazor;
if (UniverSheet) {
UniverSheet.dispose(id, () => {
EventHandler.off(document, 'changed.bb.theme', updateTheme);
});
}
}
const updateTheme = e => {
const theme = e.theme;
[...document.querySelectorAll('.bb-univer-sheet')].forEach(s => {
const id = s.getAttribute('id');
if (id) {
const univerSheet = Data.get(id);
if (univerSheet && univerSheet.darkMode === null) {
const { univerAPI } = univerSheet;
if (univerAPI) {
univerAPI.toggleDarkMode(theme === 'dark');
}
}
}
});
}