weboffice-js-sdk 2.0.5-beta.1 → 2.0.5-beta.11
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 +92 -66
- package/dist/OfficeSDK.d.ts +12 -12
- package/dist/OfficeSDK.facade.types.d.ts +40 -27
- package/dist/connect.d.ts +19 -0
- package/dist/editorFacade.contract.d.ts +26 -6
- package/dist/index.js +2 -2
- package/dist/types/ConnectV2.d.ts +17 -0
- package/dist/types/EmptyPage.d.ts +2 -2
- package/package.json +3 -3
- package/dist/OfficeSDK.branding.d.ts +0 -28
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,52 @@ connect({
|
|
|
44
44
|
|
|
45
45
|
其中:
|
|
46
46
|
|
|
47
|
-
- `disableAiEntry` 为可选布尔值,透传到 iframe 内 `
|
|
47
|
+
- `disableAiEntry` 为可选布尔值,透传到 iframe 内 `OfficeSDK` 的 AI 入口开关能力。
|
|
48
48
|
- `theme` 为可选主题对象,宿主侧仅负责透传;未传时 iframe 内仍使用默认主题配置。
|
|
49
49
|
|
|
50
|
+
### V2 统一编辑 / 预览入口
|
|
51
|
+
|
|
52
|
+
V2 使用独立的 `connectV2()`,旧 `connect()` 保持兼容。V2 要求 `type` 和 `mode` 必填:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { connectV2 } from 'weboffice-js-sdk'
|
|
56
|
+
|
|
57
|
+
const sdk = await connectV2({
|
|
58
|
+
fileId: 'your-file-id',
|
|
59
|
+
endpoint: 'https://your-shimo-endpoint',
|
|
60
|
+
signature: 'your-signature',
|
|
61
|
+
token: 'your-token',
|
|
62
|
+
container: document.querySelector('#shimo-file'),
|
|
63
|
+
type: 'writer',
|
|
64
|
+
mode: 'edit',
|
|
65
|
+
refreshCredentialsInterval: 600000
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
支持的 `type` 包括 `file`、`document`、`documentPro`、`writer`、`spreadsheet`、`presentation`、`table` 和 `form`。`writer` 与 `documentPro` 当前共存,`writer` 目前处于内测阶段。当前 `type` 主要作为 iframe 后续基于 `manifest.json` 选择资源的预留字段,不改变后端编辑准备判断。
|
|
70
|
+
|
|
50
71
|
返回值:
|
|
51
72
|
|
|
52
73
|
```
|
|
53
|
-
Promise<
|
|
74
|
+
Promise<OfficeSDK>
|
|
54
75
|
```
|
|
55
76
|
|
|
56
77
|
**使用传统的 `<script>` 的方式加载:**
|
|
57
78
|
|
|
58
79
|
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
80
|
2. 将 `.tgz` 解压缩后的 `dist` 目录下的文件放置到您托管静态资源的空间,然后使用 `<script>` 引入 `index.js` 资源
|
|
60
|
-
3. 通过 `window.
|
|
81
|
+
3. 通过 `window.WebOfficeJSSDK` 对象获取对应的方法
|
|
61
82
|
|
|
62
83
|
```js
|
|
63
|
-
const { connect, FileType } = window.
|
|
84
|
+
const { connect, FileType } = window.WebOfficeJSSDK
|
|
64
85
|
// 等价于
|
|
65
|
-
const { connect, FileType } = require('
|
|
86
|
+
const { connect, FileType } = require('weboffice-js-sdk')
|
|
66
87
|
```
|
|
67
88
|
|
|
68
89
|
#### 使用示例
|
|
69
90
|
|
|
70
91
|
```js
|
|
71
|
-
const { connect } = require('
|
|
92
|
+
const { connect } = require('weboffice-js-sdk')
|
|
72
93
|
|
|
73
94
|
const fileId = '1234'
|
|
74
95
|
const uuid = 'youruuid'
|
|
@@ -84,19 +105,19 @@ connect({
|
|
|
84
105
|
container: document.querySelector('#shimo-file'), // iframe 挂载的目标容器元素
|
|
85
106
|
userUuid: uuid
|
|
86
107
|
}).then((sdk) => {
|
|
87
|
-
// sdk 即为
|
|
108
|
+
// sdk 即为 OfficeSDK 实例
|
|
88
109
|
})
|
|
89
110
|
```
|
|
90
111
|
|
|
91
112
|
调用 `connect()` 时,会以传入参数为基础,初始化一个 `<iframe>` 并插入 `container` 对应的元素中。
|
|
92
113
|
|
|
93
|
-
返回的 `sdk` 为 `
|
|
114
|
+
返回的 `sdk` 为 `OfficeSDK` 实例,用于和 SDK、编辑器交互。
|
|
94
115
|
|
|
95
116
|
### SDK 和编辑器实例
|
|
96
117
|
|
|
97
118
|
石墨 JS SDK 共有两种实例用于和 JS SDK 交互:
|
|
98
119
|
|
|
99
|
-
- `
|
|
120
|
+
- `OfficeSDK` 由 `connect()` 返回,处理初始化编辑器和编辑器交互的工作
|
|
100
121
|
- `Editor` 文档编辑器,直接和文档内容交互。**`Editor` 所有接口均返回 Promise**
|
|
101
122
|
|
|
102
123
|
两者之间各有独立的方法和事件,具体请查看 `docs` 目录的文档。
|
|
@@ -104,7 +125,7 @@ connect({
|
|
|
104
125
|
获取编辑器实例和与其交互:
|
|
105
126
|
|
|
106
127
|
```js
|
|
107
|
-
const { FileType } = require('
|
|
128
|
+
const { FileType } = require('weboffice-js-sdk')
|
|
108
129
|
|
|
109
130
|
// 获取编辑器实例
|
|
110
131
|
const editor = sdk.getEditor()
|
|
@@ -123,7 +144,7 @@ if (sdk.fileType === FileType.Document) {
|
|
|
123
144
|
若为 `TypeScript`,可使用 `Generic`:
|
|
124
145
|
|
|
125
146
|
```typescript
|
|
126
|
-
const { Document } = require('
|
|
147
|
+
const { Document } = require('weboffice-js-sdk')
|
|
127
148
|
|
|
128
149
|
const editor = sdk.getEditor<Document.Editor>()
|
|
129
150
|
editor.on('saveStatusChanged', (payload) => {
|
|
@@ -193,7 +214,7 @@ const sdk = await connect({
|
|
|
193
214
|
|
|
194
215
|
### 协作者模块使用说明
|
|
195
216
|
|
|
196
|
-
当 iframe 套件开启协作者能力后(依赖 `ENABLE_SDK_COLLABORATORS_MODULE` 开关),
|
|
217
|
+
当 iframe 套件开启协作者能力后(依赖 `ENABLE_SDK_COLLABORATORS_MODULE` 开关),weboffice-js-sdk 使用方可按以下方式接入:
|
|
197
218
|
|
|
198
219
|
1. **监听 `collaboratorsChanged`**
|
|
199
220
|
|
|
@@ -237,56 +258,61 @@ editor.on('editForbiddenConfirmed', ({ reason }) => {
|
|
|
237
258
|
})
|
|
238
259
|
```
|
|
239
260
|
|
|
240
|
-
###
|
|
261
|
+
### 凭证自动刷新(建议)
|
|
241
262
|
|
|
242
263
|
- `signature` 为石墨区分请求来源,并实现数据隔离的基础
|
|
243
264
|
- `token` 为您用于识别回调请求来源、是否合法的依据
|
|
244
265
|
|
|
245
|
-
|
|
266
|
+
由于 `signature` 和 `token` 有过期时间,建议在 `ConnectOptions` 中配置自动刷新,避免用户长时间编辑时因凭证失效而中断。
|
|
246
267
|
|
|
247
|
-
|
|
268
|
+
```typescript
|
|
269
|
+
const { expireMs } = (await appService.getExpireConfig()).data
|
|
248
270
|
|
|
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
|
-
})
|
|
271
|
+
const options: ConnectOptions = {
|
|
272
|
+
...config,
|
|
273
|
+
// 在过期时长的 80% 处刷新,给网络重试等情况预留时间
|
|
274
|
+
refreshCredentialsInterval: Math.ceil(expireMs * 0.8),
|
|
275
|
+
getCredentials: async () => (await appService.getCredentials()).data
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const officeSDK = await connect(options)
|
|
288
279
|
```
|
|
289
280
|
|
|
281
|
+
示例配套接口:
|
|
282
|
+
|
|
283
|
+
- `GET /api/apps/expire-config`:返回凭证过期时长,例如 `{ expireMs: 900000 }`
|
|
284
|
+
- `GET /api/credentials`:返回新凭证,例如 `{ signature, token }`
|
|
285
|
+
|
|
286
|
+
`getCredentials` 应从接入方后端获取最新凭证,并返回同时包含 `signature` 和 `token` 的对象。接口路径可按接入方系统实际情况调整。
|
|
287
|
+
|
|
288
|
+
### 国际化:编辑器多语言(可选,co-1.8+)
|
|
289
|
+
|
|
290
|
+
接入方可在调用 `connect` 时通过 `lang` 指定编辑器界面语言,传入对应语言码即可;用户选择“系统默认”时省略 `lang`(或传 `undefined`;纯 JavaScript 也可传 `null`)。
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
const options: ConnectOptions = {
|
|
294
|
+
...config,
|
|
295
|
+
...(editorLang ? { lang: editorLang } : {}) // “系统默认”时不传 lang
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const officeSDK = await connect(options)
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
1.8 版本编辑器支持以下 16 种语言:
|
|
302
|
+
|
|
303
|
+
| 语言 | `lang` 语言码 | 语言 | `lang` 语言码 |
|
|
304
|
+
| ------------- | ------------- | ---------------- | ------------- |
|
|
305
|
+
| 简体中文 | `zh-CN` | 繁體中文 | `zh-TW` |
|
|
306
|
+
| English | `en-US` | 日本語 | `ja-JP` |
|
|
307
|
+
| 한국어 | `ko-KR` | Español | `es-ES` |
|
|
308
|
+
| Português | `pt-PT` | Deutsch | `de-DE` |
|
|
309
|
+
| Français | `fr-FR` | Italiano | `it-IT` |
|
|
310
|
+
| Русский | `ru-RU` | Bahasa Indonesia | `id-ID` |
|
|
311
|
+
| Tiếng Việt | `vi-VN` | ไทย | `th-TH` |
|
|
312
|
+
| Bahasa Melayu | `ms-MY` | العربية | `ar-SA` |
|
|
313
|
+
|
|
314
|
+
为兼容旧版写法,仍可传入 `en`、`ja`,SDK 会分别映射为 `en-US`、`ja-JP`。新接入建议使用表中的标准语言码。
|
|
315
|
+
|
|
290
316
|
### 如何处理 URL
|
|
291
317
|
|
|
292
318
|
由于石墨 SDK 以 `iframe` 的形式挂载到当前页面,`iframe.src` 对应的 URL 并不适合用于分享,而且在一些功能上,比如 @ 文件,需要用到您系统中对应的 URL 格式,比如 `https://your-domain/files/:id`。
|
|
@@ -294,9 +320,9 @@ const shimoSDK = await connect({
|
|
|
294
320
|
为了解决这个问题,石墨 SDK 引入 `generateUrl()` 和 `openLink()` 方法:
|
|
295
321
|
|
|
296
322
|
```js
|
|
297
|
-
import { UrlSharingType } from '
|
|
323
|
+
import { UrlSharingType } from 'weboffice-js-sdk'
|
|
298
324
|
|
|
299
|
-
const
|
|
325
|
+
const officeSDK = await connect({
|
|
300
326
|
...,
|
|
301
327
|
|
|
302
328
|
generateUrl(fileId: string, info: GenerateUrlInfo): string {
|
|
@@ -497,9 +523,9 @@ connect({
|
|
|
497
523
|
- `ui.toast.tips.edit.noPermission`
|
|
498
524
|
|
|
499
525
|
```typescript
|
|
500
|
-
import { connect } from '
|
|
526
|
+
import { connect } from 'weboffice-js-sdk'
|
|
501
527
|
|
|
502
|
-
const
|
|
528
|
+
const officeSDK = await connect({
|
|
503
529
|
ui: {
|
|
504
530
|
toast: {
|
|
505
531
|
tips: {
|
|
@@ -521,9 +547,9 @@ const shimoSDK = await connect({
|
|
|
521
547
|
此方法可显示接入方自定义 toast,具体用法如下
|
|
522
548
|
|
|
523
549
|
```typescript
|
|
524
|
-
import { connect, ShowToastOptions } from '
|
|
550
|
+
import { connect, ShowToastOptions } from 'weboffice-js-sdk'
|
|
525
551
|
|
|
526
|
-
const
|
|
552
|
+
const officeSDK = await connect({
|
|
527
553
|
// 初始化sdk时传了该方法将会拦截编辑器内的toast
|
|
528
554
|
showToast: (options: ShowToastOptions) => {
|
|
529
555
|
// show your toast
|
package/dist/OfficeSDK.d.ts
CHANGED
|
@@ -9,12 +9,10 @@ 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, 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
|
-
import type { BrandingFacade } from './OfficeSDK.branding';
|
|
15
14
|
export * from './OfficeSDK.facade.types';
|
|
16
15
|
export * from './OfficeSDK.headerBars';
|
|
17
|
-
export * from './OfficeSDK.branding';
|
|
18
16
|
export declare const MessageEvent: typeof InvokeMethod;
|
|
19
17
|
export declare class OfficeSDK extends TinyEmitter {
|
|
20
18
|
/**
|
|
@@ -80,8 +78,9 @@ export declare class OfficeSDK extends TinyEmitter {
|
|
|
80
78
|
version?: VersionFacade;
|
|
81
79
|
/**
|
|
82
80
|
* 当前套件支持的演示能力。
|
|
81
|
+
* 文档与表格支持 start / quit,幻灯片套件额外支持完整演示能力。
|
|
83
82
|
*/
|
|
84
|
-
presentation?:
|
|
83
|
+
presentation?: OfficeSDKPresentationFacade;
|
|
85
84
|
/**
|
|
86
85
|
* 当前套件支持的选区能力。
|
|
87
86
|
*/
|
|
@@ -170,7 +169,6 @@ export declare class OfficeSDK extends TinyEmitter {
|
|
|
170
169
|
*/
|
|
171
170
|
flowchart?: Flowchart.Editor;
|
|
172
171
|
readonly headerBars: HeaderBarsFacade;
|
|
173
|
-
readonly branding: BrandingFacade;
|
|
174
172
|
private _fileType;
|
|
175
173
|
private readonly messageHandler;
|
|
176
174
|
/**
|
|
@@ -203,12 +201,16 @@ export declare class OfficeSDK extends TinyEmitter {
|
|
|
203
201
|
private readonly headerBarsCommandRefs;
|
|
204
202
|
private headerBarsTitleChangeHandler?;
|
|
205
203
|
private headerBarsTitleChangeSubscribed;
|
|
206
|
-
private editorFooterLogo?;
|
|
207
204
|
private readonly onViewportResize;
|
|
208
205
|
/**
|
|
209
206
|
* 归一化后的缺省页配置,构造时一次算完,后续仅读取。
|
|
210
207
|
*/
|
|
211
208
|
private readonly normalizedEmptyPage;
|
|
209
|
+
private readonly preloadCredentialsMessageHandler;
|
|
210
|
+
private pendingInitializationErrorHandler?;
|
|
211
|
+
private pendingInitializationError?;
|
|
212
|
+
private preloadCredentialsPromise?;
|
|
213
|
+
private disconnected;
|
|
212
214
|
private readonly preloadAckTimeoutMs;
|
|
213
215
|
private readonly preloadDoneTimeoutMs;
|
|
214
216
|
private readonly preloadReadyTimeoutMs;
|
|
@@ -281,6 +283,8 @@ export declare class OfficeSDK extends TinyEmitter {
|
|
|
281
283
|
*/
|
|
282
284
|
ready(): Promise<void>;
|
|
283
285
|
private initIframe;
|
|
286
|
+
private handlePreloadMessage;
|
|
287
|
+
private getPreloadCredentials;
|
|
284
288
|
private runPreloadHandshake;
|
|
285
289
|
private initChannel;
|
|
286
290
|
/**
|
|
@@ -288,7 +292,6 @@ export declare class OfficeSDK extends TinyEmitter {
|
|
|
288
292
|
*/
|
|
289
293
|
private bindContainerMethodHandlers;
|
|
290
294
|
private initHeaderBarsFacade;
|
|
291
|
-
private initBrandingFacade;
|
|
292
295
|
/**
|
|
293
296
|
* 订阅 iframe 侧 titleChange 事件,并在宿主设置了 headerBars.onTitleChange 时转发标题值。
|
|
294
297
|
* 输入:无。
|
|
@@ -296,12 +299,9 @@ export declare class OfficeSDK extends TinyEmitter {
|
|
|
296
299
|
*/
|
|
297
300
|
private ensureHeaderBarsTitleChangeSubscription;
|
|
298
301
|
private invokeHeaderBars;
|
|
299
|
-
private invokeBranding;
|
|
300
302
|
private syncHeaderBarsCommands;
|
|
301
303
|
private createHeaderBarsHost;
|
|
302
|
-
private createBrandingHost;
|
|
303
304
|
private applyHeaderBarsChanged;
|
|
304
|
-
private applyBrandingChanged;
|
|
305
305
|
private syncHeaderBarsVisible;
|
|
306
306
|
private setHeaderBarsVisible;
|
|
307
307
|
private getHeaderBarsCommandRef;
|
|
@@ -473,7 +473,7 @@ export interface SDKToastOptions {
|
|
|
473
473
|
}
|
|
474
474
|
/**
|
|
475
475
|
* 透传给 iframe 编辑器的主题配置。
|
|
476
|
-
* 当前
|
|
476
|
+
* 当前 weboffice-js-sdk 仅负责跨 iframe 传输,不在宿主侧约束字段细节。
|
|
477
477
|
*/
|
|
478
478
|
export interface CommonThemeConfig {
|
|
479
479
|
[key: string]: unknown;
|
|
@@ -604,7 +604,7 @@ export interface OfficeSDKOptions extends Omit<ContainerMethods, 'getContainerRe
|
|
|
604
604
|
headerBarsVisible?: boolean;
|
|
605
605
|
/**
|
|
606
606
|
* 是否隐藏 iframe 内 AI 入口。
|
|
607
|
-
* 对应 iframe 内
|
|
607
|
+
* 对应 iframe 内 OfficeSDK 的现有 AI 入口开关能力。
|
|
608
608
|
*/
|
|
609
609
|
disableAiEntry?: boolean;
|
|
610
610
|
/**
|
|
@@ -162,7 +162,9 @@ export interface ClipboardPasteParams {
|
|
|
162
162
|
}
|
|
163
163
|
export type SheetAppendDataAxis = 'row' | 'column';
|
|
164
164
|
export interface SheetSelection {
|
|
165
|
-
|
|
165
|
+
/** 当前 iframe runtime 内稳定的选区标识。 */
|
|
166
|
+
id: string;
|
|
167
|
+
getRange: (value?: SheetRangeValue) => Promise<SheetRangeFacade | null>;
|
|
166
168
|
setRange: (value: SheetRangeValue | null) => Promise<void>;
|
|
167
169
|
}
|
|
168
170
|
export declare enum SheetRangeType {
|
|
@@ -429,24 +431,24 @@ export interface PresentationShapeBase {
|
|
|
429
431
|
id: string;
|
|
430
432
|
name: string;
|
|
431
433
|
type: PresentationShapeType;
|
|
432
|
-
setFill: (fill: PresentationShapeFill) => void
|
|
433
|
-
setLine: (line: PresentationShapeLine) => void
|
|
434
|
-
setLayout: (layout: PresentationShapeLayout) => void
|
|
435
|
-
remove: () => void
|
|
434
|
+
setFill: (fill: PresentationShapeFill) => Promise<void>;
|
|
435
|
+
setLine: (line: PresentationShapeLine) => Promise<void>;
|
|
436
|
+
setLayout: (layout: PresentationShapeLayout) => Promise<void>;
|
|
437
|
+
remove: () => Promise<void>;
|
|
436
438
|
}
|
|
437
439
|
export type PresentationTextShapeType = Exclude<PresentationShapeType, PresentationLineShapeType>;
|
|
438
440
|
export interface PresentationTextShape extends PresentationShapeBase {
|
|
439
441
|
type: PresentationTextShapeType;
|
|
440
442
|
textContent?: string;
|
|
441
|
-
setContent: (content: PresentationShapeContent) => void
|
|
442
|
-
appendText: (text: string) => void
|
|
443
|
-
appendParagraphs: (paragraphs: PresentationParagraph[]) => void
|
|
443
|
+
setContent: (content: PresentationShapeContent) => Promise<void>;
|
|
444
|
+
appendText: (text: string) => Promise<void>;
|
|
445
|
+
appendParagraphs: (paragraphs: PresentationParagraph[]) => Promise<void>;
|
|
444
446
|
}
|
|
445
447
|
export type PresentationShape = PresentationShapeBase | PresentationTextShape;
|
|
446
448
|
export type PresentationParagraphLineSpacing = 0.9 | 1.0 | 1.15 | 1.5 | 2.0 | 2.5 | 3.0;
|
|
447
449
|
export interface PresentationTableCell {
|
|
448
|
-
setStyle: (style: PresentationTableCellStyle) => void
|
|
449
|
-
clearStyle: () => void
|
|
450
|
+
setStyle: (style: PresentationTableCellStyle) => Promise<void>;
|
|
451
|
+
clearStyle: () => Promise<void>;
|
|
450
452
|
}
|
|
451
453
|
export type PresentationTableCellStyle = PresentationTextStyle & PresentationParagraphStyle;
|
|
452
454
|
export interface PresentationTableSelection {
|
|
@@ -456,25 +458,25 @@ export interface PresentationTableSelection {
|
|
|
456
458
|
columnCount: number;
|
|
457
459
|
}
|
|
458
460
|
export interface PresentationTableRange {
|
|
459
|
-
setStyle: (style: PresentationTableCellStyle) => void
|
|
460
|
-
clearStyle: () => void
|
|
461
|
-
setSpan: () => void
|
|
462
|
-
removeSpan: () => void
|
|
461
|
+
setStyle: (style: PresentationTableCellStyle) => Promise<void>;
|
|
462
|
+
clearStyle: () => Promise<void>;
|
|
463
|
+
setSpan: () => Promise<void>;
|
|
464
|
+
removeSpan: () => Promise<void>;
|
|
463
465
|
}
|
|
464
466
|
export interface PresentationTableItem {
|
|
465
467
|
id: string;
|
|
466
468
|
rowCount: number;
|
|
467
469
|
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
|
|
470
|
+
remove: () => Promise<void>;
|
|
471
|
+
insertRows: (index: number, count: number, placement?: 'before' | 'after') => Promise<void>;
|
|
472
|
+
insertColumns: (index: number, count: number, placement?: 'before' | 'after') => Promise<void>;
|
|
473
|
+
deleteRows: (index: number, count: number) => Promise<void>;
|
|
474
|
+
deleteColumns: (index: number, count: number) => Promise<void>;
|
|
475
|
+
setRowHeight: (index: number, height: number) => Promise<void>;
|
|
476
|
+
setColumnWidth: (index: number, width: number) => Promise<void>;
|
|
477
|
+
getCell: (row: number, column: number) => Promise<PresentationTableCell | null>;
|
|
478
|
+
getRange: (range: PresentationTableSelection) => Promise<PresentationTableRange | null>;
|
|
479
|
+
setDirection: (direction: 'ltr' | 'rtl') => Promise<void>;
|
|
478
480
|
}
|
|
479
481
|
export interface PresentationTableOptions {
|
|
480
482
|
offset: PresentationOffset;
|
|
@@ -512,14 +514,18 @@ export interface VersionFacade {
|
|
|
512
514
|
hide?: () => Promise<void>;
|
|
513
515
|
createRevision: (options?: RevisionCreateOptions) => Promise<undefined | null | DocumentErrorMessage>;
|
|
514
516
|
}
|
|
515
|
-
export interface
|
|
516
|
-
start: (
|
|
517
|
+
export interface BasicPresentationFacade {
|
|
518
|
+
start: () => Promise<void>;
|
|
517
519
|
quit: () => Promise<void>;
|
|
520
|
+
}
|
|
521
|
+
export interface PresentationFacade extends BasicPresentationFacade {
|
|
522
|
+
start: (index?: number) => Promise<void>;
|
|
518
523
|
startFromCurrent: () => Promise<void>;
|
|
519
524
|
startRemoteLive: () => Promise<void>;
|
|
520
525
|
startSpeakerView: () => Promise<void>;
|
|
521
526
|
addChangeListener: (listener: (payload: unknown) => void) => () => void;
|
|
522
527
|
}
|
|
528
|
+
export type OfficeSDKPresentationFacade = BasicPresentationFacade | PresentationFacade;
|
|
523
529
|
export interface DocsRangeFacade {
|
|
524
530
|
start: number;
|
|
525
531
|
end: number;
|
|
@@ -623,6 +629,12 @@ export interface SheetRangeFacade {
|
|
|
623
629
|
column: number;
|
|
624
630
|
rowCount: number;
|
|
625
631
|
columnCount: number;
|
|
632
|
+
getBounding: () => Promise<{
|
|
633
|
+
left: number;
|
|
634
|
+
top: number;
|
|
635
|
+
width: number;
|
|
636
|
+
height: number;
|
|
637
|
+
} | null>;
|
|
626
638
|
getText: (format?: 'plain' | 'matrix') => Promise<string | string[][]>;
|
|
627
639
|
setText: (text: SheetRangeText) => Promise<void>;
|
|
628
640
|
getHtml: () => Promise<string>;
|
|
@@ -671,6 +683,7 @@ export interface SheetWorksheetFacade {
|
|
|
671
683
|
sheet: string;
|
|
672
684
|
ranges: SheetRangeValue[] | null;
|
|
673
685
|
}) => void) => () => void;
|
|
686
|
+
/** @deprecated 先 await worksheet.getRange(range),再调用 range?.getBounding()。 */
|
|
674
687
|
getBounding: (range: SheetRangeValue) => Promise<{
|
|
675
688
|
left: number;
|
|
676
689
|
top: number;
|
|
@@ -827,7 +840,7 @@ export interface OfficeSDKRootFacadeState {
|
|
|
827
840
|
mention?: MentionFacade;
|
|
828
841
|
content?: ContentFacade;
|
|
829
842
|
version?: VersionFacade;
|
|
830
|
-
presentation?:
|
|
843
|
+
presentation?: OfficeSDKPresentationFacade;
|
|
831
844
|
selection?: DocsSelectionFacade | PresentationSelectionFacade;
|
|
832
845
|
search?: DocsSearchFacade;
|
|
833
846
|
outline?: DocsOutlineFacade;
|
package/dist/connect.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { OfficeSDK, OfficeSDKOptions } from './OfficeSDK';
|
|
2
|
+
import { type ConnectV2FileType } from './types/ConnectV2';
|
|
3
|
+
export { CONNECT_V2_FILE_TYPES, isConnectV2FileType, isConnectV2Mode, validateConnectV2Options } from './types/ConnectV2';
|
|
4
|
+
export type { ConnectV2FileType } from './types/ConnectV2';
|
|
2
5
|
export interface ConnectOptions extends OfficeSDKOptions {
|
|
3
6
|
}
|
|
7
|
+
export interface ConnectV2Options extends ConnectOptions {
|
|
8
|
+
/**
|
|
9
|
+
* V2 套件类型。当前用于 iframe 侧资源选择预留。
|
|
10
|
+
*/
|
|
11
|
+
type: ConnectV2FileType;
|
|
12
|
+
/**
|
|
13
|
+
* V2 打开模式。
|
|
14
|
+
*/
|
|
15
|
+
mode: 'edit' | 'preview';
|
|
16
|
+
}
|
|
4
17
|
/**
|
|
5
18
|
* 初始化 SDK,返回 Promise,当 ReadState 变为 Ready 或 Failed 时,Promise 将被 resolve。
|
|
6
19
|
* Promise resovled 不代表编辑器已经完整加载完毕,只代表 SDK 已经准备好了。
|
|
@@ -8,3 +21,9 @@ export interface ConnectOptions extends OfficeSDKOptions {
|
|
|
8
21
|
* 比如受浏览器限制无法发出 postMessage() 时,Promise 将会一直 pending。
|
|
9
22
|
*/
|
|
10
23
|
export declare function connect(options: ConnectOptions): Promise<OfficeSDK>;
|
|
24
|
+
/**
|
|
25
|
+
* 初始化 V2 统一编辑 / 预览入口。
|
|
26
|
+
*
|
|
27
|
+
* V2 在运行时强制校验 type 和 mode,底层 iframe 初始化流程与旧 connect 共用。
|
|
28
|
+
*/
|
|
29
|
+
export declare function connectV2(options: ConnectV2Options): Promise<OfficeSDK>;
|
|
@@ -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, 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,6 +9,7 @@ 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 = [
|
|
12
14
|
Assert<IsAssignable<NonNullable<OfficeSDK['title']>['setTitle'], (title: string) => Promise<void>>>,
|
|
13
15
|
Assert<IsAssignable<NonNullable<OfficeSDK['title']>['addChangedListener'], (listener: (title: string) => void) => () => void>>,
|
|
@@ -15,9 +17,14 @@ export type EditorFacadeContractAssertions = [
|
|
|
15
17
|
Assert<IsAssignable<NonNullable<OfficeSDK['history']>['show'], () => Promise<void>>>,
|
|
16
18
|
Assert<IsAssignable<NonNullable<OfficeSDK['mention']>['locateCellByGuid'], (guid: string, notificationType?: import('./OfficeSDK').MentionTypes) => Promise<void>>>,
|
|
17
19
|
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<
|
|
20
|
+
Assert<IsAssignable<RootPresentation, BasicPresentationFacade>>,
|
|
21
|
+
Assert<IsAssignable<RootPresentation['start'], () => Promise<void>>>,
|
|
22
|
+
Assert<IsAssignable<RootPresentation['quit'], () => Promise<void>>>,
|
|
23
|
+
Assert<IsAssignable<PresentationFacade['start'], (index?: number) => Promise<void>>>,
|
|
24
|
+
Assert<IsAssignable<PresentationFacade['startFromCurrent'], () => Promise<void>>>,
|
|
25
|
+
Assert<IsAssignable<PresentationFacade['startRemoteLive'], () => Promise<void>>>,
|
|
26
|
+
Assert<IsAssignable<PresentationFacade['startSpeakerView'], () => Promise<void>>>,
|
|
27
|
+
Assert<IsAssignable<PresentationFacade['addChangeListener'], (listener: (payload: unknown) => void) => () => void>>,
|
|
21
28
|
Assert<IsAssignable<NonNullable<OfficeSDK['batchChanges']>, <T>(callback: () => T | Promise<T>) => Promise<Awaited<T>>>>,
|
|
22
29
|
Assert<IsAssignable<NonNullable<OfficeSDK['print']>, () => Promise<void>>>,
|
|
23
30
|
Assert<IsAssignable<NonNullable<OfficeSDK['export']>, (type: string) => Promise<void>>>,
|
|
@@ -38,12 +45,25 @@ export type EditorFacadeContractAssertions = [
|
|
|
38
45
|
Assert<IsAssignable<NonNullable<OfficeSDK['text']>['apply'], (format: Partial<EditorTextFormat>, range?: PresentationTextRangeValue) => Promise<Partial<EditorTextFormat>>>>,
|
|
39
46
|
Assert<IsAssignable<NonNullable<OfficeSDK['activeSheet']>['getSelections'], () => Promise<SheetSelection[] | null>>>,
|
|
40
47
|
Assert<IsAssignable<NonNullable<OfficeSDK['activeSheet']>['getRange'], (value: SheetRangeValue) => Promise<SheetRangeFacade | null>>>,
|
|
48
|
+
Assert<IsEqual<SheetRangeFacade['getBounding'], () => Promise<{
|
|
49
|
+
left: number;
|
|
50
|
+
top: number;
|
|
51
|
+
width: number;
|
|
52
|
+
height: number;
|
|
53
|
+
} | null>>>,
|
|
41
54
|
Assert<IsAssignable<NonNullable<OfficeSDK['selections']>['getAll'], () => Promise<SheetRangeValue[]>>>,
|
|
42
55
|
Assert<IsAssignable<NonNullable<OfficeSDK['charts']>['addChartFromSelection'], (params?: import('./OfficeSDK').AddChartFromSelectionParams) => Promise<AddChartFromSelectionResult | undefined>>>,
|
|
43
56
|
Assert<IsAssignable<PresentationSelection['getSelectedShapes'], (ids?: string[]) => Promise<PresentationShape[] | null>>>,
|
|
44
57
|
Assert<IsAssignable<NonNullable<OfficeSDK['zoom']>['setPercentage'], (percentage: number) => Promise<void>>>,
|
|
45
58
|
Assert<IsAssignable<NonNullable<OfficeSDK['eventSubscription']>['addLoadedListener'], (listener: () => void) => () => void>>,
|
|
46
|
-
Assert<
|
|
47
|
-
Assert<
|
|
59
|
+
Assert<IsEqual<SheetSelection['getRange'], (value?: SheetRangeValue) => Promise<SheetRangeFacade | null>>>,
|
|
60
|
+
Assert<IsEqual<SheetSelection['id'], string>>,
|
|
61
|
+
Assert<IsEqual<PresentationShapeBase['setFill'], (fill: import('./OfficeSDK').PresentationShapeFill) => Promise<void>>>,
|
|
62
|
+
Assert<IsEqual<PresentationShapeBase['remove'], () => Promise<void>>>,
|
|
63
|
+
Assert<IsEqual<PresentationTableItem['getCell'], (row: number, column: number) => Promise<PresentationTableCell | null>>>,
|
|
64
|
+
Assert<IsEqual<PresentationTableItem['getRange'], (range: PresentationTableSelection) => Promise<PresentationTableRange | null>>>,
|
|
65
|
+
Assert<IsEqual<PresentationTableItem['insertRows'], (index: number, count: number, placement?: 'before' | 'after') => Promise<void>>>,
|
|
66
|
+
Assert<IsEqual<PresentationTableCell['clearStyle'], () => Promise<void>>>,
|
|
67
|
+
Assert<IsEqual<PresentationTableRange['setSpan'], () => Promise<void>>>
|
|
48
68
|
];
|
|
49
69
|
export {};
|