-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathUniverSheet.razor.js
More file actions
96 lines (82 loc) · 2.59 KB
/
UniverSheet.razor.js
File metadata and controls
96 lines (82 loc) · 2.59 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { addLink, 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) {
await addLink('./_content/BootstrapBlazor.UniverSheet/css/univer-sheet.bundle.css');
const el = document.getElementById(id);
if (el === null) {
return;
}
const backdrop = el.querySelector('.bb-univer-sheet-backdrop');
if (backdrop) {
backdrop.style.removeProperty('display');
}
const { theme, lang, plugins, data, ribbonType, darkMode } = options;
const univerSheet = {
el: el.querySelector('.bb-univer-sheet-wrap'),
backdrop,
invoke,
data,
plugins,
theme,
lang,
ribbonType,
darkMode,
events: {
onRendered: () => {
if (backdrop) {
backdrop.classList.add('d-none');
}
}
}
};
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);
const { firstPush, backdrop, pushData } = univerSheet;
let ret = null;
if (pushData) {
ret = pushData(data);
}
if (firstPush === true && backdrop) {
setTimeout(() => {
backdrop.classList.add('d-none');
}, 100);
}
return ret;
}
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');
}
}
}
});
}