weboffice-js-sdk 2.0.4 → 2.0.5-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -66
- package/dist/OfficeSDK.d.ts +8 -4
- package/dist/OfficeSDK.facade.d.ts +1 -0
- package/dist/OfficeSDK.facade.types.d.ts +130 -27
- package/dist/editorFacade.contract.d.ts +33 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -2
- package/dist/jsapi/contract.d.ts +22 -0
- package/dist/jsapi/index.d.ts +3 -0
- package/dist/jsapi/light-doc-p0.contract.d.ts +2 -0
- package/dist/types/EmptyPage.d.ts +2 -2
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -6,22 +6,22 @@
|
|
|
6
6
|
|
|
7
7
|
_注:此 SDK 无法用于石墨文档官网产品 (即 shimo.im) 。_
|
|
8
8
|
|
|
9
|
-
## [文档详情](https://shimo-open.github.io/
|
|
9
|
+
## [文档详情](https://shimo-open.github.io/weboffice-js-sdk/#/)
|
|
10
10
|
|
|
11
11
|
### 安装
|
|
12
12
|
|
|
13
13
|
```shell
|
|
14
14
|
# 通过 npm
|
|
15
|
-
npm install --save
|
|
15
|
+
npm install --save weboffice-js-sdk
|
|
16
16
|
|
|
17
17
|
# 通过 yarn
|
|
18
|
-
yarn add
|
|
18
|
+
yarn add weboffice-js-sdk
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
### 初始化 iframe
|
|
22
22
|
|
|
23
23
|
```js
|
|
24
|
-
const { connect } = require('
|
|
24
|
+
const { connect } = require('weboffice-js-sdk')
|
|
25
25
|
|
|
26
26
|
connect({
|
|
27
27
|
fileId: '您系统中的 file id',
|
|
@@ -29,13 +29,13 @@ connect({
|
|
|
29
29
|
signature: '用您的 app id 和 secret 签发的签名',
|
|
30
30
|
token: '用于您系统识别用户请求的 token',
|
|
31
31
|
container: document.querySelector('#shimo-file'), // iframe 挂载的目标容器元素
|
|
32
|
-
lang: 'en', //
|
|
32
|
+
lang: 'en-US', // 可选;未指定时使用编辑器默认语言
|
|
33
33
|
disableAiEntry: true, // 可选,隐藏 iframe 内 AI 入口
|
|
34
34
|
theme: {
|
|
35
35
|
name: 'light'
|
|
36
36
|
}, // 可选,透传给 iframe 内编辑器主题配置
|
|
37
37
|
userUuid:'您的uuid' // 仅在v2版本回调时需要传入(co-1.3+支持)
|
|
38
|
-
}).then((
|
|
38
|
+
}).then((officeSDK) => {
|
|
39
39
|
// ...
|
|
40
40
|
})
|
|
41
41
|
```
|
|
@@ -44,31 +44,31 @@ connect({
|
|
|
44
44
|
|
|
45
45
|
其中:
|
|
46
46
|
|
|
47
|
-
- `disableAiEntry` 为可选布尔值,透传到 iframe 内 `
|
|
47
|
+
- `disableAiEntry` 为可选布尔值,透传到 iframe 内 `OfficeSDK` 的 AI 入口开关能力。
|
|
48
48
|
- `theme` 为可选主题对象,宿主侧仅负责透传;未传时 iframe 内仍使用默认主题配置。
|
|
49
49
|
|
|
50
50
|
返回值:
|
|
51
51
|
|
|
52
52
|
```
|
|
53
|
-
Promise<
|
|
53
|
+
Promise<OfficeSDK>
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
**使用传统的 `<script>` 的方式加载:**
|
|
57
57
|
|
|
58
58
|
1. 使用 [npm view](https://docs.npmjs.com/cli/v7/commands/npm-view) 和 [npm pack](https://docs.npmjs.com/cli/v7/commands/npm-pack) 下载代码包 (`.tgz` 格式)
|
|
59
59
|
2. 将 `.tgz` 解压缩后的 `dist` 目录下的文件放置到您托管静态资源的空间,然后使用 `<script>` 引入 `index.js` 资源
|
|
60
|
-
3. 通过 `window.
|
|
60
|
+
3. 通过 `window.WebOfficeJSSDK` 对象获取对应的方法
|
|
61
61
|
|
|
62
62
|
```js
|
|
63
|
-
const { connect, FileType } = window.
|
|
63
|
+
const { connect, FileType } = window.WebOfficeJSSDK
|
|
64
64
|
// 等价于
|
|
65
|
-
const { connect, FileType } = require('
|
|
65
|
+
const { connect, FileType } = require('weboffice-js-sdk')
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
#### 使用示例
|
|
69
69
|
|
|
70
70
|
```js
|
|
71
|
-
const { connect } = require('
|
|
71
|
+
const { connect } = require('weboffice-js-sdk')
|
|
72
72
|
|
|
73
73
|
const fileId = '1234'
|
|
74
74
|
const uuid = 'youruuid'
|
|
@@ -84,19 +84,19 @@ connect({
|
|
|
84
84
|
container: document.querySelector('#shimo-file'), // iframe 挂载的目标容器元素
|
|
85
85
|
userUuid: uuid
|
|
86
86
|
}).then((sdk) => {
|
|
87
|
-
// sdk 即为
|
|
87
|
+
// sdk 即为 OfficeSDK 实例
|
|
88
88
|
})
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
调用 `connect()` 时,会以传入参数为基础,初始化一个 `<iframe>` 并插入 `container` 对应的元素中。
|
|
92
92
|
|
|
93
|
-
返回的 `sdk` 为 `
|
|
93
|
+
返回的 `sdk` 为 `OfficeSDK` 实例,用于和 SDK、编辑器交互。
|
|
94
94
|
|
|
95
95
|
### SDK 和编辑器实例
|
|
96
96
|
|
|
97
97
|
石墨 JS SDK 共有两种实例用于和 JS SDK 交互:
|
|
98
98
|
|
|
99
|
-
- `
|
|
99
|
+
- `OfficeSDK` 由 `connect()` 返回,处理初始化编辑器和编辑器交互的工作
|
|
100
100
|
- `Editor` 文档编辑器,直接和文档内容交互。**`Editor` 所有接口均返回 Promise**
|
|
101
101
|
|
|
102
102
|
两者之间各有独立的方法和事件,具体请查看 `docs` 目录的文档。
|
|
@@ -104,7 +104,7 @@ connect({
|
|
|
104
104
|
获取编辑器实例和与其交互:
|
|
105
105
|
|
|
106
106
|
```js
|
|
107
|
-
const { FileType } = require('
|
|
107
|
+
const { FileType } = require('weboffice-js-sdk')
|
|
108
108
|
|
|
109
109
|
// 获取编辑器实例
|
|
110
110
|
const editor = sdk.getEditor()
|
|
@@ -123,7 +123,7 @@ if (sdk.fileType === FileType.Document) {
|
|
|
123
123
|
若为 `TypeScript`,可使用 `Generic`:
|
|
124
124
|
|
|
125
125
|
```typescript
|
|
126
|
-
const { Document } = require('
|
|
126
|
+
const { Document } = require('weboffice-js-sdk')
|
|
127
127
|
|
|
128
128
|
const editor = sdk.getEditor<Document.Editor>()
|
|
129
129
|
editor.on('saveStatusChanged', (payload) => {
|
|
@@ -193,7 +193,7 @@ const sdk = await connect({
|
|
|
193
193
|
|
|
194
194
|
### 协作者模块使用说明
|
|
195
195
|
|
|
196
|
-
当 iframe 套件开启协作者能力后(依赖 `ENABLE_SDK_COLLABORATORS_MODULE` 开关),
|
|
196
|
+
当 iframe 套件开启协作者能力后(依赖 `ENABLE_SDK_COLLABORATORS_MODULE` 开关),weboffice-js-sdk 使用方可按以下方式接入:
|
|
197
197
|
|
|
198
198
|
1. **监听 `collaboratorsChanged`**
|
|
199
199
|
|
|
@@ -237,56 +237,61 @@ editor.on('editForbiddenConfirmed', ({ reason }) => {
|
|
|
237
237
|
})
|
|
238
238
|
```
|
|
239
239
|
|
|
240
|
-
###
|
|
240
|
+
### 凭证自动刷新(建议)
|
|
241
241
|
|
|
242
242
|
- `signature` 为石墨区分请求来源,并实现数据隔离的基础
|
|
243
243
|
- `token` 为您用于识别回调请求来源、是否合法的依据
|
|
244
244
|
|
|
245
|
-
|
|
245
|
+
由于 `signature` 和 `token` 有过期时间,建议在 `ConnectOptions` 中配置自动刷新,避免用户长时间编辑时因凭证失效而中断。
|
|
246
246
|
|
|
247
|
-
|
|
247
|
+
```typescript
|
|
248
|
+
const { expireMs } = (await appService.getExpireConfig()).data
|
|
248
249
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
*
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
setInterval(
|
|
259
|
-
() => {
|
|
260
|
-
// 建议过期时间为7天
|
|
261
|
-
// 当剩余时间不到3.5天就过期时进行更新
|
|
262
|
-
if (expires - Date.now() < 1000 * 3600 * 24 * 3.5) {
|
|
263
|
-
const resp = await getCredentialsFromServer()
|
|
264
|
-
await shimoSDK.setCredentials({
|
|
265
|
-
signature: resp.signature,
|
|
266
|
-
token: resp.token
|
|
267
|
-
})
|
|
268
|
-
expires = resp.expires
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
60 * 1000
|
|
272
|
-
)
|
|
273
|
-
// 以上为旧版本更新鉴权方式,新版本(v1.2.23+)请参照如下方式进行更新
|
|
274
|
-
const shimoSDK = await connect({
|
|
275
|
-
signature: '[your signature]',
|
|
276
|
-
token: '[your token]',
|
|
277
|
-
// 更新鉴权的时间间隔,单位为毫秒
|
|
278
|
-
// 若过期时间为7天,则建议设置为1000 * 3600 * 24 * 3.5 (3.5天)
|
|
279
|
-
refreshCredentialsInterval: 1000 * 3600 * 24 * 3.5,
|
|
280
|
-
getCredentials: async () => {
|
|
281
|
-
const res = await getCredentialsFromServer()
|
|
282
|
-
return {
|
|
283
|
-
signature: res.signature,
|
|
284
|
-
token: res.token,
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
})
|
|
250
|
+
const options: ConnectOptions = {
|
|
251
|
+
...config,
|
|
252
|
+
// 在过期时长的 80% 处刷新,给网络重试等情况预留时间
|
|
253
|
+
refreshCredentialsInterval: Math.ceil(expireMs * 0.8),
|
|
254
|
+
getCredentials: async () => (await appService.getCredentials()).data
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const officeSDK = await connect(options)
|
|
288
258
|
```
|
|
289
259
|
|
|
260
|
+
示例配套接口:
|
|
261
|
+
|
|
262
|
+
- `GET /api/apps/expire-config`:返回凭证过期时长,例如 `{ expireMs: 900000 }`
|
|
263
|
+
- `GET /api/credentials`:返回新凭证,例如 `{ signature, token }`
|
|
264
|
+
|
|
265
|
+
`getCredentials` 应从接入方后端获取最新凭证,并返回同时包含 `signature` 和 `token` 的对象。接口路径可按接入方系统实际情况调整。
|
|
266
|
+
|
|
267
|
+
### 国际化:编辑器多语言(可选,co-1.8+)
|
|
268
|
+
|
|
269
|
+
接入方可在调用 `connect` 时通过 `lang` 指定编辑器界面语言,传入对应语言码即可;用户选择“系统默认”时省略 `lang`(或传 `undefined`;纯 JavaScript 也可传 `null`)。
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
const options: ConnectOptions = {
|
|
273
|
+
...config,
|
|
274
|
+
...(editorLang ? { lang: editorLang } : {}) // “系统默认”时不传 lang
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const officeSDK = await connect(options)
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
1.8 版本编辑器支持以下 16 种语言:
|
|
281
|
+
|
|
282
|
+
| 语言 | `lang` 语言码 | 语言 | `lang` 语言码 |
|
|
283
|
+
| ------------- | ------------- | ---------------- | ------------- |
|
|
284
|
+
| 简体中文 | `zh-CN` | 繁體中文 | `zh-TW` |
|
|
285
|
+
| English | `en-US` | 日本語 | `ja-JP` |
|
|
286
|
+
| 한국어 | `ko-KR` | Español | `es-ES` |
|
|
287
|
+
| Português | `pt-PT` | Deutsch | `de-DE` |
|
|
288
|
+
| Français | `fr-FR` | Italiano | `it-IT` |
|
|
289
|
+
| Русский | `ru-RU` | Bahasa Indonesia | `id-ID` |
|
|
290
|
+
| Tiếng Việt | `vi-VN` | ไทย | `th-TH` |
|
|
291
|
+
| Bahasa Melayu | `ms-MY` | العربية | `ar-SA` |
|
|
292
|
+
|
|
293
|
+
为兼容旧版写法,仍可传入 `en`、`ja`,SDK 会分别映射为 `en-US`、`ja-JP`。新接入建议使用表中的标准语言码。
|
|
294
|
+
|
|
290
295
|
### 如何处理 URL
|
|
291
296
|
|
|
292
297
|
由于石墨 SDK 以 `iframe` 的形式挂载到当前页面,`iframe.src` 对应的 URL 并不适合用于分享,而且在一些功能上,比如 @ 文件,需要用到您系统中对应的 URL 格式,比如 `https://your-domain/files/:id`。
|
|
@@ -294,9 +299,9 @@ const shimoSDK = await connect({
|
|
|
294
299
|
为了解决这个问题,石墨 SDK 引入 `generateUrl()` 和 `openLink()` 方法:
|
|
295
300
|
|
|
296
301
|
```js
|
|
297
|
-
import { UrlSharingType } from '
|
|
302
|
+
import { UrlSharingType } from 'weboffice-js-sdk'
|
|
298
303
|
|
|
299
|
-
const
|
|
304
|
+
const officeSDK = await connect({
|
|
300
305
|
...,
|
|
301
306
|
|
|
302
307
|
generateUrl(fileId: string, info: GenerateUrlInfo): string {
|
|
@@ -497,9 +502,9 @@ connect({
|
|
|
497
502
|
- `ui.toast.tips.edit.noPermission`
|
|
498
503
|
|
|
499
504
|
```typescript
|
|
500
|
-
import { connect } from '
|
|
505
|
+
import { connect } from 'weboffice-js-sdk'
|
|
501
506
|
|
|
502
|
-
const
|
|
507
|
+
const officeSDK = await connect({
|
|
503
508
|
ui: {
|
|
504
509
|
toast: {
|
|
505
510
|
tips: {
|
|
@@ -521,9 +526,9 @@ const shimoSDK = await connect({
|
|
|
521
526
|
此方法可显示接入方自定义 toast,具体用法如下
|
|
522
527
|
|
|
523
528
|
```typescript
|
|
524
|
-
import { connect, ShowToastOptions } from '
|
|
529
|
+
import { connect, ShowToastOptions } from 'weboffice-js-sdk'
|
|
525
530
|
|
|
526
|
-
const
|
|
531
|
+
const officeSDK = await connect({
|
|
527
532
|
// 初始化sdk时传了该方法将会拦截编辑器内的toast
|
|
528
533
|
showToast: (options: ShowToastOptions) => {
|
|
529
534
|
// show your toast
|
package/dist/OfficeSDK.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { Document, DocumentPro, Presentation, Spreadsheet, Table, Form, Flowchar
|
|
|
9
9
|
import { EmptyPageOptions } from './types/EmptyPage';
|
|
10
10
|
import { BaseEditor } from './types/BaseEditor';
|
|
11
11
|
import { SlashMenuOptions } from './types/SlashMenu';
|
|
12
|
-
import type { CollaboratorFacade, CommentsFacade, ContentFacade, DiscussionFacade, DocsOutlineFacade, DocsSearchFacade, DocsSelectionFacade, DocsSettingsFacade, DocsSidebarFacade, DocsTablesFacade, ExternalAppFacade, HistoryFacade, LocksFacade, MentionFacade,
|
|
12
|
+
import type { CollaboratorFacade, CommentsFacade, ContentFacade, DiscussionFacade, DocsActiveDocumentFacade, DocsOutlineFacade, DocsSearchFacade, DocsSelectionFacade, DocsSettingsFacade, DocsSidebarFacade, DocsTablesFacade, ExternalAppFacade, HistoryFacade, LocksFacade, MentionFacade, OfficeSDKPresentationFacade, PresentationEventSubscriptionFacade, PresentationSelectionFacade, PresentationSlidesFacade, PresentationTextFacade, PresentationZoomFacade, SheetChartsFacade, SheetSelectionsFacade, SheetWorkbookFacade, SheetWorksheetFacade, TitleFacade, VersionFacade } from './OfficeSDK.facade.types';
|
|
13
13
|
import type { HeaderBarsFacade } from './OfficeSDK.headerBars';
|
|
14
14
|
export * from './OfficeSDK.facade.types';
|
|
15
15
|
export * from './OfficeSDK.headerBars';
|
|
@@ -36,6 +36,8 @@ export declare class OfficeSDK extends TinyEmitter {
|
|
|
36
36
|
* @deprecated - 用 `sdk.getEditor<T>()` 替代
|
|
37
37
|
*/
|
|
38
38
|
spreadsheet?: Spreadsheet.Editor;
|
|
39
|
+
/** 当前轻文档的标准化、强类型文档入口。 */
|
|
40
|
+
ActiveDocument?: DocsActiveDocumentFacade;
|
|
39
41
|
/**
|
|
40
42
|
* 当前套件支持的标题能力。
|
|
41
43
|
*/
|
|
@@ -78,8 +80,9 @@ export declare class OfficeSDK extends TinyEmitter {
|
|
|
78
80
|
version?: VersionFacade;
|
|
79
81
|
/**
|
|
80
82
|
* 当前套件支持的演示能力。
|
|
83
|
+
* 文档与表格支持 start / quit,幻灯片套件额外支持完整演示能力。
|
|
81
84
|
*/
|
|
82
|
-
presentation?:
|
|
85
|
+
presentation?: OfficeSDKPresentationFacade;
|
|
83
86
|
/**
|
|
84
87
|
* 当前套件支持的选区能力。
|
|
85
88
|
*/
|
|
@@ -309,6 +312,7 @@ export declare class OfficeSDK extends TinyEmitter {
|
|
|
309
312
|
* 输出:无。
|
|
310
313
|
*/
|
|
311
314
|
private unregisterEditorFacadeCallback;
|
|
315
|
+
private reportEditorFacadeError;
|
|
312
316
|
/**
|
|
313
317
|
* 创建基于 method-path 的模块 facade。
|
|
314
318
|
* 输入:模块前缀与少量自定义实现覆盖。
|
|
@@ -465,7 +469,7 @@ export interface SDKToastOptions {
|
|
|
465
469
|
}
|
|
466
470
|
/**
|
|
467
471
|
* 透传给 iframe 编辑器的主题配置。
|
|
468
|
-
* 当前
|
|
472
|
+
* 当前 weboffice-js-sdk 仅负责跨 iframe 传输,不在宿主侧约束字段细节。
|
|
469
473
|
*/
|
|
470
474
|
export interface CommonThemeConfig {
|
|
471
475
|
[key: string]: unknown;
|
|
@@ -596,7 +600,7 @@ export interface OfficeSDKOptions extends Omit<ContainerMethods, 'getContainerRe
|
|
|
596
600
|
headerBarsVisible?: boolean;
|
|
597
601
|
/**
|
|
598
602
|
* 是否隐藏 iframe 内 AI 入口。
|
|
599
|
-
* 对应 iframe 内
|
|
603
|
+
* 对应 iframe 内 OfficeSDK 的现有 AI 入口开关能力。
|
|
600
604
|
*/
|
|
601
605
|
disableAiEntry?: boolean;
|
|
602
606
|
/**
|
|
@@ -10,6 +10,7 @@ interface FacadeHost {
|
|
|
10
10
|
registerEditorFacadeListener<T>(method: string, listener: (payload: T) => void): () => void;
|
|
11
11
|
registerEditorFacadeCallback(callback: EditorFacadeCallback): string;
|
|
12
12
|
unregisterEditorFacadeCallback(callbackId: string): void;
|
|
13
|
+
reportEditorFacadeError(message: string, error: unknown): void;
|
|
13
14
|
}
|
|
14
15
|
export declare function buildRootFacadeState(host: FacadeHost): OfficeSDKRootFacadeState;
|
|
15
16
|
export {};
|
|
@@ -3,6 +3,95 @@ export interface TitleFacade {
|
|
|
3
3
|
addChangedListener: (listener: (title: string) => void) => () => void;
|
|
4
4
|
setTitle: (title: string) => Promise<void>;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* 可安全跨 iframe 传输的文档 Delta 快照。
|
|
8
|
+
*
|
|
9
|
+
* 这里只公开序列化结果和基础元数据,不承诺编辑器运行时对象上的
|
|
10
|
+
* compose / transform 等方法。
|
|
11
|
+
*/
|
|
12
|
+
export interface DocsEditorDeltaSnapshot {
|
|
13
|
+
length: number;
|
|
14
|
+
serialized: string;
|
|
15
|
+
stringify: () => string;
|
|
16
|
+
}
|
|
17
|
+
export interface DocsDocumentPermission {
|
|
18
|
+
read: boolean;
|
|
19
|
+
write: boolean;
|
|
20
|
+
comment: boolean;
|
|
21
|
+
}
|
|
22
|
+
export type DocsDownloadDocumentType = 'pdf' | 'word' | 'image' | 'md';
|
|
23
|
+
export interface DocsProductFontFacade {
|
|
24
|
+
SetTextColor: (color: string) => Promise<boolean>;
|
|
25
|
+
SetHighLightColor: (color: string) => Promise<boolean>;
|
|
26
|
+
SetBold: (value?: boolean) => Promise<boolean>;
|
|
27
|
+
SetItalic: (value?: boolean) => Promise<boolean>;
|
|
28
|
+
SetUnderline: (value?: boolean) => Promise<boolean>;
|
|
29
|
+
SetStrike: (value?: boolean) => Promise<boolean>;
|
|
30
|
+
}
|
|
31
|
+
export interface DocsProductMarkdownFacade {
|
|
32
|
+
GetMarkdown: () => Promise<string>;
|
|
33
|
+
AppendMarkdown: (value: string) => Promise<DocsRangeValue>;
|
|
34
|
+
InsertMarkdown: (value: string) => Promise<DocsRangeValue>;
|
|
35
|
+
ValidateMarkdown: (value: string) => Promise<boolean>;
|
|
36
|
+
}
|
|
37
|
+
export interface DocsProductContentFacade {
|
|
38
|
+
ReplaceSelection: (value: string) => Promise<boolean>;
|
|
39
|
+
ReplaceAllContent: (value: string) => Promise<boolean>;
|
|
40
|
+
}
|
|
41
|
+
export interface DocsProductDocumentFacade {
|
|
42
|
+
GetContent: () => Promise<DocsEditorDeltaSnapshot>;
|
|
43
|
+
GetTitleContent: () => Promise<string>;
|
|
44
|
+
SetTitleContent: (title: string) => Promise<void>;
|
|
45
|
+
Font: DocsProductFontFacade;
|
|
46
|
+
Markdown: DocsProductMarkdownFacade;
|
|
47
|
+
Content: DocsProductContentFacade;
|
|
48
|
+
}
|
|
49
|
+
export interface DocsProductEditorFacade {
|
|
50
|
+
GetEditMode: () => Promise<string>;
|
|
51
|
+
Document: DocsProductDocumentFacade;
|
|
52
|
+
}
|
|
53
|
+
export interface DocsActiveDocumentFacade {
|
|
54
|
+
Editor: DocsProductEditorFacade;
|
|
55
|
+
Reference: DocsProductReferenceFacade;
|
|
56
|
+
Service: DocsProductServiceFacade;
|
|
57
|
+
Sub: DocsProductSubFacade;
|
|
58
|
+
Env: DocsProductEnvFacade;
|
|
59
|
+
}
|
|
60
|
+
/** 轻文档产品引用能力。 */
|
|
61
|
+
export interface DocsProductReferenceFacade {
|
|
62
|
+
CanIUse: (scopes: string | string[]) => Promise<boolean>;
|
|
63
|
+
}
|
|
64
|
+
export interface DocsProductUserFacade {
|
|
65
|
+
GetUserInfo: () => Promise<unknown>;
|
|
66
|
+
}
|
|
67
|
+
export interface DocsProductPermissionFacade {
|
|
68
|
+
GetDocumentPermission: () => Promise<DocsDocumentPermission>;
|
|
69
|
+
}
|
|
70
|
+
export interface DocsProductExportFacade {
|
|
71
|
+
DownloadDocument: (format: DocsDownloadDocumentType) => Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
export interface DocsProductCollaborationFacade {
|
|
74
|
+
GetSaveStatus: () => Promise<unknown>;
|
|
75
|
+
}
|
|
76
|
+
export interface DocsProductServiceFacade {
|
|
77
|
+
User: DocsProductUserFacade;
|
|
78
|
+
Permission: DocsProductPermissionFacade;
|
|
79
|
+
Export: DocsProductExportFacade;
|
|
80
|
+
Collaboration: DocsProductCollaborationFacade;
|
|
81
|
+
}
|
|
82
|
+
export interface DocsProductSubFacade {
|
|
83
|
+
OnDocumentChange: (handler: (delta: DocsEditorDeltaSnapshot) => void) => () => void;
|
|
84
|
+
}
|
|
85
|
+
export interface DocsProductLanguageFacade {
|
|
86
|
+
GetLanguage: () => Promise<string>;
|
|
87
|
+
}
|
|
88
|
+
export interface DocsProductModeFacade {
|
|
89
|
+
GetDocsMode: () => Promise<string>;
|
|
90
|
+
}
|
|
91
|
+
export interface DocsProductEnvFacade {
|
|
92
|
+
Language: DocsProductLanguageFacade;
|
|
93
|
+
DocsMode: DocsProductModeFacade;
|
|
94
|
+
}
|
|
6
95
|
export interface CommentsFacade {
|
|
7
96
|
show: (type?: 'list' | 'card') => Promise<void>;
|
|
8
97
|
hide: (type?: 'list' | 'card') => Promise<void>;
|
|
@@ -162,7 +251,9 @@ export interface ClipboardPasteParams {
|
|
|
162
251
|
}
|
|
163
252
|
export type SheetAppendDataAxis = 'row' | 'column';
|
|
164
253
|
export interface SheetSelection {
|
|
165
|
-
|
|
254
|
+
/** 当前 iframe runtime 内稳定的选区标识。 */
|
|
255
|
+
id: string;
|
|
256
|
+
getRange: (value?: SheetRangeValue) => Promise<SheetRangeFacade | null>;
|
|
166
257
|
setRange: (value: SheetRangeValue | null) => Promise<void>;
|
|
167
258
|
}
|
|
168
259
|
export declare enum SheetRangeType {
|
|
@@ -429,24 +520,24 @@ export interface PresentationShapeBase {
|
|
|
429
520
|
id: string;
|
|
430
521
|
name: string;
|
|
431
522
|
type: PresentationShapeType;
|
|
432
|
-
setFill: (fill: PresentationShapeFill) => void
|
|
433
|
-
setLine: (line: PresentationShapeLine) => void
|
|
434
|
-
setLayout: (layout: PresentationShapeLayout) => void
|
|
435
|
-
remove: () => void
|
|
523
|
+
setFill: (fill: PresentationShapeFill) => Promise<void>;
|
|
524
|
+
setLine: (line: PresentationShapeLine) => Promise<void>;
|
|
525
|
+
setLayout: (layout: PresentationShapeLayout) => Promise<void>;
|
|
526
|
+
remove: () => Promise<void>;
|
|
436
527
|
}
|
|
437
528
|
export type PresentationTextShapeType = Exclude<PresentationShapeType, PresentationLineShapeType>;
|
|
438
529
|
export interface PresentationTextShape extends PresentationShapeBase {
|
|
439
530
|
type: PresentationTextShapeType;
|
|
440
531
|
textContent?: string;
|
|
441
|
-
setContent: (content: PresentationShapeContent) => void
|
|
442
|
-
appendText: (text: string) => void
|
|
443
|
-
appendParagraphs: (paragraphs: PresentationParagraph[]) => void
|
|
532
|
+
setContent: (content: PresentationShapeContent) => Promise<void>;
|
|
533
|
+
appendText: (text: string) => Promise<void>;
|
|
534
|
+
appendParagraphs: (paragraphs: PresentationParagraph[]) => Promise<void>;
|
|
444
535
|
}
|
|
445
536
|
export type PresentationShape = PresentationShapeBase | PresentationTextShape;
|
|
446
537
|
export type PresentationParagraphLineSpacing = 0.9 | 1.0 | 1.15 | 1.5 | 2.0 | 2.5 | 3.0;
|
|
447
538
|
export interface PresentationTableCell {
|
|
448
|
-
setStyle: (style: PresentationTableCellStyle) => void
|
|
449
|
-
clearStyle: () => void
|
|
539
|
+
setStyle: (style: PresentationTableCellStyle) => Promise<void>;
|
|
540
|
+
clearStyle: () => Promise<void>;
|
|
450
541
|
}
|
|
451
542
|
export type PresentationTableCellStyle = PresentationTextStyle & PresentationParagraphStyle;
|
|
452
543
|
export interface PresentationTableSelection {
|
|
@@ -456,25 +547,25 @@ export interface PresentationTableSelection {
|
|
|
456
547
|
columnCount: number;
|
|
457
548
|
}
|
|
458
549
|
export interface PresentationTableRange {
|
|
459
|
-
setStyle: (style: PresentationTableCellStyle) => void
|
|
460
|
-
clearStyle: () => void
|
|
461
|
-
setSpan: () => void
|
|
462
|
-
removeSpan: () => void
|
|
550
|
+
setStyle: (style: PresentationTableCellStyle) => Promise<void>;
|
|
551
|
+
clearStyle: () => Promise<void>;
|
|
552
|
+
setSpan: () => Promise<void>;
|
|
553
|
+
removeSpan: () => Promise<void>;
|
|
463
554
|
}
|
|
464
555
|
export interface PresentationTableItem {
|
|
465
556
|
id: string;
|
|
466
557
|
rowCount: number;
|
|
467
558
|
columnCount: number;
|
|
468
|
-
remove: () => void
|
|
469
|
-
insertRows: (index: number, count: number, placement?: 'before' | 'after') => void
|
|
470
|
-
insertColumns: (index: number, count: number, placement?: 'before' | 'after') => void
|
|
471
|
-
deleteRows: (index: number, count: number) => void
|
|
472
|
-
deleteColumns: (index: number, count: number) => void
|
|
473
|
-
setRowHeight: (index: number, height: number) => void
|
|
474
|
-
setColumnWidth: (index: number, width: number) => void
|
|
475
|
-
getCell: (row: number, column: number) => PresentationTableCell | null
|
|
476
|
-
getRange: (range: PresentationTableSelection) => PresentationTableRange | null
|
|
477
|
-
setDirection: (direction: 'ltr' | 'rtl') => void
|
|
559
|
+
remove: () => Promise<void>;
|
|
560
|
+
insertRows: (index: number, count: number, placement?: 'before' | 'after') => Promise<void>;
|
|
561
|
+
insertColumns: (index: number, count: number, placement?: 'before' | 'after') => Promise<void>;
|
|
562
|
+
deleteRows: (index: number, count: number) => Promise<void>;
|
|
563
|
+
deleteColumns: (index: number, count: number) => Promise<void>;
|
|
564
|
+
setRowHeight: (index: number, height: number) => Promise<void>;
|
|
565
|
+
setColumnWidth: (index: number, width: number) => Promise<void>;
|
|
566
|
+
getCell: (row: number, column: number) => Promise<PresentationTableCell | null>;
|
|
567
|
+
getRange: (range: PresentationTableSelection) => Promise<PresentationTableRange | null>;
|
|
568
|
+
setDirection: (direction: 'ltr' | 'rtl') => Promise<void>;
|
|
478
569
|
}
|
|
479
570
|
export interface PresentationTableOptions {
|
|
480
571
|
offset: PresentationOffset;
|
|
@@ -512,14 +603,18 @@ export interface VersionFacade {
|
|
|
512
603
|
hide?: () => Promise<void>;
|
|
513
604
|
createRevision: (options?: RevisionCreateOptions) => Promise<undefined | null | DocumentErrorMessage>;
|
|
514
605
|
}
|
|
515
|
-
export interface
|
|
516
|
-
start: (
|
|
606
|
+
export interface BasicPresentationFacade {
|
|
607
|
+
start: () => Promise<void>;
|
|
517
608
|
quit: () => Promise<void>;
|
|
609
|
+
}
|
|
610
|
+
export interface PresentationFacade extends BasicPresentationFacade {
|
|
611
|
+
start: (index?: number) => Promise<void>;
|
|
518
612
|
startFromCurrent: () => Promise<void>;
|
|
519
613
|
startRemoteLive: () => Promise<void>;
|
|
520
614
|
startSpeakerView: () => Promise<void>;
|
|
521
615
|
addChangeListener: (listener: (payload: unknown) => void) => () => void;
|
|
522
616
|
}
|
|
617
|
+
export type OfficeSDKPresentationFacade = BasicPresentationFacade | PresentationFacade;
|
|
523
618
|
export interface DocsRangeFacade {
|
|
524
619
|
start: number;
|
|
525
620
|
end: number;
|
|
@@ -623,6 +718,12 @@ export interface SheetRangeFacade {
|
|
|
623
718
|
column: number;
|
|
624
719
|
rowCount: number;
|
|
625
720
|
columnCount: number;
|
|
721
|
+
getBounding: () => Promise<{
|
|
722
|
+
left: number;
|
|
723
|
+
top: number;
|
|
724
|
+
width: number;
|
|
725
|
+
height: number;
|
|
726
|
+
} | null>;
|
|
626
727
|
getText: (format?: 'plain' | 'matrix') => Promise<string | string[][]>;
|
|
627
728
|
setText: (text: SheetRangeText) => Promise<void>;
|
|
628
729
|
getHtml: () => Promise<string>;
|
|
@@ -671,6 +772,7 @@ export interface SheetWorksheetFacade {
|
|
|
671
772
|
sheet: string;
|
|
672
773
|
ranges: SheetRangeValue[] | null;
|
|
673
774
|
}) => void) => () => void;
|
|
775
|
+
/** @deprecated 先 await worksheet.getRange(range),再调用 range?.getBounding()。 */
|
|
674
776
|
getBounding: (range: SheetRangeValue) => Promise<{
|
|
675
777
|
left: number;
|
|
676
778
|
top: number;
|
|
@@ -817,6 +919,7 @@ export interface PresentationEventSubscriptionFacade {
|
|
|
817
919
|
addLoadedListener: (listener: () => void) => () => void;
|
|
818
920
|
}
|
|
819
921
|
export interface OfficeSDKRootFacadeState {
|
|
922
|
+
ActiveDocument?: DocsActiveDocumentFacade;
|
|
820
923
|
title?: TitleFacade;
|
|
821
924
|
history?: HistoryFacade;
|
|
822
925
|
comments?: CommentsFacade;
|
|
@@ -827,7 +930,7 @@ export interface OfficeSDKRootFacadeState {
|
|
|
827
930
|
mention?: MentionFacade;
|
|
828
931
|
content?: ContentFacade;
|
|
829
932
|
version?: VersionFacade;
|
|
830
|
-
presentation?:
|
|
933
|
+
presentation?: OfficeSDKPresentationFacade;
|
|
831
934
|
selection?: DocsSelectionFacade | PresentationSelectionFacade;
|
|
832
935
|
search?: DocsSearchFacade;
|
|
833
936
|
outline?: DocsOutlineFacade;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { AddChartFromSelectionResult, DocsRangeFacade, DocsRangeValue, DocsTableFacade, EditorTextFormat, OfficeSDK, PresentationSlideFacade, PresentationShape, PresentationShapeBase, PresentationTextShape, PresentationTextRangeFacade, PresentationTextRangeValue, SheetRangeValue, SheetRangeFacade, SheetSelection } from './OfficeSDK';
|
|
1
|
+
import type { AddChartFromSelectionResult, BasicPresentationFacade, DocsActiveDocumentFacade, DocsEditorDeltaSnapshot, DocsRangeFacade, DocsRangeValue, DocsTableFacade, EditorTextFormat, OfficeSDK, PresentationFacade, PresentationSlideFacade, PresentationShape, PresentationShapeBase, PresentationTableCell, PresentationTableItem, PresentationTableRange, PresentationTableSelection, PresentationTextShape, PresentationTextRangeFacade, PresentationTextRangeValue, SheetRangeValue, SheetRangeFacade, SheetSelection } from './OfficeSDK';
|
|
2
2
|
type IsAssignable<T, U> = T extends U ? true : false;
|
|
3
|
+
type IsEqual<T, U> = (<V>() => V extends T ? 1 : 2) extends <V>() => V extends U ? 1 : 2 ? (<V>() => V extends U ? 1 : 2) extends <V>() => V extends T ? 1 : 2 ? true : false : false;
|
|
3
4
|
type Assert<T extends true> = T;
|
|
4
5
|
type RootSelection = NonNullable<OfficeSDK['selection']>;
|
|
5
6
|
type DocsSelection = Extract<RootSelection, {
|
|
@@ -8,16 +9,28 @@ type DocsSelection = Extract<RootSelection, {
|
|
|
8
9
|
type PresentationSelection = Extract<RootSelection, {
|
|
9
10
|
getTextRange: (value?: PresentationTextRangeValue) => Promise<PresentationTextRangeFacade | null>;
|
|
10
11
|
}>;
|
|
12
|
+
type RootPresentation = NonNullable<OfficeSDK['presentation']>;
|
|
11
13
|
export type EditorFacadeContractAssertions = [
|
|
14
|
+
Assert<IsEqual<NonNullable<OfficeSDK['ActiveDocument']>, DocsActiveDocumentFacade>>,
|
|
15
|
+
Assert<IsEqual<DocsActiveDocumentFacade['Editor']['Document']['GetContent'], () => Promise<DocsEditorDeltaSnapshot>>>,
|
|
16
|
+
Assert<IsEqual<DocsActiveDocumentFacade['Editor']['Document']['Markdown']['AppendMarkdown'], (value: string) => Promise<DocsRangeValue>>>,
|
|
17
|
+
Assert<IsEqual<DocsActiveDocumentFacade['Service']['Permission']['GetDocumentPermission'], () => Promise<import('./OfficeSDK').DocsDocumentPermission>>>,
|
|
18
|
+
Assert<IsEqual<DocsActiveDocumentFacade['Service']['Export']['DownloadDocument'], (format: import('./OfficeSDK').DocsDownloadDocumentType) => Promise<void>>>,
|
|
19
|
+
Assert<IsEqual<DocsActiveDocumentFacade['Sub']['OnDocumentChange'], (handler: (delta: DocsEditorDeltaSnapshot) => void) => () => void>>,
|
|
12
20
|
Assert<IsAssignable<NonNullable<OfficeSDK['title']>['setTitle'], (title: string) => Promise<void>>>,
|
|
13
21
|
Assert<IsAssignable<NonNullable<OfficeSDK['title']>['addChangedListener'], (listener: (title: string) => void) => () => void>>,
|
|
14
22
|
Assert<IsAssignable<NonNullable<OfficeSDK['locks']>['addRangeLock'], (options: import('./OfficeSDK').AddRangeLockParams) => Promise<void>>>,
|
|
15
23
|
Assert<IsAssignable<NonNullable<OfficeSDK['history']>['show'], () => Promise<void>>>,
|
|
16
24
|
Assert<IsAssignable<NonNullable<OfficeSDK['mention']>['locateCellByGuid'], (guid: string, notificationType?: import('./OfficeSDK').MentionTypes) => Promise<void>>>,
|
|
17
25
|
Assert<IsAssignable<NonNullable<OfficeSDK['version']>['createRevision'], (options?: import('./OfficeSDK').RevisionCreateOptions) => Promise<undefined | null | import('./types/Document').DocumentErrorMessage>>>,
|
|
18
|
-
Assert<IsAssignable<
|
|
19
|
-
Assert<IsAssignable<
|
|
20
|
-
Assert<IsAssignable<
|
|
26
|
+
Assert<IsAssignable<RootPresentation, BasicPresentationFacade>>,
|
|
27
|
+
Assert<IsAssignable<RootPresentation['start'], () => Promise<void>>>,
|
|
28
|
+
Assert<IsAssignable<RootPresentation['quit'], () => Promise<void>>>,
|
|
29
|
+
Assert<IsAssignable<PresentationFacade['start'], (index?: number) => Promise<void>>>,
|
|
30
|
+
Assert<IsAssignable<PresentationFacade['startFromCurrent'], () => Promise<void>>>,
|
|
31
|
+
Assert<IsAssignable<PresentationFacade['startRemoteLive'], () => Promise<void>>>,
|
|
32
|
+
Assert<IsAssignable<PresentationFacade['startSpeakerView'], () => Promise<void>>>,
|
|
33
|
+
Assert<IsAssignable<PresentationFacade['addChangeListener'], (listener: (payload: unknown) => void) => () => void>>,
|
|
21
34
|
Assert<IsAssignable<NonNullable<OfficeSDK['batchChanges']>, <T>(callback: () => T | Promise<T>) => Promise<Awaited<T>>>>,
|
|
22
35
|
Assert<IsAssignable<NonNullable<OfficeSDK['print']>, () => Promise<void>>>,
|
|
23
36
|
Assert<IsAssignable<NonNullable<OfficeSDK['export']>, (type: string) => Promise<void>>>,
|
|
@@ -38,10 +51,25 @@ export type EditorFacadeContractAssertions = [
|
|
|
38
51
|
Assert<IsAssignable<NonNullable<OfficeSDK['text']>['apply'], (format: Partial<EditorTextFormat>, range?: PresentationTextRangeValue) => Promise<Partial<EditorTextFormat>>>>,
|
|
39
52
|
Assert<IsAssignable<NonNullable<OfficeSDK['activeSheet']>['getSelections'], () => Promise<SheetSelection[] | null>>>,
|
|
40
53
|
Assert<IsAssignable<NonNullable<OfficeSDK['activeSheet']>['getRange'], (value: SheetRangeValue) => Promise<SheetRangeFacade | null>>>,
|
|
54
|
+
Assert<IsEqual<SheetRangeFacade['getBounding'], () => Promise<{
|
|
55
|
+
left: number;
|
|
56
|
+
top: number;
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
} | null>>>,
|
|
41
60
|
Assert<IsAssignable<NonNullable<OfficeSDK['selections']>['getAll'], () => Promise<SheetRangeValue[]>>>,
|
|
42
61
|
Assert<IsAssignable<NonNullable<OfficeSDK['charts']>['addChartFromSelection'], (params?: import('./OfficeSDK').AddChartFromSelectionParams) => Promise<AddChartFromSelectionResult | undefined>>>,
|
|
43
62
|
Assert<IsAssignable<PresentationSelection['getSelectedShapes'], (ids?: string[]) => Promise<PresentationShape[] | null>>>,
|
|
44
63
|
Assert<IsAssignable<NonNullable<OfficeSDK['zoom']>['setPercentage'], (percentage: number) => Promise<void>>>,
|
|
45
|
-
Assert<IsAssignable<NonNullable<OfficeSDK['eventSubscription']>['addLoadedListener'], (listener: () => void) => () => void
|
|
64
|
+
Assert<IsAssignable<NonNullable<OfficeSDK['eventSubscription']>['addLoadedListener'], (listener: () => void) => () => void>>,
|
|
65
|
+
Assert<IsEqual<SheetSelection['getRange'], (value?: SheetRangeValue) => Promise<SheetRangeFacade | null>>>,
|
|
66
|
+
Assert<IsEqual<SheetSelection['id'], string>>,
|
|
67
|
+
Assert<IsEqual<PresentationShapeBase['setFill'], (fill: import('./OfficeSDK').PresentationShapeFill) => Promise<void>>>,
|
|
68
|
+
Assert<IsEqual<PresentationShapeBase['remove'], () => Promise<void>>>,
|
|
69
|
+
Assert<IsEqual<PresentationTableItem['getCell'], (row: number, column: number) => Promise<PresentationTableCell | null>>>,
|
|
70
|
+
Assert<IsEqual<PresentationTableItem['getRange'], (range: PresentationTableSelection) => Promise<PresentationTableRange | null>>>,
|
|
71
|
+
Assert<IsEqual<PresentationTableItem['insertRows'], (index: number, count: number, placement?: 'before' | 'after') => Promise<void>>>,
|
|
72
|
+
Assert<IsEqual<PresentationTableCell['clearStyle'], () => Promise<void>>>,
|
|
73
|
+
Assert<IsEqual<PresentationTableRange['setSpan'], () => Promise<void>>>
|
|
46
74
|
];
|
|
47
75
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import * as Flowchart from './types/FlowChart';
|
|
|
8
8
|
import { EventMap as BaseEventMap, BaseEditor } from './types/BaseEditor';
|
|
9
9
|
export * from 'weboffice-js-sdk-shared';
|
|
10
10
|
export * from './connect';
|
|
11
|
+
export type { JSAPIAdapter, JSAPIContract, JSAPIContractCatalog, JSAPITransport } from './jsapi';
|
|
11
12
|
export * from './OfficeSDK';
|
|
12
13
|
export type { EmptyPageScene, EmptyPageOptions, EmptyPageActionOverride, EmptyPageContentOverride, NormalizedEmptyPageOptions, EmptyPageShownPayload, EmptyPageActionPayload, EmptyPageHiddenPayload, FileOpenFailedReason, TokenExpiredStrategy } from './types/EmptyPage';
|
|
13
14
|
export type { SlashMenuButton, SlashMenuEntry, SlashMenuOptions } from './types/SlashMenu';
|