-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathuniver.js
More file actions
105 lines (95 loc) · 3.53 KB
/
univer.js
File metadata and controls
105 lines (95 loc) · 3.53 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
97
98
99
100
101
102
103
104
105
import { addScript, getTheme } from '../BootstrapBlazor/modules/utility.js'
import DataService from './data-service.js'
export async function createUniverSheetAsync(sheet) {
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univer-bundle.js');
sheet.lang = sheet.lang ?? 'en-US';
const { el } = sheet;
const { LocaleType, merge } = UniverCore;
const { createUniver } = UniverPresets;
const { UniverSheetsCorePreset } = UniverPresetSheetsCore;
const { UniverSheetsDrawingPreset } = UniverPresetSheetsDrawing;
const { UniverSheetsZenEditorPlugin } = UniverSheetsZenEditor;
const { UniverSheetsDataValidationPreset } = UniverPresetSheetsDataValidation;
const lang = sheet.lang.replace('-', '')
const langStr = lang.charAt(0).toUpperCase() + lang.slice(1)
const options = {
theme: sheet.theme,
darkMode: sheet.darkMode,
locale: lang,
locales: {
[lang]: merge(
{},
window[`UniverPresetSheetsCore${langStr}`],
window[`UniverPresetSheetsDrawing${langStr}`],
window[`UniverSheetsZenEditor${langStr}`],
window[`UniverPresetSheetsDataValidation${langStr}`],
window[`UniverProSheetsChart${langStr}`],
window[`UniverProSheetsChartUi${langStr}`],
),
},
presets: [
UniverSheetsCorePreset({
container: el,
ribbonType: sheet.ribbonType ?? 'simple', // default | classic | simple
menu: {
'sheet.menu.print': {
hidden: true,
},
'sheets-exchange-client.operation.exchange': {
hidden: true,
},
},
}),
UniverSheetsDrawingPreset(),
UniverSheetsDataValidationPreset(),
],
plugins: [
UniverSheetsZenEditorPlugin,
UniverProSheetsChart.UniverSheetsChartPlugin,
UniverProSheetsChartUi.UniverSheetsChartUIPlugin,
]
};
const plugins = sheet.plugins ?? {
DefaultPlugin: '_content/BootstrapBlazor.UniverSheet/plugin.js'
};
for (const name in plugins) {
const module = await import(`../../${plugins[name]}`);
const plugin = module[name];
options.plugins.push(plugin);
}
if (options.theme === 'greenTheme') {
options.theme = UniverDesign.greenTheme;
}
else {
options.theme = UniverDesign.defaultTheme;
}
if (options.darkMode === null) {
options.darkMode = getTheme() === 'dark';
}
const { univer, univerAPI } = createUniver(options);
const { workbookData } = sheet.data || {};
if (workbookData) {
const option = typeof workbookData === 'string' ? JSON.parse(workbookData) : workbookData;
univerAPI.createWorkbook(option);
}
else {
univerAPI.createWorkbook();
}
const { onRendered } = sheet.events;
if (onRendered) {
const disposable = univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, e => {
const { stage } = e;
if (stage === univerAPI.Enum.LifecycleStages.Rendered) {
onRendered();
disposable.dispose()
}
});
}
sheet.univer = univer;
sheet.univerAPI = univerAPI;
sheet.dispose = () => {
univer.dispose();
}
const dataService = univer._injector.get(DataService.name);
dataService.registerUniverSheet(sheet);
}