刘光辉
11 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
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
import 'ant-design-vue/dist/reset.css';
import './styles.css';
 
import Antd from 'ant-design-vue';
import { createPinia } from 'pinia';
import { createApp } from 'vue';
 
import App from './App.vue';
import { createOnlyOfficeBridge } from './onlyoffice/bridge';
import type { AscGlobal } from './onlyoffice/types';
 
function isRecord(value: unknown): value is Record<string, unknown> {
  return typeof value === 'object' && value !== null && !Array.isArray(value);
}
 
function isPendingSdkMethod(value: unknown): value is undefined | ((...args: never[]) => unknown) {
  return value === undefined || typeof value === 'function';
}
 
function isAscBootstrapGlobal(value: unknown): value is AscGlobal {
  if (!isRecord(value) || !isRecord(value.plugin) || !isRecord(value.scope)) return false;
 
  const plugin = value.plugin;
  const methods = [plugin.callCommand, plugin.executeMethod, plugin.executeCommand, plugin.onThemeChangedBase];
  const methodsReady = methods.every((method) => typeof method === 'function');
  const validBootstrap = typeof plugin.attachEvent === 'function' && methods.every(isPendingSdkMethod);
  return methodsReady || validBootstrap;
}
 
const bridge = isAscBootstrapGlobal(window.Asc) ? createOnlyOfficeBridge(window.Asc) : null;
 
createApp(App).use(createPinia()).use(Antd).provide('onlyOfficeBridge', bridge).mount('#app');