@p10node/office-engine 0.2.2 → 0.3.0

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.
@@ -10,7 +10,7 @@ export declare function mount(el: HTMLElement, options: MountOptions): MountedVi
10
10
  /**
11
11
  * `<office-viewer src="/file.xlsx" style="height:600px"></office-viewer>`
12
12
  * Rendered inside a shadow root so host page CSS cannot leak in.
13
- * Attributes: src, name, editable, toolbar / thumbnails / save / download / file-menu / open ("false" to hide);
13
+ * Attributes: src, name, editable, toolbar / thumbnails / save / download / file-menu / open / capture-select-all ("false" to turn off);
14
14
  * real-time collaboration: collab (hub WebSocket URL), room, user (display name), base (snapshot seq `src` was opened at).
15
15
  * Property: `file` (File/Blob/ArrayBuffer) for local data.
16
16
  */
@@ -57,5 +57,10 @@ export interface DocViewerProps {
57
57
  * edits it together through the hub at `transport` (see src/collab).
58
58
  */
59
59
  collab?: CollabOptions;
60
+ /**
61
+ * Ctrl/⌘+A anywhere on the page selects the document (text fields outside the viewer keep their own).
62
+ * Default true. With false the shortcut works from the viewer only (its content or toolbar).
63
+ */
64
+ captureSelectAll?: boolean;
60
65
  }
61
66
  export declare function DocViewer(props: DocViewerProps): import("react").JSX.Element;
@@ -27,11 +27,17 @@ export interface ViewerApi {
27
27
  fileOps: {
28
28
  current: FileOps | null;
29
29
  };
30
+ /** set by the mounted view (see useSelectAll): Ctrl/⌘+A */
31
+ selectAll: {
32
+ current: (() => void) | null;
33
+ };
30
34
  }
31
35
  export declare const ViewerContext: import("react").Context<ViewerApi>;
32
36
  export declare const useViewer: () => ViewerApi;
33
37
  /** Publishes the view's file operations (latest closure each render) to the File menu. */
34
38
  export declare function useFileOps(ops: FileOps): void;
39
+ /** Publishes the view's select-all: Ctrl/⌘+A from the viewer chrome or, with `captureSelectAll`, from anywhere on the page. */
40
+ export declare function useSelectAll(fn: () => void): void;
35
41
  /** Renders the editor bar into the viewer's toolbar row. */
36
42
  export declare function EditorBar({ children }: {
37
43
  children: ReactNode;
@@ -18,3 +18,10 @@ export declare function useMediaUrl(client: DocumentClient, path: string | undef
18
18
  export declare function lowerIndex(arr: ArrayLike<number>, v: number): number;
19
19
  export declare function useLatest<T>(v: T): import("react").RefObject<T>;
20
20
  export declare function useStableCallback<A extends unknown[], R>(fn: (...a: A) => R): (...a: A) => R;
21
+ /** A control that takes typed text: Ctrl/⌘+A selects its own content. */
22
+ export declare function isTextEntry(target: EventTarget | null): boolean;
23
+ /**
24
+ * Focuses `el` so keyboard shortcuts work without a click. The focus stays where it is when a control
25
+ * outside the viewer has it (a host page form); the viewer's own chrome (or the page body) yields.
26
+ */
27
+ export declare function claimFocus(el: HTMLElement | null): boolean;
@@ -1,7 +1,7 @@
1
1
  import type { Block, CanonStyle, Paragraph, ParaDirty, ParaStyle, RunSet, RunStyle, StyleInfo } from '../../core/docx/types';
2
2
  import type { DocumentClient } from '../../core/worker/client';
3
3
  import { RichInput, type ReplaceOpts, type RichHost } from '../edit/input';
4
- import { type RRun, type Sel } from '../edit/rich';
4
+ import { type Pos, type RRun, type Sel } from '../edit/rich';
5
5
  export interface DocState {
6
6
  blocks: Block[];
7
7
  heights: WeakMap<Block, number>;
@@ -81,6 +81,11 @@ export declare class DocxEditor implements RichHost<Paragraph> {
81
81
  prev(pa: string): string | undefined;
82
82
  next(pa: string): string | undefined;
83
83
  cmp(a: string, b: string): number;
84
+ /** the whole document: from the first to the last editable top-level paragraph */
85
+ all(): Sel | null;
86
+ selectAll(): void;
87
+ /** Deletes a top-level range that spans tables: the end paragraphs are joined, everything between goes (section breaks stay). */
88
+ deleteAcross(s: Pos, e: Pos): Pos | null;
84
89
  withRuns(p: Paragraph, runs: RRun[]): Paragraph;
85
90
  private origOf;
86
91
  defaultRun(p: Paragraph): Partial<RRun> | undefined;
@@ -40,6 +40,10 @@ export interface RichHost<P extends RichPara = RichPara> {
40
40
  pendingStyle?(): Partial<RRun> | undefined;
41
41
  clearPending?(): void;
42
42
  onSelection?(sel: Sel | null): void;
43
+ /** the whole document (select all); null when there is nothing to select */
44
+ all?(): Sel | null;
45
+ /** deletes a range that spans other blocks (tables): applies the change and returns the caret, or null when unsupported */
46
+ deleteAcross?(s: Pos, e: Pos): Pos | null;
43
47
  }
44
48
  export declare function ordered(host: RichHost, s: Sel): [Pos, Pos];
45
49
  export declare function opDelete(host: RichHost, sel: Sel, opts?: ReplaceOpts): void;
@@ -63,6 +67,8 @@ export declare class RichInput {
63
67
  private justComposed;
64
68
  private raf;
65
69
  lastSel: Sel | null;
70
+ /** select all: the model selection covers every paragraph, the DOM one only what is rendered */
71
+ private override;
66
72
  constructor(host: RichHost);
67
73
  attach(root: HTMLElement): void;
68
74
  detach(): void;
@@ -70,6 +76,12 @@ export declare class RichInput {
70
76
  readSel(): Sel | null;
71
77
  /** current selection, falling back to the last known one (e.g. after focusing a toolbar control) */
72
78
  sel(): Sel | null;
79
+ /**
80
+ * Selects the whole document. The browser's own select-all is useless here: the editing host holds
81
+ * non-editable parts (headers, read-only paragraphs) and Chromium empties a selection that crosses them;
82
+ * pages are also virtualized, so the DOM only ever holds a part of the document.
83
+ */
84
+ selectAll(): boolean;
73
85
  /** Applies a model selection to the DOM; false when its paragraph isn't rendered. */
74
86
  restore(sel: Sel | null, focus?: boolean): boolean;
75
87
  private rangeSel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@p10node/office-engine",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Browser engine to view DOCX, XLSX, PPTX progressively (worker-based, range-loading, virtualized React views)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -54,6 +54,7 @@
54
54
  "collab": "bun scripts/collab-server.ts",
55
55
  "clean": "rm -rf dist",
56
56
  "screenshots": "bun scripts/screenshots.ts",
57
+ "gifs": "bun scripts/gifs.ts",
57
58
  "build:site": "bun scripts/build-site.ts"
58
59
  },
59
60
  "peerDependencies": {