weboffice-js-sdk 2.0.2 → 2.0.3-beta.6

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.
@@ -6,7 +6,42 @@ import 'proxy-polyfill';
6
6
  import { TinyEmitter } from 'tiny-emitter';
7
7
  import { ContainerMethod, ContainerRect, DisableMentionCards, FileType, InvokeMethod, MouseMovePayload, ReadyState, PerformanceEntry, DeviceMode, GenerateUrlHandler, APIAdaptor, RequestContext, ShowToastOptions, Credentials } from 'weboffice-js-sdk-shared';
8
8
  import { Document, DocumentPro, Presentation, Spreadsheet, Table, Form, Flowchart } from '.';
9
+ import { EmptyPageOptions } from './types/EmptyPage';
9
10
  import { BaseEditor } from './types/BaseEditor';
11
+ export interface HeaderBarsCommandDefinition {
12
+ id: string;
13
+ section?: string;
14
+ order?: number;
15
+ label?: string;
16
+ visible?: boolean;
17
+ disabled?: boolean;
18
+ editable?: boolean;
19
+ type?: 'action' | 'structural';
20
+ renderType?: string;
21
+ src?: string;
22
+ onClick?: () => void | Promise<void>;
23
+ }
24
+ export interface HeaderBarsCommandState extends HeaderBarsCommandDefinition {
25
+ type: 'action' | 'structural';
26
+ }
27
+ export interface HeaderBarsCommandRef {
28
+ readonly id: string;
29
+ visible: boolean;
30
+ disabled: boolean;
31
+ editable?: boolean;
32
+ onCommandClick?: () => void | Promise<void>;
33
+ getState: () => HeaderBarsCommandState | undefined;
34
+ }
35
+ export interface HeaderBarsFacade {
36
+ visible: boolean;
37
+ getVisible: () => Promise<boolean>;
38
+ setVisible: (visible: boolean) => Promise<void>;
39
+ addCommand: (command: HeaderBarsCommandDefinition, posCommand: string, pos?: 'before' | 'after') => Promise<boolean>;
40
+ getCommand: (id: string) => HeaderBarsCommandRef;
41
+ listViewCommands: () => Promise<HeaderBarsCommandState[]>;
42
+ setTitleDraft: (title: string) => Promise<void>;
43
+ confirmTitleChange: (title: string) => Promise<void>;
44
+ }
10
45
  export declare const MessageEvent: typeof InvokeMethod;
