-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathuniver.js
More file actions
109 lines (100 loc) · 5.37 KB
/
univer.js
File metadata and controls
109 lines (100 loc) · 5.37 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
106
107
108
109
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-thread-comment/index.umd.min.js');
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-hyper-link/index.umd.min.js');
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-filter/index.umd.min.js');
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-conditional-formatting/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-thread-comment/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 { UniverSheetsThreadCommentPreset } = UniverPresetSheetsThreadComment;
const { UniverSheetsDataValidationPreset } = UniverPresetSheetsDataValidation;
const lang = sheet.lang.replace('-', '')
const langStr = lang.charAt(0).toUpperCase() + lang.slice(1)
const options = {
theme: UniverDesign[sheet.theme] ?? UniverDesign.defaultTheme, //'defaultTheme' | greenTheme
darkMode: sheet.darkMode ?? false, // false | true
locale: lang,
locales: {
[lang]: merge(
{},
window[`UniverPresetSheetsCore${langStr}`],
window[`UniverPresetSheetsDrawing${langStr}`],
window[`UniverSheetsZenEditor${langStr}`],
window[`UniverPresetSheetsDataValidation${langStr}`],
window[`UniverPresetSheetsThreadComment${langStr}`],
window[`UniverPresetSheetsAdvanced${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(),
UniverSheetsThreadCommentPreset(),
UniverSheetsDataValidationPreset(),
UniverSheetsAdvancedPreset(),
],
plugins: [
UniverSheetsZenEditorPlugin,
]
};
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(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);
}