-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathuniver.js
More file actions
96 lines (86 loc) · 4.3 KB
/
univer.js
File metadata and controls
96 lines (86 loc) · 4.3 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 { addScript, addLink } from '../BootstrapBlazor/modules/utility.js'
import DataService from './data-service.js'
const loadAssets = async lang => {
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/react.production.min.js');
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/react-dom.production.min.js');
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/rxjs.umd.min.js');
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univerjs.presets.umd.min.js');
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-core/index.umd.min.js');
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-drawing/index.umd.min.js');
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univerjs.sheets-zen-editor/index.umd.min.js');
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-data-validation/index.umd.min.js');
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-advanced/index.umd.min.js');
await addScript(`./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-core/locales/${lang}.js`);
await addScript(`./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-drawing/locales/${lang}.js`);
await addScript(`./_content/BootstrapBlazor.UniverSheet/univer/univerjs.sheets-zen-editor/locales/${lang}.js`);
await addScript(`./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-data-validation/locales/${lang}.js`);
await addScript(`./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-advanced/locales/${lang}.js`);
await addLink('./_content/BootstrapBlazor.UniverSheet/univer/univer-sheet.bundle.css');
}
export async function createUniverSheetAsync(sheet) {
sheet.lang = sheet.lang ?? 'en-US';
await loadAssets(sheet.lang);
const { el } = sheet;
const { LocaleType, merge } = UniverCore;
const { createUniver } = UniverPresets;
const { UniverSheetsCorePreset } = UniverPresetSheetsCore;
const { UniverSheetsDrawingPreset } = UniverPresetSheetsDrawing;
const { UniverSheetsAdvancedPreset } = UniverPresetSheetsAdvanced;
const { UniverSheetsZenEditorPlugin } = UniverSheetsZenEditor
const { UniverSheetsDataValidationPlugin } = UniverSheetsDataValidation
const { UniverSheetsDataValidationUIPlugin } = UniverSheetsDataValidationUi
const lang = sheet.lang.replace('-', '')
const langStr = lang.charAt(0).toUpperCase() + lang.slice(1)
const options = {
theme: UniverDesign[sheet.theme] ?? UniverDesign.defaultTheme, //'defaultTheme' | greenTheme
locale: lang,
locales: {
[lang]: merge(
{},
window[`UniverPresetSheetsCore${langStr}`],
window[`UniverPresetSheetsDrawing${langStr}`],
window[`UniverSheetsZenEditor${langStr}`],
window[`UniverSheetsDataValidationUi${langStr}`],
window[`UniverPresetSheetsAdvanced${langStr}`],
),
},
plugins: [
UniverSheetsZenEditorPlugin,
UniverSheetsDataValidationPlugin,
UniverSheetsDataValidationUIPlugin,
]
};
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);
}
const { univer, univerAPI } = createUniver({
presets: [
UniverSheetsCorePreset({
container: el
}),
UniverSheetsDrawingPreset(),
UniverSheetsAdvancedPreset()
],
...options
});
const { workbookData } = sheet.data || {};
if (workbookData) {
const option = typeof workbookData === 'string' ? JSON.parse(workbookData) : workbookData;
univerAPI.createWorkbook(option);
}
else {
univerAPI.createWorkbook();
}
sheet.univer = univer;
sheet.univerAPI = univerAPI;
sheet.dispose = () => {
univer.dispose();
}
const dataService = univer._injector.get(DataService.name);
dataService.registerUniverSheet(sheet);
}