wordinweb 0.1.7 → 0.1.9

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
@@ -14,7 +14,7 @@ Editing is in an Alpha state and is strictly opt-in via the `editable` flag; the
14
14
 
15
15
  If you discover an edge case or perf issue create an issue and include the offending Word file.
16
16
 
17
- Part of the broader roadmap is to migrate away from DOM rendering to canvas rendering, or a hybrid of the two. Editing performance can suffer on very long documents.
17
+ Long-document performance work focuses on incremental parsing/layout and page virtualization; the current renderer remains DOM-based.
18
18
 
19
19
  ---
20
20
 
@@ -67,7 +67,7 @@ export function Editor() {
67
67
 
68
68
  return (
69
69
  <div>
70
- {api && <DocxToolbar api={api} onSave={download} />}
70
+ {api && <DocxToolbar api={api} mode="advanced" onSave={download} />}
71
71
  <DocxView
72
72
  source="/report.docx"
73
73
  editable
@@ -116,19 +116,36 @@ The object passed to `onReady`. Every command operates on the current selection
116
116
  **Page layout**
117
117
  - `setPageLayout(patch, scope?)` — margins, page size, orientation, columns, page borders. `scope` = `"document"` (all sections) or `"section"` (the caret's).
118
118
  - `insertBreak("page" | "column" | "sectionNextPage" | "sectionContinuous")`.
119
+ - `insertBlankPage()` — inserts a complete blank page at the caret.
120
+ - `insertCoverPage({ title, subtitle?, author? })` — prepends an editable, styled cover page.
119
121
  - `setLineNumbering(patch, scope?)`, `getLineNumbering()`.
122
+ - `openHeaderFooter("header" | "footer")`, `closeHeaderFooter()` — create or directly enter page header/footer editing; Escape closes it.
120
123
 
121
124
  **Tables**
122
125
  - `insertTable(rows, cols)`.
123
126
  - `tableOp(op)` — insert/delete row/column, merge/split cells, cell vertical align, cell shading, delete table.
124
127
 
125
128
  **Images**
126
- - `insertImage(file)` — inserts a `Blob`/`File` inline at the caret, clamped to the column width (TIFF/WMF/EMF are decoded to something the browser can paint).
129
+ - `insertImage(file)` — inserts a raster image or editable SVG icon inline at the caret, clamped to the column width (TIFF/WMF/EMF are decoded to something the browser can paint).
130
+ - `insertScreenshot()` — opens the browser screen/window/tab picker and inserts the captured frame as an editable PNG picture.
131
+ - `insertModel3D(file, poster?)` — packages a GLB as a native Office 3D model with an editable poster fallback.
132
+ - `insertOnlineVideo(url)` — inserts Word online-video metadata with a safe browser poster; double-click opens the validated HTTP(S) URL.
133
+ - `insertEmbeddedObject(file, filename?)` — embeds any file as a native OLE Package; double-click safely downloads the original file in the browser.
127
134
 
128
- **Comments, footnotes & fields**
135
+ **Comments, footnotes & Insert content**
129
136
  - `addComment(text)` — comment on the selection (`false` if nothing is selected).
130
137
  - `addFootnote(text)` — footnote at the caret.
131
138
  - `insertPageNumber("page" | "pageOfTotal")` — dynamic `PAGE` / `Page X of Y` field.
139
+ - `insertField(instruction, cachedResult?)`, `insertDateTime("date" | "time", picture?)` — live Word fields.
140
+ - `addBookmark(name)`, `listBookmarks()`, `insertCrossReference(name, "text" | "page")` — named bookmark targets and live `REF` / `PAGEREF` fields.
141
+ - `insertEquation(linear)`, `insertSymbol(symbol)` — native editable OMML equations and arbitrary Unicode symbols.
142
+ - `insertShape(preset, text?)` — floating editable DrawingML rectangles, rounded rectangles, ellipses, diamonds, and text boxes. Advanced mode also exposes Text Box as its own Insert control.
143
+ - `insertWordArt(text, preset?)` — editable DrawingML WordArt with plain, arch, wave, and chevron presets.
144
+ - `insertChart(data)`, `updateSelectedChart(data)` — native editable ChartML with its embedded workbook.
145
+ - `insertSmartArt(data)`, `updateSelectedSmartArt(data)` — native editable SmartArt data, layout, style, colors, and cached drawing parts.
146
+ - `setDrawingTool({ kind: "pen", color, width } | { kind: "eraser", size } | { kind: "lasso" } | null)`, `getDrawingTool()` — draw, erase, or lasso-select movable DrawingML ink.
147
+ - `arrangeObject(action)` — align the selected image, shape, or ink group to the page; rotate it 90°; or bring it to the front/send it to the back. Arrow keys nudge selected floating objects by 1px (`Shift` = 10px).
148
+ - `setDropCap("drop" | "margin" | null, lines?)` — apply, change, or remove a native Word drop cap on the caret paragraph.
132
149
 
133
150
  **Suggesting mode (tracked changes)**
134
151
  - `setSuggesting(on, author?)` — when on, edits record as OOXML `w:ins`/`w:del` instead of mutating text directly, and the view switches to markup.
@@ -144,16 +161,18 @@ The object passed to `onReady`. Every command operates on the current selection
144
161
  - `undo()`, `redo()`, `canUndo()`, `canRedo()`.
145
162
  - `save()` → edited `.docx` bytes (`Uint8Array`). Everything the model doesn't touch round-trips byte-for-byte.
146
163
  - `print()` — browser print dialog / save-as-PDF of the rendered pages.
147
- - `pageCount()`, `closeHeaderFooter()`, and `document` (the parsed `DocxDocument`).
164
+ - `pageCount()` and `document` (the parsed `DocxDocument`).
148
165
 
149
166
  ### `DocxToolbar`
150
167
 
151
- A ready-made formatting toolbar for an editable `DocxView`. Ribbon-style tabs (Home / Insert / Layout) wired to the `api`.
168
+ A ready-made formatting toolbar for an editable `DocxView`. Use `mode="simple"` for the basic Home editing strip or `mode="advanced"` for the full Home / Insert / Draw / Layout ribbon supported by the installed version.
169
+ Layout includes Word-style paper presets plus a custom width/height dialog; both document and current-section scope emit native page-size properties.
152
170
 
153
171
  | Prop | Type | What it does |
154
172
  | --- | --- | --- |
155
173
  | `api` | `DocxViewApi \| null` | The api from `onReady`. |
156
174
  | `onSave` | `(bytes: Uint8Array) => void` | Adds a Download button; receives `api.save()` bytes. |
175
+ | `mode` | `"simple" \| "advanced"` | Editing surface. Defaults to `"advanced"`; simple omits the Insert, Draw, and Layout ribbons. |
157
176
  | `features` | `Partial<Record<ToolbarFeature, boolean>>` | Per-group toggles; every group defaults on. Set one `false` to hide it (e.g. `{ table: false, image: false }`). |
158
177
  | `className` | `string` | Class on the toolbar root — handy as a scope for CSS-variable overrides. |
159
178
  | `style` | `React.CSSProperties` | Inline overrides merged onto the toolbar root. |
@@ -168,6 +187,7 @@ Every color the chrome paints — the toolbar, comment cards, selection, caret,
168
187
  | `--dxw-toolbar-fg` | `#3c4043` | Toolbar text & icons (icons use `currentColor`) |
169
188
  | `--dxw-toolbar-border` | `#dadce0` | Toolbar borders & separators |
170
189
  | `--dxw-toolbar-muted` | `#5f6368` | Secondary/label text |
190
+ | `--dxw-toolbar-z-index` | `100` | Toolbar and open-menu stacking level |
171
191
  | `--dxw-accent` | `#1a73e8` | Primary accent (active tab, pills, focus rings) |
172
192
  | `--dxw-accent-fg` | `#fff` | Text/icon on an accent fill |
173
193
  | `--dxw-btn-active-bg` | `#dfe7f5` | Toggled button background |
@@ -175,6 +195,9 @@ Every color the chrome paints — the toolbar, comment cards, selection, caret,
175
195
  | `--dxw-tab-active-bg` | `#e8f0fe` | Active ribbon-tab background |
176
196
  | `--dxw-popover-bg` | `#fff` | Dropdown / popover surface |
177
197
  | `--dxw-popover-shadow` | `0 4px 16px rgba(0,0,0,.15)` | Popover shadow |
198
+ | `--dxw-layout-menu-width` | `304px` | Layout option-menu width |
199
+ | `--dxw-layout-menu-max-height` | `480px` | Layout option-menu scroll limit |
200
+ | `--dxw-layout-preview-bg` | `#fff` | Paper fill in Layout option previews |
178
201
  | `--dxw-canvas-bg` | `#e8eaed` | Scroll area behind the pages |
179
202
  | `--dxw-page-bg` | `#ffffff` | Page paper |
180
203
  | `--dxw-page-shadow` | `0 1px 3px …, 0 4px 14px …` | Page drop shadow |
@@ -215,6 +238,12 @@ Or in a stylesheet:
215
238
  .dxw-dark { --dxw-toolbar-bg: #1f2937; --dxw-toolbar-fg: #e5e7eb; /* … */ }
216
239
  ```
217
240
 
241
+ Layout controls also expose stable `.dxw-layout-ribbon`, `.dxw-layout-menu-trigger`,
242
+ `.dxw-layout-menu`, `.dxw-layout-menu-item`, and `.dxw-layout-preview` classes.
243
+ Their `data-dxw-layout-menu`, `data-dxw-layout-option`, and
244
+ `data-dxw-layout-preview` attributes identify each menu, action, and diagram
245
+ when a host needs a narrowly scoped style override.
246
+
218
247
  ## How it works
219
248
 
220
249
  WordInWeb never converts the document to flowing HTML. It parses the OOXML into a typed model, runs a layout engine that breaks lines with real canvas metrics and paginates like Word, and renders each primitive as one absolutely-positioned element, so the browser does zero reflow. Editing mutates the retained XML tree and re-serializes only the parts it models, leaving everything else byte-for-byte intact.