weboffice-js-sdk 2.0.5-beta.13 → 2.0.5-beta.15

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 CHANGED
@@ -47,27 +47,6 @@ 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
-
71
50
  返回值:
72
51
 
73
52
  ```
@@ -9,11 +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';
13
- 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';
12
+ 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
+ import type { OfficeSDKMethodPath } from './OfficeSDK.methods';
14
14
  import type { HeaderBarsFacade } from './OfficeSDK.headerBars';
15
15
  export * from './OfficeSDK.facade.types';
16
16
  export * from './OfficeSDK.headerBars';
17
+ export { toHeaderBarsCallbackAnchorRect } from './headerBarsAnchor';
17
18
  export declare const MessageEvent: typeof InvokeMethod;
18
19
  export declare class OfficeSDK extends TinyEmitter {
19
20
  /**
@@ -37,6 +38,12 @@ export declare class OfficeSDK extends TinyEmitter {
37
38
  * @deprecated - 用 `sdk.getEditor<T>()` 替代
38
39
  */
39
40
  spreadsheet?: Spreadsheet.Editor;
41
+ /** 当前轻文档的标准化、强类型文档入口。 */
42
+ ActiveOutline?: DocsActiveOutlineFacade;
43
+ /**
44
+ * 判断当前套件和 iframe runtime 是否支持指定的公开 SDK 方法。
45
+ */
46
+ canIUse(method: OfficeSDKMethodPath): Promise<boolean>;
40
47
  /**
41
48
  * 当前套件支持的标题能力。
42
49
  */
@@ -178,7 +185,6 @@ export declare class OfficeSDK extends TinyEmitter {
178
185
  private readonly emitter;
179
186
  private channel;
180
187
  private readonly connectOptions;
181
- private readonly contentVersion?;
182
188
  private _readyState;
183
189
  private editor;
184
190
  private readonly startParams;
@@ -198,6 +204,8 @@ export declare class OfficeSDK extends TinyEmitter {
198
204
  private headerBarsVisible;
199
205
  private readonly headerBarsCommands;
200
206
  private readonly headerBarsCommandOverrides;
207
+ private readonly headerBarsCommandEventOverrides;
208
+ private headerBarsCapabilities;
201
209
  private readonly slashMenuCallbacks;
202
210
  private readonly editorFacadeCallbacks;
203
211
  private readonly headerBarsCommandRefs;
@@ -208,15 +216,10 @@ export declare class OfficeSDK extends TinyEmitter {
208
216
  * 归一化后的缺省页配置,构造时一次算完,后续仅读取。
209
217
  */
210
218
  private readonly normalizedEmptyPage;
211
- private readonly preloadCredentialsMessageHandler;
212
- private pendingInitializationErrorHandler?;
213
- private pendingInitializationError?;
214
- private preloadCredentialsPromise?;
215
- private disconnected;
216
219
  private readonly preloadAckTimeoutMs;
217
220
  private readonly preloadDoneTimeoutMs;
218
221
  private readonly preloadReadyTimeoutMs;
219
- constructor(options: OfficeSDKOptions, contentVersion?: ContentVersion);
222
+ constructor(options: OfficeSDKOptions);
220
223
  get fileType(): FileType;
221
224
  get readyState(): ReadyState;
222
225
  /**
@@ -285,8 +288,6 @@ export declare class OfficeSDK extends TinyEmitter {
285
288
  */
286
289
  ready(): Promise<void>;
287
290
  private initIframe;
288
- private handlePreloadMessage;
289
- private getPreloadCredentials;
290
291
  private runPreloadHandshake;
291
292
  private initChannel;
292
293
  /**
@@ -301,6 +302,11 @@ export declare class OfficeSDK extends TinyEmitter {
301
302
  */
302
303
  private ensureHeaderBarsTitleChangeSubscription;
303
304
  private invokeHeaderBars;
305
+ /**
306
+ * 将 iframe viewport 坐标转换为宿主 window viewport 坐标。
307
+ * 输入为 iframe 内事件矩形;输出不包含任何 DOM 对象。
308
+ */
309
+ private toHeaderBarsCallbackAnchorRect;
304
310
  private syncHeaderBarsCommands;
305
311
  private createHeaderBarsHost;
306
312
  private applyHeaderBarsChanged;
@@ -319,6 +325,7 @@ export declare class OfficeSDK extends TinyEmitter {
319
325
  * 输出:无。
320
326
  */
321
327
  private unregisterEditorFacadeCallback;
328
+ private reportEditorFacadeError;
322
329
  /**
323
330
  * 创建基于 method-path 的模块 facade。
324
331
  * 输入:模块前缀与少量自定义实现覆盖。
@@ -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,90 @@ 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 DocsActiveOutlineFacade {
54
+ Editor: DocsProductEditorFacade;
55
+ Service: DocsProductServiceFacade;
56
+ Sub: DocsProductSubFacade;
57
+ Env: DocsProductEnvFacade;
58
+ }
59
+ export interface DocsProductUserFacade {
60
+ GetUserInfo: () => Promise<unknown>;
61
+ }
62
+ export interface DocsProductPermissionFacade {
63
+ GetDocumentPermission: () => Promise<DocsDocumentPermission>;
64
+ }
65
+ export interface DocsProductExportFacade {
66
+ DownloadDocument: (format: DocsDownloadDocumentType) => Promise<void>;
67
+ }
68
+ export interface DocsProductCollaborationFacade {
69
+ GetSaveStatus: () => Promise<unknown>;
70
+ }
71
+ export interface DocsProductServiceFacade {
72
+ User: DocsProductUserFacade;
73
+ Permission: DocsProductPermissionFacade;
74
+ Export: DocsProductExportFacade;
75
+ Collaboration: DocsProductCollaborationFacade;
76
+ }
77
+ export interface DocsProductSubFacade {
78
+ OnDocumentChange: (handler: (delta: DocsEditorDeltaSnapshot) => void) => () => void;
79
+ }
80
+ export interface DocsProductLanguageFacade {
81
+ GetLanguage: () => Promise<string>;
82
+ }
83
+ export interface DocsProductModeFacade {
84
+ GetDocsMode: () => Promise<string>;
85
+ }
86
+ export interface DocsProductEnvFacade {
87
+ Language: DocsProductLanguageFacade;
88
+ DocsMode: DocsProductModeFacade;
89
+ }
6
90
  export interface CommentsFacade {
7
91
  show: (type?: 'list' | 'card') => Promise<void>;
8
92
  hide: (type?: 'list' | 'card') => Promise<void>;
@@ -830,6 +914,7 @@ export interface PresentationEventSubscriptionFacade {
830
914
  addLoadedListener: (listener: () => void) => () => void;
831
915
  }
832
916
  export interface OfficeSDKRootFacadeState {
917
+ ActiveOutline?: DocsActiveOutlineFacade;
833
918
  title?: TitleFacade;
834
919
  history?: HistoryFacade;
835
920
  comments?: CommentsFacade;
@@ -1,4 +1,5 @@
1
1
  export declare const HEADER_BARS_METHOD: {
2
+ readonly getCapabilities: "headerBars.getCapabilities";
2
3
  readonly getVisible: "headerBars.getVisible";
3
4
  readonly setVisible: "headerBars.setVisible";
4
5
  readonly addCommand: "headerBars.addCommand";
@@ -12,6 +13,12 @@ export declare const HEADER_BARS_METHOD: {
12
13
  readonly setCommandCallbackEnabled: "headerBars.setCommandCallbackEnabled";
13
14
  readonly listViewCommands: "headerBars.listViewCommands";
14
15
  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";
15
22
  };
16
23
  export declare const HEADER_BARS_CHANGED_EVENT = "headerBars:changed";
17
24
  export interface HeaderBarsCommandDefinition {
@@ -26,10 +33,21 @@ export interface HeaderBarsCommandDefinition {
26
33
  type?: 'action' | 'structural';
27
34
  renderType?: string;
28
35
  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[];
29
44
  onClick?: () => void | Promise<void>;
45
+ onOpen?: HeaderBarsCommandOpenHandler;
46
+ onClose?: HeaderBarsCommandCloseHandler;
30
47
  }
31
48
  export interface HeaderBarsCommandState extends HeaderBarsCommandDefinition {
32
49
  type: 'action' | 'structural';
50
+ open?: boolean;
33
51
  }
34
52
  export interface HeaderBarsCommandRef {
35
53
  readonly id: string;
@@ -39,9 +57,87 @@ export interface HeaderBarsCommandRef {
39
57
  src?: string;
40
58
  label?: string;
41
59
  editable?: boolean;
60
+ open: boolean;
61
+ style?: HeaderBarsCommandStyle;
62
+ subItems?: HeaderBarsCommandDefinition[];
42
63
  onCommandClick?: () => void | Promise<void>;
64
+ onCommandOpen?: HeaderBarsCommandOpenHandler;
65
+ onCommandClose?: HeaderBarsCommandCloseHandler;
43
66
  getState: () => HeaderBarsCommandState | undefined;
44
67
  }
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
+ }
45
141
  export type HeaderBarsTitleChangeHandler = (title: string) => void | Promise<void>;
46
142
  export interface HeaderBarsFacade {
47
143
  visible: boolean;
@@ -51,6 +147,9 @@ export interface HeaderBarsFacade {
51
147
  addCommand: (command: HeaderBarsCommandDefinition, posCommand: string, pos?: 'before' | 'after') => Promise<boolean>;
52
148
  getCommand: (id: string) => HeaderBarsCommandRef;
53
149
  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>;
54
153
  }
55
154
  export interface HeaderBarsChangedPayload {
56
155
  reason?: string;
@@ -66,6 +165,10 @@ interface HeaderBarsHost {
66
165
  setVisibleState(visible: boolean): void;
67
166
  getCommandsMap(): Map<string, HeaderBarsCommandState>;
68
167
  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;
69
172
  getRefsMap(): Map<string, HeaderBarsCommandRef>;
70
173
  getTitleHandler(): HeaderBarsTitleChangeHandler | undefined;
71
174
  setTitleHandler(handler: HeaderBarsTitleChangeHandler | undefined): void;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * SDK capability method identifiers.
3
+ *
4
+ * Values are public SDK method paths. Keeping the object tree aligned with the
5
+ * public facade makes the accepted canIUse arguments discoverable without
6
+ * exposing product-specific API namespaces.
7
+ */
8
+ export declare const OfficeSDKMethods: {
9
+ readonly ActiveOutline: {
10
+ readonly Editor: {
11
+ readonly GetEditMode: "ActiveOutline.Editor.GetEditMode";
12
+ readonly Document: {
13
+ readonly GetContent: "ActiveOutline.Editor.Document.GetContent";
14
+ readonly GetTitleContent: "ActiveOutline.Editor.Document.GetTitleContent";
15
+ readonly SetTitleContent: "ActiveOutline.Editor.Document.SetTitleContent";
16
+ readonly Font: {
17
+ readonly SetTextColor: "ActiveOutline.Editor.Document.Font.SetTextColor";
18
+ readonly SetHighLightColor: "ActiveOutline.Editor.Document.Font.SetHighLightColor";
19
+ readonly SetBold: "ActiveOutline.Editor.Document.Font.SetBold";
20
+ readonly SetItalic: "ActiveOutline.Editor.Document.Font.SetItalic";
21
+ readonly SetUnderline: "ActiveOutline.Editor.Document.Font.SetUnderline";
22
+ readonly SetStrike: "ActiveOutline.Editor.Document.Font.SetStrike";
23
+ };
24
+ readonly Markdown: {
25
+ readonly GetMarkdown: "ActiveOutline.Editor.Document.Markdown.GetMarkdown";
26
+ readonly AppendMarkdown: "ActiveOutline.Editor.Document.Markdown.AppendMarkdown";
27
+ readonly InsertMarkdown: "ActiveOutline.Editor.Document.Markdown.InsertMarkdown";
28
+ readonly ValidateMarkdown: "ActiveOutline.Editor.Document.Markdown.ValidateMarkdown";
29
+ };
30
+ readonly Content: {
31
+ readonly ReplaceSelection: "ActiveOutline.Editor.Document.Content.ReplaceSelection";
32
+ readonly ReplaceAllContent: "ActiveOutline.Editor.Document.Content.ReplaceAllContent";
33
+ };
34
+ };
35
+ };
36
+ readonly Service: {
37
+ readonly User: {
38
+ readonly GetUserInfo: "ActiveOutline.Service.User.GetUserInfo";
39
+ };
40
+ readonly Permission: {
41
+ readonly GetDocumentPermission: "ActiveOutline.Service.Permission.GetDocumentPermission";
42
+ };
43
+ readonly Export: {
44
+ readonly DownloadDocument: "ActiveOutline.Service.Export.DownloadDocument";
45
+ };
46
+ readonly Collaboration: {
47
+ readonly GetSaveStatus: "ActiveOutline.Service.Collaboration.GetSaveStatus";
48
+ };
49
+ };
50
+ readonly Env: {
51
+ readonly Language: {
52
+ readonly GetLanguage: "ActiveOutline.Env.Language.GetLanguage";
53
+ };
54
+ readonly DocsMode: {
55
+ readonly GetDocsMode: "ActiveOutline.Env.DocsMode.GetDocsMode";
56
+ };
57
+ };
58
+ readonly Sub: {
59
+ readonly OnDocumentChange: "ActiveOutline.Sub.OnDocumentChange";
60
+ };
61
+ };
62
+ };
63
+ type LeafValues<T> = T extends string ? T : T extends object ? {
64
+ [K in keyof T]: LeafValues<T[K]>;
65
+ }[keyof T] : never;
66
+ export type OfficeSDKMethodPath = LeafValues<typeof OfficeSDKMethods>;
67
+ export {};
package/dist/connect.d.ts CHANGED
@@ -1,19 +1,6 @@
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';
5
2
  export interface ConnectOptions extends OfficeSDKOptions {
6
3
  }
7
- export interface ConnectV2Options extends ConnectOptions {
8
- /**
9
- * V2 套件类型。当前用于 iframe 侧资源选择预留。
10
- */
11
- type: ConnectV2FileType;
12
- /**
13
- * V2 打开模式。
14
- */
15
- mode: 'edit' | 'preview';
16
- }
17
4
  /**
18
5
  * 初始化 SDK,返回 Promise,当 ReadState 变为 Ready 或 Failed 时,Promise 将被 resolve。
19
6
  * Promise resovled 不代表编辑器已经完整加载完毕,只代表 SDK 已经准备好了。
@@ -21,9 +8,3 @@ export interface ConnectV2Options extends ConnectOptions {
21
8
  * 比如受浏览器限制无法发出 postMessage() 时,Promise 将会一直 pending。
22
9
  */
23
10
  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,4 +1,5 @@
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';
1
+ import type { AddChartFromSelectionResult, BasicPresentationFacade, DocsActiveOutlineFacade, DocsEditorDeltaSnapshot, DocsRangeFacade, DocsRangeValue, DocsTableFacade, EditorTextFormat, OfficeSDK, PresentationFacade, PresentationSlideFacade, PresentationShape, PresentationShapeBase, PresentationTableCell, PresentationTableItem, PresentationTableRange, PresentationTableSelection, PresentationTextShape, PresentationTextRangeFacade, PresentationTextRangeValue, SheetRangeValue, SheetRangeFacade, SheetSelection } from './OfficeSDK';
2
+ import type { OfficeSDKMethodPath } from './OfficeSDK.methods';
2
3
  type IsAssignable<T, U> = T extends U ? true : false;
3
4
  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;
4
5
  type Assert<T extends true> = T;
@@ -11,6 +12,13 @@ type PresentationSelection = Extract<RootSelection, {
11
12
  }>;
12
13
  type RootPresentation = NonNullable<OfficeSDK['presentation']>;
13
14
  export type EditorFacadeContractAssertions = [
15
+ Assert<IsEqual<OfficeSDK['canIUse'], (method: OfficeSDKMethodPath) => Promise<boolean>>>,
16
+ Assert<IsEqual<NonNullable<OfficeSDK['ActiveOutline']>, DocsActiveOutlineFacade>>,
17
+ Assert<IsEqual<DocsActiveOutlineFacade['Editor']['Document']['GetContent'], () => Promise<DocsEditorDeltaSnapshot>>>,
18
+ Assert<IsEqual<DocsActiveOutlineFacade['Editor']['Document']['Markdown']['AppendMarkdown'], (value: string) => Promise<DocsRangeValue>>>,
19
+ Assert<IsEqual<DocsActiveOutlineFacade['Service']['Permission']['GetDocumentPermission'], () => Promise<import('./OfficeSDK').DocsDocumentPermission>>>,
20
+ Assert<IsEqual<DocsActiveOutlineFacade['Service']['Export']['DownloadDocument'], (format: import('./OfficeSDK').DocsDownloadDocumentType) => Promise<void>>>,
21
+ Assert<IsEqual<DocsActiveOutlineFacade['Sub']['OnDocumentChange'], (handler: (delta: DocsEditorDeltaSnapshot) => void) => () => void>>,
14
22
  Assert<IsAssignable<NonNullable<OfficeSDK['title']>['setTitle'], (title: string) => Promise<void>>>,
15
23
  Assert<IsAssignable<NonNullable<OfficeSDK['title']>['addChangedListener'], (listener: (title: string) => void) => () => void>>,
16
24
  Assert<IsAssignable<NonNullable<OfficeSDK['locks']>['addRangeLock'], (options: import('./OfficeSDK').AddRangeLockParams) => Promise<void>>>,
@@ -0,0 +1,26 @@
1
+ import type { HeaderBarsAnchorRect, HeaderBarsSourceAnchorRect } from './OfficeSDK.headerBars';
2
+ /** iframe 内容区矩形,仅取换算需要的字段。 */
3
+ export interface HeaderBarsIframeRect {
4
+ left: number;
5
+ top: number;
6
+ width: number;
7
+ height: number;
8
+ }
9
+ /** 宿主视口尺寸。 */
10
+ export interface HeaderBarsViewportSize {
11
+ width: number;
12
+ height: number;
13
+ }
14
+ /**
15
+ * 将 iframe 视口坐标系下的锚点矩形换算到宿主页面坐标系。
16
+ *
17
+ * 输入:
18
+ * - anchorRect:iframe 内部产生的矩形,viewport 为来源视口尺寸;
19
+ * - iframeRect:编辑器 iframe 元素在宿主页面的矩形,缺省时按无缩放、无偏移处理;
20
+ * - viewport:宿主视口尺寸。
21
+ * 输出:可序列化的宿主坐标系矩形,coordinateSpace 固定为 callback-window-viewport。
22
+ *
23
+ * 缩放比例按来源视口尺寸计算,因此 iframe 被 CSS 缩放时仍能得到正确位置;
24
+ * 不承诺旋转、倾斜或 3D transform 场景。
25
+ */
26
+ export declare function toHeaderBarsCallbackAnchorRect(anchorRect: HeaderBarsSourceAnchorRect, iframeRect: HeaderBarsIframeRect | null | undefined, viewport: HeaderBarsViewportSize): HeaderBarsAnchorRect;
package/dist/index.d.ts CHANGED
@@ -8,7 +8,9 @@ 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';
13
+ export * from './OfficeSDK.methods';
12
14
  export type { EmptyPageScene, EmptyPageOptions, EmptyPageActionOverride, EmptyPageContentOverride, NormalizedEmptyPageOptions, EmptyPageShownPayload, EmptyPageActionPayload, EmptyPageHiddenPayload, FileOpenFailedReason, TokenExpiredStrategy } from './types/EmptyPage';
13
15
  export type { SlashMenuButton, SlashMenuEntry, SlashMenuOptions } from './types/SlashMenu';
14
16
  export { ALL_EMPTY_PAGE_SCENES, normalizeEmptyPageOptions } from './types/EmptyPage';