-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathuniver.js
More file actions
136 lines (123 loc) · 6.1 KB
/
univer.js
File metadata and controls
136 lines (123 loc) · 6.1 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { addScript, addLink, getTheme } from '../BootstrapBlazor/modules/utility.js'
import DataService from './data-service.js'
const loadAssets2 = 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');
}
const loadAssets = async lang => {
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univer-bundle.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: sheet.theme,
darkMode: sheet.darkMode,
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);
}
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);
}