weboffice-js-sdk 2.0.5-beta.15 → 2.0.5-beta.17
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 +21 -0
- package/dist/OfficeSDK.d.ts +30 -9
- package/dist/OfficeSDK.headerBars.d.ts +0 -103
- package/dist/connect.d.ts +19 -0
- package/dist/index.js +2 -2
- package/dist/outsideIframePointer.d.ts +18 -0
- package/dist/preload.d.ts +13 -0
- package/dist/types/ConnectV2.d.ts +21 -0
- package/package.json +2 -2
- package/dist/headerBarsAnchor.d.ts +0 -26
package/README.md
CHANGED
|
@@ -47,6 +47,27 @@ connect({
|
|
|
47
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
|
```
|
package/dist/OfficeSDK.d.ts
CHANGED
|
@@ -9,12 +9,12 @@ 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 { ContentVersion } from './types/ConnectV2';
|
|
12
13
|
import type { CollaboratorFacade, CommentsFacade, ContentFacade, DiscussionFacade, DocsActiveOutlineFacade, 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
14
|
import type { OfficeSDKMethodPath } from './OfficeSDK.methods';
|
|
14
15
|
import type { HeaderBarsFacade } from './OfficeSDK.headerBars';
|
|
15
16
|
export * from './OfficeSDK.facade.types';
|
|
16
17
|
export * from './OfficeSDK.headerBars';
|
|
17
|
-
export { toHeaderBarsCallbackAnchorRect } from './headerBarsAnchor';
|
|
18
18
|
export declare const MessageEvent: typeof InvokeMethod;
|
|
19
19
|
export declare class OfficeSDK extends TinyEmitter {
|
|
20
20
|
/**
|
|
@@ -185,6 +185,7 @@ export declare class OfficeSDK extends TinyEmitter {
|
|
|
185
185
|
private readonly emitter;
|
|
186
186
|
private channel;
|
|
187
187
|
private readonly connectOptions;
|
|
188
|
+
private readonly contentVersion?;
|
|
188
189
|
private _readyState;
|
|
189
190
|
private editor;
|
|
190
191
|
private readonly startParams;
|
|
@@ -204,22 +205,27 @@ export declare class OfficeSDK extends TinyEmitter {
|
|
|
204
205
|
private headerBarsVisible;
|
|
205
206
|
private readonly headerBarsCommands;
|
|
206
207
|
private readonly headerBarsCommandOverrides;
|
|
207
|
-
private readonly headerBarsCommandEventOverrides;
|
|
208
|
-
private headerBarsCapabilities;
|
|
209
208
|
private readonly slashMenuCallbacks;
|
|
210
209
|
private readonly editorFacadeCallbacks;
|
|
211
210
|
private readonly headerBarsCommandRefs;
|
|
212
211
|
private headerBarsTitleChangeHandler?;
|
|
213
212
|
private headerBarsTitleChangeSubscribed;
|
|
214
213
|
private readonly onViewportResize;
|
|
214
|
+
private readonly onOutsidePointerDown;
|
|
215
|
+
private outsidePointerEventName?;
|
|
215
216
|
/**
|
|
216
217
|
* 归一化后的缺省页配置,构造时一次算完,后续仅读取。
|
|
217
218
|
*/
|
|
218
219
|
private readonly normalizedEmptyPage;
|
|
220
|
+
private readonly preloadCredentialsMessageHandler;
|
|
221
|
+
private pendingInitializationErrorHandler?;
|
|
222
|
+
private pendingInitializationError?;
|
|
223
|
+
private preloadCredentialsPromise?;
|
|
224
|
+
private disconnected;
|
|
219
225
|
private readonly preloadAckTimeoutMs;
|
|
220
226
|
private readonly preloadDoneTimeoutMs;
|
|
221
227
|
private readonly preloadReadyTimeoutMs;
|
|
222
|
-
constructor(options: OfficeSDKOptions);
|
|
228
|
+
constructor(options: OfficeSDKOptions, contentVersion?: ContentVersion);
|
|
223
229
|
get fileType(): FileType;
|
|
224
230
|
get readyState(): ReadyState;
|
|
225
231
|
/**
|
|
@@ -275,6 +281,24 @@ export declare class OfficeSDK extends TinyEmitter {
|
|
|
275
281
|
* 获取性能信息片段列表,由于性能标记是分段的、异步的,因此每次调用时获取的列表有可能不一致
|
|
276
282
|
*/
|
|
277
283
|
getPerformanceEntries(): Promise<PerformanceEntry[]>;
|
|
284
|
+
/**
|
|
285
|
+
* 在父文档 capture 阶段监听真实按下,点到本 iframe 之外时通知 iframe 结束编辑。
|
|
286
|
+
* 输入:无。
|
|
287
|
+
* 输出:无返回值,重复绑定会被忽略。
|
|
288
|
+
*/
|
|
289
|
+
private bindOutsideIframePointerListener;
|
|
290
|
+
/**
|
|
291
|
+
* 拆除父文档上的 iframe 外按下监听。
|
|
292
|
+
* 输入:无。
|
|
293
|
+
* 输出:无返回值;未绑定时直接返回。
|
|
294
|
+
*/
|
|
295
|
+
private unbindOutsideIframePointerListener;
|
|
296
|
+
/**
|
|
297
|
+
* 处理父页按下:目标不是本 iframe 时 fire-and-forget 通知 iframe。
|
|
298
|
+
* 输入:父文档上的 pointerdown/mousedown 事件。
|
|
299
|
+
* 输出:无返回值;channel 失败时吞掉,避免打断宿主页面。
|
|
300
|
+
*/
|
|
301
|
+
private notifyOutsidePointerDown;
|
|
278
302
|
disconnect(): void;
|
|
279
303
|
/**
|
|
280
304
|
* 初始化 SDK,返回 Promise,当 ReadState 变为 Ready 或 Failed 时,Promise 将被 resolve。
|
|
@@ -288,6 +312,8 @@ export declare class OfficeSDK extends TinyEmitter {
|
|
|
288
312
|
*/
|
|
289
313
|
ready(): Promise<void>;
|
|
290
314
|
private initIframe;
|
|
315
|
+
private handlePreloadMessage;
|
|
316
|
+
private getPreloadCredentials;
|
|
291
317
|
private runPreloadHandshake;
|
|
292
318
|
private initChannel;
|
|
293
319
|
/**
|
|
@@ -302,11 +328,6 @@ export declare class OfficeSDK extends TinyEmitter {
|
|
|
302
328
|
*/
|
|
303
329
|
private ensureHeaderBarsTitleChangeSubscription;
|
|
304
330
|
private invokeHeaderBars;
|
|
305
|
-
/**
|
|
306
|
-
* 将 iframe viewport 坐标转换为宿主 window viewport 坐标。
|
|
307
|
-
* 输入为 iframe 内事件矩形;输出不包含任何 DOM 对象。
|
|
308
|
-
*/
|
|
309
|
-
private toHeaderBarsCallbackAnchorRect;
|
|
310
331
|
private syncHeaderBarsCommands;
|
|
311
332
|
private createHeaderBarsHost;
|
|
312
333
|
private applyHeaderBarsChanged;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare const HEADER_BARS_METHOD: {
|
|
2
|
-
readonly getCapabilities: "headerBars.getCapabilities";
|
|
3
2
|
readonly getVisible: "headerBars.getVisible";
|
|
4
3
|
readonly setVisible: "headerBars.setVisible";
|
|
5
4
|
readonly addCommand: "headerBars.addCommand";
|
|
@@ -13,12 +12,6 @@ export declare const HEADER_BARS_METHOD: {
|
|
|
13
12
|
readonly setCommandCallbackEnabled: "headerBars.setCommandCallbackEnabled";
|
|
14
13
|
readonly listViewCommands: "headerBars.listViewCommands";
|
|
15
14
|
readonly handleCommandClick: "headerBars.handleCommandClick";
|
|
16
|
-
readonly addCommands: "headerBars.addCommands";
|
|
17
|
-
readonly setSectionVisible: "headerBars.setSectionVisible";
|
|
18
|
-
readonly setCommandOptions: "headerBars.setCommandOptions";
|
|
19
|
-
readonly setCommandOpen: "headerBars.setCommandOpen";
|
|
20
|
-
readonly setCommandEventCallbackEnabled: "headerBars.setCommandEventCallbackEnabled";
|
|
21
|
-
readonly handleCommandEvent: "headerBars.handleCommandEvent";
|
|
22
15
|
};
|
|
23
16
|
export declare const HEADER_BARS_CHANGED_EVENT = "headerBars:changed";
|
|
24
17
|
export interface HeaderBarsCommandDefinition {
|
|
@@ -33,21 +26,10 @@ export interface HeaderBarsCommandDefinition {
|
|
|
33
26
|
type?: 'action' | 'structural';
|
|
34
27
|
renderType?: string;
|
|
35
28
|
src?: string;
|
|
36
|
-
danger?: boolean;
|
|
37
|
-
disabledTip?: string;
|
|
38
|
-
itemType?: 'command' | 'divider';
|
|
39
|
-
trigger?: 'hover' | 'click';
|
|
40
|
-
open?: boolean;
|
|
41
|
-
style?: HeaderBarsCommandStyle;
|
|
42
|
-
toast?: Record<string, unknown>;
|
|
43
|
-
subItems?: HeaderBarsCommandDefinition[];
|
|
44
29
|
onClick?: () => void | Promise<void>;
|
|
45
|
-
onOpen?: HeaderBarsCommandOpenHandler;
|
|
46
|
-
onClose?: HeaderBarsCommandCloseHandler;
|
|
47
30
|
}
|
|
48
31
|
export interface HeaderBarsCommandState extends HeaderBarsCommandDefinition {
|
|
49
32
|
type: 'action' | 'structural';
|
|
50
|
-
open?: boolean;
|
|
51
33
|
}
|
|
52
34
|
export interface HeaderBarsCommandRef {
|
|
53
35
|
readonly id: string;
|
|
@@ -57,87 +39,9 @@ export interface HeaderBarsCommandRef {
|
|
|
57
39
|
src?: string;
|
|
58
40
|
label?: string;
|
|
59
41
|
editable?: boolean;
|
|
60
|
-
open: boolean;
|
|
61
|
-
style?: HeaderBarsCommandStyle;
|
|
62
|
-
subItems?: HeaderBarsCommandDefinition[];
|
|
63
42
|
onCommandClick?: () => void | Promise<void>;
|
|
64
|
-
onCommandOpen?: HeaderBarsCommandOpenHandler;
|
|
65
|
-
onCommandClose?: HeaderBarsCommandCloseHandler;
|
|
66
43
|
getState: () => HeaderBarsCommandState | undefined;
|
|
67
44
|
}
|
|
68
|
-
export interface HeaderBarsCommandStyle {
|
|
69
|
-
color?: string;
|
|
70
|
-
fontSize?: number;
|
|
71
|
-
fontWeight?: number;
|
|
72
|
-
backgroundColor?: string;
|
|
73
|
-
borderColor?: string;
|
|
74
|
-
borderWidth?: number;
|
|
75
|
-
borderRadius?: number;
|
|
76
|
-
width?: number;
|
|
77
|
-
height?: number;
|
|
78
|
-
}
|
|
79
|
-
export interface HeaderBarsAnchorRect {
|
|
80
|
-
left: number;
|
|
81
|
-
top: number;
|
|
82
|
-
right: number;
|
|
83
|
-
bottom: number;
|
|
84
|
-
width: number;
|
|
85
|
-
height: number;
|
|
86
|
-
viewport: {
|
|
87
|
-
width: number;
|
|
88
|
-
height: number;
|
|
89
|
-
};
|
|
90
|
-
coordinateSpace: 'callback-window-viewport';
|
|
91
|
-
}
|
|
92
|
-
export interface HeaderBarsSourceAnchorRect {
|
|
93
|
-
left: number;
|
|
94
|
-
top: number;
|
|
95
|
-
right: number;
|
|
96
|
-
bottom: number;
|
|
97
|
-
width: number;
|
|
98
|
-
height: number;
|
|
99
|
-
viewport: {
|
|
100
|
-
width: number;
|
|
101
|
-
height: number;
|
|
102
|
-
};
|
|
103
|
-
coordinateSpace: 'sdk-iframe-viewport';
|
|
104
|
-
}
|
|
105
|
-
export interface HeaderBarsCommandEventPayload {
|
|
106
|
-
requestId: string;
|
|
107
|
-
sequence: number;
|
|
108
|
-
commandId: string;
|
|
109
|
-
event: 'click' | 'open' | 'close';
|
|
110
|
-
anchorRect: HeaderBarsSourceAnchorRect;
|
|
111
|
-
context?: Record<string, unknown>;
|
|
112
|
-
}
|
|
113
|
-
export type HeaderBarsCommandEventResult = 'handled' | 'unhandled' | 'failed' | 'timedOut';
|
|
114
|
-
export interface HeaderBarsCommandEvent {
|
|
115
|
-
commandId: string;
|
|
116
|
-
event: 'click' | 'open' | 'close';
|
|
117
|
-
anchorRect: HeaderBarsAnchorRect;
|
|
118
|
-
context?: Record<string, unknown>;
|
|
119
|
-
}
|
|
120
|
-
export type HeaderBarsCommandClickHandler = (event?: HeaderBarsCommandEvent) => void | Promise<void>;
|
|
121
|
-
export type HeaderBarsCommandOpenHandler = (commandId: string, anchorRect: HeaderBarsAnchorRect, context: Record<string, unknown>) => void | Promise<void>;
|
|
122
|
-
export type HeaderBarsCommandCloseHandler = HeaderBarsCommandOpenHandler;
|
|
123
|
-
type HeaderBarsEventHandler = (...args: any[]) => void | Promise<void>;
|
|
124
|
-
export interface HeaderBarsCapabilities {
|
|
125
|
-
protocolVersion: 1 | 2;
|
|
126
|
-
features: {
|
|
127
|
-
treeCommands: boolean;
|
|
128
|
-
batchCommands: boolean;
|
|
129
|
-
sectionVisibility: boolean;
|
|
130
|
-
commandOptions: boolean;
|
|
131
|
-
commandOpenState: boolean;
|
|
132
|
-
commandEvents: boolean;
|
|
133
|
-
anchorEvents: boolean;
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
export interface HeaderBarsMutationResult {
|
|
137
|
-
success: boolean;
|
|
138
|
-
code?: string;
|
|
139
|
-
message?: string;
|
|
140
|
-
}
|
|
141
45
|
export type HeaderBarsTitleChangeHandler = (title: string) => void | Promise<void>;
|
|
142
46
|
export interface HeaderBarsFacade {
|
|
143
47
|
visible: boolean;
|
|
@@ -147,9 +51,6 @@ export interface HeaderBarsFacade {
|
|
|
147
51
|
addCommand: (command: HeaderBarsCommandDefinition, posCommand: string, pos?: 'before' | 'after') => Promise<boolean>;
|
|
148
52
|
getCommand: (id: string) => HeaderBarsCommandRef;
|
|
149
53
|
listViewCommands: () => Promise<HeaderBarsCommandState[]>;
|
|
150
|
-
getCapabilities: () => Promise<HeaderBarsCapabilities>;
|
|
151
|
-
addCommands: (commands: HeaderBarsCommandDefinition[], posCommand: string, pos?: 'before' | 'after') => Promise<HeaderBarsMutationResult>;
|
|
152
|
-
setSectionVisible: (section: 'left' | 'right', visible: boolean) => Promise<HeaderBarsMutationResult>;
|
|
153
54
|
}
|
|
154
55
|
export interface HeaderBarsChangedPayload {
|
|
155
56
|
reason?: string;
|
|
@@ -165,10 +66,6 @@ interface HeaderBarsHost {
|
|
|
165
66
|
setVisibleState(visible: boolean): void;
|
|
166
67
|
getCommandsMap(): Map<string, HeaderBarsCommandState>;
|
|
167
68
|
getOverridesMap(): Map<string, (() => void | Promise<void>) | undefined>;
|
|
168
|
-
getEventOverridesMap(): Map<string, HeaderBarsEventHandler | undefined>;
|
|
169
|
-
getCapabilitiesState(): HeaderBarsCapabilities;
|
|
170
|
-
setCapabilitiesState(capabilities: HeaderBarsCapabilities): void;
|
|
171
|
-
getIframeElement(): HTMLElement | null;
|
|
172
69
|
getRefsMap(): Map<string, HeaderBarsCommandRef>;
|
|
173
70
|
getTitleHandler(): HeaderBarsTitleChangeHandler | undefined;
|
|
174
71
|
setTitleHandler(handler: HeaderBarsTitleChangeHandler | undefined): void;
|
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>;
|