11
46
  export declare class OfficeSDK extends TinyEmitter {
12
47
  /**
@@ -50,9 +85,9 @@ export declare class OfficeSDK extends TinyEmitter {
50
85
  * @deprecated - 用 `sdk.getEditor<T>()` 替代
51
86
  */
52
87
  flowchart?: Flowchart.Editor;
88
+ readonly headerBars: HeaderBarsFacade;
53
89
  private _fileType;
54
90
  private readonly messageHandler;
55
- private loadingOverlay?;
56
91
  /**
57
92
  * 内部 event emitter,比如用来中转 editor 事件
58
93
  */
@@ -75,7 +110,18 @@ export declare class OfficeSDK extends TinyEmitter {
75
110
  */
76
111
  private readonly endpoint;
77
112
  private readonly sameOrigin;
113
+ private headerBarsVisible;
114
+ private readonly headerBarsCommands;
115
+ private readonly headerBarsCommandOverrides;
116
+ private readonly headerBarsCommandRefs;
78
117
  private readonly onViewportResize;
118
+ /**
119
+ * 归一化后的缺省页配置,构造时一次算完,后续仅读取。
120
+ */
121
+ private readonly normalizedEmptyPage;
122
+ private readonly preloadAckTimeoutMs;
123
+ private readonly preloadDoneTimeoutMs;
124
+ private readonly preloadReadyTimeoutMs;
79
125
  constructor(options: OfficeSDKOptions);
80
126
  get fileType(): FileType;
81
127
  get readyState(): ReadyState;
@@ -110,15 +156,20 @@ export declare class OfficeSDK extends TinyEmitter {
110
156
  * 比如受浏览器限制无法发出 postMessage() 时,Promise 将会一直 pending。
111
157
  */
112
158
  init(): Promise<void>;
113
- private setupLoadingOverlay;
114
- private removeLoadingOverlay;
115
- private ensureLoadingStyle;
116
159
  private initIframe;
160
+ private runPreloadHandshake;
117
161
  private initChannel;
118
162
  /**
119
163
  * 初始化处理编辑器需要容器返回数据的方法
120
164
  */
121
165
  private bindContainerMethodHandlers;
166
+ private initHeaderBarsFacade;
167
+ private invokeHeaderBars;
168
+ private syncHeaderBarsCommands;
169
+ private applyHeaderBarsChanged;
170
+ private syncHeaderBarsVisible;
171
+ private setHeaderBarsVisible;
172
+ private getHeaderBarsCommandRef;
122
173
  private initEditor;
123
174
  private shouldHandleMessage;
124
175
  private getContainerRect;
@@ -188,11 +239,25 @@ export declare enum Event {
188
239
  * OfficeSDK 状态变化事件
189
240
  */
190
241
  ReadyState = "readyState",
242
+ /**
243
+ * 编辑器真正完成"首屏渲染"的信号。
244
+ *
245
+ * 由 iframe 内编辑器在自身渲染稳定后通过 channel 发送,SDK 侧转发为本事件。
246
+ * 宿主可按需监听它来区分 SDK Ready 与编辑器视觉首屏完成。
247
+ */
248
+ EditorRendered = "editorRendered",
191
249
  /**
192
250
  * 编辑器事件
193
251
  */
194
252
  EditorEvent = "editorEvent"
195
253
  }
254
+ /**
255
+ * iframe 内侧用来上报"编辑器已完成首屏渲染"的 channel 事件名。
256
+ *
257
+ * 与 `InvokeMethod.ReadyState` 的枚举值保持在同一命名空间,但不入 shared 包,
258
+ * 以免跨端版本耦合。iframe 侧约定写字符串即可。
259
+ */
260
+ export declare const EDITOR_RENDERED_EVENT = "editorRendered";
196
261
  export interface Message {
197
262
  uuid?: string;
198
263
  event: string;
@@ -222,6 +287,20 @@ export type EventCallback = (...args: any[]) => any;
222
287
  export interface SDKToastOptions {
223
288
  [key: string]: string | SDKToastOptions | undefined;
224
289
  }
290
+ /**
291
+ * iframe 内置加载页配置,只支持可序列化字段。
292
+ */
293
+ export interface LoadingOptions {
294
+ /**
295
+ * 自定义加载页 Logo。传字符串时作为图片 URL / dataURL 使用;
296
+ * 传 false 时隐藏 Logo;不传时使用 iframe 内默认石墨 Logo。
297
+ */
298
+ logo?: string | false;
299
+ /**
300
+ * 自定义加载页提示文案。不传时使用 iframe 内默认文案。
301
+ */
302
+ tip?: string;
303
+ }
225
304
  /**
226
305
  * OfficeSDK 初始化参数
227
306
  */
@@ -256,6 +335,10 @@ export interface OfficeSDKOptions extends Omit<ContainerMethods, 'getContainerRe
256
335
  params?: {
257
336
  [key: string]: string;
258
337
  };
338
+ /**
339
+ * 当前打开模式。`preview` 用于预览态,其余场景默认按 `edit` 处理。
340
+ */
341
+ mode?: 'edit' | 'preview';
259
342
  /**
260
343
  * 石墨 SDK URL 参数 url?smParams={params},用于传递石墨 SDK 内部需要的参数。
261
344
  */
@@ -264,14 +347,27 @@ export interface OfficeSDKOptions extends Omit<ContainerMethods, 'getContainerRe
264
347
  * 指定石墨 SDK 编辑器界面语言,添加到 iframe URLSearchParams 的参数列表。
265
348
  * 若未指定,则 iframe 使用服务器设置的默认语言。
266
349
  *
267
- * 目前支持的语言取值:
350
+ * 目前支持的标准语言取值:
268
351
  * 1. zh-CN(简体中文)
269
- * 2. en(英文)
270
- * 3. ja(日文)
271
- * 4. ar-SA(阿拉伯语)
272
- * 5. ru-RU(俄语)
352
+ * 2. zh-TW(繁体中文)
353
+ * 3. en-US(英文)
354
+ * 4. ja-JP(日文)
355
+ * 5. ko-KR(韩文)
356
+ * 6. es-ES(西班牙语)
357
+ * 7. pt-PT(葡萄牙语)
358
+ * 8. de-DE(德语)
359
+ * 9. fr-FR(法语)
360
+ * 10. it-IT(意大利语)
361
+ * 11. ru-RU(俄语)
362
+ * 12. id-ID(印尼语)
363
+ * 13. vi-VN(越南语)
364
+ * 14. th-TH(泰语)
365
+ * 15. ms-MY(马来语)
366
+ * 16. ar-SA(阿拉伯语)
367
+ *
368
+ * 为兼容旧版写法,仍接受 en、ja,传入后会自动映射为 en-US、ja-JP。
273
369
  */
274
- lang?: 'zh-CN' | 'en' | 'ja' | 'ar-SA' | 'ru-RU';
370
+ lang?: 'zh-CN' | 'zh-TW' | 'en-US' | 'ja-JP' | 'ko-KR' | 'es-ES' | 'pt-PT' | 'de-DE' | 'fr-FR' | 'it-IT' | 'ru-RU' | 'id-ID' | 'vi-VN' | 'th-TH' | 'ms-MY' | 'ar-SA' | 'en' | 'ja';
275
371
  /**
276
372
  * 是否禁用提及的浮动卡片组件
277
373
  */
@@ -311,14 +407,24 @@ export interface OfficeSDKOptions extends Omit<ContainerMethods, 'getContainerRe
311
407
  * 是否禁用默认的签名组件,以支持自定义签名组件。受版本限制,部分版本的特定类型文档才支持。
312
408
  */
313
409
  disableSignatureComponent?: boolean;
410
+ /**
411
+ * 控制 headerbar 组件是否展示,false 表示隐藏。
412
+ */
413
+ headerBarsVisible?: boolean;
314
414
  /**
315
415
  * 是否显示内置的加载动画,只在静态资源加载到编辑器渲染这个阶段显示
316
416
  */
317
417
  showLoadingEffect?: boolean;
318
418
  /**
319
- * 是否展示 SDK 默认的加载遮罩,覆盖 container,默认 false
419
+ * 是否启用 iframe 内置默认加载页,默认 false
420
+ * 隐藏后接入方可自定义外部 loading。
320
421
  */
321
422
  showLoading?: boolean;
423
+ /**
424
+ * iframe 内置加载页配置。仅在 `showLoading === true`
425
+ * 或 `showLoadingEffect === true` 时透传给 iframe。
426
+ */
427
+ loadingOptions?: LoadingOptions;
322
428
  /**
323
429
  * 用于在编辑器发起 API 请求时,对请求参数进行修改的函数。详细用法见文档。
324
430
  */
@@ -335,4 +441,17 @@ export interface OfficeSDKOptions extends Omit<ContainerMethods, 'getContainerRe
335
441
  * 加密后的用户id
336
442
  */
337
443
  userUuid?: string;
444
+ /**
445
+ * 缺省页(Empty Page)配置。
446
+ * - 不传或传 `true`:启用默认缺省页能力(有内置图片与默认文案,**无按钮**)
447
+ * - 传 `false`:完全关闭
448
+ * - 传对象:精细控制启用的 scene、token 过期策略,以及每个 scene 的
449
+ * 文案/按钮自定义(`overrides`)。默认不渲染任何按钮,宿主需要按钮时必须
450
+ * 在 `overrides[scene].primary/secondary` 里显式配置 label,点击统一触发
451
+ * `emptyPageAction` 事件由宿主处理。
452
+ *
453
+ * 相关事件:`emptyPageShown` / `emptyPageAction` / `emptyPageHidden`。
454
+ * 详见 `./types/EmptyPage.ts`。
455
+ */
456
+ emptyPage?: boolean | EmptyPageOptions;
338
457
  }
@@ -9,5 +9,7 @@ import { EventMap as BaseEventMap, BaseEditor } from './types/BaseEditor';
9
9
  export * from 'weboffice-js-sdk-shared';
10
10
  export * from './connect';
11
11
  export * from './OfficeSDK';
12
+ export type { EmptyPageScene, EmptyPageOptions, EmptyPageActionOverride, EmptyPageContentOverride, NormalizedEmptyPageOptions, EmptyPageShownPayload, EmptyPageActionPayload, EmptyPageHiddenPayload, FileOpenFailedReason, TokenExpiredStrategy } from './types/EmptyPage';
13
+ export { ALL_EMPTY_PAGE_SCENES, normalizeEmptyPageOptions } from './types/EmptyPage';
12
14
  export { BaseEditor, DocumentPro, Document, Spreadsheet, Presentation, Table, Form, Flowchart, BaseEventMap };
13
15
  export declare const START_PARAMS_FIELD = "smParams";